akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  lint ans=1;
  lint p=1000*1000*1000+7;
  FOR(i,1,N+1){
    ans*=(lint)i;
    ans%=p;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	string str;
	cin >> str;
	int nagasa = str.size();
	for (int i = 0; i < nagasa; i = i + 2) {
		cout << str[i];
	}
	cout << endl;
	return 0;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define imid int mid=l+r>>1
#define ilr int l=i<<1,r=i<<1|1
#define LL long long
#define db double
#define INF 1000000007
#define mod 1000000007
#define maxn 100010
using namespace std;
int sum[maxn],ans,n;
int main()
{
	scanf("%d",&n);  for(int i=1,a;i<=n;i++)scanf("%d",&a),sum[a]++;
	for(int i=1;i<=maxn-10;i++)ans=max(ans,sum[i]+sum[i-1]+sum[i+1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: New Year
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int m;
  cin >> m;
  printf("%d\n", 48 - m);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	string s; cin>>s;
	int e_ans = 0;
	rep(i,s.size()){
		e_ans += (s[i]=='1');
	}
	cout<<min(e_ans, (int)(s.size()-e_ans))*2<<endl;
	return 0;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

const Mod = 1000000007

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	ans := ModPow(2, n) - CombMod(n, a) - CombMod(n, b) - 1
	fmt.Println((ans + 2*Mod) % Mod)
}

func CombMod(left, right int) int {
	if right == 0 {
		return 1
	}
	v := left
	div := right
	for i := 1; i < right; i++ {
		v = v * (left - i) % Mod
		div = div * (right - i) % Mod
	}
	div = ModPow(div, Mod-2)
	return v * div % Mod
}

func ModPow(a, n int) int {
	if n == 0 {
		return 1
	}
	v := 1
	for p := n; p > 0; p >>= 1 {
		if p&1 == 1 {
			v = v * a % Mod
		}
		a = a * a % Mod
	}
	return v
}


Measured memory_bytes: 512
/* Tuan Kkura */
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define PROB "text"
#define MAXN 200005

int a[MAXN], b[MAXN], c[MAXN];

int main()
{
    _io
    int n; cin >> n;
    FOR(i, 1, n)    cin >> a[i];
    FOR(i, 1, n)    cin >> b[i];
    FOR(i, 1, n-1)    cin >> c[i];
    int res = 0;
    FOR(i, 1, n)
    {
        res += b[a[i]];
        if(i < n && a[i+1]-1 == a[i])
            res += c[a[i]];
    }
    cout << res;
}


Measured memory_bytes: 256
// 2011/04/04 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		double xA, yA, xB, yB, xC, yC, xD, yD;
		cin >> xA;
		if(cin.eof())
			break;
		cin >> yA >> xB >> yB >> xC >> yC >> xD >> yD;

		double xAB = xB-xA;
		double yAB = yB-yA;
		double xCD = xD-xC;
		double yCD = yD-yC;

		if(xAB*xCD+yAB*yCD==0.0)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // n回
#define PI 3.14f
typedef long long ll;
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s[s.size() - 1] == 's') {
    s.push_back('e');
    s.push_back('s');
  } else {
    s.push_back('s');
  }
  cout << s << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,T,A;
    cin >> N >> T >> A;
    int mini = INF,ans;
    rep(i,0,N){
        int h;
        cin >> h;
        if(mini > abs(T * 1000 - h * 6 - A * 1000)){
            mini = abs(T * 1000 - h * 6 - A * 1000);
            ans = i;
        }
    }
    cout << ans + 1 << endl;
}

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


int main(){
    int A,B;cin >> A >> B;
    vector<vector<int>> ans(100,vector<int>(100,0));
    for(int a = 0;a < 50;a++){
        for(int b = 0;b < 100;b++)ans.at(a).at(b)=1;
    }
    for(int a = 0;a < 50;a++){
          if(A == 1)break;
        for(int b = 0;b<100;b++){
              if(A == 1)break;
            if(a %2 == 0 && b % 2 == 0){
                ans.at(a).at(b) = 0;
                A--;
            }
          
        }
    }
    for(int a = 99;a >= 50;a--){
          if(B == 1)break;
        for(int b = 99;b>=0;b--){
              if(B == 1)break;
            if(a % 2 == 1 && b % 2 == 1){
                ans.at(a).at(b) = 1;
                B--;
            }
            if(B == 1)break;
        }
        if(B == 1)break;
    }
    cout<<100<<" "<<100<<endl;
    for(int a = 0;a< 100;a++){
        for(int b = 0;b < 100;b++){
            cout<<(ans.at(a).at(b) == 0 ? '.':'#');
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <queue>

using namespace std;

int n, q, t;

int main(void){
	queue< pair<string, int> > Q;
	cin >> n >> q;
	for(int i = 0; i< n; i++){
		string s;
		int T;
		cin >> s >>T;
		pair<string, int> p(s, T);
		Q.push(p);
	}

	while(!Q.empty()){
		pair<string, int> p;
		p = Q.front();
		Q.pop();
		if(p.second <= q){
			t += p.second;
			cout << p.first << " " << t << endl;
		}else{
			t += q;
			pair<string, int> p2(p.first, p.second - q);

			Q.push(p2);
		}
	}
	
    return 0;
}

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

template <typename T>
using Matrix = vector<vector<T>>;

template <typename T>
Matrix<T> matrix(const int R, const int C, const T x = T()) { return Matrix<T>(R, vector<T>(C, x)); }

int main()
{
    int H, W, K; cin >> H >> W >> K;

    auto grid = vector<string>(H);
    for (auto& row : grid) cin >> row;

    struct Point { int row, column; };

    Point start;
    for (auto row = 0; row < H; row++) for (auto column = 0; column < W; column++)
        if (grid[row][column] == 'S') start = {row, column};

    const auto straight_line_solution = [&](const Point p)
    {
        const auto d = min({p.row, H-1-p.row, p.column, W-1-p.column});
        return (d + (K-1)) / K;
    };

    auto seen = matrix<bool>(H, W);
    struct State { Point p; int distance; };
    auto queue = std::queue<State>();

    seen[start.row][start.column] = true;
    queue.push({start, 0});

    auto result = numeric_limits<int>::max();
    while (!queue.empty())
    {
        const auto s = queue.front(); queue.pop();

        result = min(result, 1 + straight_line_solution(s.p));

        if (s.distance == K) continue;

        const auto dr = array<int, 4>{-1, 0, 1, 0};
        const auto dc = array<int, 4>{0, 1, 0, -1};
        for (auto i = 0; i < 4; i++)
        {
            const auto row = s.p.row + dr[i], column = s.p.column + dc[i];
            if (0 <= row && row < H && 0 <= column && column < W && grid[row][column] != '#' && !seen[row][column])
            {
                seen[row][column] = true;
                queue.push({{row, column}, s.distance+1});
            }
        }
    }

    cout << result << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int m, f, r;
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1){
      break;
    }
    if (m == -1 || f == -1){
      cout << 'F' << endl;
    } else if (m + f >= 80){
      cout << 'A' << endl;
    } else if (m + f >= 65){
      cout << 'B' << endl;
    } else if (m + f >= 50){
      cout << 'C' << endl;
    } else if (m + f >= 30){
      if (r >= 50){
        cout << 'C' << endl;
      } else {
        cout << 'D' << endl;
      }
    } else {
      cout << 'F' << endl;
    }
  }
}


Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int w = sc.nextInt();

		if(w >= s) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}
	}
}

Measured memory_bytes: 35756
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a); a = (a * a);  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 200009;
ll i,n,m;
ll f[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,1,n + 1) f[i % m] += 1;
    if(m & 1)
        cout<<modexp(f[0],3LL);
    else
        cout<<modexp(f[0],3LL) + modexp(f[m / 2],3LL);
    return 0;
}

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

#define Online 1
// #define multitest 1
#define Debug 1
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

void solve()
{
	int a,b;
	cin >> a >> b;
	if(a>=13)
		cout << b;
	else if(a>=6)
		cout << b/2;
	else cout << 0;
}

int main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

void ControlIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef Online
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define M 1000000007

using namespace std;

int main(void){
    int a,b,c;
    cin>>a>>b;
    c=a+b;
    if(c%2==0){
        cout<<int(c/2)<<endl;
    }else
    {
        cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
  
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//String S = sc.next();
		//int N = Integer.parseInt(sc.next());
		//out.println();
		// ArrayList<String> list = new ArrayList<String>();
		// list.stream().sorted().distinct();
		String S = sc.next();
		
		out.println("ABC"+S);
		out.flush();	
	}
}

Measured memory_bytes: 23124
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int yyyy = int.Parse(s[0].ToString()) * 1000 + int.Parse(s[1].ToString())*100 + int.Parse(s[2].ToString()) * 10 + int.Parse(s[3].ToString()) * 1;
            int mm = int.Parse(s[5].ToString())*10 + int.Parse(s[6].ToString());
            int dd = int.Parse(s[8].ToString())*10 + int.Parse(s[9].ToString());
            if (yyyy < 2019) Console.WriteLine("Heisei");
            else if (yyyy == 2019 && mm <= 4) Console.WriteLine("Heisei");
            else Console.WriteLine("TBD");
        }
    }
}


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

int main() {
	int N, keta;
	int f = 0;

	cin >> N;	//組の入力
	keta = N;
	while (keta > 0) {
		f += keta % 10;
		keta /= 10;
	}
	if (N % f == 0) {
		cout << "Yes" << endl;
	}

	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

void solve(string s, long long x, long long y){
    pair<long long, long long> dest(x, y);
    pair<long long, long long> orig(0, 0);
    vector< vector<long long> > xy(2, vector<long long>());
    long long tmp = 0;
    int c = 0;
    int i_ = 0;
    while (s[i_] != 'T' && i_ < s.size()) {
        i_++;
    }
    orig.first += i_;
    for (int i = i_; i < s.size(); i++) {
        if (s[i] == 'T') {
            if (tmp != 0) {
                xy[c].push_back(tmp);
            }
            c = c==0 ? 1 : 0;
            tmp = 0;
        } else {
            tmp++;
        }
    }
    if (tmp != 0) {
        xy[c].push_back(tmp);
    }
    long long xmax = accumulate(xy[0].begin(), xy[0].end(), 0);
    long long ymax = accumulate(xy[1].begin(), xy[1].end(), 0);
    vector< vector<bool> > dpx(2, vector<bool>((xmax)*2+1+orig.first, false));
    int e = 0;
    dpx[e][xmax+orig.first] = true;
    for (int i = 0; i < xy[0].size(); i++) {
        dpx[e==0 ? 1 : 0].assign((xmax)*2+1+orig.first, false);
        for (int j = 0; j < (xmax*2)+1+orig.first; j++) {
            if (dpx[e][j]) {
                dpx[e==0 ? 1 : 0][j+xy[0][i]] = true;
                dpx[e==0 ? 1 : 0][j-xy[0][i]] = true;
            }
        }
        e = e==0 ? 1 : 0;
    }
    vector< vector<bool> > dpy(2, vector<bool>((ymax)*2+1, false));
    int e2 = 0;
    dpy[e2][ymax+orig.second] = true;
    for (int i = 0; i < xy[1].size(); i++) {
        dpy[e2==0 ? 1 : 0].assign((ymax)*2+1, false);
        for (int j = 0; j < (ymax*2)+1; j++) {
            if (dpy[e2][j]) {
                dpy[e2==0 ? 1 : 0][j+xy[1][i]] = true;
                dpy[e2==0 ? 1 : 0][j-xy[1][i]] = true;
            }
        }
        e2 = e2==0 ? 1 : 0;
    }
    if (dest.first > xmax+orig.first || dest.first < -xmax+orig.first || dest.second > ymax || dest.second < -ymax) {
        std::cout << "No" << std::endl;
    } else {
        if (dpx[e][xmax+dest.first] && dpy[e2][ymax+dest.second]) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << "No" << std::endl;
        }
    }
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long x;
    string s;
    long long y;
    cin >> s;
    scanf("%lld",&x);
    scanf("%lld",&y);
    solve(s, x, y);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define int long long
using pint=pair<int,int>;

int N;
int A[18];
map<pair<pint,pint>,int> dp;
int dfs(int l,int r,int kl,int kr){
  if(l+1==r)return 0;
  pair<pint,pint> p={{l,r},{kl,kr}};
  if(dp.find(p)!=dp.end())return dp[p];
  int ret=LLONG_MAX;
  for(int i=l+1;i<r;i++){
    int ki=kl+kr;
    ret=min(ret,ki*A[i]+dfs(l,i,kl,ki)+dfs(i,r,ki,kr));
  }
  return dp[p]=ret;
}
signed main(){
  cin>>N;
  for(int i=0;i<N;i++)cin>>A[i];
  cout<<dfs(0,N-1,1,1)+A[0]+A[N-1]<<endl;
}

Measured memory_bytes: 22016
s = input()
m = ["dream", "dreamer", "erase", "eraser"]
t = ""
i = 0
find = False
fin = False
while fin == False:
    if s[i:i+6] == m[3]:
        t += m[3]
        i += 6
    elif s[i:i+5] == m[2]:
        t += m[2]
        i += 5
    elif s[i:i+5] == m[0]:
      
        if s[i+5:i+7] == "er":
            if s[i+5:i+10] == "erase":
                t += m[0]
                i += 5
            else:
                t += m[1]
                i += 7
        else:
            t += m[0]
            i += 5
       
    else:
        fin = True

    if i >= len(s):
        find = True


if find:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
input = __import__('sys').stdin.readline
MIS = lambda: map(int,input().split())

n, m = MIS()
adj = [[] for i in range(n+1)]
speaker = [[] for i in range(m+1)]
for i in range(n):
    lang = list(MIS())[1:]
    for x in lang: speaker[x].append(i+1)
for L in speaker:
    for i in range(len(L)-1):
        adj[L[i]].append(L[i+1])
        adj[L[i+1]].append(L[i])

vis = [False]*(n+1); vis[1] = True
stack = [1]
while stack:
    p = stack.pop()
    for q in adj[p]:
        if vis[q]: continue
        vis[q] = True; stack.append(q)
print("YES" if sum(vis) == n else "NO")

Measured memory_bytes: 26696
#include <iostream>

int main(int argc, char const *argv[])
{
    while (true) {
        int x, y;
        std::cin >> x >> y;
        if (x == 0 && y == 0) {
            break;
        }

        x < y ? std::cout << x << " " << y << std::endl
        : std::cout << y << " " << x << std::endl;
    }
}

Measured memory_bytes: 3068
($N,$M)=glob<>;
@_=<>;
($S,$T)=glob pop@_;
map{push@{$`+$_*$N},$'+($_+1)%3*$N for!/ /..2}@_;
@q=$S;
$d[$S]=0;
while(@q){
	$q=shift@q;
	$d[$_]//=((push@q,$_),$d[$q]+1)for@$q
}
print$d[$T]/3||-1


Measured memory_bytes: 189440
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      int X = sc.nextInt();
      int A = sc.nextInt();
      System.out.println((X < A) ? 0 : 10);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
int64_t N,P,p,i,r,v,m[1<<20];std::string S;main(){std::cin>>N>>P>>S;if(10%P)for(*m=p=1,i=N;i--;)r+=m[v=(v+(S[i]-48)*(p=(p*10)%P))%P]++;else for(;i<N;i++)if(!((S[i]-8)%P))r+=i+1;std::cout<<r;}


Measured memory_bytes: 644
//
//  main.cpp
//  dp
//
//  Created by 贾皓翔 on 2019/11/26.
//  Copyright © 2019 贾皓翔. All rights reserved.
//
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <cstring>
#include <unordered_set>
#define ll long long
using namespace std;
int buf[200005];
int minBUf[200005];
int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>buf[i];
    }
    int c=0;
    int m=buf[0];
    for(int i=0;i<N;i++){
        if(buf[i]<m){
            m=buf[i];
        }
        minBUf[i]=m;
    }
    for(int i=0;i<N;i++){
        if(buf[i]<=minBUf[i]){
            c++;
        }
    }
    cout<<c<<endl;
    
}





Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main(void){

    string input_str, ans_str;
    
    cin >> input_str;
    
    if(input_str[(int)(input_str.length())-1]=='s'){
        ans_str = input_str + "es";
    }else{
        ans_str = input_str + "s";
    }
    
    cout << ans_str << endl;
    
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int rem,flag;
    while(n>0){
        rem=n%10;
        if(rem==7){
            flag=0;
            cout<<"Yes";
            break;
 
        }
        else flag=1;
        n/=10;
    }
    if(flag==1) cout<<"No";
 
}

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

signed main () {
    int x, n, t;
    cin >> x >> n;
    set < int > p;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        p.insert(t);
    }
    int d = 1000, ans = -1;
    for (int j = x - n; j <= x + n; ++j) {
        if (p.find(j) == p.end()) {
            if (abs(j - x) < d) {
                d = abs(j - x);
                ans = j;
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
int main()
{
	int n,i,j,k;
	cin>>n;
	long long a[n+1][n+1];
	for(i=1;i<=n;i++)for(j=1;j<=n;j++)cin>>a[i][j];
	long long ans=0;
	
	for(k=1;k<=n;k++)
	{
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(a[i][j]>a[i][k]+a[k][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			ans+=a[i][j];
			for(k=1;k<=n;k++)
			{
				if(k!=i and k!=j and a[i][k]+a[k][j]==a[i][j])
				{
					ans-=a[i][j];
					break;
				
				}
			}
		}
	}
	
	cout<<ans;
}

Measured memory_bytes: 1024
is_prime = [True] * (10**5)
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, len(is_prime)):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, len(is_prime), i):
            is_prime[j] = False

def do_prime_fact(x, ps):
    res = {}
    for prime in ps:
        while x % prime == 0:
            x /= prime
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
    if x > 1: # x is large prime
        res[x] = 1
    return res

def solve(x):
    y = do_prime_fact(x[1] - x[0], primes)
    ps = y.keys()
    ys = [do_prime_fact(x[i+1] - x[i], ps) for i in range(len(x)-1)]
    d = 1
    for k in ps:
        ok = True
        while ok:
            for y in ys:
                if (not k in y) or (y[k] == 0):
                    ok = False
                    break
            if ok:
                for y in ys:
                    y[k] -= 1
                d *= k
    return d

n, x0 = map(int, raw_input().split())
x = map(int, raw_input().split())
x = list(sorted(set([x0] + x)))
print(solve(x))

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

int main() {
    long long n;
    cin >> n;
    if(n & 1ll) {
        cout << 0;
    } else {
        long long count = 0;
        while(n) {
            count += (n / 5) / 2;
            n /= 5;
        }
        cout << count;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool s[101];

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

    fill(s, s + 101, false);

    int d, A;
    for (int i = 0; i < K; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> A;
            s[A] = true;
        }
    }

    int ans = 0;

    for (int i = 1; i <= N; i++) {
        if (!s[i]) ans++;
    }

    cout << ans << endl;
}

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

#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define pb  push_back

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

using int_type = int64_t;

const int N = 2e5 + 3;

int main() {

    int_type k, x;
    cin >> k >> x; 
    if(500 * k >= x)
        cout << "Yes\n";
    else 
        cout << "No\n"; 

    return 0;
}


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    int n;
    cin >> n;
    vector<int>p(n+1);
    for(int i=1;i<=n;i++){
        cin >> p[i];
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(p[i]==i){
            swap(p[i],p[i+1]);
            ans++;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define foru(i, a, b) for(int i = int(a); i <= int(b); i++)
#define ford(i, a, b) for(int i = int(a); i >= int(b); i--)
using namespace std;

const int N = 3005;

int n, t, s, a[N], b[N];
int f1[N][N], luu[N], maxx[N];

int main() {
    //freopen("a.txt", "r", stdin);

    scanf("%d%d%d", &n, &t, &s);
    foru(i, 1, n) scanf("%d%d", &a[i], &b[i]);
    ///xuoi
    foru(j, 0, t) maxx[j] = 0;
    foru(i, 1, n) {
        foru(j, 0, t) {
            f1[i][j] = f1[i-1][j];
            if (j >= b[i]) f1[i][j] = max(f1[i][j], maxx[j-b[i]] + a[i]);
        }
        foru(j, 0 , t) {
            maxx[j] = max(maxx[j], f1[i][j]);
            if (j) maxx[j] = max(maxx[j], maxx[j-1]);
        }
    }
    foru(i, 1, n) {
        luu[i] = f1[i][s];
        foru(j, 0, t) f1[i][j] = 0;
    }
    ///nguoc
    foru(j, 0, t) maxx[j] = 0;
    ford(i, n, 1) {
        ford(j, t, 0) {
            f1[i][j] = f1[i+1][j];
            if (j+b[i] <= t) f1[i][j] = max(f1[i][j], maxx[j+b[i]] + a[i]);
        }
        ford(j, t, 0) {
            maxx[j] = max(maxx[j], f1[i][j]);
            if (j < t) maxx[j] = max(maxx[j], maxx[j+1]);
        }
    }

    int ans = 0;
    foru(i, 1, n) ans = max(ans, luu[i] + f1[i+1][s]);
    cout << ans << endl;

}

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

int main(){
  int N,M,C;
  cin>>N>>M>>C;
  vector<int> B(M);
  for (int i=0; i<M; i++){
    cin>>B.at(i);
  }
  vector<vector<int>> A(N,vector<int>(M));
  vector<int> AB_sum(N,0);
  for (int i=0; i<N; i++){
    for (int j=0; j<M; j++){
      cin>>A.at(i).at(j);
      A.at(i).at(j)*=B.at(j);
      AB_sum.at(i)+=A.at(i).at(j);
    }
  }
  int count=0;
  for (int i=0; i<N; i++){
    if ((AB_sum.at(i)+C)>0){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X), B(Y), C(Z);
  for(int i=0; i<X; i++)
    cin >> A[i];
  for(int i=0; i<Y; i++)
    cin >> B[i];
  for(int i=0; i<Z; i++)
    cin >> C[i];
  sort(A.begin(), A.end(), greater<ll>());
  sort(B.begin(), B.end(), greater<ll>());
  sort(C.begin(), C.end(), greater<ll>());
  vector<ll> all;
  for(int i=0; i<X; i++)
    for(int j=0; j<Y; j++)
      for(int k=0; k<Z; k++)
	if(i * j * k < K)
	  all.push_back(A[i] + B[j] + C[k]);
  sort(all.begin(), all.end(), greater<ll>());
  for(int i=0; i<K; i++)
    cout << all[i] << endl;
  return 0;
}


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

int main(){
  int A,B,H,M;
  long double rh,rm,rd,c;
  cin >> A >> B >> H >> M;
  
  rh = 2 * M_PI * H / 12.0 + 2*M_PI/12.0/60.0*M;
  rm = 2 * M_PI * M / 60.0;
  rd = rh - rm;
  
  //cout << rd << endl;
  
  if(rd < 0)
    rd = -rd;
  if(rd > M_PI)
    rd = 2 * M_PI - rd;
  
  c = A*A + B*B - (2 * A * B * cos(rd));
  c = sqrt(c);
  
  if(rd == 0)
    c = abs(A-B);
  
  cout << fixed << setprecision(15) << c << endl;
}

Measured memory_bytes: 4080
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let h: i32 = s.next().unwrap().parse().unwrap();
	let w: i32 = s.next().unwrap().parse().unwrap();
	let n: i32 = s.next().unwrap().parse().unwrap();
	let m = std::cmp::max(h, w);
	println!("{}", (n + m - 1) / m);
}


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

struct UnionFind{
    vector<int> tree;

    UnionFind(int n): tree(n+1, -1) {};

    int root(int i){ return tree[i] < 0 ? i : tree[i] = root(tree[i]); }

    bool unite(int i, int j){
        i = root(i), j = root(j);
        if(i == j) return false;
        tree[i] += tree[j], tree[j] = i;
        return true;
    }

    bool same(int i, int j){ return root(i) == root(j); }

    int size(int i){ return -tree[root(i)]; }
};

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

    UnionFind uf(n);
    for(int i = 0;i < m;i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        uf.unite(a, b);
    }

    int ans = 0;
    for(int i = 0;i < n;i++){
        if(i == uf.root(i)){
            ans++;
        }
    }

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

Measured memory_bytes: 768
n = int(input())
s = input()

# S:1 W:-1
T = [[1, 1], [1, -1], [-1, 1], [-1, -1]]
for t in T:
    for i in range(n-1):
        if t[i+1] == 1:
            if s[i+1] == "o":
                t.append(t[i])
            else:
                t.append(-1*t[i])
        else:
            if s[i+1] == "o":
                t.append(-1*t[i])
            else:
                t.append(t[i])
#print(T)
for t in T:
    if t[0] == t[-1]:
        if t[0] == 1:
            if s[0] == "o" and t[-2] == t[1]:
                ans = t
                break
            elif s[0] == "x" and t[-2] != t[1]:
                ans = t
                break
        elif t[0] == -1:
            if s[0] == "o" and t[-2] != t[1]:
                ans = t
                break
            elif s[0] == "x" and t[-2] == t[1]:
                ans = t
                break
else:
    print(-1)
    exit()


str_ans = ""
for i in range(n):
    if ans[i] == 1:
        str_ans += "S"
    elif ans[i] == -1:
        str_ans += "W"
print(str_ans)




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

int main(){
int x, y, z, tmp;
int one, two, three;
cin >> x >> y >> z;
if ( x > y ) {
tmp = x;
x = y;
y = tmp;
}
if ( y > z ) {
tmp = y;
y = z;
z = tmp;
}
if ( x > y ) {
tmp = x;
x = y;
y = tmp;
}

cout << x << " " << y << " " << z << endl;
return 0;
}

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

int main() {
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> A(N);
  
  for(int i=0;i<Q;i++){
    int Ai;
    cin >>Ai;
    A.at(Ai-1)+=1; 
  }
  for(int i=0;i<N;i++){
    A.at(i)+=K-Q;
    if (A.at(i)>0){
      cout << "Yes" <<endl;
    }
    else{
      cout << "No" <<endl;
    }
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int
const int mod = (int)1e9 + 7;
const int lim = (int)2e5;
vi fac(lim);



long long inv(long long a, long long b = mod){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}

int c(int n, int k){
    assert(k >= 0 && k <= n);
    int ans = fac[n] * inv(fac[k]);
    ans %= mod;
    ans *= inv(fac[n-k]);
    ans %= mod;
    //cout <<n  << "  " << k << " " << ans <<endl;
    return ans;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;cin >> n;
    vi in(n);
    FOR(i, n)cin >> in[i];
    int ans = 0;
    fac[0] =1;
    FOR1(i, lim)fac[i] = fac[i-1]*i, fac[i] %= mod; 

    vi pre;
    pre.pb(0);
    int sum  =0; 
    int sum2 = 0;
    // 1 boundary
    for(int pr = 0; pr < n -1; pr++){
        sum += in[pr];
        sum %= mod;
        pre.pb(sum);
        int ways = c(n, pr +2) * fac[pr + 1]; 
        ways %= mod;
        ways *= fac[n - pr - 2];
        ways %= mod;
        sum2 += in[n - pr- 1];
        sum2 %= mod;
        ans += ways*(sum2 + sum);
        ans %= mod;
    }
    sum2 += in[0];
    sum += in[n-1];
    sum %= mod;
    sum2 %= mod;
    assert(sum == sum2);
    pre.pb(sum);
    
    // 0 boundary
    ans += sum *fac[n]; 
    
    // 2 boundary cases
    vi tri1(n), tri2(n);
    sum = 0;
    sum2 = 0;
    int cum = 0;
    int cum2 = 0;
    for(int i = 1; i < n; i++){
        sum += in[i] * i;
        sum %= mod;
        tri1[i] = sum;
        sum2 += in[n - 1 - i] * (i);
        sum2 %= mod;
        tri2[n - 1- i] = sum2; 
    }
    int i = 0;
    int j = n- 1;
    for(int len = 1; len <= n-2; len++){
        int ways = c(n, len + 2) * 2 * fac[len];
        ways %= mod;
        ways *= fac[n - len - 2];
        ways %= mod;
        ans += ways*(((tri1[i] + tri2[j] + (pre[j] - pre[i+1])*len))%mod);
        ans %= mod;
        i++;
        j--;

    }
    ans %= mod;
    while(ans < 0)ans += mod;
    cout << ans;

}




Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int a, b, c; cin >> a >> b >> c;

  if (a == b && a != c) cout << "Yes" << endl;
  else if (b == c && a != b) cout << "Yes" << endl;
  else if (a == c && a != b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
int main(){
    int N,M;
    cin >> N >> M;
    vector<int>cnt(N+1,0);
    for(int i = 0; i < M; ++i){
        int a,b; cin >> a >> b;
        cnt[a] += 1; cnt[b] += 1;
    }
    if(find_if(cnt.begin(),cnt.end(),[](int e){
        return (e % 2 != 0);
    }) == cnt.end()){
        return puts("YES") * 0;
    }
    cout << "NO" << endl;
}



Measured memory_bytes: 3776
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;

int main(int argc, const char * argv[]) {
    long N, K;
    cin >> N >> K;
    
    long rangemin = 3e8+1;
    queue<long> q;
    REP(i, N) {
        long x;
        cin >> x;
        q.push(x);
        if (q.size() == K) {
            long y = q.front();
            q.pop();
            assert(x >= y);
            long r = min(abs(x), abs(y)) + x-y;
            rangemin = min(rangemin, r);
        }
    }
    
    cout << rangemin << endl;
}


Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include<vector>

struct DisjointSet {
    std::vector<int> par;
    std::vector<int> rak; // number of the vertices

    void init(int n) {
      par.resize(n);
      rak.resize(n);
      for(int i=0; i<n; i++) {
        par[i] = i;
        rak[i] = 1;
      }
    }

    int find(int x) {
      if (par[x] == x) {
        return x;
      } else {
        return par[x] = find(par[x]);
      }
    }

    void unite(int x, int y) {
      x = find(x);
      y = find(y);
      if (x==y) return;
      if (rak[x] < rak[y]) {
        rak[y] += rak[x];
        par[x] = y;
      } else {
        rak[x] += rak[y];
        par[y] = x;
      }
    }

    bool same(int x, int y) {
      return find(x) == find(y);
    }
};


class ADisjointSetUnion {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      DisjointSet dsu;
      int n; cin >> n;
      int q; cin >> q;
      dsu.init(n);
      while(q--) {
        int t, u, v; cin >> t >> u >> v;
        if (t == 0) {
          dsu.unite(u, v);
        } else {
          if (dsu.same(u, v)) {
            cout << 1 << '\n';
          } else {
            cout << 0 << '\n';
          }
        }
      }
    }
};

signed main() {
  ADisjointSetUnion solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 4728
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    vector<vector<int>> P(N, vector<int>(11));
    rep(i, N) {
        rep(j, 10) { cin >> F[i][j]; }
    }
    rep(i, N) {
        rep(j, 11) { cin >> P[i][j]; }
    }
    int res = -INF;
    for(int bit = 1; bit < (1 << 10); bit++) {
        int tmp = 0;
        rep(i, N) {
            int cnt = 0;
            rep(j, 10) {
                if((bit & (1 << j)) && F[i][j]) {
                    cnt++;
                }
            }
            tmp += P[i][cnt];
        }
        res = max(tmp, res);
    }
    cout << res << endl;
    return 0;
}

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

int main()
{
	int N, D;
	vector<int> d;
	cin >> N;
	int Kmax, Kmin;
	for (int i = 0; i < N; i++) {
		cin >> D;
		d.push_back(D);
	}
	sort(d.begin(), d.end());
	Kmax = d[N / 2 ];
	Kmin = d[N / 2 - 1];

	cout << Kmax - Kmin;
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> T INF = 1006633153;

int main() {
    int n;
    cin >> n;
    vector<int> v(n-1);
    for (auto &&i : v) scanf("%d", &i);
    vector<vector<int>> dp0(2, vector<int>(n/2+1, INF<int>)), dp1(2,vector<int>(n/2+1, INF<int>));
    dp0[0][0] = 0; dp1[0][1] = 0;
    for (int i = 0; i < n-1; ++i) {
        int now = i&1, nxt = now^1;
        fill(dp0[nxt].begin(),dp0[nxt].end(), INF<int>);
        fill(dp1[nxt].begin(),dp1[nxt].end(), INF<int>);
        for (int j = 0; j <= min(i+1, n/2); ++j) {
            dp0[nxt][j] = min({dp0[nxt][j], dp0[now][j], dp1[now][j]+v[i]});
            if(j < n/2) dp1[nxt][j+1] = min({dp1[nxt][j+1], dp0[now][j]+v[i], dp1[now][j]});
        }
    }
    cout << min(dp0[(n-1)&1][n/2], dp1[(n-1)&1][n/2]) << "\n";
    return 0;
}


Measured memory_bytes: 3372
n, d = gets.split(" ").map(&:to_i)
array = []
count = 0
n.times do
  array << gets.split(" ").map(&:to_i)
end

(1..n).to_a.combination(2) do |i, j|
  sum = 0
  array[i - 1].zip(array[j - 1]) do |a, b|
    sum += (a - b).abs ** 2
  end
  count += 1 if Math.sqrt(sum) == Math.sqrt(sum).to_i
end

puts count

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

vector<int> rec(int n,int a,int b){
    if (n==1) return {a,b};
    vector<int> res(1<<n),F,B;
    for (int i=n-1;i>=0;--i) if ((a^b)&(1<<i)){
        int c=((a>>(i+1))<<i)^(a&((1<<i)-1))
            ,d=((b>>(i+1))<<i)^(b&((1<<i)-1));
        F=rec(n-1,c,c^1); B=rec(n-1,c^1,d);
        for (int j=0;j<(1<<(n-1));++j){
            res[j]=((F[j]>>i)<<(i+1))^(a&1<<i)^(F[j]&(1<<i)-1);
            res[j+(1<<(n-1))]=((B[j]>>i)<<(i+1))^(b&1<<i)^(B[j]&(1<<i)-1);
        } break;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,A,B; cin >> N >> A >> B;
    if (!(__builtin_popcount(A^B)&1)){cout << "NO" << '\n'; return 0;}
    cout << "YES" << '\n';
    vector<int> ans=rec(N,A,B);
    for (int i=0;i<(1<<N);++i)
        cout << ans[i] << (i!=(1<<N)-1?' ':'\n');
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,H;
    cin >> H >> N;
    vec<int> A(N),B(N);
    for(int i=0;i<N;i++) cin >> A[i] >> B[i];
    vvec<int> dp(N+1,vec<int>(H+1,1e9));
    dp[0][0] = 0;
    for(int i=0;i<N;i++) for(int j=0;j<=H;j++){
        dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        int nh = min(H,j+A[i]);
        dp[i+1][nh] = min(dp[i+1][nh],dp[i][j]+B[i]);        
        dp[i+1][nh] = min(dp[i+1][nh],dp[i+1][j]+B[i]);
//        cerr << dp[i][j] << (j!=H? " ":"\n");
    }
    cout << dp[N][H] << endl;
}

Measured memory_bytes: 39424
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n; cin >> n;

    ll res = INF;
    rep(i, 1, sqrt(n) + 2){
        if(n % i == 0){
            chmin(res, i + n / i - 2);
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  string s;
  cin >> s;
  string t;
  rep(i, s.size()) {
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G'
       || s[i] == 'T')
      t.push_back('1');
    else
      t.push_back('0');
  }
  int ans = 0;
  int cnt = 0;
  rep(i, t.size()) {
    if(t[i] == '1') {
      cnt++;
      ans = max(ans, cnt);
    } else {
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

#include <iostream>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, dp[110000][2], pa[110000];
vector<vector<ll>> list(200000);
vector<ll> s;
queue<ll> q;


int main() {
	REP(i, 110000) REP(j, 2)dp[i][j] = 1;
	cin >> n;
	REP(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		list[a].push_back(b);
		list[b].push_back(a);
	}
	q.push(0);
	while (!q.empty()) {
		ll now = q.front();
		REP(i, list[now].size()) {
			if (list[now][i] != pa[now]) {
				pa[list[now][i]] = now;
				s.push_back(list[now][i]);
				q.push(list[now][i]);
			}
		}
		q.pop();
	}
	reverse(ALL(s));
	REP(i, s.size()) {
		ll a = list[s[i]].size();
		if (a == 1) {
			dp[s[i]][0] = 1;
			dp[s[i]][1] = 1;
		}
		dp[pa[s[i]]][0] *= dp[s[i]][0] + dp[s[i]][1];
		dp[pa[s[i]]][1] *= dp[s[i]][0];
		dp[pa[s[i]]][0] %= MOD;
		dp[pa[s[i]]][1] %= MOD;
	}
	if (n == 1)cout << 2 << endl;
	else cout << (dp[0][0] + dp[0][1]) % MOD << endl;
}

Measured memory_bytes: 13180
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N,A,B;

int main() {
  INCANT;
  cin >> N >> A >> B;
  A--;B--;
  if ((B-A)%2) {
    cout << "Borys";
  } else {
    cout << "Alice";
  }
  cout << "\n";
  return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    double pi = 3.1415926535;
    double a, b, C;
    cin >> a >> b >> C;
    double h = sin(M_PI * C / 180) * b;
    double c = sqrt(a * a + b * b - 2 * a * b * cos(M_PI * C / 180));

    double L = a + b + c;

    double S = h * a / 2;

    cout << fixed << setprecision(5) << S << endl;
    cout << fixed << setprecision(5) << L << endl;
    cout << fixed << setprecision(5) << h << endl;

    return 0;
}


Measured memory_bytes: 3428