akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}
vector<int> v[100010];
vector<int> u;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[100010];
    fact();
    rep(i, n + 1) cin >> a[i];
    rep(i, n + 1) v[a[i]].push_back(i);
    rep(i, n + 1) if (v[a[i]].size() > 1) u = v[a[i]];
    //cout << u[0] << " " << u[1] << endl;
    int k = n - u[1] + u[0];
    
    rep(i, n + 1) {

        cout << (C(n + 1, i + 1) - C(k, i) + mod) % mod << endl;
    }

    return 0;
}

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

int main() {
    int p, q, r;
    cin >> p >> q >> r;
    int a = p+q;
    int b = p+r;
    int c = q+r;
    int mini = a;
    if(b<mini) {
        mini = b;
    }
    if(c<mini) {
        mini = c;
    }
    cout << mini;
    return 0;
}


Measured memory_bytes: 256
S = input()
nums = [0] * (len(S)+1)
pos = 0
count = 0
pre_count = 0
now = '>'
for (i, s) in enumerate(S):
  if s != now:
    if s == '<':
      nums[pos] = max(pre_count, count)
      while pos != i:
        pos += 1
        count -= 1
        nums[pos] = count
    else:
      pos = i
      pre_count = count+1
      count = 1
    now = s
  else:
    count += 1
    if s == '<':
      nums[i] = count
if now == '<':
  nums[i+1] = count+1

if s == '>':
  nums[pos] = max(pre_count, count)
  while pos != i+1:
    pos += 1
    count -= 1
    nums[pos] = count

print(sum(nums))

Measured memory_bytes: 47944
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N,K;
  cin>>N>>K;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  
  for(int i=0;i<N-K;i++){
    if(A[i]<A[i+K]){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 4052
import java.io.*;

class Main
{
    public static void main(String args[])
    {
        String buf;
        try {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        buf = br.readLine();
        char seven = '7';
        for(int i = 0; i < buf.length(); i++){
            if ( buf.charAt(i)  == seven){
                System.out.println("Yes");
                break;
            }else if( i == 2 ){
                System.out.println("No");
                break;
            }
        }
    } catch(Exception e) {}
  }
}

Measured memory_bytes: 32528
# https://atcoder.jp/contests/abc060/tasks/arc073_a

import itertools
import collections
import bisect

def main():
    N, T = map(int, input().split())
    ts = list(map(int, input().split()))

    ans = 0

    for i in range(1, len(ts)):
        ans += min(T, ts[i] - ts[i-1])
    ans += T
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 85328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int S,W;
    cin >> S >> W;
    if (S <= W) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}



Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int len=0;
char s[30];
bool flag[300];
char c;

int findDec()
{
    for (int i=len-1; i>=0; --i)
    {
        if (i==0) return -1;
        if (s[i-1]>s[i]) continue;
        if (s[i-1]<s[i]) return i-1;
    }
    return -1;
}

void geneLoc(int loc)
{
    memset(flag,0,sizeof(flag));
    for (int i=0; i<loc; ++i)
    {
        cout<<s[i];
        flag[s[i]]=1;
    }
    for (char c=s[loc]+1; c<='z'; ++c)
        if (flag[c]==0)
        {
            cout<<c<<endl;
            break;
        }
}


int main()
{
    while (scanf("%c",&c)!=EOF)
    {
        if (c>='a' && c<='z')
            s[len++]=c;
        else break;
        flag[c]=1;
    }
    if (len<26)
    {
        cout<<s;
        for (char c='a'; c<='z'; ++c)
            if (flag[c]==0)
            {
                cout<<c<<endl;
                break;
            }
    }
    if (len==26)
    {
        int loc=findDec();
        if (loc==-1)
        {
            cout<<loc<<endl;
        }else
        {
            geneLoc(loc);
        }
    }
    return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto p = readln.split.to!(int[]);

  auto r = 0;
  foreach (i; 0..n-1) {
    if (i+1 == p[i]) {
      swap(p[i], p[i+1]);
      ++r;
    }
  }
  if (p[n-1] == n) ++r;
  writeln(r);
}


Measured memory_bytes: 4284
package main

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

const (
	BLOCKED   = -1
	EMPTY     = 0
	QUEEN     = 1
	BOARD_DIM = 8
	QUEEN_NUM = 8
)

type Board struct {
	table [][]int
	dim   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	board := NewBoard(BOARD_DIM)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		row, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		col, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		board = board.Put(row, col)
	}

	_, result := eightQueens(n, board)

	for i := 0; i < board.dim; i++ {
		row := make([]string, board.dim)
		for j, v := range result.table[i] {
			if v == QUEEN {
				row[j] = "Q"
			} else {
				row[j] = "."
			}
		}
		fmt.Println(strings.Join(row, ""))
	}
}

func eightQueens(numQueens int, board *Board) (bool, *Board) {
	if numQueens == QUEEN_NUM {
		return true, board
	}
	for i := 0; i < BOARD_DIM; i++ {
		for j := 0; j < BOARD_DIM; j++ {
			if board.CanPut(i, j) {
				newBoard := board.Put(i, j)
				result, resultBoard := eightQueens(numQueens+1, newBoard)
				if result {
					return true, resultBoard
				}
			}
		}
	}
	return false, nil
}

func NewBoard(dim int) *Board {
	table := make([][]int, dim)
	for i := 0; i < dim; i++ {
		table[i] = make([]int, dim)
	}
	return &Board{table: table, dim: dim}
}

func CopyBoard(board *Board) *Board {
	dim := board.dim
	newBoard := NewBoard(dim)
	for i := 0; i < dim; i++ {
		for j := 0; j < dim; j++ {
			newBoard.table[i][j] = board.table[i][j]
		}
	}
	return newBoard
}

func (board *Board) IsEmpty(row int, col int) bool {
	return board.table[row][col] == EMPTY
}

func (board *Board) existsQueen(posX int, posY int, dirX int, dirY int) bool {
	dim := board.dim
	posX = posX + dirX
	posY = posY + dirY
	for 0 <= posX && posX < dim && 0 <= posY && posY < dim {
		if board.table[posX][posY] == QUEEN {
			return true
		}
		posX = posX + dirX
		posY = posY + dirY
	}
	return false
}

func (board *Board) CanPut(row int, col int) bool {
	if !board.IsEmpty(row, col) {
		return false
	}
	for dirX := -1; dirX < 1; dirX++ {
		for dirY := -1; dirY < 1; dirY++ {
			if dirX == 0 && dirY == 0 {
				continue
			}
			if board.existsQueen(row, col, dirX, dirY) {
				return false
			}
		}
	}
	return true
}

func (board *Board) Put(row int, col int) *Board {
	newBoard := CopyBoard(board)
	newBoard.table[row][col] = 1
	newBoard.fill(row, col, -1, -1)
	newBoard.fill(row, col, 0, -1)
	newBoard.fill(row, col, 1, -1)
	newBoard.fill(row, col, 1, 0)
	newBoard.fill(row, col, 1, 1)
	newBoard.fill(row, col, 0, 1)
	newBoard.fill(row, col, -1, 1)
	newBoard.fill(row, col, -1, 0)
	return newBoard
}

func (board *Board) fill(posX int, posY int, dirX int, dirY int) {
	dim := board.dim
	posX = posX + dirX
	posY = posY + dirY
	for 0 <= posX && posX < dim && 0 <= posY && posY < dim {
		board.table[posX][posY] = -1
		posX = posX + dirX
		posY = posY + dirY
	}
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}



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

int ans[100001];

int main()
{
    int n;
    cin >> n;
    int a[100001], b[100001];
    for(int i=0; i<n+1; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];

    ll ans=0;
    for(int i=0; i<n; i++){
        int f=min(a[i],b[i]);
        ans += f;
        b[i] -= f;
        f=min(a[i+1],b[i]);
        ans += f;
        a[i+1] -= f;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int n, m;
int x[101010];
int cnt1[101010];
int cnt2[101010]; 
int main() {
	cin >> n >> m;
	for (int i = 0; i < n;i++) cin >> x[i];

	map<int, int> mapp;
	for (int i = 0; i < n; i++)mapp[x[i]]++;

	for (auto p : mapp) {
		cnt1[p.first % m] += p.second;
		cnt2[p.first % m] += p.second / 2;
	}

	int ans = 0;

	for (int i = 0; i < m / 2 + 1; i++) {
		int j = m - i;

		if (i == 0 || i == j) {
			ans += cnt1[i] / 2;
		}
		else {
			if (cnt1[i] < cnt1[j]) {
				ans += cnt1[i];
				int d = cnt1[j] - cnt1[i];
				d = d / 2;
				ans += min(d, cnt2[j]);
			}
			else {
				ans += cnt1[j];
				int d = cnt1[i] - cnt1[j];
				d = d / 2;
				ans += min(d, cnt2[i]);
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long N,i;
    cin>>N;
    pair<long long,long long> a[N];
    for(i=0;i<N;i++){
        cin>>a[i].second>>a[i].first;
    }
    sort(a,a+N);
    long long b[N];
    b[0]=a[0].second;
    for(i=1;i<N;i++){
        b[i]=b[i-1]+a[i].second;
    }
    for(i=0;i<N;i++){
        if(b[i]>a[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 4992
from operator import attrgetter

class Rest:
    def __init__(self, city, point, index):
        self.city = city
        self.point = point
        self.index = index + 1


def main():
    N = int(input())
    restList = []
    for index in range(N):
        SP = input().split()
        city = SP[0]
        point = int(SP[1])
        restList.append(Rest(city, point, index))

    restList = sorted(restList, key=attrgetter("city"))
    citylistlist = []
    dummylist = [Rest("dummydummydummy",0,1000)]
    citylistlist.append(dummylist)
    for rest in restList:
        if citylistlist[-1][-1].city == rest.city:
            citylistlist[-1].append(rest)
        else:
            citylistlist.append([rest])
    citylistlist.pop(0)


    truelist = []
    for lis in citylistlist:
        truelist = truelist + sorted(lis, key=attrgetter("point"), reverse=True)

    for rest in truelist:
        print(rest.index)



main()

Measured memory_bytes: 3188
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	int i,j;
	int N;
	int count = 0;
	int yakusu = 0;
	cin >> N;

	for (i = 1; i <= N; ++i) {
		if (i % 2 == 1) {
			for (j = 1; j <= N; ++j) {
				if (i%j == 0) {
					++yakusu;
				}
			}
			if (yakusu == 8) {
				++count;
			}
			//cout << yakusu << endl;
			yakusu = 0;

		}

	}
	cout << count << endl;




}



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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var ST1 = cin.ReadInt;
            var ET1 = cin.ReadInt;
            var ST2 = cin.ReadInt;
            var ET2 = cin.ReadInt;

            var duration = cin.ReadInt;

            int minutes1 =ST1 * 60 + ET1;
            int minutes2 = ST2 * 60 + ET2;

            WriteLine(minutes2-minutes1-duration);


        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 27844
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

class UnionFind {
  public:
  // 親の番号を格納。ルートだった場合は-(その集合のサイズ)
  vector<ll> parents;

  UnionFind(ll N) {
    parents = vector<ll>(N, -1);
  }

  // iがどのグループに属しているか
  ll root(ll i) {
    if (parents[i] < 0) {
      return i;
    } else {
      return parents[i] = root(parents[i]);
    }
  }

  // iが属しているグループの大きさ
  ll size(ll i) {
    return -parents[root(i)];
  }

  // root(a)とroot(b)を接続する
  bool connect(ll a, ll b) {
    ll rootA = root(a);
    ll rootB = root(b);
    if (rootA == rootB) {
        return false;
    } else {
      // 大きいほう(a)に小さいほう(b)をくっつける
      // 大小が逆の場合はスワップ
      if (size(rootA) < size(rootB)) {
        swap(rootA, rootB);
      }

      // aグループのサイズを増やす
      parents[rootA] += parents[rootB];
      // bの親をaのルートに変更する
      parents[rootB] = rootA;

      return true;
    }
  }

};

int main() {
  ll N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for (ll i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  vector<ll> ans(M);
  // 橋が全部崩落した
  ans[M-1] = N*(N-1)/2;

  UnionFind Uni(N);
	for (int i = M - 1; i >= 1; i--) {
		ans[i - 1] = ans[i];

		//繋がってなかったのが繋がった時
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}
  for (ll i = 0; i < M; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let vec: Vec<i32> = read_vec();
    let (a, b) = (vec[0], vec[1]);
    if a * b % 2 == 0 {
        println!("Even");
    } else {
        println!("Odd");
    }
}

Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>
#include <iomanip>

using namespace std;

using ll = long long;

typedef pair<int, int> P;

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

static int mod = 1000000007;
static int large = 1000000000;

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

int N;
int a[100001];
int b[100001];
int c[100001];

int dp[100001][3];

inline int change(int x, int i) {
	if (x == 0) return a[i - 1];
	if (x == 1) return b[i - 1];
	if (x == 2) return c[i - 1];
}

int main() {
	cin >> N;
	rep(i, N) {
		cin >> a[i] >> b[i] >> c[i];
	}
	rep(i, 100001) {
		rep(k, 3) {
			dp[i][k] = -1;
		}
	}
	rep(i, 3) {
		dp[0][i] = 0;
	}
	//i日目にjで遊ぶ
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j != k) {
					dp[i][j] = max(dp[i][j], dp[i - 1][k] + change(j, i));
				}
			}
		}
	}
	cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
	return 0;
}



Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
using namespace std;

// Debug Vector
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v)
{
    if (!v.empty())
    {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p)
{
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}

typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> like(m);
    for (int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int a;
            cin >> a;
            like[--a]++;
        }
    }
    int cnt = 0;
    // cout << like << endl;
    for (int i = 0; i < m; i++)
    {
        if (like[i] == n)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int ans[26];
string s;

main() {
    cin >> s;
    rep(i,s.size()) ans[s[i]-'a']++;
    rep(i,26) if (ans[i]%2) {
        ct("No")
        return 0;
    }
    ct("Yes")
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define rrep(i,m,n) for(int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
string K;
ll D;
ll dp[10010][2][110];
ll rec(ll k = 0, ll tight = 1, ll sum = 0){
    if(k == K.size()){
        return (sum == 0);
    }
    ll x = K[k] - '0';
    ll r = tight ? x : 9;
    ll &res = dp[k][tight][sum];
    if(~res) return res;
    res = 0;
    rep(i,0,r+1){
        res += rec(k+1, tight && (i == r), (sum + i) % D) % MOD;
        res %= MOD;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> K;
    cin >> D;
    memset(dp, -1, sizeof(dp));
    ll ans = rec();
    print((ans - 1 + MOD) % MOD);

}


Measured memory_bytes: 18432
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int cases;
	string d[] =  {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	string s;
	cin >> s;
	int d1;
	for(int i = 0; i < 14; i++) {
		if( s == d[i] ) {
			d1 = i;
			break;
		}
	}
	for(int i = d1 + 1; i < 14; i++) {
		if( d[i] == "SUN" ) {
			cout << (i - d1) << "\n";
			break;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int n, m, ck[200000]{};

int main() {
	string ans = "IMPOSSIBLE";
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (a == 0)ck[b]++;
		if (b == 0)ck[a]++;
		if (a == n-1)ck[b]++;
		if (b == n-1)ck[a]++;
	}
	for (int i = 0; i < n; i++) {
		if (ck[i] == 2) {
			ans = "POSSIBLE";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
N, L = list(map(int, input().split()))

s = 0
for n in range(1, N+1):
    s += L + n - 1

for n in range(1, N+1):
    if n == 1:
        m = abs(s - (s - (L + n - 1)))
        ans = s - (L+n-1)
    if m > abs(s - (s - (L+n-1))):
        m = abs(s - (s - (L + n - 1)))
        ans = s - (L+n-1)

print(ans)


Measured memory_bytes: 38256
#include<stdio.h>
#define N 100000
int bs(int*, int, int);

int main(){
  int n, q, k;
  int i, j, num=0;
  int s[N]={0}, t[N][2]={0};

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &s[i]);
  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) scanf("%d", &t[i][0]);

  for( i = 0 ; i < q ; i++){
    if(bs(s, t[i][0], n)!=-1){
      t[i][1] = 1;
    }
  }

  for( j=0 ; j < q ; j++){
    if(t[j][1]==1){
      num++;
    }
  }

  printf("%d\n" ,num);
  return 0; // Don't forget return 0
}

int bs(int* a_p, int key, int n){
  int left  = 0;
  int right = n;
  int mid   = 0;
  while( left < right ){
    mid = (left+right)/2;
    if( key == a_p[mid]){
      return mid;
    }else if( key > a_p[mid]){
      left = mid + 1;
    }else if( key < a_p[mid]){
      right = mid;
    }
  }
  return -1;
}

Measured memory_bytes: 1780
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

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

    while(s.size()){
        s.pop_back();
        if(s.size() % 2 == 1){
            continue;
        }
        int k = (int)(s.size() / 2);
        if(s.substr(0, k) == s.substr(k, k)){
            std::cout<<s.size()<<std::endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int p){
	for(int i=2;i<=sqrt(p);i++){
		if(!p%i)return false;
	}
	return true;
}
//ライブラリ終了
int d,g,p[11],c[11],ans=INF,pr,cnt;
signed main(){
	cin>>d>>g;
	rep(i,d)cin>>p[i]>>c[i];
	for(int i=0;i<(1<<d);i++){
		pr=0,cnt=0;
		rep(j,d){
			if((i>>j)&1){
				cnt+=p[j]*(j+1)*100+c[j];
				pr+=p[j];
			}
		}
		for(int j=d-1;j>=0;j--){
			if(!((i>>j)&1)){
				if(g>cnt){
					if((g-cnt+100*(j+1)-1)/(100*(j+1))<=p[j]){
						pr+=((g-cnt+100*(j+1)-1)/(100*(j+1)));
						cnt+=((g-cnt+100*(j+1)-1)/((j+1)*100)*((j+1)*100));
					}
					else goto lp;
				}
				break;
			}
		}
		if(g<=cnt)ans=min(ans,pr);
		lp:;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)
#define int long long 

int N;
int num[3] = {3,5,7};
int dfs(int n){
    int res = 0;
    if(n > N) return 0;

    int tmp = n;
    bool three = false,five = false,seven = false;
    string s = to_string(n);
    for(char c : s){
        if(c == '3') three = true;
        if(c == '5') five = true;
        if(c == '7') seven = true;
    }
    if(three && five && seven) ++res;
    for(int i=0;i<3;++i) res += dfs(n*10 + num[i]);
    return res;
}

signed main(){
    cin >> N;
    cout << dfs(0) << endl;
}

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

int n, k, q;
bool ans[100100];
vector<int> cnt[100100];
int main()
{
  cin >> n >> k >> q;
  for (int i = 0; i < q; ++i) {
    int x;
    cin >> x;
    --x;
    cnt[x].push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    ans[i] = true;
    int curans = k;
    cnt[i].push_back(q);
    for (int j = 0; j < cnt[i].size() && ans[i]; ++j) {
      if (j == 0) {
        curans -= cnt[i][0];
      } else {
        curans -= cnt[i][j] - cnt[i][j - 1] - 1;
      }
      if (curans <= 0)
        ans[i] = false;
    }
    if (ans[i])
      cout << "Yes";
    else
      cout << "No";
    cout << endl;
  }
}

Measured memory_bytes: 6656
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const double PI = 3.14159265358979323846264338327950;
const LL MOD = 1000000007;

#define PrintLn(X) cout << X << endl
#define Loop(n) for(int loop_ = n; loop_; --loop_)
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int main(void)
{
	LL N, X;
	cin >> N >> X;
	X = min(X, N - X);
	LL Y = N - X;
	LL ans = N;
	while(1){
		if(X == 0){
			ans -= Y;
			PrintLn(ans);
			return 0;
		}
		ans += (Y / X) * X * 2;
		LL nextX = Y % X;
		Y = X;
		X = nextX;
	}
	PrintLn(ans);
	return 0;
}


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

typedef long long int ll;

ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}


int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
    }

    bool now = true;
    ll m = 1000, c = 0, cm = 1000, nm;
    for(ll i = 0;i < n - 1;i++){
        if(now){
            if(a[i] < a[i + 1]){
                cm = a[i];
                c = m / a[i];
                m = m % a[i];
                now = false;
            }
        }
        else{
            if(cm < a[i] && a[i] > a[i + 1]){
                m += a[i] * c;
                c = 0;

                now = true;
            }

        }
    }

    ll ans = 0;
    if(now){
        ans = m;
    }
    else{
        if(a[n - 1] > cm){
            ans = m + c * a[n - 1];
        }
        else{
            ans = m + c * cm;
        }
    }

    cout << ans;


    return 0;
}


Measured memory_bytes: 3624
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n, k = rli()
    ans = 0
    for i in range(1, n+1):
        m = i
        prob = 1.0
        while m < k:
            prob /= 2
            m *= 2
        ans += prob
        # print(i, m, prob)
    ans /= n
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
using namespace std;

int main()
{
	double a, b;
	double c;

	cin >> a;
	b = 0;
	for (int i = 1;i <= a;i++)
	{
		if (i % 2 == 1)
			b++;
	}
	c = b / a;
	cout << setprecision(7)<<c;
	return 0;
}

Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N = read()
cnt = Counter()

for a in reads():
  cnt[a] += 1

edges = sorted([e for e in cnt.keys() if cnt[e] >= 2], reverse=True)

if len(edges) == 0:
  print(0)
else:
  e = edges[0]
  if cnt[e] >= 4:
    print(e*e)
  elif len(edges) <= 1:
    print(0)
  else:
    f = edges[1]
    print(e*f)
    

Measured memory_bytes: 68760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;cin >>n;
vector<ll>a(n+1,2);
a[1] = 1;
ll ans = 0;
for(ll i = 2;i<=n/2;i++){
    ll j = 2;
    while(i*j<=n){
        a[i*j]++;
        j++;
    }
}
for(ll i = 1;i<=n;i++) ans += i*a[i];
cout << ans;
return 0;
}

Measured memory_bytes: 81292
#include<stdio.h>
#include<string.h>
int main(void){
  char s[110];
  int i,k;
  scanf("%s",s);
  k=(strlen(s)-1)/2;
  for(i=0;i<k;i++){
    if(s[i]!=s[k-i]&&s[i]!=s[k+1+i]){puts("No");return 0;}
  }
  puts("Yes");
 return 0; 
}

Measured memory_bytes: 1608
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()
ans = 0
first = T[0]
arrived = 0
for t in T:
    if first + K < t or arrived == C:
        ans += 1
        arrived = 0
        first = t
    arrived += 1
print(ans + (arrived > 0))

Measured memory_bytes: 7384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	string s;
	cin >> s;
	int n = s.size();
	cout << s[0] << n - 2 << s[n - 1] << endl;
	return 0;
}
	

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	ll n,k,q;
	cin>>n>>k>>q;
	vector<ll> a;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	a.pb(-1);
	ll ans = mod;
	for(int i=0;i<n;i++){
		ll mi = a[i];
		vector<ll> ps;
		vector<ll> cur;
		ps.clear();
		cur.clear();
		for(int j=0;j<=n;j++){
			if(mi<=a[j]){
				cur.pb(a[j]);
				//cout<<j<<a[j]<<endl;
			}
			else{
				if(cur.size()>=k){
					sort(cur.begin(),cur.end());
					for(int ii = 0; ii < cur.size()-k+1 ; ii++){
						ps.pb(cur[ii]);
					}
				}
				cur.clear();
			}
		}
		//cout<<i<<endl;
		sort(ps.begin(),ps.end());
		if( ps.size()>=q){
			ll tmp = ps[q-1]-ps[0];
			if(tmp<ans)ans=tmp;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
 	int N,t,cnt=0;
  	cin>>N;
  	
  	if(0<N&&N<10) cout<<N<<endl;
  	else if(10<=N&&N<100)cout<<9<<endl;
  	else if(100<=N &&N<1000) cout<<9+N-99<<endl;
  	else if(1000<=N&&N<10000) cout<<9+900<<endl;
  	else if(10000<=N&&N<100000) cout<<9+900+N-9999<<endl;
	else if(N==100000)cout<<9+900+90000<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<vector<int>> v(n + 1, vector<int>(n - 1, 0));
	vector<vector<pair<int, int>>> index(n + 1, vector<pair<int, int>>(n + 1, make_pair(-1, -1)));
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < n - 1; j++) {
			cin >> v[i][j];
			index[i][v[i][j]] = make_pair(i, j);
		}
	}
	vector<vector<int>> remain(n + 1, vector<int>(n + 1, 0));
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < n - 1; j++) {
			int x = min(i, v[i][j]), y = max(i, v[i][j]);
			remain[x][y]++;
		}
	}
	vector<pair<int, int>> vp1, vp2;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (remain[i][j] == 0) {
				vp1.push_back(make_pair(i, j));
			}
		}
	}
	int res = 0;
	int c = 0;
	while (vp1.size() > 0) {
		vp2.clear();
		res++;
		for (auto p : vp1) {
			c++;
			auto p1 = index[p.first][p.second];
			auto p2 = index[p.second][p.first];
			int x, y;
			if (p1.second + 1 < n - 1) {
				x = min(v[p1.first][p1.second + 1], p1.first);
				y = max(v[p1.first][p1.second + 1], p1.first);
				remain[x][y]--;
				if (remain[x][y] == 0) vp2.push_back(make_pair(x, y));
			}
			if (p2.second + 1 < n - 1) {
				x = min(v[p2.first][p2.second + 1], p2.first);
				y = max(v[p2.first][p2.second + 1], p2.first);
				remain[x][y]--;
				if (remain[x][y] == 0) vp2.push_back(make_pair(x, y));
			}
		}
		vp1 = vp2;
	}
	if (c != n * (n - 1) / 2) 
		cout << -1 << endl;
	else
		cout << res << endl;
}


Measured memory_bytes: 19260
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
signed main(){
	int N,M;
	cin>>N>>M;
	swap(N,M);
	vector<int>A(N);
	for(int i=0;i<N;i++){
		cin >>A[i];
	}
	sort(A.begin(),A.end());
	vector<int> B;
	for(int i=0;i<N-1;i++){
		B.push_back(A[i + 1] - A[i]);
	}
	sort(B.begin(),B.end());
	int res = 0;
	for(int i=0;i<N-M;i++){
		res+=B[i];
	}
	cout << res<<endl;
	return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <cstdio>
using namespace std;

int main(void){
  double mountain,max=0.0,min=100000.0;

  while( scanf("%lf" ,&mountain ) != EOF ){
    if( max < mountain ) max = mountain;
    if( min > mountain ) min = mountain;
  }
  cout << max - min << endl;
  return 0;
}

Measured memory_bytes: 1284
n=int(input())
al=list(map(int,input().split()))
nummin=sum(a<0 for a in al)
asum=0
amin=10**9
for a in al:
  a=abs(a)
  asum+=a
  amin=min(amin,a)
if nummin%2==1:
  ans=asum-2*amin
else:
  ans=asum
print(ans)

Measured memory_bytes: 14332
//400 review
fun b011(args: Array<String>) {
    val numList = args[1].split(" ").map { it.toLong() }.sorted()
    var x = 0
    var sum = 0L
    (0 until numList.size - 1).forEach {
        sum += numList[it]
        if (2 * sum < numList[it + 1]) {
            x = it + 1
        }
    }
    println(numList.size - x)
}

fun main(args: Array<String>) {
    b011(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 59384
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    long long N;

    cin>>N;

    long long ans=to_string(N).size();

    for(long i=2;i*i<=N;++i){
        if(N%i==0){
            long long tmp=to_string(N/i).size();
            ans=min(ans,tmp);
        
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
#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 <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    vector<int> dp(k+1, 0);
    dp[0] = 1;
    for(int i=0; i<n; ++i){
        vector<int> nextDp = dp;
        for(int j=1; j<=k; ++j){
            nextDp[j] += nextDp[j-1];
            nextDp[j] %= MOD;
            if(j - a[i] - 1 >= 0){
                nextDp[j] += MOD - dp[j-a[i]-1];
                nextDp[j] %= MOD;
            }
        }
        dp = move(nextDp);
    }
    cout << dp[k] << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] whn = br.readLine().split(" ");
        int w = Integer.parseInt(whn[0]);
        int h = Integer.parseInt(whn[1]);
        int n = Integer.parseInt(whn[2]);
        boolean[][] shikaku = new boolean[w][h];
        String[] line;
        int x, y, a;
        
        /*
        a i = 1 のときは長方形の x < x i をみたす領域
        a i = 2 のときは長方形の x > x i をみたす領域
        a i = 3 のときは長方形の y < y i をみたす領域 
        a i = 4 のときは長方形の y > y i をみたす領域
        */
        
        for (int i = 0; i < n; i++) {
            line = br.readLine().split(" ");
            x = Integer.parseInt(line[0]);
            y = Integer.parseInt(line[1]);
            a = Integer.parseInt(line[2]);
            
            if (a == 1) {
                for (int j = 0; j < x; j++) {
                    for (int k = 0; k < h; k++) {
                        shikaku[j][k] = true;
                    }
                }
            }
            
            if (a == 2) {
                for (int j = x; j < w; j++) {
                    for (int k = 0; k < h; k++) {
                        shikaku[j][k] = true;
                    }
                }
            }
            
            if (a == 3) {
                for (int j = 0; j < w; j++) {
                    for (int k = 0; k < y; k++) {
                        shikaku[j][k] = true;
                    }
                }
            }
            
            if (a == 4) {
                for (int j = 0; j < w; j++) {
                    for (int k = y; k < h; k++) {
                        shikaku[j][k] = true;
                    }
                }
            }
        }
        
        int ans = 0;
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                if (shikaku[i][j] == false) ans++; 
            }
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 22484
#include<bits/stdc++.h>
#define LL long long
#define DB long double
using namespace std;
#define P 998244353
inline int ad(int x,int y){return (x+y>=P)?(x+y-P):(x+y);}
inline int mt(int x,int y){return 1ll*x*y%P;}
inline void mo(int &x){x=(x>=P)?(x-P):x; x=(x<0)?(x+P):x;}
template<typename T>inline void ckmx(T &x,T y){x=max(x,y);}
template<typename T>inline void ckmi(T &x,T y){x=min(x,y);}
template<typename T>void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-48;
	x*=f;
}
int n,x;
int g[3010][6010];
int f[3010][6010];
int cnt[3010]; 
int c[3010][3010];
void prec(int n){
	for(int i=0;i<=n;++i){
		c[i][0]=1;
		for(int j=1;j<=i;++j)
			mo(c[i][j]=c[i-1][j]+c[i-1][j-1]);
	}
}
int main(){
	read(n);read(x);
	prec(n);
	f[0][0]=1;
	for(int i=1;i<=n;++i){
		f[i][i]=1;
		for(int j=i+1;j<=n+n;++j)
			mo(f[i][j]=f[i-1][j-1]+f[i-1][j-2]);
	}
	for(int i=0;i<x;++i)
		for(int j=0;j<=n;++j)
			mo(cnt[j]+=f[j][i]);
	for(int i=x+1;i<=n+n;i+=2){
		int zs=(i-(x-1))/2;
		if(zs*2>x-1){
			if(x&1) mo(++cnt[i/2]);
			continue;	
		}
		for(int j=zs;j<=n;++j)
			mo(cnt[j+zs]+=f[j-zs][x-1-zs*2]);
	}
	int ans=0;
	for(int i=0;i<=n;++i)
		mo(ans+=mt(cnt[i],c[n][i]));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 105472
def main():
    n, m = map(int, input().split())
    x = list(map(int, input().split()))

    if m <= n:
        print(0)
        return

    x.sort()
    d = []
    for i in range(m-1):
        d.append(abs(x[i+1]-x[i]))

    d.sort()

    print(sum(d[0:(m-n)]))
    return


if __name__ == '__main__':
    main()

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

int main(){
  int N;
  cin >> N;
  vector<long>L(N+1);
  L.at(0)=2;
  L.at(1)=1;

  if(N==1){
    cout << L.at(1) << endl;
  }
  else{
    for(int i=1;i<N;i++){
      L.at(i+1)=L.at(i)+L.at(i-1);
    }
    cout << L.at(N) << endl;
  }
}


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

#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define ll long long
template<typename T, typename U> 
static inline void amin(T &x, U y){
	if(x>y)
		x = y;
}
template<typename T, typename U> 
static inline void amax(T &x, U y){
	if(x<y)
		x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define irep(i,k,n) for(int i = k; i <= n; ++i)
#define irepr(i,k,n) for(int i = k; i >= n; --i)

int inf = 2e9+5;
ll INF = 2e18L+15;
const int mod = 1e9+7;

int main(){
	int n;
	string s;
	cin >> n>> s;
	int dp[n+2][n+2];
	memset(dp,0,sizeof(dp));
	vi pref(n+2,0);
	irep(j,1,n){
		pref[j] = 1;
	}
	dp[1][1] = 1;
	for(int len = 2; len <= n; ++len){
		for(int j = 1; j <= len; ++j){
			if(s[len-2]=='<'){
				dp[len][j] = (pref[j-1] - pref[0] + mod)%mod;
			}else{
				dp[len][j] = (pref[len-1] - pref[j-1] + mod)%mod;
			}
		}
		for(int j=1;j<=n;++j){
			pref[j] = (pref[j-1] + dp[len][j])%mod;
		}
	}
	cout<<pref[n]<<endl;
	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    bool ans=false;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(n==i*j) ans=true;
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

ll mod_pow(ll n, ll p, ll mod=MOD) {
    if(p==0) return 1;
    ll res = mod_pow(n*n%mod, p/2, mod);
    if(p%2==1) res = res * n % mod;
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int k;
	cin >> k;
    if(k%2==0) {
        cout << -1 << "\n";
        return 0;
    }
    int ans = 0, now = 0;
    while (true) {
        now += mod_pow(10, ans, k) * 7;
        now %= k;
        ans++;
        if (now==0) break;
        if (ans>k) {
            cout << -1 << "\n";
            return 0;
        }
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;

typedef long long ll;

int main() {
    ll N;cin>>N;
    ll B = (int)sqrt(N);
    pair<ll,ll> hoge;
    for(int i = B; i > 0; i--){
        if(N%i == 0){
            hoge = make_pair(i, N/i);
            break;
        }
    }
    ll ans = hoge.first - 1 + hoge.second -1;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a, b;
  cin >> a >> b;
  int c, d;
  c = a % 2;
  d = b % 2;
  
  if (c == 1 && d == 1) {
    cout << "Odd" << endl;
  }
  
  else {
    cout << "Even" << endl;
  }
}

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

int main() {
    string s;
    int n,k;
    cin >> n >> s >> k;
    for(int i=0;i<n;i++){
        if(s.at(i)!=s.at(k-1)){
            s.at(i)='*';
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n;
	cin>>n;
	ll a[100];
	for(ll i=0;i<n;i++){
		ll now;
		cin>>a[i];
	}
	for(ll i=1;i<n;i++){
		a[i]=a[i-1]+a[i];
	}
	ll ans=INF;
	for(ll i=0;i<n;i++){
		ll l=a[i];
		ll r=a[n-1]-l;
		ans=min(ans,abs(l-r));
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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


int main() {
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s < t)cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
from itertools import combinations

N = int(input())

cnt = [0 for i in range(5)]
march = "MARCH"
for i in range(N):
    s = input()
    if s[0] in march:
        cnt[march.find(s[0])] += 1

ans = 0
for c in combinations(cnt,3):
    ans += c[0]*c[1]*c[2]
print(ans)

Measured memory_bytes: 3064
from heapq import heappush, heappop
def inpl(): return list(map(int, input().split()))

Q = int(input())
L = []
R = []

B = 0
M = 0

for _ in range(Q):
    q = inpl()
    if len(q) == 3:
        B += q[2]
        if len(R) == 0:
            L.append(-q[1])
            R.append(q[1])
            continue

        M += min(abs(-L[0] - q[1]), abs(R[0] - q[1])) * (not (-L[0] <= q[1] <= R[0]))
        if q[1] < R[0]:
            heappush(L, -q[1])
            heappush(L, -q[1])
            heappush(R, -heappop(L))
        else:
            heappush(R, q[1])
            heappush(R, q[1])
            heappush(L, -heappop(R))
    else:
        print(-L[0], B+M)


Measured memory_bytes: 19084