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

#define ll long long int
#define pb push_back
#define pob pop_back
#define vl vector<ll>
#define mp make_pair
#define sz size()
#define fast ios::sync_with_stdio(0)
#define maxx 100005
#define edge pair<ll,ll>
using namespace std;
 
 
// ¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++¦¦¦++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦¦¦¦¦¦¦¦¦+++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦+++++++¦++¦¦
// ¦¦¦¦¦¦¦¦++¦¦¦¦¦¦++++++¦¦¦¦+++++++++++++¦
// ¦¦¦¦¦¦¦++++++¦¦¦++++++¦¦++++++++++++++¦¦
// ¦¦¦¦¦¦¦+++++++¦¦¦+++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++¦¦¦¦¦¦¦¦+++++++¦ 
// ¦¦¦¦¦¦¦¦¦¦++¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦++++¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦ 
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦+¦++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++¦¦+++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦¦+++¦¦¦¦++++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++¦¦+¦¦¦¦¦+++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦+++++++++++¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦¦¦¦
 
int main()
{
	ll n,t,a,b;
	string s;
	cin>>s;
	
		if(s[2]==s[3] && s[4]==s[5])
		cout<<"Yes"<<endl;
		else
		{
			cout<<"No"<<endl;
		}
	
	return 0;
	
}

Measured memory_bytes: 256
def main():
    n,k,c=map(int,input().split())
    S=list(input().strip())
    if n==1:
        Ans=[1]
    else:
        A=[]
        for i,s in enumerate(S):
            if s=='o':
                A.append(i+1)
        l=len(A)
        L=[0]*k
        L[0]=A[0]
        prev=A[0]
        cnt=1
        for a in A[1:]:
            if cnt==k:
                break
            if a-prev>c:
                prev=a
                L[cnt]=a
                cnt+=1
        R=[0]*k
        R[-1]=A[-1]
        prev=A[-1]
        cnt=1
        for a in reversed(A[:-1]):
            if cnt==k:
                break
            if prev-a>c:
                prev=a
                R[k-cnt-1]=a
                cnt+=1
        Ans=[]
        #print(L,R)
        for i in range(k):
            if L[i]==R[i]:
                Ans.append(L[i])
    print(*Ans,sep='\n')
    
if __name__=='__main__':
    main()

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

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

    int N;
    cin >> N;

    vector<int> A(N + 2);
    vector<int> X(N + 1);

    for(int i = 1; i <= N; i++) cin >> A[i];

    int sum = 0;

    for(int i = 0; i <= N; i++) {
        X[i] = abs(A[i + 1] - A[i]);
        sum += X[i];
    }

    for(int i = 0; i < N; i++) {
        cout << sum - X[i] - X[i + 1] + abs(A[i] - A[i + 2]) << endl;
    }
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int H,W;
    cin >> H >> W;

    vector<string> s(H);
    rep(i,H) cin >> s[i];

    int white_num = 0;
    rep(i,H)
    {
        rep(j,W)
        {
            if( s[i][j] == '.' ) white_num++;
        }
    }

    vector<vector<int> > dist(H, vector<int>(W, -1));
    queue<pair<int, int> > que;
    dist[0][0] = 0;
    que.push(make_pair(0,0));

    while( !que.empty() )
    {
        pair<int, int> point = que.front();
        que.pop();

        //上
        if( point.first > 0 && s[point.first-1][point.second] == '.' && dist[point.first-1][point.second] == -1 )
        {
            dist[point.first-1][point.second] = dist[point.first][point.second]+1;
            que.push(make_pair(point.first-1, point.second));
        }
        //下
        if( point.first+1 < H && s[point.first+1][point.second] == '.' && dist[point.first+1][point.second] == -1 )
        {
            dist[point.first+1][point.second] = dist[point.first][point.second]+1;
            que.push(make_pair(point.first+1, point.second));
        }
        //右
        if( point.second+1 < W && s[point.first][point.second+1] == '.' && dist[point.first][point.second+1] == -1 )
        {
            dist[point.first][point.second+1] = dist[point.first][point.second]+1;
            que.push(make_pair(point.first, point.second+1));
        }
        //左
        if( point.second > 0 && s[point.first][point.second-1] == '.' && dist[point.first][point.second-1] == -1 )
        {
            dist[point.first][point.second-1] = dist[point.first][point.second]+1;
            que.push(make_pair(point.first, point.second-1));
        }
    }
    if( dist[H-1][W-1] != -1 ) cout << white_num - dist[H-1][W-1] -1 << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>
#include <sys/timeb.h>
#include <fstream>

using namespace std;


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

	int l, a, b, c, d;
	cin >> l >> a >> b >> c >> d;
	int ans = l;
	while (a > 0 || b > 0) {
		a -= c;
		b -= d;
		ans--;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3100
def recta():
    N = int(input())
    S = input()
    if N % 2 == 0:
        N_2 = int(N / 2)
        if str(S[:N_2]) == str(S[N_2:]):
            print('Yes')
        else:
            print('No')
    else:
        print('No')


if __name__ == "__main__":
    recta()


Measured memory_bytes: 2940
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s = show $ max (a - b) 0 where [a, b] = fmap read (words s) :: [Int]

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
 
#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 1e5 + 10 , lg = 22 ;

int n , ar [ N ] , L , dp [ N ] [ lg ] ; 

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n ;
	for ( int i = 1 ; i <= n ; ++ i )
		cin >> ar [ i ] ;
	cin >> L ; 
	int can = 1 ;
	for ( int i = 1 ; i <= n ; ++ i ) {
		//while ( can < i ) ++ can ; 
		while ( can + 1 <= n && ar [ can + 1 ] - ar [ i ] <= L )
			++ can ;
		dp [ i ] [ 0 ] = can ;
	}
	for ( int j = 1 ; j < lg ; ++ j ) {
		for ( int i = 1 ; i <= n ; ++ i ) {
			dp [ i ] [ j ] = dp [ dp [ i ] [ j - 1 ] ] [ j - 1 ] ; 
		}
	}
	int q ; 
	cin >> q ;
	while ( q -- ) {
		int a , b ;
		cin >> a >> b ;
		if ( a > b ) swap ( a , b ) ;
		int res = 0 ;
		for ( int j = lg - 1 ; ~j ; -- j ) {
			if ( dp [ a ] [ j ] < b ) {
				res += ( 1 << j ) ;
				a = dp [ a ] [ j ] ; 
			}
		}
		cout << ++res << '\n' ; 
	}
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> d(10);
  for (int i = 0; i < K; ++i) {
    int num;
    cin >> num;
    ++d[num];
  }
  vector<int> use;
  for (int i = 0; i < 10; ++i) {
    if (d[i] == 0) {
      use.push_back(i);
    }
  }
  int result = N;
  while (true) {
    int cnt = 0;
    bool flg = false;
    int dig = 0;
    int num = result;
    int i = 5;
    while (0 <= i) {
      int a = num / pow(10, i);
      if (flg) {
        for (int j = 0; j < use.size(); ++j) {
          if (a == use[j]) {
            ++cnt;
            num -= a * pow(10, i);
            break;
          }
        }
      } else {
        if (a != 0) {
          flg = true;
          dig = i + 1;
          for (int j = 0; j < use.size(); ++j) {
            if (a == use[j]) {
              ++cnt;
              num -= a * pow(10, i);
              break;
            }
          }
        }
      }
      --i;
    }
    if (dig == cnt) {
      break;
    }
    ++result;
  }
  cout << result << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if(a <= 8 && b <= 8){
        cout << "Yay!";
    }
    else
        cout << ":(";
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vi t,y;
vvi g;
ll n;
vi ans;
vi fac;
ll dfs(int i,int p){
    for(ll x:g[i])if(x!=p){
        ll k=dfs(x,i);
        if(x!=p)t[i]+=k;
        y[i]*=fac[k];
        y[i]%=mod;
    }
    t[i]++;
    y[i]=y[i]*fac[n-t[i]]%mod;
    return t[i];
}
ll inv(ll i){
    return modpow(i,mod-2);
}
void solve(int i,int p){
    for(ll x:g[i])if(x!=p){
        ans[x]=ans[x]*fac[n-t[x]-1]%mod;
        ans[x]=ans[x]*fac[t[x]]%mod;
        ans[x]=ans[x]*inv(y[i])%mod;
        //cout<<i<<' '<<x<<' '<<endl;
        //outv(ans);
    }
    if(p!=-1){
        ans[0]=ans[0]*fac[n-t[i]]%mod;
        ans[0]=ans[0]*fac[t[i]-1]%mod;
        ans[0]=ans[0]*inv(y[i])%mod;
        ans[i]=ans[i]*inv(fac[n-t[i]])%mod;
        ans[i]=ans[i]*inv(fac[t[i]-1])%mod;
        ans[i]=ans[i]*y[i]%mod;
    }
    //outv(ans);
    for(ll x:g[i])if(x!=p)solve(x,i);
}
void res(int i,int p){
    for(ll x:g[i])if(x!=p){
        ans[x]=ans[x]*ans[i]%mod;
        res(x,i);
    }
}
void f(int i,int p){
    ans[i]=ans[i]*fac[n-1]%mod;
    for(ll x:g[i]){
        if(x!=p){
            ans[i]=ans[i]*inv(fac[t[x]])%mod;
        }
        else ans[i]=ans[i]*inv(fac[n-t[i]])%mod;
    }
    for(ll x:g[i])if(x!=p)f(x,i);
}
int main(){
    cin>>n;
    g=vvi(n);
    t=vi(n);
    y=vi(n,1);
    fac=vi(1000000);
    fac[0]=1;
    rep(i,999999)fac[i+1]=fac[i]*(i+1)%mod;
    ans=vi(n,1);
    rep(i,n-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(0,-1);
    //outv(t);
    solve(0,-1);
    res(0,-1);
    //outv(ans);
    f(0,-1);
    for(ll x:ans)out(x);
}

Measured memory_bytes: 27248
#include <stdio.h>
int main (void)
{
  int i, j, num = 0;
  for(i = 1; i < 10; i++){
    for(j = 1; j < 10; j++){
      num = i * j;
      printf("%dx%d=%d\n", i, j, num);
    }
  }
  return 0;
}

Measured memory_bytes: 524
#include<stdio.h>
int main()
{
   int n, v;
   int A[150];
   int i = 0,
	   s = 0;
   int flag;

   scanf("%d", &n);
   while (i < n) {
      scanf("%d", &A[i]);
      i++;
   }

   flag = 1;
   while (flag) {
      flag = 0;
      for (i = n - 1; i > 0; --i) {
         if (A[i] < A[i - 1]) {
            v = A[i];
			A[i] = A[i - 1];
			A[i - 1] = v;
			s = s + 1;
			flag = 1;
         }
      }
   }
   for (i = 0; i < n; ++i) {
      printf("%d", A[i]);
	  if (i != n - 1)
		  putchar(' ');
   }
   putchar('\n');
   printf("%d\n", s);
   return 0;
}

Measured memory_bytes: 1852
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
class UnionFind{
  private:
    vector<int>par;
  public:
    UnionFind(int n):par(n,-1){}
    int root(int x){
      if(par[x] < 0)return x;
      return par[x] = root(par[x]);
    }
    bool unite(int x,int y){
      x = root(x); y = root(y);
      if (x == y) return false;
      if (par[x] > par[y]) swap(x, y);
      par[x] += par[y];
      par[y] = x;
      return true;
    }
    bool same(int x,int y){
      return root(x) == root(y);
    }
    int size(int x) {
      return -par[root(x)];
    }
};
int solve(){
  int n,m,k;
  cin >> n >> m >> k;
  vector<set<int>>cnt(n);
  UnionFind un(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    cnt[a].insert(b);
    cnt[b].insert(a);
    un.unite(a,b);
  }
  rep(i,k){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    if(un.same(a,b)){
      cnt[a].insert(b);
      cnt[b].insert(a);
    }
  }
  rep(i,n)cout << un.size(i) - cnt[i].size() - 1 << " ";
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

Measured memory_bytes: 24704
using System;
using System.Collections.Generic;
public class ABC143B {
    public static void Main() {
        int N, ans = 0;
        List<int> d = new List<int>();
        N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        for (int i = 0; i < str.Length; i++) {
            d.Add(int.Parse(str[i]));
        }

        for (int i = 0; i < N - 1; i++) {
            for (int j = i + 1; j < N; j++) {
                ans += d[i] * d[j];
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11220
#include <stdio.h>

int gcd(int p, int q)
{
    if(p % q == 0)
        return q;
    return gcd(q, p % q);
}

int main(void)
{
    int K;
    scanf("%d", &K);
    
    int i, j, k, sum = 0;
    for(i=1; i<=K; i++){
        for(j=1; j<=K; j++){
            for(k=1; k<=K; k++){
                sum += gcd(gcd(i, j), k);
            }
        }
    }
    printf("%d", sum);
    
    return 0;
}



Measured memory_bytes: 1720
// DPL_1_A.cpp
//
#include <bits/stdc++.h>
using namespace std;
const int INF=INT_MAX;
int n,m;
int dp[50001],coin[20];
int solve() {
  fill(dp,dp+n+1,INF);
  dp[0]=0;
  for(int i=0;i<n;++i)
    for(int j=0;j<m;++j)
      if(i+coin[j]<=n)
        dp[i+coin[j]]=min(dp[i+coin[j]],dp[i]+1);
  return dp[n];
}
int main() {
  cin>>n>>m;
  for(int i=0;i<m;++i)cin>>coin[i];
  cout<<solve()<<endl;;
  return 0;
}



Measured memory_bytes: 3288
h,w = map(int,input().split())
s = list(map(int,input().split()))
g = list(map(int,input().split()))
s[0] -= 1
s[1] -= 1
g[0] -= 1
g[1] -= 1
raw = []
seen = []
for _ in range(h):
  tmp = input()
  raw.append(tmp)
  t = []
  for j in range(w):
    if tmp[j] == '.':
      t.append(0)
    else:
      t.append(1)
  seen.append(t)
#print(seen)
now = [s]
ans = 0
def check(ii,jj):
  if 0 <= ii < h and 0 <= jj < w:
    if seen[ii][jj] == 0:
      seen[ii][jj] = 1
      now.append([ii,jj])
while now:
  for x in now:
    a,b = x
    check(a-1,b)
    check(a+1,b)
    check(a,b-1)
    check(a,b+1)
  if seen[g[0]][g[1]] == 1:
    print(ans)
    break
  ans += 1
  last = now
  now = []
  for x in last:
    a,b = x
    for di in range(-2,3):
      for dj in range(-2,3):
        check(a+di,b+dj)
else:
  print(-1)

Measured memory_bytes: 107652
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
#include <iomanip>
#include <unordered_map>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp

//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;
//const double INF=1e20;
const int INF=0x3f3f3f3f;
//const int INF= 0x7fffffff;
//const ll INF=0x3f3f3f3f3f3f3f3fll;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=2e5+5;
//const ll MAXN=2e8;
//const int MAX_N=MAX;
const int MOD=1e9+7;
//const ull MOD=1e7+7;
//const ll MOD=998244353;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
//const long double eps=-1.0;
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);
void open()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}

int n,an;
int a[MAX];
int pre[MAX];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=0;i<n;i++)
        pre[a[i]]=pre[a[i]-1]+1,an=max(an,pre[a[i]]);
    printf("%d\n",n-an);


}
/*

*/


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll rt<<1
#define rr rt<<1|1
#define PI acos(-1)
#define MM int m=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
//#define P pair<int,int>
using namespace std;
const int INF=LLONG_MAX;
const int maxn=1e6+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;

int32_t main()
{
    IOS
    cin>>n;
    double t;
    cout<<setprecision(13)<<fixed;
    fun(i) {
        int x;
        cin >>x;
        t+=((double)1/(double)x);
    }
    cout<<(double)1/(double)t;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b, c;
    cin >> a >> b >> c;

    //*
    if(a + b == c || a + c == b || b + c == a){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    //cout << b.size() << endl;

    return 0; 
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define N 200005
#define mod 1000000007
#define pp pair<ll,ll>
typedef long long int ll;
typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++)    
void fastIO(void);
 
void decimal(int);
ll modmulti(ll, ll, ll);
ll modadd(ll, ll, ll);
ll modpower(ll, ll, ll);
ll gcd(ll, ll );
ll modinv(ll, ll);
 

int main()
{
  // decimal(1);
   fastIO();
   ll t;
   cin>>t;
   cout<<t*t*t<<endl;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b, ll m){
   return ((a%m)*(b%m))%m;
}
ll modadd(ll a, ll b, ll m){
   return ((a%m)+(b%m)+m)%m;
}
ll modpower(ll a, ll n, ll m){
   if(n==0)
      return 1;
   ll result = 1;
   while(n>0){
      if(n%2==1)
         result = modmulti(result,a,m);
      a = modmulti(a,a,m);
      n = n/2;
   }
   return result;
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a, ll m){
   return modpower(a,m-2,m);
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

H,W,N = II()
sr,sc = II()
S = str(input())
T = str(input())

for i in range(N)[::-1]:
    if i==N-1:
        l = 1+(int(S[i]=='L'))
        r = W-(int(S[i]=='R'))
        u = 1+(int(S[i]=='U'))
        d = H-(int(S[i]=='D'))
    else:
        l = max(l+int(S[i]=='L')-int(T[i]=='R'), 1+(int(S[i]=='L')))
        r = min(r-int(S[i]=='R')+int(T[i]=='L'), W-(int(S[i]=='R')))
        u = max(u+int(S[i]=='U')-int(T[i]=='D'), 1+(int(S[i]=='U')))
        d = min(d-int(S[i]=='D')+int(T[i]=='U'), H-(int(S[i]=='D')))
    if l>r or u>d:
        print('NO')
        exit()

if l<=sc<=r and u<=sr<=d:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 60380
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

ll espal(string s){
	string t=s;
	reverse(ALL(t));
	return t==s;
}

int main(){FIN;
	string s; cin>>s;
	string t,tt;
	ll n=SZ(s);
	fore(i,0,(n-1)/2)t+=s[i];
	fore(i,(n+1)/2,n)tt+=s[i];
	if(espal(s)&&espal(t)&&espal(tt)){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <random>
#include <stack>
#include <ctime>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int d;
    cin >> d;
    if (d < 1000) {
        cout << "ABC" << endl;
 //       printf("%03d\n", d);
    } else {
        cout << "ABD" << endl;
//        printf("%03d\n", d - 1000 + 1);
    }
}


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

int w,h;
int mx;
vector< vector<int> > t;
void rec(int y,int x,int dp){
	if(t[y][x]==0)return;
	mx = max(mx,dp);
	t[y][x]=0;
	if(x+1< w)rec(y,x+1,dp+1);
	if(y+1< h)rec(y+1,x,dp+1);
	if(x-1>=0)rec(y,x-1,dp+1);
	if(y-1>=0)rec(y-1,x,dp+1);
	t[y][x]=1;
}

int main(){
	int o;
	while(cin >> w >> h && w || h){
		t.clear();
		t.resize(h);
		mx = 0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> o;
				t[i].push_back(o);
			}
		}
		/*
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cout << t[i][j];
			}
			cout << endl;
		}*/
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(t[i][j])rec(i,j,1);
			}
		}
		cout << mx << endl;
	}
}

Measured memory_bytes: 0
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let q: usize = sc.read();
    let s = sc.chars();
    let mut sum = vec![0; n + 1];

    for i in 1..n {
        let c1 = s[i - 1];
        let c2 = s[i];
        if c1 == 'A' && c2 == 'C' {
            sum[i] += 1;
        }
        sum[i] += sum[i - 1];
    }

    let res = (0..q).map(|i| {
        let l: usize = sc.read();
        let r: usize = sc.read();
        if l != 1 {
            sum[r - 1] - sum[l - 1]
        } else {
            sum[r - 1]
        }
    }).collect::<Vec<i32>>();
    for x in res {
        println!("{}", x);
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4860
#include<string>
#include<iostream>
using namespace std;
int main(){
  int C,c;
  string moji;
  cin>>moji;
  c=moji.size();
  for(C=1;C<c;C++)if(moji.substr(C,1)!=moji.substr(C-1,1))break;
  if(C==c){
    cout<<moji.substr(0,1)<<endl;
    return 0;
  }
  if(moji.substr(0,1)==moji.substr(c-1,1)){
    cout<<moji.substr(0,1)<<endl;
  }else{
    cout<<"o"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}

int main() { // E,F , virtual
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll m, k; cin >> m >> k;
	ll cmp = (1 << m) - 1;
	if (cmp < k  || (m == 1 && k == 1)) {
		cout << -1 << '\n'; return 0;
	}
	if (k == 0) {
		for (int i = 0; i <= cmp; i++) {
			cout << i << ' ' << i << ' ';
		}cout << '\n'; return 0;
	}
	cout << 0 << ' ' << k << ' ' << 0 << ' ';
	for (int i = 1; i <= cmp; i++) {
		if (i == k)continue;
		cout << i << ' ';
	}cout << k << ' ';
	for (int i = cmp; i > 0; i--) {
		if (i == k)continue;
		cout << i << ' ';
	}
	

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    vector<Int> A(N); for (auto& a : A) cin >> a;
    vector<Int> B(N+1); for (int i = 0; i < N; i++) B[i+1] = B[i] + max(A[i], 0LL);
    vector<Int> C(N+1); for (int i = 0; i < N; i++) C[i+1] = C[i] + min(A[i], 0LL);
    Int wloss = 1e18, bloss = 1e18;
    for (int i = K; i <= N; i++) {
        wloss = min(wloss, B[i] - B[i-K]);
    }
    for (int i = K; i <= N; i++) {
        bloss = min(bloss, -(C[i] - C[i-K]));
    }
    cout << B[N] - min(wloss, bloss) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <math.h>
#include <bitset>
#include <vector>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

typedef long long ll;

const ll INF = 1e18, MOD = 1e9 + 7;
const int INT_MAX = 1e9;

ll n;

double a[3000];

double d[3000][3000];

int main () 
{
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		scanf ("%lf", &a[i]);
	}

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

	for (int i = 1; i < n; i++)
	{
		d[i][0] = (1.0 - a[i]) * d[i-1][0];

		for (int j = 1; j <= i + 1; j++)
			d[i][j] = (1.0 - a[i]) * d[i-1][j] + a[i] * d[i-1][j-1];
	}

	double ans;

	for (int i = n; i > n - i; i--)
		ans += d[n-1][i];

	printf("%.10lf\n", ans);
}

Measured memory_bytes: 68992
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int a,b,c;
    string ans;
    cin>>a;
    if(a==1)cout<<"Hello World"<<endl;
    else {
        cin>>c>>b;
        cout<<c+b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))




H,W=acinput()

field=[]
dp=np.zeros([H,W])

for i in range(H):
    field.append(list(input()))
    
dp[0,0]=(field[0][0]=="#")

def g(a,b):
    if a=="." and b=="#":
        return 1
    return 0

j=0    
for i in range(1,H):
    dp[i,j]=dp[i-1, j]+g(field[i-1][j],field[i][j])
    
i = 0
for j in range(1,W):
    dp[i, j] = dp[i, j-1]+g(field[i][j-1],field[i][j])

#print(dp)
for i in range(1,H):
    for j in range(1,W):
        l=dp[i,j-1]+g(field[i][j-1],field[i][j])
        u = dp[i-1, j]+g(field[i-1][j], field[i][j])
        dp[i,j]=min(l,u)


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


Measured memory_bytes: 12520
import java.util.Scanner;

public class Main {

	static String s;
	static long n, total = 0, count = 1;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		s = sc.next();
		n = s.length();
		long ans = dfs(0, "");
		System.out.println(ans);
	}

	public static long dfs(int x, String formula) {
		if(x == n) {
			long res = 0;
			String[] split = formula.split("\\+");
			for(int i = 0 ; i < split.length ; i++) {
				res += Long.valueOf(split[i]);
			}
			total += res;
//			System.out.println(String.format("現在の合計値：%d 現在の状態(%d,%s) %dループ目", total, x, formula, count));
			count++;
			return res;
		}
		long ret = 0;
		char c = s.charAt(x);
		if(x != 0) ret += dfs(x + 1, formula + "+" + s.charAt(x));
		ret += dfs(x + 1, formula + c);
		return ret;
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 444444;
int n,col[N],head[N],to[N],nxt[N],edgenum;bool gg;
void add(int u, int v){
	to[++edgenum]=v;nxt[edgenum]=head[u];head[u]=edgenum;
//	printf("add %d %d\n",u,v);
}
void dfs(int u, int x){
	col[u]=x;
	L(i,u)if(col[to[i]]==-1)dfs(to[i],x^1);
	else if(col[to[i]]==x)gg=1;
}
struct QAQ{
	int fa[N],rt,a[N];Vi e[N];
	void ADD(int x, int y){if(!a[x])a[x]=y;else add(a[x],y),add(y,a[x]),a[x]=0;}
	void dfs(int u){
		int deg=0;per(i,SZ(e[u])-1,0){
			dfs(e[u][i]),deg^=1;if(a[e[u][i]])ADD(u,a[e[u][i]]);
		}
		if(!deg)ADD(u,u);
	}
	inline void solve(){
		rep(i,1,n)read(fa[i]);rep(i,1,n)if(fa[i]==-1)rt=i;
		rep(i,1,n)if(fa[i]>0)e[fa[i]].pb(i);
		dfs(rt);
	}
}yzr1,yzr2;
int main() {
	read(n);yzr1.solve();yzr2.solve();
	memset(col,-1,sizeof(col));
	rep(i,1,n)if(col[i]==-1)dfs(i,0);
	rep(i,1,n)gg|=(SZ(yzr1.e[i])-SZ(yzr2.e[i]))&1;
	if(gg){puts("IMPOSSIBLE");return 0;}
	puts("POSSIBLE");
//	rep(i,1,n)printf("%d:%d\n",i,col[i]);
	rep(i,1,n)printf("%d ",SZ(yzr1.e[i])&1?0:(col[i]?1:-1));
	return 0;
}


Measured memory_bytes: 44032
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


ll T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    while(cin >> n){
        REP(u, n) {
            for(int v = u + 1; v < n; v ++) {
                cout << 32 - __builtin_clz(u ^ v) << " \n"[v + 1 == n];
            }
        }
    }
    return 0;
}


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

using namespace std;

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



int main(){
	int n,m;
	cin>>n>>m;
	
	vector<int> a;
	vector<int> b;
	vector<int> c;
	
	rep(i,n){
		int t;
		cin>>t;
		if(t==1)a.push_back(i);
	}
	
	int v = 1;
	int cnt = 0;
	
	rep(i,m){
		int t;
		cin>>t;
		
		rep(j,t){
			if(v==1)b.push_back(cnt+j);
			else c.push_back(cnt+j);
		}
		cnt+=t;
		v=(v+1)%2;
	}
	
	const int INF = 1000000000;
	int ans = INF;
	
	if(a.size()==b.size()){
		ans = 0;
		rep(i,a.size()){
			ans += abs(a[i]-b[i]);
		}
	}
	
	
	
	int ans2 = INF;
	
	if(a.size()==c.size()){
		ans2=0;
		rep(i,a.size()){
			ans2 += abs(a[i]-c[i]);
		}
	}
	
	printf("%d\n",min(ans,ans2));
	
	
	
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll N; cin >> N;
    ll res=0;
    if(N != 1){
        res = N*(N-1)/2;
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
n = int(input())
w = list(map(int, input().split()))
lw = [0] * n
rw = [0] * n
sumL = 0
sumR = 0

for i in range(n):
    sumL += w[i]
    sumR += w[n-i-1]
    lw[i] = sumL
    rw[n-i-1] = sumR

sub = [0] * (n - 1)
for i in range(n - 1):
        sub[i] = abs(lw[i] - rw[i+1])
print(min(sub))

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

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

  string y = s.substr(0, 4);
  string m = s.substr(5, 2);
  string d = s.substr(8, 2);

  ll v = stoi(y) * 10000 + stoi(m) * 100 + stoi(d);

  if (v <= 20190430) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll X, N;
    cin >> X >> N;
    if(N == 0){
        cout << X;
        return 0;
    }
    vl p(N);
    rep(i, N){
        cin >> p[i];
    }
    sort(all(p));
    ll idx = 0;
    ll ans = 0;
    ll min = LONG_LONG_MAX;
    FOR(i, -10, 110){
        if(p[idx] == i){
            if(idx != N-1){
                idx++;
            }
            continue;   
        }
        if(min > abs(X-i)){
            min = abs(X-i);
            ans = i;
        }

    }
    cout << ans;
}

Measured memory_bytes: 3672
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
struct Node
{
	Node *ch[26];
	int siz;
	bool mk;
	Node ()
	{
		for(int i=0;i<26;i++)
			ch[i]=NULL;
		siz=0;
		mk=false;
	}
}*rt,node[404040];
int nn=0;
Node *newnode()
{
	return &node[nn++];
}
string s[101010],qu;
int cnt[101010][26][26];
int h[101010];
void inserts(int x)
{
	Node *p=rt;
	for(int i=0;i<s[x].size();i++)
	{
		p->siz++;
		if(!p->ch[s[x][i]-'a'])
			p->ch[s[x][i]-'a']=newnode();
		p=p->ch[s[x][i]-'a'];
	}
	p->siz++;
	p->mk=true;
}
void calc(int x)
{
	Node *p=rt;
	for(int i=0;i<s[x].size();i++)
	{
		for(int j=0;j<26;j++)
			if(p->ch[j])
				cnt[x][j][s[x][i]-'a']+=p->ch[j]->siz;
		h[x]+=p->mk;
		p=p->ch[s[x][i]-'a'];
	}
}
int main()
{
	int n,ans=0,kk,q;
	ios::sync_with_stdio(0);
	cin>>n;
	rt=newnode();
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		inserts(i);
	}
	memset(cnt,0,sizeof(cnt));
	memset(h,0,sizeof(h));
	for(int i=1;i<=n;i++)
		calc(i);
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		cin>>kk>>qu;
		ans=1;
		for(int j=0;j<26;j++)
			for(int k=j+1;k<26;k++)
				if(cnt[kk][qu[j]-'a'][qu[k]-'a'])
					ans+=cnt[kk][qu[j]-'a'][qu[k]-'a'];
		cout<<ans+h[kk]<<endl;
	}
	return 0;
}

Measured memory_bytes: 358656
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		private const int mod = 1000000007;  // 10^9+7

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int x = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int k = vs[1];
			bool[] f = new bool[n];
			for (int i = 0; i < k; i++) {
				int d = int.Parse(Console.ReadLine());
				int[] a = Console.ReadLine().Split().Select(p => int.Parse(p) - 1).ToArray();
				foreach (var j in a) {
					f[j] = true;
				}
			}
			int ans = 0;
			for (int i = 0; i < n; i++) {
				if (!f[i]) {
					ans++;
				}
			}
			Console.WriteLine(ans);

		}
	}
}


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

int main(){
    int64_t n, a, b, ans = 0;
    cin >> n;
    for (int i = 1; i < n; i++){
        a = n / i;
        b = n % i;
        if(b == 0)ans += a - 1;
        if(b != 0)ans += a;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    int n; cin >> n;
    int odd = 0;
    for(int i = 1;i<=n;i++) {
        if(i % 2 == 1)odd++;
    }
    cout << double(odd)/double(n);
}



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

int main(){
  string s;
  cin >> s;
  
  int cnt = 0;
  
  for (int i=0; i<3; i++){
    for (int j=i+1; j<4; j++){
      if (s.at(i) == s.at(j)) cnt++;
    }
  }
  
  if (cnt == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
 int N;
 scanf("%d", &N);
 int i,j,hozon,minj,A[N+1];
 int count = 0;
  
 for(i = 0; i < N; i++)
{
 scanf("%d",&A[i]);
}
 for(i = 0; i < N; i++)
{
  minj = i;
 for(j = i; j < N; j++)
{
 if(A[minj] > A[j])
{
 minj = j;
}
}
 if(minj != i)
{
  hozon = A[i];
  A[i] = A[minj];
  A[minj] = hozon;
  count++;
}
}
 for(i = 0; i < N; i++)
{
 if(i > 0)
 printf(" ");
 printf("%d",A[i]);
}
 printf("\n");
 printf("%d\n",count);
 return 0;

}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define MAX_W 100000
#define MAX_N 100
ll dp[MAX_N+5][MAX_W+5]; 

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

    int N,W; cin >> N >> W;
    vei w(N); vel v(N); rep(i,N) cin >> w[i] >> v[i];

    for(int i  = N - 1; i >= 0; i--) {
        rep(j,W+1) {
            if(j < w[i]) dp[i][j] = dp[i+1][j];
            else dp[i][j] = max(dp[i+1][j], dp[i+1][j - w[i] ] + v[i]);
        }
    }
    cout << dp[0][W] << endl;
    return 0;
    
}



Measured memory_bytes: 80128
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100000+19;

struct Edge{
	int y,nxt;
} E[N*2];
int las[N],f[N];
Vi V[N];
int n,cnt;

bool cmp(int x,int y){
	return f[x]>f[y];
}
void Add_Edge(int x,int y){
	E[cnt]=(Edge){y,las[x]};las[x]=cnt++;
}
void dfs(int x){
	for (int y:V[x]) dfs(y);
	sort(V[x].begin(),V[x].end(),cmp);
	For(i,0,V[x].size()) f[x]=max(f[x],f[V[x][i]]+i+1);
}

int main(){
	memset(las,-1,sizeof(las));
	n=IN();
	For(i,2,n+1) V[IN()].pb(i);
	dfs(1);
	printf("%d\n",f[1]);
}

Measured memory_bytes: 12160