akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        int[] a,b;
        a = new int[101];
        b = new int[101];
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int i,j,t,now=111,co=0,nowt=-1;
        for(i=0;i<n;i++)a[i] = s.nextInt();
        for(i=0;i<n;i++){
            for(j=i;j<n;j++){
                if(now>a[j]){
                    now=a[j];
                    nowt = j;
                }
            }
            if(a[i]!=now&&nowt>=0){
                t = a[nowt];
                a[nowt] = a[i];
                a[i]=t;
                co++;
            }
            now=111;
        }
        for(i=0;i<n;i++){
            if(i==0)System.out.print(a[i]);
            else System.out.print(" "+a[i]);
        }
        System.out.println();
        System.out.println(co);
 
 
    }
}



Measured memory_bytes: 26220
#include<iostream>
#include<algorithm>
#include<string> 
using namespace std;
string a;
int ans=0;
int main()
{  
	cin>>a;
		for(int i=0;i<6;i++)
		{
			if (a[i]=='1') ans++;
		}
		if(ans!=0)cout<<ans<<endl;
		else cout<<"0"<<endl;
   
        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,pair< int , int> >  
long long MOD  = 1e9+7;


signed main(){
    fast;
    int n; cin >> n;
    string s; cin >> s;
    int c = 0;
    int ans = 0;
    for(int i=0 ; i<n-1 ; i++){
    	if(s[i] == s[i+1]){
    		c++;
    	}
    	else{
    		ans++;
    		c =1;
    	}
    }
    if(c)
    	ans++;
    if(n==1){
   		ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
import java.util.Arrays;
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 s[] = new int[M];
		int c[] = new int[M];
		
		for(int i = 0; i < M; i++){
			s[i] = sc.nextInt() - 1;
			c[i] = sc.nextInt();
		}
		
		int digit[] = new int[N];
		Arrays.fill(digit, -1);
		
		boolean error = false;
		
		for(int i = 0; i < M; i++){
			if(digit[s[i]] == -1 || digit[s[i]] == c[i]){
				digit[s[i]] = c[i];
			}
			else error = true;
		}
		
		StringBuffer sb = new StringBuffer(""); 
		
		if(!error){
			
			if(digit[0] != -1)sb.append(digit[0]);
			else if(N != 1)sb.append(1);
			else sb.append(0);
			
			for(int i = 1; i < N; i++){
				if(digit[i] != -1)sb.append(digit[i]);
				else sb.append(0);
			}
			
			int len = String.valueOf(Integer.valueOf(sb.toString())).length();
			if(len < N)error = true;
		}
		
		System.out.println((error)?-1:sb.toString());
	}
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	bool flg=1;
	for(int i=1;i<=9;++i)
		for(int j=1;j<=9;++j)
			if(i*j==n){ cout << "Yes" << endl; return 0; }
	if(flg) cout << "No" << endl;
	return 0;
}

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
	ll x, y, n, i;
	cin >> n >> x >> y;
	bool ok = 0;
	ll cur = 0;
	if(x == y)
		cur = 1;
	rep(i,0,n - 1){
		cin >> x >> y;
		if(x == y){
			cur++;
		}
		else 
			cur = 0;
		if(cur == 3){
			ok = 1;
		}
	}
	if(ok)
		cout << "Yes" << nl;
	else cout << "No" << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


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

int main() {
 int N;
  cin >> N;
  int answer=0;
  int T,Y;
  cin >> T >> Y;
  vector<int> a(N);
  vector<int> b(N);
    for(int i=0;i<N;i++){
      cin >> a.at(i) >> b.at(i);
    }
  for(int i=0;i<N;i++){
    if(a.at(i)>=T&&b.at(i)>=Y){
      answer++;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
import re
inp=input()
newInp=[]
for ch in inp:
#    print(ch)
#    print(ord(ch))
    if re.match(r"[a-z]", ch):
        #小文字は大文字に
        newInp.append(chr(ord(ch)-ord('a')+ord('A')))
    elif re.match(r"[A-Z]", ch):
        #大文字は小文字に
        newInp.append(chr(ord(ch)-ord('A')+ord('a')))
    else:
        newInp.append(ch)

print(''.join(newInp))


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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e9;
const int MOD = 1e9+7;

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

int V, E;
vvi d;
vvi dp;

int calc(int S, int v)
{
    int ret = INF;
    if(dp[S][v] != -1) return dp[S][v];
    REP(i, V) if(d[v][i] != INF && !(S & (1 << i))) chmin(ret, calc(S | (1 << i), i) + d[v][i]);
    return dp[S][v] = ret;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> V >> E;
    d.resize(V, vi(V, INF));
    REP(i, E)
    {
        int s, t, dist; cin >> s >> t >> dist;
        d[s][t] = dist;
    }

    dp.resize(1 << V, vi(V, -1));
    dp[(1 << V)-1][0] = 0;
    int ans = calc(0, 0);
    cout << ((ans != INF) ? ans : -1) << endl;
}


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

int main(){
    int n;
    char a,b;
    cin >> n;
    int ans  = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a==0){
            b = a;
            ans++;
            continue;
        }
        if(a!=b) ans++;
        b = a; 
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  long long int n,k,i,wa=0,saidai=0;
  double kotae;
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    if(i<k){
      wa+=a[i];
      if(i==k-1){
        saidai=wa;
      }
    }else{
      wa+=a[i];
      wa-=a[i-k];
      saidai=max(saidai,wa);
    }
  }
  saidai+=k;
  kotae=((double)saidai)/2.0;
  printf("%lf", kotae);
        
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
int Array[100005] , dp[100005];

int main(){
    int N , k , i , j , limit;
    scanf( "%d%d" , &N , &k );

    for( i = 1 ; i <= N ; ++i )
        scanf( "%d" , Array + i );
    
    dp[1] = 0;

    for( i = 2 ; i <= N ; ++i ){
        dp[i] = 1000000007;
        limit = max( 1 , i - k );

        for( j = i - 1 ; j >= limit ; --j )
            dp[i] = min( dp[i] , dp[j] + abs( Array[i] - Array[j] ) );         
    }

    printf( "%d\n" , dp[N] );
    return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))
MOD = 998244353
N = int(input())
D = inpl()
n = defaultdict(int)
M = 0
for i in range(N):
    m = D[i]
    n[m] += 1
    if m > M:
        M = m
if D[0] > 0 or n[0] > 1:
    print(0)
    exit()
ans = 1
for i in range(1,M+1):
    ans *= pow(n[i-1],n[i],MOD)
    ans %= MOD
    if ans == 0:
        break
print(ans)

Measured memory_bytes: 63668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll r, s, p;
  cin >> r >> s >> p;
  string str;
  cin >> str;
  ll res = 0;
  rep(i, n) {
    bool flag = 1;
    if (i >= k) {
      if (str.at(i) == str.at(i-k)) {
        str.at(i) = '0';
        flag = 0;
        continue;
      }
    }
    if (flag) {
        if (str.at(i) == 'r') res += p;
        if (str.at(i) == 's') res += r;
        if (str.at(i) == 'p') res += s;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 512
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

//辞書順順列はiota(1,N),nextPermituionを使う


void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
    import core.stdc.stdlib;
    writeln(v);
    exit(0);
}

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}


void main()
{
  auto a=scanElem;
  auto b=scanElem;
  if(a%3==0||b%3==0||(a+b)%3==0)end("Possible");end("Impossible");
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;
template<typename T>
class UnionFind {
    int size_;
    std::vector<T> par;
    std::vector<T> rank;
    public:
    UnionFind(int size_) : size_(size_) {
        par.resize(size_);
        rank.resize(size_);
        for(int i=0; i<size_; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    T find(T x) {
        return par[x] == x ? x : par[x] = find(par[x]);
    }
    void unite(T x,T y) {
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(rank[x] < rank[y]) {
            par[x] = y;
        }
        else {
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    bool same(T x,T y) {
        return find(x) == find(y);
    }
};
int n;
struct Sphere {
    double x,y,z,r;
};
struct Edge {
    int from;
    int to;
    double cost;

    bool operator<(const Edge &rth) const {
        return cost < rth.cost;
    }
};
double pow2(double x) {
    return x*x;
}
double dist(Sphere s1, Sphere s2) {
    double t;
    t=pow2(s1.x-s2.x);
    t+=pow2(s1.y-s2.y);
    t+=pow2(s1.z-s2.z);
    t=sqrt(t);

    t=t-s1.r-s2.r;

    if(t<0) t=0;
    return t;
}
void solve() {
    UnionFind<int> uf(102);
    vector<Edge> edges;
    Sphere sphere[102];
    rep(i,n) {
        double x,y,z,r;
        cin>>x>>y>>z>>r;
        sphere[i]={x,y,z,r};
    }
    rep(i,n) rep(j,n) if(i!=j) {
        double d=dist(sphere[i],sphere[j]);
        edges.push_back({i,j,d});
    }

    sort(all(edges));
    double ans=0;

    rep(i,edges.size()) {
        Edge e = edges[i];
        if(!uf.same(e.from,e.to)) {
            ans+=e.cost;
            uf.unite(e.from,e.to);
        }
    }

    printf("%.3f\n",ans);
}
int main() {
    while(cin>>n) {
        if(n==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1648
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int n;
    cin >> n;
    string s = to_string(n);
    int x = 0;
    rep(i, s.size())
    {
        x += (s[i] - '0');
    }
    if (n % x == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[10],temp;
  for(int i=0;i<10;i++){
    cin>>a[i];
  }
  for(int i=0;i<10;i++){
    for(int j=0;j<10-i-1;j++){
      if(a[j]<a[j+1]){
	temp=a[j];
	a[j]=a[j+1];
	a[j+1]=temp;
      }
    }  
  }
  for(int i=0;i<3;i++){
    cout<<a[i]<<endl;
  }
  return(0);
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define rep(i,a,b) for (rg int i=a;i<=b;i++)
#define per(i,a,b) for (rg int i=b;i>=a;i--)
#define pb push_back
#define lowbit(x) (x&(-x))
#define mk make_pair
#define VI vector<int>
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define fi first
#define se second
#define il inline
#define ll long long
#define db double
#define ld long double
#define inf 0x3f3f3f3f
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
char buf[1<<15],*p1 = buf,*p2 = buf;
inline ll read(){
    #define num ch-'0'
    char ch;bool flag=0;ll res;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=res*10ll+num);
    (flag)&&(res=-res);
    #undef num
    return res;
}
inline void write(ll x){
	if (x < 0) x = ~x + 1ll, putchar('-');
	if (x > 9) write(x / 10ll);
	putchar(x % 10ll + '0');
}
#define mid ((l + r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
#undef mid
#undef ls
#undef rs
#define maxn 2020
int a[maxn];
int n;
int erfen(int v,int l)
{
	int r = n,pre = l+1;l++;
	int ans = 0;
	while(l<=r)
	{
		int mid = (l+r)>>1;
		if(a[mid] <v)
		{
			ans = mid;
			l = mid+1;
		}
		else r = mid - 1;
	}
	if(ans == 0) return 0;
	return ans - pre+1;
}
void solve()
{
	n = read();
	rep(i,1,n) a[i] = read();
	sort(a+1,a+1+n);
	int ans = 0;
//	rep(i,1,n)
//	{
//		rep(j,i+1,n)
//		{
//			int cnt = erfen(a[i]+a[j],j);
//			ans+=cnt;
//		}
//	}
	rep(i,1,n-2)
	{
		rep(j,i+1,n-1)
		{
			int k = j+1;
			while(a[k]<a[i]+a[j]&&k<=n)
			{
				k++;
				ans++;
			}
		}
	}
	cout<<ans;
 } 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
//	int T = read();
//	while(T--)
	solve();
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, l, r, capacity = 100000, sold = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sold += (r - l + 1);
  }
  if (sold <= capacity) {
    cout << sold << endl;
  }
  else {
    cout << capacity << endl;
  }
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    h: usize,
    w: usize,
    a: usize,
    b: usize,
  }
  for i in 0 .. h {
    for j in 0 .. w {
      if (i < b) == (j < a) {
        puts!("0");
      } else {
        puts!("1");
      }
    }
    puts!("\n");
  }
}


Measured memory_bytes: 5244
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Cards
    {
        readonly int N = 51;

        long[][] dp;
        int[] cards;

        int n, target;

        public Cards(int n, int a)
        {
            dp = new long[N][];

            for (int i = 0; i < N; i++)
            {
                dp[i] = Enumerable.Repeat((long)-1, N * N).ToArray();
            }

            cards = new int[N];

            this.n = n;
            target = a;
        }

        public void MakeMap(string[] source)
        {
            for (int i = 0; i < source.Length; i++)
            {
                cards[i + 1] = int.Parse(source[i]);
            }
        }

        public long Solve()
        {
            dp[0][0] = 1;

            int sum = 0;

            for (int k = 1; k <= n; k++)
            {
                sum += cards[k];

                for (int i = k; i > 0; i--)
                {
                    for (int j = sum; j >= cards[k]; j--)
                    {
                        if (dp[i - 1][j - cards[k]] == -1) continue;

                        if (dp[i][j] == -1) dp[i][j] = 0;

                        dp[i][j] += dp[i - 1][j - cards[k]];
                    }
                }
            }

            long ret = 0;

            for (int i = 1; i <= n; i++)
            {
                if (dp[i][i * target] != -1) ret += dp[i][i * target];
            }
            return ret;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int a = int.Parse(input[1]);

            Cards cs = new Cards(n, a);

            input = Console.ReadLine().Split(' ');

            cs.MakeMap(input);

            Console.WriteLine(cs.Solve());
        }
    }
}

Measured memory_bytes: 8024
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)
#define int ll
struct st{
    int first,second,ident;
    bool operator < (st obj) const{
        return this->second < obj.second;
    }
};

signed main(){
    int n;
    while(cin>>n&&n){
        set<pii> free;
        set<st> used;
        free.insert(pii(0,1e9+1));
        rep(i,n){
            char ch;
            cin>>ch;
            if(ch=='W'){
                int num,len;
                cin>>num>>len;
                while(len>0){
                    pii tmp = *(free.begin());
                    free.erase(free.begin());
                    if(tmp.second-tmp.first<=len){  //????????????
                        len -= tmp.second-tmp.first;
                        used.insert(st{tmp.first,tmp.second,num});
                    }
                    else{                           //????????????????????????
                        used.insert(st{tmp.first,tmp.first+len,num});
                        free.insert(pii(tmp.first+len,tmp.second));
                        len = 0;
                    }
                }
            }
            if(ch=='D'){
                int num;
                cin>>num;
                auto itr = used.begin();
                while (itr != used.end()) {
                    if (itr->ident==num) {
                        st tmp = *itr;
                        free.insert(pii(tmp.first,tmp.second)); //??????????£?
                        used.erase(itr++);
                    }
                    else {
                        itr++;
                    }
                }
            }
            if(ch=='R'){
                int pos;
                cin>>pos;
                auto res = used.upper_bound(st{0,pos,0});
                if(res==used.end())cout<<"-1"<<endl;
                else{
                    if(res->first>pos)cout<<"-1"<<endl;
                    else{
                        st tmp = *(res);
                        cout<<tmp.ident<<endl;
                    }
                }
            }
        }
        cout<<endl;
    }
    
}

Measured memory_bytes: 3472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) {
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") {
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

struct root {
	int i;
	int value;
};

int main() {
	string n;
	cin >> n;
	switch (n[n.size() - 1]) {
		case '2':
		case '4':
		case '5':
		case '7':
		case '9':
			cout << "hon" << endl;
			break;
		case '0':
		case '1':
		case '6':
		case '8':
			cout << "pon" << endl;
			break;
		case '3':
			cout << "bon" << endl;
			break;
	}
	return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cmath>
using namespace std;
#define pi 3.141592653589793

int main() {
  double a, b, x;
  double angle;
  scanf("%lf %lf %lf", &a, &b, &x);
  double area = x / a;
  if (x <= a*a*b/2) {
    angle = atan(b*b/(2*area));
  }
  else
    angle = atan(2*b/a-2*area/(a*a));
  printf("%.10lf\n", angle*180/pi);
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

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] % INF) % INF;
}
///////////////////////////////////////

int main() {
	int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
	vector<int>p, q, r;
	REP(i, a) {
		int z; cin >> z;
		p.push_back(z);
	}
	REP(i, b) {
		int z; cin >> z;
		q.push_back(z);
	}
	REP(i, c) {
		int z; cin >> z;
		r.push_back(z);
	}
	sort(p.begin(), p.end(), greater<int>());
	sort(q.begin(), q.end(), greater<int>());
	vector<int>all;
	REP(i, x)all.push_back(p[i]);
	REP(i, y)all.push_back(q[i]);
	REP(i, c)all.push_back(r[i]);
	sort(all.begin(), all.end(), greater<int>());
	ll ans = 0;
	REP(i, x + y) {
		ans += all[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 1e5 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

ll n,i,mx[N],p,q,maxx,cur;
LL a[N],b[N];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    q = n + 1; a[q].sc = inf;
    cin>>n;
    for (i = 1;i <= n;i++){
        cin>>a[i].fs>>a[i].sc;
        a[i].sc++;
        maxx = max(maxx,a[i].sc - a[i].fs);
        if (a[i].fs > a[p].fs) p = i;
        if (a[i].sc < a[q].sc) q = i;
    }
    p = a[p].fs; q = a[q].sc;
    ll ans = maxx + max(0ll,q - p);
    for (i = 1;i <= n;i++){
        b[i].fs = max(0ll,a[i].sc - p);
        b[i].sc = q - a[i].fs;
    }
    sort(b + 1,b + n + 1);
    for (i = n;i >= 1;i--) mx[i] = max(mx[i + 1],b[i].sc);
    cur = b[1].sc;
    for (i = 1;i <= n;i++){
        if (i == 1) ans = max(ans,b[i].fs + mx[i + 1]);
        else ans = max(ans,b[i].fs + max(cur,mx[i + 1]));
        cur = min(cur,b[i].sc);
    }
    cout<<ans;
}


Measured memory_bytes: 7492
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cmp::*;
use std::collections::*;

fn main() {
    let (n, m): (usize, usize) = readln();
    let mut freq: Vec<usize> = vec![1;n+1];
    let mut flag: Vec<bool> = vec![false;n+1];
    freq[0] = 0;
    flag[1] = true;
    for _ in 0..m {
        let (x, y): (usize, usize) = readln();

        freq[x] -= 1;
        freq[y] += 1;
        flag[y] |= flag[x];

        if freq[x] == 0 {
            flag[x] = false;
        }
    }

    let mut res = 0;
    for b in flag {
        if b {
            res += 1;
        }
    }

    println!("{}", res);

}


fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_string()
}

fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

fn readln<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

trait Read {
    fn read(s: &str) -> Self;
}

macro_rules! read_impl{
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}


Measured memory_bytes: 4476
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

h,w=LI()
h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0})
dp=[1e6]*(h*w)
dp[w+1]=g[w+1]

for j in range(h*w-w):
  for d in (1,w):
    dp[j+d]=min(dp[j]+1 if (g[j],g[j+d])==(0,1) else dp[j],dp[j+d])

print(dp[(h-2)*w+w-2])


Measured memory_bytes: 41708
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b = LI()
    print(min(n*a,b))
    return

#B
def B():
    s = S()
    print(s.count("1"))
    return

#C
def C():
    n = list(map(int, S()))
    k = 0
    s = sum(n)
    for i in range(len(n)):
        k *= 10
        k += n[i]
    if k%s == 0:
        print("Yes")
    else:
        print("No")
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 39024
#include<iostream>
#include<string>
using namespace std;
int p;
int cnt;
void calc(char t){
  if ( p == 25 ) cnt++;
  p = (p+1)%26;

  while(1){
    if ( p == (t-'A') ) break;
    if ( p == 25 ) cnt++;
    p = (p+1)%26;
  }
}

main(){
  string s;
  cin >> s;
  p = 0;
  cnt = 0;
  for ( int i = 0; i < s.size(); i++ ) calc(s[i]);
  cout << cnt << endl;
}

Measured memory_bytes: 3156
from itertools import product
N=int(input())
XYs = []
for i in range(N):
    A = int(input())
    XYs.append([tuple(map(int, input().split())) for _ in range(A)])

n=0
for ts in product(*[[1, 0] for _ in range(N)]):
    for i, t in enumerate(ts):
        if t:
            if not all(ts[x-1] == y for x, y in XYs[i]):
                break
    else:
        n=max(n,sum(ts))
print(n)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}

double calcAngle(double h, double m)
{
    double hour_angle = 0.5 * (h * 60 + m);
    double minute_angle = 6 * m;
    double angle = abs(hour_angle - minute_angle);
    angle = min(360 - angle, angle);
    return angle;
}
double third_side(int a, int b, double c)
{
    double pi = 2 * acos(0.0);
    double angle = c * (pi / 180);
    return sqrt((a * a) + (b * b) - 2 * a * b * cos(angle));
}
int main()
{
    fastio();
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << fixed << setprecision(10) << third_side(a, b, calcAngle(c, d));
}


Measured memory_bytes: 4240
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        "\n"
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
  
int n;
cin>>n;
unordered_map<string,int>map;
int count=0;
rep(i,0,n)
{
	string a;
	cin>>a;
	if(map.count(a)==0)
	count++;
	map[a]++;
}
cout<<count<<endl;
return 0;
}

Measured memory_bytes: 17704
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    map<string, int> mp;
    int n;
    cin >> n;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int m;
    cin >> m;
    rep(i, m) {
        string s;
        cin >> s;
        mp[s]--;
    }
    int ans = -1001001001;
    for (auto p : mp) {
        chmax(ans, p.second);
    }
    if (ans < 0) cout << 0 << endl;
    else cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int a,b,c,d;

int main(){
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << '\n';
}

Measured memory_bytes: 256
n,m=map(int,input().split())
INF=float('inf')
G=[]
for _ in range(m):
  a,b,c=map(int,input().split())
  G.append([a-1,b-1,-c])
  
def main():
  D=[INF for _ in range(n)]
  D[0]=0
  for i in range(n):
    for x,y,z in G:
      if D[x]!=INF and D[y]>D[x]+z:
        D[y]=D[x]+z
        if i==n-1 and y==n-1:
          return 'inf'
  return -D[n-1]
   
if __name__=='__main__':
  print(main())

Measured memory_bytes: 74724
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int m;
    cin >> m;
    cout << 24 + (24 - m) << endl;
}

Measured memory_bytes: 256
// B.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 100; ; --i) {
		if ((a % i) == 0 && (b % i) == 0) {
			if (--k == 0) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}


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

typedef pair<int,int> P;

int main() {
  //input
  int N;
  cin >> N;
  priority_queue<P, vector<P>, greater<P>> pq;
  int p;
  rep(i,N) {
    cin >> p;
    pq.push(make_pair(p, i));
  }
  //calc
  int answer = 0;
  int flag = INF;
  while (!pq.empty()) {
    P entry = pq.top(); pq.pop();
    if ( entry.second < flag ) {
      answer++;
      flag = entry.second;
    }
    if ( entry.second == 0 ) {
      break;
    }
  }
  //output
  cout << answer << endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#include<limits.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define MAX 100000

struct node{
    // parent　親ノード
    // left 左の子ノード
    // right 右の子ノード
    int parent = -1;
    int left = -1;
    int right = -1;
};


vector<node> tree(MAX);
vector<int> node_depth(MAX, -1);
vector<int> node_degree(MAX, 0);
vector<int> node_sibling(MAX, -1);
vector<int> node_height(MAX);

int depth = 0;
int hight;
void DFS(int id){
    if(tree.at(id).left != -1){
        depth++;
        DFS(tree.at(id).left);
        depth--;
    }
    if(tree.at(id).right != -1){
        depth++;
        DFS(tree.at(id).right);
        depth--;
    }
    

    //子が存在しない時をheight 0とする。
    if(tree.at(id).right == -1 && tree.at(id).left == -1){
        node_height.at(id) = 0;
    }else if(tree.at(id).right == -1){
        node_height.at(id) = node_height.at(tree.at(id).left) + 1;
    }else if(tree.at(id).left == -1){
        node_height.at(id) = node_height.at(tree.at(id).right) + 1;
    }else{
        node_height.at(id) = max(node_height.at(tree.at(id).left), node_height.at(tree.at(id).right)) + 1;
    }
    node_depth.at(id) = depth;
    return;
}

void printMode(int id){
    if(tree.at(id).parent == -1){
        cout << "root";
    }else if(tree.at(id).left == -1 && tree.at(id).right == -1){
        cout << "leaf";
    }else{
        cout << "internal node";
    }
}

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


    rep(i, n){
        int id;
        int left_child_index;
        int right_child_index;
        cin >> id >> left_child_index >> right_child_index;
        tree.at(id).left = left_child_index;
        tree.at(id).right = right_child_index;


        if(left_child_index != -1){
            tree.at(left_child_index).parent = id;
            node_degree.at(id)++;
            node_sibling.at(left_child_index) = right_child_index;
        }
        if(right_child_index != -1){
            tree.at(right_child_index).parent = id;
            node_degree.at(id)++;
            node_sibling.at(right_child_index) = left_child_index;
        }
    }

    // ルートノードを探す
    int root_index;
    rep(i, n){
        if(tree.at(i).parent == -1){
            root_index = i;
            break;
        }
    }
    
    // depth first searchによって各ノードの深さを計算
    DFS(root_index);

    // cout << "============result=============" << endl;
    rep(i, n){
        cout << "node " << i << ": parent = " <<  tree.at(i).parent << ", sibling = " << node_sibling.at(i) << ", degree = " << node_degree.at(i) <<  ", depth = " << node_depth.at(i) << ", height = " << node_height.at(i);
        cout << ", ";
        printMode(i);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 5328
import sys
sys.setrecursionlimit(10**5+10)
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])
MOD = 1000000007
memo = {}
def Fib(n, MOD):
    if n in A:
        return 0
    elif n == 0:
        return 1
    elif n == 1:
        return 1
    elif n in memo:
        return memo[n]
    else:
        memo[n] = ( Fib(n-1, MOD) + Fib(n-2, MOD) ) % MOD
        return memo[n]
print(Fib(N, MOD))

Measured memory_bytes: 98444
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll n, m;
    cin >> n >> m;
    map<ll, set<ll>> edges;
    for (ll i = 0; i < m; ++i) {
        ll a, b;
        cin >> a >> b;
        --a; --b;
        if (edges.find(a) == edges.end()) {
            edges[a] = set<ll>();
        }
        edges[a].insert(b);
        if (edges.find(b) == edges.end()) {
            edges[b] = set<ll>();
        }
        edges[b].insert(a);
    }
    set<ll> visited;
    queue<ll> q;
    q.push(0);
    vector<ll> res(n);
    vector<ll> dist(n, 1e9);
    dist[0] = 0;
    while (!q.empty()) {
        ll cur = q.front(); q.pop();
        visited.insert(cur);
        for (ll next : edges[cur]) {
            ll d = dist[cur] + 1;
            if (d < dist[next]) {
                dist[next] = d;
                res[next] = cur + 1;
                q.push(next);
            }
        }
    }
    bool ok = true;
    for (auto d : dist) {
        if (d == 1e9) {
            ok = false;
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (ll i = 1; i < n; ++i) {
        cout << res[i] << endl;
    }

}



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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int a; cin >> a;
    cout << 3 * a * a << endl;
}


Measured memory_bytes: 256
import math

ts = [int(input()), int(input()), int(input()), int(input()), int(input())]

ans = float('inf')
for i in range(5):
    time = 0
    for j in range(4):
        t = ts[(i + j) % 5]
        time += math.ceil(t / 10) * 10
    time += ts[(i + 4) % 5]
    ans = min(time, ans)
print(ans)


Measured memory_bytes: 3064
using System;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {


            //テンプレート
            //// 整数の入力
            //int a = int.Parse(Console.ReadLine());
            //// スペース区切りの整数の入力
            //string[] input = Console.ReadLine().Split(' ');
            //int b = int.Parse(input[0]);
            //int c = int.Parse(input[1]);
            //// 文字列の入力
            //string s = Console.ReadLine();
            ////出力
            //Console.WriteLine(a + b + c + " " + s);


            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            int get_coins;

            if (b >= a)
                get_coins = 2 * b - 1;
            else
                get_coins = 2 * a - 1;


            if (b > a)
                get_coins = 2 * b - 1;
            else if (b == a)
                get_coins = 2 * b;
            else
                get_coins = 2 * a - 1;

            Console.WriteLine(get_coins);
 //           Console.ReadLine();

        }

    }
}

Measured memory_bytes: 13140