akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();

    int ans = 0;
    for(int i = 1; i < n; i++){
      ans += n / i;
      if(n % i == 0){
        ans--;
      }
    }
    System.out.println(ans);
  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 25904
def p(u):
 if u+1:print(s,u,end=s);p(T[u]);p(T[u+N])
def i(u):
 if u+1:i(T[u]);print(s,u,end=s);i(T[u+N])
def o(u):
 if u+1:o(T[u]);o(T[u+N]);print(s,u,end=s)
s=''
N=int(input())
T=[0,0]*N
R=set(range(N))
for _ in[0]*N:
 a,b,c=map(int,input().split())
 T[a],T[a+N]=b,c
 R-={b,c}
r=R.pop()
print('Preorder')
p(r)
print('\nInorder')
i(r)
print('\nPostorder')
o(r)
print()


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

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

ll mod = 1000000007;

ll gcd(ll a, ll b){
  if (a%b == 0)return(b);
  else return(gcd(b, a%b));
}

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}

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

  int n;
  int cnt = 0;
  string ret = "No";

  cin >> n;
  rep(i,n){
    int a,b;
    cin >> a >> b;
    if(a == b) cnt++;
    else cnt = 0;
    if(cnt >= 3) ret = "Yes";
  }
  cout << ret << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
const int _max=2e5+50;
long long num[_max];
using namespace std;
using LL = long long;
int main()
{
	LL n;
	map<LL, LL >mp;
	cin>>n;
	for( LL i=0;i<n;i++)
	{
		cin>>num[i];
		mp[num[i]]=0;
	}
	for( LL i=0;i<n;i++)
	  mp[num[i]]++;
	map< LL, LL > ::iterator it;
	LL ans=0;
	for(it=mp.begin();it!=mp.end();it++)
	{
	    if(it->second>=2)
	    ans+=((it->second-1)*(it->second-1)+(it->second-1))/2;
	}
	for( LL i=0;i<n;i++)
	{
		LL t=0;
		if(mp[num[i]]>=2)
		{t=((mp[num[i]]-1)*(mp[num[i]]-1)+(mp[num[i]]-1))/2;
		mp[num[i]]--;
		t-=((mp[num[i]]-1)*(mp[num[i]]-1)+(mp[num[i]]-1))/2;
		mp[num[i]]++;
		}
		t=ans-t;
		cout<<t<<endl;
	}
	//system("pause");
	return 0;  
}

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

int main(){
  int h,w,n,p,q,x,y;
  cin >> h >> w >> n >> p >> q;
  
  int res = 0;
  for(int i=1;i<n;i++){
    cin >> x >> y;
    x-=p; y-=q;
    if(x*y<0)res += abs(x) + abs(y);
    else res += max(abs(x),abs(y));
    p += x; q += y;
  }

  cout << res << endl;
}

Measured memory_bytes: 1164
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Dr. Podboq or: How We Became Asymmetric
public class Main{

	double EPS = 1e-8;
	class R{
		String rep;
		Set<String> sub;
		int id, left, right, num, h;
		double rate;
		public R(int id) {
			this.id = id;
			rate = left = right = -1;
			rep = "";
			h = num = 1;
			sub = new HashSet<String>();
		}
		void f(boolean isLeft){
			if(left==-1)return;
			boolean leftStrong = comp(left, right)<=0;
			if(leftStrong && !isLeft || !leftStrong && isLeft){
				int t = left;
				left = right;
				right = t;
			}
			rs[left].f(true);
			rs[right].f(false);
		}
		int comp(int v1, int v2){
			if(Math.abs(rs[v1].rate-rs[v2].rate)>EPS){
				return rs[v1].rate < rs[v2].rate?-1:1;
			}
			if(rs[v1].left==-1 && rs[v2].left==-1)return 0;
			int l1 = rs[v1].left, r1 = rs[v1].right, l2 = rs[v2].left, r2 = rs[v2].right;
			if(comp(l1, r1)==1){
				int t = l1;
				l1 = r1; r1 = t;
			}
			if(comp(l2, r2)==1){
				int t = l2;
				l2 = r2; r2 = t;
			}
			int c = comp(l1, l2);
			if(c!=0){
				return c;
			}
			return comp(r1, r2);
		}
		void p(){
			if(left==-1)System.out.print("x");
			else{
				System.out.print("(");
				rs[left].p();
				System.out.print(" ");
				rs[right].p();
				System.out.print(")");
			}
		}
		void proc(){
			if(left==-1){
				rate = 0;
				h = 1;
				rep = "x";
				sub.add(rep);
				return;
			}
			rs[left].proc();
			rs[right].proc();
			sub.addAll(rs[left].sub); sub.addAll(rs[right].sub);
			int c = 0;
			for(String s:sub)if(rs[left].sub.contains(s) && rs[right].sub.contains(s))c++;
			rate = 1.*c/sub.size();
			num+=rs[left].num+rs[right].num;
			if(rs[left].h < rs[right].h || 
					rs[left].h==rs[right].h&&rs[left].num < rs[right].num ||
					rs[left].h==rs[right].h&&rs[left].num==rs[right].num&&rs[left].rep.compareTo(rs[right].rep)>0){
				int t = left;
				left = right;
				right = t;
			}
			h = Math.max(rs[left].h, rs[right].h)+1;
			rep = "("+rs[left].rep+" "+rs[right].rep+")";
			sub.add(rep);
		}
	}

	R[] rs;
	
	int idx, ID;
	char[] s;
	char get(){
		return s[idx++];
	}
	
	int tree(){
		int res = ID++;
		rs[res] = new R(res);
		char ch = get();
		if(ch=='x'){
			return res;
		}
		rs[res].left = tree();
		get();
		rs[res].right = tree();
		get();
		return res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			s = sc.nextLine().toCharArray();
			if(s[0]=='0')break;
			idx = ID = 0;
			rs = new R[128];
			tree();
			rs[0].proc();
			rs[0].f(true);
			rs[0].p();
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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


int main() {
  int N;
  cin >> N;
  cout << (N + 1) / 2 << endl;
  return 0;
}


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

using namespace std;

template <typename Type>
void print(const Type& data) {
    cout << data << endl;
}

template <typename T, typename... Rest>
void print(const T& data, const Rest&... rest) {
    cout << data << " ";
    print(rest...);
}

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

    vector<int> rateCounter(8, 0);
    int overs = 0;

    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;

        int rate = a / 400;
        if (rate < 8)
            rateCounter[rate]++;
        else
            overs++;
    }

    int kinds = 0;
    for (int i : rateCounter) {
        if (i > 0)
            kinds++;
    }

    int minKinds = max(kinds, 1);
    int maxKinds = kinds + overs;

    print(minKinds, maxKinds);

    return 0;
}


Measured memory_bytes: 256
import sys

# 最大公約数(greatest common divisor)を求める関数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# 最小公倍数(least common multiple)を求める関数
# //は切り捨て除算
def lcm(a, b):
    return a * b // gcd(a, b)

lines = sys.stdin.readlines()
for line in lines:
    a = list(map(int, line.split(" ")))
    print(gcd(a[0], a[1]), lcm(a[0], a[1]))



Measured memory_bytes: 5600
import numpy as np

N, M = map(int, input().split())
H = [int(a) for a in input().split()]
good = np.zeros(N, dtype=int)
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if H[a] > H[b]:
        good[b] += 1
    elif H[a] < H[b]:
        good[a] += 1
    else:
        good[a] += 1
        good[b] += 1

ans = 0
for i in good:
    if i == 0:
        ans += 1
print(ans)


Measured memory_bytes: 38656
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll ac =0;
    ll wa = 0;
    ll tle = 0;
    ll re = 0;
    ll n;
    cin >> n;
    REP(i,n){
        string tmp;
        cin >> tmp;
        if(tmp[0] == 'A'){
            ac++;
        }else if(tmp[0] == 'W'){
            wa++;
        }else if(tmp[0] == 'T'){
            tle++;
        }else if(tmp[0] == 'R'){
            re++;
        }
    }

    cout << "AC x " << ac <<endl;
    cout << "WA x " << wa <<endl;
    cout << "TLE x " << tle <<endl;
    cout << "RE x " << re <<endl;
    return 0;
}

Measured memory_bytes: 3224
if __name__ == '__main__':
    #s = input().rstrip().split(' ')
    N = int(input())
    if N%10==7:
        print('Yes')
        exit()

    N = int(N/10)
    if N%10==7:
        print('Yes')
        exit()

    N = int(N/10)
    if N%10==7:
        print('Yes')
        exit()

    print('No')


Measured memory_bytes: 9172
#include <iostream>
#include <algorithm>
#include <queue>
#include <sstream>

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

template<class T> T getAs(){ T v; std::cin >> v; return v; }
inline int getInt(){ return getAs<int>(); }

using namespace std;

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

int mod;

template<class T>
class BIT{
  vector<T> data;
  size_t n;
public:
  BIT(size_t nn) : data(vector<int>(nn + 1)), n(nn) {}

  T sum(int i){
    T s = (T)0;
    i++;
    while(i > 0){
      s += data[i]; s %= mod;
      i -= i & -i;
    }
    return s;
  }

  void add(int i, T x){
    i++;
    while(i <= (int)n){
      data[i] += x; data[i] %= mod;
      i += i & -i;
    }
  }
};

int main(){
  while(true){
    int a = getInt();
    int b = getInt();
    int p = getInt(); mod = p;

    if(a + b + p == 0) break;

    vector<string> v(b - a + 1);
    vector<int> num(b - a + 1);
    BIT<int> bit(b - a + 2);

    REP(i, b - a + 1) v[i] = to_str(a + i);
    sort(v.begin(), v.end());
    REP(i, b - a + 1) num[i] = atoi(v[i].c_str());

    bit.add(0, 1);
    REP(i, b - a + 1){
      bit.add(num[i] - a + 1, bit.sum(num[i] - a));
    }

    cout << (p + bit.sum(b - a + 1) - 1) % p << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

ll t(ll h, ll w){
	ll ans = LINF;
	for(ll i = 1; i < h; i++) {
		ll a = i*w;
		ll b = (h - i)*(w/2);
		ll c = (h - i)*(w - w/2);
		ll smax = max(a,max(b,c));
		ll smin = min(a,min(b,c));
		ans = min(ans,smax - smin);
	}
	return ans;
}
ll to(ll h, ll w){
	ll ans = LINF;
	for(ll i = 1; i < w; i++) {
		ll a = i*h;
		ll b = (w - i)*(h/2);
		ll c = (w - i)*(h - h/2);
		ll smax = max(a,max(b,c));
		ll smin = min(a,min(b,c));
		ans = min(ans,smax - smin);
	}
	return ans;
}

ll ni(ll h,ll w){
	ll ans = LINF;
	for(ll i = 1; i < h; i++) {
		ll a = i*w;
		ll b = ((h - i)/2)*w;
		ll c = (h- i - (h - i)/2)*w;
		ll smax = max(a,max(b,c));
		ll smin = min(a,min(b,c));
		ans = min(ans,smax - smin);
	}
	return ans;
}

ll H(ll h,ll w){
	ll ans = LINF;
	for(ll i = 1; i < w; i++) {
		ll a = i*h;
		ll b = (w - i)/2*h;
		ll c = (w- i - (w - i)/2)*h;
		ll smax = max(a,max(b,c));
		ll smin = min(a,min(b,c));

		ans = min(ans,smax - smin);
	}
	return ans;
}





int main(){
	ll h,w;
	cin >> h >> w;
	ll ans = LINF;
	if (h > 2){
		ans = min(ans,ni(h,w));
		// cout << "ni" << ni(h,w) << endl;
	}
	if (w > 2){
		ans = min(ans,H(h,w));
		// cout << "H" << H(h,w) << endl;
	}
	ans = min(ans,t(h,w));
	// cout << "t" << t(h,w) << endl;
	ans = min(ans,to(h,w));
	// cout << "to" << to(h,w) << endl;
	cout << ans << endl;
	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    set<int> st;
    map<int, bool> mp;
    int n;
    cin >> n;
    while(n--) {
        int a;
        cin >> a;
        if(mp[a]) mp[a] = false;
        else mp[a] = true;
        st.insert(a);

    }

    int c = 0;
    for(auto it = st.begin(); it != st.end(); ++it) {
        if(mp[*it]) ++c;
    }
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 9600
#include<stdio.h>
int a[200010];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        printf("%d\n",a[i]);
    }
}


Measured memory_bytes: 2504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
ll n;
cin>>n;
map<ll,ll>mp;
for(ll i=0;i<n;i++){
    ll t;
    cin >> t;
    t*=-1;
    mp[t]++;
}
ll ans = 0;
for (auto itr:mp){
    if(itr.second>=4){
        ans = (itr.first) * (itr.first);
        cout << ans << endl;
        return 0;
    } else if (itr.second>=2){
        for (auto itr2:mp){
            if(itr.first>=itr2.first)continue;
            if(itr2.second>=2){
                ans = (itr.first) * (itr2.first);
                cout <<ans<<endl;
                return 0;
            }
        }
    }
}
cout<<0<<endl;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<bool> flag(10,true);
  int D;
  for(int i=0;i<K;i++){
    cin >> D;
    flag.at(D)=false;
  }
  string S;
  int j;
  for(int i=N;;i++){
    S=to_string(i);
    for(j=0;j<S.size();j++){
      if(!flag.at(S.at(j)-'0')){
        break;
      }
    }
    if(j==S.size()){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std; 
int main() {
  int n; cin >> n; 
  int ans = 0; 
  int mn = 1e6;
  for(int i = 0; i < n; i++) {
   int x; cin >> x; 
    mn = min(mn, x);
    if (x <= mn) {
     ans++; 
    }
  }
  cout << ans << endl;
 return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 1000000007
#define ll long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define ull unsigned long long int
using namespace std;

int main(){
    // fast i/o
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

//    int t;
//    cin>>t;
//    while(t--){

//    }

    int x;
    cin>>x;
    ll a=x/500;
    int b=x%500;
    ll total = a*1000 + (b/5)*5;
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {
      var n = readLine.split(" ").map(_.toInt)
      while( n(0) != 0 || n(1) != 0) {
        (1 to n(0)).foreach(s=>println("#"*n(1)))
        println("")
        n = readLine.split(" ").map(_.toInt)
      }
  }
}

Measured memory_bytes: 45016
#include<bits/stdc++.h>
#define mod (long)(1e9 + 7)
using namespace std;

long tree[8 * 100001];

void update(int start, int end, int node, int pos, long val) {
	if(start == end) {
		tree[node] = val;
		return;
	}
	int mid = (start + end) / 2;
	if(pos <= mid) {
		update(start, mid, 2 * node, pos, val);
	}
	else update(mid + 1, end, 2 * node + 1, pos, val);
	tree[node] = max(tree[2 * node], tree[2 * node + 1]);
} 

long query(int start, int end, int l, int r, int node) {
	// cout<<start << " " << end << endl;
	if(start > r || end < l) {
		return -1;
	}
	if(l <= start && end <= r) {
		// cout <<"FOr" << start <<" " << end << ":" << tree[node];
		return tree[node];
	}
	int mid = (start + end) / 2;
	long left = query(start, mid, l, r, 2 * node); 
	long right = query(mid + 1, end, l, r, 2 * node + 1);
	return max(left, right);
} 

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	long h[n], a[n];
	for(int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	update(0, n, 1, h[0], a[0]);
	for(int i = 1; i < n; ++i) {
		// cout<<tree[1000];
		long mx = query(0, n, 0, h[i] - 1, 1);
		// if(mx == -1) cout << i <<" ou";
		// break;
		// cout << mx + a[i] << endl;
		update(0, n, 1, h[i], a[i] + mx);
	}
	cout << tree[1];

	return 0;
}

Measured memory_bytes: 10860
#include <algorithm>
#include <cmath>
#include <ctime>
#include <iostream>
#include <cstdlib>
#include <string>
#define sbc __builtin_popcount
#define pb push_back
#define em emplace
#define emb emplace_back
int mod = 1e9+7;
using namespace std;
    void solve() {
                string str,b="",e="";
                cin>>str;
                char ch;
                int q,r=0,t,f;
                cin>>q;
                while(q--) {
                        cin>>t;
                        if(t-1) {
                                cin>>f>>ch;
                                if(f-1) {
                                        if(r) {
                                                b=ch+b;
                                        } else {
                                                e+=ch;
                                        }
                                } else {
                                        if(r) {
                                                e+=ch;
                                        } else {
                                                b=ch+b;
                                        }
                                }
                        } else {
                                r=1-r;
                        }
                }
                str=b+str+e;
                if(r) {reverse(str.begin(),str.end());}
                cout<<str<<'\n';
    }

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);



   // int t;
   // cin>>t;
   // while(t--)
          solve();


    return 0;
}

Measured memory_bytes: 1316
#include <iostream>
using namespace std;
int main(void){

    int W,H,x,y,r;
    cin>>W;
    cin>>H;
    cin>>x;
    cin>>y;
    cin>>r;
    
    if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H){
        cout << "Yes" ;
   }
   else {
       cout << "No" ;
   }
       
   cout << endl;

}


Measured memory_bytes: 3108
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long

int main(){
  ll n,k;
  scanf("%lld%lld",&n,&k);
  ll ans = n%k;
  if(ans > k-ans) ans=k-ans;

  printf("%lld\n",ans);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


int main() {
    unsigned long long a, b, x;
    unsigned long long answ = 0;

    cin >> a >> b >> x;
    a+=x;
    b+=x;

    answ = (b/x+1)-((a-1)/x+1);

    cout << answ << endl;

}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N;
	scanf("%d",&N);
	if(N<=104)printf("0\n");
	else if(N<=134)printf("1\n");
	else if(N<=164)printf("2\n");
	else if(N<=188)printf("3\n");
	else if(N<=194)printf("4\n");
	else printf("5\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

#define MAX 30

int N,C,dp[MAX][1<<16];
int a[MAX],b[MAX+1];

int solve(int cur,int p){
  if(cur == N) return 0;
  if(dp[cur][p] >= 0) return dp[cur][p];
  int res = 0;
  for(int i = 0 ; i < C ; i++){
    int S = (a[cur] | p) & b[i];
    int next = ((a[cur] | p) ^ b[i]) & (a[cur] | p);
    res = max(res,solve(cur+1,next) + __builtin_popcount(S));
  }
  return dp[cur][p] = res;
}

int main(){
  int in,S;
  while(cin >> N >> C,(N | C)){
    memset(dp,-1,sizeof(dp));
    for(int i = 0 ; i < N ; i++){
      S = 0;
      for(int j = 0 ; j < 16 ; j++){
        cin >> in;
        if(in){
          S |= 1<<j;
        }
      }
      a[i] = S;
    }
    for(int i = 0 ; i < C ; i++){
      S = 0;
      for(int j = 0 ; j < 16 ; j++){
        cin >> in;
        if(in){
          S |= 1<<j;
        }
      }
      b[i] = S;
    }
    cout << solve(0,0) << endl;
  }

  return 0;
}

Measured memory_bytes: 8856
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
    int s;
    cin >> s;

    int x = s / 3600;
    int xx = s % 3600;
    int y = xx / 60 ;
    int yy = xx % 60;
    
    cout << x << ":" << y << ":" << yy << endl;
}

int main()
{
    std::cout << std::fixed << std::setprecision(15);
    Main();
}


Measured memory_bytes: 3132
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
char in[110];
int v[110];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",v+i);
	}
	std::sort(v,v+a);
	double ret=(v[0]+v[1])/2.0;
	for(int i=2;i<a;i++){
		ret=(ret+v[i])/2.0;
	}
	printf("%.12f\n",ret);
}

Measured memory_bytes: 128
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: usize = sc.read();
    let b: usize = sc.read();

    let segments = (n + b - 1) / b;
    if a + b > n + 1 || segments > a {
        println!("-1");
        return;
    }

    let mut ans: Vec<_> = (1..(n + 1)).collect();
    for segment in 0..segments {
        ans[(segment * b)..cmp::min(n, segment * b + b)].reverse();
    }

    let mut a = a - segments;
    for segment in (0..segments).rev() {
        let from = segment * b;
        let to = cmp::min(n, from + b);
        let reverse = cmp::min(to - from, a + 1);
        let from = to - reverse;
        ans[from..to].reverse();
        a -= to - from - 1;
        if a == 0 {
            break;
        }
    }

    for i in 0..n {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!();
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10364
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, long long K){
    if(N %K == 0) 
        cout << 0 << endl;
    else
    {
        cout << 1 << endl;
    }
    
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,x;
  cin>>N>>x;
  vector<int>a(N);
  for(int &i:a)cin>>i;
  sort(a.begin(),a.end());
  int ans=0;
  for(int i=0;i<N;i++){
    if(x>=a.at(i)){
      ans++;
      x-=a.at(i);
    }
  }
  if(ans==N&&x>0)ans--;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int N,Y,x,y,z,r;

    scanf("%d %d",&N,&Y);

    r = 0;

    for(x=0;x<=N;x++){
        for(y=0;y<=N-x;y++){
            z = N - x - y;
            if((z >= 0)&&(10000*x + 5000*y + 1000*z == Y)){
                r = 1;
                break;
            }
        }
        if(r == 1){
            printf("%d %d %d\n",x,y,z);
            break;
        }
    }

    if(r!=1) printf("%d %d %d\n",-1,-1,-1);

    return 0;
}

Measured memory_bytes: 128
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('');
   let count = 0;
   for(let i=0; i<4; i++){
     if(xs[i]==2){
       count += 1;
     }else{
       count += 0;
     }
   }
   console.log(count);

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

Measured memory_bytes: 7372
#include <cmath>
#include <iostream>
using namespace std;
typedef unsigned long long ll;
#define M 1000000007

ll po(ll a, ll b){
	ll ans=1;
	a=a%M;
	while(b>0){
		if(b%2) ans=ans*a%M;
		a=a*a%M;
		b/=2;
	}
	return ans;
}

int main() {
	ll a,b;
	cin>>a>>b;
	cout<<po(a,b)<<endl;
	return 0;
}


Measured memory_bytes: 3068
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        char[] S = sc.next().toCharArray();

        int count = 0;
        boolean isA = false;
        boolean isB = false;
        for (int i = 0; i < N-2; i++) {
            if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

func parseProblem() scorer {
	d := scanInt(sc)
	v := 26
	cs := make([]int, v)
	for i := 0; i < v; i++ {
		cs[i] = scanInt(sc)
	}
	ss := make([][]int, d)
	for i := range loop0(d) {
		ss[i] = make([]int, v)
		for j := range loop0(v) {
			ss[i][j] = scanInt(sc)
		}
	}
	return scorer{
		d: d, v: v,
		cs: cs, ss: ss,
	}
}

func loop0(n int) chan int {
	return loop(0, n-1, 1)
}

func loop1(n int) chan int {
	return loop(1, n, 1)
}

func loop(s, e, d int) chan int {
	ch := make(chan int)
	go func() {
		for i := s; i <= e; i += d {
			ch <- i
		}
		close(ch)
	}()
	return ch
}

type scorer struct {
	// 0-indexed
	d, v int
	cs   []int
	ss   [][]int // [<d][<v]
}

func (scr scorer) greedyGen() []int {
	result := make([]int, scr.d)
	lasts := make([]int, scr.v)
	for i := range loop0(scr.d) {
		max, maxT := math.MinInt32, 0
		for j := range loop0(scr.v) {
			v := scr.score(i, j, lasts)
			if max < v {
				max = v
				maxT = j
			}
		}
		lasts[maxT] = i + 1
		result[i] = maxT + 1
	}
	return result
}
func (scr scorer) score(d, v int, lasts []int) int {
	s := 0
	for i := range lasts {
		s -= (d + 1 - lasts[i]) * scr.cs[i]
	}
	s += (d + 1 - lasts[v]) * scr.cs[v]
	s += scr.ss[d][v]
	return s
}
func (scr scorer) receiveInput(sc *bufio.Scanner) []int {
	satisfaction := 0
	lasts := make([]int, scr.v)
	results := make([]int, scr.d)
	for day := range loop0(scr.d) {
		tipe := scanInt(sc) - 1
		satisfaction += scr.ss[day][tipe]
		lasts[tipe] = day + 1
		for cType := range loop0(scr.v) {
			satisfaction -= scr.cs[cType] * (day + 1 - lasts[cType])
		}
		results[day] = satisfaction
	}
	return results
}

func resolve(scr scorer) {
	for _, v := range scr.greedyGen() {
		fmt.Println(v)
	}
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, lint> pi;

int n;
int l[132000], r[132000];
int lc[132000], rc[132000];

vector<pi> dp[132000];

bool solve(int p, lint k){
	if(!l[p]){
		dp[p].push_back(pi(0, 0));
		return 1;
	}
	if(!solve(l[p], k) || !solve(r[p], k)) return 0;
	if(dp[l[p]].size() > dp[r[p]].size()){
		swap(l[p], r[p]);
		swap(lc[p], rc[p]);
	}
	vector<pi> tmp;
	for(auto &i : dp[l[p]]){
		int s = 0, e = (int)dp[r[p]].size() - 1;
		while(s != e){
			int m = (s+e+1)/2;
			if(dp[r[p]][m].first + i.second + lc[p] + rc[p] <= k){
				s = m;
			}
			else e = m-1;
		}
		if(dp[r[p]][s].first + i.second + lc[p] + rc[p] <= k){
			tmp.push_back(pi(i.first + lc[p], dp[r[p]][s].second + rc[p]));
		}
		s = 0, e = (int)dp[r[p]].size();
		while(s != e){
			int m = (s+e)/2;
			if(dp[r[p]][m].second + i.first + lc[p] + rc[p] <= k){
				e = m;
			}
			else s = m+1;
		}
		if(s != dp[r[p]].size()){
			tmp.push_back(pi(dp[r[p]][s].first + rc[p], lc[p] + i.second));
		}
	}
	sort(tmp.begin(), tmp.end());
	for(auto &i : tmp){
		if(!dp[p].empty() && dp[p].back().second <= i.second){
			continue;
		}
		dp[p].push_back(i);
	}
	return dp[p].size() > 0;
}

bool trial(lint x){
	for(int i=1; i<=n; i++){
		dp[i].clear();
	}
	return solve(1, x);
}

int main(){
	scanf("%d",&n);
	for(int i=2; i<=n; i++){
		int p, v;
		scanf("%d %d",&p,&v);
		if(l[p]){
			r[p] = i;
			rc[p] = v;
		}
		else{
			l[p] = i;
			lc[p] = v;
		}
	}
	lint s = 0, e = 1e11;
	while(s != e){
		lint m = (s+e)/2;
		if(trial(m)) e = m;
		else s = m+1;
	}
	cout << s << endl;
}


Measured memory_bytes: 29188
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

const int N = 110;
const int INF = 1e9;
int G[N][N];

int main(){
	int n;
	while (cin >> n, n){
		vector<int> v(n);
		rep(i, n) cin >> v[i];
		rep(i, N) v.push_back(v[i]);
		rep(i, N) rep(j, N) if (i < j) G[i][j] = INF;
		int t;
		cin >> t;
		vector<int> m(N, 23);
		rep(i, t){
			int d, x;
			cin >> d >> x;
			m[d - 1] = min(m[d - 1], x);
		}
		rep(i, N){
			int x = i, j = 0;
			while (x < N && v[j++] <= m[x++]);
			G[i][x-1] = 1;
		}
		rep(i, N) rep(j, N) rep(k, N) G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
		cout << G[0][N - 1] - 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1264
n=gets.to_i
cs='R'+gets.chomp+'W'
s,i1,i2=0,1,n
loop {
  i1+=1 while cs[i1]=='R'
  i2-=1 while cs[i2]=='W'
  break if i1>i2
  cs[i1]='R'
  cs[i2]='W'
  s+=1
}
puts s

Measured memory_bytes: 15144
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	string s; cin >> s;
	rep(i, 0, s.size()) {
		if (i < s.size() - 1 && s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		else if (i < s.size() - 2 && s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
from collections import deque
h,w=map(int,input().split())
S=[input()for _ in range(h)]
inf=float('inf')
ans=0
for i in range(h):
      for j in range(w):
            if S[i][j]!='#':
                  dp=[[inf for _ in range(w)]for _ in range(h)]
                  dp[i][j]=0
                  que=deque([(i,j)])
                  while que:
                        si,sj=que.popleft()
                        for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
                              if 0<=ni<h and 0<=nj<w and S[ni][nj]!='#':
                                    if dp[ni][nj]>dp[si][sj]+1:
                                          dp[ni][nj]=dp[si][sj]+1
                                          ans=max(ans,dp[si][sj]+1)
                                          que.append((ni,nj))
print(ans)                                  
                 

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll mod = 1e9+7;
const int max_h = 110;
const int max_w = 8;

// dp[i][j] = 高さiの直後にj番目の線にいるときのあみだくじの総数
ll dp[max_h][max_w] = {};

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

  int h, w, k;
  cin >> h >> w >> k;
  dp[0][0] = 1;
  REP(i,h+1) {
    rep(j,w) {

      auto func = [&](int n, bool ok) {
        ll res = 0;
        for(int bit = 0; bit < (1<<(w-1)); bit++) {
          bitset<max_w-1> b(bit);
          if(ok) {
            if(!b[n]) continue;
          }
          else {
            if(b[n]) continue;
            if(n != 0 && b[n-1]) continue;
          }
          bool ok = true;
          REP(l,w-1) {
            if(b[l] && b[l-1]) ok = false;
          }
          res += ok;
        }
        return res;
      };

      if(j != 0) dp[i][j] += dp[i-1][j-1] * func(j-1, true);
      if(j != w-1) dp[i][j] += dp[i-1][j+1] * func(j, true);
      if(w >= 3) dp[i][j] += dp[i-1][j] * func(j, false);
      else dp[i][j] += dp[i-1][j];
      dp[i][j] %= mod;
    }
  }
  cout << dp[h][k-1] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int[] ans = new int[1000];
		String[] str = new String[1000];
		int i = 0;
		int k = 0;
		int count = 0;
		int max = 0;
		while(stdIn.hasNext()){
			str[i] = stdIn.next();
			for(int j=0;j<i;j++){
				if(str[i].equals(str[j])){
					ans[j]++;
					if(max<ans[j]){
						max = ans[j];
					}
					break;
				}
			}
			if(count<str[i].length()){
				count = str[i].length();
				k = i;
			}
			i++;
			
		}
		
		for(int x=0;x<1000;x++){
			if(max==ans[x]){
				System.out.print(str[x]+" ");
			}
		}
		System.out.println(str[k]);
	}
}

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

using namespace std;
int main()
{
    int n,c=0;
    cin>>n;
    string s,s1,s2;
    cin>>s;
    for(int i=0;i<n/2;i++){
        s1.push_back(s[i]);
    }
    for(int i=n/2;i<n;i++){
        s2.push_back(s[i]);
    }
    if(s1!=s2||n==1){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); i++)

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char get_char() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int get_int() {
  int A = 0;
  if (ci - cn + 16 > cm)
    while ((ct = get_char()) >= '0') A = A * 10 + ct - '0';
  else
    while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
  return A;
}

int cnt[1001][1001];

int main() {
  int N = get_int(), K = get_int();
  rep(i, N) {
    int x = get_int(), y = get_int(), b;
    char c = get_char();
    get_char();
    if(c=='W')y += K;
    b = x / K % 2 == y / K % 2 ? 1 : -1;
    if(b > 0) cnt[0][0]++;
    int nx = x % K + 1, ny = y % K + 1;
    cnt[nx][0] -= b;
    cnt[0][ny] -= b;
    cnt[nx][ny] += b * 2;
  }
  rep(i, K + 1)rep(j, K)cnt[i][j + 1] += cnt[i][j];
  rep(j, K + 1)rep(i, K)cnt[i + 1][j] += cnt[i][j];
  int ans = 0;
  rep(i, K)rep(j, K)ans = std::max(ans, std::max(cnt[i][j], N - cnt[i][j]));
  printf("%d", ans);
}


Measured memory_bytes: 5640
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline 


a,b,c,k = list(map(int,read().split()))

ans = 0
if a >= k:
    print(k)
    exit()

ans = a
k -= a
if b >= k:
    print(ans)
    exit()
else:
    print(ans-(k-b))










Measured memory_bytes: 9172
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[][] A = new int[3][N + 1];
		for (int i = 1; i <= N; i++)
			A[1][i] = sc.nextInt();
		for (int i = 1; i <= N; i++)
			A[2][i] = sc.nextInt();

		int max = 0;
		for (int i = 1; i <= N; i++) {
			int s = 0;
			for (int j = 1; j <= i; j++)
				s += A[1][j];
			for (int k = i; k <= N; k++)
				s += A[2][k];
			max = Math.max(max, s);
		}

		System.out.println(max);
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21332
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
  ans += min(A[i]+A[i+1], B[i])
  A[i+1] = max(min(A[i+1], A[i]+A[i+1]-B[i]), 0)
  
print(ans)

Measured memory_bytes: 19116
program ordinary_number
  implicit none
  integer :: n, p(20), m, i
  p = 0
  m = 0
  read(*,*) n
  read(*,*) p(1:n)
  do i = 2, n-1
    if (p(i).eq.sum(p(i-1:i+1))-maxval(p(i-1:i+1))-minval(p(i-1:i+1))) m = m+1
  end do
  write(*,'(i0)') m
  stop
end program ordinary_number

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);

    ll ans = 0, inc = 0;
    rep(i,n) {
        cin >> a[i] >> b[i];
    }
    for(int i = n-1; i >= 0; i--) {
        a[i] += inc;
        ans += (a[i]%b[i]) ? b[i]-(a[i]%b[i]) : 0;
        inc += (a[i]%b[i]) ? b[i]-(a[i]%b[i]) : 0;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
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
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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 = 1000000007


n, k = LI()
D = set(range(10)) - set(LI())
for i in range(n, 100000):
    if set([int(j) for j in str(i)]) <= D:
        print(i)
        break







Measured memory_bytes: 41964