akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

const int MAXN = 5e5 + 10;
const int P = 1e9 + 7;

int n, m, prod[MAXN], inv[MAXN], ans;

void add(int& a, int b) { a = a + b > P ? a + b - P : (a + b < 0 ? a + b + P : a + b); }
int Combine(int n, int m) { return 1ll * prod[n] * inv[m] % P * inv[n - m] % P; } // \binom{n}{m}
int Permutation(int n, int m) { return 1ll * prod[n] * inv[n - m] % P; }

/*
int qpower(int a, int x) {
    int res = 1;
    for (; x; x >>= 1, a = 1ll * a * a % P) x & 1 ? res = 1ll * res * a % P : 0;
    return res;
}
*/

int main() {
    IO::read(n), IO::read(m);
    prod[0] = 1, inv[0] = 1, inv[1] = 1;
    rep(i, 1, m) prod[i] = 1ll * prod[i - 1] * i % P;
    rep(i, 2, m) inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
    rep(i, 2, m) inv[i] = 1ll * inv[i - 1] * inv[i] % P;
    rep(i, 0, n) {
        int cfc = i & 1 ? -1 : 1;
        add(ans, 1ll * cfc * Permutation(m, i) % P * Combine(n, i) % P * Permutation(m - i, n - i) % P * Permutation(m - i, n - i) % P);
    }
    printf("%d\n", ans);
    return 0;
}

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

# 整数の入力
N = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
l = list(map(int, input().split()))
max = max(l)
#for i in l:
#    print(i)

num = 0
for i in l:
    num=i+num
num = num-max
#print(num)
#print(max)
if num > max:
    print("Yes")
else:
    print("No")
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

Measured memory_bytes: 3060
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
#dp[i][ｊ]:=i番目までで、最後にｊを出したときの点数の最大値
dp = [[-10**9]*3for i in range(n+k)]
for i in range(k):
    dp[i][0],dp[i][1],dp[i][2] = 0,0,0
    
    
 
for i in range(k):
    for j in range(n//k+3):
        if i > n-1:continue
        if t[i] == "r":
            dp[i+k][0] = max(dp[i][1],dp[i][2])
            dp[i+k][1] = max(dp[i][0],dp[i][2])
            dp[i+k][2] = max(dp[i][0]+p,dp[i][1]+p)
        
        elif t[i] == "s":
            dp[i+k][0] = max(dp[i][1]+r,dp[i][2]+r)
            dp[i+k][1] = max(dp[i][0],dp[i][2])
            dp[i+k][2] = max(dp[i][0],dp[i][1])
        
        elif t[i] == "p":
            dp[i+k][0] = max(dp[i][1],dp[i][2])
            dp[i+k][1] = max(dp[i][0]+s,dp[i][2]+s)
            dp[i+k][2] = max(dp[i][0],dp[i][1])
        i += k
ans = 0    
for i in range(n,n+k):
    ans += max(dp[i])
print(ans)


Measured memory_bytes: 25932
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using vec = vector<T>;
template<typename T> using prior = priority_queue<T>;;

const ll MOD = 1e9+7;
const ll SPMOD = 998244353;
const double PI  = 3.14159265358;
const double EPS = 1e-8;
 
#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define siz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define Unique(v) v.rs(unique(ALL(v))-v.begin())
#define EB emplace_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define __ <<' '<<
#define kiyohime ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

// template
ll POW();
int gcd(int a, int b);
// end of template

#define N 100010

void solve(){
    string s;
    bool flag = true;
    
    cin >> s;
    int n = s.size();
    
    rep(i, n/2)
        if(s[i] != s[n-i-1])
            flag = false;
    
    rep(i, n/4){
        if(s[i] != s[n/2-1-i])
            flag = false;
    }
    
    if(flag) cout << "Yes" << '\n';
    else     cout << "No "  << '\n';
}

int main(){
    kiyohime
    int T = 1;
    
    while(T--){
        solve();
    }
}


// templates

ll POW(ll a, ll b, ll m = MOD){
    ll res = 1;
    while(b){
        if(b&1) res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

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


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean ok = true;
		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		while(sc.hasNext()) {
			int[] list = new int[3];
			for(int i = 0; i < 3; i++) {
				list[i] = sc.nextInt();
			}
			if(!ok) continue;
			Arrays.sort(list);
			if(list[0] + list[1] <= list[2]) ok = false;
			else {
				a++;
				if(list[0]*list[0] + list[1] * list[1] < list[2] * list[2])c++;
				else if(list[0]*list[0] + list[1] * list[1] > list[2] * list[2]) d++;
				else b++;
			}
		}
		System.out.println(a + " " + b + " " + d + " " + c);

	}



}

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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 3010;

int R, C, K;
V< V<> > item;

int dp[MAX_N][MAX_N][4];

static inline int dfs(int i, int j, int state) {
    if(i >= R && j >= C) { return 0; }

    int& ret = dp[i][j][state];
    if(~ret) { return ret; }
    ret = 0;

    // 右に移動
    if(j < C - 1) {
        if(item[i][j + 1] > 0) {
            if(state < 3) {
                // アイテムがまだ取れる
                chmax(ret, dfs(i, j + 1, state + 1) + item[i][j + 1]);
            }
        }
        // とらない場合
        chmax(ret, dfs(i, j + 1, state));
    }

    // 下に移動
    if(i < R - 1) {
        if(item[i + 1][j] > 0) {
            // 取る
            chmax(ret, dfs(i + 1, j, 1) + item[i + 1][j]);
        }
        // とらない場合
        chmax(ret, dfs(i + 1, j, state));
    }

    return ret;
}

signed main() {
    IOS;

    cin >> R >> C >> K;
    item.assign(R, V<>(C, 0));
    REP(i, K) {
        int r, c, v;
        cin >> r >> c >> v;
        --r; --c;
        item[r][c] = v;
    }

    MINUS(dp);
    int ans = max(dfs(0, 0, 0), dfs(0, 0, 1) + item[0][0]);
    print(ans);

    return 0;
}


Measured memory_bytes: 357212
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.sort()
y.sort()
Zx = x[-1] + 1
Zy = y[0]
flag = True
if Zx <= Zy:
    for z in range(Zx, Zy+1):
        if X < z and z<= Y:
            flag = False
            break
if flag:
    print("War")
else:
    print("No War")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3,y3,x4,y4,d1,d2;
    d1=x2-x1;
    d2=y2-y1;
    cout << x2-d2<<" ";
    cout << y2+d1<<" ";
    cout << x1-d2<<" ";
    cout << y1+d1<<endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
from collections import deque
def main():
    readline = stdin.readline
    H,W = map(int,readline()[:-1].split())
    A = ['' for i in range(H)]
    visited = [[False] * W for i in range(H)]
    q = deque()
    for i in range(H):
        A[i] = readline()[:-1]
        # print(A[i])
        for j,color in enumerate(A[i]):
            if '#' == color:
                q.append([i,j,0])
                visited[i][j] = True
            # for i in visited:
            #     print(i)
    mx = 0
    direction = [[1,0],[0,1],[-1,0],[0,-1]]
    op = -1
    while len(q) > 0:
        # print(q)
        tmp = [y,x,op] = q.popleft()
        # print(tmp)
        mx = mx if mx > op else op
        for [dx,dy] in direction:
            ny,nx = y + dy , x + dx
            if  0 <= ny and ny < H and 0 <= nx and nx < W:
                if A[ny][nx] == '#' or visited[ny][nx] == True:
                    continue
                q.append([ny,nx,op+1])
                visited[ny][nx] = True
    print(op)

main()


Measured memory_bytes: 174172
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APayment solver = new APayment();
        solver.solve(1, in, out);
        out.close();
    }

    static class APayment {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            out.println((1000 - (n % 1000)) % 1000);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

unsigned long gcd(const unsigned long a, const unsigned long b){
    return (b == 0) ? a : gcd(b,a % b);
}

void Main(){
    ul a,b;
    ll ans = 1;
    cin >> a >> b;
    ul g = gcd(a,b);
    for(ll i = 2; i*i <= g; i++){
        if(g % i == 0){
            ans++;
            while(g % i == 0){
                g /= i;
            }
        }
    }
    if(g>2) ans++;
    cout << ans << endl;
}
    
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    Main();
    return 0;
}



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

int main(){
	int N,S;
	

	while(1){
    int n[20002]={};
	cin>>N>>S;if(N==0&&S==0)break;

	for(int i=0;i<N;i++)
		cin>>n[i];

	int c=0;
	for(int i=0;i<N;i++)
		for(int j=i+1;j<N;j++)
			if(n[i]+n[j]>S)c++;

	cout<<c<<endl;
	}
	return 0;
}
	

Measured memory_bytes: 1244
import itertools

N, M = map(int, input().split())
KS = []
for _ in range(M):
    KS.append(tuple(map(int, input().split())))
P = tuple(map(int, input().split()))

ans = 0
for t in itertools.product([0, 1], repeat=N):
    for m in range(M):
        if sum(t[x - 1] for x in KS[m][1:]) % 2 != P[m]:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>


int main()
{
	int N = 0;
	std::cin >> N;

	if (N % 2 == 0)
	{
		std::cout << N / 2 << std::endl;
	}
	else
	{
		int ans = N / 2;
		std::cout << ans + 1 << std::endl;
	}

	return 0;
}

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

int main() {
	int n,m,k,i,ans=0,tot,k1=0,k2=0,mx1=0,mx2=0;
	cin>>n>>m>>k;
//	map<pair<int,int>,int>mp;
	int a[n+1]={0},b[m+1]={0};
	int x[k+1],y[k+1];
	for(i=1;i<=k;i++){cin>>x[i]>>y[i];
	   a[x[i]]++;b[y[i]]++;
	   mx1=max(mx1,a[x[i]]);
	mx2=max(mx2,b[y[i]]);
	}
    ans=mx1+mx2-1;
   for(i=1;i<=n;i++)if(a[i]==mx1)k1++;
   for(i=1;i<=m;i++)if(b[i]==mx2)k2++;
   int x1[n+1]={0};
   for(i=1;i<=k;i++){
       if(b[y[i]]==mx2)x1[x[i]]++;
   }
   for(i=1;i<=n;i++){
       if(a[i]<mx1)continue;
       if(x1[i]<k2){ans++;break;}
   }
   cout<<ans;
	return 0;
}


Measured memory_bytes: 9460
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100 * 1000 + 47;


int A[MAX];
int B[MAX];

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    
    FOR(i, 0, n)
        A[i] = 1;
    
    B[0] = 1;
    
    FOR(i, 0, m)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        --x, --y;
        if (B[x])B[y] = 1;
        A[x]--, A[y]++;
        if (!A[x])B[x] = 0;
    }
    int cnt = 0;
    FOR(i, 0, n)
        cnt += B[i];
    cout << cnt << endl;
}


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

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

    int N;
    cin >> N;

    vector<vector<ll> > A(N, vector<ll>(N));
    vector<vector<ll> > c(N, vector<ll>(N));

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }

    vector<vector<ll> > x = A;

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(i == j) continue;
            for(int k = 0; k < N; k++) {
                if(i == k || j == k) continue;
                x[j][k] = min(x[j][k], x[j][i] + x[i][k]);
                if(x[j][k] == x[j][i] + x[i][k]) {
                    c[j][k] = true;
                }
            }
        }
    }

    ll ans = 0;

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(A[i][j] != x[i][j]) {
                cout << -1 << endl;
                return 0;
            }
            if(c[i][j]) continue;
            ans += A[i][j];
        }
    }

    cout << ans / 2 << endl;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main() {
  int R, G, B, N, ans=0; cin >> R >> G >> B >> N;
  for (int i=0; i<=N/R; i++) {
    for (int j=0; j<=N/G; j++) {
      int res = N-R*i-G*j;
      if(res%B==0&&res>=0) ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
n = int(input())
ans = [0] * (n+1)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            s = x*x + y*y + z*z
            s += x*y + y*z + z*x
            if (s > n):
                continue
            else:
                ans[s] += 1

for i in range(1, n+1):
    print(ans[i])

Measured memory_bytes: 74524
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define MOD 1000000007

int main(){
  int n;
  cin>>n;
  long ans=1;
  while(n>1) ans *= n--, ans%=MOD;

  cout<<ans%MOD<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
    string S;
    cin >> S;
    int n = S.size();
    rep(i, n)
    {
        rep2(j, i, n)
        {
            string s = S.substr(0, i) + S.substr(j, n - j);
            if (s == "keyence")
            {
                cout << "YES";
                return 0;
            }
        }
    }
    cout << "NO";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
m = 1000
s = 0
for i in range(0,n):
    for j in range(i+1,n):
        if a[i] != a[j]:
            if a[i] >= a[j]:
                m = m + s *a[i]
                s = 0
                break
            else:
                s = s + m//a[i]
                m = m - m//a[i]*a[i]
                break

print(m+s*a[len(a)-1])

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=2019;

int main(){
    ll N, D;
    cin >> N >> D;
    vector<ll> x(N), y(N);
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i];
    }
    int cnt=0;
    for(int i=0; i<N; i++){
        ll dist=x[i]*x[i]+y[i]*y[i];
        if(dist <= D*D) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6348
n = input()
m = list(n)
r = []

for i in range(3):
    if m[i] == "1":
        m[i] = "9"
        r.append(m[i])
    elif m[i] == "9":
        m[i] ="1"
        r.append(m[i])
    else:
        r.append(m[i])

print(int("".join(r)))

Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
    int n,i,cnt=1;
    scanf("%d",&n);
    char a[n+1];
    for(i=0;i<n;i++) scanf("%s",&a[i]);
    for(i=1;i<n;i++){
        if(a[i-1]!=a[i]) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,cnt,num[100001],renum[100001],dp[100001][2];
vector<vector<int>> graph;

void dfs(int curr , int par){
	cnt += 1;
	num[curr] = cnt;
	renum[cnt] = curr;
	for(int i : graph[curr]){
		if(i == par){
			continue;
		}
		dfs(i,curr);
	}
}

int main(){
	cin >> n;
	graph.resize(n+1);
	for(int i = 0 ; i < n-1 ; i += 1){
		int a,b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	dfs(1,1);
	// 0 = white , 1 = black
	for(int i = n ; i >= 1 ; i -= 1){
		long long sum1 = 1 , sum2 = 1;
		bool f = false;
		for(int j : graph[renum[i]]){
			if(num[j] > i){
				f = true;
				sum1 *= dp[num[j]][0];
				sum2 *= dp[num[j]][0]+dp[num[j]][1];
				sum1 %= 1000000007;
				sum2 %= 1000000007;
			}
		}
		dp[i][0] = sum2;
		dp[i][1] = sum1;
	}
	cout << (dp[1][0]+dp[1][1])%1000000007 << endl;
}

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

int R, G, B, N, ans;

int main()
{
    std::scanf("%d%d%d%d", &R, &G, &B, &N);
    for (int i = 0; i * R <= N; i++)
    {
        for (int j = 0; j * G + i * R <= N; j++)
        {
            if ((N - i * R - j * G) % B == 0) ans++;
        }
    }
    std::printf("%d\n", ans);
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

c = 0
m = 0

if n == 1:
    print(0)
else:
    for i in range(n-1):
        if h[i+1] <= h[i]:
            c += 1
        else:
            c = 0
        m = max(m, c)

    print(m)

Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;
    if(S=="Sunny"){
        cout << "Cloudy" << endl;
    }
    if(S=="Cloudy"){
        cout << "Rainy" << endl;
    }
    if(S=="Rainy"){
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
flag = [1] * n
for i in range(m):
    p1, p2 = map(int, input().split())
    if h[p1-1] == h[p2-1]:
        flag[p1-1], flag[p2-1] = 0, 0
    elif h[p1-1] < h[p2-1]:
        flag[p1-1] = 0
    else:
        flag[p2-1] = 0
print(flag.count(1))


Measured memory_bytes: 20104
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T>using onset=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
  #ifndef ONLINE_JUDGE    
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf   
    ll n; 
    cin>>n; 
    ll ans=n%1000;
    ans=1000-ans; 
    if(n%1000==0){
      ans=0;
    }
    cout<<ans<<endl; 
    
    //printclock;
    return 0;
}
    

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#define INT_MAX 2147483647
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,n;
    vector<pair<int,int> > ab;
    vector<int> dp;
    cin >> h >> n;
    for (int i = 0; i < n; i++)
    {
        pair<int,int> p;
        int a,b;
        cin >> a >> b;
        p = make_pair(a,b);
        ab.push_back(p);
    }
    dp.push_back(0);
    for (int i = 1; i < h+1; i++)
    {
        dp.push_back(INT_MAX);
    }
    for (int i = 1; i < h+1; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int idx;
            idx = max(0,i-ab[j].first);
            dp[i] = min(dp[i], dp[idx] + ab[j].second);
        }
        
    }
    cout << dp[h] << "\n";
    
    return 0;
}


Measured memory_bytes: 384
local n=io.read("n")
for i=1,3500 do
    for j=1,3500 do
        local a=n*i*j
        local b=(4*i*j-n*j-n*i)
        if b>0 and a%b==0 then
            local k=math.floor(a/b)
            print(i.." "..j.." "..k)
            os.exit()
        end
    end
end

Measured memory_bytes: 2784
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

const int mod = 2019;

signed main(){
  int a, b;cin >> a >> b;
  b = min(a+2019+1, b);
  int ans = (a*(a+1))%mod;
  repi(i,a,b+1)repi(j,a,b+1){
    if(j <= i)continue;
    ans = min(ans, i*j%mod);
  }
  cout << ans << endl;
  return 0;
}






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


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

  rep(i,q){
      string X,Y;
      cin >> X >> Y;
      int xl,yl;
      xl = X.size();
      yl = Y.size();

      vector<vector<int>> dp(xl+1,vector<int>(yl+1));
      for(int i = 0;i < xl;i++){
          for(int j = 0;j < yl;j++){
              if (X.at(i) == Y.at(j)){
                  dp.at(i+1).at(j+1) = max(dp.at(i).at(j)+1,dp.at(i+1).at(j+1));
              }
              dp.at(i+1).at(j+1) = max(dp.at(i+1).at(j+1),dp.at(i+1).at(j));
              dp.at(i+1).at(j+1) = max(dp.at(i+1).at(j+1),dp.at(i).at(j+1));
          }
      }
      cout << dp.at(xl).at(yl) << endl;


  }
  
}


Measured memory_bytes: 6800
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 = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (i < 10) {
                if (a <= i && i <= b) {
                    ans += i;
                }
            } else if (i < 100) {
                int x = i / 10;
                int y = i % 10;
                int sum = x + y;
                if (a <= sum && sum <= b) {
                    ans += i;
                }
            } else if (i < 1000) {
                int x = i / 100;
                int y = (i / 10) % 10;
                int z = i % 10;
                int sum = x + y + z;
                if (a <= sum && sum <= b) {
                    ans += i;
                }
            } else if (i < 10000) {
                int x = i / 1000;
                int y = (i / 100) % 10;
                int z = (i / 10) % 10;
                int w = i % 10;
                int sum = x + y + z + w;
                if (a <= sum && sum <= b) {
                    ans += i;
                }
            } else {
                if (a == 1) {
                    ans += i;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
S = gets.chomp
h,t,r = '',''
gets.to_i.times {
  _,f,c = gets.split
  next r = !r  if !c
  [h,t][f.ord-?1.ord-(r ? 1: 0)] << c
}
r ? (print t.reverse, S.reverse, h) : (print h.reverse, S, t)

Measured memory_bytes: 4348
H,W=map(int,input().split())
A=[[int(i) for i in input().split()] for i in range(H)]
n=0
B=[]
for j in range(H-1):
    for i in range(W):
        if A[j][i]%2!=0:
            #S.append(A[j][i]-1)
            A[j][i]-=1
            A[j+1][i]+=1
            n+=1
            B.append([j+1,i+1,j+2,i+1])
for i in range(W-1):
    if A[H-1][i]%2!=0:
        #S.append(A[H-1][i]-1)
        A[H-1][i]-=1
        A[H-1][i+1]+=1
        n+=1
        B.append([H,i+1,H,i+2])
print(n)
for i in range(len(B)):
    print(' '.join(map(str,B[i])))

Measured memory_bytes: 65884
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int t[n+1],x[n+1],y[n+1];
    t[0]=0; x[0]=0; y[0]=0;
    for(int i=1;i<n+1;i++){
        cin >> t[i] >> x[i] >> y[i];
        if(t[i]-t[i-1] < abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
          || ( (t[i]-t[i-1] > abs(x[i]-x[i-1])+abs(y[i]-y[i-1])) 
          && ( ( (t[i]-t[i-1])%2 != abs(x[i]-x[i-1])%2 + abs(y[i]-y[i-1])%2 ) )) ){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 4648
#include<bits/stdc++.h>
using namespace std;
int n,d,x[15][15],di,ans;
double di1;
int main(){
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=d;j++){
			scanf("%d",&x[i][j]);
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			di1=0;
			for(int k=1;k<=d;k++){
				di1+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			di1=sqrt(di1);
			di=(int)(di1);
			if(di1==di) ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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



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

    vector<int64_t> L(n),R(n);
    for(int i=0;i<n;i++){
        int64_t A;
        cin>>A;
        L.at(i)=i+1+A;
        R.at(i)=i+1-A;
    }

    map<int64_t, int64_t> check;
    for(int i=0;i<n;i++){
        if(check.count(L.at(i)))
            check.at(L.at(i))++;
        else
            check[L.at(i)]=1;
    }

    int64_t sum=0;
    for(int i=0;i<n;i++){
        if(check.count(R.at(i)))
            sum+=check.at(R.at(i));
    }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 18628
#include<bits/stdc++.h>
using namespace std;
string a,b;
int lena,lenb;
int main(){
    getline(cin,a);
    getline(cin,b); 
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), greater<char>()); 
    if(a < b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
ll x[100010]; 
int main() {
	ll n,a,b;
	cin >> n >> a >> b;
	rep(i,n) cin >> x[i];

	ll ans = 0;
	ll now = x[0];
	rep(i,n) {
		ll walk = a * (x[i] - now);
		if (walk <= b) ans += walk;
		else ans += b;
		now = x[i];
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    cout << min(N*A,B) << endl;
}

Measured memory_bytes: 3620
stdin.ReadLine()
|> fun x -> x.Split(' ')
|> Array.map int
|> fun x -> (x.[0], x.[1])
|> fun (k, s) ->
  [0..k]
  |> Seq.map (fun x ->
    [0..k]
    |> Seq.filter (fun y -> (s >= x + y) && (k >= s - x - y))
    |> Seq.length
  )
  |> Seq.reduce (+)
|> printfn "%A"


Measured memory_bytes: 28700
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

  map<int,ll> mp;
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    mp[a] += b;
  }
  ll ans = 0;
  for (auto shop : mp) {
    ll buy = min((ll)m, shop.se);
    ans += buy*shop.fi;
    m -= buy;
  }
  cout << ans << endl;
  return 0;
}

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

int N, M;
vector<vector<ll>> xyz(3, vector<ll>(1001, 0));
 
int main(void){
    
    scanf("%d %d", &N, &M);
    for(int i = 0; i < N; ++i) scanf("%lld %lld %lld", &xyz[0][i], &xyz[1][i], &xyz[2][i]);
    
    ll ans = 0;
    for (int bit = 0; bit < (1 << 3); ++bit){
        
        vector<int> s;
        for (int i = 0; i < 3; ++i){
            if (bit & (1 << i)) s.push_back(i);
        }
        
        vector<bool> mx(3, false);
        for(int i = 0; i < s.size(); ++i) mx[s[i]] = true;
        
        vector<ll> v;
        for(int i = 0; i < N; ++i){
            ll num = 0;
            for(int j = 0; j < 3; ++j) num += (mx[j]) ? xyz[j][i] : -xyz[j][i];
            v.push_back(num);
        }
        sort(v.begin(), v.end(), greater<ll>());
        
        ll num = 0;
        for(int i = 0; i < M; ++i) num += v[i];
        ans = max(ans, num);
    }
    printf("%lld\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let N = read::<i32>();
    let bdama = N%10 + (N/10)%10 + N/100;
    println!("{}", bdama);
}


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

int main() {
	int N,A,B;
	cin >> N >> A >> B;
  
  	int sum = N * A;
  
  	if(sum > B) {
    	cout << B << endl;
    }else {
    	cout << sum << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1005;
int main() {
	int n; cin >> n;
	vv(int, dp, MAX, MAX, 0);
	string X, Y;
	rep(i, 0, n) {
		cin >> X >> Y;
		int len_X = len(X);
		int len_Y = len(Y);
		rep(i, 0, len_X) {
			rep(j, 0, len_Y) {
				dp[i + 1][j + 1] = (X[i] == Y[j] ? dp[i][j] + 1 : max(dp[i][j + 1], dp[i + 1][j]));
			}
		}
		P(dp[len_X][len_Y]);
	}
	return 0;
}

Measured memory_bytes: 6720
n = gets.to_i
a = gets.split.map(&:to_i)

b = []
n.step(1, -2) do |i|
  b << a[i - 1]
end

(n.odd? ? 2 : 1).step(n, 2) do |i|
  b << a[i - 1]
end

puts b.join(" ")


Measured memory_bytes: 25476
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=200086;
const int maxm=400086;
int head[maxn],Next[maxm],to[maxm],vis[maxn],cnt,ans;
int a[maxn],p[maxn],f[maxn],n;
inline void add(int x,int y){
	to[++cnt]=y;Next[cnt]=head[x];head[x]=cnt;
	to[++cnt]=x;Next[cnt]=head[y];head[y]=cnt;
}
inline int Read(){
	int x=0;char c=getchar();
	while (!isdigit(c))c=getchar();
	while (isdigit(c)){
		x=(x<<1)+(x<<3)+c-48;
		c=getchar();
	}
	return x;
}
int main(){
	n=Read();
	for (int i=1;i<=n;i++){
		a[i]=Read();
		p[a[i]]=i;
	}
	for (int i=2;i<=n;i++){
		if (p[i]>p[i-1])f[i]=f[i-1]+1;
	}
	for (int i=1;i<=n;i++){
		ans=max(f[i],ans);
	}
/*	for (int i=1;i<=n;i++){
		printf("%d ",a[i]);
	}printf("\n");
	for (int i=1;i<=n;i++){
		printf("%d ",p[i]);
	}printf("\n");
	for (int i=1;i<=n;i++){
		printf("%d ",f[i]);
	}printf("\n");*/
	printf("%d",n-ans-1);
	return 0;
}

Measured memory_bytes: 4352
#include<iostream>

using namespace std;

void Wrap(int (&a)[100],int num1,int num2){
		int tmp=a[num1];
		a[num1]=a[num2];
		a[num2]=tmp;
}


int main(){
	int N;
	int a[100];
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	
	for(int i=0;i<N-1;i++){
		if(a[i]<a[i+1]){
			for(int j=i;j>=0;j--){
				
				if(a[j]>a[j+1])break;
				Wrap(a,j,j+1);
			}
		}
	}
	
	
	int  Alice,Bob;
	
	Alice=0;
	Bob=0;
	
	for(int i=0;i<N;i++){
		if(i%2==0){
			Alice+=a[i];
		}else{
			Bob+=a[i];
		}
	}
	int ans=Alice-Bob;
	cout << ans;
}

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

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

  vector< vector<int>> bc(m,vector<int>(2));
  for (int i = 0;i < m;i++){
    long long int b,c;
    cin >> b >> c;

    bc.at(i).at(0) = c;
    bc.at(i).at(1) = b;
  }

  sort(avec.begin(),avec.end());
  sort(bc.begin(),bc.end(),greater<vector <int> >());


  long long int ans = 0;
  int flag = 0;
  for (int i = 0;i < n;i++){
    long long int a = avec.at(i);

    if (bc.at(flag).at(1) > 0){
      if (bc.at(flag).at(0) > a){
        a = bc.at(flag).at(0);
        bc.at(flag).at(1)-=1;
      }
    }else{
      flag+=1;
      if (flag == m){
        break;
      }
      if (bc.at(flag).at(0) > a){
        a = bc.at(flag).at(0);
        bc.at(flag).at(1)-=1;
      }
    }

    avec.at(i) = a;
  }


  for (int i = 0;i < n;i++){
    ans+=avec.at(i);
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 6144
#include "bits/stdc++.h"
using namespace std;
int main(){
    string A,B;
    cin >> A >> B;
    int n,m,i;
    n = A.size();
    m = B.size();
    if(n>m) cout << "GREATER" << endl;
    else if(n<m) cout << "LESS" << endl;
    else{
        for(i=0;i<n;i++){
            if(A.at(i)<B.at(i)){
                cout << "LESS" << endl;
                break;
            }
            else if(A.at(i)>B.at(i)){
                cout << "GREATER" << endl;
                break;
            }
        }
        if(i == n) cout << "EQUAL" << endl;
    }
    return 0;
}

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

class Main {
	double[][] p = new double[2][6];

	void run() {
		Scanner sc = new Scanner(System.in);
		int Na = sc.nextInt();
		int Nb = sc.nextInt();
		long[] xa = new long[Na];
		long[] ya = new long[Na];
		long[] xb = new long[Nb];
		long[] yb = new long[Nb];
		for (int i = 0; i < Na; ++i) {
			xa[i] = sc.nextLong();
			ya[i] = sc.nextLong();
		}
		for (int i = 0; i < Nb; ++i) {
			xb[i] = sc.nextLong();
			yb[i] = sc.nextLong();
		}

		double ans = Double.MAX_VALUE / 3;
		for (int t = 0; t < 2; ++t) {
			for (int i = 0; i < Na; ++i) {
				for (int j = 0; j < Na; ++j) {
					if (cross(xa[0], ya[0], xa[i], ya[i], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					if (cross(xa[i], ya[i], xa[j], ya[j], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					if (cross(xa[j], ya[j], xa[1], ya[1], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					ans = Math.min(ans, dist(xa[0], ya[0], xa[i], ya[i]) + dist(xa[i], ya[i], xa[j], ya[j])
							+ dist(xa[j], ya[j], xa[1], ya[1]) + dist(xb[0], yb[0], xb[1], yb[1]));
				}
			}
			Na ^= Nb;
			Nb ^= Na;
			Na ^= Nb;
			long[] tmp = new long[Na];
			tmp = Arrays.copyOf(xa, xa.length);
			xa = Arrays.copyOf(xb, xb.length);
			xb = Arrays.copyOf(tmp, tmp.length);
			tmp = Arrays.copyOf(ya, ya.length);
			ya = Arrays.copyOf(yb, yb.length);
			yb = Arrays.copyOf(tmp, tmp.length);
		}
		System.out.println(ans >= Double.MAX_VALUE / 4 ? "-1" : ans);
	}

	double dist(long xa, long ya, long xb, long yb) {
		long dx = xa - xb;
		long dy = ya - yb;
		return Math.sqrt(dx * dx + dy * dy);
	}

	boolean cross(long xa1, long ya1, long xb1, long yb1, long xa2, long ya2, long xb2, long yb2) {
		long v = f(xa1, ya1, xb1, yb1, xa2, ya2) * f(xa1, ya1, xb1, yb1, xb2, yb2);
		long u = f(xa2, ya2, xb2, yb2, xa1, ya1) * f(xa2, ya2, xb2, yb2, xb1, yb1);
		return v <= 0 && u <= 0;
	}

	long f(long xa, long ya, long xb, long yb, long x, long y) {
		return (ya - yb) * (x - xa) - (y - ya) * (xa - xb);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 36744
#include<stdio.h>

int main(void) {
        int H,W,i,j;
        while(1) {
                scanf("%d %d", &H, &W);
                if(H==0 && W==0)        break;
                for(i=0;i<H;i++) {
                        for(j=0;j<W;j++) {
                                printf("#");
                        }
                        printf("\n");
                }
                printf("\n");
        }
        return 0;
}

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

int main()
{
	LL n;
	in >> n;
	std::vector<LL>p(n);
	rep(i, n) in >> p[i];

	LL ans = 0;
	rep(i, n - 2)
	{
		if (p[i + 1] != std::min({ p[i],p[i + 1],p[i + 2] }) && p[i + 1] != std::max({ p[i],p[i + 1],p[i + 2] }))
		{
			++ans;
		}
	}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);

	set<int> color;
	color.insert(a);
	color.insert(b);
	color.insert(c);

	printf("%d\n", color.size());


	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> gr={0,2,0,1,0,1,0,0,1,0,1,0};
  int x,y;
  cin>>x>>y;
  if(gr.at(x-1)==gr.at(y-1))
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>

#define mod 1000000007
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

void solve() {
    int n, k, res = 0;
    cin >> n >> k;
    int x[n];
    REP(i, n) cin >> x[i];

    REP(i, n){
        res += 2*min(abs(x[i]-k), x[i]);
    }
    cout << res << endl;
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int k = sc.nextInt();
        
        char hoge = s[k-1];
        for (int i = 0; i < n; i++) {
            if (s[i] == hoge)
                sb.append(s[i]);
            else
                sb.append('*');
        }
        
        System.out.println(sb.toString());
    }
}


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

using namespace std;

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

    int max1=0;
    int max2=0;
    int max_index=0;
	int d[n];
//	int d_sort[n];
	for(int i=0; i<n;i++){
	  cin >> d[i];

		if(max1<d[i]){
			max1 = d[i];
			max_index = i;
		}
	}

//	sort(d_sort,d_sort+n);
//
//	max2 = d_sort[n-2];
	sort(d,d+n);

	max2 = d[n-2];

	for(int i=0; i<n;i++){
		if(i == max_index){
	    	cout<<max2<<endl;
		}
		else{
			cout<<max1<<endl;
		}
//    	ans[i] = tmp;

    }

//    cout<<endl;
//    for(int i=0;i<n;i++){
//    	cout<<ans[i]<<endl;
//    }
    return 0;
}

Measured memory_bytes: 2432