akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<string>
#include<set>
#include<cstdio>

const long long int MOD=1e9+7;

using namespace std;

int main(){
    int n;
    vector<double> v;
    cin >> n;
    for(int i=0;i<n;i++){
        double tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    double ans=v[0];
    for(int i=1;i<n;i++){
        ans = (ans+v[i])/2.0;
    }
    printf("%.6f\n", ans);
}



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

int main(){
  int N, K;
  std::cin >> N >> K;
  
  if (K >= N){
    std::cout << 0;
    return 0;
  }
  
  std::vector<unsigned long> nums;
  unsigned long n;
  
  while(std::cin >> n) nums.push_back(n);
  std::sort(nums.begin(), nums.end(), std::greater<unsigned long>());
  
  unsigned long long sum = 0;
  for (int i = K; i < N; i++) sum += nums[i];
  
  std::cout << sum;
  
  return 0;
}

Measured memory_bytes: 4892
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;

vector<i64> x,y;


/** 
 * Kruskal's Algorithm [Tarjan]
 * 
 * O(mlogm + m * a(m , n))
*/

#include <vector>
#include <set>
#include <algorithm>
using namespace std;

struct UnionFind {
  vector<int> par_;
  vector<int> rank_;

  void init(int size) {
    par_.resize(size, 0);
    rank_.resize(size, 0);
    for (int i = 0; i < size; i++) {
      par_[i] = i;
      rank_[i] = 0;
    }
  }
  int root(int x) { return par_[x] == x ? x : par_[x] = root(par_[x]); }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return true;

    if (rank_[x] < rank_[y]) {
      par_[x] = y;
    } else {
      par_[y] = x;
      if (rank_[x] == rank_[y]) rank_[x]++;
    }
    return false;
  }
  bool same(int x, int y) { return root(x) == root(y); }
};

struct edge{
    int to;
    i64 cost;
};

i64 Kruskal(const vector<vector<edge>>& G){
    using P = pair<i64,pair<int,int>>;
    vector<P> edges;
    for(int i = 0;i < G.size();i++){
        for(auto & e : G[i]){
            edges.push_back({e.cost,{i,e.to}});
        }
    }

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

    UnionFind uf;
    uf.init(G.size());

    i64 res = 0;
    for(auto& p : edges){
        if(!uf.unite(p.second.first,p.second.second)){
          res += p.first;
        }
    }
    return res;
}

int main(){
  cin >> N;
  x.resize(N);
  y.resize(N);
  rep(i,0,N - 1){
    cin >> x[i] >> y[i];
  }

  vector<vector<edge>> G(N);
  {
    vector<pair<pair<int,int>,int>> vec;
    rep(i,0,N - 1) vec.push_back({{x[i],y[i]},i});
    sort(vec.begin(),vec.end());
    rep(i,0,N - 2){
      int a = vec[i].second;
      int b = vec[i + 1].second;
      G[a].push_back({b,abs(x[a] - x[b])});
      G[b].push_back({a,abs(x[a] - x[b])});
      G[a].push_back({b,abs(y[a] - y[b])});
      G[b].push_back({a,abs(y[a] - y[b])});
    }
  }
  {
    vector<pair<pair<int,int>,int>> vec;
    rep(i,0,N - 1) vec.push_back({{y[i],x[i]},i});
    sort(vec.begin(),vec.end());
    rep(i,0,N - 2){
      int a = vec[i].second;
      int b = vec[i + 1].second;
      G[a].push_back({b,abs(x[a] - x[b])});
      G[b].push_back({a,abs(x[a] - x[b])});
      G[a].push_back({b,abs(y[a] - y[b])});
      G[b].push_back({a,abs(y[a] - y[b])});
    }
  }

  cout << Kruskal(G) << endl; 
}

Measured memory_bytes: 40536
class Tree
	attr_accessor :parent, :root, :dep, :key, :left,:right, :sib
	def initialize(key)
		@parent = -1
		@left = -1
		@right = -1
		@dep = -1
		@key = key
		@sib = -1
	end

	def depth(ans,tree)
		if @left!=-1
			@left.depth(ans+1,tree)
		end
		
		if @right != -1
			@right.depth(ans+1,tree)
		end
		@dep = ans
	end

	def height(h)
		n1 = h
		n2 = h

		if @left!=-1
			n1 = left.height(h+1) 
		end

		if @right!=-1
			n2 = right.height(h+1)
		end

		return n1 > n2 ? n1:n2
	end

	def showparent
		if @parent==-1
			return -1
		else
			return @parent.key
		end
	end

	def showsib
		if @sib == -1
			return -1
		else
			return @sib.key
		end
	end

	def degree
		ans = 0
		if @left != -1
			ans+=1
		end
		if @right != -1
			ans+=1
		end
		ans
	end	
end




n = gets.to_i

tree = Hash.new
check = Array.new(n){true}
n.times do |i|
	tree[i] = Tree.new(i)
end

n.times do
	data = gets.split.map(&:to_i)
	num = data[0]
	tree[num].left = tree[data[1]]||-1
	tree[num].right = tree[data[2]]||-1
	if tree[data[1]]
		tree[data[1]].parent = tree[num]
		tree[data[1]].sib = tree[data[2]]||-1
		check[data[1]] = false
	end
	if tree[data[2]]
	tree[data[2]].parent = tree[num]
	tree[data[2]].sib = tree[data[1]]||-1
	check[data[2]] = false
    end
	
	
end
r = check.index(true)
tree[r].depth(0,tree)

n.times do |i|
	obj = tree[i]
	jd = nil
	if obj.parent == -1
		jd = "root"
	elsif obj.left == -1 && obj.right == -1
		jd = "leaf"
	else 
		jd = "internal node"
	end
	
	puts "node #{i}: parent = #{obj.showparent}, sibling = #{obj.showsib}, degree = #{obj.degree}, depth = #{obj.dep}, height = #{obj.height(0)}, #{jd}"
	
	
end

Measured memory_bytes: 8672
#include <bits/stdc++.h>
using namespace std;
const int MAX_X=1e5+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    vector<int> cnt(MAX_X,0);
    for (int i=0;i<N;++i){
        int X; cin >> X;
        ++cnt[X];
    }
    int ans=0;
    for (int i=0;2*i<=M;++i){
        int sum1=0,sum2=0,sum3=0,sum4=0;
        for (int j=i;j<MAX_X;j+=M){
            sum1+=cnt[j]; sum2+=cnt[j]&1;
        }
        if (2*i%M==0){ans+=sum1/2; continue;}
        for (int j=(M-i)%M;j<MAX_X;j+=M){
            sum3+=cnt[j]; sum4+=cnt[j]&1;
        }
        if (sum1<sum3) ans+=sum1+(sum3-max(sum1,sum4))/2;
        else ans+=sum3+(sum1-max(sum3,sum2))/2;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 640
#include <stdio.h>

using namespace std;

using ll = long long;

#define rep(i, n) for(int i = 0; i < n; i++)

class data {
public:
  ll n, k, s;
  data() : n(1), k(-1), s(0) {}
};

int dn;
data d[444444];

data unite(data a, data b) {
  data r;
  r.n = a.n + b.n;
  r.k = -1;
  r.s = a.s + b.s;
  return r;
}

void deley(int i) {
  if(d[i].k >= 0) {
    d[i * 2 + 1].k = d[i].k;
    d[i * 2 + 1].s = d[i * 2 + 1].n * d[i * 2 + 1].k;
    d[i * 2 + 2].k = d[i].k;
    d[i * 2 + 2].s = d[i * 2 + 2].n * d[i * 2 + 2].k;
  }
}

data init() {
  dn = 1;
  while(dn <= 111111) { dn *= 2; }
  for(int i = dn - 2; i >= 0; i--) {
    d[i] = unite(d[i * 2 + 1], d[i * 2 + 2]);
  }
}

void replace_(int p, int nb, int ne, int b, int e, ll x) {
  if(b <= nb && ne <= e) {
    d[p].k = x;
    d[p].s = d[p].n * d[p].k;
    return;
  }
  if(ne <= b || e <= nb) {
    return;
  }
  deley(p);
  int m = (nb + ne) / 2;
  replace_(p * 2 + 1, nb, m, b, e, x);
  replace_(p * 2 + 2, m, ne, b, e, x);
  d[p] = unite(d[p * 2 + 1], d[p * 2 + 2]);
}

void replace(int b, int e, ll x) {
  replace_(0, 0, dn, b, e, x);
}

ll sum_(int p, int nb, int ne, int e) {
  if(ne <= e) {
    return d[p].s;
  }
  if(e <= nb) {
    return 0;
  }
  deley(p);
  int m = (nb + ne) / 2;
  return sum_(p * 2 + 1, nb, m, e) + sum_(p * 2 + 2, m, ne, e);
}

ll sum(int e) {
  return sum_(0, 0, dn, e);
}

ll get(ll b, ll l) {
  return sum(l + 1) - sum(b);
}

int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  init();
  replace(0, 1, (ll)10000000000000000);
  rep(i, q) {
    ll t, k;
    scanf("%lld%lld", &t, &k);
    ll b = 1;
    ll e = t + 1;
    while(b < e - 1) {
      ll m = (b + e) / 2;
      if(get(m, t) + k <= get(m - 1, m - 1) * (t - m + 1)) {
        b = m;
      }
      else {
        e = m;
      }
    }
    ll q = get(b, t);
    ll r = get(b, b);
    ll a = k - ((t - b + 1) * r - q);
    replace(b, t + 1, r + a / (t - b + 1));
    replace(b, b + a % (t - b + 1), r + a / (t - b + 1) + 1);
  }
  rep(i, n) {
    printf("%lld\n", get(i + 1, i + 1));
  }
}


Measured memory_bytes: 11904
char=list(input())
cnt = 0
for i in range(len(char)):
    if ((i+1)%2==1 and char[i]=="R" )or ((i+1)%2==1 and char[i]=="U")or ((i+1)%2==1 and char[i]=="D"):
        cnt +=1
    elif (i%2==1 and char[i]=="L" )or (i%2==1 and char[i]=="U")or (i%2==1 and char[i]=="D"):
        cnt +=1
    else:
        cnt=0
        break

    

if cnt==0:
    print("No")
else:
    print("Yes")        

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int n,a,b,i,x=0,sum=0,k;
  scanf("%d%d%d",&n,&a,&b);
  for(i=1; i<=n; i++){
    k=i;
    x=0;
    while(k>0){
      x+=(k%10);
      k/=10;
    }
    if(x>=a && x<=b){
      // printf("%d\n",i);
      sum=sum+i;
    }
  }
  printf("%d\n",sum);
  return 0;


}


Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	int a = n / 100, b = n % 100;
	if (a > 12 || a == 0) {
		if (b > 12 || b == 0) {
			cout << "NA" << endl;
		}
		else {
			cout << "YYMM" << endl;
		}
	}
	else {
		if (b > 12 || b == 0) {
			cout << "MMYY" << endl;
		}
		else {
			cout << "AMBIGUOUS" << endl;
		}
	}
	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))
#define each(i, map) for (auto& i : map)

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

    int mod = N % 10;
    if (mod == 2 or mod == 4 or mod == 5 or mod == 7 or mod == 9)
        cout << "hon" << endl;
    else if (mod == 0 or mod == 1 or mod == 6 or mod == 8)
        cout << "pon" << endl;
    else
        cout << "bon" << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
   int n;cin >> n;
   vector<int>a(n);
   vector<int>b(1e6+5,0);
   bool ok = 0;bool s = 0;
   for(int i = 0;i<n;i++){
    cin >> a[i];b[a[i]]++;
   }
   for(int i = 2;i<=1e6;i++){
        int cnt = 0;
    for(int j = 1;j*i<=1e6;j++){
        cnt += b[i*j];
    }
   if(cnt>1) s=1;
   if(cnt==n) ok = 1;
   }
   if(ok) cout << "not coprime";
   else if(s) cout << "setwise coprime";
   else cout <<"pairwise coprime";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 11104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<ll> cnt(62,0);
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    
    for(int i=0;i<N;i++){
        for(int j=0;j<60;j++){
            if(A[i]&(1LL<<j)) cnt[j]++;
        }
    }
    
    ll sum=0;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<60;j++){
            if(A[i]&(1LL<<j)){
                sum+=ll(1LL<<j)%mod*ll(N-cnt[j]);
            }else{
                sum+=ll(1LL<<j)%mod*cnt[j];
            }
            sum%=mod;
        }
    }
    
    cout<<sum*rui(2,mod-2)%mod<<endl;
}



Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <cmath>

using namespace std;

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

	int x = sqrt(n);
	cout << x * x << endl;
	return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<long> price(N);
for(int i = 0; i < N; i++){
    cin >> price[i];
}
long maxp = price[1] - price[0];
long minp = price[0];
for(int i = 1; i < N; i++){
    maxp = max(maxp, price[i] - minp);
    minp = min(minp, price[i]);
}
cout << maxp << endl;
}


Measured memory_bytes: 4332
#include<iostream>

using namespace std;

void call(int n)
{
	int i = 1;

	while (i <= n)
	{
		int x = i;
		if (x % 3 == 0)
		{
			cout << " " << i;
		}
		else
		{
			while (x)
			{
				if (x % 10 == 3)
				{
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
		
		++i;
	}
	cout << endl;
}


int main()
{
	int num;

	cin >> num;

	call(num);

	return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include <iomanip>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
  double x1, x2, y1, y2, distance;

  cin >> x1 >> y1 >> x2 >> y2;

  distance = sqrt(pow(y1 - y2, 2) + pow(x1 - x2, 2));

  printf("%.5f\n",distance);
  return 0;
}

Measured memory_bytes: 1240
n,m,k = map(int,input().split())
mod =  998244353

## nCkのmodを求める関数
# テーブルを作る(前処理)
max = 3 * 10**5
fac, finv, inv = [0]*max, [0]*max, [0]*max

def comInit(max):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,max):
      fac[i] = fac[i-1]* i% mod
      inv[i] = mod - inv[mod%i] * (mod // i) % mod
      finv[i] = finv[i-1] * inv[i] % mod

comInit(max)

# 二項係数の計算
def com(n,k):
    if(n < k):
        return 0
    if( (n<0) | (k < 0)):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod


ans = 0
color = pow((m-1), (n-k-1), mod)
color = (color*m) % mod
for i in range(k,-1,-1):
    tmp = color * com(n-1, i)
    tmp %= mod
    ans += tmp
    color *= (m-1)
    color %= mod

ans %= mod
print(ans)

Measured memory_bytes: 77948
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


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

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始

int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i = 0; i < n; i++){
      cin>>a[i];
    }
    for(int i = 0; i < n; i++){
      cin>>b[i];
    }
    ll cnt1 = 0;
    ll cnt2 = 0;
    for(int i = 0; i < n; i++){
      cnt1+=max(0,a[i]-b[i]);
      cnt2+=max(0,(b[i]-a[i])/2);
    }
    if(cnt1<=cnt2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 384
h, w, m = map(int, input().split())
R = [0] * h
C = [0] * w
XY = [tuple(map(lambda x:int(x) - 1, input().split())) for i in range(m)]
for x, y in XY:
    R[x] += 1
    C[y] += 1
maxR, maxC = max(R), max(C)
cnt0 = R.count(maxR) * C.count(maxC)
cnt1 = sum(R[x] == maxR and C[y] == maxC for x, y in XY)
print(maxR + maxC - int(cnt0 == cnt1))


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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  rep(i, n) {
    if (a[i] > (ll)1e18 / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }

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


Measured memory_bytes: 4052
#include  <iostream>
using namespace std;
int main() {
  int n=0;
  int i=0;
  int a=0;
  cin >> n;
  if(n > 9){
    i+=9;
    if(n > 999){
      i+=900;
      if(n>99999){
        i+=90000;
      }else{
      a=n-9999;
      if(a<0) a=0;
      i+=a;
      }
    }else{
      a=n-99;
      if(a<0) a=0;
      i+=a;
    }
  }else{
    i=n;
  }
  cout << i;
  return 0;
}

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

int main(void) {
	int d[MAX], f[MAX];
	int n, u, k, v, i, j;
	vector<vector<int> > vec;
	vector<int> ve;
	vec.push_back(ve);
	cin >> n;
	for (i = 1; i <= n; i++) {
		ve.clear();
		d[i] = f[i] = 0;
		cin >> u >> k;
		ve.push_back(k);
		while (k--) {
			cin >> v;
			ve.push_back(v);
		}
		vec.push_back(ve);
	}
	stack<int> S_v, S_c;
	int Mytime = 1;
	int now, cnt;
	bool flag;
	for (i = 1; i <= n; i++) {
		if (d[i] != 0) continue;
		S_v.push(i);
		S_c.push(1);
		while (!S_v.empty()) {
			now = S_v.top();
			cnt = S_c.top();
			S_c.pop();
			flag = false;
			if (d[now] == 0) {
				d[now] = Mytime;
				Mytime++;
			}
			while(cnt <= vec[now][0]) {
				if (d[vec[now][cnt]] == 0) {
					flag = true;
					break;
				}
				cnt++;
			}
			if (flag) {
				S_v.push(vec[now][cnt]);
				S_c.push(cnt + 1);
				S_c.push(1);
				continue;
			}
			f[now] = Mytime;
			Mytime++;
			S_v.pop();
		}
	}
	for (i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
}


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

using namespace std;

long long n,m,k,l,i,j,a,b,mod=1000000007,d[20][20],dp[66666],val[66666];
string s;
vector<long long>v;

/*
long long pow(long long a,long long b){
    long long ret=0;
    for(long long j=b;j>0;j/=2){
        if(j%2==1) ret=(ret+a)%mod;
        a=(a*a)%mod;
    }
    return ret;
}

long long gay(long long a,long long b){
    return a*pow(b,mod-2);
}

long long countC(long long a,long long b){
    return gay(fact(a),(fact(b)*fact(a-b))%mod);
}
*/
main(){

cin>>n;

for(i=0;i<n;i++){
    for(j=0;j<n;j++){
        cin>>d[i][j];
    }
}

for(i=0;i<(1<<n);i++){
    v.clear();
    for(long long j=i,t=0;j>0;j/=2,t++){
        if(j&1) v.push_back(t);
    }
    for(long long j=0;j<v.size();j++){
        for(long long t=j+1;t<v.size();t++){
            val[i]+=d[v[j]][v[t]];
        }
    }
    dp[i]=val[i];
   // cout<<i<<" "<<val[i]<<endl;
}


for(i=1;i<(1<<n);i++){
    for(long long j=i&(i-1);j;j=(j-1)&i){
        dp[i]=max(dp[i],dp[j]+dp[i^j]);
    }
}

cout<<dp[(1<<n)-1];
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<int> x;
vector<int> y;
vector<int> nextx;
vector<int> nexty;
int w,h;
int count;
bool check(int a,int b){
  for (int i=0;i<nextx.size();i++){
    if (nextx[i]==a&&nexty[i]==b)
      return false;
  }
  return true;
}
int search(int **field){
  x.clear();
  y.clear();
  for (int i=0;i<nextx.size();i++){
    x.push_back(nextx[i]);
    y.push_back(nexty[i]);
  }
  nextx.clear();
  nexty.clear();
  for (int i=0;i<x.size();i++){
    field[x[i]][y[i]]=0;
    count++;
  }
  for (int i=0;i<x.size();i++){
    if (field[x[i]-1][y[i]]==1&&x[i]-1>=0&&check(x[i]-1,y[i])){
      nextx.push_back(x[i]-1);
      nexty.push_back(y[i]);
    }
    if (x[i]+1<h&&field[x[i]+1][y[i]]==1&&check(x[i]+1,y[i])){
      nextx.push_back(x[i]+1);
      nexty.push_back(y[i]);
    }
    if (field[x[i]][y[i]-1]==1&&y[i]-1>=0&&check(x[i],y[i]-1)){
      nextx.push_back(x[i]);
      nexty.push_back(y[i]-1);
    }
    if (field[x[i]][y[i]+1]==1&&y[i]+1<w&&check(x[i],y[i]+1)){
      nextx.push_back(x[i]);
      nexty.push_back(y[i]+1);
    }
  }
  if (nextx.empty()){
    return -1;
  }
  int *f[h];
  for (int i=0;i<h;i++)
    f[i]=field[i];
  return search(f);
}
int main(){
  string temp;
  while (cin>>w>>h,w|h!=0){
    count=0;
    int field[h][w];
    for (int i=0;i<h;i++){
      cin>>temp;
      for (int j=0;j<w;j++){
	if (temp[j]=='.')
	  field[i][j]=1;
	if (temp[j]=='#')
	  field[i][j]=0;
	if (temp[j]=='@'){
	  field[i][j]=1;
	  nextx.push_back(i);
	  nexty.push_back(j);
	}
      }
    }
    int *f[h];
    for (int i=0;i<h;i++)
      f[i]=field[i];
    search(f);
    cout<<count<<endl;
  }
}

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

int main()
{
    ll N, M, X;
    cin >> N >> M >> X;

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

    ll min = 1000000000;
    ll isTassei = 0;
    for (int tmp = 0; tmp < (1 << 12); tmp++)
    {
        bitset<12> s(tmp);
        ll cost = 0;
        vector<ll> sum(M);
        for (size_t i = 0; i < N; i++)
        {
            if (s[i] == 0)
            {
                continue;
            }

            cost += C[i];

            for (size_t j = 0; j < M; j++)
            {
                sum[j] += A[i][j];
            }
        }

        bool tassei = 1;
        for (size_t i = 0; i < M; i++)
        {
            if (sum[i] < X)
            {
                tassei = 0;
            }
        }

        if (tassei == 0)
        {
            continue;
        }
        else
        {
            isTassei = 1;
            if (cost < min)
            {
                min = cost;
            }
        }
    }
    if (isTassei == 1)
    {
        cout << min << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  ll h, w;
  cin >> h >> w;
  if(h==1){
    if(w==1){
      cout << 1 << endl;
    }else{
      cout << w-2 << endl;
    }
    return 0;
  }else if(w==1){
    cout << h-2 << endl;
    return 0;
  }
  ll ans = (h-2)*(w-2);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
 
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;

int main(){
    ll x,y;
    cin >> x >> y;
    if(4*x - y >= 0 && (4*x - y) % 2 == 0 && (x - ((4*x - y)/2) >= 0)) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3632
my $n = <STDIN>;
my $s = <STDIN>;

my @dat = split(/ /,$s);
#print "@dat\n";
#print "$#dat\n";
my $sum=0;

for(my $i=0;$i<=$#dat;$i++){
  #print "i$i\n";
  $sum = $sum + (1/$dat[$i]);
}

my $ans = 1/$sum ;

print "$ans";

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

int main() {
  int n,m,a,ac=0,wa=0;
  string b;
  cin >> n >> m;
  map<int, int> mp;
  map<int,int> mp2;
  r(i,n){
    mp[i+1]=0;
  }
  r(i,m){
    cin >> a >> b;
    if(mp[a]==0&&b=="AC"){
      ac++;	mp[a]++;
      wa+=mp2[a];
    }
    else if(mp[a]==0&&b=="WA")mp2[a]++;
  }
  cout<< ac << " " << wa << endl;
}

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

int main(){
    string s;
    cin >> s;

    int cnt[3] = {};
    for(char x : s) cnt[x-'a']++;
    sort(cnt, cnt+3);

    if(cnt[2]-cnt[0] <= 1)  cout << "YES" << endl;
    else                    cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 512
import itertools
abcd = list(map(int, input()))

case = ["+", "-"]
set_combination = list(itertools.product(case, repeat=3))

for x in set_combination:
    if x[0] == "+":
        sum_abcd = abcd[0] + abcd[1]
    else:
        sum_abcd = abcd[0] - abcd[1]
    if x[1] == "+":
        sum_abcd = sum_abcd + abcd[2]
    else:
        sum_abcd = sum_abcd - abcd[2]
    if x[2] == "+":
        sum_abcd = sum_abcd + abcd[3]
    else:
        sum_abcd = sum_abcd - abcd[3]

    if sum_abcd == 7:
        print("%d%s%d%s%d%s%d=7" % (abcd[0], x[0],
                                    abcd[1], x[1], abcd[2], x[2], abcd[3]))
        break


Measured memory_bytes: 38384
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
map<long long,int> mp;
int main()
{
	int n;
	cin>>n;
	long long ret=0,sum=0;
	mp[0]++;
	for(int i=0;i<n;i++)
	{
		long long a;
		cin>>a;
		sum+=a;
		ret+=mp[sum];
		mp[sum]++;
	}
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 12800
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
        ll n;
        cin>>n;
        string p="";
        string a,b;
        cin>>a>>b;
        for(int i=0;i<n;i++)
        {
          p+=a[i];
          p+=b[i];
        }
        cout<<p;
         

      }
      






}

Measured memory_bytes: 256
while True:
    H, W = list(map(int, input().split()))
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or i == H - 1:
                print('#', end="")
            elif j == 0 or j == W - 1:
                print('#', end="")
            else:
                print('.', end="")
        print()
    print()


Measured memory_bytes: 7004
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {

    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    // ll sum=0;

    rep(i,n){
        cin>>v[i];
        //sum+=v[i];
    }

    int ans=-INF;
    int lim=min(n,k);
    for(int l=0;l<=lim;l++){
        for(int r=0;r<=lim-l;r++){

            vector<int> te;
            int sum=0;

            for(int i=0;i<l;i++){
                sum+=v[i];
                if(v[i]<0) {
                    te.push_back(v[i]);
                }
            }
            for(int i=0;i<r;i++){
                sum+=v[n-i-1];
                if(v[n-i-1]<0) {
                    te.push_back(v[n - i - 1]);
                }
            }

            int a=k-(l+r);
            int b=te.size();
            sort(te.begin(),te.end());
            if(min(a,b)!=0) {
                for (int tt = 0; tt < min(a, b); tt++) {
                    /*if (te[tt] < 0) {
                        sum -= te[tt];
                        if (ans < sum) {
                            ans = sum;
                        }

                    } else { break; }*/
                    sum -= te[tt];
                    if (ans < sum) {
                        ans = sum;
                    }
                    //cout<<l<<" "<<r<<" "<<sum<<endl;

                }
            }else {
                if (ans < sum) {
                    ans = sum;
                }
            }




        }
    }

    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int q = sc.nextInt();

        boolean isHanten = false;

        Deque<String> deque = new ArrayDeque();
        for (char ch : s) {
            deque.addLast(String.valueOf(ch));
        }

        for (int i = 0; i < q; i++) {
            int f = sc.nextInt();
            if (f == 1) {
                isHanten = !isHanten;
            } else {
                int ff = sc.nextInt();
                if (isHanten) {
                    ff = 3 - ff;
                }
                if (ff == 1) {
                    deque.addFirst(sc.next());
                } else {
                    deque.addLast(sc.next());
                }
            }
        }

        if (isHanten) {
            while (!deque.isEmpty()) {
                System.out.print(deque.getLast());
                deque.pollLast();
            }
        } else {
            for (String str : deque) {
                System.out.print(str);
            }
        }
    }
}

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

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

    vector<string> ans(1);
    vector<string> alpha(26);
    for (int i = 0; i < 26; i++)
    {
        alpha[i] = 'a' + i;
    }

    int anssize = 0;
    int number = 0;

    for (int i = 0; n > 0; i++)
    {
        n--;
        anssize++;
        ans.resize(anssize + 1);
        ans[anssize] = alpha[n % 26];
        n = n / 26;
    }

    reverse(ans.begin(), ans.end());

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

Measured memory_bytes: 3652
package main

import (
  "fmt"
)

func makePair() map[byte]byte {
  acgt := []byte("ACGT")
  pair := make(map[byte]byte)
  for i := 0; i < 4; i++ {
    pair[acgt[i]] = acgt[3-i]
  }
  return pair
}

func main() {
  pair := makePair()
  var b string
  fmt.Scan(&b)
  fmt.Println(string(pair[[]byte(b)[0]]))
}

Measured memory_bytes: 512
def pn(x):
    res = ''
    if x > 0:
        res = 'Positive'
    elif x == 0:
        res = 'Zero'
    else:
        res = 'Negative'
    return res

a, b = map(int, input().split())

ans = ''
if a > 0:
    ans = pn(1)
elif a <= 0 <= b:
    ans = pn(0)
elif b < 0:
    if (b - a + 1) % 2 == 0:
        ans = pn(1)
    else:
        ans = pn(-1)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int n, m;
    cin >> n >> m;
    int s, c;
    bool flag = true;
    vector<int> v(4, -1);
    for (int i = 0; i < m; i++){
        cin >> s >> c;
        if (c == 0 && s == 1 && n != 1){
            flag = false;
        }
        else{
            if (v[s] >= 0 && v[s] != c){
                flag = false;
            }
            v[s] = c; 
        }
    }
    if (flag){
        for (int i = 1; i <= n; i++){
            if (v[i] < 0){
                if (i == 1 && n > 1) cout << "1";
                else cout << "0";
            }
            else{
                cout << v[i];
            }
        }
        cout << endl;
    }
    else cout << "-1" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

int main() {
  ll N, M;
  cin >> N >> M;
  vvi G(N);
  vvi H(N, vi(N));
  for (ll i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    G[a].push_back(b);
    H[a][b] = 1;
  }

  for (ll i = 0; i < N; i++) {
    vi prev(N, -1);
    queue<ll> q;
    q.push(i);
    while (q.size()) {
      ll fr = q.front();
      q.pop();
      for (ll to : G[fr]) {
        if (prev[to] == -1) {
          prev[to] = fr;
          q.push(to);
        }

        if (to == i) {
          vi route{to, fr};
          while (route.back() != i) {
            route.push_back(prev[route.back()]);
          }
          reverse(route.begin(), route.end());
          route.pop_back();
        hoge:
          for (ll i = 0; i < route.size(); i++) {
            for (ll j = 0; j < route.size(); j++) {
              if (i + 1 == j || (i == route.size() - 1 && j == 0)) continue;
              if (H[route[i]][route[j]]) {
                vi new_route{route[j], route[i]};
                while (new_route.back() != route[j]) {
                  new_route.push_back(prev[new_route.back()]);
                }
                reverse(new_route.begin(), new_route.end());
                new_route.pop_back();
                new_route.swap(route);
                goto hoge;
              }
            }
          }
          
          cout << route.size() << endl;
          for (ll i : route) {
            cout << i + 1 << endl;
          }
          return 0;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}



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

int main()
{
  int H, W;
  string S, UPP_S, LOW_S;
  
  cin >> H >> W >> S;
  for (int h = 0; h < H; h++)
  {
  	cin >> LOW_S;
    for (int i = 0; i < W; i++)
    {
      int n = 0;
      if (S.at(i) == '.')
      {
        if (h != 0)
        {
          if (i != 0 && UPP_S.at(i - 1) == '#')
            n++;
          if (UPP_S.at(i) == '#')
            n++;
          if (i != W - 1 && UPP_S.at(i + 1) == '#')
            n++;
        }
        if (i != 0 && S.at(i - 1) == '#')
          n++;
        if (i != W - 1 && S.at (i + 1) == '#')
          n++;
        if (h != H - 1)
        {
          if (i != 0 && LOW_S.at(i - 1) == '#')
            n++;
          if (LOW_S.at(i) == '#')
            n++;
          if (i != W - 1 && LOW_S.at(i + 1) == '#')
            n++;
        }
        cout << n;
      }
      else
        cout << '#';
    }
    cout << endl;
    UPP_S = S;
    S = LOW_S;
  }
}


Measured memory_bytes: 256
"use strict"

function Main(input) {
  input = input.trim().split('\n');
  const N = Number(input[0].trim().split(' ')[0]);
  const K = Number(input[0].trim().split(' ')[1]);
  const Q = Number(input[0].trim().split(' ')[2]);
  const A = input.slice(1, Q+1).join(' ').trim().split(' ').map(Number);
  const ary = new Array(N).fill(K)

  let ans = {};
  for(let i=0; i<Q; i++){
    ans[A[i]-1] = ans[A[i]-1] ? ans[A[i]-1] + 1 : 1;
  }

  const limit = Math.abs(K - Q);
  for(let i=0; i<N; i++){
    let tmp = 0;
    if(ans[i]){
      tmp = Q - ans[i];
    } else {
      tmp = Q;
    }

    if(K - tmp > 0){
      console.log('Yes');
    } else {
      console.log('No');
    }
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 47836
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long K, long long N, std::vector<long long> A){
  pri_queue<ll> x;
  ll n=0;
  for (int i = 0; i < N-1; i++) {
    x.push(abs(A[i] - A[i+1]));
    n += abs(A[i] - A[i+1]);
  }
  x.push(K-abs(A[0] - A[N-1]));
  n += K-abs(A[0] - A[N-1]);
  cout << n - x.top() << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, std::move(A));
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 2e9
using namespace std;
typedef long long ll;

class mint
{
  const ll mod = 1000000007;
  ll x;

public:
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const
  {
    return mint(-x);
  }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint &a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint &a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint &a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint &a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint &a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint &a) const
  {
    mint res(*this);
    return res /= a;
  }
  friend ostream &operator<<(ostream &os, const mint &m)
  {
    os << m.x;
    return os;
  }
};

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

  map<pair<ll, ll>, pair<ll, ll>> mp;
  ll z = 0;
  REP(i, n)
  {
    ll x, y;
    cin >> x >> y;

    if (x == 0 && y == 0)
    {
      z++;
      continue;
    }

    ll g = gcd(x, y);
    x /= g, y /= g;
    if (y < 0)
      x = -x, y = -y;
    if (y == 0 && x < 0)
      x = -x;

    if (x <= 0)
    {
      mp[{y, -x}].second++;
    }
    else
    {
      mp[{x, y}].first++;
    }
  }

  mint ans = 1;
  for (auto m : mp)
  {
    mint s = mint(2).pow(m.second.first) - 1;
    mint t = mint(2).pow(m.second.second) - 1;
    ans *= (s + t + 1);
  }
  ans -= 1;
  ans += z;

  cout << ans << endl;

  return 0;
}


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

int main() {
    int r, d, x;
    cin >> r >> d >> x;

    rep(i, 10) {
        x = r*x - d;
        cout << x << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
	int n;
	std::cin >> n;
	
	if (n < 3)
		std::cout << 0 << std::endl;
	else if (n % 2 == 0)
		std::cout << n / 2 - 1 << std::endl;
	else
		std::cout << n / 2 << std::endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		if((c+b-1)/b>(a+d-1)/d){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 35820
#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
using namespace std;
int main() {
	string s;
	cin >> s;
	int count1 = 0;
	int count2 = 0;
	int count3 = 0;
	int count4 = 0;

	for (int i = 0; i < 4; i++) {
		if (s[0] == s[i]) count1++;
		if (s[1] == s[i])count2++;
		if (s[2] == s[i])count3++;
		if (s[3] == s[i])count4++;

	}
	if (count1 == 2 && count2 == 2 && count3==2 && count4==2)cout << "Yes";
	else cout << "No";
}

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

int main(){
    int a, b, c, k, ans=0;
    
    cin >> a >> b >> c >> k;

    if(k>=a){
        ans += a;
        k = k - a;
    }
    else{
        ans += k;
        k = 0;
    }

    if(k!=0 && k>=b){
        k = k - b;
    }
    else{
        k = 0;
    }

    if(k!=0 && k>=c){
        ans -= c;
        k = k - c;
    }
    else{
        ans -= k;
        k = 0;
    }

    cout << ans;

}

Measured memory_bytes: 3164
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
private:
  int siz;
  vector<int> a;

public:
  UnionFind(int x) : a(x, -1) {}

  int root(int x) {
    return a[x] < 0 ? x : a[x] = root(a[x]);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    siz--;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] =x;
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -a[root(x)];
  }
};
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }
  vector<long long> ans;
  ans.push_back(1LL * n * (n - 1) / 2);
  UnionFind u(n);
  for (int i = m - 1; i > 0; i--) {
    ans.push_back(ans.back());
    if (u.same(a[i], b[i])) continue;
    *prev(ans.end()) -= 1LL * u.size(a[i]) * u.size(b[i]);
    u.unite(a[i], b[i]);
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
  return 0;	  
}

Measured memory_bytes: 3444
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	char x[1201];
	char a;
	int j=0;
	while(1){
		a=getchar();
		if(a!=32&&a<32||a>125)break;
		else{
			if(a>=65&&a<=90){
				x[j]=a+32;
			}
			else if(a>=97&&a<=122){
				x[j]=a-32;
			}
			else{
				x[j]=a;
			}
			j++;
		}
	}
	for(int i=0;i<=j-1;i++){
		cout<<x[i];
	}
	cout<<endl;
}

Measured memory_bytes: 3084
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int, int> P;

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


long nCr(int n,int r) {
	long ans = 1;
	for (int i = n; i > n - r; i--) {
		ans *= i;
	}
	for (int i = 1; i <= r; i++) {
		ans /= i;
	}
	return ans;
}

int n;
long long c[200002];
int main() {
	cin >> n;
	c[0] = 0;
	map<long long, int>mp;
	mp[c[0]]++;
	for (int i = 0; i < n; i++) {
		long long a;
		cin >> a;
		c[i + 1] = c[i] + a;
		mp[c[i + 1]]++;
	}
	long long ans = 0;
	for (auto a : mp) {
		long long p = a.second;
		if (p >= 2) {
			ans += nCr(p, 2);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 14336