akhauriyash/Code-Regression huggingface dataset:
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n, k; cin >> n >> k;
	println(min(n%k, k-(n%k)));
}


Measured memory_bytes: 256
import collections
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
a = collections.Counter(A)
tmp = sum(A)

for i in range(Q):
  B,C = map(int,input().split())
  tmp += (a[B]*C -a[B]*B)
  if C in a:
    a[C] += a[B]
  else:
    a[C]=a[B]
  del a[B]
  print(tmp)
  

Measured memory_bytes: 24272
#include<iostream>

using namespace std;

int main(){
    long long N;
    int sum = 0;
    cin >> N;
    long long tmp = N;
    while(tmp>0){
        sum += tmp%10;
        tmp = tmp/10;
    }
    if(N%sum == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main()
{
    int m, f, r;
 
    do{
        cin >> m >> f >> r;
        if((m < 0) && (f < 0) && (r < 0)) break;

        if((m < 0) || (f < 0)){
            cout << "F" << endl;
        }else if(m + f >= 80){
            cout << "A" << endl;
        }else if(m + f >= 65){
            cout << "B" << endl;
        }else if(m + f >= 50){
            cout << "C" << endl;
        }else if(m + f >= 30){
            if(r >= 50){
                cout << "C" << endl;
            }else{
                cout << "D" << endl;
			}
        }else{
            cout << "F" << endl;
	    }
 
    }while(1);
 
    return 0;
}

Measured memory_bytes: 1152
N = int(input())
count2 = 0
if N < 105:
    print('0')
    exit()
for j in range(105, N+1):
    count = 0
    for i in range(1, j+1, 2):
        if j % i == 0:
            count += 1
    if count == 8:
        count2 += 1
print(count2)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int N,i;
	cin >> N >> i;
	cout << N - i + 1 << endl;
	return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    int cnt = 0;
    for(int i=a; i<=b; i++){
        string str = to_string(i);
        reverse(str.begin(), str.end());
        int s = stoi(str);
        if(i == s) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main(void){
 int a,b,c;
 cin>>a>>b>>c;
 if(a==b){
     cout<<c<<endl;
 }else if(a==c){
     cout<<b<<endl;
 }else if(b==c){
     cout<<a<<endl;
 }
 return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
 
 
 
class Solve
{
    public Solve() { }
    public static int Main()
    {
        new Solve().calc();
        return 0;
    }
 
 
    Scanner cin;
 
    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int K = cin.nextInt();
        var mod = new Modulo(3000);
 
        for(int i=1; i<=K; i++)
        {
            var a = mod.Ncr(N - K + 1, i);
            var b = mod.Ncr(K - 1, i - 1);
            Console.WriteLine(mod.Mul(a, b).ToString());
        }
    }
}
class Modulo
{
    private const int M = 1000000007;
    private readonly int[] m_facs;
    public int Mul(int a, int b)
    {
        return (int)(Math.BigMul(a, b) % M);
    }
    public Modulo(int n)
    {
        m_facs = new int[n + 1];
        m_facs[0] = 1;
        for (int i = 1; i <= n; ++i)
        {
            m_facs[i] = Mul(m_facs[i - 1], i);
        }
    }
    public int Fac(int n)
    {
        return m_facs[n];
    }
    public int Pow(int a, int m)
    {
        switch (m)
        {
        case 0:
            return 1;
        case 1:
            return a;
        default:
            int p1 = Pow(a, m / 2);
            int p2 = Mul(p1, p1);
            return ((m % 2) == 0) ? p2 : Mul(p2, a);
        }
    }
    public int Div(int a, int b)
    {
        return Mul(a, Pow(b, M - 2));
    }
    public int Ncr(int n, int r)
    {
        if (n < r) { return 0; }
        if (n == r) { return 1; }
        int res = Fac(n);
        res = Div(res, Fac(r));
        res = Div(res, Fac(n - r));
        return res;
    }
}
 
class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13248
import std.stdio;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
  int[] m;
  while((m=map!(to!int)(readln.strip.split).array)!=[0,0]) {
    int n=m[0],x=m[1],sum = 0;

    foreach(i;1..n)
      foreach(j;i+1..x-i)
      {
          int k = x-i-j;
          if(j<k && k<=n) sum ++;
      }
    writeln(sum);
  }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    ++mp[s];
  }
  vector<pair<int, string>> a;
  for (auto p : mp) a.emplace_back(p.second, p.first);
  sort(a.rbegin(), a.rend());
  int cnt = a[0].first;
  vector<string> b;
  for (int i = 0; i < (int)a.size(); ++i) {
    if (a[i].first == cnt) b.push_back(a[i].second);
  }
  reverse(b.begin(), b.end());
  for (string s : b) cout << s << '\n';
  return 0;
}


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

using namespace std;

#define reps(i,f,n)  for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

class E{
public:
  int split;
  int power;
  E(){}
  E(int split,int power):split(split),power(power){}
  bool operator<(const E& a)const{
    if(split==a.split)return power<a.power;
    return split<a.split;
  }
  E operator+(const E& a)const{
    return E(split+a.split, min(power, a.power));
  }
};


const int H = 33;
const int INF = 1000000000;
int h,w,s;
int allpower;
int board[H][H];
int sum[H][H];

E memo[H][H][H][H];

void init(){
  rep(i,H)rep(j,H)sum[i][j]=0;
  rep(i,H)rep(j,H)rep(k,H)rep(p,H)memo[i][j][k][p] = E(-1,-1);
}

bool input(){
  cin>>h>>w>>s;
  if(h==0)return false;

  rep(i,h){
    rep(j,w){
      cin>>board[i][j];
    }
  }

  return true;
}

void mksum(){
  rep(i,H)rep(j,H)sum[i][j] = 0;
  reps(i,1,h+1){
    reps(j,1,w+1){
      sum[i][j] = sum[i-1][j] + sum[i][j-1] -sum[i-1][j-1] + board[i-1][j-1];
    }
  }

  allpower = 0;
  rep(i,h)rep(j,w)allpower += board[i][j];
}

int getsum(int y1,int x1,  int y2,int x2){
  return sum[y2][x2] - sum[y1][x2] - sum[y2][x1] + sum[y1][x1];
}

E solve_dp(int y1,int x1,int y2,int x2){
  if(memo[y1][x1][y2][x2].split!=-1)return memo[y1][x1][y2][x2];

  int power = getsum(y1,x1,y2,x2);
  if(allpower-power>s)return E(-INF,-INF);

  E ret(1, s-(allpower-power));
  reps(i,y1+1,y2){
    ret = max(ret, solve_dp(y1,x1,i,x2)+solve_dp(i,x1,y2,x2));
  }
  reps(i,x1+1,x2){
    ret = max(ret, solve_dp(y1,x1,y2,i)+solve_dp(y1,i,y2,x2));
  }
  return memo[y1][x1][y2][x2]=ret;
}

pair<int,int> solve(){
  pair<int,int> ret;
  mksum();
  E res = solve_dp(0,0,h,w);
  ret.first = res.split;
  ret.second = res.power;
  return ret;
}

int main(){
  while(init(),input()){
    pair<int,int> ret = solve();
    printf("%d %d\n",ret.first, ret.second);
  }
}

Measured memory_bytes: 10424
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// #pragma GCC optimize("O2")
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef multiset <ll> mms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define deb(x) cout << #x << " " << x << endl;
#define ff first
#define ss second
#define pb(v) push_back(v)
#define lb(v) lower_bound(v)
#define ub(v) upper_bound(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b) {
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s) {
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v) {
	forl(i,v.size()) cout<<v[i]<<" ";
	cout<<"\n";
}
void pa(ll *v, ll size) {
	forl(i,size) cout<<v[i]<<" ";
	cout<<"\n";
}
void removeDups(mv &v) {
	sort(all(v));
	mv::iterator it = unique(v.begin(), v.end());
	v.resize(distance(v.begin(), it));
}
inline ld kthRoot(ld n, ll k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}
ll power(ll x, ll y, ll p) {
	ll res=1;
	x=x%p;
	while(y>0) {
		if(y&1) res = (res*x)%p;
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x, ll mod) {
	if(x>=mod) x%=mod;
}

ll mod = 1e9 + 7;

void thisIsMain() {
	ll x, k, d;
	cin>>x>>k>>d;
	x = abs(x);
	ll n = x / d;
	n = min(n, k);
	k -= n;
	x -= n * d;
	if(k % 2 == 0) cout<<x<<"\n"; else cout<<abs(x - d)<<"\n";
}

int main(void)
{
	fastio
	ll t = 1;
	// cin>>t;
	while(t--) thisIsMain();
	return 0;
}

Measured memory_bytes: 3656
from sys import stdin
n,k = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [-1]*n
b[0] = 0
tf = True
t = 1
g = 0
m = 0
while k > 0:
    k -= 1
    if b[a[g]-1] == -1:
        b[a[g]-1] = t
    else:
        m = b[a[g]-1]
        g = a[g]-1
        break
    t += 1
    g = a[g]-1
mo = t-m
k = k % mo
while k > 0:
    g = a[g]-1
    k -= 1
print(g+1)

Measured memory_bytes: 92208
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  string s;
  cin >> s;

  int ans = 0;
  rep(i, s.size()) {
    if (s[i] == 'o') ans++;
  }

  ans += 15 - (int)s.size();
  if (8 <= ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
const int INF=1e9;
int main(){
      int n,m,a[1000],cnt[1000],b;
      memset(cnt,0,sizeof(cnt));
      scanf("%d%d",&n,&m);
      REP(i,n)cin>>a[i];
      REP(i,m){
            cin>>b;
            REP(i,n){
                  if(a[i]<=b){
                        cnt[i]++;break;
                  }
            }
      }
      int ans=-1,num;
      REP(i,n){
            if(ans<cnt[i]){
                  ans=cnt[i];
                  num=i;
            }
      }
      cout<<num+1<<endl;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=200005,K=40;
ll n,k,nx[M];
vl a,c,lg[K];
vvl g;

int main(){
	cin>>n>>k;
	a=c=vl(n);
	for(auto &i:a) cin>>i;
	vl b(n+1);
	g=vvl(n+1);
	b[n]=n;
	fill(nx,nx+M,-1);
	for(int i=n-1;i>=0;i--){
		if(nx[a[i]]>=0){
			g[nx[a[i]]+1].push_back(i);
			c[i]++;
		}
		nx[a[i]]=i;
	}
	lg[0]=vl(n+1);
	for(int i=0;i<n;i++) if(!c[i]){
		queue<int> q;
		q.push(i);
		lg[0][i]=nx[a[i]]+1;
		while(!q.empty()){
			int v=q.front();q.pop();
			for(auto u:g[v]){
				lg[0][u]=lg[0][i];
				q.push(u);
			}
		}
	}
	for(int i=1;i<K;i++){
		lg[i]=vl(n+1);
		for(int j=0;j<=n;j++) lg[i][j]=lg[i-1][lg[i-1][j]];
	}
	int v=0;
	k--;
	for(int i=0;i<K;i++) if(k&1ll<<i) v=lg[i][v];
	vl res;
	fill(nx,nx+M,0);
	for(int i=v;i<n;i++){
		if(nx[a[i]]){
			while(res.back()!=a[i]){
				nx[res.back()]--;
				res.pop_back();
			}
			res.pop_back();
			nx[a[i]]--;
		}
		else{
			res.push_back(a[i]);
			nx[a[i]]++;
		}
	}
	int S=res.size();
	for(int i=0;i<S;i++) cout<<res[i]<<" \n"[i==S-1];
}

Measured memory_bytes: 80000
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,j,sum=0;
	cin>>n;
	j=n;
	while(j!=0)
    {
    	sum+=j%10;
    	j/=10;
    }
    if(n%sum==0)
       cout<<"Yes";
    else
       cout<<"No";
    return 0;
}

Measured memory_bytes: 256
# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# library
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
A = list(map(int,input().split()))

cnt = 0
for i in range(N):
    if A[i] < 0:
        cnt += 1
        A[i] *= -1

A.sort()

if cnt%2==0:
    print(sum(A))
else:
    print(sum(A)- A[0]*2)

Measured memory_bytes: 14284
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	char N;
	cin >> N;
	if (N >= 'a') {
		cout << 'a' << endl;
	}
	else {
		cout << 'A' << endl;
	}

	

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 998244353

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

template <class X>
class SegmentTree {
    int n;
    vector<X> dat;
    X identity;

    X query_sub(int a, int b, int i, int l, int r) {
        if (r <= a || b <= l) return identity;
        if (a <= l && r <= b)
            return dat[i];
        else {
            X vl = query_sub(a, b, i * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, i * 2 + 2, (l + r) / 2, r);
            return op(vl, vr);
        }
    }

    X get_identity(){
        return std::numeric_limits<X>::min(); // Range Maximum Query
    }
    X op(X x, X y){
        return max(x, y); // Range Maximum Query;
    }
public:
    SegmentTree(int n_) {
        n = 1;
        while (n < n_) n *= 2;

        identity = get_identity();
        dat = vector<X>(2 * n - 1, identity);

    }
    void update(int i, X x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    // [a, b)
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    X at(int i) { return dat[i + n - 1]; }
};

int main(){
    long long N;
    cin >> N;
    vector<pair<long long, long long>> XD(N);
    REP(i, N) cin >> XD[i].first >> XD[i].second;
    XD.push_back(make_pair(1LL<<60, 0));
    sort(XD.begin(), XD.end());

    SegmentTree<long long> st(N);
    for(int i=0; i<N; i++) st.update(i, i);
    for(int i=N-1; i>=0; i--){
        long long l = i;
        long long r = lower_bound(XD.begin(), XD.end(), make_pair(XD[i].first+XD[i].second, 0LL)) - XD.begin();
        st.update(i, st.query(l, r));
    }
    vector<int> R(N);
    REP(i, N)
        R[i] = st.at(i);

    vector<long long> dp(N+1);
    dp[N] = 1;
    dp[N-1] = 2;
    for(int i=N-2; i>=0; i--){
        dp[i] = (dp[i+1] + dp[R[i]+1]) % MOD;
    }
    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 11592
using System;
using System.Collections.Generic;
using System.Linq;

public static partial class Program
{
    public static long n;
    public static bool[,] graph = new bool[8, 8];
    public static void Main()
    {
        var nm = CRL().ArrayLongs();
        n = nm[0];
        for (int i = 0; i < nm[1]; i++)
        {
            var ab = CRL().ArrayLongs().Select(x => x - 1).ToArray();
            graph[ab[0], ab[1]] = true;
            graph[ab[1], ab[0]] = true;
        }

        var passed = new bool[n, n];
        var visited = new bool[n];
        visited[0] = true;
        CWL(DFS(0, passed, visited));
    }

    public static int DFS(int vert, bool[,] passed, bool[] visited)
    {
        if (visited.All(x => x))
        {
            return 1;
        }

        var ret = 0;
        for (int next = 0; next < n; next++)
        {
            //道が無かったら
            if (graph[vert, next] == false)
            {
                continue;
            }

            //既に通った道だったら
            if (passed[vert, next])
            {
                continue;
            }

            //既に訪れていたら
            if (visited[next])
            {
                continue;
            }

            visited[next] = true;      //頂点
            passed[vert, next] = true; //道(進むとき)
            passed[next, vert] = true; //道(戻るとき)
            ret += DFS(next, passed, visited);
            visited[next] = false;
            passed[vert, next] = false;
            passed[next, vert] = false;
        }

        return ret;
    }
}

public static partial class Program
{
    //テンプレここから
    private static long ToInt(this string str) => long.Parse(str);
    private static long[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static long[] dx = new long[] { 0, -1, 0, 1 };
    public static long[] dy = new long[] { -1, 0, 1, 0 };
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    //テンプレここまで
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;

int main() {
	cin >> s;
	
	int ans = 0;
	inc(i, 2) { if(s[i] == '9') { ans = 1; } }
	
	cout << (ans == 1 ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	//System.out.println();はつかわない！！
	void solve() throws Exception{
		int N = in.nextInt(), L = in.nextInt();
		int ans = 0, min = Integer.MAX_VALUE;
		int sum = 0;
		for(int i = 1; i <= N; i++) sum += L + i - 1;
		for(int i = 1; i <= N; i++){
			if(min > Math.abs(L + i - 1)){
				min = Math.abs(L + i - 1);
				ans = sum - (L + i - 1);
			}
		}
		out.println(ans);
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
}
/* end Main */

class FastScanner {
	Reader input;

	FastScanner() {this(System.in);}
	FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
	
	int nextInt() {return (int) nextLong();}

	long nextLong() {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	}

	double nextDouble() {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	}

	char nextChar() {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	}

	String nextStr() {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}

Measured memory_bytes: 25172
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class CAverageLength {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vector<pair<double,double>> p(n);
        rep(i,n){
            in >> p[i].first >> p[i].second;
        }
        vector<int> v(n);
        rep(i,n){
            v[i]=i;
        }
        double ans=0.;
        out << setprecision(12);
        ll w=1L;
        for(int i=1;i<=n;i++){
            w*=i;
        }
        do{
            double su=0.;
            rep(i,n-1){
                su+=sqrt(pow(p[v[i+1]].first-p[v[i]].first,2)+pow(p[v[i+1]].second-p[v[i]].second,2));
            }
            ans+=su;
        }while(next_permutation(v.begin(),v.end()));
	    out << ans/(double)w << endl;
	}
};


int main() {
	CAverageLength solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
	int n,m;
	while(cin>>n,n){
		cin>>m;
		vector<string> hits(n);
		vector<int> moneys(n);
		for(int i=0;i<n;++i) cin>>hits[i]>>moneys[i];
		int reward=0;
		for(int i=0;i<m;++i){
			string mynum;
			cin>>mynum;
			for(int j=0;j<hits.size();++j){
				bool f=false;
				for(int k=0;k<8;++k){
					if(hits[j][k]=='*') continue;
					if(hits[j][k]!=mynum[k]) f=true;
				}
				if(!f) reward+=moneys[j];
			}
		}
		cout<<reward<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
import sys
import numpy as np
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = np.array(readline().split(), np.int64)
    B = np.array(readline().split(), np.int64)
    C = A-B
    pos = C[C>0]
    neg = C[C<0]
    Lpos = len(pos)
    Lneg = len(neg)
    pos = np.sort(pos)[::-1]
    total = np.sum(neg)
    if Lneg == 0:
        print(0)
        sys.exit()
    for i in range(Lpos):
        total += pos[i]
        if total>=0:
            print(Lneg+i+1)
            break
        else:
            continue
    else:
        print(-1)




if __name__ == '__main__':
    main()


Measured memory_bytes: 19420
#include<iostream>
#define ll long long
using namespace std;
int main() {
	ll n, m, sum = 0, suma = 0, a, b;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		suma += a;
	}
	for (int j = 0; j < m; ++j) {
		cin >> b;
		sum += suma * b;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3096
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;



int cnta[1000001] = {0};
int cntb[1000001] = {0};

signed main(){
    
    int n;
    cin >> n;
    int a[100010];
    int b[100010];
    int sa[100010];
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) sa[i] = a[i]-b[i];
    sort(sa,sa+n);
    int all = 0;
    int ans = 0;
    rep(i,n){
        all += sa[i];
    }
    if(all < 0){
        cout << -1 << endl;
        return 0;
    }
    all = 0;
    rep(i,n){
        if(sa[i] < 0){
            all -= sa[i];
            ans++;
        }
    }
    if(all == 0){
        cout << 0 << endl;
        return 0;
    }
    for(int i = n-1;i >= 0;i--){
        ans++;
        all -= sa[i];
        if(all <= 0){
            cout << ans << endl;
            return 0;
        }
    }


    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 
// rm -r -f test;oj dl http://arc074.contest.atcoder.jp/tasks/arc074_b

Measured memory_bytes: 2560
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#include <string>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

struct data_t
{
    int b;
    int c;

    // 最後のconstを忘れると"instantiated from here"というエラーが出てコンパイルできないので注意
    bool operator<(const data_t &right) const
    {
        return c > right.c;
    }
};

int main()
{
    int N, M;
    cin >> N >> M;
    ll A[N];
    REP(i, N)
    {
        int a;
        cin >> a;
        A[i] = a;
    }
    int B[M];
    ll C[M];
    data_t BC[M];
    REP(i, M)
    {
        int b, c;
        cin >> b >> c;
        BC[i].b = b;
        BC[i].c = c;
    }

    sort(A, A + N);
    sort(BC, BC + M);

    int index = 0;
    int cnt = 0;
    REP(i, N)
    {
        if (A[i] < BC[index].c)
            A[i] = BC[index].c;
        else
            break;

        cnt++;
        if (BC[index].b == cnt)
        {
            index++;
            cnt = 0;
        }
    }

    ll ret = 0;
    REP(i, N)
    {
        ret += A[i];
    }

    cout << ret << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define ld          long double


void solve()  
{
	ll n, m; cin>>n>>m;
	ll c[m];
	ll mask[m];
	for(ll i=0; i<m; i++)
	{
		cin>>c[i];
		ll x=0;
		ll b; cin>>b;
		while(b--)
		{
			ll y; cin>>y;
			x^=(1<<(y-1));
		}
		mask[i]=x;
	}
	ll lim=(1<<n);
	ll dp[lim];
	for(ll i=0; i<lim; i++) dp[i]=1e18;
	dp[0]=0;
	for(ll i=0; i<m; i++) dp[mask[i]]=c[i];
	for(ll msk=0; msk<lim; msk++)
	{
		if(dp[msk]==1e18) continue;
		for(ll i=0; i<m; i++)
		{
			ll nmsk=(msk|mask[i]);
			ll nc=dp[msk]+c[i];
			dp[nmsk]=min(dp[nmsk], nc);
		}
	}
	if(dp[lim-1]==1e18)
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<dp[lim-1]<<endl;
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
	ll T = 1;
	//cin>>T; 
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 256
from math import gcd
n=int(input())
a=list(map(int,input().split()))

l=[0]*n
r=[0]*n

for i in range(n-1):
  l[i+1]=gcd(l[i],a[i])
for i in range(n-1,0,-1):
  r[i-1]=gcd(r[i],a[i])
ans=0
for i in range(n):
  ans=max(ans,gcd(l[i],r[i]))
print(ans)

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

#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

const int N = 2e5 + 77;
int A[N];

int32_t main()
{
    fast;  
    int n ; cin >> n;
    for(int i = 0 ; i < n ; ++i) {
        cout << "ACL" ;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3608
#pragma GCC optimize("03")
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vec;
typedef vector<vector<ll> > matrix;
ll const mod=1e9+7;
ll dp[100100],n,ar[100100];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll k,l,r;
	cin>>n>>k;
	for(ll i=1;i<=n;i++)
	{
		cin>>ar[i];
	}
	dp[0]=1;
	for(ll i=1;i<=n;i++)
	{
		vector<ll> br(k+100,0);
		for(ll j=k-1;j>=0;j--)
		{
			l=j+1;
			r=min(k,j+ar[i]);
			if(l <= r)
			{
				br[l]=(br[l]+dp[j]+mod)%mod;
				br[r+1]=(br[r+1]-dp[j])%mod;
				if(br[r+1] < 0)
					br[r+1]+=mod;
			}
		}
		ll pref=0;
		for(ll j=0;j<=k;j++)
		{
			pref=(pref+br[j]+mod)%mod;
			dp[j]=(dp[j]+pref+mod)%mod;
		}
	}
	cout<<dp[k]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;
const long long mod = 1e9 + 7;
long long pow(long long a, long long b) {
  if (b == 0) {
	  return 1;
	}
  if (b % 2 == 1) {
	  return (a * pow(a, b - 1)) % mod;
	}
  long long n = pow(a, b / 2);
  return (n * n) % mod;
}

long long inv(long long a) {
  return pow(a, mod - 2);
}

int main() {
  long long N, M;
  cin >> N >> M;
  vector <long long> p;
  if (M % 2 == 0) {
	  long long c = 0;
	  while (M % 2 == 0) {
		  M /= 2;
		  c++;
		}
	  p.push_back(c);
	}
  for (long long i = 3; i <= sqrt(M); i++) {
	  if (M % i == 0) {
		  long long c = 0;
		  while (M % i == 0) {
			  M /= i;
			  c++;
			}
		  p.push_back(c);
		}
	}
  if (M > 1) {
	  p.push_back(1);
	}
  long long ans          = 1;
  long long fact[200000] = { 1 };
  for (long long i = 1; i <= 200000; i++) {
	  fact[i] = fact[i - 1] * i % mod;
	}
  for (auto itr = p.begin(); itr != p.end(); itr++) {
	  long long a = fact[*itr + N - 1];
	  a   = a * inv(fact[*itr]) % mod;
	  a   = a * inv(fact[N - 1]) % mod;
	  ans = a * ans % mod;
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
def solve(): 

    N = int(input())
    A = list(map(int, input().split()))

    i = 0
    result = 0

    while i < N:
        while i+1 < N and A[i] == A[i+1]:
            i += 1
        if i+1 < N and A[i] < A[i+1]:
            while i+1 < N and A[i] <= A[i+1]:
                i += 1
        elif i+1 < N and A[i] > A[i+1]:
            while i+1 < N and A[i] >= A[i+1]:
                i += 1
        
        result += 1
        i += 1

    print(result)    

if __name__ == "__main__":
    solve()


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

int main()
{

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  string a,b;cin>>a>>b;
  string temp=a+b;
  int ans=stoi(temp);
  for(int t=1;t<=10000;t++){
    if(ans==t*t){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


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

int main(){
    int n;
    double tmp=0;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >>v.at(i);
    sort(v.begin(),v.end());
    tmp=v[0];
    rep(i,n-1){
        tmp=(tmp+v[i+1])/2;
    }
    cout << tmp << endl;
}

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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	for(int i=1; i<=50000; i++) {
		if((int)(i*1.08) == n)
			return !(cout << i);
	}
	cout << ":(";
}

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
 
h = Hash.new(0)
a.each{ |i| h[i] += 1 }
h = h.sort_by {|k, v| v }
 
ans = 0
if K < h.size
  n = h.size - K
  n.times{ |j| ans += h[j][1] }
end
 
puts ans

Measured memory_bytes: 41672
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int get(int n){
    if(n%2==0)return n/2;
    else return 3*n+1;
}
int main(){
    int n,d,x;
    cin>>n>>d>>x;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    int ans=n;
    for(int i=0;i<n;i++){
        ans=ans+(d-1)/arr[i];
    }
    cout<<ans+x;
}



Measured memory_bytes: 3612
macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}

fn main() {
    let n = get_one!(usize);
    // let (q, r) = (n / 15, n % 15);

    let ans: usize = (1..=n).filter(|&x| x % 3 != 0 && x % 5 != 0).sum();

    println!("{}", ans);
}


Measured memory_bytes: 2116
s=input()
a=[0]*(len(s)+1)
r=0
l=0
for i in range(len(a)):
  j=i
  if r==0:
    while j < len(s) and s[j] == '>':
      r+=1
      j+=1
  else:
    r-=1
  if i !=0 and s[i-1] == '<':
    l+=1
  else:
    l=0
  a[i]=max(l,r)
print(sum(a))

Measured memory_bytes: 23336
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;

int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    for (auto &Pi : P)
    {
        cin >> Pi;
        --Pi;
    }
    // 各数字がPの何番目に入っているか調べる
    vector<int> Q(N);
    for (int i = 0; i < N; ++i)
    {
        Q[P[i]] = i;
    }
    // 数字iとi+1について，（iの場所）＜（i+1の場所）ならば
    // これらについては動かす必要がない（間の数を前後に移せばよい）
    // 動かす必要がない連番のうち，最大長のもの l,l+1,...,r-1,rを探す
    // しゃくとり法で探す：O(N)
    int maxLen = 1; // 1で初期化しておくとN=1でループに入らないときも問題ない
    for (int l = 0; l < N - 1;)
    {
        int r = l;
        for (; r < N - 1; ++r)
        {
            if (Q[r] > Q[r + 1]) break;
        }
        maxLen = max(maxLen, r - l + 1);
        l = r + 1;
    }
    // 0,...,l-1 および r+1,...,N-1 をそれぞれ前後に動かせばよい
    cout << N - maxLen << endl;
}


Measured memory_bytes: 1792
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main  {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int count = 0;
		TreeMap<Integer, Integer> map = new TreeMap<>();

		for(int i = 0; i < n; i++) {
			int query = scan.nextInt();
			int a = scan.nextInt();

			switch(query) {

			case 0:	//insert
				if(!map.containsKey(a)) map.put(a, 1);
				else map.put(a, map.get(a) + 1);
				count++;
				System.out.println(count);
				break;

			case 1:	//find
				if(map.get(a) != null) System.out.println(map.get(a));
				else System.out.println(0);
				break;

			case 2:	//delete
				if(map.get(a) != null) {
					count -= map.get(a);
					map.remove(a);
				}
				break;

			case 3:	//dump
				int b = scan.nextInt();
				Map<Integer, Integer> subM = map.subMap(a,true, b,true);
				for(Integer x : subM.keySet()) {
					for(int j=0; j<map.get(x); j++) {
						System.out.println(x);
					}
				}
				break;
			}
		}
	}
}


Measured memory_bytes: 166252
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    d = [[0 if i == j else float("inf") for j in range(n)] for i in range(n)]
    for _ in range(m):
        a,b,c = LI()
        d[a][b] = c
    for k in range(n):
        for i in range(n):
            for j in range(n):
                nd = d[i][k]+d[k][j]
                if nd < d[i][j]:
                    d[i][j] = nd
    for i in range(n):
        if d[i][i] < 0:
            print("NEGATIVE CYCLE")
            return
        for j in range(n):
            if d[i][j] == float("inf"):
                d[i][j] = "INF"
    for i in d:
        print(*i,sep = " ")
    return

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



Measured memory_bytes: 6992
#!/usr/bin/env python3
import sys
from itertools import *


def solve(S: str, K: int):
    onelen = len(list(takewhile(lambda x:x=="1",S)))
    res = "1" if onelen >= K else S[onelen]
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: int
    K = int(next(tokens))  # type: int
    solve(S, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// 理屈はしらんけどサンプル眺めてたら差1で最長増加部分列ぶん以外並び替える感じになりました
// （後出しだけど途中に挿入できないからでしょう。）
// 探索が分からんけどインデックスを保持するmapで探索していけないだろうか
// （計算量はいつもながら不明です）
// ようわからんけどLCS忘れたからしゃくとりっぽいのでやった

package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	P := make([]int, N)
	T := make(map[int]int)
	for i := 0; i < N; i++ {
		var V int
		fmt.Scan(&V)
		P[i] = V
		T[V] = i + 1
	}
	lnh := 0
	r := 0
	for l := 1; l <= N; {
		tmp := T[l]
		for r = l + 1; r <= N && tmp < T[r]; {
			tmp = T[r]
			r++
		}
		lnh = max(lnh, r-l)
		l = r
	}
	fmt.Println(N - lnh)
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 15380
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		Pair p[] = new Pair[n];

		for (int i = 0; i < n; i++) {
			str = br.readLine().split(" ");

			p[i] = new Pair(Integer.parseInt(str[0]), Integer.parseInt(str[1]));
		}

		Arrays.sort(p);

		long ans = 0;

		for (int i = 0; i < n; i++) {
			int diff = m - p[i].b;
			if (diff >= 0) {
				m -= p[i].b;
				ans += (long) p[i].a * p[i].b;
			} else {
				ans += (long) m * p[i].a;
				break;
			}
		}

		System.out.println(ans);
	}
}

class Pair implements Comparable<Pair> {
	int a;
	int b;

	public Pair(int a, int b) {
		this.a = a;
		this.b = b;
	}

	@Override
	public int compareTo(Pair p) {
		return this.a - p.a;
	}
}

Measured memory_bytes: 59304
#include<stdio.h>

int main(void){
  int a,b,c,d;
  int p,q,r,s;
  int x,y;
  
  scanf("%d %d %d %d",&a,&b,&c,&d);
  x = c-a;
  y = d-b;
  p = c-y;
  q = d+x;
  r = p-x;
  s = q-y;
  
  printf("%d %d %d %d\n",p,q,r,s);
  
  return 0;
}

Measured memory_bytes: 128