akhauriyash/Code-Regression huggingface dataset:
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1001001001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

queue<long long> Q;

long long lunlun(int N,int count){
    long long num = Q.front();
    Q.pop();
    count++;
    int lastdigit = num%10;
    if(count == N) return num;
    if(lastdigit != 0) Q.push(num*10+lastdigit-1);
    Q.push(num*10+lastdigit);
    if(lastdigit != 9) Q.push(num*10+lastdigit+1);
    lunlun(N,count);
}

int main() {
    int N;cin >> N;
    for(int i = 1;i<=9;i++){
        Q.push(i);
    }

    cout << lunlun(N,0) << endl;

    // PLEASE GIVE ME THE "ACCEPTED" !
}

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

int main(){
  std::string str;
  std::cin >> str;
  unsigned i;
  for(i = (str.length() + 1)/2; i < str.length(); i++){
    if(str[i] != str[i - 1] || str[str.length() - i] != str[str.length() - i - 1]){
		std::cout << i << std::endl;
		return 0;
	}
  }
  std::cout << i << std::endl;
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int H, W;
vector<string> a;
vector<vector<ll>> cnt;
int main(){
  const int mod = 1e9+7;
  cin >> H >> W;
  a.resize(H), cnt.resize(H+1, vector<ll>(W+1, 0));
  REP(i, H){
    cin >> a[i];
  }
  cnt[0][0] = 1;
  REP(i, H){
    REP(j, W){
      if(j+1 < W && a[i][j+1] == '.'){
        cnt[i][j+1] += cnt[i][j];
        cnt[i][j+1] %=mod;
      }
      if(i+1 < H && a[i+1][j] == '.'){
        cnt[i+1][j] += cnt[i][j];
        cnt[i+1][j] %= mod;
      }
    }
  }
  cout << cnt[H-1][W-1] << endl;
  
  return 0;
}


Measured memory_bytes: 9216
var
	N,M,i,p,j,ans,t:Longint;
	s:String;
	c:Array[1..100000]of Longint;
begin
	readln(N,M);
	for i:=1 to M do begin
		readln(s);
		p:=0;
		j:=1;
		while s[j]<>' 'do begin
			p:=p*10+ord(s[j])-48;
			inc(j);
		end;
		inc(j);
		if s[j]='A'then begin
			if c[p]>=0 then begin
				inc(ans,c[p]);
				inc(t);
			end;
			c[p]:=-1;
		end else begin
			if c[p]>=0 then inc(c[p]);
		end;
	end;
	writeln(t,' ',ans);
end.


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	/** 7 */
	private static final int SEVEN = 7;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] abcd = scanner.next().toCharArray();
			for (int i = 0; i < (1 << abcd.length); i++) {
				if (ok(abcd, i)) {
					System.out.println(toFormula(abcd, i) + "=" + SEVEN);
					return;
				}
			}
		}
	}

	/**
	 * abcdと'+'か'-'を表す二進数で数式を組み立てて、結果が7かどうかを判定
	 * 
	 * @param abcd
	 * @param n    '+'か'-'を表す二進数
	 * @return 結果が7かどうか
	 */
	private static boolean ok(char[] abcd, int n) {
		int result = abcd[0] - '0';
		for (int i = 1; i < abcd.length; i++) {
			if (1 == (n & 1)) {
				result += abcd[i] - '0';
			} else {
				result -= abcd[i] - '0';
			}
			n >>= 1;
		}
		return SEVEN == result;
	}

	/**
	 * abcdと'+'か'-'を表す二進数で数式を組み立てる
	 * 
	 * @param abcd
	 * @param n    '+'か'-'を表す二進数
	 * @return a?b?c?d の数式
	 */
	private static String toFormula(char[] abcd, int n) {
		StringBuilder result = new StringBuilder();
		for (char c : abcd) {
			result.append(c);
			result.append((1 == (n & 1)) ? '+' : '-');
			n >>= 1;
		}
		// 最後の文字を削除
		result.deleteCharAt(result.length() - 1);
		return result.toString();
	}
}


Measured memory_bytes: 38704
#include <algorithm>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cstring>

using namespace std;

typedef long long    ll;
typedef long double  ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;

template <typename T> bool chmax(T &a, T& b) {if (a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, T& b) {if (a > b) {a = b; return true;} return false;}
#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define mset(x, val) memset(x,(val),sizeof(x))
#define cons(a, b) make_pair((a), (b))
#define car first
#define cdr second

#define endl '\n'
#define INF  0x7f7f7f7f7f7f7f7f
#define INFi 0x7f7f7f7f


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

pll solve(int N, const vector<ll> & a) {
  int joker = false;
  bitset<8> res(0);
  rep(i, N) {
    int inx = a[i]  < 400 ? 0
              : a[i]< 800 ? 1
              : a[i]<1200 ? 2
              : a[i]<1600 ? 3
              : a[i]<2000 ? 4
              : a[i]<2400 ? 5
              : a[i]<2800 ? 6
              : a[i]<3200 ? 7 : 8;
    if (inx != 8) res[inx]=1;
    else joker++;
  }
  ll mincolor = res.count()!=0 ? res.count() : 1;
  ll maxcolor = res.count()+joker;
  return cons(mincolor, maxcolor);
}

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

  int N;
  cin >> N;
  vector<ll> a(N);
  rep (i, N) {
    cin >> a[i];
  }

  auto ans = solve(N, a);
  // failed to analyze output format
  // TODO: edit here
  cout << ans.car << " " << ans.cdr << endl;

  return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#include <queue>
using namespace std;
int main(){
	long long int ans = 0; 
	int R, G, B, N; cin >> R >> G >> B >> N; 
	for(int r = 0; r <= 3010; r++){
		for(int g = 0; g <= 3010; g++){
			if(N - r * R - g * G >= 0 && (N - r * R - g * G) % B == 0){
				ans ++; 
			}
		}
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define vll vector<ll>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {x++;}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){if(n<k)return 0;if(n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

void solve(ll N, vector<ll> h){
    vll cost(N, LLONG_MAX);
    cost.at(0) = 0, cost.at(1) = abs(h.at(1) - h.at(0));

    rep2(i, 2, N - 1) {
        ll plan_1 = cost.at(i - 1) + abs(h.at(i) - h.at(i - 1));
        ll plan_2 = cost.at(i - 2) + abs(h.at(i) - h.at(i - 2));
        cost.at(i) = min(plan_1, plan_2);
    }
    printf("%lld\n", cost.at(N - 1));
}

int main() {
    ll N;
    ignore_ret(scanf("%lld",&N));
    vector<ll> h(N);
    for(int i = 0 ; i < N ; i++){
        ignore_ret(scanf("%lld",&h[i]));
    }
    solve(N, move(h));
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int a[10],t1=0,t2=0,min1=0,min2=0,k=0;
		for(int i=0;i<10;i++)
		scanf("%d",&a[i]);
		for(int i=0;i<10;i++)
		{
			t1=a[i]-min1;
            t2=a[i]-min2;
			if(t1<0&&t2<0)
			   {
			   	   k=1;
			   	   break;
			   }
			if(t2>=t1&&t1>0)
			min1=a[i];
			else 
			min2=a[i];
		}
		if(k==1)	printf("NO\n");
		else 	  	printf("YES\n");
	}
	return 0;
}


Measured memory_bytes: 2032
#include<iostream>
#include<map>
#include<list>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}

// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
  for(const pair<S,T>& x: mp){
    cout << "[" << x.first << "]=" << x.second << " ";
  }
  return os;
}

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

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

int legal(pair<int,int> p,vector<vector<int>>& maze){
  int h=maze.size(),w=maze[0].size();
  int x=p.first,y=p.second;
  return (0<=x) and (x<h) and (0<=y) and (y<w) and maze[x][y];
}

void moveA(pair<int,int> tmp,vector<vector<int>>& cnt,list<pair<int,int>>& que,vector<vector<int>>& maze){
  if(df)print("moveA");
  rep(i,4){
    pair<int,int> next;
    next.first=tmp.first+dx[i];
    next.second=tmp.second+dy[i];
    if(legal(next,maze)){
      if(cnt[next.first][next.second]!=-1 and cnt[next.first][next.second] <= cnt[tmp.first][tmp.second]) continue;
      que.push_front(next);
      cnt[next.first][next.second]=cnt[tmp.first][tmp.second];
      maze[next.first][next.second]=0;
    }
  }
  if(df)print(que);
}

void moveB(pair<int,int> tmp,vector<vector<int>>& cnt,list<pair<int,int>>& que,vector<vector<int>>& maze){
  pair<int,int> next;
  if(df)print("moveA");
  repa(i,-2,3){
    next.first=tmp.first+i;
    repa(j,-2,3){
      next.second=tmp.second+j;
      if(legal(next,maze)){
        if(cnt[next.first][next.second]!=-1 and cnt[next.first][next.second] <= cnt[tmp.first][tmp.second]+1) continue;
        que.push_back(next);
        cnt[next.first][next.second]=cnt[tmp.first][tmp.second]+1;
      }
    }
  }
  if(df)print(que);
}

int main(){
  int h,w; cin >>h >>w;
  pair<int,int> s,t;
  int a,b; cin >>a >>b; a--; b--;
  s={a,b};
  cin >>a >>b; a--; b--;
  t={a,b};
  vector<vector<int>> maze(h,vector<int>(w));
  rep(i,h){
    string str; cin >>str;
    rep(j,w) maze[i][j]=(str[j]=='.');
  }
  vector<vector<int>> seen(h,vector<int>(w,0));
  vector<vector<int>> cnt(h,vector<int>(w,-1));
  list<pair<int,int>> que;
  que.push_back(s);
  cnt[s.first][s.second]=0;
  if(df)print(que);
  while(!que.empty()){
    pair<int,int> p=que.front(); que.pop_front();
    if(p==t){
      print(cnt[t.first][t.second]);
      return 0;
    }
    if(seen[p.first][p.second])continue;
    seen[p.first][p.second]=1;
    moveA(p,cnt,que,maze);
    moveB(p,cnt,que,maze);
    if(df)rep(i,h)print(cnt[i]);
    if(df)rep(i,h)print(seen[i]);
  }
  print(-1);
}


Measured memory_bytes: 15776
import sys
import math
import fractions
from functools import reduce
from collections import Counter
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)


N = II()
ans = ''
if N == 0:
    print('0')
while N:
    if N % (-2) == 0:
        N = N // (-2)
        ans = '0' + ans
    else:
        N = (N-1) // (-2)
        ans = '1' + ans
print(ans)





Measured memory_bytes: 5172
import java.util.*;

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

        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }

        int triangleCount = 0;
        for (int i = 0; i < l.length; i++) {
            for (int j = i + 1; j < l.length; j++) {
                for (int k = j + 1; k < l.length; k++) {
                    if (canTriangle(l[i], l[j], l[k])) {
                        triangleCount++;
                    }
                }   
            }
        }
        System.out.println(triangleCount);
    }

    private static boolean canTriangle(int a, int b, int c) {
        if (a == b || a == c || b == c) {
            return false;
        }
        if (a > b && a > c) {
            return b + c > a;
        } else if (b > a && b > c) {
            return c + a > b;
        } else {
            return b + a > c;
        }
    }
}


Measured memory_bytes: 27308
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!( n: String );

    let s: Vec<char> = n.chars().collect();
    let sum = s.iter().map(|c| *c as i32 - 48 ).collect::<Vec<i32>>();
    let sum: i32 = sum.iter().sum();
    let ans = if sum % 9 ==0 {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


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


typedef struct cell{
 int id;
 struct cell *right;
 struct cell *left;
}cell;


void preorder(cell *root){
cell *p=root;
printf(" %d",p->id);

if(p->left!=NULL){preorder(p->left);}
if(p->right!=NULL){preorder(p->right);}

return;
}

void inorder(cell *root){
cell *p=root;
if(p->left!=NULL){inorder(p->left);}
printf(" %d",p->id);
if(p->right!=NULL){inorder(p->right);}

return;
}



cell* makecell(int x){
cell *new=malloc(sizeof(cell));
new->id=x;
new->left=NULL;
new->right=NULL;

return new;
}

void insert(cell **p,cell *new){

cell *temp;

if((*p)==NULL){(*p)=new;return;}
else{

 if( (*p)->left==NULL && (*p)->right==NULL ){/*子なし*/
   if((*p)->id < new->id){
     (*p)->right=new;return;}
   else{
     (*p)->left=new;return;}
  }
  else if((*p)->left==NULL&&(*p)->right!=NULL){/*左なし右あり*/
   if( (*p)->id > new->id ){
     (*p)->left=new;return;}
   else{insert(&((*p)->right),new);}
  }
  else if((*p)->left!=NULL&&(*p)->right==NULL){/*左あり右なし*/
   if( (*p)->id < new->id){
     (*p)->right=new;return;}
   else{insert(&((*p)->left),new);}
  }
  else{/*どっちも子あり*/
   if((*p)->id < new->id){
     insert(&((*p)->right),new);
   }
   else{insert(&((*p)->left),new);}
 }
}

return;
}
     










int main(){
int n,i,x;
char com[7];
cell *root=NULL;
cell *new;

scanf("%d",&n);

for(i=0;i<n;i++){
 scanf("%s",com);

 switch(com[0]){
  case 'i':scanf("%d",&x);
           new=makecell(x);
           insert(&root,new);
           break;

  case 'p':inorder(root);
           printf("\n");
           preorder(root);
           printf("\n");
           break;


 }/*switch end*/

}/*for end*/

return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<char> hat(N);
  int count_R = 0;
  int count_B = 0;

  for(int i = 0;i < N;i++){
    cin >> hat[i];
    if(hat[i] == 'R')count_R++;
    else count_B++;
  }

  if(count_R > count_B)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h> 
 
 int main(void){ 
 int a;
 int b;
 int c; 
 int wwwwww;
 int i;
 int n;
      
 scanf("%d", &n); 
 for(i = 0; i < n; i++){ 
     scanf("%d %d %d", &a, &b, &c); 
     if(a > c){ 
      wwwwww = c;             
	  c = a; 
      a = wwwwww; 
    } 
     if(b > c){ 
       wwwwww = c; 
       c = b; 
       b = wwwwww; 
     } 
     if(a * a + b * b == c * c){ 
         printf("YES\n"); 
     }else{ 
         printf("NO\n"); 
     } 
 } 
 
 
 return 0; 
 } 

Measured memory_bytes: 1008
N=int(input())
S=list(input())


for i in range(len(S)):
    ss=S[i].lower()
    tmp=ord(ss) - ord("a")+N
    num=tmp%26 + ord("a")
    ss=chr(num)
    S[i]=ss.upper()

S="".join(S)
print(S)    

Measured memory_bytes: 3568
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

N=int(input())-1

c=26
a=1
while N>=c:

    N-=c
    c*=26
    a+=1
#print(a)


lst=[0 for i in range(a)]
b=0
while N:
    a=N%26
    lst[b]=a
    N//=26
    b+=1

lst.reverse()
S="".join([chr(i+ord("a")) for i in lst])
print(S)


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

typedef long long ll;
typedef unsigned long long ull;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main()
{
    FASTIO;
    int n = 0; cin >> n;
    ull ans = 0;
    for(int i=1; i<=n; i++){
        if(i%3!=0 && i%5!=0){
            ans += i;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a, b, c;
    a = n / 100;
    b = (n % 100) / 10;
    c = (n % 10);
    
    a = 10 - a;
    b = 10 - b;
    c = 10 - c;
    
    cout << 100 * a + 10 * b + c << endl;
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var x = cin.ReadInt;
            Console.WriteLine(x*x*x);
        }
        
    }

    static class ExtendClass {
        public static void Swap<T>(this T[] X, int i, int j) {
            T tmp = X[i];
            X[i] = X[j];
            X[j] = tmp;
        }
        public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X);
        public static S[] Clone<S>(this S[] src) where S : struct {
            var res = new S[src.Length];
            Array.Copy(src, res, src.Length);
            return res;
        }
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}



Measured memory_bytes: 16368
/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/21 8:23:51
File Name     :TEST.cpp
************************************************ */

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <unordered_map>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i,x,y) for(int i = x;i <= y;++i)
#define fori(i,x,y) for(int i = x;i >= y; -- i)
#define bug puts("--------------")
#define out(x) cout<<x<<'\n';
inline char gc(){char op[2];scanf("%s",op);return op[0];}
const int N = 2e5+10;
const double eps = 0.00000001;
const ll mod = 1e9 ;
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
double a[N];
int main(){
    int n = read(),m = read();
    ll sum = 0;
    rep(i,1,n) a[i] =read(),sum += a[i];
    double k = 1.0*sum/(4*m);
    sort(a+1,a+n+1,greater<int>());
    if(a[m]>=k) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int r;
  cin >> r;
  int ans = 3 * r * r;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    int n, w, d;
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0) break;
    vector<pair<int, int>> cs;
    cs.emplace_back(w, d);
    rep(i, n) {
      int p, s;
      cin >> p >> s;
      --p;
      int w = cs[p].first, d = cs[p].second;
      s %= (w + d);
      cs.erase(cs.begin() + p);
      if (s < w) {
        cs.emplace_back(s, d);
        cs.emplace_back(w - s, d);
      } else {
        cs.emplace_back(w, s - w);
        cs.emplace_back(w, d + w - s);
      }
      sort(cs.end() - 2, cs.end(), [](auto &p, auto &q) { return p.first * p.second < q.first * q.second; });
    }
    vector<int> s(n + 1);
    rep(i, n + 1) s[i] = cs[i].first * cs[i].second;
    sort(all(s));
    cout << s << endl;
  }
}



Measured memory_bytes: 3108
public class
Main
{
  public static void
  main (
    String[ ] args
    )
  {
    java.util.Scanner cin = new java.util.Scanner ( System.in );

    while ( cin.hasNext ( ) )
    {
      int eger = cin.nextInt ( ) + cin.nextInt ( );
      int res = 0;

      for ( ; eger != 0; eger /= 10 )
      {
        ++res;
      }

      System.out.println ( res == 0 ? "1" : res );
    }

    return ;
  }
}

Measured memory_bytes: 12000
fn main() {
    proconio::input! {
        n: usize,
        vw: [(u32,usize);n],
        q: usize,
        vl: [(usize,usize);q],
    }
    let k=n.min(1<<9);
    let m=vl.iter().max_by_key(|vl|vl.1).unwrap().1 as usize;
    let mut dp=vec![vec![0;m+1];k+1];
    for (i,&(v,w)) in vw[0..k].iter().enumerate() {
        let i=i+1;
        let p=i/2;
        for j in 0..=m {
            let mut x=dp[p][j];
            if j>=w {
                x=x.max(dp[p][j-w]+v);
            }
            dp[i][j]=x;
        }
    }
    let mut u=Vec::with_capacity(9);
    let mut s=Vec::with_capacity(1<<9);
    for (v,l) in vl {
        u.clear();
        let mut v=v;
        while v>k {
            u.push(v-1);
            v/=2;
        }
        let mut r=dp[v][l];
        s.clear();
        s.push((0,0));
        for b in 1usize..1<<u.len() {
            let i=b.trailing_zeros()as usize;
            let (v2,w2)=s[b&b-1];
            let vw=vw[u[i]];
            let vw=(vw.0+v2,vw.1+w2);
            if vw.1<=l {
                r=r.max(dp[v][l-vw.1]+vw.0);
            }
            s.push(vw);
        }
        println!("{}",r);
    }
}

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

int main() {
  string S;
  cin >> S;
  int count = 0;
  for(int i = 0;i < S.size();i++) {
    if(S.at(i) == 'x') {
      count++;
    }
  }
  if(count < 8) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        var x1 = n / 500;
        n -= 500 * x1;

        var x2 = n / 5;

        return x1 * 1000 + x2 * 5;
    }
}

Measured memory_bytes: 13140
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <utility>
using namespace std;

typedef pair<int,int> pii;
typedef array<int,3> ai3;
typedef long long LL;

const double EPS = 1e-8;


vector<ai3> pts;

bool lessthan(int a, int b){
	return pts[a] < pts[b];
}

bool lessthan(const pii &a, const pii &b){
	if(lessthan(a.first, b.first)){
		return true;
	}
	if(lessthan(b.first, a.first)){
		return false;
	}
	return lessthan(a.second, b.second);
}

double abs(const ai3 &p){
	return sqrt(p[0] * p[0] + p[1] * p[1] + p[2] * p[2] + 0.0);
}

double eucdist(int a, int b){
	double ta = abs(pts[a]), tb = abs(pts[b]);
	double sum = 0.0;
	for(int i = 0; i < 3; ++i){
		double d = pts[a][i] / ta - pts[b][i] / tb;
		sum += d * d;
	}
	return sqrt(sum);
}

LL grid(int a, double d){
	d *= abs(pts[a]);
	LL ret = 0;
	for(int i = 0; i < 3; ++i){
		ret |= (LL(pts[a][i] / d) + 3) << (i * 21);
	}
	return ret;
}

pii solve(int m, int n, int S, int W){
	pts.resize(m + n);
	for(int i = 0; i < m; ++i){
		scanf("%d%d%d", &pts[i][0], &pts[i][1], &pts[i][2]);
	}
	int g = S;
	for(int i = m; i < m + n; ++i){
		pts[i] = ai3{(g / 7) % 100 + 1, (g / 700) % 100 + 1, (g / 70000) % 100 + 1};
		if(g % 2 == 0){ g /= 2; }
		else{ g = (g / 2) ^ W; }
	}
	
	random_shuffle(pts.begin(), pts.end());

	unordered_map<LL,vector<int> > mp;
	pii ans;
	double mdis = 1e8;
	
	const LL ddx = 1, ddy = 1LL << 21, ddz = 1LL << 42;
	
	for(int i = 0; i < m + n; ++i){
		double tdis = mdis;
		LL gi = grid(i, mdis);
		for(LL dx = -ddx; dx <= ddx; dx += ddx)
		for(LL dy = -ddy; dy <= ddy; dy += ddy)
		for(LL dz = -ddz; dz <= ddz; dz += ddz){
			auto it = mp.find(gi + dx + dy + dz);
			if(it != mp.end()){
				for(int k : it->second){
					double ds = eucdist(i, k);
					if(ds < EPS){ continue; }
					pii pr = (lessthan(i, k) ? pii(i, k) : pii(k, i));
					if(ds + EPS < tdis){
						tdis = ds;
						ans = pr;
					}
					else if(abs(ds - tdis) < EPS && lessthan(pr, ans)){
						ans = pr;
					}
				}
			}
		}
		
		if(tdis + EPS < mdis){
			mdis = tdis;
			mp.clear();
			for(int j = 0; j < i; ++j){
				mp[grid(j, mdis)].push_back(j);
			}
		}
		mp[grid(i, mdis)].push_back(i);
	}
	
	return ans;
}

int main(){
	srand(time(0));

	int m, n, S, W;
	while(scanf("%d%d%d%d", &m, &n, &S, &W), S){
		pii ans = solve(m, n, S, W);
		int a = ans.first, b = ans.second;
		printf("%d %d %d %d %d %d\n",
			pts[a][0], pts[a][1], pts[a][2], pts[b][0], pts[b][1], pts[b][2]);
	}
}

Measured memory_bytes: 10264
#include <cstdio>
#include <algorithm>
#include <tr1/unordered_map>

std::tr1::unordered_map<int,int> f; int n, ans, a[200005], b[35];

int read() {
	int x = 0; char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	while (c >= '0' && c <= '9') {
		x = (x << 3) + (x << 1) + (c ^ 48);
		c = getchar();
	}
	return x;
}

int main() {
	n = read();
	for (int i = 1; i <= n; ++i) a[i] = read(), ++f[a[i]];
	std::sort(a + 1, a + n + 1);
	for (int i = 1, j = 0; j <= 30; ++j) {
		while (a[i] <= 1 << j && i < n) ++i;
		b[j] = i;
	}
	for (int j = 30, i = 1 << j; ~j; --j, i = 1 << j) {
		for (int k = b[j]; k >= 1; --k)
			if ((a[k] != i - a[k] && f[a[k]] && f[i-a[k]]) || (a[k] == i - a[k] && f[a[k]] > 1)) ++ans, --f[a[k]], --f[i-a[k]];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 29556
#include<bits/stdc++.h>
using namespace std;
#define N 300000 + 5
#define int long long
#define mid (l + r) / 2
#define inf 10000000000000000
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define dep(i, l, r) for(int i = r; i >= l; --i)
typedef double D;
int n, m, P, X, top, f[N], g[N], h[N], t[N], T[N], S1[N], S2[N], st[N], mx[N];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int Y1(int x){
    return f[x] + x * (x - 1) / 2 + S1[x];
}
int Y2(int x){
    return g[x] + x * (x - 1) / 2 + S2[x];
}
int Y3(int x){
    return x * (x + 1) / 2 - S1[x] + g[x + 1];
}
int Y4(int x){
    return x * (x - 1) / 2 + S1[x] + f[x];
}
D slope1(int a, int b){
    return 1.0 * (Y1(a) - Y1(b)) / (a - b);
}
D slope2(int a, int b){
    return 1.0 * (Y2(a) - Y2(b)) / (a - b);
}
D slope3(int a, int b){
    return 1.0 * (Y3(a) - Y3(b)) / (a - b);
}
D slope4(int a, int b){
    return 1.0 * (Y4(a) - Y4(b)) / (a - b);
}
void solve(int l, int r){
    if(l == r){ h[l] = max(h[l], f[l - 1] + g[l + 1] + 1 - T[l]); return;}
    solve(l, mid), solve(mid + 1, r);
    st[top = 1] = mid + 1;
    rep(i, mid + 2, r){
        while(top > 1 && slope3(st[top], st[top - 1]) < slope3(st[top - 1], i)) --top;
        st[++top] = i;
    }
    rep(i, l - 1, mid - 1){
        while(top > 1 && i > slope3(st[top], st[top - 1])) --top;
        t[i] = f[i] + (st[top] - i + 1) * (st[top] - i) / 2 + g[st[top] + 1] - S1[st[top]] + S1[i];
    }
    mx[l - 1] = -inf;
    rep(i, l, mid) mx[i] = max(mx[i - 1], t[i - 1]), h[i] = max(h[i], mx[i]);
    st[top = 1] = l - 1;
    rep(i, l, mid - 1){
        while(top > 1 && slope4(st[top], st[top - 1]) < slope4(st[top - 1], i)) --top;
        st[++top] = i;
    }
    rep(i, mid + 1, r){
        while(top > 1 && i > slope4(st[top], st[top - 1])) --top;
        t[i] = g[i + 1] + (i - st[top] + 1) * (i - st[top]) / 2 + f[st[top]] - S1[i] + S1[st[top]];
    }
    mx[r + 1] = -inf;
    dep(i, mid + 1, r) mx[i] = max(mx[i + 1], t[i]), h[i] = max(h[i], mx[i]);
}
signed main(){
    n = read();
    rep(i, 1, n) T[i] = read(), S1[i] = S1[i - 1] + T[i], h[i] = -inf;
    dep(i, 1, n) S2[n - i + 1] = S2[n - i] + T[i];
    st[++top] = 0;
    rep(i, 1, n){
        while(top > 1 && i > slope1(st[top], st[top - 1])) --top;
        f[i] = max(f[i - 1], f[st[top]] + (i - st[top] + 1) * (i - st[top]) / 2 + S1[st[top]] - S1[i]);
        while(top > 1 && slope1(st[top], st[top - 1]) < slope1(st[top - 1], i)) --top;
        st[++top] = i;
    }
    st[top = 1] = 0;
    rep(i, 1, n){
        while(top > 1 && i > slope2(st[top], st[top - 1])) --top;
        g[i] = max(g[i - 1], g[st[top]] + (i - st[top] + 1) * (i - st[top]) / 2 + S2[st[top]] - S2[i]);
        while(top > 1 && slope2(st[top], st[top - 1]) < slope2(st[top - 1], i)) --top;
        st[++top] = i;
    }
    reverse(g + 1, g + n + 1);
    solve(1, n);
    m = read();
    while(m--) P = read(), X = read(), printf("%lld\n", max(f[P - 1] + g[P + 1], h[P] + T[P] - X));
    return 0;
}

Measured memory_bytes: 22436
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.0000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define SECOND_MOD 1000000009
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
using namespace std;
int main() {
	long long a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	long long ans = LONG_INF;
	for (long long i = 0; i <= max(x, y); ++i) {
		long long hoge = i*2LL * c + max(0LL, (x - i) * a) + max(0LL, (y - i) * b);
		ans = min(ans, hoge);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# n:yen, m:coins
n, m = map(int, input().split())

# list of coins
c = list(map(int, input().split()))

dp = [float("inf")] * (n + 1)
dp[0] = 0

for i in range(m):
    for j in range(n + 1):
        if dp[j] >= 0 and j + c[i] <= n:
            dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1)


print(dp[n])



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

int main(void){
    string s;
    cin >> s;
    
    int i;
    for(i = 0; i < s.length() - 1; i++){
        if(s[i] == s[i + 1]){
            printf("%d %d\n", i + 1, i + 2);
            return 0;
        }
    }
    
    for(i = 0; i < s.length() - 2; i++){
        if(s[i] == s[i + 2]){
            printf("%d %d\n", i + 1, i + 3);
            return 0;
        }
    }
    
    cout << "-1 -1" << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;
	int N = S.size();
	int ans = 0;
	rep(i,N){
		int x = S[i] - '0';
		ans += x;
	}
	if(ans % 9 == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;

// nCk mod p (mod対応版nCk)
/* ここから */
const int MAX =
    2000000;  // 問題によって変更する(パスカルの三角形の段数、nCkのnの最大)
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

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

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

  COMinit();

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll now = COM(i, k - 1);
    ans += a[i] * now % MOD;
  }

  reverse(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    ll now = COM(i, k - 1);
    ans -= a[i] * now % MOD;
  }

  cout << ans % MOD << endl;

  return 0;
}

Measured memory_bytes: 47488
#include <stdio.h>

int main()
{
  int N,judge,count=0;
  int H[100];

  scanf("%d",&N);
  for ( int i = 0; i < N; i++ ) {
    scanf("%d",&H[i]);
  }
  count = 1;
  for ( int i = 1; i < N; i++ ) {
    judge = 1;
    for (int j = 0; j < i; j++) {
      if( H[j] > H[i]) judge = 0;
    }
    if ( judge == 1 ) count++;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>

using namespace std;

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/
int main(){
    int n;
    cin>>n;
    int h[n];
    int sum = 0;
    for(int i = 0; i<n;i++){
        cin >> h[i];
        int flag=0;
        for(int j = 0;j<=i;j++){
            if(h[j]>h[i]){
                flag=1;
                break;
            }
        }
        if(flag ==0){
            sum++;
        }
    }
    cout << sum << '\n';
    return 0;  
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

if n == 1 || n == 2
  puts 1
  exit
end

ans = 0
b = []
a.each do |c|
  if b.empty?
    b << c
    ans += 1
  elsif b.length == 1
    b << c
  else 
    if (b[-1] - b[0]) * (c - b[-1]) >= 0
      b << c
    else
      b = [c]
      ans += 1
    end
  end
end
puts ans

Measured memory_bytes: 12036
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())
count = [0, 0, 0, 0]
count[a1 - 1] += 1
count[a2 - 1] += 1
count[a3 - 1] += 1
count[b1 - 1] += 1
count[b2 - 1] += 1
count[b3 - 1] += 1
if 3 in count:
    print("NO")
else:
    print("YES")

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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);
int dp[3005][3005];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	string s,t;
	cin>>s>>t;
	int s1=s.size(),t1=t.size();
	for(int i=1;i<=s1;i++)
		for(int j=1;j<=t1;j++)
			if(s[i-1]==t[j-1]){
				dp[i][j]=1+dp[i-1][j-1];
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
	int i=s1,j=t1;
	string ans;
	while(i>=1 and j>=1){
		if(s[i-1]==t[j-1]){
			ans+=s[i-1];
			i--;j--;
		}
		else if(dp[i-1][j]>dp[i][j-1]){
			i--;
		}
		else
			j--;
	}
	reverse(all(ans));
	cout<<ans<<endl;
}

Measured memory_bytes: 70656
c = [500,100,50]
a = []
for i in range(3):
    a.append(int(input()))
x = int(input())

def dfs(d,y):
    if d == 3:
        if y == x:
            return 1
        return 0

    ret = 0
    for i in range(a[d]+1):
        ret += dfs(d+1, y+c[d]*i)
    return ret

print(dfs(0,0))


Measured memory_bytes: 3060
from sys import *

input = stdin.readline
maxn = 10 ** 5 + 5

Sum = [0] * maxn
Cnt = [0] * maxn

n = int(input())
arr = list(map(int, input().split()))
ans = 0
for x in arr:
	ans += x
	Sum[x] += x
	Cnt[x] += 1 
q = int(input())
result = []
for i in range(q):
	x, y = map(int, input().split())
	ans -= Sum[x]
	ans += y * Cnt[x]
	Sum[y] += y * Cnt[x]
	Cnt[y] += Cnt[x]
	Sum[x] = 0
	Cnt[x] = 0
	result.append(ans)
print('\n'.join(map(str, result)))

Measured memory_bytes: 93240
#!/usr/bin/env python3
# GRL_5_D: Tree - Range Query on Tree


class Edge:
    __slots__ = ('v', 'w')

    def __init__(self, v, w):
        self.v = v
        self.w = w

    def either(self):
        return self.v

    def other(self, v):
        if v == self.v:
            return self.w
        else:
            return self.v


class Graph:
    def __init__(self, v):
        self.v = v
        self._edges = [[] for _ in range(v)]

    def add(self, e):
        self._edges[e.v].append(e)
        self._edges[e.w].append(e)

    def adj(self, v):
        return self._edges[v]

    def edges(self):
        for es in self._edges:
            for e in es:
                yield e


class RAQ:
    """Segment Tree
    """
    def __init__(self, n, initial=0):
        size = 1
        while size < n:
            size *= 2
        self.size = 2*size - 1
        self.data = [initial] * self.size

    def add(self, i, j, v):
        def _add(r, lo, hi):
            if hi < i or lo > j:
                return
            elif i <= lo and hi <= j:
                self.data[r] += v
            else:
                mid = lo + (hi - lo)//2
                _add(r*2 + 1, lo, mid)
                _add(r*2 + 2, mid+1, hi)

        return _add(0, 0, self.size//2)

    def get(self, i):
        def _get(r, lo, hi, v):
            v += self.data[r]
            if lo == hi:
                return v
            mid = lo + (hi - lo)//2
            if mid >= i:
                return _get(r*2 + 1, lo, mid, v)
            else:
                return _get(r*2 + 2, mid+1, hi, v)

        return _get(0, 0, self.size//2, 0)


class PathSum:
    def __init__(self, graph, root):
        self.seg = RAQ(graph.v * 2)
        self._in = [0] * graph.v
        self._out = [0] * graph.v
        self.dfs(graph, root)

    def dfs(self, graph, root):
        visited = [False] * graph.v
        stack = [root]
        i = 0
        while stack:
            v = stack.pop()
            if not visited[v]:
                visited[v] = True
                self._in[v] = i
                i += 1
                stack.append(v)
                for e in graph.adj(v):
                    w = e.other(v)
                    if not visited[w]:
                        stack.append(w)
            else:
                self._out[v] = i
                i += 1

    def add(self, v, val):
        i = self._in[v]
        j = self._out[v]
        self.seg.add(i, j, val)

    def get(self, v):
        return self.seg.get(self._in[v])


def run():
    n = int(input())
    g = Graph(n)

    for i in range(n):
        k, *cs = [int(i) for i in input().split()]
        if k > 0:
            for j in cs:
                g.add(Edge(i, j))

    raq = PathSum(g, 0)
    q = int(input())
    for _ in range(q):
        com, *args = [int(i) for i in input().split()]
        if com == 0:
            u, val = args
            raq.add(u, val)
        elif com == 1:
            u, = args
            print(raq.get(u))
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()



Measured memory_bytes: 44480
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;i++)
#define swap(a,b,type)do{type temp; temp= a;a = b; b= temp;}while(0); 
int main(){
 int n,m,c;
 cin >> n >> m >> c;
 vector<int>b(m);
 int a[n][m];
 rep(i,m){
     cin >> b[i];
 }
 rep(i,n){
     rep(j,m){
         cin >> a[i][j];
     }
 }
 int ans = 0;
 rep(i,n){
    int d = 0;
     rep(j,m){
         d += a[i][j]*b[j];
     }
     if(d+c>0){
        ++ans;
     }
 }
 cout << ans<< endl;
 return 0; 
}


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

vector<bool> prime(150000, true);

int main(){
  prime[0] = prime[1] = false;
  for(int i=2; i*i<150000; i++){
    if(prime[i]){
      for(int j=2; j*i<150000; j++){
        prime[i*j]=false;
      }
    }
  }
  
  while(1){
    int n, p;
    cin >> n >> p;
    if(n==-1) break;

    vector<int> prm_btn(50);
    int cnt=0;
    for(int i=n+1; cnt<50; i++){
      if(prime[i]){
        prm_btn[cnt]=i;
        cnt++;
      }
    }

    vector<int> matsuzaki;
    for(int i=0; i<50; i++){
      for(int j=i; j>=0; j--){
        matsuzaki.push_back(prm_btn[i]+prm_btn[j]);
      }
    }
    sort(matsuzaki.begin(), matsuzaki.end());

    cout << matsuzaki[p-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3084