akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
dict_ = {i:tuple(map(int, input().split())) for i in range(m)}

sorted_dict = sorted(dict_.items(), key=lambda x: x[1])

res = {}
tmp = ''
cnt = 0
for item in sorted_dict:
    if item[1][0] == tmp:
        cnt += 1
    else:
        tmp = item[1][0]
        cnt = 1
    res[item[0]] = str(item[1][0]).zfill(6) + str(cnt).zfill(6)

for i in sorted(res.items()):
    print(i[1])



Measured memory_bytes: 53260
#include <bits/stdc++.h>
using namespace std;
int p,q,r;
int ans;
int main()
{
	cin>>p>>q>>r;
	ans=p+q+r;
	ans=min(ans,p+q);
	ans=min(ans,q+r);
	ans=min(ans,p+r);
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

S = sum(A) - 2 * A[0]
res = abs(S)
flag = 1
while res != 0 and flag < N - 2:
    S -= 2 * A[flag]
    if res > abs(S):
        res = abs(S)
    flag += 1
print(res)

Measured memory_bytes: 24832
N, K = map(int,input().split())
from math import ceil, log2
m_list = [ceil(log2(K/(n+1))) if n+1<K else 0 for n in range(N)]
#print(m_list) #各nに対し勝つのに必要な表の数

#
# m_list = []
# for n in range(N):
#     if n+1 >=

def calc_prob(x):
    return (1/2)**x

prob_list = list(map(calc_prob,m_list))

# Kより大きいインデックスのところは1に書き換え
#print(prob_list)
print(sum(prob_list)/N)

Measured memory_bytes: 7064
#include <stdio.h>

#define MAX 100

void sort(int *,int );
int check(int *,int *,int );

int main(){
	int p[MAX];
	int q[MAX];
	int n;

	scanf("%d",&n);

	for(int i=0; i<n; i++){
		scanf("%d",&p[i]);
		q[i]=p[i];
	}
	sort(q,n);
	if(check(p,q,n)<=2)
		printf("YES\n");
	else
		printf("NO\n");

	return 0;
}

void sort(int *q,int n)
{
	int i, j;
	int temp;

	for(i=0; i<n-1; i++){
		for(j=i+1; j<n; j++){
			if(q[i]>q[j]){
				temp=q[i];
				q[i]=q[j];
				q[j]=temp;
			}
		}
	}
}

int check(int *p,int *q,int n)
{
	int count=0;
	
	for(int i=0; i<n; i++){
		if(p[i]!=q[i])
			count++;
	}

	return count;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, a[112345];
LL cou[112345], max, ans;

int main()
{
	in >> N;
	rep(i, N) { in >> a[i]; }

	rep(i, N)
	{
		cou[a[i]]++;
		max = std::max(max, a[i]);
	}
	rep(i, max + 1)
	{
		ans = std::max(ans, cou[i] + cou[i + 1] + cou[i + 2]);
	}

	out << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1792
def gcd(a, b):
    if a<b:
        a,b = b,a
    r = a%b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b
n = int(input())
a = list(map(int,input().split()))
ans = gcd(a[0],a[1])
for i in range(2,n):
    ans = gcd(ans,a[i])
print(ans)

Measured memory_bytes: 20064
// Created by abhay
#include <bits/stdc++.h>
#define sz(a) 			int((a).size())
#define pb 				push_back
#define all(c) 			c.begin(),c.end()
#define tr(c,i) 		for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) 	(c.find(x) != c.end())
#define cpresent(c,x) 	(find(allc,x) != c.end())
#define rep(i,n) 		for(int i=0;i<(n);++i)
#define int 		 	long long
#define w(tc)           int tc; cin>>tc; while(tc--)
#define ff              first
#define se              second
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define ps(x,y)         fixed<<setprecision(y)<<x
#define ne              "\n"

using namespace std;

int32_t main()

{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int x;
	cin >> x;
	int a = 100;
	for (int i = 1; i <= 8000; i++)
	{
		a = a + (a * 1) / 100;

		if (a >= x)
		{
			cout << i;
			return 0;
		}

	}
}

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

int main(){
  vector<int> x(4);
  vector<int> y(4);
  int diffx, diffy;

  for(int i = 0; i < 2; ++i){
    cin >> x.at(i) >> y.at(i);
  }

  diffx = x.at(1) - x.at(0);
  diffy = y.at(1) - y.at(0);
  x.at(2) = x.at(1) - diffy;
  y.at(2) = y.at(1) + diffx;
  x.at(3) = x.at(2) - diffx;
  y.at(3) = y.at(2) - diffy;

  cout << x.at(2) << " " << y.at(2)<< " " << x.at(3) << " " << y.at(3) << endl;




  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  
  cin >> N;
  vector<string> ao(N);
  
  for(int i=0; i < N; i++) {
    cin >> ao.at(i);
  }
  
  cin >> M;
  vector<string> aka(M);
  
  for(int i=0; i < M; i++) {
    cin >> aka.at(i);
  }
  
  vector<int> kazu(N);
  
  for(int i=0; i < N; i++) {
    for( int j=0; j < N; j++) {
      if(ao.at(i) == ao.at(j)) {
        kazu.at(i)++;
      }
    }
    
    for( int j=0; j < M; j++) {
      if(ao.at(i) == aka.at(j)) {
        kazu.at(i)--;
      }
    }
  }
  
  int answer =0;
  for(int i=0; i < N; i++) {
    answer = max(answer,kazu.at(i));
  }
  
  cout << answer << endl;
}
    
    
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    ll ans = 1002003004;

    ans = min(ans, a*x+b*y);
    ans = min(ans, max(x,y)*2 * c);
    if(x >= y) ans = min(ans, y*2 * c + (x-y) * a);
    if(x < y)  ans = min(ans, x*2 * c + (y-x) * b);

    cout << ans << endl;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : Anik Das *
* NICK : sadn1ck *
* INSTITUTION : IIEST Shibpur *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
  //freopen("/home/anik/Desktop/cp/input.txt", "r", stdin); 
  //freopen("/home/anik/Desktop/cp/output.txt", "w", stdout); 
	ll n=0;
  cin >> n;
  ll count=0;
  while(n>=500){
    n-=500;
    // cout << n<< " ";
    count+=1000;
  }
  while(n>=5){
    n=n-5;
    count+=5;
  }
  cout << count;
  
	
	
	return 0;
}


Measured memory_bytes: 256
use std::io;
use std::io::prelude::*;
use std::cmp::max;

fn main() {

    let stdin = io::stdin();
    let mut lines = stdin.lock().lines().map(|x| x.unwrap());

    let num_days: usize = lines.next().unwrap().trim().parse().unwrap();
    let mut days: Vec<Vec<u32>> = vec![];
    for _ in 0..num_days {
        let day = lines.next().unwrap().trim().split_whitespace().map(|x| x.parse().expect("Error")).collect();
        days.push(day);
    }

    let mut dp = days[0].clone();

    for i in 1..num_days {

        let mut temp = vec![0; 3];
        for j in 0..3 {
            let mut max_prev = 0;
            for k in 0..3 {
                if j == k { continue }
                max_prev = max(max_prev, dp[k])
            }
            temp[j] = days[i][j] + max_prev;
        }
        dp = temp;
    }

    let result: &u32 = dp.iter().max().unwrap();
    println!("{}", result);
}

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

int main() {
  long long l, r;
  cin >> l >> r;
  int mod = 2019;
  long long ans = 2019;
  if (r - l >= 2019)
    cout << 0;
  else {
    for (long long i = l; i <= r - 1; i++) {
      for (long long j = i + 1; j <= r; j++) {
        long long tmp = (i * j) % mod;
        ans = min(ans, tmp);
      }
    }
    cout << ans;
  }

  return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define MAXN
#define MAXM
#define scanf(a) scanf("%d",&a)
#define print(a) printf("%d",a)
#define printn(a) printf("%d\n",&a);
using namespace std;
int n,m;
struct qwq
{
	int a,c;
}e[10];
bool cmp(qwq x,qwq y)
{
	return x.c<y.c;
}
int main()
{
	for (int i=1;i<=5;i++)
	{
		scanf(e[i].a);
		for (int j=1;j<=9;j++)
		{
			if ((e[i].a+j)%10==0)
			{
				e[i].c=j;
				break;
			}
		}
	}
	sort(e+1,e+6,cmp);
	int sum=0;
	for (int i=1;i<=4;i++)
	{
		sum+=e[i].a;
		sum+=e[i].c;
	}
	sum+=e[5].a;
	print(sum);
	return 0;
}


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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int i = a;i < b;++i) cout << ary[i] << (b-1 == i ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

int main () {
    int n,k;
    vector<int> a(110);
    cin >> n >> k;
    for (int i = 0;i < n;++i) cin >> a[i];
    vector<bool> dp(100010,false);
    for (int i = 0;i <= k;++i) for (int j = 0;j < n;++j) if (i-a[j] >= 0 && !dp[i-a[j]]) dp[i] = true;
    cout << (dp[k] ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * Dictionary.c
 *
 *  Created on: 2015/02/16
 */
#include<stdio.h>
#include<string.h>

#define M 1000213

void insert(char*);
int find(char*);
int get_key(char*);
int get_keycode(char);
int get_hash_num(int,int);

char hash[M][13]={"\0"};

int main(void){
	int n;
	int i;
	char str[13],input[7];

	scanf("%d",&n);

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

		if(input[0]=='i') insert(str);

		if(input[0]=='f'){
			if(find(str)==1) printf("yes\n");
			else printf("no\n");
		}
	}

	return 0;
}

void insert(char *str){
	int i=0,hash_num,data;

	data=get_key(str);

	while(1){
		hash_num=get_hash_num(data,i);
		if(strcmp(hash[hash_num],"\0")==0){
			strcpy(hash[hash_num],str);
			break;
		}
		i++;
	}

}

int find(char *str){
	int data,hash_num,i=0;

	data=get_key(str);

	while(1){
		hash_num=get_hash_num(data,i);
		if(strcmp(hash[hash_num],"\0")==0) return 0;
		if(strcmp(hash[hash_num],str)==0) return 1;
		i++;
	}
}

int get_key(char *str){
	int data=0,cnt=0,p=1;

	while(str[cnt]!='\0'){
		data+=p*get_keycode(str[cnt]);
		p*=5;
		cnt++;
	}

	return data;
}

int get_keycode(char work){
	switch(work){
	case 'A':
		return 1;
	case 'C':
		return 2;
	case 'G':
		return 3;
	case 'T':
		return 4;
	}
}

int get_hash_num(int data,int i){
	return ((data%M)+i*(data%(M-1)+1))%M;
}

Measured memory_bytes: 13300
#include<stdio.h>
int main(void){

    int r,c, i,j, sum=0,rsum[100] = {},csum[100] = {};
    int Array[100][100] = {};

    scanf("%d %d", &r, &c);

    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            scanf("%d", &Array[i][j]);
            csum[i] += Array[i][j];
            rsum[j] += Array[i][j]; 
            sum += Array[i][j];
        }
    }


    for(i = 0; i <= r; i++){
        for(j = 0; j <=c; j++){
            if(j == c && i == r){
                printf("%d",sum);
            }else if(j == c){
                printf("%d",csum[i]);
            }else if(i == r){
                printf("%d ",rsum[j]);
            }else{
                printf("%d ",Array[i][j]);
            }


        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 652
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll h;
  cin >> h; 
  ll ans = 0;
  ll leg = 1;
  ll co = 0;

  while(h!=1){
    h = (h/2);
    ans += leg;
    leg*=2;
    co++;
  }
  co++;
  pri((1ll<<co)-1);
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;

namespace Atcoder
{
    class Program
    {
        private const long COMDIV = 1000000007;
        static void Main(string[] args)
        {
            var r = Console.ReadLine();
            var hon = new int[] {2,4,5,9,7 };
            var pon = new int[] { 0, 1, 6, 8 };
            var bon = new int[] { 3 };
            var target = int.Parse(r.Last().ToString());
            if (bon.Contains(target))
            {
                Console.WriteLine("bon");
            }else if (hon.Contains(target))
            {
                Console.WriteLine("hon");
            }else if (pon.Contains(target))
            {
                Console.WriteLine("pon");
            }

        }
        
    }
}

Measured memory_bytes: 18584
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
string ans = "" ;
ll dp[3005][3005];
int main()
{
    ios;
    string s, t ;
    cin >> s >> t;
    ll n = s.len , m = t.len ;
    ms(dp) ;
    forn(i , 1 , n){
       forn(j , 1 , m ) {
          if(s[i-1] == t[j-1]){
              dp[i][j] = max(dp[i][j] ,  1 + dp[i-1][j-1] ) ;
          }
          else {
            dp[i][j] = max(dp[i][j] , max(dp[i-1][j] , dp[i][j-1])) ;
          }
       }
    }
    ll maxx = dp[n][m] ;
    ll i = n , j = m ;
    while(1){
        if(i == 0 or j == 0) br ;
        ll currmax = dp[i][j] ;
        ll left = dp[i][j-1] ;
        ll top = dp[i-1][j] ;
        ll dig  = dp[i-1][j-1] ;
        if(s[i-1] == t[j-1]){
            ans = ans + s[i-1] ;
            --i ;
            --j ;
        }
        else {
            if(left > top){
                --j ;
            }
            else if(top > left){
                --i;
            }
            else if(left == top){
                --i;
            }
        }
    }
    reverse(all(ans)) ;
    cout << ans << el ;
    ro ;

}


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

using namespace std;

#define int long long
int const maxn = 1e5 + 5;
int a[maxn];

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k = 1, b = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i < n; ++i) {
        a[i] *= 2;
        k = k * (-1), b = a[i] - b;
    }
    a[n] *= 2;
    int x = (a[n] - b) / 2;
    k = 1, b = 0;
    for (int i = 1; i <= n; ++i) {
        cout << k * x + b << " ";
        k = k * (-1), b = a[i] - b;
    }
    return 0;
}



Measured memory_bytes: 2176
#include <stdio.h>
int main(){
	int cont = 0;
	char a[3];
	char b[3];
	scanf("%s", a);
	scanf("%s", b);
	if (a[0]==b[0]){
		cont+=1;
	}
	if (a[1]==b[1]){
		cont+=1;
	}
	if (a[2]==b[2]){
		cont+=1;
	}
	printf("%d\n",cont );
	return 0;
}

Measured memory_bytes: 128
s = input()
first = s[:2]
second = s[2:]

f = int(first)
s = int(second)

# print(f,s)

if(1 <= f <= 12 and 1 <= s <= 12):
	print("AMBIGUOUS")
elif (1 <= f <= 12):
	print("MMYY")
elif (1 <= s <= 12):
	print("YYMM")
else:
	print("NA")

Measured memory_bytes: 3060
n, h = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

a_all = [_ab[0] for _ab in ab]
b_all = [_ab[1] for _ab in ab]

a_max = max(a_all)

b_all_useful = []
for b in b_all:
    if b > a_max:
        b_all_useful.append(b)

b_all_useful.sort()

useful_sum = sum(b_all_useful)
if useful_sum > h:
    counter = 0
    i = 0
    while True:
        counter += b_all_useful[-1 * (i + 1)]
        i += 1
        if counter >= h:
            break
    print(i)

else:
    h_new = h - useful_sum
    import math
    print(math.ceil(h_new / a_max) + len(b_all_useful))


Measured memory_bytes: 69208
#ifndef _BLESS_MCLAREN_MCL32_
#define _BLESS_MCLAREN_MCL32_ true
#endif

#ifndef _BLESS_FERNANDO_ALONSO_14_
#define _BLESS_FERNANDO_ALONSO_14_ true
#endif

#ifndef _FERNANDO_ALONSO_WILL_WIN_ANOTHER_CHAMPIONSHIP_
#define _FERNANDO_ALONSO_WILL_WIN_ANOTHER_CHAMPIONSHIP_ true
#endif

#ifndef _1731_TRUE_LOVE_
#define _1731_TRUE_LOVE_ true
#endif

#ifndef _CIVILIZATION_
#define _CIVILIZATION_ true
#endif

#include <bits/stdc++.h>
using namespace std;

int sum() { return 0; }
template<typename T, typename ...Args>
auto sum(const T& x, Args ...args) { return x + sum(args...); }

#define _error(args...) { vector<string> _v; string _str = #args; split(_v, _str, ','); _output(args); }
#define _output(args...) { cerr << "* "; err(_v.begin(), args); }
void split(vector<string>& vec, const string& str, const char& ch) {
    string t = "";
    for (size_t i = 0; i <= str.size(); i++)
        if (i == str.size() || str[i] == ch) t = (vec.push_back(t), ""); else t += str[i];
}
void err(vector<string>::iterator it) { cerr << "\n"; }
template<typename T, typename ...Args>
void err(vector<string>::iterator it, const T& x, Args ...args) {
    cerr << it->substr((*it)[0] == ' ') << " = " << x << "  ";
    err(++it, args...);
}

typedef long long ll;

const int MAX_N = (int)1e5 + 5;
const ll MOD = 1e9 + 7;
ll inv[MAX_N], pinv[MAX_N], perm[MAX_N];
int n, occur[MAX_N];

void get_p() {
    inv[1] = pinv[1] = inv[0] = perm[0] = perm[1] = pinv[0] = 1;
    for (int i = 2; i <= n + 1; i++) {
        perm[i] = perm[i - 1] * i % MOD;
        inv[i] = -MOD / i * inv[MOD % i] % MOD + MOD;
        pinv[i] = pinv[i - 1] * inv[i] % MOD;
    }
}

ll C(int n, int m) {
    return n <= m ? (perm[m] * pinv[n] % MOD) * pinv[m - n] % MOD : 0;
}

int main() {
    {
        assert(_BLESS_MCLAREN_MCL32_);
        assert(_BLESS_FERNANDO_ALONSO_14_);
        assert(_FERNANDO_ALONSO_WILL_WIN_ANOTHER_CHAMPIONSHIP_);
        assert(_1731_TRUE_LOVE_);
        assert(_CIVILIZATION_);
    }
    
    int all, temp, x;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) 
        scanf("%d", &x), occur[x] ? all = n - i + occur[x] : occur[x] = i;
//    _error(all);
    get_p();
    for (int i = 1; i <= n + 1; i++) {
        temp = C(i, n + 1) - C(i - 1, all);
        if (temp < 0) temp += MOD;
        printf("%d\n", temp);
//        int a = C(i, n + 1), b = C(i - 1, all);
//        _error(a, b);
    }
    return 0;;
}


Measured memory_bytes: 3968
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	string s;
	cin >> n >> s;
	int ans = 0;

	for (int d = 1; d < n; d++) {
		int i = 0;
		while (i + d < n) {
			int len = 0;
			while (i + len < d + i && d + i + len < n && s[i + len] == s[d + i + len]) {
				len++;
			}
			ans = max(ans, len);
			i += max(1, len);
		}
	}



	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define mp  make_pair
#define SIZE 101
ll ans=0;
void sol(ll t[],ll n){
	ll mine=INT_MAX;
	for(ll i=0;i<n;++i){
		// cout<<t[i]<<" ";
		if(t[i]!=0)
			mine=min(mine,t[i]);
	}
	// cout<<endl;
	if(mine==INT_MAX)
		return;
	ll seg=0;
	ll prev=0;
	for(ll i=0;i<n;++i){
		if(prev==0&&t[i]!=0){
			seg++;
		}
		prev=t[i];
		if(t[i]!=0)
			t[i]=t[i]-mine;
	}
	ans+=seg*mine;
	// cout<<ans<<endl;
	sol(t,n);
}

int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ll n;
	cin>>n;
	ll t[n];
	for(ll i=0;i<n;++i){
		cin>>t[i];
	}
	sol(t,n);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include  <cassert>
#include <fstream>
#include <codecvt>

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


static const int N = 4;
static const int N2 = 16;
static const int LIMIT = 100;
static const char dir[4] = { 'r','u','l','d' };
int MDT[N2][N2];

struct Puzzle {
	int f[N2], space, MD;
};

Puzzle state;
int limit;
int path[LIMIT];

int GetAllMD(Puzzle pz) {
	int sum = 0;
	rep(i, N2) {
		if (pz.f[i] == N2) continue;
		sum += MDT[i][pz.f[i] - 1];
	}
	return sum;
}

bool isSolved() {
	rep(i, N2) if (state.f[i] != i + 1) return false;
	return true;
}

bool dfs(int depth, int prev) {
	if (state.MD == 0) return true;
	if (depth + state.MD > limit) return false;
	int sx = state.space / N;
	int sy = state.space % N;
	Puzzle tmp;

	rep(r, 4) {
		int tx = sx + dx[r];
		int ty = sy + dy[r];
		if (tx < 0 or ty < 0 or tx >= N or ty >= N)  continue;
		if (max(prev, r) - min(prev, r) == 2) continue;
		tmp = state;
		state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
		state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
		swap(state.f[tx * N + ty], state.f[sx * N + sy]);
		state.space = tx * N + ty;
		if (dfs(depth + 1, r)) { path[depth] = r; return true; }
		state = tmp;
	}
	return false;
}

string iterative_deepning(Puzzle in) {
	in.MD = GetAllMD(in);
	for (limit = in.MD; limit <= LIMIT; limit++) {
		state = in;
		if (dfs(0, -100)) {
			string ans = "";
			rep(i, limit) ans += dir[path[i]];
			return ans;
		}
	}
}

signed main() {
	ios::sync_with_stdio(true);
	
	rep(i, N2) {
		rep(j, N2)
			MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
	}


	Puzzle in;
	rep(i, N2) {
		cin >> in.f[i];
		if (in.f[i] == 0) {
			in.f[i] = N2;
			in.space = i;
		}
	}

	cout << iterative_deepning(in).size() << endl;

	return 0;
}


Measured memory_bytes: 3220
N = int(input())

A = []
for i in range(N):
    A.append(list(map(int, input().split())))

A.sort(key=lambda x: (x[1], x[0]))

gokei = 0
for i in A:
    gokei += i[0]
    if gokei > i[1]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 59704
class Dinic
  def initialize(v, inf = 2**30)
    @V = v
    @inf = inf
    @g = Array.new(v) {[]}
    @level = Array.new(v, 0)
    @iter = Array.new(v, 0)
  end
  attr_accessor :g

  def add_edge(from, to, cap)
    @g[from] << {"to" => to, "cap" => cap, "rev" => @g[to].size}
    @g[to] << {"to" => from, "cap" => 0, "rev" => @g[from].size-1}
  end

  def bfs(s) # sからの最短距離をbfs
    @level = Array.new(@V, -1)
    @level[s] = 0
    q = [s]
    while !q.empty?
      v = q.shift
      @g[v].size.times do |i|
        e = @g[v][i]
        if e["cap"] > 0 && @level[e["to"]] < 0
          @level[e["to"]] = @level[v] + 1
          q << e["to"]
        end
      end
    end
  end

  def dfs(v, t, f)
    return f if v == t
    (@iter[v]...@g[v].size).each do |i|
      @iter[v] = i
      e = @g[v][i]
      if e["cap"] > 0 && @level[v] < @level[e["to"]]
        d = dfs(e["to"], t, [f, e["cap"]].min)
        if d > 0
          e["cap"] -= d
          @g[e["to"]][e["rev"]]["cap"] += d
          return d
        end
      end
    end
    return 0
  end

  def max_flow(s, t)
    flow = 0
    while true
      bfs(s)
      return flow if @level[t] < 0
      @iter = Array.new(@V, 0)
      f = dfs(s, t, @inf)
      while f > 0
        flow += f
        f = dfs(s, t, @inf)
      end
    end
  end
end


N = gets.to_i
g = Dinic.new(2*N+2)
s = 2*N
t = s + 1

red = {}
blue = {}

N.times do |i|
  g.add_edge(s, i, 1)
  red[i] = gets.split.map(&:to_i)
end
N.times do |i|
  g.add_edge(N+i, t, 1)
  blue[N+i] = gets.split.map(&:to_i)
end
N.times do |i|
  N.times do |j|
    if red[i][0] < blue[N+j][0] && red[i][1] < blue[N+j][1]
      g.add_edge(i, N+j, 1)
    end
  end
end

puts g.max_flow(s, t)

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

ll lcm(ll a, ll b)
{
    return a*b / gcd(a, b);
}

ll f(ll x)
{
    ll res = 0;
    while (x%2 == 0)
        x /= 2, res++;

    return res;
}

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

    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];

    rep(i,0,n) 
    {
        if (a[i]%2==1)
        {
            cout << 0 << endl;
            return 0;
        } 
        a[i] /= 2;
    }

    ll t = f(a[0]);
    rep(i,0,n)
    {
        if (f(a[i]) != t)
        {
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }

    m >>= t;

    ll l = 1;
    rep(i,0,n)
    {
        l = lcm(l, a[i]);
        if (l > m)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    m /= l;
    ll ans ((m+1)/2);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
N, X, D = map(int, input().split())
if D == 0:
    r = N+1
    if X == 0:
        r = 1
    print(r)
else:
    if D < 0:
        X, D = -X, -D
    d = dict()
    for k in range(N+1):
        M = (k*X) % D
        F = (k*X)//D + ((k-1)*k)//2 #(1..k-1)
        L = (k*X)//D + (2*N-k-1)*k//2# (N-k..N-1)
        if M not in d:
            d[M] = list()
        d[M].append((F, 0))
        d[M].append((L, 1))
    r = 0
    for m in d:
        d[m] = sorted(d[m])
        fc = 0
        f = 0
        for x in d[m]:
            if not x[1]:
                fc += 1
                if fc == 1:
                    f = x[0]
            if x[1]:
                fc -= 1
                if fc == 0:
                    r += x[0] - f + 1
    print(r)


Measured memory_bytes: 107224
function main(input) {
  input=input.trim();
  const a = parseInt(input.split("\n")[0], 10);
  const s = input.split("\n")[1];
  if(a>=3200){
    console.log(s);
  }else{
    console.log("red");
  }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int bunkai(int);
int n, m;

main(){

  while(1){
    cin >> n >> m;
    if(n==0 && m==0) break;
    int a=bunkai(n);
    int b=bunkai(m);
    if(a>=b) cout << 'a' << endl;
    else cout << 'b' << endl;
  }
  return 0;
}

int bunkai(int n){
  int num[100000];
  int k=0;

  if(n%2==0){
    while(1){
      if(n%2!=0) break;
      n/=2;
    }
    num[k]=2;
    k++;
  }
 
  for(int i=3;;i+=2){
    if(n==1) break;
    if(n%i==0){
      while(1){
	if(n%i!=0) break;
	n/=i;
      }
      num[k]=i;
      k++;
    }
  }
  sort(num, num+k);

  int sum=0;
  int max=num[k-1];

  for(int i=0;i<k-1;i++){
    sum+=num[i];
  }

  return max-sum;
}

Measured memory_bytes: 856
def main():
    A, B, C = map(int, input().split())

    def d(A, B, C):
        """
        どれか偶数なら半分にできる
            if A%2==0 or B%2==0 or C%2==0:
        どれも奇数なら e.g. A = 3 + (2 + 1) のとき
        厚さ1の面ができるのでそれが差分
        """
        return (A - A // 2 * 2) * B * C

    ans = min([
        d(A, B, C),
        d(B, A, C),
        d(C, A, B)
    ])
    print(ans)


if __name__ == '__main__':
    main()


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

int n;
int a;
int b;
int c;
int d;

typedef long long ll;

ll nCr[1001][1001];

ll fact[1001];

ll inv_f[1001];

ll MOD = 1e9 + 7;


ll dp[1010][1010];

ll inv_mod( ll a, ll m = MOD )
{
  ll b, x, u, q, abs_m, tmp; 

  abs_m = ( m < 0 ) ? -m : m;
  b = m; x = 1; u = 0; 
  while ( b > 0 ) {
    q = a / b; 
    tmp = u; u = x - q * u; x = tmp;
    tmp = b; b = a - q * b; a = tmp;
  }

  return ( x < 0 ) ? abs_m + x : x;
}



int main()
{
	fact[0] = 1;
	inv_f[0] = 1;

	for(int i = 1;i <= 1000;i++)
	{
		fact[i] = (fact[i - 1] * i) % MOD;

		inv_f[i] = inv_mod(fact[i]) % MOD;
	}


	for(int i = 0;i <= 1000;i++)
	{
		for(int j = 0;j <= 1000;j++)
		{
			if(j == 0 || j >= i)
			{
				nCr[i][j] = 1;
			}
			else
			{
				nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % MOD;
			}
		}
	}

	cin >> n >> a >> b >> c >> d;

	dp[0][a - 1] = 1;

	for(int i = 0;i <= n;i++)
	{
		for(int j = a;j <= b;j++)
		{
			dp[i][j] = 0;
			ll comb = 1;
			for(int k = 0;k <= i / j;k++)
			{
				if(k > 0)
					comb = (comb * nCr[n - (i - j * (k))][j]) % MOD;
				//cout << "comb " << j << "*" << k << "=" << comb << endl;
				if(k == 0 || (c <= k && k <= d))
				{
					dp[i][j] = (dp[i][j] + dp[i - j * k][j - 1] * comb % MOD * inv_f[k]) % MOD;
				}
			}

			//cout << i << " " << j << "=" << dp[i][j] << endl;
		}
	}

	cout << dp[n][b] % MOD << endl;
	return 0;
}
		

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

int main(){
  int E, Y , Y2;
  cin >> E >> Y;
  if(E == 0){
    if(1868 <= Y && Y <= 1911){ Y2 = Y - 1867;
      cout << "M" << Y2 << endl;}
    if(1912 <= Y && Y <= 1925){ Y2 = Y - 1911;
      cout << "T" << Y2 << endl;}
    if(1926 <= Y && Y <= 1988){ Y2 = Y - 1925; 
      cout << "S" << Y2 << endl;}
    if(1989 <= Y && Y <= 2016){ Y2 = Y - 1988;
      cout << "H" << Y2 << endl;}
  }

  if(E == 1){Y2 = 1867 + Y;
    cout << Y2 << endl;}

  if(E == 2){Y2 = 1911 + Y;
    cout << Y2 << endl;}

  if(E == 3){Y2 = 1925 + Y;
    cout << Y2 << endl;}

  if(E == 4){Y2 = 1988 + Y;
    cout << Y2 << endl;}

}

   
  




 


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){

    int s,w;
    cin >> s >> w;
    if(s > w){
        cout << "safe" << endl;
    }else{
        cout << "unsafe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


int main(int argc, char** argv) {
    int n;
    cin >> n;
    std::vector<int> c(n), v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    int ans{0};
    for (int i = 0; i < n; ++i) {
        if (v[i] > c[i]) ans += v[i]-c[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

signed main(){
  int n,m;
  cin>>n>>m;
  vector<P>v;
  r(i,n){
    int a,b;
    cin>>a>>b;
    v.push_back(P(a,b));
  }
  sort(v.begin(),v.end());
  int s=0;
  r(i,n){
    int a=v[i].F;
    int b=v[i].S;
    if(m<b){
      s+=a*m;
      m=0;
    }
    else{
      s+=a*b;
      m-=b;
    }
  }
  cout<<s<<endl;
}

Measured memory_bytes: 2420
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int[] b=new int[n];
		int[] c=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt()-1;
		}
		int sum=0;
		for(int i=0; i<n; i++){
			b[i]=sc.nextInt();
			sum+=b[i];
		}
		for(int i=0; i<n-1; i++){
			c[i]=sc.nextInt();
		}
		for(int i=0; i<n-1; i++){
			if(a[i]+1==a[i+1]){
				sum+=c[a[i]];
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main(){
	char s[1005];
	scanf("%s",&s);
	int v1=0,v2=0,v3=0,v4=0;
	for (int i=0;s[i];i++){
		if (s[i]=='N')v1=1;
		if (s[i]=='S')v2=1;
		if (s[i]=='W')v3=1;
		if (s[i]=='E')v4=1;
	}
	if ((v1^v2)||(v3^v4))puts("No");
	else puts("Yes");
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long N,ans;
main()
{
	cin>>N;
	if(N%2)
	{
		cout<<0<<endl;
		return 0;
	}
	N/=2;
	while(N>0)
	{
		ans+=N/=5;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
D=int(input())
ListC = list(map(int, input().split()))
dictC={}
for i in range (1,27):
   dictC[i] = int(0) 
ListS = []
for i in range (D):
   ListS.append(list(map(int, input().split())))
ListT = []
for i in range (D):
   ListT.append(int(input()))
res = 0
for j in range(D):
  res += ListS[j][ListT[j]-1]
  for i in range(1,27):
    if ListT[j] == i:
      pass
    else:
      res += -1*(j+1-dictC[i])*ListC[i-1]
  dictC[ListT[j]] = j+1
  print(res)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main(){
    int a; string s;
    cin>>a>>s;
    cout<<(a>=3200?s:"red")<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <cmath>

using namespace std;
#define ll long long


int main()
{
    // Value
    string c = "";
    string result;

    // Input
    cin >> c;
    //cin>>N>>x;
    //ll size = 2*N-1;

    // Cal
    if(c=="a" || c=="i" || c=="u" || c=="e" || c=="o"){
        result = "vowel";
    }else{
        result = "consonant";
    }

    // Output
    cout << result << endl;

    // Fin
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b){
	return *(int *)a-*(int *)b;
}
int main(){
	int N;
	int M;
	int D[200000];
	int T[200000];
	scanf("%d",&N);
	int i;
	for(i=0;i<N;i++){
		scanf("%d",&D[i]);
	}
	qsort(D,N,sizeof(int),comp);
	scanf("%d",&M);
	for(i=0;i<M;i++){
		scanf("%d",&T[i]);
	}
	qsort(T,M,sizeof(int),comp);
	if(M>N){
		printf("NO");
		return 0;
	}
	int j;
	j=0;
	for(i=0;i<M;i++){
		for(;j<N;j++){
			if(T[i]==D[j]){
				j=j+1;
				break;
			}
			if(T[i]<D[j]||N-j<M-i){
				printf("NO");
				return 0;
			}
		}
	}
	printf("YES");
}

Measured memory_bytes: 2540
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, K, x):
    l = [abs(xi) for xi in x if xi < 0] + [0]
    l.reverse()
    r = [0] + [xi for xi in x if xi >= 0]
    ans = 10 ** 18 * 2 + 1
    for i in range(max(K - (len(l) - 1), 0), min(K + 1, len(r))):
        ll = l[K - i]
        rr = r[i]
        ans = min(ans, min(ll, rr) * 2 + max(ll, rr))
    print(ans)


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    N, K = map(int, input().split())
    x = [int(i) for i in input().split()]
    # B = [int(i) for i in input().split()]
    # AB = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, K, x)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


Measured memory_bytes: 19956
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++){
        cin >> P[i];
    }
    int P_MIN,Count;
    P_MIN = P[0];
    Count = 0;
    for(int i = 0; i < N; i++){
        if(P[i] <= P_MIN){
            P_MIN = P[i];
            Count++;
        }
        else{
            //Count++;
        }
        //cout << P_MIN << endl;
    }
    cout << Count << endl;
}


Measured memory_bytes: 1024
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let s = Array(readLine()!)
    let t = Array(readLine()!)

    let sn = s.count
    let tn = t.count

    var dp = (0...sn).map { i in (0...tn).map { j in 0 }}

    for i in 0..<sn {
        for j in 0..<tn {
            if s[i] == t[j] {
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
            }
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])
        }
    }

    var ans = ""
    var (i, j) = (sn, tn)
    while i > 0 && j > 0 {
        if dp[i][j] == dp[i-1][j] {
            i -= 1
        } else if dp[i][j] == dp[i][j-1] {
            j -= 1
        } else {
            ans.append(s[i-1])
            i -= 1
            j -= 1
        }
    }

    print(String(ans.reversed()))

}


main()

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

struct node
{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};
typedef struct node *Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x)
{
    while (x->left != NIL)
    {
        x = x->left;
    }
    return x;
}

Node treeMaximum(Node x)
{
    while (x->right != NIL)
    {
        x = x->right;
    }
    return x;
}

Node treeSearch(Node u, int k)
{
    if (u == NIL || k == u->key)
        return u;
    if (k < u->key)
        return treeSearch(u->left, k);
    else
        return treeSearch(u->right, k);
}

Node treeSuccessor(Node x)
{
    Node y;
    if (x->right != NIL)
        return treeMinimum(x->right); //case 1

    y = x->parent;
    while ((y != NIL) && x == y->right)
    {
        x = y;
        y = y->parent;
        return y; //case 2
    }
}

void treeDelete(Node z)
{
    Node y; // node to be deleted
    Node x; // child of y

    if ((z->left == NIL) || z->right == NIL)
        y = z;
    else
        y = treeSuccessor(z);

    if (y->left != NIL)
        x = y->left;
    else
        x = y->right;

    if (x != NIL)
        x->parent = y->parent;
    if (y->parent == NIL)
        root = x;
    else if (y == y->parent->left)
        y->parent->left = x;
    else
        y->parent->right = x;

    if (y != z)
        z->key = y->key;
}

void insert(int k)
{
    Node y = NIL;
    Node x = root;
    Node z;

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL)
    {
        y = x;
        if (z->key < x->key)
            x = x->left;
        else
            x = x->right;
    }

    z->parent = y;

    if (y == NIL)
        root = z;
    else if (z->key < y->key)
        y->left = z;
    else
        y->right = z;
}

void inorder(Node u)
{
    if (u != NIL)
    {
        inorder(u->left);
        printf(" %d", u->key);
        inorder(u->right);
    }
}
void preorder(Node u)
{
    if (u != NIL)
    {
        printf(" %d", u->key);
        preorder(u->left);
        preorder(u->right);
    }
}

int main()
{
    int n, i, x;
    char com[20];
    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%s", com);
        if (com[0] == 'f')
        {
            scanf("%d", &x);
            Node t = treeSearch(root, x);
            if (t != NIL)
                printf("yes\n");
            else
                printf("no\n");
        }
        else if (com[0] == 'i')
        {
            scanf("%d", &x);
            insert(x);
        }
        else if (com[0] == 'p')
        {

            inorder(root);
            // if(i != n-1)printf(" ");//空白処理
            printf("\n");

            preorder(root);
            // if(i != n-1) printf(" ");//空白処理
            printf("\n");
        }
        else if (com[0] == 'd')
        {
            scanf("%d", &x);
            treeDelete(treeSearch(root, x));
        }
    }

    return 0;
}



Measured memory_bytes: 20476
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
using namespace std;

int main() {
    int W;
    cin >> W;
    vector<int> v(W);
    for(int i=0; i<W; ++i) {
        cin >> v[i];
    }
    int l_out = -1, r_out = -1;
    int l_wall = -1, r_wall = -1;
    vector<int> ans(W);
    for(int i=0; i<W; ++i) {
        if(v[i] < 0) {
            if(l_wall == -1 || i-l_wall-v[i] < -v[l_wall]) {
                l_wall = i;
            }
        } else if(v[i] == 0) {
            l_out = i;
            l_wall = -1;
        } else {
            if(l_out != -1) {
                if(l_wall == -1) {
                    ans[i] = v[i];
                } else if(i-l_wall+v[l_wall] < 0) {
                    ans[i] = max(ans[i], min(-v[l_wall]-i+l_wall, v[i]));
                }
            }
        }
        int r = v.size() - 1 - i;
        if(v[r] < 0) {
            if(r_wall == -1 || r_wall-r-v[r] < -v[r_wall]) {
                r_wall = r;
            }
        } else if(v[r] == 0) {
            r_out = r;
            r_wall = -1;
        } else {
            if(r_out != -1) {
                if(r_wall == -1) {
                    ans[r] = v[r];
                } else if(r_wall-r+v[r_wall] < 0) {
                    ans[r] = max(ans[r], min(-v[r_wall]+r-r_wall, v[r]));
                }
            }
        }
    }
    cout << accumulate(ans.begin(), ans.end(), 0) << endl;
}


Measured memory_bytes: 3648
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, Dist[int(2e5 + 5)], ans[int(2e5 + 5)];
bool Used[int(2e5 + 5)];
int odd = 0, even = 0;
vector <int> Graph[int(2e5 + 5)];

int Calc_Dist(){
  Dist[1] = 0;
  queue <int> que; que.push(1);
  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < Graph[Q].size(); i++){
      int next = Graph[Q][i];
      if (Dist[next] != -1) continue;
      Dist[next] = Dist[Q] + 1;
      que.push(next);
    }
  }
  for (int i = 1; i <= N; i++){
    if (Dist[i] % 2 != 0) odd++;
    else even++;
  }
  return 0;
}

int Display(){
  printf("%d", ans[1]);
  for (int i = 2; i <= N; i++) printf(" %d", ans[i]);
  printf("\n");
  return 0;
}

int main(){
  scanf("%d", &N);
  fill(Dist, Dist + N + 1, -1);
  for (int i = 0; i < N - 1; i++){
    int A, B; scanf("%d%d", &A, &B);
    Graph[A].push_back(B);
    Graph[B].push_back(A);
  }
  Calc_Dist();

  if (odd <= N / 3){
    int now = 3;
    for (int i = 1; i <= N; i++){
      if (Dist[i] % 2 != 0){
        ans[i] = now; Used[now] = true;
        now += 3;
      }
    }
    now = 1;
    for (int i = 1; i <= N; i++){
      if (ans[i] == 0){
        ans[i] = now; Used[now] = true;
        while (Used[now]) now++;
      }
    }
    Display(); return 0;
  }
  if (even <= N / 3){
    int now = 3;
    for (int i = 1; i <= N; i++){
      if (Dist[i] % 2 == 0){
        ans[i] = now; Used[now] = true;
        now += 3;
      }
    }
    now = 1;
    for (int i = 1; i <= N; i++){
      if (ans[i] == 0){
        ans[i] = now; Used[now] = true;
        while (Used[now]) now++;
      }
    }
    Display(); return 0;
  }

  int now1 = 1, now2 = 2, now3 = 3;
  for (int i = 1; i <= N; i++){
    if (Dist[i] % 2 != 0 && now1 <= N){
      ans[i] = now1; now1 += 3;
    }else if (Dist[i] % 2 == 0 && now2 <= N){
      ans[i] = now2; now2 += 3;
    }else{
      ans[i] = now3; now3 += 3;
    }
  }
  Display();

  return 0;
}


Measured memory_bytes: 15476
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, a, b, as, bs;

	while (cin >> n, n){
		as = 0;
		bs = 0;
		for (int i = 0; i < n; i++){
			cin >> a >> b;
			if (a == b){
				as += a;
				bs += b;
			}
			else if (a == max(a, b)) as += a + b;
			else if (b == max(a, b)) bs += a + b;
		}
		cout << as << " " << bs << endl;
	}
	return (0);
}

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
 
 
int main(){
    string n;
	cin >> n;
	if (n.find("7") != std::string::npos) {
          cout << "Yes" << endl;  
	}else{
 
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  string S;
  cin >> S;
  string ans = "Yes";
  vector<int> mozi(3);
  for(int i = 0;i<3;i++){
    if(S.at(i) == 'a'){
      mozi.at(0)++;
    }
    else if(S.at(i) == 'b'){
      mozi.at(1)++;
    }
    else{
      mozi.at(2)++;
    }
  }

  for(int j = 0;j<3;j++){
    if(mozi.at(j) != 1){
      ans = "No";
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256