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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, k;
	scanf("%d%d", &n, &k);
	vi a(n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	int answer = 1e9;
	for (int i = 0; i <= n - k; i++) {
		int tmp;
		if (a[i] >= 0)
			tmp = a[i+k-1];
		else if (a[i+k-1] <= 0)
			tmp = -a[i];
		else
			tmp = a[i+k-1] - a[i] + min(a[i+k-1], -a[i]);
		answer = min(answer, tmp);
	}
	printf("%d\n", answer);
}


Measured memory_bytes: 640
seq = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(seq[k - 1])


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

using namespace std;

void matmul(vector<vector<bool>> &a, const vector<vector<bool>> &b) {
    const int N = a.size();
    vector<vector<bool>> res(N, vector<bool>(N, false));

    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            for(int k = 0; k < N; ++k) {
                res[i][j] = res[i][j] || (a[i][k] && b[k][j]);
            }
        }
    }
    a.swap(res);
}

bool solve() {
    int N, M, Z;
    cin >> N >> M >> Z;
    if(!N && !M && !Z) return false;

    vector<pair<int,int>> nodes; // (node, prev)
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        nodes.push_back(make_pair(a, b));
        nodes.push_back(make_pair(b, a));
    }
    nodes.push_back(make_pair(0, -1));
    const int K = nodes.size();
    vector<vector<bool>> mat(K, vector<bool>(K, false));
    for(int i = 0; i < K; ++i) {
        for(int j = 0; j < K; ++j) {
            if(nodes[i].first == nodes[j].second && nodes[j].first != nodes[i].second) mat[i][j] = true;
        }
    }
    vector<vector<bool>> res(K, vector<bool>(K, false));
    for(int i = 0; i < K; ++i) {
        res[i][i] = true;
    }
    while(Z) {
        if(Z % 2 == 1) {
            matmul(res, mat);
        }
        matmul(mat, mat);
        Z /= 2;
    }
    for(int i = 0; i < K; ++i) {
        for(int j = 0; j < K; ++j) {
            if(nodes[i].first == 0 && nodes[j].first == N-1 && res[i][j]) {
                cout << "yes" << endl;
                return true;
            }
        }
    }
    cout << "no" << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    char c[1000000] = {};
    int ans = 100000000,count = 0;

    for(int i = 0; i < n; ++i){
        cin >> c[i];
        if(i != 0 && c[i] == 'E') count++;
    }

    ans = count;

    for(int i = 1; i < n; ++i){
        if(c[i-1] == 'W') count++;
        if(c[i] == 'E') count--;

        if(ans > count) ans = count;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1280
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	H, W, A, B := getInt(), getInt(), getInt(), getInt()

	if H < B || W < A {
		out("No")
		return
	}

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	//	out(H, W, A, B)
	flgY := false
	for y := 0; y < H; y++ {
		if y == B {
			flgY = !flgY
		}
		flgX := false
		for x := 0; x < W; x++ {
			if x == A {
				flgX = !flgX
			}
			if flgX != flgY {
				fmt.Fprintf(w, "1")
			} else {
				fmt.Fprintf(w, "0")
			}
		}
		fmt.Fprintln(w)
	}

}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> diff(n);
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		diff[i] = a - (i + 1);
	}
	
	sort(diff.begin(), diff.end());
	
	int b = diff[n / 2];
	ll ans = 0LL;
	
	for(int i = 0; i < n; ++i) {
		ans += abs(diff[i] - b);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k; cin >> k;
  int count=0;
  for(int i=2;i<=k;i+=2){
    for(int j=1;j<=k;j+=2){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX_N=1e5+5;
const int MOD=1e9+7;
typedef long long ll;
int d[MAX_N];
int main(){
	int n,t;
	cin>>n>>t;
	for(int i=0;i<n;i++)cin>>d[i];
	ll ans=1;
	sort(d,d+n);
	for(int i=0;i<n;i++)ans=(ans*(1+i-(lower_bound(d,d+i,d[i]-t)-d))%MOD);
	cout<<ans<<endl;
}

Measured memory_bytes: 3540
using System;
using System.IO;

namespace Dynamic_Programming
{
    class Longest_Common_Subsequence
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            for (int i = 0; i < n; i++)
            {
                var X = Console.ReadLine();
                var Y = Console.ReadLine();

                Console.WriteLine(LongestCommonSubseq(X, Y));
            }
            Console.Out.Flush();
        }

        static int LongestCommonSubseq(string x, string y)
        {
            var row = x.Length;
            var col = y.Length;

            var l = new int[row, col];
            if (x[0] == y[0]) l[0, 0] = 1;
            for (int i = 1; i < row; i++)
                if (x[i] == y[0] || l[i - 1, 0] == 1) l[i, 0] = 1;
            for (int i = 1; i < col; i++)
                if (x[0] == y[i] || l[0, i - 1] == 1) l[0, i] = 1;

            for (int i = 1; i < row; i++)
                for (int j = 1; j < col; j++)
                    if (x[i] == y[j]) l[i, j] = l[i - 1, j - 1] + 1;
                    else l[i, j] = (l[i - 1, j] > l[i, j - 1]) ? l[i - 1, j] : l[i, j - 1];

            return l[row - 1, col - 1];
        }

    }
}

Measured memory_bytes: 13056
import java.util.*;
 
public class Main {
 
	public static Scanner scan = new Scanner(System.in);
	public static void main(String[] args) {
    
      int n = scan.nextInt();
      int k = scan.nextInt();
      int yen[] = new int[n];
      
      for(int i=0; i<n; i++) yen[i] = scan.nextInt();
      
      Arrays.sort(yen);
      
      int sum = 0;
      
      for(int i=0; i<k; i++) sum += yen[i];
        
      System.out.println(sum);
      
      
    }
}

Measured memory_bytes: 38932
#include <stdio.h>

int main (void)
{
    int h, w, t, i, j;
    char s[51][51];

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

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

    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            t = 0;

            if (s[i][j] == '#') continue;

            if ((i - 1) >= 0) {
                if ((j - 1) >= 0) {
                    if (s[i - 1][j - 1] == '#') {
                        t += 1;
                    }
                }
                if (s[i - 1][j] == '#') {
                    t += 1;
                }
                if ((j + 1) < w) {
                    if (s[i - 1][j + 1] == '#') {
                        t += 1;
                    }
                }
            }

            if ((j - 1) >= 0) {
                if (s[i][j - 1] == '#') {
                    t += 1;
                }
            }
            if ((j + 1) < w) {
                if (s[i][j + 1] == '#') {
                    t += 1;
                }
            }

            if ((i + 1) < h) {
                if ((j - 1) >= 0) {
                    if (s[i + 1][j - 1] == '#') {
                        t += 1;
                    }
                }
                if (s[i + 1][j] == '#') {
                    t += 1;
                }
                if ((j + 1) < w) {
                    if (s[i + 1][j + 1] == '#') {
                        t += 1;
                    }
                }
            }

            s[i][j] = t + '0';
        }
    }

    for (i = 0; i < h; i++) {
        puts(&s[i][0]);
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define fi                      first
#define se                      second
#define pb                      push_back
#define pbb                     pop_back
#define mp                      make_pair
#define pii     	            pair<int,int>
#define all(x)                  x.begin(), x.end()
#define mem(array, value)       memset(array, value, sizeof(array))
#define fastRead 	            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#ifdef Lollipop
    #define line                    cout << "\n===================\n"
    #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ )
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " = " << arg1 << "\n";
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " = " << arg1 << " , ";
    __f(comma + 1, args...);
    }
#else
    #define line
    #define trace(...)
#endif

int sz;
vector<int> input;
ll dp[2][2][105][105];
string num;
int k;

ll cal(int is_start, int is_small, int pos, int value)
{
    if (pos >= sz){
        if (value == k){
            return 1;
        }
        return 0;
    }
    ll &ret = dp[is_start][is_small][pos][value];
    if (ret != -1){
        return ret;
    }
    ret = 0;
    int limit = is_small ? 9 : input[pos];
    if (is_start){
        for (int i = 1; i <= limit; i++){
            if (value + (i != 0) <= k){
                ret += cal(0, is_small | (i < input[pos]), pos + 1, value + (i != 0));
            }
        }
        ret += cal(1, 1, pos + 1, 0);
    }
    else{
        for (int i = 0; i <= limit; i++){
            if (value + (i != 0) <= k){
                ret += cal(0, is_small | (i < input[pos]), pos + 1, value + (i != 0));
            }
        }
    }
    return ret;
}

int main ()
{
    #ifdef Lollipop
        freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif
    //fastRead;
    cin >> num;
    cin >> k;
    sz = num.size();
    for (auto x : num){
        input.pb(x - '0');
    }
    mem(dp, -1);
    cout << cal(1, 0, 0, 0) << endl;
    return 0;
}




Measured memory_bytes: 640
#include <stdio.h>

int main(void){

  int h,w,k;
  scanf("%d %d %d", &h, &w, &k);
  char s[h][w+1];
  for (int i = 0; i < h; i++) {
    scanf("%s", s[i]);
  }
  int cut[h][w];
  int row[h];
  int strawberry;
  int area = 1;
  for (int i = 0; i < h; i++) {
    strawberry = 0;
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        strawberry++;
      }
    }
    row[i] = strawberry;
  }
  int start_row;
  int start_column;
  for (int i = 0; i < h; i++) {
    if (row[i] != 0) {
      start_row = i;
      for (int j = 0; j < w; j++) {
        if (s[i][j] == '#') {
          start_column = j;
          cut[i][j] = area;
          for (int l = 0; l < j; l++) {
            cut[i][l] = area;
          }
          break;
        }
      }
      for (int j = start_column+1; j < w; j++) {
        if (s[i][j] == '#') {
          area++;
        }
        cut[i][j] = area;
      }
      break;
    }
  }
  for (int i = 0; i < start_row; i++) {
    for (int j = 0; j < w; j++) {
      cut[i][j] = cut[start_row][j];
    }
  }
  for (int i = start_row+1; i < h; i++) {
    if (row[i] != 0) {
      area++;
      for (int j = 0; j < w; j++) {
        if (s[i][j] == '#') {
          start_column = j;
          cut[i][j] = area;
          for (int l = 0; l < j; l++) {
            cut[i][l] = area;
          }
          break;
        }
      }
      for (int j = start_column+1; j < w; j++) {
        if (s[i][j] == '#') {
          area++;
        }
        cut[i][j] = area;
      }
    } else {
      for (int j = 0; j < w; j++) {
        cut[i][j] = cut[i-1][j];
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w-1; j++) {
      printf("%d ", cut[i][j]);
    }
    printf("%d\n", cut[i][w-1]);
  }

  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
// typedef
using ll  = long long;
using str = string;
using PL  = pair<ll, ll>;
using P   = pair<int, int>;
using VL  = vector<ll>;
using VI  = vector<int>;
using VS  = vector<str>;
using VP  = vector<P>;
using VPL = vector<PL>;
using VVL = vector<VL>;
using VVI = vector<VI>;

// const num
const ll INF         = 1e18 + 18;
const ll MAX         = 100005;
const ll MOD         = 1000000007;
const long double PI = acosl(-1.0);

// loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(ll(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)

// YesNo
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
// All
#define ALL(v) v.begin(), v.end()
#define deduplicate(v) (v).erase(unique(ALL(d)), (v).end())

int main(void) {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * c, max(b * d, max(a * d, b * c))) << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

int main() {
    int h, w, d, q;
    cin >> h >> w >> d;
    vector< pair<int, int> > board(h * w + 1);
    for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
        int a;
        cin >> a;
        board.at(a) = make_pair(i, j);
    }
    vector<int> distance(h * w + 1);
    for (int i = 0; i < d; ++i) for (int j = h * w - d - i; j > 0; j -= d) distance.at(j) = distance.at(j + d) + abs(board.at(j + d).first - board.at(j).first) + abs(board.at(j + d).second - board.at(j).second);
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        cout << distance.at(l) - distance.at(r) << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x){
	S[++top] = x;
}

int pop(){
	top--;
	return S[top+1];
}

int main(){
	int a, b;
	top = 0;
	char s[100];
	
	while( scanf("%s", s) != EOF ){
		if ( s[0] == '+'){
			a = pop();
			b = pop();
			push(a + b);
		}else if( s[0] == '-'){
			b = pop();
			a = pop();
			push(a - b);
		}else if( s[0] == '*'){
			a = pop();
			b = pop();
			push(a * b);
		}else{
			push(atoi(s));
		}
	}
	
	printf("%d\n", pop());
	
	return 0;
}


Measured memory_bytes: 2144
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  int M;
  cin >> M;
  ll L=0,sum=0;
  for(int i=0; i<M; i++){
    ll d,c;
    cin >> d >> c;
    L += c;
    sum += d*c;
  }
  cout << L-1 + (sum-1)/9 << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
sol = [-1] * N
for i in range(M):
    s, c = list(map(int, input().split()))
    if sol[s-1] != -1 and sol[s-1] != c:
        print('-1')
        exit(0)
    sol[s-1] = c

for v in range(0, 1000):
    s = str(v)
    if len(s) != N:
        continue
    fail = False
    for i in range(len(sol)):
        if sol[i] == -1:
            continue
        if int(s[i]) != sol[i]:
            fail = True
            break
    if not fail:
        print(v)
        exit(0)
print(-1)


Measured memory_bytes: 38580
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll n;
string s;
vl a;  // a[i] : s[i]が'o'なら0、'x'なら1 

void f(vl& v) {  // v[0],v[1]をもとにvの要素を埋める
    exrep(i, 1, n-2) {
        if(a[i] == v[i]) {
            v[i+1] = v[i-1];
        }
        else {
            v[i+1] = 1 - v[i-1];
        }
    }
}

bool check(vl& v) {  // fで埋めたvの要素が矛盾してないか調べる
    if(a[n-1] == v[n-1]) {
        if(v[n-2] != v[0]) {
            return false;
        }
    }
    else if(v[n-2] == v[0]) {
        return false;
    }
    if(a[0] == v[0]) {
        if(v[n-1] != v[1]) {
            return false;
        }
    }
    else if(v[n-1] == v[1]) {
        return false;
    }
    return true;
}

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

    a.assign(n, 0);
    rep(i, n) {
        if(s[i] == 'x') {
            a[i] = 1;
        }
    } 

    vl v(n);  // v[i] : i匹目が羊なら0、狼なら1
    rep(x, 2) {
        rep(y, 2) {
            v[0] = x, v[1] = y;
            f(v);
            if(check(v)) {
                rep(i, n) {
                    if(v[i]) {
                        cout << 'W';
                    }
                    else {
                        cout << 'S';
                    }
                }
                cout << "\n";
                re0;
            }
        }
    }
    
    out(-1);
    re0;
}

Measured memory_bytes: 2176
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


if __name__ == "__main__":
    n, m, k = map(int, input().split())
    uf = UnionFind(n)

    friendlist = dict()
    for i in range(m):
        tmp = list(map(int, input().split()))
        uf.union(tmp[0]-1, tmp[1]-1)
        if tmp[0] - 1 not in friendlist:
            friendlist[tmp[0]-1] = [tmp[1]-1]
        else:
            friendlist[tmp[0]-1].append(tmp[1]-1)
        if tmp[1] - 1 not in friendlist:
            friendlist[tmp[1]-1] = [tmp[0]-1]
        else:
            friendlist[tmp[1]-1].append(tmp[0]-1)

    blocklist = dict()
    for i in range(k):
        tmp = list(map(int, input().split()))
        if tmp[0] - 1 not in blocklist:
            blocklist[tmp[0]-1] = [tmp[1]-1]
        else:
            blocklist[tmp[0]-1].append(tmp[1]-1)
        if tmp[1] - 1 not in blocklist:
            blocklist[tmp[1]-1] = [tmp[0]-1]
        else:
            blocklist[tmp[1]-1].append(tmp[0]-1)

    ans = list()
    for i in range(n):
        blocknum = 0
        if i in blocklist:
            for ii in blocklist[i]:
                if uf.find(ii) == uf.find(i):
                    blocknum += 1
        friendnum = 0
        if i in friendlist:
            friendnum = len(friendlist[i])

        print(str(uf.size(i) - friendnum - blocknum - 1))

Measured memory_bytes: 57840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007

using graph = vector<vector<ll>>;

int main(){
    int l,r,d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i <= r; i++){
        if(i % d == 0) ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3632
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <time.h>
#include <random>
using namespace std;

int main(){
    int64_t N;
    cin>>N;
    int64_t F=1000;
    for(int64_t A=1;A<=sqrt(N);A++){
        if(N%A) continue;
        int64_t B=N/A;
        F = min(F,int64_t(max(log10(A),log10(B)))+1);
    }
    cout<<F<<endl;

    return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N){
    ll sum =0;
    rep(i,1,N+1) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        sum += i;
    }
    cout << sum << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

struct edge { int to,cost; };

int main() {
  string S;cin>>S;
  reverse(ALL(S));
  vector<string> words{"dream","erase","dreamer","eraser"};
  REP(i,4) reverse(ALL(words[i]));

  int tmp = 0;
  while (true) {
    int checker = false;
    for (string word:words) {
      if (S.substr(tmp,word.size())==word) {
        tmp += word.size();
        checker = true;
        break;
      }
    }
    if (!checker) break;
  }

  if (tmp==S.size()) {
    OUT("YES");
  } else {
    OUT("NO");
  }

  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
	public class Main{
		public static void main(String args[]){
			Scanner sc = new Scanner(System.in);
			while(sc.hasNext()){
				String str = sc.nextLine();
				String get;
				int sum = 0;
				int val = 0;
				for(int i =str.length()-1; i  >= 0;i--){
					get=String.valueOf(str.charAt(i));
					switch(get){
					case "I":
						if(val<=1){
						sum+=1;
						}else{
							sum-=1;
						}
						val=1;
						continue;
					case "V":
						if(val<=5)sum+=5;
						else sum-=5;
						val=5;
						continue;
					case "X":
						if(val<=10)sum+=10;
						else sum-=10;
						val=10;
						continue;
					case "L":
						if(val<=50)sum+=50;
						else sum-=50;
						val=50;
						continue;
					case "C":
						if(val<=100)sum+=100;
						else sum-=100;
						val=100;
						continue;
					case "D":
						if(val<=500)sum+=500;
						else sum-=500;
						val=500;
						continue;
					case "M":
						if(val<=1000)sum+=1000;
						else sum-=1000;
						val=1000;
						continue;
					}
				}
				System.out.println(sum);
			}
	}
}

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

int findGroup(int x, const vector< vector<int> >& g) {
  int idx = 0;
  for(auto i : g){
    auto Iter = find( i.begin(), i.end() , x );
    if(Iter != i.end()) {
      return idx;
    }
    idx++;
  }
  return -1;
}

int main() {
  int a, b;
  cin >> a >> b;
  vector< vector<int> > group; 
  vector<int> g1{1, 3, 5, 7, 8, 10, 12}; 
  vector<int> g2{4, 6, 9 , 11}; 
  vector<int> g3{2}; 
  group.push_back(g1);
  group.push_back(g2);
  group.push_back(g3);
  if(findGroup(a, group) == findGroup(b, group)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby
#coding: utf-8

ss = readlines[0..-2]

ss.each do |s|
  catch(:done) do
    s.chomp.split('|').each do |c|
      t = true
      cs = c[1..-2].split('&')
      cs.each do |l|
        cs.each do |_l|
          if ('~' + l == _l || l == '~' + _l)
            t = false
          end
        end
      end
      if t
        puts 'yes'
        throw(:done)
      end
    end
    puts 'no'
  end
end
  

Measured memory_bytes: 2792
import sys

N = int(input())
S = input()

position_L = []
position_R = []
for s in S:
    if s == 'W':
        position_R.append(0)
    else:
        position_R.append(1)
        
flips = sum(position_R[1:])
flips_temp = flips
#print(0,flips_temp)
i = 1
while i < N:
    #print(i,flips_temp)
    flips_temp = flips_temp - position_R[i] + ((-1) * position_R[i-1] + 1)
    if flips_temp < flips:
        flips = flips_temp
    i = i + 1
print(flips)

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

int main() {
  string S;
  cin >> S;
  sort(S.begin(), S.end());
  cout << (S.at(0) == S.at(1) && S.at(1) != S.at(2) && S.at(2) == S.at(3) ? "Yes" : "No") << "\n";
}

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

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

int n;
vector<string> word;
vector<string> seq;
map<char, int> mp;
map<char, char> conv;
vector< pair<int, char> > ord;
string ans;
int num;

bool check() {
  rep(i, seq.size()) {
    bool flag = false;
    rep(j, word.size()) {
      if(word[j].size() != seq[i].size()) continue;
      bool flag2 = true;
      rep(k, seq[i].size()) {
	if(conv[seq[i][k]] == '$') continue;
	if(conv[seq[i][k]] != word[j][k]) flag2 = false;
      }
      if(flag2) flag = true;
    }
    if(!flag) return false;
  }
  return true;
}

void dfs(int idx) {
  //for(auto p : conv) {
    //cout << p.first << " " << p.second << endl;
  //}
  //cout << check() << endl;  
  if(!check()) return;
  if(idx == ord.size()) {
    string tmp = "";
    rep(i, seq.size()) {
      if(i) tmp += " ";
      rep(j, seq[i].size()) {
	tmp += conv[seq[i][j]];
      }
    }
    ans = tmp;
    num++;
    return;
  }
  if(conv[ord[idx].second] != '$') {
    dfs(idx+1);
    return;
  }
  ///cout << ord[idx].second << endl;
  rep(i, 26) {
    if(conv[(char)('A'+i)] != '$') continue;
    conv[ord[idx].second] = (char)('A'+i);
    conv[(char)('A'+i)] = ord[idx].second;
    dfs(idx+1);
    if(num > 1) return;
    conv[ord[idx].second] = '$';
    conv[(char)('A'+i)] = '$';
  }
}

signed main(){
  while(cin >> n, n) {
    word.clear();
    word.resize(n);
    rep(i, n) cin >> word[i];
    seq.clear();
    while(1) {
      string s;
      cin >> s;
      seq.push_back(s);
      if(s.back() == '.') {
	seq[seq.size()-1].pop_back();
	break;
      }
    }
    ord.clear();
    mp.clear();
    conv.clear();
    rep(i, seq.size()) rep(j, seq[i].size()) {
      if(seq[i][j] == '.') continue;
      mp[seq[i][j]]++;
    }
    for(auto p : mp) {
      ord.push_back(make_pair(p.second, p.first));
    }
    sort(ord.begin(), ord.end(), greater<pair<int, int> >());
    ans = "-";    
    rep(i, 26) conv[(char)('A'+i)] = '$';
    conv['.'] = '.';
    num = 0;
    dfs(0);
    //cout << num << endl;
    if(num != 1) ans = "-";
    cout << ans + "." << endl;
  }
  return 0;
}

Measured memory_bytes: 3196
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char c = sc.next().toCharArray()[0];
		char c2 = sc.next().toCharArray()[0];
		if(c > c2) {
			System.out.println(">");
		} else if(c == c2) {
			System.out.println("=");
		} else {
			System.out.println("<");
		}
	}
}

Measured memory_bytes: 22996
import sys
sys.setrecursionlimit(10 ** 6 + 10)

n, m, k = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(m)]
CD = [list(map(int, input().split())) for _ in range(k)]
group = []  # 連結成分ごとのサイズ
person_group = [-1] * n  # 人ごとの属するグループ
person_unable= [0] * n  # 人ごとの候補に入らない人の人数
graph = [[] for _ in range(n)]  # 連結リスト
for ab in AB:
    ab[0] -= 1
    ab[1] -= 1
    graph[ab[0]].append(ab[1])
    graph[ab[1]].append(ab[0])

seen = [False] * n
# その節の連結成分のサイズを返す
def dfs(n, group_id):
    global size
    seen[n] = True
    person_group[n] = group_id
    for v in graph[n]:
        if seen[v]:
            continue
        size = dfs(v, group_id)
    size += 1
    return size
    
    
group_id = 0
for i in range(n):
    if seen[i]:
        continue
    size = 0
    group.append(dfs(i, group_id))
    group_id += 1

# unable計算。まず友達の人
for i in range(n):
    person_unable[i] += len(graph[i])
# 次にブロックの人
for i in range(k):
    CD[i][0] -= 1
    CD[i][1] -= 1
    if person_group[CD[i][0]] == person_group[CD[i][1]]:
        person_unable[CD[i][0]] += 1
        person_unable[CD[i][1]] += 1

for i in range(n):
    print(group[person_group[i]] - person_unable[i] - 1, "", end="")

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

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  for (int i=0; i<N; i++) {
    int A;
    cin >> A;
    if (A % 2 != 0)
      cnt++;
  }

  if (cnt % 2 != 0) cout << "NO" << endl;
  else cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 256
# 要復習
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    L = LIST()
    L.sort()
    ans = 0
    # count = 0
    for i in range(0, N - 2):
        a = L[i]
        for j in range(i + 1, N - 1):
            b = L[j]
            x = a + b - 1
            # a + b > c なので c <= a + b - 1
            # x の入るべき場所にいれた際，そのxの最初のインデックスを返す
            # print(x)
            index = bisect(L, x)
            # print(index)
            # indexの方が大きければ調べる
            if j < index:
                # index が指してるのは，xを入れるべきindex
                # つまり，a + b - 1 の次に大きい数字の一番最初があるindex
                # を指しているので，それを除くための-1が必要
                ans += (index - j - 1)
    print(ans)
if __name__ == "__main__":
    main()




Measured memory_bytes: 5332
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

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

Measured memory_bytes: 3556
w,h,n=map(int,input().split())
m=0
l=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if x>m:
            m=x
    if a==2:
        if x<w:
            w=x
    if a==3:
        if y>l:
            l=y
    if a==4:
        if y<h:
            h=y
if (w>m) and (h>l):
    print((w-m)*(h-l))
else:
    print(0)


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

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

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

const long long INF = 1LL << 60;

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

    vector<int> H(N);
    rep(i, N) cin >> H.at(i);

    vector<long long> dp(N);
    rep(i, N) dp.at(i) = INF;

    dp.at(0) = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 1; j <= K && i + j < N; j++)
        {
            chmin(dp.at(i + j), dp.at(i) + abs(H.at(i) - H.at(i + j)));
        }
    }

    cout << dp.at(N - 1) << endl;
    return 0;
}

Measured memory_bytes: 4512
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll H,W;
    cin>>H>>W;
    if(H==1 || W==1)
        cout<<1;
    else
    cout<<(H*W)/2+(H*W)%2;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int a, b, x;

  scanf("%d %d %d", &a, &b, &x);

  if (x-a<0) {
    printf("NO");
  }else{
    if (a+b < x) {
      printf("NO");
    }else{
      printf("YES");
    }
  }

}


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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP				make_pair

typedef pair<int, string> P;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

map<string, int> ans;

void bfs() {
	queue<string> que;
	que.push( "01234567" );
	while( !que.empty() ) {
		string t = que.front(); que.pop();
		int pos;
		REP( i, 8 ) if( t[i] == '0' ) pos = i;
		REP( i, 4 ) {
			if( 0 <= pos + dx[i] && pos + dx[i] < 8 &&
				!( pos == 3 && i == 0 ) && !( pos == 4 && i == 1 )  ) {
				string u = t;
				swap( u[pos], u[pos + dx[i]] );

				if( ans[u] == 0 ) {
					ans[u] = ans[t] + 1;
					que.push( u );
				}
			}
		}
	}
}

signed main() {
	ans["01234567"] = 1;

	bfs();

	char c;
	string s;
	while( 1 ) {
		s = "";
		REP( i, 8 ) {
			if( !( cin >> c ) ) return 0;
			s += c;
		}

		cout << ans[s] - 1 << endl;
	}

}


Measured memory_bytes: 5224
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

int N;
long long int c[200005];
long long int A[200005];

int main(void) {

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

	long long int tot = 0;

	for (int i = 1; i <= N; i++) {
		tot += (c[i] * (c[i] - 1)) / 2;
	}

	for (int i = 1; i <= N; i++) {

		long long int sub;
		if (c[A[i]] >= 1) { sub = c[A[i]]-1; }
		else { sub = 0; }
		cout << tot - sub << endl;

	}

	return 0;
}

Measured memory_bytes: 4736
N, T = map(int, input().split())
t = list(map(int, input().split()))
L = [0] * (N-1)

for i in range(N-1):
    if t[i+1] - t[i] < T:
        L[i] = t[i+1] - t[i] 
    else:
        L[i] = T

print(sum(L) + T)

Measured memory_bytes: 26836
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef  pair<int,int> pa;
int dv[][2]={{0,1},{1,0},{-1,0},{0,-1}};
int mod=1e9+7;
const int N=2e5+100;

int main()
{
   string s,c;
   int ans=0;
   cin>>s>>c;
   for(int i=0;i<3;i++)
    if(s[i]==c[i]) ans++;
   cout<<ans;
   return 0;
}


Measured memory_bytes: 256
//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) 0//(cerr<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))
#define rep(i,n) for(int i = 0; i < (n); i++)
#define REP(i,n) for(int i = 1; i <= (n); i++)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
typedef pair<ll,ll> pll;
template <typename T> using rkt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-8;
constexpr ll N = 50, INF = 1e18, MOD = 1000000007, K = 2;
constexpr inline ll cdiv(ll x, ll m) { return (x+m-1)/m; } // ceiling divide, x/m for flooring divide
template <typename T> void M(T &x, ll m = MOD){x%=m; if(x<0) x+=m;}

ll n,k,dp[N+1][N+1][N*N+1];
signed main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
    dp[0][0][0] = 1;
    for(int i = 1; i <= N; i++) {
        for(int j = 0; j <= i; j++) {
            for(int k = j; k <= i*i; k++) {
                dp[i][j][k] += dp[i-1][j][k-j]*(j*2+1);
                if(j) dp[i][j][k] += dp[i-1][j-1][k-j];
                dp[i][j][k] += dp[i-1][j+1][k-j]*(j+1)*(j+1);
                M(dp[i][j][k]);
            }
        }
    }
    /*for(int i = 1; i <= N; i++) for(int k = 0; k <= i*i; k++) {
        cout << dp[i][0][k] << " \n"[i*i==k];
    }*/
    cin >> n >> k;
    if(k&1)
        cout << 0 << '\n';
    else
        cout << dp[n][0][k/2] << '\n';
}


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

int main()
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double ax = A * sin(2 * M_PI / 12 * H + 2 * M_PI / 720 * M);
    double ay = A * cos(2 * M_PI / 12 * H + 2 * M_PI / 720 * M);
    double bx = B * sin(2 * M_PI / 60 * M);
    double by = B * cos(2 * M_PI / 60 * M);
    auto res = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
    cout << setprecision(15) << res << endl;

    return 0;
}

Measured memory_bytes: 4100
#include <iostream>
using namespace std;
const int MAxn = 105;
int n, a[MAxn], ans;

void dg(int x, int num) {
    if(x == n) {
        if(num%2 == 0) ans++;
        return;
    }
    for(int i = -1; i <= 1; i++)
        dg(x+1, num*(a[x+1]+i));
}

int main() {
    while(cin >> n) {
        ans = 0;
        for (int i = 1; i <= n; i++) cin >> a[i];
        for (int i = -1; i <= 1; i++) {
            dg(1, a[1]+i);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

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

A = sorted(A)[::-1]

ans = 0
for i, a in enumerate(A):
    if i==0:
        ans += a
        itr = 2
        if itr >= N:
            break
    else:
        ans += a
        itr += 1
        if itr >= N:
            break
        ans += a
        itr += 1
        if itr >= N:
            break

print(ans)


Measured memory_bytes: 94304
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    std::vector<double> vt(N,0);
    double sum=0;
    cout.precision(15);
    for(int i=0;i<N;i++){
        cin>>vt[i];
        sum+=(1/vt[i]);
    }
    sum=(1/sum);
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {X=X;}
#define TF(f) {f=f;}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 10000000000000;
#define NMAX 50
#define MAX 10
int N, K;
int A[20];
int nh;
ll ans = 0;
int binary(int bina) {
	int ans = 0;
	for (int i = 0; bina>0; i++)
	{
		ans = ans + (bina % 2)*pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
int_fast8_t popcount(uint32_t bits) {
#ifdef __GNUC__
	return __builtin_popcount(bits);
#endif
	bits = bits - (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = bits + (bits >> 4) & 0x0f0f0f0f;
	bits = bits * 0x01010101;
	return bits >> 24;
}
int main() {
	cin >> N >> K;
	REP(i, N)cin >> A[i];
	ans = INF;
	REP(bit, (1 << N)) {
		if (popcount(bit)<K) { continue; }
		ll count = 0, front = A[0];
		//cout<<binary(bit)<<endl;
		REP(i, N) {
			if (i == 0) { continue; }
			if ((bit >> i) & 1) {
				if (front<A[i]) { front = A[i]; }
				else {
					front++;
					count += front - A[i];
				}
			}
			else {
				if (front<A[i]) { count = INF; break; }
			}
		}
		ans = min(ans, count);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int GCD(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(x%y!=0){
    int temp=x;
    x=y;
    y=temp%y;
  }
  return y;
}

int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int gcd=a[n-1];
  for(int i=n-2;i>=0;i--){
    int temp=a[i];
    gcd=GCD(temp,gcd);
  }
  if(gcd!=1){
    cout<<"not coprime"<<endl;
    return 0;
  }
  map<int,int> memo;
  bool ans=true;
  for(int i=n-1;i>=0;i--){
    if(a[i]==1) continue;
    for(int j=2;j<=sqrt(a[i]);j++){
      if(a[i]%j==0){
        if(memo[j]>0) {
          ans=false;
          break;
        }
        else{
          memo[j]++;
          while(a[i]%j==0){
            a[i]/=j;
          }
        }
      }
      else continue;
    }
    if(a[i]!=1){
      if(memo[a[i]]>0) ans=false;
      else memo[a[i]]++;
    }
    if(!ans) break;
  }
  if(ans) cout<<"pairwise coprime"<<endl;
  else cout<<"setwise coprime"<<endl;
  return 0;
}


Measured memory_bytes: 7560
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> v{a, b, c};
  sort(v.begin(), v.end());
  if (v[0] == 5 && v[1] == 5 && v[2] == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

#define NMAX 100005
using namespace std;

long long dp[NMAX], v[NMAX];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;

    for(int i = 1; i <= n; ++i)
        cin >> v[i];

    dp[2] = abs(v[1] - v[2]);
    for(int i = 3; i <= n; ++i)
        dp[i] = min(dp[i - 1] + abs(v[i] - v[i - 1]), dp[i - 2] + abs(v[i] - v[i - 2]));
    cout << dp[n] << '\n';
    return 0;
}


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

typedef long long int ll; 
#define MOD 1000000007
#define ON 200000
#define rep(i,n) fp(i,0,n)  
#define fp(i,a,b) for(ll i=(a);i<(b);++i)
#define fn(i,a,b) for(ll i=(a);i>(b);i--)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define FF first
#define SS second
typedef pair<ll, ll> pll; 
typedef vector<pll> vpll;
typedef vector<ll> vll;
#define rs(t) string t;cin>>t
#define ri(t) int t;cin>>t
#define rll(t) long long int t;cin>>t
#define MK make_pair
#define PB push_back
#define PO pop_back
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
///// This part below is only for debug, not used /////
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
///// END /////



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  rs(s);
  if(s[2]==s[3] && s[4]==s[5]){
    cout << "Yes" << endl;
  }
  else
      cout << "No" << endl;
  return 0;
  
}

Measured memory_bytes: 256
/* ***********************************************
Author        :yang12138
Created Time  :2018年08月18日 星期六 20时20分06秒
File Name     :D.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=505;

int cnt[N][N];

void solve(){
	int n,m,Q;
	scanf("%d%d%d",&n,&m,&Q);

	for(int i=1;i<=m;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		cnt[l][r]++;
	}

	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++) cnt[i][j]+=cnt[i][j-1];
	}

	while(Q--){
		int l,r;
		scanf("%d%d",&l,&r);
		int ans=0;
		for(int i=l;i<=r;i++) ans+=cnt[i][r];
		printf("%d\n",ans);
	}

}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	solve();
    return 0;
}


Measured memory_bytes: 1920
// D - Knight
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while(b){
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if(u < 0) u += m;
	return u;
}

int main(){
	int X,Y; cin>>X>>Y;
	if((X+Y)%3 != 0) puts("0");
	else{
		int r = (2*X-Y)/3;
		int n = (2*Y-X)/3;
		if(n<0 || r<0){puts("0"); return 0;}
		n += r;
		ll nPr = 1;
		for(int i=n; i>=n-r+1; --i) nPr = nPr * i % MOD;
		ll fact_r = 1;
		for(int i=r; i>=2; --i) fact_r = fact_r * i % MOD;
		cout<< nPr * modinv(fact_r, MOD) % MOD << endl;
	}
}

Measured memory_bytes: 256