akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

/// Calcuates `x^n`. O(log n) time.
/// By Fermat's little theorem, `x^(-1) = pow(x, P - 2)`.
pub fn pow(x: i64, n: i64) -> i64 {
    let (mut x, mut y, mut n) = (x % P, 1_i64, n);
    while n > 0 {
        if n % 2 != 0 {
            y = (y * x) % P;
            n -= 1;
        }

        x = (x * x) % P;
        n /= 2;
    }
    y
}

fn main() {
    let N = read!(usize);
    let A = read![[i64]];

    let nf = (2..(N + 1) as i64).fold(1_i64, |x, y| x * y % P);

    // h[k] = Σ[i≤k] 1/i
    let mut h = vec![0; N + 1];
    for i in 1..h.len() {
        h[i] += h[i - 1];
        h[i] %= P;
        h[i] += pow(i as i64, P - 2);
        h[i] %= P;
    }

    // for i in 1..5 {
    //     let a = (1..i + 1)
    //         .map(|i| pow(i as i64, P - 2))
    //         .fold(0, |x, y| (x + y) % P);
    //     debug!((i, h[i], a));
    // }

    let mut s = 0_i64;
    for i in 0..N {
        let mut t = 0_i64;

        // j 番目のブロックを取ろうとしたときにブロック i の重さが加算される確率の和
        // for j in 0..N {
        //     t += pow((j as i64 - i as i64).abs() + 1, P - 2);
        //     t %= P;
        // }

        // Σ[0≤j<N] (1/(|i-j|+1))
        // = 1 + Σ[0≤j<i] (1 / (i-j+1)) + Σ[i<j<N] (1 / (j-i+1))
        // j < i のとき k=i-j+1 とおくと 0 ≤ j=i-k+1 < i だから 1 < k ≤ i+1
        // i < j のとき k=j-i+1 とおくと i < j=i+k-1 < N だから 1 < k < N-i+1

        t += h[i + 1];
        t %= P;
        t += h[N - i];
        t %= P;
        t += P - 2 + 1;
        t %= P;

        s += A[i] % P * t % P;
        s %= P;
    }
    s *= nf;
    s %= P;

    println!("{}", s)
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
	int R, G;
	cin >> R >> G;
	cout << 2 * G - R << endl;
}

Measured memory_bytes: 3656
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rept(i,s,n) for (int i = (s); i < (n); ++i)


#include <iostream>
#include <cmath>
using namespace std;

int main() {
   const int V1K = 1000;
   const int V5K = 5000;
   const int V10K = 10000;

   int num1K= 0;
   int num5K = 0;
   int num10K = 0;

   int n;
   int y;
   cin >> n >> y;
   int temp = y;

   num10K = temp / V10K;
   temp %= V10K;
   num5K = temp / V5K;
   temp %= V5K;
   num1K = temp / V1K;

   bool done = false;


   for(int i=0; i<=num10K; ++i){
      if(done)break;

      num10K -= i;
      num5K += i*2;

      for(int j=0; j<=num5K; ++j){
         if(done) break;

         num5K -= j;
         num1K += j*5;
         if(num1K+num5K+num10K == n){
            cout << num10K << " " << num5K << " " <<num1K << endl;
            done = true;
         }
         num5K += j;
         num1K -= j*5;
      }
      num10K += i;
      num5K -= i*2;
   }

   if(!done)
      cout << "-1 -1 -1"<<endl;







   return 0;
}


Measured memory_bytes: 256
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
def myAnswer(N: int, A: list) -> int:
    odds = [a for a in A if a % 2 == 0]
    counter = 0
    for odd in odds:
        dic = collections.Counter(prime_factorize(odd))
        counter += dic[2]
    return counter




def modelAnswer():
    tmp = 1


def main():
    N = int(input())
    A = list(map(int, input().split()))
    print(myAnswer(N, A[:]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4524
def cin():  return list(map(int,input().split()))

N, K = cin()
A = cin()
INF = 10 ** 9 + 7

cnt1 = 0
l = len(A)
for i in range(l):
    for j in range(i + 1, l):
        cnt1 += (A[i] > A[j])
        
AA = A + A
l = len(AA)
cnt2 = 0
for i in range(l):
    for j in range(i + 1, l):
        cnt2 += (AA[i] > AA[j])

ans = K * cnt1 + (cnt2 - 2 * cnt1) * K * (K - 1) // 2
print(ans % INF)

Measured memory_bytes: 70808
program main
  implicit none
  integer(8) :: n, i, x, y
  integer(8), allocatable :: a(:), t(:)
  read(*, *) n
  allocate(a(n), t(n))
  do i = 1, n
    read(*, *) t(i), a(i)
  end do
  x = 1
  y = 1
  do i = 1, n
    call update(x, y, t(i), a(i))
  end do
  write(*, "(i0)") x + y
  deallocate(a, t)

  contains

  subroutine update(x, y, t, a)
    implicit none
    integer(8), intent(inout) :: x, y
    integer(8), intent(in) :: t, a
    integer(8) :: ma, mb, mult
    ma = x / t
    if (mod(x, t) > 0) ma = ma + 1
    mb = y / a
    if (mod(y, a) > 0) mb = mb + 1
    mult = max(ma, mb)
    x = t * mult
    y = a * mult
  end subroutine update
end


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    string s;
    cin>>s;
    ll a;
    cin>>a;
    stack<ll> S;
    S.push(s[0]-'0');
    for(int i=1;i<s.size();i+=2){
        if(s[i]=='+'){
            S.push(s[i+1]-'0');
        }
        else{
            ll k=S.top(); S.pop();
            S.push(k*(s[i+1]-'0'));
        }
    }
    ll cul1=0;
    while(!S.empty()){cul1+=S.top(); S.pop();}
    ll cul2=s[0]-'0';
    for(int i=1;i<s.size();i+=2){
        if(s[i]=='+'){cul2+=s[i+1]-'0';}
        else{cul2*=s[i+1]-'0';}
    }
    if(cul1==cul2){
        cout<<(a==cul1?"U":"I")<<endl;
    }
    else{
        cout<<(a==cul1?"M":(a==cul2?"L":"I"))<<endl;
    }
    
    

    return 0;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

void check(map<char,int> m){
	for(auto i : m){
		if(i.second != 0){
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}

int main(){
	int h, w;
	cin >> h >> w;

	map<char,int> m;
	rep(i,h){
		rep(j,w){
			char a;
			cin >> a;
			m[a]++;
		}
	}

	if(h % 2 == 0 && w % 2 == 0){
		for(auto i : m){
			if(i.second % 4 != 0){
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}else if((h % 2 == 1 && w % 2 == 0) || (h % 2 == 0 && w % 2 == 1)){
		if(h % 2 == 0){
			swap(h,w);
		}
		int cnt = 0;
		for(auto& i : m){
			while(i.second >= 4){
				i.second -= 4;
				cnt++;
				//if(cnt == (h / 2) * (w / 2)) break;
			}
		}
		//if(cnt != (h / 2) * (w / 2)){
		//	cout << "No" << endl;
		//	return 0;
		//}

		cnt = 0;
		for(auto &i : m){
			while(i.second >= 2){
				cnt++;
				i.second -= 2;
				if(w / 2 == cnt) break;
			}
			if(w / 2 == cnt ) break;
		}
		//if(cnt != w / 2){
		//	cout << "No" << endl;
		//	return 0;
		//}
		//cout << "Yes" << endl;
		check(m);
	}else{
		int cnt = 0;
		for(auto& i : m){
			while(i.second >= 4){
				i.second -= 4;
				cnt++;
				//if(cnt == (h / 2) * (w / 2)) break;
			}
		}
		//if(cnt != (h / 2) * (w / 2)){
		//	cout << "No" << endl;
		//	return 0;
		//}

		cnt = 0;
		for(auto &i : m){
			while(i.second >= 2){
				cnt++;
				i.second -= 2;
				if((w / 2) + (h / 2) == cnt ) break;
			}
				if((w / 2) + (h / 2) == cnt ) break;
		}

		for(auto &i : m){
			if(i.second > 0){
				i.second--;
				break;
			}
		}
		//if(cnt != (w / 2) + (h / 2)){
		//	cout << "No" << endl;
		//	return 0;
		//}
		check(m);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int N; cin >> N;
    int H, D; cin >> H >> D;

    ll* fact = new ll[N+1];
    fact[0] = 1;
    ll factSum = 0;
    FOR(i, 1, N+1) {
    	fact[i] = fact[i-1] * i;
    	fact[i] = fact[i] % MOD;
    	factSum += fact[i];
    	factSum = factSum % MOD;
    }

    ll* ans = new ll[H+1];
    ll* pref = new ll[H+2];
    pref[0] = 0; pref[1] = fact[N];
    ans[0] = fact[N];
    FOR(i, 1, H) {
    	ans[i] = pref[i] - pref[max(0, i-D)];
    	ans[i] += MOD; ans[i] = ans[i] % MOD;
    	ans[i] = ans[i] * factSum; ans[i] = ans[i] % MOD;
    	pref[i+1] = pref[i] + ans[i];
    	pref[i+1] = pref[i+1] % MOD;
    	//cout << ans[i] << " " << endl;
    }

    ans[H] = pref[H] - pref[max(0, H-D)];
    ans[H] += MOD; ans[H] = ans[H] % MOD;
    cout << ans[H] << endl;


    
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;  // or pb_ds;

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#ifndef DEBUG
#define endl "\n"
#endif
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

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

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

template <typename T, typename B = null_type>
using oset =
    tree<T, B, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order / order_of_key

const ld eps = 1e-12;

ll fexp(ll b, ll e, ll p = PRIME) {
  ll res = 1;
  while (e) {
    if (e & 1) res = (res * b) % p;
    b = (b * b) % p;
    e >>= 1;
  }
  return res;
}

const int RANDOM =
    chrono::high_resolution_clock::now().time_since_epoch().count();

struct no_hack_hash {
  int operator()(int x) const { return x ^ RANDOM; }
};

struct iihash {
  int operator()(ii x) const { return x.first * 31 + x.second; }
};

// To use most bits rather than just the lowest ones:
struct ghash {  // large odd number for C
  const uint64_t C = ll(4e18 * acos(0)) | 71;
  ll operator()(ll x) const { return __builtin_bswap64(x * C); }
};

/*-----------------END TEMPLATE-----------------*/

int(((((((((((((((main)))))))))))))))() {
  FASTIO;
  priority_queue<int> pq1;
  priority_queue<int, vi, greater<int>> pq2;
  ll q;
  cin >> q;
  ll sum = 0;
  ll left = 0, right = 0;
  while (q--) {
    ll a, b, c;
    cin >> a;
    if (a == 1) {
      cin >> b >> c;
      sum += c;

      pq1.push(b);
      left += b;
      right += pq1.top();
      left -= pq1.top();
      pq2.push(pq1.top());
      pq1.pop();
      if (pq2.size() > pq1.size()) {
        pq1.push(pq2.top());
        right -= pq2.top();
        left += pq2.top();
        pq2.pop();
      }
    } else {
      ll med = pq1.top();
      ll qleft = pq1.size();
      ll ans = med * qleft - left;
      ll qright = pq2.size();
      ans += right - qright * med;
      cout << med << ' ' << ans + sum << endl;
    }
  }
}


Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,n,i,j,k=0;
  cin>>a>>b>>c>>n;
  ll x[n],y[n],z[n];
  for(i=0;i<n;i++) cin>>x[i]>>y[i]>>z[i];
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      k+=((abs(x[i]-x[j])+abs(y[i]-y[j])+abs(z[i]-z[j]))==1);
  for(i=0;i<n;i++){
    if(x[i]==0) k++;
    if(x[i]==a-1) k++;
    if(y[i]==0) k++;
    if(y[i]==b-1) k++;
    if(z[i]==0) k++;
    if(z[i]==c-1) k++;
  }
  cout << 2*(a*b+b*c+c*a)+6*n-k*2 << endl;
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char x,y; cin>>x>>y;
    if (x>y){
        cout<<">\n";
    }else if(x<y){
        cout<<"<\n";
    }else{
        cout<<"=\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c, d;
	int count = 0;
	int n;
	
	while (scanf("%d", &n) != EOF){
		count = 0;
		if (n <= 36){
			for (a = 0; a <= 9; a++){
				for (b = 0; b <= 9; b++){
					for (c = 0; c <= 9; c++){
						d = n - (a + b + c);
						
						if (d >= 0 && d <= 9)count++;
					}
				}
			}
		}
		printf("%d\n", count);
	}
	
	return (0);
}

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i=0;i<26;i++) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    for (int i=0;i<D;i++){
        for (int j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    vector<int> t(D);
    //初期t[i]の決定
    for (int i=0;i<D;i++) {
        t[i] = i % 26;
    }

    ll oldsum = 0;
    for (int m=0;m<100000;m++){
        //ここでt[i]を更新していく
        int dd = rand()%365;
        int mx = 0;
        int qq;
        for (int i=0;i<26;i++){
            if (s[dd][i] > mx){
                mx = s[dd][i];
                qq = i;
            }
        }
        int oldval = t[dd];
        t[dd] = qq;
        //=======================
        ll sum = 0;
        vector<int> last(26);
        for (ll i=0;i<D;i++){
            sum += s[i][t[i]];
            last[t[i]] = i+1;
            for (int j=0;j<26;j++){
                sum -= c[j]*(i+1-last[j]);
            }
        }
        if (sum > oldsum) {
            oldsum = sum;
        } else {
            t[dd] = oldval;
        }
    }
    for (int i=0;i<D;i++){
        cout << t[i]+1 << "\n";
    }
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  ll N,M;
  cin>>N>>M;
  if(N>1&&M>1){
    cout<<(N-2)*(M-2)<<endl;
  }else if(N==1&&M==1){
    cout<<1<<endl;
  }else if(M==1){
    cout<<N-2<<endl;
  }else if(N==1){
    cout<<M-2<<endl;
  }
}


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

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

    int n = S.size();

    int a_loc, z_loc;

    bool min_a_loc = false;
    bool max_z_loc = false;

    for (int i = 0; i < n; i++)
    {
        if (S.at(i) == 'A' && min_a_loc == false)
        {
            a_loc = i;
            min_a_loc = true;
        }
        if (S.at(n - 1 - i) == 'Z'  && max_z_loc == false)
        {
            z_loc = n - 1 - i;
            max_z_loc = true;
        }

        if (min_a_loc == true && max_z_loc == true)
        {
            break;
        }
    }

    cout << z_loc - a_loc + 1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;
mint i2 = (mint)1/2;
mint f[3000][3000];
int is[20000];
int js[20000];
mint vs[20000];
int main(){
	int N,Q;
	cin>>N>>Q;
	V<int> a(N);
	rep(i,N) cin>>a[i];
	rep(i,N) rep(j,N) if(i>j) f[i][j] = 1;
	V<int> X(Q),Y(Q);
	rep(i,Q){
		cin>>X[i]>>Y[i];
		X[i]--,Y[i]--;
	}
	for(int t=Q-1;t>=0;t--){
		int K = 0;
		auto add = [&](int i,int j,mint v){
			is[K] = i;
			js[K] = j;
			vs[K] = v;
			K++;
		};
		int x = X[t], y = Y[t];
		rep(_,2){
			add(x,y,i2);
			rep(j,N) if(j!=x && j!=y){
				add(x,j,(f[x][j]+f[y][j])*i2);
				add(j,x,(f[j][x]+f[j][y])*i2);
			}
			swap(x,y);
		}
		rep(k,K){
			f[is[k]][js[k]] = vs[k];
		}
	}
	mint ans = 0;
	rep(i,N) rep(j,N) if(a[i]<a[j]) ans += f[i][j];
	rep(_,Q) ans *= 2;
	cout<<ans<<endl;
}

Measured memory_bytes: 35712
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] A = new int[N];

		for(int i=0; i<N; i++) {
			A[i] = sc.nextInt();
		}

		long cash = 1000;
		for(int i=0; i<N-1; i++) {
			if(A[i] <= A[i+1]) {
				cash += (A[i+1] - A[i]) * (cash / A[i]);
			}
		}

		System.out.println(cash);

	}


}


Measured memory_bytes: 35964
from heapq import heappush, heappop

mod = 10 ** 9 + 7

N, *E = map(int, open(0).read().split())
Q = []
for i, e in enumerate(E):
    heappush(Q, (e, 1 if i < N else -1))

res = 1
cnt = 0
while Q:
    _, delta = heappop(Q)
    if cnt * delta < 0:
        res *= abs(cnt)
        res %= mod
    cnt += delta

print(res)

Measured memory_bytes: 25820
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

#define LOCAL

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
#else
    #define dbg(x)
#endif

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    cout << "\n";
    return a;
}

const int INF = 1e18;
//const int mod = 2600000069;
//const int p = 179;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    if (a >= b) for (int i = 0; i < a; i++) cout << b;
    else for (int i = 0; i < b; i++) cout << a;
}
/*
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int K;
string S;
int main(){
	cin>>N>>K>>S;
	REP(i,N){
		if(i==K-1){
			if(S[i]=='A'){
				cout<<'a';
			}
			if(S[i]=='B'){
				cout<<'b';
			}
			if(S[i]=='C'){
				cout<<'c';
			}
		}else{
			cout<<S[i];
		}
	}
	cout<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    
    public static final long INF = (long)1e11;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        TreeSet<Long> s = new TreeSet<>();
        TreeSet<Long> t = new TreeSet<>();
        s.add(INF);
        s.add(-INF);
        t.add(INF);
        t.add(-INF);
        for(int i=0; i<a; i++){
            s.add(Long.parseLong(sc.next()));
        }
        for(int i=0; i<b; i++){
            t.add(Long.parseLong(sc.next()));
        }
        for(int i=0; i<q; i++){
            long x = Long.parseLong(sc.next());
            long[] sa = {s.lower(x), s.higher(x)};
            long[] ta = {t.lower(x), t.higher(x)};
            long ans = INF;
            for(int j=0; j<4; j++){
                long jinja = sa[j&1];
                long tera = ta[j>>1];
                long sum = Math.abs(jinja-tera) + Math.min(Math.abs(x-jinja), Math.abs(x-tera));
                ans = Math.min(ans, sum);
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 101240
#include <cstdio>

int main() {
	int m, f, r;
	char grade;
	
	while (true) {
	scanf("%d %d %d", &m, &f, &r);
	if (m == -1 && f == -1 && r == -1) break;
	if (m == -1 || f == -1) {
	grade = 'F';
	} else if (80 <= m + f) {
	grade = 'A';
	} else if (65 <= m + f) {
	grade = 'B';
	} else if (50 <= m + f) {
	grade = 'C';
	} else if (30 <= m + f) {
	if (50 <= r) {
	grade = 'C';
	} else {
	grade = 'D';
	}
	} else {
	grade = 'F';
	}
	printf("%c\n", grade);
    }
    return 0;
}

Measured memory_bytes: 2708
//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,d, num = 0;
    cin >> n >> d;
    
    REP(i,n){
        int x,y;
        cin >> x >> y;
        if(hypot(x,y) <= d){
            num++;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 3692
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int K,n,i,j,k;cin>>K;
	if(K==1){cout<<1<<endl<<1<<endl;return 0;}
	n=((K+3)/4)*2;
	int am=K-n;
	cout<<n<<endl;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			int x=(i+j)%n +1;
			if(x<=am&&i%2==1){x+=n;}
			cout<<x<<" ";
		}
		cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 1152
#include<iostream>
#include<math.h>
#include<string>

int main()
{
    int sx,sy,tx,ty,x,y,i,j;
    std::cin>>sx>>sy>>tx>>ty;
    x = std::abs(sx-tx);
    y = std::abs(sy-ty);
    std::string str;
    for(i=0;i<y;i++){
        str.push_back('U');
        if(i==y-1){
            for(j=0;j<x;j++){
                str.push_back('R');
            }
        }
    }
    for(i=0;i<y;i++){
        str.push_back('D');
        if(i==y-1){
            for(j=0;j<x;j++){
                str.push_back('L');
            }
        }
    }
    str.push_back('L');
    for(i=0;i<y+1;i++){
        str.push_back('U');
        if(i==y){
            for(j=0;j<x+1;j++){
                str.push_back('R');
            }
        }
    }
    str.push_back('D');
    str.push_back('R');
    for(i=0;i<y+1;i++){
        str.push_back('D');
        if(i==y){
            for(j=0;j<x+1;j++){
                str.push_back('L');
            }
        }
    }
    str.push_back('U');
    std::cout<<str<<std::endl;
}


Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int c = 0;
    if (a > b) {
        swap(a, b);
        c = 1;
    }

    int k = 4, l = 24;
    int h, w; h = w = k * l + 1;

    vector<string> s(h, string(w, '.'));

    a--;
    for (int i = 0; i < h - k + 1; i += k) {
        for (int j = 0; j < w - k + 1; j += k) {
            if (b == 0) break;
            b--;
            for (int x = 1; x < k; x++) {
                for (int y = 1; y < k; y++) {
                    s[i + x][j + y] = '#';
                }
            }
            if (a > 0) {
                a--;
                s[i + 2][j + 2] = '.';
            }
        }
    }

    if (c) {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                s[i][j] = s[i][j] == '.' ? '#' : '.';
            }
        }
    }

    cout << h << ' ' << w << endl;
    for (int i = 0; i < h; i++) {
        cout << s[i] << endl;
    }

    return 0;
}

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

int main() {
	// your code goes here
	long long int n;
	cin>>n;
	long long int k;
	int a[n];
	cin>>k;
	a[0]=k;
	for(int i=1;i<n;i++)
	{
	   cin>>a[i];
	   k=k^a[i];
	}
	//cout<<k<<"\n";
	for(int i=0;i<n;i++)
	{
	    cout<<(k^a[i])<<" ";
	}
	cout<<"\n";
	return 0;
}


Measured memory_bytes: 4416
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
map<string,int> dp;
string s;
int dx[]={-1,1,-4,4};
void bfs()
{
    queue<string>que;
    que.push("01234567");
    dp["01234567"]=0;
    while(que.size()){
        string now=que.front(); que.pop();
        int p=0;
        for(int i=0;i<8;i++){
            if(now[i]=='0'){
                p=i; break;
            }
        }
        for(int i=0;i<4;i++){
            int nx=p+dx[i];
            if(nx>=0&&nx<8&&!(p==3&&i==1)&&!(p==4&&i==0)){
                string next;
                next=now;
                swap(next[nx],next[p]);
                if(dp.find(next)==dp.end()){
                    dp[next]=dp[now]+1;
                    que.push(next);
                }
            }
        }
    }
}
int main()
{
    int x;
    bfs();
    while(scanf("%d",&x)!=EOF){
        s="";
        s+=(x+'0');
        for(int i=0;i<7;i++)
        {
            scanf("%d",&x);
            s+=x+'0';
        }
        cout<<dp[s]<<endl;
    }
    return 0;
}

Measured memory_bytes: 5388
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (int i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
	string s;
	cin>> s;
	rep(i, 0, s.size())
		if(s[i] == '?')	
			s[i] = 'D';
	cout<< s<< "\n";
	return 0;	
}
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 3728
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll k, q, n, x, m;
    cin >> k >> q;
    vector<ll> org(k, 0);
    vector<ll> org_cum(k, 0);
    vector<ll> mods(k, 0);
    vector<ll> mod_sum(k+1, 0);
    vector<ll> zero_num(k+1, 0);
    rep(i, k){
        sll(org[i]);
    }
    // org_cum[0] = org[0];

    // rep(i, k-1){
    //     org_cum[i+1] = org_cum[i] + org[i+1];
    // }
    // cout << org_cum << endl;

    rep(i, q){
        cin >> n >> x >> m;
        // mod_cum[0] = x % m;
        ll one_num = 0;
        ll res = (n-2) % k;
        ll times = (n-2) / k;
        ll res_num = 0;
        // ll mod_sum = 0;
        rep(i, k){
            mods[i] = org[i] % m;
            zero_num[i+1] = (mods[i]== 0) + zero_num[i];
            mod_sum[i+1] = mods[i] + mod_sum[i];
        }
        // calc add num
        ll add_num = times * mod_sum[k] + mod_sum[res+1] + x;

        // cout << mod_sum << endl;
        ll small_num = add_num / m - x / m;
        ll equal_num = times * zero_num[k] + zero_num[res+1];

        // cout << "times=" << times << " add_num=" << add_num << " zeronum=" << zero_num << " res=" << res << endl;

        cout << n-1 - (small_num + equal_num) <<endl;

    }

}

int main(){
    Main();
    // string S = "ksdfjl";
    // char v = S[3];
    // S[3] = 'a';
    // cout << S <<endl;
}

Measured memory_bytes: 3428
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

vector<vector<unsigned> > change(25);
vector<char> memo(1<<25, -1);

int solve(unsigned enemy)
{
    if(enemy == 0)
        return 0;
    if(memo[enemy] != -1)
        return memo[enemy];

    int k = 0;
    while(!(enemy & (1 << k)))
        ++ k;

    int ret = INT_MAX;
    for(unsigned i=0; i<change[k].size(); ++i){
        unsigned next = enemy ^ change[k][i];
        ret = min(ret, solve(next) + 1);
    }

    return memo[enemy] = ret;
}

int main()
{
    for(int i=0; i<25; ++i){
        for(int j=i/5; j<5; ++j){
            for(int k=i%5; k<5; ++k){
                bitset<25> bs;
                for(int y=i/5; y<=j; ++y){
                    for(int x=i%5; x<=k; ++x){
                        bs[y*5+x] = true;
                    }
                }
                change[i].push_back(bs.to_ulong());
            }
        }
    }

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        bitset<25> enemy;
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                char tmp;
                cin >> tmp;
                if(tmp == '1')
                    enemy[i*5+j] = true;
            }
        }

        int m = solve(enemy.to_ulong());
        string ret;
        while(--m >= 0)
            ret += "myon";
        cout << ret << endl;
    }
}

Measured memory_bytes: 32000
#include<stdio.h>

int main(void){
    int s,m,h;
    scanf("%d",&s);
    m = s / 60;
    s = s % 60;
    h = m / 60;
    m = m % 60;
    
    printf("%d:%d:%d\n",h,m,s);
    
    
    return 0;
}


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


int main(){
	int n,m;
	cin >> n >> m;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin >> h.at(i);
	}
	vector<int> vec(n,0);
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		if(h.at(a-1)>=h.at(b-1)){
			vec.at(b-1)++;
		}
		if(h.at(a-1)<=h.at(b-1)){
			vec.at(a-1)++;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(vec.at(i)==0){
			ans++;
		}
	}
	cout << ans << endl;
}

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

int main(){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx,dy;
    dx = x2 - x1;
    dy = y2 - y1;
    cout << x2 - dy << ' ' << y2 + dx << ' ' << x1 - dy <<  ' ' << y1 + dx << endl;
}

Measured memory_bytes: 256
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f

let util = ABC(stdin)

let N = util.Scan1 int
let xs = util.ScanVecH int

let tot = Array.sum xs

//よくわかんないから全部やる
[ for i in 0..N-1 ->
    let s = xs |> Array.take i |> Array.append [|0|] |> Array.sum
    abs (tot - 2 * s)
]
|> List.min
|> printfn "%d"


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

const int MAXN = 1e5 + 5;

int main()
{
    int n, c[MAXN], s[MAXN], f[MAXN];
    cin >> n;
    for (int i = 0; i < n - 1; ++i)
        cin >> c[i] >> s[i] >> f[i];

    int ans[MAXN], time;
    ans[n - 1] = 0;
    for (int i = n - 2; i >= 0; --i)
    {
        time = 0;
        for (int j = i; j < n - 1; ++j)
        {
            if (time < s[j])
            {
                time = s[j];
            }
            time += (f[j] - ((time - s[j]) % f[j])) % f[j];
            time += c[j];
        }
        ans[i] = time;
    }
    for (int i = 0; i < n; ++i)
        cout << ans[i] << '\n';
}


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

typedef long long int ll;
typedef unsigned long long int ull;

int main(){
    ll n,a,b;
    scanf("%lld %lld %lld",&n,&a,&b);
    if(a==0) printf("0\n");
    else if(b==0) printf("%lld\n",n);
    else{
        ll ans = (n/(a+b));
        if(ans*(a+b)==n) printf("%lld\n",ans*a);
        else{
            ll temp = ans*a;
            ll temp2 = ans*b;
            ll val = n-(temp+temp2);
            if(val>=a) temp+=a;
            else temp+=val;
            printf("%lld\n",temp);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void call(int n);

int main()
{
	int n; cin >> n;
	call(n);
	return 0;
}

void call(int n)
{
	for (int i = 1; i <= n; ++i){
		int x = i;
		if (x % 3 == 0){
			cout << " " << i;
		} else {
			while(1){
				if (x % 10 == 3){
					cout << " " << i;
					break;
				} else {
					x /= 10;
					if (!x)
						break;
				}
			}
		}
	}
	cout << endl;
}


Measured memory_bytes: 3076
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        ++mp[s];
    }
    int mx = 0;
    for (auto &p : mp) {
        mx = max(mx, p.second);
    }
    for (auto &p : mp) {
        if (p.second == mx) cout << p.first << endl;
    }
    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll p;
  cin >> p;
  vector<ll> a(p);
  rep(i,p){
      cin >> a[i];
  }
  ll first = a[0];
  if(a[0]){
      rep(i,p){
          a[i] = (p+a[i]-1)%p;
      }
  }
  vector<ll> v(p);
  rep(i,p-1){
      ll sum = 0;
      rep(j,p){
          sum += a[j];
          a[j] = (a[j]*j+p)%p;
      }
      sum %= p;
      v[p-1-i] = (sum*(p-1))%p;
  }
  v[0]  = first;
  rep(i,p){
      cout << v[i] << " ";
  }
}

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

int main(){
	int N;
  	cin >> N;
  	map<string, int> lib;
  	rep(i, N) {
    	string s;
      	cin >> s;
      	lib[s]++;
    }

  	int mx = 0;
  	for(auto p : lib){
    	mx = max(mx, p.second);
    }
  	for(auto p: lib){
    	if(p.second != mx)continue;
        cout << p.first << endl;
    }
}

Measured memory_bytes: 25216
// ~maqsat~
/*
*/

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e10 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
    fre("");
    ACCELERATE;

    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n & 1) cout << "No";
    else if(s.substr(0, n / 2) == s.substr(n / 2)) cout << "Yes";
    else cout << "No";

    return 0;
}
/*
 
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n, l, q;
ll x[100000];
ll to[100000][31];

int main(){
	cin >> n;
	rep(i,n){
		scanf("%lld",x+i);
	}
	cin >> l;
	rep(i,n){
		ll s = i, e = n, mid;
		while(e-s>1){
			mid = (s+e)/2;
			if(x[mid]-x[i] <= l) s = mid;
			else e = mid;
		}
		to[i][0] = s;
	}
	for(ll i = 1; i < 31; i++){
		rep(j,n){
			to[j][i] = to[to[j][i-1]][i-1];
		}
	}
	cin >> q;
	while(q--){
		ll a, b;
		scanf("%lld%lld",&a,&b);
		a--; b--;
		if(b < a) swap(a,b);
		ll ans = 0;
		while(true){
			bool end = false;
			for(ll i = 30; i >= 0; i--){
				if(to[a][i] >= b && i == 0){
					ans += 1;
					end = true;
					break;
				}
				if(to[a][i] < b){
					ans += (1LL<<i);
					a = to[a][i];
					break;
				}
			}
			if(end) break;
		}
		printf("%lld\n",ans);
	}
}








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

using namespace std;

int main() {
	int N[10];

	for (int i = 0; i < 4; i++) {
		cin >> N[i];
	}

	sort(N, N + 4);

	if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>
#include <list>
 
using namespace std;
typedef long long ll;
 
#define mod 1000000007
#define INF 1000000000
#define SIZE 100000

struct NODE{
  int min_d;
  int max_d;
  int min_x;
  int min_y;
  int max_x;
  int max_y;

  NODE(){
    min_d = INF;
    max_d = 0;
    min_x = INF;
    max_x = 0;
    min_y = INF;
    max_y = 0;
  }
  
  NODE(int a,int b,int c,int d,int e,int f){
    min_d = a;
    max_d = b;
    min_x = c;
    max_x = d;
    min_y = e;
    max_y = f;
  }

  NODE operator+ (const NODE &B) const{
    int a = min(min_d,B.min_d);
    int b = max(max_d,B.max_d);
    int c = min(min_x,B.min_x);
    int d = max(max_x,B.max_x);
    int e = min(min_y,B.min_y);
    int f = max(max_y,B.max_y);

    return NODE(a,b,c,d,e,f);
  }
};

NODE data[1 << 19];
int segn2;

NODE query(int a,int b,int k=0){
  if(b<a) return NODE();
  if(data[k].max_d < data[k].min_d) return NODE();
  if(data[k].max_d < a || b < data[k].min_d) return NODE();

  if(a<= data[k].min_d && data[k].max_d <= b) return data[k];

  return query(a,b,k*2+1) + query(a,b,k*2+2);
}

int main(){
  int n,d;
  int x,y,b;
  vector<pair<int,pair<int,int> > > in;

  scanf("%d%d",&n,&d);

  segn2 = 1;
  while(segn2<n) segn2*=2;
  
  for(int i=0;i<n;i++){
    scanf("%d%d%d",&x,&y,&b);
    in.push_back(make_pair(b,make_pair(x,y)));
  }

  sort(in.begin(),in.end());

  for(int i=0;i<n;i++){
    int pd = in[i].first;
    int px = in[i].second.first;
    int py = in[i].second.second;
  
    data[i+segn2-1] = NODE(pd,pd,px,px,py,py);
  }

  for(int i = segn2-2;i>=0;i--){
    data[i] = data[i*2+1] + data[i*2+2];
  }
  
  ll ans = 0,calc;
  NODE a;
  
  for(int i=0;i<n;i++){
    a = query(in[i].first,in[i].first+d);
    if(a.max_d < a.min_d) continue;
    calc = (ll)(a.max_x - a.min_x)*(ll)(a.max_y - a.min_y);
    ans = max(ans,calc);
  }

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

Measured memory_bytes: 17944