akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int n, m, q;
int a[51], b[51], c[51], d[51], ans = 0;
int arr[11];

void solve(int i, int val, int p) {
	if(i > n) {
		return;
	}
	arr[i] = val;
	int cur = p;
	for(int j = 0; j < q; j++) {
		if(b[j] == i && arr[i] - arr[a[j]] == c[j]) {
			cur += d[j];
		}
	}
	for(int j = val; j <= m; j++) {
		solve(i + 1, j, cur);
	}
	ans = max(ans, cur);
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	cin >> n >> m >> q;
	for(int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	for(int i = 1; i <= m; i++) {
		solve(1, i, 0);
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
    cin >> a >> b;
    if(a < b) {
        for(int i = 0; i < b; ++i) {
            cout << a;
        }
        cout << endl;
    }else {
        for(int i = 0; i < a; ++i) {
            cout << b;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

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

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

int main(){
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<3;i++){
        if(s[i]=='o')
            cnt++;
    }
    cout<<700+100*cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

string s;
int main() {
	cin >> s;
	cout << (s > "2019/04/30" ? "TBD" : "Heisei") << endl;
}




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

int main()
{
  string s;
  for(;cin>>s,s!="#";)
    {
      int c=0;
      bool t;
      for(int i=0;i<s.size();i++)
	{
	  if( string("qwertasdfgzxcvb").find(s[i],0)!= string::npos )
	    {
	      if(i!=0 && !t)
		c++;
	      t=true;
	    }
	  else
	    {
	      if(i!=0 && t)
		c++;
	      t=false;
	    }
	}
      cout<<c<<endl;
    }
}

Measured memory_bytes: 1188
class UnionFind: # simple
    def __init__(self, n):
        self.prsz = [-1] * n # parent ' size
    def find(self, v): # root
        if self.prsz[v] < 0: return v
        else:
            self.prsz[v] = self.find(self.prsz[v])
            return self.prsz[v]
    def union(self, v, u): # unite
        v = self.find(v); u = self.find(u)
        if v == u: return False
        if self.prsz[v] > self.prsz[u]: v, u = u, v # size(v) < size(u)
        self.prsz[v] += self.prsz[u]
        self.prsz[u] = v
        return True
    def size(self, v): return -self.prsz[self.find(v)]

n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m): uf.union(*map(lambda x: int(x)-1, input().split())) # unite
ans = 0
for i in range(n): ans = max(ans, uf.size(i))
print(ans)


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

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

// 無限大の値
const long long INF = 1LL << 60;

// 入力
int N;
long long W, weight[110], value[110];

// DP テーブル
long long dp[110][100100] = {0};

int main()
{
    // input
    cin >> N >> W;
    for (int i = 0; i < N; ++i)
        cin >> weight[i] >> value[i];


    // ループ
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {
            // i番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                // cout << "debg " << dp[i+1][sum_w] << " weigh " << weight[i] << " " << dp[i][sum_w - weight[i]] + value[i] << endl;
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }
            // 選ばない場合
            // cout << "debg2 " << dp[i+1][sum_w] << " " << dp[i][sum_w] << endl;
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    // 解を得て出力
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 79360
use std::io::{self, Read};
use std::iter::FromIterator;

trait Source {
    fn next_chr(&mut self) -> char;
    fn next_str(&mut self) -> String;
}

#[allow(dead_code)]
fn from_stdin() -> SourceImpl {
    let mut data = String::new();
    io::stdin().read_to_string(&mut data).expect("Input error");
    from_str(&data)
}

fn from_str(s: &str) -> SourceImpl {
    let data = String::from(s);
    let chars = data.chars().collect::<Vec<char>>().into_iter();
    SourceImpl { chars: chars }
}

struct SourceImpl {
    chars: std::vec::IntoIter<char>,
}

impl Source for SourceImpl {
    fn next_chr(&mut self) -> char {
        self.chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .next()
            .expect("eof")
    }

    fn next_str(&mut self) -> String {
        let it = self
            .chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .take_while(|c| !char::is_whitespace(*c));
        let s = String::from_iter(it);
        if s.is_empty() {
            panic!("eof")
        } else {
            s
        }
    }
}

#[allow(unused_macros)]
macro_rules! input {
    ($src:expr; $($elem:tt)*) => {
        input_inner!($src, $($elem)*)
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($src:expr) => {};
    ($src:expr,) => {};
    ($src:expr, $var:ident : mut $ty:tt $($rest:tt)*) => {
        let mut $var = parse!($src, $ty);
        input_inner!($src $($rest)*)
    };
    ($src:expr, $var:ident : $ty:tt $($rest:tt)*) => {
        let $var = parse!($src, $ty);
        input_inner!($src $($rest)*)
    };
}

#[allow(unused_macros)]
macro_rules! parse {
    ($src:expr, ( $($ty:tt),* )) => {
        ( $(parse!($src,$ty)),* )
    };
    ($src:expr, char) => {
        $src.next_chr()
    };
    ($src:expr, [ $ty:tt; $len:expr ]) => {
        (0..$len).map(|_| parse!($src,$ty)).collect::<Vec<_>>()
    };
    ($src:expr, $ty:tt) => {
        parse_str!($src,$ty)
    };
}

#[allow(unused_macros)]
macro_rules! parse_str {
    ($src:expr, chars) => {
        $src.next_str().chars().collect::<Vec<char>>()
    };
    ($src:expr, $ty:ty) => {
        $src.next_str().parse::<$ty>().expect("Parse error")
    };
}

fn main() {
    let mut src = from_stdin();
    input! { src;
             n: usize, m: usize,
             c: i32, b: [i32; m],
             testcases: [[i32; m]; n]
    }

    let res = testcases
        .iter()
        .filter(|t| {
            let v = t.iter().zip(b.iter()).fold(c, |x, (a, b)| x + a * b);
            v > 0
        })
        .count();

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


Measured memory_bytes: 4352
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return int(input())
from collections import defaultdict
import bisect

sys.setrecursionlimit(1000000000)

n = SI()
a_list = LI()

a_list =  sorted(a_list)
minus = bisect.bisect_left(a_list, 0)
minus_list = a_list[:minus]

plus_list = a_list[minus:]

ans = 0
p_i = 0
m_i = 0
if minus == 0:
    print(sum(plus_list) - 2*plus_list[0])
    minus_list = plus_list[0:1]
    plus_list = plus_list[1:]


elif minus == n:
    print(-sum(minus_list) + 2*minus_list[-1])
    plus_list = minus_list[-1:]
    minus_list = minus_list[:-1]

else:
    print(sum(plus_list) - sum(minus_list))

ans = minus_list[m_i]
m_i += 1
minus = len(minus_list)
plus = len(plus_list)


while p_i != (plus-1):
    print(ans, plus_list[p_i])
    ans = ans - plus_list[p_i]
    p_i += 1

print(plus_list[p_i], ans)
ans = plus_list[p_i] - ans

while m_i != minus:
    print(ans, minus_list[m_i])
    ans = ans - minus_list[m_i]
    m_i += 1


Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

int main()
{
    set<int> paper;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        if (paper.count(a))
            paper.erase(a);
        else
            paper.insert(a);
    }
    cout << paper.size() << endl;
    return 0;
}

Measured memory_bytes: 4864
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        k: usize,
        mut aabb: [(usize, usize); n]
    };
    aabb.sort_by_key(|ab| ab.0);
    let mut num_sum = 0;
    for (a, b) in aabb {
        if k <= num_sum + b {
            println!("{}", a);
            return;
        }
        num_sum += b;
    }
}


Measured memory_bytes: 5500
// HTTF.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define int LL
#define pb emplace_back
#define eb pb

using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 3010;
const int SIZE3 = 330;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;

#define endl "\n" //インタラクティブでは消す
ut N, M, K, L, Q, D, H, W;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], maps2[SIZE2][SIZE2], answer = zero;
LL maps[SIZE2][SIZE2];
LL DP[SIZE2][SIZE2];
bool finished[SIZE2][SIZE2];
LL A[SIZE];
LL sums[SIZE];
LL sum(LL x) {
	return sums[x];
}
LL sum(LL a, LL b) {
	return sum(b) - sum(a - 1);
}
LL solve2(LL a, LL b) {
	if (a == b) return 0;
	if (finished[a][b]) return DP[a][b];
	finished[a][b] = true;
	DP[a][b] = INF;
	FOR(i, a, b) {
		MN(DP[a][b], solve2(a, i) + solve2(i + 1, b) + sum(a, b));
	}
	return DP[a][b];
}
LL solve() {
	cin >> N;
	EFOR(i,1, N) cin >> A[i];
	EFOR(i, 1, N) sums[i] = sums[i - 1] + A[i];
	cout << solve2(1,N) << endl;
	return 0;
}




//!!!!!!!!!!!!!!!!!!!実装を詰める!!!!!!!!!!!!!!!!!!!!!!!!!
signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(12);
	solve();
	cin >> N;
	return 0;

}

Measured memory_bytes: 29952
/*
 * aoj/dpl_5_c/main.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

#define MOD 1000000007
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}
/* nCk */
template<class T> struct BiCoef {
    vector<T> fact_, inv_, finv_;
    constexpr BiCoef() {}
    constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
        init(n);
    }
    constexpr void init(int n) noexcept {
        fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
        for(int i = 2; i < n; i++){
            fact_[i] = fact_[i-1] * i;
            inv_[i] = -inv_[MOD%i] * (MOD/i);
            finv_[i] = finv_[i-1] * inv_[i];
        }
    }
    constexpr T com(int n, int k) const noexcept {
        if (n < k || n < 0 || k < 0) return 0;
        return fact_[n] * finv_[k] * finv_[n-k];
    }
    constexpr T fact(int n) const noexcept {
        if (n < 0) return 0;
        return fact_[n];
    }
    constexpr T inv(int n) const noexcept {
        if (n < 0) return 0;
        return inv_[n];
    }
    constexpr T finv(int n) const noexcept {
        if (n < 0) return 0;
        return finv_[n];
    }
};

// sum((-1)^(k-i)*kCi*i^n | for i in range(0, k+1))
int N, K;
BiCoef<mint> bc;
void solve() {
  cin >> N >> K;
  if (K > N) {
    cout << 0 << endl;
    return;
  }

  bc.init(1001);
  mint s = 0;
  for (int i=0; i<=K; i++) {
    mint sign = (K-i) % 2 == 1 ? -1 : 1;
    mint i_n = 1;
    loop(x,0,N) i_n *= i;
    s += sign * bc.com(K, i) * i_n;
  }
  cout << s << endl;
}

int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}



Measured memory_bytes: 3112
n,m=map(int,input().split())
a=[];b=[]
flag=False
for _ in range(n):
  a.append(list(input()))
for _ in range(m):
  b.append(list(input()))
for i in range(n-m+1):
  for j in range(n-m+1):
    c=[]
    for k in range(m):
      c.append(a[i+k][j:j+m])
    if c==b:
      flag=True
      break
print(['No','Yes'][flag])

Measured memory_bytes: 3064
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main{
   static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pw = new PrintWriter(System.out);
    static StringTokenizer st;
    
    static String next()
        {
            while(st==null || !st.hasMoreElements()) 
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
  
    static double calcAngle(double h, double m) 
    { 
        // validate the input 
        if (h <0 || m < 0 || h >12 || m > 60) 
            System.out.println("Wrong input"); 
  
        if (h == 12) 
            h = 0; 
        if (m == 60)  
            m = 0; 
  
        // Calculate the angles moved by hour and minute hands 
        // with reference to 12:00 
        double hour_angle = (double)(0.5 * (h*60 + m)); 
        double minute_angle = (double)(6*m); 
  
        // Find the difference between two angles 
        double angle = (double)Math.abs(hour_angle - minute_angle); 
  
        // smaller angle of two possible angles 
        angle = (double)Math.min(360-angle, angle); 
  
        return angle; 
    } 
  
    // Function to find third side 
    static double third_side(double a,  
                    double b, double c) 
    { 
        double angle =(double) Math.cos((double)Math.toRadians(c));
          
        return (double)Math.sqrt((a * a) + 
            (b * b) - 2 * a * b * angle); 
} 
  public static void main (String[] args) throws java.lang.Exception
   {
	try{
	   
		  double a=Double.parseDouble(next());
		  double b=Double.parseDouble(next());
		  double h=Double.parseDouble(next());
		  double m=Double.parseDouble(next());
		  
		  double angle=calcAngle(h,m);
		  double side=third_side(a,b,angle);
		  System.out.printf("%.20f",side);
		      
		      
		    
	   }     
	catch(Exception e)
		 {}
	}
}


Measured memory_bytes: 34644
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<unordered_map>
#include <iomanip>
typedef long long ll;
using namespace std;
#define MOD 998244353
int main(){
    string s,t;cin>>s>>t;
    vector<vector<ll>> alpha(26);
    for(ll i=0;i<s.size();i++){
        alpha[s[i]-'a'].push_back(i);
    }
    ll ind=0;
    ll size=s.size();
    for(int i=0;i<t.size();i++){
        int c=t[i]-'a';
        ll pos=ind%size+(i!=0);
        auto itr=lower_bound(alpha[c].begin(),alpha[c].end(),pos);
        //sの途中で見つかった場合
        if((itr!=alpha[t[i]-'a'].end())){
            ind=ind-(ind%size)+(*itr);
        }
        //sの途中では見つからなかった場合
        else{
            ind=(ind+size)/size*size;//sの次の反復へ
            auto hoge=lower_bound(alpha[c].begin(),alpha[c].end(),0);
            if(hoge==alpha[c].end()){
                cout<<-1<<endl;
                return 0;
            }
            else{
                ind+=*hoge;
            }
        }
    }
    cout<<ind+1<<endl;
}

Measured memory_bytes: 1724
a = gets.chomp
b = gets.chomp

res = true
table = {}

acs = {}
bcs = {}
a.chars.each { |c| acs[c] ||= 0; acs[c] += 1 }
b.chars.each { |c| bcs[c] ||= 0; bcs[c] += 1 }

sorted_acs = acs.sort_by { |i, j| j}
sorted_bcs = bcs.sort_by { |i, j| j}

sorted_acs.size.times do |i|
  if sorted_acs[i][1] != sorted_bcs[i][1]
    res = false
    break
  end
end

puts res ? "Yes" : "No"

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

typedef long long int lli;

int main(void)
{
	//freopen("A.in","r",stdin);
	//freopen("A.out","w",stdout);
	lli n,sum(0);
	cin >> n;
	while(n--)
	{
		lli l,r;
		cin >> l >> r;
		sum += (r-l+1);
	}
	cout << sum;
	return 0;
}

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

int main () {
  int N,M;
  cin >> N >> M;
  vector<int>k(M);
  vector<vector<int>> data(M, vector<int>(N));
  vector<int>p(M);
 
  for (int i = 0; i < M; i++) {
    cin >> k.at(i);
    for (int j = 0; j < k.at(i); j++) {
      cin >> data.at(i).at(j);
    }
  }
  
  for (int i = 0; i < M; i++) {
    cin >> p.at(i);
  }
  
  int sum = 0;

  // すべての選び方を試して、総和がKになるものがあるかを調べる
  for (int tmp = 0; tmp < (1 << 10); tmp++) {
    bitset<10> s(tmp);  // 最大20個なので20ビットのビット列として扱う
    
    if (N < 10 && s.test(N)) {
      break;
    }
    
    vector<int>A(M,0);

    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    
    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        for (int j = 0; j < M; j++) {
          for (int l = 0; l < k.at(j); l++) {
            if (data.at(j).at(l) == i+1){
              A.at(j)++;
              break;
            }
          }
        }
      }
    }
    for (int i = 0; i < M; i++) {
      if (A.at(i) % 2 != p.at(i)){
        break;
      }
      else if (i == M-1){
        sum++;
      }
    }
  }
  
  cout << sum << endl;
}

  

Measured memory_bytes: 3636
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long n = sc.nextLong();
        long k = sc.nextLong();

        double ans = 0;
        double invn = 1d / n;
        for(int i=1; i<=n; i++){
            long score = i;
            int count = 0;
            while(score < k){
                score <<= 1;
                count++;
            }
            ans += invn * (1d / (1 << count));
        }

        System.out.println(ans);
    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  int n;
  cin>>n;
  int flag=0;
  int c=0;
  int max=0;
  for(int i=0;i<n;i++){
  	int a,b;
  	cin>>a>>b;
  	if(!flag && a==b){
  		flag=1;
  	}
  	if(flag && a==b)
  		c++;
  	if(flag && a!=b){
  		flag=0;
  		if(c>max){
  			max=c;
  		}
  		c=0;
  	}
  }
  if(c>=max)
	max=c;
  if(max>=3)
	cout<<"Yes"<<endl;
  else
	cout<<"No"<<endl;
  return 0;   
}

Measured memory_bytes: 3664
# -*- coding: utf-8 -*-
import itertools

# スペース区切りの整数の入力
N,M = map(int, raw_input().split())
data=([],[],[])
for i in range(N):
	dd = map(int, raw_input().split())
	for i, x in enumerate(dd):
		data[i].append(x)

#print data
ret=-1
de=(1,-1)
for sx, sy, sz in itertools.product(de,de,de):
	d2=[sx*xi + sy*yi + sz *zi for xi,yi,zi in zip(data[0],data[1],data[2])]
	p=sorted(d2, reverse=True)
	r2= sum(p[0:M])
	
	ret=r2 if ret < r2 else ret
print ret


Measured memory_bytes: 2948
#include <cstdio>

int
main(void)
{
  long a, b, d, r;
  double f;

  std::scanf("%ld %ld", &a, &b);
  // a = 3;
  // b = 2;
  // a = 100000009;
  // b = 2;

  d = a / b;
  r = a % b;
  f = (double)a / (double)b;

  std::printf("%ld %ld %.5lf\n", d, r, f);

  return 0;
}



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

using namespace std;

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

    long ans = 0;
    int cnt = 1;
    for(int i=0; i<N; ++i){
        if(cnt != a[i]){
            ans++;
        }else{
            cnt++;
        }
    }

    if(cnt>1){
        cout<<ans<<endl;
    }else{
        cout<<-1<<endl;
    }

    return 0;
}




Measured memory_bytes: 1792
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys


def main():
    day = 0
    data = map(int,input().split())
    data = list(data)
    while( data[2] > 0):
        day = day +1
        data[2] -= data[0]
        if(day % 7 == 0):
            data[2] -= data[1]
    print(day)

if __name__ == '__main__':
    main()


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

int main(){
    int x,y;
    cin >> x >> y;
    vector<int> a = {0,1,3,1,2,1,2,1,1,2,1,2,1};
    if (a[x] == a[y]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

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

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll s, c;
	cin >> s >> c;

	ll res = 0;

	while (c > 1)
	{
		if (s == 0)
		{
			res += c / 4;
			c = 0;
		}
		else if (2 * s < c)
		{
			res += s;
			c -= 2 * s;
			s = 0;
			
		}
		else
		{
			res += c / 2;
			s -= c / 2;
			c = 0;
			
		}
	}

	println(res);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int[] arr = new int[n + 1];
        int[] mods = new int[300002];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        arr[n] = 300000;
        Arrays.sort(arr);
        for (int i = 0; i < n; i++) {
            mods[arr[i] + 1] = arr[i];
        }
        for (int i = arr[n - 1] + 1; i < 300002; i++) {
            mods[i] = arr[n - 1];
        }
        for (int i = 2; i <= arr[n - 1]; i++) {
            if (mods[i] == 0) {
                for (int j = 0; j < n; j++) {
                    mods[i] = Math.max(mods[i], arr[j] % i);
                    if (mods[i] == i - 1) {
                        break;
                    }
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            sb.append(mods[x]).append("\n");
        }
        System.out.print(sb);
    }
}



Measured memory_bytes: 125608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long data[105],sum; 
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&data[i]);
		if(i!=1)
		{
			data[i]=data[i]/__gcd(data[i],data[i-1])*data[i-1];
		}
		
	}printf("%lld",data[n]);
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return d;
}

int main(void) {

	lli k,sum = 0;
	cin >> k;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int m = 1; m <= k; m++) {
				//cerr << i << " " << j << " " << m << " " << gcd(gcd(i, j), m) << endl;
				sum += gcd(gcd(i,j),m);
			}
		}
	}

	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
    using namespace std;
         
    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long
    #define ld long double
    #define vll vector<long long>
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define F first
    #define S second
    #define pll pair<ll,ll> 
    #define G(a,b) get<a>(b)
    #define ALL(v) v.begin(),v.end()
    #define MP make_pair
    #define MT make_tuple
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
    #define endl "\n"
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;

    ll p=1e9+7;
      
    ll modpro(ll x,ll y,ll z=1)
    {
      x%=p;
      y%=p;
      z%=p;
      ll res=(x*y)%p;
      res=(res*z)%p;
      return res;
    }
     
    ll modadd(ll x,ll y,ll z=0)
    {
      x%=p;
      y%=p;
      z%=p;
      ll res=(x+y)%p;
      res=(res+z)%p;
      return res;
    }



    void func()
    {
       ll n;
       cin>>n;
       string s;
       cin>>s;
       ll cnt[26]={},ans=0;
       f(i,0,n)
       {
         ll temp=1;
         char ch='a';
         f(j,0,26)
         {
            if(ch!=s[i]) temp=modpro(temp,cnt[j]+1);
            ch++;
         }
         ans=modadd(ans,temp);
         cnt[s[i]-'a']++;
       }
       
       pr(ans) nl
    }     
     
     
    int main() 
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE
        
     
        ll ntc=1;
        //cin>>ntc;
     
        f(i,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";
          func();
        }
     
        return 0;
    }

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
//const ll p = 1e9 + 7;
//const ll p = 998244353;
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

ll bfs(ll n, vector<vll> &nx, ll s, ll t) {
	queue<ll> task;
	task.push(s);
	vector<bool> seen(n, false);
	seen[s] = true;
	ll depth = 1;
	while (task.size()) {
		ll sz = task.size();
		while (sz--) {
			for (ll i = 0; i < nx[task.front()].size(); i++) {
				if (nx[task.front()][i] == t) return depth;
				if (!seen[nx[task.front()][i]]) {
					task.push(nx[task.front()][i]);
					seen[nx[task.front()][i]] = true;
				}
			}
			task.pop();
		}
		depth++;
	}
	return -3;
}

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

	ll n, m;
	cin >> n >> m;

	auto index = [&] (ll i, ll x) {return i + x * n;};

	vector<vll> nx(3 * n, vll(0));
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		nx[index(u, 0)].push_back(index(v, 1));
		nx[index(u, 1)].push_back(index(v, 2));
		nx[index(u, 2)].push_back(index(v, 0));
	}

	ll s, t;
	cin >> s >> t;
	s--;
	t--;

	//index(s, 0) -> index(t, 0)の到達可否・最短距離を求める
	ll ans = bfs(3 * n, nx, index(s, 0), index(t, 0));
	cout << ans / 3 << endl;
}


Measured memory_bytes: 16640
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
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/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;
    cin>>n;
    vector<double>p(n);
    for(int i=0;i<n;i++)
        cin>>p[i];
    if(n==1){
        cout<<p[0]<<endl;
        return 0;
    }
    double dp[3004][3004];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    /*dp[3][3]=p[0]*p[1]*p[2];
    dp[3][2]=(1-p[0])*p[1]*p[2]+p[0]*(1-p[1])*p[2]+p[1]*p[0]*(1-p[2]);
    for(int i=3;i<n-1;i+=2){
        for(int j=(i+2)/2+1;j<=i+2;j++){
            for(int m=i/2+1;m<=i;m++){
                if(m>=j)
                    dp[i+2][j]+=dp[i][m];
                else if(m+2==j)
                    dp[i+2][j]+=p[i]*p[i+1]*dp[i][m];
                else if(m+1==j)
                    dp[i+2][j]+=((p[i]*(1-p[i+1])+(1-p[i])*p[i+1])+p[i]*p[i+1])*dp[i][m];
            }
        }
    }*/
    for(int i=0;i<n;i++){
        for(int j=0;j<=n;j++){
            if(j==0)
                dp[i+1][j]=dp[i][j]*(1-p[i]);
            else
                dp[i+1][j]=dp[i][j]*(1-p[i])+dp[i][j-1]*p[i];
        }
    }
    double ans=0;
    for(int j=n/2+1;j<=n;j++)
        ans+=dp[n][j];
    printf("%.10lf\n",ans);
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------




Measured memory_bytes: 70784
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

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

	string S;
	cin >> S;
	int n = S.length();

	VI A('z' - 'a' + 1, 0);
	if(n < 26){
		EACH(c, S) A[c - 'a'] = 1;
		cout << S;
		for(int i = 0; i < A.size(); i++){
			if(A[i] == 0){
				cout << char('a' + i) << endl;
				return 0;
			}
		}
	}

	for(int i = n - 1; 0 <= i; i--){
		A[S[i] - 'a'] = 1;
		FOR(j, S[i] - 'a' + 1, A.size()){
			if(A[j] == 1){
				cout << S.substr(0, i) + char('a' + j) << endl;
				return 0;
			}
		}
	}

	cout << -1 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n) for(int i=0;i<(int)(n);i++)
#define repd(i,n) for(int i=(int)(n);i>=0;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

int main()
{
    long X,Y;
    cin >> X >> Y;
    long A = X;
    int cnt=0;
    while(A<=Y){
        cnt++;
        A*=2;
    }
    cout << cnt << endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 3e5 + 5;

int v[MAXN];

set<pii> st1, st2, st3;

vector<pii> pp;

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, 3 * n) {
		scanf("%d", &v[i]);
	}
	ll v1 = 0ll;
	REP(i, 0, n) {
		st1.insert(mp(v[i], i));
		v1 += v[i];
	}
	REP(i, n, 3 * n) {
		pp.pb(mp(v[i], i));
	}
	SORT(pp);
	ll v2 = 0ll;
	REP(i, 0, n) {
		st2.insert(pp[i]);
		v2 += pp[i]._1;
		st3.insert(pp[i + n]);
	}
	ll ans = v1 - v2;
	REP(i, n, 2 * n) {
		v1 += v[i];
		st1.insert(mp(v[i], i));
		v1 -= st1.begin()->_1;
		st1.erase(st1.begin());
		
		if (st3.find(mp(v[i], i)) != st3.end()) {
			st3.erase(mp(v[i], i));
		} else {
			v2 -= v[i];
			st2.erase(mp(v[i], i));
			
			int ind = st3.begin()->_2;
			v2 += v[ind];
			st3.erase(st3.begin());
			st2.insert(mp(v[ind], ind));
		}
		
		ans = max(ans, v1 - v2);
	}
	printf("%lld\n", ans);
	
}

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 17012
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
LL A,B,C,D;
LL f(LL N){
    return N-N/C-N/D+N/(C/__gcd(C,D)*D);
}
int main(){
    R(A,B,C,D);
    W(f(B)-f(A-1));
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace ::std;
 
#define all(x)  x.begin(),x.end()
#define Unique(x) x.erase(unique(x.begin(), x.end()), x.end())

template< class T > T SQR(T N) {return (T) N * N;}
template< class T > double DIST(T a, T b) {return 1.0 * sqrt(SQR(double(a)) + SQR(double(b)));}
template< class T > bool CROSS(pair< T,T > a, pair< T,T > b, pair< T,T > c) {return (b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first);}
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int,int > pi;
 
int px[] = {0, 1, -1, 0, -1, -1, 1};
int py[] = {1, 0, 0, -1, -1, 0, -1, -1};

const double eps = 1e-9;
 
inline ll power(ll a, ll p, ll mod)
{
    ll x = a, res = 1;
 
    while(p)
    {
        if(p&1) res = (res * x)%mod;
        p /= 2, x = (x * x)%mod;
    }
    return res;
}

int main()
{
    int n, m, c, d, a, b, k;
 
    int test;
 
    // scanf("%d", &test);
    // while(test--)
    // {
        scanf("%d", &n);
        int in[n];

        for(int i = 0; i<n; ++i)
            scanf("%d", &in[i]);

        sort(in, in + n);

        ll x = in[n - 1];

        c = 2;
        for(int i = n - 2; c < n; --i)
        {
            if(n - c >= 2)
                x += 2LL * in[i], c += 2;
            else if(n - c >= 1)
                x += 1LL * in[i], c++;
        }

        printf("%lld\n", x);
        
    //}
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int a[200500];
int main(){
	int n; cin >> n;
	for( int i = 2; i <= n; ++i ){
		int t; cin >> t;
		++a[t];
	}
	for( int i = 1; i <= n; ++i ) cout << a[i] << endl;
}

Measured memory_bytes: 4376
def main():
    ans = 0
    n = int(input())
    A = [int(i) for i in input().split()]+[10**9]

    Sum = 0
    right = 0
    for left in range(n):
        while(right<n):
            if Sum^A[right]  == Sum+A[right]:
                Sum += A[right]
                right += 1
            else:
                break
        ans += right-left
        if left==right:
            right +=1
        else:
            Sum -= A[left]
    print(ans)
main()

Measured memory_bytes: 30732
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(S: str):
    return 7 - ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'].index(S)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    print(f'{solve(S)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 70404
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	vector<int> apple(N);

	int pie = 0;
	REP(i, N) {
		apple[i] = L + i;
		pie += apple[i];
	}

	int min_diff = 1e9;
	int pie2 = 0;
	REP(i, N) {
		if (min_diff > abs(apple[i])) {
			min_diff = abs(apple[i]);
			pie2 = pie - apple[i];
		}
	}

	cout << pie2 << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
x = [None]*N
y = [None]*N
h = [None]*N

for i in range(N):
    x[i],y[i],h[i] = map(int, input().split())

def height(X,Y,xn,yn,hn):
    return hn+abs(X-xn)+abs(Y-yn)

def check(x,y,h,X,Y,H):
    for n in range(N):
        if h[n]>0:
            if height(X,Y,x[n],y[n],h[n])!=H:
                return False
        elif H-abs(X-x[n])-abs(Y-y[n])>0:
            return False
    return True

for X in range(101):
    for Y in range(101):
        for n in range(N):
            if h[n]>0:
                H = height(X,Y,x[n],y[n],h[n])
                if check(x,y,h,X,Y,H) is True:
                    print(X,Y,H)
                    exit()


Measured memory_bytes: 3064
N = int(input())
A = [int(s) for s in input().split()]
evenA = [i for i in A if i%2 == 0]
flg = True
for i in evenA:
  if i%3 != 0 and i%5 != 0:
    flg = False
if flg:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
	string s[3];
	int A[3], B[3], i, j;
	bool f;
	while (1)
	{
		for (i = f = 0; i < 3; i++)
		{
			cin >> s[i];
			if (s[i] == "0")
			{
				f = true;
				break;
			}
		}
		if (f) break;

		for (i = 0; i < 3; i++)
		{
			A[i] = B[i] = 0;
			for (j = 1; j < s[i].length(); j++)
			{
				if (s[i][j] == 'A')
					A[i]++;
				else
					B[i]++;
			}
			if (i < 2 && s[i+1][0] == 'A')
				A[i]++;
			else
				B[i]++;
		}
		if (A[2] >= 10 && B[2] >= 10)
		{
			if (A[2] - B[2] == 1)
				A[2]++;
			else if (B[2] - A[2] == 1)
				B[2]++;
		}
		else if (A[2] == 10)
			A[2]++, B[2]--;
		else if (B[2] == 10)
			B[2]++, A[2]--;
		cout << A[0] << " " << B[0] << endl;
		cout << A[1] << " " << B[1] << endl;
		cout << A[2] << " " << B[2] << endl;
	}
	return 0;
}

Measured memory_bytes: 0