akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

fn main() {
    input!{
        n: usize,
        v: [String; 2 * n - 1]
    }
    let mut tab = vec![vec![i64::min_value(); 3]; n];
    tab[0][0] = v[0].parse::<i64>().unwrap();
    for i in 1..n {
        let vi = v[2 * i].parse::<i64>().unwrap();
        if v[2 * i - 1] == "+" {
            tab[i][0] = max(tab[i - 1][0], tab[i - 1][1]) + vi;
            if max(tab[i - 1][1], tab[i - 1][2]) > i64::min_value() {
                tab[i][1] = max(tab[i - 1][1], tab[i - 1][2]) - vi;
                tab[i][2] = tab[i - 1][2] + vi;
            }
        } else {
            tab[i][1] = max(tab[i - 1][0], tab[i - 1][1]) - vi;
            tab[i][2] = max(tab[i - 1][1], tab[i - 1][2]) + vi;
        }
    }
    println!("{}", tab[n-1].iter().max().unwrap());
}


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

#define ll long long
#define NIL 0
#define INF 2e9
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vl vector<ll>
#define vvl vector<vector<ll>> 
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pb push_back
#define F first
#define S second
#define pp pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rpk(i,k,n) for(int i=k;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++) 
#define RPK(i,k,n) for(int i=k;i<=n;i++) 
#define ritr(i,gr) for(auto i=gr.begin();i!=gr.end();i++)

const int M = 1e9+7;

int V, E, i, j, k, u, v, x, y, p, q, r, t, n,w;
vi *g;
vb sn;

void topo (int u, vi &S) {
    sn[u] = true;
    for(auto v: g[u]) {
        if(!sn[v]) topo(v, S);
    }
    S.pb(u);
}

void solve() {
    vi S;
    sn.assign(V+1, false);
    REP(i,V) {if(!sn[i]) topo(i, S);}
    
    vi dist(V+1,0);
    dist[S[0]] = 0;
    REP(i,S.size()-1) {
        int temp  =0;
        for(auto v: g[S[i]]) {temp = max(dist[v]+1, temp);}
        dist[S[i]] = temp;
    }
    int res=0;
    REP(i,V) res = max(res, dist[i]);
    cout<<res<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>V>>E;
    g = new vi[V+1];
    while(E--){ cin>>x>>y; g[x].pb(y);}
    solve();
    
    
}
    

Measured memory_bytes: 12416
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        Collections.sort(list);
        int sum = 0;
        int max = list.get(n - 1);
        for (int i = 0; i < n - 1; i++) {
            sum += list.get(i);
        }
        if (max < sum) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


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

#define forn(i, n) for (int i = 0; i < n; i++)
#define re return
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define point pair <int, int>
#define re return
#define se second
#define fi first
#define mp(a, b) make_pair(a, b)
#define mp1(a, b, c, d) make_pair(mp(a, b), mp(c, d))
using namespace std;
typedef long long ll;
const int mod =  998244353;
const int ma = 2 * 128 * 1024;
const int k1 = 8, k2 = 8;
using namespace std;

ll n;
vector<pair<ll, ll> > pq;

ll solve() {
    set<pair<ll, ll> > a, b;
    ll qmx = 0;
    forn (i, n) {
        a.insert(mp(pq[i].fi, i));
        b.insert(mp(pq[i].se, i));
        if (pq[i].se < 0 || pq[i].fi > 0)
            qmx = max(qmx, min(abs(pq[i].fi), abs(pq[i].se)));
    }

    ll lst = 0;
    ll ans = 0;
    vector<ll> ax, bx;
    forn (i, n) {
        if (a.empty()) break;
        if (i % 2 == 0) {
            auto we = (*b.begin());
            b.erase(we);
            a.erase(mp(pq[we.se].fi, we.se));
            if (i == 0) {
                ax.push_back(we.se);
                lst = we.fi;
            } else {
                if (we.fi > lst) break;
                ax.push_back(we.se);
                ans += lst - we.fi;
                lst = we.fi;
            }
        } else {
            auto we = (*a.rbegin());
            a.erase(we);
            b.erase(mp(pq[we.se].se, we.se));
            if (we.fi < lst) break;
            bx.push_back(we.se);
            ans += we.fi - lst;
            //cout << we.fi << " " << lst << "\n";
            lst = we.fi;
        }
    }
    //cout << ans << "\n";
    if (sz(ax) > sz(bx)) {
        ll qmax = 0;
        if (sz(ax) == 1) {
            return 2LL * qmx;
        } else {
            ans += abs(pq[ax[0]].se);
            ans += abs(pq[ax.back()].se);
        }
    } else {
        ans += abs(pq[ax[0]].se);
        ans += abs(pq[bx.back()].fi);
    }
    //cout << ans << "\n";
    return max(ans, 2LL * qmx);
}
int main() {
    iostream::sync_with_stdio(0);
    cin >> n;
    pq.resize(n);
    forn (i, n) {
        cin >> pq[i].fi >> pq[i].se;
    }
    ll an = solve();
    forn (i, n) {
        swap(pq[i].fi, pq[i].se);
        pq[i].fi = -pq[i].fi;
        pq[i].se *= -1;
    }
    an = max(an, solve());
    cout << an << "\n";
} 

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

struct SgTree{
private:
	vector<pair<long long, bool>> node;
	long long defval;
	int N;
	int n;
public:
	void init(int n, long long defval = INT64_MAX){
		N = 1;
		while(N < n)N<<=1;
		this->n = n;
		this->defval = defval;
		node.assign(N*2-1, make_pair(defval, false));
	}
	long long query(int a, int b, int l = 0, int r = -1, int i = 0){
		if(r == -1) r = N;
		if(b <= l || r <= a) return defval;
		if(a <= l && r <= b) return node[i].first;
		if(node[i].second) return node[i].first;
		return min(query(a,b,l,(l+r)/2,i*2+1),query(a,b,(l+r)/2,r,i*2+2));
	}
	void update2(int a, int b, long long v, int l, int r, int i, long long defv){
		if(b <= l || r <= a) { node[i] = make_pair(defv, true); return; }
		if(a <= l && r <= b) { node[i] = make_pair(v, true); return; }
		
		update2(a,b,v,l,(l+r)/2,i*2+1,defv);
		update2(a,b,v,(l+r)/2,r,i*2+2,defv);

		node[i].second = false;
		node[i].first = min(node[i*2+1].first, node[i*2+2].first);
	}
	void update(int a, int b, long long v, int l = 0, int r = -1, int i = 0){
		if(r == -1) r = N;
		if(b <= l || r <= a) return;
		if(a <= l && r <= b) { node[i] = make_pair(v, true); return; }
		if(node[i].second) return update2(a,b,v,l,r,i,node[i].first);
		
		update(a,b,v,l,(l+r)/2,i*2+1);
		update(a,b,v,(l+r)/2,r,i*2+2);

		node[i].first = min(node[i*2+1].first, node[i*2+2].first);
	}

};


int main() {
	int n, q; cin >> n >> q;
	SgTree tr; tr.init(n, INT_MAX);

	vector<long long> ans;

	for(int i = 0; i < q; i++){
		int c; cin >> c;
		if(c == 0){
			int s,t,x; cin >> s >> t >> x;
			tr.update(s, t+1, x);
		}
		else {
			int i; cin >> i;
			ans.push_back(tr.query(i, i+1));
		}
	}

	for(int i = 0; i < ans.size(); i++){
		cout << ans[i] << endl;
	}

    return 0;
}



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

void swap(int& x, int& y){
	int tmp = x;
	x=y;
	y=tmp;
}

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(a>b) swap(a,b);
	if(b>c) swap(b,c);
	if(a>b) swap(a,b);
	
	cout << a << " " << b << " "  << c << endl;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
#define PI 3.14159265358979323846264338327950L
typedef unsigned long long uint64;
using namespace std;
int main(){
   int a;
   cin >>a;
   if(a%1000==0){
      cout << 0 << endl;
   }else{
      cout << 1000-(a%1000) << endl;
   }
return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    vector<int> v(3);

    cin >> v[0] >> v[1] >> v[2];

    std::sort(v.begin(), v.end());

    cout << (v[1] - v[0]) + (v[2] - v[1]) << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())
if a+b<=2*c:
    print(a*x+b*y)
else:
    ans=2*c*min(x,y)
    if x==y:
        print(ans)
    elif x>y:
        d=x-y
        if a<=2*c:
            print(ans+a*d)
        else:
            print(ans+2*c*d)
    else:
        d=y-x
        if b<=2*c:
            print(ans+b*d)
        else:
            print(ans+2*c*d)

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

int main(){

    int n;

    cin >> n;

    int num_arr[n+1];
    for(int i=0; i<n+1; i++){
        num_arr[i] = 0;
    }

    num_arr[1] = 1;

    for(int i=2; i*i<=n; i++){
        int temp = i*i;
        while(true){
            num_arr[temp] = 1;
            temp *= i;
            if(temp > n){
                break;
            }
        }
    }

    int ans=n;

    for(int i=n; i >= 1; i--){
        
        if(num_arr[i] == 1){
            ans = i;
            break;
        }
    }

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

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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;
constexpr int MAX = 2020;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

ll f[MAX];
void init() {
    f[0] = 1;
    for (int i = 1; i < MAX; i++)
        f[i] = (f[i - 1] * i) % MOD;
}

ll inv(ll x) {
    ll res = 1;
    ll k = MOD - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}
ll C(int n, int k) {
    ll a = f[n];
    ll b = f[n-k];
    ll c = f[k];
    ll bc = (b * c) % MOD;
    return (a * inv(bc)) % MOD;
}
ll H(int n, int k) {
    return C(n + k - 1, k);
}

int main() {
    init();
    int s;
    cin >> s;
    
    int n = s / 3;
    ll ans = 0;
    for (int i = n; i >= 1; i--) {
        int r = s - i * 3;
        ans += H(i, r);
        ans %= MOD;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

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

    ll ans = 0;
    ll n, a, b;

    cin >> n >> a >> b;

    ans = n / (a + b) * a;
    if (n % (a + b) > a) ans += a;
    else ans += n % (a + b);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main(){
    int N;
    int t[110000];
    int x[110000];
    int y[110000];

    t[0]=0;
    x[0]=0;
    y[0]=0;

    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>t[i]>>x[i]>>y[i];
    }
    
    bool flag=true;
    for(int i=1;i<=N;i++){
        int t0=abs(t[i]-t[i-1]);
        int x0=abs(x[i]-x[i-1]);
        int y0=abs(y[i]-y[i-1]);

        if((x0+y0)>t0){
            flag=false;
        }
        if((x0+y0)%2!=t0%2)        
        flag=false;
    }
    if(flag)cout<<"Yes";
    else cout<<"No";
    
    return 0;
}

Measured memory_bytes: 1408
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>
using namespace std;

int main(){
	// sankou
	//   http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=198978#1
	// 理解力が足りずに分からなかった 
	//   http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=511339#1
	string in;
	int nowSuu=0, ans = 0;

	while (cin >> in, !cin.eof()){
		nowSuu = 0;
		for (int i = 0; i < in.size(); i++){
			if (isdigit(in[i])){
				nowSuu *= 10;
				nowSuu += in[i] - '0';
			}
			else{
				// 数字列が途切れたら,nowSuuをansに追加して0にする.
				// elseを書かないと,一行に複数数字列あったときに余計なnowSuu*=10が行われる.
				ans += nowSuu;
				nowSuu = 0;
			}
		}
		// elseを通らなかったとき、つまり入力文字列の末尾が数字だったとき用.
		ans += nowSuu;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1184
V,E=map(int,input().split())
d=[[float('inf')]*V for _ in range(V)]
for i in range(E):
    com=list(map(int,input().split()))
    d[com[0]][com[1]]=com[2]
for i in range(V):
    d[i][i]=0
S=pow(2,V-1)
dp=[[0]+[float('inf')]*(S-1) for _ in range(V)]
for i in range(1,V):
    dp[i][1<<(i-1)]=d[0][i]
for i in range(1,S):
    for v in range(1,V):
        if i>>(v-1) & 1:
            #print(i,v)
            #print(*dp,sep='\n')
            dp[v][i]=min([float('inf')]+[dp[v][i]]+[dp[u][i-(1<<(v-1))]+d[u][v] for u in range(1,V) if i>>(u-1) & 1 and u!=v])
ans=min([dp[i][S-1]+d[i][0] for i in range(V)])
if ans==float('inf'):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 11232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int main()
{
    ll X, Y;
    cin >> X >> Y;
    ll tmp = X, ans = 0;
    while (tmp <= Y)
    {
        tmp *= 2;
        ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
a = [int(i) for i in input().split()]
b = collections.Counter(a)
ans = "No"
if (len(b) == 3):
    if (list(b.keys())[0] ^ list(b.keys())[1] ^ list(b.keys())[2]) == 0:
        if ((list(b.values())[0] == list(b.values())[1]) & (list(b.values())[0] == list(b.values())[2])):
            ans = "Yes"
elif (len(b) == 1):
    if list(b.keys())[0] == 0:
        ans = "Yes"
elif (len(b) == 2):
    if (n % 3 == 0):
        dd = list(b.keys())
        dd.sort()
        if (dd[0] == 0) & ((b[0] * 2) == (b[dd[1]])):
            ans = "Yes"
print(ans)

Measured memory_bytes: 14468
#357, 375, 537, 573, 735, 753

$count = 0
def solve(n, c)
  return 0 if n < c
  $count += 1 if c.to_s(10).split("").uniq.length == 3
  solve(n, (c.to_s(10)+'3').to_i)
  solve(n, (c.to_s(10)+'5').to_i)
  solve(n, (c.to_s(10)+'7').to_i)
end

n = gets.to_i
solve(n, 3)
solve(n, 5)
solve(n, 7)
puts $count

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);   
    int n;
    cin >> n;
    mint ans = 0;
    mint tmp = 1;
    rep(i,n) tmp *= 10;
    ans += tmp;
    tmp = 1;
    rep(i,n) tmp *= 9;
    tmp *= 2;
    ans -= tmp;
    tmp = 1;
    rep(i,n) tmp *= 8;
    ans += tmp;
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include<stdio.h>

int main()
{
	float a,b,c,d,e,f;
	float x,y;

	while(scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f) == 6){

	y=(c*d-a*f)/(b*d-a*e);
	x=(c*e-b*f)/(a*e-b*d);

	y=y*10000+0.5;
	y=(int)y;
	y=y/10000;

	x=x*10000+0.5;
	x=(int)x;
	x=x/10000;

	printf("%.3f %.3f\n",x,y);
	}
	
	return 0;
}

Measured memory_bytes: 648
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      k: usize,
      xys: [(i64,i64); n],
    }
    let mut xs: Vec<_> = xys.iter().map(|v| v.0).collect();
    let mut ys: Vec<_> = xys.iter().map(|v| v.1).collect();
    xs.sort();
    ys.sort();

    let mut ans = 1 << 62;
    for b in 0..n {
        for t in b+1..n {
            for l in 0..n {
                for r in l+1..n {
                    let y1 = ys[b];
                    let y2 = ys[t];
                    let x1 = xs[l];
                    let x2 = xs[r];

                    let mut cnt = 0;
                    for i in 0..n {
                        let (x, y) = xys[i];
                        if x1 <= x && x <= x2 && y1 <= y && y <= y2 {
                            cnt += 1;
                        }
                    }
                    if cnt >= k {
                        let area = (x2-x1) * (y2-y1);
                        ans = min(ans, area);
                    }
                }
            }
        }
    }
    puts!("{}\n", ans);
}


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

#define ll long long
#define ar array


ll solve()
{
    ll k,a,b,i;
    cin>>k>>a>>b;
    for(i=a;i<=b;i++)
    {
        if(i%k==0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    
    
  return 0;
}

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

    
        solve();

return 0;    
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=1000005,mod=1e9+7;
int n,m,lim;
char s[N];

void special(int n){
	static int f[N],s[N];
	s[1]=s[0]=f[0]=1;
	rep(i,2,n){
		f[i]=s[i-2];
		s[i]=(s[i-1]+f[i])%mod;
	}
	int ans=1;
	rep(i,2,n)
		ans=(ans+(ll)i*f[n-i])%mod;
	cout<<ans<<endl;
}

void solve(int n,int k){
	static int f[N],s[N];
	s[0]=f[0]=1;
	for(int i=2;i<=n;i+=2){
		f[i]=(s[i-2]+(i>=k+3?mod-s[i-k-3]:0))%mod;
		s[i]=(s[i-2]+f[i])%mod;
	}
	int ans=0;
	for(int i=2;i<=k+1;i+=2)
		ans=(ans+(ll)i*f[n-i])%mod;
	cout<<ans<<endl;
}

int main(){
	read(n),read(m);
	scanf("%s",s+1);
	lim=n-1;
	for(int l=1,r;l<=m;l++)
		if(s[l]==s[1]){
			r=l;
			while(r<m&&s[r+1]==s[l])
				r++;
			if(l==1&&r==m){
				special(n);
				return 0;
			}
			if(l==1){
				if(r%2==0) lim=min(lim,r+1);
				else lim=min(lim,r);
			}
			else if(r!=m&&(r-l)%2==0){
				lim=min(lim,r-l+1);
			}
			l=r;
		}
	solve(n,lim);
	return 0;
}

Measured memory_bytes: 4480
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 d; 

int pw[19];

int hoge(int x, int ma, int mi, int first) {
    if(ma == mi) return (x == 0 ? 1 : 0) * 10LL;
    if(ma < mi) return (x == 0 ? 1 : 0) * 1LL;
    int tmp = (pw[ma] - pw[mi]) / 9;
    int res = 0;
    int co = x / tmp;
    if(co <= 9 && co >= -9) res += hoge(x - co * tmp, ma - 1, mi + 1, 0) * (10 - co - first);
    if(co + 1 <= 9 && co + 1 >= -9) res += hoge(-(x - (co + 1) * tmp), ma - 1, mi + 1, 0) * (10 -(co + 1) - first);
    return res;
}

void solve() {
    pw[0] = 1LL;
    for(int i = 1; i <= 18; ++ i) {
        pw[i] = pw[i - 1] * 10LL;
    }
	cin >> d;
    if(d % 9 != 0) {
        cout << 0 << endl;
        return;
    }
    d /= 9;
    int ans = 0;
    for(int k = 2; k <= 18; ++ k) {
        ans += hoge(d, k - 1, 0, 1);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3656
import copy
n, m = (int(i) for i in input().split())
e = [[int(i)-1 for i in input().split()] for i in range(m)]

b = arr = [[0 for i in range(n)] for j in range(n)]

for x in e:
    b[x[0]][x[1]] = 1
    b[x[1]][x[0]] = 1

def f(idx):
    used[idx] = 1
    for i in range(n):
        if b_[idx][i] == 1 and used[i] == 0:
            f(i)

count = 0
for x in e:
    b_ = copy.deepcopy(b)
    b_[x[0]][x[1]] = 0
    b_[x[1]][x[0]] = 0
    used = [0]*n
    f(0)
    if used.count(1) != n:
        count+=1

print(count)

Measured memory_bytes: 3540
"""
Writer:SPD_9X2
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_C&lang=ja

ヒストグラム上の最大長方形
またdpかな…？
参考：
http://algorithms.blog55.fc2.com/blog-entry-132.html
"""
#最後に要素0を追加してくこと
def Largest_rectangle_in_histgram(lis):

    stk = []

    ans = 0
    N = len(lis)

    for i in range(N):

        if len(stk) == 0:
            stk.append((lis[i],i))

        elif stk[-1][0] < lis[i]:
            stk.append((lis[i],i))

        elif stk[-1][0] == lis[i]:
            pass

        else:
            lastpos = None
            while len(stk) > 0 and stk[-1][0] > lis[i]:

                nh,np = stk[-1]
                lastpos = np
                del stk[-1]

                ans = max(ans , nh*(i-np))

            stk.append((lis[i] , lastpos))

    return ans

N = int(input())
h = list(map(int,input().split()))
h.append(0)
print (Largest_rectangle_in_histgram(h))




Measured memory_bytes: 19680
# include<stdio.h>
int main(){
	char str[100];
	int i, t = 1;
	scanf("%s",str);
	for (i = 0; str[i] != '\0'; i++){
		if ((i + 1) % 2 != 0){
			if (str[i] =='L')
			{
				t = 0;
				break;
			}
		}
		else
		{
			if (str[i] == 'R')
			{
				t = 0;
				break;
			}
		}
	}
	if (t)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  rep(i, n) cnt += s[i] == '1';
  if (cnt == 0) {
    rep(i, n) {
      cout << 1 << '\n';
    }
    return;
  }
  vi32 m(2);
  m[0] = cnt + 1;
  m[1] = cnt - 1;
  vector<vi32> mods(2, vi32(n + 1));
  rep(mi, 2) {
    int mod = m[mi];
    if (mod == 0) continue;
    int acc = 1;
    rrep(i, n) {
      int k = s[i] - '0';
      mods[mi][i] = (mods[mi][i + 1] + k * acc) % mod;
      acc = acc * 2 % mod;
    }
  }
  vi32 ans(n);
  int acc = 1;
  rrep(i, n) {
    int k = s[i] - '0';
    int mod = m[k];
    if (mod != 0) {
      int a = (mods[k][0] - mods[k][i] + mod) % mod;
      int b = (mods[k][i + 1] - mods[k][n] + mod) % mod;
      int x = (a + b + (1 - k) * acc) % mod;
      int y = __builtin_popcount(x);
      int c = 1;
      while (y) {
        c += 1;
        x %= y;
        y = __builtin_popcount(x);
      }
      ans[i] = c;
    }
    acc = acc * 2 % m[0];
  }
  rep(i, n) {
    cout << ans[i] << '\n';
  }
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    deque<char> alist, blist, clist;
    string str;
    char chr;
    for (long long i=0; i<3; i++) {
        cin >> str;
        long long len=str.length();
        for (long long t=0; t<len; t++) {
            chr=str[t];
            if (i==0) {alist.push_back(chr);}   else if (i==1) {blist.push_back(chr);}  else if (i==2) {clist.push_back(chr);}}}
    chr=alist[0];
    while (true) {
        if (chr=='a' && alist.size()==0) {cout << "A"; break;} else if (chr=='b' && blist.size()==0) {cout << "B"; break;} else if (chr=='c' && clist.size()==0) {cout << "C"; break;}
        if (chr=='a') {chr=alist[0]; alist.pop_front();} else if (chr=='b') {chr=blist[0]; blist.pop_front();} else {chr=clist[0]; clist.pop_front();}}}

Measured memory_bytes: 3660
#include <cstdio>
#include <cstring>
typedef long long ll;
inline int rd(){
    int x=0,p=1;
    char a=getchar();
    while((a<48||a>57)&&a!='-')a=getchar();
    if(a=='-')p=-p,a=getchar();
    while(a>47&&a<58)x=(x<<1)+(x<<3)+(a&15),a=getchar();
    return x*p;
}
int k,n;
char s[1002];
int main(){
	k=rd();
	scanf("%s",s+1);n=strlen(s+1);
	if(n<=k)return puts(s+1),0;
	else for(int i=1;i<=k;i++)putchar(s[i]);
	puts("...");
    return 0;
}

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

const int Max=110;
int n,ans,k;
char ch[Max];

int main()
{
	scanf("%s%d",ch+1,&k);	
	n=strlen(ch+1);
	if(ch[1]!='1') printf("%c\n",ch[1]);
	else for(int i=1;i<=n;i++)
	{
	  if(ch[i]!='1' || i==k) {printf("%c\n",ch[i]);return 0;}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define maxi 1e18
#define pll pair<ll,ll>
map<ll,ll> pos,pos1;
int main(){
   /*ll a,b;
    cin>>a>>b; //ll giv=a;
    //ll ans;
    ll ans=0,giv=0;
    while(giv+a<b){
        giv+=a-1;
        ans++;
    }
    cout<<ans+1;*/
    ll n;
    cin>>n;
    cout<<(n*(n-1))/2;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>

using namespace std;


int main() {


	int p,q,r;
	cin >> p>>q>>r;
	
	
	int ans;
	ans = min(p+q,p+r);
	ans = min(ans,q+r);


	cout << ans << endl;
	
	

	
	

	return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b = b[::-1]

l = []
num = -1
for i in range(n):
    if a[i] == b[i]:
        l.append(i)
        num = a[i]

ind = 0
for i in range(n):
    if b[i] != num and a[i] != num and ind < len(l):
        b[i],b[l[ind]] = b[l[ind]],b[i]
        ind += 1
if ind < len(l):
    print("No")
else:
    print("Yes")
    print(*b)

Measured memory_bytes: 40164
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  int x;
  for(int i=0;i<n;i++){
    cin >> x;
    a[i] = -x;
  }
  sort(a,a+n);
  int scorea=0,scoreb=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      scorea += -a[i];
    }else{
      scoreb += -a[i];
    }
  }
  cout << scorea-scoreb;
}


Measured memory_bytes: 256
#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
inf = float("inf")

import numpy as np
import scipy.sparse.csgraph as csg

def main():
    N,M,L = map(int,input().split())
    ABC = [tuple(map(int,input().split())) for _ in range(M)]
    Q = int(input())
    ST = [tuple(map(int,input().split())) for _ in range(Q)]

    # 町の最短距離を求める
    A = np.array([[inf]*N]*N)
    for a,b,c in ABC:
        A[a-1][b-1] = c
        A[b-1][a-1] = c
    A = csg.floyd_warshall(A)
    
    # 求めた町の距離が L以下 に 1の辺をはる (給油なしでたどり着ける)
    B = np.array([[inf]*N]*N)
    for i in range(N):
        for j in range(N):
            if A[i][j] <= L:
                B[i][j] = 1
    # 最短距離を求める
    B = csg.floyd_warshall(B)
    
    for s,t in ST:
        if B[s-1][t-1] == inf:
            print(-1)
        else:
            print(int(B[s-1][t-1] - 1))

if __name__ == "__main__":
    main()

Measured memory_bytes: 56672
#include<stdio.h>

int main(void){
  char s[4];
  scanf("%s",s);
  int c=0;
  for(int i=0;i<4;i++){
    if(s[i]=='+'){
      c++;
    }else{
      c--;
    }
  }
    printf("%d",c);
   return 0;
}


Measured memory_bytes: 1708
import math
MOD = pow(2,61) - 1
def charToNum(char):
    return ord(char) - 96

def check(string,subLen):
    if subLen == 0: return True
    #長さsubLenの部分文字列すべてについてローリングハッシュを計算して、
    #一致するものがあるかどうかを計算する。
    # setOfRollingHash = set()
    dictOfRollingHash = {}
    totalLen = len(string)
    h = 0
    b = 1
    for i in range(subLen):
        c = string[subLen - 1 - i]
        h += charToNum(c) * b
        b *= 27
        b %= MOD
    h %= MOD
    dictOfRollingHash[h] = 0
    maxBase = pow(27,subLen - 1,MOD) 
    for i in range(1,totalLen - subLen + 1):
        h -= maxBase * charToNum(string[i - 1])
        h *= 27
        h += charToNum(string[i + subLen - 1])
        h %= MOD
        if h in dictOfRollingHash:
            if i - dictOfRollingHash[h] >= subLen:
                return True
        else:
            dictOfRollingHash[h] = i
    return False

N = int(input())
S = input()
ok = 0
ng = N + 1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if check(S,mid):
        ok = mid
    else:
        ng = mid
print(ok)

Measured memory_bytes: 3776
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	LL n; cin >> n;
	LL ans = (n * (n - 1)) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll N; cin>>N;
    vector<ll>t(N);
    rep(i,N)cin>>t[i];
    ll lcm=1;
    for(int i=0;i<N;i++){
        lcm=lcm/__gcd(lcm,t[i])*t[i];
    }
    cout<<lcm<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
template<class T> ll sum(const T& a){ return accumulate(a.begin(), a.end(), 0LL); }

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    for(auto& i : h) cin >> i;
    vector good(n, true);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(h[a] <= h[b]) good[a] = 0;
        if(h[b] <= h[a]) good[b] = 0;
    }
    cout << sum(good) << endl;
}

Measured memory_bytes: 3676
#include<stdio.h>
int main(void)
{
	int i,t,n[4];
	for(i=0;i!=4;i++){
		scanf("%d%d",&t,&n[i]);
		switch(t){
			case 1:
			n[i]*=6000;
			break;
			case 2:
			n[i]*=4000;
			break;
			case 3:
			n[i]*=3000;
			break;
			case 4:
			n[i]*=2000;
			break;
		}
	}
	for(i=0;i!=4;i++){
		printf("%d\n",n[i]);
	}
	return 0;
}

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

int main() {
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	if (s[0] == t[0])cnt++;
	if (s[1] == t[1])cnt++;
	if (s[2] == t[2])cnt++;
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
	string S, T;
	cin >> S >> T;
	int ans=0;
	for(int i=0; i<S.size(); ++i){
		if(S[i]!=T[i]) ++ans;
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[111111];

bool vis[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i],A[i]--;

    int v=0;
    for(int i=0;!vis[v];i++){
        if(v==1){
            cout<<i<<endl;
            return 0;
        }
        vis[v]=true;
        v=A[v];
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 1152
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <unordered_map>
#include <map>
using namespace std;

typedef long long ll;

const int MAX = 500000, MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

struct rolling_hash64 {
    int n;
    vector<long long> hs, pw;
    rolling_hash64(){}
    rolling_hash64(const string &s) {
        n = s.size();
        hs.assign(n+1,0);
        pw.assign(n+1,0);
        pw[0] = 1;
        for (int i = 0; i < n; i++) {
            hs[i+1] = hs[i]*base+s[i];
            pw[i+1] = pw[i]*base;
        }
    }

    long long hash(int l, int r) { return hs[r]-hs[l]*pw[r-l]; }
    bool match(int l1, int r1, int l2, int r2) { return hash(l1,r1) == hash(l2,r2); }
};

int main() {
  int n; cin >> n;
  vector<string> ls(n);
  // unordered_map<string, map<char, int> > dic;
  unordered_map<ll, map<char, int> > dic;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> ls[i];
    reverse(ls[i].begin(), ls[i].end());
  }
  sort(ls.begin(), ls.end(), [&](auto& l, auto &r){
    return l.size() < r.size();
  });
  for (auto & s: ls) {
    rolling_hash64 rh(s);
    string t = "";
    vector<int> cnt(26, 0);
    for (int i = 0; i < s.size(); ++i) {
      char c = s[i];
      cnt[c-'a'] += 1;
    }
    for (int i = 0; i < s.size(); ++i) {
      ll h = 0;
      if (i > 0) h = rh.hash(0, i);
      // if (dic.find(t) != dic.end()) { 
      if (dic.find(h) != dic.end()) { 
        // cerr << s << " " << t << endl;
        for (auto it: dic[h]) {
          if (cnt[it.first-'a'] > 0) { 
            // cerr << it.first << " " << it.second << endl;
            ans += it.second;
          }
        }
      }
      if (i < s.size()-1) {
        t += s[i];
        --cnt[s[i]-'a'];
      }
      else {
        dic[h][s[i]] += 1;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 31528
module app;

import std.stdio;
import std.algorithm;
import std.range;
import std.array;
import std.string;
import std.conv;

void main(string[] args) {
    // 一行目の入力を捨てる
    readln();
    int[][] lines = iota(0,2).map!((Unused) => readln.chop.split.map!(to!int).array).array;
    auto candies = iota(0,lines[0].length).map!((x) => sum(lines[0][0..x+1]) + sum(lines[1][x..$]));
    int max_score = 0;
    candies.each!((num){
        if(num > max_score){
            max_score = num;
        }
    });
    writeln(max_score);
}

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

int p;

long long modpow(long long a, long long b){
    if (b == 0) return 1;
    if (b % 2 == 0) return modpow(a, b / 2) * modpow(a, b / 2) % p;
    return a * modpow(a, b - 1) % p;
}

int check(long long x){
    if (x % 2) return p - 1;
    return 1;
}

int main(){
    cin >> p;
    vector<long long> inv(p);
    inv[0] = 0; inv[1] = 1;
    for (int i = 2; i < p; i++) inv[i] = (p - p / i) * inv[p % i] % p;
    vector<long long> C(p);
    C[0] = 1;
    for (int i = 1; i < p; i++) C[i] = (C[i - 1] * (p - i) % p) * inv[i] % p;
    vector<int> a(p);
    for (int i = 0; i < p; i++) cin >> a[i];
    vector<long long> b(p, 0);
    for (int i = 0; i < p; i++){
        if (a[i]){
            b[0] += 1;
            int pw = 1;
            for (int j = p - 1; j >= 0; j--) {
                b[j] += (p - (C[j] * pw % p) * check(p - 1 - j) % p) % p;
                b[j] %= p;
                pw *= i;
                pw %= p;
            }
        }
    }
    for (int i = 0; i < p; i++){
        cout << b[i];
        if (i == p - 1) cout << endl;
        else cout << " ";
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

vector<int> s;
int n, k;

int get_sum(int left, int right)
{
	return s.at(right) - s.at(left);
}

void get_ans(void)
{
	vector<int> a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	s = vector<int>(n + 1, 0);
	for (int i = 0; i < n; i++)s.at(i + 1) = s.at(i) + a.at(i);
	int ans = get_sum(0, k);
	int tmp;
	for (int i = 1; i < n; i++)
	{
		if (k + i == n)break;
		tmp = get_sum(i, k + i);
		if (tmp > ans)ans = tmp;
	}
	cout << ans << endl;
}

int main(void)
{
	while (1)
	{
		cin >> n >> k;
		if (n == 0 && k == 0)break;
		get_ans();
	}
	return 0;
}


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

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

  // vector<string> s(N);
  map<string,int> mp;
  int i;
  for(i=0;i<N;i++){
    string ss;
    cin>>ss;
    sort(ss.begin(),ss.end());
    mp[ss]++;
    // cout << mp[ss] <<endl;
    // s.at(i)=ss;
  }
  ll ans = 0;
  for (auto& p : mp){
    ll c = p.second;
    ans += c*(c-1)/2;
  }
  // sort(s.begin(),s.end());
  // for(i=0;i<N;i++){
  //   cout<<s.at(i)<<endl;
  // }


  // int top=0;
  // int bottom=0;
  // long long ans=0;
  // while(top<N){
  //   int n=0;
  //   bottom=top;
  //   // cout<<"top "<<top<<" bot "<<bottom<<endl;
  //   while(bottom+1<N){
  //     if(s.at(bottom+1)==s.at(top)){
  //       bottom++;
  //       n++;
  //     }else{
  //       break;
  //     }
  //   }
  //   if(n>=1){
  //     ans+=(n+1)*n/2;
  //   }
  //   top=bottom+1;
  //
  //   // cout<<ans<<endl;
  // }
  cout<<ans<<endl;


}


Measured memory_bytes: 11136
#include <iostream>
using namespace std;
int n,a,d,t[1000003],maxa=-(1<<30);
int gcd(int x,int y)
{
    if(!y) return x;
    return gcd(y,x%y);
}
void fj(int x)
{
    for(int i=2;i*i<=x;)
	{
        if(!(x%i)){
            t[i]++;
            while(!(x%i)) x/=i;
        }
        else i++;
    }
    if(x>1) t[x]++;
}
int main()
{
    cin>>n>>a;
    d=a;
    for(int i=2;i<=n;i++)
	{
        cin>>a;
        if(maxa<a) maxa=a;
        d=gcd(d,a);
        fj(a);
    }
    if(d==1){
        for(int i=2;i<=maxa;i++)
            if(t[i]>1)
			{
				cout<<"setwise coprime";return 0;
			}
        cout<<"pairwise coprime";
    }
    else cout<<"not coprime";
    return 0;
}

Measured memory_bytes: 7524
from collections import deque

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a,b,c = map(int,input().split())
    edge[a-1].append((b-1,c))
    edge[b-1].append((a-1,c))

q,k = map(int,input().split())

dist = [float('inf')] * n
visited = [0] * n

dist[k-1] = 0
visited[k-1] = 1
vq = deque([k-1])

while vq:
    
    vs = vq.popleft()
    
    for ve,vc in edge[vs]:
        if visited[ve] == 1: continue
        
        dist[ve] = dist[vs] + vc
        visited[ve] = 1
        vq.append(ve)


for _ in range(q):
    x,y = map(int,input().split())
    print(dist[x-1] + dist[y-1])

Measured memory_bytes: 44392
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

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

using namespace std;
using ll = long long int;

const ll INF = 1<<30;
const ll LINF = 1LL<<60;
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(void) {
    int n; cin >> n;
    map<int, int> a;
    REP(i, n) {
        int c; cin >> c;
        a[c]++;
    }
    ll sum = 0;
    for (auto m : a) {
        sum += m.first * m.second;
    }
    int q; cin >> q;
    REP(i, q) {
        int b, c; cin >> b >> c;
        sum += c * a[b] - b * a[b];
        a[c] += a[b];
        a[b] = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 8080
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {

    size_t N;
    cin >> N;
    vector<long long> a(N + 1);
    vector<long long> dp(N + 1, 0);
    vector<long long> prev(N + 1, 0);
    for (size_t i = 1; i <= N; ++i) cin >> a[i];
    prev[1] = a[1];
    for (size_t i = 3; i <= N; i += 2) prev[i] = a[i] + prev[i - 2];

    for (size_t i = 2; i <= N; ++i) {
        if ((i & 1) == 0) {
            dp[i] = max(prev[i - 1], dp[i - 2] + a[i]);
        } else {
            dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
        }
    }
    
    cout << dp[N];
    return 0;
}

Measured memory_bytes: 7964
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int arr[3001],n;
long long dp[3001][3001];
long long f(int i,int j){
	if(i>j)return 0;
	long long &res=dp[i][j];
	if(~res)return res;
	if(!((n-j+i-1)&1)){
		return res=max(f(i+1,j)+arr[i],f(i,j-1)+arr[j]);
	}else{
		return res=min(f(i+1,j)-arr[i],f(i,j-1)-arr[j]);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	memset(dp,-1,sizeof dp);
	cin>>n;
	for(int i=0;i<n;i++)cin>>arr[i];
	cout<<f(0,n-1)<<endl;
	return 0;
}

Measured memory_bytes: 70784