akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=100010;

vector<ll> adj[N];
ll ans[N];
ll vis[N];

void dfs(ll v)
{
    vis[v]=1;
    for(auto u:adj[v])
    {
        if(vis[u]==0){dfs(u);}
        ans[v]=max(ans[v],1+ans[u]);
    }
}

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

    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;++i)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].pb(b);
    }

    for(ll i=0;i<=n;++i){
        vis[i]=0;
        ans[i]=0;
    }

    for(ll i=1;i<=n;++i)
    {
        if(vis[i]==0)
        {
            dfs(i);
        }
    }

    ll ch=0;
    for(ll i=1;i<=n;++i){
        ch=max(ch,ans[i]);
    }
    cout<<ch<<endl;

    return (0);
}


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

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

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

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

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

using pint = pair<int, int>;
int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<set<int>> dame(N);
    UnionFind uf(N);
    for (int i = 0; i < M; i++)
    {
        int a, b; cin >> a >> b; --a, --b;
        dame[a].insert(b);
        dame[b].insert(a);
        uf.merge(a, b);
    }
    for (int i = 0; i < K; i++)
    {
        int c, d; cin >> c >> d; --c, --d;
        if(!uf.issame(c, d)) continue;
        dame[c].insert(d);
        dame[d].insert(c);
    }
    for (int i = 0; i < N; i++)
    {
        int mem = uf.size(i) - 1;
        mem -= dame[i].size();
        cout << mem << " ";
    }
    cout << endl;
}

Measured memory_bytes: 24704
# AGC C Ants on a Circle
f=lambda:map(int,input().split())
N,L,T=f()
X,W=[],[]
for _ in [0]*N:
    x,w=f()
    X.append(x)
    W.append(w)
    
if W[0]==2:
    X[0]+=L
    
col=0
for j in range(N):
    if W[j]==W[0]:
        continue
    else:
        if W[0]==1:
            if 2*T-(X[j]-X[0])>=0:
                col+=(1+(2*T-(X[j]-X[0]))//L)
        else:
            if 2*T-(X[0]-X[j])>=0:
                col-=(1+(2*T-(X[0]-X[j]))//L)

col=col%N
X2=[(X[i]+(3-2*W[i])*T) % L for i in range(N)]
X2_0=X2[0]

X2.sort()

index=[i for i,x in enumerate(X2) if x==X2_0]

if len(index)==1:
    index=index[0]
else:
    if W[0]==1:
        index=index[1]
    else:
        index=index[0]

i=(index-col)%N

X2=X2[i:]+X2[:i]
print(*X2,sep='\n')

Measured memory_bytes: 97368
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		string S = GetString();
		int num = 0;
		for(int i = 0; i < S.Length; i++)
			if(S[i] == 'o')
				num++;

		Console.WriteLine((num + (15 - S.Length)>= 8) ? "YES" : "NO");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


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

int main(void){
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N), d(N);
    int count = 0;
    
    for(int i = 0; i < N; i++)
        cin >> a[i] >> b[i];
    for(int i = 0; i < N; i++)
        cin >> c[i] >> d[i];

    for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++){
            if(b[i]<b[j]){
                swap(a[i], a[j]); swap(b[i], b[j]);
            }
            if(c[i]>c[j]){
                swap(c[i], c[j]); swap(d[i], d[j]);
            }
        }
    }
    int check = 0;
    for(int i = 0; i < N; i++){
        check=0;
        for(int j = 0; j < N; j++){
            if(c[i]>a[j]&&d[i]>b[j]&&check==0){
                count++; check++;
                N--;
                c.erase(c.begin()+i); d.erase(d.begin()+i);
                a.erase(a.begin()+j); b.erase(b.begin()+j);
            }
        }
        if(check!=0)
            i=-1;
    }
        cout << count << endl;  
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int a[5], b[5];
  int num1, num2, hit = 0, blow = 0;


  while (scanf("%d %d %d %d %d %d %d %d",
    &a[1], &a[2], &a[3], &a[4], &b[1], &b[2], &b[3], &b[4]) != EOF) {

    for (num1 = 1; num1 <= 4; num1++) {
      if (a[num1] == b[num1]) {
        hit += 1;
      }
    }

    for (num1 = 1; num1 <= 4; num1++) {
      for (num2 = 1; num2 <= 4; num2++) {

        if (num1 == num2) {
          continue;
        } else {
          if (a[num1] == b[num2]) {
            blow += 1;
          }
        }

      }
    }

    printf("%d %d\n", hit, blow);
    hit = 0; blow = 0;
  }

  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int dp[3010];

int main() {
  int n;
  cin >> n;
  dp[0] = 1;
  for (int i = 1; i <= n; ++i) for (int j = i - 3; j >= 0; --j) {
    dp[i] += dp[j];
    dp[i] %= mod;
  }

  cout << dp[n] << endl;
}

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

vector<vector<int>> g(50, vector<int>());

void dfs(int v, int a, int b, vector<bool> &done) {
    if (done.at(v)) return;

    done.at(v) = true;

    for (int i = 0; i < (int)g.at(v).size(); i++)
    {
        if ((v == a && g.at(v).at(i) == b) || (v == b && g.at(v).at(i) == a)) {
            continue;
        }

        dfs(g.at(v).at(i), a, b, done);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a.at(i) >> b.at(i);
        a.at(i)--;
        b.at(i)--;

        g.at(a.at(i)).push_back(b.at(i));
        g.at(b.at(i)).push_back(a.at(i));
    }
    
    int ans = 0;
    for (int i = 0; i < m; i++)
    {
        vector<bool> done(n, false);
        dfs(0, a.at(i), b.at(i), done);
        
        bool isOk = true;
        for (int j = 0; j < n; j++)
        {
            if (!done.at(j)) {
                isOk = false;
            }
        }
        if (!isOk) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"

#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0);}

int main()
{
//    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;

    vector<int> mask(300, 0);
    for(char c : s)
        ++mask[c];

    int n = s.length();
    long long ans = n * 1LL * (n + 1) / 2 + 1;
    for(int x : mask)
        ans -= x * 1LL * (x + 1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 720
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {

	int a, b;
	char op[10];

	while (1) {
		cin >> a >> op >> b;

		if (op[0] == '?') break;

		switch (op[0])
		{
		case '+':
			cout << a + b << endl;
			break;
		case '-':
			cout << a - b << endl;
			break;
		case '*':
			cout << a * b << endl;
			break;
		case '/':
			cout << a / b << endl;
			break;
		default:
			break;
		}

	}

	return 0;
}


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

ans=0
for i in range(1,n+1):
    ans+=i*(n-i+1)

for _ in range(n-1):
    a,b=map(int,input().split())
    if a>b:
        a,b=b,a
    ans-=a*(n-b+1)

print(ans)

Measured memory_bytes: 9124
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC163C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = RInt;
            int[] ans = new int[N];

            var a = RInts;
            for (int i = 0; i < N - 1; i++)
            {
                ans[a[i] - 1]++;
            }

            foreach (var b in ans)
            {
                Console.WriteLine(b);
            }
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            T[,] map2 = new T[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = (T)(object)0;
                    else if (i == 0) map2[i, j] = (T)(object)(j - 1);
                    else if (j == 0) map2[i, j] = (T)(object)(i - 1);
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write((dynamic)map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 43680
#include <stdio.h>

// first type, to use switch-case. ?include "abc"
// second type, to use ascii number. ?(sum(a,b,c)==sum(str)) 
int main(void){
	char str[3];
	int c = 6;
	scanf("%s",&str);

	int sum = 'a'+'b'+'c';

	for(int i=0;i<sizeof(str);i++){
		switch(str[i]){
			case 'a':
				c -= 1;
				break;
			case 'b':
				c -= 2;
				break;
			case 'c':
				c -= 3;
		}
		sum -= str[i];
	}


	if(!sum)
		printf("%s\n","Yes");
	else
		printf("%s\n","No");

	return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){

    

}


void solve(){
    
    ll k;
    cin >> k;
    ll no=0;
    ll MAX = 1e7;
    ll ind=1;
    while(MAX--){
        no = no*10 + 7;
        no %= k;
        if(no==0)
            break;
        ind++;
    }    
    if(no != 0){
        ind = -1;
    }
    cout << ind;
    
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  int p[26];
  for(int i=0;i<26;i++) p[i]=50;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    for(int j='a';j<='z';j++){
      int tmp=0;
      for(int k=0;k<s.size();k++){
        if(s[k]==j) tmp++;
      }
      if(p[j-'a']>tmp) p[j-'a']=tmp;
    }
  }

  for(int i=0;i<=25;i++){
    char a='a'+i;
    for(int j=0;j<p[i];j++){
      cout<<a;
    }
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

const int MAXN = 50, MAXM = 100, MOD = 1e9 + 7;
int n, m, a[MAXM + 5], f[2][MAXM + 5][MAXM + 5];

inline void addeq ( int& a, const int b ) { if ( ( a += b ) >= MOD ) a -= MOD; }

int main () {
	scanf ( "%d", &n ), m = 2 * n;
	for ( int i = 1; i < m; ++ i ) scanf ( "%d", &a[i] );
	std::sort ( a + 1, a + m );
	f[0][0][0] = 1;
	for ( int i = n, t = 0; i > 1; -- i, t ^= 1 ) {
		bool dl = a[i] ^ a[i - 1], dr = a[m - i + 1] ^ a[m - i];
		for ( int j = 0; j < m; ++ j ) {
			for ( int k = 0; k < m; ++ k ) {
				int& cur = f[t][j][k];
				if ( ! cur ) continue;
				addeq ( f[t ^ 1][j + dl][k + dr], cur );
				for ( int p = 0; p < j + dl; ++ p ) addeq ( f[t ^ 1][p][k + dr + 1], cur );
				for ( int p = 0; p < k + dr; ++ p ) addeq ( f[t ^ 1][j + dl + 1][p], cur );
				cur = 0;
			}
		}
	}
	int ans = 0;
	for ( int i = 0; i < m; ++ i ) {
		for ( int j = 0; j < m; ++ j ) {
			addeq ( ans, f[n & 1 ^ 1][i][j] );
		}
	}
	printf ( "%d\n", ans );
	return 0;
}

Measured memory_bytes: 3312
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int[] num = new int[] {a,b,c};
        for(int n = 0;n < num.length-1;n++){
            int min = n;
            for(int i = n+1;i < num.length;i++){//最小値を決める
                if(num[min] > num[i]){
                    min = i;
                }
            }
            if(num[min] != num[n]){
                int work =num[n];
                num[n] = num[min];
                num[min] = work;
            }
        }
        System.out.println(num[0]+" "+num[1]+" "+num[2]);
    }
}


Measured memory_bytes: 26340
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int K = sc.nextInt();
        int S = sc.nextInt();
        
        int count = 0;
        for (int x = 0; x <= K; x++) {
            for (int y = 0; y <= K; y++) {
                int z = S - (x+y);
                if (0 <= z && z <= K) {
                    count++;
                }
            }
        }
        so.println(count);
    }
}


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

#define rep(i,j,k) for(int i=j;i<k;i++)
int main(void){
    while(1){
    int ans=0,n;
    cin>>n;
    if(n==0)break;
    vector<int> v(n);
    rep(i,0,n)v[i]=i+1;
    
    int right=0,left=0;
    int sum=v[0];
    while(1){
        if(sum<n){
            right++;
            if(right>n-2)break;
            sum+=v[right];
            
        }else if(sum>n){
            sum-=v[left];
            left++;
            if(left>n-2)break;
        }else if(sum==n){
            if(right-left>0)ans++;
            right++;
            if(right>n-2)break;
            sum+=v[right];
            
            
        }
        
    }
    
    cout<<ans<<endl;
    }
}

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
const double PI=3.14159265358979323846;

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







int main() {


  cout<<fixed<<setprecision(10);

  ll n,m; cin>>n>>m;

  vvint edges(n, vint());
    // puts("HO");

  vint cnt(n, 0);
  rep(i,m){
    ll x, y; cin>>x>>y;
    x--; y--;
    // cout<<x<<y<<endl;
    edges[x].push_back(y);
    cnt[y]++;
  }
  queue<ll> q;
  rep(i,n){
    if(cnt[i] == 0) q.push(i);
  }

  vint dp(n, 0);

  while(!q.empty()){
    ll cur = q.front(); q.pop();

    for(auto nxt:edges[cur]){
      cnt[nxt]--;
      if(cnt[nxt] == 0) q.push(nxt);
      chmax(dp[nxt], dp[cur]+1);
    }
  }

  cout<<*max_element(ALL(dp))<<endl;

}

//


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

int main()
{
   string s;
   cin >> s;
   if (s == "SSS")
      cout << "0" << endl;
   if (s == "SSR")
      cout << "1" << endl;
   if (s == "SRS")
      cout << "1" << endl;
   if (s == "SRR")
      cout << "2" << endl;
   if (s == "RSS")
      cout << "1" << endl;
   if (s == "RSR")
      cout << "1" << endl;
   if (s == "RRS")
      cout << "2" << endl;
   if (s == "RRR")
      cout << "3" << endl;
}

Measured memory_bytes: 3548
from collections import deque
import sys

N,M = map(int,input().split())

s = input()

dic = {}
linkA = [0] * N
linkB = [0] * N
able = [True] * N

for i in range(M):

    a,b = map(int,input().split())
    a -= 1
    b -= 1

    if a not in dic:
        dic[a] = []
    if b not in dic:
        dic[b] = []

    dic[a].append(b)
    dic[b].append(a)

    if s[a] == "A":
        linkA[b] += 1
    else:
        linkB[b] += 1

    if s[b] == "A":
        linkA[a] += 1
    else:
        linkB[a] += 1

#print (linkA,linkB)
q = deque([])

for i in range(N):

    if linkA[i] == 0 or linkB[i] == 0:
        able[i] = False
        q.append(i)

while len(q) > 0:

    now = q.popleft()
    #print (q)

    if now in dic:
        for i in dic[now]:

            if s[now] == "A":
                linkA[i] -= 1
            else:
                linkB[i] -= 1


            if (linkA[i] <= 0 or linkB[i] <= 0) and able[i]:
                able[i] = False
                q.append(i)

for i in able:
    if i:
        print ("Yes")
        sys.exit()

print ("No")

Measured memory_bytes: 93652
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, M;
    cin >> N >> M;

    if (M == 1) {
        write("1 2");
        return 0;
    }
    else if (N % 2 == 1) {
        write("1 2");
        rep(i, M - 1) {
            int a = 2 + M;
            cout << (a - i - 1) << " " << (a + i + 1) << "\n";
        }
    }
    else {
        rep(i, 1, M + 1) {
            if (i % 2 == 1) {
                int a = (M + 1) / 2 - i / 2;
                int b = a + i;
                cout << a << " " << b << "\n";
            }
            else {
                int a = N / 2 + M / 2 - i / 2 + 1;
                int b = a + i;
                cout << a << " " << b << "\n";
            }
        }
    }
}

Measured memory_bytes: 3648
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	f := 1
	for i := 1; i <= n; i++ {
		f *= i
	}
	fmt.Println(f)
}



Measured memory_bytes: 1064
n = int(input())
s = int(input())

if n == s:
  print(n+1)
  exit(0)

m = int((n-1)**.5) + 2
for i in range(2, m):
  t = 0
  f = n
  while f:
    t += f % i
    f //= i
  if t == s:
    print(i)
    exit(0)

a = 10**12
for i in range(1, min(m, s+1)):
  j = s - i
  if (n - j) % i == 0:
    b = (n - j) // i
    if j < b and i < b:
      a = min(a, b)
print(a if a < 10**12 else -1)

Measured memory_bytes: 3064
// https://atcoder.jp/contests/agc006/tasks/agc006_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, X;

  cin >> N >> X;

  if (X == 1 || X == 2 * N - 1) drop("No");

  cout << "Yes" << endl;

  ll len = 2 * N - 1;
  VL res(len);

  if (N == 2) {
    print_ints({1, 2, 3});
    return;
  }

  set<ll> used;

  used.insert(X);
  used.insert(2 * N - 1);
  used.insert(1);

  if (X == 2 * N - 2) {
    res[len / 2] = X;
    res[len / 2 - 1] = 2 * N - 1;
    res[len / 2 - 2] = 1;
    res[len / 2 + 1] = 2;
    used.insert(2);
  } else {
    res[len / 2] = X;
    res[len / 2 - 1] = 1;
    res[len / 2 - 2] = 2 * N - 1;
    res[len / 2 + 1] = 2 * N - 2;
    used.insert(2 * N - 2);
  }

  ll next_i = 0;

  rep1(num, len) {
    if (used.count(num)) continue;
    while (next_i >= len / 2 - 2 && next_i <= len / 2 + 1) next_i++;

    res[next_i] = num;
    next_i++;
  }

  rep(i, len) cout << res[i] << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 3072
import java.io.*;
import java.util.*;
import java.util.Map.Entry;

public class Main {
	
	final boolean isDebug = false;
	String fileName = "input.txt";
	FastScanner sc;
	PrintWriter out;
	final int MOD = (int)1e9+7;
	final int INF = Integer.MAX_VALUE / 2;
	
	void solve() throws Exception{
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
		if(a == b && b == c) System.out.println("Yes");
		else System.out.println("No");
		
	}
	
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		long S = System.currentTimeMillis();
		sc = (isDebug) ? new FastScanner(new FileInputStream(fileName)) : new FastScanner(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
		long G = System.currentTimeMillis();
		if(isDebug){
			System.out.println("---Debug---");
			System.out.printf("%8d ms", (G-S));
		}
	}
	/* end main */
}
/* end Main */

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

Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n;
    int p,pm=0;
    int sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p;
        pm=max(pm,p);
        sum+=p;
    }
    sum-=pm/2;
    cout<<sum<<"\n";

    return 0;
}


Measured memory_bytes: 256
object Main{
    def main(args: Array[String]): Unit ={
        var in = scala.io.StdIn.readDouble()
        var a = in * in * scala.math.Pi
        var c = (in + in) * scala.math.Pi
        println(f"$a%.7f"  + " " + f"$c%.7f")
    }
}

Measured memory_bytes: 43808
import std.stdio;
import std.conv;
import std.string;

void main()
{
  string s;
  while ((s=readln()).length != 0) {
    int cnt = 0;
    int n = to!(int)(chomp(s));

    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          for (int l = 0; l < 10; l++) {
            if (i + j + k + l == n) cnt++;
          }
        }
      }
    }
    writeln(cnt);
  }
}

Measured memory_bytes: 1052
N = list(input())
K = int(input())

d = len(N)

def f(j,k):#j桁で0でない桁がk桁ある自然数の個数(最高位0を許す)
    if j < k:
        return 0
    elif k == 0:
        return 1
    elif k == 1:
        return 9*j
    elif k == 2:
        return 81*j*(j-1)//2
    elif k == 3:
        return 729*j*(j-1)*(j-2)//6

b = 0
ans = 0

for i in range(d):
    if b == K:
        break
    else:
        if int(N[i]) != 0:
            ans += f(d-(i+1),K-b) + (int(N[i])-1)*f(d-(i+1),K-b-1)
            b += 1
        else:
            continue

if b == K:
    print(ans+1)
else:
    print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
int main() {
  int n,T;
  cin >> n >> T;
  vector<int> t(n);
  rep(i,n) cin >> t.at(i);
  ll ans = 0;
  rep(i,n-1){
    if(t.at(i+1)-t.at(i) <= T) ans += t.at(i+1)-t.at(i);
    else ans += T;
  }
  ans+=T;
  cout << ans << endl;
} 

Measured memory_bytes: 3988
s=input()
c=0
l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
if s[0]=='A':c+=1
if s[2:-1].count('C')==1:c+=1
x=0
for i in range(len(s)):
    x+=l.count(s[i])
if x==len(s)-2:c+=1
if c==3:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const int infty = 1e9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, r;
  cin >> n >> m >> r;
  vector<vector<pair<int, int> > > grh(n);
  for (int i = 0; i < m; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    grh[s].push_back({d, t});
  }
  vector<int> dst(n);
  for (int i = 0; i < n; i++) {
    dst[i] = infty;
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > prque;
  prque.push({0, r});
  dst[r] = 0;
  while (!prque.empty()) {
    pair<int, int> crr = prque.top();
    prque.pop();
    int crrd = crr.first;
    int crrv = crr.second;
    if (crrd > dst[crrv]) {
      continue;
    }
    for (int k = 0; k < grh[crrv].size(); k++) {
      pair<int, int> nxt = grh[crrv][k];
      int nxtd = crrd + nxt.first;
      int nxtv = nxt.second;
      if (nxtd > dst[nxtv]) {
        continue;
      }
      prque.push({nxtd, nxtv});
      dst[nxtv] = nxtd;
    }
  }
  for (int i = 0; i < n; i++) {
    if (dst[i] == infty) {
      cout << "INF" << '\n';
    } else {
      cout << dst[i] << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 13060
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or i == H - 1:
                print("#", end = "")
            elif j == 0 or j == W - 1:
                print("#", end="")
            else: print(".",end="")
        print()
    print()
    


Measured memory_bytes: 7004
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a>=13){
        cout << b << endl;
    }else if(a>=6){
        cout << b/2 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <unordered_set>

using namespace std;

typedef long long int li;
typedef vector<char> vc;


int main()
{
    int N;
    cin >> N;
    unordered_set<string>  s;

    for (int i = 0; i < N; ++i)
    {
        string str;
        cin >> str;
        s.insert(str);
    }
    cout << s.size();

    return 0;
}


Measured memory_bytes: 17680
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int main() {
	int r, g, b;
	cin >> r >> g >> b;
	if ((r * 100 + g * 10 + b) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

typedef long long custom_type;

int main()
{

    custom_type a, b, c , d;
    cin >> a >> b >> c >> d;

    custom_type the_ans = max((max(a, b) * max(c, d)),(min(a, b) * min(c, d)));

    the_ans = max(the_ans, (max(a, b) * min(c, d)));
    the_ans = max(the_ans, (min(a, b) * max(c, d)));

    cout << the_ans << endl;


    return 0;
}


Measured memory_bytes: 3668
H, W = map(int, input().split())

# array size HxW filled with zeroes
black = [[0 for c in range(W)] for r in range(H)]
# array size HxW filled with 10^18 (basically infinity)
dp = [[int(1e18) for c in range(W)] for r in range(H)]

for r in range(H):
    line = input()
    for c in range(W):
        black[r][c] = (line[c] == '#')

dp[0][0] = black[0][0] # this case is handled separately

for r in range(H):
    for c in range(W):
        if r >= 1:
            # r-1 can be indexed
            dp[r][c] = min(dp[r][c], dp[r-1][c] + (black[r][c] and not black[r-1][c]))
        if c >= 1:
            # c-1 can be indexed
            dp[r][c] = min(dp[r][c], dp[r][c-1] + (black[r][c] and not black[r][c-1]))

print(dp[H-1][W-1])


Measured memory_bytes: 43120
#include <stdio.h>
#define N 1200

int main(void) {

    int i;
    int calp[26];
    char chbuf;

    for (i = 0; i < 26; i++) {
        calp[i] = 0;
    }

    while (scanf("%c", &chbuf) != EOF) {
        if ((chbuf >= 'A') && (chbuf <= 'Z')) {
            calp[chbuf - 'A']++;
        } else if ((chbuf >= 'a') && (chbuf <= 'z')) {
            calp[chbuf - 'a']++;
        }
    }

    for (i = 0; i < 26; i++) {
        printf("%c : %d\n", i + 97, calp[i]);
    }

    return 0;

}

Measured memory_bytes: 540
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	bool cond1 = true, cond2=true;
	for(int i=0;i<s.length();i++)
	{
		if(i==a)
		{
			if(s[i]!='-')
				cond1=false;
		}
		else
		{
			if(!(s[i]>='0' && s[i]<='9'))
				cond2=false;
		}
	}
	if( cond1 && cond2)
		cout<<"Yes"<<"\n";
	else
		cout<<"No"<<"\n";

}

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

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

signed main(){
    int n,s;
    while(cin>>n>>s,n||s){
        int ans=0;
        rep(i,1<<10){
            int cnt=0,sum=0;
            rep(j,10){
                if(i>>j&1){
                    cnt++;
                    sum+=j;
                }
            }
            if(cnt==n&&sum==s)ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

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

    int y = (s[0]-'0')*10+(s[1]-'0');
    int m = (s[2]-'0')*10+(s[3]-'0');

    if((m<1 || m>12) && (y<1 || y>12))
        cout<<"NA";
    else if((m>0 || m<13) && (y<1 || y>12))
        cout<<"YYMM";
    else if((y>0 || y<13) && (m<1 || m>12))
        cout<<"MMYY";
    else
        cout<<"AMBIGUOUS";

}


Measured memory_bytes: 384
from heapq import heappush
from heapq import heappop

class cake:
    def __init__(self, x, y, z):
        self.x, self.y, self.z = x, y, z
    def score(self, x, y, z):
        return self.x * x + self.y * y + self.z *z

def solution(cakeList, m):
    foo = 0
    for x in xrange(-1, 2, 2):
        for y in xrange(-1, 2, 2):
            for z in xrange(-1, 2, 2):
                cache = []
                for el in cakeList:
                    heappush(cache, el.score(x, y, z))
                    while len(cache) > m:
                        heappop(cache)
                foo = max(sum(cache), foo)
    return foo

def main():
    n, m = [int(i) for i in raw_input().strip().split()]
    cakeList = []
    for i in xrange(n):
        x, y, z = [int(i) for i in raw_input().strip().split()]
        cakeList.append(cake(x, y, z))
    print solution(cakeList, m)

if __name__ == '__main__':
    main()

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    int n;
    cin >> n;
    V<ll> a(n), b(n);
    ll as = 0, bs = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        as += a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        bs += b[i];
    }
    if (as < bs) {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    ll neg = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] < b[i]) {
            ans++;
            neg += b[i] - a[i];
        }
    }
    V<ll> s;
    for (int i = 0; i < n; ++i) {
        if (a[i] > b[i]) s.push_back(a[i] - b[i]);
    }
    sort(s.begin(), s.end());
    while (neg > 0) {
        ans++;
        neg -= s.back();
        s.pop_back();
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)

typedef long long ll;
int a[3010],b[3010];
int dp[3010][3010][2];
signed main(){
   int n,T;
   cin>>n>>T;
   vector<pair<int,int>>v(n);
   REP(i,n) {
       cin>>a[i]>>b[i];
   }
  for (int i = 0; i < n; i++)
  {
      for (int t = 0; t < T; t++)
      {
           dp[i+1][t][0] = max( dp[i+1][t][0], dp[i][t][0]);
           dp[i+1][t][1] = max( dp[i+1][t][1], dp[i][t][1]);
          if(t+a[i]<T){
          dp[i+1][t+a[i]][0] = max( dp[i+1][t+a[i]][0] , dp[i][t][0]+b[i]);
          dp[i+1][t+a[i]][1] = max( dp[i+1][t+a[i]][1] , dp[i][t][1]+b[i]);
          }
         
          dp[i+1][t][1] = max( dp[i+1][t][1] , dp[i][t][0]+b[i]); 
      }
      
  }
  cout<<dp[n][T-1][1]<<endl;
   


  
    return 0;
}

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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    vector<pair<int, int>> vp(n);
    for (int i = 0; i < n; i++)
        scanf("%d %d", &vp[i].second, &vp[i].first);
    sort(vp.rbegin(), vp.rend());
    int finish = 1e9;
    for(int i=0; i<vp.size(); i++){
        finish = min(finish, vp[i].first);
        finish -= vp[i].second;
    }
    if(finish<0){
        puts("No");
    }else{
        puts("Yes");
    }

    return 0;
}

Measured memory_bytes: 1792
N = int(input())
P = list(map(int,input().split()))

if N == 1:
    print(1)
else:
    min = P[0]
    count = 1
    for i in range(N-1):
        if P[i+1] <= min:
            count += 1
            min = P[i+1]
    print(count)

Measured memory_bytes: 24744
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int n,a[100010],b[100010],sum=0,ans[100010],max=0,max2=0,min2=INF,min=INF,t=0;
	cin>>n;
	a[0]=0,a[n+1]=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		sum+=abs(a[i]-a[i-1]);
	}
	sum+=abs(a[n]);
	for(int i=1;i<=n;i++){
		cout<<sum-(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]))+abs(a[i-1]-a[i+1])<<endl;
	}
	return 0;
}

Measured memory_bytes: 1664
# coding: utf-8
N = gets.to_i
ans = 0

ary = Array.new(10) {Array.new(10, 0)}
#ary = Array.new(10, Array.new(10, 0))

1.upto(N) do |i|
  is = i.to_s
  ary[is[0].to_i][is[-1].to_i] += 1
end

1.upto(N) do |i|
  is = i.to_s
  ans += ary[is[-1].to_i][is[0].to_i]
end

puts ans
  


Measured memory_bytes: 1788
open Batteries
(* listのmin *)
let min_list lst_ = 
  let rec search_min lst value = 
    match lst with
     [] -> value
    | first :: rest -> if first < value then search_min rest first else search_min rest value
  in search_min lst_ 0
let n = read_int ()
let p = read_line () |> String.split_on_char ' ' |> List.map int_of_string
let rec loop lst mined ans =
  match lst with
  | [] -> ans
  | first :: rest ->
    if first < mined then loop rest (min mined first) (1+ans) else loop rest (min mined first) (ans)

let _ = Printf.printf "%d\n" @@ loop p max_int 0


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

using namespace std;

#define rep(i , n) for(int i=0 ; i<n ; i++)
#define rep1(i , n) for(int i=1 ; i<=n ; i++)

typedef long long int ll;


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

	int n;
	
	cin >> n;
	double ans = 0;
	rep(i , n)
	{
		double temp;
		string str;
		cin >> temp >> str;
		if(str == "JPY")
		    ans += temp;
		else
		    ans += temp*(380000.0);
	}

    cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

int main() {

	ll a, b, c;
	cin >> a >> b >> c;

	if (b - a == c - b) { cout << "YES"; }
	else { cout << "NO"; }
	
	system("PAUSE");
}


Measured memory_bytes: 504
l, r = map(int, input().split())

if l%2019 >= r%2019:
    print(0)
elif r-l >= 2019:
    print(0)
elif l%2019 == 0 or r%2019 == 0:
    print(0)
else:
    h = []
    for i in range((r-l)%2019):
        for j in range(i+1, (r-l+1)%2019):
            h.append((((l+i)%2019)*((l+j)%2019))%2019)
    print(min(h))

Measured memory_bytes: 75428
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

int main()
{
    int sx, sy, tx, ty;
    std::cin >> sx >> sy >> tx >> ty;

    std::cout << std::string(ty - sy, 'U');
    std::cout << std::string(tx - sx, 'R');
    std::cout << std::string(ty - sy, 'D');
    std::cout << std::string(tx - sx, 'L');
    std::cout << "L";
    std::cout << std::string(ty - sy + 1, 'U');
    std::cout << std::string(tx - sx + 1, 'R');
    std::cout << "DR";
    std::cout << std::string(ty - sy + 1, 'D');
    std::cout << std::string(tx - sx + 1, 'L');
    std::cout << "U" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define NO -1
#define MAX 1000000
typedef struct Node{
  int p,l,r;
}S;
S tree[MAX];
int getdepth(int x){
  int d=0;
  while(tree[x].p!=NO){
    x=tree[x].p;
    d++;
  }
  return d;
}
void out(int y){
  int i,j;
  printf("node %d: ",y);
  printf("parent = %d, ",tree[y].p);
  printf("depth = %d, ",getdepth(y));
  if(tree[y].p==NO)printf("root, ");
  else if(tree[y].l==NO)printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  for(i=0,j=tree[y].l;j!=NO;i++,j=tree[j].r){
    if(i)printf(", ");
    printf("%d",j);
  }
  printf("]\n");
}
int main(){
  int n,i,j,a,b,m,z,l;
  scanf("%d",&n);
  for(i=0;i<n;i++)tree[i].p=tree[i].r=tree[i].l=NO;
  for(i=0;i<n;i++){
    scanf("%d%d",&a,&b);
    for(j=0;j<b;j++){
      scanf("%d",&m);
      if(j==0)tree[a].l=m;
      else tree[l].r=m;
      l=m;
      tree[m].p=a;
    }
  }
  for(i=0;i<n;i++)out(i);
  return 0;
}



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

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	set <int> s;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	cout << (int)s.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  vector<ll> l(n + 1);
  l[0] = 2, l[1] = 1;
  FOR(i, 2, n + 1) {
    l[i] = l[i - 1] + l[i - 2];
  }
  cout << l[n] << endl;



  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=1e9+7;

int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max(max(max(a*c,a*d),b*c),b*d)<<endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	int A[N] = {};
	double ans;
	double sum = 0.0;

	REP(idx, N) {
		cin >> A[idx];
		sum += 1.0 / A[idx];
	}
	ans = 1.0 / sum;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384