akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    static int binarySearch(int x, int[] arr) {
        int left = 0;
        int right = arr.length;
        while (left < right) {
            int mid = (left + right) / 2;
            if (arr[mid] == x) {
                return arr[mid];
            } else if (x < arr[mid]) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return Integer.MIN_VALUE;
    }

    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            int n = Integer.parseInt(in.readLine());
            if (n <= 0) {
                System.out.println(0);
                System.exit(0);
            }

            String[] line = in.readLine().split(" ");
            int[] S = new int[n];
            for (int i = 0; i < n; i++) {
                S[i] = Integer.parseInt(line[i]);
            }

            int q = Integer.parseInt(in.readLine());
            line = in.readLine().split(" ");
            int C = 0;
            for (int i = 0; i < q; i++) {
                int t = Integer.parseInt(line[i]);
                int ret = binarySearch(t, S);
                if (ret != Integer.MIN_VALUE) C++;
            }

            System.out.println(C);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


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

int main()
{
	const int N = 10;
	int A[N];
	const int M = 3;
	int top[M] = {0};

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

	for(int i = 0; i < N; i++)
	{
		if(top[0] < A[i])
		{
			top[2] = top[1];
			top[1] = top[0];
			top[0] = A[i];
		}
		else if(top[1]<A[i])
		{
			top[2] = top[1];
			top[1] = A[i];
		}
		else if(top[2] < A[i])
			top[2] = A[i];
	}


	for(int i = 0; i < M; i++)
		cout <<top[i] << endl;

	return 0;
}

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

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(m);

    rep(i, n) {
        int k;
        cin >> k;
        rep(j, k) {
            int tmp;
            cin >> tmp;
            a.at(tmp-1)++;
        }
    }
    int ans = 0;
    rep(i, a.size()) {
        if (a.at(i) == n)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=10000;
const ll INF=1000000010;
const int MAX=100001;
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
int main(){
	ll n;
	cin>>n;n--;
	int ans=0;
	while(n>=1){
		n/=3;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3100
import java.util.Scanner;
class KnapsackProblem {
    int w;
    KnapsackProblem (int w) {
	this.w = w;
    }

    int knapsack (int[] value, int[] weight) {
	int n = value.length;
	int[] dp = new int[w + 1];
	for (int i = 0; i < n; i++) {
	    for (int j = weight[i]; j <= w; j++) {
		dp[j] = Math.max(dp[j], dp[j - weight[i]] + value[i]);
	    }
	}
	return dp[w];
    }
}

public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	String[] input = scan.nextLine().split(" ");
	int n = Integer.parseInt(input[0]);
	int w = Integer.parseInt(input[1]);
	int[] value = new int[n];
	int[] weight = new int[n];
	for (int i = 0; i < n; i++) {
	    input = scan.nextLine().split(" ");
	    value[i] = Integer.parseInt(input[0]);
	    weight[i] = Integer.parseInt(input[1]);
	}
	KnapsackProblem kp = new KnapsackProblem(w);
	System.out.println(kp.knapsack(value, weight));
    }
}

Measured memory_bytes: 26880
c = [0] * 1001
(2..50).each do |i|
  (1..1000/i).each do |j|
    k = j
    num = 0
    i.times{ num += k; k += 1}
    break if num > 1000
    c[num] += 1
  end
end

while n = gets.to_i
  break if n == 0
  p c[n]
end

Measured memory_bytes: 8672
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    A.pb(0);
  }

  int ans = 0;
  rep(i, N) {
    ans += A[i] / 2;
    A[i] %= 2;
    if (A[i]) {
      if (A[i + 1] > 0) {
        ans++;
        A[i + 1]--;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
n, m = (int(i) for i in input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]
a.sort()
bc.sort(key=lambda x:x[1], reverse=True)

# print(a)
# print(bc)

index = 0
break_flag = False

for i in range(m):
    for j in range(bc[i][0]):
        if (index < n):
            if(a[index] < bc[i][1]):
                a[index] = bc[i][1]
                index += 1
                # print(a)
            else:
                break_flag = True
                break
        else:
            break_flag = True
            break
    if  break_flag:
        break
print(sum(a))

Measured memory_bytes: 33108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define MOD2 1000000009
#define endl "\n"
#define pii pair <int, int>
#define pll pair <ll, ll>
#define F first
#define S second

int div(int n) {
    int cnt = 0;
    for(int i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            if(n / i == i)
                cnt++;
            else
                cnt += 2;
        }
        
    }
    return cnt;
}

int main()
{   
    IOS;
        #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
        #endif

    
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++) {

        ans += (n / i);
    }

    cout << ans - div(n)<< endl;
    

return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define per(a, b, c) for(int a = (b); a >= (c); -- a)
using namespace std;
template <class T> void rd(T &x){
  x = 0; int f = 1; char ch = getchar();
  while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
}

const int maxn = 2e3 + 5;
int col[maxn][maxn], up[maxn];
int n, m;
char s[maxn];
int q[maxn], top;

void sol(){
  int ans = max(n, m);
  rep(i, 1, m) up[i] = 1;
  rep(i, 2, n){
	rep(j, 2, m){
	  if(col[i - 1][j - 1] ^ col[i][j - 1] ^ col[i - 1][j] ^ col[i][j]) up[j - 1] = 1;
	  else up[j - 1] ++;
	}
	top = 0;
	rep(j, 1, m - 1){
	  while(top > 0 && up[q[top]] > up[j]){
		ans = max(ans, (j - q[top - 1]) * up[q[top]]);
		top --;
	  }
	  q[++ top] = j;
	}
	while(top > 0){
	  ans = max(ans, (m - q[top - 1]) * up[q[top]]);
	  top --;
	}
  }
  printf("%d\n", ans);
}

int main(){
  rd(n), rd(m);
  rep(i, 1, n){
	scanf("%s", s + 1);
	rep(j, 1, m) col[i][j] = s[j] == '#';
  }
  sol();
  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
  size_t mSize;
  vector<vector<vector<double_t>>> mDp;
  void rec(int x, int y, int z);
};

Tmp::Tmp(int N)
  : mSize(N), mDp(N+1, vector<vector<double_t>>(N+1, vector<double_t>(N+1, -2)))
{}

void Tmp::rec(int x, int y, int z)
{
  if (mDp[x][y][z] > -1) {
    return;
  }
  if (!x && !y && !z) {
    mDp[0][0][0] = 0;
    return;
  }

  auto tmp = 0.0;
  if (x > 0) {
    rec(x-1, y, z);
    tmp += mDp[x-1][y][z] * x;
  }
  if (y > 0) {
    rec(x+1, y-1, z);
    tmp += mDp[x+1][y-1][z] * y;
  }
  if (z > 0) {
    rec(x, y+1, z-1);
    tmp += mDp[x][y+1][z-1] * z;
  }
  tmp += mSize;
  tmp /= (x + y + z);
  mDp[x][y][z] = tmp;
  return;
}

void solve(void)
{
  int N; cin >> N;
  map<int, int> m{};
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    ++m[a];
  }

  Tmp t(N);
  t.rec(m[1], m[2], m[3]);
  auto ans = t.mDp[m[1]][m[2]][m[3]];
  cout << std::setprecision(20)
    << std::setfill('0')
    << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 219008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

void solve(){
    int n, k;
    cin >> n >> k;
    vector<int> f(n);
    for(int i = 0; i < n; i++) cin >> f[i];

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

    int c = 0;
    for(int i = 0; i < k; i++){
        c += f[i];
    }

    cout << c << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>
#include<queue>
#include<set>


#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

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

	return true;
}



bool comp(const pair<long long int, vector<int>> a, const pair<long long int, vector<int>> b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}
	else {
		return a.second < b.second;
	}

}






int main()
{

	long long int n, m;
	cin >> n >> m;

	vector<long long int> a(n);
	for (auto& i : a)cin >> i;
	sort(a.begin(), a.end());

	vector<long long int> ruiseki(n + 1);
	ruiseki[0] = 0;
	for (int i = 1; i < ruiseki.size(); i++) {
		ruiseki[i] = ruiseki[i - 1] + a[i - 1];
	}

	long long int ans = 0;
	
	
	long long int L = 0, R = a[n-1] + a[n-1] + 1; //全握手がL以上である。また、全握手がR未満である。

	
	const auto& cnt = [&a](long long int mid) -> long long int {
		long long int ret = 0;

		for (const auto& i : a) {

			long long int wk = lower_bound(a.begin(), a.end(), mid - i) - a.begin();
			ret += a.size() - wk;

		}

		return ret;
	};

	const auto& sum = [&a, &ruiseki, &m](long long int border) -> long long int {

		long long int ret = 0;
		long long int cnt = 0;
		for (const auto& i : a) {
			
			long long int wk = lower_bound(a.begin(), a.end(), border - i) - a.begin();
			ret += ruiseki[ruiseki.size() - 1] - ruiseki[wk];
			ret += (a.size() - wk) * i;
			cnt += a.size() - wk;
		}

		//足しすぎた分引く。
		ret -= (cnt - m) * border;

		return ret;
	};
	
	//L <= border < R となるborderが一意に定まるまでループする。
	while (L + 1 < R) {
		long long int mid = (L + R) / 2;

		//mid以上の要素を全て取り出す。使う要素はvector aとmidの二つ。
		long long int count = cnt(mid);

		
		//countがm以上ならば、そのmidは条件を満たす。そのため、下限を上げることができる。
		if (count >= m) {
			L = mid;
		}
		//countがm未満ならば、そのmidは条件満たさない。下限は変えることができず、上限を下げる。
		else {
			R = mid;
		}
	}
	

	ans = sum(L);


	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,k;
  cin >> n >> k;

  ll a[n],f[n];
  for(ll i=0;i<n;i++)cin >> a[i];
  for(ll i=0;i<n;i++)cin >> f[i];

  sort(a,a+n);
  sort(f,f+n);
  reverse(f,f+n);

  ll m=0;
  for(ll i=0;i<n;i++)m=max(m,a[i]*f[i]);

  ll r=m,l=-1;
  ll h;

  while(abs(r-l)>1){
    h=(r+l)/2;
    ll s=0;
    for(ll i=0;i<n;i++){
      ll b;
      if(h%f[i]==0) b=max((ll) 0,a[i]-h/f[i]);
      else b=max((ll) 0,a[i]-h/f[i]);
      s+=b;
    }
    if(s<=k){
      r=h;
    }
    else l=h;
  }

  cout << r << endl;

}

Measured memory_bytes: 6640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
typedef long long ll;
using namespace std;
const int inf=0x3f3f3f3f;
const int mod=998244353;
const int maxn=1e6+5;

const ll UP=3234566667;

ll dv[20];

vector<ll>vec;
void dfs(ll num,int dig,int fir)
{
    if(fir<0)return;
    if(fir>9)return;
    if(fir)vec.push_back(num);
    if(num>UP||dig>10)return;
    dfs(num+dv[dig+1]*fir,dig+1,fir);
    dfs(num+dv[dig+1]*(fir-1),dig+1,fir-1);
    dfs(num+dv[dig+1]*(fir+1),dig+1,fir+1);
}

int main()
{
    dv[1]=1;for(int i=2;i<=12;i++)dv[i]=dv[i-1]*10;
    for(int i=0;i<=9;i++)dfs(i,1,i);
    sort(vec.begin(),vec.end());
    int n;
    scanf("%d",&n);
    printf("%lld\n",vec[n-1]);
}

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

#define x first
#define y second
#define all(a) (a).begin(), (a).end()

#define sz(a) (int) (a).size()

#define int long long

int c[200000][26];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = sz(s);
    c[n-1][s[n-1]-'a']++;
    for (int i=n-2; i>-1; i--) {
        for (int j=0; j<26; j++) {
            c[i][j] = c[i+1][j];
        }
        c[i][s[i]-'a']++;
    }
    int ans = 0;
    for (int i=0; i<n-1; i++) {
        ans += n-i-1-c[i+1][s[i]-'a'];
    }
    cout << ans+1;
    return 0;
}


Measured memory_bytes: 41236
n,k=map(int,input().split())
r,s,p=map(int,input().split())
tl=list(input())

win={"r":"p","s":"r","p":"s"}
score={"r":r,"s":s,"p":p}
total=0
already=[]
for i in range(k):
    win_hand=win[tl[i]]
    already.append(win_hand)
    total+=score[win_hand]
temp=["r","s","p"]
for j in range(k,n):
    temp=["r","s","p"]
    win_hand=win[tl[j]]
    #print(j-k)
    if already[j-k]==win_hand:
        temp.remove(win_hand)
        if j+k <= n-1:
            keep=win[tl[j+k]]
            if not keep in temp:
                already.append(temp[0])
            else:
                temp.remove(keep)
                already.append(temp[0])
        else:
            already.append(temp[0])
        pass
    else:
        already.append(win_hand)
        total+=score[win_hand]
print(total)








Measured memory_bytes: 4796
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
#define cint(...) ll __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__);

int main() {
	cint(
		a, b, c
	);
	cout << ((a == b) ? c : (a == c) ? b : a) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int a,b,c;cin>>a>>b>>c;
  string ans;
  if (a==b&&b!=c) ans="Yes";
  else if (b==c&&c!=a) ans="Yes";
  else if (c==a&&a!=b) ans="Yes";
  else ans="No";
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
use std::collections::HashMap;

fn main() {
    proconio::input! {
        n: usize,
        mut sc: [(String, u64); n],
    }

    let mut rev = Vec::new();
    let mut cost = u64::max_value();
    let sc: Vec<_> = sc
        .iter()
        .filter(|e| {
            let r = e.0.chars().rev().collect::<String>();
            let f = e.0 != r;
            if f {
                rev.push(r);
            } else {
                cost = cost.min(e.1);
            }
            f
        })
        .collect();

    let solver = Solver::new(&sc, &rev);
    for e in &sc {
        cost = cost.min(solver.clone().calc(e.0.as_str(), e.1, true));
    }

    if cost < u64::max_value() {
        println!("{}", cost);
    } else {
        println!("-1");
    }
}

#[derive(Clone)]
struct Solver<'a> {
    done: HashMap<(&'a str, bool), u64>,
    n: usize,
    sc: &'a Vec<&'a (String, u64)>,
    rev: &'a Vec<String>,
}

impl<'a> Solver<'a> {
    fn new(sc: &'a Vec<&'a (String, u64)>, rev: &'a Vec<String>) -> Solver<'a> {
        Solver {
            done: HashMap::new(),
            n: sc.len(),
            sc: sc,
            rev: rev,
        }
    }

    fn calc(&mut self, s: &'a str, cost: u64, is_left: bool) -> u64 {
        let mut v = u64::max_value();
        if if let Some(&c) = self.done.get(&(s, is_left)) { cost >= c } else { false } {
            v
        } else {
            self.done.insert((s, is_left), cost);
            for i in 0..self.n {
                let oppo = if is_left { &self.rev[i] } else { &self.sc[i].0 };
                let next = if s.starts_with(oppo) {
                    Some((&s[oppo.len()..], is_left))
                } else if oppo.starts_with(&s) {
                    Some((&oppo[s.len()..], !is_left))
                } else {
                    None
                };
                if let Some((next, is_left)) = next {
                    let cost = cost + self.sc[i].1;
                    v = v.min(if next == next.chars().rev().collect::<String>() {
                        cost
                    } else {
                        self.calc(next, cost, is_left)
                    });
                }
            }
            v
        }
    }
}


Measured memory_bytes: 2228
import sys

input = sys.stdin.readline

def main():
    n = int(input())
    s = input()[::-1]
    ans = 0
    l = 0
    r = 1
    while l < n:
        if s[l:r] in s[r:]:
            r += 1
            if r == n + 1: break
        else:
            l += 1
            ans = max(ans, r - l)
    ans = max(ans, r - l - 1)
    print(ans)

main()


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

int main(){
    int a[5];
    int i,j,k;
    bool flag = false;
    for(i = 0;i < 5;i++){
        cin >> a[i];
    }
    cin >> k;
    for(i = 0;i < 4;i++){
        for(j = i+1; j < 5;j++){
            if((a[j] - a[i]) > k){
                flag = true;
                break;
            }
        }
    }
    if(flag == true)cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define sz 100105
using namespace std;
ll dp[sz][10];
void solve(ll n , ll i){
   if(i<n){
        ll mx;
        for(int j=0;j<3;j++){
            mx = 0;
            for(int k = 0 ; k < 3 ; k++)
                if(k!=j)mx = max(mx,dp[i-1][k]);
            dp[i][j] += mx;
        }
        solve(n,i+1);
   }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i , j , n , k , res = 0;
    cin>>n;
    for(i=0;i<n;i++){
        for(j=0;j<3;j++)
            cin>>dp[i][j];
    }
    solve(n,1);
    for(j=0;j<3;j++)
        res = max(res,dp[n-1][j]);
    cout<<res<<endl;
    return 0;
}




Measured memory_bytes: 8064
#include <iostream>
    using namespace std;
      
    int main() {
    int h,w;
    while(1){
        cin>> h >> w;
        if(h == 0 && w == 0){
            break;
        }
        for (int i=0; i<w ; i++){
            cout<< "#";
        };
        cout << endl;
        for (int j=0; j<h-2 ; j++){
            cout<<"#";
            for (int i=0; i<w-2 ; i++){
            cout<< ".";
        };
        cout << "#"<<endl;
        };
    for (int i=0; i<w ; i++){
            cout<< "#";
    };
    cout << endl;
     cout <<endl;
    }
    
    return 0;
    }



Measured memory_bytes: 3080
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> s;
  rep(i, Size(s)) {
    if (s[i] == 'h' && s[i + 1] == 'i') {
      i++;
    } else {
      Cout("No");
      return 0;
    }
  }
  Cout("Yes");
  return 0;
}

Measured memory_bytes: 256
from networkx import *
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
g = Graph(a)
ans = 0
for x in a:
  g.remove_edges_from([x])
  if not is_connected(g):
    ans += 1
  g.add_edges_from([x])
print(ans)

Measured memory_bytes: 53372
#include<bits/stdc++.h>
     
    #define ll long long
    #define fornum(A,B,C) for(A=B;A<C;A++)
    #define mp make_pair
    #define pii pair<int,int>
    #define pll pair<ll,ll>
     
    using namespace std;
    #define MOD ((ll)1e9+7)
    ll N,K;
    ll C[2020][2020];
    ll i,j,ans;
    int main(){
        scanf("%lld%lld", &N,&K);
     
        C[0][0]=1;
        fornum(i,0,N){
            C[i + 1][0] = 1;
            fornum(j,0,N){
                C[i + 1][j + 1] = (C[i][j] + C[i][j + 1]) % MOD;
            }
        }
        fornum(i,1,K+1){
            j = 0;
            printf("%lld\n", C[N-K + 1][i] * C[K - 1][i - 1] % MOD);
        }
        
        return 0;
    }

Measured memory_bytes: 31872
def bfs(n,e,fordfs,D):
    #点の数、スタートの点、有向グラフ
    W = [-1]*(n-1)
    #各点の状態量、最短距離とか,見たかどうかとか
    used = defaultdict(bool)
    que = deque()
    que.append(e)
    while que:
        now = que.popleft()
        i = 1
        for ne in fordfs[now]:
            l = min(now,ne); r = max(now,ne)
            if W[D[(l,r)]] == -1:
                while(True):
                    if not used[(now,i)]:
                        used[(now, i)] = True
                        used[(ne, i)] = True
                        break
                    i +=1
                que.append(ne)
                W[D[(l,r)]] = i
    return W
def examD():
    N = I()
    V = [[]for _ in range(N)]
    d = defaultdict(int)
    for i in range(N-1):
        a, b = LI()
        V[a-1].append(b-1)
        V[b-1].append(a-1)
        d[(a-1,b-1)] = i
    ans = bfs(N,0,V,d)
    print(max(ans))
    for v in ans:
        print(v)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()


Measured memory_bytes: 108832
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    AB = sorted([[int(_) for _ in input().split()] for __ in range(N)], key=lambda x:x[1])
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            print('No')
            break
    else:
        print('Yes')

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 42728
X = int(input())

num = X // 100
mod_v = X % 100

num_5 = mod_v // 5
mod_5 = mod_v % 5

if (mod_5 == 0 and num >= num_5) or (mod_5 > 0 and num >= (num_5+1)):
    print(1)
else:
    print(0)

Measured memory_bytes: 3060
#if 0
はじめ、一番左の一番下の点を始点として凸包を求めたがWAしてしまった。問題文をよく読むと一番下の一番左の点を始点にしなければならないと分かったので、最初に行う点のソートの際にy座標を優先し、それに合わせて複素数平面の座標を設定することで、一番下の一番左の点から凸包を求めることができ、無事解くことができた。
#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef complex<double> xy_t;
const double EPS = 1e-11;

double dot_product(xy_t a, xy_t b) {
  return (conj(a)*b).real();
}
double cross_product(xy_t a, xy_t b) {
  return (conj(a)*b).imag();
}
xy_t projection(xy_t p, xy_t b) {
  return b*dot_product(p,b)/norm(b);
}

int N;
pair<int,int> P[100010];
xy_t PL[100010], PH[100010];

int main() {
  cin >> N;
  int x, y;
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    P[i] = make_pair(y,x);
  }
  sort(P, P+N);
  for (int i = 0; i < N; i++) {
    PL[i] = xy_t(P[i].second*1.0, P[i].first*1.0);
    PH[i] = xy_t(P[N-1-i].second*1.0, P[N-1-i].first*1.0);
  }
  vector<xy_t> VL;
  VL.push_back(PL[0]); VL.push_back(PL[1]);
  for (int i = 2; i < N; i++) {
    bool c = true;
    xy_t p2 = PL[i];
    while (c) {
      if (VL.size() <= 1) {
        VL.push_back(p2);
        c = false;
      } else {
        xy_t p1 = VL[VL.size()-1], p0 = VL[VL.size()-2];
        if (cross_product(p1-p0, p2-p1) > 0.0 || abs(cross_product(p1-p0, p2-p1)) < EPS) {
          c = false; VL.push_back(p2);
        }
        else
          VL.pop_back();
      }
    }
  }
  vector<xy_t> VH;
  VH.push_back(PH[0]); VH.push_back(PH[1]);
  for (int i = 2; i < N; i++) {
    bool c = true;
    xy_t p2 = PH[i];
    while (c) {
      if (VH.size() <= 1) {
        VH.push_back(p2);
        c = false;
      } else {
        xy_t p1 = VH[VH.size()-1], p0 = VH[VH.size()-2];
        if (cross_product(p1-p0, p2-p1) > 0.0 || abs(cross_product(p1-p0, p2-p1)) < EPS) {
          c = false; VH.push_back(p2);
        }
        else
          VH.pop_back();
      }
    }
  }
  cout << VL.size() + VH.size() - 2 << endl;
  for (int i = 0; i < VL.size(); i++)
    cout << (int)(VL[i].real()) << ' ' << (int)(VL[i].imag()) << endl;
  for (int i = 1; i < VH.size()-1; i++)
    cout << (int)(VH[i].real()) << ' ' << (int)(VH[i].imag()) << endl;
}



Measured memory_bytes: 7920
#include <iostream>
using namespace std;
long long gcd(long long x, long long y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
long long calc(long long A, long long X, long long Y) {
	return A - A / X - A / Y + A / (X / gcd(X, Y) * Y);
}
int main() {
	long long A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << calc(B, C, D) - calc(A - 1, C, D) << endl;
	return 0;
}

Measured memory_bytes: 3592
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(0) ;
using ll = long long ;
const ll INF = 1e10 + 10 ;

int main(){
    fastio
    int n ;
    cin >> n ;
    string s ;
    cin >> s ;
    int ans = 0 ;
    for(int i = 0; i < n; ){
        char c = s[i] ;
        while(i < n && s[i] == c ) i++ ;
        ans++ ;
    }
    cout << ans << endl;
    return 0 ;
}

Measured memory_bytes: 512
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque

h,w,k= map(int, input().split())
sx,sy,gx,gy= map(int, input().split())
maze= [list(input()) for i in range(h)]


# 迷路　BFS
def clear_maze(sx, sy, gx, gy):

    INF=10**9
    distance = [[INF for i in range(w)] for j in range(h)]
    #    distance = [[None]*field_x_length]*field_y_length
    def bfs():
        # きた点と方向を格納
        d=deque()
        d.append((sx, sy))
        distance[sx][sy] =0

        while len(d):
            x, y = d.popleft()

            for i in range(0, 4):
                for j in range(1,k+1):
                    nx, ny = x + [j, 0, -j, 0][i], y + [0, j, 0, -j][i]
                    if not (0 <= nx < h and 0 <= ny < w):
                        break

                    elif maze[nx][ny] == '@' or distance[nx][ny]<=distance[x][y]:
                        break

                    elif distance[nx][ny] == INF:
                        d.append((nx, ny))
                        distance[nx][ny] = distance[x][y] + 1


        return distance[gx][gy]

    return bfs()

ans=clear_maze(sx-1,sy-1,gx-1,gy-1)

if  ans==10**9:
    print(-1)
else:
    print(ans)

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

struct grid{
  char g[12][12];
  int cost;
};

void paint(grid& gr,char l_u_cell,char changecolor,int p_x,int p_y){
  if(gr.g[p_y][p_x]!=l_u_cell){
    return ;
  }
  gr.g[p_y][p_x]=changecolor;
  paint(gr,l_u_cell,changecolor,p_x+1,p_y);
  paint(gr,l_u_cell,changecolor,p_x-1,p_y);
  paint(gr,l_u_cell,changecolor,p_x,p_y+1);
  paint(gr,l_u_cell,changecolor,p_x,p_y-1);
}
bool chacker(grid& gr,char l_u_cell,int X,int Y){
  bool flag=true;
  for(int i=1;i<=Y;i++){
    for(int j=1;j<=X;j++){
      if(l_u_cell!=gr.g[i][j]){flag=false;break;}
    }
  }
  return flag;
}

int main(){
  while(1){
    int X,Y;
    cin>>X>>Y;
    if(X==0&&Y==0)break;
    grid first;
    for(int i=1;i<=Y;i++){
      for(int j=1;j<=X;j++){
        cin>>first.g[i][j];
      }
    }

    first.cost=0;
    queue<grid> que;
    que.push(first);

    while(1){
      grid Grid=que.front();que.pop();
      char l_u_cell;
      l_u_cell=Grid.g[1][1];
      if(chacker(Grid,l_u_cell,X,Y)){
        cout<<Grid.cost<<endl;
        break;
      }
      if(l_u_cell != 'R'){
        grid tmp=Grid;
        tmp.cost=tmp.cost+1;
        paint(tmp,l_u_cell,'R',1,1);
        que.push(tmp);
      }
      if(l_u_cell != 'G'){
        grid tmp=Grid;
        tmp.cost=tmp.cost+1;
        paint(tmp,l_u_cell,'G',1,1);
        que.push(tmp);
      }
      if(l_u_cell != 'B'){
        grid tmp=Grid;
        tmp.cost=tmp.cost+1;
        paint(tmp,l_u_cell,'B',1,1);
        que.push(tmp);
      }
    }
  }
  return 0;
}


Measured memory_bytes: 40264
#include<bits/stdc++.h>
using namespace std;
#define INFTY 10000000000
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
  int n;cin>>n;
  vector<int> c(n),s(n),f(n);
  rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
  int now = n-2;
  ll time[n];time[n-1] = 0;
  rep(i,n-1){
    ll t = s[i] + c[i];
    for (int j = i+1; j < n-1; j++)
    {
      if(t<=s[j])t = s[j] +c[j];
      else {
        if((t-s[j])%f[j]==0)t += c[j];
        else t = ((t-s[j])/f[j]+1)*f[j]+c[j]+s[j];
      }
    }
    time[i] = t;
  }

  rep(i,n)cout<<time[i]<<endl;
  return 0;
}

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

int main() {
  int n, k; cin >> n >> k;
  vector<int> e(n);
  for(int i=0; i<n; i++){
    int p; cin >> p;
    e[i] = p+1;
  }
  
  int mx,sum_e;
  for(int i=0; i<k; i++){
    sum_e += e[i];
  }
  
  mx = sum_e;
  
  for(int i=0; i<n-k; i++){
    sum_e = sum_e - e[i] + e[i+k];
    if(sum_e > mx) mx = sum_e;
  }
  
  double ans = mx;
  ans /= 2;
  cout << fixed << setprecision(5) << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int bfs(int &p, string s, vector<int> &win){
    if(s[p] != '['){
        return s[p++];
    }
    int left = bfs(++p, s, win);
    int right = bfs(++p, s, win);
    p++;
    if(left == -1 or right == -1) return -1;
    if(win[left] != 0 and win[right] != 0) return -1;
    if(win[left] == 0 and win[right] == 0) return -1;
    if(win[left] == 0){
        win[right]--;
        return right;
    }else{
        win[left]--;
        return left;
    }
}

int main(){
    string s;
    cin >> s;
    vector<int> win(256, 0);
    char ch;
    int winnum;
    int n=0, sum=0;
    while(cin >> ch >> winnum){
        win[(int)ch] = winnum;
        n++;
        sum += winnum;
    }
    int p = 0;
    if(sum != n-1 or bfs(p, s, win) == -1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


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

int main() {
	int n, z, w;
	cin >> n >> z >> w;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int p = abs(w-a[n-1]);
	int q = -1;
	if(n >= 2) q = abs(a[n-2]-a[n-1]);
	int ans = max(p, q);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0]
A.extend(list(map(int, input().split())))
A.append(0)

S = 0
for i in range(1, N + 2):
  S += abs(A[i] - A[i - 1])
  
for i in range(1, N + 1):
  print(S - (abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i])) + abs(A[i + 1] - A[i - 1]))


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

int main(){

    ll n; cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    
    sort(all(a));
    reverse(all(a));

    vll ans;
    rep(i, n){
        ans.push_back(a[i]);
        ans.push_back(a[i]);
    }
    ans[0] = 0;

    ll out = 0;
    rep(i, n) out += ans[i];

    cout << out << endl;

    return 0;
}

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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

char BigAlphaToSmall(char a){
    if (a >= 65 && a <= 90){
        return a + 32;
    }
    return a;
}

char SmallAlphaToBig(char a){
    if (a >= 97 && a <= 122){
        return a - 32;
    }
    return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    vector<vector<int>> hoge(n);
    int a, b, c;
    for (int i = 0; i < q; i++){
        cin >> a;
        if(a == 0){
            cin >> b >> c;
            hoge[b].push_back(c);
            continue;
        }

        if(a == 1){
            cin >> b;
            if(hoge[b].empty()){
                cout << endl;
                continue;
            }
            for (int e = 0; e < hoge[b].size(); e++){
                if(e == hoge[b].size() - 1){
                    cout << hoge[b][e] << endl;
                    continue;
                }
                cout << hoge[b][e] << " ";
            }
            continue;
        }

        if(a == 2){
            cin >> b;
            hoge[b].clear();
        }
    }
}


Measured memory_bytes: 5868
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;
using namespace std;



int main() {
    ll x, y=0, sum = 100;
    
    cin>>x;
    
    while(true){
        y++;
        sum = sum + (sum/100);
        
        if(sum>=x) break;
    }
    
    
    cout<<y<<endl;
    
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string c;
	cin >> c;
	if (c == "a" || c == "i" || c == "u" || c == "e" || c == "o") {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}

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

typedef pair<int, int> P;
const int M = 1000000007;

vector<int> dijkstra(int s, vector<vector<P>> edge) {
    int n = edge.size();
    vector<int> dist(n, M);
    priority_queue<P, vector<P>, greater<P>> q;
    dist[s] = 0;
    q.push(P(0, s));
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        for (auto& e : edge[p.second]) {
            if (dist[e.second] > p.first + e.first) {
                dist[e.second] = p.first + e.first;
                q.push(P(p.first + e.first, e.second));
            }
        }
    }
    return dist;
}


int main() {
    int n;
    cin >> n;
    vector<vector<P>> edge(n);
    for (int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;
        if (i != u) exit(1);
        for (int j = 0; j < k; ++j) {
            int v, c;
            cin >> v >> c;
            edge[i].push_back(P(c, v));
        }
    }
    vector<int> d = dijkstra(0, edge);
    for (int i = 0; i < n; ++i) {
        cout << i << " " << d[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,l;cin>>n>>l;
  vector<string> s;
  REP(i,n){
    string ss;cin>>ss;
    s.push_back(ss);
  }
  if(n==1){
    P(s[0]);
    return 0;
  }
  sort(s.begin(),s.end());
  string t;
  for(int i=0;i<n;i++){
    t+=s[i];
  }
  P(t);
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>

typedef long long ll;
const ll INF = 1e18 + 1;

// choco(x);
template <typename T> void choco(T a) {std::cout << a << std::endl;}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  ll ans = INF;
  for (std::vector< ll >::iterator it = va.begin(); it != va.end(); it++) {
    ll num = *it;
    ll cnt = 0;
    while (num > 0 && num % 2 == 0) {
      num /= 2;
      cnt++;
    }
    ans = std::min(ans, cnt);
  }

  choco(ans);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define neko 100010
#define heko 410
#define qwq return printf("YES"),0; 
#define orz return printf("NO"),0; 
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
static int n,H;
typedef int arr[heko];
arr fa,book,dgi,dgo,out;
namespace IO
{
	const unsigned int bufsize=1<<16,outsize=1<<24;
	static char ch[bufsize],*S=ch,*T=ch;
	inline char getc()
	{return ((S==T)&&(T=(S=ch)+fread(ch,1,bufsize,stdin),S==T)?0:*S++);}
	static char Out[outsize],*nowp=Out;
	inline void flush(){fwrite(Out,1,nowp-Out,stdout);nowp=Out;}
	template<typename T>
		void read(T &x)
		{
			char c=getc();x=0;
			for(;!isdigit(c);c=getc());
			for(;isdigit(c);x=(x<<1)+(x<<3)+(c^'0'),c=getc());
		}
	template<typename T>
		void write(T x,char c='\n')
		{
			if(!x)*nowp++='0';
			static unsigned int stk[50],tp=0;
			for(;x;x/=10)stk[++tp]=x%10;
			for(;tp;*nowp++=stk[tp--]^'0');*nowp++=c;
		}
}
int find(int x){return fa[x]^x?fa[x]=find(fa[x]):x;}
int main()
{
	using namespace IO;
	int x,y,z,o,X,Y;
	read(n),read(H);
	f(i,0,H<<1)fa[i]=i;
	f(i,1,n)
	{
		read(x),read(y),read(z),read(o);
		if(z==0)X=H+x;
		else X=H-z;
		if(o==0)Y=H-y;
		else Y=H+o;
		book[X]=book[Y]=1;
		++dgi[Y],++dgo[X];
		fa[find(Y)]=find(X);

	}
	f(i,0,H)if(dgi[i]<dgo[i])orz;
	f(i,H+1,H<<1)if(dgi[i]>dgo[i])orz;
	f(i,0,H<<1)out[fa[i]]|=(dgi[i]^dgo[i]);
	f(i,0,H<<1)if(fa[i]==i&&book[i]&&!out[fa[i]])orz;
	qwq;
}

Measured memory_bytes: 256