akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <utility>
static const int MAXN = 5e5 + 4;
#define double long double

int n, l;
int t[MAXN], v[MAXN];

int qhead, qtail;
std::pair<double, double> q[MAXN];
std::pair<double, double> offset;

double eval_linear(std::pair<double, double> p, std::pair<double, double> q, double x)
{
    double ratio = (x - p.first) / (q.first - p.first);
    return p.second * (1.0 - ratio) + q.second * ratio;
}

int main()
{
    scanf("%d%d", &n, &l);
    for (int i = 0; i < n; ++i) scanf("%d%d", &t[i], &v[i]);

    qhead = MAXN - 2, qtail = MAXN;
    q[MAXN - 2] = std::make_pair(0, 0);
    q[MAXN - 1] = std::make_pair(v[0], (double)v[0] * t[0]);
    offset = std::make_pair(0, 0);
    printf("%.8Lf\n", (double)t[0]);

    for (int i = 1; i < n; ++i) {
        offset.first += v[i];
        while (qtail > qhead + 1 && q[qtail - 2].first + offset.first > l) --qtail;
        q[qtail - 1] = std::make_pair(l - offset.first, eval_linear(q[qtail - 2], q[qtail - 1], l - offset.first));
        offset.second += (double)v[i] * t[i];
        int lo = qhead, hi = qtail, mid;
        while (lo < hi - 1) {
            mid = (lo + hi) >> 1;
            if ((q[mid].second + offset.second) / (q[mid].first + offset.first)
                >= (q[mid - 1].second + offset.second) / (q[mid - 1].first + offset.first)) lo = mid;
            else hi = mid;
        }
        qhead = lo;
        q[--qhead] = std::make_pair(-offset.first, -offset.second);
        printf("%.8Lf\n", (q[qtail - 1].second + offset.second) / l);
    }

    return 0;
}


Measured memory_bytes: 28928
def main():
    n, x, y = map(int, input().split())
    distances = [0 for _ in range(n)]
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            distances[min(j-i, min(abs(i-x)+abs(j-y), abs(j-x)+abs(i-y))+1)] += 1

    for v in distances[1:]:
        print(v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
signed main(){
int a,b,c,d;
  int z=0;
  cin>>a>>b>>c>>d;
 if(a==1 || a==3 || a==5 || a==7 || a==8 || a==10 || a==12){
	if(b==31){
	z++;
    }
 }else if(a==4 || a==6 || a==9 || a==11){
	if(b==30){
	z++;
	}
 }else if(a==2 && b==28){
	z++;
 }
 if(z>0) cout<<"1\n";
 else cout<<"0\n";
}

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

int main()
{
	long long numA, numB, numC, numD;
	cin >> numA >>numB >> numC >> numD;

	//   a b c d
	//   + + + + : bd
	//   - + + + : bd
	//   - - + + : bc
	//   + + - + : bd
	//   - + - + : bd or ac 
	//   - - - + : ac
	//   + + - - : ad
	//   - + - - : ad
	//   - - - - : bd

	long long ansAC, ansAD, ansBC, ansBD;
	ansAC = numA * numC;
	ansAD = numA * numD;
	ansBC = numB * numC;
	ansBD = numB * numD;

	long long ans = ansAC;
	ans = (ans < ansAD) ? ansAD : ans;
	ans = (ans < ansBC) ? ansBC : ans;
	ans = (ans < ansBD) ? ansBD : ans;

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

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b;
  cin >> a >> b;
  cout << max(0, a-b) <<endl;
}

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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return x;}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in(),K=in();
	auto H=vecin(N);
	vll dp(N,1ll<<60);
	dp[0] = 0;

	REP(i,N-1){
		REP(j,K){
			if(i+1+j<N) chmin(dp[i+1+j],dp[i]+abs(H[i]-H[i+1+j]));
		}
	}
	out(dp[N-1]);
	return 0;
}


Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
const int N=100005,mod=1e9+7;
int n,r,a[N],d[N],f[N],q[N],qq[N],vis[N],cnt[N],dp[N];
vector<int>g[N],G[N];
int fnd(int x){return f[x]==x?x:f[x]=fnd(f[x]);}
int uni(int u,int v){u=fnd(u);v=fnd(v);f[u]=v;}
int gt(int x)
{
	int t=vis[g[x][0]]?g[x][1]:g[x][0],cc=1;
	while(g[t].size())
	{
		if(g[t].size()>=2){puts("0");exit(0);}
		cc++,t=g[t][0];
	}
	return cc;
}
int main()
{
	scanf("%d",&n);r=1;
	for(int i=1;i<=n;i++)f[i]=i;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),g[a[i]].push_back(i),d[a[i]]++,uni(i,a[i]);
	for(int i=1;i<=n;i++)if(d[i]>2){puts("0");return 0;}
	for(int i=1;i<=n;i++)G[fnd(i)].push_back(i);
	for(int t=1;t<=n;t++)if(G[t].size())
	{
		int m=G[t].size(),mx=d[G[t][0]],mxi=G[t][0];
		for(int i=1;i<m;i++)if(mx<d[G[t][i]])mx=d[G[t][i]],mxi=G[t][i];
		if(mx==1)cnt[m]++;
		else
		{
			int x=mxi,tt=0,cc=0;
			while(!vis[x])vis[x]=1,q[++tt]=x,x=a[x];
			for(int i=1;i<=tt;i++)if(d[q[i]]==2)qq[++cc]=i;
			for(int i=1;i<=cc;i++)
			{
				int pre=(i==1?cc:i-1),dis=(i==1?qq[i]-qq[cc]+tt:qq[i]-qq[i-1]),sz=gt(q[qq[i]]);
				if(dis>sz)r=r*2%mod;else if(dis<sz)r=0;
			}
		} 
	}
	for(int i=1;i<=n;i++)if(cnt[i])
	{
		int c=(i&1?2:1);if(i==1)c=1;dp[0]=1;dp[1]=c;
		for(int j=2;j<=cnt[i];j++)dp[j]=(dp[j-1]*c%mod+1ll*dp[j-2]*(j-1)%mod*i%mod)%mod;
		r=1ll*r*dp[cnt[i]]%mod;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 13824
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void)
{		
	while (1) {
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0) break;
				
		for (int k = 1; k <= w; k++) {
			cout << "#";
		}
		cout << "\n";
		
		for (int i = 2; i <= h - 1; i++) {
			cout << "#";
			for (int j = 2; j <= w - 1; j++) {
				cout << ".";
			}
			cout << "#";
			cout << "\n";
		}
		
		for (int k = 1; k <= w; k++) {
			cout << "#";
		}
		cout << "\n";
		
		cout << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 3072
import java.util.*;

class Main {
    private static Scanner scan = new Scanner(System.in);

    public static void out(int num) {
        System.out.println(num);
    }

    public static void main(String[] args) {

        int n = scan.nextInt();
        String str = scan.next();
        int max = 0;

        for (int i = 0; i < (n - 1); i++) {
            String cut1 = str.substring(0, n - i);
            String cut2 = str.substring(n - i);

            HashSet<String> has1 = new HashSet<String>();
            for (int j = 0; j < cut1.length(); j++) {
                has1.add((String.valueOf(cut1.charAt(j))));
            }
            // ArrayList<String> list1 = new ArrayyList<String>(has1);

            HashSet<String> has2 = new HashSet<String>();
            for (int j = 0; j < cut2.length(); j++) {
                has2.add((String.valueOf(cut2.charAt(j))));
            }
            // ArrayList<String> list2 = new ArrayyList<String>(has2);

            has1.retainAll(has2);
            if (has1.size() > max) {
                max = has1.size();
            }
        }
        out(max);
    }
}

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

// 入力
int N, M, Q;
vector<long long> a, b, c, d;

// 数列 A のスコアを計算
long long score(const vector<int> &A) {
    long long res = 0;
    for (int i = 0; i < Q; ++i) if (A[b[i]] - A[a[i]] == c[i]) res += d[i];
    return res;
}

// 数列 A に要素を付け加えて行って、最終的にできる数列のうちの
// スコアの最大値を返す
// 特に、最初の呼出しに対する返り値が答え
long long dfs(vector<int> &A) {
    if (A.size() == N) {
        return score(A);
    }
    long long res = 0;
    int prev_last = (A.empty() ? 0 : A.back());
    for (int add = prev_last; add < M; ++add) {
        A.push_back(add);
        res = max(res, dfs(A)); // 再帰呼出しながら、スコア最大値を更新
        A.pop_back();
    }
    return res;
}

int main() {
    cin >> N >> M >> Q;
    a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
    for (int q = 0; q < Q; ++q) {
        cin >> a[q] >> b[q] >> c[q] >> d[q];
        --a[q], --b[q];
    }
    vector<int> A;
    cout << dfs(A) << endl;
}

Measured memory_bytes: 3660
n = int(input())
x = range(n)
P =[]
n = 0
for _ in x:P += [[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:n += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(n*0.5)

Measured memory_bytes: 7720
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var w = int.Parse(line[0]);
        var h = int.Parse(line[1]);
        var c = int.Parse(line[2]);
        var g = Gcd(w, h);
        Console.WriteLine(w * h * c / (g * g));
    }
    public static int Gcd(int a, int b)
    {
        if (a < b)      return Gcd(b, a);
        while (b != 0)
        {
            var temp = a % b;
            a = b;
            b = temp;
        }
        return a;
    }
}

Measured memory_bytes: 9236
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

m = 2*10**5+10
ans = [0] * m
for i in range(1,m):
    nnow = i
    res = 0
    stnow = bin(nnow).count('1')
    while nnow:
        # print(nnow)
        nnow %= stnow
        stnow = bin(nnow).count('1')
        res += 1
    ans[i] = res
# for i in range(10):
#     print(i,ans[i])
n = inp()
s = list(input())
tmp = s.count('1')
stm = tmp-1
stp = tmp+1
numm = 0
nump = 0
for i,x in enumerate(s):
    if x == '1': 
        nump += pow(2,n-i-1,stp)
        nump %= stp
        if stm > 0:
            numm += pow(2,n-i-1,stm)
            numm %= stm

for i in range(n):
    if s[i] == '0':
        nnow = (nump+pow(2,n-i-1,stp))%stp
    else:
        if stm <= 0:
            print(0)
            continue
        nnow = (numm-pow(2,n-i-1,stm))%stm
    # print(nnow)
    print(ans[nnow]+1)


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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

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

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    string str; cin >> str;
    int q; cin >> q;
    REP(i, q)
    {
        string order; cin >> order;
        int a, b; cin >> a >> b;
        if(order == "print") cout << str.substr(a, b-a+1) << endl;
        else if(order == "reverse") reverse(str.begin()+a, str.begin()+b+1);
        else
        {
            string p; cin >> p;
            str.replace(str.begin()+a, str.begin()+b+1, p);
        }
    }
}


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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k, a, b;
  cin >> k >> a >> b;
  bool ans = false;
  for(int i = a; i <= b; i++){
    if(i%k == 0){
      ans = true;
      break;
    }
  }
  if(ans){
    cout << "OK";
  }else{
    cout << "NG";
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
int main(){
  int n,m,a[100001],d[100001],r=0,i=0;
  std::cin>>n>>m;
  while(std::cin>>a[i])i++;
  std::sort(a, a+m);
  for(int i=0;i<m-1;++i)d[i]=a[i+1]-a[i];
  std::sort(d, d+m-1);
  for(int i=0;i<m-n;++i)r+=d[i];
  std::cout<<r<<"\n";
}

Measured memory_bytes: 1024
#include<unistd.h>
char s[1111];
int main(){
	int l = read(0, s, 1111);
	if(s[l-2]=='s'){
		l++;
		s[l-2] = 'e';
	}
	s[l-1] = 's';
	write(1, s, l);
	return 0;
}

Measured memory_bytes: 1388
using System; 
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq; 
using E = System.Linq.Enumerable; 


class Program {
    static bool[,] cost;
    static void Main(string[] args) {
        //var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var S = Console.ReadLine();
        var N = S.Length; 
       // Console.WriteLine(N);
        var mod = 2019;
        var res = new long[2019];
        res[0] = 1;
        
        var ten = 1; 
        long sum = 0;
        //1の倍数の余りを登録
        int num1 = S[N-1] - '0';
        sum += num1;
        res[sum]++;
        long ans = 0;
        for(long i = N -2;i >= 0;i--){
            int num = S[(int)i]- '0';
            ten *= 10;
            ten %= mod;
            sum += ((num*ten)%mod);
            sum %= mod;
            ans += res[sum];
           
            res[sum]++;
        }
        Console.WriteLine(ans);
     }
}
     





     
             




Measured memory_bytes: 26436
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

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

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m; cin >> n >> m;
	int ans = 0;
	ans += n * (n - 1) / 2;
	ans += m * (m - 1) / 2;
	cout << ans << endl;
}

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

int debug = 0;

main() {
    int n, ans = 0;
    cin >> n;
    n--;
    rep(a, 1, n+1) {
        ans += (n / a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
  std::cout << std::setprecision(20) << std::fixed;

  int n; cin >> n;
  vector<int> x(n), y(n);

  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    a[i] = i;
  }
  double ans = 0;

  do {
    double sum = 0;
    for (int k = 0; k < n-1; k++) {
      int i = a[k], j = a[k+1];
      int dx = x[i]-x[j];
      int dy = y[i]-y[j];
      sum += sqrt(dx*dx + dy*dy);
    }
    ans += sum;
  } while (next_permutation(a.begin(), a.end()));

  for (int i = 1; i <= n; i++) {
    ans /= i;
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;
const long long INF = 1LL <<60;

int main(void){
  long long n;
  long long i,j,k;
  string tmp;
  long long res[4]={};
  string comp[4]={"AC","WA","TLE","RE"};
  cin>>n;
  
  for(i=0;i<n;i++){
    cin>>tmp;
    if(tmp==comp[0]){
      res[0]++;
    }
    else if(tmp==comp[1]){
      res[1]++;
    }
    else if(tmp==comp[2]){
      res[2]++;
    }
    else{
      res[3]++;
    }
  }

  cout<<"AC x "<<res[0]<<endl;
  cout<<"WA x "<<res[1]<<endl;
  cout<<"TLE x "<<res[2]<<endl;
  cout<<"RE x "<<res[3]<<endl;
  
  return 0;
  
}    


Measured memory_bytes: 3628
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int N;
    cin >> N;

    N %= 1000;

    if (N > 0) N = 1000 - N;

    cout << N << endl;

    return 0;
}

Measured memory_bytes: 3608
// Bismillah .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e6+5;
bool flag[mx];
int a[200005];
 map<int,int>mp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,coun=0;
    cin>>n;
    for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            mp[a[i]]++;
        }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        if(mp[a[i]]>1)
            flag[a[i]] = true;
    }
    for(int i=1;i<=n;i++)
    {
        if(!flag[a[i]])
            coun++;

        if(a[i]!=a[i-1])
        {

            for(int j= a[i]*2;j<=mx;j+=a[i])
            flag[j] = true;
        }
    }
    cout<<coun<<endl;
    return 0;
}


Measured memory_bytes: 14636
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	while(scan.hasNext())
	    {
		int a,b;
		a=scan.nextInt();
		b=scan.nextInt();
		System.out.println(a+b);
	    }
    }
}

Measured memory_bytes: 20356
from itertools import permutations
import copy

def resolve():
    N, M = list(map(int, input().split()))
    G = [[0] * N for _ in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        G[a-1][b-1] = 1
        G[b-1][a-1] = 1

    ls = list(permutations(range(1, N)))
    ans = 0
    for l in ls:
        h = copy.deepcopy(G)
        cnt = 1
        p = 0 
        for k in l:
            if h[p][k] == 0:
                break
            else:
                cnt += 1
                p = k
        if cnt == N:
            ans += 1
    print(ans)
    return

resolve()

Measured memory_bytes: 9632
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;

int main(int argc, char const* argv[])
{
    string S;
    cin >> S;
    ll ans[S.length()];
    rep(i,S.length()){
        ans[i] = 0;
    }
    ans[0] = 0;
    ans[S.length()-1] = 0;
    ll cnt = 0;
    for(int i = 0; i < S.length()-1 ; i++){
        if(S[i] == 'R'){
            cnt++;
        }
        if(S[i] == 'R' && S[i+1] == 'L'){
            ans[i] =  cnt/2 + cnt%2;
            ans[i+1] =  cnt/2;
            cnt = 0;
        }
    }
    cnt = 0;
    for(int i = S.length() -1; i > 0 ; i--){
        if(S[i] == 'L'){
            cnt++;
        }
        if(S[i] == 'L' && S[i-1] == 'R'){
            ans[i] += cnt/2 + cnt%2;
            ans[i-1] += cnt/2;
            cnt = 0;
        }
    }

    rep(i,S.length()){
        cout << ans[i] << endl;
    }
    return 0;
}


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

int main() {
 int n;
 cin >> n;
 vector<int> v(n);
 for(int i= 0;i<n;i++){
   cin >> v[i];
 }
  bool flag = true;
  int a = 1;
  for(int i= 0;i<n-1;i++){
    if(v[i] == v[i+1]) a++;
  }
  if(a == n) flag = false;
  if(flag){
  vector<int> v0(n/2);//vの偶数番目の項の列
  vector<int> v1(n/2);//vの奇数番目の項の列
  for(int i= 0;i<n;i++){
   if(i%2 == 0){
     v0[i/2] = v[i];
   }
    if(i%2 == 1){
      v1[i/2] = v[i];
    }
  }
  
  sort(v0.begin(),v0.end());
  sort(v1.begin(),v1.end());
  v0.push_back(0);
  v1.push_back(0);
  vector<pair<int,int>> p0;
  vector<pair<int,int>> p1;
  
  int c = 1;
  for(int i= 0;i<n/2;i++){
   if(v0[i] == v0[i+1]){
      c++;
      }
    else if(v0[i] != v0[i+1]){
      p0.push_back(make_pair(c,v0[i]));
      c = 1;
    }
  }

  int d = 1;
  for(int i= 0;i<n/2;i++){
   if(v1[i] == v1[i+1]){
      d++;
      }
    else if(v1[i] != v1[i+1]){
     p1.push_back(make_pair(d,v1[i]));
      d = 1;
    }
  }

  sort(p0.begin(),p0.end());
  reverse(p0.begin(),p0.end());
  sort(p1.begin(),p1.end());
  reverse(p1.begin(),p1.end());

  
  v0.pop_back();
  v1.pop_back();
  int ans = 0;
  
  if(p0[0].second != p1[0].second){
    ans += v0.size()-p0[0].first;
    ans += v1.size()-p1[0].first;
  }
  
  else if(p0[0].second == p1[0].second){
    int ans1 = n/2 - p0[0].first +n/2 -p1[1].first;
    int ans2 = n/2 - p0[1].first + n/2 -p1[0].first;
    ans = min(ans1,ans2);
   
    }
    cout << ans << endl;
  }
  
  else cout << n/2 << endl;
}


Measured memory_bytes: 2164
#include<stdio.h>
#include<math.h>
double Koch(int,double,double,double,double);
int main()
{
  int n;
  scanf("%d",&n);
  printf("%.8f %.8f\n",0.0,0.0);
  Koch(n,0,0,100,0);
  printf("%.8f %.8f\n",100.0,0.0);
  return 0;
}

double Koch(int n,double leftx,double lefty,double rightx,double righty)
{
  if(n!=0){
  double santou[3][2];
  santou[0][0]=(2*leftx+rightx)/3;
  santou[0][1]=(2*lefty+righty)/3;
  santou[2][0]=(leftx+2*rightx)/3;
  santou[2][1]=(lefty+2*righty)/3;

  santou[1][0]=(santou[2][0]-santou[0][0])/2-(santou[2][1]-santou[0][1])*sqrt(3)/2+santou[0][0];
  santou[1][1]=(santou[2][0]-santou[0][0])*sqrt(3)/2+(santou[2][1]-santou[0][1])/2+santou[0][1];
  
Koch(n-1,leftx,lefty,santou[0][0],santou[0][1]);
  printf("%.8f %.8f\n",santou[0][0],santou[0][1]);
  Koch(n-1,santou[0][0],santou[0][1],santou[1][0],santou[1][1]);
  printf("%.8f %.8f\n",santou[1][0],santou[1][1]);
  Koch(n-1,santou[1][0],santou[1][1],santou[2][0],santou[2][1]); 
  printf("%.8f %.8f\n",santou[2][0],santou[2][1]);
  Koch(n-1,santou[2][0],santou[2][1],rightx,righty); 
  }
  if(n==0)return 0;
  
}

Measured memory_bytes: 640
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m;
string s;

int main() {
	cin >> n>> m;
	int a = n + m;
	a = max(a, n - m);
	a = max(a, n*m);
	cout << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	string s;
	int k = 0;
	cin >> s >> k;
	int n = s.size();
	vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(k + 2, vector<ll>(2)));
	dp[0][0][1] = 1;
	int f = s[0] - '0';
	dp[0][1][1] = f - 1;
	dp[0][1][0] = 1;
	for (int i = 0; i < n - 1; ++i) {
		//i -> i + 1
		int next = s[i + 1] - '0';
		for (int now = 0; now <= 9; ++now) {
			for (int kk = 0; kk <= k; ++kk) {
				for (bool sm : {0, 1}) {
					if (sm == 0 && now > next) {
						continue;
					}
					int new_k = (now == 0 ? kk : kk + 1);
					int new_sm = -1;
					if (now < next) {
						new_sm = 1;
					} else {
						new_sm = sm;
					}
					dp[i + 1][new_k][new_sm] += dp[i][kk][sm];
				}
			}
		}
		//~ for (int kk = 0; kk <= k; ++kk) {
			//~ dp[i + 1][kk + 1][1] += dp[i][kk][1] * 9;
			//~ dp[i + 1][kk][1] += dp[i][kk][1];
			//~ dp[i + 1][kk + 1][1] += dp[i][kk][0] * (next - 1);
			//~ if (next != 0) {
				//~ dp[i + 1][kk][1] += dp[i][kk][0];
			//~ }
			//~ if (next != 0) {
				//~ dp[i + 1][kk + 1][0] += dp[i][kk][0];
			//~ } else {
				//~ dp[i + 1][kk][0] += dp[i][kk][0];
			//~ }
		//~ }
	}
	cout << dp[n - 1][k][0] + dp[n - 1][k][1] << '\n';
 	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int Q = Integer.parseInt(st.nextToken());
        String S = br.readLine();
        int[] arr = new int[N];
        for (int i=0; i<N-1; i++) {
            if (S.charAt(i)=='A' && S.charAt(i+1)=='C') {
                arr[i+1]++;
            }
        }
        int[] psa = new int[N];
        fillPrefixSum(arr,N,psa);
        for (int i=0; i<N; i++) {
            //System.out.println(psa[i]);
        }
        for (int i=0; i<Q; i++) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            System.out.println(psa[b-1]-psa[a-1]);
        }
    }
    static void fillPrefixSum(int array[], int n, int prefixSum[])
    {
        prefixSum[0] = array[0];
        for( int i = 1; i < n; ++i )
            prefixSum[i] = prefixSum[i-1] + array[i];
    }
}


Measured memory_bytes: 61680
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define MAX 15
#define INF 1<<28
int n;
int d[MAX][MAX];
int dp[1<<MAX][MAX];
//s=?¨??????????,v=?????¨??????
int rec(int s,int v){
  if(dp[s][v]>=0)return dp[s][v];
  if(s==(1<<n)-1&&v==0)return dp[s][v]=0;
  int res=INF;
  for(int u=0;u<n;u++)
    if(!(s>>u&1))
      res=min(res,rec(s|1<<u,u)+d[v][u]);
  return dp[s][v]=res;
}
int main(){
  memset(dp,-1,sizeof(dp));
  r(i,MAX)r(j,MAX)d[i][j]=INF;
  int m;
  cin>>n>>m;
  while(m--){
    int s,t,dd;
    cin>>s>>t>>dd;
    d[s][t]=dd;
  }
  int p=rec(0,0);
  if(p==INF)p=-1;
  cout<<p<<endl;
}

Measured memory_bytes: 5016
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	double T, X;
	cin >> T >> X;
	cout << T / X << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int mo = 1e9 + 7;

ll ksm(ll x, ll y) {
	ll s = 1;
	for(; y; y /= 2, x = x * x % mo)
		if(y & 1) s = s * x % mo;
	return s;
}

const int N = (1 << 16) + 5;

int a2[20];
int n, m, a[20];
ll fac[N], nf[N];
ll f[2][N][17]; int o;

void build(int n) {
	fac[0] = 1; fo(i, 1, n) fac[i] = fac[i - 1] * i % mo;
	nf[n] = ksm(fac[n], mo - 2); fd(i, n, 1) nf[i - 1] = nf[i] * i % mo;
}

ll C(int n, int m) {
	if(n < m || m < 0) return 0;
	return fac[n] * nf[n - m] % mo * nf[m] % mo;
}

int main() {
	a2[0] = 1; fo(i, 1, 16) a2[i] = a2[i - 1] * 2;
	scanf("%d %d", &n, &m);
	build(1 << n);
	fo(i, 1, m) scanf("%d", &a[i]);
	sort(a + 1, a + m + 1);
	f[0][0][0] = 1;
	fd(i, m, 1) {
		memcpy(f[!o], f[o], sizeof f[o]);
		ff(j, 0, a2[n]) fo(k, 0, m) if(f[o][j][k]) {
			fo(u, 0, n - 1)  if(!(j >> u & 1)) {
				int nj = j | a2[u], nk = k + 1;
				f[!o][nj][nk] = (f[!o][nj][nk] - f[o][j][k] * C(a2[n] - a[i] - j, a2[u] - 1) % mo * fac[a2[u]]) % mo;
			}
		}
		o = !o;
	}
	ll ans = 0;
	ff(j, 0, a2[n]) fo(k, 0, m) if(f[o][j][k]) {
		ans = (ans + f[o][j][k] * fac[a2[n] - 1 - j]) % mo;
	}
	ans = (ans % mo + mo) * a2[n] % mo;
	pp("%lld\n", ans);
}

Measured memory_bytes: 18688
import collections
N = int(input())
a = list(map(int,input().split()))
cnt = 0
ans = []
item = []
for i in range(N):
    ans.append(a[i]-1)
    ans.append(a[i])
    ans.append(a[i]+1)

c = collections.Counter(ans)
d = c.most_common()

# for i in range(N):
#     for j in range(N):
#         item.append(a[i][j])



print(d[0][1])

Measured memory_bytes: 30932
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;

  cout << max(0, c - (a - b)) << endl;
  return 0;
}


Measured memory_bytes: 256
//fpc 3.0.4

program bt;

var i,j,k,n,t:longint;
    a        :array[1..1000000] of longint;

begin 
   readln(n);
   for i:=1 to n-1 do
    read(a[i]);
   readln(a[n]);
   t:=0;
   for i:=1 to n-2 do
    for j:=i+1 to n-1 do
     for k:=j+1 to n do
      if (a[i]+a[j]>a[k]) and (a[i]+a[k]>a[j]) and (a[j]+a[k]>a[i]) and (a[i]<>a[j]) and (a[j]<>a[k]) and (a[i]<>a[k]) then
       inc(t);
   write(t);
end.
       


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

int main(){
    int n,t;
    cin >> n >> t;
    int c,s;
    int mini = 1001;
    for (int i = 0; i < n; i++){
        cin >> c >> s;
        if (s <= t){
            mini = min(mini,c);
        }
    }
    if (mini == 1001){
        cout << "TLE" << endl;
    }else{
        cout << mini << endl;
    }
}

Measured memory_bytes: 256
H, W = list(map(int,input().split()))
l=[]
for i in range(H):
    l.append(list(input()))
ans=[[0 for i in range(W)] for j in range(H)]
for i in range(H):
    for j in range(W):
        for dx, dy in [(1,0), (0, 1), (0 , -1 ), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]:
            try:
                if j+dx < 0 or i+dy< 0:
                    continue
                if l[i+dy][j+dx]=='#':
                    ans[i][j] += 1
            except:
                pass
for i in range(H):
    for j in range(W):
        if l[i][j]=='#':
            ans[i][j] = '#'
for i in range(H):
    for j in range(W):
        print(ans[i][j],end='')
    print()



Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N;
int L[112345], R[112345];

int main() {
	cin >> N;
	REP(i, N) scanf("%d %d", L + i, R + i), --L[i];
	
	vector<pii> itv;
	REP(i, N) itv.emplace_back(L[i], R[i]);
	sort(ALL(itv));
	
	ll ans = 0;
	vector<pii> sumpre(N + 1, pii(-1, INF)), sumsuf(N + 1, pii(-1, INF));
	REP(i, N) {
		chmax(sumpre[i + 1].fi, max(sumpre[i].fi, itv[i].fi));
		chmin(sumpre[i + 1].se, min(sumpre[i].se, itv[i].se));
	}
	for (int i = N - 1; i >= 0; --i) {
		chmax(sumsuf[i].fi, max(sumsuf[i + 1].fi, itv[i].fi));
		chmin(sumsuf[i].se, min(sumsuf[i + 1].se, itv[i].se));
	}
	
	REP(i, N + 1) { // [0, i), [i, N)
		ll cur = 0;
		if (sumpre[i].fi != -1) cur += max(sumpre[i].se - sumpre[i].fi, 0);
		if (sumsuf[i].fi != -1) cur += max(sumsuf[i].se - sumsuf[i].fi, 0);
		chmax(ans, cur);
	}
	REP(i, N) {
		ll cur = itv[i].se - itv[i].fi;
		ll cl = -1, cr = INF;
		
		chmax(cl, sumpre[i].fi);
		chmin(cr, sumpre[i].se);
		
		chmax(cl, sumsuf[i + 1].fi);
		chmin(cr, sumsuf[i + 1].se);
		cur += max(cr - cl, 0ll);
		
		chmax(ans, cur);
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vec vector<int>
#define vecll vector<ll>
#define pb(x) push_back(x)

using namespace std;
///////////////////////////////////////////////////////////



int main() {
    int n, m;
    cin >> n >> m;
    int s[m], c[m];
    vec anss;
    rep(i, n)
        anss.pb(-1);
    int ans = 0;

    rep(i, m) {
        cin >> s[i] >> c[i];
        if (n != 1 && s[i] == 1 && c[i] == 0)
            ans = -1;
        else if (anss[s[i]-1] == -1 || anss[s[i]-1] == c[i])
            anss[s[i]-1] = c[i];
        else
            ans = -1;
    }

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

    ans = 0;
    int base = 1;
    for (int i = n-1; i >= 0; i--) {
        if (anss[i] == -1) {
            if (i == 0 && n != 1)
                anss[i] = 1;
            else
                anss[i] = 0;
        }
        ans += anss[i] * base;
        base *= 10;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools
import numpy as np
import copy


ansl = []
N, A, B, C = list(map(int, input().split()))

a = []
for i in range(N):
    a.append(int(input()))

def get_ptn(la):
    ptn = []
    for i in range(1, len(la) + 1):
        ptn.append(list(itertools.combinations(la, i)))
    return ptn

takes = list(itertools.permutations([A, B, C]))

for take in takes:
    # print(take)
    # print(a)
    try:
        ta = copy.deepcopy(a)
        ans = 0
        for k in range(3):
            # print(a)
            ptn = get_ptn(ta)

            # print(ptn)
            cost = []
            tmp = []
            for i in range(len(ptn)):
                tmp.append([abs(take[k] - sum(j)) for j in ptn[i]])
                cost.append(min(tmp[i]) + 10 * i)
            ans += min(cost)
            ac = np.argmin(cost)
            # print(np.argmin(cost))
            # print(ptn[ac])
            # print(tmp[ac])
            at = np.argmin(tmp[ac])
            # print(ptn[ac][at])

            for _ in ptn[ac][at]:
                ta.remove(_)

        ansl.append(ans)
    except:
        pass

print(min(ansl))


Measured memory_bytes: 12452
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author rn-sshawish
 */
public class Main{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println(input.nextInt() + input.nextInt() >= input.nextInt()? "Yes": "No");
    }
}


Measured memory_bytes: 23124
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    int64_t a1 = 0, a2 = 0;

    int flag = 1;
    rep(i, N - 1)
    {
        if (flag && A[i] == A[i + 1])
        {
            a1 = A[i];
            i++;
            flag = 0;
            continue;
        }
        if (A[i] == A[i + 1])
        {
            a2 = A[i];
            cout << a1 * a2 << endl;
            return 0;
        }
    }
    cout << a1 * a2 << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

int main() {
  int A, B;
  cin >> A >> B;
  cout << std::max(A*B, std::max(A-B, A+B)) << '\n';
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N;
	scanf("%d", &N);
	if(N % 3 == 0)	printf("%d\n", N/3);
	if(N % 3 == 1)	printf("%d\n", (N-1)/3);
	if(N % 3 == 2)	printf("%d\n", (N-2)/3);
	
	return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(),a.end()
#define IN(a,x,b) (a<=x && x<b)
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long H(int n,int k){
    return COM(n+k-1,k);
}

signed main(){
	COMinit();
	int N,K;
	cin>>N>>K;
	FOR(i,1,K+1){
		//cout<<COM(N-K+1,i)<<" "<<H(i+1,N-K-(i-1))<<endl;
		cout<<COM(N-K+1,i)*COM(K-1,i-1)%MOD<<endl;
	}
}

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

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    int d1 = a[2] - a[0];
    int d2 = a[2] - a[1];
    int ans = 0;
    ans += d1/2 + d2/2;
    if((d1%2 + d2%2)%2 == 0){
        ans += (d1%2 + d2%2)/2;
    }
    else{
        ans += 2;
    }
    cout <<  ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }


void solve() {
    int x,n;
    cin >> x >> n;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    set<int> s;
    REP(i,0,n) s.insert(a[i]);
    REP(i,0,101) {
        if (s.count(x-i) == 0) {
            cout << x - i << endl;
            return;
        }
        if (s.count(x+i) == 0) {
            cout << x + i << endl;
            return;
        }
    }
    cout << x << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int solve(int h[],int s,int e,long long dp[],int k){
	if(s>e)
	return INT_MAX;
	if(s==e)
	return 0;
	if(dp[s]!=-1)
	return dp[s];
	long long so1=INT_MAX;
	for(int i=1;i<=k;i++){
	 long long so2=(long long)abs(h[s+i]-h[s])+solve(h,s+i,e,dp,k);
	 so1=min(so1,so2);
	}
	dp[s]=so1;
	return so1;
}
int main() {
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++)
	cin>>h[i];
	long long dp[n];
	memset(dp,-1,sizeof(dp));
	cout<<solve(h,0,n-1,dp,k)<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 10752
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


N, Q = list(map(int, input().split()))
STX=[]
D=[]
for i in range(N):
    S, T, X = list(map(int, input().split()))
    STX.append((X, S, T))
STX = sorted(STX, key=lambda x: x[0])

for i in range(Q):
    D.append(int(input()))

skip = [-1]*Q

dist = [-1]*Q

for X, S, T in STX:
    s = S - X
    t = T - X - 1
    a = bisect.bisect_left(D, s)
    b = bisect.bisect_right(D, t)
    #print(D)
    j = a
    while j < b:
        if skip[j] == -1:
            skip[j] = b
            dist[j] = X
            j+=1
        else:
            j=skip[j]


for i in range(Q):
    print(dist[i])

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

typedef long long ll;

ll n;
ll ans;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            if(i<n/i-1ll)ans+=n/i-1ll;
            if(i<i-1ll&&i*i!=n)ans+=i-1ll;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
A = [0] + LI() + [0]
C = [0]
for a1, a2 in zip(A[:-1], A[1:]):
    C.append(C[-1] + abs(a2 - a1))

for i in range(1, n + 1):
    if A[i - 1] <= A[i] <= A[i + 1]:
        print(C[-1])
    elif A[i - 1] >= A[i] >= A[i + 1]:
        print(C[-1])
    else:
        print(C[-1] - 2 * min(abs(A[i] - A[i - 1]), abs(A[i] - A[i + 1])))

Measured memory_bytes: 14052
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}
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;
}
int main() {
    ll N, K, Q;
    cin >> N >> K >> Q;
    vl a(Q);
    vl point(N);
    rep(i, 0, Q) {
        cin >> a[i];
        a[i] -= 1;
    }
    rep(i, 0, N) {
        point[i] = K - Q;
    }

    rep(i, 0, Q) {
        point[a[i]] += 1;
    }

    rep(i, 0, N) {
        if (point[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2176
N, M = map(int, input().split())
ans = [0 for i in range(M)]
for i in range(N):
  tmp = list(map(int, input().split()))
  #print(tmp)
  for j in range(tmp[0]): #K
    ans[tmp[j+1]-1] += 1

count = 0
for k in ans:
  if k == N:
    count += 1
print(count)

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

int main(void) {

    char n[2][3];
    cin>>n[0];
    cin>>n[1];
    if(n[0][0]==n[1][2]&&n[0][1]==n[1][1]&&n[0][2]==n[1][0])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, W; cin >> N >> W;
    int w[N], v[N];
    REP(i, 0, N) cin >> w[i] >> v[i];

    vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
    REP(i, 0, N) {
        REP(j, 0, W + 1) {
            if (j >= w[i]) dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); 
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

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

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

    int m[101];
    for(int i=0;i<N;i++)
        cin >> m[i];
    
    int remain;
    remain = X;
    
    //1種類ずつ作る
    for(int i=0;i<N;i++)
        remain -= m[i];
    
    //最小値
    int min;
    min = m[0];
    for(int i=0;i<N;i++){
        if(min > m[i])
            min = m[i];
    }
    
    //個数計算
    int num;
    num = remain/min;

    cout << N + num << endl;
    return 0;
}

Measured memory_bytes: 256