akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(i = p;i < q;i++)
#define ll long long

using namespace std;

//34B
int main(void) {
	string s;
	cin >> s;
	int aCount = 0;
	ll ans = 0;
	int i = 0;
	rep(i,0, s.size()) {
		if (s[i] == 'A')aCount++;
		else if (s[i] == 'B') {
			if (i + 1 == s.size()) break;
			i++;
			if (s[i] == 'C') {
				ans += aCount;

			}
			else if (s[i] == 'A')aCount = 1;
			else aCount = 0;
		}
		else aCount = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	ll table[n + 1];

	table[0] = 2;
	table[1] = 1;

	FOR(i, 2, n + 1){
		table[i] = table[i - 2] + table[i - 1];
	}		

	cout << table[n] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
    int t=1,te=0;
    //Int(t);
    while(t--){
      int n;
      Int(n);

      set<string>s;

      while(n--){
        string ss;
        cin>>ss;

        s.insert(ss);
      }
      printf("%d\n", sz(s));

        //printf("Case %d: ",++te);
    }
    return 0;
}






Measured memory_bytes: 19172
use std::io;
use std::cmp;


/// https://beta.atcoder.jp/contests/abc052/tasks/abc052_b
fn main() {
    let _ = read_one::<usize>();
    let s = read_one::<String>().chars().collect::<Vec<char>>();

    let mut max = 0;
    let mut score = 0;
    for j in 0..s.len() {
        match s[j] {
            'I' => {
                score += 1;
                max = cmp::max(max, score);
            },
            'D' => score -= 1,
            _ => unreachable!(),
        }
    }
    println!("{}", max);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double
# define ull unsigned long long

# define pb push_back
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vld vector < ld >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < long , long >
# define pDD pair < D , D >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b));
# define mod 1000000007

# define pp(n) printf("%.10f",n);
# define line cout<<"\n";

const D pie = acos(-1);
const D hpie = asin(1);
const D qpie = atan2(1,1);
const D tpie = 2*pie;

string vow = "aeiou";

int n,m;
vvd v;

D dis ( int i , int j )
{
    D temp = 0;
    for ( int k=0 ; k<m ; k++ )
        temp += (v[i][k] - v[j][k])*(v[i][k] - v[j][k]);

    R temp;
}

void solve( int test_case )
{
    cin >> n >> m;

    v = vvd ( n , vd ( m ) );
    for ( int i=0 ; i<n ; i++ )
        for ( int j=0 ; j<m ; j++ )
            cin >> v[i][j];

    int cnt = 0;
    for ( int i=0 ; i<n ; i++ )
    {
        for ( int j=i+1 ; j<n ; j++ )
        {
            D d = dis(i,j);
            d = sqrt(d);

            int temp = d;
            if ( temp == d )
                cnt++;
        }
    }

    cout << cnt;
    line
}

int main()
{
    fast
    int t = 1;
    //cin>>t;

    for ( int i=0 ; i<t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> l(n + 1, 0);
  rep(i, 1, n + 1) {
    cin >> l[i];
    l[i] += l[i - 1];
  }
  int ans = 0;
  rep(i, 0, n + 1) {
    if (l[i] > x) {
      ans = i;
      break;
    }
  }
  if (ans == 0) ans = n + 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3536
from functools import reduce
from math import gcd 

n = int(input())
A = list(map(int, input().split()))

def furui(x):
    memo = [0]*(x+1)
    primes = []
    for i in range(2, x+1):
        if memo[i]: continue
        primes.append(i)
        memo[i] = i
        for j in range(i*i, x+1, i):
            if memo[j]: continue
            memo[j] = i
    return memo, primes

memo, primes = furui(10**6+5)

pr = [True]*(10**6+5)
for a in A:
    if a == 1: continue
    while a != 1:
        w = memo[a]
        if not pr[w]:
            break
        pr[w] = False
        while a%w == 0:
            a = a // w
    else:
        continue
    break
else:
    print('pairwise coprime')
    exit()

if reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')


Measured memory_bytes: 197176
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	long[string] b, r;
	foreach (i; 0..N)
	{
		++b[RD!string];
	}
	auto M = RD;
	foreach (i; 0..M)
	{
		++r[RD!string];
	}

	long ans;
	foreach (key; b.keys)
	{
		ans = max(ans, max(0, b[key] - r.get(key, 0)));
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
fn read_input() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).expect("");
    s
}

fn main() {
    let s = read_input();
    let mut s = s.chars();
    let a = s.nth(0);
    let b = s.nth(1);
    if a == b {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'

//素因数分解
map<long long,int > primeMap(ll N){
    map<long long,int> z;
    for(ll i = 2; i*i <= N; i++){
        while(N%i == 0){
            z[i]++;
            N /= i;
        }
    }
    if(N != 1) z[N]++;
    return z;
}

int main(){
    ll N;
    cin >> N;
    map<ll, int>z = primeMap(N);
    /*
    for(const auto& p:z){
        cout << p.first << " " << p.second << endl;
    }
    */
    int count = 0;
    for(const auto& p:z){
        for (long j = 1; p.second > 0; j++)
        {
            if(p.second >= j*(j+1)/2)
                count++;
            else break;
        }
    }
    fin(count);

    return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
#define title "chords"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll N=605;
const ll mod=1e9+7;
ll cp[N],n,m,vis[N],g[N],dp[N][N],ans;
ll su(ll l,ll r){
	return r-l+1-(vis[r]-vis[l-1]);
}
signed main(){
	n=read()<<1,m=read();
	for(ll i=1;i<=m;i++){
		ll x=read(),y=read();
		cp[x]=y,cp[y]=x,vis[x]=vis[y]=1;
	}
	for(ll i=1;i<=n;i++)vis[i]+=vis[i-1];
	g[0]=1;for(ll i=2;i<=n;i+=2)g[i]=g[i-2]*(i-1)%mod;
	for(ll i=1;i<=n;i++)for(ll j=i;j<=n;j++)if((j-i)&1){
		bool flag=true;
		for(ll k=i;k<=j;k++)if(cp[k]&&(cp[k]<i||cp[k]>j))flag=false;
		if(!flag)continue;
		dp[i][j]=g[su(i,j)];
		for(ll k=i+1;k<j;k++)dp[i][j]=(dp[i][j]-dp[i][k]*g[su(k+1,j)]%mod+mod)%mod;
		ans=(ans+dp[i][j]*g[su(1,i-1)+su(j+1,n)]%mod)%mod;
	}return cout<<ans,signed();
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll N, A, B, C, D;
map<ll, ll> mp;

ll dfs(ll n, ll high) {
    if (mp.find(n) != mp.end()) return mp[n];

    ll res = n < 4e9 ? n * D : INT64_MAX;
    ll m;

    m = n / 2 * 2;
    if (m > 0) res = min(res, D * abs(m - n) + A + dfs(m / 2, n));
    m = (n + 1) / 2 * 2;
    if (m < high && m / 2 < n) res = min(res, D * abs(m - n) + A + dfs(m / 2, n));
    m = n / 3 * 3;
    if (m > 0) res = min(res, D * abs(m - n) + B + dfs(m / 3, n));
    m = (n + 2) / 3 * 3;
    if (m < high && m / 3 < n) res = min(res, D * abs(m - n) + B + dfs(m / 3, n));
    m = n / 5 * 5;
    if (m > 0) res = min(res, D * abs(m - n) + C + dfs(m / 5, n));
    m = (n + 4) / 5 * 5;
    if (m < high && m / 5 < n) res = min(res, D * abs(m - n) + C + dfs(m / 5, n));

    mp[n] = res;
    return res;
}

int main() {
    int T;
    cin >> T;
    vector<ll> ans(T);

    rep(t, T) {
        cin >> N >> A >> B >> C >> D;

        mp.clear();
        ans[t] = dfs(N, N + 5);
    }

    for (ll x : ans) write(x);
}


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

int main() {
	// your code goes here
	int n,m;
	cin >> n >> m;
  	int ll = -INT_MAX,sl = INT_MAX;
	for(int i = 1 ; i <= n ; i++)
	{
		int l,r;
		cin >> l >> r;
		ll = max(ll,l);
      	sl = min(sl,r);
	}
	if(sl-ll < 0)cout << 0;
  	else cout << sl-ll+1;
	return 0;
}

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




























int main () {
    long long N;
    cin >> N;
    vector<long long> vect;
    while (N > 0) {
        if (N % 26 == 0) {
            vect.push_back(26);
            N -= 26;
        }
        else {
            vect.push_back(N % 26);
        }
        N /= 26;
    }
    reverse (vect.begin(), vect.end());

    string s;
    for (long long i: vect) {
        s.push_back((char)('a' + i - 1));
    } 

    cout << s << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
const double EPS = 1e-10;//sample:if((double)>=(double)+EPS)
#define CLR(a) memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)  cerr << #x << " = " << (x) << endl;//debug
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

int cont = 0;

void bsort(int A[],int n){
  bool flag = 1;
  while(flag){
    flag = 0;
    for(int j = n-1; j >= 1; j--){
      if(A[j] < A[j-1]){
	swap(A[j],A[j-1]);
	flag = 1;
	cont++;
      }
    }
  }
}

int main(void){
  int n, a[100];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  bsort(a,n);
  for(int i=0;i<n-1;i++)printf("%d ",a[i]);cout<<a[n-1]<<endl;
  cout<<cont<<endl;
  return 0;
}



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

using namespace std;

typedef long long LL;
#define N 120000
#define INF 0x3f3f3f3f3f3f3f3fLL

const LL mod=1000000007;
LL n,x,y,a[N],f[N];

int main(){
	scanf("%lld%lld%lld",&n,&x,&y);
	if (x>y) swap(x,y);
	for (LL i=1;i<=n;++i) scanf("%lld",a+i);
	for (LL i=3;i<=n;++i)
		if (a[i]-a[i-2]<x){puts("0"); return 0;}
	f[0]=1; a[0]=-INF; a[n+1]=INF;
	for (LL i=1,j=0,k=0;i<=n+1;++i){
		for (;k+1<i&&a[i]-a[k+1]>=y;++k);
		if (j<=k) f[i]=(f[k]-(j?f[j-1]:0))%mod;
		f[i]=(f[i-1]+f[i])%mod;
		if (i>1&&a[i]-a[i-1]<x) j=i-1;
	}
	printf("%lld\n",(f[n+1]-f[n]+mod*2)%mod);
	
	return 0;
}
			

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

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

  int even,odd;
  long long int a;
  for(int i=0; i < N; i++){
    cin >> a;
    if((a & 1) == 0)
      even++;
    else
      odd++;
  }
  if((odd & 1) == 0){
    even += odd/2;
    for(;;){
      if((even & 1) == 0)
	even = even/2;
      if(even == 0){
	cout << "NO" << endl;
	break;
      }
      if((even & 1) == 1){
	cout << "YES" << endl;
        break;
      }
    }
  }else{
    even += (odd-1)/2;
    for(;;){
      if((even & 1) == 0)
	even = even/2;
      if(even == 0){
	cout << "YES" << endl;
	break;
      }
      if((even & 1) ==1){
	cout << "NO" << endl;
        break;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            var output = N == new string(N.Reverse().ToArray())
                ? "Yes"
                : "No";

            Console.Write(output);
        }
    }
}


Measured memory_bytes: 11220
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let m:usize = read();
    let c:i32 = read();
    let brr:Vec<i32> = (0..m).map(|_| read()).collect();
    let mut cnt = 0;
    for _ in 0..n {
        let arr:Vec<i32> = (0..m).map(|_| read()).collect();
        let sum:i32 = arr.iter().zip(brr.iter()).map(|(a, b)| a * b).sum();
        if sum + c > 0 {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int X;
	cin >> X;

	int time = 0;
	int reach_pos = 0;
	while (reach_pos < X)
	{
		time++;
		reach_pos += time;
	}

	cout << time;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll a,b;
	rl2(a,b);
	ll ans=6-a-b;
	wl(ans);
	NL;
	return 0;
}

Measured memory_bytes: 256
s = int(input())

ai = s
a = [ai]

n = 2
while True:
    if ai % 2 == 0:
        ai = int(ai / 2)
    else:
        ai = int(3 * ai + 1)
    if ai in a:
        break
    a.append(ai)
    n += 1

print(n)

Measured memory_bytes: 2940
gets.to_i
a = gets.split.map(&:to_i)
gets.to_i
m = gets.split.map(&:to_i)

arr = [0]
a.each{|i|
  arr += arr.clone.map{|j| j+i}
#  p arr
}

m.each{|num|
  if arr.index(num) == nil then
    puts "no"
  else
    puts "yes"
  end
}

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

int main(){
	int n, m;
	cin >> n;
	m = n - 1;
	int a[100] = {};
	for( int i = 0; i < n; i++ ){ cin >> a[i]; }
	for( int j = 0; j < n; j++ ){ if( m == 0 ){ cout << a[m] << endl;} else { cout << a[m] << " ";} --m; }	
return 0;
}

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

typedef long long ll;

const int N = 1e5 + 20;
int n, q, a[N], cnt[N];
ll sum;

int main() {
        cin >> n;
        for (int i = 0; i < n; i++) {
                cin >> a[i];
                sum += a[i];
                cnt[a[i]]++;
        }
        cin >> q;
        while (q--) {
                int b, c;
                cin >> b >> c;
                sum += cnt[b] * (c - b);
                cnt[c] += cnt[b];
                cnt[b] = 0;
                cout << sum << "\n";
        }
        return 0;
}

Measured memory_bytes: 4316
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int q = sc.nextInt();
			Map<String, Integer> m = new HashMap<>();
			for(int i = 0; i < q; i++) {
				int query = sc.nextInt();
				switch(query) {
				case 0:
					m.put(sc.next(), sc.nextInt());
					break;
				case 1:
					System.out.println(m.getOrDefault(sc.next(), 0));
					break;
				case 2:
					m.remove(sc.next());
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 194640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc163/abc163_d.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K;
  cin >> N >> K;

  vector<ll> com(N + 1, 0);
  repi(i, 1, N + 1) { com[i] = com[i - 1] + i; }

  ll ans = 0;
  repi(k, K, N + 2) {
    ll l = com[k - 1];
    int ri = N - k >= 0 ? N - k : 0;
    ll r = com[N] - com[ri];

    ans += (r - l + 1) % MOD;
    // printf("%d %d: %lld %lld %lld\n", N, k, l, r, ans);
    ans %= MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4788
S = list(input())
S1 = ''.join(S[0:2])
S2 = ''.join(S[2:4])

if int(S1) >= 1 and int(S1) <= 12 :
    if int(S2) >= 1 and int(S2) <= 12 :
        print('AMBIGUOUS')
    else :
        print('MMYY')

else :
    if int(S2) >= 1 and int(S2) <= 12 :
        print('YYMM')
    else :
        print('NA')

Measured memory_bytes: 3060
#include<iostream>
#include<string>

int main() {
	int N;
	std::cin >> N;
	int A = N / 1000;

	if (N % 1000 == 0) {
		std::cout << 0 << std::endl;
	}
	if (N % 1000 != 0) {
		A++;
		A = A * 1000;
		std::cout << A - N << std::endl;
	}
	
}

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

int main() {
	char S[4];
	int a = 0;
	int b = 0;
	for (int i = 0; i < 4; i++) {
		cin >> S[i];
	}
	if (S[0] == S[1] && S[0] == S[2] && S[0] == S[3]) {
		cout << "No";
	}
	else if (S[0] == S[1] && S[2] == S[3]) {
		cout << "Yes";
	}
	else if (S[0] == S[2] && S[1] == S[3]) {
		cout << "Yes";
	}
	else if (S[0] == S[3] && S[1] == S[2]) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    string T[3]={"Sunny","Cloudy","Rainy"};
    string S;
    cin >> S;
    REP(i,3){
        if(S==T[i]){
            cout << T[(i+1)%3] << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll  long long
#define PI  acos(-1)
#define pb  push_back
#define ins insert
#define INF 1000000000000000007 //1e18+7
#define mk  make_pair
#define lb(v,x) lower_bound(all(v),x)
#define ub(v,x)  upper_bound(all(v),x)
#define ff  first
#define ss  second
#define rev reverse
#define endl "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a) (ll)a.size()
#define double long double
#define minpq  priority_queue <ll,vector<ll>,greater<ll> > 
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define mset(x,y)  memset(x,y,sizeof(x))
#define all(x)   (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bp(n)  __builtin_popcountll(n)
#define mxt(a)  *(max_element(a.begin(),a.end()))
#define mnt(a)  *(min_element(a.begin(),a.end())
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define trav(a, x) 	  for(auto &a : x)
#define re(i,n)       for(ll i=0;i<n;++i) 
#define int2Bin(x,y)  bitset <y> z=x; cout<<z.to_string()<<endl;
const double eps=1e-7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
// int dx[8]={+1, +1, +1, 0, 0, -1, -1, -1};
// int dy[8]={+1, 0, -1, +1, -1, +1, 0, -1};
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
ll sqr(ll x) { return x * x;}
template <typename T> T gcd(T a,T b){ if(a==0) return b; return gcd(b%a,a); }
template <class T> inline void chmax(T &x,T y){ x = max((x), (y));}
template <class T> inline void chmin(T &x,T y){ x = min((x), (y));}
template <class T> T abs(T x) { return x>0 ? x : -x;}
template <typename T> T powm(T a,T b, ll m){T cnt=1; while(b>0){ if(b%2==1) cnt=(cnt*a)%m; b/=2; a=(a*a)%m; }return cnt%m;}
typedef pair<int,int>  pii;
typedef pair<ll,ll>  pll;
typedef vector<pll>  vpii;
typedef vector<ll>   vll;
typedef vector<int>  vii;
///template <typename T> using orderset = tree <T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
///*X.find_by_order(k) //returns the kth largest element.(0-based)
///X.order_of_key(val) //returns the no. of values less than val.
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
const int MOD=1000000007;	
const int N=5005;
void prec(){
	
}
void run(){
	int n;cin>>n;
	map <string,int> mp;
	while(n--){
		string s;cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<< mp["AC"]<<endl;
	cout<<"WA x "<< mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
}					
int32_t main()
{
    cin.sync_with_stdio(0);cin.tie(0);
	cin.exceptions(cin.failbit);
    int tc=1;
    //cin>>tc;
    prec();
    re(i,tc)
    	run();
    return 0; 
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;

int main(){
	LL H, W;
	cin >> H >> W;
	if(H%3==0 || W%3==0){
		cout << 0 << endl;
		return 0;
	}
	LL ans=min(H,W);
	for(LL i=0; i<=H; i++){ 
		LL s1=i*W, s2=(H-i)*(W/2), s3=(H-i)*((W+1)/2);
		LL smax=max({s1,s2,s3}), smin=min({s1,s2,s3});
		LL res=smax-smin;
		ans=min(ans,res);
	}
	for(LL i=0; i<=W; i++){ 
		LL s1=i*H, s2=(W-i)*(H/2), s3=(W-i)*((H+1)/2);
		LL smax=max({s1,s2,s3}), smin=min({s1,s2,s3});
		LL res=smax-smin;
		ans=min(ans,res);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
num_list = list(map(int, input().split()))
sorted_list = sorted(num_list, reverse=True)

hoge = 4*M
thr = sum(num_list) / hoge

ans = 'Yes'
if sorted_list[M-1] < thr:
    ans = 'No'


print(ans)


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

#define pb push_back
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ll const mod = 1e9 + 7;

int const N = 1e3 + 7;
char grid[N][N];
ll dp[N][N];

inline ll add(ll x, ll y)
{
	return (x + y) % mod;
}

int main()
{
	fastio;

	memset(dp, 0, sizeof(dp));

	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; ++i)	
		cin >> grid[i];

	dp[0][1] = 1;
	for (int i = 1; i <= h; ++i)
	{
		for (int j = 1; j <= w; ++j)
		{
			if (grid[i-1][j-1] == '.')
			{
				dp[i][j] = add(dp[i-1][j], dp[i][j-1]);
			}
		}
	}

	cout << dp[h][w] << '\n';
	return 0;
}


Measured memory_bytes: 12528
from heapq import *

n, q = map(int, input().split())
box = [[] for i in range(n)]
for _ in range(q):
    a, b, *c = map(int, input().split())
    if a == 0:
        heappush(box[b],-c[0])
    elif a == 1 and box[b]:
        print(-box[b][0])
    else:
        if box[b]:heappop(box[b])



Measured memory_bytes: 13172
n = int(input())
A = list(map(int,input().split()))
ng = sum([bool(a<0) for a in A])
if ng%2==0:
    print(sum([abs(a) for a in A]))
else:
    print(sum([abs(a) for a in A]) - 2*min([abs(a) for a in A]))   

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

lli gcd(lli a, lli b)
{
  unless (a > b) swap(a, b);
  return b ? gcd(b, a % b) : a;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli n, m;
  string s, t;
  while (cin >> n >> m >> s >> t) {
    lli lcm = n * m / gcd(n, m);
    map<lli, char> x;
    for (int i = 0; i < s.size(); ++i) {
      x[i * lcm / n] = s[i];
    }
    bool f = true;
    for (int i = 0; i < t.size(); ++i) {
      if (x.count(i * lcm / m)) {
        f = f && (x[i * lcm / m] == t[i]);
      }
    }
    if (!f) cout << -1 << endl;
    else cout << n * m / gcd(n, m) << endl;
  }
  
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(3*N);
  rep(i,3*N) cin >> a[i];
  sort(a.rbegin(), a.rend());
  long long sum =0;
  for (int i = 1; i<2*N; i+=2) {
    sum += a[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 4236
#include<stdio.h>
void bubble(int A[], int n){
  int i =0,k=0,j=0,l=0;

  for( i =0;i <= n-1;i++){
    for(j = n-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	k = A[j];
	A[j] = A[j-1];
	A[j-1] = k;
	l++;
      }
    }
  }
  for(i=0;i<n;i++){
    if(i>=1)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",l);

}

int main(){
  int i,j,n,A[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  bubble(A,n);
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head, const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n;
    in(n);
    ll ans=0;
    string s;
    set<string> set;
    map<string,ll> map;
    rep(i,n){
        cin>>s;
        sort(all(s));
        if(map.count(s)){
            map[s]++;
        }else{
            set.insert(s);
            map[s]=1;
        }
    }
    for(auto value:set){
        if(map[value]>=2)ans+=map[value]*(map[value]-1)/2;
    }
    out(ans);
}

Measured memory_bytes: 19300
import collections

def main():
    S = list(input())
    Sset = set(S)
    if len(Sset) in [1, 3]:
        print('No')
    elif Sset == set(['S', 'N']) or Sset == set(['W', 'E']):
        print('Yes')
    elif len(Sset) == 4:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 9412
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <set>
#include <utility>
#include <climits>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>

#define ll long long
#define ull unsigned long long
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int k, a, b;
	cin >> k >> a >> b;
	int t = a / k * k;
	cout << (t >= a && t <= b || t + k >= a && t + k <= b ? "OK" : "NG");
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<string>
#include<cctype>

#define N 64
using namespace std;

bool isrectangle(char c, map<char,int> &s, map<char, set<char> > &cont)
{
  set<char>::iterator its = cont[c].begin();
  while(its!=cont[c].end()){
    if( *its == '.' ) return false;
    if( s[c] < s[*its] ) return false;
    ++its;
  }
  return true;
}

int main(){
  int T;
  cin >> T;
  for(int tc=1;tc<=T;++tc){
    int h,w;
    bool suspicious=true;
    map<char,int> s;
    map<char,set<char> > cont;
    char M[N][N];
    vector<int> x;
    cin >> h >> w;

    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
	cin >> M[i][j];
	if(isalpha(M[i][j])){
	  s[M[i][j]]=0;
	}
      }
    }
    
    for(int i = 0; i < s.size(); ++i){
      x.push_back( i );
    }
    
    map<char,int>::iterator itm = s.begin();
    while(itm!=s.end()){
      int mini=N,maxi=-1,minj=N,maxj=-1;
      for(int i = 0; i < h; ++i){
	for(int j = 0; j < w; ++j){
	  if( M[i][j] == itm->first ){
	    mini = min( mini, i );
	    maxi = max( maxi, i );
	    minj = min( minj, j );
	    maxj = max( maxj, j );
	  }
	}
      }
      for(int i = mini; i <= maxi; ++i){
	for(int j = minj; j <= maxj; ++j){
	  if( M[i][j] != itm->first ){
	    cont[ itm->first ].insert( M[i][j] );
	  }
	}
      }
      ++itm;
    }
    
    do{
      bool ok=true;
      map<char,int>::iterator its = s.begin();
      for(int i = 0; i < s.size(); ++i){
	its->second = x[i];
	++its;
      }
      for(its = s.begin(); its != s.end(); ++its){
	if( !isrectangle( its->first, s, cont ) ){
	  ok=false;
	}
      }
      if(ok){
	suspicious = false;
      }
    }while(next_permutation(x.begin(),x.end()));

    if( suspicious ){
      cout << "SUSPICIOUS";
    }else{
      cout << "SAFE";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 908
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define nummax 110000
using namespace std;


int main() 
{
	string S;
	string A = "0";
	string B = "1";
	int N, K, i, j, L, R, ans, sum[nummax], sumsum[nummax], count = 0, ini, type = 0, invtime, ansans = 0;
	sum[0] = 1;
	for (i = 1; i < nummax; i++)
		sum[i] = 0;
	
	cin >> N >> K;
	cin >> S;
	if (S[0] == '0')
		ini = 0;
	else ini = 1;
	for (i = 1; i < N; i++)
	{
		if (S[i] == S[i - 1])
		{
			sum[count]++;
		}
		else
		{
			count++;
			sum[count]++;
		}
	}
	sumsum[0] = sum[0];
	for (i = 1; i <= count; i++)
	{
		sumsum[i] = sumsum[i - 1] + sum[i];
	}
	for (i = 0; i <= count; i++)
	{
		type = 0;
		if (i % 2 == 0)
			type++;
		if (ini == 0)
			type++;
		if(K % 2 == 0)
			type++;
		if (type % 2 == 0)
			invtime = K;
		else invtime = K - 1;
		L = i - invtime;
		R = i + invtime;
		if (L < 0)
			L = 0;
		if (R > count)
			R = count;
		if(L == 0)
			ans = sumsum[R];
		else ans = sumsum[R] - sumsum[L - 1];
		ansans = max(ans, ansans);
	}
	cout << ansans << endl;
}

Measured memory_bytes: 1280
N, K = map(int, input().split())
c = 0
d = 0
if K % 2 == 0:
    for i in range(N):
        if (i + 1) % K != 0 and (i + 1) % (K // 2) == 0:
            d += 1
        elif (i + 1) % K == 0:
            c += 1
else:
    for i in range(N):
        if (i + 1) % K == 0:
            c += 1
print(c**3 + d**3)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MOD 1000000007
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

struct Hen {
	int a;
	int b;
	int color;
	int dist;
};

std::vector<Hen> a;
std::vector<std::vector<Hen> > hen;
int n, q;

std::vector<std::vector<Hen> > child;
std::vector<int> parent;
std::vector<int64_t> dist;
std::vector<int> depth;
std::vector<std::vector<int> > up;
std::vector<std::map<int, std::pair<int, int> > > qpool;
void dfs1(int i, int par, int64_t _dist, int _depth) {
	if (i) {
		int cur = par;
		up[i].push_back(cur);
		for (int pos = 0; pos < up[cur].size(); pos++) up[i].push_back(cur = up[cur][pos]);
	}
	parent[i] = par;
	dist[i] = _dist;
	depth[i] = _depth;
	for (auto j : hen[i]) {
		if (j.b == par) continue;
		child[i].push_back(j);
		dfs1(j.b, i, _dist + j.dist, _depth + 1);
	}
}
int lca(int i, int j) {
	if (i == j) return i;
	if (depth[i] > depth[j]) std::swap(i, j);
	if (!i) return 0;
	int change = depth[j] - depth[i];
	for (int beki = 0; beki < 20; beki++)
		if (change >> beki & 1) j = up[j][beki];
	assert(depth[i] == depth[j]);
	if (i == j) return i;
	for (int beki = 20; beki--; ) {
		assert(up[i].size() == up[j].size());
		if (beki >= (int) up[i].size()) continue;
		if (up[i][beki] == up[j][beki]) continue;
		i = up[i][beki];
		j = up[j][beki];
	}
	assert(i != j);
	assert(parent[i] == parent[j]);
	return parent[i];
}
void dfs2(int i, std::vector<std::pair<int, int> > &cur) {
	// qpool[i]
	for (auto &j : qpool[i]) j.second = cur[j.first];
	for (auto &j : child[i]) {
		cur[j.color].second += j.dist;
		cur[j.color].first++;
		dfs2(j.b, cur);
		cur[j.color].first--;
		cur[j.color].second -= j.dist;
	}
}


int main() {
	n = ri(), q = ri();
	a.resize(n - 1);
	hen.resize(n);
	for (int i = 0; i + 1 < n; i++) {
		int aa = ri() - 1;
		int b = ri() - 1;
		int c = ri() - 1;
		int d = ri();
		a[i] = {aa, b, c, d};
		hen[aa].push_back(a[i]);
		hen[b].push_back({b, aa, c, d});
	}
	parent.resize(n);
	child.resize(n);
	dist.resize(n);
	depth.resize(n);
	up.resize(n);
	dfs1(0, -1, 0, 0);
	std::cerr << "dfs1 finished" << std::endl;
	qpool.resize(n);
	std::vector<int> c(q), l(q), lc(q);
	std::vector<std::pair<int, int> > v(q);
	for (int i = 0; i < q; i++) {
		c[i] = ri() - 1, l[i] = ri();
		v[i] = {ri() - 1, ri() - 1};
		lc[i] = lca(v[i].first, v[i].second);
		qpool[v[i].first][c[i]] = {0, 0};
		qpool[v[i].second][c[i]] = {0, 0};
		qpool[lc[i]][c[i]] = {0, 0};
	}
	std::vector<std::pair<int, int> > cur(n);
	dfs2(0, cur);
	for (int i = 0; i < q; i++) {
		int res = dist[v[i].first] + dist[v[i].second] - 2 * dist[lc[i]];
		res += qpool[v[i].first][c[i]].first * l[i] - qpool[v[i].first][c[i]].second;
		res += qpool[v[i].second][c[i]].first * l[i] - qpool[v[i].second][c[i]].second;
		res -= 2 * (qpool[lc[i]][c[i]].first * l[i] - qpool[lc[i]][c[i]].second);
		std::cout << res << std::endl;
	}
	
	return 0;
}


Measured memory_bytes: 52736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n;
cin>>n;
char a[200005];
int w,r;
w=r=0;
for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]=='W')
            w++;
        else
            r++;
    }
int ans=0;
for(int i=n;i>n-w;i--)
    if(a[i]=='W')
    ans++;
    cout<<w-ans<<endl;
}


Measured memory_bytes: 3852
import math
n = int(input())
l = ["".join(sorted(input())) for i in range(n)]
l.sort()
c = 0
b = l[0]
ans = 0
for s in l[1:]:
    if s == b:
        c += 1
    else:
        ans += c * (c + 1) * 0.5
        c = 0
        b = s
ans += c * (c + 1) * 0.5
print(int(ans))

Measured memory_bytes: 11012
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 1000006, MOD = 1000000007;
typedef long long i64;

void update(i64 &x, i64 y) {
  x = (x + y) % MOD;
}

i64 f[MAX_N];
int N;

int main() {
  scanf("%d", &N);
  if (N == 1) {
    puts("1");
    return 0;
  }
  
  i64 result = 0, sum = 0;
  f[0] = 1, f[1] = 1, sum = 2;
  for (int i = 2; i <= N; ++i) {
    f[i] = (sum - f[i - 2]) % MOD;
    sum = (sum + f[i]) % MOD;
  }
  
  for (int i = 1; i < N; ++i) {
    update(result, 1LL * (N - 1) * max((N - i - 2), 0) % MOD * f[i - 1] % MOD);
    update(result, 1LL * N * (i + (i < N - 1)) % MOD * f[i - 1] % MOD);
  }
  update(result, 1LL * N * f[N - 1] % MOD);
  printf("%lld\n", (result + MOD) % MOD);
  return 0;
}


Measured memory_bytes: 7936
import sys
from math import factorial

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, p = map(int, input().split())
    A = list(map(int, input().split()))

    cnt_odd = 0
    for i in range(n):
        if A[i] % 2 != 0:
            cnt_odd += 1
    cnt_even = n - cnt_odd

    odd = 0
    for r in range(1, n + 1, 2):
        if cnt_odd - r >= 0:
            odd += factorial(cnt_odd) // factorial(r) // factorial(cnt_odd - r)
    even = pow(2, cnt_even)

    odd_pattern = even * odd
    total = pow(2, n)
    if p == 0:
        print(total - odd_pattern)
    else:
        print(odd_pattern)


if __name__ == '__main__':
    resolve()


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

namespace _1_8_b
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string  s = Console.ReadLine();
               
                string a;
                int answer = 0;
                if (s == "0")
                {
                    break;
                }

                for (int i = 0; i < s.Length; i++)
                {
                    a = s[i].ToString();
                    answer += int.Parse(a);
                }
                Console.WriteLine(answer);
            }
        }
    }
}



Measured memory_bytes: 17956
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
#define pb push_back
#define mp make_pair
 
const long double pi = 3.141592653589793238462;
const long double qu = (long double)20.0 * pi / 4;
const long double ha = (long double)20.0 * pi / 2;
int n;
struct p{
    int x, y;
    p(int x, int y): x(x), y(y) {}
};
vector<p> need;
 
bool cmp(const p &lhs, const p &rhs){
    return lhs.x < rhs.x;
}
 
vector<int> d;
vector<int> a;
 
int main()
{
    ios_base::sync_with_stdio(0);
    ll x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if(x1 > x2){
        swap(x1, x2);
        swap(y1, y2);
    }
    cin >> n;
    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        if(x >= x1 && x <= x2 && y >= min(y1, y2) && y <= max(y1, y2)){
            need.pb(p(x, y));
        }
    }
    if(need.empty()){
        long double ans = 100.0 * (abs(x1 - x2) + abs(y1 - y2));
        cout << fixed << setprecision(16) << ans << endl;
        exit(0);
    }
    if(x1 == x2 || y1 == y2){
        long double ans = 100.0 * (abs(x1 - x2) + abs(y1 - y2));
        if(!need.empty()){
            ans -= 20.0;
            ans += ha;
        }
        cout << fixed << setprecision(16) << ans << endl;
        exit(0);
    }
    sort(need.begin(), need.end(), cmp);
    d.assign(need.size() + 1, 1000000000);
    for(int i = 0; i < need.size(); i++){
        if(y1 < y2) a.pb(need[i].y);
        else a.pb(-need[i].y);
    }
    d[0] = -1000000000;
    for(int i = 0; i < need.size(); i++){
        int j = int(upper_bound(d.begin(), d.end(), a[i]) - d.begin());
        if(d[j - 1] < a[i] && a[i] < d[j]) d[j] = a[i];
    }
 
    int cnt = 0;
    for(int i = 1; i <= need.size(); i++){
        if(d[i] != 1000000000){
            cnt = i;
        }
    }
    int add = 0;
    if(cnt == min(x2-x1, abs(y1-y2)) +1){
        cnt--;
        add = 1;
    }
    long double ans = 100.0 * (abs(x1 - x2) + abs(y1 - y2));
    ans -= 20.0 * (long double)cnt;
    ans += qu * (long double)cnt;
    if(add) ans += ha - 20.0;
    cout << fixed << setprecision(16) << ans << endl;
    return 0;
}

Measured memory_bytes: 4464
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)() //queueのclear
#define all(s) (s).begin(),(s).end()
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

  int h,w;cin >> h >> w;
  vector<vector<char>> a(h,vector<char>(w));
  rep(i,h)rep(j,w)cin >> a[i][j];
  rep(i,2*h)rep(j,w){
    cout << a[(i+2)/2-1][j];
    if(j+1==w)cout << endl;
  }
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,k,i,j;
	cin >> N >> k;
	int h[N],dp[N];
	for(i=0;i<N;i++)
	{
		cin >> h[i];
		if(i==0)
		dp[0] = 0;
		else 
		dp[i] = INT_MAX;
	}
	for(i=0;i<N;i++)
	{
		for(j=1;(j<=k) && ((i+j)< N) ;j++)
		{
			dp[i+j] = min(dp[i] + abs(h[i] - h[i+j]),dp[i+j]);
		}
	}
	cout << dp[N-1];
	return 0;
}

Measured memory_bytes: 1024