akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, k;
string s;

signed main() {
	cin >> n >> k >> s;
	rep(i, s.size()) {
		if (i + 1 == k) {
			char a = s[i] + ' ';
			cout << a;
		}
		else cout << s[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,x,y) for(int i=x;i<y;i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int n,m;
    cin>>n>>m;
    if(2*n<m){
       m-=2*n;
       cout<<n+m/4;
    }else{
        cout<<m/2<<endl;
    }

    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <numeric>
#include <algorithm>
#include <math.h>

using namespace std;

int64_t N, ans;
vector<int64_t> A(200'000);

int main(){
	cin >> N;
	for(int i=0;i<N;i++)	cin >> A[i];

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

	sort(B.begin(), B.end());
	int64_t midd = B[N/2];

	ans = 0;
	for(int i=0;i<N;i++){
		ans += abs( A[i] - (midd + (i+1) ) );
	}

	cout << ans << endl;
}

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

#define ll long long int

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast_io std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;
#define trace3(x,y,z) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;
#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(),(v).end()

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

int n,m;

const int mod = 1e9+7;
const int N = 1e5+5;

ll fact[N];
void pre(){
	fact[0] = 1;
	for(int i = 1;i<=N-5 ; ++i){
		fact[i] = (1LL*fact[i-1]*i)%mod;
	}
}


int main()
{
	fast_io;

	pre();
	cin>>n>>m;

	if(n>m){
		int temp = n;
		n = m;
		m = temp;
	}

	if(m-n>1){
		cout<<0<<endl;
		return 0;
	}

	ll ans;

	if(n==m){
		ans = (2*(1LL*fact[n]*fact[n])%mod)%mod;
	}
	else{
		ans = (1LL*fact[n]*fact[m])%mod;
	}

	cout<<ans<<endl;
	return 0;

}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>

#define WHITE 0
#define BRACK 1
#define GRAY 2
#define N 101

int color[N];
int d[N];
int f[N];
int e[N];
int time;
int A[N][N];
int v[N];
int B[N][N];

void DFE_Visit(int u){
  int v,i;
  
  color[u]=GRAY;
  d[u]=++time;

  for(i=1;i<=e[u];i++){
    v=B[u][i];
    if(color[v]==WHITE)DFE_Visit(v);
  }
  color[u]=BRACK;
  f[u]=++time;
}

void DFS(int n){
  int i,u;
  
  for(i=1;i<=n;i++){
    u=v[i];
    color[u]=WHITE;
    time=0;
  }
  
  for(i=1;i<=n;i++){
    u=v[i];
    if(color[u]==WHITE)DFE_Visit(u);
    printf("%d %d %d\n",u,d[u],f[u]);
  }
}

main(){
  int n,i,j,v1;
 
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      A[i][j]=WHITE;
    }
  }

  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d%d",&v[i],&e[i]);
    for(j=1;j<=e[i];j++){
      scanf("%d",&v1);
      B[i][j]=v1;
      A[i][v1]= BRACK;
    }
  }
  DFS(n);

  return 0;
}

Measured memory_bytes: 680
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  if(all_of(a, a+n, [](int x){ return x%2 == 0; })) cout << "second" << endl;
  else cout << "first" << endl;

  return 0;
}


Measured memory_bytes: 640
class Node:
    def __init__(self):
        self.parent = -1
        self.degree = 0
        self.sibling = -1

def make_orderlist(node_id, answer_dic):
    preorder(node_id, answer_dic)
    inorder(node_id, answer_dic)
    postorder(node_id,answer_dic)

def preorder(node_id, answer_dic):
    if node_id == -1:
        return
    answer_dic["Preorder"].append(str(node_id))
    preorder(Tree[node_id].left, answer_dic)
    preorder(Tree[node_id].right, answer_dic)
    
def inorder(node_id, answer_dic):
    if node_id == -1:
        return
    inorder(Tree[node_id].left, answer_dic)
    answer_dic["Inorder"].append(str(node_id))
    inorder(Tree[node_id].right, answer_dic)

def postorder(node_id, answer_dic):
    if node_id == -1:
        return
    postorder(Tree[node_id].left, answer_dic)
    postorder(Tree[node_id].right, answer_dic)
    answer_dic["Postorder"].append(str(node_id))
    

N = int(input())
Tree = [Node() for _ in range(N)]

#make_tree
for _ in range(N):
    #id, left, right
    tree_info = list(map(int, input().split()))
    node_id = tree_info[0]
    left = tree_info[1]
    right = tree_info[2]
    #自身の子をセット
    Tree[node_id].left = left
    Tree[node_id].right = right
    #子からみた親をセット
    if left != -1:
        Tree[left].parent = node_id
    if right != -1:
        Tree[right].parent = node_id
    if left != -1 and right != -1:
        #兄弟をセット
        Tree[right].sibling = left
        Tree[left].sibling = right
        
#search_root
root_id =[i for i,t in enumerate(Tree) if t.parent == -1][0]
answer_dic = {"Preorder":[], "Inorder":[], "Postorder":[]}
make_orderlist(root_id, answer_dic)

#answer_output
for i in answer_dic:    
    print(i)
    print(" "+" ".join(answer_dic[i]))


Measured memory_bytes: 5616
h, w, n = gets.split.map(&:to_i)
ps = Hash.new { 0 }
n.times do
  a, b = gets.split.map(&:to_i)
  (a-1..a+1).each do |i|
    (b-1..b+1).each do |j|
      ps["#{i}:#{j}"] += 1 if 1 < i && i < h && 1 < j && j < w
    end
  end
end

rs = Array.new(10) { 0 }
x = 0
ps.each do |_, n|
  x += 1
  rs[n] += 1
end
rs[0] = (h-2)*(w-2) - x

puts rs

Measured memory_bytes: 127740
n=gets.to_i
k=gets.to_i

array=gets.split.map(&:to_i)


i=0
answer=0
n.times{
if  array[i]<=k-array[i]
  aa=array[i]
else  aa=k-array[i]
end

answer+=2*aa
i=i+1
}

puts answer


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

using namespace std;
int n;
long double p[3000], dp[3001][3001];
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> p[i];
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < i; j++){
            dp[i][j + 1] += (dp[i - 1][j] * p[i]);
            dp[i][j] += (dp[i - 1][j] * (1 - p[i]));
        }
    }
    long double ans = 0;
    for(int i = n; i >= 1; i--){
        if(n - i < i){
            ans += dp[n][i];
        }
    }
    cout << fixed << setprecision(9) << ans;
}


Measured memory_bytes: 139136
#include<bits/stdc++.h>
using namespace std;
long long ans;
int cnt[100000];
const int mod = 1000000007;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    int base = 3;
    ans = 1;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if (a == 0) {
            ++cnt[0];
            ans *= base;
            --base;
        } else {
            ++cnt[a];
            ans *= cnt[a-1];
            --cnt[a-1];
        }
        ans %= mod;
    }
    printf("%lld\n", ans);
    return 0;
}


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

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

    static class AShrinking {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int maxlen = 0;
            for (char i = 'a'; i <= 'z'; i++) {
                maxlen = Math.max(maxlen, f(s, i));
            }
            out.println(s.length() - maxlen);
        }

        int f(String s, char c) {
            // 全てcにするときの最小長さ
            if (s.indexOf(c) == -1) return 0;
            //System.out.println(s + " " + c);
            char[] u = new char[s.length() - 1];
            StringBuilder t = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                t.append(c);
            }
            //System.out.println(s + " " + t.toString());

            if (s.equals(t.toString())) return s.length();
            for (int i = 0; i < s.length() - 1; i++) {
                if (s.charAt(i) == c || s.charAt(i + 1) == c) {
                    u[i] = c;
                } else {
                    u[i] = s.charAt(i);
                }
            }
            return f(new String(u), c);

        }

    }
}



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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec.at(i);
    }
    int a=0, b=0;
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    for (int i = 1; i < n+1; i++)
    {
        if (i % 2 != 0) a += vec.at(i-1);
        else b += vec.at(i-1);
    }
    
    cout << a-b << endl;
    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;
public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner (System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int x=sc.nextInt();
    int []a=new int [m];
    int j=0;
    int k=0;
    
    for (int i=0; i<a.length; i++){
      a[i]=sc.nextInt();
    }
    for (int i=0; i<a.length; i++){
      if(a[i]>x){j++;}
      if(a[i]<x){k++;}
    }
    if(j<=k){System.out.printf("%d\n", j);}
    else {System.out.printf("%d\n", k);}
  }
}


Measured memory_bytes: 21844
(function(input) {
    var p = input.split('\n');
    var args = p.shift().split(' ').map(Number);
    var n = args[0];
    var k = args[1];
    var weights = p.slice(0, n).map(Number);

    var sumWeight = weights.reduce(function(a, b) { return a + b; });
    var P = Math.ceil(sumWeight / k);

    var l = 0;
    var left = P / 2;
    var right = P * 2;
    while (right - left > 1) {
        //console.log(left, right);
        var m = (right + left)/2;
        var i = getWeightCount(m, k, weights);
        //console.log(i, m, n);

        if (i >= n) {
            right = m;
        } else {
            left = m;
        }

    }

    console.log(Math.floor(right));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function getWeightCount(P, k, weights) {
    var count = 0;

    var i = 0;
    for (var j = 0; j < k; j++) {
        var kWeight = 0;
        for (; i < weights.length; i++) {
            if (kWeight + weights[i] <= P) {
                kWeight += weights[i];
                count++;
            } else {
                break;
            }
        }
    }

    return count;
}

Measured memory_bytes: 20288
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_4_A
AC
"""
import sys
from sys import stdin
from bisect import bisect_right, bisect_left
input = stdin.readline


def main(args):
    N, V = map(int, input().split())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    D = [int(x) for x in input().split()]

    #AB = []
    #for i in A:
    #    for j in B:
    #       AB.append(i+j)
    AB = [a+b for a in A for b in B]
    #AB.sort()

    #CD = [float('-inf'), float('inf')]
    #for i in C:
    #    for j in D:
    #       CD.append(i+j)
    CD = [c+d for c in C for d in D]
    CD.append(float('-inf'))
    CD.append(float('inf'))
    CD.sort()

    count = 0
    for ab in AB:
        i = bisect_left(CD, V - ab)
        j = bisect_right(CD, V - ab)
        count += max((j-i), 0)

    print(count)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 102524
from sys import stdin
import math
d,g = map(int,stdin.readline().rstrip().split())
PC = [list(map(int,stdin.readline().rstrip().split())) for _ in range(d)]
mi = 10**10
for i in range(2**d):
    point = 0
    count = 0
    not_all = []
    for j in range(d):
        if (i >> j) & 1:
            point += (j+1)*PC[j][0]*100+PC[j][1]
            count += PC[j][0]
        else:
            not_all.append(j)
    if point < g:
        #すべて取り出す以外の問題番号のうち最大のもの
        saidai = not_all[-1]
        need = math.ceil((g-point)/((saidai+1)*100))
        if need >= PC[saidai][0]:
            continue
        else:
            count += need
    mi = min(mi,count)
print(mi)

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

#define ll long long
using namespace std;

int main() {
    ll n;
    string s,t;
    cin >> n >> s >> t;

    string output;
    for (int i = 0; i < s.size()+t.size(); i++)
    {
        if (i%2 == 0)
            output[i] = s[i/2];
        else
            output[i] = t[i/2];
        cout<< output[i];
    }
    
    return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

int main()
{
    string s, t;
    cin >> s >> t;

    int ans = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == t[i])
            ans++;
    }

    cout << ans;

    return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll k,n,maximum=0;
	cin>>k>>n;
	vector<ll> v(n);
	for(ll i=0;i<n;i++){
        cin>>v[i];
	}
	for(ll i=1;i<n;i++){
        maximum=max(maximum,abs(v[i]-v[i-1]));
	}
	maximum=max(maximum,abs(k-v[n-1]+v[0]));
	cout<<k-maximum<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string.h>
using namespace std;
int main () {
  int n;
  cin >> n;
  double x[n];
  string s[n];
  double sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> s[i]; 
    if (s[i] == "JPY") {
      sum += x[i];  
    } 
    else {
      sum += 380000 * x[i];  
    }
  }  
  cout << fixed << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n) cin >> vec.at(i);
  ll ans = 0;
  reps(i,1, n) {
    if (vec.at(i) < vec.at(i-1)) {
      ans += vec.at(i-1) - vec.at(i);
      vec.at(i) = vec.at(i-1);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4752
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) ->
      if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  print_newline ();
  preorder (fun e -> print_string " "; print_int e) t;
  print_newline ()

let () =
  let m = read_int () in
  let t = ref (create ()) in
  for _ = 0 to m - 1 do
    let op = Scanf.scanf "%s " (fun i -> i) in
    if op = "print" then print !t
    else t := insert (Scanf.scanf "%d " (fun i -> i)) !t
  done

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

int main() {
	string divide[4]={"dream","dreamer","erase","eraser"};
	
	    string S;
	    cin>> S;
	    
	    reverse(S.begin(),S.end());
	    for(int i=0;i<4;i++) reverse(divide[i].begin(),divide[i].end());
	    
	    bool can = true;
	    for(int i=0;i<S.size();){
	        bool can2 = false;
	        for (int j=0;j<4;j++){
	            string d= divide[j];
	            if(S.substr(i,d.size())==d){
	                can2 = true;
	                i += d.size();
	            }
	        }
	        if(!can2){
	            can = false;
	            break;
	        }
	    }
	    if(can) cout << "YES" << endl;
	    else cout << "NO" << endl;
	    return 0;
}

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

int n, m;
int edge[55][55];
int par[55][10];
pair<int, int> q[22];
int dept[55];
int hasquery[55];
ll dp[55][1100000];

void dfs(int now){
	rep(i, 7) par[now][i+1] = par[par[now][i]][i];
	rep(i, n){
		if(edge[now][i] >= 0 && i != par[now][0]){
			par[i][0] = now;
			dept[i] = dept[now] + 1;
			dfs(i);
		}
	}
}
int lca(int a, int b){
	if(dept[a] > dept[b]) swap(a, b);
	for(int i = 7; i >= 0; i--){
		if(dept[par[b][i]] >= dept[a]) b = par[b][i];
	}
	for(int i = 7; i >= 0; i--){
		if(par[a][i] != par[b][i]) a = par[a][i], b = par[b][i];
	}
	if(a != b) a = par[a][0], b = par[b][0];
	return a;
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	memset(edge, -1, sizeof(edge));
	rep(i, n-1){
		int a, b;
		cin >> a >> b;
		a--, b--;
		edge[a][b] = edge[b][a] = i;
	}
	dfs(0);
	cin >> m;
	rep(i, m){
		cin >> q[i].first >> q[i].second;
		q[i].first--, q[i].second--;
		int now = q[i].first;
		while(now != lca(q[i].first, q[i].second)){
			hasquery[edge[now][par[now][0]]] |= (1 << i);
			now = par[now][0];
		}
		now = q[i].second;
		while(now != lca(q[i].first, q[i].second)){
			hasquery[edge[now][par[now][0]]] |= (1 << i);
			now = par[now][0];
		}
	}
	dp[0][0] = 1;
	rep(i, n-1){
		rep(mask, 1 << m){
			if(!dp[i][mask]) continue;
			dp[i+1][mask | hasquery[i]] += dp[i][mask];
			dp[i+1][mask] += dp[i][mask];
		}
	}
	cout << dp[n-1][(1 << m) - 1] << endl;
	return 0;
}

Measured memory_bytes: 138764
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF int(1e9+7)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

int a[100005];

int main()
{
	IO_OP;
	
	int n, k, mn = INF;
	cin >> n >> k;
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a, a+n);
	for(int i=0;i<n-k+1;i++)
		mn = min(mn, a[i+k-1] - a[i]);
	cout << mn << endl;
}



Measured memory_bytes: 640
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat Dec  1 12:48:05 2018
//
package main

import "fmt"

var n, t int

func main() {
	fmt.Scan(&n, &t)
	cost := 1001
	min := -1
	for i := 0; i < n; i++ {
		var c, time int
		fmt.Scan(&c, &time)
		if c < cost && time <= t {
			cost = c
			min = i
		}
	}

	if min == -1 {
		fmt.Println("TLE")
		return
	}

	fmt.Println(cost)
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int N; cin >> N;
  bool flag = true;
  ll ans = 1e9, sum = 0;
  for (int i = 0; i < N; i++){
    ll A, B; cin >> A >> B;
    sum += A;
    if (A != B) flag = false;
    if (A > B) ans = min(ans, B);
  }

  if (flag) cout << 0 << endl;
  else cout << sum - ans << endl;

  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main (){
	int a,b;cin>>a>>b;
	int k1=a+b;
	int k2=a*b;
	int k3=a-b;
	cout<<max(k1,max(k2,k3))<<endl;
	return 0;
}


Measured memory_bytes: 256
n, qt = gets.chomp.split.map(&:to_i)
pss = []
past = 0

n.times {
    ps, tm = gets.chomp.split
    tm = tm.to_i
    pss << [ps, tm]
}

while pss != []
    ps, tm = pss.shift
    if tm - qt <= 0
        past += tm
        puts "#{ps} #{past}"
    else
        past += qt
        tm -= qt
        pss << [ps, tm]
    end
end


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

int main(){
    int n,m; cin >> n >> m;
    vector<int> a(m + m);
    vector<int> f(n + 1);
    rep(i, 0, m*2){ 
       cin >> a[i];
       f[a[i]] += 1;
    }
    for(int i = 1; i <= n; i++) cout << f[i] << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
if n==1:
    if a[0]%2==0:
        print(1)
    else:
        print(2)
else:
    ans=0
    c=0
    d=0
    for i in range(n):
        if a[i]%2==0:
            c+=1
        else:
            d+=1
    print(3**n-2**c)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#define int long long
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0,-1 }; // x軸方向への変位
int dy[4] = { 1, 0,-1, 0 }; // y軸方向への変位

std::vector<int> v;
int c[51][51];	//nCr->c[n][r];
long double ave[51];

int nCr(int n, int r) {
	if (r == 0) return 1;
	if (n == r) return 1;
	if (c[n][r] != -1) return c[n][r];
	//停止条件じゃなくてメモに載ってなかったら漸化式を計算
	int comb = nCr(n - 1, r - 1) + nCr(n - 1, r);
	c[n][r] = comb;
	return comb;
}

signed main() {
	int N;
	string S;
	cin >> N >> S;
	string first = "", last = "";
	int open = 0, close = 0;
	for (int i = 0; i < (int)S.size(); i++) {
		if (S[i] == '(') {
			open++;
		}
		if (S[i] == ')') {
			if (open > 0) {
				open--;
			}
			else {
				first += "(";
			}
		}
	}
	for (int i = 0; i < open; i++) {
		last += ")";
	}
	cout << first + S + last << "\n";

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long ans = Integer.MAX_VALUE;
		for(int i = 1; i <= Math.sqrt(N); i++) {
			if(N % i == 0) {
				long temp = Math.max(i, N / i);
				ans = Math.min(temp, ans);
			}
		}
		System.out.println(Long.toString(ans).length());
	}
}


Measured memory_bytes: 21844
n=int(input())
S,T=[],[]
for i in range(n):
  s=input()
  S.append(s)
m=int(input())
for i in range(m):
  t=input()
  T.append(t)
k=0
for i in range(n):
  k=max(k,S.count(S[i])-T.count(S[i]))
print(k)

Measured memory_bytes: 3060
#define DINGER_GISBAR
#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
#ifdef ZEROKUGI
#include <dumper.hpp>
#define dump(x) dumper::dumper(cerr, __LINE__, (#x), (x), 50, 1, 1)
#define tick(...) dumper::tick(__VA_ARGS__)
#pragma message "Compiling " __FILE__
#else
#define dump(x)
#define tick(...)
#endif
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n) \
    for (int i = 0, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)   \
    sort(all(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto&
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) { return 1LL << x; }
template <class T>
inline int size(const T& a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T>& v, const char& c) {
    return make_pair(v, c);
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto& x : v) is >> x;
    return is;
}
template <class T>
inline ostream& operator<<(ostream& os, const pair<vector<T>, char>& v) {
    bool t = 0;
    for (const T& x : v.first) {
        if (t) os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
        tick(0, 0);
    };
} __before_main;
//}}}TEMPLATE_END

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    int ans = 2 * n;

    for (int i = 1; i <= n; i++) {
        int ss = n - i;

        if (ss < 0 || n < i) break;

        bool ok = true;
        for (int j = 0; j < i; j++) {
            ok &= s[ss + j] == t[j];
        }

        if (ok) ans = 2 * n - i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
n,q = map(int, input().split())
s = input()
tmp=[0]*n
cnt=0
for i in range(n-1):
  if 'AC' == s[i:i+2]:
    cnt+=1  
  tmp[i+1]=cnt
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Measured memory_bytes: 6188
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	d := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&d[i])
	}

	sort.Ints(d)
	ans := d[N/2] - d[N/2-1]

	fmt.Println(ans)
}


Measured memory_bytes: 7424
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#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 long double ld;

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


int main() {
  int N,A;
  cin >> N >> A;
  int ans = N % 500;
  if(ans <= A){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  
  
  
  
  
}

Measured memory_bytes: 3612
#include<stdio.h>

#define MAX(a,b)(a>b?a:b)

int main() {
	long long N, T, A;
	long long nowT, nowA, coef;
	scanf("%lld", &N);
	scanf("%lld%lld", &T, &A);
	while (--N) {
		scanf("%lld%lld", &nowT, &nowA);
		if (T%nowT != 0) { T += nowT - T%nowT; }
		if (A%nowA != 0) { A += nowA - A%nowA; }
		coef = MAX(T / nowT, A / nowA);
		T = nowT * coef;
		A = nowA * coef;
	}
	printf("%lld\n", T + A);
	return 0;
}

Measured memory_bytes: 128
import itertools
import math

N,D = map(int,input().split())

X = [[] for i in range(N)]
for i in range(N):
    X[i] = list(map(int,input().split()))

p = [ i for i in range(N)]
road = itertools.combinations(p,2)



cnt =0

for i in road:
    
    temp = 0.0
    
    for d in range(D):
            temp += ((X[i[1]][d] -X[i[0]][d])**2)
    
    res = math.sqrt(temp)
            
    if res.is_integer():
        cnt+=1
            
print(cnt)

Measured memory_bytes: 3188
#include <stdio.h>
#include<string.h>
#include<limits.h>
#include<queue>
#include <cmath>
#include<stack>
using namespace std;
char s[110],t[110];
bool vis[110]={false};
bool vit[110]={false};
int sl,tl;
char ss='z',tt=0;

void findd()
{
    ss='z';tt='a';
    int x,y;
    for(int i=0; i<sl; i++)
    {
        if(ss>=s[i]&&!vis[i])
        {
            ss=s[i];
            x=i;
        }
    }
    for(int i=0; i<tl; i++)
    {
        if(tt<=t[i]&&!vit[i])
        {
            tt=t[i];
        y=i;
        }
    }
    vis[x]=true;
    vit[y]=true;
}


int main()
{
    scanf("%s",s);
    sl=strlen(s);
    scanf("%s",t);
    tl=strlen(t);
    bool b=true;
    int u=0;
    while(1)
    {
        u++;
        findd();
        if(ss>tt)
        {
            b=false;
            break;
        }else if(ss<tt){
        b=true;
        break;
        }else{
        if(u>=sl||u>=tl){
         if(sl>=tl){
            b=false;
         }else{
             b=true;
         }
         break;
        }
        }

    }
    if(b){
        printf("Yes\n");
    }else{
      printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
//
//  abc112d.cpp
//  
//
//  Created by Yoshida Satoshi on 2018/10/22.
//

#include <stdio.h>
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int N,M;
    
    cin>>N>>M;
    int ans=1;
    for(int i=1;i*i<=M;i++){
        if(M%i==0){
            if(i>=N) ans=max(ans,M/i);
            if(i<=M/N)ans=max(ans,i);
        }
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=200010;
const ll mod=1e9+7;

int main(){  
  int n,m;
  cin >> n >> m;
  set<int> st;
  vector<int> ans(n,0);
  rep(i,m){
    int s,c; cin >> s >> c;
    if(st.find(s)!=st.end() && ans[s-1]!=c){cout<<-1<<endl; return 0;}else{st.insert(s);}
    if(s-1>n){ cout<<-1<<endl; return 0;}
    if(n==3 && s!=3 && c==0){ cout<<-1<<endl; return 0;}
    if(n==2 && s!=2 && c==0){ cout<<-1<<endl; return 0;}
    ans[s-1]=c;
  }
  
  if(n==1){ cout<<ans[0]<<endl; return 0;}
  if(n==2){ 
    cout<<(ans[0]==0?1:ans[0])<<ans[1]<<endl; 
    return 0;
  }
  if(n==3){ 
    cout<<(ans[0]==0?1:ans[0])<<ans[1]<<ans[2]<<endl; 
    return 0;
  }
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	while( n-- > 0 ){
		string num1, num2;
		cin >> num1 >> num2;
		/*if( num1.size() > 80 || num2.size() > 80 ){
			cout << "overflow" << endl;
			continue;
		}
		*/
		vector<int> sum;
		int degit = 0;
		for( int i = 0; i <= max(num1.size(), num2.size()); i++ ) sum.push_back(0);
		for( int i = 0; i < num1.size(); i++ ){
			sum[sum.size()-i] = num1[num1.size()-i-1]-'0';
		}
		int d;
		for( int i = 0; i < num1.size() || i < num2.size() || degit != 0; i++ ){
			int now;
			if( i < num2.size() ){
				now = sum[sum.size()-i] + (int)num2[num2.size()-i-1]-(int)('0') + degit;
			}else{
				now = sum[sum.size()-i] + degit;
			}
			sum[sum.size()-i] = (now%10);
			if( now >= 10 ) degit = 1;
			else degit = 0;
			d = i;
		}
		if( d < 80 ){
			for( int i = sum.size()-d; i <= sum.size(); i++ ) cout << sum[i];
			cout << endl;
		}else{
			cout << "overflow" << endl;
		}
	}
}

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

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool ng = false;
  rep(i,n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || (ll)1e18/ans < a) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
fn read_line() -> String {
    use std::io;
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

fn main() {
    let line = read_line();
    let mut iter = line.split_whitespace();
    let x = iter.next().unwrap();
    let y = iter.next().unwrap();
    let res = if x < y {
        "<"
    } else if x == y {
        "="
    } else {
        ">"
    };
    println!("{}", res);
}

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

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {	
	IO;
	
	int n; cin >> n;
	int tot = 0;
	while (tot < n) {
		tot+= 1000;
	}
	
	cout << tot - n;
		
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
typedef long long int LLI;
int main()
{
  	int a, b, c;
  	cin >> a >> b >> c;
  	if( (a*100+b*10+c) % 4 == 0 )
      	cout << "YES";
  	else
      	cout << "NO";
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    int a,b;
    cin >> a >> b;
    cout << a*b<<" "<<2*(a+b)<<endl;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=998244353;
const int N=2e5+5;
int main() {
  
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        ll n,s;cin>>n>>s;
        ll a[n+1];rep(i,n)cin>>a[i+1];
        ll dp[n+1][s+1];
        fill(dp,0);
        ll ans=0;
        ll pre[s+1]={0};
        for(ll i=1;i<=n;i++){
            if(a[i]<=s)
            dp[i][a[i]]=i;
            for(ll j=1;j<=s;j++){
                if(j>a[i]){
                    // dbg(i,pre[j-a[i]],j);
                    dp[i][j]=(pre[j-a[i]]);
                    dp[i][j]%=p;
                }
            }
            for(ll j=1;j<=s;j++){
                // dbg(dp[i][j]);
                pre[j]+=dp[i][j];pre[j]%=p;
            }
            // dbg(dp[i][s],pre[2],dp[i][s]);
            ans=ans+((n-i+1)*(dp[i][s]))%p;ans%=p;
            // dbg(ans);
        }
        cout<<ans<<endl;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 70656
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <numeric>
#include <cstdlib>

bool valid(const std::string &s, int k) {
  if (k % 15 == 0) {
    if (s != "FizzBuzz") return false;
  } else if (k % 3 == 0) {
    if (s != "Fizz") return false;
  } else if (k % 5 == 0) {
    if (s != "Buzz") return false;
  } else {
    if (s != std::to_string(k)) return false;
  }
  return true;
}

int testcase_ends() {
  size_t m;
  int n;
  scanf("%zu %d", &m, &n);
  if (m == 0 && n == 0)
    return 1;

  std::list<int> pp(m);  // players
  std::iota(pp.begin(), pp.end(), 1);
  auto it=pp.begin();
  for (int i=1; i<=n; ++i) {
    char buf[32];
    scanf("%s", buf);
    std::string s=buf;
    if (pp.size() <= 1) continue;

    if (!valid(s, i)) {
      pp.erase(it++);
    } else {
      ++it;
    }
    if (it == pp.end())
      it = pp.begin();
  }
  
  it = pp.begin();
  while (it != pp.end()) {
    printf("%d%c", *it, std::next(it)!=pp.end()? ' ':'\n');
    ++it;
  }
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2944
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
#define int long long
/*
const ll mod = 1e9 + 7;
ll func(ll n, ll value) {
	vector<vector<ll>>dp(n + 1, vector<ll>(value + 1, 0));
	for (ll i = 0; i <= n; i++) {
		dp[i][0] = 1;
	}
	for (ll i = 0; i < n; i++) {
		for (int j = 1; j <= value; j++) {
			dp[i + 1][j] = (dp[i + 1][j - 1] % mod + dp[i][j] % mod) % mod;
		}
	}
	return dp[n][value] % mod;
}
*/
const int MAX = 510000;
const int MOD = 1e9+7;

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;
}
map<int, int> prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}
int n, m;//nが長さ　mは値
signed main() {
	COMinit();
	cin >> n >> m;
	map<int, int> ma = prime_factor(m);
	int ans = 1;
	for (auto e : ma) {
		int key, value;
		tie(key, value) = e;
		ans *= COM(n+value-1,value) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


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

int n;
vector<int> a;
vector<long long> dp;

long long solve();

int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  dp.assign(n + 1, 0);
  dp[0] = dp[1] = 1000;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < i; ++j) {
      dp[i + 1] = max(dp[i + 1], dp[i]);
      long long now = dp[j];
      now = dp[j] / a[j] * a[i] + dp[j] % a[j];
      dp[i + 1] = max(dp[i + 1], now);
    }
  return dp[n];
}

Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	vector<int> a(3);
	for(int i = 0; i < 3; i++)
	{
		cin >> a[i];
	}
	
	sort(a.begin(), a.end(), [](const int &x, const int &y){return x > y;});
	int ans = 0;
	if (a[1] == a[0] && a[0] == a[2])
	{
		cout << ans << endl;
	}
	else if(a[0] == a[1])
	{
		if((a[0] - a[2]) % 2 == 0)
		{
			cout << (a[0] - a[2]) / 2 << endl;
		}
		else
		{
			cout << ((a[0] - a[2]) / 2) + 2 << endl;
		}
	}
	else if(a[1] == a[2])
	{
		cout << a[0] - a[1] << endl;
	}
	else
	{
		if((a[1] - a[2]) % 2 == 0)
		{
			ans += (a[1] - a[2]) / 2;
			ans += a[0] - a[1];
		}
		else
		{
			ans += (((a[1] + 1) - a[2]) / 2) + 1;
			ans += a[0] - a[1];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
#include <iterator>     // std::back_inserter
const double PI = acos(-1);
using namespace std;
using ll =long long;
#define rep(i,n)for(ll i=0;i<(n);i++)
const int mod = 1000000007;
const ll inf = 1e18 + 1;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
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;
}
//ll f[101010], rf[101010];
//ll inv(ll x) {
//	ll res = 1;
//	ll k = mod - 2;
//	ll y = x;
//	while (k) {
//		if (k & 1) res = (res * y) % mod;
//		y = (y * y) % mod;
//		k /= 2;
//	}
//	return res;
//}
//void init() {
//	f[0] = 1;
//	for (ll i = 1; i < 101010;i++) f[i] = (f[i - 1] * i) % mod;
//	for(ll i = 0; i < 101010; i++) rf[i] = inv(f[i]);
//}
////---------------------------------------------------------------------------------------------------
//ll C(int n, int k) {
//	ll a = f[n]; // = n!
//	ll b = rf[n - k]; // = (n-k)!
//	ll c = rf[k]; // = k!
//
//	ll bc = (b * c) % mod;
//
//	return (a * bc) % mod;
//}

//小文字=大文字+32
int main() {
	ll N;
	cin >> N;
	vector<ll>a(3*N);
	priority_queue<ll,vector<ll>,greater<ll>>Qhead;//（根は最小）
	priority_queue<ll>Qtail;//ちっちゃい物優先で入れてく（ので根は最大）
	vector<ll>m(N+1);
	vector<ll>n(N+1);
	ll res=-inf;
	ll tmpm=0;
	ll tmpn=0;
	rep(i, 3*N) {
		cin >> a[i];
	}
	rep(i, N) {
		Qhead.push(a[i]);
		tmpm += a[i];
	}
	for (ll i = 2 * N; i < 3 * N; i++) {
		Qtail.push(a[i]);
		tmpn += a[i];
	}
	m[0] = tmpm;
	n[N] = tmpn;
	for (ll i = N; i < 2 * N; i++) {
		if (Qhead.top() < a[i]) {
			tmpm += a[i];
			tmpm -= Qhead.top();
			Qhead.pop();
			Qhead.push(a[i]);
		}
		m[i-N+1] = tmpm;
	}
	for (ll i = 2*N-1; i >= N; i--) {
		if (Qtail.top() > a[i]) {
			tmpn += a[i];
			tmpn -= Qtail.top();
			Qtail.pop();
			Qtail.push(a[i]);
		}
		n[i-N] = tmpn;
	}
	rep(i, N+1) {
		res = max(res, m[i] - n[i]);
	}
	cout << res;
}

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

int main(){
	string str;
	cin >> str;
	
	vector<int> suji(str.size());
	vector<int> sanketa(str.size()-2);
	vector<int> sa(str.size()-2);
	
	for(int i=0;i<str.size();i++){
		if(str.at(i)=='0'){
			suji.at(i)=0;
		}
		else if(str.at(i)=='1'){
			suji.at(i)=1;
		}
		else if(str.at(i)=='2'){
			suji.at(i)=2;
		}
		else if(str.at(i)=='3'){
			suji.at(i)=3;
		}
		else if(str.at(i)=='4'){
			suji.at(i)=4;
		}
		else if(str.at(i)=='5'){
			suji.at(i)=5;
		}
		else if(str.at(i)=='6'){
			suji.at(i)=6;
		}
		else if(str.at(i)=='7'){
			suji.at(i)=7;
		}
		else if(str.at(i)=='8'){
			suji.at(i)=8;
		}
		else if(str.at(i)=='9'){
			suji.at(i)=9;
		}
	}
	
	for(int i=0;i<str.size()-2;i++){
		sanketa.at(i)=suji.at(i)*100+suji.at(i+1)*10+suji.at(i+2);
//      	cout << sanketa.at(i) << endl;
	}
	
	for(int i=0;i<str.size()-2;i++){
		if(sanketa.at(i)>=753){
			sa.at(i)=sanketa.at(i)-753;
		}
		else{
			sa.at(i)=753-sanketa.at(i);
		}
//      cout << sa.at(i) << endl;
	}

//  	cout << "" << endl;
	sort(sa.begin(), sa.end());
  
//	for(int i=0;i<str.size()-2;i++)	{
    		cout << sa.at(0) << endl;
//    }

	}

	
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int ans[100022],arr[100022];
int main()
{
	int n,i,k;
	cin>>n>>k;
	for(i=0;i<n;i++)
		cin>>arr[i];
	ans[0]=0;
	for(i=1;i<n;i++)
	{
		ans[i]= abs(arr[i]-arr[i-1])+ans[i-1];
		for(int j=2;j<=min(i,k);j++)
			ans[i]= min(ans[i],abs(arr[i]-arr[i-j])+ans[i-j]);
	}
	cout<<ans[n-1];
	return 0;
}


Measured memory_bytes: 1792