akhauriyash/Code-Regression huggingface dataset:
/*
Author : N_o_o_B
Created : April 22 2020 22:21:16 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int n;
    cin >> n;
    vector<string> a(n);
    fori(i,n) cin >> a[i];
    map<string,bool> m;
    m[a[0]]=1;
    bool ok = 1;
    rep(i,1,n-1){
        ok &= (m[a[i]]==0 and a[i][0] == a[i-1].back());
        m[a[i]]=1;
    }
    cout << (ok ? "Yes":"No") << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,n;
  double a,res=0.0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf",&a);
    res+=(1.0/a);
  }
  printf("%.12lf\n",1.0/res);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>
#include <cmath>

using namespace std;

template <int base>
int digit_sum(int n)
{
	int sum = 0;
	while (n > 0) {
		sum += n % base;
		n /= base;
	}
	return sum;
}

using ivec = vector<int>;

ivec read_int_args()
{
	int N;
	cin >> N;
	ivec v(N);
	for (auto& e : v) {
		cin >> e;
	}
	return v;
}

int compar(const void * b, const void* a)
{
	return (*(int*)a - *(int*)b );
}

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

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


int main()
{
	typedef pair<int, int> X;
	
	int N;
	cin >> N;
	
	vector<X> data(N);
	int cnt = 1;
	for (auto& e : data) {
		cin >> e.second;
		e.first = cnt++;
	}
	
	sort(data.begin(), data.end(), [](const X& a, const X&b) {return a.second < b.second;});

	int first = 1;
	for (auto& e : data) {
		if (!first)
			cout << " ";
		cout << e.first;
		first = false;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 1664
#pragma once
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#include <ctype.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}
int search(int x) {

	int k = 0;
	int p = 1;
	while (p * 2 <= max_n)
	{
		p *= 2;
	}
	for (int i = p; i > 0; i /= 2)
	{
		if (i + k < max_n && bit[i + k] < x) {
			x -= bit[i + k];
			k += i;
		}
	}
	return k + 1;
}
void solv() {

	string s;
	cin >> s;
	int q;
	cin >> q;
	for (size_t i = 0; i < q; i++)
	{
		string que;
		cin >> que;
		int a, b;
		cin >> a >> b;
		if (que == "replace") {
			string rep;
			cin >> rep;
			for (size_t j = 0; j < rep.size(); j++)
			{
				s[j + a] = rep[j];
			}
		}
		else if (que == "reverse") {
			reverse(s.begin() + a, s.begin() + b + 1);
		}
		else {
			for (size_t i = a; i <= b; i++)
			{
				cout << s[i];
			}
			cout << endl;
		}
	}

}
int main() {
	//	COMinit();
	solv();
	return 0;
}



Measured memory_bytes: 3228
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

Int dp[51][51][3001];

int main(void) {
    int n,k;
    cin>>n>>k;

    dp[0][0][0] = 1;
    for(int i = 0;i < n;i++) {
        for(int j = 0;j <= i;j++) {
            for(int k = 0;k <= (i+1)*(i+1);k++) {
                (dp[i+1][j][2*j+k] += (2*j+1)*dp[i][j][k] % MOD) %= MOD;
                if(j >= 1) {
                    (dp[i+1][j-1][k+2*(j-1)] += j*j*dp[i][j][k] % MOD) %= MOD;
                }
                (dp[i+1][j+1][k+2*(j+1)] += dp[i][j][k]) %= MOD;
            }
        }
    }

    cout<<dp[n][0][k]<<endl;

    return 0;
}


Measured memory_bytes: 59136
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
        h:usize,
        w:usize,
        ch:usize,
        cw:usize,
        dh:usize,
        dw:usize,
        v:[String;h],
    }
    let map = v.into_iter().map(|s| s.chars().collect_vec()).collect_vec();
    let mut seen = vec![vec![false; w + 4]; h + 4];
    let mut sseen = vec![vec![false; w + 4]; h + 4];
    let mut ans = vec![vec![100000000; w+4]; h+4];
    let mut start = (ch-1,cw-1);
    let mut q = VecDeque::new();
    q.push_front(start);
    let mut flag = false;
    seen[start.0][start.1] = true;
    ans[start.0][start.1] = 0;

    while let Some((i, j)) = q.pop_front() {
        let ii = i;
        let jj = j;
        if i == dh - 1 && j == dw - 1 {
            flag = true;
            println!("{}", ans[dh - 1][dw - 1]);
            exit(0);
        }
        let (i, j) = (i as isize, j as isize);
        let c = [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]
            .iter()
            .filter(|(i, j)| (0..h as isize).contains(&i) && (0..w as isize).contains(&j))
            .map(|&(i, j)| (i as usize, j as usize))
            .filter(|&(i, j)| !seen[i][j] && map[i][j] != '#')
            .collect_vec();
        for (ci, cj) in c {
            seen[ci][cj] = true;
            if ans[ci][cj] > ans[ii][jj] {
                ans[ci][cj] = ans[ii][jj];
            }
            q.push_front((ci, cj));
        }
        let c = [(i - 2, j - 2), (i - 1, j - 2), (i, j - 2), (i + 1, j - 2), (i + 2, j - 2), (i - 2, j - 1), (i - 1, j - 1), (i, j - 1), (i + 1, j - 1), (i + 2, j - 1), (i - 2, j), (i - 1, j), (i, j), (i + 1, j), (i + 2, j), (i - 2, j + 1), (i - 1, j + 1), (i, j + 1), (i + 1, j + 1), (i + 2, j + 1), (i - 2, j + 2), (i - 1, j + 2), (i, j + 2), (i + 1, j + 2), (i + 2, j + 2), ]
            .iter()
            .filter(|(i, j)| (0..h as isize).contains(&i) && (0..w as isize).contains(&j))
            .map(|&(i, j)| (i as usize, j as usize))
            .filter(|&(i, j)| !sseen[i][j] && map[i][j] != '#')
            .collect_vec();
        for (ci, cj) in c {
            sseen[ci][cj] = true;
            if ans[ci][cj] > ans[ii][jj] {
                ans[ci][cj] = ans[ii][jj] + 1;
            }
            q.push_back((ci, cj));
        }
    }
    println!("-1")
}

Measured memory_bytes: 13512
#include<bits/stdc++.h>
using namespace std;
void solve();
typedef long long ll;
#define endl "\n"
const unsigned int M = 1000000007;

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

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

	int t = 1;
	///*is Single Test case?*/cin>>t;
	while (t--) {
		solve();
		cout << "\n";
	}
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}

void solve() {
	string str, s;
	cin >> str >> s;
	int count = 0;
	for (int i = 0; i < str.length(); ++i) {
		if (str[i] != s[i])count++;
	}
	cout << count;
}

Measured memory_bytes: 3828
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class B
{
	public static void Main()	
	{
		string s = GetString();
		Console.WriteLine(s.LastIndexOf("Z") - s.IndexOf("A") + 1);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


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

int main() {

  long long int n = 0;

  while( cin >> n, n) {

    long long int max_ = -10000000;

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

    for(int i = 0; i < n; i++){
      long long int sum = 0;
    
      for(int j = i; j < n; j++){
	sum += array[j];
	max_ = max(sum, max_);
      }
    }
    cout << max_ << endl;
  }

  return 0;

}

Measured memory_bytes: 1176
n,d = map(int,input().split())

x = [0 for i in range(n)]

for i in range(n):
    x[i] = list(map(int,input().split()))

chk = 0
cnt = 0


for i in range(n-1):
    for k in range(i+1,n):
        for j in range(d):
            #print(x[i][j],x[i+1][j])
            chk += (abs(x[i][j]-x[k][j]))**2
        chk = chk**0.5
        #print(i,k,chk)
        if chk.is_integer():
            cnt+=1
        chk = 0

print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;


long long ans;

long long pow(long long x,long long n){
	long long val=x;
	for(long long i=0;i<n;i++){
		val*=2;
	}
	return val;
}

int main(){
	
	long long a,b,c;cin>>a>>b>>c;
	long long k;cin>>k;
	long long key=max(a,b);
	key=max(key,c);
	ans+=a+b+c-key;
	ans+=pow(key,k);
	
	cout<<ans<<endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> P;
map<P, int> mp;
long long  h, w, n;
long long f[10], sum;
int dx[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}, dy[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int main(void){
    // Your code here!
    cin >> h >> w >> n;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        for (int j = 0; j < 9; j++) {
            int nx = a + dx[j], ny = b + dy[j];
            if (nx < 1 || nx > h - 2) continue;
            if (ny < 1 || ny > w - 2) continue;
            mp[P(nx, ny)]++;
        }
    }
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        f[itr -> second]++;
    }
    for (int i = 1; i <= 9; i++) sum += f[i];
    cout << (h - 2) * (w - 2) - sum << endl;
    for (int i = 1; i <= 9; i++) {
        cout << f[i] << endl;
    }
}


Measured memory_bytes: 56448
/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define MAX 100001
  #define md 1000000007
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  #define repa(a,n) for(int i=a;i<n;i++)
  //
  //
  int main(){
    ll n;
    cin>>n;
    int fst[n],snd[n];
    rep(i,0,n)
      cin>>fst[i];
    rep(i,0,n)
      cin>>snd[i];
      ll ans=0;
    rep(i,0,n){
      // cin>>fst[i]>>snd;
      ans=max(ans,ans+fst[i]-snd[i]);
    }
    cout<<ans;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
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++)

int main() {
  int n;
  cin >>n;
  vector<int> a(n);
  rep(i,n) {
    cin>>a.at(i);
  }
  long double now=0;
  rep(i,n){
    now+=1.0/a[i];
  }
  long double ans=1.0/now;
  cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			cout << i << "x" << j << "=" << i * j << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3020
fun main(args:Array<String>) {
    val (cardCount, gateCount) = readLine()!!.split(" ").map { it.toInt() };
    var fromNum = 1
    var toNum = cardCount

    for(i in (1..gateCount)) {
        val(l,r) = readLine()!!.split(" ").map { it.toInt() }

        if(fromNum > r || l > toNum) {
            println("0")
            return
        }

        fromNum = Math.max(fromNum, l)
        toNum = Math.min(toNum, r)
    }
    println(Math.max(toNum-fromNum + 1, 0))
}


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

#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n) cin>>a[i];
	int k=0;
	rep(i,n) if(a[i]!=i+1)k++;
	if(k<=2) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;	
	return 0;
}

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

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000*1000*1000+7)
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >

const int mod = 1e9+7;
const int inf=1e17+9;

int power(int a,int b,int p)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}
int32_t main()
{
    fast;
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b)
        swap(a,b);
    if(a<=c && c<=b)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main(){
  
  int n,k; cin >> n >> k;
  vector<ll> h(n); rep(i,n) cin >> h[i];

  sort(all(h));
  reverse(all(h));

  ll ans = 0;
  repm(i,k,n){
    ans += h[i];
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 1792
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1.01e9;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

void add(int & x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int sum(int x, int y) {
  add(x, y);
  return x;
}

int mult(int x, int y) {
  return (ll) x * y % mod;
}

int power(int x, ll p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}

void precalc() {
}

const int maxn = 1e5 + 100;

int n;
ll a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
  }
  return true;
}

void solve() {
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  ll step = (ll) n * (n + 1) / 2;
  if (sum % step) {
    printf("NO\n");
    return;
  }
  ll cnt = sum / step;
  ll taken = 0;
  for (int i = 0; i < n; i++) {
    ll cur = a[i];
    ll nxt = a[(i + 1) % n];
    nxt -= cur;
    nxt -= cnt;
    if (nxt % n) {
      printf("NO\n");
      return;
    }
    if (nxt > 0) {
      printf("NO\n");
      return;
    }
    taken += -nxt / n;
  }
  if (taken != cnt) {
    printf("NO\n");
  } else {
    printf("YES\n");
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.3f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MAX (ll)(1e6 + 7)
#define INF (ll)(1e18)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;

int cc[MAX];
int main () {
	ios_base :: sync_with_stdio (false);
	cin.tie (nullptr);
	int n;
	cin >> n;
	int ar[n];
	map<int, int> ma;
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
		ma[ar[i]]++;
	}
	for (pair<int, int> x : ma) {
		int v = x.first;
		for (int j = v; j < MAX; j += v) {
			cc[j] += x.second;
		}
	}
	int c = 0;
	for (int i = 0; i < n; i++) {
		if (cc[ar[i]] == 1) {
			c++;
		}
	}
	cout << c << "\n";
}


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

int main() {
    int L;
    int R;
    int l;
    int r;
    int ans = 2019; 
  cin >> L;
  cin >> R;
  l = L % 2019; 
  r = R % 2019;
  if (R - L >= 2019)
  {
    l = 0;
    r = 2018;
  }
  else if (l > r)
  {
    r = r + 2019;
  }

    for (int i = l; i < r+1; i++){
      for (int j = i + 1; j < r+1; j++)
      {
        int I;
        int J;
        I = i % 2019;
        J = j % 2019;
        ans = min ((I*J) % 2019,ans);
      }
    }
     cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> a(n+1), b(n);
    for(int i = 0; i < n+1; i++){
        std::cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        std::cin >> b[i];
    }
    long long ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] >= b[i]){
            ans += b[i];
        }else{
            if(b[i] - a[i] >= a[i+1]){
                ans += a[i] + a[i+1];
                a[i+1] = 0;
            }else{
                ans += b[i];
                a[i+1] -= b[i] - a[i];
            }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3988
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll x, y, d = 0, c = 0, ux, uy, dx, dy, t;
  scanf("%lld%lld", &x, &y);
  for(ux = uy = dx = dy = 0; ux < x || dx > x || uy < y || dy > y; c = (c + 1) % 3, d = (d + 1) % 4) {
    if(!d) t = uy - dy + 1, ux += t;
    else if(d == 1) t = ux - dx + 1, uy += t;
    else if(d == 2) t = uy - dy + 1, dx -= t;
    else t = ux - dx + 1, dy -= t;
  }
  printf("%lld\n", c + 1);
  return 0;
}


Measured memory_bytes: 2760
num,time = map(int, raw_input().split())
t = raw_input().split()
ans = time
for i in range(0,num-1):
	if int(t[i+1])-int(t[i]) < time:
		ans += int(t[i+1])-int(t[i])
	else:
		ans += time
print ans

Measured memory_bytes: 20060
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    int p[N];
    int q[N+1];
    for(int i = 0; i < N; i++){
        cin >> p[i];
        q[p[i]-1] = i; 
    }

    int ans = 0;
    int cnt = 1;
    for(int i = 0; i < N; i++){
        if(q[i] < q[i+1]){
            cnt++;
        } else {
            ans = max(ans, cnt);
            cnt = 1;
        }
    }

    cout << N-ans << endl;
}

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

int main()
{
  string s;
  cin>>s;
  vector<int> d(26);
  for(auto i:s)
    d[i-'a']++;
  for(auto i:d)
    if(i%2)
    { cout<<"No\n"; return 0;}
  cout<<"Yes\n";
  
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
  int n,l;
  cin >> n >> l;
  string s[n];
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  for(int i=0;i<n-1;i++){
    for(int j=0;j<n-i-1;j++){
      if(s[j] > s[j+1]){
	string temp;
	temp=s[j];
	s[j]=s[j+1];
	s[j+1]=temp;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int INF = 1e18;
const int M = 1e9 + 7;
//__int128


signed main()
{
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  const int maxn = 2e6;
  static char s[maxn];
  cin >> (s + 1);
  static int sc[maxn], mc[maxn];
  for(int i = 1; i <= n; ++i) {
    sc[i] = sc[i - 1];
    if(s[i] == 'C') {
      sc[i]++;
    }
  }
  int q;
  cin >> q;
  while(q--) {
    int k, m = 0;
    cin >> k;
    --k;
    mc[1] = 0;
    for(int i = 1; i <= k; ++i) {
      if(s[i] == 'M') {
        mc[1] += sc[k] - sc[i];
        ++m;
      }
    }
    // cout << m << endl;
    for(int i = 2; i <= n; ++i) {
      mc[i] = mc[i - 1];
      if(s[i - 1] == 'M') {
        int r = min(n, i + k - 2);
        mc[i] -= sc[r] - sc[i - 1];
        --m;
      }
      if(i + k - 1 <= n) {
        if(s[i + k - 1] == 'M') {
          ++m;
        } else if(s[i + k - 1] == 'C') {
          mc[i] += m;
        }
      }
      // cout << mc[i] << ' ';
    }
    long long res = 0;
    for(int i = 1; i < n; ++i) {
      if(s[i] == 'D') {
        res += mc[i + 1];
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 20736
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


int main(){
  long tmp;
  int n;
  long max, min;

  cin >> n;


  cin >> tmp;
  max = tmp;
  min = tmp;
  
  for(int i = 1; i < n; i++){
    cin >> tmp;
    if(max < tmp)
      max = tmp;
    if(tmp < min)
      min = tmp;
  }

  cout << (max - min) << endl;

  return 0;
}


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


using namespace std;


int n, m;


void generate_mat(int array[][50], int size)
{
  string tmp;

  for (int i=0; i<size; i++){
    cin >> tmp;
    for (int j=0; j<tmp.length(); j++){
      if (tmp[j] == '.'){
	array[i][j] = 0;
      } else if (tmp[j] == '#'){
	array[i][j] = 1;
      }
    }
  }
}


bool stride_mat(int x[][50], int y[][50], int i, int j)
{
  for (int k=0; k<m; k++){
    for (int l=0; l<m; l++){
      if (x[i+k][j+l] != y[k][l]){
	return false;
      }
    }
  }

  return true;
}	


int main()
{
  int a[50][50], b[50][50];

  cin >> n >> m;
  generate_mat(a, n);
  generate_mat(b, m);

  bool flag = false;
  for (int i=0; i<n-m+1; i++){
    for (int j=0; j<n-m+1; j++){
      if (stride_mat(a, b, i, j)){
	flag = true;
	break;
      }
    }
  }

  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define max(a,b) (a < b ? b : a)

int main(){
  int N,a[200000],Min,i,ans = -1e9;

  scanf("%d" ,&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d" ,a + i);
  }

  Min = a[0];
  for(i = 1 ; i < N ; i++){
    ans = max(ans,a[i]-Min);
    Min = -max(-Min,-a[i]);
  }
  printf("%d\n" ,ans);

  return 0;
}

Measured memory_bytes: 1376
using System;
using System.Collections.Generic;

namespace V0067{
    public class Program{
        public static void Main(string[] args){
            while(true){
                string input;
                var map = new List<char[]>();

                while(!string.IsNullOrEmpty(input = Console.ReadLine())){
                    map.Add(input.ToCharArray());
                }

                var w = map[0].Length;
                var h = map.Count;

                Func<int, int, int> bfs = (i, j) =>{
                    Func<int, int, bool> isInside = (mx, my) => 0 <= mx && mx < w && 0 <= my && my < h;
                    var dx = new[]{0, 1, 0, -1};
                    var dy = new[]{-1, 0, 1, 0};

                    map[j][i] = '0';
                    var que = new Queue<int>();
                    que.Enqueue(i);
                    que.Enqueue(j);

                    var area = 1;

                    while(que.Count > 0){
                        var x = que.Dequeue();
                        var y = que.Dequeue();

                        for(var t = 0; t < 4; t++){
                            var mx = x + dx[t];
                            var my = y + dy[t];
                            if(isInside(mx, my) && map[my][mx] == '1'){
                                map[my][mx] = '0';
                                que.Enqueue(mx);
                                que.Enqueue(my);
                                area++;
                            }
                        }
                    }

                    return area;
                };

                var areaList = new List<int>();
                for(var i = 0; i < w; i++){
                    for(var j = 0; j < h; j++){
                        if(map[j][i] == '1'){
                            areaList.Add(bfs(i, j));
                        }
                    }
                }

                //Console.WriteLine(string.Join(" ", areaList));
                Console.WriteLine(areaList.Count);
                //Console.ReadLine();

                if(input == null) break;
            }
        }
    }
}

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

const int M = 1000000;
int n;
int a[200000];
bool c[M + 1];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (c[a[i]]) continue;
    if (i == n - 1 || a[i + 1] != a[i]) {
      ++cnt;
    }
    for (int p = a[i]; p <= M; p += a[i]) {
      c[p] = true;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 5320
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> v_table(10*10*10*10*10+1, 0);
	long long sum = 0;
	for (int i = 0; i < n; ++i) {
		int a;
		scanf("%d", &a);
		v_table[a]++;
		sum += (long long)a;
	}
	int q; cin >> q;

	for (int i = 0; i < q; ++i) {
		int b, c;
		scanf("%d %d", &b, &c);

		sum += (long long)(v_table[b] * c);
		sum -= (long long)(v_table[b] * b);
		v_table[c] += v_table[b];
		v_table[b] -= v_table[b];

		cout << sum << endl;
	}

	return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

int digit_sum(int n){
    int ret = 0;
    while(n > 0){
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int ans = 1e9;
    int n;
    cin >> n;
    for(int a = 1;a < n;a++){
        int b = n - a;
        ans = min(ans, digit_sum(a) + digit_sum(b));
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
        int l, r, d;
        cin >> l >> r >> d;
        int ans = 0;
        rep(i, (r-l+1))if((l+i)%d==0)ans++;
        cout << ans << endl;
}

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

using namespace std;

struct segmentTree {
    const long long NEUTRO = 0;
    long long st[500010];
    int n = 200010;
    
    void update(long long pos, long long value){
        for (st[pos += n] = value; pos > 1; pos >>= 1)
            st[pos >> 1] = max(st[pos],st[pos ^ 1]); 
    }
 
    // interval[l,r)
    long long query(int l,int r){
        long long ans = NEUTRO;
        r++;
        for (l += n, r += n; l < r; l >>= 1,r >>= 1){
            if(l & 1) ans = max(ans, st[l++]);
            if(r & 1) ans = max(st[--r], ans);
        }
        return ans;
    }
};

long long h[200010];
long long a[200010];
segmentTree dp;

int main() {

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) 
        cin >> h[i];

    for (int i = 0; i < n; ++i) 
        cin >> a[i];
    
    for (int i = 0; i < n; ++i) 
        dp.update(h[i], dp.query(0, h[i]) + a[i]);
    

    cout << dp.query(0, 200010) << "\n";

    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define all(x) x.begin(),x.end()
#define int long long

/* 
ll exp(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}



int nCrModPFermat(int n, int r, int p)
{
   if (r==0)
      return 1;
    int fac[n+1];
    fac[0] = 1;
    for (int i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;
 
    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}
*/
/*struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
 
*/
 
/*vector<bool> sieve(100007,true);
 
void help(){
     sieve[0] = false;
     sieve[1] = false;
 
     for(int i=2;i*i<100007;++i){
        if(sieve[i]){
            for(int j=i*i;j<100007;j+=i)
                sieve[j] = false;
 
        }
     }
 
}*/
/*
ll expo(ll a,ll b){ll r=1;a=a%mod;while(b){if(b%2)r=(r*a)%mod;a=(a*a)%mod;b=b/2;}
return r;}
 
 
 */
 int n,s;
 const int mod = 1000000007;
  const int N = 200009;
  int arr[N];
  int sum ; 
  bool check(int mid)
  {
      
     int v[n];
     

      fo(i,n)
        v[i] = arr[i] + (i+1)*mid; 

      sort(v,v+n);
     int sum = 0;
      for(int i=0;i<mid;++i)
        sum+= v[i];
      
     return sum>s;
  }
  
  

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

    int arr[n+1];

    fo(i,n)
     cin>>arr[i];

     int ct = 0;

     int ct1 = 0;

     for(int i=0;i<n-1;++i)
     {
        if(arr[i]>=arr[i+1]){            
            ct1++;
            ct = max(ct,ct1);
        }
        else
            ct1=0;
     }
     cout<<ct;
 
     return 0;
      }
// always test the corner cases ALWAYS;

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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;


int main() {

    int a,b,sum=1,count=0;

    cin>>a>>b;

    while(sum<b){
        sum=sum+(a-1);
        count++;
    }
    cout<<count<<endl;

  
}

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<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;
typedef complex<D> P;
const ll E = 1e18 + 7;
const ll MOD = 1000000007;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define fill(x, y) memset(x, y, sizeof(x))
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
template <class... A>
void prints()
{
    cout << endl;
}
template <class... A>
void prints_rest() { cout << endl; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest)
{
    cout << " " << first;
    prints_rest(rest...);
}
template <class T, class... A>
void prints(const T &first, const A &... rest)
{
    cout << first;
    prints_rest(rest...);
}

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

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

    int N;
    ll K;
    ll fg = 0, fl = 0;
    cin >> N >> K;
    vector<int> A(N, 0);

    rep(i, N)
    {
        cin >> A[i];
    }

    rep(i, N)
    {
        rep(j, N)
        {
            if (A[i] > A[j])
            {
                fg++;
                if (i < j)
                {
                    fl++;
                }
            }
        }
    }

    ll comb = (K * (K - 1) / 2) % MOD;

    ll ans = (fl * K + fg * comb) % MOD;
    prints(ans);
    return 0;
}


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

const int maxn=110;
short dp[maxn][maxn][maxn][maxn];
int n,m, tx,ty, add;
short sumc[maxn][maxn], sumr[maxn][maxn], ans;
char s[maxn][maxn];

void chkmax(short& x,short y){ if(x<y) x=y; }
short calc(short* sum,int l,int r){
	if(l>r) return 0;
	return sum[r]-sum[l-1];
}

int main(){

	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){ 
		scanf("%s",s[i]+1); 
		for(int j=1;j<=m;j++) if(s[i][j]=='E') tx=i, ty=j;
	}
	swap(tx, ty);

	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) sumr[i][j]=sumr[i][j-1]+(s[i][j]=='o');
	for(int j=1;j<=m;j++) for(int i=1;i<=n;i++) sumc[j][i]=sumc[j][i-1]+(s[i][j]=='o');
	swap(n, m);
	
	for(int i=0;i<tx;i++) for(int j=0;j<ty;j++) for(int k=0;k<=n-tx;k++) for(int l=0;l<=m-ty;l++){
		int v=min(ty+l, m-j), u=max(ty-j, l+1);
		int b=min(tx+k, n-i), a=max(tx-i, k+1);
		int now=dp[i][j][k][l];
		if(i<tx-1){
			if(tx-i-1>k) add=calc(sumc[tx-i-1], u, v); else add=0;
			chkmax( dp[i+1][j][k][l], now+add );
		}
		if(j<ty-1){
			if(ty-j-1>l) add=calc(sumr[ty-j-1], a, b); else add=0;
			chkmax( dp[i][j+1][k][l], now+add );
		}
		if(k<n-tx){
			if(tx+k+1<=n-i) add=calc(sumc[tx+k+1], u, v); else add=0;
			chkmax( dp[i][j][k+1][l], now+add );
		}
		if(l<m-ty){
			if(ty+l+1<=m-j) add=calc(sumr[ty+l+1], a, b); else add=0;
			chkmax( dp[i][j][k][l+1], now+add );
		}
		chkmax( ans, dp[i][j][k][l] );
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 234112
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long

char s[55][55];
bool check(int H, int W) {
	if (s[H + 1][W] == '#'||s[H][W + 1] == '#'||s[H - 1][W] == '#'||s[H][W - 1] == '#') {
		return true;
	}
	else {
		return false;
	}
}

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

	bool flg = true;
	for (int i = 0; i < 55; i++)
	{
		for (int j = 0; j < 55; j++)
		{
			s[i][j] = '.';
		}
	}
	int H, W;
	cin >> H >> W;

	for (int i = 1; i <= H; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			cin >> s[i][j];
		}
	}

	for (int i = 1; i <= H; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			if (s[i][j] == '#') {
				if (!check(i, j)) {
					flg = false;
				}
			}
		}
	}

	if (flg) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846264338327
#define NUM 1000000007
#define ss second
#define ff first
using namespace std;
int main(){
	ios::sync_with_stdio(0);	
	int n, m;
	long long ans = 0, a[100001];
	pair <long long, int> op[100001];
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	
	sort(a, a + n);
	for (int i = 0; i < m; i++)
		cin >> op[i].ss >> op[i].ff;
	sort(op, op + m);
	reverse(op, op + m);
	bool ok = true;
	int cur = 0;
	for (int i = 0; i < m && ok; i++){
		int x = upper_bound(a, a + n, op[i].ff) - a - cur - 1;
		ok = x >= 0;
		if (ok){
			ans += op[i].ff * (long long)(min(op[i].ss, x + 1));	
			cur += min(op[i].ss, x + 1);
		}
		//cout << op[i].ff <<" " << op[i].ss <<" " << (long long)x + 1 <<" " <<"\n";
	}
	for (int i = cur; i < n; i++)
		ans += a[i];
	cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<ll> a(n + 1, 0);
    for(int i = 1; i <= n; i++) {
        int tmp = i;
        while(tmp <= n) {
            a[tmp]++;
            tmp += i;
        }
    }
    ll ans = 0;
    for(ll i = 1; i <= n; i++) {
        ans += i * a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 81376
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> x(n), y(n); for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];
  V<> idx(n);
  iota(begin(idx), end(idx), 0);
  sort(begin(idx), end(idx), [&](int i, int j) {
    return atan2(y[i], x[i]) + 1e-10 < atan2(y[j], x[j]);
  });
  for (int i = 0; i < n; ++i) {
    idx.push_back(idx[i]);
  }
  lint mx = 0;
  for (int s = 0; s < n; ++s) {
    lint sx = 0, sy = 0;
    for (int k = 0; k < n; ++k) {
      sx += x[idx[s + k]];
      sy += y[idx[s + k]];
      mx = max(mx, sx * sx + sy * sy);
    }
  }
  cout << fixed << setprecision(15) << sqrt(mx) << '\n';
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    long long  X,K;
    cin>>X>>K;
    if(X==K||K==1)
        cout<<0;
    else
    {
        X%=K;
        long long temp=X;
        X=abs(X-K);
        while(X<temp)
        {
            temp=X;
            X=abs(X-K);
        }
        cout<<temp;
    }
    return 0;
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=305;
bitset<N>c,bas[N];int f[N][N],bin[N*N],vis[N],res,r,n,x;
int main(){
	scanf("%d",&n);
	fp(i,1,n){
		fp(j,1,n)scanf("%d",&x),c[j]=x;
		fd(j,n,1)if(c[j]){
			if(!vis[j]){
				bas[j]=c,vis[j]=1,++r;
				break;
			}
			c^=bas[j];
		}
	}
	bin[0]=1;fp(i,1,n*n)bin[i]=mul(bin[i-1],2);
	f[0][0]=1;
	fp(i,0,n-1)fp(j,0,n)if(f[i][j]){
		upd(f[i+1][j],mul(f[i][j],bin[j]));
		upd(f[i+1][j+1],mul(f[i][j],dec(bin[n],bin[j])));
	}
	fp(i,r,n)upd(res,1ll*f[n][i]*bin[n*(n-i)]%P*f[i][r]%P);
	res=mul(res,ksm(f[n][r],P-2));
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
s = input()
if s[k-1] == 'A':
  s = s[:k-1] + 'a' + s[k:]
elif s[k-1] == 'B':
  s = s[:k-1] + 'b' + s[k:]
else:
  s = s[:k-1] + 'c' + s[k:]
print(s)

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(void){
	while(1){
		int n, m, p; cin >> n >> m >>p;
		if(!n && !m && !p) break;
		m--;
		int sum = 0;
		int win = 0;
		for(int i=0; i<n; i++){
			int x; cin >> x;
			sum += x;
			if(i == m) win = x;
		}
		if(win == 0){
			cout << 0 << endl;
			continue;
		}
		int ans = sum*(100-p);
		ans /= win;
		cout << ans << endl;
	}
	return 0;
}


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

int main(){
	int n; cin >> n;
	vector<ll> a(n);
	for( auto &k : a ) cin >> k;
	sort( a.begin(), a.end() );
	vector<ll> sum(n);
	sum[0] = a[0];
	for( int i = 0; i < n-1; ++i ){
		sum[i+1] = sum[i]+a[i+1];
	}
	int maxc = -1;
	for( int i = 0; i < n-1; ++i ){
		if( sum[i]*2 < a[i+1] ) maxc = i;
	}
	cout << n-maxc-1 << endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

int n;
ll c, ans;
vector< P > v;
vector< PP > A, B;

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

	cin >> n >> c;
	REP(i, n) {
		ll a, b; cin >> a >> b;
		v.pb(P(a, b));
	}

	A.resize(n), B.resize(n);

	ll sum = 0, a_ma = 0, b_ma = 0;
	REP(i, n) {
		sum += v[i].se;
		A[i].se.fi = sum;
		A[i].se.se = v[i].fi;
		A[i].fi = A[i].se.fi - A[i].se.se;
		ans = max(ans, A[i].fi);
	}

	reverse(ALL(v));
	sum = 0;
	REP(i, n) {
		sum += v[i].se;
		B[i].se.fi = sum;
		B[i].se.se = c - v[i].fi;
		B[i].fi = B[i].se.fi - B[i].se.se;
		ans = max(ans, B[i].fi);
	}

	/*REP(i, n) cout << '(' << A[i].fi << ',' << A[i].se.se << ')';
	cout << endl;
	REP(i, n) cout << '(' << B[i].fi << ',' << B[i].se.se << ')';
	cout << endl;*/

	int idx = 0;
	for (int i = n - 2; i >= 0; i--) {
		ll tmp = A[i].fi - A[i].se.se;
		b_ma = max(b_ma, B[idx].fi);
		ans = max(ans, tmp + b_ma);
		tmp = B[i].fi - B[i].se.se;
		a_ma = max(a_ma, A[idx].fi);
		ans = max(ans, tmp + a_ma);
		idx++;
	}

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6652
from collections import deque
n, m, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for _ in range(Q)]

# a = itertools.combinations_with_replacement(range(1, m + 1), n)
# combinations_with_replacement('ABC', 2) --> AA AB AC BB BC CC

def dfs():
  stack = deque()
  for i in range(1, m + 1):
    stack.append([i])
  while stack:
    q = stack.popleft()
    if len(q) >= n:
      a.append(q)
    else:
      l = q[-1]
      for i in range(l, m + 1):
        stack.append(q + [i])

a = []
dfs()

ans = 0
for i in a:
  prs = 0
  for a, b, c, d in ABCD:
    if i[b - 1] - i[a - 1] == c:
      prs += d
  ans = max(ans, prs) 

print(ans)

Measured memory_bytes: 23992
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <complex>
#include <algorithm>

using namespace std;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using i32 = int_fast32_t;
using u32 = uint_fast32_t;

#define int i64

template<class T>
inline bool chmin(T &a, T b) { if(a > b) {a = b; return true;} return false; }
template <class T>
inline bool chmax(T &a, T b) { if(a < b) {a = b; return true;} return false; }
const int INF = 1LL << 60;

signed main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for(int i = 0; i < n; i++) cin >> h[i];

	sort(h.begin(), h.end());
	for(int i = 0; i < k; i++) {
		if(h.size() >= 1) h.pop_back();
	}

	int res = 0;
	for(auto x: h) res += x;
	cout << res << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <iostream>

using namespace std;
const int maxx = 1e3 + 10;

int main()
{
    string ss,dd;
    cin>>ss;
    stack <char> s;
    for(int i=0; i<ss.size(); i++)
    {
        if (ss[i] == 'B')
        {
            if (!s.empty())
                s.pop();
            else
                continue;
        }
        else
            s.push(ss[i]);
    }
    dd.clear();
    while(!s.empty())
    {
//        printf("%c",s.top());
        dd += s.top();
        s.pop();
//        s.pop();
    }
    for(int i=dd.size()-1; i>=0; i--)
    cout << dd[i];
//    puts("");
    return 0;
}


Measured memory_bytes: 256