akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <sstream>
#include <bitset>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
#define MOD ((int)1e9+7)
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

struct Combination {
	const int num=51e4;			//要素数
	const int mod=1e9+7;
	vector<ll> fact,inv,finv; //階乗,逆元,逆元の階乗.
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){ //nが大きいとき
		ll res=1LL;
		for (int i = 0; i < k; i++) {
			res=res*(n-i)%mod;
		}
		res = res*finv[k]%mod;
		return res;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

ll pow_mod(ll n, ll k, ll p) { // n^k(mod p)
	if (k == 0) {
		return 1;
	}
	ll res = pow_mod(n * n % p, k / 2, p);
	if (k & 1) {
		res = res * n % p;
	}
	return res;
}

bool vector_finder(std::vector<int> vec, int number) { // vector 内にnumberがあるかどうか
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance( vec.begin(), itr );
	if (index != vec.size()) { // 発見できたとき
		return true;
	}
	else { // 発見できなかったとき
		return false;
	}
}

int main() {
	int n, y;
	cin >> n >> y;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n - i; j++) {
			int k = n - i - j;
			if ((10000*i + 5000*j + 1000*k) == y) {
				return cout << i << " " << j << " " << k << endl, 0;
			}
		}
	}
	return cout << "-1 -1 -1\n", 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl

int main() {
    IN(int, n);
    ll sum = 0;
    REPS(i, n){
        if ((i%3 != 0)&&(i%5 != 0)) {
            sum += i;
        }
    }
    COUT(sum);
}




Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main()
{
	string s;
	string t;
	cin >> s;
	t = s;
	char s_old=s[0];
	int s_count = 0;
	char t_old=t[0];
	int t_count = 0;
	REP(i, (int)s.length())
	{
		if(t[0]=='1'){
			t[0] = '0';
			t_count++;
			t_old = '0';
		}
		if(i!=0){
			if(t_old=='0'&&t[i]=='0'){
			t[i] = '1';
			t_count++;
			t_old = '1';
			}
			else if(t_old=='1'&&t[i]=='1'){
			t[i] = '0';
			t_count++;
			t_old = '0';
			}
			else{
				t_old = t[i];
			}
		}

		if(s[0]=='0'){
			s[0] = '1';
			s_count++;
			s_old = '1';
		}
		if(i!=0){
			if(s_old=='0'&&s[i]=='0'){
			s[i] = '1';
			s_count++;
			s_old = '1';
			}
			else if(s_old=='1'&&s[i]=='1'){
			s[i] = '0';
			s_count++;
			s_old = '0';
			}
			else{
			s_old = s[i];
			}
		}

		
	}
	cout << min(s_count, t_count) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int dp[100005];
vector<vector<int>> g;
int calc(int u)
{
    if(dp[u] != -1)
        return dp[u];

    dp[u] = 0;
    for (int i = 0; i < g[u].size(); ++i) {
        dp[u] = max(dp[u], calc(g[u][i])+1);
    }

    return dp[u];

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

    memset(dp, -1, sizeof(dp));

    int n, m; cin >> n >> m;
    g.resize(n+1);
    for (int i = 0; i < m; ++i) {
        int x, y; cin >> x >> y;
        g[x].push_back(y);
    }
    for (int i = 1; i <= n; ++i) {
        g[0].push_back(i);
    }

    cout << calc(0) - 1 << endl;
    return 0;
}

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

int main() {
  
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for(int i = 0; i <n; i++){
    cout << s.at(i) << t.at(i);
  }
  cout << endl;
  
  
}



Measured memory_bytes: 3576
#include <stdio.h>
#include <unordered_map>
 
using namespace std;
 
#define N 110000
 
typedef long long ll;
 
ll a[N], pre[N];
 
int main() {
    unordered_map<ll, ll> ma;
    ll n, m; scanf("%lld%lld", &n, &m);
    ll sum = 0, tot = 0; pre[0] = 0;
    for (ll i = 1; i <= n; ++i) {
        scanf("%lld", &a[i]);
        pre[i] = (pre[i - 1] + a[i]) % m;
    }
    for (int i = 0; i <= n; ++i) {
        if (ma[pre[i]]) sum += ma[pre[i]];
        ma[pre[i]]++;
    }
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 5260
#include <iostream>
    #include <math.h>
    #include <vector>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    using namespace std;

int main() {

    int n,k;cin>>n>>k;
    if(n%k !=0) cout<<1<<endl;
    else cout<<0<<endl;
    return 0;   

}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! printvec {
    ( $item:expr ) => {
        for &i in &$item {
            print!("{} ", i);
        }
        println!("");
    }
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
#[derive(PartialEq, PartialOrd, Clone, Debug)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        a: char, b: char,
    }
    if (a == 'H' && b == 'H') ||(a == 'D' && b == 'D') {
        println!("H");
    } else {
        println!("D");
    }
}

Measured memory_bytes: 4352
//=====================COMPILER OPTIMIZATION STARTS=======================
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//======================COMPILER OPTIMIZATION ENDS=======================

//compile using : g++ -D DEB file.cpp
#ifdef DEB
    //to check from out of bounds errors
    #define _GLIBCXX_DEBUG
#endif
//=============================DEBUG PART ENDS===========================

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

#define ll long long int
#define pi pair<ll,ll>

ll power(ll x, ll y, ll mod = 1e9+7){
    ll res = 1;
    while(y > 0){
        if(y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x*x)% mod;
    }
    return res % mod;
}

void solve(){
    int n;  cin >> n;
    if (n == 3 || n == 5 || n == 7)
        cout << "YES\n";
    else 
        cout << "NO\n";
}

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

    int test = 1;
    // cin >> test;
    while(test--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

/*
    ここに問題名を入力
*/

int main() {
    int q; cin >> q;
    deque<int> a;

    rep(i,q){
        int q_; cin >> q_;
        if(q_ == 0){
            int d, x; cin >> d >> x;
            if(d == 0){
                a.push_front(x);
            }else{
                a.push_back(x);
            }
        }else if(q_ == 1){
            int p; cin >> p;
            cout << a[p] << endl;
        }else{
            int d; cin >> d;
            if(d == 0){
                a.pop_front();
            }else{
                a.pop_back();
            }
        }
    }


    return 0;
}
 
 



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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;

int main(int argc, char const *argv[])
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		putchar('A');
		putchar('C');
		putchar('L');
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 3688
#include <iostream>

using namespace std;

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

    int max_count = 0;
    int max_num = 1;
    for (int i = 1; i <= n; ++i) {
        int count = 0;
        int ii = i;
        while (ii > 0 && ii % 2 == 0) {
            ++count;
            ii >>= 1;
        }

        if (max_count < count) {
            max_num = i;
            max_count = count;
        }
    }
    cout << max_num << '\n';
}


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

int main() {
  int n; cin >> n;
  int ans;
  for (int i = 1000; i<=10000; i+=1000) {
    ans = i - n;
    if (ans >= 0) break;
  }
  cout << ans << endl;
  return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
long long calc(long long A) {
  long long cnt = (A+1) / 2;
  long long ans = cnt % 2;
  if(A%2==0) ans ^= A;
  return ans;
}

int main() {
  long long A, B; cin >> A >> B;
  long long ans = calc(B) ^ calc(A-1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=310;
int n,m,a[N][N];
#define pr pair<int,int> 
pr rnk[N];
bool v[N];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
        rnk[i].second=i;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            scanf("%d",&a[i][j]);
            if(j==1) rnk[a[i][j]].first--;
        }
    int cnt=0,ans=1e9;
    while(cnt<m){
        sort(rnk+1,rnk+m+1);
        ans=min(ans,-rnk[1].first);
        v[rnk[1].second]=true;
        memset(rnk,0,sizeof(rnk));
        for(int i=1;i<=m;i++)
            rnk[i].second=i;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                if(!v[a[i][j]]){
                    rnk[a[i][j]].first--;
                    break;
                }
        cnt++;
    }
    printf("%d",ans);
}


Measured memory_bytes: 640
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]

loves = {}
for i in range(N):
    for j in range(1, A[i][0]+1):
        love = A[i][j]
        if love in loves:
            loves[love] += 1
        else:
            loves[love] = 1

print( len(list(filter( lambda x: loves[x] == N, loves ))))


Measured memory_bytes: 3060
using System;

namespace abc043_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string x = "";
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'B')
                {
                    if (!string.IsNullOrEmpty(x))
                    {
                        x = x.Substring(0, x.Length - 1);
                    }
                }
                else
                {
                    x += s[i];
                }
            }
            Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 2648
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <tuple>
 
using namespace std;
 
template<typename E>
using Matrix = std::vector<std::vector<E> >;
 
typedef long long LL;
typedef long double LD;
typedef std::pair<LL ,LL> LP;
 
#define INF		1e9
#define EPS		1e-9
#define gcd 	__gcd
#define make_matrix(rows, col, type, default) 			\
					std::vector< std::vector<type> >( 	\
						rows 						  	\
						std::vector<type>(col, default) \
					);
 
#define repeat(n)	for(LL __x = 0; __x < n; __x++)
#define watch(x)	cout << (#x) << " is " << (x) << "\n";
#define DEG_TO_RAD(x) (x * PI / 180.0)
#define RAD_TO_DEG(x) (x * 180.0 / PI)

auto cost(LL i, LL j) -> LL {
    return abs(i-j);
}

auto main() -> int {
    LL n, k, t, cm;

    std::vector<LL> memo;
    std::vector<LL> rocks; // rock height

    std::cin >> n >> k;
    for(LL i = 0; i < n; i++) {
        std::cin >> t;
        rocks.push_back(t);
        if(i == 0) { memo.push_back(0); }
        else {
            cm = memo[i-1] + cost(rocks[i], rocks[i-1]);
            for(LL j = i-2; j >= 0 && j >= i-k; j--)
                cm = min(cm, memo[j] + cost(rocks[i], rocks[j]));
            memo.push_back(cm);
        }
    }
    std::cout << memo[n-1];
}

Measured memory_bytes: 2036
#include "bits/stdc++.h"
using namespace std;

int a[200000];
int b[200000];
int imos[200002];
int ruia[200002]; //a[i]の累積和（200000から取る）
int ruib[200002]; //b[i]の累積和（0から取る）
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	fill(imos,imos+200002,0);
	fill(ruia,ruia+200002,0);
	fill(ruib,ruib+200002,0);
	for(int i=0;i<n;i++)
	{
		imos[a[i]]++;
		imos[b[i]]--;
		ruia[a[i]]++;
		ruib[b[i]]++;
	}
	for(int i=1;i<200002;i++)
	{
		imos[i]+=imos[i-1];
		ruib[i]+=ruib[i-1];
		ruia[200001-i]+=ruia[200001-i+1];
	}
	int ans1=-1;
	int ans2=-1;
	for(int i=1;i<200001;i++)
		ans2=max(ans2,imos[i]);
	for(int i=0;i<n;i++)
		ans1=max(ans1,n-ruia[b[i]]-ruib[a[i]]);
	cout<<ans1<<" "<<ans2<<endl;
	return 0;
}


Measured memory_bytes: 7008
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b, h; cin >> a >> b >> h;

    cout << (a+b) * h/2 << endl;
}

Measured memory_bytes: 256
// In the Name of Allah. Ya Ali!
#include<bits/stdc++.h>
typedef long long ll;
const ll MAX_N = 2e5+100;
const ll MOD = 1e9+7;
using namespace std;

vector<int> l[MAX_N];
vector<int> r[MAX_N];
pair<int,int> lr[MAX_N];
ll dp[MAX_N];
ll mx[MAX_N*4];
ll fl[MAX_N*4];
ll a[MAX_N];
int n,m,y;

void update(int k)
{
    int l = k*2;
    int r = l+1;
    mx[k] = max(mx[l],mx[r]);
}

void shift(int k)
{
    int l = k*2;
    int r = l+1;
    fl[l]+=fl[k];
    fl[r]+=fl[k];
    mx[l]+=fl[k];
    mx[r]+=fl[k];
    fl[k] = 0;
}

void add(int l,int r,int a,int b,int k,ll d)
{
    if (r<a or b<l)
        return;
    if (a<=l and r<=b)
    {
        mx[k]+=d;
        fl[k]+=d;
        return;
    }
    int mid = (l+r)/2;
    shift(k);
    add(l,mid,a,b,k*2,d);
    add(mid+1,r,a,b,k*2+1,d);
    update(k);
}

ll ask(int l,int r,int a,int b,int k)
{
    if (r<a or b<l)
        return (-1e18);
    if (a<=l and r<=b)
        return mx[k];
    int mid = (l+r)/2;
    shift(k);
    return max(ask(l,mid,a,b,k*2),ask(mid+1,r,a,b,k*2+1));
}

int main()
{
    cin >> n >> m;
    for(int i = 1;i<=m;++i)
    {
        cin >> lr[i].first >> lr[i].second >> a[i];
        l[lr[i].first].push_back(i);
        r[lr[i].second].push_back(i);
    }
    y = (1<<((int)ceil(log2(n+10))));
    for(int i = 1;i<=n;++i)
    {
        ll sum = 0;
        for(auto x:l[i])
            sum+=a[x];
        dp[i] = ask(0,y-1,0,i-1,1)+sum;
        add(0,y-1,0,i-1,1,sum);
        add(0,y-1,i,i,1,dp[i]);
        for(auto x:r[i])
            add(0,y-1,0,lr[x].first-1,1,-a[x]);
    }
    ll ans = 0;
    for(int i = 1;i<=n;++i)
        ans = max(ans,dp[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 39296
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define N	    100001
#define rep(i,a,b)  for(int i=a;i<b;i++)
typedef long long ll;
void self_max(int &a, int b) {
	a = max(a, b);
}
int main() {
	int n, m;
	cin>>n>>m;
	char s[n + 1][m + 1];
	int dp[n + 1][m + 1];
	memset(dp, 0, sizeof(dp));
	rep(i, 1, n + 1)
		rep(j, 1, m + 1)
			cin>>s[i][j];
	rep(i, 1, n + 1) {
		rep(j, 1, m + 1){
			if(i == 1 && j == 1) {
				dp[i][j] = 1;
			}
			else if(s[i][j] != '#')
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % hell;
		}
	}
	cout<<dp[n][m]<<endl;
}



Measured memory_bytes: 5120
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    const correct = "CODEFESTIVAL2016".split("");
    
    let answer = 0;
    
    for(let i in S) {
        if(S[i] !== correct[i]) {
            answer++;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main(void){
	double v,t;
	double y;
	int ans;
	while(1){
		cin>>v;
		if(cin.eof()==1)	break;
		t=v/9.8;
		y=4.9*pow(t,2);
		y+=5;
		if(fmod(y,5.0)!=0){
			y/=5;
			y++;
		}
		else	y/=5;
		ans=y;
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    string s;
    int w;
    cin >> s >> w;
    rep (i, s.size()) {
        if (i % w == 0)cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int min(a,b){        //min関数を定義
  if (a<b) return a;
  else return b;
}

int main(){
  int n,x,m;
  int minimum=1000;
  scanf("%d%d",&n,&x);
  for(int i=0;i<n;i++){
    scanf("%d",&m);
    x -= m;                    //i番目のお菓子必ず一個は作るのでxから引く
    minimum = min(minimum,m);  //一番コストのかからないお菓子を覚えておく
  }
  printf("%d",n+x/minimum);
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

string S;
int dp[2][100100];
const int mod = 1000000007;

signed main() {
    cin >> S;
    dp[0][0] = 2;
    dp[1][0] = 1;
    for (int i = 1; i < S.length(); ++i) {
        if (S[i] == '1') {
            dp[0][i] = dp[0][i - 1] * 2;
            dp[1][i] = dp[1][i - 1] * 3 + dp[0][i - 1];
        } else if (S[i] == '0') {
            dp[0][i] = dp[0][i - 1];
            dp[1][i] = dp[1][i - 1] * 3;
        }
        dp[0][i] %= mod;
        dp[1][i] %= mod;
    }
    int ans = dp[0][S.length() - 1] + dp[1][S.length() - 1];
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2048
using System;
namespace _0219
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] kosuu = new int[10];
                int kaisuu = int.Parse(Console.ReadLine());
                if (kaisuu == 0)
                {
                    break;
                }
                for (int i = 0; i < kaisuu; i++)
                {
                    kosuu[int.Parse(Console.ReadLine())]++;
                }
                for (int i = 0; i < 10; i++)
                {
                    if (kosuu[i] == 0)
                    {
                        Console.WriteLine("-");
                    }
                    else
                    {
                        for (int I = 0; I < kosuu[i]; I++)
                        {
                            Console.Write("*");
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 8916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int e=0,o=0;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(a%2) o++;
    else e++; 
  }
  while(1){
    int a=e/2,b=o/2;
    //cout<<e<< " "<<o<<endl;
    e-=a*2;
    o-=b*2;
    e+=a+b;
    if(!a&&!b) break;
  }
  //cout<<e<< " "<<o<<endl;
  cout<<(e+o==1?"YES":"NO")<<endl;
  return 0;
}


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

int main(){ 
  
  int X; cin >> X;
  
  int B = X%100;
  
  int a = B/5; //105をこれだけ買う
  int b = 0;
  if( B%5 > 0){ b++;}  //余りがあったら、追加で買う
  
  X -= 105*a+100*b+B%5;
  
  if( X < 0){ cout << "0" << endl;}
  else{ cout << "1" << endl;}
  
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
const int INF=1000000000;
const int MAX_N=55;
const int MAX_M=55;
typedef pair<int,int> P;
char maze[MAX_N][MAX_N+1];
int N,M;
int sx,sy;
int gx,gy;
int d[MAX_N][MAX_N];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int bfs(){
  cin>>N>>M;
  int count =0;
  sx=0;
  sy=0;
  gx=N-1;
  gy=M-1;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin>>maze[i][j];
      
      /*if(maze[i][j]=='S'){
        sx=i;
        sy=j;
      }else if(maze[i][j]=='G'){
        gx=i;
        gy=j;
      }*/
      if(maze[i][j]=='.')count++;
    }
  }
  if(maze[0][0]=='#'){
    return -1;
  }
  if(maze[N-1][M-1]=='#'){
    return -1;
  }
  queue<P>que;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      d[i][j]=INF;
    }
  }
  que.push(P(sx,sy));
  d[sx][sy]=0;
  while(que.size()){
    P p=que.front();que.pop();
    if(p.first==gx&&p.second==gy)break;
    for(int i=0;i<4;i++){
      int nx=p.first+dx[i],ny=p.second+dy[i];
      if(0<=nx&&nx<N&&0<=ny&&ny<M&&maze[nx][ny]!='#'&&d[nx][ny]==INF){
        que.push(P(nx,ny));
        d[nx][ny]=d[p.first][p.second]+1;
      }
    }
  }
  return count-(d[gx][gy]+1);
}
int main(){
  ll kotae=bfs();
  if(kotae>=0)cout<<kotae;
  else cout<<-1;
  return 0;
}

Measured memory_bytes: 3608
package main

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

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInts() (int,int) {
  var x,y int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  return x,y
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}

func main() {
  const mod int64 = 1000000007
  var n,m int = NextInts()
  var x []int = NextIntArray()
  var y []int = NextIntArray()
  var a,b,s,t int64
  for i:=0;i<n;i++ {
    s = int64(2*i-n+1)
    for s < 0 { s += mod }
    t = int64(x[i])
    for t < 0 { t += mod }
    a += (s%mod)*(t%mod)
    a %= mod
  }
  for i:=0;i<m;i++ {
    s = int64(2*i-m+1)
    for s < 0 { s += mod }
    t = int64(y[i])
    for t < 0 { t += mod }
    b += (s%mod)*(t%mod)
    b %= mod
  }
  fmt.Println((a*b)%mod)
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)
#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(V.begin(),V.end(),c))

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    string S;
    cin >>S;
    int N=S.size();
    int ans=0;
    rep(i,N/2){
        if(S[i]!=S[N-1-i])ans++;
    }
    
    cout << ans <<endl;
    return (0);
}

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

#define int long long

main()
{
  string s;
  int cnt = 0;
  int ans = 0;
  
  cin >> s;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'S') {
      cnt++;
    } else if(cnt > 0) {
      cnt--;
      ans++;
    }
  }

  cout << s.size() - ans * 2 << endl;

  return (0);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} cout << endl;
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

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

    rep(i, n) {
        int d = 'z' - s[i] + 1;
        if (s[i] != 'a' && k >= d) {
            s[i] = 'a';
            k -= d;
        }
    }
    s.back() = (s.back() - 'a' + k) % 26 + 'a';
    cout << s << endl;
}


Measured memory_bytes: 592
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[10^^5+1] MEMO;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (_; 0..M) {
        auto lr = readln.split.to!(int[]);
        auto L = lr[0]-1;
        auto R = lr[1]-1;
        MEMO[L] += 1;
        MEMO[R+1] -= 1;
    }

    int c, r;
    foreach (i; 0..N) {
        c += MEMO[i];
        if (c == M) ++r;
    }
    writeln(r);
}

Measured memory_bytes: 1660
#include <stdio.h>
#include <string.h>
#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define N 100000
void yes_or_no(char boolean){
    if(boolean){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}

int main(){
    char S[N];
    scanf("%s", S);
    unsigned int i, len = strlen(S), ANS = 0;

    REP(i, len - 1){
        if(S[i] != S[i + 1]){
            ANS++;
        }
    }
    printf("%d\n", ANS);
    return 0;
}

Measured memory_bytes: 256
while l = gets
    a = l.split(",").map(&:to_i).sort
    g = a.group_by(&:itself)
    g = a.group_by(&:itself).values.map(&:size).sort
    if g == [1, 4]
        puts 'four card'
    elsif g == [2, 3]
        puts 'full house'
    elsif a == (a.min..a.max).to_a or a == [1] + (10..13).to_a
        puts 'straight'
    elsif g == [1, 1, 3]
        puts 'three card'
    elsif g == [1, 2, 2]
        puts 'two pair'
    elsif g == [1, 1, 1, 2]
        puts 'one pair'
    else
        puts 'null'
    end
end



Measured memory_bytes: 6884
#include <iostream>
using namespace std;
int main(){
	int h[10],one=0,two=0,three=0;
	for(int i=0;i<10;i++){
		cin>>h[i];
		if(three<h[i]){
			if(two<=h[i]){
				if(one<=h[i]){
					three=two;
					two=one;
					one=h[i];
				}else{
					three=two;
					two=h[i];
				}
			}else{
				three=h[i];
			}
		}
	}
	cout<<one<<endl<<two<<endl<<three<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;
#define endl '\n'

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (auto& x : a) cin >> x;
    
    unordered_map<ll, ll> cnt;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cnt[i+a[i]]++;
        ans+= cnt[i-a[i]];
    }
    cout << ans << endl;
}


Measured memory_bytes: 20136
#[1,2,...,N]の差配列は[1,1,...,-N+1]である
N=int(input())
A=list(map(int,input().split()))
oneton=(N*(N+1))//2
flag=1
allsum=sum(A)
dif=[]
for i in range(N):
    dif.append(A[(i+1)%N]-A[i%N])#1つ前の数字と比べどれだけ差があるかの配列
#print(dif)
#print(allsum,oneton)
if allsum%oneton!=0:
    flag=0
else:
    opnum=allsum//oneton        #[1~N]のsequenceを何こ使っているか
    l=[opnum]*N                 #差配列を、全て等しく1ずつ(sequence数)回増えたと考え、[(sequence数)]*Nで初期化
    #print(l)
    for i in range(N):
        if l[i]<dif[i]:         #sequence数以上の差が出るのはどう頑張っても無理
            flag=0
            break
        else:                   #l[i]>=dif[i]ということは+1の差を期待した部分がいくつか-N+1になっているということである
            diff=l[i]-dif[i]    #よって(期待しているやつ)-(現実)をして
            useminus=diff//N    #それをNで割り捨てることで、+1→-N+1にする回数を求められる
            opnum=opnum-useminus
            l[i]=l[i]-(useminus*N)
    if opnum!=0:                    #-Nの操作を仕切れてないとダメ
        flag=0
    for i in range(N):              #-Nの操作を仕切った結果ズレててもダメ
        if l[i]!=dif[i]:
            flag=0
if flag==0:
    print("NO")
else:
    print("YES")




Measured memory_bytes: 64412
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    A = LI()
    
    return 'Yes' if len(set(A)) == 1 else 'No'


print(main())


Measured memory_bytes: 3064
n = int(input())
txy = [list(map(int, input().split())) for i in range(n)]

x = 0
y = 0
t = 0
for i in range(n):
    sub = abs(txy[i][1] - x) + abs(txy[i][2] - y)
    if txy[i][0] - t < sub:
        print("No")
        exit()
    if txy[i][0] - t != sub:
        if (txy[i][0] - t) % 2 == 0:
            if sub % 2 != 0:
                print("No")
                exit()
        else:
            if sub % 2 != 1:
                print("No")
                exit()

    t = txy[i][0]
    x = txy[i][1]
    y = txy[i][2]

print("Yes")

Measured memory_bytes: 27380
/*
 * main.c
 *
 *  Created on: 2020/02/22
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}


int main()
{
	int A = 0, B = 0;
	int a = 0, b = 0, ans = 0;
	double m = 0;
	scanf("%d %d", &A, &B);
	while (1) {
		a = m * 0.08;
		b = m * 0.1;
		if ((A == a) && (B == b)) {
			ans = (int)m;
			break;
		}
		if ((A < a) && (B < b)) {
			ans = -1;
			break;
		}
		m += 1.0;
	}
	printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define inf 1000000000
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef map<int,int> mii;
int main()
{
    int n,h;
    scanf("%d",&n);
    h=(n/500)*1000;
    n%=500;
    h+=(n/5)*5;
    printf("%d",h);
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#define mod 1000000007
#define MN 201000

int n, a, b, c;
int fac[MN], inv[MN];

int qpow(int x, int p)
{
	int ans = 1;
	while(p)
	{
		if(p & 1) ans = 1ll * ans * x % mod;
		x = 1ll * x * x % mod; p >>= 1;
	}
	return ans;
}

int C(int a, int b) {return 1ll * fac[a] * inv[b] % mod * inv[a - b] % mod;}

int main()
{
	scanf("%d%d%d%d", &n, &a, &b, &c);

	int N = 2 * n; fac[0] = 1;
	for(int i = 1; i <= N; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[N] = qpow(fac[N], mod - 2);
	for(int i = N - 1; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;

	int P = qpow(a + b, mod - 2);
	a = 1ll * a * P % mod;
	b = 1ll * b * P % mod;
	int w = 100ll * qpow(100 - c, mod - 2) % mod;
	
	int ans = 0;
	for(int i = n; i < N; i++)
	{
		int p1 = 1ll * qpow(a, n) * qpow(b, i - n) % mod;
		ans = (ans + 1ll * p1 * C(i - 1, n - 1) % mod * i) % mod;
		
		int p2 = 1ll * qpow(a, i - n) * qpow(b, n) % mod;
		ans = (ans + 1ll * p2 * C(i - 1, n - 1) % mod * i) % mod;
	}
	
	printf("%lld\n", 1ll * ans * w % mod);
} 

Measured memory_bytes: 1792
from collections import Counter
def main():
    N=int(input())
    AB=[list(map(int, input().split())) for _ in range(N-1)]
    G=[[]for _ in range(N)]
    cnt=[0]*N
    for a,b in AB:
        G[a-1].append(b-1)
        G[b-1].append(a-1)
        cnt[a-1]+=1
        cnt[b-1]+=1
    CI=sorted(((c,i) for i,c in enumerate(cnt)), reverse=True)
    ans=[0]*N
    C=[0]*N
    stack=[(0,-1,0)]
    while stack:
        u,p,d=stack.pop()
        for v in G[u]:
            if v!=p:
                stack.append((v,u,d^1))
                C[v]=d^1
    X=sum(C)
    if X<=N//3:
        D=[[i for i in range(1,N+1,3)]+[i for i in range(2,N+1,3)],[i for i in range(3,N+1,3)]]
        for i in range(N):
            if D[C[i]]:
                ans[i]=D[C[i]].pop()
            else:
                ans[i]=D[C[i]^1].pop()
    elif N-X<=N//3:
        D=[[i for i in range(3,N+1,3)],[i for i in range(1,N+1,3)]+[i for i in range(2,N+1,3)]]
        for i in range(N):
            if D[C[i]]:
                ans[i]=D[C[i]].pop()
            else:
                ans[i]=D[C[i]^1].pop()
    else:
        D=[[i for i in range(1,N+1,3)],[i for i in range(2,N+1,3)],[i for i in range(3,N+1,3)]]
        for i in range(N):
            if D[C[i]]:
                ans[i]=D[C[i]].pop()
            else:
                ans[i]=D[2].pop()
    print(*ans)

if __name__ == "__main__":
    main()

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

using namespace std;

typedef unsigned long long ull;

string s;
ull N,red,out;
int main()
{
    cin>>N;

    cin>>s;

    for(ull i = 0; i<N; i++){
        if(s[i] == 'R'){
            red++;
        }
    }

    for(ull i = 0; i<red; i++){
        if(s[i] == 'W'){
            out++;
        }
    }

    cout<<out<<endl;
    return 0;
}


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

const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define ll long long
#define vi vector < int >
#define si set <int>
#define mii map <int, int>
#define vll vector < ll >
#define pii pair < int , int >
#define ff first
#define tc \
    int ttt; cin >> ttt;\
    while(ttt --)
#define ss second
#define f(i,a,b) for(int i=a;i<b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define nl '\n'
#define all(x) x.begin() , x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
int logg(ll x , ll y) {if (x == 0) return -1; return logg(x / y, y) + 1;}
ll poww(ll a, ll b, ll m) {
	if (b == 0) return 1;
	ll ans = 1;
	ans = poww(a, b >> 1, m);
	ans = (ans * ans) % m;
	if (b & 1) ans = (ans * a) % m;
	return ans;
}
// Start of code

int dp[3005][3005];
string s1, s2;

string solve() {
	int n = s1.size();
	int m = s2.size();
	f(i, 0, n + 1) dp[0][i] = 0;
	f(i, 0, m + 1) dp[i][0] = 0;

	f(i, 1, n + 1) {
		f(j, 1, m + 1) {
			int q = 0;
			if (s1[i - 1] == s2[j - 1]) q = 1 + dp[i - 1][j - 1];
			else q = max(dp[i][j - 1], dp[i - 1][j]);
			dp[i][j] = q;
		}
	}
	string ans = "";
	int i = n, j = m;
	while (i > 0 && j > 0) {
		if (s1[i - 1] == s2[j - 1]) ans = s1[i - 1] + ans, i--, j--;
		else if (dp[i - 1][j] > dp[i][j - 1]) i--;
		else j--;
	}
	return ans;
}

int32_t main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast;

	cin >> s1 >> s2;
	cout << solve() << nl;
}

Measured memory_bytes: 74104
n,m = map(int,input().split())
ab = []

for i in range(n):
	ab.append(list(map(int,input().split())))

ab.sort()

sum = 0
num = m
for i in range(n):
	if(0 >= num):
		break
	sum += ab[i][0]*min(ab[i][1],num)
	num -= ab[i][1]

print(sum)

Measured memory_bytes: 27760
#include<bits/stdc++.h>//h
using namespace std;
int main()
{
    int a,w,x,y,z,c,b,d,p[4],coutt=0;
    cin>>a;
    if(a>=1000 && a<=9999)
    {
        w=a%10;
        b=a/10;
        x=b%10;
        c=b/10;
        y=c%10;
        z=c/10;
        p[0]=w;
        p[1]=x;
        p[2]=y;
        p[3]=z;
        for(int i=0; i<2; i++)
        {
            if(p[i]==p[i+1] && p[i]==p[i+2])
            {
                coutt++;
                break;
            }
        }
        if ((coutt>0)) cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}


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

int main() {

    int N;
    cin >> N;

    int a, b, c;

    for(int i = 0; i < N; i++) {
        cin >> a >> b >> c;

        vector<int> vec;

        vec.push_back(a);
        vec.push_back(b);
        vec.push_back(c);

        sort(vec.begin(), vec.end(), greater<int>());

        if(pow(vec[0], 2) == pow(vec[1], 2) + pow(vec[2], 2)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        if (n < 1200){
            System.out.println("ABC");
        }else if (n < 2800){
            System.out.println("ARC");
        }else{
            System.out.println("AGC");
        }
    }
}


Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:07 2019

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

"""
S = str(input())

def main():
    cnt_10=0
    cnt_01=0
    for i in range(len(S)):
        if int(S[i]) != (i+1)%2:
            cnt_10 +=1

    for i in range(len(S)):
        if int(S[i]) != i%2:
            cnt_01 +=1
    print(min(cnt_10, cnt_01))
    
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 15348
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] a = new int[n];
        
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }
        
        for(int i=n-1; i>=0; i-=2){
        	System.out.print(a[i] + " ");
        }
        for(int i=n%2; i<n; i+=2){
        	System.out.print(a[i] + " ");
        }
   }
}


Measured memory_bytes: 61916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

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

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		int x = fs.nextInt();
		if(x >= 30) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 32716