akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define N 100005
int st[N],nd[N],a[N];
int pos[N],dfn[2*N],cnt,sum[N][2],s1;
int fa[N][20],dep[N],ans[N],n,m,an;
int g1[N][2];
bool f[N];
struct mzls
{
	int l,r,id,aa,bb;
	bool p;
}a1[N];
struct node
{
	int to,co,ct;
	node(){}
	node(int xx,int yy,int zz)
	{
		to=xx,co=yy,ct=zz;
	}
};
vector<node>g[N];
bool operator<(mzls a,mzls b)
{
	return pos[a.l]==pos[b.l]?a.r<b.r:a.l<b.l;
}
inline void dfs(int x)
{
	dfn[++cnt]=x;
	st[x]=cnt;
	dep[x]=dep[fa[x][0]]+1;
	for(int i=1;i<20;i++)
		fa[x][i]=fa[fa[x][i-1]][i-1];
	int l1=g[x].size();
	for(int i=0;i<l1;i++)
	{
		int v=g[x][i].to,co=g[x][i].co,ct=g[x][i].ct;
		if(v==fa[x][0])
			continue;
		fa[v][0]=x;
		g1[v][0]=co,g1[v][1]=ct;
		dfs(v);
	}
	dfn[++cnt]=x;
	nd[x]=cnt;
}
inline int LCA(int x,int y)
{
	if(dep[x]<dep[y])
		swap(x,y);
	for(int i=19;i>=0;i--)
		if(dep[fa[x][i]]>=dep[y])
			x=fa[x][i];
	if(x==y)
		return x;
	for(int i=19;i>=0;i--)
		if(fa[x][i]!=fa[y][i])
		{
			x=fa[x][i];
			y=fa[y][i];
		}
	return fa[x][0];
}
inline void modify(int x)
{
	if(!f[x])
	{
		sum[g1[x][0]][0]++;
		sum[g1[x][0]][1]+=g1[x][1];
		s1+=g1[x][1];
		f[x]=1;
	}
	else
	{
		sum[g1[x][0]][0]--;
		sum[g1[x][0]][1]-=g1[x][1];
		s1-=g1[x][1];
		f[x]=0;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)
	{
		int x,y,x1,y1;
		scanf("%d%d%d%d",&x,&y,&x1,&y1);
		g[x].push_back(node(y,x1,y1));
		g[y].push_back(node(x,x1,y1));
	}
	dfs(1);
	int d=sqrt(n);
	for(int i=1;i<=2*n;i++)
		pos[i]=i/d;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d%d%d",&a1[i].aa,&a1[i].bb,&a1[i].l,&a1[i].r);
		int lc=LCA(a1[i].l,a1[i].r);
		if(lc==a1[i].l||lc==a1[i].r)
		{
			if(lc==a1[i].r)
				swap(a1[i].l,a1[i].r);
			x=st[a1[i].l]+1;
			y=st[a1[i].r];
			a1[i].p=0;
		}
		else
		{
			if(st[a1[i].l]>st[a1[i].r])
				swap(a1[i].l,a1[i].r);
			x=nd[a1[i].l];
			y=st[a1[i].r];
			a1[i].p=1;
		}
		a1[i].l=x;
		a1[i].r=y;
		a1[i].id=i;
	}
	sort(a1+1,a1+m+1);
	int l1=1,r1=0;
	for(int i=1;i<=m;i++)
	{
		while(l1>a1[i].l)
			modify(dfn[--l1]);
		while(l1<a1[i].l)
			modify(dfn[l1++]);
		while(r1<a1[i].r)
			modify(dfn[++r1]);
		while(r1>a1[i].r)
			modify(dfn[r1--]);
		//int lc=LCA(dfn[l1],dfn[r1]);
		//if(a1[i].p)
		//	modify(lc);
		ans[a1[i].id]=s1-sum[a1[i].aa][1]+sum[a1[i].aa][0]*a1[i].bb;
		//if(a1[i].p)
		//	modify(lc);
	}
	for(int i=1;i<=m;i++)
		printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 24832
S = input()
dp = [[0] * 13 for _ in range(len(S) + 1)]
mod = pow(10, 9) + 7

dp[0][0] = 1
for i in range(1, len(dp)):
    c = int(S[i-1]) if S[i-1] != '?' else -1
    for j in range(13):
        for k in range(10):
            if c != -1 and c != k:
                continue
            dp[i][(j*10+k) % 13] += dp[i-1][j]
    for j in range(13):
        dp[i][j] %= mod

print(dp[-1][5])


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

using namespace std;

char to_num(char c)
{
    if (c <= 'c') return '2';
    if (c <= 'f') return '3';
    if (c <= 'i') return '4';
    if (c <= 'l') return '5';
    if (c <= 'o') return '6';
    if (c <= 's') return '7';
    if (c <= 'v') return '8';
    return '9';
}

vector<string> w, v;

void dfs(string &seq, int idx, vector<string> words)
{
    int size = seq.size();
    if (idx == size) {
        for (int i = 0; i < (int)words.size(); i++) {
            if (i > 0) cout << " ";
            cout << words[i];
        }
        cout << "." << endl;
        return;
    }

    for (int i = 0; i < (int)v.size(); i++) {
        int len = v[i].size();
        if (idx + len <= size) {
            bool ok = 1;
            for (int j = 0; j < len; j++) {
                if (seq[idx + j] != v[i][j]) {
                    ok = 0;
                    break;
                }
            }
            if (ok) {
                words.push_back(w[i]);
                dfs(seq, idx + len, words);
                words.pop_back();
            }
        }
    }
}

void init()
{
    w.clear();
    v.clear();
}

int main()
{
    int N;
    while (cin >> N, N) {
        init();
        string s, seq;
        for (int i = 0; i < N; i++) {
            cin >> s;
            string t;
            for (int j = 0; j < (int)s.size(); j++) {
                t += to_num(s[j]);
            }
            w.push_back(s);
            v.push_back(t);
        }
        cin >> seq;
        dfs(seq, 0, vector<string>());
        cout << "--" << endl;
    }
    return 0;
}

Measured memory_bytes: 3220
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	string s;
    cin >> s;
    ll tmp=0;
    if(s == "0"){
        cout << "Yes" << endl;
        return 0;
    }
    for(ll i=0;i<s.size();i++){
        tmp+=(ll)s[i]-48;
    }
    if(tmp%9==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll num;
vector<int>d;
ll dp[20][2];
int main(){
	cin>>num;
	if(num<=9){
		cout<<num<<endl;
		return 0;
	}
	while(num){
		d.pb(num%10);
		num/=10;
	}
	reverse(d.begin(),d.end());
	rep(a,20)rep(b,2) dp[a][b]=-INF;
	dp[0][1] = 0;
	rep(i,d.size()){
		if(dp[i][0] >= 0){
			dp[i+1][0] = max(dp[i+1][0],dp[i][0]+9);
		}
		if(dp[i][1] >= 0){
			if(d[i]){
				dp[i+1][0] = max(dp[i+1][0],dp[i][1]+d[i]-1);
			}
			dp[i+1][1] = max(dp[i+1][1],dp[i][1]+d[i]);
		}
	}
	cout<<max(dp[d.size()][0],dp[d.size()][1])<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a,b;
  cin>>a>>b;
 // cout<<a<<endl<<b;
    if(a=="H"){
      cout<<b;
    }
  	else{
      if(b=="H"){
        cout<<"D";
    	}
      else{
        cout<<"H";
      }
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<string.h>
#include<cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;


int main()
{
    int n, m, x, c[12], a[12][12];
    cin >> n >> m >> x;
    rep(i, n)
    {
        cin >> c[i];
        rep(j, m)
        {
            cin >> a[i][j];
        }
    }
    
    const int max = 12000 * pow(10, 5);
    int res = max;
    rep(comb_, pow(2, n))
    {
        int sum = 0, comb = comb_;
        int und[12] = {0};
        rep(i, n)
        {
            if(comb & 1)
            {
                sum += c[i];
                rep(j, m)
                {
                    und[j] += a[i][j];
                }
            }
            comb >>= 1;
        }
        bool isAble = true;
        rep(i, m)
        {
            if (und[i] < x) isAble = false;
        }
        if (isAble) res = min(res, sum);
    }
    if (res == max) cout << -1 << endl;
    else cout << res << endl;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
//#define Mfc_Tanzim
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ff first
#define ss second
#define all(v) (v.begin(), v.end())
#define pi acos(-1.0)
#define FastRead ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define bug(a) cerr << #a << " : " << a << endl
using namespace std;

ll posx[] = {1,-1, 0, 0};
ll posy[] = {0, 0, 1,-1};

int main()
{
    FastRead

#ifdef Mfc_Tanzim
    freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
#endif /// Mfc_Tanzim

    ll n;
    cin >> n;
    cout << (1000-(n%1000))%1000 << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n,sum=0;
  cin >> n;
  vector<int> v=input(n);
  
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  
  rep(i,n){
    sum += v[i];
  }
  
  if(v[0]<sum-v[0]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(string, s);
    Cout(string(s.begin(), s.end()-8));
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace io{
	const int l=1<<19;
	char *s,*t,buf[l],c;
	char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	template<class IT>void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gc();}
	}
}
using io::gc;
using io::gi;
template<class IT>void chkmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>void chkmax(IT &a,IT b){if(a<b)a=b;}

const int N=1005;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int n,m,vis[N][N],s,x,y;
char c[N][N];
struct node{int x,y,d;};
queue<node>q;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",c[i]+1);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(c[i][j]=='#'){
		vis[i][j]=1;
		q.push((node){i,j,0});
	}
	while(!q.empty()){
		x=q.front().x;
		y=q.front().y;
		s=q.front().d;
		q.pop();
		for(int i=0;i<4;i++){
			int X=x+dx[i],Y=y+dy[i];
			if(X&&X<=n&&Y&&Y<=m&&!vis[X][Y]){
				vis[X][Y]=1;
				q.push((node){X,Y,s+1});
			}
		}
	}
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 17296
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let s: String = read!();

    let s = s.chars().collect_vec();

    let red = s.iter().filter(|c| **c == 'R').count();
    let white = s.iter().filter(|c| **c == 'W').count();

    let mut expected = String::new();

    for _ in 0..red {
        expected.push('R');
    }
    for _ in 0..white {
        expected.push('W');
    }

    let diff = s
        .iter()
        .zip(expected.chars())
        .filter(|(a, b)| **a != *b)
        .count();

    println!("{}", [red, white, diff / 2].iter().min().unwrap());
}


Measured memory_bytes: 3144
N,K=map(int,input().split())

a=[]
for i in range(K):
    if (K-i)*3%K==i and (K-i)*2%K==0:
        a.append(i)

b=[]
for i in range(len(a)):
    b.append((N-a[i])//K+1)
b[0]-=1

print(sum([i**3 for i in b]))

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

ll item[3030][3030];
ll dp[3030][3030][4];

int main()
{
    int R, C, K;
    cin >> R >> C >> K;
    rep(i,K)
    {
        int r, c, v;
        cin >> r >> c >> v;
        //r--; c--;
        item[r][c] = v;
    }

    rep(i,R+1) rep(j,C+1) rep(k,4)
    {
        //行移動, とる
        dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][k] + item[i+1][j]);
        //行移動, とらない
        dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
        //列移動,　とる
        if(k < 3) dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + item[i][j+1]);
        //列移動,　とらない
        dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
    }
    ll ans = 0;
    //rep(i,R+1) {rep(j,C+1) cout << item[i][j] << " "; cout<< endl;}
    //rep(i,R+1) {rep(j,C+1) cout << dp[i][j][0] << " "; cout<< endl;}
    //rep(i,4) cout << dp[R][C][i] << " ";
    rep(i,4) ans = max(ans, dp[R][C][i]);
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

typedef long long int lld;
typedef unsigned long long int llu;

lld foods[40];
int N, M;

int main() {
  scanf("%d %d", &N, &M);
  for(lld i = 0; i < N; i++) {
    lld num;
    scanf("%lld", &num);
    for(lld j = 0; j < num; j++) {
      lld tmp;
      scanf("%lld", &tmp);
      foods[tmp-1]++;
    }
  }
  lld ans = 0;
  for(lld i = 0; i < M; i++) {
    if(foods[i] == N) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;

}

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

int64_t gcd(int64_t a, int64_t b) {
    if (a < b) return gcd(b, a);
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int main() {
    int n;
    cin >> n;
    vector<int64_t> t(n);
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    vector<int64_t> gcd1(n);
    vector<int64_t> gcd2(n);
    int64_t curGcd = t[0];
    for (int i = 1; i < n; i++) {
        gcd1[i] = curGcd;
        curGcd = gcd(curGcd, t[i]);
    }
    curGcd = t[n-1];
    for (int i = n - 2; i >= 0; i--) {
        gcd2[i] = curGcd;
        curGcd = gcd(curGcd, t[i]);     
    }
    int64_t ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, gcd(gcd1[i], gcd2[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const int INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    sort(a.begin(),a.end());
    int res = -1;
    for (int i = 1; i < 99999; i++) {
        int tmp = lower_bound(a.begin(),a.end(),i+2) -
                  upper_bound(a.begin(),a.end(),i-2);
        chmax(res,tmp);
    }
    cout << res << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<int>> vc;
int n;
int dp[100005][3];

int go(int i , int prev) {
	if (i >= n)
		return 0;
	if (dp[i][prev] != -1)
		return dp[i][prev];
	int res = -1;
	if (prev == 0)
		res = max(vc[i][1] + go(i + 1, 1), vc[i][2] + go(i + 1, 2));
	else if (prev == 1)
		res = max(vc[i][0] + go(i + 1, 0), vc[i][2] + go(i + 1, 2));
	else
		res = max(vc[i][1] + go(i + 1, 1), vc[i][0] + go(i + 1, 0));
	return dp[i][prev] = res;
}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	int t = n;
	int x, y, z;
	memset(dp, -1, sizeof(dp));
	while (t--) {
		cin >> x >> y >> z;
		// int one = max({x, y, z});
		// int three = min({x, y, z});
		// int two = x ^ y ^ z ^ one ^ three;

		vc.push_back({x, y, z});
	}
	cout << max({go(0, 0), go(0, 1), go(0, 2)}) << endl;
	return 0;
}

Measured memory_bytes: 14376
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define f first
#define s second


signed main()
{

int l,r,d;
cin>>l>>r>>d;
cout<<r/d-(l%d==0?l/d-1:l/d)<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
using namespace std;

long long calc(string S, int i){
    long long num = 0;
    int ind = 0;
    int len = S.length();
    i <<= 1;
    long long res = 0;
    while(i){
        if (i & 1){
            res += num;
            num = S[ind] - '0';
        }else{
            num = num * 10 + S[ind] - '0';
        }
        ind += 1;
        i >>= 1;
    }
    for(int j = ind; j < len; j ++){
        num = num * 10 + S[j] - '0';
    }
    return res + num;
}

int main(){
    string S;
    cin >> S;
    int len = S.length() - 1;
    long long ans = 0;
    for(int i = 0; i < pow(2, len); i ++){
        ans += calc(S, i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

ll get(int p) {
  ll res = 1LL;
  while(p--) res *= 26LL;
  return res;
}

void solve() {
  int n; cin >> n;
  vector <ll> a(n);
  int xr = 0;
  for(auto &x : a) {
    cin >> x;
    xr ^= x;
  }
  for(auto x : a) {
    cout << (xr ^ x) << ' ';
  }
}

int main() {
  int t; t = 1;
  while(t--) solve();
}




Measured memory_bytes: 4836
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int first=0,end=0;
    for(int i=0;i<s.length();i++){
      if(s.charAt(i)=='A'){
        first=i;
        break;
      }
    }
    for(int i=s.length()-1;i>=0;i--){
      if(s.charAt(i)=='Z'){
        end=i;
        break;
      }
    }
    System.out.println(end-first+1);
  }
}

Measured memory_bytes: 26544
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  int n; cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  int sum = 0;
  while(1){
    bool f = 0;
    bool ch = 1;
    // cout << "a" << endl;
    rep(i, n){
      if(f){
        if(h[i] == 0){
          f = 0;
          sum++;
        }else h[i]--;
      }else{
        if(h[i] > 0){
          f = 1;
          h[i]--;
          ch = 0;
        }
      }
    }
    if(f) sum++;
    if(ch){
      cout << sum << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
package main

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

func fiveAntennas(ar []int32) string {
    k := ar[5]
    for i := 0; i < 5; i++ {
        for j := 0; j < 5; j++ {
            if ar[j] - ar[i] > k {
                return ":("
            }
        }
    }
    return "Yay!"
}

func main() {
    reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)

    var ar = make([]int32, 6)
    for i, _ := range(ar) {
        item, err := strconv.ParseInt(readLine(reader), 10, 32)
        checkError(err)
        ar[i] = int32(item)
    }

    res := fiveAntennas(ar)
    fmt.Println(res)
}

func readLine(reader *bufio.Reader) string {
    str, _, err := reader.ReadLine()
    if err == io.EOF {
        return ""
    }

    return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
    if err != nil {
        panic(err)
    }
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int n,i,j,k;
    cin>>n;
    cout<<n+n*n+n*n*n;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <unordered_map>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)
 
#define PI (acos(-1))
#define PRINT(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
 
template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}
 
template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}
 
struct UnionFind {
    vector<ll> par;
    vector<ll> sz;
 
    UnionFind(ll n=0){ if(n>0) initialize(n); }
    void initialize(ll n){
        par.resize(n);
        sz.assign(n, 1);
        for(ll i=0; i<n; i++){
            par[i] = i;
        }
    }
 
    ll find(ll x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }
 
    bool unite(ll x, ll y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }
 
    bool same(ll x, ll y){ return find(x) == find(y); }
    ll size(ll x){ return sz[find(x)]; }
};
 
int main()
{
    ll N, M, K;
    cin >> N >> M >> K;
 
    UnionFind uf(N);
    vector<set<ll>> graph(N);
    REP(i, M) {
        ll A, B;
        cin >> A >> B;
        A--; B--;
        uf.unite(A, B);
        graph[A].insert(B);
        graph[B].insert(A);
    }
    REP(i, K) {
        ll C, D;
        cin >> C >> D;
        C--; D--;
        if (uf.same(C, D)) {
            graph[C].insert(D);
            graph[D].insert(C);
        }
    }
    REP(i, N) {
        cout << uf.size(i) - graph[i].size() - 1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 25856
#include "bits/stdc++.h"
#define ll long long
using namespace std;
int main(){
ll N,D;
cin>>N>>D;
vector<vector<double>> x((N),vector<double>(D));
for(ll i=0;i<N;i++){
  for(ll j=0;j<D;j++){
    cin>>x[i][j];
  }
}

ll ans=0;
double tmp=0;
for(int i=0;i<N-1;i++){
for(int j=i+1;j<N;j++){
tmp=0;
for(int k=0;k<D;k++){
tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
}
tmp = sqrt(tmp);
if(tmp == int(tmp))
ans++;
}
}
cout<<ans<<endl;
return 0;
}


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

int main() {
	long long n, a[100005], b[100005], k, cnt=0, sum=0;
	bool flag = false;
	cin >> n;
	for(int i=1; i<=n;i++){
		cin >> a[i];
		sum += a[i];
	}
	if(sum % (n*(n+1)/2) == 0){
		k = sum / (n*(n+1)/2);
	}else{
		cout << "NO" << endl;
		return 0;
	}
	sum=0;
	for(int i=1; i<=n-1;i++){
		b[i] = a[(i+1)] - a[i] - k;
	}
	b[n] = a[1] -a[n]-k;
	for(int i=1;i<=n;i++){
		if(b[i] > 0){
			cout << "NO" << endl;
			return 0;
		}
		if(b[i]%n == 0){
			cnt += (b[i]/n)*(-1);
		}
	}
	if(cnt == k){
		flag = true;
	}
	
	if(flag){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
    
	return 0;
}

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

int main() {
  int N;
  long long answer = 0;
  cin >> N >> answer;
  
  for (int i = 0; i < N + 1; i++) {
    
    if (i % 3 != 0 && i % 5 != 0) {
      
      answer += i;
    }
    else { answer += 0; }
  }  

  cout << answer << endl;
}

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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int n;
string s;
vector<int> b,w;
int w_s[1000000];
int b_s[1000000];
int main() {
    cin >> n >> s;
    for (int i=0;i<n;i++) {
        if(s[i]=='#') b_s[i+1] = b_s[i] + 1;
        else b_s[i+1] = b_s[i];
    }
    reverse(s.begin(), s.end());
    // cout << s << endl;
    for (int i=0;i<n;i++) {
        if(s[i]=='.') w_s[i+1] = w_s[i] + 1;
        else w_s[i+1] = w_s[i];
    }

    int ans = INF;
    for (int i=0;i<=n;i++) {
        ans = min(b_s[i] + w_s[n-i], ans);
        // cout << i <<" " << b_s[i] << " " << w_s[n-i] <<endl;
    }

    // b_s: i番目までの黒のわ
    // w_s: n-i番目までの白のわ

    cout << ans << endl;
}

Measured memory_bytes: 5508
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main()
{
	int i=0,count=0,cnt=0;
	int length;
	int ret;
	char root[100];
	while(1){
		ret=scanf("%s",root);
		if(ret==EOF){
			break;
		}
		length=strlen(root);
		for(i=0; i<length; i++){
			if(root[i]!=root[length-1-i]){
				cnt++;
			}
		}
		if(cnt==0){
			count++;
		}
		cnt=0;
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 540
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scan;
    String N;
    
    scan = new Scanner(System.in);
    N = scan.next();
    
    if (N.contains("7")){
    System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35644
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef int64_t lint;
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using lb = long double;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SI(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define debug(x) cerr << #x << ": " << x << "\n"//手動デバッグ
#define debugV(x) for(int i=0;i<((ll)(x).size());i++)cerr << #x <<"at:"<<i<< ": " << x[i] << "\n"//手動デバッグ 
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define O(p) cout<<p<<"\n",0
#define OS(p) cout<<p<<" ",0
#define ON(p) cout<<p,0
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define endl "\n"//endlを置き換える
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定

const int dy[4]={1,0,-1,0};
const int dx[4]={0,1,0,-1};//^>v<

template<class T=int> T in(){
    T x;
    cin>>x;
    return (x);
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
//------------------------------------------------------------





//------------------------------------------------------------
int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
//------------------------------------------------------------
    int n;cin>>n;
    map<string,int> m;
    rep(i,n){
        string s;cin>>s;
        m[s]++;
    }
    int ma=0;
    for (auto i : m) {
        ma=max(ma,i.second);
    }
    for (auto i : m) {
        if(i.second==ma)O(i.first);
    }
    
    
    
    
//------------------------------------------------------------
	return 0;
}


Measured memory_bytes: 19260
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
ll mod = 1000000007;

int main(){
  ll n,k; cin >> n >> k;
  ll ans=0;
  ans+=(n-k)*(n-k+1)/2;
  rep(b,n){
    ll pm = n/b;
    rep(p,pm){
      ll qm = min(b-1,n-p*b);
      if(qm<k) continue;
      ans += qm-k+1;
    }
  }
  if(k==0) ans-=n;
  cout << ans;
  return 0;
}

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

using namespace std;
#define f first
#define s second
#define int long long
#define dear_crush int32_t main()
#define bari_ja return 0
#define forn(i, n) for (int i = 0; i < n; i++)
#define INF 1e9+5
dear_crush
{

	int n,k;

	std::cin >> n>>k;

	int arr[n];

	for(int i=0; i<n; i++)
	    std::cin >> arr[i];

	std::vector<int> v(n, INF);

	v[0] = 0;
	int i, j;
	for( i=0; i<n; i++){

	  for( j=1; j<=k; j++){
	    if (i+j<n) {
	    v[j+i] =min(v[j+i], v[i]+abs(arr[j+i]-arr[i]));
	    //cout<<"v[j]  "<<v[j];
	  }
	}
	//  cout<<"i "<<i<<"  "<<v[j]<<endl;
	}

	cout<<v[n-1]<<endl;



	bari_ja;
}


Measured memory_bytes: 1792
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	lint N;
	cin >> N;

	lint ans = 0;
	for (int i = 1; i <= N; i++) {
		lint n = N / i;
		ans += (n + 1) * n / 2 * i;
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3584
#include <cstdio>
#include <cstring>

const int MaxN = 100000 + 5;

int N;
int H[MaxN];
int Dp[MaxN];

inline int abs(int x) { return x > 0 ? x : -x; }
inline int min(int x, int y) { return x < y ? x : y; }

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%d", &H[i]);
}

void solve() {
  memset(Dp, 0x7F, sizeof Dp);
  Dp[1] = 0; Dp[2] = abs(H[2] - H[1]);
  for (int i = 3; i <= N; ++i)
    Dp[i] = min(Dp[i - 2] + abs(H[i] - H[i - 2]),
                Dp[i - 1] + abs(H[i] - H[i - 1]));
  printf("%d\n", Dp[N]);
}

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

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int pow(int base, int exp) {
  if (exp == 0)
    return 1;

  if (exp % 2 == 0) {
    int tmp = pow(base, exp / 2);
    return tmp * tmp;
  } else {
    return base * pow(base, exp - 1);
  }
}

int main(int argc, char *argv[])
{
  char ans;
  int out;

  int d = 9;
  for (; d >= 0; d--) {
    ll n = pow(10, d);

    printf("? %lld\n", n);
    fflush(stdout);
    scanf(" %c", &ans);

    if (ans == 'Y')
      break;
  }

  if (d == 9) {
    // N=10^m (m=0~9)

    int i = 0;

    ans = 'N';
    while (ans == 'N') {
      printf("? %lld\n", 2ULL * pow(10, i));
      fflush(stdout);
      scanf(" %c", &ans);
      i ++;
    }

    i --;
    out = pow(10, i);
    
  } else {
    // N=10^d+1 ~ 10^(d+1)-1
    
    int lower, upper, mid;
    lower = pow(10, d) + 1;
    upper = pow(10, d+1) - 1;
    
    while (lower < upper) {
      mid = ((ll)lower + upper) / 2;
  
      printf("? %lld\n", (ll)mid * 10);
      fflush(stdout);
      scanf(" %c", &ans);

      if (ans == 'Y') {
        upper = mid;
      } else {
        lower = mid + 1;
      }
    }

    out = lower;
  }


  printf("! %d\n", out);
  
  return 0;
}


Measured memory_bytes: 596
#include <iostream>
#include <cstring>
using namespace std;
char s[15];
int cnt;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
	if(s[0] != 'A' || s[1] == 'C' || s[strlen(s)-1] == 'C') {
		cout << "WA\n";
		return 0;
	}
	for(int i = 1; s[i] != '\0'; i++) {
		if(s[i] >= 'A' && s[i] <= 'Z') {
			if(s[i] == 'C') cnt ++;
			else if(s[i] == 'A');
			else {
				cout << "WA\n";
				return 0;
			}
		}
	}
	if(cnt == 1) cout << "AC\n";
	else cout << "WA\n";
	return 0;
}


Measured memory_bytes: 256
K = int(input())

if K%2 == 0 or K%5 == 0:
    ans = -1
else:
    ans = 1
    mod = 7
    mod_bfr = 7

    while True:
        if mod % K == 0:
            break
        else:
            mod_nxt = mod_bfr * 10
            if mod_nxt < K:
                mod += mod_nxt
                mod_bfr = mod_nxt
            else:
                mod += mod_nxt % K
                mod_bfr = mod_nxt % K
            ans += 1

print(ans)

Measured memory_bytes: 9068
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str;
	map<char, int>Map;
	Map['I']++;
	Map['V'] = 5;
	Map['X'] = 10;
	Map['L'] = 50;
	Map['C'] = 100;
	Map['D'] = 500;
	Map['M'] = 1000;
	char pre_char = 'I';
	
	while (cin >> str) {
		int ans = 0;
		for (int i = 0; i < str.length(); i++) {
			char this_char = str[i];
			if (i == 0) { pre_char = str[i]; continue; }
			if (Map[this_char] > Map[pre_char]) {
				ans -= Map[pre_char];
			}
			else {
				ans += Map[pre_char];
			}
			pre_char = str[i];
		}
		ans += Map[pre_char];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3120
//コピペ 何秒かかるか
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100100];

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

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100100; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
a, b, c, d = map(int, input().split())
length = max(b,d)
checker = [0] * length
for i in range(a, b):
    checker[i] = 1
for i in range(c, d):
    checker[i] = 1
ans = (b-a) + (d-c) -sum(checker)
print(ans)

Measured memory_bytes: 3060
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, deque<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    deque<int> as(n); cin >> as;
    sort(as.begin(), as.end());
    ll ans = 0;
    for(auto& a : as){
        a *= 2;
    }
    int piv = n & 1 ? as[n / 2] : (as[n / 2] + as[n / 2 - 1]) / 2;
    int m1 = M, m2 = M;
    for(int i = 0; i < n; i++){
        int v = abs(as[i] - piv);
        ans += v;
        printde(v, ans, piv);
        m2 = min(m2, v);
        if(m1 > m2){
            swap(m1, m2);
        }
    }
    cout << ans - (m1 + m2) / 2 << '\n';
    // for(int h = 0; h < 2; h++){
    //     int piv = as[n / 2];
    //     int mini1 = M, mini2 = M;
    //     ll cand = 0;
    //     int cnt = 0;
    //     for(int i = 0; i < n; i++){
    //         if(piv == as[i]){ cnt++; continue; }
    //         cand += abs(piv - as[i]);
    //         if(i < n / 2){
    //             mini1 = min(mini1, abs(piv - as[i]));
    //         }else{
    //             mini2 = min(mini2, abs(piv - as[i]));
    //         }
    //     }
    //     cand *= 2;
    //     if(cnt > 1){
    //     }else if(n & 1){
    //         cand -= min(mini1, mini2);
    //     }else{
    //         cand -= mini1;
    //     }
    //     ans = max(ans, cand);
    //     if(n & 1){ break; }
    //     reverse(as.begin(), as.end());
    // }
    // cout << ans << '\n';
}


Measured memory_bytes: 640
n = int(input())
uv = [[] for _ in range(n+1)]
for i in range(n-1):
    u,v,w = map(int, input().split())
    uv[u].append([v,w])
    uv[v].append([u,w])
stack = [1]
ans = [-1]*(n+1)
ans[1]=0
while stack:
    x = stack.pop()
    for j,k in uv[x]:
        if ans[j] == -1:
            if k % 2 ==0:
                ans[j] = ans[x]
            else:
                ans[j] = (ans[x]+1)%2
            stack.append(j)
for m in range(n):
    print(ans[m+1])

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

int main(){
    int n;
    cin>>n;
    int p[n];
    for(int i=0;i<n;i++)
    cin>>p[i];
    int a=1000000,ans=0;
    for(int i=0;i<n;i++){
        if(p[i]<=a){
            ans++;
            a=min(a,p[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
    int a,b,k;
    int ans,s=0;
    cin >> a >> b >> k;
    ans=a+1;
    while(s!=k){
        ans--;
        if(a%ans==0&&b%ans==0)
            s++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    rep(i, N)
    {
        cin >> x.at(i) >> y.at(i);
    }
    vector<int> v(N);
    rep(i, N)
    {
        v[i] = i;
    }

    double ans = 0.0;
    do
    {
        rep(j, N - 1)
        {
            ans += pow((pow(x.at(v[j]) - x.at(v[j + 1]), 2) +
                        pow(y.at(v[j]) - y.at(v[j + 1]), 2)),
                       0.5);
        }
    } while (next_permutation(all(v)));
    int Factorial = 1;
    for (int i = 2; i <= N; i++)
        Factorial *= i;
    cout << fixed << setprecision(10) << ans / Factorial << endl;
    return 0;
}

Measured memory_bytes: 640
import copy

def solve(N, W, w, v):
    dp = [[0]*(W+1) for _ in range(N+2)]
    for i in range(N):
        for sum_w in range(W):
            if sum_w+w[i] <=W:
                dp[i+1][sum_w+w[i]] = max(dp[i][sum_w+w[i]], dp[i][sum_w]+v[i])
        dp[i+2] = copy.copy(dp[i+1])
    return max(dp[-1])

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
w,v=[], []
for i in wv:
    w.append(i[0])
    v.append(i[1])

print(solve(N, W, w, v))

Measured memory_bytes: 174248
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        if (Math.abs(N - M) > 1) {
            System.out.println(0);
            return;
        } else if (N == M) {
            System.out.println((((fact(N) * fact(M)) % (1000000000 + 7) * 2)) % (1000000000 + 7));
        } else {
            System.out.println(fact(N) * fact(M) % (1000000000 + 7));
        }
    }

    static long fact(int n) {
        long ans = 1;
        for (int i = 1; i <= n; i++) {
            ans = (ans * (i % (1000000000 + 7))) % (1000000000 + 7);
        }
        return ans;
    }
}


Measured memory_bytes: 21844
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const int MAXN = 100010;
int N, sum, ans, A[MAXN + 10], acc[MAXN + 10];
int fact[MAXN + 10], finv[MAXN + 10];

int mod_pow(int n, int k) {
    int res = 1;
    for(; k>0; k>>=1) {
        if(k & 1) (res *= n) %= MOD;
        (n *= n) %= MOD;
    }
    return res;
}

void init() {
    fact[0] = 1;
    for(int i=1; i<=MAXN; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }
    finv[MAXN] = mod_pow(fact[MAXN], MOD-2);

    for(int i=MAXN-1; i>=0; i--) {
        finv[i] = (finv[i+1] * (i+1)) % MOD;
    }
}

int comb(int n, int r) {
    if(r < 0 or n < r) return 0;
    return fact[n] * finv[n-r] % MOD * finv[r] % MOD;
}

signed main() {
    init();
    cin >> N;
    for(int i=0; i<N; i++) {
        cin >> A[i];
        acc[i+1] = (acc[i] + A[i]) % MOD;
    }

    // 左端込
    sum = 0;
    for(int i=0; i<N; i++) {
        (sum += A[i]) %= MOD;
        int len = i + 1, cntFree = N - len - 1 + (i == N - 1);
        int add = fact[cntFree] * fact[len] % MOD * comb(N, cntFree) % MOD;
        // debug("// debug 1: cntFree = %lld, add = %lld, sum = %lld\n", cntFree, add, sum);
        (ans += add * sum) %= MOD;
    }

    // 右端込
    sum = 0;
    for(int i=N-1; i>=1; i--) {
        (sum += A[i]) %= MOD;
        int len = N - i, cntFree = N - len - 1;
        int add = fact[cntFree] * fact[len] % MOD * comb(N, cntFree) % MOD;
        // debug("// debug 2: cntFree = %lld, add = %lld, sum = %lld\n", cntFree, add, sum);
        (ans += add * sum) %= MOD;
    }

    // それ以外 (長さごとにまとめてやる)
    sum = 0;
    for(int i=1; i<=N-2; i++) {
        (sum += acc[N-i] - acc[i] + MOD) %= MOD;
        int add = 2 * fact[i] % MOD, cntFree = N - i - 2;
        add = add * fact[cntFree] % MOD * comb(N, cntFree) % MOD;
        // debug("// debug 3: cntFree = %lld, add = %lld, sum = %lld\n", cntFree, add, sum);
        (ans += add * sum) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328