akhauriyash/Code-Regression huggingface dataset:
# Header {{{
def assert(p)
  raise 'Assertion Failed' unless p
end

# Constants {{{
INF = 10**9
# }}}

# IO {{{
class MyIO
  def initialize
    @input = $stdin
    @output = $stdout
  end

  # @param filename [String]
  def set_input(filename)
    @input = File.open(filename, 'r')
  end

  def set_output(filename)
    @output = File.open(filename, 'w')
  end

  def intl
    splitl.map(&:to_i)
  end

  def splitl
    @input.gets.chomp.split(' ')
  end

  def gets
    @input.gets.chomp
  end

  def puts(*args)
    @output.puts(*args)
  end
end

io = MyIO.new
# }}}

# }}}

# io.set_input('inputs/2.txt')
# io.set_output('my_outputs/1.txt')

while true
  n, d = io.intl
  break if n == 0

  missiles = Array.new(n) { [] }
  n.times do |i|
    c = io.intl
    c.shift
    missiles[i] = c
  end

  maxs, mins = 0, INF
  maxi, mini = nil, nil
  sums = Array.new(n) { [] }
  n.times do |i|
    sum = missiles[i].reduce(:+) || 0
    sums[i] = sum
    if sum > maxs
      maxs, maxi = sum, i
    end
    if sum < mins
      mins, mini = sum, i
    end
  end

  disposed = true
  while disposed
    disposed = false
    n.times do |i|
      next if missiles[i].empty?
      next if i == maxi
      nsum = sums[i] - missiles[i].last
      next if maxs - nsum > d

      sums[i] -= missiles[i].pop
      disposed = true
      if nsum < mins
        mini = i
        mins = nsum
      end
    end

    # Try removing from max sum country
    maxs2, maxi2 = 0, nil
    n.times do |i|
      next if i == maxi
      if sums[i] > maxs2
        maxs2, maxi2 = sums[i], i
      end
    end

    if maxi2.nil?
      missiles[maxi] = []
      break
    end

    ns = sums[maxi] - missiles[maxi].last
    if ns < mins
      next if maxs2 - ns > d
      mins, mini = ns, maxi
    end
    disposed = true
    _t = missiles[maxi].pop
    sums[maxi] -= _t
    maxs -= _t

    if maxs < maxs2
      maxs, maxi = maxs2, maxi2
    end
  end

  if missiles.all? { |m| m.empty? }
    io.puts "Yes"
  else
    io.puts "No"
  end
end

# vim: foldmethod=marker

Measured memory_bytes: 6184
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
using namespace std;

void printV(vll v){
	cout << "size (" << v.size() << "): ";
	for(ll i = 0; i < v.size(); i++){
		cout << v[i] << " ";
	}
	cout << "\n";
}

void printM(vector<vll> v){
	cout << "size (" << v.size() << "," << v[0].size() << "): ";
	for(ll i = 0; i < v.size(); i++){
		for(ll j = 0; j < v[i].size(); j++){
			cout << v[i][j] << " ";
		}
		cout << "\n";
	}
}

ll powermod(ll x, ll y){
	ll res = 1;
	x = x % mod;
	while (y > 0)
	{
		if (y & 1){
			res = (res * x) % mod;
		}
		y = y >> 1;
		x = (x * x) % mod;
	}
	res %= mod;
	return res;
}

ll factmod(ll n)
{
	ll res = 1;
	while (n > 1)
	{
		res = (res * ((n / mod) % 2 ?  mod - 1 : 1)) % mod;
		for (ll i = 2; i <= n % mod; ++i){
			res = (res * i) % mod;
		}
		n /= mod;
	}
	res %= mod;
	return res;
}

int isGreater(long double a, ll b, long double c, ll d){
	ll temp = (ll)a, t = 0;
	while(temp / 10){
		temp = temp / 10; t++;
	}
	a = a / pow(10, t);
	b = b + t;
	temp = (ll)c, t = 0;
	while(temp / 10){
		temp = temp / 10; t++;
	}
	c = c / pow(10, t);
	d = d + t;
//	cout << "now: " << a << " " << b << " prev: " << c << " " << d << "\n";
	if(b > d) return 1;
	if(b == d and a > c) return 1;
	else return 0;
}

void solve(){
	ll n, money = 1000, profit = 0, stock;
	cin >> n;
	vll a(n), mon;
	mon.pb(1000);
	for(ll i = 0; i < n; i++){
		cin >> a[i];
	}	
	ll i = 0;
	while(i < n){
		while(i + 1 < n  and a[i] >= a[i + 1]){
			i++;
		}
//		cout << i << "\n";
		stock = money / a[i];
		money = money % a[i];
		mon.pb(money);
		while(i + 1 < n and a[i] <= a[i + 1]){
			i++;
		}
//		cout << i << "\n";
		money = money + stock * a[i];
		stock = 0;
		mon.pb(money);
		if(i == n-1)break;
	}
	cout << *max_element(mon.begin(), mon.end()) << "\n";
		
}


int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
//	ll t;
//	cin >> t;
//	while (t--)
//	{
		solve();
//	}
	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<list>
using namespace std;
const int N=1010;
int main()
{
    list <int > L[N];
    int z,T;
    cin>>z>>T;
    while(T--)
    {
        int c;
        cin>>c;
        if(c==0)
        {
            int t,x;cin>>t>>x;
            L[t].push_back(x);
        }else if(c==1)
        {
            int t;
            cin>>t;
          
            if(L[t].size())
            {
              auto z=L[t].begin();
              cout<<*z;
              z++;
              for(auto it=z;it!=L[t].end();it++)
                {
                    cout<<" "<<*it;
                }
            }
            
            cout<<endl;
        }
        else
        {
            int s,t;cin>>s>>t;
            L[t].splice(L[t].end(),L[s]);
        }
    }
}


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

bool solve(string s){
  for(int i=0; i<s.length()/2; i++){
    if(s[i]!=s[s.length()-i-1])return false;
  }
  return true;
}

int main(){
  string s;
  int n=0;
  while(cin>>s){
    if(solve(s))n++;
  }
  cout<<n<<endl;
  return 0;
}

Measured memory_bytes: 1188
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    Amax, Amin = max(A), min(A)
    imax, imin = A.index(Amax), A.index(Amin)

    ans = []
    rev = False

    if Amax <= 0:
        rev = True
    elif Amax > 0 and Amin < 0:
        if Amax >= abs(Amin):
            for i in range(N):
                if A[i] < 0:
                    A[i] += Amax
                    ans.append((imax, i))
        else:
            rev = True
            for i in range(N):
                if A[i] > 0:
                    A[i] += Amin
                    ans.append((imin, i))

    if not rev:
        for i in range(N - 1):
            if A[i] > A[i + 1]:
                A[i + 1] += A[i]
                ans.append((i, i + 1))
    else:
        for i in range(N - 1, 0, -1):
            if A[i] < A[i - 1]:
                A[i - 1] += A[i]
                ans.append((i, i - 1))

    print(len(ans))
    for x, y in ans:
        print(x + 1, y + 1)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9288
import numpy as np
n,d=map(int,input().split())
x=np.array([list(map(int,input().split())) for _ in range(n)])
cnt=0
for i in range(n):
    for j in range(i+1,n):
        dist=np.linalg.norm(x[i]-x[j])
        if dist==int(dist):
            cnt+=1
print(cnt)

Measured memory_bytes: 12528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni();
        int[] t = nia(n);
        int m = ni();

        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += t[i];
        }

        for (int i = 0; i < m; i++) {
            int p = ni() - 1;
            int x = ni();

            out.println(sum - (t[p] - x));
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (bit & (1LL << i))

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = {0, -1, 0, 1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


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

    int N;
    cin >> N;
    V<int> v(N);
    FOR(i, 0, N - 1) {
        cin >> v[i];
    }

    // dp[i][j][k] = iまでみたときにAがj個とって最後とった人がkのときの最小コスト
    VVV<int> dp(2, VV<int>(N + 1, V<int>(2, INF)));
    dp[0][0][1] = 0;
    FOR(i, 0, N - 1) {
        dp[(i + 1) & 1].assign(N + 1, V<int>(2, INF));
        FOR(j, 0, N - 1) {
            // A -> A
            chmin(dp[(i + 1) & 1][j + 1][0], dp[i & 1][j][0]);
            // A -> B;
            chmin(dp[(i + 1) & 1][j][1], dp[i & 1][j][0] + v[i]);
            // B -> A
            chmin(dp[(i + 1) & 1][j + 1][0], dp[i & 1][j][1] + v[i]);
            // B -> B
            chmin(dp[(i + 1) & 1][j][1], dp[i & 1][j][1]);
        }
    }
    print(min(dp[(N - 1) & 1][N / 2][0], dp[(N - 1) & 1][N / 2][1]));

    return 0;
}


Measured memory_bytes: 4560
n = gets.to_i
s = gets.strip

if n % 2 != 0
  print 'No'
else
  n.times do |i|
    if s[i] != s[i + n/2]
      print 'No'
      break
    end
    
    if i >= n/2 - 1
      print 'Yes'
      break
    end
  end
end
 

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

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

    vector<int> a(N);
    for(auto& c : a) cin >> c;

    int ans = 0;
    bool prev = false;
    for(int i = 0; i < N-1; ++i){
        if(a[i] == a[i+1] && !prev){
            ++ans;
            prev = true;
        } else {
            prev = false;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip> 
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;


void walk_on_multiplication_table()
{
  long long int n;
  cin >> n;

  long long int ans = n;
  for (int i = 1; i <= sqrt(n); ++i)
  {
    if (n % i == 0 && ans > (i - 1) + (n / i - 1))
    {
      ans = (i - 1) + (n / i - 1);
    }
  }

  cout << ans << '\n';
}


void average_length()
{
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

  double sum = 0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      if (i == j) continue;
      sum += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
    }
  }

  cout << setprecision(14) << sum / n << '\n';
}


int calc_digits(long long int n)
{
  int digits = 0;
  while (n >= 1)
  {
    n /= 10;
    ++digits;
  }

  return digits;
}


void buy_an_interger()
{
  long long int a, b;
  long long int x;
  cin >> a >> b >> x;

  long long int left = 0, right = 1000000001;
  long long int mid;
  while (right - left > 1)
  {
    mid = left + (right - left) / 2;
    if (a * mid + b * calc_digits(mid) <= x) left = mid;
    else right = mid;
  }

  cout << left << '\n';
}


void honest_or_unkind2()
{
  //後回し
}


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

  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)
{
  return a * b / gcd(a, b);
}


void snack()
{
  long long int a, b;
  cin >> a >> b;

  cout << lcm(a, b) << "\n";
}


bool is_prime(int n)
{
  if (n <= 1) 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;
}


void next_prime()
{
  int x;
  cin >> x;

  int prime = x;
  while (!is_prime(prime)) ++prime;

  cout << prime << "\n";
}


int factorial(int n)
{
  int fact = 1;
  for (int i = n; i > 0; --i) fact *= i;
  return fact;
}


int calc_order(int n, vector<int> x)
{
  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    cnt += (x[i] - 1) * factorial(n - 1 - i);
    for (int j = i + 1; j < n; ++j) {
      if (x[j] > x[i]) --x[j];
    }
  }
  return cnt;
}


void count_order()
{
  int n;
  cin >> n;

  vector<int> p(n);
  vector<int> q(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < n; i++) cin >> q[i];

  int p_cnt = 0, q_cnt = 0;
  p_cnt = calc_order(n, p);
  q_cnt = calc_order(n, q);

  cout << abs(p_cnt - q_cnt);
}




int main()
{
  walk_on_multiplication_table();
  //average_length();
  //buy_an_interger();
  //cout << calc_digits(1000000000) << '\n';
  //honest_or_unkind2();
  //snack();
  //next_prime();
  //count_order();
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if (a + b >= c)cout << "Yes";
	else cout << "No";
	return(0);
}

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

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

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

const int MOD = 1000000007;

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

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

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

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

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

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

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

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

LL power_MOD(LL a,LL b){
	LL ans = 1;
	for(LL i=0;i<b;i++){
		ans=ans*a%MOD;
	}
	return ans;
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	LL n;
	cin>>n;
	LL ans = power_MOD(10,n)-power_MOD(9,n)*2+power_MOD(8,n);
	ans%=MOD;
	ans = (ans+MOD)%MOD;
	cout<<ans<<endl;

	return 0;
}


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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  vector<int> y(M);
  for (int i = 0; i < N; i++) cin >> x[i];
  for (int i = 0; i < M; i++) cin >> y[i];

  int max_x = *max_element(x.begin(), x.end());
  int min_y = *min_element(y.begin(), y.end());
  int z = min(Y, min_y);
  if (X < z && max_x < z)
    cout << "No War" << endl;
  else
    cout << "War" << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
	"strings"
)

var N int

func dfs(x int) int {
	if x > N {
		return 0
	}
	cnt := 0
	if contains(strconv.Itoa(x), "753") {
		cnt++
	}
	cnt += dfs(x*10 + 7)
	cnt += dfs(x*10 + 5)
	cnt += dfs(x*10 + 3)
	return cnt
}
func contains(t, s string) bool {
	for _, r := range s {
		if !strings.ContainsRune(t, r) {
			return false
		}
	}
	return true
}

func main() {
	fmt.Scan(&N)

	fmt.Println(dfs(0))
}


Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		String s = in.next();
		int nam = s.length();
		char[] s_chars = s.toCharArray();
		
		int nam2 = nam/2;
		int cnt = 0;
		for(int i = 0;i<nam2;i++){
		    if(s_chars[i] != s_chars[nam-i-1]){
		        cnt++;
		    }
		}
       
       System.out.print(cnt);
      
	}
}

Measured memory_bytes: 21844
#include <cstdio>
#include <string>
using namespace std;
int n;
void dfs(string s,int max){
	if(s.size()==n){
		printf("%s\n",s.c_str());
		return;
	}
	for(int i=97;i<=max;++i){
		dfs(s+char(i),max);
	}
	dfs(s+char(max+1),max+1);
}
int main(){
	scanf("%d",&n);
	dfs("a",97);
	return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int N,M,cou=0;
  cin>>N>>M;
  if(M>=N*2){
    cou+=N;
    M-=N*2;
    cou+=M/4;
  }
  else{
    cou+=M/2;
  }
  cout<<cou<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define MAXC 100000
int main()
{
	int n, k;cin>>n>>k;
	int a[n];
// 	unordered_set<int> s1;
	for(int i=0;i<n;i++){
		int x;cin>>a[i];
	}
	bool dp[k+1];
	memset(dp, false, sizeof(dp));
	for(int i=1;i<=k;i++){
		for(int j=0;j<n;j++){
			if(i-a[j]>=0)
			dp[i]|=!dp[i-a[j]];
		}
	}
// 	for(int i=1;i<=k;i++) cout<<dp[i]<<" ";
	cout<<(dp[k] == true ? "First" : "Second");
}

Measured memory_bytes: 384
#include <stdio.h>

#define SIZE_F 51000

int furui[SIZE_F];
int prime[20000];

int main() {
	int i, j, k;
	int n;

	for(i = 2, k = 0; i < SIZE_F; i++) {
		if(!furui[i]) {
			for(j = i * 2; j < SIZE_F; j += i) {
				furui[j] = 1;
			}
			prime[k] = i;
			k++;
		}
	}

	while(scanf("%d", &n) != EOF) {
		int middle;
		int top = k - 1, bottom = 0;

		while(top - bottom > 1) {
			middle = (top + bottom) / 2;
			
			if(prime[middle] == n)
				break;
			else if(prime[middle] > n)
				top = middle;
			else
				bottom = middle;
		}

		if(prime[middle] != n)
			printf("%d %d\n", prime[bottom], prime[top]);
		else
			printf("%d %d\n", prime[middle - 1], prime[middle + 1]);
	}

	return 0;
}

Measured memory_bytes: 816
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll arr[120];
ll KK1(ll n, ll r)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1]);
    }
    return C[r];
}
/*
ll KK2(ll n, ll m)
{
	ll ans=1;
	for(int i=1;i<=m;i++)
	{
		ans=ans/i*(n-m+i);
	}
	return ans;
}
*/
int main()
{
    ll tot=0;
    long double ans=0,sum=0,cnt=0;
    map<ll,int>N,R;
    int n,a,b;
    cin>>n>>a>>b;
    for(int i=0; i<n; i++){
       	cin>>arr[i];
		N[arr[i]]++;
	}
    sort(arr,arr+n);
    ll last ;
    for(int i=n-1; i>=0; i--)
    {
        sum+=arr[i];
        R[arr[i]]++;
        cnt++;
        if(cnt>b)
               break;
        if(cnt==a)
        {
            last = arr[n-1];
            ans=sum/cnt;
        }
            if(cnt>=a)
        {
            long double cur=(sum/cnt);
            if(cnt==a)
                {tot+=KK1(N[arr[i]],R[arr[i]]);
                }
            else if(arr[i]==last)
            {
                tot+=KK1(N[arr[i]],R[arr[i]]);
            }
        }
    }
        cout<<setprecision(18)<<fixed<<ans<<endl;
        cout<<tot<<endl;
        return 0;
    }


Measured memory_bytes: 3840
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

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

int memo[45];

long fib(int n)
{
	if(n <= 1)
		return 1;
	if(memo[n] != 0) return memo[n];
	return memo[n] = fib(n - 1) + fib(n - 2);
}

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

	cout << fib(n) << endl;
	return 0;

}

Measured memory_bytes: 1164
#include <stdio.h>

int main() {
    int t, h, m, s;
    scanf("%d", &t);
    t %= 86400;
    s = t % 60;
    m = (t / 60) % 60;
    h = t / 3600;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

Measured memory_bytes: 1844
def main():
    n, k = map(int, input().split())
    As = list(map(int, input().split()))
    i = 0
    visit = [0]*n
    move = []
    roop = []
    while visit[i] != 2:
        if visit[i] == 0:
            move.append(i)
        else:
            roop.append(i)
        visit[i] += 1
        i = As[i] - 1

    if len(move) > k:
        ans = move[k] + 1
    else:
        ans = roop[(k-(len(move)-len(roop))) % len(roop)]+1
    print(ans)


if __name__ == "__main__":
    main()


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

int memo[1000005]={};

int main(int argc, char const *argv[])
{
	int s;
	cin>>s;
	memo[s]=1;
	for (int i = 2; i < 1000005; ++i)
	{
		if (s%2==0)
		{
			s/=2;
		}
		else
		{
			s=3*s+1;
		}
		if (memo[s]==1)
		{
			cout<<i<<endl;
			return 0;
		}
		memo[s]=1;
	}
	return 0;
}


Measured memory_bytes: 256
"""
tの先頭から、できるだけ長い文字列を一回のsで消費するゲーム
できるだけ短い時間で、残っているtの先頭からどこまでを一回で消費できるかを判断したい。
部分文字列DPのときにやったみたいに、ns[i][j] => i番目より後ろで、つぎに文字jが出てくるインデックス
という表を作っておけばよい。
"""

S = input()
T = input()
N = len(S)
dp = [[-1]*26 for _ in range(N+1)]
for i in range(N):
    s = S[i]
    dp[i][ord(s)-ord("a")] = i+1

for i in range(N-2,-1,-1):
    for j in range(26):
        if dp[i][j] == -1:
            dp[i][j] = dp[i+1][j]

cycleCnt = 0
sInd = 0
for i in range(len(T)):
    if dp[sInd][ord(T[i])-ord("a")] == -1:
        cycleCnt += 1
        sInd = 0
        if dp[sInd][ord(T[i])-ord("a")] == -1:
            print(-1)
            exit()
    sInd = dp[sInd][ord(T[i])-ord("a")]
else:
    print(cycleCnt*N+sInd)



Measured memory_bytes: 104720
#include <bits/stdc++.h>
using namespace std;
const int N = 100020;
int n, m, ans;
vector <int> bi[N];
int A, B;
int fa[N], dep[N];
int get_f(int t) {return fa[t] = (fa[t] == t? t: get_f(fa[t]));}
int cnt[2];
void dfs1(int t, int f = 0, int d = 0)
{
    fa[t] = f; dep[t] = d; cnt[dep[t] & 1] ++;
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
            dfs1(bi[t][i], t, d + 1);
}
int dfs21(int t)
{
    int x = (dep[t] & 1)? 1: -1;
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != fa[t])
            x += dfs21(bi[t][i]);
    ans += abs(x);
    return x;
}
vector <int> V;
pair <int, int> dfs22(int t)
{
    int x = (dep[t] & 1)? 1: -1, y = 0;
    if (t == A) y = 1; else if (t == B) y = -1;
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != fa[t])
        {
            pair <int, int> s = dfs22(bi[t][i]);
            x += s.first;
            y += s.second;
        }
    if (y) V.push_back(-y * x);
    else ans += abs(x);
    return make_pair(x, y);
}
int dfs23(int t)
{
    int x = (dep[t] & 1)? 1: -1;
    if (t == A || t == B) x -= (cnt[1] - cnt[0]) / 2;
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != fa[t])
            x += dfs23(bi[t][i]);
    ans += abs(x);
    return x;
}
int main()
{
    scanf("%d%d", &n, &m);
    if (n & 1) return puts("-1"), 0;
    for (int i = 1; i <= n; ++ i) fa[i] = i;
    for (int i = 1; i <= m; ++ i)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if (get_f(a) == get_f(b)) A = a, B = b;
        else
        {
            bi[a].push_back(b);
            bi[b].push_back(a);
            fa[get_f(a)] = get_f(b);
        }
    }
    dfs1(1);
    if (m == n - 1)
    {
        if (cnt[0] != cnt[1]) return puts("-1"), 0;
        dfs21(1);
    }
    else if ((dep[A] ^ dep[B]) & 1)
    {
        if (cnt[0] != cnt[1]) return puts("-1"), 0;
        dfs22(1);
        V.push_back(0); sort(V.begin(), V.end());
        for (int i = 0; i < V.size() / 2; ++ i) ans += V[V.size() / 2] - V[i];
        for (int i = V.size() / 2 + 1; i < V.size(); ++ i) ans += V[i] - V[V.size() / 2];
    }
    else
    {
        ans += abs(cnt[1] - cnt[0]) / 2;
        dfs23(1);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 14460
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

void solve(void){
    int N; string S;
    cin >> N >> S;
    string cand[] = {"SS", "SW", "WW", "WS"};
    rep(4, c) {
        string ans = cand[c];
        rep(N-2, i) {
            if ((S[i+1] == 'o' && ans[i+1] == 'S') || (S[i+1] == 'x' && ans[i+1] == 'W')) ans += ans[i];
            else ans += (ans[i]=='S'?"W":"S");
        }
        bool ok = false;
        if (ans[N-1] == 'S') {
            if ((S[N-1] == 'o' && ans[0] == ans[N-2]) || (S[N-1] == 'x' && ans[0] != ans[N-2])) {
                if (ans[0] == 'S') {
                    ok = (S[0] == 'o' && ans[1] == ans[N-1]) || (S[0] == 'x' && ans[1] != ans[N-1]);
                }
                else {
                    ok = (S[0] == 'x' && ans[1] == ans[N-1]) || (S[0] == 'o' && ans[1] != ans[N-1]);
                }
            }
        }
        else {
            if ((S[N-1] == 'x' && ans[0] == ans[N-2]) || (S[N-1] == 'o' && ans[0] != ans[N-2])) {
                if (ans[0] == 'S') {
                    ok = (S[0] == 'o' && ans[1] == ans[N-1]) || (S[0] == 'x' && ans[1] != ans[N-1]);
                }
                else {
                    ok = (S[0] == 'x' && ans[1] == ans[N-1]) || (S[0] == 'o' && ans[1] != ans[N-1]);
                }
            }
        }
        if (ok) {
            cout << ans << endl;
            return;
        }
    }

    cout << -1 << endl;
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


Measured memory_bytes: 776
@d=$t=1;
$/=\1;
for(;$t+=($j=ord<>)>10?($c+=$j%3,1):-1;$d[$c<$t?$t:$c-$t]=0){
	for($j=$c;$j;$j--){
		if(($d[$j]+=$d[$j-1])>=998244353){
			$d[$j]-=998244353;
		}
	}
}
printf("%d",$d[$c]);


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
// Addition and Multiplication
int main() {
  int N, K, x = 1;
  cin >> N >> K;

  for (int i = 0; i < N; i++) {
    if (x <= K) {
      x *= 2;
    } else {
      x += K;
    }
  }

  cout << x << endl;
}

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

using namespace std;

int main(void)
{
    int N, X, T;
    cin >> N >> X >> T;

    int ans;
    ans = N / X * T;
    if (N % X != 0)
    {
        ans += T;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

int s[200];
 

int main() {
	string w;
	cin >> w;
	for (int i = 0; i < w.length(); i++) {
		s[w[i]]++;
	}
	for (int i = 97; i < 123; i++) {
		if (s[i] % 2 == 0)continue;
		else {
			print("No");
			return 0;
		}

	}
	print("Yes");






	return 0;
}

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


int main() {
  string S;
  cin >> S;
  int result = 0;
  int cnt_0 = 0;
  int cnt_1 = 0;
  for (char s : S) {
    if (s == '0') {
      ++cnt_0;
    } else {
      ++cnt_1;
    }
  }
  result = min(cnt_0, cnt_1) * 2;
  cout << result << endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
    int n,d,x;
    cin >> n >> d >>x;
    int a[n];
    int ans = x;
    for(int i=0;i<n;i++){
        cin >> a[i];
        for(int j=0;a[i]*j+1<=d;j++){
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
d = []
a = []
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int,input().split())))
import itertools
b = list(set(list(itertools.chain.from_iterable(a))))
cnt = 0
for i in range(1,n+1):
    if not i in b:
        cnt+=1
print(cnt)

Measured memory_bytes: 9240
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
//#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;



int main(){
  int h,w;
  cin>>h>>w;
  int y,x;
  string s;
  rep(i,h)rep(j,w){
    cin>>s;
    if(s=="snuke"){
      y=i+1;
      x=j;
    }
  }
  cout<<(char)(x+'A')<<y<<endl;
  return 0;
}


Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 5e5 + 20;
int n, a[N], res;
string s;

int32_t main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> s;

	n = _sz(s) + 1;

	for (int i = 0; i < n - 1; i++)
	{
		if (s[i] == '<') a[i + 1] = max(a[i + 1], a[i] + 1);
	}
	for (int i = n - 2; i >= 0; i--)
	{
		if (s[i] == '>') a[i] = max(a[i], a[i + 1] + 1);
	}

	for (int i = 0; i < n; i++)
	{
		res += a[i];
	}

	cout << res << '\n';
}


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

int main(){

    int N, M;
    cin >> N >> M;
    
    int ans = 0;
    for(int i = 1; i * i <= M; i++){
        if(M % i == 0){
            if(M / i >= N) ans = max(ans, i);
            if(i >= N) ans = max(ans, M / i);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque

s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    ls = list(input().split())
    if ls[0] == '1':
        rev = not rev
    elif rev ^ (ls[1] == '1'):
        s.appendleft(ls[2])
    else:
        s.append(ls[2])

if rev:
    s.reverse()

print(''.join(s))


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

int main(){
    int N;
    cin >> N;
    vector<int>V(N);
    vector<int>C(N);
    int ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> V[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> C[i];
    }
    for(int i = 0; i < N; i++) {
        if(V[i]-C[i] > 0) {
            ans += V[i]-C[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  int s;
  cin >> s;
  int k = s / 100;
  int l = s % 100;
  if(k >= 13 && l >= 13)cout << "NA" << endl;
  else if(k == 0 && l >= 13)cout << "NA" << endl;
  else if(k >= 13 && l == 0)cout << "NA" << endl;
  else if(k >= 13 && l >= 1 && l <= 12)cout << "YYMM" << endl;
  else if(k == 0 && l >= 1 && l <= 12)cout << "YYMM" << endl;
  else if(k >= 1 &&k <= 12 && l >= 13)cout << "MMYY" << endl;
  else if(k >= 1 && k <= 12 && l == 0)cout << "MMYY" << endl;
  else if(k == 0 && l == 0)cout << "NA" << endl;
  else cout << "AMBIGUOUS" <<endl;
  }



Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    max_r = 10 ** 5 + 5
    prime = [False, True] * (max_r // 2 + 1)
    prime[0] = prime[1] = False
    prime[2] = True
    for x in range(3, max_r):
        if prime[x]:
            for y in range(x ** 2, max_r, x):
                prime[y] = False
    cnt_to_x = [0] * max_r
    p = 0
    for x in range(1, max_r, 2):
        if prime[x] and prime[(x + 1) // 2]:
            cnt_to_x[x] = p = p + 1
        else:
            cnt_to_x[x] = p

    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        print(cnt_to_x[r] - cnt_to_x[l - 2])

main()


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

int main(int argc, char **argv)
{
	ll N; cin >> N;

	vector<ll> v;
	v.reserve(40);
	ll i{0};
	for (; N != 0; ++i)
	{
		ll r = N % 2;
		if (r < 0) r += 2;
		v.push_back(r);
		N = (N - r) / (-2);
	}
	if (v.empty()) v.push_back(0);
	reverse(v.begin(), v.end());
	for (auto &e : v)
		std::cout << e;
	std::cout << std::endl;
}


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

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  for(int i=0; i<H; i++){
    cin >> A.at(i);
  }
  for(int i=0; i<W+2; i++){
    cout << "#";
  }
  cout << endl;
  for(int i=0; i<H; i++){
    cout << "#" << A.at(i) << "#" << endl;
  }
  for(int i=0; i<W+2; i++){
    cout << "#";
  }
  cout << endl;
}


Measured memory_bytes: 256
/*
ID: amagica1
TASK: ariprog
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define NINF -INF
#define mp make_pair
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define For(i, a, b) for(int i=a; i<b; i++)
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define Rev(i, a, b) for(int i=a; i>b; i--)
#define REV(i, a, b) for(int i=a; i>=b; i--)
typedef long long ll;
typedef long double ld;
typedef int64_t l;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int MAXN = 200005;
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
int leftmost[MAXN], N, a[MAXN];
int main() {
    //-----------FILE------------//
    // freopen("ariprog.in", "r", stdin);
    // freopen("ariprog.out", "w", stdout);
    //----------------------------//
    cin >> N; bool pos=false; int first=0;
    for(int i=1; i<=N; i++) {
        cin >> a[i];
        leftmost[a[i]] = i;
        if(a[i] == 1) {pos=true; first=i;}
    }
    int cnt=0;
    for(int i=1; i<=N; i++) {
        if(i <= leftmost[i] && leftmost[i] >= first) cnt++;
        else break;
    }
    if(!pos) printf("-1\n");
    else printf("%d\n", N - cnt);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
using LL = long long;

int main() {
	int n;
	cin >> n;
	int b, f, r, v;
	int ans[4][3][10] = {};
	for (int i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		ans[b - 1][f - 1][r - 1] += v;
	}
	string s = "####################";
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				cout << " " << ans[i][j][k];
			}
			cout << endl;
		}
		if (i != 3) cout << s << endl;
	}
	return 0;
}



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

int main() {
    int h, w; cin >> h >> w;
    int ans_i = -1, ans_j = -1;
    for (int i = 1; i <= h; i++) for (int j = 0; j < w; j++) {
        string s; cin >> s;
        if (s == "snuke") {
            ans_i = i;
            ans_j = j + 'A';
        }
    }
    cout << (char)ans_j << ans_i << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
typedef long long ll;
ll h[110000];
int n,a,b;
int check(ll k)
{
	ll ret=0;
	for(int i=1;i<=n;i++)
	{
		h[i]-=b*k;
		if(h[i]>0) ret+=h[i]%(a-b)==0?h[i]/(a-b):h[i]/(a-b)+1;
		h[i]+=b*k;
	}
	return ret<=k;
}
int main()
{
	ll s=0;
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++) scanf("%lld",&h[i]),s=s>h[i]?s:h[i];
	ll l=0,r=s/b+(s%b!=0);
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",r+1);
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>

using namespace std;

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

    long long x=1e5;
    for (int i=0; i<n; ++i) {
        x += (x+19)/20;
        ((x+=999)/=1000) *= 1000;
    }

    printf("%lld\n", x);
    return 0;
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 107;
const LD PI = acos ( -1.0 );
const LD EPS = 1e-9;

struct cT
{
	cT () : x ( 0 ), y ( 0 ) {}
	cT ( int _x, int _y ) : x ( _x ), y ( _y ) {}
	
	cT operator + ( const cT &a ) const
	{
		return cT ( x + a.x, y + a.y );
	}
	
	cT operator - ( const cT &a ) const
	{
		return cT ( x - a.x, y - a.y );
	}
	
	LL operator * ( const cT &a ) const
	{
		return SC ( LL, x ) * a.x + SC ( LL, y ) * a.y;
	}
	
	LL operator ^ ( const cT &a ) const
	{
		return SC ( LL, x ) * a.y - SC ( LL, y ) * a.x;
	}
	
	bool operator < ( const cT &a ) const
	{
		return ( x ^ a.x ) ? ( x < a.x ) : ( y < a.y );
	}
	
	LL abs ()
	{
		return SC ( LL, x ) *  x + SC ( LL, y ) * y;
	}
	
	LD len ()
	{
		return sqrt ( abs () );
	}
	
	int x, y;
}cr[MAXN];

int n;
int ord[MAXN];
int stk[MAXN], top;
LD ang[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d%d", &cr[i].x, &cr[i].y );
}

void work ()
{
	// main work
	
	lpi ( i, 1, n ) ord[i] = i;
	sort ( ord+1, ord+1+n, [] ( int x, int y ) { return cr[x] < cr[y]; } );
	sort ( cr+1, cr+1+n );
	
	lpi ( i, 1, n ){
		while ( top > 1 && ( ( cr[stk[top]] - cr[stk[top-1]] ) ^ ( cr[i] - cr[stk[top]] ) ) <= 0 ) --top;
		stk[++top] = i;
	}
	int nt = top;
	lpd ( i, n-1, 0 ){
		while ( top > nt && ( ( cr[stk[top]] - cr[stk[top-1]] ) ^ ( cr[i] - cr[stk[top]] ) ) <= 0 ) --top;
		stk[++top] = i;
	}
	if ( top == 1 ) stk[++top] = stk[1];
	
//	lpi ( i, 1, top ) cerr << ord[stk[i]] << " "; cerr << endl;
	
	stk[0] = stk[top-1];
	lp ( i, 1, top ) ang[ord[stk[i]]] = acos ( ( ( cr[stk[i+1]] - cr[stk[i]] ) * ( cr[stk[i]] - cr[stk[i-1]] ) ) / ( ( cr[stk[i+1]] - cr[stk[i]] ).len () * ( cr[stk[i]] - cr[stk[i-1]] ).len () * ( 1 + EPS ) ) ) / ( 2 * PI );
	
	lpi ( i, 1, n ) printf ( "%.13lf\n", SC ( double, ang[i] ) );
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
  int main(){
      lint n;
      cin >>n; vector<lint> a(n);
      rep(i,n)cin >> a[i];
      if(a[0]!=0)cout<<-1<<endl;
      else{
          lint ans=0;
          rep(i,n-1){
              if(a[i+1]-a[i]>1){
                  cout<<-1<<endl;
                  return 0;
              }else if(a[i+1]>a[i])ans++;
              else ans+=a[i+1];

          }
          cout<<ans<<endl;
      }
  }
  
     


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

using namespace std ;

const int MAX = 1e5 + 10 ;

vector< vector<int> >st(MAX) , en(MAX) ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n , C;
	cin>>n>>C ;
	for(int i = 0 ; i < n ; ++i)
	{
		int x , y , c;
		cin>>x>>y>>c ;
		st[x].push_back(c) ;
		en[y].push_back(c) ;
	}
	int ans = 0 , cnt = 0;
	for(int i = 1 ; i < MAX ; ++i)
	{
		for(auto &j : st[i])
		{
			bool found = false ;
			for(auto &k : en[i])
			{
				if(k == j)
				{
					found = true ;
					break ;
				}
			}
			if(found)
			{
				cnt-- ;
				continue ;
			}
			if(cnt > 0)
				cnt-- ;
			else
				ans++ ;
		}
		cnt += en[i].size() ;
	}
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(){

    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    int flag = 0;
    int ans = 1;
    for(int i = 0; i < n - 1; i++){
        if(a[i + 1] - a[i] == 0) continue;
        else if(a[i + 1] - a[i] > 0){
            if(flag == -1){
                ans++;
                flag = 0;
            }
            else flag = 1;
        }else{
            if(flag == 1){
                ans++;
                flag = 0;
            }
            else flag = -1;
        }
    }   

    cout << ans << endl;
    return 0;
}

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

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

  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.at(i) = x - 1;
  }

  vector<int> v;
  set<int> s;
  int ind = 0;
  while (true) {
    if (s.count(ind)) {
      break;
    }

    s.insert(ind);
    v.push_back(ind);
    ind = a.at(ind);
  }

  int64_t i = 0;
  for (i = 0; i < n; ++i) {
    if (v.at(i) == ind) {
      break;
    }
  }

  int v_i = 0;
  if (k < v.size()) {
    v_i = k;
  } else {
    v_i = (k - i) % ((int64_t)v.size() - i) + i;
  }
  cout << v.at(v_i) + 1 << endl;
}


Measured memory_bytes: 13896
def main():
	N = int(input())
	d = [0] * N

	for i in range(N):
		d[i] = int(input())

	num = [0] * 101

	for i in range(N):
		num[d[i]] += 1

	ans = 0

	for i in range(101):
		if num[i] > 0:
			ans += 1

	print(ans)

  
if __name__ == "__main__":
  	main()

Measured memory_bytes: 9128
#include <iostream>
#include <deque>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(){
	std::ios_base::sync_with_stdio(false);
	deque<int> a;
	int num, n;
	string command;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>command;
		if((command.length() >= 6) && (command[6] == 'F')){
			a.pop_front();
		}else if((command.length() >= 6) && (command[6] == 'L')){
			a.pop_back();
		}else if(command[0] == 'i'){
			cin>>num;
			a.push_front(num);
		}else if(command == "delete"){
			cin>>num;
			deque<int>::iterator iter;
			iter = find(a.begin(), a.end(), num);
			if(iter != a.end())
				a.erase(iter);
		}
	}

	
	for(int i=0;i<a.size();i++){
		if(i != 0) cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 5300