akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 
	
void solve(){
   cout << fixed;
   cout << setprecision(12);
   vector<double> v;
   double n, ret;
   while(cin >> n){
	   v.push_back(n);  
	 }
	double mx = *max_element(all(v));
	double mn = *min_element(all(v));
	ret = mx - mn;
	cout << ret << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3256
li = [int(input())]
for i in range(1, 10 ** 6):

    n = li[i - 1]
    if n % 2 == 0:
        fn = n / 2
    else:
        fn = 3 * n + 1
    if fn in li:
        print(i + 1)
        exit()
    li.append(fn)




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

int main(){

    int n;
    cin >> n;
    int d[n];
    for(int i = 0;i<n;i++) cin >> d[i];
    sort(d,d+n);
    int cnt = 1;
    for(int i = 1;i<n;i++){
        int bac = d[i-1];
        if(d[i] != bac) cnt ++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

ll n;
ll p = 0, q = 0;
ll nump = 0, numq = 0;
ll cnt = 0;
bool used[100] = {};
void count(ll len, ll x){
    // cout << len << ":" << x << endl;
    if(len == n){
        cnt++;
        // cout << x << endl;
        if(x == p)nump = cnt;
        if(x == q)numq = cnt;
    }
    else {
        for(ll i = 1; i <= n; ++i)if(!used[i]){
            used[i] = true;
            count(len+1, x*10+i);
            used[i] = false;
        }
    }
}

int main(){
    cin >> n;
    rep(i, n){
        p *= 10;
        ll a;
        cin >> a;
        p += a;
    }
    rep(i, n){
        q *= 10;
        ll a;
        cin >> a;
        q += a;
    }
    
    count(0, 0);
    cout << abs(numq-nump) << endl;
}

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

using namespace std;

const long long inf = (long long) 1e18;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  long long ans = inf;
  for (int i = 1; i <= n; i++) {
    long long a = i * 1LL * m;
    long long x = n - i, y = m;
    if (x % 2 == 0) {
      long long b = (x / 2) * 1LL * y;
      long long c = x * 1LL * y - b;
      long long mx = max(abs(a - b), max(abs(a - c), abs(b - c)));
      ans = min(ans, mx);
    } else {
      long long b = (y / 2) * 1LL * x;
      long long c = y * 1LL * x - b;
      long long mx = max(abs(a - b), max(abs(a - c), abs(b - c)));
      ans = min(ans, mx);
    }
  }
  for (int i = 1; i <= m; i++) {
    long long a = i * 1LL * n;
    long long x = n, y = m - i;
    if (x % 2 == 0) {
      long long b = (x / 2) * 1LL * y;
      long long c = y * 1LL * x - b;
      long long mx = max(abs(a - b), max(abs(a - c), abs(b - c)));
      ans = min(ans, mx);
    } else {
      long long b = (y / 2) * 1LL * x;
      long long c = y * 1LL * x - b;
      long long mx = max(abs(a - b), max(abs(a - c), abs(b - c)));
      ans = min(ans, mx);
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int r, n;
	while(cin >> r >> n) {

		if(r == 0 && n == 0) break;

		vector<pair<int, P> > v(n);
		rep(i, n) cin >> v[i].second.first >> v[i].second.second >> v[i].first;

		int H[60], GETA = 30;
		memset(H, 0, sizeof(H));


		rep(i, n) {
			int h = v[i].first, x1 = v[i].second.first, x2 = v[i].second.second;

			REP(j, x1, x2) {
				H[j + GETA] = max(H[j + GETA], h);
			}
		}

		double ans = INF;
		REP(i, -r+1, r) {
			double res = r + min(H[i + GETA], H[i - 1 + GETA]);
			ans = min(ans, res - sqrt(r*r - i*i));
		}

		cout << fixed;
		cout.precision(4);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1268
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x,y = y,x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)

def main():
    n, m = map(int,input().split())
    ab = [tuple(map(int,input().split())) for _ in range(m)]

    uf = UnionFind(n)

    ans = [n*(n-1)//2]

    for a,b in ab[::-1]:
        sa,sb=uf.size(a-1),uf.size(b-1)
        if uf.same(a-1,b-1):
            ans.append(ans[-1])
        else:
            ans.append(ans[-1]-sa*sb)
        uf.union(a-1,b-1)
        
    print(*ans[::-1][1:], sep="\n")

main()

Measured memory_bytes: 30568
#include <stdio.h>

int A[1000000],n;

int binarySearch(int key)
{
	int left=0;int right=n;
	int mid;
	while(left<right)
	{
		mid=(left+right)/2;
		if(key==A[mid]) return 1;
		if(key>A[mid]) left=mid+1;
		else if(key<A[mid]) right=mid;
	}
	return 0;
}
 
 int main()
 {
 	int i,key,m,sum=0;
 	scanf("%d",&n);
 	for(i=0;i<n;i++)
 	scanf("%d",&A[i]);
 	scanf("%d",&m);
 	for(i=0;i<m;i++)
 	{
 		scanf("%d",&key);
 		if(binarySearch(key)) sum++;
	 }
	 printf("%d\n",sum);
	 return 0;
 }


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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n;
	cin>>n;
	vector<string> ss(n);
	rep(i,n)cin>>ss[i];
	vector<vector<int>> char_cnt(n, vector<int>(30,0));
	rep(i,n){
		string t = ss[i];
		rep(j,t.size()){
			char_cnt[i][t[j]-'a']++;
		}
	}
	vector<pair<char,int>> ans;
	rep(j,'z'-'a'+1){
		int cnt = inf;
		rep(i,n){
			cnt = min(cnt, char_cnt[i][j]);
		}
		if(cnt>0)ans.push_back(make_pair('a'+j,cnt));
	}
	for(auto x : ans){
		rep(i,x.second){
			cout<<x.first;
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// Not gonna give up until it's over
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this
const ll MAXN = 2e5 + 10;
ll a[MAXN],h[MAXN];
ll bit[MAXN];
 
void update(ll idx,ll val){
    for(;idx<MAXN;idx+=(idx&(-idx))){
        bit[idx] = max(bit[idx],val);
    }
}
 
ll maxx(ll idx){
    ll ret = 0;
    for(;idx>0;idx-=(idx&(-idx))){
        ret = max(ret,bit[idx]);
    }
    return ret;
}

ll ans;
void solve(){
    ll n; cin>>n;

    FOR(i,1,n) cin>>h[i];
    FOR(i,1,n) cin>>a[i];

    FOR(i,1,n){
        ll val = maxx(h[i]) + a[i];
        ans = max(ans,val);
        update(h[i],val);
    }

    cout<<ans<<endl;
}

signed main(){
 
   FastRead;    
 
    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;


int main(){
    iosetup;
    ll N, A, B; IN(N, A, B);
    vector<ll> X(N);
    rep(i, 0, N) IN(X[i]);
    ll ans = 0;

    rep(i, 0, N-1){
        ll t1 = (X[i+1]-X[i]) * A;
        ans += min(t1, B);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
a,b,c,d = map(int,input().split())
answer =0
if b < 0:
	if c < 0:
		answer = max(a*c,b*d)
	if c>=0:
		answer = max(a*c,b*d,b*c)
if b>=0:
	if a <0:
		answer = max(a*c ,b * d,0)
	if a >= 0:
		if d< 0:
			if a == 0:
				answer = 0
			else:
				answer = a*d
		if d>=0:
			answer = b*d
print(answer)


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define ld long double
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';              

typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

const ll mod = 1e9 + 7;
ll n;
const ll N = 1e6 + 5;
ll dp[2][N];
string s;


ll solve(bool is_same, ll i){

	if(i == n)
		return 1;

	if(dp[is_same][i] != -1){
		return dp[is_same][i];
	}
	
	ll t = 0;

	if(is_same){
		if(s[i] == '0'){
			t = (t % mod + solve(1,i + 1) % mod) % mod;
		}else{
			t = (t % mod + solve(0,i + 1) % mod) % mod;
			t = (t % mod + 2 * solve(1,i + 1) % mod) % mod;
		}

	}else{
		t = 3*solve(0,i + 1) % mod;
	}
	return dp[is_same][i] = t;
}

int main(){

	IOS

	cin >> s;
	n = s.size();
	memset(dp, -1, sizeof dp);

	cout << solve(1,0) << '\n';

}

Measured memory_bytes: 20816
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<=n;i++)
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;


/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;    
    }
    return sum;
}
/// 最大公約数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }



int main(){
int X,Y;
cin >> X >> Y;
cout << X + Y/2 << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;
fn main() {
    let n = read::<usize>();
    let mut h = HashMap::new();
    h.insert('M', 0);
    h.insert('A', 1);
    h.insert('R', 2);
    h.insert('C', 3);
    h.insert('H', 4);
    let mut s = vec![vec![]; n];
    let mut ss = vec![0; 5];
    for i in 0..n {
        s[i] = read::<String>().chars().collect::<Vec<char>>();
        if h.get(&s[i][0]) != None {
            ss[h[&s[i][0]]] += 1;
        }
    }
    let mut ans:i64 = 0;
    for i in 0..3 {
        for j in i+1..4 {
            for k in j+1..5 {
                ans += ss[i] * ss[j] * ss[k];
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 12540
nmax = 8
graph = [[0]*nmax for i in range(nmax)]
visited = [0] * nmax


def dfs(v, N, visited):
    all_visited = True
    for i in range(N):
        if visited[i] == 0:
            all_visited = False
    if all_visited:
        return 1
  
    ret = 0
    for i in range(N):
        if graph[v][i] == 0:
            continue
        if visited[i] == 1:
            continue
        visited[i] = 1
        ret += dfs(i, N, visited)
        visited[i] = 0
    return ret
      

N, M = [int(i) for i in input().split()]
for j in range(M):
    a, b = [int(j) for j in input().split()]
    graph[a-1][b-1] = graph[b-1][a-1] = 1


visited[0] = 1
print(dfs(0, N, visited))

Measured memory_bytes: 3064
/*
Author - Vedant Daigavane
*/

#include<bits/stdc++.h>

#define pb push_back
#define vi vector<int>
#define nl cout<<endl;
#define vc vector<char>
#define ll long long int
#define w(t)  while(t!=0)
#define daigavane int main()
#define vii vector<vector<int>>
#define ul unsigned long long int
#define f(i,s,n) for(int i=s;i<=n;i++)
using namespace std;

daigavane
{
    ll c=0;
    string a,b;
    cin>>a;
    cin>>b;

    f(i,0,a.size()-1)
    {
      if(a[i]!=b[i])  c+=1;
    }
    cout<<c;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define Pll complex<int>
#define X real()
#define Y imag()
#define ii pair<int, int>
#define fi first
#define se second
const int MAX = 200000; //2 * 10^5
const int MOD = 1000000007; //10^9 + 7
const int OO = 0x3f3f3f3f; // 0x3f3f3f3f

int n, x, y;
int ans[4000];

int dist(int u, int v)
{
	int d1 = abs(u - v);
	int d2 = abs(u - x) + 1 + abs(v - y);
	int d3 = abs(u - y) + 1 + abs(v - x);
	return min(d1, min(d2, d3));
}

int32_t main()
{
	cin >> n >> x >> y;
	
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			ans[ dist(i, j) ]++;
	
	for(int i = 1; i < n; i++)
		cout << ans[i] << '\n';
	
	return 0;
}

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

int main(void)
{
	int   n;
	int** ppMat;

	while(1)
	{
		cin >> n;
		if(n == 0)break;
	
		ppMat = new int*[n+1];
		for(int i=0; i<n+1; i++)
		{
			ppMat[i] = new int[n+1];
			for(int j=0; j<n+1; j++)
				ppMat[i][j] = 0;
		}

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

		for(int y=0; y<n+1; y++)
		{
			for(int x=0; x<n+1; x++)
			{
				cout.width(5);
				cout << ppMat[x][y];
			}
			cout << endl;
		}
		
		for(int i=0; i<n; i++)
			delete [](ppMat[i]);
	}


	return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
int main(void){
    int A,B,K;
    scanf("%d %d %d",&A,&B,&K);
    if(A < B){
        int w = A;
        A = B; B = w;
    } //A > B
    int r[B];
    int j;
    for(int i = 1; i <= B; i++){
        if(A%i == 0 && B%i == 0){
            r[j] = i; j++;
            // printf("r[%d] = %d\n",j,i);
        }
    }
    // printf("j = %d\n",j);
    printf("%d\n",r[j-K]);
    return 0;
}

Measured memory_bytes: 128
from collections import defaultdict as DD
N = int(input())
S = DD(int)
for i in range(N):
  S[input()] += 1
M = max(S.values())
L = []
for k,v in S.items():
  if v == M:
    L.append(k)
for x in sorted(L):
  print (x)

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

#define int long long 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

#define N 100005
int mx=0;
const int  mod =1e9+7;
int n,m;
int dp1[N];
int dp2[N];
unordered_map<int,vector<int> > adj;

void solve2(int u,int par,int ans){

    //dp2[u] represents the number of ways to paint the tree if the root of the tree is u and is painted black
    
    dp2[u]=(dp1[u]*(1+ans))%m;
    vector<int> pref,suff;
    for(auto v:adj[u]){
        if(v!=par){
           pref.push_back(1+dp1[v]);
           suff.push_back(1+dp1[v]);
        }
    }
    int n=pref.size();
    for(int i=1;i<n;i++) pref[i]=(pref[i-1]*pref[i])%m;
    for(int i=n-2;i>=0;i--) suff[i]=(suff[i+1]*suff[i])%m;

    int cnt=0;
    for(auto v:adj[u]){
        if(v!=par){
            int ways=1+ans;
            if(cnt>0) ways=(ways*pref[cnt-1])%m;
            if(cnt<n-1) ways=(ways*suff[cnt+1])%m;

            solve2(v,u,ways);
            cnt++;
        }
       
    }

}

void solve1(int u,int par){
    
    //dp1[u] represents the number of ways to paint the subtree if the it is rooted at node u which is painted black

    int ways=1;
    for(auto v:adj[u]){
        if(v!=par){
            solve1(v,u);
            ways=(ways*(dp1[v]+1))%m;
        }
    }
    dp1[u]=ways;

}

int32_t main(){
    cin>>n>>m;
    memset(dp1,-1,sizeof(dp1));
    memset(dp2,-1,sizeof(dp2));
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    solve1(1,0);
    //for(int i=1;i<=n;i++) cout<<dp1[i]<<" ";
    //cout<<endl;
    solve2(1,0,0);
    for(int i=1;i<=n;i++) cout<<dp2[i]<<endl;
}

Measured memory_bytes: 27556
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//#include <DEBUG.h>
#ifndef LL
#define LL long long
#endif
#ifndef uLL
#define uLL unsigned long long
#endif
#ifndef uL
#define uL unsigned int
#endif
#ifndef iL
#define iL int
#endif
#ifndef iS
#define iS short
#endif
#ifndef uS
#define uS unsigned short
#endif
#ifndef uC
#define uC unsigned char
#endif
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define abs(a) (((a)<0)?(-(a)):(a))
#define sgn(a) (((a)<0)?(1):(0))
#define movs(a,b,l) (memmove((a),(b),sizeof(*(b))*(l)))
#define stosb(a,b,l) (memset((a),(b),sizeof(*(a))*(l)))
static inline uLL sqrt64(uLL x)
{
    uLL t,g;
    for (g=(x>>1)+(x&1),t=x;g<t;g=(g+x/g)>>1)
    {
        t=g;
    }
    return t;
}
LL num[100000];
char str[10000];
int main()
{
	//freopen("in.in","r",stdin);
	LL a,b,c,i,j,k,n,m,ans[8],ans2;
	scanf("%lld",&n);m=sqrt64(n);ans2=0;
	for (i=1;i<=m;i++)
	{
		if (n/i==n%i) {ans2+=i;}
	}
	for (i=1;i<=m;i++)
	{
		if (((n-i)%i==0)&&((n-i)/i>m)) {ans2+=(n-i)/i;}
	}
	printf("%lld\n",ans2);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
  int n,divider=1;
  cin >> n;
  vector<int> x(n),y(n);
  rep(i,n) cin >> x[i] >> y[i];
  for(int i=1;i<=n;i++) divider *= i;
  double sum=0.0;
  rep(i,n)rep(j,n){
    int distansx = abs(x[i] - x[j]);
    int distansy = abs(y[i] - y[j]);
    int distans = distansx*distansx + distansy*distansy;
    sum += (sqrt((double)(distans)) * (double)(divider/n));
  }
  double ans = (sum) / (double)(divider);
  cout << setprecision(10) << ans << endl;
}









































//以下、ライブラリ
//ユークリッドの互除法

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int n;
		double h;
		int[] d = new int[6];
		
		n = scan.nextInt();
		for(int i = 0; i < n; i++){
			h = scan.nextDouble();
			if(h < 165.0)d[0]++;
			else if(h < 170.0)d[1]++;
			else if(h < 175.0)d[2]++;
			else if(h < 180.0)d[3]++;
			else if(h < 185.0)d[4]++;
			else d[5]++;
		}
		for(int i = 0; i < 6; i++){
			System.out.print(i + 1 + ":");
			for(int j = 0; j < d[i]; j++){
				System.out.print("*");
			}
			System.out.println();
		}
	}
}

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

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

    int d = a/b;
    int r = a%b;
    double fa = a;
    double fb = b;
    double f = fa/fb;

    printf("%d %d %.5lf\n", d, r, f);

    return 0;
}


Measured memory_bytes: 3216
N = int(input())
A= list(map(int, input().split()))
mod = 10 ** 9 + 7
sum = 0
for i in range(60):
    count0 = 0
    count1 = 0
    count2 = 0

    for j in range(N):
        if A[j] & 1:
            count1 += 1
        else:
            count0 += 1
        A[j] = A[j] >> 1
    count2 = count0 * count1
    sum += count2 * (2 ** i)

print(sum % mod)


Measured memory_bytes: 122936
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

ll lcm(ll a, ll b) {
  return a / std::__gcd(a, b) * b;
}

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

  ll A, B;
  std::cin >> A >> B;

  print(lcm(A, B));
  return 0;
}


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

typedef vector<int> vi;

const int INF = 2000000000;
int N, M;
vector<vi> cost;
vi d;
vi prv;
vector<bool> used;
set<pair<int, int> > need;

void dijkstra(int s) {
	d.clear();
	d.resize(N, INF);
	used.clear();
	used.resize(N, false);
	prv.clear();
	prv.resize(N, -1);

	d[s] = 0;
	while (true) {
		int v = -1;
		for (int u = 0; u < N; u++) {
			if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}
		if (v == -1) break;
		used[v] = true;
		for (int u = 0; u < N; u++) {
			if (d[u] > d[v] + cost[v][u]) {
				d[u] = d[v] + cost[v][u];
				prv[u] = v;
			}
		}
	}
}

void set_path(int t1) {
	while (true) {
		int t0 = prv[t1];
		if (t0 == -1)
			break;
		if (t0 < t1)
			need.insert(make_pair(t0, t1));
		else
			need.insert(make_pair(t1, t0));
		t1 = t0;
	}
}

int main(void) {
	int a, b, c;
	vi v;

	cin >> N >> M;
	v.resize(N, INF);
	cost.resize(N, v);
	for (int i = 0; i < M; ++i) {
		cin >> a >> b >> c;
		cost[a - 1][b - 1] = c;
		cost[b - 1][a - 1] = c;
	}

	need.clear();
	for (int s = 0; s < N - 1; ++s) {
		dijkstra(s);
		for (int t = s + 1; t < N; ++t)
			set_path(t);
	}

	int ans = M - (int)need.size();
	cout << ans << '\n';
	return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll, int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

void solve(){
	int n,k;
	cin >> n >> k;
	vi v(n);
	for(auto &i:v)cin >> i;
	sort(all(v));
	int ans=  0;
	for(int i = 0; i < k; i++)
		ans += v[i];
	cout << ans << endl;
}

int main(){
	fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 3588
n, m = map(int, input().split())
g = [[False] * n for _ in range(n)]
visited = [False] * n
a = []
b = []
ans = 0


def dfs(v):
    visited[v] = True
    for to in range(n):
        if not g[v][to]:
            continue
        if visited[to]:
            continue
        dfs(to)


for _ in range(m):
    ai, bi = map(int, input().split())
    ai -= 1
    bi -= 1
    a.append(ai)
    b.append(bi)
    g[ai][bi] = True
    g[bi][ai] = True

for i in range(m):
    g[a[i]][b[i]] = False
    g[b[i]][a[i]] = False
    for j in range(n):
        visited[j] = False
    dfs(0)
    for j in range(n):
        if not visited[j]:
            ans += 1
            break
    g[a[i]][b[i]] = True
    g[b[i]][a[i]] = True

print(ans)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int num = 0;
    for(int i = 0;i < N-2;i++){
        if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C'){
            num++;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())
inline void Fail(){
	printf("-1");
	exit(0);
}

const int maxn=305;
int n;
ll dist[maxn][maxn];
bool done[maxn][maxn];
ll ans;

int main(){
	scanf("%d",&n);
	rep(i,n)rep(j,n){
		scanf("%lld",&dist[i][j]);
		ans+=dist[i][j]; 
	}
	rep(k,n)rep(i,n)rep(j,n){
		if(dist[i][k]+dist[k][j]<dist[i][j])Fail();
		if(i!=k&&j!=k&&dist[i][k]+dist[k][j]==dist[i][j]&&!done[i][j])
		ans-=dist[i][j],done[i][j]=true;
	}
	printf("%lld",ans/2);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	cout << (n * 800) - (n / 15 * 200) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools
import heapq


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(input):
    nums = string_to_int(input)

    def euclid(large, small):
        if small == 0:
            return large
        l = large % small
        return euclid(small, l)

    nums.sort(reverse=True)
    eee = euclid(nums[0], nums[1])
    return int((nums[0] * nums[1]) / eee)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(input())
    print(ret)


Measured memory_bytes: 38384
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INF = 2147483647;
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP(i, 1, n+1)
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for(int i = (int)(n) - 1 - (int)(x); i >= 0; i--)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}

int main() {
    int X;
    cin>>X;
    int x = X%10;
    if (x==2||x==4||x==5||x==7||x==9) cout << "hon";
    else if(x==0||x==1||x==6||x==8) cout << "pon";
    else cout << "bon";
    
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std;

struct pa{
  ll f, s;
};

int main()
{
FASTIO
//input_from_file

int n;
cin >> n;

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

pa dp[n][n];

for(int i = 0; i < n; i++){
  for(int j = 0; j < n; j++){

    if(j < i){
      dp[i][j].f = 0;
      dp[i][j].s = 0;
    }

    else if(i == j){
      dp[i][j].f = a[i];
      dp[i][j].s = 0;
    }
  }
}

int i = 0;
while(i < n - 1){
  int temp = 0, j = i + 1, cnt = n - i -1;

  while(cnt > 0){

    dp[temp][j].f = max(dp[temp + 1][j].s + a[temp], dp[temp][j - 1].s + a[j]);

    if(dp[temp + 1][j].s + a[temp] > dp[temp][j - 1].s + a[j]){
      dp[temp][j].s = dp[temp + 1][j].f;
    }

    else{
      dp[temp][j].s = dp[temp][j - 1].f;
    }

    cnt--; temp++; j++;
  }

  i++;
}

ll ans = dp[0][n - 1].f - dp[0][n - 1].s;

cout << ans;
}


Measured memory_bytes: 140928
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int n=stdIn.nextInt();
		int A[]=new int[26];
		int z=0,y=0;
		while(z<n){
			String a=stdIn.next();
			int G[]=new int[26];
			while(y<a.length()){
				char b=a.charAt(y);
				G[b-'a']++;
				y++;
			}y=0;
			while(y<26) {
				if(z==0||A[y]>G[y])
					A[y]=G[y];
				G[y]=0;
				y++;
			}y=0;
			z++;
		}z=0;
		while(z<26) {
			while(y<A[z]) {
				System.out.print((char)(z+97));
				y++;
			}y=0;
			z++;
		}
		System.out.println();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)|(1<<(i)))
#define togglebit(n,i) ((n)^(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
// Function to find modulo inverse of a
 ll gcdExtended(ll a, ll b, ll *x, ll *y)
    {
        // Base Case
        if (a == 0)
        {
            *x = 0, *y = 1;
            return b;
        }
 
        ll x1, y1; // To store results of recursive call
        ll gcd = gcdExtended(b%a, a, &x1, &y1);
 
 
        *x = y1 - (b/a) * x1;
        *y = x1;
 
        return gcd;
    }  
    ll modInverse(ll a, ll m)
    {
        ll x, y;
        ll g = gcdExtended(a, m, &x, &y);
 
        ll res = (x%m + m) % m;
        return res;
    }
    ll modularExponentiation(ll x,ll n,ll M)
   {
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modularExponentiation((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

   }
   ll find_ncr(ll n,ll r,ll m){
   	 ll temp=1;
   	 for(ll i=n;i>=(n-r+1);i--){
   	       temp=((temp%m)*(i%m))%m; 	
		}
     ll kola=1;
	 for(ll i=1;i<=r;i++){
	 	kola=((kola%m)*(i%m))%m;
	 }
	 ll temp2=modInverse(kola,m);
	 ll res=((temp%m)*(temp2%m))%m;
	 return res;	
   }
int main()
{
    fastread;
    ll n,i,j,k,l,m;
    cin>>n>>k>>l;
    m=1000000007;
    ll res1=((modularExponentiation(2,n,m)-1)+m)%m;
    ll res2=find_ncr(n,k,m);
    ll res3=find_ncr(n,l,m);
    ll finres=(res1-res2+m)%m;
    finres=(finres-res3+m)%m;
    cout<<finres;
    return 0;
}

Measured memory_bytes: 256
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let (a, b): (usize, usize) = parse_line().unwrap();

    let mut board = vec![vec!['#'; 100]; 50];
    let mut board2 = vec![vec!['.'; 100]; 50];
    board.append(&mut board2);
    for i in 0..(a - 1) {
        board[(i / 50) * 2][2 * (i % 50)] = '.';
    }
    for i in 0..(b - 1) {
        board[99 - (i / 50) * 2][2 * (i % 50)] = '#';
    }

    println!("100 100");
    for i in 0..100 {
        for j in 0..100 {
            print!("{}", board[i][j]);
        }
        println!();
    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
int a[MAX_N];

double g(ll n) {
  if (n == 0) return 0;
  return n * log(n) - n;
}

double f(ll n, ll r) {
  return g(n) - g(r) - g(n - r);
}

int main2() {
  int N = nextInt();
  REP(i, N) a[i] = nextInt();
  sort(a, a+N);

  pair<int,int> ans;
  double value = -1;


  for (int i = 0; i < N; i++) {
    vector<int> v;
    int p = distance(a, lower_bound(a, a + i, a[i]/2));
    for (int d = -1; d <= 1; d++) {
      if (p + d >= 0 && p + d < i) {
        v.push_back(a[p+d]);
      }
    }
    for (int b : v) {
      double s = f(a[i], b);
      // cout << a[i] << " " << b << " " << s << endl;
      if (value < s) {
        value = s;
        ans = {a[i], b};
      }
    }
  }

  cout << ans.first << " " << ans.second << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string.h>
 
#define Optimize ios_base::sync_with_stdio(false); cin.tie(0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define iter(a) a.begin(), a.end()
using namespace std;

int main() {
	Optimize
 
	int n;
	cin >> n;
	vector<int> v(n), dp(n);
	for (auto& i : v) {
		cin >> i;
	}
	dp[0] = 0;
	dp[1] = abs(v[1]-v[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i-1] + abs(v[i]-v[i-1]),
					dp[i-2] + abs(v[i]-v[i-2]));
	}
	cout << dp[n-1] << '\n';
 
	return 0;
}

Measured memory_bytes: 3956
import numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections as C #most_common
#import math
#import sympy

N = int(input())
#N,K,d= map(int,input().split())
#A = list(map(int,input().split()))
#S = str(input())
#T = str(input())

num=np.zeros(10**4+1)
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            ans = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if ans < 10**4+1:
                num[ans]+=1


for i in range(N):
    print(int(num[i+1]))


Measured memory_bytes: 27216
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    if(N < 1200){
        cout<<"ABC"<<endl;
    }else if(N < 2800){
        cout<<"ARC"<<endl;
    }else{
        cout<<"AGC"<<endl;
    }
}


Measured memory_bytes: 256
program Knapsack_2
    implicit none
    integer(4):: n,wn
    integer(8), parameter:: inf=400000000000_8
    integer(8),allocatable:: w(:), v(:)
    integer(8):: dp(0:100000), ndp(0:100000), ans
    integer(4):: i,j

    read*, n,wn
    allocate(w(n), v(n))
    do i=1,n
        read*, w(i), v(i)
    end do

    dp(:) = inf
    ndp(:) = inf

    dp(0) = 0
    ndp(0) = 0

    do i=1, n
        do j=1, 100000
            if (j < v(i)) then
                ndp(j) = dp(j)
            else
                ndp(j) = min(dp(j), dp(j-v(i))+w(i))
            end if
        end do
        dp(:) = ndp(:)
    end do

    ans = 0
    do i=1, 100000
        if (dp(i) <= wn) then
            ans = max(ans,i)
        end if
    end do
    print*, ans
end program Knapsack_2

Measured memory_bytes: 2176
N, M = [int(s) for s in input().split()]

def main():
    ans = set()
    [ans.add(int(s)) for s in range(1, M + 1)]
    for _ in range(N):
        _, *a = [int(s) for s in input().split()]
        ans = ans & set(a)
    print(len(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n,k;
    cin>>n>>k;
    ll a=n%k;
    ll b=k-a;
    cout<<min(a,b);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 12032
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1LL<<60
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  ll diff = b-a;
  bool k = false;
  REP(i, n){
    ll up = d * (n-1-i) - c * i;
    ll down = c * (n-1-i) - d * i;
    if(down <= diff && diff <= up) k = true;
  }
  if(k) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
TYPES = 26
days = gets.to_i

#満足度低下
c = gets.split(" ").map(&:to_i).slice(0,TYPES)

#日々の満足度
s = Array.new(days).map{|d| gets.split(" ").map(&:to_i).slice(0,TYPES)}

#日々のイベント
t = []

#最後の開催日
last = Array.new(TYPES,0)

score = 0

for d in 1..days
    i = s[d-1].index(s[d-1].max)
    score += s[d-1][i]
    last[i] = d
    c.each_with_index do |rate, index|
        score = score - rate * (d - last[index])
    end
    puts i+1
end


Measured memory_bytes: 14400
#include <stdio.h>
long euclid(long x,long y){
  long s = x % y;
  if(s == 0){return y;}
  else{euclid(y,s);}
}
int main(void) {
  long a,b,x,y;
  while(scanf("%ld %ld\n",&a,&b) != EOF){
    x = euclid(a,b);
    y = a/x*b;
    printf("%ld %ld\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 600
# -*- coding: utf-8 -*-
from itertools import product
import sys
 
def main(A, B, C, D):
    for op1, op2, op3 in product(("+", "-"), repeat=3):
        e = A + op1 + B + op2 + C + op3 + D
        x = eval(e)
        if x == 7:
            print(e + "=7")
            sys.exit()
    
if(__name__ == "__main__"):
    A, B, C, D = list(input())
    
    main(A, B, C, D)

Measured memory_bytes: 3060
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		for(int i = 0 ; i < n ; i++) {
			set.add(sc.nextInt());
		}
		System.out.println(set.size());
		sc.close();

	}

}


Measured memory_bytes: 23380
s = gets.strip;

dict = [
  "dream",
  "dreamer",
  "erase",
  "eraser",
].map(&:reverse)
s = s.reverse()

i = 0
while i < s.length
  ok = false
  dict.each do |str|
    if s.slice(i, str.length) == str
      i = i + str.length
      ok = true
      break
    end
  end

  if !ok
    puts "NO"
    exit
  end
end
puts "YES"


Measured memory_bytes: 2044
n, m = gets.split.map(&:to_i)
submissions = Hash.new { |h, k| h[k] = [] }
ac = 0
wa = 0

m.times do
  pi, s = gets.split

  submissions[pi.to_i] << s.chomp
end

submissions.each do |_pi, s_ary|
  # ある問題piに対してAC数が0ならスキップ
  next if s_ary.count('AC').zero?

  # 初めてACしたのが何回目の提出か
  first_ac_idx = s_ary.index('AC')

  ac += 1
  wa += first_ac_idx
end

puts "#{ac} #{wa}"


Measured memory_bytes: 20604
import bisect,collections,copy,heapq,itertools,math,numpy,string
from fractions import gcd
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) # tupleも検討する。
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N, L = LI()
    A = [S() for _ in range(N)]

    A.sort()
    print("".join(A))

if __name__ == '__main__':
    main()

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

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    int amt = x/d;
    amt = min(amt, k);
    k -= amt;
    x -= d*amt;
    if (k%2==1) x = abs(x-d);
    cout << x << '\n';
}
/*

 */

Measured memory_bytes: 3648