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

typedef std::pair<int, int> ipair;
#define   pb            push_back
#define   ff            first
#define   ss            second
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int mod  =  2019;
const ld  pi   =  acos(-1);
const int Maxn =  105;

template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}

int A,B;

int lcm(int a, int b){
  return (a*b)/(__gcd(a,b));
}
int divisors(int n){
  int temp = (A%n==0) ? A : (n+A-A%n);
	int diff = B-B%n-(temp);
  //cout<<diff/n+1<<endl;
	return diff/n+1;
}

int32_t main(){ IOS;
  int a,b,C,D;  cin>>a>>b>>C>>D;
  A = min(a,b), B = max(a,b);
  int ans = B-A+1 - (divisors(C) + divisors(D) - divisors(lcm(C,D)));
  cout<<ans<<endl;
}


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

int main() {
  int L, R;
  cin >> L >> R;

  if (L / 2019 == R / 2019) {
    L %= 2019;
    R %= 2019;

    int ans = 2020;
    for (int i = L; i < R; i++) {
      for (int j = i + 1; j <= R; j++) {
        ans = min(ans, (i * j) % 2019);
      }
    }
    cout << ans << endl;

  } else {
    cout << 0 << endl;
  }
}

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

using namespace std;

int main() {
	string s;
	int ans = 0;
	int n;
	cin >> n >> s;
	int m = n / 2;
	if (n % 2 == 1) {
		cout << "No" << endl;
	}
	else {
		for (int i = 0; i < m; i++) {
			if (s[i] == s[i + m ]) {
				ans++;
			}
		}
		if (ans == m) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 256
# 解説

def main():
    N, M, K = map(int, input().split())
    A = map(int, input().split())
    B = map(int, input().split())

    def accumulate(a):
        s = 0
        yield s
        for x in a:
            s += x
            yield s

    *A, = accumulate(A)
    *B, = accumulate(B)

    ans = 0
    j = M

    for i, x in enumerate(A):
        if x > K: break
        while B[j] > K - x: j -= 1
        ans = max(ans, i + j)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 50672
import scala.io._
import scala.util.control.Breaks

// e.g
// 1 2 3
// val Array(a, b) = readLine.split(" ").map(_.toInt) => Array(1, 2, 3)
// 5
// 1 2 3
// 4 5 6
// 7 8 9
// val lines = Source.stdin.getLines()
// データ個数読み取り
// val n = lines.next().toInt
// データ行n個読み取り
// val data = lines.take(n).map{ line => line.split(" ").map(_.toInt).toList }.toList => List(List(1, 2, 3), List(4, 5, 6), List(7, b, 9))

object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine.toInt
    val h = readLine.split(" ").map(_.toInt)
    var ans = 1
    for (i <- 1 to n-1){
      ans += 1
      val b = new Breaks
      b.breakable {
        for (j <- 0 to i) {
          if (h(i) < h(j)) { ans -= 1; b.break}
        }
      }
    }

    println(ans)
  }
}


Measured memory_bytes: 25404
#include <iostream>
#include <map>
#include <vector>
#include <cctype>
using namespace std;

#define ERROR vector<int>()

int n, idx;
string s;
map<string, vector<int> > d;
map<vector<int>, string > rd;
map<string, vector<int> > v;

vector<int> formula();

vector<int> factor(){
  if(s[idx] == '('){
    idx++;
    vector<int> res = formula();
    idx++;
    return res;
  }
  else{
    string str = "";
    while(isalpha(s[idx])){
      str += s[idx];
      idx++;
    }
    return v[str];
  }
}

vector<int> term(){
  vector<int> res = factor();
  if(res == ERROR) return ERROR;

  while(s[idx] == '*' || s[idx] == '/'){
    bool mult = (s[idx] == '*');
    idx++;
    vector<int> tmp = factor();
    if(tmp == ERROR) return ERROR;

    for(int i = 0; i < n; i++){
      if(mult) res[i] += tmp[i];
      else     res[i] -= tmp[i];
    }
  }

  return res;
}

vector<int> formula(){
  vector<int> res = term();
  if(res == ERROR) return ERROR;

  while(s[idx] == '+' || s[idx] == '-'){
    bool plus = (s[idx] == '+');
    idx++;
    vector<int> tmp = term();

    if(res != tmp) return ERROR;
  }

  return res;
}

int main(){
  int m, p;

  while(cin >> n >> m >> p, n || m || p){
    d.clear();
    rd.clear();
    v.clear();

    for(int i = 0; i < m; i++){
      string derived;
      cin >> derived;

      vector<int> vec(n);
      for(int j = 0; j < n; j++){
        cin >> vec[j];
      }
      d[derived] = vec;
      rd[vec] = derived;
    }

    cin >> s;
    s = "(" + s + ")";

    for(int i = 0; i < p; i++){
      string V;
      string D;
      cin >> V >> D;
      v[V] = d[D];
    }

    idx = 0;

    vector<int> ans = formula();

    if(ans == ERROR){
      cout << "error\n";
    }
    else if(rd.find(ans) == rd.end()){
      cout << "undefined\n";
    }
    else{
      cout << rd[ans] << endl;
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  ll A, B;
  char op;
  cin >> A;
  cin >> op;
  cin >> B;
  if (op == '+') {
    cout << (A + B) << endl;
  } else {
    cout << (A - B) << endl;
  }
}

Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3","unroll-loops")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert
#define aer(v) (v).erase((v).begin(),(v).end()) 

//{
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...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int k,a,b,nb=1,ny;

void ttk(){
	nb++;
	k--;
	return;
}

void bty(){
	nb-=a;
	k--;
	return;
}

void ytb(){
	nb+=b;
	k--;
	return;
}

void w(){
	if(k==1){
		dump(nb+1);
		exit(0);
	}
}

main(){
	cin>>k>>a>>b;
	if(k<=a||b-a<=2){
		dump(k+1);
		return 0;
	}
	k-=a-1;
	int kai=k/2;
	k%=2;
	dump(a+kai*(b-a)+k);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;


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

int main()
{
    int n,m;
    while(cin>>n>>m,n){
        vector<int> y,x;
        y.push_back(0);
        x.push_back(0);
        
        for(int i=0;i<n;i++){
            int tmp;
            cin>>tmp;
            y.push_back(y.back()+tmp);
        }
        
        for(int j=0;j<m;j++){
            int tmp;
            cin>>tmp;
            x.push_back(x.back()+tmp);
        }
        
        map<int,int> diag;
        for(int i=0;i<n+1;i++){
            for(int j=0;j<m+1;j++){
                diag[y[i]-x[j]]++;
            }
        }
        
        long long res=0;
        for(auto it=diag.begin();it!=diag.end();it++){
            int tmp=it->second;
            res+=tmp*(tmp-1)/2;
        }
        cout<<res<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 27992
x,y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [2]
c = [4, 6, 9, 11]

if ( x in a and y in a) or (x in b and y in b) or (x in c and y in c):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[100000],b[100000];
    vector< pair <int,int> > vect;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
      cin>>a[i]>>b[i];
        vect.push_back( make_pair(a[i],b[i]) );
    }
    sort(vect.begin(), vect.end());
    for (int i=0; i<n; i++)
    {
        cout << vect[i].first << " "
             << vect[i].second << endl;
    }
    return 0;
  }



Measured memory_bytes: 4652
mod = 10**9+7
s=[x for x in input()]
n=len(s)
dp=[[0 for i in range(13)] for j in range(n+1)]
dp[0][0]=1
for i in range(n):
  for j in range(10):
    if s[i]!='?' and s[i]!=str(j):
      continue
    for k in range(13):
      dp[i+1][(k*10+j)%13] += dp[i][k]
  for j in range(13):
    dp[i+1][j]=dp[i+1][j]%mod
print(dp[n][5])

Measured memory_bytes: 71524
import java.util.*;

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

        int num = sc.nextInt();

        String[] str1 = new String[num];
        String[] str2 = new String[num];
        for(int i = 0;i < num;i++){
            String s = sc.next();
            str1[i] = s;
            str2[i] = s;
        }
        //バブルソート
        for(int i = 1;i < num;i++){
            for(int j = num - 1;j >= i;j--){
                if(str1[j].charAt(1) < str1[j - 1].charAt(1)){
                    String tmp = str1[j];
                    str1[j] = str1[j - 1];
                    str1[j - 1] = tmp;
                }
            }
        }
        //選択ソート
        for(int i = 0;i < num;i++){
            int min = i;
            for(int j = i + 1;j < num;j++){
                if(str2[min].charAt(1) > str2[j].charAt(1)){
                    min = j;
                }
            }
            String tmp = str2[i];
            str2[i] = str2[min];
            str2[min] = tmp;
        }
        //バブルソート後表示
        for(int i = 0;i < num;i++){
            if(i != 0)  System.out.print(" ");
            System.out.print(str1[i]);
        }
        System.out.println();

        System.out.println("Stable");

        //選択ソート後表示
        for(int i = 0;i < num;i++){
            if(i != 0)  System.out.print(" ");
            System.out.print(str2[i]);
        }
        System.out.println();

        int result = 1;
        for(int i = 0;i < str1.length;i++){
            if(!str1[i].equals(str2[i]))    result = 0;
        }
        if(result == 0) System.out.println("Not stable");
        else if(result == 1)    System.out.println("Stable");
    }
}


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

int main(void)
{
    int a, b;
    vector<int> aVector;
    cin >> a >> b;
    aVector.push_back(a+b);
    aVector.push_back(a-b);
    aVector.push_back(a*b);
    cout << *max_element(aVector.begin(), aVector.end()) << endl;
}

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

string s;

int main(int argc, char const *argv[]) {
	cin >> s;
	char c = s[0];
	int res = 0;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] != c) {
			res++;
			c = s[i];
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main (void)


{


int n,ai,i;
long long int x,y,z;

x=1000000;


y=-1000000;
z=0;


scanf("%d",&n);


for(i=1;i<=n;i++)


{


scanf("%d",&ai);


if(ai>y)


{


y=ai;


}


if(ai<x)


{


x=ai;


}


z=z+ai;


}


printf("%d %d %ld\n",x,y,z);


return 0;


}

Measured memory_bytes: 600
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
ll a[100010];

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

  cin>>n;
  rep(i,n)cin>>a[i];

  sort(a,a+n);
  ll idx=n-1;
  repl(i,1,n){
    if(a[i]>=0){
      idx=i;break;
    }
  }

  ll resa=0;
  rep(i,n){
    if(i<idx)resa-=a[i];
    else resa+=a[i];
  }

  vector<P> resb;
  repl(i,idx,n-1){
    resb.push_back(P(a[0],a[i]));
    a[0]-=a[i];
  }
  rep(i,idx){
    resb.push_back(P(a[n-1],a[i]));
    a[n-1]-=a[i];
  }
  cout<<resa<<endl;
  rep(i,resb.size())cout<<resb[i].fi<<" "<<resb[i].se<<endl;

  return 0;
}


Measured memory_bytes: 4336
program AGC39_A
  character(100)::S
  integer(8)::i,J=1,K,L(100)=1,M(100)=1,N
  read(*,*)S
  read(*,*)K
  N=len_trim(S)
  do i=1,N-1
     if(S(i:i)==S(i+1:i+1)) then
        L(J)=L(J)+1
     else
        J=J+1
     end if
  end do
  if(S(1:1)/=S(N:N)) then
     L=L/2
     write(*,*)sum(L)*K
  else
     M=L
     if(J/=1) then
        M(J)=M(J)+M(1)
        M(1)=0
        M=M/2
        L=L/2
        write(*,*)L(1)+sum(M)*K-M(J)+L(J)
     else
        write(*,*)M(1)*K/2
     end if
  end if
end program AGC39_A

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1595

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <cassert>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


struct edge{
  int to, cost;
};
vector<vector<edge>  >g;
vector<int> d;

void dfs(int now, int par){
    for(auto e: g[now])if(e.to != par){
        dfs(e.to,now);
        d[now] = max(d[now], d[e.to] + e.cost);
    }
}

void dfs2(int now, int d_par, int par){
    vp d_child;//深さ、頂点番号
    d_child.push_back(pii(0,-1));
    for(auto e: g[now]){
        if(e.to == par){
            d_child.push_back(pii(d_par + e.cost, e.to));
        }else{
            d_child.push_back(pii(d[e.to] + e.cost, e.to));
        }
    }
    sort(all(d_child));
    reverse(all(d_child));
    d[now] = max(d[now], d_child[0].first);
    for(auto e: g[now])if(e.to != par){
        dfs2(e.to, d_child[d_child[0].second == e.to].first,now);
    }
}

signed main(void) {
    int n;
    cin >> n;
    g.resize(n);
    d = vi(n,0);
    rep(i,n-1){
        int a,b,c;
        cin >> a >> b;
        a--,b--;
        edge e1 = {b,1};
        g[a].push_back(e1);
        edge e2 = {a,1};
        g[b].push_back(e2);
    }
    dfs(0,-1);
    //rep(i,n)cout << d[i] << endl;
    dfs2(0,0,-1);
    //rep(i,n)cout << d[i] << endl;
    rep(i,n){
        cout << (n-1)*2 - d[i] << endl;
    }
}



Measured memory_bytes: 29476
# solution

data=int(input())

ini=input()

array=[]

l=0

for i in range(data):
  if ini[i]=="W":
    l+=1
  array.append(l)

m=min(array[data-1],data-array[data-1])

for i in range(1,data):
  m=min(m,array[i-1]+data-1-i-array[data-1]+array[i])
print(m)

Measured memory_bytes: 15400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" \
                              << "\n";

int main()
{
string s;
  cin>>s;
  if(s.at(0)+s.at(1)+s.at(2)=='a'+'b'+'c')cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
var a,b,c,x:longint;
   the:string;

procedure nhap;
begin
   read(x,a,b);
end;

procedure xuly;
begin
   if a-b>=0 then the:='delicious'
      else  begin
            c:=a-b;
               if x+c>=0 then the:='safe'
                  else the:='dangerous';
            end;
end;

procedure xuat;
begin
   write(the);
end;

begin

   nhap;
   xuly;
   xuat;

end.

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>

using namespace std;


int N, M, H, K;
int main() {

	while (cin >> N >> M >> H >> K, N)
	{
		vector<int> s(N);
		vector<P> g(M);
		rep(i, N) {
			cin >> s[i];
		}
		rep(i, M) {
			int a, b;
			cin >> a >> b; a--;
			g[i] = { b, a };
		}

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

		for (int i = M - 1; i >= 0; i--) {
			swap(s[g[i].second], s[g[i].second + 1]);
		}

		vector<int> num(N);
		rep(i, N) num[i] = i;
		vector<int> l(M), r(M);
		rep(i, M) {
			l[i] = num[g[i].second];
			r[i] = num[g[i].second + 1];
			swap(num[g[i].second], num[g[i].second + 1]);
		}

		int ans = 0;
		rep(i, K) ans += s[i];
		int tmp = ans;
		rep(i, M) {
			if (l[i] < K && r[i] < K) continue;
			if (l[i] < K) {
				ans = min(ans, tmp - s[l[i]] + s[r[i]]);
			}
			else if (r[i] < K) {
				ans = min(ans, tmp + s[l[i]] - s[r[i]]);
			}
		}

		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 4380
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
int main(){
  int n,m,count=0;double sum=0;
  cin>>n>>m;
  vll a(n);
  REP(i,n){
    cin>>a[i];sum+=a[i];
  }
  REP(i,n){
    if(a[i]>=sum/(4*m)){count++;}
  }
  if(count>=m){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
typedef pair<ll, ll> pint;


void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }

}

int main(){
    int N;
    cin >> N;
    int A[N];
    int B[N];
    rep(i, N) {
        B[i] = 0;
    }

    rep(i, N-1) {
        cin >> A[i];
        A[i]--;
        B[A[i]]++;
    }

    rep(i, N) {
        cout << B[i] << endl;
    }
}

Measured memory_bytes: 5196
import java.util.*;

// DDCC 2017-D
// http://ddcc2017-qual.contest.atcoder.jp/tasks/ddcc2017_qual_d	

public class Main {

	public static void main (String[] args) throws InterruptedException {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		HashMap<Integer, Integer> problems = new HashMap<Integer, Integer>();
		for (int i = 0; i < N; i++) {
			int diff = in.nextInt();
			
			if (problems.containsKey(diff)) {
				problems.put(diff, 1 + problems.get(diff));
			} else {
				problems.put(diff, 1);
			}
		}
		
		int M = in.nextInt();
		boolean canCreate = true;
		for (int i = 0; i < M && canCreate; i++) {
			int diff = in.nextInt();
			
			if (!problems.containsKey(diff) || problems.get(diff) == 0) {
				canCreate = false;
			} else {
				problems.put(diff, problems.get(diff) - 1);
			}
		}
		System.out.println(canCreate ? "YES" : "NO");
	}
}


Measured memory_bytes: 137984
N, K = map(int, input().split())
S=0
for b in range(K+1,N+1):
    S += (b-K)*(N//b)
    #print(S,b,-1,N,K)
    M=(b*(N//b))+K
    if N%b>=K:
        S+=(N-M)
        if K!=0:
            S+=1
        #print(b)
        #print(S,b,M,N,K)
print(S)


Measured memory_bytes: 2940
import java.util.*;
public class Main {

	public static void main(String[] ble){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		double res = arr[0] + arr[1];
		res /= 2;
		for(int i = 2; i < n; i++){
			res += arr[i];
			res /= 2;
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

using bits = bitset<5000>;

int main() {

  auto bitlen = [](const bits& a) {
    for(i64 j = 5000; j --> 0;) {
      if(a[j]) {
        return j + 1;
      }
    }
    return 0ll;
  };

  i64 N;
  cin >> N;
  bits X;
  i64 xs;
  cin >> X;
  xs = bitlen(X);

  vector<bits> A(N);
  vector<i64> S(N);
  rep(i,0,N) {
    cin >> A[i];
    S[i] = bitlen(A[i]);
  }
  auto bitmod = [](bits a, i64 as, bits b, i64 bs) {
    for(i64 i = as - bs + 1; i --> 0;) {
      if(a[i + bs - 1]) {
        a ^= (b << i);
      }
    }
    return a;
  };

  auto bitgcd = [&](bits a, i64 as, bits b, i64 bs) {
    while(b.any()) {
      auto m = bitmod(a, as, b, bs);
      a = b;
      as = bs;
      b = m;
      bs = bitlen(b);
    }
    return pair<bits, i64>(a, as);
  };

  auto g = A[0];
  auto gs = S[0];
  for(i64 i = 1; i < N; i++) {
    auto p = bitgcd(g, gs, A[i], S[i]);
    g = p.first;
    gs = p.second;
  }
  i64 ans = 0;
  const i64 MOD = 998244353;
  if(xs - gs + 1 >= 0) {
    vector<i64> Bs(xs - gs + 1, 1);
    for(i64 i = 1; i < xs - gs + 1; i++) {
      Bs[i] = (Bs[i - 1] * 2) % MOD;
    } 
    bits now;
    for(i64 i = xs - gs + 1; i --> 0;) {
      if(X[i + gs - 1]) {
        ans = (ans + Bs[i]) % MOD;
      }
      if(now[i + gs - 1] != X[i + gs - 1]) {
        now ^= (g << i);
      }
    }
    bool OK = true;
    for(i64 i = 5000; i --> 0; ) {
      if(now[i] != X[i]) {
        if(now[i]) {
          OK = false;
        }
        break;
      }
    }
    if(OK) ans = (ans + 1) % MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
  ll k;
  cin>>k;
  string s;
  cin>>s;
  for (int i = 0; i < min(k,sz(s)); ++i)
  {
    cout<<s[i];
  }
  if(sz(s)>k)cout<<"...";
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String ss = s.substring(0, s.length()/2);
        if(s.equals(ss + ss)) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 39296
S = input()
f = lambda x: 2**(x-1) if x > 0 else 1
lenS = len(S)
ans = 0
for i in range(1,lenS+1):
    for j in range(lenS-i+1):
        ans += int(S[j:j+i]) * f(j) * f(lenS-j-i) 
print(ans)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int s=0,a,b,p=100;
  cin>>a>>b;
  if(a==0&&b==100)cout<<101<<endl;
  else if(a==1&&b==100)cout<<10100<<endl;
  else if(a==2&&b==100)cout<<1010000<<endl;
  else if(!a)cout<<b<<endl;
  else{
    if(a==2)p*=p;
    for(int i=1;;i++){
      if(i%p==0){
        s++;
        if(s==b){
          cout<<i<<endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 256
import math
from math import ceil,sqrt,log,gcd,pi
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())



def calcAngle(h,m): 
          
    # validate the input 
    if (h < 0 or m < 0 or h > 12 or m > 60): 
        print('Wrong input') 
      
    if (h == 12): 
        h = 0
    if (m == 60): 
        m = 0
      
    # Calculate the angles moved by  
    # hour and minute hands with  
    # reference to 12:00 
    hour_angle = 0.5 * (h * 60 + m) 
    minute_angle = 6 * m 
      
    # Find the difference between two angles 
    angle = abs(hour_angle - minute_angle) 
    angle = min(360 - angle, angle) 
      
    return angle 
      
a,b,h,m=mi()
x=calcAngle(h,m)
if(x==0):
    print(abs(a-b))
    exit(0)
x=180/x
x1=math.cos(pi/x)
# print(x1
x=(a*a+b*b)-(2*a*b*x1)
print(sqrt(x))

Measured memory_bytes: 62724
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

int main(){
  int n,m;
  double table[100][100];
  while(cin>>n>>m,n){
    REP(i,n)REP(j,n)cin>>table[i][j]; //j->i
    vector<double> dp(n,1.0);
    REP(i,m-1){
      vector<double> ndp(n);
      REP(j,n)REP(k,n)ndp[k] = max(ndp[k],table[k][j] * dp[j]); //j->k
      dp = ndp;
    }
    double ans = 0;
    REP(i,n)ans = max(ans,dp[i]);
    /*
    int intans = ans * 1000;
    if(intans % 10 < 5) {
      intans -= intans % 10;
    }else{
      intans += (10 - intans % 10);
    }
    ans = (double)intans / 1000;
    */
    printf("%0.2lf\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1056
#include <stdio.h>
int main(){
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    
    if(a==1||b==1){
        if(a>b){printf("Bob");}
        else if(a<b){printf("Alice");}
        else printf("Draw");
    }
    else{
        if(a<b){printf("Bob");}
        else if(a>b){printf("Alice");}
        else printf("Draw");
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.ArrayList;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		int n = sc.nextInt();
		int m = sc.nextInt();
		for(int i = 0; i < n; i++){
			int k = sc.nextInt();
			for(int j = 0; j < k; j++){
				int ik = sc.nextInt();
				list.add(ik);
			}
		}
		if(n == 1){
			System.out.println(list.size());
		}else{
			int[] count = new int[m];
			int a = 0;
			for (int v : list) {
				count[v - 1]++;
			}
			int cnt = 0;
			for(int i = 0; i < m; i++){
				if(count[i] == n){
					cnt++;
				}
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> v(n), c(n);
	for(int i = 0; i < n; i++) scanf("%d", &v[i]);
	for(int i = 0; i < n; i++) scanf("%d", &c[i]);
	
	int ans = 0;
	for(int i = 0; i < n; i++) ans += std::max(0, v[i] - c[i]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Diagnostics;
using static System.Console;
using static System.Math;


namespace FunProCon
{
    class FunProConSummer
    {
        static void Main(string[] args)
        {
            long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();
            long n = s[0];
            long t = s[1];
            long[] ts = ReadLine().Split(' ').Select(long.Parse).ToArray();
            long ans = t;
            for (long i = n - 1; i >= 1; i--)
            {
                long target = ts[i] - ts[i - 1];
                ans += Min(target, t);
            }
            WriteLine(ans);
        }

    }
}


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

 
/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
 
 
ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    ll C=A+B;
    ll amari=N%C;
    ll tmp=N/C;
    
    ll p=tmp*A;

    if(amari>A){
        p+=A;
    }
    else{
        p+=amari;
    }
    cout<<p<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define PII pair<int,int>
#define X first
#define Y second
#define MP make_pair
#define PI acos(-1.0)
#define eps 1e-8
const int maxn=3e5+10;
const int mod=998244353;
using namespace std;

int n,k;
int ans[maxn];

void dfs(int num,int x,ll tmp)
{
    if(k==1e5)
        return;
    if(x==num)
    {
        ans[k++]=tmp;
        return;
    }
    if(x==0)
        for(int i=1;i<=9;i++)
            dfs(num,x+1,tmp*10+i);
    else
    {
        if(tmp%10!=0)
            dfs(num,x+1,tmp*10+tmp%10-1);
        dfs(num,x+1,tmp*10+tmp%10);
        if(tmp%10!=9)
            dfs(num,x+1,tmp*10+tmp%10+1);
    }
    
}

int main()
{
    for(int i=1;i<=10;i++)
    {
        dfs(i,0,0);
    }
    scanf("%d",&n);
    printf("%lld",ans[n-1]);
    // system("pause");
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	private static Scanner in;

	private static int[] id;
	private static int n, m;
	
	private static int[] size;
	
	public static void main(String[] args) {
		in = new Scanner(System.in);

		n = in.nextInt();
		m = in.nextInt();
		
		
		id = new int[n];
		size = new int[n];
		
		for(int i=0; i<n; i++) {
			id[i] = i;
			size[i] = 1;
		}
		
		for(int i = 0; i<m; i++) {
			int u = in.nextInt()-1;
			int v = in.nextInt()-1;
			
			if (connected(u, v)) {
				continue;
			}
			
			union(u, v);
		}
		int ans = 0;
		
		
		for(int i=0; i<n; i++) {
			ans = Math.max(ans, size[i]);
		}
		
		System.out.println(ans);
	}

	
	private static int root(int u) {
		while(u!=id[u]) {
			id[u] = id[id[u]];
			u = id[u];
		}
		return u;
	}
	
	private static boolean connected(int u, int v) {
		return root(u)==root(v);
	}
	
	private static void union(int u, int v) {
		int p = root(u);
		int q = root(v);
		id[p] = q;
		size[q] += size[p];
	}
}


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

int dp[401][401];

int main() {
	int n, m1, m2; scanf("%d%d%d", &n, &m1, &m2);
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	rep(i, n) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		int t = i * 10;
		for (int j = t; j >= 0; j--)for (int k = t; k >= 0; k--) {
			dp[j + a][k + b] = min(dp[j + a][k + b], dp[j][k] + c);
		}
	}
	int Min = INF;
	for (int i = 1; i*m1 <= 400 && i*m2 <= 400; i++)
		Min = min(Min, dp[m1*i][m2*i]);
	if (Min == INF)puts("-1");
	else printf("%d\n", Min);
}

Measured memory_bytes: 896
// https://atcoder.jp/contests/diverta2019/tasks/diverta2019_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    string S;
    cin >> S;
    int ans = 0;
    if (S == "RRR")
    {
        cout << 3 << endl;
    }
    else if (S[1] == 'R')
    {
        if (S[0] == 'R' || S[2] == 'R')
        {
            cout << 2 << endl;
        }
        else
        {
            cout << 1 << endl;
        }
    }
    else if (S[0] == 'R' || S[2] == 'R')
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(void){
    string s,t;
  	cin>>s>>t;
  	
  	int answer = 0;
  	for(int i=0;i<(int)s.size();i++){
      	if(s[i]!=t[i]){
          	answer++;
        }
    }
  	cout<<answer<<endl;
  	return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  int sum = 0;
  int cnt = 0;
  while (true){
    sum = cnt * A - cnt + 1;
    if (sum >= B) break;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3604
// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself 
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sortva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll mod=1e9+7;
ll const maxn=1e6+5;
ll const inf=1e18;
bool ss(const pair<ll,ll> &a, const pair<ll,ll> &b) { 
    return a.first*b.second+a.second<b.first*a.second+b.second;
}
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {     
    bool prim[n+1]; 
    memset(prim, true, sizeof(prim)); 
  
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) { 
            for (int i=p*p; i<=n; i += p) 
                prim[i] = false; 
        } 
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v; 
}
bool check(string s){
    ll l=0,r=sz(s)-1;
    while(l<=r){
        if(s[l]!=s[r])return false;
        l++;
        r--;
    }
    return true;
}
int main(){
    fio;
    ll n;
    cin>>n;
    vi a(n),dp(n);
    fr1(i,n)cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    fr(i,2,n-1){
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

#include <stack>
#include <queue>
// #include <deque>
// #include <set>
// #include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;


typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef pair<long long, long long> pllll;
typedef pair<long long, int> plli;
typedef pair<int,long long> pill;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/

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

    int n,k; cin>>n>>k; cin.ignore();

    ll kpow=1;
    int pow=0;

    while (kpow<=n) {
        ++pow;
        kpow*=k;
    }

    cout<<pow<<el;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void) {
  int n;
  cin >> n;
  int num;

  num = 0;

  for (int i = 1; i <= n / 2; ++i) {
    if (i != n - i) ++num;
  }

  cout << num << endl;
}


Measured memory_bytes: 256
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    string cellsInfo;
    cin >> cellsInfo;
    
    int ballNum = 0;
    if (cellsInfo[0] == '1') {
        ballNum++;
    }
    if (cellsInfo[1] == '1') {
        ballNum++;
    }
    if (cellsInfo[2] == '1') {
        ballNum++;
    }
    
    cout << ballNum << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	ok := true
	for i := range s {
		if i%2 == 1 && (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
		} else if i%2 == 0 && (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
		} else {
			ok = false
		}
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using namespace std;

int a , b;
int main()
{
	cin >> a >> b;
	if (a > 0)
	{
		cout << "Positive";
	}
	else if (b < 0)
	{
		if ((b - a + 1) % 2 == 1)
		{
			cout << "Negative";
		}
		else
		{
			cout << "Positive";
		}
	}
	else
	{
		cout << "Zero";
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

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

    static class DLeapingTak {
        long[] dp_acc;
        static long MOD = 998244353;

        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            int k = in.nextInt();
            int[] l = new int[k];
            int[] r = new int[k];
            for (int i = 0; i < k; i++) {
                l[i] = in.nextInt();
                r[i] = in.nextInt();
            }

            long[] dp = new long[n];
            dp_acc = new long[n];
            for (int i = 0; i < n; i++) {
                dp_acc[i] = i == 0 ? 1 : 0;
            }

            for (int i = 1; i < n; i++) {
                for (int j = 0; j < k; j++) {
                    dp[i] += dp_acc(i - r[j], i - l[j]);
                  	dp[i] %= MOD;
                    dp_acc[i] = (dp_acc[i - 1] + dp[i]) % MOD;
                }
            }

            System.out.println(dp[n - 1] % MOD);

        }

        public long dp_acc(int l, int r) {
            long left, right;
            if (l <= 0) {
                left = 0;
            } else {
                left = dp_acc[l - 1];
            }

            if (r < 0) {
                right = 0;
            } else {
                right = dp_acc[r];
            }

            return (right - left + MOD) % MOD;
        }

    }
}



Measured memory_bytes: 39488
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000000
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int n;
int p[200000];
int a[200000], b[200000];
int q[200000];
int main(){

    cin >> n;
    rep(i,n) cin >> p[i];
    rep(i,n){
        p[i]--;
        q[p[i]] = i;
    }
    rep(i,n){
        a[i] = (i+1)*30000+q[i];
        b[i] = INF-(i+1)*30000;
    }
    rep(i,n){
        cout << a[i];
        if(i != n-1) cout << " ";
        else cout << endl;
    }
    rep(i,n){
        cout << b[i];
        if(i != n-1) cout << " ";
        else cout << endl;
    }
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  int now = 1;
  REP(i,n){
    if(a[i] != now) continue;
    now++;
  }

  if(now == 1){
    cout << -1 << endl;
    return 0;
  }

  int ans = n + 1 - now;

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3956