akhauriyash/Code-Regression huggingface dataset:
////////////////////////////////////////////////////////////////
//
//    (☝ ՞ਊ ՞)☝ << Be accept!!
//
//    C++ format for competitive professional v1.0
//
//    need gcc & boost::c++
//
////////////////////////////////////////////////////////////////
#define BOOST
#define CGCC
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int66_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   //setfill(char)
#include <ios>       //left,right
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp> // cpp_int
using namespace boost::multiprecision;
#endif
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
#ifdef CGCC
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
int setup(void) { // set
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return 0;
}
int lenght(char *str) { // getcharlengh
  int i = 0;
  while (str[i]) {
    i++;
  }
  return i;
}
int gcd(long long a, long long b) {
  if (a < b)
    return gcd(b, a);
  long long r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
int iinput(void) {
  int a = 0;
  cin >> a;
  return a;
}
int dinput(void) {
  double a = 0;
  cin >> a;
  return a;
}
string sinput(void) {
  string a = "";
  cin >> a;
  return a;
}
int kuriup(double a) {
  int b = int(a);
  if (a != b) {
    return b + 1;
  } else {
    return b;
  }
}
int kuridown(double a) {
  int b = int(a);
  return b;
}
int run(void);
int main(){
  setup();
  run();
  return 0;
}
struct corr{
  ll y;
  ll x;
  ll depth;
};
int run(void){

  int a,b,c,ans=0;
  cin>>a>>b>>c;
  if(a==b)ans++;
  if(b==c)ans++;
  if(a==c)ans++;

  if(ans==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main (){
  int x,y,i,v;
  
  scanf("%d%d",&x,&y);

  if(x < 1 || y < 1 || x > 1000000000 || y > 1000000000){
    printf("Please type 1 to 1000000000.");
    exit(1);
  }

  if(x > y){
    v = x;
    x = y;
    y = v;
  }


    for(i=1; i<=x/2;i++){
      if(x%i == 0 && y%i == 0){
	v = i;
      }
    }
    if(x == y)v=x;
  
   
  printf("%d\n",v);
  
  
  return 0;
}




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

int main() {
  int N , K;
  cin >> N >> K;
  int goukei = 1;
  for (int i = 0; i < N; i++){
    if (goukei + K > goukei * 2){
      goukei *=  2;
    }else{
      goukei +=  K;
    }
  }
  cout << goukei << endl;
}


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

int main(){
  int n, sum;
  vector<int>vec;
  sum = 0;
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    int a; cin >> a; vec.push_back(a);
    sum ^= a;
  }
  for(int i = 0 ; i < vec.size() ; i++){
    if(i)cout << ' ';
    cout << (sum^vec[i]);
  }
  cout << endl;
  return 0;
}


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

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

    int cnt[2] = {0};
    vector<int> a(s.size());
    rep(i, s.size()) {
        if (s[i] == 'R')
            cnt[i % 2]++;
        else {
            a[i - 1] += cnt[1 - i % 2];
            a[i] += cnt[i % 2];
            cnt[0] = cnt[1] = 0;
        }
    }

    for (int i = s.size() - 1; i >= 0; --i) {
        if (s[i] == 'L')
            cnt[i % 2]++;
        else {
            a[i + 1] += cnt[1 - i % 2];
            a[i] += cnt[i % 2];
            cnt[0] = cnt[1] = 0;
        }
    }

    rep(i, a.size()) {
        if (i != 0)
            cout << " ";
        cout << a[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3820
def on_the_way(A: int, B: int, C: int)->bool:
    if A > B:
        A, B = B, A
    return A < C and C < B


if __name__ == "__main__":
    A, B, C = map(int, input().split())

    yes = on_the_way(A, B, C)
    print('Yes' if yes else 'No')


Measured memory_bytes: 2940
n,k = map(int,input().split())


v = list(map(int,input().split()))
res = -(10**-12)
#left
for left in range(min(n+1,k+1)):
    for right in range(min(n-left+1,k-left+1)):
        if right == 0:
            s = v[:left]
        else:
            s=v[:left]+v[-right:]
        s.sort()
        r = 0
        cnt = 0
        bound = k-left-right
        for i in s:
            if i<0 and cnt<bound:
                cnt+=1
            else:
                r+=i
        res = max(res,r) 
print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)

void search(int pos,bool *done,bool *edge_done,queue<int> &que,vector<pair<int,int>> *vec){
    pair<int,int> p;
    while(!vec[pos].empty()){
        p=vec[pos].back();
        vec[pos].pop_back();
        if(edge_done[p.second])continue;
        else{
            que.push(p.second);
            edge_done[p.second]=true;
            search(p.first,done,edge_done,que,vec);
        }
    }
    done[pos]=true;
}

int main(){
    int N,M;
    int L[200000],R[200000],D[200000];
    cin>>N>>M;
    rep(i,M) cin>>L[i]>>R[i]>>D[i];
    vector<pair<int,int>> vec[100000];
    rep(i,M){
        vec[L[i]-1].push_back(make_pair(R[i]-1,i));
        vec[R[i]-1].push_back(make_pair(L[i]-1,i));
    }
    queue<int> que;
    bool done[100000];
    bool edge_done[200000];
    rep(i,N){
        if(done[i]) continue;
        search(i,done,edge_done,que,vec);
    }
    bool fix[100000];
    ll pos[100000];
    int num;
    while(!que.empty()){
        num=que.front();
        que.pop();
        if(!fix[L[num]-1] && !fix[R[num]-1]){
            pos[L[num]-1]=0;
            pos[R[num]-1]=D[num];
            fix[L[num]-1]=true;
            fix[R[num]-1]=true;
        }else if( !fix[L[num]-1] ){
            pos[L[num]-1]=pos[R[num]-1]-D[num];
            fix[L[num]-1]=true;
        }else if(!fix[R[num]-1]){
            pos[R[num]-1]=pos[L[num]-1]+D[num];
            fix[R[num]-1]=true;
        }else{
            if((pos[R[num]-1]-pos[L[num]-1])!=D[num]) {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;

    
    return 0;
}


Measured memory_bytes: 23936
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(void) {
  int N, M, i, j, k, c, cnt, row;
  scanf("%d%d", &N, &M);
  char S[55][55]={0};
  for (i = 0; i < N; i++) {
    scanf("%s", S[i]);
  }
  int ans = 999999;
  for (i = 1; i <= N-2; i++) {
    for (j = 1; i+j <= N-1; j++) {
      cnt = 0;
      row = 0;
      for (k = 0; k < i; k++) {
        for (c = 0; c < M; c++) {
          if (S[row][c] != 'W') cnt++;
        }
        row++;
      }
      for (k = 0; k < j; k++) {
        for (c = 0; c < M; c++) {
          if (S[row][c] != 'B') cnt++;
        }
        row++;
      }
      for (k = 0; k < N-i-j; k++) {
        for (c = 0; c < M; c++) {
          if (S[row][c] != 'R') cnt++;
        }
        row++;
      }
      if (cnt < ans) ans = cnt;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

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

    string ans;

    for(int i = 0; i < (int)s.size(); i++){
        if(s[i] == '0'){
            ans += "0";
        }
        else if(s[i] == '1'){
            ans += "1";
        }
        else if(!ans.empty()){

            ans.pop_back();
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define MAX 100005
#define NIL -1
struct Node_struct {
    int parent, left, right;
};
typedef struct Node_struct Node;
Node tree[MAX];
int n, depth[MAX];

void print(int u)
{
    int i, c;
    printf("node %d: parent = %d, depth = %d, ", u, tree[u].parent, depth[u]);
    if (tree[u].parent == NIL)
        printf("root, ");
    else if (tree[u].left == NIL)
        printf("leaf, ");
    else
        printf("internal node, ");
    printf("[");
    for (i = 0, c = tree[u].left; c != NIL; i++, c = tree[c].right) {
        if (i)
            printf(", ");
        printf("%d", c);
    }
    printf("]\n");
}

// 再帰的に深さを求める
void setDepth(int u, int parent)
{
    depth[u] = parent; // 最初は0
    if (tree[u].left != NIL) // 最も左の子に自分の深さ+1
        setDepth(tree[u].left, parent + 1);
    if (tree[u].right != NIL) // 右の兄弟に同じ深さを設定
        setDepth(tree[u].right, parent);
}

int main()
{
    int i, j, k;
    int N;
    int id, sib, child;
    int root = NIL;
    cin >> N;
    // 全ての節点の親,左右兄弟をNILで初期化する
    for (i = 0; i < N; i++)
        tree[i].parent = tree[i].left = tree[i].right = NIL;

    for (i = 0; i < N; i++) {
        cin >> id >> k;
        // tree[id]にはkだけ子供がいる
        for (j = 0; j < k; ++j) {
            cin >> child;
            if (j == 0) { // 最初の子供は左
                tree[id].left = child;
            } else {
                // tree[sib]はparentが同じ
                // あるid=tree[i].leftからsib=tree[id]にいけ
                // val=tree[sib].rightからいけるtree[val].rightがNILでないのは全て兄弟
                tree[sib].right = child;
            }
            sib = child;
            tree[child].parent = id;
        }
    }

    for (i = 0; i < N; i++) {
        if (tree[i].parent == NIL)
            root = i;
    }
    setDepth(root, 0);
    for (i = 0; i < N; i++)
        print(i);

    return 0;
}



Measured memory_bytes: 4660
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.util.function.DoubleToLongFunction;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		int[] A = new int[N];
		double sum = 0;
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
			sum += A[i];
		}
		sum /= N;
		
		double dist = Double.MAX_VALUE;
		int ans = N-1;
		for(int i = 0; i < N; i++){
			if(Math.abs(sum - A[i]) < dist){
				dist = Math.abs(sum - A[i]);
				ans = i;
			}
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int N, num, a, b;
vector<int> h(100010);

vector<int> dp(100010);

int main() {
	cin >> N;
  for (int i = 0; i < N; i++) cin >> h[i];
  //num = N - 1;
  dp[1] = abs(h[1] - h[0]);
  for (int i = 2; i < N; i++) {
    dp[i] = min((abs(h[i] - h[i-1]) + dp[i - 1]), (abs(h[i] - h[i-2]) + dp[i - 2]));
  }
  cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, N;
    cin >> H >> N;
    int A[N], B[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }
    long long dp[N + 1][H + 1];
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= H; j++) {
            dp[i][j] = LLONG_MAX / 10;
        }
    }
    for(int i = 1; i <= N; i++) {
        dp[i][0] = 0;
        for(int j = 1; j <= H; j++) {
            dp[i][j] =
                min(dp[i][max(0, j - A[i - 1])] + B[i - 1], dp[i - 1][j]);
        }
    }
    cout << dp[N][H] << endl;
    return 0;
}


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

int main() {

    std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

    int min = 124, max = -1;
    int antenna;
    int k = 0;
    for (int i = 0; i < 5; ++i) {
        std::cin >> antenna;
        min = std::min(min, antenna);
        max = std::max(max, antenna);
    }
    std::cin >> k;
    std::cout << (max - min <= k ? "Yay!" : ":(") << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <stack>


using namespace std;
typedef long long LL;
const int MaxN = 1e6 + 5;
const int Mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double esp = 1e-6;

LL n,k;


int main(){
    cin >> n >> k;
    if(n > k)n = n%k;
    cout << min(n,abs(n-k)) << endl;
    return 0 ;
}


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

const int INF = 1 << 30;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int N, W;
ll dp[105][100005]; //---- dp[n][w]: 重さw以下で、初めのn個の品物のみを使った場合の最大価値
int w[105]; ll v[105];

int main(){
    cin >> N >> W;
    rep(i,N) cin >> w[i+1] >> v[i+1];

    //初期化
    for(int n=0; n<105; ++n){
        for(int wei=0; wei<100005; wei++){
            dp[n][wei] = 0;
        }
    }
    for(int wei=0; wei<=W; ++wei){
        for(int n=0; n<N; ++n){
            int weight = w[n+1];
            if(wei + weight <= W){
                chmax(dp[n+1][wei+weight], dp[n][wei] + v[n+1]);
            }
            chmax(dp[n+1][wei], dp[n][wei]);
            // cout << "dp[" << n+1 << "][" << wei+1 << "]: " << dp[n+1][wei] << endl;
        }
    }   

    cout << dp[N][W];
	return 0;
}

Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli n;

int main(void){
    cin >> n;
    vector<lli> a(n);
    vector<lli> s(n+1);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    rep(i, n){
        s[i+1] = s[i]+a[i];
    }
    vector<lli> ans;
    rep(i, n){
        if(2*s[i] < a[i]){
            ans.clear();
        }
        ans.push_back(i);
    }
    cout << ans.size() << endl;
    return 0;
}


Measured memory_bytes: 5888
import Control.Monad
import Data.List
import Data.Maybe
import Data.Bits

query :: Int -> [Int] -> Int
query m = sum . map ((\n -> (n * (n-1)) `div` 2) . length)
  . group . sort . scanl (\x y -> (x + y) `mod` m) 0 

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  ais <- map read . words <$> getLine
  putStrLn $ show $ query m ais

Measured memory_bytes: 38268
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    double v[n];
    rep(i, n) {
        cin >> v[i];
    }
    sort(v, v+n);

    double ans = v[0];

    for(int i = 1; i < n; i++) {
        ans += v[i];
        ans /= 2.0;
    }

    printf("%.10f\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
/* author : akshatjai258 */
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define int ll
#define mod int(1e9 + 7)
#define inf int(1e9)
#define endl "\n"
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define fi first
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define memf(a) memset(a, false, sizeof(a))
#define all(v) v.begin(), v.end()
#define se second
#define mp make_pair
#define pb push_back
#define w(x)  \
	int x;    \
	cin >> x; \
	while (x--)
#define ps(x, y) fixed << setprecision(y) << x
void prep()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
}
int32_t main()
{
	prep();
	string s;
	cin>>s;
	if(s=="ABC") cout<<"ARC";
	else cout<<"ABC";
	return 0;
}


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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)                                                             \
  sort(x.begin(), x.end());                                                    \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y)                                                           \
  cerr << "(" << #x << ", " << #y << ") = "                                    \
       << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  long double a,b;
  cin >> a >> b;

  ll ans = ll(a*b);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3740
n=int(input())

alphabet=[None] + [chr(i) for i in range(97,97+26)]

rest=[]
while n!=0:
    rest.append(n%26)
    n = n // 26
rest.reverse()

for i in range(len(rest)-1):
    if rest[len(rest)-1-i]<=0:
        rest[len(rest)-1-i]+=26
        rest[len(rest)-2-i]-=1
if rest[0]<=0:
    rest=rest[1:]

ans=''
for i in range(len(rest)):
    ans+=alphabet[rest[i]]
print(ans)


Measured memory_bytes: 9240
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int h,w;
  cin>>h>>w;
  char s[h][w];
  for(int i = 0; i<h; i++){
    for(int j = 0; j<w; j++){
      cin>>s[i][j];
    }
  }
  bool ans = true;
  for(int i = 0; i<h; i++){
    for(int j = 0; j<w; j++){
      bool f[4] = {true,true,true,true};
      if(i>0){
        if(s[i][j]=='#'&&s[i-1][j]=='.') {
          f[0] = false;
        }
      }
      if(i<h-1){
        if(s[i][j]=='#'&&s[i+1][j]=='.') {
          f[1] = false;
        }
      }
      if(j>0){
        if(s[i][j]=='#'&&s[i][j-1]=='.') {
          f[2] = false;
        }
      }
      if(i<w-1){
        if(s[i][j]=='#'&&s[i][j+1]=='.') {
          f[3] = false;
        }
      }
      if(f[0]||f[1]||f[2]||f[3]) ;
      else {
        ans = false;
        break;
      }
    }
  }

  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
int main(){
    long long n, k;
    scanf("%lld%lld", &n, &k);
    if(k == 1){
        printf("0\n");
    }else if(n>k){
        if(n%k == 0){
            printf("0\n");
        }else{
            printf("%lld\n", n%k<(k-n%k)?n%k:(k-n%k));
        }
    }else if(n==k){
        printf("0\n");
    }else{ // n<k
        printf("%lld\n", n<(k-n)?n:k-n);
    }
    
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define up(x,y) (x<(y)?x=(y):0)
#define N 109
using namespace std;

int m,n,ans,tx,ty,dp[2][N][N][N],s[N][N];
char ch[N][N];
void ins(int i,int j,int k,int l,int v){
	up(ans,v);
	if (i<=j && k<=l) up(dp[i&1][j][k][l],v);
}
int S(int x1,int y1,int x2,int y2){
	if (x1>x2 || y1>y2) return 0;
	return s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1];
}
int main(){
	scanf("%d%d",&m,&n);
	int i,j,k,l,u,d,x,y,tmp;
	for (i=1; i<=m; i++){
		scanf("%s",ch[i]+1);
		for (j=1; j<=n; j++){
			if (ch[i][j]=='E'){
				tx=i; ty=j;
			}
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(ch[i][j]=='o');
		}
	}
	for (i=1; i<=m; i++){
		memset(dp[!(i&1)],0,sizeof(dp[i&1]));
		for (j=m; j>=i; j--)
			for (k=1; k<=n; k++)
				for (l=n; l>=k; l--){
					tmp=dp[i&1][j][k][l];
					u=max(1,tx-(m-j)); d=min(m,tx+(i-1));
					x=max(1,ty-(n-l)); y=min(n,ty+(k-1));
					if (u<=i && i<=d)
						ins(i+1,j,k,l,tmp+S(i,max(k,x),i,min(l,y)));
					if (u<=j && j<=d)
						ins(i,j-1,k,l,tmp+S(j,max(k,x),j,min(l,y)));
					if (x<=k && k<=y)
						ins(i,j,k+1,l,tmp+S(max(i,u),k,min(j,d),k));
					if (x<=l && l<=y)
						ins(i,j,k,l-1,tmp+S(max(i,u),l,min(j,d),l));
				}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 10368
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    A_1 = list(map(int, input().split()))
    logging.info("Hello!")

    sum = 0
    for i in A_1:
        sum += (1 / i)


    print(1 / sum)
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 4212
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] nums = new int[n];
		
		for(int i=0; i<n; i++) {
			nums[i] = sc.nextInt();
		}
		int cnt = 1;
		int flag = 0;
		for(int i=1; i<n; i++) {
			for(int j=0; j<i; j++) {
				if(nums[j]<=nums[i]) {
					flag = 1;
				}else {
					flag = 0;
					break;
				}
			}
			if(flag == 1) {
				cnt++;
			}
		}
		System.out.println(cnt);
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>


int main()
{
    int n,q;
    std::cin>>n;
    std::vector<long long> a;

    for(int i = 0; i < n; i++)
    {
        int hoge;
        std::cin>>hoge;
        a.push_back(hoge);
    }

    std::cin>>q;

    for(int i = 0; i < q; i++)
    {
        int k;
        std::cin>>k;
        std::cout <<std::lower_bound(a.begin(), a.end(),k)-a.begin()<<" ";
        std::cout <<std::upper_bound(a.begin(), a.end(),k)-a.begin()<< std::endl;
    }
    return 0;
}



Measured memory_bytes: 3948
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	A := make([]int, N)
	B := make([]int, N)
	C := make([]int, N-1)
	for i := 0; i < N; i++ {
		A[i] = sc.nextInt() - 1
	}
	for i := 0; i < N; i++ {
		B[i] = sc.nextInt()
	}
	for i := 0; i < N-1; i++ {
		C[i] = sc.nextInt()
	}
	point := 0
	before := -100
	for _, dish := range A {
		point += B[dish]
		if dish == before+1 {
			point += C[dish-1]
		}
		before = dish
	}
	fmt.Println(point)
}


Measured memory_bytes: 640
n, m , x = map(int, input().split())
c, a = [], []
for _ in [0]*n:
    temp = list(map(int, input().split()))
    c.append(temp[0])
    a.append(temp[1:])

sign = (1, 0)

ans = float("inf")
import numpy as np
from itertools import product
for i in product(sign, repeat = n):
    temp = np.zeros(m)
    cc = 0
    for j in range(n):
        tt = a[j]
        if i[j] == 1:
            temp += tt
        cc += c[j] * i[j]

    if np.all(temp >= x):
        ans = min(ans, cc)

print(ans if ans != float("inf") else -1)

Measured memory_bytes: 27236
#!/usr/bin/env pypy3
import bisect
import sys
def input(): return sys.stdin.readline().rstrip()
 
 
def is_ok(arg, sei, hu, k):
    # 条件を満たすかどうか？問題ごとに定義
    count = 0
    for index, NN in enumerate(sei, 1):
        if NN==0:
            count+=len(sei)-index
        else:
            if NN**2 >= arg:
                break
            count += bisect.bisect_right(sei, ((arg)//NN))-index  # n以下の個数を数える
    for index, NN in enumerate(hu, 1):
        if NN**2 >= arg:
            break
        count += bisect.bisect_right(hu, ((arg)//NN))-index  # n以下の個数を数える
    return count >= k
 
 
def meguru_bisect(ng, ok, sei, hu, k):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, sei, hu, k):
            ok = mid
        else:
            ng = mid
    return ok
 
 
def is_ok2(arg, sei, hu, k):#seiとhuの組み合わせで-arg以上の数がk個あるか？
    # 条件を満たすかどうか？問題ごとに定義
    count = 0
    hulen=len(sei)
    for NN in hu:
        count += hulen-bisect.bisect_right(sei, ((-arg)-1)//NN)#n未満の個数を数える
    return count >= k
 
def meguru_bisect2(ng, ok, sei, hu, k):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid, sei, hu, k):
            ok = mid
        else:
            ng = mid
    return ok
 
def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    sei = []
    hu = []
    for AA in A:
        if AA >= 0:
            sei.append(AA)
        else:
            hu.append(-AA)
    sei.sort()
    hu.sort()
    seinum = len(sei)
    hunum = len(hu)
    if seinum*hunum < k:
        ans=meguru_bisect(-1, 10**18, sei, hu, k-seinum*hunum)
    else:
        ans=meguru_bisect2(-1*10**18, 0, sei, hu, k)
    print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 106196
#include "bits/stdc++.h"

using namespace std;

void solve()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> cnt(n);
    for (int i = 0; i < q; i++)
    {
        int x;
        cin >> x;
        cnt[x - 1]++;
    }
    for (int i = 0; i < n; i++)
    {
        if (k - (q - cnt[i]) > 0)
        {
            cout << "Yes" << '\n';
        }
        else
        {
            cout << "No" << '\n';
        }
    }
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 1024
s = gets
a = s.slice(0..3).to_i
b = s.slice(5..6).to_i
c = s.slice(8..9).to_i
if b.size == 2 then
    b = b.slice(1)
end
if a <= 2019 and b <= 4 then
    puts "Heisei"
else
    puts "TBD"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)



int main (){
  ll n,m;
  cin>>n>>m;

  if(n>=m/2){
    cout<<m/2<<endl;
  }else{
    m=m-2*n;

    cout<<n+m/4<<endl;

  }

  return 0;
}


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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int p[8], num[8] = {1, 2, 1, 2, 1, 4, 1, 4};
  while (cin >> p[0]) {
    for (int i = 1; i < 8; i++) {
      cin >> p[i];
    }
    int ans = -1, d_min = 1 << 30;
    for (int i = 0; i < 8; i++) {
      int d = 0;
      for (int j = 0; j < 8; j++) {
        d += max(0, p[j] - num[(i + j) % 8]);
      }
      if (d < d_min) d_min = d, ans = i;
      else if (d == d_min) {
        for (int j = 0; j < 8; j++) {
          int l = (i + j) % 8, r = (ans + j) % 8;
          if (num[l] == num[r]) continue;
          if (num[l] < num[r]) ans = i;
          break;
        }
      }
    }
    for (int i = 0; i < 8; i++) {
      cout << num[(i + ans) % 8] << " \n"[i + 1 == 8];
    }
  }

  return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <float.h>
#include <stdio.h>
#include <math.h>
#define REP(i,n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
    int n, R[10001], max = -10000001, min = 10000001;
    long long sum = 0;

    cin >> n;
    REP(i, n) cin >> R[i];

    REP(i, n) {
        if (fmax(max, R[i]) == R[i]) max = R[i];
        if (fmin(min, R[i]) == R[i]) min = R[i];
        sum = sum + R[i];
     }  
    cout << min << " " << max << " " << sum << endl;
    return 0;

}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
const int mex = (1<<12);
int n, m;
 
int dp[mex+5][1005];
vector <int> boxes[1005];
int cost[1005];
 
void initialize(){
    for(int i = 0; i < (1<<12); i++){
        for(int j = 0; j <= 1000; j++){
            dp[i][j] = -1;
        }
    }
}
 
int set_bits(int n){
    int res = 0;
    
    while(n){
          res+=(n&1);
          n>>=1;
    }
    
    return res;
}
 
int solve(int mask, int ind){
    
    if(set_bits(mask) == n){
        return 0LL;
    }
    if(ind > m){
        return 1000000000000LL;
    }
    
    int &cache = dp[mask][ind];
    
    if(cache != -1){
        return cache;
    }
    
    int temp1 , temp2;
    
    temp2 = solve(mask, ind + 1);
    
    for(auto i : boxes[ind]){
            mask |= (1<<(i-1));
    }
    
    temp1 = cost[ind] + solve(mask, ind + 1);
    
    return(cache = min(temp1, temp2));
}
 
 
signed main(){
      initialize();
     
      int x, y;
      cin >> n >> m;
      
      for(int i = 1; i <= m; i++){
          cin >> cost[i] >> x;
          while(x--){
              cin >> y;
              boxes[i].push_back(y);
          }
      }
      
      int ans = solve(0, 1);
      
      if(ans >= 1000000000000LL){
          cout << "-1\n";
      }
      else{
          cout << ans << '\n';
      }
}
 

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;

int N,T;
int D[100000];
int dp[100010];

signed main(){
    scanf("%lld%lld",&N,&T);
    rep(i,N)scanf("%lld",&D[i]);
    sort(D,D+N);
    dp[0]=1;
    int l=0;
    rep(i,N){
        while(D[l]+T<D[i])l++;
        dp[i+1]=dp[i]*(i-l+1)%mod;
    }
    printf("%lld\n",dp[N]);

    return 0;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int d[10][10];

void warshall_floyd(int V){
  for(int k=0; k<V;k++)
    for(int i=0; i<V;i++)
      for(int j=0; j<V;j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main(void)
{
    int a[201][201];
    int H,W;cin>>H>>W;
    for(int i=0; i<=9;i++)
      for(int j=0; j<=9;j++) cin>>d[i][j];

    for(int i=0; i<H;i++)
        for(int j=0; j<W;j++) cin>>a[i][j];

    warshall_floyd(10);
    int ans=0;
    for(int i=0; i<H;i++){
        for(int j=0; j<W;j++){
          if(a[i][j] != -1){
            ans += d[a[i][j]][1];
          }
        }
    }

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


Measured memory_bytes: 384
// https://atcoder.jp/contests/dp/tasks/dp_a

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    vector<int> dp(N);
    vector<int> cost(K);
    rep(i,N) cin >> h[i];

    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for(int i=2;i<N;i++){
        int m = 999999999;
        for(int j=1;j<=K;j++){
            if((i-j)<0){
               continue;
            }else{
                cost[j] = abs(h[i]-h[i-j]);
            }
            if(m>dp[i-j]+cost[j]){
                m = dp[i-j]+cost[j];
            }
        }
        dp[i] = m;
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k;
    cin>>n>>k;
    vector<long long int> v(n,0);
    for(long long int i=0;i<n;i++)
    {
        long long int value;
        cin>>value;
        v[i]=value;
    }
    long long int dp[n];
    for(int i=0;i<n;i++)
    {
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(long long int i=2;i<n;i++)
    {
        for(int j=i-1;j>=0&&j>=i-k;j--)
        {
            dp[i]=min(dp[i],abs(v[i]-v[j])+dp[j]);
        }
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

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

		int x=-1;
		int y=-1;
		int z=-1;
		
		int k;
		if(10000*1>=N){
			for(int i=0;i<=N;i++){
				for(int j=0;j<=N-i;j++){
					k=N-i-j;
					if(i+j+k==N&&10000*i+5000*j+1000*k==Y){
						x=i;
						y=j;
						z=k;
						System.out.println(x+" "+y+" "+z);
						i=N;
						j=N;
						k=N;
					}
				}
			}
		}
		if(x==-1){
			System.out.println(x+" "+y+" "+z);
		}
	}
}


Measured memory_bytes: 22996
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    XYH = [NLI() for _ in range(N)]
    XYH.sort(key= lambda x: x[2], reverse=True)
    H = 10**10
    for cx in range(101):
        for cy in range(101):
            is_badc = False
            for i, xyh in enumerate(XYH):
                x, y, h = xyh
                if i == 0:
                    H = h + abs(cx - x) + abs(cy - y)
                else:
                    if max(H - abs(cx-x) - abs(cy-y), 0) != h:
                        is_badc = True

            if not is_badc:
                print(cx, cy, H)
                exit()



if __name__ == "__main__":
    main()

Measured memory_bytes: 9472
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;
const int N = 1e6 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
const int LN = 22;

long long n, m, u, v, k, t, q, x, d, p, a, b, c, s;


long long arr[N];
long long brr[N];

long long isPoss(int div) {
   for (int i = 1; i <= n; ++i) {
      brr[i] = arr[i] % div;
   }
   
   sort(brr + 1, brr + 1 + n);
   
   long long pref = 0;
   int cur = 1;
   while (cur <= n and brr[cur] + pref <= k) {
      pref += brr[cur];
      cur++;
   }
   long long suff = 0;
   
   for (int i = n; i >= cur; --i) suff += (div - brr[i]);
   
   if (suff <= k) return true;
   else return false;
}
int main() {
   ios::sync_with_stdio(false);cin.tie(0);
   cin >> n >> k;
   long long sum = 0;
   for (int i = 1; i <= n; ++i) {
      cin >> arr[i];
      sum += arr[i];
   }
   
   long long best = 1;
   
   for (long long div = 1; div * div <= sum; ++div) {
      if (sum % div == 0) {
         if (isPoss(div)) best = max(best, div);
         if (isPoss(sum / div)) best = max(best, sum / div);
      }
   }
   
   cout << best << endl;
}


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

int min( int a, int b )
{
    if( a < b )
        return a;
    else
        return b;
}

int main()
{
    int a, b, c, d, p;
    cin >> a >> b >> c >> d >> p;

    if( c < p )
        cout << min( a * p, b + ( p - c ) * d ) << endl;
    else
        cout << min( a * p, b ) << endl;

    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  int a[4];
  rep(i, 4) a[i] = 0;
  string s;
  rep(i, n){
    cin >> s;
    if(s == "AC") a[0]++;
    else if(s == "WA") a[1]++;
    else if(s == "TLE") a[2]++;
    else a[3]++;
  }
  cout << "AC x " << a[0] << endl;
  cout << "WA x " << a[1] << endl;
  cout << "TLE x " << a[2] << endl;
  cout << "RE x " << a[3] << endl;
  return 0;
}


Measured memory_bytes: 3628
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    use std::collections::HashSet;
    let mut set = HashSet::new();
    let mut big_user_num = 0;
    for _ in 0..N {
        let v: usize = read();
        let quot = v / 400;
        if quot <= 7 {
            set.insert(quot);
        } else {
            big_user_num += 1;
        }
    }
    println!(
        "{} {}",
        std::cmp::max(set.len(), 1),
        set.len() + big_user_num
    );
}


Measured memory_bytes: 4352
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (H, W, N) = read!(usize, usize, usize);
    let (Y, X) = read!(usize, usize);
    let S = rl().chars().collect::<Vec<_>>();
    let T = rl().chars().collect::<Vec<_>>();

    let mut ok = true;

    for &negative in &['L', 'R', 'U', 'D'] {
        let (start, end, positive) = match negative {
            'L' => (X, W, 'R'),
            'R' => (W - X + 1, W, 'L'),
            'U' => (Y, H, 'D'),
            'D' => (H - Y + 1, H, 'U'),
            _ => unreachable!(),
        };

        let mut x = start;
        for i in 0..N {
            if S[i] == negative {
                x -= 1;
            }
            if x == 0 {
                // debug!((start, end, positive, negative, i));
                ok = false;
                break;
            }
            if T[i] == positive && x + 1 <= end {
                x += 1;
            }
        }
    }

    println!("{}", if ok { "YES" } else { "NO" })
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int r,c,n;
int jud(int x,int y){
  if(x==0||x==r||y==0||y==c)return 1;
  else return 0;
}
int main(){
  cin>>r>>c>>n;
  int x1[n],y1[n],x2[n],y2[n];
  vector<int> v;
  for(int i=0;i<n;i++){
    cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
    if(jud(x1[i],y1[i])==1&&jud(x2[i],y2[i])==1){
      v.push_back(i);
    }
  }
  vector<int> w;
  vector<pii> vv;
  for(int i=0;i<v.size();i++){
    int now=v[i];
    if(x1[now]==0){
      vv.push_back(make_pair(y1[now],i));
    }
    if(x2[now]==0){
      vv.push_back(make_pair(y2[now],i));
    }
  }
  sort(vv.begin(),vv.end());
  for(int i=0;i<vv.size();i++)w.push_back(vv[i].second);
  vv={};
  for(int i=0;i<v.size();i++){
    int now=v[i];
    if(y1[now]==c&&x1[now]>0){
      vv.push_back(make_pair(x1[now],i));
    }
    if(y2[now]==c&&x2[now]>0){
      vv.push_back(make_pair(x2[now],i));
    }
  }
  sort(vv.begin(),vv.end());
  for(int i=0;i<vv.size();i++)w.push_back(vv[i].second);
  vv={};
  for(int i=0;i<v.size();i++){
    int now=v[i];
    if(x1[now]==r&&y1[now]<c){
      vv.push_back(make_pair(y1[now],i));
    }
    if(x2[now]==r&&y2[now]<c){
      vv.push_back(make_pair(y2[now],i));
    }
  }
  sort(vv.begin(),vv.end(),greater<pii>());
  for(int i=0;i<vv.size();i++)w.push_back(vv[i].second);
  vv={};
  for(int i=0;i<v.size();i++){
    int now=v[i];
    if(y1[now]==0&&x1[now]<r&&x1[now]>0){
      vv.push_back(make_pair(x1[now],i));
    }
    if(y2[now]==0&&x2[now]<r&&x2[now]>0){
      vv.push_back(make_pair(x2[now],i));
    }
  }
  sort(vv.begin(),vv.end(),greater<pii>());
  for(int i=0;i<vv.size();i++)w.push_back(vv[i].second);
  int pla[v.size()];
  for(int i=0;i<w.size();i++){
    pla[w[i]]=i;
  }
  int inf=1000000000;
  int l=pla[w[0]],ri=inf;
  vector<int> g;
  for(int i=0;i<v.size();i++)g.push_back(pla[i]);
  sort(g.begin(),g.end());
  set<int> st;
  for(int i=0;i<w.size();i++){
    if(pla[w[i]]==i){
      auto itr=st.find(i);
      itr++;
      if(itr==st.end())ri=inf;
      else ri=*itr;
    }
    else{
      if(pla[w[i]]<=ri){
        ri=pla[w[i]];
        st.insert(pla[w[i]]);
      }
      else{
        cout<<"NO"<<endl;
        return 0;
      }
    }
  }
  cout<<"YES"<<endl;
}
  
  
  
  

Measured memory_bytes: 8820