akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>


using namespace std;

int main(){

	/*Q1*/
/*	int ret = 0;
	int in = 0;

	cin >> in;

	for (int i = 0; i < 4; ++i){
		if (in % 10 == 2){
			ret++;
		}
		in /= 10;
	}

	cout << ret;
	*/
	/*Q2*/
	long h = 0;
	long w = 0;
	long n = 0;
	int ret = 0;

	long h_in = 0;
	long w_in = 0;

	string str, tmp;
	cin >> n >> h >> w;


	for (int i = 0; i < n; ++i){
		cin >> h_in >> w_in;
		if (h <= h_in  && w <= w_in){
			ret++;
		}

	}
	 
	cout << ret;


	/*Q3*/
	
	/*Q4*/

	return 0;
	
}


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

vector<int> graph[100001];
bool vis[100001];
int dp[100001];
void dfs(int u)
{
	dp[u]=0;
	vis[u]=1;
	for(auto v:graph[u])
	{
		if(!vis[v])
		{
			dfs(v);
		}
		dp[u]=max(dp[u],dp[v]+1);
	}
}	

int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		graph[x].push_back(y);
	}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
			dfs(i);
	}
	cout<<*max_element(dp+1,dp+n+1);
	return 0;
}


Measured memory_bytes: 8192
#include "bits/stdc++.h"

using namespace std;

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

    int m,nmin,nmax;
    while(cin>>m>>nmin>>nmax,m||nmin||nmax){
        vector<int> p(m);
        nmin--;nmax--;
        for(int i=0;i<m;i++) cin>>p[i];
        sort(p.rbegin(),p.rend());
        int res=0,gap=0;
        for(int i=nmin;i<=nmax;i++){
            int gtmp=p[i]-p[i+1];
            if(gtmp>=gap){
                gap=gtmp;
                res=i+1;
            }
        }
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
char ch[700005],temp[100005];
int main()
{
	char a;
	int n,dir=0,op,pos,fir=300000,end=300000;
	scanf("%s",temp);
	for(int i=fir;i<=strlen(temp)+fir-1;i++)ch[i]=temp[i-fir];
	end=strlen(temp)+fir-1;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&op);
		if(op==1)dir=1-dir;
		else
		{
			scanf("%d %c",&pos,&a);
			if((dir==0&&pos==1)||(dir==1&&pos==2))
			{
				fir--;
				ch[fir]=a;
			}
			else
			{
				end++;
				ch[end]=a;
			}
		}
	}
	if(dir==0)for(int i=fir;i<=end;i++)printf("%c",ch[i]);
	else for(int i=end;i>=fir;i--)printf("%c",ch[i]);
	printf("\n");
}

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

#define int long long

const int MOD = 1e9 + 7;

int a(int A, int B)
{
    if (B == 0)
        return 1;
    if (B % 2 == 1)
        return a(A, B - 1) * A % MOD;
    int C = a(A, B / 2);
    return C * C % MOD;
}
int b(int A, int B)
{
    int C = 1;
    for (int i = A; i <= B; i++)
        C = C * i % MOD;
    return C;
}
signed main()
{
    int x, y;
    cin >> x >> y;

    if ((x + y) % 3)
    {
        cout << 0 << "\n";
        return 0;
    }

    int n = (2 * y - x) / 3, m = (2 * x - y) / 3;
    if (n < 0 || m < 0)
    {
        cout << 0 << "\n";
        return 0;
    }
    cout << b(n + 1, m + n) * a(b(1, m) % MOD, MOD - 2) % MOD << endl;
}

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

using namespace std;

long long k;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> k;

    long long ans = -1;
    long long re = 0;
    for(long long i = 1; i <= 1e6; i++){
        long long calc = (re * 10 + 7) % k;
        re = calc;
        if(re == 0){
            ans = i;
            break;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3636
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

n,m = map(int,input().split())
uf1=UnionFind(n)
for i in range(m):
    a,b=map(int, input().split())
    uf1.union(a-1,b-1)

for i in range(n):uf1.find(i)
X = uf1.par

ans = [0]*n
for i in range(n):
    ans[X[i]] += 1

print(max(ans))


Measured memory_bytes: 20024
n, k = gets.split.map(&:to_i)
points = []
n.times { points << gets.split.map(&:to_i) }
areas = []
if k < 4
  points.combination(k).each do |combination|
    xs = combination.map { |p| p[0] }.sort
    ys = combination.map { |p| p[1] }.sort
    x_first = xs.first
    x_last = xs.last
    y_first = ys.first
    y_last = ys.last
    inner_points = 0
    points.each_with_index do |(x, y), index|
      inner_points += 1 if (x_first <= x && x <= x_last) && (y_first <= y && y <= y_last)
      break if inner_points >= k || inner_points + (n - index - 1) < k
    end
    areas << (x_last - x_first) * (y_last - y_first) if inner_points >= k
  end
  puts areas.min
else
  points.combination(4).each do |a, b, c, d|
    xs = [a[0], b[0], c[0], d[0]].sort
    ys = [a[1], b[1], c[1], d[1]].sort
    x_first = xs.first
    x_last = xs.last
    y_first = ys.first
    y_last = ys.last
    inner_points = 0
    points.each_with_index do |(x, y), index|
      inner_points += 1 if (x_first <= x && x <= x_last) && (y_first <= y && y <= y_last)
      break if inner_points >= k || inner_points + (n - index - 1) < k
    end
    areas << (x_last - x_first) * (y_last - y_first) if inner_points >= k
  end
  puts areas.min
end

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1000000007;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, q, x, K;
string s,t;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>s>>t;
	string Sx = s,Tx = t;
	reverse(all(Sx));
	reverse(all(Tx));

	if(Sx == t && Tx == s) cout<<"YES";
	else cout<<"NO";
}


int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;

int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i, n) {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<char> VB;

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

const double eps=1e-5;
const long long INF=(LL)(1e9)*(LL)(1e9);

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;
}

const LL pow(const LL p, const LL q)
{
	LL t=1;
	REP(i,q)
		t*=p;
	return t;
}


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

	string ss;
	cin>>ss;
	/*
	string s="";
	REP(i,ss.size())
	{
		if(ss[i]=='x')
			continue;
		s+=string{ss[i]};
	}

	REP(i,s.size()/2)
	{
		if(s[i]!=s[s.size()-i-1])
		{
			cout<<-1<<endl;
			return 0;
		}
	}*/

	int ans=0;
	int l=0,r=ss.size()-1;
	while(1)
	{
		if(l>=r) break;
		while(ss[l]=='x'&&ss[r]=='x')
		{
			l++;r--;
			if(l>=r) break;
		}
		if(l>=r) break;

		while(ss[l]=='x')
		{
			l++;
			ans++;
		}
		while(ss[r]=='x')
		{	
			r--;
			ans++;
		}
		if(ss[l]!=ss[r])
		{
			cout<<-1<<endl;
			return 0;
		}
		l++;
		r--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
use std::str::FromStr;
use std::io::stdin;

fn main() {
    let (A,B,T) = {
        let r = read_vec::<i32>();
        (r[0], r[1], r[2])
    };
    println!("{}", B*(T/A));
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line: String = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#D問題
S = list(str(input()))
N = len(S)

ans = [-1,-1]
now = []
for i in range(N):
    if i == 0:
        now.append(S[0])
    elif i == 1:
        if now[0] == S[1]:
            ans[0] = 1
            ans[1] = 2
            break
        else:
            now.append(S[1])
    else:
        if S[i] in now:
            if now[0] == S[i]:
                ans[0] = i-1
            else:
                ans[0] = i
            ans[1] = i+1
            break
        else:
            del now[0]
            now.append(S[i])
            
print(*ans)

Measured memory_bytes: 3956
n,m  = gets.chomp.split(' ').map(&:to_i)
k = []
m.times do
  k.push(gets.chomp.split(' ').map(&:to_i))
end

kekka = Array.new(n,0)

n.times do |i|
  i+1
  k.each{|kk|
    if kk.include?(i+1)
      kekka[i]+=1
    end
  }
end

kekka.each do |kk|
  puts kk
end

Measured memory_bytes: 1788
#include <iostream>
#include <queue>
#include <assert.h>   
#include <vector>
#include <algorithm>
#include <time.h>
#include <numeric>
#include <string>
#include <cstring>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <numeric>
#include <deque>
#include <iomanip>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <cstdio>
using namespace std;


//#define double long double
#define int long long
//#define int unsigned long long

#define ll long long
#define ld long double 
#define pi pair<int, int> 
#define pl pair<ll,ll>  
#define pd pair<ld,ld> 
#define str string  
#define mp make_pair
#define vi vector<int> 
#define vl vector<ll> 
#define vd vector<ld> 
#define vs vector<str> 
#define vpi vector<pi> 
#define vpl vector<pl> 
#define vpd vector<pd> 
#define si set<int> 
#define FF(i,j,n) for(signed i=j;i<=n;i++)  
#define DD(i,j,n) for(signed i=j;i>=n;i--) 
#define F(i,j,n) for(signed i=j;i<n;i++)   
#define D(i,j,n) for(signed i=j;i>n;i--) 
#define mem(a,b) memset(a,b,sizeof(a))
#define ndl cout << endl
#define ull unsigned long long 

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;


#define sz(x) (signed)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 
#define ft front() 
#define bk back() 
#define fi first
#define se second
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

//math


const int mod = 1e9 + 7;

ll powmod(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 gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int pct(int x) { return __builtin_popcount(x); } 
int bit(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) 
int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 


//DEBUG, compile with -DLOCAL
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
  cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
  DBG(t...); }
#ifdef LOCAL 
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#define HERE cout << "===GOTHERE===" << endl
#else
#define dbg(...) 42
#define HERE 42
#endif


 /* ============== END OF HEADER ============== */





const int maxn = 1e5*3+20;

int n,q,k;
int qs[100];
int len;
char D = 'D';
char C = 'C';
char M = 'M';
str s;

void solve(){
	cin >> n;
	cin >> s;
	cin >> q;
	F(_,0,q){
		cin >> len;
		int dmc = 0, dc = 0, mc = 0, tt = 0;
		F(i,0,sz(s)){
			if(i > len - 1){
				if(s[i-len] == D){
					dc--;
					dmc -= mc;
				}else if(s[i-len] == M){
					mc --;
				}
			}
			if(s[i] == D){
				dc++;
			}else if(s[i] == M){
				dmc += dc;
				mc++;
			}else if(s[i] == C){
				tt += dmc;
			}
		}
		cout << tt << endl;
	}
}

signed main(){
  //clock_t t1 = clock();  
	IOS
	solve();
  
  //cout << "THE ALGORITHM TOOK: " << (clock() - t1) * 1.0 / CLOCKS_PER_SEC * 1000 << "ms"<< endl;
	return 0;
}

Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int sum = N;
    for(int i = 0;i < N;i++){
        cin >> A.at(i);
    }
    for(int i = N - 1;0 < i;i--){
        for(int k = 0;k < i;k++){
            if(A.at(i) > A.at(k)){
                int s = 0;
                s = A.at(i);
                A.at(i) = A.at(k);
                A.at(k) = s;
            }
        }
    }
    for(int i = 0;i < N - 1;i++){
        if(A.at(i) == A.at(i + 1)){
            sum--;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	READ(n);
	READARR(a, n);
	int cnt = 0;
	FOR (i, 2, n - 1)
	{
		if ((a[i] > a[i - 1] && a[i] < a[i + 1]) || (a[i] < a[i - 1] && a[i] > a[i + 1])) cnt++;
	}
	cout << cnt;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

double eps = 0.00001;
using p2 = complex<double>;
double det(p2 v1, p2 v2) {
  return v1.real() * v2.imag() - v1.imag() * v2.real();
}
double dot(p2 v1, p2 v2) {
  return v1.real() * v2.real() + v1.imag() * v2.imag();
}
bool same(double x, double y) { return fabs(x - y) < eps; }

auto p2comp = [](const p2 &l, const p2 &r) {
  if (fabs(l.real() - r.real()) > eps)
    return l.real() < r.real();
  return l.imag() < r.imag();
};
struct Line {
  p2 st, ed;
  Line(p2 st, p2 ed) : st(st), ed(ed) {}
  Line(double x1, double y1, double x2, double y2)
      : st(p2(x1, y1)), ed(p2(x2, y2)) {}
  Line(p2 st, double x, double y) : st(st), ed(p2(x, y)) {}
  Line(double x, double y, p2 ed) : st(p2(x, y)), ed(ed) {}
};

struct Poly {
  vector<p2> ps;
  Poly(vector<p2> ps) : ps(ps) {}
};

struct Circle {
  p2 p;
  double r;
  Circle(p2 p, double r) : p(p), r(r) {}
};

struct ConX {
  vector<p2> ps;
  // graham scan
  // ref: プログラミングコンテストチャレンジブック p233
  ConX(vector<p2> v) {
    sort(v.begin(), v.end(), p2comp);

    int k = 0, n = v.size();
    ps.resize(n * 2);
    for (int i = 0; i < n; i++) {
      while (k > 1 && det(ps[k - 1] - ps[k - 2], v[i] - ps[k - 1]) < -eps)
        k--;
      ps[k++] = v[i];
    }
    for (int i = n - 2, t = k; i >= 0; i--) {
      while (k > t && det(ps[k - 1] - ps[k - 2], v[i] - ps[k - 1]) < -eps)
        k--;
      ps[k++] = v[i];
    }
    ps.resize(k - 1);
  }
  size_t size() { return ps.size(); }
};

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

  int n;
  cin >> n;
  vector<p2> ps;
  for (int i = 0; i < n; i++) {
    double x, y;
    cin >> x >> y;
    ps.emplace_back(x, y);
  }
  ConX c(ps);

  int j = 0;
  p2 st = c.ps[0];
  for (int i = 1; i < c.size(); i++) {
    if (st.imag() > c.ps[i].imag() ||
        (same(st.imag(), c.ps[i].imag()) && st.real() > c.ps[i].real())) {
      st = c.ps[i];
      j = i;
    }
  }

  cout << c.size() << endl;
  for (int i = 0; i < c.size(); i++) {
    int x = c.ps[(i + j) % c.size()].real();
    int y = c.ps[(i + j) % c.size()].imag();
    cout << x << " " << y << endl;
  }

  return 0;
}



Measured memory_bytes: 9192
#include<cstdio>
#include<queue>
using namespace std;
struct Y{
	int h,t;
	Y(int h=0,int t=0):h(h),t(t){}
	inline bool operator>(const Y&a)const{
		return t>a.t;
	}
};
priority_queue<Y,vector<Y>,greater<Y> >w,a[100005];
int n,m,f[100005],v[100005],sum,num[100005],p,s;
char b[100005];
#define ll long long
unsigned long long ans;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int gf(int x){
	return x==f[x]?x:f[x]=gf(f[x]);
}
int main(void){
	register int i,x,y;
	n=read(),m=read();
	for(i=1;i<=n;++i)f[i]=i;
	for(i=1;i<=n;++i)v[i]=read();
	for(i=1;i<=m;++i)
		x=1+read(),y=1+read(),f[gf(x)]=gf(y);
	for(i=1;i<=n;++i)a[gf(i)].push(Y(gf(i),v[i]));
	for(i=1;i<=n;++i)
		if(gf(i)==i)
			++sum;
	s=sum,sum=sum*2-2;
	if(sum==0){
		puts("0");
		return 0;
	}
	for(i=1;i<=n;++i)
		if(gf(i)==i){
			--sum,ans+=a[i].top().t,a[i].pop(),num[i]=1;
			if(!a[i].empty())w.push(a[i].top()),a[i].pop();
		}
	if(sum<0){
		puts("Impossible");
		return 0;
	}
	while(sum--){
		while(!w.empty()){
			x=w.top().h;
			if(num[x]+1==s)w.pop();
			else break;
		}
		if(w.empty()){
			puts("Impossible");
			return 0;
		}
		ans+=w.top().t,++num[w.top().h];
		int y=w.top().h;
		w.pop();
		if(!a[y].empty()){
			w.push(a[y].top()),a[y].pop();
		}
	}
	printf("%llu\n",ans);
	return 0;
}

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

using namespace std;

const int nmax = 8;

int ans, n, m;
vector<vector<int>> g(nmax);

void dfs(int u, int mask)
{
    if (mask == (1 << n) - 1)
        ans++;
    for (int v : g[u])
        if (!((1 << v) & mask))
            dfs(v, mask | (1 << v));
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    while (m--)
    {
        int u, v;
        cin >> u >> v;
        g[--u].push_back(--v);
        g[v].push_back(u);
    }
    ans = 0;
    dfs(0, 1);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                break
        else:
            return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    elif 0 in [ n%i for i in range(11,min(n-1,50),2) ]:return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Measured memory_bytes: 7724
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

const int N = 500 + 5;

int ans[N*N], cnt[N];

vector<pii> ord;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	rep(i,1,n+1){
		int x;
		cin >> x;
		ord.push_back({x,i});
		ans[x] = i;
	}
	sort(all(ord));
	queue<int> q, lft;
	for(pii p:ord){
		rep(i,0,p.second-1)q.push(p.second);
	}
	bool val = 1;
	rep(i,1,n*n+1){
		if(ans[i] == 0){
			if(q.size()){
				ans[i] = q.front();	
				++cnt[ans[i]];
				q.pop();
			}
			else if(lft.size()){
				ans[i] = lft.front();
				lft.pop();
			}
			else {
				val = false;
				break;
			}
		}
		else {
			rep(j,0,n-ans[i])lft.push(ans[i]);
			if(cnt[ans[i]] < ans[i] - 1){
				val = false;
				break;
			}
		}
	}
	if(val){
		cout << "Yes" << '\n';	
		rep(i,1,n*n+1)cout << ans[i] << ' ';
		cout << '\n';
	}
	else{
		cout << "No" << '\n';
	}
}


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

int main() {
    // Write Your Code Below
    int n;cin >> n;
    vector<pair<string, pair<int,int>>> vp(n);
    for(int i=0;i<n;i++){
        int t;
        cin >> vp[i].first >> t;
        vp[i].second.first = -t;
        vp[i].second.second = i;
    }
    sort(vp.begin(), vp.end());
    for(int i=0;i<n;i++){
        cout << vp[i].second.second+1 << endl;
    }

}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
mn = [100 for x in range(26)]
exist = [True for x in range(26)]
for _ in range(n):
    l = list(input())
    d = Counter(l)
    for i in range(26):
        if d[chr(i+97)] == 0:
            exist[i] = False

    for key, val in d.items():
        mn[ord(key)-97] = min(mn[ord(key)-97], val)
for i in range(26):
    if exist[i]:
        print(chr(i+97)*mn[i], end='')


Measured memory_bytes: 9244
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>

using namespace std;

int main() {
    int A[3][3]={0};
    int a = 0;

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a;
            A[i][j]=a;
        }
    }
    int ans[3][3]={0};
    int n = 0;
    cin >> n;
    int b[n];
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (A[j][k] == b[i]) {
                    ans[j][k] = 1;
                }
            }
        }
    }
    for (int i = 0; i < 3; i++) {
        if (ans[i][0]+ans[i][1]+ans[i][2] == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (int i = 0; i < 3; i++) {
        if (ans[0][i]+ans[1][i]+ans[2][i] == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (ans[0][0]+ans[1][1]+ans[2][2] == 3 && ans[0][0] != ans[1][1] != ans[2][2]) {
        cout << "Yes" <<endl;
        return 0;
    }
    if (ans[0][2]+ans[1][1]+ans[2][0] == 3 && ans[0][0] != ans[1][1] != ans[2][2]) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

const int MAX_N = 115;
int N;
int W[MAX_N];

void solve()
{
	const int tot = accumulate(W+1,W+N+1,0);
	int ans = tot;
	for(int t = 1; t < N; ++t){
		int a = 0;
		for(int i=1;i<=t;++i)a+=W[i];
		ans=min(ans, (int)abs((tot-2*a)));
	}
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=1;i<=N;++i)cin >> W[i];
	solve();
	return 0;
}

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

using namespace std;

#define rep(i, s, n) for(long i = s; i < (long)(n); ++i)

int main() {
  long n;
  cin >> n;

  vector<long> l(n);
  rep(i, 0, n) {
    cin >> l[i];
  }

  sort(l.begin(), l.end());

  long answer = 0;
  rep(i, 0, n) {
    rep(j, i + 1, n) {
      long upper_limit = l[i] + l[j];
      auto bound = lower_bound(l.begin() + j + 1, l.end(), upper_limit);
      auto bound_index = bound - l.begin();
      answer += max(bound_index - j - 1, (long)0);
    }
  }

  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 512
n =int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
x = []
sum = 0
for i in range(n):
     x.append(v[i]-c[i])
for i in range(n):
     if x[i] > 0:
          sum += x[i]
print(sum)

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

int power(int x, int y, int p)
{
    int res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


int32_t main(){
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	cout<<max(a*b, c*d)<<endl;
}

// UUURRRDDDLLLLUUUURRRRDRDDDDLLLLU
// UURRURRDDDLLDLLULUUURRURRDDDLLDL


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;

int main() {
	ll n, a, b;	cin >> n >> a >> b;
	a -= b;
	vector<ll> h(n);
	rep(i, n)	cin >> h[i];
	sort(h.begin(), h.end());
	reverse(h.begin(), h.end());
	ll left = 0, right = mod;
	for (int i = 0; i < 50; i++) {
		ll mid = (left + right) / 2;
		vector<ll> tmp = h;
		rep(i, n)	tmp[i] -= mid*b;
		ll need = 0;
		rep(i, n) {
			if (tmp[i] <= 0)	break;
			need += (tmp[i] + a - 1) / a;
		}
		if (mid >= need)	right = mid;
		else	left = mid;
	}
	cout << right << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	string A, B;
	cin >> A >> B;

	vector<int> A_v(A.begin(), A.end());
	vector<int> B_v(B.begin(), B.end());

	for (int i = 0; i < A_v.size(); i++) {
		A_v[i] -= 48;
	}
	for (int i = 0; i < B_v.size(); i++) {
		B_v[i] -= 48;
	}


	//桁が違えばそっちのが小さい
	if (A_v.size() > B_v.size()) {
		cout << "GREATER";
		return 0;
	}
	else if (A_v.size() < B_v.size()) {
		cout << "LESS";
		return 0;
	}
	else {
		for (int i = 0; i < A_v.size(); i++) {
			if (A_v[i] > B_v[i]) {
				cout << "GREATER";
				return 0;
			}
			else if (A_v[i] < B_v[i]) {
				cout << "LESS";
				return 0;
			}

		}
		cout << "EQUAL";
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, k;
int w[100000] = {};

bool ok(int x) {
	int now = 0;
	for (int i = 0; i < k; ++i) {
		int tmp = 0;
		while (tmp + w[now] <= x) {
			tmp += w[now];
			now++;
			if (now == n) return true;
		}
	}
	return false;
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; ++i) cin >> w[i];
	int l = 0, r = 1e9;
	while (l != r - 1) {
		int mid = (l + r) / 2;
		if (ok(mid)) r = mid;
		else l = mid;
	}
	cout << r << endl;

	return 0;
}


Measured memory_bytes: 3464
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
const int maxn=1e5+7;
const ll modn=1e9+7;
const int inf=2e9+7;
const ll INF=1000000000000000000ll;
const double PI = acos(-1.0);
const double eps=1e-8;
inline int lowbit(int x){return x&-x;}
inline ll lowbit(ll x) {return x&-x;}
inline int CountOneBinary(ll num){int ans=0;while(num){if(num&1) ans+=1;num>>=1;}return ans;}
inline void read(int &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline void read(ll &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline ll qpow(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x%modn;x=x*x%modn;y>>=1;}return ans;}
inline double qpow(double x,ll y){double ans=1;while(y){if(y&1) ans=ans*x;x=x*x;y>>=1;}return ans;}
ll n,a[maxn],C[maxn],sum[maxn],stn;
void add(int pos)
{
    for(int i=pos;i<maxn;i+=lowbit(i)) C[i]++;
}
ll query(int pos)
{
    ll ans=0;
    for(int i=pos;i;i-=lowbit(i)) ans+=C[i];
    return ans;
}
bool check(ll x)
{
    memset(C,0,sizeof(C));
    ll bot=1;
    for(int i=1;i<=n;i++)
    {
        if(x<=a[i]) sum[i]=sum[i-1]+1;
        else sum[i]=sum[i-1]-1;
        bot=min(sum[i],bot);
    }
    bot-=2;
    ll ans=0;
    add(-bot);
    for(int i=1;i<=n;i++)
    {
        sum[i]-=bot;
        ans+=query(sum[i]);
        add(sum[i]);
    }
    return ans>=stn;
}
int main()
{
    while(scanf("%lld",&n)==1)
    {
        stn=n*(n+1)/2-n*(n+1)/2/2;
        ll l=1e9,r=1;
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]),l=min(a[i],l),r=max(a[i],r);
        while(l<r)
        {
            ll mid=l+(r-l+1)/2;
            if(check(mid))
                l=mid;
            else
                r=mid-1;
        }
        printf("%lld\n",l);
    }
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    if(n<10)
        printf("%d\n", n);
    else if(n>=10 && n<100)
        printf("9\n");
    else if(n>=100 && n<1000)
        printf("%d\n", n-90);
    else if(n>=1000 && n<10000)
        printf("909\n");
    else if(n>=10000 && n<100000)
        printf("%d\n", n-9090);
    else
        printf("90909\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int a, b;
  cin >> a >> b;
  if (a > b) {
    swap(a, b);
  }
  
  REP(i, b) {
    cout << a;
  }
  cout << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main (void){
    int i,N,ans=0;
    char S[100000]; 

    scanf("%s",S);

    N = strlen(S);

    for(i=0;i<N;i++){
        if(S[i]=='0' && S[i-1]=='0'){
            S[i] = '1';
            ans++;
        }
        else if(S[i]=='1' && S[i-1]=='1'){
            S[i] = '0';
            ans++;
        }
    }

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
ab = [0] * M
for i in range(M):
    ab[i] = tuple(map(int, input().split()))


for i in range(1,N+1):
    road = 0
    for a,b in ab:
        if a == i:
            road += 1
        if b == i:
            road += 1
    print(road)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
    int n;
    scanf("%d", &n);
    vector<int> vec(n);
    rep(i, n) scanf("%d", &vec[i]);
    sort(vec.begin(), vec.end());
    int temp = 0;
    rep(i, n - 1) temp += vec[i];
    if(vec[n - 1] < temp) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int main()
{
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  int A[12][12];
  int INF = 1001000101;
  int ans = INF;

  for (int i = 0; i < N; i++){
    cin >> C[i];
    for (int j = 0; j < M; j++){
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < (1<<N); i++){
    int cost = 0;
    vector<int> d(M,0);
    for (int j = 0; j < N; j++){
      if (i>>j&1){
        cost += C[j];
        for (int k = 0; k < M; k++){
          d[k] += A[j][k];
        }
      }
      bool ok = true;
      for (int l = 0; l < M; l++) if (d[l]<X) ok = false;
      if(ok) ans = min(ans, cost);
    }
  }

  if(ans==INF){
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
    
  return 0;
}


Measured memory_bytes: 3624
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
    
print(ans)

Measured memory_bytes: 47388
d = {'a':0,'b':1,'c':2}
S = [0,0,0]
S[0] = list(map(lambda x:d[x],list(input())))
S[1] = list(map(lambda x:d[x],list(input())))
S[2] = list(map(lambda x:d[x],list(input())))
i = [0,0,0]
j = list(map(len,S))
k = 0
while True:
    if i[k] == j[k]:
        print('ABC'[k])
        exit()
    l = i[k]
    i[k] += 1
    k = S[k][l]

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        var list1 = Console.ReadLine().Split(' ');
        var list2 = Console.ReadLine().Split(' ');

        var ass = new int[n + 1];
        for (int i = 0; i < ass.Length; ++i)
            ass[i] = int.Parse(list1[i]);

        var bs = new int[n];
        for (int i = 0; i < bs.Length; ++i)
            bs[i] = int.Parse(list2[i]);

        long count = 0;

        for (int i = 0; i < bs.Length; ++i)
        {
            var p = Math.Min(ass[i], bs[i]);
            ass[i] -= p;
            bs[i] -= p;
            count += p;

            p = Math.Min(ass[i + 1], bs[i]);
            ass[i + 1] -= p;
            bs[i] -= p;
            count += p;
        }

        Console.WriteLine(count);
    }

    private static int GCD(int a, int b) => a > b ? GCD_impl(a, b) : GCD_impl(b, a);
    private static int GCD_impl(int a, int b) => b == 0 ? a : GCD_impl(b, a % b);
    private static long LCM(int a, int b) => (long)a * b / GCD(a, b);

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 33372
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int *array=(int *)malloc(sizeof(int)*(n+2));
  array[0]=array[n+1]=0;
  int i;
  for(i=1;i<=n;i++) scanf("%d",array+i);
  int sum=0;
  for(i=1;i<=n+1;i++){
    sum+=ABS(array[i]-array[i-1]);
  }
  for(i=1;i<=n;i++){
    int t=sum-ABS(array[i]-array[i-1])-ABS(array[i+1]-array[i])+ABS(array[i+1]-array[i-1]);
    printf("%d\n",t);
  }
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
const int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}};
void read(int &x){
	register char ch=getchar();x=0;
	for(;ch==' '||ch=='\n';ch=getchar());
	for(;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(int x){
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
int n,X,x,y,ans;
short d[503][503],f[503][503];
short sol(int x,int y){
	short mn=1e4;
	for(int i=0;i<4;i++){
		int u=x+dir[i][0],v=y+dir[i][1];
		if(u<1 || v<1 || u>n || v>n)continue;
		mn=min(mn,d[u][v]);
	}
	return mn+f[x][y];
}
void upd(int x,int y){
	d[x][y]--;
	for(int i=0;i<4;i++){
		int u=x+dir[i][0],v=y+dir[i][1];
		if(u<1 || v<1 || u>n || v>n)continue;
		if(sol(u,v)<d[u][v])upd(u,v);
	}
}
int main(){
	read(n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) d[i][j]=min(min(i,j),min(n-i+1,n-j+1)),f[i][j]=1;
	for(int i=1;i<=n;i++) for (int j=1;j<=n;j++)
		read(X),x=(X+n-1)/n,y=X-(x-1)*n,f[x][y]=0,upd(x,y),ans+=d[x][y];
	write(ans);
}

Measured memory_bytes: 19976
#include<iostream>
#include<cstring> 
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

const int limit = 1e5;

int k;
int cost[limit];
int h[limit];

int ans(int n){
    if(cost[n]!=-1) return cost[n];

    int ret=2147483647;
    for(int i=n-k;i<=n-1;i++){
        if(i<0) continue;
        ret = min(ret,ans(i)+abs(h[i]-h[n]));
    }
    return cost[n]=ret;
}

int main(){
    int n;cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> h[i];
    }

    memset(cost,-1,sizeof(cost));
    cost[0]=0;

    p(ans(n-1))
}

Measured memory_bytes: 5760
from math import radians, cos,sqrt
a,b,h,m = map(int,input().split())
# hour: 1min 0.5  minute: 1min 6
min_total = h*60 + m
rad_h = min_total*0.5 % 360
rad_m = m*6
rad_diff = abs(rad_h - rad_m)
if rad_diff >= 180:
    rad_diff = 360 - rad_diff
#print(rad_diff)
result2 = a**2 + b**2 - 2*a*b*cos(radians(rad_diff))
print(sqrt(result2))

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int first_judge = false;
    REP(i, n) {
        cin >> a[i];
        if(a[i] == 1) {
            first_judge = true;
        }
    }

    if(!first_judge) {
        cout << "-1" << endl;
        return 0;
    }

    int num = 1;

    REP(i, n) {
        if(a[i] == num) {
            num++;
        }
    }
    
    cout << n - num + 1 << endl;


    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<int>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define mem(a) memset((a),0,sizeof(a))
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
double x,y,xx,yy,xxx,yyy,xxxx,yyyy;
int q;
int main(){
	cin>>q;
	while(q--){
		cin>>x>>y>>xx>>yy>>xxx>>yyy>>xxxx>>yyyy;
		xx-=x,yy-=y;
		xxxx-=xxx,yyyy-=yyy;
		if(xxxx*xx+yyyy*yy==0) cout<<"1"<<endl;
		else{
			if(xx*yyyy-xxxx*yy==0) cout<<"2"<<endl;
			else cout<<"0"<<endl;
		}
	}
	return 0;
}


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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main(){
    input!{
        n:usize,
        an:[i64;n],
    }
    let count = an.iter().filter(|&x| *x < 0).count();
    let sum:i64 = an.iter().map(|&x| x.abs()).sum();
    let ans = if count % 2 != 0{
        sum - 2 * an.iter().map(|&x|x.abs()).min().unwrap()
    } else{
        sum
    };
    println!("{}",ans);
}

Measured memory_bytes: 4476