akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

const int MAX_N = 100010;
int par[MAX_N], uniteRank[MAX_N];

void uniteInit(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        uniteRank[i] = 0;
    }
}

int root(int x)
{
    return par[x] == x ? x : par[x] = root(par[x]);
}

bool same(int x, int y)
{
    return root(x) == root(y);
}

void unite(int x, int y)
{
    x = root(x);
    y = root(y);
    if (x == y)
        return;
    if (uniteRank[x] < uniteRank[y])
    {
        par[x] = y;
    }
    else
    {
        par[y] = x;
        if (uniteRank[x] == uniteRank[y])
        {
            uniteRank[x]++;
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    uniteInit(N + 1); //1-indexed
    vector<ll> nums(N + 1);
    vector<ll> numIndexes(N + 1);
    for (int i = 1; i <= N; i++)
    {
        ll P;
        cin >> P;
        nums.at(i) = P;
        numIndexes.at(P) = i;
    }
    for (int i = 0; i < M; i++)
    {
        ll X, Y;
        cin >> X >> Y;
        ll XIndex, YIndex;
        XIndex = numIndexes.at(X);
        YIndex = numIndexes.at(Y);
        unite(XIndex, YIndex);
    }
    ll answer = 0;
    for (int i = 1; i <= N; i++)
    {
        if (same(i, nums.at(i)))
        {
            answer++;
        }
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 2560
n = gets.to_i
v = gets.split.map(&:to_i)
p = Hash.new(0)
q = Hash.new(0)
n.times do |i|
  p[v[i]] += 1 if i.even?
  q[v[i]] += 1 if i.odd?
end
ps = Hash[p.sort_by{|k, v| -v}].keys
qs = Hash[q.sort_by{|k, v| -v}].keys
x, y, ans = 0, 0, 0
f = false
(n / 2).times do |i|
  x = ps[i]
  (n / 2).times do |j|
    if ps[i] != qs[j]
      y = qs[j]
      f = true
      break
    end
  end
  break if f
end
ans = n - p[x] - q[y] if f
x, y = 0, 0
f = false
(n / 2).times do |i|
  x = qs[i]
  (n / 2).times do |j|
    if qs[i] != ps[j]
      y = ps[j]
      f = true
      break
    end
  end
  break if f
end
ans = n - q[x] - p[y] if f && ans > n - q[x] - p[y]
puts ans

Measured memory_bytes: 24808
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};




int main(){
  int a,b;
  cin>>a>>b;
  if(a<=b)cout<<a<<endl;
  else cout<<a-1<<endl;

  return 0;
  }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	char a[3];
	for (int i = 0; i < 3; i++) cin >> a[i];
	int t1 = 0, t2 = 0;
	for (int i = 0; i < 3; i++)
	{
		if (a[i] == 'A') t1++;
		else t2++;
	}
	if (t1 == 1 || t2 == 1) cout << "Yes" << '\n';
	else cout << "No" << '\n';
}


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


int solve(long long X){
    vector<ll> vals;
    ll i = 0;
    for(ll i=0;i<150;i++) {
        ll val = pow(i, 5);
        vals.push_back(val);
        
    }
    // rep(i, vals.size())
    //     cout << vals[i] << " ";
    // cout << endl;
    for(ll i = 0; i < vals.size();i++) {
        for(ll j = 0; j < vals.size(); j++) {
            // cout << i << " " << j << endl;
            if(vals[i] - vals[j] == X) {
                cout << i << " " << j << endl;
                return 0;
            }
            else if(vals[i] + vals[j] == X) {
                cout << i << " " << -j << endl;
                return 0;
            }
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 4104
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, k = sc.nextInt

    if (k % 2 != 0) {
      // kが奇数の場合
      val ans = math.pow((1 to n).count(_ % k == 0), 3).toLong
      println(ans)

    } else {
      // kが偶数の場合
      val ans = math.pow((1 to n).count(_ % k == 0), 3).toLong + math.pow((1 to n).count(_ % k == (k / 2)), 3).toLong
      println(ans)
    }
  }
}


Measured memory_bytes: 30320
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string input;
	cin >> input;

	for (int i = 0; i < input.size() - 1; i++)
	{
		if (input[i] == input[i + 1])
		{
			cout << i + 1 << " " << i + 2 << endl;
			return;
		}

		if (i < input.size() - 2 && input[i] == input[i + 2])
		{
			cout << i + 1 << " " << i + 3 << endl;
			return;
		}
	}

	cout << -1 << " " << -1 << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

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

    int N, M, X;
    cin >> N >> M >> X;
    vector<int> cost(N);
    vector<vector<int>> knowledge(N, vector<int>(M));
    for (int i = 0; i < N; ++i) {
        cin >> cost[i];
        for (int j = 0; j < M; ++j) {
            cin >> knowledge[i][j];
        }
    }

    bool succ = true;
    for (int j = 0; j < M; ++j) {
        int sum = 0;
        for (int i = 0; i < N; ++i) {
            sum += knowledge[i][j];
        }
        if (sum < X) {
            succ = false;
            break;
        }
    }

    if (!succ) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> score(M, 0);
    int ans = INT_MAX;
    function<void(int, int)> dfs = [&](int idx, int spent) {
        if (idx == N) {
            for (int s : score) {
                if (s < X) {
                    return;
                }
            }
            ans = min(ans, spent);
            return;
        }
        if (spent >= ans) return;

        dfs(idx + 1, spent);

        for (int i = 0; i < M; ++i) {
            score[i] += knowledge[idx][i];
        }
        dfs(idx + 1, spent + cost[idx]);
        for (int i = 0; i < M; ++i) {
            score[i] -= knowledge[idx][i];
        }
    };

    dfs(0, 0);

    if (ans == INT_MAX) ans = -1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
# -*- coding: utf-8 -*-

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

hero_rsp_list = [''] * K
ans = 0

for i in range(N):
    opponent_rsp = T[i]
    hero_last_rsp = hero_rsp_list[i % K]
    if opponent_rsp == 'r':
        if hero_last_rsp != 'p':
            hero_rsp_list[i % K] = 'p'
            ans += P
        else:
            hero_rsp_list[i % K] = ''
    elif opponent_rsp == 's':
        if hero_last_rsp != 'r':
            hero_rsp_list[i % K] = 'r'
            ans += R
        else:
            hero_rsp_list[i % K] = ''
    elif opponent_rsp == 'p':
        if hero_last_rsp != 's':
            hero_rsp_list[i % K] = 's'
            ans += S
        else:
            hero_rsp_list[i % K] = ''

print(ans)


Measured memory_bytes: 3956
#include<stdio.h>

int A[1000000], n;

int binarysearch( int key ){
    int left = 0;
    int right = n;
    int mid;
    while( left < right){
        mid = ( left + right ) / 2;
        if( key == A[mid] ){
            return 1;
        }if( key < A[mid]){
            right = mid;
        }else if( key > A[mid]){
            left = mid + 1;
        }
    }
    return 0;
}

int main(){
    int i, q, key, sum = 0;
    
    scanf("%d", &n);
    for( i = 0; i < n; i++) scanf("%d", &A[i]);
    
    scanf("%d", &q);
    for( i = 0; i < q; i++){
        scanf("%d", &key);
        if( binarysearch( key )) sum++;
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 2124
// https://beta.atcoder.jp/contests/abc083

#define SUBMIT

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <map>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    auto ans = 0;
    for (int i = 1; i <= N; ++i) {
        // copy
        auto x = i;

        auto digit_sum = 0;
        while (x != 0) {
            digit_sum += x % 10;
            x /= 10;
        }

        if (A <= digit_sum && digit_sum <= B) ans += i;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  string t;
  cin >> s;
  cin >> t;
  int ans = 0;
  for (int i = 0; i < s.size(); i++){
    if (s.at(i)!=t.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
    int h, w;
    const int MOD = 1000000007;
    cin>>h>>w;
    vector<vector<char> > v(h+1, vector<char>(w+1));
    for(int i = 1; i<=h; i++) {
        for(int j = 1; j<=w; j++) {
            cin>>v[i][j];
        }
    }
    vector<vector<int> > dp(h+1, vector<int>(w+1, 0));
    for(int i = 2; i<=h; i++) {
        if(v[i][1] == '.') {
            dp[i][1] = 1;
        } else {
            break;
        }
    }
    for(int j = 2; j<=w; j++) {
        if(v[1][j] == '.') {
            dp[1][j] = 1;
        } else {
            break;
        }
    }
    for(int i = 2; i<=h; i++) {
        for(int j = 2; j<=w; j++) {
            if(v[i][j] == '.') {
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            }
        }
    }
    cout<<dp[h][w]<<"\n";
}


Measured memory_bytes: 8584
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int a,b;
  cin >> a >> b;
  cout << 6 - a - b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處
const int MAXN = 1e5 + 2;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<int> adj[MAXN];
    vector<int> adj_inv[MAXN];
    vector<int> deg(MAXN, 0);
    for (int i = 0; i < N-1+M; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj_inv[v].push_back(u);
        ++deg[u];
    }
    vector<int> ans(MAXN, 0);
    queue<int> q;
    for (int i = 1; i <= N; ++i) {
        if (deg[i] == 0) {
            q.push(i);
        }
    }
    while (q.size()) {
        int idx = q.front();
        q.pop();
        for (auto x : adj_inv[idx]) {
            --deg[x];
            if (deg[x] == 0) {
                q.push(x);
                for (auto y : adj[x]) {
                    if (ans[y] == 0) {
                        ans[y] = x;
                    }
                }
            }
        }
    }
    for (int i = 1; i <= N; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 15032
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  string S; cin >> S;
  
  rep(i,S.size()) {
    for(char c = 'a'; c <= 'z'; c++) {
      if (!count(all(S),c)) {
        cout << c << endl;
        return 0;
      }
    }
  }
  cout << "None" << endl;
}


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

ll gcd(ll x, ll y) {
  if (x > y) {
    return gcd(y, x);
  }

  if (x==0)
    return y;

  return gcd(y%x, x);
}

ll lcm(ll x, ll y){
  return (x/gcd(x,y))*y;
}


ll A,B,C,D;

ll f(ll x) {
  return x-x/C-x/D+x/lcm(C,D);
}

signed main() {
  cin>>A>>B>>C>>D;
  cout<<f(B)-f(A-1)<<endl;
  return 0;
}


Measured memory_bytes: 256
# ABC163c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと
    from collections import Counter

    def dump(*args):
        sys.stderr.write(str(args))

    n = int(input())
    a = list(map(int, input().split()))
    a = Counter(a)
    for i in range(n):
        print(a[i+1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 116596
#include <stdio.h>

int main(){

    char xyz[3] ;

    scanf("%s", xyz);
    int i;
    int a = 0;

    for(i = 0; i < 3 ;i++){
        if(xyz[i] == '1') (a = a + 1);
    }
    printf("%d\n" ,a);
    return 0;

}

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

void solve();
int main(){
	ios_base::sync_with_stdio(false);
	int testcase = 1;
//	cout <<"testcases: " ;cin >> testcase;
	while(testcase--){
		solve();
	}
	
}
/*----------------------
7
218 786 704 233 645 728 389
-------------------------*/
#define ll long long 
int n,res = 0;

void solve(){
	cin >> n;
	int arr[n];
	for(int &i: arr) cin >> i;
	sort(arr, arr+n);
	for(int i = -1; ++i < n-2;)
	for(int j = i; ++j < n-1;)
	for(int k = j; ++ k < n && arr[k] < arr[j] + arr[i];) res++;
	cout << res;

}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int test = sc.nextInt();
        long T = 1, A = 1, t, a, n;
        for (int i = 0; i < test; i++) {
            t = sc.nextLong();
            a = sc.nextLong();
            n = Math.max((T + t - 1) / t, (A + a - 1) / a);
            T = n * t;
            A = n * a;
        }
        System.out.println(T + A);
        bw.flush();
    }
}


Measured memory_bytes: 23640
/******************************************
* AUTHOR : ARPIT *
* NICK : arpitfalcon *
* INSTITUTION : BIT MESRA *
* Ab m game m hu. *
******************************************/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007 -
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vin                    \
    ll n;                      \
    cin >> n;                  \
    vector<ll> v(n);           \
    for (ll i = 0; i < n; i++) \
    cin >> v[i]
#define vout                   \
    for (ll i = 0; i < n; i++) \
    cout << v[i] << " "
#define T     \
    ll t = 1; \
    cin >> t; \
    while (t--)
#define ain                    \
    ll n, k;                   \
    cin >> n >> k;             \
    ll a[n];                   \
    for (ll z = 0; z < n; z++) \
    cin >> a[z]
#define aout                   \
    for (ll i = 0; i < n; i++) \
    cout << a[i] << " "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define max4(a, b, c, d) max(a, max3(b, c, d))
#define min4(a, b, c, d) min(a, min3(b, c, d))
#define blink                \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double PI = 3.141592653589793238463;

#define forn(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define for1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define forr(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define forab(i, a, b, c) for (ll(i) = a; (i) <= (b); (i) += (c))

/*
__builtin_ffs(x)
  Number of set bits: __builtin_popcount(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
*/

int calcWindows(int len, int k)
{
    if (len == 1)
        return 0;

    if (k >= len)
        return 1;

    if (k == 2)
        return len - 1;

    int quo = len / (k - 1);
    if (quo == 1 && k < len)
        return 2;

    return quo;
}

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

    // your code goes here

    vin;
    cout << *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end()) << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
long long b[110];
long long c[110];
int main()
{
long long a;
long long ans=1;
cin>>a;
for(long long s=0;s<a;s++)
cin>>b[s];
sort(b,b+a);
int q=b[0];
for(long long i=0;i<a;i++)
{if(b[i]!=q){
q=b[i];
ans++;}
}
cout<<ans;
system("pause");
return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C;
    cin >> K;
    int ma = 0;
    ma = max(A, max(B, C));
    cout << A + B + C - ma + int(ma * pow(2, K));

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
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;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int s=max(a,c),t=min(b,d);
	int out=t-s;
	cout<<max(0,out)<<endl;
}









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

struct Node{
    vector<ll> connections;

    void add(ll n){
        connections.push_back(n);
    }
};
vector<ll> A;
vector<ll> LIS;
vector<Node> Nodes;
vector<ll> ANS;

void solve(ll n, ll p){
    // update ANS, LIS
    // back LIS
    ll update_index, previous_value;
    update_index = lower_bound(LIS.begin(), LIS.end(), A[n]) - LIS.begin();
    previous_value = LIS[update_index];
    LIS[update_index] = A[n];
    ANS[n] = lower_bound(LIS.begin(), LIS.end(), LLONG_MAX) - LIS.begin();
    Node node = Nodes[n];
    for(ll i=0ll;i<node.connections.size();i++){
        ll child = node.connections[i];
        if (child == p){
            continue;
        }
        solve(child, n);
    }
    // back
    LIS[update_index] = previous_value;
}

int main(void)
{
    ll N;
    cin >> N;
    vector<ll> a(N);
    for(ll i=0;i<N;i++){
        cin >> a.at(i);
    }
    A = a;
    vector<ll> lis(N, LLONG_MAX);
    LIS = lis;
    vector<Node> nodes(N, Node());
    for(ll i=0;i<N-1;i++){
        ll v, u;
        cin >> u >> v;
        u--;
        v--;
        nodes[u].add(v);
        nodes[v].add(u);
    }
    Nodes = nodes;
    vector<ll> ans(N, 0);
    ANS = ans;
    solve(0, -1);
    for(ll i=0;i<N;i++){
        cout << ANS[i] << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
        cin.sync_with_stdio(0);
       
        int k, a, b;
        cin >> k >> a >> b;

        if (b / k - (a - 1) / k > 0)
                cout << "OK";
        else
                cout << "NG";

        return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

struct point {
    long double x, y, r;
    point(long double xx, long double yy, long double rr) :x(xx), y(yy), r(rr) {};
};

int main() {
    long double xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    int n;
    cin >> n;

    auto d = make_v(n+2, n+2, 0.0L);
    vector<point> v;
    vector<long double> ans(n+2, INF<long double>);
    vector<int> used(n+2, 0);
    ans[0] = 0;

    v.emplace_back(xs, ys, 0.0L);


    for (int i = 1; i <= n; ++i) {
        long double x, y, r;
        scanf("%Lf %Lf %Lf", &x, &y ,&r);
        v.emplace_back(x, y, r);
    }
    v.emplace_back(xt, yt, 0.0L);

    for (int i = 0; i <= n+1; ++i) {
        for (int j = i+1; j <= n+1; ++j) {
            if(i == j) continue;
            d[i][j] = d[j][i] = max(0.0L, hypot(fabs(v[i].x-v[j].x), fabs(v[i].y-v[j].y))-v[i].r-v[j].r);
        }
    }
    while(true){
        int x = -1;
        for (int u = 0; u < n+2; ++u) {
            if(!used[u] && (x == -1 || ans[u] < ans[x])) x = u;
        }
        if(x == -1) break;
        used[x] = true;
        for (int u = 0; u < n+2; ++u) {
            ans[u] = min(ans[u], ans[x] + d[x][u]);
        }
    }
     cout << setprecision(20) << ans[n+1] << "\n";

    return 0;
}


Measured memory_bytes: 16128
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
  int n, m;
  int p[1024];
  vector<long long> v;
  for( ; ; ){
    scanf("%d %d", &n, &m);
    if(!(n + m)) break;
    for(int i = 0;i < n; i++) scanf("%d", p + i);
    v.clear();
    p[n++] = 0;
    for(int i = 0;i < n; i++)
      for(int j = i;j < n; j++)
	v.push_back(p[i] + p[j]);
    sort(v.begin(), v.end());
    long long ans = 0;
    for(int i = 0;i < v.size(); i++){
      if(v[i] > m) break;
      vector<long long>::iterator it = upper_bound(v.begin(), v.end(), m - v[i]);
      ans = max(ans, v[i] + *(it - 1));
    }
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 6352
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back

vll sum;
vll seq;
vector<vector<ll>> bit;
vll bitsum;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vll sum(n+1);
    vll bitsum(40);
    vector<vector<ll>> bit(((n*(n+1))/2),vector<ll>(40));
    sum[0] = 0;
    for(int i=1;i<=n;i++) {
        ll t;
        cin >> t;
        sum[i] = sum[i-1]+t;
    }
    int x = 0;
    for(int i=1;i<=n;++i){
        for(int j=i;j<=n;++j){
            ll t = sum[j]-sum[i-1];
            int y=0;
            while(t>0){
                bit[x][y]+=t%2;
                bitsum[y]+=t%2;
                t>>=1;
                y++;
            }
            x++;
        }
    }
    bool fz = true;
    bool f[(n*(n+1))/2];
    for(int i=0;i<(n*(n+1))/2;i++){
        f[i]=true;
    }
    bool ans[40];
    REP(i,40) ans[i]=false;
    for(int i=39;i>=0;i--){
        if(bitsum[i]>=k){
            fz = false;
            int t=0;
            for(int j=0;j<(n*(n+1))/2;j++){
                if(f[j]&&(bit[j][i]>0)) t++;
            }
            if(t>=k){
                ans[i]=true;
                for(int j=0;j<(n*(n+1))/2;j++){
                    if(f[j]&&(bit[j][i]>0)){
                        f[j]=true;
                    }else{
                        f[j]=false;
                    }
                }
            }
        }
    }
    ll ret=0;
    ll p =1;
    for(int i=0;i<40;i++){
        if(ans[i]){
            ret+=p;
        }
        p*=2;
    }
    if(fz) ret = 0;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 176768
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,u,v;
    cin >> N >> u >> v;
    u--;v--;
    vector<vector<int>>ki(N);
    for(int i = 0; i < N-1; i++) {
        int A,B;
        cin >> A >> B;
        A--;B--;
        ki[A].push_back(B);
        ki[B].push_back(A);
    }
    queue<int>que;
    que.push(u);
    vector<int>cnt(N,-1);
    cnt[u] = 0;
    while(!que.empty()) {
        int x = que.front();
        que.pop();
        for(int i = 0; i < ki[x].size(); i++) {
            if(cnt[ki[x][i]] == -1) {
                cnt[ki[x][i]] = cnt[x]+1;
                que.push(ki[x][i]);
            }
        }
    }
    vector<int>road;
    que.push(v);
    road.push_back(v);
    while(!que.empty()) {
        int x = que.front();
        que.pop();
        for(int i = 0; i < ki[x].size(); i++) {
            if(cnt[ki[x][i]] == cnt[x]-1) {
                road.push_back(ki[x][i]);
                que.push(ki[x][i]);
            }
        }
    }
    reverse(road.begin(),road.end());
    int ans = (road.size()-2)/2;
    int now = road[road.size()/2-1];
    int ng = road[road.size()/2];
    que.push(now);
    vector<int>cnt2(N,-1);
    cnt2[now] = 0;
    while(!que.empty()) {
        int x = que.front();
        que.pop();
        for(int i = 0; i < ki[x].size(); i++) {
            if(ki[x][i] == ng) {
                continue;
            }
            if(cnt2[ki[x][i]] == -1) {
                cnt2[ki[x][i]] = cnt2[x]+1;
                que.push(ki[x][i]);
            }
        }
    }
    int mx = 0;
    for(int i = 0; i < N; i++) {
        mx = max(mx,cnt2[i]);
    }
    ans += ((road.size()%2)?mx+1:mx);
    cout << ans << endl;
}


Measured memory_bytes: 10836
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ALL(a) (a.begin(), a.end())
using ll = long long;
template<typename T> void Out(T x) { cout << x << endl; }

vector<int> coins = {500 ,100, 50, 10, 5, 1};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int x; cin >> x;
  int res = 0;
  res += (x/500) * 1000;
  x %= 500;
  res += (x/5) * 5;
  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
   int n,m;
  int a[10000];
  double s=0;
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i];
    s+=a[i];
  }
  sort(a,a+n,greater<int>());
  for(int i=0;i<m;i++){
    
    if((double)(s/(4*m))>a[i]){
      cout<<"No\n";
      return 0;
    }
  }
  cout<<"Yes\n";
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s;
    cin >> s;
    int n = s.length();
    int flag = 1;
    int l = 0;
    int r = n-1;
    while(l<r){
        if(s[l]!=s[r]){
            flag = 0;
            break;
        }
        l++;
        r--;
    }
    l = 0;
    r = (n-1)/2-1;
    while(l<r){
        if(s[l]!=s[r]){
            flag = 0;
            break;
        }
        l++;
        r--;
    }
    l = (n+3)/2-1;
    r = n-1;
    while(l<r){
        if(s[l]!=s[r]){
            flag = 0;
            break;
        }
        l++;
        r--;
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}






Measured memory_bytes: 256
#import numpy as np
#import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    K = first_input[0]
    A = second_input[0]
    B = second_input[1]

    for i in range(1,1001):
        kn = K*i
        if A<=kn and kn<=B:
            print("OK")
            return

    print("NG")
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 61852
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n,m=map(int,input().split())

S=set(range(1,m+1))
for i in range(n):
	K,*A=map(int,input().split())
	S&=set(A)
print(len(S))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define fr                first
#define sc                second
#define vc                vector
#define endl              '\n'
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define LSB(i)            ((i)&-(i))

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
    string s, t;
    int a, b;
    cin >> s >> t >> a >> b;
    string u;
    cin >> u;
    if (s == u)
        a--;
    else if (t == u)
        b--;
    cout << a << " " << b << endl;
}
signed main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

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

#define N 1000000


void insertionSort(int *A, int n, int g);
void sellSort(int *A, int n);

int cnt = 0;

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

    int n;
    cin>>n;
    int a[N];
    for(int i = 0; i < n; i++) cin>>a[i];
    
    sellSort(a, n);
    
    return 0;
}

void insertionSort(int *A, int n, int g) {
    for(int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;
        
        while(j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void sellSort(int *A, int n) {
    cnt = 0;
    int m;
    int G[13] = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161};
    
    for(int i = 12; i >= 0; i--) {
        if(n >= G[i]) {
            m = i+1;
            break;
        }
    }
    
    for(int i = 0; i < m; i++) {
        insertionSort(A, n, G[m-1-i]);
    }
    
    cout<<m<<endl;
    for(int i = m-1; i > 0; i--) cout<<G[i]<<' ';
    cout<<G[0]<<endl;
    cout<<cnt<<endl;
    for(int i = 0; i < n; i++) cout<<A[i]<<endl;
}



Measured memory_bytes: 7064
#include<cstdio>

char s[1001][1001];
int main()
{
	int n,i,j;scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%s",s[i]);

	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(s[i][j]!='.')
			{ i=n+1;break; }
	if(i==n)return puts("-1"),0;

	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(s[i][j]!='#')
			{ i=n+1;break; }
	if(i==n)return puts("0"),0;

	int c=0;
	for(j=0;j<n;j++)
	{
		for(i=0;i<n;i++)
			if(s[i][j]!='#')
				break;
		c+=i==n;
	}

	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
			if(s[i][j]!='#')
				break;
		if(j==n)return printf("%d\n",n-c),0;
	}

	int ans=0,t;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
			if(s[j][i]=='#')
				break;
		t=j==n?-1:0;
		for(j=0;j<n;j++)
			t+=s[i][j]=='#';
		t>ans&&(ans=t);
	}

	printf("%d\n",n-ans+n-c);
}


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

int main()
{
    int ans = 0;
    //cout << (5-2)/2 << endl;
    vector<int> x(3);
    for (int i = 0; i < 3; ++i)
        cin >> x[i];
    sort(x.begin(), x.end());
    if (x[0] % 2 == 0 && x[1] % 2 == 0 && x[2] % 2 == 0)
    {
        ans += (x[2] - x[1]) / 2;
        ans += (x[2] - x[0]) / 2;
        cout << ans << endl;
        return 0;
    }
    else if (x[0] % 2 == 1 && x[1] % 2 == 1 && x[2] % 2 == 1)
    {
        ans += (x[2] - x[1]) / 2;
        ans += (x[2] - x[0]) / 2;
        cout << ans << endl;
        return 0;
    }

    ans += (x[2] - x[1]) / 2;
    x[1] += ans * 2;

    int y= (x[2] - x[0]) / 2;
    ans += y;
    x[0] += y * 2;

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

    if(x[0]==x[1]){
        ans++;
    }else{
        ans += 2;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int main(){
	
	int n;cin >> n;
	int ans = 0;
	for(int i = 1;i <= n;i+=2){
		int cou = 0;
		for(int j = 1;j <= i;j++){
			if(i % j == 0)cou++;
		}
		if(cou == 8)ans++;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	scanf("%d %d",&a,&b);
	for(int i=a*12;i<=a*20;++i)
		if(floor(0.08*i)==a && floor(0.1*i)==b) {printf("%d\n",i);return 0;}
	puts("-1");return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String fst = br.readLine();
		Dice dice = new Dice(fst);
		int q = Integer.parseInt(br.readLine());
		for (int i = 0; i<q ;i++ ) {
			String[] str = (br.readLine()).split(" ");
			int top = Integer.parseInt(str[0]);
			int forth = Integer.parseInt(str[1]);
			while(true){
				if ( top == dice.getForth()){
					dice.sim("N");
				}else if( top == dice.getRight()){
					dice.sim("W");
				}else if( top == dice.getLeft()){
					dice.sim("E");
				}else if( top == dice.getBack()){
					dice.sim("S");
				}else if( top == dice.getBottom()){
					dice.sim("NN");
				}

				if ( forth == dice.getRight()){
					dice.sim("WSE");
				}else if ( forth == dice.getBack()){
					dice.sim("WNNE");
				}else if ( forth == dice.getLeft()){
					dice.sim("ESW");
				}

				if( top == dice.getTop() && forth == dice.getForth()){break;}


			}
			System.out.println(dice.getRight());
		} 			
	}
}



class Dice{
	private int top;
	private int forth;
	private int right;
	private int left;
	private int back;
	private int bottom;
	Dice(String str){
		String[] s = str.split(" ");	
		top = Integer.parseInt(s[0]);
		forth = Integer.parseInt(s[1]);
		right = Integer.parseInt(s[2]);
		left = Integer.parseInt(s[3]);
		back = Integer.parseInt(s[4]);
		bottom = Integer.parseInt(s[5]);
	}

	public void sim(String st){
		int work;
		for (int i = 0; i<st.length() ; i++ ) {
			switch(st.charAt(i)){

				case 'N':
				work = top;
				top = forth;
				forth = bottom;
				bottom = back;
				back = work;
				break;

				case 'E':
				work = top;
				top = left;
				left = bottom;
				bottom = right;
				right = work;
				break;

				case 'S':
				work = top;
				top = back;
				back = bottom;
				bottom = forth;
				forth = work;
				break;

				case 'W':
				work = top;
				top = right;
				right = bottom;
				bottom = left;
				left = work;
				break;

			}
		}

	}
	public int getTop(){
		return top;
	}
	public int getForth(){
		return forth;
	}

	public int getRight(){
		return right;
	}
	public int getLeft(){
		return left;
	}
	public int getBack(){
		return back;
	}
	public int getBottom(){
		return bottom;
	}
}

Measured memory_bytes: 24276
//Repeat ACL 

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int k;cin>>k;
    rep(i,0,k)cout<<"ACL";
    cout<<nnn;
    
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
int ans[100010];

signed main(){
  int n,m;
  cin>>n>>m;
  vector<int> l[100010];
  lp(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    l[a].push_back(b);
    l[b].push_back(a);
  }
  int cnt=0;
  lp(i,n){
    if(ans[i+1]==1) continue;
    cnt++;
    queue<int> q;
    q.push(i+1);
    while(!q.empty()){
      int now=q.front();
      q.pop();
      lp(i,l[now].size()){
        int next=l[now][i];
        if(ans[next]==0){
          ans[next]=1;
          q.push(next);
        }
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 8052
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int A[][]=new int[n][m];
		int b[]=new int[m];
		int c[]=new int[n];


		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				int ai=sc.nextInt();
				A[i][j]=ai;
			}
		}
		for(int k=0;k<m;k++) {
			int bm=sc.nextInt();
			b[k]=bm;
		}
		for(int l=0;l<n;l++) {
			for(int p=0;p<m;p++) {
				c[l]+=A[l][p]*b[p];
			}
			System.out.println(c[l]);
		}



	}
}


Measured memory_bytes: 40652
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))

const ll inf = (1LL<<62);
const int iinf = (1<<30);
//CLOCKS_PER_SEC

int n, x;
unordered_map <int, int> mp;
ll ans;

int main(){
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //ifstream cin ("test.in");
    //ofstream cout ("test.out");
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> x;
		ans += mp[i-1 - x];
		mp[x + i - 1]++;
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 18504
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P       = pair<int, int>;

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

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    int n;
    cin >> n;
    vector<int> hs(n);
    rep(i, 0, n) {
        int h;
        cin >> h;
        hs[i] = h;
    }

    int ans = 0;
    rep(r, 0, n) {
        bool ok = true;
        rep(l, 0, r) {
            if (hs[l] > hs[r]) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		int num;
		stackList sl = new stackList();
		
		while(str!=null){
			num=Integer.parseInt(str);
			if(num>0){
				sl.setList(num);
			}else if (num==0){
				System.out.println(sl.getList());
			}else{
				System.out.println("0??\????????´??°?????\?????????????????????");
			}
			str=br.readLine();
		}
	}

}

final class stackList {
	int[] array = new int[10];
	int index = 0;	//??????????????????????????????????????????
	
	stackList(){
		for(int i=0;i<10;i++){
			array[i]=0;
		}
	}
	
	public void setList(int num){
		array[index]=num;
		index++;
	}
	
	public int getList(){
		int tmp;
		if(index-1<0){
			index=1;
		}
		tmp = array[index-1];
		array[index-1]=0;
		index--;
		return tmp;
	}
}

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

int main(){
 int n,ans=0;
 cin >> n ;
 vector<int> a(n);

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

 for(int i=0;i<n;i++){
	if(a.at(i)>0){
		for(int l=i;l<n;l++){
			if(a.at(l)==0){break;}
			else {a.at(l)--;}
		}
		ans++;
		i--;
	}
 }
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */


int main() {
    int n, d, x;
    cin >> n >> d >> x;
    d--;
    vector<int> A(n);
    int sum = 0;
    rep(i, n) {
        int a;
        cin >> a;
        sum += d / a + 1;
    }
    cout << sum + x << endl;
    
    return 0;
}

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

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
//constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;


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

	cin>>H>>W;
	vector<vector<int>>v(H,vector<int>(W));
	for(auto &i:v)for(auto &j:i)cin>>j;
	vector<vector<int>>visited(H,vector<int>(W));
	for(int i=0;i<H-2;i++){
		for(int j=0;j<W-2;j++){
			while(v[i][j]){
				visited[i+1][j+1]++;
				for(int k=0;k<3;k++){
					for(int l=0;l<3;l++){
						v[i+k][j+l]--;
					}
				}
			}
		}
	}
	vector<pair<int,int>>two;
	vector<pair<int,int>>one;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(!visited[i][j])continue;
			if(visited[i][j]==1){
				int sum=0;
				for(int k=-1;k<=1;k++){
					for(int l=-1;l<=1;l++){
						sum+=visited[i+k][j+l];
					}
				}
				if(sum<3){
					one.push_back({i,j});
				}
			}
			else{
				two.push_back({i,j});
			}
		}
	}
	vector<pair<int,int>>ans;
	for(auto i:one)ans.push_back(i);
	for(auto i:two)ans.push_back(i);
	if(ans.size()==1&&!two.empty()){
		ans.push_back(two[0]);
	}
	sort(ans.begin(),ans.end());
	cout<<ans[1].first<<" "<<ans[1].second<<" "<<ans[0].first<<" "<<ans[0].second<<endl;
	return 0;
}


Measured memory_bytes: 4972
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=2000000000000000000;
constexpr int mod=998244353;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n;
string s;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>s;
    for(char c:s){
        int d=c-'A';
        d+=n;
        d%=26;
        cout<<(char)(d+'A');
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 256