akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
const long long llinf=9223372036854775807ll;
const int N=100005;
int a[N][3],ma[N],ans[N],bfs[N];
vector<int> g[N];
void go(int in[])
{
	int x=in[0]-1,dd=in[1],v=in[2];
	if(dd<ma[x])
		return ;
	ma[x]=dd;
	bfs[0]=x;
	int rr=1;
	for(int i=0;i<rr;i++)
	{
		int x=bfs[i];
		if(!ans[x])
			ans[x]=v;
		if(!ma[x])
			continue;
		for(int i=0;i<g[x].size();i++)
		{
			int y=g[x][i];
			int nd=ma[x]-1;
			if(nd>ma[y])
			{
				ma[y]=nd;
				bfs[rr++]=y;
			}
		}
	}
}
int n,m,q,x,y;
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		x--,y--;
		g[x].push_back(y);
		g[y].push_back(x);  
	}
	cin>>q;
	for(int i=0;i<q;i++)
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	for(int i=0;i<N;i++)
		ma[i]=-1;
	for(int i=q;i>=0;i--)
		go(a[i]);
	for(int i=0;i<n;i++)
		cout<<ans[i]<<'\n';
	return 0;
}

Measured memory_bytes: 8824
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ld long double
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

struct node{int t,x,y;};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vector<node> a(n+1);
    a[0].t=a[0].x=a[0].y=0;
    rep(i,n) cin >> a[i+1].t >> a[i+1].x >> a[i+1].y;
    FOR(i,0,n){
        int t=a[i+1].t-a[i].t;
        int d=abs(a[i+1].x-a[i].x)+abs(a[i+1].y-a[i].y);
        if(t<d || (t%2!=d%2)){
            coutn;
            return 0;
        }
    }
    couty;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    string s;
    int i;

    cin >> s;

    for(i=0; i<s.size(); i++){
        if(i < s.size() - 8){
            cout << s[i];
        }
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  //vector<int> A(M,0);
  int days = 0;

  int result = -1;

  for(int i=0; i < M ;i++){
    int tmp;
    cin >> tmp;
    days += tmp;
  }
  if(days > N){
    cout << result << endl;
  }else{
    cout << (N-days) << endl;
  }
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n;
    ll k;
    cin >> n >> k;
    ll a[2005];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll c1 = 0;
    ll c2 = 0;
    for (int i = 0; i < n - 1; i++){
        for (int j = i + 1; j < n; j++){
            if (a[i] > a[j]) c1++;
        }
    }
    
    for (int i = 0; i < n;i++){
        for (int g = 0; g < n;g++){
            if (a[i] > a[g]) c2++;
        }
    }
    ll c = 1000000007;
    cout << ((c1*k) + (((k*(k-1)/2%c*c2))))%c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int n; cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
    return 0;
  }

  int a, b; cin >> a >> b;
  cout << a+b << endl;
}

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

int main() {
	int a[102][102];
	int b[102][102];

	int n, m, l;
	cin >> n >> m >> l;

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

	for (int i = 0; i < m; ++i) {
		for (int i2 = 0; i2 < l; ++i2) {
			cin >> b[i][i2];
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < l; ++j) {
			long long int c = 0;
			for (int k = 0; k < m; ++k) {
				c += a[i][k] * b[k][j];
			}
			cout << c;
			if (j < l - 1) {
				cout << ' ';
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3156
import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.ArrayBuffer

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val M = sc.nextInt()

    val p = Array.fill[Int](N)(sc.nextInt() - 1)
    val reverse = Array.ofDim[Int](N)
    (0 until N) foreach { i =>
      reverse(p(i)) = i
    }

    val uf = new UnionFind(N)
    (0 until M) foreach { _ =>
      uf.unite(sc.nextInt() - 1, sc.nextInt() - 1)
    }

    val ans = (0 until N) count { i =>
      uf.find(i) == uf.find(reverse(i))
    }

    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  class UnionFind(n: Int) {
    private val par = Array.iterate(0, n)(_ + 1)
    private val rank = Array.ofDim[Int](n)

    def find(x: Int): Int = {
      if (par(x) == x) x
      else {
        par(x) = find(par(x))
        par(x)
      }
    }

    def unite(x: Int, y: Int): Unit = {
      val x1 = find(x)
      val y1 = find(y)
      if (x1 != y1) {
        if (rank(x1) < rank(y)) {
          par(x1) = y1
        } else {
          par(y1) = x1
          if (rank(x1) == rank(y1)) rank(x1) += 1
        }
      }
    }
  }
}


Measured memory_bytes: 45640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    ll n; cin>>n;
    unordered_map<string, int> s;
    ll ans = 0;
    for(int i=0; i<n; i++){
        string tmp; cin>>tmp;
        sort(ALL(tmp));
        auto itr = s.find(tmp);
        if(itr != s.end()){
            ans += itr->second;
        }
        s[tmp]++;
    }
    OUT(ans);
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <typename T> inline void print(T val) { cout << val << '\n'; }

template <typename Iterator> inline void print(Iterator begin, Iterator end) {
  for (auto it = begin; it != end; it = next(it)) {
    cout << *it << ' ';
  }
  cout << '\n';
}

template <class T> inline T square(T x) {
  T result;
  result = x * x;
  return result;
};

#ifdef LOCAL
#define DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) 0
#endif

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

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

  auto start = chrono::steady_clock::now();
#endif

  int n;
  cin >> n;
  set<string> s;

  for (auto i = 0; i < n; ++i) {
    string a;
    cin >> a;
    s.insert(a);
  }

  print(s.size());

#ifdef LOCAL
  auto end = chrono::steady_clock::now();
  auto diff = end - start;

  cout << "Duration: " << chrono::duration<double, milli>(diff).count() << " ms"
       << '\n';
#endif

  return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end(), greater<int>());
    vector<int> B(N); for (int i = 0; i < N; i++) cin >> B[i];
    sort(B.begin(), B.end(), greater<int>());
    vector<int> C(N); for (int i = 0; i < N; i++) cin >> C[i];
    sort(C.begin(), C.end(), greater<int>());
    vector<int> BgA(N);
    for (int i = 0; i < N; i++) {
        if (A[i] >= B[0]) {
            BgA[i] = -1;
        } else {
            int ok = 0, ng = N;
            while (ng - ok != 1) {
                int med = (ng + ok) / 2;
                if (A[i] < B[med]) {
                    ok = med;
                } else {
                    ng = med;
                }
            }
            BgA[i] = ok;
        }
    }
    vector<int> CgB(N);
    for (int i = 0; i < N; i++) {
        if (B[i] >= C[0]) {
            CgB[i] = -1;
        } else {
            int ok = 0, ng = N;
            while (ng - ok != 1) {
                int med = (ng + ok) / 2;
                if (B[i] < C[med]) {
                    ok = med;
                } else {
                    ng = med;
                }
            }
            CgB[i] = ok;
        }
    }
    vector<ll> cuCgB(N); cuCgB[0] = CgB[0] + 1;
    for (int i = 1; i < N; i++) cuCgB[i] = cuCgB[i-1] + CgB[i] + 1;
    ll ans = 0;
    for (int i = 0; i < N; i++) if (BgA[i] != -1) ans += cuCgB[BgA[i]];
    cout << ans << endl;
}


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

int main(void){
	int N;
	cin >> N;
	vector<pair<ll,int>> v;
	ll x[N], y[N];
	rep(i,N) {
		int p, q;
		cin >> p >> q;
		x[i] = (ll)(p+q);
		y[i] = (ll)(p-q);
	}
	sort(x, x+N);
	sort(y, y+N);
	ll ans = x[N-1] - x[0];
	ans = max(ans, y[N-1] - y[0]);
	cout << ans << endl;
return 0;
}


Measured memory_bytes: 6752
#include<bits/stdc++.h>
using namespace std;
long long a,b,n,t;
int main(){
	cin>>a>>b;
	n=a*b;
	t=a;
	if(a<b){
		a=b;
		b=t;
		t=a;
	}
	t=a%b;
	while(t){
		a=b;
		b=t;
		t=a%b;
	}
	cout<<n/b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int n,m;
char grid[1009][1009];
int vis[1009][1009];
ll num[1009][1009];
ll dp(int x,int y){
    if(x==n&&y==m)return 1;
    if(x>n||y>m||grid[x][y]=='#')return 0;
    if(vis[x][y])return num[x][y];
    vis[x][y]=1;
//    num[x][y]=(num[x][y]+dp(x,y+1))%mod;
//    num[x][y]=(num[x][y]+dp(x+1,y))%mod;
    num[x][y]=(dp(x,y+1)%mod+dp(x+1,y)%mod)%mod;
    return num[x][y]%mod;
}
int main()
{
  //  ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        scanf("%s",grid[i]+1);
    cout<<dp(1,1)%mod<<endl;
    return 0;
}


Measured memory_bytes: 13312
l=[]
s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
s = s.replace(' ','')
l = s.split(',')
k = input()
print(l[int(k)-1])

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n; cin >> n;
    char c[n];
    rep(i,n) cin >> c[i];
    vector<int> w(n+1), r(n+1);
    rep(i,n){
        w[i+1] = w[i];
        if(c[i] == 'W') w[i+1]++;
        r[i+1] = r[i];
        if(c[i] == 'R') r[i+1]++;

    }
    if(r[n] == n || w[n] == n){
        cout << 0 << endl;
        return 0;
    }

    int ans = 1e9;
    rep(i,n+1){
        int tmp = 0;
        tmp = max(w[i], r[n] - r[i]);
        chmin(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5036
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let s = scan!();
    let (mut num0, mut num1) = (0, 0);
    for c in s.chars() {
        if c == '0' {
            num0 += 1
        } else {
            num1 += 1
        }
    }
    println!("{}", min(num0, num1) * 2)
}


Measured memory_bytes: 4352
//https://codeforces.com/blog/entry/64250?#comment-576206

#include<bits/stdc++.h>
#define ll double

ll dp[301][301][301];
ll solve(int one, int two, int three, int& n)
{
    if(one < 0 || two < 0 || three < 0)
        return 0;
    if(three == 0 && two == 0 && one == 0)
        return 0;
 
    if(dp[one][two][three] > 0)
        return dp[one][two][three];
 
    int remaining = one + two + three;
    ll exp_val = n + one * solve(one - 1, two, three, n) 
                   + two * solve(one + 1,two - 1, three, n) 
                   + three * solve(one, two + 1, three - 1, n);
 
    return dp[one][two][three] = exp_val / remaining;
}
 
int main()
{
    using namespace std;
    int n;
   
    cin >> n;
  
    int one = 0, two = 0, three = 0;

    for(int i = 0; i < n; i++) {
      int x;
      cin >> x;
      if(x == 1) one++;
      else if(x == 2) two++;
      else three++;
    }

    memset(dp, -1, sizeof(dp));
   
    cout << fixed << setprecision(9) << solve(one, two, three, n);
    
    return 0;
}


Measured memory_bytes: 216900
n, x = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

ans = 0
(n-1).times do |i|
  sum = a[i] + a[i+1]
  if sum > x
    t = sum - x # 超過分
    if a[i+1] >= t
      a[i+1] -= t
    else
      a[i] -= (t - a[i+1])
      a[i+1] = 0
    end
    ans += t
  end
end
p ans


Measured memory_bytes: 9604
#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 N; cin >> N;
    vector <pair<int,int>> A(N);
    rep(i,N){
        int a;cin >> a;
        A[i]=make_pair(a,i+1);
    }
    sort(A.begin(),A.end());
    rep(i,N) cout << A[i].second  << " " ;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  cout<<fixed<<setprecision(10);
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i=0; i<N; ++i)cin >> A[i];
  B = A;
  sort(B.begin(),B.end());
  for(int i=0; i<N; ++i){
    if(A[i]!=B[N-1]) cout << B[N-1] << endl;
    else cout << B[N-2] << endl;
  }
}


Measured memory_bytes: 3200
#include<iostream>
using namespace std;
int a[100001];
long long ans=0;
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=i+1;j<=n;++j)
		{
			ans+=a[i]*a[j];
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int interviewNum = sc.nextInt();
		int foodNum = sc.nextInt();
		int[] foods = new int[foodNum];
		for(int i = 0; i < foodNum; i++)foods[i] = 0;

		for(int i = 0; i < interviewNum; i++){
			int likeNum = sc.nextInt();
			for(int j = 0; j < likeNum; j++){
				int likeId = sc.nextInt();
				foods[likeId-1]++;
			}
		}

		int ans = 0;
		for(int i : foods){
			if(i == interviewNum)ans++;
		}

		System.out.println(ans);
	}
}




Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int j,k;
		int maxv = -1000000000;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int R[] = new int[n];
		for(j=0;j<n;j++)R[j] = Integer.parseInt(sc.next());
		int minv = R[0];

			for(k=1;k<n;k++){
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				}
			System.out.println(maxv);
	}

}

Measured memory_bytes: 72048
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        w: [i32; n],
    }
    let mut a = 0;
    let mut b: i32 = w.iter().sum();
    let mut mi = b;
    for i in 0..n {
        a += w[i];
        b -= w[i];
        mi = min(mi, (a - b).abs());
    }
    puts!("{}\n", mi);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
using namespace std;
signed main()
{
    fast;
    
    int n,m,i;
    cin>>n>>m;
    string s;
    cin>>s;
    vector<int> ans;
    bool ok = true;
    for(i=s.length()-1;i>=0;)
    {
    	int ba = max(0,i-m), turn = (i-ba);
    	if(i==0) break;
    	if(s[ba]=='0')
    	{
    		i = ba;
    		ans.pb(turn);
    	}
    	else
    	{
    		while(s[ba]=='1' and ba<i)
    		{
    			ba++;
    			turn--;
    		}
    		if(s[ba]=='1' or ba==i)
    		{
    			ok = false;
    			break;
    		}
    		i = ba;
    		ans.pb(turn);
    	}
    }
    reverse(all(ans));
    if(ok) for(auto u:ans) cout<<u<<" ";
    else cout<<"-1";
}

Measured memory_bytes: 1096
'use strict';
(function(stdin) {
  //declare function

  //declare variable
  var inputs = stdin.toString().trim().split(' ').map(Number);
  //main
  if (inputs[0] >= inputs[2] + inputs[4]) {
    if (inputs[1] >= inputs[3] + inputs[4]) {
      if (0 <= inputs[2] - inputs[4]) {
        if (0 <= inputs[3] - inputs[4]) {
          console.log('Yes');
          return;
        }
      }
    }
  }
  console.log('No');
  //display
  //console.log(inputs);
})(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 15600
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline bool read(ll &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
char c[yuzu|10];

int main(){
scanf("%s",c+1);
int len=strlen(c+1),i;
int cnt1=0;
for (i=2;i<=len;++i){
  cnt1+=c[i]!=c[i-1];
  }
int cnt2=0;
for (i=len-1;i;--i) cnt2+=c[i]!=c[i+1];
write(min(cnt1,cnt2));
}

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

using namespace std;

#define bug(x) cerr << #x << " = " << x << '\n'
#define ll     long long
#define maxn

int main() {
        //freopen(".inp","r",stdin);

        int n;
        cin >> n;

        vector<int> l(n);
        for(int i = 0; i < n; ++ i)
            cin >> l[i];

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

        int ret = 0;
        for(int i = 0; i < n; ++ i)
            for(int j = i+1; j < n; ++ j)
                for(int z = j+1; z < n; ++ z) {
                    if(l[i] == l[j] || l[j] == l[z] || l[z] == l[i]) continue;
                    if(l[i] + l[j] > l[z]) ret ++;
                }
        cout << ret;
}



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

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

    ll ans = 0;
    for (ll i = 1; i <= N; i++){
        if (i % 3 != 0 && i % 5 != 0) ans += i;
    }

    cout << ans << endl;
    
}

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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(X) X.begin(), X.end()
#define sz(X) (int)X.size()

using ll = long long;

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

// xz

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

    vector a(1 << n, 0);
    for (int i = 0; i < (1 << n); ++i) cin >> a[i];

    vector S(1 << n, pair(0, 0));
    for (int i = 0; i < (1 << n); ++i)
        S[i].first = a[i];

    auto insert = [](pair<int, int>& S, pair<int, int> T)
    {
        int x = T.first, y = T.second;

        if (x > S.second) S.second = x;
        if (S.first < S.second) swap(S.first, S.second);

        if (y > S.second) S.second = y;
        if (S.first < S.second) swap(S.first, S.second);
    };

    for (int k = 0; k < n; ++k)
        for (int x = 0; x < (1 << n); ++x)
            if ((x >> k & 1) == 0) insert(S[x | (1 << k)], S[x]);

    int ans = 0;
    for (int i = 1; i < (1 << n); ++i)
    {
        ans = max(ans, S[i].first + S[i].second);
        cout << ans << endl;
    }

    exit(0);
}



Measured memory_bytes: 6688
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
const int N = 2e5 + 1;
//ll int freq[100001];
ll int bigPower(ll int x, unsigned ll int y, ll int p)
{
    ll int res = 1;     // Initialize result

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

    if (x == 0) return 0; // In case x is divisible by 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;
}
void findAns()
{

    string s;
    cin >> s;
    string t;
    cin >> t;

    bool ok = true;
    for (int i = 0; i < s.size(); i++) if (s[i] != t[i]) ok = false;

    if (!ok or t.size() != s.size() + 1) cout << "No";
    else
        cout << "Yes";


}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("o1.txt", "w", stdout);
// #endif

    fastio;

        findAns();
}

Measured memory_bytes: 3564
x,y = list(map(int,input().split()))
if y%2==0:
	y = y//2
	t = y-x
	c = x-t
	if c>=0 and t>=0 and c+t==x and c+2*t==y:
		print("Yes")
	else:
		print("No")
else:
	print("No")

Measured memory_bytes: 9188
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef pair<int, int> P;

vector<P> way[32];
int def, poal;
int n;

int mini(int s, int g, int money, int spend = 0);

int main()
{
	int m;
	
	scanf("%d", &n);
	scanf("%d", &m);
	for (int i = 0; i < m; i++){
		int a, b, c, d;
		
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		way[a].push_back(P(c, b));
		way[b].push_back(P(d, a));
	}
	int s, g;
	scanf("%d,%d,%d,%d", &s, &g, &def, &poal);
	
	printf("%d\n", mini(g, s, mini(s, g, def, poal)));
}

int mini(int s, int g, int money, int spend)
{
	priority_queue<P, vector<P>, greater<P> > q;
	int dijkstra[32];
	
	for (int i = 0; i <= n; i++) dijkstra[i] = 1000000000;
	q.push(P(0, s));
	dijkstra[s] = 0;
	while (!q.empty()){
		P p = q.top(); q.pop();
		
		if (dijkstra[p.second] < p.first) continue;
		for (int i = 0; i < way[p.second].size(); i++){
			P edge = way[p.second][i];
			
			if (dijkstra[edge.second] > dijkstra[p.second] + edge.first){
				dijkstra[edge.second] = dijkstra[p.second] + edge.first;
				q.push(P(dijkstra[edge.second], edge.second));
			}
		}
	}
	return money - dijkstra[g] - spend;
}

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

using namespace std;

typedef long long ll;

map<ll,int> m;
ll pref = 0, x, tot = 0;
int N;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	m[0] = 1;
	for (int i = 1; i <= N; ++i){
		cin >> x;
		pref += x;
		if (m.find(pref) == m.end()){
			m[pref] = 0;
		}
		tot += m[pref];
		m[pref]++;
	}
	cout << tot << '\n';
	cout << flush;
	//for (int i = 0; i < 1e9; ++i){for (int j = 0; j < 1e9; ++j){}}
}

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

int main(){
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> reizouko;
  vector<int> renji;
  int cheapestReizouko = 1000000;
  int cheapestRenji = 1000000;
  int smallest = 1000000;
  for(int i=0; i<a; i++){
    int num;
    cin >> num;
    cheapestReizouko = min(cheapestReizouko, num);
    reizouko.push_back(num);
  }
  for(int i=0; i<b; i++){
    int num;
    cin >> num;
    cheapestRenji = min(cheapestRenji, num);
    renji.push_back(num);
  }
  for(int i=0; i<m; i++){
    int x, y, c;
    cin >> x >> y >> c;
    int sum = reizouko[x-1] + renji[y-1] - c;
    smallest = min(smallest, sum);
  }
  cout << min(smallest, cheapestReizouko+ cheapestRenji) << endl;
  return 0;
}
  
  

Measured memory_bytes: 1400
import java.util.*;

public class Main {

    /* チェックリスト
     * SNSに結果を書き込むときはACかWAかのみ(半分だけACとかは書かないこと)
     * 結果はintの範囲を超えていませんか？(必要な時以外はlongを使いましょう)
     * TLEしそうな処理はありませんか？
     */
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = Integer.parseInt(s.nextLine());
        //String[] in = s.nextLine().split(" ");
        int r = 0;
        for(int i = 1;i<=n;i++){
            String str = String.valueOf(i);
            if(str.length() % 2 != 0){
                r++;
            }
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 27732
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long a,b,c,d,e,f,g;
    string arr,brr;
    cin>>arr>>brr;

  if(arr.compare(brr)==0)
  {
      cout<<"EQUAL";
  }
  else if(arr.length()>brr.length())
  {
      cout<<"GREATER";
  }
   else if(arr.length()<brr.length())
  {
      cout<<"LESS";
  }
  else
  {
      if(arr.compare(brr)>0)
        cout<<"GREATER";
      else cout<<"LESS";
  }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define rd(a) cin>>(a)
#define RD(a,b) cin>>(a)>>(b)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

bool b[51][51];
int n,m;
bool ck;
string s[51];

int dfs(int nx, int ny,char c) {
  b[nx][ny]=true;
  int cnt=0;
  rep(i,4) {
    int x=nx+dx[i],y=ny+dy[i];
    if(check(n,m,x,y) && !b[x][y]) {
      if(s[x][y]=='.') cnt+=dfs(x,y,c);
      else if(s[x][y]!=c) ck=false;
    }
  }
  return cnt+1;
}

int main() {
  while(cin >> m >> n && n) {
    rep(i,n) cin >> s[i];
    memset(b,false,sizeof(b));
    int p=0,q=0;
    rep(i,n) {
      rep(j,m) {
	if(s[i][j]=='.') continue;
	rep(k,4) {
	  ck=true;
	  int x=i+dx[k],y=j+dy[k];
	  if(check(n,m,x,y) && !b[x][y] && s[x][y]=='.') {
	    if(s[i][j]=='W') {
	      int z=dfs(x,y,'W');
	      if(ck) q+=z;
	    } else {
	      int z=dfs(x,y,'B');
	      if(ck) p+=z;
	    }
	  }
	}
      }
    }
    PR(p,q);
  }
  return 0;
}


Measured memory_bytes: 1348
/// Codeforces - ishibly
#include "bits/stdc++.h"

using namespace std;

int main() {
	string s;
	cin >> s;
	int n = s.size();

	int cnt = 0;
	for (char c : s) if (c == 'o') cnt ++;
	if (cnt + 15 - n >= 8) puts("YES");	
	else puts("NO");
}

Measured memory_bytes: 256
// Java program For handling Input/Output 
import java.io.*;
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main {
    BufferedReader br;
    StringTokenizer st;

    int max = -1;
    final long P = 998244353;

    HashSet<String> set = new HashSet<>();
    HashMap<Integer, Integer> map = new HashMap<>();

    // actual logic
    void solve() throws IOException {
        int n = ni();
        long a[] = new long[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = nl();
            sum ^= a[i];
        }

        for (int i = 0; i < n; i++) {
            sum ^= a[i];
            System.out.print(sum + " ");
            sum ^= a[i];
        }

    }

    // constructor
    Main() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                System.out.println(e);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    Main(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
            st = new StringTokenizer(br.readLine());
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    // main metohd
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    // Utility methods

    String ns() {
        if (!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                System.out.println(e);
            }
        }
        return st.nextToken();

    }

    int ni() {
        return Integer.parseInt(ns());
    }

    long nl() {
        return Long.parseLong(ns());
    }

    double nd() {
        return Double.parseDouble(ns());
    }

    void pl(String s) {
        System.out.println(s);
    }

    void pl(long s) {
        System.out.println(s);
    }
}


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

int main(){
  int n,l;
  cin>>n>>l;
  string a[n];
  
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  
  sort(a,a+n);
  
  for(int i=0;i<n;i++){
     cout<<a[i];
  }
}
  


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)

N = int(input())

edges = [[] for i in range(N+1)]
color = [0 for i in range(N-1)]

for i in range(N-1):
    a, b = map(int,input().split())
    edges[a].append([b,i])
    edges[b].append([a,i])

root = -1
MAX = 0

for i in range(N+1):
    if MAX < len(edges[i]):
        root = i
        MAX = len(edges[i])

K = MAX

def dfs(parent,v,c):
    flag = 0
    for i in range(len(edges[v])):
        if edges[v][i][0] == parent:
            flag = 1
        else:
            color[edges[v][i][1]] = (c+i+1-flag)%K
            dfs(v,edges[v][i][0],(c+i+1-flag)%K)

dfs(-1,root,0)

print(K)

for i in color:
    if i == 0:
        print(K)
    else:
        print(i)

Measured memory_bytes: 77936
n, m = map(int, input().split())
L = []
R = []
for i in range(m):
	l,r = map(int,input().split())
	L.append(l)
	R.append(r)
if min(R)-max(L)+1 >0:
	print(min(R)-max(L)+1)
else:
	print(0)

Measured memory_bytes: 11052
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
D=[i-j for i,j in zip(a,b)]
c=[i for i in D if i>0]
c.sort()
d=[i for i in D if i<0]

e=sum(d)
if sum(a)<sum(b):
    print(-1)
elif len(d)==0:
    print(0)
else:
    ans=0
    for i in c[::-1]:
        ans+=1
        e+=i
        if e>=0:
            print(ans+len(d))
            exit()

Measured memory_bytes: 19188
#include <iostream>
#include <string>
#define llint long long
#define mod 998244353

using namespace std;

string s;
llint dp[200005][3][4];

int main(void)
{
	cin >> s;
	
	bool flag = true;
	for(int i = 0; i < s.size(); i++){
		if(s[i] != s[0]){
			flag = false;
			break;
		}
	}
	if(flag){
		cout << 1 << endl;
		return 0;
	}
	if(s.size() <= 2){
		cout << 2 << endl;
		return 0;
	}
	
	llint sum = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'b') sum++;
		if(s[i] == 'c') sum+= 2;
	}
	sum %= 3;
	if(sum == 0 && s.size() == 3){
		cout << 3 << endl;
		return 0;
	}
	
	llint ans = 0; flag = false;
	for(int i = 1; i < s.size(); i++){
		if(s[i-1] == s[i]){
			flag = true;
			break;
		}
	}
	if(!flag) ans++;
	
	dp[0][0][0] = 1;
	for(int i = 0; i < s.size(); i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 4; k++){
				for(int l = 0; l < 3; l++){
					int kk = l;
					if(k == 3 || (i != 0 && k == l)) kk = 3;
					dp[i+1][(j+l)%3][kk] += dp[i][j][k];
					dp[i+1][(j+l)%3][kk] %= mod;
				}
			}
		}
	}
	
	ans += dp[s.size()][sum][3];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 19332
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<iostream>
#include<queue>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
LL a;
int main(){
	cin >> a;
	if(a<7){
		puts("1");
		return 0;
		}
	if(a<11){
		puts("2");
		return 0;
		}
	if(!(a%11))
	cout << a / 11 * 2<< endl;
	else {
		if(a%11<7)
		cout << a / 11 * 2 + 1 << endl;
		else cout << a / 11 * 2 + 2 << endl;
	}
	return 0;
	}

Measured memory_bytes: 256
def insertionSort(A,N):
  for i in range(N):
      j = i
      while (j > 0) and (A[j-1] > A[j]) :
          tmp = A[j-1]
          A[j-1] = A[j]
          A[j] = tmp
          j -= 1
      print(' '.join(map(str, A)))
  
N = input()
N = int(N)
A = input()
A = list(map(int, A.split()))
insertionSort(A,N)


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

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

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

#define fo(i, n) for(i = 0; i < n; i++)
#define of(i, n) for(i = n - 1; i >= 0; i--)
#define ll long long

bool com1(int a, int b)
{
    return (a < b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
	cin>>n;
	cin>>m;
	ll s[m],c[m];
	for (int i = 1; i <= m; ++i)
	{
		cin>>s[i]>>c[i];
	}
	map <ll,ll> m1;
	for (int i = 1; i <= n; ++i)
	{
		m1[i]=-1;
	}

	for (int i = 1; i <= m; ++i)
	{
		if(c[i]==0 && s[i]==1 && n!=1)
		{
			cout<<-1;
			return 0;
		}
		if(m1[s[i]]!=c[i] && m1[s[i]]!=-1)
		{
			cout<<-1;
			return 0;
		}
		m1[s[i]]=c[i];
	}
	for (int i = 1; i <= n; ++i)
	{
		if(i==1 && m1[i]==-1 && n!=1)
		{
			m1[i]=1;
		}
		else if(m1[i]==-1)
		{
			m1[i]=0;
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		cout<<m1[i];
	}

    }



Measured memory_bytes: 256
#include <cstdio>
const long long MOD = 1000000007;
long long fc[3000001], fi[3000001], O;
int x1l, x1r, x2l, x2r, x3l, x3r, y1l, y1r, y2l, y2r, y3l, y3r;
inline long long W(int x, int y)
{
	return fc[x + y] * fi[x] % MOD * fi[y] % MOD;
}
long long Z(int x, int y, int X, int Y)
{
	long long r = 0;
	for (int i = 0; i <= x; i++)
		r = (r + W(i, y) * W(X - i, Y - y - 1) % MOD * (i + y + 1)) % MOD;
	for (int i = 0; i <= y; i++)
		r = (r + W(x, i) * W(X - x - 1, Y - i) % MOD * (x + i + 1)) % MOD;
	return r;
}
long long G(int x1, int y1, int x2l, int x2r, int y2l, int y2r, int x3, int y3)
{
	long long r = 0;
	r += Z(x2r - x1, y2r - y1, x3 - x1, y3 - y1);
	r -= Z(x2r - x1, y2l - y1, x3 - x1, y3 - y1);
	r -= Z(x2l - x1, y2r - y1, x3 - x1, y3 - y1);
	r += Z(x2l - x1, y2l - y1, x3 - x1, y3 - y1);
	return (r % MOD + MOD) % MOD;
}
int main()
{
	fc[0] = fi[0] = fi[1] = 1;
	for (int i = 2; i <= 3000000; i++)
		fi[i] = (MOD - MOD / i) * fi[MOD % i] % MOD;
	for (int i = 1; i <= 3000000; i++)
	{
		fc[i] = fc[i - 1] * i % MOD;
		fi[i] = fi[i - 1] * fi[i] % MOD;
	}
	scanf("%d%d%d%d%d%d%d%d%d%d%d%d", &x1l, &x1r, &x2l, &x2r, &x3l, &x3r, &y1l, &y1r, &y2l, &y2r, &y3l, &y3r);
	x1l--, y1l--;
	x2l--, y2l--;
	x3r++, y3r++;
	long long O = 0;
	O += G(x1l, y1l, x2l, x2r, y2l, y2r, x3r, y3r);
	O -= G(x1l, y1l, x2l, x2r, y2l, y2r, x3r, y3l);
	O -= G(x1l, y1l, x2l, x2r, y2l, y2r, x3l, y3r);
	O += G(x1l, y1l, x2l, x2r, y2l, y2r, x3l, y3l);
	O -= G(x1l, y1r, x2l, x2r, y2l, y2r, x3r, y3r);
	O += G(x1l, y1r, x2l, x2r, y2l, y2r, x3r, y3l);
	O += G(x1l, y1r, x2l, x2r, y2l, y2r, x3l, y3r);
	O -= G(x1l, y1r, x2l, x2r, y2l, y2r, x3l, y3l);
	O -= G(x1r, y1l, x2l, x2r, y2l, y2r, x3r, y3r);
	O += G(x1r, y1l, x2l, x2r, y2l, y2r, x3r, y3l);
	O += G(x1r, y1l, x2l, x2r, y2l, y2r, x3l, y3r);
	O -= G(x1r, y1l, x2l, x2r, y2l, y2r, x3l, y3l);
	O += G(x1r, y1r, x2l, x2r, y2l, y2r, x3r, y3r);
	O -= G(x1r, y1r, x2l, x2r, y2l, y2r, x3r, y3l);
	O -= G(x1r, y1r, x2l, x2r, y2l, y2r, x3l, y3r);
	O += G(x1r, y1r, x2l, x2r, y2l, y2r, x3l, y3l);
	printf("%lld\n", (O % MOD + MOD) % MOD);
	return 0;
}


Measured memory_bytes: 46976
import sys
import fractions
input = lambda: sys.stdin.readline().rstrip()


def count_div(N, C, D):

    t = N // C + N // D - N // (C * D // fractions.gcd(C, D))
    return N - t


def solve():

    A, B, C, D = map(int, input().split())
    ans = count_div(B, C, D) - count_div(A - 1, C, D)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 5180
#include<stdio.h>

struct Card{
  char suit;
  char value;
};



int main(){
  struct Card C1[100], C2[100],f;
  int n, i,j,mini,x=0;
  char ch;

  scanf("%d%c", &n, &ch);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
  }
  for ( i = 0; i < n; i++ ){
    C2[i] = C1[i];
  }
  for(i = 0; i < n; i++){
    for(j = n-1; j >= i+1; j--){
      if(C1[j].value < C1[j-1].value){
	f = C1[j];      
	C1[j] = C1[j-1]; 
	C1[j-1] = f;
      }
    }
  }
  
  for(i = 0; i < n; i++){
    printf("%c%c",C1[i].suit,C1[i].value);
    if(i< n-1){
      printf(" ");
    }
  } 
  printf("\n");
  
  printf("Stable\n");
  
  for(i = 0; i <= n-1; i++){
    mini = i;
    for(j = i; j <= n-1; j++){
      
      if(C2[j].value < C2[mini].value){
	mini = j;
      }
    } 
    
    f = C2[i];      
    C2[i] = C2[mini]; 
    C2[mini] = f; 
  }
  for(i = 0; i < n; i++){
    if(C1[i].suit != C2[i].suit){
      x = 1;
    }
  }
  
  for(i = 0; i < n; i++){
    printf("%c%c",C2[i].suit,C2[i].value);
    if(i<n-1){
      printf(" ");
    }
    
  }   
  printf("\n");

  if(x == 1){
    printf("Not stable\n");
  }
  else {
    printf("Stable\n");
  }
  
  return 0;
}

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

typedef long long ll;
vector<ll>q1[200005];
vector<ll>q2[200005];

int main()
{
	ll n;
	cin>>n;
	for(ll i=1;i<n;i++){
		ll u,v;
		cin>>u>>v;
		ll a=min(u,v);
		ll b=max(u,v);
		q1[a].push_back(b);
		q2[b].push_back(a);
	}
	ll sum1=1;
	ll sum2=1;
	for(ll i=n-1;i>=1;i--){
		sum1+=(1-q1[i].size());
		sum2+=sum1;
	}
	ll sum3=sum2;
	for(ll i=n;i>=1;i--){
		q2[i].push_back(0);
		ll len=q2[i].size();
		q2[i].push_back(i);
		sort(q2[i].begin(),q2[i].end());
		for(ll j=len-1;j>=0;j--){
			sum2+=(q2[i][j+1]-q2[i][j])*(len-1-j-1);
		}
		sum3+=sum2;
	}
	cout<<sum3<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

const ll INF = 1ll<<62;

int n,m,p;
ll po[2521];
bool inf[2521];
pair<pii,int> es[5252];

int main(){
    scanf("%d%d%d",&n,&m,&p);
    REP(i,m){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        --a;--b;
        c -= p;
        es[i] = make_pair(pii(a,b),c);
    }
    ll ans = 0;
    fill(po,po+2521,-1ll<<60);
    po[0] = 0;

    REP(_,2*n){
        REP(i,m){
            int a = es[i].first.first;
            int b = es[i].first.second;
            int c = es[i].second;
            if(po[a] < (-1ll<<50))continue;
            if(po[b] < po[a]+c){
                po[b] = po[a]+c;
            }
        }
        CHMAX(ans, po[n-1]);
    }
    REP(_,2*n){
        REP(i,m){
            int a = es[i].first.first;
            int b = es[i].first.second;
            int c = es[i].second;
            if(po[a] < (-1ll<<50))continue;
            if(po[b] < po[a]+c){
                po[b] = po[a]+c;
                inf[b] = true;
            }
            inf[b] = inf[b] || inf[a];
        }
    }
    if(inf[n-1]){
        puts("-1");return 0;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define D (double)
using namespace std;
int n,m;
signed main()
{
	scanf("%d%d",&n,&m);
	printf("%.10lf",((D(1*1.0/((D(1*1.0/n))+(D(1*1.0/m)))))));
	return putchar(10),0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

bool visited[10];
int cnt;
int N, M;
vector<vector<int>> G;

int dfs(int v){
    if(cnt == N-1) return 1;
    visited[v] = true;
    int ret = 0;
    for(int to: G[v]){
        if(!visited[to]){
            cnt++;
            ret += dfs(to);
            cnt--;
        }
    }
    visited[v] = false;
    return ret;
}

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

    G.assign(N, vector<int>());
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    cnt = 0;
    memset(visited, 0, sizeof(visited));
    cout << dfs(0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

template <typename T>
std::map<T, int> prime_factorize(T n)
{
	std::map<T, int> m;
	for (T i = 2; i * i <= n; ++i) {
		int c = 0;
		for (; n % i == 0; n /= i) {
			++c;
		}
		if (c != 0) {
			m[i] = c;
		}
	}
	if (n != 1) {
		m[n] = 1;
	}
	return m;
}

using namespace std;

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

	auto m = prime_factorize(N);

	int ans = 0;
	for (auto& e : m) {
		int c = e.second;
		for (int i = 1; i <= c; ++i) {
			ans += 1;
			c -= i;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3632