akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
long long int dp[1005][1005];
char c[1005][1005];
int main()
{
	int h,w,b1=0;
	cin >> h >> w;
	for(int i=0;i<h;i++) {
		for(int j=0;j<w;j++) {
			cin >> c[i][j];
		}
	}
	for(int i=0;i<h;i++) {
		if(b1==0 && c[i][0]!='#') dp[i][0]=1;
		if(c[i][0]=='#') b1+=1;
	}
	b1=0;
	for(int i=0;i<w;i++) {
		if(b1==0 && c[0][i]!='#') dp[0][i]=1;
		if(c[0][i]=='#') b1+=1;
	}
	for(int i=1;i<h;i++) {
		for(int j=1;j<w;j++) {
			if(c[i-1][j]!='#') dp[i][j]+=dp[i-1][j];
			if(c[i][j-1]!='#') dp[i][j]+=dp[i][j-1];
			dp[i][j]%=1000000007;
		}
	}
	/*for(int i=0;i<h;i++) {
		for(int j=0;j<w;j++) {
			//cout <<dp[i][j]<<" ";
		}
		cout <<endl;
	}*/
	cout <<dp[h-1][w-1]%1000000007;
	return 0;
}


Measured memory_bytes: 9088
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    void solve() {
        String input = in.nextToken();
        int letters[] = new int[26];
        int len = input.length();
        long result = (long)len * (len + 1) / 2;
        for (int i = 0 ; i < len ; i++) {
            letters[input.charAt(i) - 'a']++;
        }
        for(int i = 0 ; i < len ; i++){
            result -= letters[input.charAt(i) - 'a'];
            letters[input.charAt(i) - 'a']--;
        }
        result += 1;
        out.print(result);
    }


    FastScanner in;
    PrintWriter out;

    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

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

}

Measured memory_bytes: 27220
#include <stdio.h>

int main(void){
	int a;
	
	scanf("%d",&a);

	// printf("%d\n",a);

	if(a < 1200){
		printf("ABC\n");
	}else if(a < 2800){
		printf("ARC\n");
	}else{
		printf("AGC\n");
	}



	return 0;
}

Measured memory_bytes: 128
K,T=map(int,input().split())

a=list(map(int,input().split()))

answer=max(a)

print(max(0,answer-(K-answer+1)))
#K-answerで一番多いケーキを除いたケーキの個数が分かる。
#実際には◎×◎△◎のように1個分多く処理できるため、さらに1個分余分にmaxから引く

Measured memory_bytes: 2940
#include <stdio.h>

int main(void){
	long long int a;
	long long int b;
	scanf("%lld %lld", &a, &b);
	if(a <= 0 && b >= 0){
		printf("Zero\n");
		return 0;
	}
	if(a > 0){
		printf("Positive\n");
		return 0;
	}
	b = b - a + 1;
	if(b % 2 == 0){
		printf("Positive\n");
	} else {
		printf("Negative\n");
	}

	return 0;
}

Measured memory_bytes: 128
#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 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;}

int N;

int sig[111111];
int A[111111];
signed main(){
    cin>>N;
    int lat;cin>>lat;
    N--;
    int normal=0;
    rep(i,N){
        char c;
        int a;
        cin>>c>>a;
        if(c=='+')sig[i]=1;
        else sig[i]=-1;
        A[i]=a;
        normal+=a*sig[i];
    }

    int ans=normal;
    int latte=0,malta=0;
    for(int i=N-1;i>=0;i--){
        latte+=A[i];
        normal-=A[i]*sig[i];
        if(sig[i]==-1){
            chmax(ans,normal-latte+malta);
            malta+=latte;
            latte=0;
        }
    }
    cout<<ans+lat<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdint>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct Node
{
    vector<pair<int, int64_t>> edges;
    int64_t pos = 0;
    bool is_set = false;
};

using Graph = vector<Node>;

bool Bfs(Graph &g, int start)
{
    if (!g[start].is_set) {
        g[start].pos = 0;
        g[start].is_set = true;
    }

    queue<int> q;
    q.push(start);

    while (!q.empty()) {
        auto node = q.front();
        q.pop();

        for (const auto &edge : g[node].edges) {
            if (g[edge.first].is_set) {
                if (g[edge.first].pos != g[node].pos + edge.second) {
                    return false;
                }
                continue;
            }

            g[edge.first].pos = g[node].pos + edge.second;
            g[edge.first].is_set = true;
            q.push(edge.first);
        }
    }
    return true;
}

bool Solve(Graph &g)
{
    for (size_t i = 0; i < g.size(); i += 1) {
        if (!g[i].is_set && !Bfs(g, i)) {
            return false;
        }
    }
    return true;
}

int main()
{
    int nodes, edges;
    cin >> nodes >> edges;

    Graph graph(nodes);
    for (auto i = 0; i < edges; i += 1) {
        int a, b, dist;
        cin >> a >> b >> dist;

        graph[a - 1].edges.push_back({b - 1, dist});
        graph[b - 1].edges.push_back({a - 1, -dist});
    }

    cout << (Solve(graph) ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 14592
from heapq import heapify, heappush, heappop

def main():
    n, m = map(int, input().split())
    a = [int(x)*-1 for x in input().split()]
    ans = sum(a)*-1
    diff = 0
    
    heapify(a)
    for _ in range(1, m+1):
        _h_a = heappop(a) * -1
        diff += _h_a - _h_a // 2
        heappush(a, (_h_a // 2)*-1)
    ans -= diff
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 20248
N=int(input())
s=[input() for i in range(N)]
A=s.count("AC")
B=s.count("WA")
C=s.count("TLE")
D=N-(A+B+C)
print("AC x",A)
print("WA x",B)
print("TLE x",C)
print("RE x",D)

Measured memory_bytes: 16192
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228

#define tm tm228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << endl; 
#define TIME (ld)clock()/CLOCKS_PER_SEC
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 1e9 + 7, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll INF = 1e18, inf = 1e15;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
string s; 

void solve() {
    cin >> s; 
    int n = s.size(); 
    int ans = 0; 
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            if (s[i] == 'p') --ans; 
        } 
        if (i % 2) {
            if (s[i] == 'g') ++ans; 
        }        
    }
    cout << ans; 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
} 

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

struct Node {
  long key;
  Node *parent, *left, *right;
};

Node *root, *nil;

void insertNode(long k) {
  Node *y = nil;
  Node *x = root;

  Node *z;
  z = (Node*)malloc(sizeof(Node));
  z->key = k;
  z->parent = nil;
  z->left = nil;
  z->right = nil;

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

  z->parent = y;

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

void in(Node* n) {
  if (n == nil) return;
  in(n->left);
  cout << ' ' << n->key;
  in(n->right);
}

void pre(Node* n) {
  if (n == nil) return;
  cout << ' ' << n->key;
  pre(n->left);
  pre(n->right);
}

Node* findNode(long k) {
  Node* n = root;

  while (n != nil && n->key != k) {
    if (k < n->key) n = n->left;
    else n = n->right;
  }

  return n;
}

Node* minNodeInRight(Node* n) {
  while (n->left != nil) n = n->left;
  return n;
}

Node* getSuccessor(Node* n) {
  if (n->right != nil) return minNodeInRight(n->right);

  Node* parentN = n->parent;
  
  while (parentN != nil && n == parentN->right) {
    n = parentN;
    parentN = parentN->parent;
  }

  return parentN;
}

void deleteNode(Node* n) {
  if (n == nil) return;

  Node* childN;
  Node* deleteN;

  if (n->left == nil || n->right == nil) deleteN = n;
  else deleteN = getSuccessor(n);
  
  // decide child
  if (deleteN->left != nil) childN = deleteN->left;
  else childN = deleteN->right;

  if (childN != nil) childN->parent = deleteN->parent;

  if (deleteN->parent == nil) {
    root = childN;
  } else {
    if (deleteN->parent->left == deleteN) deleteN->parent->left = childN;
    else deleteN->parent->right = childN;
  }

  if (n != deleteN) n->key = deleteN->key;

  free(deleteN);
}

void print() {
  in(root); cout << endl;
  pre(root); cout << endl;
}

int main() {

  long l; cin >> l;

  while (l--) {
    string s; cin >> s;

    if (s == "insert") {
      long k; cin >> k;
      insertNode(k);
    } else if (s == "find") {
      long k; cin >> k;
      if (findNode(k) == nil) cout << "no";
      else cout << "yes";
      cout << endl;
    } else if (s == "delete") {
      long k; cin >> k;
      deleteNode(findNode(k));
    } else {
      print();
    }
  }

  return 0;
}

Measured memory_bytes: 19964
#include<bits/stdc++.h>
using namespace std;
string f(int k) { string s = ""; while (k--)s += '.'; return s; }
int main() {
	int n, sum = 0; string s1, s2; scanf("%d", &n);
	if (n == 2) { printf("-1\n"); return 0; }
	if (n == 3) { printf("aa.\n..x\n..x\n"); return 0; }
	if (n % 4 == 3) {
		s1 = f(sum), s2 = f(n - sum - 7);
		cout << s1 << "aabb..c" << s2 << "\n";
		cout << s1 << ".i..llc" << s2 << "\n";
		cout << s1 << ".imm..d" << s2 << "\n";
		cout << s1 << "h...n.d" << s2 << "\n";
		cout << s1 << "h...nk." << s2 << "\n";
		cout << s1 << "gjj..k." << s2 << "\n";
		cout << s1 << "g..ffee" << s2 << "\n";
		sum += 7;
	}
	else if (n % 4 == 2) {
		s1 = f(sum), s2 = f(n - sum - 6);
		cout << s1 << "aabb.c" << s2 << "\n";
		cout << s1 << ".i.llc" << s2 << "\n";
		cout << s1 << "hi...d" << s2 << "\n";
		cout << s1 << "h...kd" << s2 << "\n";
		cout << s1 << "gjj.k." << s2 << "\n";
		cout << s1 << "g.ffee" << s2 << "\n";
		sum += 6;
	}
	else if (n % 4 == 1) {
		s1 = f(sum), s2 = f(n - sum - 5);
		cout << s1 << "aabbc" << s2 << "\n";
		cout << s1 << "hii.c" << s2 << "\n";
		cout << s1 << "h..jd" << s2 << "\n";
		cout << s1 << "g..jd" << s2 << "\n";
		cout << s1 << "gffee" << s2 << "\n";
		sum += 5;
	}
	while (sum < n) {
		s1 = f(sum), s2 = f(n - sum - 4);
		cout << s1 << "aacd" << s2 << "\n";
		cout << s1 << "bbcd" << s2 << "\n";
		cout << s1 << "efgg" << s2 << "\n";
		cout << s1 << "efhh" << s2 << "\n";
		sum += 4;
	}
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}
// Fenwick tree with ranged updates and point queries. Complexity: O(log(n))
template<typename T> struct FenwickTree {
    int N;  vector<T> A;
    FenwickTree(int n): N(n+1), A(N) {}                    // Create tree with n elements
    void adjust(int b, T v) { for (;b;b-=b&-b) A[b]+=v; }              // Add v to A[0,b)
    void adjust(int a,int b, T v) { adjust(b,v), adjust(a,-v); }       // Add v to A[a,b)
    T pq(int i) { T r=0; for (i++;i<N;i+=i&-i) r+=A[i]; return r;	}           // Get A[i]
};

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m;
    cin >> n >> m;
    vi arr(n);
    ll Ma = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        arr[i] %= m;
    }
    FenwickTree<ll> tree(m+10);

    vector<ll> acc(m+10), dec(m+10);
    for (int i = 1; i < n; i++){
        int a = arr[i-1], b = arr[i];
        if (a < b) {
            Ma += b-a;
            acc[a+2]++;
            dec[b]++;
            tree.adjust(b+1, m, -(b-1-a));
        } else {
            Ma += (b + m - a);
            acc[a+2]++;
            //
            int c = m-(a+2);
            acc[0]++;
            tree.adjust(0, b+1, c);
            // minus
            dec[b]++;
            tree.adjust(b+1, m, -(b+1));
        }
    }
    ll best = LLONG_MIN/2;
    ll accum = 0;
    ll sum = 0;
    for (int i = 0; i < m; i++){
        accum += acc[i];
        sum += accum;
        ll cur = sum + tree.pq(i);
        best = max(best, cur);
        accum -= dec[i];
    }
    cout << Ma - best << endl;
}


Measured memory_bytes: 3072
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:isize,
    b:char,
    c:isize,
    }
    println!("{}",if b=='-'{a-c}else{a+c})
}

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

using namespace std;


#define MAXN 100001
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  long long a[MAXN], sm[MAXN] = {};
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sm[i] = sm[i-1]+a[i];
  }
  map<int, int> mp;
  long long ans = 0;
  for (int i = n; i > 0; --i) {
    mp[sm[i]%m]++;
    if (mp.find(sm[i-1]%m)!=mp.end()) ans += mp[sm[i-1]%m];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
inline int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
inline int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
inline int mul(int a, int b) {return 1ll * a * b % P;}
inline int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 14;
int n, m, all;
int LOG[1 << N];
bool vis[N];
string s[N], str[N];
int match[N];
bool check() {
	bool use = !(m % 2);
	memset(vis, 0, sizeof(vis));
	for(int i = 0, l = 0, r = n - 1; i < n; i++) {
		if(vis[match[i]] || vis[i]) continue;
		if(match[i] == i) continue;
		str[l] = s[i], str[r] = s[match[i]];
		vis[i] = vis[match[i]] = 1;
		l++, r--;
	}
	rep(i, 0, n) if(i == match[i]) str[n / 2] = s[i];
	memset(vis, 0, sizeof(vis));
	rep(i, 0, m) {
		if(vis[i]) continue;
		bool ok = 0;
		int j;
		for(j = 0; j < m; j++) {
			if(vis[j] || j == i) continue;
			int a, b;
			for(a = 0, b = n - 1; a < n && str[a][i] == str[b][j]; a++, b--);
			if(a == n) {
				ok = 1;
				break;
			}
		}
		if(ok) vis[i] = vis[j] = 1;
		else if(!use) {
			int a, b;
			for(a = 0, b = n - 1; a <= b && str[a][i] == str[b][i]; a++, b--);
			if(a < b) return 0;
			vis[i] = use = 1;
		}
		else return 0;
	}
//	rep(i, 0, n) de(str[i]);
//	rep(i, 0, n) dd(i), de(match[i]);
	return 1;
}
void gao(int id, int msk) {
	if(msk >> id & 1) {
		gao(id + 1, msk);
		return ;
	}
	if(msk == all) {
		if(check())
			throw 1;
		return ;
	}
	msk |= 1 << id;
	for(int j = all ^ msk; j; j -= j & -j) {
		int nxt = LOG[j & -j];
		if(nxt == id) continue;
		match[id] = nxt;
		match[nxt] = id;
		gao(id + 1, msk | 1 << nxt);
	}
}
int main(){
	bool ans = 0;
	for(int i = 0; i < N; i++) LOG[1 << i] = i;
	cin >> n >> m;
	rep(i, 0, n) cin >> s[i];
	all = (1 << n) - 1;
	try{
		if(n & 1) {
			rep(i, 0, n) {
				match[i] = i;
				gao(0, 1 << i);
			}
		} else {
			gao(0, 0);
		}
	} catch(int e) {
		ans = e;
	}
	puts(ans ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int H[] = new int[N];
		for (int i = 0; i < N; i++) {
			H[i] = sc.nextInt();
		}
		boolean f = true;
		for (int i = 1; i < N; i++) {
			if (H[i] > H[i - 1]) {
				H[i]--;
			}
			if (H[i] < H[i - 1]) {
				if (H[i] - 1 < H[i - 1]) {
					f = false;
					break;
				} else
					H[i]--;
			}
		}
		System.out.println(f ? "Yes" : "No");

	}
}

Measured memory_bytes: 59604
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
constexpr ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
#else
#define print(...)
#endif


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll n,ans;
    map<string,ll> m;
    
    cin >> n;

    m["AC"] = m["WA"] = m["TLE"] = m["RE"] = 0;
    for(ll i=0; i<n; i++){
        string s;
        cin >> s;
        m[s]++;
    }
    
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
 
    return 0;
}



Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String strIn = scan.nextLine();
		String strCheck = scan.nextLine();
		strIn += strIn;
		if(strIn.indexOf(strCheck) != -1){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		scan.close();
	}
}

Measured memory_bytes: 17280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;cin>>n;
	string s;
	cin>>s;
	
	int pR[n+1];
	int pG[n+1];
	int pB[n+1];
	memset(pR, 0, sizeof pR);
	memset(pB, 0, sizeof pB);
	memset(pG, 0, sizeof pG);
	for(int i=0;i<n;i++)
	{
		pR[i+1]=pR[i];
		pG[i+1]=pG[i];
		pB[i+1]=pB[i];
		if(s[i]=='R')pR[i+1]++;
		if(s[i]=='G')pG[i+1]++;
		if(s[i]=='B')pB[i+1]++;
	}
	
	
	
	ll ans=0;
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			if(s[i]==s[j])continue;
			
			int dist=j-i;
			int tmp=0;
			
			char fd=87^(s[i]^s[j]);
			//cout<<s[i]<<s[j]<<fd<<"\n";
			if(fd=='R')
			tmp=pR[n]-pR[j];
			else if(fd=='G')
			tmp=pG[n]-pG[j];
			else if(fd=='B')
			tmp=pB[n]-pB[j];
			
			if(j+dist < n and tmp>0)
			{
				if(s[j+dist]==fd)
				tmp--;
			}
		
			ans=ans+tmp;
			
			
			
			
			
		}
	}
	cout<<ans;
	
}

Measured memory_bytes: 3664
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int N,X,Y; cin >> N >> X >> Y;
    X--; Y--;
    vector<ll> cnt(N);
    rep(i,N-1)repr(j,i+1,N){
        if(j <= X){
            cnt[j-i-1]++;
        }
        else if(i <= X && j >= X && j <= Y){
            int k = min(j-i,X-i+Y-j+1);
            cnt[k-1]++;
        }
        else if(i <= X && j >= Y){
            cnt[X-i+j-Y]++;
        }
        else if(i >= X && i <= Y && j >= Y){
            int k = min(j-i,i-X+j-Y+1);
            cnt[k-1]++;
        }
        else if(i >= X && j <= Y){
            int k = min(j-i,i-X+Y-j+1);
            cnt[k-1]++;
        }
        else{
            cnt[j-i-1]++;
        }
    }
    rep(i,N-1){
        cout << cnt[i] << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
char s[maxn];
vector<int> a[26], b;
ll ans;
ll sub()
{
	int n = b.size();
	vector<int> pos;
	for(int i = 0; i < n; ++i)
		if(b[i])
			pos.push_back(i);
	ll ret = 0;
	for(int i = 0, j = pos.size() - 1; i <= j; ++i, --j)
		if(i < j)
			ret += abs(pos[i] - (n - 1 - pos[j]));
		else
			ret += abs(pos[i] - (n - 1) / 2);
	return ret;
}
ll solve(const int & x, const int & y)
{
	int i = 0, j = 0;
	b.clear();
	while(i < a[x].size() && j < a[y].size())
		if(a[x][i] < a[y][j])
		{
			++i;
			b.push_back(0);
		}
		else
		{
			++j;
			b.push_back(1);
		}
	while(i < a[x].size())
	{
		++i;
		b.push_back(0);
	}
	while(j < a[y].size())
	{
		++j;
		b.push_back(1);
	}
	return sub();
}
int main()
{
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	for(int i = 1; i <= n; ++i) a[s[i] - 'a'].push_back(i);
	bool find_mid = 0;
	for(int i = 0; i < 26; ++i) 
	{
		if(a[i].size() % 2)
		{
			if(find_mid)
			{
				puts("-1");
				return 0;
			}
			find_mid = 1;
		}
	}
	for(int i = 0; i < 26; ++i)	
		for(int j = i + 1; j < 26; ++j)
			if(a[i].size() && a[j].size())
				ans += solve(i, j);
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> AC(N+1,0);
  for (int i = 0; i < N; i++) {
    AC[i+1] = AC[i];
    if (S[i] == 'A' && S[i+1] == 'C') AC[i+1]++;
  }
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << AC[r-1] - AC[l-1] << endl;
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int a[100001], p[100001];

int ft[100001];
void update(int i, int v){
    for(;i<=100000;i+=(i&-i)) ft[i] += v;
}
int query(int i){
    int ans = 0;
    for(;i>0;i-=(i&-i)) ans+=ft[i];
    return ans;
}

int main(){
    int n;
    scanf("%d", &n);   
    vector<pii> v;
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
        p[a[i]] = i;
    }
    long long ans = 0;
    update(p[n], 1);
    for(int i=n-1;i>=1;i--){
        int x = p[i];
        int lo = 1, hi = x-1;

        int l1 = -1, r1 = -1;
        while(lo <= hi){
            int mid = (lo+hi)/2;
            if(query(x) - query(mid-1) >= 1){
                r1 = mid;
                lo = mid+1;
            }
            else hi = mid-1;
        }
        if(r1 != -1){
            lo = 1, hi = r1;
            while(lo <= hi){
                int mid = (lo+hi)/2;
                if(query(x) - query(mid-1) == 1){
                    l1 = mid;
                    hi = mid-1;
                }
                else lo = mid+1;
            }
            int le1 = r1-l1+1;
            int le2 = x-1;

            lo = x, hi = n;
            while(lo <= hi){
                int mid = (lo+hi)/2;
                if(query(mid) - query(x-1) == 0){
                    le2 = mid;
                    lo = mid+1;
                }
                else hi = mid-1;
            }

            le2 = le2-x+1;
            ans += le1*1ll*le2*i;
        }


        lo = x+1, hi = n;
        l1 = -1, r1 = -1;
        while(lo <= hi){
            int mid = (lo+hi)/2;
            if(query(mid) - query(x-1) >= 1){
                l1 = mid;
                hi = mid-1;
            }
            else lo = mid+1;
        }
        if(l1 != -1){
            lo = l1, hi = n;
            while(lo <= hi){
                int mid = (lo+hi)/2;
                if(query(mid) - query(x-1) == 1){
                    r1 = mid;
                    lo = mid+1;
                }
                else hi = mid-1;
            }
            int le1 = r1-l1+1;
            int le2 = x+1;

            lo = 1, hi = x;
            while(lo <= hi){
                int mid = (lo+hi)/2;
                if(query(x) - query(mid-1) == 0){
                    le2 = mid;
                    hi = mid-1;
                }
                else lo = mid+1;
            }

            le2 = x-le2+1;
            ans += le1*1ll*le2*i;
        }

        update(x, 1);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  deque<ll> V;
  for (int i = 0; i < N; i++)
  {
    ll v;
    cin >> v;
    V.push_back(v);
  }
  ll ans = -INF;
  for (int i = 0; i <= (K + 1) / 2; i++)
  {
    for (int j = 0; j < K + 1 - i; j++)
    {
      vector<ll> tmp;
      deque<ll> Vcopy = V;
      for (int k = 0; k < K - i - j; k++)
      {
        if (!Vcopy.empty())
        {
          tmp.push_back(Vcopy.front());
          Vcopy.pop_front();
        }
      }
      for (int k = 0; k < j; k++)
      {
        if (!Vcopy.empty())
        {
          tmp.push_back(Vcopy.back());
          Vcopy.pop_back();
        }
      }
      sort(tmp.begin(), tmp.end());
      int tmpSize = tmp.size();
      for (int k = 0; k < min(i, tmpSize); k++)
      {
        if (tmp[k] < 0)
          tmp[k] = 0;
      }
      /*
      for (auto &it : tmp)
        cerr << it << " ";
      cerr << endl;
      */
      ans = max(ans, accumulate(tmp.begin(), tmp.end(), 0LL));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            
            if (h == 0 && w == 0) {
                break;
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
        
        
    }
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc094() {
	ll n;
	cin >> n;

	V x(n), y(n);
	rep(i, n) {
		cin >> x[i];
		y[i] = x[i];
	}

	sort(ALL(y));

	ll mean = y[n / 2];
	V ans(n);
	rep(i, n) {
		if (x[i] < mean) {
			ans[i] = mean;
		}
		else {
			ans[i] = y[n / 2 - 1];
		}
	}

	rep(i, n) {
		cout << ans[i] << "\n";
	}
}

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

	solve_abc094();

	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <string>

using namespace std;

int main()
{
#if 0
	int N;
//	unsigned int num[200];
	unsigned int OR = 0;

	cin >> N;
	for (int i = 0; i < N; ++i) {
//		cin >> num[i];
		unsigned int tmp;
		cin >> tmp;
		OR |= tmp;
	}

	int count = 0;
	while (OR != 0) {
		if ((OR & 0x1) == 0) { count += 1; }
		OR /= 2;
	}

#else
	int N;
	unsigned int num[200];

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

	int count = 0;
	for(int i = 0; i < 32; ++i) {
		bool even = true;
		for (int k = 0; k < N; ++k) {
			if ((num[k] >> i) & 0x1) {
				even = false;
				break;
			}
		}

		if (even) {
			++count;
		}
		else {
			break;
		}
	}

#endif

	cout << count << endl;
	return 0;
}




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

int main() {

	int n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	if (a[0] == 0) {
		cout << 0 << endl;
		return 0;
	}
	const ll u = 1000000000000000000LL;
	ll prod = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] <= u / prod) {
			prod *= a[i];
		}
		else {
			prod = -1;
			break;
		}
	}
	cout << prod << endl;
	return 0;
}

Measured memory_bytes: 3980
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#include <map>


#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int a,b,n;
	while(cin >> a >> b >> n){
		if( cin.eof()) break;
		int s=0;
		a = a * 10;
		rep(i,n){
			s += (a/b) % 10;
			a %= b;
			a *= 10;
		}
		cout << s << endl;
	}
	return 0;
	
	
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<vector>

int main(){
	int N,A,B;
	int max,min;
	
	std::cin >> N >> A >> B;
	
	max = std::min(A,B);
	min = std::max(A+B-N,0);
	
	std::cout << max << " " << min << std::endl;
	
	return 0;
}

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

for testCase in range(N):
    A = list(map(int, input().split()))
    ok = False
    for i in range(2 ** 10):
        x = []
        y = []
        for j in range(10):
            if i & (1 << j):
                x.append(A[j])
            else:
                y.append(A[j])
        if x == sorted(x) and y == sorted(y):
            ok = True
    if ok:
        print('YES')
    else:
        print('NO')

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

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

int main(){
  int a,b;
  while(cin >> a >> b){
    cout << gcd(a,b) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import numpy as np
import sys
input = sys.stdin.readline
 
N = int(input())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
C = np.array(input().split(), dtype=np.int64)

A.sort()
C.sort()

ans = 0
for i in range(N):
	b = B[i]
	A_cnt = np.searchsorted(A, b, side='left')
	C_cnt = np.searchsorted(C, b, side='right')
	ans += A_cnt * (N-C_cnt)

print(ans)

Measured memory_bytes: 33488
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 7 2019
 * 
 */

#include <bits/stdc++.h>

//#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 

    string s;
    getline(cin , s);

    puts((s<="2019/04/30"?"Heisei":"TBD"));




    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("ain","r",stdin);
    freopen("aout","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n m ->
    let ab = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun a b -> a, b)) in
    Array.sort compare ab;

    let rec loop i acc hon =
        let a, b = ab.(i) in
        let d = min b (m - hon) in
        let acc = acc + a * d in
        let hon = hon + d in
        if hon < m then loop (i + 1) acc hon
            else acc
    in
    loop 0 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 9380
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  string s;
  cin >> s;
  int ans = 1e9;
  rep(i,s.size()-2) {
    int a = s.at(i) - '0';
    int b = s.at(i+1) - '0';
    int c = s.at(i+2) - '0';
    int x = a*100 + b*10 + c;
    ans = min(ans, abs(x-753));
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define optimize() ios_base ::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n";
using namespace std;
 
 
int main()
{
  string s;
  cin>>s;
  int siz=s.size()-1;
  if(s[siz]=='s')
  {
    cout<<s<<"es"<<endl;
  }
  else
  {
  cout<<s<<"s"<<endl;
  }


return 0;
}

Measured memory_bytes: 3588
def insertion_sort(A,N):
	prin(A)
	for i in range(1,N):
		v = A[i]
		j = i-1
		while j >= 0 and A[j] > v:
			A[j+1] = A[j]
			j -= 1
		A[j+1] = v
		prin(A)
def prin(A):
	print(' '.join(list(map(str, A))))
N = int(input())
A = [int(i) for i in input().split(' ')]
insertion_sort(A,N)


Measured memory_bytes: 5604
#include <iostream>
#include <cstring>

using namespace std;


void calc(int s, bool *list, int n, int ans[]){
        if(n == 1){
                for(int i = 0; i < 10; i++){
                        if(list[i]) ans[s+i]++;
                }  
        }else{
                for(int i = 0; i < 10; i++){
                        if(list[i]){
                                list[i] = false;
                                calc(s+n*i, list, n-1, ans);
                                list[i] = true;
                        }  
                }  
        }  
}

int main(){
        int n,s;
        int ans[11][386];
        bool list[10];
        memset(ans,0,sizeof(ans));
        for(int i = 1; i <= 10; i++){
                memset(list, 1, sizeof(list));
                calc(0,list,i,ans[i]);
        }  
        while(cin >> n >> s){
                if(n > 10 || s > 385) cout << 0 << endl;
                else cout << ans[n][s] << endl;
        }  
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define PI 4*atan(1)
#define INF 1e8

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(){
  int a, b, h;
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 764
# coding: utf-8
import os
import time
import re
import math

def main():
    #s=input()
    #n=int(input())
    P,Q,R=map(int,input().split())

    print(P+Q+R-max([P,Q,R]))



start=time.time();
main()
#print(time.time()*1000-start*1000)

Measured memory_bytes: 3568
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
N = int(input())
A = list(map(int,input().split()))

S = sum(A) % MOD
T = sum([a*a for a in A]) % MOD

ans = (S*S - T) % MOD
if ans % 2 == 1:
	ans += MOD
print(ans // 2)

Measured memory_bytes: 31288
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int tmp;
if(a>b){
tmp=a;
a=b;
b=tmp;
}
if(b>c){
tmp=b;
b=c;
c=tmp;
}
if(a>b){
tmp=a;
a=b;
b=tmp;
}
System.out.println(a+" "+b+" "+c);
}
}

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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> p(N);
	rep(i, N) cin >> p[i];

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

	int sum = 0;
	rep(i, K) sum += p[i];

	cout << sum << endl;

	return 0;
}

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

int main(){
  int h,w;
  char s[106][106];

  scanf("%d %d", &h, &w);

  int i;
  for(i = 0;i < h;i++) scanf("%s", s[i]);

  for(i = 0;i < h;i++){
    printf("%s\n", s[i]);
    printf("%s\n", s[i]);
  }

  return 0;
}


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

pre_countA = 0
pre_countB = 0
if N >= 2:
    for i in range(N):
        for k in range(i + 1, N):
            if A[i] > A[k]:
                pre_countA += 1
    for i in range(N):
        for k in range(N):
            if A[i] > A[k]:
                pre_countB += 1

    result = pre_countA * K
    result += pre_countB * (((K - 1) * (1 + (K - 1))) // 2)
    print(result % (10 ** 9 + 7))
else:
    print(0)

Measured memory_bytes: 41948
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int main(){
	int a;
	string s;
	cin >> a >> s;
	if (a < 3200){
		cout << "red" << endl;
	}
	else{
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

using MIte = multimap<long, long, greater<long> >::iterator;


//1406

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

	// long long?
	long long N;
	cin >> N;

	vector<int> vP(N, 0);
	rep(i, N) cin >> vP[i];
	rep(i, N) vP[i]--;

	vector<int> vidx(N, 0);
	rep(i, N) {
		vidx[vP[i]] = i;
	}

	if (vP.size() == 1) {
		cout << "0" << endl;
		return 0;
	}

	int idx = 0;
	vector<int> vnum(N, 0);
	int vnumidx = 0;
	int num = 1;
	int maxnum = 0;
	while (1) {
		if (vidx[idx] > vidx[idx + 1]) {
			vnum[vnumidx] = num;
			maxnum = max(maxnum, num);
			num = 1;
			vnumidx++;
		}
		else {
			num++;
		}
		idx++;
		if (idx == vP.size() - 1) {
			vnum[vnumidx] = num;
			maxnum = max(maxnum, num);
			break;
		}
	}

	cout << N - maxnum << endl;

	return 0;

}

Measured memory_bytes: 2560
N = int(input())
A = [int(i) for i in input().split()]
print(" ".join(map(str, A)))
for i in range(1,N):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(" ".join(map(str, A)))


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

vector<pair<ll, ll> > pairs;

int main()
{
    ll A, B;
    cin >> A >> B;
    int base, rep;
    if (A >= B){
        base = B;
        rep = A;
    } else {
        base = A;
        rep = B;
    }
    rep(i, rep){
        cout << base;
    }
    return 0;    
}


Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){

        string[] input = ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int cost = 999999;
        for(int i=0;i<a;i++){
            string[] temp = ReadLine().Split(' ');
            int c = int.Parse(temp[0]);
            int d = int.Parse(temp[1]);
            if(d <= b){
                cost = Min(cost,c);
            }
        }
        if(cost == 999999){
            WriteLine("TLE");
        }else{
            WriteLine(cost);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>

int main()
{
 int a,b,c,d;
 std::cin>>a>>b>>c>>d;
    while(1>0){
        c=c-b;
        if(c<=0){
         std::cout << "Yes" << std::endl;
            return 0;
        }
        if(c>0){
            a=a-d;
            if(a<=0){
             std::cout << "No" << std::endl;
             return 0;
            }
        
            
        }
    }
    
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD  = 1e9 + 7;
int main(){

    int N;
    ll num[2010];
    cin >> N;

    num[0] = 0;
    num[1] = 0;
    num[2] = 0;
    num[3] = 1;
    num[4] = 1;
    num[5] = 1;
    for (int i = 6; i <= N; ++i){

        ll sum = 1;
        for (int j = 3; j <= i-3; ++j){
            sum = (sum + num[i-j]) % MOD;
        }
        num[i] = sum;
    }
    cout << num[N] << endl;
}


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

int dp[505050];

int main(){
  int N; cin>>N;
  string S; cin>>S;
  S="0"+S+"0";
  for(int i=1;i<=N;i++){
    dp[i+1]=max(dp[i+1],dp[i]);
    if(S[i-1]=='1'&&S[i]=='0'&&S[i+1]=='1'){
      int l=i-1,r=i+1;
      while(1){
        if(S[l]=='0') break;
        dp[i+1]=max(dp[i+1],dp[l-1]+(i-l));
        l--;
      }
      while(1){
        if(S[r]=='0') break;
        dp[r]=max(dp[r],dp[i-2]+(r-i));
        r++;
      }
    }
  }
  cout<<dp[N+1]<<endl;
  return 0;
}


Measured memory_bytes: 2840
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long DP[1 << 21];
bool A[21*21];
int BitData[1 << 21];
void Calc(){
	int N = rei();
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			A[i*21+j] = rei() == 1; 
		}
	}
	for(int i=0;i<1<<N;i++){
		int c = 0;
		for(int j=0;j<N;j++){
			if(i & (1<<j)){
				c++;
			}
		}
		BitData[i] = c;
	}
	DP[0] = 1;
	for(int i=0;i<1<<N;i++){
		DP[i] %= mod;
		for(int j=0;j<N;j++){
			if((i & (1 << j)) == 0 && A[BitData[i]*21+j]){
				DP[i + (1 << j)] += DP[i];
			}
		}
	}
	cout << DP[(1<<N)-1] << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 24832
s = input()
n = len(s)
if (s[:(n - 1) // 2] == s[(n - 1)//2 -1::-1]) & (s[(n - 1) // 2 + 1:] ==  s[:(n - 1)//2:-1]) & (s == s[::-1]):
    print('Yes')
else:
    print('No')

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

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

    long a, b, r;
    a = max(A, B);
    b = min(A, B);
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    long lcm = A * B / b;
    cout << lcm << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


 
int main(void){
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        cout<<'x';
    }
    cout<<endl;
	return 0; 
}

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


int main(){
int A[3][3];
int N,m=0;
cin >> A[0][0] >> A[0][1] >> A[0][2];
cin >> A[1][0] >> A[1][1] >> A[1][2];
cin >> A[2][0] >> A[2][1] >> A[2][2];
cin >> N;
int b[N];
for (int k=0;k<N;k++){
  cin >> b[k];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
  if(A[i][j]==b[k]){
    A[i][j]=0;
  }
}  
}
}
for (int k=0;k<3;k++){
  if(A[k][0]==0 && A[k][1]==0 && A[k][2]==0){
    m++;
  }
  if(A[0][k]==0 && A[1][k]==0 && A[2][k]==0){
    m++;
  }
  
}
if(A[0][0]==0 && A[1][1]==0 && A[2][2]==0){
    m++;
  }
  if(A[2][0]==0 && A[1][1]==0 && A[0][2]==0){
    m++;
  }
  if(m==0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256