akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	ll n, c, k;
	cin >> n >> c >> k;
	vector<ll> t(n);
	rep(i, n) cin >> t[i];
	
	sort(t.begin(), t.end());
	ll ans = 1;
	ll th = t[0] + k;
	ll tmpc = c - 1;
	for(int i = 1; i < n; ++i){
		if(0 < tmpc && t[i] <= th){
			tmpc--;
		}
		else{
			tmpc = c - 1;
			th = t[i] + k;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    // 今までのコストを保存するテーブル
    vector<int> dp(N);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    repr(i, 2, N) {
        dp[i] = min((dp[i-2] + abs(h[i-2] - h[i])), (dp[i-1] + abs(h[i-1] - h[i])));
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
n = raw_input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])

q = ["+","-"]

now = a
for x2 in range(2):
  now2 = now + b * pow(-1,x2)
  for x3 in range(2):
    now3 = now2 + c * pow(-1,x3)
    for x4 in range(2):
      now4 = now3 + d * pow(-1,x4)
      if now4 == 7:
        print "%d%s%d%s%d%s%d=7" % (a,q[x2],b,q[x3],c,q[x4],d)
        exit(0)


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const ll MOD = 1000000007LL;
/*メモ 
*/
int main(){
    int n,m;
    std::cin >> n>>m;
    std::vector<pair<int,int>> a(n);
    rep(i,n)std::cin >> a[i].fi>>a[i].se;
    sort(all(a));
    int i=0;
    ll ans=0ll;
    while(m!=0){
        if(a[i].se){
            ans+=a[i].fi;
            a[i].se--;
            m--;
        }
        else{
            i++;
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 1024
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
t = [0]*N
count = 0

for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]
for l, r in lr:
    print(t[r-1]-t[l-1])


Measured memory_bytes: 30664
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
#include<numeric>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0])
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

using namespace std;
typedef long long ll;



int main(void) {
	int n, k,sum=0;
	int p;

	cin >> n>>k;
	vector<int> vec(n);

	rep(i, n) {
		cin >> p;
		vec[i] =p;
	}
	sort(vec.begin(), vec.end());

	rep(i, k) {
		sum += vec[i];
	}

	cout << sum;



	return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,e,j;
  while(cin >> n&&n){
    rep(i,n){
      cin >> m >> e >> j;
      if(m == 100 || e == 100 || j == 100){
        cout << "A"<<endl;
        continue;
      }
      if((1.0*m+e)/2.0 >= 90){
        cout << "A"<<endl;
        continue;
      }
      if(1.0*(m+e+j)/3.0 >= 80){
        cout << "A"<<endl;
      }
      else if(1.0*(m+e+j)/3.0 >= 70) cout << "B"<<endl;
      else if(1.0*(m+e+j)/3.0 >= 50 && (m >= 80 || e >= 80)) cout << "B" << endl;
      else cout << "C" <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3116
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    const vector<int> c{-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
    }

    vector<int> dp(n + 10, -1);
    dp[0] = 0;
    for (int d : a) {
        dp[c[d]] = 1;
    }

    for (int i = 0; i <= n; ++i) {
        for (int d : a) {
            if (i - c[d] >= 0 && dp[i - c[d]] != -1)
                dp[i] = max(dp[i], dp[i - c[d]] + 1);
        }
    }

    string ans = "";
    while (n > 0) {
        int max_digit = -1;
        int cand = -1;
        for (int d : a) {
            if (n - c[d] >= 0 && dp[n - c[d]] != -1) {
                if (dp[n - c[d]] > max_digit) {
                    cand = d;
                    max_digit = dp[n - c[d]];
                } else if (dp[n - c[d]] == max_digit && d > cand) {
                    cand = d;
                }
            }
        }
        n -= c[cand];
        ans += (char)(cand + '0');
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) acm(all(v),0l)

long gcd(long a,long b){
  if(a>b)swap(a,b);
  if(a==0)return b;
  return gcd(b%a,a);
}

int main() {
  int n;
  long x;
  cin>>n>>x;
  nvec(long, v, n);
  sort(all(v));
  for (size_t i = n-1; i > 0; --i) {
    v[i]-=v[i-1];
  }
  v[0]=abs(v[0]-x);
  for (size_t i = 1; i < n; i++) {
    v[i]=gcd(v[i-1],v[i]);
  }
  cout<<v[n-1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 1000002
#define pie 3.14159265358979323
#define minuss 1e-6
int main()
{
    ll n,l;
    cin>>n>>l;
    ll str[n+3],s[n+3];
    ll lock=0,sum=0;
    for(int i=1; i<=n; i++)
    {
        s[i-1]=l+i-1;
        sum=sum+s[i-1];
        if(s[i-1]==0)
            lock=1;
    }
    if(lock==1)
        pf("%lld\n",sum);
    else
    {
        sort(s,s+n);
        ll sum1=sum-s[n-1];
        ll sum2=sum-s[0];
        if(sum2<0)
            cout<<min(sum1,sum2)<<endl;
        else
            cout<<max(sum1,sum2)<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int cnt = 0;
        int red = 0;
        int blue = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '0') {
                red++;
            } else {
                blue++;
            }
            if (i != s.length() - 1 && s.charAt(i) != s.charAt(i + 1)) {
                cnt++;
            }
        }
        int temp = Math.min(red - cnt, blue - cnt);
        System.out.println(cnt * 2 + temp * 2);
    }
}

Measured memory_bytes: 23724
#include <stdio.h>

int main(void){
  long int n = 0;
  long int d = 0;
  scanf("%ld", &n);
  scanf("%ld", &d);
  
  long int x = 0;
  long int y = 0;
  long int i = 0;
  long int q = 0;
  
  for(; i < n; i++){
    scanf("%ld", &x);
    scanf("%ld", &y);
    if(((x * x) + (y * y)) <= (d * d)){
      q++;
    }
  }
  
  printf("%ld", q);
  return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

ll dp[202020][3] = {0};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  string t = "^ " + s;
  for (int i = 0; i < n; i++) {
    if (t[i + 2] != t[i + 1]) {
      dp[i + 1][0] = dp[i][0] + 1;
    }
    if (i > 1 && (t[i + 2] != t[i] || t[i + 1] != t[i - 1])) {
      dp[i + 1][1] = dp[i - 1][1] + 1;
    }
    dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + 1);
    if (i > 0) {
      dp[i + 1][1] = max(dp[i + 1][1], dp[i - 1][0] + 1);
    }
  }
  cout << max(dp[n][0], dp[n][1]) << endl;
  return 0;
}


Measured memory_bytes: 5524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll ans = 0,n;
    cin>>n;
    rep(i,n+1){
        if(i%3 != 0 && i%5 != 0){
            ans += i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3640
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let aa = util::gets::<usize>();

    let mut h = HashMap::new();

    for &a in &aa {
        *h.entry(a).or_insert(0) += 1;
    }

    let ans = h.iter()
        .map(|(&a, &c)| if c >= a { c - a } else { c })
        .sum::<usize>();

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


Measured memory_bytes: 12540
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int main(){

    int N,D,ans,r;
    cin>>N>>D;

    r=2*D+1;

    ans=(N+r-1)/r;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int A,B;
	cin>>A>>B;	
	if(A>B){
		if(B!=1){
			cout<<"Alice";	
		}else
		cout<<"Bob";
    }else if(A==B){
    	cout<<"Draw";
	}else{
		if(A!=1){
			cout<<"Bob";
		}else{
			cout<<"Alice";
		}
	}
	return 0;
}

Measured memory_bytes: 256
//上皿天秤が左に傾くなら Left を、
//釣り合うなら Balanced を、
//右に傾くなら Right を出力せよ。
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A,B,C,D;
  	cin >> A >> B >> C >> D;
  if ((A+B)>(C+D)){
  cout<<"Left"<<endl;}
  if ((A+B)<(C+D)){
  cout<<"Right"<<endl;}
  if ((A+B)==(C+D)){
  cout<<"Balanced"<<endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  cin >> A ;
 
  if (A==11||A==13||A==17||A==19||A==22||A==23||A==26||A==29||A==31||A==33||A==34||A==37||A==38||A==39||A==41||A==43||A==44||A==46||A==47||A==50||A==51||A==52||A==53||A==55||A==57||A==58||A==59||A==60||A==61||A==62||A==65||A==66||A==67||A==68||A==69||A==70||A==71||A==73||A==74||A==75||A==76||A==77||A==78||A==79||A==80||A>81) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

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

int main() {
  double n;
  cin>>n;
  if ((int)(n)%2==1) cout<<setprecision(10)<<(n+1)/2/n<<endl;
  else cout<<setprecision(10)<<n/2/n<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input()[::-1][:1])
    if N==0 or N==1 or N==6 or N==8:
        print('pon')
    if N==2 or N==4 or N==5 or N==7 or N==9:
        print('hon')
    if N==3:
        print('bon')

if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  int M = N;
  int keta=0;
  int A,B,C;
  int ans;
  while(M!=0){
    M /= 10;
    keta++;
  }
  switch (keta) {
    case 1:
    cout << N << '\n';
    break;
    case 2:
    cout << 9 << '\n';
    break;
    case 3:
    ans=N-90;
    cout << ans << '\n';
    break;
    case 4:
    cout << 909 << '\n';
    break;
    case 5:
    ans = N-9090;
    cout << ans << '\n';
    break;
    case 6:
    cout << 90909 << '\n';
    break;  
  } 
}

Measured memory_bytes: 256
n = int(input())
ab = []
bsum = 0
for _ in range(n):
  a, b = map(int, input().split())
  ab.append(a + b)
  bsum += b

tans = 0
for i, _ab in enumerate(sorted(ab, key=lambda x: -x)):
  if i % 2 == 0:
    tans += _ab

print(tans - bsum)


Measured memory_bytes: 12628
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextLong()
	val a = scn.nextLong()
	val b = scn.nextLong()
	val k = n / (a+b)
	val r = n % (a+b)
	print(k*a+Math.min(r, a))
}

Measured memory_bytes: 31276
#include "stdio.h"

int main(void){
  int x,y,z,i,k,b,j;

  for(b = 0; b < 1000; b++){
    int a = 0;  
    scanf("%d %d", &x, &y);
    if((x == 0) && (y == 0))break;
    for(i = 1; i <= x; i++){
      for(j = i+1; j <= x; j++){
        k = y - i -j;

        if((i != j) && (i != k) && (j != k) && (k <= x) &&(k > 0) && (j < k)){

          a++;
        }
      }
    }
    printf("%d\n", a);
  }

}



Measured memory_bytes: 2044
def main():
    N = int(input())
    S = input()
    R = S[::-1]
    cnt = 0
    i = 0
    r = N-1
    while i<r:
        if(S[i]=='W'):
            while i<r:
                if S[r]=='R':
                    cnt += 1
                    r -= 1 
                    break
                r -= 1
        i+=1

    print(cnt)


if __name__ == '__main__':
    main()



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

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

  int R_count = 0;
  int B_count = 0;
  for(int i = 0; i < N; i++){
    if(s.at(i) == 'R'){
      R_count++;
    }
    else{
      B_count++;
    }
  }
  if(R_count > B_count){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl; 
    }
}

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


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

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

typedef long long ll;
typedef pair<int, int> P;

#define MAX 1000000020
#define INF 1001001001

int main(int, char**)
{
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  while (a >= b && k >= 0) {
    b <<= 1; k--;
  }
  while (b >= c && k >= 0) {
    c <<= 1; k--;
  }
  if (k >= 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
string O, E, F;

int main(void){
	//IO("test.in", "test.out");
	cin >> O >> E;
	for(int i = 0; i < max(O.length(), E.length()); i++){
		if(i < O.length()) F += O[i];
		if(i < E.length()) F += E[i];
	}
	cout << F << endl;
}

Measured memory_bytes: 256
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
string s;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	string s1="";
	while(cin>>s)
	s1+=s[0];
	cout<<s1;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b, c, d, e string
	fmt.Scan(&a, &b, &c, &d, &e)

	sHou, _ := strconv.Atoi(a)
	sMin, _ := strconv.Atoi(b)
	eHou, _ := strconv.Atoi(c)
	eMin, _ := strconv.Atoi(d)
	time, _ := strconv.Atoi(e)

	sta := sHou*60 + sMin
	end := eHou*60 + eMin

	fmt.Println(end - sta - time)
}

Measured memory_bytes: 1756
#include <iostream> // cout, endl, cin
#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
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

#define INF (1e+9)
int main(void) {
    int as, bs;
    int64_t limit;
    cin >> as >> bs >> limit;
    vector<int64_t> arr(as+1);
    vector<int64_t> brr(bs+1);
    for(int i = 0; i < as; i++) {
        cin >> arr[i+1];
    }
    for(int i = 0; i < bs; i++) {
        cin >> brr[i+1];
    }
    // cumulative sum
    for(int i = 1; i <= as; i++) {
        arr[i] += arr[i-1];
    }
    for(int i = 1; i <= bs; i++) {
        brr[i] += brr[i-1];
    }

    int ans = 0;
    for(int i = 0; i <= as; i++) {
        int64_t rem = limit - arr[i];
        if(rem < 0) continue;
        auto pos = upper_bound(brr.begin(), brr.end(), rem);
        int m = pos - brr.begin() - 1;
        ans = max(i + m, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6380
#pragma GCC optimize "O3"
#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(int x = l; x < r; ++x)
#define LoopR(x, l, r) for(int x = r-1; x >= l; --x)
#define all(x) x.begin(), x.end()
#define Kill(x) return cout << x << '\n', 0
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

const int N = 200'010;
const int oo = 1e9;
int H, W;

class Seg
{
private:
	struct node
	{
		int v;
		int l, r;
		int lazy = -1;
	};
	node t[N << 2];
	int n;

	int par(int n) { return (n - 1) / 2; }
	int lef(int n) { return 2 * n + 1; }
	int rig(int n) { return 2 * n + 2; }

	int merge(int a, int b)
	{
	    return min(a, b);
	}
	int create(int n, int l, int r)
	{
		if (l == r)
        {
			t[n].v = 0;
            t[n].l = t[n].r = l;
        }
		else
		{
		    t[n].l = l;
		    t[n].r = r;
		    int m = (l+r)/2;
		    t[n].v = merge(create(lef(n),l,m),
                            create(rig(n),m+1,r));
		}
		return t[n].v;
	}
	void down(int n)
	{
        if(t[n].lazy == -1)
            return;
        t[lef(n)].lazy = t[n].lazy;
        t[lef(n)].v = t[lef(n)].lazy;
        t[rig(n)].lazy = t[n].lazy + t[lef(n)].r - t[n].l + 1;
        t[rig(n)].v = t[rig(n)].lazy;
        t[n].lazy = -1;
	}
	int get(int n, int l, int r)
	{
		if (t[n].r < l || t[n].l > r)
			return oo;
		else if (t[n].l >= l && t[n].r <= r)
			return t[n].v;
		else
			return down(n), merge(get(lef(n), l, r),
                        get(rig(n), l, r));
	}
	int update(int n, int l, int r, int v)
	{
		if (t[n].r < l || t[n].l > r)
			return t[n].v;
		else if (t[n].l >= l && t[n].r <= r)
			(t[n].v = v + t[n].l - l), t[n].lazy = t[n].v;
		else
			down(n), t[n].v = merge(update(lef(n), l, r, v),
                                    update(rig(n), l, r, v));
        return t[n].v;
	}
public:
	void Create(int size)
	{
	    n = size;
		create(0, 0, size - 1);
	}
	int Get()
	{
		return get(0, 0, n-1);
	}
	int Get(int i)
	{
	    return get(0,i,i);
	}
	void Update(int l, int r, int v)
	{
        update(0,l,r,v);
	}
}T;

int main()
{
    FAST;
    cin >> H >> W;
    T.Create(W);
    Loop(i,0,H)
    {
        int l, r;
        cin >> l >> r;
        l--; r--;
        if(!l)
            T.Update(l, r, oo);
        else
            T.Update(l, r, T.Get(l-1)+1);
        int ans = T.Get() + i + 1;
        if(ans >= oo)
            cout << "-1\n";
        else
            cout << ans << '\n';
    }
}


Measured memory_bytes: 16116
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <iomanip>
#include <unordered_map>

using namespace std;

#define ll long long int

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,ans=0;
    cin>>n;
    while(n>=500)
    {
        ans+=1000;
        n-=500;
    }
    while(n>=5)
    {
        ans+=5;
        n-=5;
    }
    cout<<ans;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0)
                break;
            int[] input = new int[n];
            int[] output = new int[n];
            for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            }
            int loopCount = 0;
            while (true) {
                for (int i = 0; i < n; i++) {
                    int count = 0;
                    for (int j = 0; j < n; j++) {
                        if (input[i] == input[j]) {
                            count++;
                        }
                    }
                    output[i] = count;
                }
                if (isSame(input, output)) {
                    break;
                }
                loopCount++;
                input = output.clone();
                Arrays.fill(output,0);
            }
            System.out.println(loopCount);
            for (int i = 0; i < output.length; i++) {
                System.out.print(output[i]);
                if (i == output.length - 1) {
                    System.out.println();
                } else {
                    System.out.print(" ");
                }
            }
        }
    }

    static boolean isSame(int[] a, int[] b) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] != b[i]) {
                return false;
            }
        }
        return true;
    }
}


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

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

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

    if(min > a[i]){
      min = a[i];
    }
  }

  int search = 1, num = 0;
  if(min != 1){
    cout << "-1" << endl;
  }
  else{
    for(int i = 0; i < n; i++){
      if(search == a[i]){
        num++;
        search++;
      }
    }

    cout << n - num << endl;
  }

  return 0;  
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1000 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if (a1 + a2 + a3 >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}



int main() {

  long h, w;

  cin >> h >> w;
  vector<string> s(h);

  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  long ans = 0;



  vector<vector<long>> map = vector<vector<long>>(h, vector<long>(w, 0));


  for (int i = 0; i < h; i++) { //i行 j 列
    for (int j = 0; j < w; j++) {
      vector<long> searchnode;
      vector<long> searched;
      if (map[i][j] != 0)continue;
      searchnode.push_back(i * w + j);

      while (searchnode.size() > 0) {
        long nodeid = searchnode.back();
        searchnode.pop_back();
        long n_i = nodeid / w;
        long n_j = nodeid % w;

        if (map[n_i][n_j] == 0) {
          searched.push_back(nodeid);
          map[n_i][n_j] = i + 10;
          char schar = s[n_i][n_j];
          //上下左右
          //↑
          if (n_i > 0) {
            if (map[n_i - 1][n_j] == 0 && s[n_i - 1][n_j] != schar) {
              searchnode.push_back( (n_i - 1) * w + n_j);
            }
          }
          //下
          if (n_i < h - 1 ) {
            if (map[n_i + 1][n_j] == 0 && s[n_i + 1][n_j] != schar) {
              searchnode.push_back( (n_i + 1) * w + n_j);
            }
          }
          //→
          if (n_j < w - 1) {
            if (map[n_i ][n_j + 1] == 0 && s[n_i][n_j + 1] != schar) {
              searchnode.push_back( (n_i) * w + n_j + 1);
            }
          }
          //左
          if (n_j > 0) {
            if (map[n_i][n_j - 1 ] == 0 && s[n_i ][n_j - 1] != schar) {
              searchnode.push_back( (n_i) * w + n_j - 1);
            }
          }


        }
      }

      cerr << i << "," << j << "  :" << searched.size() << endl;
      // ans += (searched.size() -1) * searched.size() / 2;
      // ans += (searched.size() / 2  + 1) * (searched.size() / 2);


      long black =0;
      long white = 0;
      for(auto nodeid : searched){
        long n_i = nodeid / w;
        long n_j = nodeid % w;
        if (s[n_i][n_j] == '#')black++;
        if (s[n_i][n_j] == '.')white++;
      }

      ans += black * white;


      // cerr << endl;
      // for(auto v : searched){
      //   cerr << v <<endl;
      // }

      // cerr << endl;
      // for (int i = 0; i < h; i++) { //i行 j 列
      //   for (int j = 0; j < w; j++) {
      //     cerr << map[i][j];
      //   }
      //   cerr << endl;
      // }


    }
  }






  cout << ans << endl;


}




















Measured memory_bytes: 4972
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long 
#define PI 3.14159265358979323846
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(x,n) for(ll x=1;x<(ll)n+1;x++)
using namespace std;



int main() {
    ll X, N;
    bool unpi = false;
    bool manpi = false;
    cin >> X >> N;
    if (N == 0) {
        cout << X << endl;
        return 0;
    }
    vector<ll> p(N);
    rep(i, N) cin >> p[i];
    sort(p.begin(), p.end());
    rep(i, 100) {
        ll x = X - i;
        rep(j, N) {
            if (p[j] == x) {
                unpi = false;
                break;
            }
            else unpi = true;
        }
        if (unpi) {
            cout << x << endl;
            return 0;
        }
        ll y = X + i;
        rep(k, N) {
            if (p[k] == y) {
                manpi = false;
                break;
            }
            else manpi = true;
        }
        if (manpi) {
            cout << y << endl;
            return 0;
        }
    }
    return 0;
 }


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

bool is_prime(int n){
	if(n % 2 == 0 && n != 2) return false;
	for(int i = 3; i <= pow(n, 0.5); i += 2){
		if(n % i == 0) return false;
	}
	return true;
}


int main (){
	int n;
	cin >> n;
	int temp, count = 0;
	for(int i = 0; i < n; i++){
		cin >> temp;
		if(is_prime(temp)) count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 3240
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let k: usize = sc.read();
    let mut cur = 1;
    for _ in 0..k {
        sc.write(format!("{}\n", cur));
        let mut candidates = vec![];
        for prefix in 0..1000 {
            let mut p = prefix;
            let mut s = s(p);
            while p < cur * 100 {
                if p > cur {
                    candidates.push((p, s));
                }
                p = p * 10 + 9;
                s += 9;
            }
        }
        candidates.sort_by(|&(n, sn), &(m, sm)| {
            let a = n * sm;
            let b = m * sn;
            if a == b {
                n.cmp(&m)
            } else {
                a.cmp(&b)
            }
        });

        let (next, _) = candidates[0];
        cur = next;
    }
}

fn s(mut x: usize) -> usize {
    let mut result = 0;
    while x > 0 {
        result += x % 10;
        x /= 10;
    }
    result
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 1000000000, MAXI = N, D = 14;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 5, flag = 1;
//     cout << tc << "\n";
//     while (tc--)
//     {
//         int a = rand()%N+1;
//         a *= flag;
      
//         flag *= -1;

//         int b = rand()%MAXI + 1, c;

//         int d = rand()%D + 1;

//         int flag2 = rand()%3, k;

//         if(flag2==0)
//         {
//         	k = rand()%d+1;
//         	c = a + k*b;
//         }
//         else if(flag2==1)
//         {
//         	k = rand()%d + 1;
//         	c = a - k*b;
//         }
//         else
//         	c = rand()%MAXI;

//         cout << a << " " << b << " " << c << " " << d;
//         cout << "\n";
//         cout << "~\n";
//     }
 
//     return 0;
// }
 
 
 
 
 
 
 
 
//---------------------------------------------//
 
 
 
/*
#define int long long 
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 */ 
 
 
 
 
 
 
//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long
#define mod (int)(1e9+7)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 100005


int power(int a,int m1)
{
    if(m1==0)return 1;
    else if(m1==1)return a;
    else if(m1==2)return (1LL*a*a)%mod;
    else if(m1&1)return (1LL*a*power(power(a,m1/2),2))%mod;
    else return power(power(a,m1/2),2)%mod;
}



int fun(int k, int n)
{
	if(k==1)
		return 1;
	int x = power(k, n);
	int y = power(k-1, n);

	return (x - y + mod)%mod;
}
 

// Driver code to test above functions
int32_t main()
{
   
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    int ans = 0;
 
    
   	int n, k;
   	cin >> n >> k;
   	
   	vector<int> dp(k+1, 0);

   	for(int i=k;i>=1;i--)
   	{
   		int x = k/i;

   		int temp = power(x, n);
   		int extra = 0;
   		for(int j=2*i;j<=k;j+=i)
   			extra = (extra + dp[j])%mod;

   		dp[i] = (temp - extra + mod)%mod;

   		ans += (1LL*i*dp[i])%mod;
   	}

    cout << ans%mod;

    return 0;
 
} 

Measured memory_bytes: 3964
#include <vector>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define MAX 100000

struct edge{
    int s,t,d;
};

vector<edge> edges;
string ans;
int d[MAX];

int BellmanFord(int startVertex,int vNum,int eNum){
    fill((int*)d,(d + MAX),__INT_MAX__);
    d[startVertex] = 0;
    
    for(int i = 0;i < vNum;++i){
        bool update = false;
        for(int j = 0;j < eNum;++j){
            edge e = edges[j];
            if(d[e.s] != __INT_MAX__ && d[e.t] > d[e.s] + e.d){
                d[e.t] = d[e.s] + e.d;
                update = true;
                if(i == vNum - 1){
                    cout<<"NEGATIVE CYCLE"<<endl;
                    return - 1;
                }
            }
        }
        if(!update)break;
    }
    for(int i = 0;i < vNum;++i){
        if(i > 0) ans.append(" ");
        if(d[i]==__INT_MAX__){
            ans.append("INF");
        }
        else{
            stringstream ss;
            ss << d[i];
            ans.append(ss.str());
        } 
    }
    return 0;
}

int main(){
    int vNum,eNum;
    cin >> vNum >> eNum;
    
    int s,t,w;
    for(int i = 0;i < eNum;++i){
        cin >> s >> t >> w;
        edges.push_back({s,t,w});
    }
    for(int i = 0;i < vNum;++i){
        if(BellmanFord(i,vNum,eNum) == -1){
            return 0;
        }
        ans.append("\n");
    }
    cout << ans;
}



Measured memory_bytes: 3728
import numpy as np

n, m = map(int, input().split())
a = np.array([list(input()) for _ in range(n)])
b = np.array([list(input()) for _ in range(m)])

ans = 'No'
for i in range(n-m+1):
    for j in range(n-m+1):
        if (a[i:m+i, j:m+j] == b).all():
            ans = 'Yes'
print(ans)


Measured memory_bytes: 26768
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)




typedef struct Edge{
    int to;
    int w;
}Edge;


int N;
vector<vector<Edge>> g;
vector<int> col;

void DFS(int v,int p,int c){
    col[v] = c;
    for(auto a : g[v]){
        if(a.to == p)continue;
        // 行先での処理
        if(a.w & 1) DFS(a.to,v,1-c);
        else DFS(a.to,v,c);
    }
    return;
}

int main(){
    cin >> N;
    g.resize(N,vector<Edge>());
    col.resize(N,0);
    rep(i,N-1){
        int u,v,w;
        cin >> u >> v >> w;
        --u;--v;
        g[u].push_back((Edge){v,w});
        g[v].push_back((Edge){u,w});
    }
    

    DFS(0,-1,1);

    for(auto k : col)cout << k << endl;
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e4 + 10;

ll a[MAXN], gall[MAXN], gback[MAXN];

int main() {
	ios::sync_with_stdio(false);
	ll n, k, mod = 1e9 + 7;
	while(cin >> n >> k) {
		memset(gall, 0, sizeof(gall));
		memset(gback, 0, sizeof(gback));
		for(int i = 0; i < n; i++) {
			cin >> a[i];
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(a[i] > a[j]) {
					gall[i]++;
					if(j > i) {
						gback[i]++;
					}
				}
			}
		}
		ll ans = 0;
		for(int i = 0; i < n; i++) {
			ans = (ans + k * gback[i] + (k * (k - 1) / 2 % mod) * gall[i] % mod) % mod;
		}
		cout << ans % mod << endl;
	}
	return 0;
}

Measured memory_bytes: 640
w,h,n=gets.split.map(&:to_i)
M=(h+1).times.map{[0]*(w+1)}
n.times{
	a,b,c=gets.split.map(&:to_i)
	if c==1
		M[0][0]+=1
		M[0][a]-=1
		M[h][0]-=1
		M[h][a]+=1
	elsif c==2
		M[0][a]+=1
		M[0][w]-=1
		M[h][a]-=1
		M[h][w]+=1
	elsif c==3
		M[0][0]+=1
		M[0][w]-=1
		M[b][0]-=1
		M[b][w]+=1
	elsif c==4
		M[b][0]+=1
		M[b][w]-=1
		M[h][0]-=1
		M[h][w]+=1
	end
}
h.times{|i|(w+1).times{|j|M[i+1][j]+=M[i][j]}}
(h+1).times{|i|w.times{|j|M[i][j+1]+=M[i][j]}}
r=0
h.times{|i|w.times{|j|r+=M[i][j]==0 ? 0 : 1}}
p h*w-r

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

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

using namespace std;

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

    for( int i = str.length() % 2; i < str.length(); i += 2 )
    {
        if( i == 0 ) i += 2;
        
        string first = str.substr(0, (str.length() - i) / 2);
        string second = str.substr((str.length() - i) / 2, (str.length() - i) / 2);

        if( first == second )
        {
            cout << first.length() * 2 << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

int joyo(int m){
	if(m > 0) return m % 2;
	if(m < 0) return (-1 * m) % 2;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	if(n == 0){
		cout << 0 << endl;
		rtn 0;
	}
	stack<int> sta;
	while(n != 0){
		//cout << joyo(n) << endl;
		if(joyo(n) == 0) sta.push(0);
		else sta.push(1);
		if(n > 0) n = -1 * (n / 2);
		else n = (-1*n + 1) / 2;
	}

	while(!sta.empty()){
		cout << sta.top();
		sta.pop();
	}
	cout << endl;
	rtn 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int A[N];
  int s[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
    s[i]=0;
    for(;;){
      if(A[i]%2==1)
        break;
      A[i]/=2;
      s[i]++;
    }
  }
  int m;
  m=min(s[0],s[1]);
  for(int j=2;j<N;j++){
    m=min(m,s[j]);
  }
  cout<<m<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int c[3]={0},len[3]={0};
  char s[3][1000];
  
  for(i=0;i<3;i++){
    scanf("%s",s[i]);
    len[i] = strlen(s[i]);
  }
  i=0;
  while(c[0]<=len[0]&&c[1]<=len[1]&&c[2]<=len[2]){
    c[i]++;
    if(c[i]>len[i]){
      result = i;
      break;
    }
    i = (ll)((s[i][c[i]-1])-'a');
  }
  if(result==0) printf("A");
  else if(result==1) printf("B");
  else printf("C");
  return 0;
}



Measured memory_bytes: 128
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val ans = Vector(sc.nextInt, sc.nextInt, sc.nextInt) match {
    case Vector(5, 5, 7) => "YES"
    case Vector(5, 7, 5) => "YES"
    case Vector(7, 5, 5) => "YES"
    case _ => "NO"
  }
  println(ans)
}


Measured memory_bytes: 25408