akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	cout<<max(0,-a)*c+(b-max(a,0))*e+(a<0?d:0)<<endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    // 制約を読み直そう！
    int n;
    cin >> n;
    vector<int> p(n);
    for (int& x : p) cin >> x;

    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
        int a, b, c;
        a = p[i - 1];
        b = p[i];
        c = p[i + 1];
        if (a > c) swap(a, c);
        ans += (a < b && b <= c);
    }
    cout << ans << endl;
}


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


int main(){
    int n, m, maxi = 0;
    cin >> n;
    unordered_map<string, int> cntr;
    rep(i,n){
        string tmp;
        cin >> tmp;
        cntr[tmp]++;
    }
    cin >> m;
    rep(i,m){
        string tmp;
        cin >> tmp;
        cntr[tmp]--;
    }
    for(auto elem: cntr){
        maxi = max(maxi, elem.second);
    }
    cout << maxi << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, sum = 0,h,w;
int main() {
    int n;ll m = 100000; cin >> n;
    rep(i, n) {
        m += m * 0.05;
        if (m % 1000 != 0) {
            m -= m % 1000;
            m += 1000;
        }
    }cout << m << endl;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int h,w;
  cin >> h >> w;
  char s[h][w];
  char ans[h][w];
  vpi check;
  REP(i,h) {
    REP(j,w) {
      cin >> s[i][j];
      ans[i][j]=s[i][j];
      if(s[i][j]=='.') check.push_back(pi(i,j));
    }
  }
  for(auto i:check) {
    int x=i.second,y=i.first;
    int cnt=0;
    REP(j,8) {
      int cx=x+dx[j],cy=y+dy[j];
      if(cx<0||cy<0||cx>=w||cy>=h) continue;
      if(s[cy][cx]=='#') cnt++;
    }
    char t='0'+cnt;
    ans[y][x]=t;
  }
  REP(i,h) {
    REP(j,w) {
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3604
S = input()
C = 105
F = -5
for i in range(len(S)):
  if S[i] == "C":
    C = i
    break
for i in range(len(S)-1,-1,-1):
  if S[i] == "F":
    F = i
    break
if C<F:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main (String [] args){
		List <Integer> list = new ArrayList<Integer>();
		HashMap <Integer, Integer>hm = new HashMap<Integer, Integer>();
//		int v1 = Integer.parseInt(sc.next());
		String s2 = sc.next();		
		String ans_str = "";
		int ans_int = 0;
		int[]ints = null;
		for(int i = 0;i < s2.length();i++){
			ans_int += (Integer.valueOf(String.valueOf(s2.charAt(i))));
		}
		if(Integer.parseInt(s2)%ans_int == 0){
			ans_str = "Yes";
		}else{
			ans_str = "No";
		}
		System.out.println(ans_str);
		System.out.flush();
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60; 
#define MOD 1000000007

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}


long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

//ここまでライブラリ
//ここから本文

long long int tpimin(vector<int> a) {
	int MIN = 1000000000;
	int number = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
		number = i;
	}
	return number;
}


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> px(m);
	vector<int> py(m);
	vector<int> x(n);
	vector<int> y(n);
	for (int i = 0; i < n; i++) {
		cin >> x.at(i) >> y.at(i);
	}
	for (int i = 0; i < m; i++) {
		cin >> px.at(i) >> py.at(i);
	}
	for (int i = 0; i < n; i++) {
		int MIN = 1000000006;
		int number = 0;
		for (int j = 0; j < m; j++) {
			int length = abs(x.at(i) - px.at(j)) + abs(y.at(i) - py.at(j));
			if (length < MIN) {
				MIN = length;
				number = j + 1;
			}
		}
		cout << number << endl;
	}
}



Measured memory_bytes: 256
#include <cstdio>
#include <set>
using namespace std;
#define R for(i=0;i<n;++i)
#define L(l,m,n) l=max(l,min(max(a[i]-e,m),max(f-a[i],n)));
int a[1<<17],b[1<<17],e=1e7,f=-1e7,g=1e7,h=-1e7,n,c,d,j=-1e7,k=-1e7,i;
int main(){
	scanf("%d",&n);
	R{
		scanf("%d %d",&c,&d);
		a[i] = c+d;
		b[i] = c-d;
		e = min(e,a[i]);
		f = max(f,a[i]);
		g = min(g,b[i]);
		h = max(h,b[i]);
	}
	R{
		L(j,b[i]-g,h-b[i])
		L(k,h-b[i],b[i]-g)
	}
	printf("%d\n",min(j,k));
}

Measured memory_bytes: 1816
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int H, W;
    cin >> H >> W;
    vector<vector<int> > v(H + 2, vector<int>(W + 2));

    rep(i, 0, H) {
        rep(j, 0, W) {
            char tmp;
            cin >> tmp;
            if (tmp == '#') {
                v[i + 1][j + 1] = 1;
            }
        }
    }
    rep(i, 1, H + 1) {
        rep(j, 1, W + 1) {
            int sum = 0;
            if(v[i][j] == 0){
                continue;
            }
            sum += v[i][j+1];
            sum += v[i][j-1];
            sum += v[i-1][j];
            sum += v[i+1][j];
            if (sum <= 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<math.h>
using namespace std;

int main()
{
	
	
	int a,b,h;
	cin>>a>>b>>h;
	
	int area;
	
	area=(a+b)*h/2;

	
	cout<<area<<endl;
	
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define fi first
#define se second
#define pb push_back
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int oo = 1e18 + 7;
 
int n, k, ans[100005], d[100005];
ii range[100005];
vector<int> Adjlist[100005];
 
void dfs(int u, int p){
	for(int i = 0; i < Adjlist[u].size(); i++){
		int v = Adjlist[u][i];
		if(v == p) continue;
		d[v] = d[u] + 1;
		dfs(v, u);
		range[u].fi = max(range[u].fi, range[v].fi - 1);
		range[u].se = min(range[u].se, range[v].se + 1);
		if(range[u].fi > range[u].se){
			range[u].fi = oo;
			range[u].se = -oo;
		}
	}
}
 
void dfs2(int u, int p){
	for(int i = 0; i < Adjlist[u].size(); i++){
		int v = Adjlist[u][i];
		if(v == p) continue;
		if(range[v].fi <= (ans[u] + 1) && range[v].se >= (ans[u] + 1)) ans[v] = ans[u] + 1;
		else ans[v] = ans[u] - 1;
		dfs2(v, u);
	}
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++) range[i] = {-oo, oo};
	for(int i = 1; i < n; i++){
		int x, y;
		cin >> x >> y;
		Adjlist[x].pb(y);
		Adjlist[y].pb(x);
	}
	cin >> k;
	for(int i = 1; i <= n; i++) ans[i] = -oo;
	for(int i = 1; i <= k; i++){
		int pos, num;
		cin >> pos >> num;
		ans[pos] = num;
		range[pos] = {num, num};
	}
	dfs(1, 1);
	for(int i = 1; i <= n; i++){
		if(range[i].fi > range[i].se){
            cout << "No";
            return 0;
        }
    }
    bool ck1 = 0, ck2 = 0;
    for(int i = 1; i <= n; i++){
    	ck1 |= (ans[i] != -oo && !(abs(ans[i] - d[i]) & 1));
    	ck2 |= (ans[i] != -oo && (abs(ans[i] - d[i]) & 1));
	}
	if(ck1 & ck2){
		cout << "No";
		return 0;
	}
	cout << "Yes\n";
	ans[1] = range[1].fi;
	dfs2(1, 1);
	for(int i = 1; i <= n; i++) cout << ans[i] << "\n";
}

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

using namespace std;

int main(){
	int N, Q;
	while(cin >> N >> Q, N){
		vector<int> cnt(101, 0);
		for(int i=0;i<N;i++){
			int M; cin >> M;
			for(int j=0;j<M;j++){
				int d; cin >> d;
				cnt[d]++;
			}
		}
		int res = 0;
		for(int i=0;i<=100;i++){
			if(cnt[res] < cnt[i]) res = i;
		}
		cout << (cnt[res] >= Q ? res : 0) << endl;
	}
}

Measured memory_bytes: 1196
package main

import (
	"fmt"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	listC := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&listC[i])

	}

	for i := 0; i < h; i++ {
		fmt.Println(listC[i])
		fmt.Println(listC[i])
	}

}


Measured memory_bytes: 512
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    S = input()
    Q = int(input())
    mae = ''
    usiro = ''
    s = True
    for _ in range(Q):
        q = list(input().split())
        if q[0]=='1':
            s = not s
        else:
            if q[1]=='1' and s:
                mae = q[2] + mae
            elif q[1]=='2' and s:
                usiro = usiro + q[2] 
            elif q[1]=='2' and not s:
                mae = q[2] + mae
            else:
                usiro = usiro + q[2]
    if s:
        print(mae+S+usiro)
    else:
        print(usiro[::-1]+S[::-1]+mae[::-1])




if __name__ == '__main__':
    main()

Measured memory_bytes: 4856
n = int(input())
m = n
A = ""
i = 2
while True:
    if n%i == 0:
        A = A + " " + str(i)
        if i == n:
            break
        n = n//i
        i = 2
    else:
        if i*i >= n:
            A = A + " " + str(n)
            break
        else:
            i += 1

print("{}:{}".format(m,A))


Measured memory_bytes: 5592
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for(auto i=0; i<(n); i++)
#define rep1(i,m,n) for(auto i=m; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define len(x) ((int)x.length())
#define sqr(x) ((x)*(x))
#define pb push_back
#define clr clear()
#define inf (1<<30)
#define ins insert
#define itr(x) ::iterator x
#define ull unsigned long long int
#define ll long long int
#define xx first
#define fast cin.tie(0); cout.tie(0);
#define yy second
#define cas int t; cin>>t; while(t--)
#define eps 1e-9
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(x) cout << x << "\n";
#define printall(x) for(auto y:x){cout << y << " ";}cout<<'\n';
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << "\n";
#define debug4(x,y,z,zz) cout << x << " " << y << " " << z <<" "<<zz << "\n";
#define debug5(x,y,z,zz,yy) cout << x << " " << y << " " << z <<" "<<zz << " "<< yy << "\n";
typedef long long i64;
typedef unsigned long long ui64;
typedef pair<int,int> pii;
typedef string st;
typedef vector<int> vi;
typedef list<int> li;
typedef vector<st> vs;
typedef map<int,int> mii;
typedef map<st,int> msi;
typedef set<int> si;
typedef set<st> ss;
typedef vector<pii> vpii;
typedef set<pii > spi;
#define mx 0
int main() {
    ios_base::sync_with_stdio(0);
    ll n; cin>>n;
    int arr[n+1];
    rep1(i,1,n+1){
        int x; cin>>x;
        arr[x] = i;
    }
    rep1(i,1,n+1){
        cout<<arr[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
using namespace std;
int main()
{
	int s,a,b;
	cin>>s;
	a=s/100;
	b=s%100;
	if(a>0&&a<=12&&b>0&&b<=12)
		cout<<"AMBIGUOUS"<<endl;
	else if(a>=0&&a<100&&b>0&&b<=12)
		cout<<"YYMM"<<endl;
	else if(a>0&&a<=12&&b>=0&&b<=100)
		cout<<"MMYY"<<endl;
	else cout<<"NA"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int A;
  ll B, N;
  cin >> A >> B >> N;
  cout << A*min(B-1, N)/B << endl;
  return 0;
}


Measured memory_bytes: 3648
def solve():
    L = [int(i) for i in input().split()]
    L.sort()
    a, b, c = L
    ans = 0
    while b < c:
        a += 1
        b += 1
        ans += 1
    while a < b:
        a += 2
        ans += 1
    print(ans if a == b else ans + 1)


if __name__ == "__main__":
    solve()


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

int main() {
  int A,B,C,D,N;
 A=0;
  string S,T;
  cin >> N;
  vector<int>d(N);
  for(int i=0;i<(N);i++){
    cin >> d.at(i);
  }
  for(int i=0;i<(N-1);i++){
    for(int j=(i+1);j<(N);j++){
      A=A+(d.at(i)*d.at(j));
    }
    
  }
cout << A << endl;

}


Measured memory_bytes: 256
package main

// にぶたん使うらしいんだけどどうやってつかうの どうせ結果をソートするんだったらインデックスで参照できるじゃん

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	n := nextInt()
	h := nextInts(n)
	ans := make([]int, n)
	INF := int(math.Pow(10, 9))
	for i := 0; i < n; i++ {
		ans[i] = INF
	}
	ans[0] = 0
	for i := 1; i < n; i++ {
		if i == 1 {
			// 最初の1手しか進めない
			ans[i] = int(math.Min(float64(ans[i]), float64(ans[i-1]+int(math.Abs(float64(h[i]-h[i-1]))))))
		} else {
			// ひとつまえかふたつまえの小さい方
			pre_one := float64(ans[i-1]) + math.Abs(float64(h[i]-h[i-1]))
			pre_two := float64(ans[i-2]) + math.Abs(float64(h[i]-h[i-2]))
			ans[i] = int(math.Min(pre_one, pre_two))
		}
	}
	fmt.Fprint(out, ans[n-1])
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i <= (b); ++i)
#define fd(i, a, b) for (int i = (a); i >= (b); --i)
#define edge(i, u) for (int i = head[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define mod 1000000007
#define ll long long
#define N 205
#define pb push_back
int n, m, x, y;
int main ()
{
    scanf("%d %d %d", &n, &x, &y);
    printf("%d", (n - x + 1) * (n - y + 1));
}

Measured memory_bytes: 256
//Code Author: S.M. Istiak Ahmed
#include<bits/stdc++.h>
using namespace std;

const int mxN=100100;
int cnt[mxN];
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,a;
  cin>>n;
  vector<int> v;
  int ans=0;
  for(int i=0; i<n; i++){
    cin>>a;
    if(!cnt[a]) v.push_back(a);
    cnt[a]++;
  }
  sort(v.begin(),v.end());
  n=v.size();
  for(int i=0; i<n; i++){
    int x=cnt[v[i]];
    if(i+1<n && v[i+1]-1==v[i]) x+=cnt[v[i+1]];
    if(i+2<n && v[i+2]-1==v[i+1]) x+=cnt[v[i+2]];
    ans=max(ans,x);
  }
  cout<<ans;
  return 0;
}

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

int main()
{
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    sort(a,a+3);
    int ans=0;
    ans=ans+(a[2]-a[0])/2+(a[2]-a[1])/2;
    //printf("%d\n",ans);
    a[0]+=((a[2]-a[0])/2*2);
    a[1]+=((a[2]-a[1])/2*2);
    sort(a,a+3);
    //printf("%d %d %d\n",a[0],a[1],a[2]);
    for(int i=0;i<3;i++){
        ans=ans+a[i]-a[0];
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n){
    int in;
    cin >> in;
    mp[i+1] = in;
  }

  ll ans = 0;
  for(auto p : mp){
    ans += p.second/2;
    p.second %= 2;
    if(p.second == 1){
      if(mp[p.first+1] > 0){
        ans++;
        mp[p.first+1]--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
const int N = 607, mod = 1000000007;

int n, link, opp[N], g[N], f[N][N], c[N][N];

int main() {
  scanf("%d%d", &n, &link);
  n <<= 1;
  while (link--) {
    int x, y;
    scanf("%d%d", &x, &y);
    opp[x] = y;
    opp[y] = x;
  }
  g[0] = 1;
  for (int i = 2; i <= n; i += 2) {
    g[i] = (ll) g[i - 2] * (i - 1) % mod;
  }
  for (int l = 1; l <= n; l++) {
    for (int r = l; r <= n; r++) {
      c[l][r] = c[l][r - 1] + !opp[r];
    }
  }
  int ans = 0;
  for (int len = 2; len <= n; len++) {
    for (int l = 1; l + len - 1 <= n; l++) {
      int r = l + len - 1, ok = 1;
      for (int i = l; i <= r; i++) {
        if (opp[i] && (opp[i] < l || opp[i] > r)) {
          ok = 0;
        }
      }
      if (!ok) continue;
      f[l][r] = g[c[l][r]];
      for (int k = l + 1; k < r; k++) {
        f[l][r] = (f[l][r] + mod - (ll) f[l][k] * g[c[k + 1][r]] % mod) % mod;
      }
      ans = (ans + (ll) f[l][r] * g[c[1][l - 1] + c[r + 1][n]]) % mod;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 3072
#include <cstdio>
#include <iostream>
#include <string>

int main() {
    int n;
    scanf("%d", &n);
    int big = -1, small = 1001;
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        big = std::max(a, big);
        small = std::min(a, small);
    }
    printf("%d\n", big - small);
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use itertools::Itertools;

#[fastout]
fn main() {
  input! {
    n: usize,
    s: Chars,
  }
  let s: Vec<usize> = s.into_iter().map(|c| match c {
    'R' => 0,
    'G' => 1,
    _ => 2,
  }).collect();
  let mut count = vec![vec![0; 3]; n+1];
  for (i, &c) in s.iter().enumerate() {
    for x in 0 .. 3 {
      count[i+1][x] = count[i][x];
    }
    count[i+1][c] += 1;
  }
  let mut ans = 0i64;
  for j in 0 .. n {
    for k in j+1 .. n {
      if s[j] == s[k] {
        continue;
      }
      let x = 3 - s[j] - s[k];
      ans += count[j][x];
      if let Some(i) = (2 * j).checked_sub(k) {
        if s[i] == x {
          ans -= 1;
        }
      }
    }
  }

  println!("{}", ans);
}


Measured memory_bytes: 2300
def main():
    N, M = (int(i) for i in input().split())
    edge = [set() for _ in range(N)]
    for i in range(M):
        a, b = (int(i) for i in input().split())
        edge[a-1].add(b-1)
        edge[b-1].add(a-1)
    from itertools import permutations
    ans = 0
    for p in permutations(range(1, N)):
        u = 0
        for v in p:
            if v not in edge[u]:
                break
            u = v
        else:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
#include<stdio.h>
int main(){
  int x,y,esc,i;
  scanf("%d %d",&x,&y);
  for(i=0;;i++){
    if(x==0&&y==0){
      break;
    }else if(x>y){
      esc=x;
      x=y;
      y=esc;
    }
    printf("%d %d\n",x,y);
    scanf("%d %d",&x,&y);
  }
  return 0;
}


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

int main() {
  int a, b;
  if (scanf("%d %d", &a, &b) < 0) {
    exit(1);
  }
  int product = a * b;
  if (product % 2 == 0) {
	printf("Even");
  } else {
    printf("Odd");
  }
}

Measured memory_bytes: 128
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>

long long PRIME = 1e9 + 7;
using namespace std;

int main(){
    int H, W;

    cin >> H >> W;

    vector<string> S(H);
    for(int i = 0; i < H; ++i){
        cin >> S.at(i);
    }

    vector<vector<int>> table(H, vector<int>(W, 0));

    for(int i = 1; i < W; ++i){
        table[0][i] = table[0][i-1];
        if(S[0][i-1] == '#' && S[0][i] == '.'){
            table[0][i] += 1;
        }
    }

    for(int i = 1; i < H; ++i){
        table[i][0] = table[i-1][0];
        if(S[i-1][0] == '#' &&  S[i][0] == '.'){
            table[i][0] += 1;
        }
    }

    for(int i = 1; i < H; ++i){
        for(int j = 1; j < W; ++j){
            int from_top = table[i-1][j];
            if(S[i-1][j] == '#' && S[i][j] == '.'){
                ++from_top;
            }

            int from_left = table[i][j-1];
            if(S[i][j-1] == '#' && S[i][j] == '.'){
                ++from_left;
            }

            table[i][j] = min(from_top, from_left);
        }
    }

    if(S[H-1][W-1] == '#'){
        ++table[H-1][W-1];
    }

    cout << table[H-1][W-1];

}



Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(1LL << n);
    rep(i,0,1LL << n) cin >> a[i];
    sort(all(a), greater<ll>());
    priority_queue<ll> pq;
    pq.emplace(1LL << n);
    ll last = a[0];
    ll id = 0;
    bool ok = true;
    debug(a);
    for(; id < (1LL << n);){
        ll cnt = 0;
        while(id < (1LL << n) && a[id] == last){
            cnt++;
            id++;
        }
        vector<ll> v;
        while(!pq.empty() && cnt){
            v.emplace_back(pq.top());pq.pop();
            cnt--;
        }
        debug(cnt, id, last, v);
        if(cnt){
            ok = false;
            break;
        }
        for(auto k : v){
            while(k > 1){
                k /= 2;
                pq.emplace(k);
            }
        }
        if(id < (1LL << n))last = a[id];
    }

    YES(ok);
}

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

int main(int argc, char const *argv[]) {
    string Str;
    cin >> Str;
    int sec_num;
    sec_num = stoi(Str);

    vector<int> sec(4);

    for (int i=0; i<4; i++) {
        sec.at(i) = sec_num % 10;
        sec_num /= 10;
    }
    
    bool judge =true;

    for (int i=0; i<3; i++) {
        if (sec.at(i) == sec.at(i+1)) {
            judge = false;
            break;
        }
    }

    if (judge) {
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

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

    ll N; cin >> N;
    ll x;
    ll p[N], s[N]; REP(i,N) {
        cin >> x;
        p[i] = x;
        s[i] = x;
    }
    sort(s, s+N);
    ll cnt = 0;
    REP(i,N) {
        if (s[i] != p[i]) ++cnt;
    }
    cout << ((cnt>2)?"NO":"YES") << '\n';

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 400010
#define RG register
#define ls (x<<1)
#define rs (x<<1|1)
#define mid ((l+r)>>1)
using namespace std;
int m,n,ans,tr[N<<2];
struct node{
    int l,r;
    bool operator < (const node &x) const{
	return r-l<x.r-x.l;
    }
}good[N];
inline int gi(){
    RG int x=0;RG char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x;
}
inline void pushdown(RG int x){
    tr[ls]+=tr[x];tr[rs]+=tr[x];tr[x]=0;
}
inline int query(RG int x,RG int l,RG int r,RG int g){
    if(l<r&&tr[x]) pushdown(x);
    if(l==r)   return tr[x];
    if(g<=mid) return query(ls,l,mid,g);
    else       return query(rs,mid+1,r,g);
}
inline void add(RG int x,RG int l,RG int r,RG int ll,RG int rr){
    if(l<r&&tr[x]) pushdown(x);
    if(l==ll&&r==rr){++tr[x];return;}
    if(rr<=mid)     add(ls,l,mid,ll,rr);
    else if(ll>mid) add(rs,mid+1,r,ll,rr);
    else            add(ls,l,mid,ll,mid),add(rs,mid+1,r,mid+1,rr);
}
int main(){
    n=gi();m=gi();
    for (RG int i=1;i<=n;++i){
	good[i].l=gi();
	good[i].r=gi();
    }
    sort(good+1,good+n+1);
    for (RG int i=1,j=1;i<=n&&j<=m;++i){
	if(i==1||good[i].r-good[i].l>good[i-1].r-good[i-1].l)
	    for (;j<=good[i].r-good[i].l+1;++j){
		ans=0;
		for (RG int k=j;k<=m;k+=j)
		    ans+=query(1,1,m,k);
		printf("%d\n",ans+n-i+1);
	    }
	add(1,1,m,good[i].l,good[i].r);
    }
    for (RG int i=good[n].r-good[n].l+2;i<=m;++i){
	ans=0;
	for (RG int j=i;j<=m;j+=i)
	    ans+=query(1,1,m,j);
	printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 7040
#include<bits/stdc++.h> //ABC 154_c   [TLE]
using namespace std;
int A[210000];
int main(){
	int N;
	cin>>N;
	bool flag=true;
	for(int i=1;i<=N;i++){	cin>>A[i];}	
	sort(A+1,A+N+1);
	for(int j=N;j>1;j--){
			if(A[j]==A[j-1]){
					cout<<"NO";return 0;
			}
		}
	

		cout<<"YES";

	return 0;
}

Measured memory_bytes: 1024
p=[-1]*8**6
for q in[*open(0)][1:]:
 q,*x=map(int,q.split());a,b=sorted(map(f:=lambda x:f(p[x])if~p[x]<0else x,x))
 if q:print(+(a==b))
 elif a<b:p[b]=a

Measured memory_bytes: 26472
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 201001
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n,m;
int a[sz],b[sz],p[sz];
int cur,_cur;
int cnt[sz],cnt1[sz];

int fa[sz];
int getfa(int x){return fa[x]==x?x:fa[x]=getfa(fa[x]);}

int main()
{
	file();
	read(n);
	rep(i,1,n) read(a[i]),cur^=a[i];
	rep(i,1,n) read(b[i]);
	rep(i,1,n) if (a[i]!=b[i]) p[++m]=a[i],p[++m]=b[i];
	if (!m) return puts("0"),0;
	sort(p+1,p+m+1);m=unique(p+1,p+m+1)-p-1;
	int ans=0;
	rep(i,1,n) if (a[i]!=b[i]) ++ans;
	rep(i,1,n) cnt[a[i]=lower_bound(p+1,p+m+1,a[i])-p]++;
	rep(i,1,n) cnt1[b[i]=lower_bound(p+1,p+m+1,b[i])-p]++;
	if (*lower_bound(p+1,p+m+1,cur)==cur) ++cnt[lower_bound(p+1,p+m+1,cur)-p]; else ++ans;
	rep(i,1,n+n) if (cnt[i]<cnt1[i]) return puts("-1"),0;
	rep(i,1,m) fa[i]=i;
	rep(i,1,m) if (fa[i]==i) ++ans;--ans;
	rep(i,1,n) if (a[i]!=b[i]&&getfa(a[i])!=getfa(b[i]))
		--ans,fa[fa[a[i]]]=fa[b[i]];
//	m=0;rep(i,1,n) if (a[i]!=b[i]) p[++m]=a[i],p[++m]=b[i];
//	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 7040
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll a;
    ll b;
    ll n;
    cin >> a >> b >> n;
    ll tmp=b-1;
    CHMIN(tmp,n);
    ll ans = ((a*tmp)/b) - (a*(tmp/b)) ;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, x, N) for (int i = x; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
typedef long long ll;
int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i, 0, N)
    {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int ans = 0;
    rep(a, 0, N)
    {
        rep(b, 0, a)
        {
            int ab = d[a] + d[b];
            int r = lower_bound(d.begin(), d.end(), ab) - d.begin();
            int l = a + 1;
            ans += r - l;
        }
    }
    cout << ans << endl;                                    
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!(n: i64,d: i64);
    let mut sum = 0;
    for i in 0..n {
        input!(x: i64,y: i64); 
        let dist = x*x+y*y;
        if dist<=d*d {
            sum += 1;
        }
    }
    println!("{}",sum);
}

Measured memory_bytes: 4916
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+10;
const double inf=1e9;
typedef long long ll;
typedef pair<int,int>pr;
const ll mod=1e9+7;
ll _pow(ll  a,ll b) {
    ll ans=1;
    while(b) {
        if(b&1)
            ans=ans*a;
        a=a*a;
        b>>=1;
    }
    return ans;
}
double a[maxn];
int main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin>>n;

  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  sort(a+1,a+n+1);
  double ans=(a[1]+a[2])/2.0;
  for(int i=3;i<=n;i++){
     ans=(ans+a[i])/2.0;
  }
  cout<<ans<<endl;
  return 0;
}
/*
9 111 92
150 254 268 417 798 704 701 927 128
*/


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> P(N);
    for (int& x : P) cin >> x, --x;
    vector<int> Q(N);
    for (int i = 0; i < N; i++) Q[P[i]] = i;
    multiset<int> S;
    S.insert(-1);
    S.insert(-1);
    S.insert(N);
    S.insert(N);
    ll res = 0;
    for (int i = N - 1; i >= 0; i--) {
      auto it = S.lower_bound(Q[i]);
      auto f = it, b = it;
      int f1 = *(--f);
      int f2 = *(--f);
      int b1 = *(b++);
      int b2 = *(b++);
      ll ways = 0;
      ways += 1ll * (Q[i] - f1) * (b2 - b1);
      ways += 1ll * (f1 - f2) * (b1 - Q[i]);
      res += ways * (i + 1);
      S.insert(Q[i]);
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int C = 8;

string cs[C] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
int R[C] = {0, 0, 0, 0, 255, 255, 255, 255};
int G[C] = {0, 0, 255, 255, 0, 0, 255, 255};
int B[C] = {0, 255, 0, 255, 0, 255, 0, 255};

int solve(int r, int g, int b){
  int d = 1e9, res = 0;
  REP(i, C){
    int _d = (r - R[i]) * (r - R[i]) + (g - G[i]) * (g - G[i]) + (b - B[i]) * (b - B[i]);
    if(_d < d){ d = _d; res = i; }
  }
  return res;
}

int main() {
  string s;
  char **buf;
  while(cin >>s && s != "0"){
    string _s = s, __s = s;
    int r = (int)strtol(s.substr(1, 2).c_str(), buf, 16);
    int g = (int)strtol(_s.substr(3, 2).c_str(), buf, 16);
    int b = (int)strtol(__s.substr(5, 2).c_str(), buf, 16);
    cout <<cs[solve(r, g, b)] <<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
using namespace std;

const int N_MAX = 11;
int N, M;
int k[N_MAX];
int s[N_MAX][N_MAX];
int p[N_MAX];
int sw[10] = {};
int status;
bool flag;
int ans = 0;

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> s[i][j];
		}
	}
	for (int i = 0; i < M; i++) cin >> p[i];

	for (int bit = 0; bit < (1 << N); ++bit) {
		flag = true;
		for (int i = 0; i < N; i++) sw[i] = 0;
		for (int i = 0; i < N; ++i) {
			if (bit & (1 << i)) {
				sw[i] = 1;
			}
		}
		for (int i = 0; i < M; i++) {
			status = 0;
			for (int j = 0; j < k[i]; j++) {
				status += sw[s[i][j]-1];
			}
			//cout <<"status:"<< status << endl;
			//cout << "p[i]:" << p[i] << endl;
			//cout << "mod" << status % 2 << endl;
			if ((status % 2) != p[i]) { 
				//cout << "not valid" << endl;
				flag = false; }
		}
		if (flag) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
//#include "debug.cpp"

const int M=1e9+7;

int mod(int n){
    while(n<0)
        n+=M;
    return n%M;
}

int power(int x,int y)
{
    int res = 1;
    x = mod(x);
    while (y > 0)
    {
        if (y & 1)
            res =mod(res*x);
        y = y>>1;
        x = mod(x*x);
    }
    return mod(res);
}

int modInv(int a)
{
    int ans = power(a, M-2);
    return ans%M;
}

vector<PI>pfact;
void prime_factor(int n)
{
    pfact.clear();
    int cnt=0;
    while (n % 2 == 0){
        n = n/2;
        cnt++;
    }
    if(cnt)
        pfact.push_back({2,cnt});
   for (int i = 3; i <= sqrt(n); i = i + 2){
        cnt=0;
        while (n % i == 0){
            n = n/i;
            cnt++;
        }
        if(cnt)
            pfact.push_back({i,cnt});
    }
    if (n > 2)
        pfact.push_back({n,1});
}

int32_t main()
{
    boost;
    int n;
    cin>>n;
    int a[n];
    map<int,int>mp;
    vector< map<int,int> >v;
    for(int i=0;i<n;i++){
        cin>>a[i];
        prime_factor(a[i]);
        map<int,int>m;
        for(PI p:pfact){
            m[p.ff]=p.ss;
            mp[p.ff]=max(p.ss,mp[p.ff]);
        }
        v.push_back(m);
    }
    int ans=0,ml=1;
    for(PI p:mp)
        ml=mod(ml*power(p.ff,p.ss));

    for(int i=0;i<n;i++)
        ans=mod(ans+ml*modInv(a[i]));
    cout<<ans<<endl;
}


Measured memory_bytes: 3896
from collections import deque
n , q = map(int,input().split())
lot = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int,input().split())
    lot[a-1].append(b-1)
    lot[b-1].append(a-1)
tyu = [0]*n
for i in range(q):
    p , x = map(int,input().split())
    tyu[p-1] += x

taiki = deque()
taiki.append(0)
owari = [True] * n
while  taiki:
    s = taiki.pop()
    for i in lot[s]:
        if owari[i]:
            tyu[i] += tyu[s]
            taiki.append(i)
    owari[s] = False
print(*tyu)

Measured memory_bytes: 56088