akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

#define ll long long
#define vl vector<ll>
#define vll vector<vl>
#define double long double

const int INF = 1e9;

const int di[] = {0, 1, 0, -1};
const int dj[] = {1, 0, -1, 0};
int w, h;
string s[500];
int f[500][500];
int g[500][500];
int si, sj, gi, gj;

const double inf = 1e18; 

void sub(double prob) {
	using State = pair<int, pair<int, int>>;
	queue<State> Q;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (s[i][j] == '*') {
				f[i][j] = 0;
				g[i][j] = 0;
				for (int k = 0; k < 4; ++k) {
					int ni = i + di[k];
					int nj = j + dj[k];
					Q.push(make_pair(1, make_pair(ni, nj)));
				}
			}
		}
	}

	while (!Q.empty()) {
		auto q = Q.front(); Q.pop();
		int c = q.first;
		int i = q.second.first;
		int j = q.second.second;
		if (s[i][j] == '#') continue;
		if (g[i][j] < INF) continue;
		g[i][j] = c;

		for (int k = 0; k < 4; ++k) {
			int ni = i + di[k];
			int nj = j + dj[k];
			Q.push(make_pair(c + 1, make_pair(ni, nj)));
		}
	}


	Q.push(make_pair(0, make_pair(gi, gj)));
	while (!Q.empty()) {
		auto q = Q.front(); Q.pop();
		int c = q.first;
		int i = q.second.first;
		int j = q.second.second;
		if (s[i][j] == '#') continue;
		if (f[i][j] < INF) continue;
		f[i][j] = c;

		for (int k = 0; k < 4; ++k) {
			int ni = i + di[k];
			int nj = j + dj[k];
			Q.push(make_pair(c + 1, make_pair(ni, nj)));
		}
	}
}

double get(int i, int j, double prob) {
	double val = inf;
	if (f[i][j] < INF) val = min<double>(val, f[i][j]);
	if (g[i][j] < INF) val = min<double>(val, g[i][j] + prob);
	return val;
}

double avg(double prob) {
	double sum = 0;
	int cnt = 0;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (s[i][j] == '.' || s[i][j] == 's') {
				sum += get(i, j, prob);
				++cnt;
			}
		}
	}
	return sum / cnt;
}

int main() {
	cin >> w >> h;
	for (int i = 0; i < h; ++i) {
		cin >> s[i];
		for (int j = 0; j < w; ++j) {
			if (s[i][j] == 's') {
				si = i;
				sj = j;
			} else if(s[i][j] == 'g') {
				gi = i;
				gj = j;
			}
		}
	}

	double lo = 0;
	double hi = 1e17;
	rep(z, 200) {
		double mid = (lo + hi) / 2;

		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				f[i][j] = INF;
				g[i][j] = INF;
			}
		}

		sub(mid);

		if (avg(mid) < mid) {
			hi = mid;
		} else {
			lo = mid;
		}
	}

	cout << setprecision(16) << fixed << get(si, sj, lo) << endl;
	return 0;
}


Measured memory_bytes: 7052
// *
// *
// *  Created By :hozaifa wahid
// * "mai maut ko takia aur kafan ko chadar banakar sota hu" 
// *------------------------------------
// *  OS : Ubuntu 16.04
// *  Language : CPP14
// *  Editor : Sublime Text 3
// *  C++ compiler : g++
// *
// *
//https://www.geeksforgeeks.org/find-the-point-where-maximum-intervals-overlap/
#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a+n
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
ll MOD=1000000007;
vector<ll>v[100055];
void sieve()
{
for(int n=1;n<=100055;n++)
{
for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            // If divisors are equal, print only one 
            if (n/i == i) 
               v[n].push_back(i);
  
            else // Otherwise print both 
               {
                   v[n].push_back(i);
                   v[n].push_back(n/i);
               }
        } 
    } 
}

}
ll pw(ll a,ll b){
    if(b==0) return 1;
    ll x=pw(a,b/2);
    x=(x*x)%MOD;
    if(b%2) x=(x*a)%MOD;
    return x;
}
ll n,s;
ll a[100005];
int ok=0;
//ll res=0;
ll dp[100005];
ll go(ll i)
{
if(i==n-1)
{
return 0;
}
else if(i==n-2)
{
return abs(a[i]-a[i+1]);
}
else if(dp[i]>-1)
return dp[i];
else
{
s=min(abs(a[i]-a[i+1])+go(i+1),abs(a[i+2]-a[i])+go(i+2));
dp[i]=s;
}
return s;
}


void solve()
{
 ll t;
 t=1;
while(t--)
{
//ll n;
cin>>n;
//ll a[n];
FOR(i,0,n)
cin>>a[i];
memset(dp,-1,sizeof(dp));
cout<<go(0);

}
}



int main(){
    std::ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int start = clock();
    #ifdef ONLINE_JUDGE
    #else
      //freopen("input.in" , "r" , stdin);
      // freopen("output.txt", "w", stdout);
    #endif
    solve();
    int stop = clock();
    #ifdef ONLINE_JUDGE
    #else
        // cout << setprecision(6) << fixed << (stop - start) * 1000.00 / double(CLOCKS_PER_SEC)<< endl;
    #endif
}









Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n,m; cin >> n >> m;
    int c; cin >> c;
    vector<int> b(m);
    vector<vector<int>> a(n,vector<int>(m));
    for(int i=0;i<m;i++) cin >> b[i];
    rep(i,n){
        rep(j,m){
            cin >> a[i][j];
        }
    }

    ll ans = 0;
    rep(i,n){
        ll p = c;
        rep(j,m) p += a[i][j] * b[j];
        if(p > 0) ans++;
    }
    cout << ans << endl;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
typedef pair<li, li> PI;

PI a[100100];

int main(void)
{
	li n, m, k;
	cin >> n >> m >> k;
	rep(i, n + 1) {
		rep(j, m + 1) {
			li ii = n - i;
			li jj = m - j;
			if (ii * j + jj * i == k) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");

	return 0;
}

Measured memory_bytes: 256
n = int(input())
tn = [int(num) for num in input().split()]
m = int(input())

pxn = []
for _ in range(m):
  p, x = map(int, input().split())
  pxn.append([p, x])
  
for p in pxn:
  print(sum(tn) - tn[p[0]-1] + p[1])

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

using namespace std;

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

  for (int i = n - 1; i >= 0; i-=2) {
    if (i == n - 1) {
      cout << a[i];
    } else {
      cout << " " << a[i];
    }
  }

  int start = ((n % 2 == 0) ? 0 : 1);
  for (int i = start; i < n - 1; i += 2) {
    cout << " " << a[i];
  }

  cout << '\n';
  return 0;
}



Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int n, k, m, cnt[MAX_N]{}, ans = 0;

int main() {
    vector<int> v;
    cin >> n >> k;
    REP(i,n){
        int a;
        cin >> a;
        cnt[a]++;
    }
    REP(i,int(2e5)+1){
        if(cnt[i]>0)v.push_back(cnt[i]);
    }
    SORT(v);
    m = max(int(v.size())-k,0);
    REP(i,m){
        ans += v[i];
    }
    cout << ans << endl;
    return 0;
}


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

void solve()
{
	ll d,t,s;
	cin>>d>>t>>s;
	if(d>t*s)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
}

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

Measured memory_bytes: 3628
import java.util.*;
 
class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        if(k<=9){
            System.out.println(k);
            return;
        }
 
        Queue<Long> q = new PriorityQueue<>();
        for(long i=1;i<10;i++){
            q.add(i);
        }
        int count = 9;
        long now = 0;
        while(true){
            long tmp = q.poll();
            long r1 = tmp%10;
 
            if(tmp%10!=0){
                now = tmp*10+r1-1;
                q.add(now);
                count++;
                if(count==k)break;
            }
 
            now = tmp*10+r1;
            q.add(now);
            count++;
            if(count==k)break;
 
            if(tmp%10!=9){
                now = tmp*10+r1+1;
                q.add(now);
                count++;
                if(count==k)break;
            }
        }
        System.out.println(now);
 
    }
}

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

typedef long long ll;

string s; int n;
ll k;
int ans1, ans2;

int main() {
	
	cin >> s; n = (int)s.size();
	cin >> k;
	
	if (s == string(n, s[0])) {
		cout << n * k / 2 << endl;
		return 0;
	}
	
	for (int i = 1; i < n; i++)
		if (s[i] == s[i - 1]) {
			++ans1;
			++i;
		}
	for (int i = 1; i < 2 * n; i++)
		if (s[i % n] == s[(i - 1) % n]) {
			++ans2;
			++i;
		}
	cout << ans1 + (ans2 - ans1) * (k - 1) << endl;
	
	return 0;
	
}

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

fn main() {
    let line: String = read();
    let vec: Vec<&str> = line.split("").filter(|e| e.len() > 0).collect();
    let odd: Vec<&str> = vec.iter().enumerate()
        .filter(|&(idx, _)| idx % 2 == 0)
        .map(|(_, &i)| i).collect();
    let even: Vec<&str> = vec.iter().enumerate()
        .filter(|&(idx, _)| idx % 2 == 1)
        .map(|(_, &i)| i).collect();
    let result_odd = odd.iter().find(|&&i| i == "L");
    let result_even = even.iter().find(|&&i| i == "R");
    let result = match (result_odd, result_even) {
        (None, None) => "Yes",
        (_, _) => "No",
    };
    println!("{}", result);
}

fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
fun main(arg: Array<String>) {
    val (N, M) = listOfLong()
    val ans = if (N * 2 <= M) N + (M - N * 2) / 4 else M / 2
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 36136
#include <stdio.h>
#include<stdlib.h>
int main(void){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(abs(a-c)<=d){puts("Yes");return 0;}
    if(abs(a-b)<=d && abs(b-c)<=d){puts("Yes");return 0;}
    puts("No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int n;
  cin >> n;
  for (int i = 1; i < 10; i++){

    if (n == (i * 100 + i * 10 + i)){
      cout << i * 100 + i * 10 + i << endl;
      break;
    }

    if (n < (i * 100 + i * 10 + i)){
      cout << i * 100 + i * 10 + i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().strip().split(' '))
a = list(map(str, input().strip().split(' ')))
MOD = 1000000007
# 一周期内
bn = 0
for i in range(n-1):
  for j in range(n-1-i):
    if int(a[i]) > int(a[i+j+1]):
      bn = bn + 1
# 次の周期も考える
bm = 0
for i in range(n):
  for j in range(n):
    if int(a[i]) > int(a[j]):
      bm = bm + 1
if k % 2 == 0:
  bm = (bm % MOD) * ((k // 2) % MOD) * (k-1 % MOD)
else:
  bm = (bm % MOD) * (k % MOD) * (((k-1) // 2) % MOD)
s = (bn % MOD) * (k % MOD) + (bm % MOD)
print(s % MOD)

Measured memory_bytes: 41820
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

#define say(args) cout << (args) << endl
#define rep(i, a) for (int i = 0; i < a; i++)

using namespace std;

int main() {
  int num;
  cin >> num;
  while (num != 0) {
    int count = 0;
    for (int i = 1; i < num - 1; i++) {
      int sum = 0;
      for (int j = i; j <= (int) ceil( (double) num / 2 ); j++) {
        sum += j;
        if (sum == num) {
          count += 1;
          break;
        }
      }
    }
    say(count);
    cin >> num;
  }
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n;
	cin>>n;
	
	vector<string> s(n);
	vector<int> p(n);
	vector<int> num(n);
	
	REP(i,n){
		cin>>s[i]>>p[i];
		num[i]=i+1;
	}
	
	for(int i=0;i<n-1;++i){
		for(int j=n-1;j>i;--j){
			if(p[j-1]<p[j]){
				swap(s[j-1],s[j]);
				swap(p[j-1],p[j]);
				swap(num[j-1],num[j]);
			}
		}
	}	
	
	for(int i=0;i<n-1;++i){
		for(int j=n-1;j>i;--j){
			if(s[j-1]>s[j]){
				swap(s[j-1],s[j]);
				swap(p[j-1],p[j]);
				swap(num[j-1],num[j]);
			}
		}
	}
	
	REP(i,n) cout<<num[i]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
    ll a[5];
    ll i,j;
    for(i=0;i<5;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<5;i++)
    {
        if(a[i]==0)
        {
            cout<<(i+1)<<"\n";
            return;
        }
    }
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

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

int main() {
	int n;
	cin >>n;
	for (int i=1; i <= n; ++i){
		if (i % 3 == 0 || to_string(i).find('3') != string::npos){
			cout << ' ' << i;
		}
	}
	cout << endl;
}

Measured memory_bytes: 1224
alp = [chr(i) for i in range(97, 97+26)]
N = int(input())
q = N
s = ""
while True:
  q,m = divmod(q,26)
  if m == 0:
    m = 26
    q -= 1
  s = alp[m - 1] + s
  if q == 0:
    break
print(s)
  

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

int main() {
    int mod = 1000000007;
  int N;
  cin >> N;
  long long A[N];
  long long sum = 0;
  for(int i = 0; i < N; i++){
      cin >> A[i];
      sum += A[i];
      sum %= mod;
  }
  long ans = 0;

  for(int i = 0; i < N; i++){
      sum -= A[i];
      if(sum < 0) sum += mod;
      ans += A[i]*sum;
      ans %= mod;

  }
  cout << ans << endl;
}

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

using namespace std;

#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; };
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; };
template<class T> T th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

template<int MOD>
class Modint{
public:
	long long val;
	Modint(long long val) : val(val) {}
	Modint &operator+=(const Modint &a){
		val += a.val;
		if(val >= MOD) val -= MOD;
		return *this;
	}
	Modint &operator-=(const Modint &a){
		val -= a.val;
		if(val < 0) val += MOD;
		return *this;
	}
	Modint &operator*=(const Modint &a){
		val = val * a.val % MOD;
		return *this;
	}
	void inverse(){
		long long x[2] = {MOD, val};
		long long a[2][2] = {{1, 0}, {0, 1}};
		int i;
		for(i = 0; x[~i&1]; ++i){
			for(int j = 0; j < 2; ++j){
				long long tmp = a[j][1];
				a[j][1] = a[j][0] + x[i&1] / x[~i&1] * a[j][1];
				a[j][0] = tmp;
			}
			x[i&1] = x[i&1] % x[~i&1];
		}
		val = a[1][0];
		if(!(i & 1)) val = MOD - val;
	}
	Modint &operator/=(Modint a){
		a.inverse();
		return *this *= a;
	}
	friend Modint operator+(Modint a, const Modint &b){
		return a += b;
	}
	friend Modint operator-(Modint a, const Modint &b){
		return a -= b;
	}
	friend Modint operator*(Modint a, const Modint &b){
		return a *= b;
	}
	friend Modint operator/(Modint a, const Modint &b){
		return a /= b;
	}
};

template<class T, class U>
T mypow(T x, U n){
	T ret(1);
	while(n){
		if(n & 1){
			ret *= x;
		}
		x *= x;
		n >>= 1;
	}
	return ret;
}

using Mint = Modint<1000000007>;
using Int = long long;

int main(){
	Int n, a, b;
	cin >> n >> a >> b;
	Mint x = mypow(Mint(2), n);
	Mint y(1), z(1);
	for(Int i = 0; i < a; ++i) y *= Mint(n - i);
	for(Int i = a; i > 0; --i) y /= Mint(i);
	for(Int i = 0; i < b; ++i) z *= Mint(n - i);
	for(Int i = b; i > 0; --i) z /= Mint(i);
	cout << (x - y - z - 1).val << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = Read().Int();
            var s = Read();
            var r = 0L;
            var g = 0L;
            var b = 0L;
            for (int i = 0; i < n; i++)
            {
                var str = s[i].ToString();
                if (str == "R")
                {
                    r++;
                }
                else if (str == "G")
                {
                    g++;
                }
                else if (str == "B")
                {
                    b++;
                }
            }
            var ans = r * g * b;
            if (ans == 0)
            {
                WriteRead(ans);
                return;
            }
            var sub = 0L;
            for (int i = 0; i < n; i++)
            {
                for (int j = 1; j < n; j++)
                {
                    var a1 = s[i].ToString();
                    if (i + (j * 2) >= n) break;
                    var a2 = s[i + j].ToString();
                    var a3 = s[i + (j * 2)].ToString();
                    if (a1 != a2 && a1 != a3 && a2 != a3)
                    {
                        sub++;
                    }
                }
            }
            WriteRead(ans - sub);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 21744
def main():
    from itertools import permutations
    N = int(input())
    P = tuple([i for i in input().split()])
    Q = tuple([i for i in input().split()])

    if P == Q:
        print(0)
        return

    if ''.join(P) > ''.join(Q):
        T = P[::]
        P = Q
        Q = T

    per = ''.join([str(i) for i in range(1, N + 1)])
    cnt = 0
    p_found = False
    for S in permutations(per):
        if not p_found:
            if S == P:
                p_found = True
        else:
            cnt += 1
            if S == Q:
                break

    print(cnt)

if __name__ == '__main__':
    main()



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

const int mod = (int)1e9+7;

int main(){
	int H, W, K; cin >> H >> W >> K;

	vector<vector<int>> dp(H+1, vector<int>(W+1, 0));
	dp[0][1] = 1;

	for(int y=0; y<H; ++y){
		for(int x=1; x<=W; ++x){
			for(int i=0; i<(1 << (W-1)); ++i){
				bool ok = true;
				for(int k=0; k<W-2; ++k){
					if(((i >> k) & 3) == 3)
						ok = false;
				}
				if(ok){
					if(x - 1 >= 1 && ((i >> (x-2)) & 1))
						dp[y+1][x-1] = (dp[y+1][x-1] + dp[y][x]) % mod;

					else if(x + 1 <= W && ((i >> (x-1)) & 1))
						dp[y+1][x+1] = (dp[y+1][x+1] + dp[y][x]) % mod;

					else
						dp[y+1][x] = (dp[y+1][x] + dp[y][x]) % mod;
				}
			}
		}
	}

	cout << dp[H][K] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool vis[200005];
vector <ll> adj[200005];
set <ll> chk[200005];
vector <ll> vec;
ll counter=0;
void dfs(ll a)
{
    vis[a]=1;
    counter++;
    for(int i=0;i<(ll)adj[a].size();i++)
    {
        if(vis[adj[a][i]]==0)
        {
            dfs(adj[a][i]);
        }
    }
}
int main()
{
    ll n,m,a,b,ans=0;
    cin>>n>>m;
    for(int i=0;i<=n;i++)
    {
        vis[i]=0;
    }
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        if(chk[a].count(b)==0)
        {
            adj[a].push_back(b);
            chk[a].insert(b);
        }
        if(chk[b].count(a)==0)
        {
            adj[b].push_back(a);
            chk[b].insert(a);
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            counter=0;
            dfs(i);
            vec.push_back(counter);
        }
    }
    sort(vec.begin(),vec.end());
    if(vec.size()==1)
    {
        cout<<vec[0]<<'\n';
    }
    else
    {
        ans+=vec[0];
        for(int i=1;i<(ll)vec.size();i++)
        {
            ans+=(vec[i]-vec[i-1]);
        }
        cout<<ans<<'\n';
    }
    return 0;
}


Measured memory_bytes: 49128
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int[][] arr = new int[n][m+1];
    int ans = Integer.MAX_VALUE;


    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        for (int i=0; i<n; i++) {
            for (int j=0; j<m+1; j++) {
                arr[i][j] = sc.nextInt();
            }
        }

        dfs("0");
        if (ans == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }

    }

    void dfs(String s) {
        if (s.length() == n + 1) {
            ans = Math.min(ans, calc(s));
//            System.out.println(s);
        }
        if (s.length() < n + 1) {
            for (int i=0; i<2; i++) {
                s = s + String.valueOf(i);
                dfs(s);
                s = s.substring(0, s.length()-1);
            }
        }
    }

    int calc(String s) {
        int ret = 0;
        int[] p = new int[m];
        for (int i=1; i<=n; i++) {
            if (s.charAt(i) == '1') {
                for (int j=0; j<m; j++) {
                    p[j] += arr[i-1][j+1];
                }
                ret += arr[i-1][0];
            }
        }
        for (int i=0; i<m; i++) {
            if (p[i] < x) {
                return Integer.MAX_VALUE;
            }
        }
        return ret;
    }
}



Measured memory_bytes: 41784
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func Max(x ...int64) int64 {
	max := x[0]
	for _, v := range x {
		if v > max {
			max = v
		}
	}
	return max
}

type ints []int
func (f ints) Len() int {
	return len(f)
}

func (f ints) Less(i, j int) bool {
	return f[i] > f[j]
}

func (f ints) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

func Reverse(l []int) []int {
	n := len(l)
	x := make([]int, n)
	for i := 0; i<n; i++ {
		x[n-i-1] = l[i]
	}
	return x
}

func SortInt(x []int) []int {
	i := ints(x[:])
	sort.Sort(i)
	return i
}

func main() {
	n := nextInt()
	k := int64(nextInt())
	a := make([]int, n)
	f := make([]int, n)

	for i := 0; i<n; i++ {
		a[i] = nextInt()
	}

	for i := 0; i<n; i++ {
		f[i] = nextInt()
	}

	a = SortInt(a)
	f = Reverse(SortInt(f))

	var l, r int64
	l = -1
	r = 100100100100100100
	for r - l > 1 {
		m := l + (r - l) /2
		if func() bool {
			sum := int64(0)
			for i := 0; i<n; i++ {
				sum += Max(0, int64(a[i]) - m/int64(f[i]))
			}
			return sum <= k
		}() {
			r = m
		} else {
			l = m
		}
	}

	fmt.Printf("%d", r)
}


Measured memory_bytes: 7936
N=int(input())
S=input()
stack= []
ans=""
L=0
R=0

for i in range(N):
  if S[i]=="(":
    stack.append(S[i])
  else:
    if len(stack)>0:
      stack.pop()
    else:
      L += 1

R=len(stack)
ans = L * "(" + S + R * ")"

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;

int main(){
  auto dmy=scanf("%d", &n);
  vector<int> d(n);
  for(int i=0; i<n; i++) dmy=scanf("%d", &d[i]);
  
  ll ans=0;
  for(int i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){
      ans += d[i]*d[j];
    }
  }
  printf("%lld\n", ans);
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

int main(){
    int n, k; cin >> n >> k;
    vector<int> p(n); rep(i,n) cin >> p[i];

    sort(all(p));

    int ans = 0;
    rep(i,k){
        ans += p[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < (ll)V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path; vl A; vl dp; vl Ans;
int main(){
	cin >> N >> K;
	ll P = N / K;
	ans += P * (P - 1) * (P - 2);
	ans += P * (P - 1)*3;
	ans += P;
	if (K % 2 == 0 && N>=K/2) {
		ll Q = (N - K / 2) / K + 1;
		ans += Q * (Q - 1) * (Q - 2) + Q * (Q - 1)*3 + Q;
	}
	cout << ans;
}

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

using namespace std;

const int N = (int)1e5+9;

struct node {
    int v,d,c;
}q[N];

int n,m,h;
vector <int> gp[N];
int dp[N];
int color[N];

void solve(int vertex, int dist, int cc) {
    if (dist <= dp[vertex])return;
    dp[vertex] = dist;
    if (color[vertex] == 0) {
        color[vertex] = cc;
    }
    for (auto it : gp[vertex]) {
        solve(it,dist-1,cc);
    }
}

int main() {
    scanf("%d %d",&n,&m);
    memset(dp,-1,sizeof(dp));
    for (int i = 0; i < m; i++) {
        int p1,p2;
        scanf("%d %d",&p1,&p2);
        gp[p1].push_back(p2);
        gp[p2].push_back(p1);
    }   
    scanf("%d",&h);
    for (int i = 0; i < h;i++) {
        int p1,p2,p3;
        scanf("%d %d %d",&p1 ,&p2, &p3);
        q[i].v = p1;
        q[i].d = p2;
        q[i].c = p3;
    }
    for (int i = h - 1; i >= 0; i--) {
        solve(q[i].v , q[i].d , q[i].c);
        /*for (int i = 1; i <= n; i++) {
            cout << color[i] <<" ";
        }
        cout << endl;*/
    }
    for (int i = 1; i <= n; i++) {
        printf("%d\n",color[i]);
    }
    return 0;
}


Measured memory_bytes: 8440
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <string>
#define SIZE 131080
#define INF 100000000000000000LL

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

vector <int> vec[SIZE];
vector <int> cost[SIZE];
vector <P> dp[SIZE];
ll X;
bool vl;

void dfs(int v,ll d)
{
	dp[v].clear();
	if(vec[v].size()==0)
	{
		dp[v].push_back(P(d,d));
		return;
	}
	int l=vec[v][0],r=vec[v][1];
	dfs(l,d+cost[v][0]);dfs(r,d+cost[v][1]);
	if(dp[l].size()<dp[r].size()) swap(l,r);/*
	if(v==2)
	{
		for(int i=0;i<dp[l].size();i++) printf("[%lld %lld] ",dp[l][i].first,dp[l][i].second);puts("");
		for(int i=0;i<dp[r].size();i++) printf("[%lld %lld] ",dp[r][i].first,dp[r][i].second);puts("");
	}*/
	int to=0;
	vector <P> A,B;
	ll bef=INF;
	for(int i=0;i<dp[r].size();i++)
	{
		P p=dp[r][i];
		int to=lower_bound(dp[l].begin(),dp[l].end(),P(X+2LL*d-p.second+1,-1))-dp[l].begin();
		//while(to<dp[l].size()&&dp[l][to].first+p.second<=X+2LL*d) to++;
		if(to>0)
		{
			to--;
			if(bef==dp[l][to].second) continue;
			bef=dp[l][to].second;
			A.push_back(P(p.first,bef));
			B.push_back(P(bef,p.first));
		}
	}
	reverse(B.begin(),B.end());
	int s=0,t=0;
	while(s<A.size()||t<B.size())
	{
		if(s==A.size()) dp[v].push_back(B[t++]);
		else if(t==B.size()) dp[v].push_back(A[s++]);
		else if(A[s]<=B[t])
		{
			while(t<B.size()&&B[t].second>=A[s].second) t++;
			dp[v].push_back(A[s++]);
		}
		else
		{
			while(s<A.size()&&A[s].second>=B[t].second) s++;
			dp[v].push_back(B[t++]);
		}
	}
}
void see(int v)
{
	printf("%d\n",v+1);
	for(int i=0;i<dp[v].size();i++) printf("[%lld %lld]\n",dp[v][i].first,dp[v][i].second);
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int a,v;
		scanf("%d %d",&a,&v);a--;
		vec[a].push_back(i);
		cost[a].push_back(v);
	}
	//X=15;
	//dfs(0,0);
	//for(int i=0;i<n;i++) see(i);
	//return 0;
	ll l=-1,r=INF;
	while(r-l>1)
	{
		X=(l+r)/2;
		dfs(0,0);
		//for(int i=0;i<n;i++) see(i);
		//return 0;
		if(dp[0].empty()) l=X;
		else r=X;
	}
	printf("%lld\n",r);
	return 0;
}


Measured memory_bytes: 37112
import fractions
from functools import reduce
import itertools
import math

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

if K == 1:
    ans = 1
elif K == 2:
    ans = 9
else:
    ans = 0
    for i in range(1, K+1):
        ans += i
        for j in range(i+1, K+1):
            ans += gcd(i, j) * 6
            for k in range(j+1, K+1):
                ans += gcd(i, j, k) * 6

print(ans)


Measured memory_bytes: 10524
import sys
input = sys.stdin.readline

def query(x1, y1, x2, y2, acc):
    return acc[x2+1][y2+1]-acc[x2+1][y1]-acc[x1][y2+1]+acc[x1][y1]

N, K = map(int, input().split())
W = [[0]*K for _ in range(K)]
B = [[0]*K for _ in range(K)]

for _ in range(N):
    xi, yi, ci = input().split()
    xi = int(xi)
    yi = int(yi)
    t = (xi-xi%K)//K+(yi-yi%K)//K
    
    if t%2==1:
        ci = 'B' if ci=='W' else 'W'
    
    if ci=='W':
        W[xi%K][yi%K] += 1
    else:
        B[xi%K][yi%K] += 1


W_acc = [[0]*(K+1) for _ in range(K+1)]
B_acc = [[0]*(K+1) for _ in range(K+1)]

for i in range(K):
    for j in range(K):
        W_acc[i+1][j+1] = W_acc[i+1][j]+W_acc[i][j+1]-W_acc[i][j]+W[i][j]
        B_acc[i+1][j+1] = B_acc[i+1][j]+B_acc[i][j+1]-B_acc[i][j]+B[i][j]
        
ans = 0

for i in range(K):
    for j in range(K):
        clear_w = query(0, 0, i, j, W_acc)+query(i+1, j+1, K-1, K-1, W_acc)
        clear_b = query(i+1, 0, K-1, j, B_acc)+query(0, j+1, i, K-1, B_acc)
        ans = max(ans, clear_w+clear_b)
        
        clear_w = query(0, 0, i, j, B_acc)+query(i+1, j+1, K-1, K-1, B_acc)
        clear_b = query(i+1, 0, K-1, j, W_acc)+query(0, j+1, i, K-1, W_acc)
        ans = max(ans, clear_w+clear_b)
        
print(ans)

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

using namespace std;

int main()
{
  vector<vector<int>> v(3, vector<int>(3,0));
  for(int i = 0; i < 3; ++i) for(int j = 0; j < 3; ++j) cin>>v[i][j];
  
  int n; cin >> n;
  
  int num; 
  while(n--)
  {
    cin >> num;
    for(int i = 0; i < 3; ++i)
    {
      for(int j = 0; j < 3; ++j)
      {
        if(v[i][j] == num)
        {
          v[i][j] = 0; break;
        }
      }
    }
  }
  
  bool found = false;
  
  for(int i = 0; i < 3 and !found; ++i)
  {
    int count = 0;
    for(int j = 0; j < 3; ++j)
    {
      if(v[i][j] == 0) ++count;
    }
    if(count == 3)
    {
      found = true;
    }
  }
  
   for(int i = 0; i < 3 and !found; ++i)
  {
    int count = 0;
    for(int j = 0; j < 3; ++j)
    {
      if(v[j][i] == 0) ++count;
    }
    if(count == 3)
    {
      found = true;
    }
  }
  
  found = found or (v[0][0]+v[1][1]+v[2][2]==0) or (v[0][2]+v[1][1]+v[2][0]==0);
  if(found) cout <<"Yes";
  else cout <<"No";
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t int64;

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

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

class C {
	int d, target;
	int mask{ 0 };
	vector<vector<int>> problems;
public:
	C()
	{
		cin >> d >> target;
		problems.resize(d, vector<int>(2));
		
		REP(i, d)
		{
			mask |= (1 << i);
			cin >> problems[i][0] >> problems[i][1];
			problems[i][1] += 100 * (i + 1) * problems[i][0];
		}
	}

	int calcNQuestions(int bit)
	{
		int ret{ 0 };
		for (int b{ 0 }; b < d; b++)
			if (bit & b)
				ret += problems[b][0];

		return ret;
	}

	void solve()
	{

		int ans{ 2000 };
		int sum;
		int n_questions;

		for (int bit{ 0 }; bit < (1 << d); bit++)
		{
			sum = 0;
			n_questions = 0;

			for (int b{ 0 }; b < d; b++)
				if (bit & (1 << b))
				{
					sum += problems[b][1];
					n_questions += problems[b][0];
				}

			if (sum >= target)
			{
				chmin(ans, n_questions);
				continue;
			}
			else
			{
				int notUsed{ mask ^ bit };
				if (notUsed)
				{
					// look for highest bit that is zero
					for (int b{ d - 1 }; b >= 0; b--)
					{
						if (notUsed & (1 << b))
						{
							// find out how many questions we need to the target
							int needMore{ ceil(((double)target - sum) / 100 / (b + 1)) };

							// if the number does not exceed existing qustions
							if (needMore <= problems[b][0])
								// and add the number to n_questions
								// update ans
								chmin(ans, n_questions + needMore);

							break;
						}
					}
				}
			}
		}

		cout << ans << endl;
	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin>>N;
  if(N<=0){
    cout<<0<<endl;
  }
  else if(N%11==0){
    cout<<N/11*2<<endl;
  }
  else if(N%11<=6){
    cout<<N/11*2+1<<endl;
  }
  else{
    cout<<N/11*2+2<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

class RmqTree {
private:
	ll _find(ll a, ll b, ll k, ll l, ll r) {
		//区間[l,r)の最小値を持つk番目のノードを探索
		if (r <= a || b <= l)return INF;    // 交差しない
		if (a <= l && r <= b)return dat[k];   // 完全に含む
		else {
			ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
			ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
			return min(s1, s2);
		}
	}
public:
	ll n, height;
	vector<ll> dat;

	// 初期化（_nは最大要素数）
	RmqTree(ll _n) {
		n = 1;
		height = 1;
		while (n < _n) {
			n *= 2;
			height++;
		}
		dat = vector<ll>(2 * n - 1, INF);
	}

	// i番目の値(0-indexed)をxに変更
	void update(ll i, ll x) {
		i += n - 1; // i番目の葉ノードへ
		dat[i] = x;
		while (i > 0) { // 登りながら更新
			i = (i - 1) / 2;//親ノードのインデックス
			dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
			//子ノードの小さい方の値を代入
		}
	}

	// 区間[a,b)の最小値の取得
	ll find(ll a, ll b) {
		return _find(a, b, 0, 0, n);
	}
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	ll n;
	cin >> n;
	Array c(n, 0);
	REP(i, n)cin >> c[i];

	Array dp(n+1, 0);		//位置i-1までの組み合わせの数
	Array last(2e5+10, -1);	//色iが最後に出現した位置

	dp[0] = 1;

	REP(i, n) {
		dp[i+1] = dp[i];
		ll pre = last[c[i] - 1];
		last[c[i] - 1] = i;
		if (pre != -1 && pre != i - 1) {
			//挟める場合、挟む位置の前の数分挟んだ場合の組み合わせが増える
			(dp[i + 1] += dp[pre+1])%=MOD;
		}
	}

	cout << dp[n] << endl;


	return 0;
}

Measured memory_bytes: 4992
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		ArrayList<Integer> train = new ArrayList<Integer>();
		try{
			while(true){
				int i = scn.nextInt();
				if(i == 0){
					System.out.println(train.get(train.size()-1));
					train.remove(train.size()-1);
				}else{
					train.add(i);
				}
			}
		}catch(Exception e){
			}
		}
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	vector<llong> b;

	cin >> N;
	b.resize(N);
	for(int i = 0; i < N; i++)
		cin >> b[i];

	vector<llong> ans;
	for(int j = 0; j < N; j++){
		for(int i = b.size(); i >= 1; i--){
			if(b[i-1] == i){
				ans.push_back(b[i-1]);
				b.erase(b.begin()+i-1);
				break;
			}
		}
	}

	if(b.size() == 0){
		reverse(BE(ans));
		for(auto x : ans)
			cout << x << endl;
	}else{
		cout << -1 << endl;
	}

	return 0;
}

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

int main()
{
string n ;
cin >> n ;
ll sum=0;
rep(i,n.size()){
  sum+=n[i]-'0';
}
if(sum%9==0)cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}

Measured memory_bytes: 3716
n = int(input())
v = list(map(int, input().split()))

m = max(v)+1
o = [0]*m
e = [0]*m

for i in range(n):
    if i%2 == 0:
        o[v[i]] += 1
    else:
        e[v[i]] += 1

a = sorted(o)[-2:]
b = sorted(e)[-2:]


if o.index(a[1]) == e.index(b[1]):
    if a[0] >= b[0]:
        ans = n - o[o.index(a[0])] - e[e.index(b[1])]
    else:
        ans = n - o[o.index(a[1])] - e[e.index(b[0])]
else:
    ans = n - a[1] - b[1]
    
print(ans)

Measured memory_bytes: 55132
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x,a,b; cin >> x >> a >> b;
    if(a >= b) cout << "delicious" << endl;
    else if(a+x >=b) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 256
# 自分以外なら引かれるので
n, k, q = map(int, input().split())
d = {}
for _ in range(q):
    x = int(input())
    if x in d:
        d[x] += 1
    else:
        d[x] = 1

for i in range(n):
    if k > q:
        print("Yes")
        continue
    if i + 1 in d and q - d[i + 1] < k:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 53848
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){
  string A, B,check;
  int C, D;
  cin >> A >> B;
  cin >> C >> D;
  cin >> check;
  if(check == A){
    cout << C - 1 << " " << D;
  } else {
    cout << C << " " << D - 1;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eps 1e-8
#define all(v) (v.begin(),v.end())
#define db double
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const double pi=acos(-1.0);
const double inf = 1e100;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
  	string s,t;
  	cin>>s>>t;
  	int cnt=0;
  	rep(i,0,s.size()){
    	if(s[i]!=t[i]) cnt++;
    }
  	cout<<cnt;
    return 0;
}



Measured memory_bytes: 3752
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define maxn 400
using namespace std;

int g[maxn][maxn];
int n,m;
int num[maxn];
int now[maxn];
bool bo[maxn];


void Delete(int x){
for (int i=1;i<=n;i++)
    if ( g[ i ] [ now[i] ]==x)
    {
        int j;
        for (j=now[i];j<=m;j++)
            if ( !bo[  g[i][j] ])
                break;
        num[ x ]--;
        num[ g[i][j] ]++;
        now[i]=j;
    }
}


int main(){
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            scanf("%d",&g[i][j]);
    for (int i=1;i<=n;i++)
        num[ g[i][1] ]++;
    for (int i=1;i<=n;i++)
        now[i]=1;
    int ans=n;
    for (int i=1;i<m;i++)
        {
            int tmp=0;
            int maxi=0;
            for (int j=1;j<=m;j++)
                if ( tmp <num [j])
                    tmp=num[j],maxi=j;
            ans=min(ans,tmp);
            bo[ maxi ]=1;
            Delete(maxi);
        }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 768