akhauriyash/Code-Regression huggingface dataset:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.main = function (N, _Q, S, lrList) {
    var splitted = S.split('');
    var sList = [0];
    for (var i = 0; i < N; i++) {
        if (splitted[i] === 'A' && splitted[i + 1] === 'C') {
            sList.push(sList[i] + 1);
        }
        else {
            sList.push(sList[i]);
        }
    }
    var res = lrList.map(function (lr) {
        var l = lr[0] - 1;
        var r = lr[1] - 1;
        return sList[r] - sList[l];
    });
    return res;
};
var input = require('fs').readFileSync('/dev/stdin', 'UTF-8');
var lines = input.split('\n');
var NQ = lines[0].split(' ');
var N = Number(NQ[0]);
var Q = Number(NQ[1]);
var S = lines[1];
var lrList = [];
for (var i = 0; i < Q; i++) {
    lrList.push(lines[2 + i].split(' ').map(function (l) { return Number(l); }));
}
var res = exports.main(N, Q, S, lrList);
res.forEach(function (r) { return console.log(r); });


Measured memory_bytes: 57108
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;

string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
	bool operator>(Edge e) {
		return cost > e.cost;
	}
};

int N, M;
Graph G;
vi col;
bool connect = false;

void dfs(int pos, int par, int c) {
	if (col[pos] >= 0) {
		if (c != col[pos]) {
			connect = true;
			return;
		}
		else return;
	}
	col[pos] = c;
	for (auto e : G[pos]) {
		if (e.to == par)continue;
		dfs(e.to, pos, 1 - c);
	}
}

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

	cin >> N >> M;
	G = Graph(N);
	col = vi(N, -1);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(Edge{ a,b,1 });
		G[b].push_back(Edge{ b,a,1 });
	}

	dfs(0, -1, 0);

	if (connect) {
		cout << (ll)N*(N - 1) / 2 - M << endl;
	}
	else {
		int num = 0;
		rep(i, N) {
			if (col[i] == 0)num++;
		}
		cout << (ll)num*(N - num) - M << endl;
	}


	return 0;
}

Measured memory_bytes: 7936
function main(input) {
    const args = input.split('\n')
    const tmp = args[0].split(' ');
    const n = parseInt(tmp[0], 10);
    const d = parseInt(tmp[1], 10);
    console.log(Math.ceil(n / (d*2+1)))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  int prev = 0;
  int count = 0;
  for (int n = 0; n < N; n++) {
    int H;
    cin >> H;
    if (H <= prev) {
      count++;
      if (count > ans) {
        ans = count;
      }
    } else {
      count = 0;
    }
    prev = H;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}


int main() {
	int n;
	cin >> n;
	
	int min = 1e9;
	rep(a, 1, n){
		int sum = findSumOfDigits(a) + findSumOfDigits(n - a);
		if (sum < min) min = sum;
	}
	cout << min << endl;
}


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

int main(){
    int64_t N,ans = 0,i = 1,A = 1;
    int K;
    cin >> N >> K;
    while((N / i) > 0){ 
        i = pow(K,A);
        A++;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define PI 3.14159265358979323846
const int MOD = 1e9 + 7 ;
const int EPS = 1e-9;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N=201010;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
  
      int n;
      cin>>n;
      string a[n];
      int ans=0,ans1=0;
      
      for(int i=0;i<n;i++)
      {
            cin>>a[i];
            for(int j=0;j<(int)a[i].length()-1;j++)
            {
                  if(a[i][j]=='A'&&a[i][j+1]=='B') ans++,ans1++; 
            }
      }
      int cnt1=0,cnt2=0,cnt3=0;
      for(int i=0;i<n;i++)
      {
            if(a[i][0]=='B'&&a[i][(int)a[i].length()-1]=='A') cnt1++;
            else if(a[i][(int)a[i].length()-1]=='A') cnt2++;
            else  if(a[i][0]=='B') cnt3++;

      }
      if(cnt1>0) ans1+=cnt1-1;
      if(cnt1>0)
      {
            if(cnt2>0) ans1++;
            if(cnt3>0 ) ans1++;
            ans1+=min(cnt2-1,cnt3-1);
      }
      if(cnt1>0) ans+=cnt1-1;
      int mn=min(cnt2,cnt3);
      ans+=mn;
      cnt2-=mn;
      cnt3-=mn;
      if(cnt1>0&&(cnt2>0||cnt3>0)) ans++;
      cout<<max(ans,ans1);
} 

// B...A
// A... B
// A....
// ....B
// B...
// ....A
// .....
// B..A B..A B..A ....
// B...A
// ...A B..A B....

Measured memory_bytes: 768
//https://atcoder.jp/contests/agc022/tasks/agc022_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
#if LOCAL&0
    std::ifstream in("./test/sample-5.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    string S; cin>>S;
    unordered_map<char,ll> tbl;
    bool flag=false;
    for(const auto& s:S){
        ++tbl[s];
        if(tbl[s]>1) flag=true;
    }
    if(flag) {
        assert(0);
        cout<<-1<<endl;
        return 0;
    }
    if(tbl.size()>=26){
        for(ll i=S.size()-1;i>=1;--i){
            if(S[i-1]<S[i]){
                auto ss = S.substr(i);
                auto tgt = S[i-1];
                sort(ss.begin(),ss.end());
                S.erase(S.begin()+i-1,S.end());
                for(auto& c:ss){
                    if(c>tgt){
                        S.push_back(c);
                        break;
                    }
                }
                cout<<S<<endl;
                return 0;
            }
        }
        cout<<-1<<endl;
        return 0;
    }
    //後ろにつける
    for(char ch='a';ch<='z';++ch){
        auto it=tbl.find(ch);
        if(it==tbl.end()){
            S.push_back(ch);
            break;
        }
    }
    cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String s = sc.nextLine();
			String[] t = new String[501];
			String u;
			int[] a = new int[501];
			int[] b = new int[501];
			int count = 0;
			int start = 0;
			int i = 0;
			int maxlen = 0;
			boolean go = true;			
			
			while(true){
				go = true;
				start = i;
				while(s.codePointAt(i)!=32){
					i++;
					if(i==s.length())break;
				}
				u = s.substring(start, i);
				i++;
				for(int j=0;j<count;j++){
					if(t[j].compareTo(u)==0){
						a[j]++;
						go = false;
						break;
					}
				}
				if(go==true){
					t[count] = u;
					a[count] = 1;
					count++;
					maxlen = Math.max(maxlen, u.length());
				}
				if(i>=s.length())break;
			}
			
			b = Arrays.copyOf(a, 501);
			Arrays.sort(a);
			
			for(int j=0;j<501;j++){
				if(b[j]==a[500]){
					System.out.print(t[j] + " ");
					break;
				}
			}
			for(int j=0;j<501;j++){
				if(t[j].length()==maxlen){
					System.out.println(t[j]);
					break;
				}
			}
			
			
		}
	}	
}

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

using namespace std;

#define rep(i, n)	for(int i = 0; i < (n); ++i)
#define repA(i, a, n)	for(int i = a; i <= (n); ++i)
#define repD(i, a, n)	for(int i = a; i >= (n); --i)
#define trav(a, x)	for(auto& a : x)
#define fix(a)	cout << setprecision(a); cout << fixed;
#define fast	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);
#define clr(a)	memset(a, 0, sizeof(a))
#define all(x)	(x).begin(), (x).end()
#define rall(x)	(x).rbegin(), (x).rend()
#define len(x)	((int)(x).size())
#define vi	vector<int>
#define vl	vector<ll>
#define vpii	vector<pair<int, int>>
#define vpll	vector<pair<ll, ll>>
#define ff	first
#define ss	second
#define mp	make_pair
#define pb	push_back

typedef long long ll;
typedef long double ld;

int main() {
	fast;
	string s;
	cin>>s;
	ll sum = 0;
	int SIZE = (int)s.size();
	for(int i = 0; i < SIZE; i++) {
		sum += (s[i]-'0');
	}
	if(sum%9==0)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 3748
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

int main(){
    ll N,R;
    cin >> N >> R;
    if(N >= 10){
        cout << R << endl;
        return 0;
    }else{
        cout << R + (100*(10-N)) << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int ans = 0;
		for(int i=0; i<N; i++){
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			ans += r - l + 1;
		}
		System.out.println(ans);
    }
}

Measured memory_bytes: 24180
object Main extends App {
  val stInput =  scala.io.StdIn.readLine()
  val stArray = stInput.split(" ").toSeq
  val abInput =  scala.io.StdIn.readLine()
  val abArray = abInput.split(" ").map(_.toInt).toSeq
  val u =  scala.io.StdIn.readLine()
  if(u == stArray(0)) {
    println((abArray(0) - 1) + " " + abArray(1))
  } else {
    println(abArray(0) + " " + (abArray(1) - 1))
  }

}

Measured memory_bytes: 27348
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
    int n, k;
    string s;
    cin >> n;
    cin >> s;
    cin >> k;

    char tmp = s[k-1];
    for(int i=0;i<n;i++)
    {
        if(s[i] != tmp){
            s[i] = '*';
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 768
package main

import (
	f "fmt"
)

func main() {
	var x int
	f.Scan(&x)

	if 400<=x && x<=599{
		f.Println(8)
	}else if 600<=x && x<=799{
		f.Println(7)
	}else if 800<=x && x<=999{
		f.Println(6)
	}else if 1000<=x && x<=1199{
		f.Println(5)
	}else if 1200<=x && x<=1399{
		f.Println(4)
	}else if 1400<=x && x<=1599{
		f.Println(3)
	}else if 1600<=x && x<=1799{
		f.Println(2)
	}else if 1800<=x && x<=1999{
		f.Println(1)
	}
}

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

int main() {
  vector<int> data(5);
  for (int i = 0; i < 5; i++) {
    cin >> data.at(i);
  }
  int k;
  cin >> k;
  bool tooi = false;
  
  for(int i = 0; i < 5; i++){
    for(int j = 0; j < 5; j++)
      if(data.at(i) - data.at(j) > k){
        tooi = true;
      }
  }
  if(tooi){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
ll dp[55][55][3010],a[maxn];
int main() {
    ll n,ave;
    cin>>n>>ave;
    dp[0][0][0]=1;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j>=0;j--)
        {
            for(int k=3000;k>=0;k--)
            {
                dp[i][j][k]+=dp[i-1][j][k];
                if(k>=a[i]&&j>=1) dp[i][j][k]+=dp[i-1][j-1][k-a[i]];
            }
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ans+=dp[n][i][ave*i];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 69888
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		player player1[] = new player[8];
		player player2[] = new player[8];
		player player3[] = new player[8];
        for(int i=0; i<8; i++)player1[i] = new player(sc.nextInt() , sc.nextDouble());
        for(int i=0; i<8; i++)player2[i] = new player(sc.nextInt() , sc.nextDouble());
        for(int i=0; i<8; i++)player3[i] = new player(sc.nextInt() , sc.nextDouble());
        
        Arrays.sort(player1);
        System.out.println(player1[0] + "\n" + player1[1]);
        player1[0].record = 50;
        player1[1].record = 50;
         
        Arrays.sort(player2);
        System.out.println(player2[0] + "\n" + player2[1]);
        player2[0].record = 50;
        player2[1].record = 50;
         
        Arrays.sort(player3);
        System.out.println(player3[0] + "\n" + player3[1]);
        player3[0].record = 50;
        player3[1].record = 50;
        
        Arrays.sort(player1);
        Arrays.sort(player2);
        Arrays.sort(player3);
        player player4[]= new player[6];
        player4[0] = new player(player1[0].playerNumber,player1[0].record);
        player4[1] = new player(player1[1].playerNumber,player1[1].record);
        player4[2] = new player(player2[0].playerNumber,player2[0].record);
        player4[3] = new player(player2[1].playerNumber,player2[1].record);
        player4[4] = new player(player3[0].playerNumber,player3[0].record);
        player4[5] = new player(player3[1].playerNumber,player3[1].record);
        Arrays.sort(player4);
        System.out.println(player4[0] + "\n" + player4[1]);
    }
}
	class player implements Comparable<player>{
		int playerNumber;
	    double record;
	    player(int playerNumber, double record){
	        this.playerNumber = playerNumber;
	        this.record = record;
	    }
	    @Override
	    public String toString(){
	        return  playerNumber + " " + record;
	    }
	    @Override
	    public int compareTo(player o) {
	    	return new Double(record).compareTo(o.record);
	    }
}

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

typedef pair<int,int> pint;
pint p1[500000];
int main(){
    int n,x,y;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>x>>y;
        p1[i].first=x;p1[i].second=y;
    }
    sort(p1,p1+n);
    int ans=1000000000;
    for(int i=0;i<n-1;++i){
        int x1,x2,y1,y2;
        for(int j=1;j<n-i;++j){
            x1=p1[i].first;x2=p1[i+j].first;
            y1=p1[i].second;y2=p1[i+j].second;
            if((x2-x1)*(x2-x1)>ans) break; 
            ans=min(ans,(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int N;
    while(cin >> N, N) {
        vector<int> dp((1 << 16), 0);
        vector<int> v(N), L(N);
        for(int i=0; i<N; ++i) {
            int m, l;
            cin >> m >> l;
            L[i] = l;
            int bit = 0;
            for(int j=0; j<m; ++j) {
                int s, e;
                cin >> s >> e;
                for(int k=s-6; k<e-6; ++k) {
                    bit |= (1 << k);
                }
            }   
            v[i] = bit;
        }

        for(int i=0; i<(1<<16); ++i) {
            for(int j=0; j<N; ++j) {
                if(i & v[j]) {
                    continue;
                }
                dp[i | v[j]] = max(dp[i | v[j]], dp[i] + L[j]);
            }
        }
        cout << *max_element(dp.begin(), dp.end()) << endl;
    }
}


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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define list_input(x, n) x[n]; rep(i,n){ cin >> x[i];}
#define ll long long

int main(){
  int D, N;
  cin >> D >> N;
  if (D == 0) {
    if (N%100 == 0) {
      N += 1;
    }
    cout << N << endl;
  }else if (D == 1) {
    if (N%100 == 0) {
      N += 1;
    }
    cout << N*100 << endl;
  }else{
    if (N%100 == 0) {
      N += 1;
    }
    cout << N*10000 << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
const long long mod = 1000000007;
//const long long mod = 998244353;

int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	int *A = new int[N];
	long long *a = new long long[N];
	long long *b = new long long[N];
	for (int i = 0; i < N; i++) {
		scanf("%d", A + i);
		a[i] = 0;
		b[i] = 0;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (A[i] < A[j]) {
				if (i < j) {
					b[i]++;
				}
				else if (i > j) {
					a[i]++;
				}
			}
		}
	}
	long long k1 = (long long)(K)*(K + 1) / 2;
	long long k2 = (long long)(K)*(K - 1) / 2;
	k1 %= mod;
	k2 %= mod;
	long long res = 0;
	for (int i = 0; i < N; i++) {
		res += a[i] * k1 + b[i] * k2;
		res %= mod;
	}
	printf("%d", res);
	return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a%2==1 || b%2==1 || c%2==1){
        cout << 0 << endl;
        return 0;
    }
    if(a==b && b==c){
        cout << -1 << endl;
        return 0;
    }
    int ans=0;
    while(a%2==0 && b%2==0 && c%2==0){
        ++ans;
        int aa=a/2,bb=b/2,cc=c/2;
        a=bb+cc;
        b=cc+aa;
        c=aa+bb;
    }
    cout << ans << endl;
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n; cin >> n;
    vi a(n); REP(i, n) cin >> a[i];
    deque<int> q;
    REP(i, n)
    {
        if(i % 2 == 0) q.push_back(a[i]);
        else q.push_front(a[i]);
    } 
    if(n % 2 == 0)
    {
        while(!q.empty())
        {
            cout << q.front() << " ";
            q.pop_front();
        }
        cout << endl;
    }
    else
    {
        while(!q.empty())
        {
            cout << q.back() << " ";
            q.pop_back();
        }
        cout << endl;
    }
}

Measured memory_bytes: 4680
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 505;
int x[N] , a[N * N] , n , l[N] , r[N];

int main(){
  scanf("%d",&n);
  rep(i,1,n+1) scanf("%d",x + i) , a[x[i]] = i;
  priority_queue<pii> L;
  rep(i,1,n+1) l[i] = i - 1;
  rep(i,2,n+1) L.push(mp(-x[i] , i));
  int tot = n * n;
  vi R;
  rep(i,1,tot+1) {
    if(a[i]) {
      if(l[a[i]]) return puts("No") , 0;
      rep(j,0,n-a[i]) R.pb(a[i]);
    } else {
      if(sz(L)) {
        int t = L.top().se;L.pop();
        a[i] = t;
        if(--l[t]) L.push(mp(-x[t] , t));
      } else {
        if(!sz(R)) return puts("No") , 0;
        a[i] = R.back();
        R.pop_back();
      }
    }
  }
  puts("Yes");
  rep(i,1,tot+1) printf("%d%c",a[i]," \n"[i==tot]);
  return 0;
}


Measured memory_bytes: 2816
import collections
N = int(input())
A = map(int, input().split())
c = collections.Counter(A)

neven = nodd = 0
for v in c.values():
    if v % 2 == 1:
        nodd += 1
    else:
        neven += 1

ans = nodd
if neven % 2 == 0:
    ans += neven
else:
    ans += neven - 1
print(ans)


Measured memory_bytes: 59692
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n,t = 1000000007,a[100000],ans = 1;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1,a+1+n);
	if (a[1] == 0)
		{
			for (int i = 2; i <= n; i++)
				{
					if (i % 2 == 0)
						{
							if (a[i] - a[i-1] != 2)
								{
									cout << 0 << endl;
									return 0;
								}
						}
					if (i % 2 == 1)
						{
							if (a[i] != a[i-1])
								{
									cout << 0 << endl;
									return 0;
								}
						}	
				}
		}
		else
			{
				if (a[1] == 1)
					{
						for (int i = 2; i <= n; i++)
							{
								if (i % 2 == 1)
									{
										if (a[i] - a[i-1] != 2)
											{
												cout << 0 << endl;
												return 0;
											}
									}
								if (i % 2 == 0)
									{
										if (a[i] != a[i-1])
											{
												cout << 0 << endl;
												return 0;
											}
									}	
							}
					}
					else	
						{
							cout << 0 << endl;
							return 0;
						 } 
			}
	n /= 2;
	for (int i = 1; i <= n; i++) ans = ans * 2 % t;
	cout << ans << endl;
	return 0;
 } 

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int ans = (n - 1) * (m - 1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float("inf")

N, M = map(int, input().split())
H = list(map(int, input().split()))
paths = []
for _ in range(M):
    line = list(map(int, input().split()))
    paths.append(line)

# print(H, path)

flags = [0 for _ in range(N)]
path = [[] for _ in range(N)]
for a, b in paths:
    path[a-1].append(H[b-1])
    path[b-1].append(H[a-1])

# print(path)

for i in range(N):
    if len(path[i]) == 0:
        flags[i] = 1
    else:
        if max(path[i]) < H[i]:
            flags[i] = 1

print(sum(flags))


Measured memory_bytes: 107736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD=1e9+7;

constexpr int MAX_N = 2000000;
ll inv[MAX_N+1], i_c_n[MAX_N+1], pow_25[MAX_N+1], pow_26[MAX_N+1];
void preprocess(ll n){
    pow_25[0]=1;
    pow_26[0]=1;
    for(int i=1; i<=MAX_N; ++i){
        pow_25[i] = (pow_25[i-1] * 25) % MOD;
        pow_26[i] = (pow_26[i-1] * 26) % MOD;
    }
    inv[1]=1;
    for(int i=2; i<=MAX_N; ++i){
        inv[i] = inv[MOD%i] * (MOD - MOD / i) % MOD;
    }
    i_c_n[n]=1;
    for(int i=n+1; i<=MAX_N; ++i){
        i_c_n[i] = (inv[i-n] * (i-1) % MOD) * i_c_n[i-1] % MOD;
    }
}

int main()
{
    int k;
    string s;
    cin >> k >> s;
    int n = s.length();
    ll ret = 0;
    preprocess(n);
    for (int i=n; i<=n+k; ++i){
        // 延長した文字列で s[n-1] が i 文字目にあるとき
        // s[j] たち（ j < n-1 ）は i-1 箇所の候補から n-1 箇所選んで順番に埋める
        // s[n-1] より前の要素（ i - n 個 ）は、重ならないように選ぶ
        // s[n-1] より後の要素（ n + k - i 個 ）は任意に選べる
        //ll pattern_ = (ncr(i-1, n-1) * pow_mod(25, i-n) % MOD) * pow_mod(26, n+k-i);
        ll pattern = (i_c_n[i] * pow_25[i-n] % MOD) * pow_26[n+k-i] % MOD;
        //cout << pattern_ << " " << pattern << endl;
        ret = (ret + pattern) % MOD;
    }
    cout << ret % MOD;
    return 0;
}


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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#define db(x) cout << "> " << #x << " = " \
	<< (x) << '\n'
#define db2(x, y) cout << "> " << #x << " = " \
	<< (x) << ", " << #y << " = " << (y) << '\n'
#define db3(x, y, z) cout << "> " << #x << \
	" = " << (x) << ", " << #y << " = " << \
	(y) << ", " << #z << " = " << (z) << '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mii;
typedef set<int> si;

const int MX = 1e4;
int n, d, x[12][12], ans;
si perfSqr;

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);
	for (int i = 1; i <= MX; ++i) {
		perfSqr.insert(i * i);
	}
	cin >> n >> d;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < d; ++j) {
			cin >> x[i][j];
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int sum = 0;
			for (int k = 0; k < d; ++k) {
				sum += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]);
			}
			if (present(perfSqr, sum))
				++ans;
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

ll sum(ll n,ll s){
  return (s+s+n-1)*n/2;
}
void solve(long long N, long long L){
  if(L>=0){
    cout<<sum(N-1,L+1)<<endl;
  }else if(N>abs(L)){
    cout<<sum(N,L)<<endl;
  }else{
    cout<<sum(N-1,L)<<endl;
  }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long L;
    scanf("%lld",&L);
    solve(N, L);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,k ;
	cin >> n >> k ;
	vll a(n) ;
	vll b ;
	for(auto &i:a) cin >> i ;
	vvll dpl(n+1,vll(n+1,0)) ;
	for(int i=1;i<=n;i++){
		b.emplace_back(a.at(i-1)) ;
		sort(all(b)) ;
		ll sum = 0 ;
		for(int j=0;j<b.size();j++) sum += b.at(j) ;
		for(int j=i;j>=0;j--){
			dpl.at(i).at(j) = sum ;
			if(j!=0) sum -= b.at(i-j) ;
		}
	}
	reverse(all(a)) ;
	b = {} ;
	vvll dpr(n+1,vll(n+1,0)) ;
	for(int i=1;i<=n;i++){
		b.emplace_back(a.at(i-1)) ;
		sort(all(b)) ;
		ll sum = 0 ;
		for(int j=0;j<b.size();j++) sum += b.at(j) ;
		for(int j=i;j>=0;j--){
			dpr.at(i).at(j) = sum ;
			if(j!=0) sum -= b.at(i-j) ;
		}
	}
//	for(auto i:dpr){
//		for(auto j:i) cout << j << " " ;
//		cout << endl ;
//	}
	ll ans = -INF ;
	for(int i=0;i<=n;i++){
		if(i>k) continue ;
		for(int j=0;j<=i;j++){
			if(i+j>k) continue ;
			for(int l=0;l<=n-i;l++){
				if(i+j+l>k) continue ;
				for(int m=0;m<=l;m++){
					if(i+j+l+m>k) continue ;
					ans = max(ans,dpl.at(i).at(i-j)+dpr.at(l).at(l-m)) ;
				}
			}
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")

def findsum(li):

    for i in range(1,len(li)+1):
        tot[i]=tot[i-1]+li[i-1]
    #print(tot)

def findans(start,end,li):
  global tot
  #print("HI")
  if(start>=end):
    return 0
  if(dp[start][end]!=-1):
    return dp[start][end]
  ans = INF
  for k in range(start,end):


      ans=min(findans(start,k,li)+findans(k+1,end,li),ans)
  dp[start][end]=ans+(tot[end+1]-tot[start])
  return dp[start][end]
n=int(input())
li=[int(k) for k in input().split()]
tot=[0]*(len(li)+1)
findsum(li)
dp=[[-1 for i in range(n)]for k in range(n)]
print(findans(0,n-1,li))


Measured memory_bytes: 44764
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int n, p, q, s, t;
  vector<int> v;
  string buf;
  while (1) {
    getline(cin, buf);
    istringstream iss(buf);
    iss >> p;
    if (!p) break;
    v.clear();
    v.push_back(p);
    while (iss >> p) {
      v.push_back(p);
    }
    s = t = 0;
    for (int i=0; i<(int)v.size(); i++) {
      if (v[i] < 10) {
        s += v[i];
        if (v[i] == 1) {
          ++t;
        }
      } else {
        s += 10;
      }
    }
    if (s > 21) {
      s = 0;
    } else {
      s += 10 * min(t, (21-s)/10);
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1240
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    LL A,B,K;
    R(A,B,K);
    LL mi=min(A,K);
    A-=mi;
    K-=mi;
    mi=min(B,K);
    B-=mi;
    W(A,B);
    return 0;
}


Measured memory_bytes: 256
#pragma comment (linker, "/STACK:256000000")
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(const size_t n, const size_t m, const T v) { return vv<T>(n, vector<T>(m, v)); }
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; }
constexpr ll pow2(const int n) { return 1ll << n; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

template<int N>
struct SieveOfEratosthenes {
    int n;
    int primes[N];
    bool isPrime[N];
    constexpr SieveOfEratosthenes() : n(), primes(), isPrime() {
        for (int i = 2; i < N; ++i) isPrime[i] = true;
        isPrime[0] = isPrime[1] = false;

        for (int i = 2; i < N; ++i) {
            if (!isPrime[i]) continue;
            primes[n++] = i;
            for (int j = i * 2; j < N; j += i) isPrime[j] = false;
        }
    }
};
constexpr int Size = 55555 + 1;
constexpr SieveOfEratosthenes<Size> SoE;
static_assert(SoE.primes[0] != 0, "a");

int N;
vi prime4nplus1;

int main() {
    cin >> N;

    for (const int p : SoE.primes) {
        if (p % 5 == 1) {
            prime4nplus1.emplace_back(p);
        }
    }

    rep(i, N - 1) {
        cout << prime4nplus1[i] << " ";
    }
    cout << prime4nplus1[N - 1];
}

Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
int main() {
	int a,b,c,d;
	char op1,op2,op3;
	scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
	if(a+b+c+d==7){
		op1=op2=op3='+';
	}else if(a+b+c-d==7){
		op1=op2='+';
		op3='-';
	}else if(a+b-c+d==7){
		op1=op3='+';
		op2='-';
	}else if(a+b-c-d==7){
		op1='+';
		op2=op3='-';
	}else if(a-b-c-d==7){
		op1=op2=op3='-';
	}else if(a-b-c+d==7){
		op1=op2='-';
		op3='+';
	}else if(a-b+c-d==7){
		op1=op3='-';
		op2='+';
	}else if(a-b+c+d==7){
		op1='-';
		op2=op3='+';
	}
	printf("%d%c%d%c%d%c%d=7\n",a,op1,b,op2,c,op3,d);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int n,p[301000],h[301000];
int main(){
	read(n);
	for(int i=1;i<=n;i++)
		read(p[i]);
	int sum=0,lst=1;
	for(int i=1;i<=n;i++){
		if(h[i]) sum++;
		h[p[i]]=1;
		if(p[i]<=i) sum++;
		if(sum==i){
			if(i-lst&1){puts("No");return 0;}
			int l=0,r=0;
			for(int j=lst;j<=i;j+=2){
				if(p[j]<j){
					if(p[j]<l){puts("No");return 0;}
					l=p[j];
				}
				else{
					if(p[j]<r){puts("No");return 0;}
					r=p[j];
				}
			}
			for(int j=lst+1;j<=i;j+=2)
				if(p[j]!=j){puts("No");return 0;}
			lst=i+1;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
 
int main()
{
    int i,j;
    int a,b;
    while(1){
        scanf("%d %d", &a, &b);
        if(a==0&&b==0){
            break;
        }
        else if(a>=3&&a<=300&&b<=300){
            for(i=0; i<a; i++){
                for(j=0; j<b; j++){
                    if(i==0||i==a-1){
                        printf("#");
                    }
                    else if(j==0||j==b-1){
                        printf("#");
                    }
                    else{
                        printf(".");
                    }
                }
                printf("\n");
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 572
// #include <bits/stdc++.h>
// #define int long long int
// #define endl "\n"
// #define mod 1000000007
// #define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x
// #define IO if(fopen("input.txt", "r")){freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);} std::ios::sync_with_stdio(false);
// using namespace std;

// int power(int x, unsigned int y, int p)
// {
//     int res = 1;
//     x = x % p;
//     if (x == 0) return 0;

//     while (y > 0) {
//         if (y & 1)
//             res = (res * x) % p;

//         y = y >> 1;
//         x = (x * x) % p;
//     }
//     return res % p;
// }


// signed main()
// {

//     IO
//     int t = 1;
//     // cin >> t;
//     while (t--) {

//         int n;
//         cin >> n;
//         if (n > 1)
//             cout << ( (n * (n - 1)) % mod + power(10, n - 2, mod) ) % mod;
//         else
//             cout << 0;

//     }


//     return 0;
// }









#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define mod 1000000007
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x
#define IO if(fopen("input.txt", "r")){freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);} std::ios::sync_with_stdio(false);
using namespace std;


int geval(int n) {

}


signed main()
{

    IO
    int t = 1;
    // cin >> t;
    while (t--) {


        int n;
        cin >> n;
        int dp[2001];
        dp[0] = 0;
        dp[1] = 0;
        dp[2] = 0;
        for (int i = 3; i <= n; i++) {
            dp[i] = 1;
            for (int j = 3; j <= i - 3; j++) {
                if (j == i - j) {
                    dp[i] += dp[j];
                } else {
                    dp[i] += dp[i - j];
                }
                dp[i] = dp[i] % mod;
            }
        }
        cout << dp[n];
    }


    return 0;
}

Measured memory_bytes: 3696
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

void solve() {
    int n, k;
    cin >> n >> k;
    V<int> B(n, 0);
    rep(i, n) {
        int a;
        cin >> a;
        B[--a]++;
    }
    sort(B.begin(), B.end());
    int ans = accumulate(B.begin(), B.begin() + n - k, 0);
    cout << ans << "\n";
}
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

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

using namespace std;

typedef long long ll;

const int MX = 606;

int n, d1, d2;

struct GRAPH
{
	vector<pair<int, int> > dir;
	int col[MX][MX], num[3];

	void bfs(int x, int y)
	{
		queue<pair<int, int> > que;
		que.push(make_pair(x, y));
		col[x][y] = 1;
		while(!que.empty())
		{
			auto a = que.front();
			que.pop();
			for(auto d : dir)
			{
				auto b = a;
				b.first += d.first;
				b.second += d.second;
				if(b.first>=0 && b.first<n*2 && b.second>=0 && b.second<n*2 && !col[b.first][b.second])
				{
					col[b.first][b.second] = 3-col[a.first][a.second];
					num[col[b.first][b.second]]++;
					que.push(b);
				}
			}
		}
	}

	void color()
	{
		for(int i=0; i<n*2; i++)
			for(int j=0; j<n*2; j++)
				if(!col[i][j])
					bfs(i, j);
	}
} G1, G2;

void build(GRAPH &g, int d)
{
	g.dir.clear();
	for(int i=0; i*i<=d; i++)
		for(int j=0; j*j<=d; j++)
			if(i*i + j*j == d)
			{
				g.dir.push_back(make_pair(i, j));
				g.dir.push_back(make_pair(i, -j));
				g.dir.push_back(make_pair(-i, j));
				g.dir.push_back(make_pair(-i, -j));
			}
}

void print()
{
	vector<pair<int, int> > typ[3][3];
	for(int i=0; i<n*2; i++)
		for(int j=0; j<n*2; j++)
			typ[G1.col[i][j]][G2.col[i][j]].push_back(make_pair(i, j));
	for(int i=1; i<=2; i++)
		for(int j=1; j<=2; j++)
			if(typ[i][j].size() >= n*n)
			{
				while(typ[i][j].size() > n*n) typ[i][j].pop_back();
				for(auto it : typ[i][j]) printf("%d %d\n", it.first, it.second);
				return;
			}
}

int main()
{
	scanf("%d%d%d", &n, &d1, &d2);
	build(G1, d1);
	build(G2, d2);
	G1.color();
	G2.color();
	print();
	return 0;
}

Measured memory_bytes: 7656
#include <iostream>
#include <vector>

using namespace std;

int GetGCD(int a, int b)
{
	if (a == 0)return b;
	if (b == 0)return a;

	int r = a % b;

	if (r == 0)
	{
		return b;
	}
	else
	{
		return GetGCD(b, r);
	}
}

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

	vector<int> A(N);
	for (auto& a : A)
	{
		cin >> a;
	}

	vector<int> L(N);
	L[0] = 0;
	for (int i = 1; i < N; i++)
	{
		L[i] = GetGCD(L[i - 1], A[i - 1]);
	}

	vector<int> R(N);
	R[N - 1] = 0;
	for (int i = N - 2; i >= 0; i--)
	{
		R[i] = GetGCD(R[i + 1], A[i + 1]);
	}

	int Max = 1;
	for (int i = 0; i < N; i++)
	{
		int GCD = GetGCD(L[i], R[i]);
		if (GCD > Max)Max = GCD;
	}

	cout << Max;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll>a(n);
  rep(i,0,n) cin >> a[i];
  if(a[0] != 0){cout << -1 << endl;return 0;}
  ll ans = 0;
  rep(i,1,n){
    if(a[i]-a[i-1] > 1){cout << -1 << endl;return 0;}
    else if(a[i]-a[i-1] == 1) ans++;
    else ans += a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4816
// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
using namespace std;
const int MaxN=1000050;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
char s[MaxN];
signed main(void)
{
	scanf("%s",s+1);
	reg int n=strlen(s+1);
	s[0]=0;
	reg int ans=0;
	for(int i=1;i<=n;++i)
		s[i]-='0';
	for(int i=n;i>=1;--i)
	{
		if(s[i]==10)
		{
			s[i]=0;
			++s[i-1];
		}
		if(s[i]==5)
		{
			if(s[i-1]>=5)
			{
				++s[i-1];
				ans+=5;
			}
			else
			{
				ans+=5;
			}
		}
		else if(s[i]<5)
		{
			ans+=s[i];
		}
		else if(s[i]>5)
		{
			ans+=10-s[i];
			++s[i-1];
		}
	}
	ans+=s[0];
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a;
	cin>>a;
	cout<<2*a*double(3.141592)<<endl;
}

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

int main(){
    int n; //問題数
    cin >> n;

    vector<int> time(n); //各問題を解くのにかかる時間
    for (int i = 0; i < n; i++) {
        cin >> time.at(i);
    }
    // 元々の合計時間
    int sum;
    sum = accumulate(time.begin(),time.end(),0);

    int m; cin >>m; //ドリンクの数

    for(int i = 0; i < m; i++){
        int ans, p, x;
        cin >> p >> x;
        ans = sum + x - time.at(p - 1);
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 256
book_count, subject_count, each_understanding_level = gets.split.map(&:to_i)
book_info_list = book_count.times.map { gets.split.map(&:to_i) }

buy_pattern_list = (1..book_count).inject([]) do |result, i|
  result.concat(book_info_list.combination(i).to_a)
end

understand_list = buy_pattern_list.filter do |patterns|
  transposed_list = patterns.transpose
  transposed_list.each_with_index.all? do |list, i|
    next true if i == 0
    list.sum >= each_understanding_level
  end
end

p understand_list.empty? ? -1 : understand_list.map { |items| items.transpose[0].sum }.min

# 流れをまとめると・・・
# bit全探索で、購入パターンを網羅。bit全探索 => 購入パターンに変換と言う感じ
# ※後書き: combination使えばbit全探索のロジック書かずに、全パターン出してくれた。のでそれを連結する処理だけ書いた
# その中から、理解度を満たしている購入パターンを抽出
# その中から、最小合計金額を算出

# ポイントは、買うか買わないかのパターンに気づいて、bit全探索が使えると閃けるか。
# これ、conmbinationで書き直してみよう

Measured memory_bytes: 15352