akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

void prians(bool answer) {
  if(answer)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int x;

int main() {
  cin >> x;
  prians(x == 3 || x == 5 || x == 7);
  return 0;
}

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

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

using namespace std;

string s;

void compute() {
  int ptr = (int)s.size()-1;
  while( ptr >= 0 ) {
    if( ptr < 4 ) goto FAIL;
    if( s[ptr] == 'm' ) {
      if( s[ptr-4] == 'd' && s[ptr-3] == 'r' && s[ptr-2] == 'e' && s[ptr-1] == 'a' ) {
        ptr -= 5;
      } else goto FAIL;
    } else if( s[ptr] == 'e' ) {
      if( s[ptr-4] == 'e' && s[ptr-3] == 'r' && s[ptr-2] == 'a' && s[ptr-1] == 's' ) {
        ptr -= 5;
      } else goto FAIL;
    } else if( s[ptr] == 'r' ) {
      if( s[ptr-5] == 'e' && s[ptr-4] == 'r' && s[ptr-3] == 'a' && s[ptr-2] == 's' && s[ptr-1] == 'e' ) {
        ptr -= 6;
      } else if( s[ptr-6] == 'd' && s[ptr-5] == 'r' && s[ptr-4] == 'e' && s[ptr-3] == 'a' && s[ptr-2] == 'm' && s[ptr-1] == 'e' ) {
        ptr -= 7;
      } else goto FAIL;
    } else goto FAIL;
  }
  puts("YES");
  return;
  FAIL:
  puts("NO");
}

int main() {
  cin >> s;
  compute();
  return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <time.h>
using namespace std;
#define sci(n) scanf("%lld", &(n))
#define scd(n) scanf("%Ld", &(n))

typedef long long LL;
typedef pair<LL, LL> PLL;

LL cb[57][75];

LL c(LL n, LL k) {
	if (k > (n / 2)) { k = n - k; }
	if (k<0 || k>n) {
		return 0;
	}
	if (k < 1) {
		return 1;
	}
	if (n == k) {
		return 1;
	}
	LL& ret = cb[n][k];
	if (ret != -1) {
		return ret;
	}
	return ret = (c(n - 1, k) + c(n - 1, k - 1));
}

LL fac(LL n) {
	LL ret = 1;
	if (n == 0) { return 0; }
	while (n >= 1) {ret *= n; n--;}
	return ret;
}

bool isAllSame(vector<LL>& v,LL st, LL fin) {
	return v[st] == v[fin - 1];
}

int main(void)
{
	memset(cb, -1, sizeof(cb));
	LL n, a, b;
	sci(n), sci(a), sci(b);
	vector<LL> v(n,0),prefix(n,0);
	for (int i = 0; i < n; i++) sci(v[i]); 
	sort(v.begin(), v.end(), std::greater<LL>());
	prefix[0] = v[0];
	for (int i = 1; i < n; i++) prefix[i] = prefix[i - 1] + v[i];
	//for (int i = 0; i < v.size(); i++) {printf("%lld ", v[i]);}
	double avg = (double)prefix[a - 1] / a; printf("%lf\n", avg);
	LL ans = 0;
	LL pick = v[0], uni = 0, cnt = 1, samenumcnt = 0;
	map<LL, LL> mp;
	for (int i = 0; i < a; i++) {mp[v[i]]++;}

	for (int i = 0; i < v.size(); i++) {
		if (isAllSame(v, i, a)) {
			uni += 1; 
			if(i<a){
				samenumcnt += 1;
			}
		}
	}
	if (samenumcnt == a) {
		for (int i = a; i <= b; i++) {
			ans += c(uni, i);
		}
	}
	else {	
		ans += c(uni, samenumcnt); 
	}
	time_t st, fin;
	int moroje_ganbatte = 1;
	st = clock();
	for (;;) {
		fin = clock();
		if (fin - st > 1901) {
			break;
		}
		moroje_ganbatte++;
	}
	printf("%lld", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

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

	auto a = vectors(n, 3, 0LL);
	rep(i,n){
		rep(j,3)
			cin >> a[i][j];
	}

	auto dp = vectors(n + 1, 3, 0LL);
	rep(i,n){
		rep(from,3){
			rep(to, 3){
				if(from == to) continue;
				dp[i + 1][to] = max(dp[i + 1][to], dp[i][from] + a[i][to]);
			}
		}
	}

	auto& b = dp.back();
	cout << max({b[0], b[1], b[2]}) << endl;
}


Measured memory_bytes: 11136
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
 
        try {
            String buffer[] = br.readLine().split("\\s+");
 
            int N = Integer.parseInt(buffer[0]);
            int M = Integer.parseInt(buffer[1]);
            int L = Integer.parseInt(buffer[2]);
 
            int A[][] = new int[N][M];
            int B[][] = new int[M][L];
 
            String buf_A[] = new String[M];
            String buf_B[] = new String[L];
 
            for(int row = 0; row < N; row++){
                buf_A = br.readLine().split("\\s+");
                for(int col = 0; col < M; col++){
                    A[row][col] = Integer.parseInt(buf_A[col]);
                }
            }
 
            for(int row = 0; row < M; row++){
                buf_B = br.readLine().split("\\s+");
                for(int col = 0; col < L; col++){
                    B[row][col] = Integer.parseInt(buf_B[col]);
                }
            }
 
            Long ans;
 
            for(int A_row = 0; A_row < N; A_row++){
                for(int B_col = 0; B_col < L; B_col++){
                    ans = 0L;
                    for(int B_row = 0; B_row < M; B_row++){
                        ans += A[A_row][B_row]*B[B_row][B_col];
                    }
                    if(B_col == 0){
                        System.out.printf("%d", ans);
                    }else{
                        System.out.printf(" %d", ans);
                    }
                }
                System.out.printf("\n");
            }
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 80360
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
#define ll long long
#define ii pair<intt,intt>
#define mp make_pair
typedef long long intt;
using namespace std;
int main()
{
  intt a,b;
  cin>>a>>b;
  if(a<=10)
   cout<<b+100*(10-a)<<endl;
  else
   cout<<b<<endl;

    return 0;
}


Measured memory_bytes: 256
import heapq
import sys
import collections
input = sys.stdin.readline

def solve():
  n = int(input())
  query = collections.deque([3,5,7])
  template = []
  while query:
    tmp = query.popleft()
    tmp3 = str(tmp*10+3)
    if tmp3.count("3") and tmp3.count("5") and tmp3.count("7"):
      template.append(int(tmp3))
    tmp5 = str(tmp*10+5)
    if tmp5.count("3") and tmp5.count("5") and tmp5.count("7"):
      template.append(tmp5)
    tmp7 = str(tmp*10+7)
    if tmp7.count("3") and tmp7.count("5") and tmp7.count("7"):
      template.append(tmp7)
    if int(tmp3) <= n:
      query.append(int(tmp3))
    if int(tmp5) <= n:
      query.append(int(tmp5))
    if int(tmp7) <= n:
      query.append(int(tmp7))
  template2 = list(set(template))
  ans = 0
  for i in template2:
    if int(i) <= n:
      ans += 1
  print(ans)
   
      
    
solve()

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


int main() {
    int N, M; cin >> N >> M;
    int a[M + 1], b[M + 1], c[M + 1][N + 1];
    for (int i = 1; i <= M; i++) {
        cin >> a[i] >> b[i];
        for (int j = 1; j <= b[i]; j++) cin >> c[i][j];
    }

    const int INF = 1e9;
    vector<int> dp(4096, INF);
    dp[0] = 0;

    for (int i = 1; i <= M; i++) {
        int now = 0;
        for (int j = 1; j <= b[i]; j++) {
            now |= (1 << (c[i][j] - 1));
        }
        for (int bits = 0; bits < (1 << N); bits++) {
            if (dp[bits] + a[i] < dp[bits | now]) {
                dp[bits | now] = dp[bits] + a[i];
            }
        }
    }
    if (dp[(1 << N) - 1] == INF) dp[(1 << N) - 1] = -1;

    cout << dp[(1 << N) - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
D = {}
for i in A:
  if i in D:
    D[i] += 1
  else:
    D[i] = 1
S = 0
for i in D:
  S += (D[i] * (D[i] - 1)) // 2
for i in range(N):
  print(S - (D[A[i]] - 1))

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

int main(){
  int N;
  long long D,count=0;
  cin >> N >> D;
  for(int i=0;i<N;i++){
    long long X,Y;
    cin >> X >> Y;
    if(X*X+Y*Y<=D*D){
      count++;
    }
  }
  cout << count << endl;
}
  

Measured memory_bytes: 3608
from math import *

while True:
    a = int(input())
    if a == 0: break

    #print('a')
    score_list = []
    #max_score = 0
    #min_score = 1000
    for i in range(a):
        score_list.append(int(input()))
    #print(score_list)
    max_ = max(score_list)
    min_ = min(score_list)

    #print('b')
    ans_list = []
    flag = 0
    for score in score_list:
        if score == max_ and not flag:
            flag = 1
            continue
        else:
            ans_list.append(score)

    new_ans_list = []
    flag = 0
    for score in ans_list:
        if score == min_ and not flag:
            flag = 1
            continue
        else:
            new_ans_list.append(score)

    avg = sum(new_ans_list)/len(new_ans_list)
    print(int(avg))



Measured memory_bytes: 5652
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
using Graph = vector<vector<int>>;
// Californium:Paken
vector<bool> seen;
void dfs(const Graph& G, int v) {
    seen[v] = true; // v を訪問済にする
 
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}
signed main() {
    int L, R; cin >> L >> R;
    int M = 2019;
    if (L / 2019 == R / 2019 && L % 2019 != 0) {
        for (int X = L; X < min(L+2019,R); X++) {
            for (int Y = X+1; Y <= min(L+2019,R); Y++) {
                M = min(M,X*Y%2019);
            }
        }
        cout << M << endl;
    }
    else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 3596
import scala.io.StdIn.readInt

object Main {
  def sieve(n:Int) = {
    val primes = Array.tabulate(n+1) { _ % 2 }
    primes(1) = 0
    primes(2) = 1

    for( i <- 3 to Math.sqrt(n).toInt by 2 )
      if(primes(i) == 1)
        (i*i to n by i*2).foreach { primes(_) = 0 }
    primes
  }

  def main(args:Array[String]) = {
    val p = sieve(50000)
    var n = 0
    while( { n = readInt; n} != 0 ) {
      var cnt = 0
      if(p(n-2) == 1) cnt = 1
      else if(n%2==0) {
        for(i<- 3 to n/2 by 2)
          if(p(i) ==1 && p(n-i) ==1)
            cnt += 1
      }
      println(cnt)
    }
  }
}

Measured memory_bytes: 51116
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for (int i=n;i>=0;i--)
    {
        int e=sqrt (1.0*i);
        if (e*e==i) {cout<<i;break;}
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int x,y;
  cin>>x>>y;
  if((y-2*x)%2==0 && (4*x-y)%2==0 && y-2*x>=0 && 4*x-y>=0)
    cout<<"Yes\n";
  else
    cout<<"No\n";
return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
string c1,c2;
int fail[5000005];
int cou[5000005];
int main(){
	cin>>c1>>c2;
	string t1=c1;
	c1+=t1;
	c1+=t1;
	c1+=t1;
	while(c1.size()<=9*(int)c2.size()) c1+=t1;
	int f=-1;
	int n1=c1.size();
	int n2=c2.size();
	fail[0]=-1;
	f=-1;
	for(int i=1;i<=n2;i++){
		while(f>=0&&c2[f+1]!=c2[i]) f=fail[f];
		if(c2[f+1]==c2[i]) f++;
		fail[i]=f;
	//	cout<<fail[i]<<" ";
	}
	int p=-1;
	for(int i=0;i<n1;i++){
		while(p>=0&&c1[i]!=c2[p+1]) p=fail[p];
		if(c1[i]==c2[p+1]) p++;
	//	cout<<p;
		if(p==n2-1) cou[i]=1;
	}
	for(int i=n2+1;i<=n1;i++) if(cou[i])cou[i]+=cou[i-n2];
	int ma=0;
	for(int i=0;i<=n1;i++){
		ma=max(ma,cou[i]);
	}
	if(ma>=n1/n2-2) cout<<-1;
	else cout<<ma;
}

Measured memory_bytes: 28748
import java.util.Scanner;

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

		int X = Integer.parseInt(sc.next());
		int Y = Integer.parseInt(sc.next());

//		int[] a = new int[N + 1];
//		for(int i = 1;i <= N;i++) {
//			a[i] = Integer.parseInt(sc.next());
//		}

//		String s = sc.next();

		sc.close();

		int ret = 0;

		if(X == 1) {
			ret += 300000;
		}else if(X == 2) {
			ret += 200000;
		}else if(X == 3) {
			ret += 100000;
		}
		if(Y == 1) {
			ret += 300000;
		}else if(Y == 2) {
			ret += 200000;
		}else if(Y == 3) {
			ret += 100000;
		}
		if(X == 1 && Y == 1) {
			ret += 400000;
		}



//		for(int i = 1;i <= N;i++) {
//			System.out.print(a[i]);
//		}

		System.out.println(ret);



	}
}



Measured memory_bytes: 25172
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

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

  int a, b;
  cin >> a >> b;

  if (a == b)
  {
    cout << "Draw" << endl;
  }
  else if (a == 1)
  {
    cout << "Alice" << endl;
  }
  else if (a > b && b != 1)
  {
    cout << "Alice" << endl;
  }
  else
  {
    cout << "Bob" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N = gets.chomp.to_i
result = [0] * N
(1..200).each do |x|
  (x..200).each do |y|
    (y..200).each do |z|
      nn = x ** 2 + y ** 2 + z ** 2 + x*y + y*z + z*x
      next if nn > N
      uniq_size = [x, y, z].uniq.length
      result[nn - 1] = result[nn - 1] + { 1 => 1, 2 => 3, 3 => 6 }[uniq_size]
    end
  end
end
result.each do |r|
  puts r
end

Measured memory_bytes: 14612
#bit全探索

def solve(S, bitls, bitlslen):
    splited = []
    splitlen = 0
    prev = 0
    for i in range(bitlslen):
        if bitls[i] == 1:
            splited.append(S[prev:i+1])
            prev = i+1
            splitlen += 1
    splited.append(S[prev:])
    splitlen += 1
    
    sum = 0
    for i in range(splitlen):
        sum += int(splited[i])
    return sum


S = input()
lenS = len(S)
#lenS-1箇所だけ+を入れる場所がある -> 2**(lenS-1)回試行
loop = 2**(lenS-1)

ans = 0
for i in range(loop):
    val = i
    bitls = []
    for j in range(lenS-1):
        bitls.append(val % 2)
        val //= 2
    ans += solve(S, bitls, lenS-1)
print(str(ans))

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

struct Node {
	int key;
	Node *parent, *left, *right;
};

Node *NIL, *root;

void printPreOrder(Node *u);
void printInOrder(Node *u);
void insertTree(int k);

int main() {
	int i, j, n, k;
	char com[10];
	cin >> n;
	
	for (i = 0; i < n; i++) {
		cin >> com;
		if (com[0] == 'i') {
			cin >> k;
			insertTree(k);
		} else {
			printInOrder(root);
			cout << endl;
			printPreOrder(root);
			cout << endl;
		}
	}
	return 0;
}

void printPreOrder(Node *u) {
	if (u == NIL)return;
	cout << " " << u->key;
	printPreOrder(u->left);
	printPreOrder(u->right);
}

void printInOrder(Node *u) {
	if (u == NIL)return;
	printInOrder(u->left);
	cout << " " << u->key;
	printInOrder(u->right);
}

void insertTree(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	z = new Node;
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	while (x != NIL) {
		y = x;
		if (z->key < x->key)x = x->left;
		else x = x->right;
	}
	z->parent = y;
	if (y == NIL)root = z;
	else if (z->key < y->key)y->left = z;
	else y->right = z;
}

Measured memory_bytes: 26452
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <stack>
#include <queue>
#include <set>

#define mod 1000000007
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    if(n <= m) cout << "unsafe";
    else cout << "safe";
    return 0;
}

Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;

namespace Digits
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');

            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            int output = 0;
            bool loopOn = true;

            while(loopOn)
            {
                n /= k;
                output += 1;

                if(n <= 0)
                {
                    break;
                }
            }

            Console.WriteLine(output);

        }
    }
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

bool dp_x[8100][32100];
bool dp_y[8100][32100];

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

  string s;
  int x, y;
  cin >> s >> x >> y;
  x += 16000;
  y += 16000;

  int cnt = 0;
  bool p = true;
  vi X, Y;
  rep(i, 0, s.size()) {
    if(s[i] == 'T') {
      if(p) X.push_back(cnt);
      else Y.push_back(cnt);
      p = !p;
      cnt = -1;
    }
    cnt++;
  }
  if(p) X.push_back(cnt);
  else Y.push_back(cnt);
  X.push_back(0);
  Y.push_back(0);

  dp_x[0][16000 + X[0]] = true;
  rep(i, 1, X.size()) {
    rep(j, 8000, 24001) dp_x[i][j] = dp_x[i - 1][j + X[i]] | dp_x[i - 1][j - X[i]];
  }

  dp_y[0][16000 + Y[0]] = dp_y[0][16000 - Y[0]] = true;
  rep(i, 1, Y.size()) {
    rep(j, 8000, 24000) {
      dp_y[i][j] = dp_y[i - 1][j + Y[i]] | dp_y[i - 1][j - Y[i]];
    }
  }

  if(dp_x[X.size() - 1][x] && dp_y[Y.size() - 1][y]) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 240768
N,A,B,C,D=map(int,input().split())
if N%A==0:
    X=N//A
else:
    X=N//A+1
if N%C==0:
    Y=N//C
else:
    Y=N//C+1
if X*B<=Y*D:
    print(X*B)
else:
    print(Y*D)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main(){
   int n; cin >> n;
   vector<int> count;
   rep(i,n){
       int a; cin >> a;
       count.push_back(a);
    }
    int ans_min = 0;
    int ans_max = 0;
    bool flag_hai = false;
    bool flag_tya = false;
    bool flag_midori = false;
    bool flag_mizu = false;
    bool flag_ao = false;
    bool flag_ki = false;
    bool flag_daidai = false;
    bool flag_aka = false;


    for(auto it : count){
        if(it < 400){
            if(!flag_hai){
                flag_hai = true;
                ans_min++;
            }
        }else if(it < 800){
            if(!flag_tya){
                flag_tya = true;
                ans_min++;
            }
        }else if(it < 1200){
            if(!flag_midori){
                flag_midori = true;
                ans_min++;
            }
        }else if(it < 1600){
            if(!flag_mizu){
                flag_mizu = true;
                ans_min++;
            }
        }else if(it < 2000){
            if(!flag_ao){
                flag_ao = true;
                ans_min++;
            }
        }else if(it < 2400){
            if(!flag_ki){
                flag_ki = true;
                ans_min++;
            }
        }else if(it < 2800){
            if(!flag_daidai){
                flag_daidai = true;
                ans_min++;
            }
        }else if(it < 3200){
            if(!flag_aka){
                flag_aka = true;
                ans_min++;
            }
        }else{
            ans_max++;
        }
    }
    if(ans_min != 0){
    cout << ans_min << " " << ans_max + ans_min << endl;
    }else{
        cout << 1 << " " << ans_max << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

int main()
{
  int r,g,b,n;
  cin>>r>>g>>b>>n;
  ll cnt=0;

  rep(i,n/r+1)
  rep(j,n/g+1)
  {
    if((n-i*r-j*g)%b==0 && (n-i*r-j*g)>=0) cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		String line = "";

		try {
			scanner = new Scanner(System.in);
			line = scanner.nextLine();

			char[] wkArray = line.toCharArray();
			StringBuffer buf = new StringBuffer();
			for (int i = 0; i < wkArray.length; i++) {
				switch (wkArray[i]) {
				case '1':
					buf.append(9);
					break;
				case '9':
					buf.append(1);
					break;
				default:
					buf.append(wkArray[i]);
					break;
				}

			}

			System.out.println(buf.toString());

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		String line = "";

		try {
			scanner = new Scanner(System.in);
			line = scanner.nextLine();
			int start = Integer.parseInt(line);

			for (int outer = start; outer <= 999; outer++) {
				char[] wkArray = Integer.toString(outer).toCharArray();

				if (wkArray[0] == wkArray[1] && wkArray[1] == wkArray[2]) {
					System.out.println(outer);
					return;
				}
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 22868
K=int(input())
Xs=[1,2,3,4,5,6,7,8,9]
s=0
e=9
while K > len(Xs):
    for i in range(e-s):
        n=list(str(Xs[s+i]))
        if int(n[-1])-1 >= 0:
            Xs.append(int(''.join(n+[str(int(n[-1])-1)])))
        Xs.append(int(''.join(n+[str(int(n[-1]))])))
        if int(n[-1])+1 <= 9:
            Xs.append(int(''.join(n+[str(int(n[-1])+1)])))
    s=e
    e=len(Xs)
print(Xs[K-1])

Measured memory_bytes: 11016
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Vector;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			int n = sc.nextInt();
			ArrayList <Vector <Integer>> vectors = new ArrayList <Vector <Integer>>();  //VectorのArrayListを生成
			for (int i=0; i<n; i++) {
				vectors.add(new Vector<Integer>());  //n個のvectorを追加
			}
			int times = sc.nextInt();
			for (int i=0; i<times; i++) {
				int request = sc.nextInt();
				int vec = sc.nextInt();
				switch (request) {
				case 0:
					int x = sc.nextInt();
					vectors.get(vec).add(x);
					break;

				case 1:
					if (vectors.get(vec).size() != 0) {  //空じゃなかったら
						for (int j=0; j<vectors.get(vec).size(); j++) {
							System.out.print(vectors.get(vec).get(j));
							if (j < vectors.get(vec).size()-1) System.out.print(' ');
							else System.out.print('\n');
						}
					} else System.out.print('\n');
					break;

				case 2:
					if (vectors.get(vec).size() != 0) {  //元々空だったらなにもしない
						vectors.remove(vec);
						vectors.add(vec,new Vector<Integer>());
					}
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 312596
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, M;
    cin>>n>>M;
    vl as(n);
    cin>>as;
    sort(rng(as));
    vl ss(n + 1);
    rep(i, n) ss[i + 1] = ss[i] + as[i];

    ll l = -1, r = INF;
    ll cnt;
    while (l + 1 < r) {
        ll m = (l + r) / 2;
        cnt = 0;
        rep(i, n) {
            cnt += as.end() - lower_bound(rng(as), m - as[i]);
        }
        if (cnt >= M) l = m;
        else r = m;
    }
    cnt = 0;
    rep(i, n) {
        cnt += as.end() - lower_bound(rng(as), l - as[i]);
    }
    ll ans = 0;
    rep(i, n) {
        ll d = lower_bound(rng(as), l - as[i]) - as.begin();
        ans += ss[n] - ss[d] + (n - d) * as[i];
    }
    ans -= (cnt - M) * l;
    cout<<ans<<endl;
}

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

#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
#define double long double
	while (t--) {
		double n;
		cin >> n;
		double sum = 0;
		for (double i = 1; i <= n; i++) {
			sum = sum + ((i / 2.0) * (floor(n / i)) * (floor(1.0 + n / i)));
		}
		int k = sum;
		cout << k << endl;
	}
	return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
const ll mod = 1e9 + 7;
const ll inf = 1e12;
const double pi = 3.141592;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n + 1);
    rep(i, n) cin >> p[i+1];
    int ans = 0;
    rep1(i,n){
        if(p[i] != i)
            continue;
        swap(p[i], p[i + 1]);
        ans++;
    }
    if(p[n] == n)
        ans++;
    cout << ans << "\n";
    return 0;
}

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

string a, b;

int convert(string s){
    int i=0;
    int convert_num = 0;
    
    while(i < s.length()){
        if(s[i] >= '0' && s[i] <= '9'){
            int n = s[i] - '0';
            switch (s[i+1])
            {
            case 'm' : convert_num += n * 1000; break;
            case 'c' : convert_num += n * 100; break;
            case 'x' : convert_num += n * 10; break;
            case 'i' : convert_num += n * 1; break; 
            default:   break;
            }
            i += 2;
        }else{
            switch (s[i])
            {
            case 'm' : convert_num += 1000; break;
            case 'c' : convert_num += 100; break;
            case 'x' : convert_num += 10; break;
            case 'i' : convert_num += 1; break; 
            default:   break;
            }  
            i += 1;
        }
    }
    return convert_num;
}

int add(int a, int b){
    return a + b;
}

string re_convert(int num){
    string str;
    if(num >= 1000){
        if(num/1000 > 1){
            str += num/1000 + '0';
        }
        str += 'm';
        num = num % 1000;
    }

    if(num >= 100){
        if(num/100 > 1){
            str += num/100 + '0';

        }
        str += 'c';
        num = num % 100;
    }

    if(num >= 10){
        if(num/10> 1){
            str += num/10 + '0';
        }
        str += 'x';
        num = num % 10;
    }

    if(num >= 1){
        if(num > 1){
            str += num + '0';
        }
        str += 'i';
        num = num % 1000;
    }
    return str;
}


int main(void){
    int convert_a, convert_b, sum_num;
    int n;
    string str;
    cin >> n;
    for(int i=0; i < n; i++){
        cin >> a >> b;
        convert_a = convert(a);
        convert_b = convert(b);
        sum_num = add(convert_a, convert_b);
        str = re_convert(sum_num);
        cout << str << endl;
    }
    return 0;
}


Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff first
#define INF 1000000001
#define inf1 1000000000000000001
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 300000+5;
const lli mod= 1000000007;
vector<lli> catlan(int n) {vector<lli> dp(n + 1, 0);dp[0] = 1;dp[1] = 1;for (int i = 2; i <= n; i ++) {for (int j = 0; j < i; ++ j) {dp[i] += dp[j] * dp[i - j - 1];}}return dp;}
lli digit(lli n){int res=(int)log10(n)+1;return res;}
lli lcm(lli a,lli b){lli ans=(a*b)/(__gcd(a,b));return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n){int c=0;if(n==0)return 0;while(n){if((n&1)==1){cout<<c<<" ";}c++;n=n>>1;}return c;}

/// RULESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS////
/// READ THEM ALOUD......................................................................................................
/// 1. If the constraints are low think brute force :3................
/// 2. Always cheack with customed testcases .. i.e = Base cases 0 or 1 or similar cases
/// 3. Always use lli :)
/// 4. Read the question again if the solution isnt gatting ac xD
/// 5. Work ur way through solutions :)
/// 6. :D


void solve()
{
    string a;cin>>a;
    int n=a.size();
    if(a[n-1]=='s')a+="es";
    else a+="s";
    cout<<a<<endl;

}
int main()
{
    solve();
}


Measured memory_bytes: 3596
// //AUTHOR:BlackBox Inc.//
// #include<bits/stdc++.h>
// #include<unordered_map>
// #include<tr1/unordered_map>
// #define ll long long
// #define ull unsigned long long
// #define vi vector<long long>
// #define vlli vector<long long long long>
// #define vvi vector<vector<long long>>
// #define endl "\n"
// #define vpii vector<pair<long long,long long>>
// #define vs vector<string>
// #define lin1(x) ll long long x; x = scan();
// #define lin2(x,y) ll long long x, y; x = scan(), y = scan();
// #define lin3(x,y,z) ll long long x, y, z; x = scan(), y = scan(), z = scan();
// #define pb(x) push_back(x)
// #define makep(x,y) make_pair(x,y)
// #define mx(a,b) (a)>(b)?(a):(b)
// #define mn(a,b) (a)<(b)?(a):(b)
// #define fori(s,e) for(i=s;i<=e;i++)
// #define forj(s,e) for(j=s;j<=e;j++)
// #define fork(s,e) for(k=s;k<=e;k++)
// #define rep(i,s,e) for(long long i=s;i<=e;i++)
// #define brep(i,s,e) for(long long i=s;i>=e;i--)
// #define all(x) x.begin(),x.end()
// #define mem(x,y) memset(x,y,sizeof(x));
// #define bits1(x) __builtin_popcount(x)
// #define pi 3.14159265358979323846264338327950
// #define MOD7 1000000007
// #define MOD9 1000000009
// #define cn cin>>
// #define co cout<<
// #define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
// using namespace std;
// using namespace std::tr1;

// long long main()
// {
// #ifndef RAHUL
//     freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
// #endif

// long long a,b,c,d,e,f,g,h;
// cin>>a;
// long long count= 100;
// // std::vector<long long> v(a);

// for (long long i = 0; i < a; ++i)
// {
// 	/* code */
// 	long long ans;
// 	cin>>ans;
// 	long long count1=0;
// 	while(ans%2==0){
// 		ans/=2;
// 		count++;
// 	}
// 	count=min(count1,count);
// }
// cout<<count<<endl;

// return 0;
// }
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define cn cin>>
#define co cout<<
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

int main()
{


long long a,b,c,d,e,f,g,h;

cin>>a;
long long count1=0;

while(a){
	int count=a%10;
	if (count==1)
	{	
		/* code */
		count1++;
	}
	a=a/10;
}
cout<<count1<<endl;

return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,D,X;
  cin >>N>>D>>X;
  vector<int> A(N);
  int ans = X;
  for(int i=0;i<N;i++){
    cin >>A[i];
    ans += (D-1)/A[i]+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import bisect
color = range(400,3201,400)
num_color = len(color)
p = [0]*(num_color+1)
N=int(input())
for a in input().split():
    a=int(a)
    p[bisect.bisect_right(color, a)]+=1
print(max(1, num_color-p[:-1].count(0)), num_color-p[:-1].count(0)+p[-1])

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

typedef pair<int, int> II;
typedef vector< II > VII;
typedef vector<int> VI;

#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ll long long
#define fr(i,n) for(i=0;i<n;i++)

ll a[100010];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll k,i,mn,mx,tp;
    cin>>k;
    for(i=1;i<=k;i++)
        cin>>a[i];
    if(a[k]!=2)
        cout<<-1<<endl;
    else
    {
        mn=2;
        mx=3;
        for(i=k-1;i>0;i--)
        {
            tp=(mn+a[i]-1)/a[i];
            tp*=a[i];
            mn=tp;
            tp=mx/a[i];
            tp*=a[i];
            tp+=a[i]-1;
            mx=tp;
            if(mx<mn)
                break;
        }
        if(i>0)
            cout<<-1<<endl;
        else
            cout<<mn<<" "<<mx<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print( int u){
	int i, c;
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";
	
	if( T[u].p == NIL ) cout << "root, ";
	else if ( T[u].l == NIL ) cout << "leaf, ";
	else cout << "internal node, ";
	
	cout << "[";
	
	for( i=0, c=T[u].l; c != NIL; i++, c = T[c].r){
		if(i) cout << ", ";
		cout << c;
	}
	cout << "]" << endl;
}

//再帰的に深さを求める
int rec(int u, int p){
	D[u] = p;
	if( T[u].r != NIL ) rec(T[u].r, p); //右の兄弟は同じ高さを設定
	if( T[u].l	!= NIL ) rec(T[u].l, p+1); //最も左の子に自分の深さ+1を設定
}

int main(){
	int i, j, d, v, c, l, r;
	cin >> n;
	for( i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
	
	for( i=0; i<n; i++){
		cin >> v >> d;
		for( j=0; j<d; j++){
			cin >> c;
			if( j==0 ) T[v].l =c;
			else T[l].r = c;
			l = c;
			T[c].p = v;
		}
	}
	for ( i=0; i<n; i++){
		if( T[i].p == NIL) r=i;
	}
	
	rec(r, 0);
	
	for( i=0; i<n; i++) print(i);
	
	return 0;
}


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

int main(void) {
  int N, L;
  cin >> N >> L;

  string S[110];
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  sort(S, S+N);

  string ans;
  for (int i = 0; i < N; i++) {
    ans += S[i];
  }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		while(true){
			int h = scan.nextInt();
			int w = scan.nextInt();

			if(h == 0 && w == 0){
				 break;
			}else{
				for(int a = 0; a < h; a++){
					for(int b = 0; b < w; b++){
						if(a % 2 == 0){
							if(b % 2 == 0){
								System.out.print("#");
							}else{
								System.out.print(".");
							}
						}else{
							if(b % 2 == 0){
								System.out.print(".");
							}else{
								System.out.print("#");
							}
						}
					}
					System.out.println();
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 35152
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i = 0; i < n; ++i){
  	cin >> h[i];
  }

  sort(h.rbegin(), h.rend());

  ll ans = 0;
  for(int i = 0; i < n; ++i){
  	if(k <= 0)ans += h[i];
  	--k;
  }

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


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    
    if ((s.contains("N") && s.contains("S") && s.contains("W") && s.contains("E"))
        || (s.contains("N") && s.contains("S") && !s.contains("W") && !s.contains("E"))
        || (!s.contains("N") && !s.contains("S") && s.contains("W") && s.contains("E"))) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
    
  }
}

Measured memory_bytes: 35532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll INF = 1LL << 60; //MAX 9223372036854775807

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

//lower側がtrue judgeがtrueとなる最もupper側のvalを返す
//lowerboundでもfalseなら-1を返す
auto judge = [&](ll val) { 
  ll cnt=0;
  rep(i,n){
    if(a[i]==0){
      if(val>=0)cnt+=n-i-1;
    }
    if(a[i]>0&&val>0){
      ll p=upper_bound(a.begin(), a.end(), val/a[i])-a.begin();
      cnt+=max(0LL,p-i-1);
    }
    if(a[i]<0){
      if(val<=0)cnt+=a.end()-lower_bound(a.begin(), a.end(), (a[i]+1+val)/a[i]);
      else {
        ll p=a.end()-lower_bound(a.begin(), a.end(), val/a[i]);
        cnt+=min(p,n-i-1);
      }
    }
    if(cnt>=k)return false;
  }
  return true; 
  };
auto binarysearch = [&](ll lowerbound, ll upperbound) {
  if (!judge(lowerbound)) return -1LL;
  ll lower = lowerbound, upper = upperbound;
  while (1){
    if (judge((lower + upper) / 2)) lower = (lower + upper) / 2;
    else upper = (lower + upper) / 2;
    if (abs(upper - lower) <= 1){
      if (judge(upper)) return upper;
      else return lower;
    }
  }
};
cout << binarysearch(-INF, INF)+1 << endl; 

return 0;
}

Measured memory_bytes: 1920
# coding: utf-8
# Your code here!

num = 0

S = input()

# print(S)

# print(S[0])
# print(S[1])
# print(S[2])
# print(S[3])

if S[0] == '+':
    num += 1
else:
    num -= 1
    
if S[1] == '+':
    num += 1
else:
    num -= 1
    
if S[2] == '+':
    num += 1
else:
    num -= 1
    
if S[3] == '+':
    num += 1
else:
    num -= 1

print(num)

Measured memory_bytes: 3064
n=int(input())
l=list(map(int,input().split()))
a=abs(l[0])
m=0
d=0
z=0
s=0
for i in range(n):
  if l[i]<0:
    d+=1
  elif l[i]==0:
    z+=1
if d%2==0 or (d+z)%2==0:
  for i in range(n):
    s+=abs(l[i])
  print(s)
else:
  for i in range(1,n):
    if a>=abs(l[i]):
      a=abs(l[i])
      m=i
  s=0
  for i in range(m):
    s+=abs(l[i])
  s+=-abs(l[m])
  for i in range(m+1,n):
    s+=abs(l[i])
  print(s)
    

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

string s;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> s;
	int n = s.size();
	int t = 0;
	long long ans = 0;
	for(int i=0; i<n; ++i){
		if(s[i] == 'W'){
			ans += i - t;
			++t;
		}
	}
	cout << ans << "\n";
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    int M, NA, NB;
    while (cin >> M >> NA >> NB, M || NA || NB) {
        vector<int> P(M);
        rep(i, M) {
            cin >> P[i];
        } 

        int ans = 0, mgap = 0;
        for (int i=NA; i<=NB; i++) {
            int gap = P[i-1] - P[i];
            if (gap >= mgap) {
                ans = i;
                mgap = gap;
            }
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3080
St2=[[1],[0,1]]
2.upto(1000){|n|St2<<[0,*St2[-1].each_cons(2).map.with_index(1){|(x,y),k|x+y*k},1]}
a,b=gets.split.map &:to_i
p St2[a][b].to_i%(10**9+7)


Measured memory_bytes: 241236
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair


int main()
{
    long long X;
    cin >> X;
    for (int i=-1000; i<1000; i++) {
        for (int j=-1000; j<1000; j++) {
            if (pow(i,5)-pow(j,5)==X) {
                cout << i << " " << j;
                return 0;
            }
        }
    }
    

}

Measured memory_bytes: 3964
# 1からNへの経由地点Kの気持ちでみると各クエリで判別可能
n, m = map(int, input().split())
arr = [[False, False] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        arr[b - 1][0] = True
    if b == n:
        arr[a - 1][1] = True

for x in arr:
    if x[0] and x[1]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Measured memory_bytes: 64756
//temprates
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <iomanip>

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define LREP(i,n) LFOR(i,0,(ll)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)
#define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9+7;




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll w,h,x,y;
  ll aa;
  cin >> w >> h >> x >> y;
  aa = w*h;
  bool ss = (x+x==w && y+y==h);
  cout << aa*0.5 << " " << ss << endl;

}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    LL N, P;
    cin >> N >> P;
    LL ans = 1;
    for (LL i = 2; i * i <= P; i++)
    {
        LL cnt = 0;
        while (P % i == 0)
        {
            cnt++;
            P /= i;
        }
        if (cnt >= N)
        {
            REP0 (_, cnt / N)
            {
                ans *= i;
            }
        }
    }
    if (P > 1 && N == 1)
    {
        ans *= P;
    }

    std::cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXH 1000
#define MAXW 1000
#define MOD 1000000007

char grid[MAXH][MAXW+1];
int dp[MAXH][MAXW];
int h, w;


int main() {
  int i,j;
  int suma;
  int val;
  scanf("%d %d%*c",&h,&w);
  for (i=0; i<h; i++) {
    scanf("%s",grid[i]);
  }
  dp[0][0]=0;
  val=1;
  for (j=1; j<w; j++) {
    if (grid[0][j]=='.') {
      dp[0][j]=val;
    }
    else {
      dp[0][j]=-1; val=0;
    }
  }
  val=1;
  for (i=1; i<h; i++) {
    if (grid[i][0]=='.') {
      dp[i][0]=val;
    }
    else {
      dp[i][0]=-1; val=0;
    }
  }
  for (i=1; i<h; i++) {
    for (j=1; j<w; j++) {
      if (grid[i][j]!='#') {
        if (dp[i-1][j]==-1) {
          suma=0;
        }
        else {
          suma = dp[i-1][j];
        }
        if (dp[i][j-1]!=-1) {
          suma+=dp[i][j-1];
        }
        if (suma>MOD) {
          suma -= MOD;
        }
        dp[i][j]=suma;
      }
      else {
        dp[i][j]=-1;
      }
    }
  }

  /*for (i=0; i<h;i++) {
    printf("%d:%s\n",i,grid[i]);
  }
  for (i=0; i<h;i++) {
    for (j=0; j<w;j++) {
      printf("%5d", dp[i][j]);
    }
    printf("\n");
  }*/

  printf("%d\n",dp[h-1][w-1]);
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    int A[N], B[N-1];
    for (int i = 0; i < N-1; i++) {
        cin >> B[i];
    }

    for (int i = 0; i < N; i++) {
        if (i == 0) A[i] = B[0];
        else if (i == N-1) A[i] = B[i-1];
        else A[i] = min(B[i-1], B[i]);
    }

    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum += A[i];
    }

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

Measured memory_bytes: 256