akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

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

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

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

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

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

fn main() {
    let s: Vec<char> = util::line().chars().collect();

    let p = s.iter().filter(|&&c| c == 'p').count();

    println!("{}", s.len() / 2 - p);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=300009;
ll  ara[mx];
ll  cost[mx];
int main()
{
    ll n,k;
    cin>>n>>k;
    for(ll  i=1;i<=n;i++) cin>>ara[i];
    cost[1]=0;
    cost[2]=abs(ara[2]-ara[1]);
    for(ll  i=3;i<=n;i++)
    {
        cost[i]=LLONG_MAX;
        for(ll  j=1;j<=min(i-1,k);j++)
        {
            cost[i]=min(cost[i],cost[i-j]+abs(ara[i]-ara[i-j]));
        }
    }
    cout<<cost[n]<<endl;


}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

void transpose(vector<vector<char>> &b)
{
    if (b.size() == 0)
        return;

    vector<vector<char>> trans_vec(b[0].size(), vector<char>());

    for (int i = 0; i < b.size(); i++)
    {
        for (int j = 0; j < b[i].size(); j++)
        {
            trans_vec[j].push_back(b[i][j]);
        }
    }

    b = trans_vec; // <--- reassign here
}

// C++ゆるさねえリスト
// accumulate(all(a), 0LL);
// 二分探索

int main()
{

    ll n, ans = 0;

    cin >> n;

    rep(i, 1000000)
    {
        if (floor(i * 1.08) == n)
        {
            ans = i;
        }
    }
    if (ans == 0)
    {
        cout << ":(" << endl;
    }
    else
    {
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define optimize ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define INF 2000000020LL
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define POS(n, x) (lower_bound(ALL(n), x) - (n).begin())
#define ll long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define PB push_back
#define EB emplace_back
#define MOD 1000000007
#define PRIME 101 
#define MAXN 3030
#define MAXL 23
#define endl '\n'

using namespace std;

// (1 + sqrt(5)) / 2
const ld GOLDEN_RATIO = 1.6180339887498949025257388711906969547271728515625;
const ld PI = 2.0 * acos(0.0);
const int BLOCK = 333;

ll dp[MAXN][MAXN], nums[MAXN];
int N;

ll solve(int l = 0, int r = N - 1)
{
	if(dp[l][r] != -1) return dp[l][r];
	if(l == r) return dp[l][r] = nums[l];

	return dp[l][r] = max(nums[l] - solve(l + 1, r), nums[r] - solve(l, r - 1));
}

int main(int argc, char const *argv[])
{
	optimize;

	memset(dp, -1, sizeof dp);

	cin >> N;

	for(int i = 0; i < N; i++)
		cin >> nums[i];

	cout << solve() << endl;
	
	return 0;
}

Measured memory_bytes: 75488
def nsn(n):
    s = 0
    nn = n
    while nn > 0:
        s += nn % 10
        nn = int(nn / 10)
    return n / s

def big(a):
    r = 1
    while a > 0:
        r *= 10
        a = int(a / 10)
    return r

def clear(a, d):
    aa = a
    asa = nsn(a)
    b = True
    ba = big(a)
    while aa < ba:
        aa += d
        if nsn(aa) < asa:
            b = False
            break
    return b

K = int(input())
T = [1]
a = 1
d = 1
while len(T) < K:
    n = 1
    while 1:
        an = a + n * d
        if clear(an, d):
            T.append(an)
            a = an
            d = n * d
            break
        n += 1
for x in T:
    print(x)

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

struct Card{char suit,value; };

void bubbleSort(struct Card A[],int N){ 
    for (int i=0;i<N;i++){
        for (int j=N-1;j>=i+1;j--){
            if(A[j].value < A[j-1].value){
                Card t=A[j];A[j]=A[j-1];A[j-1]=t;
            }
        }
    }   
}

void selectionSort(struct Card A[],int N){ 
    for (int i=0;i<N;i++){
        int minj = i;
        for (int j=i;j<N;j++){
            if(A[j].value < A[minj].value){
                minj = j;
            }
        }
        Card t=A[minj];A[minj]=A[i];A[i]=t;
    }   
}


bool isStable(struct Card In[],struct Card Out[], int N){
    for (int i=0;i<N;i++){
        for(int j=1+1;j<N;j++){
            for(int a=0;a<N;a++){
                for(int b=a+1;b<N;b++){
                    if (In[i].value == In[j].value && In[i].value == Out[j].value && In[j].value == Out[i].value){
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
int main(){
    Card C0[100],C1[100],C2[100];
    int N;
    char ch; 

    cin >> N;
    for (int i=0;i<N;i++){
        cin >> C1[i].suit >> C1[i].value;
        C2[i] = C1[i];
        C0[i] = C1[i];
    }   

    bubbleSort(C1,N);
    for (int i=0;i<N;i++){
        if(i) cout << " ";
        cout << C1[i].suit << C1[i].value;
    }   
    cout << endl;
    cout << "Stable" << endl;
    selectionSort(C2,N);
    for (int i=0;i<N;i++){
        if(i) cout << " ";
        cout << C2[i].suit << C2[i].value;
    }   
    cout << endl;
    if (isStable(C0,C2,N)){
        cout << "Stable" << endl;
    } else{
        cout << "Not stable" << endl;
    }   
    return 0;
}




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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

std::vector<int> eratosthenes(int M) {
  std::vector<int> res(M, 0);
  res[0] = -1;
  res[1] = -1;
  for (int i = 2; i * i < M; ++i) {
    if (res[i] == 0) {
      for (int j = i * i; j < M; j += i) {
        if (res[j] == 0) res[j] = i;
      }
    }
  }
  return res;
}


int main()
{
    const int n = 100010;
    vector<int> prime_factor = eratosthenes(n);
    vector<int> similar(n);
    vector<int> cnt(n);
    cnt[0]=0;
    
    for(int i = 0; i < n; i++)
    {
        if(prime_factor[i]==0 && prime_factor[(i+1)/2]==0)
        {
            similar[i]=1;
        }
        else
        {
            similar[i]=0;
        }
    }


    

    for(int i = 1; i < 100010; i++)
    {
        cnt[i]=cnt[i-1];
        if(similar[i]==1)
        {
            cnt[i]++;
        }
    }

        
    int q;
    cin>>q;
    for(int i = 0; i < q; i++)
    {
        int l,r;
        cin>>l>>r;
        cout<<cnt[r]-cnt[l-1]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

const long LIMIT=1000000000;

int main(){
	unsigned long long n, t, ans=0;
	string s;
	int p[10], pp=0;
	
	cin >> n >> t;
	cin >> s;
	
	int now=0;
	while(now<s.size()){
		p[pp++]=s[now+2]-'0';	
		now+=4;
	}
	sort(p, p+pp);
	
	bool tle=false;
	for(int i=0; i<pp; ++i){
		unsigned long long tmp=1;
		for(int j=0; j<p[i]; ++j){
			tmp*=n;
			if(tmp>LIMIT){
				tle=true;
				break;
			}
		}		
		if(tle) break;
		else{
			tmp*=t;	
			if(tmp>LIMIT){
				tle=true;
				break;
			}
			
			ans+=tmp;
		}
		
		if(ans>LIMIT){
			tle=true;
			break;
		}
	}
	
	if(tle) printf("TLE\n");
	else cout << ans << endl;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
	ll n,a,b; cin >> n >> a >> b;
	vector<ll> h(n);
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	ll l=0; ll r=1e9;
	while(l+1<r){
		ll mid=(r+l)/2;
		ll cnt=0;
		for(int i=0;i<n;i++){
			if(h[i]>mid*b){
				cnt+=((h[i]-mid*b+(a-b-1))/(a-b));
			}
		}
		if(cnt<=mid){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	cout << r << endl;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();

        int[] t = new int[n];

        for(int i=0; i<n-1; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            t[b] = a;
        }

        long[] p = new long[n];
        for(int i=0; i<q; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt();
            p[a] += b;
        }


        for(int i=1; i<n; i++) {
            p[i] += p[t[i]];
        }

        System.out.print(p[0]);
        for(int i=1; i<n ;i++) {
            System.out.print(' ');
            System.out.print(p[i]);
        }
        System.out.println();
    }

}


Measured memory_bytes: 164172
#include <stdio.h>
 int main () {
   int a, b, x;

   scanf("%d %d\n", &a, &b);

   if (a >= b) {
     while (b != 0) {
       x = a % b;
       a = b;
       b = x;
     }
    printf("%d\n", a);
   }

   if (b > a) {
     while (a != 0) {
       x = b % a;
       b = a;
       a = x;
     }
    printf("%d\n", b);
   }

   return 0;
}

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

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

using namespace std;

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

	if (b % a == 0)
		cout << a + b << endl;
	else
		cout << b - a << endl;

	return 0;
}

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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

ll cnt = 0; 

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 

int main(){
  ll n;
  cin>>n;
  
  string s;
  cin>>s;

  ll ans = 0;
  rep(i, n){
    if(i==0) continue;
    ll can= 0;
    map<char, ll> m;
    rep(j, i){
      //cout<<s[j]<<endl;
      m[s[j]]++;
    }
    rep(j, n-i){
      //cout<<"#"<<s[i+j]<<endl;
      if(m[s[i+j]]) {
	can++;
	m[s[i+j]]=0;
      }
    }
    chmax(ans, can);
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n;
ll ans,s1[200005],s2[200005];
int main(){
	in(n);
    for(int i=1;i<=n;i++){
        int x;
        in(x);
        s1[i]=s1[i-1]+x;
        s2[i]=s2[i-1]^x;
    }
    int l=1;
    for(int r=1;r<=n;r++){
        while((s1[r]-s1[l-1])!=(s2[r]^s2[l-1]))l++;
        ans+=(r-l+1);
    }
    printf("%lld\n",ans);
	return 0;
}


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

int main(){
    int n;
    uint64_t a[100'000], b[100'000];
    uint64_t x = 0;
    cin >> n;
    for(int i=0;i<n;++i) cin >> a[i];
    for(int i=0;i<n;++i) x ^= a[i];
    for(int i=0;i<n;++i) b[i] = a[i] & (~x);

    int st = 0;
    for(int i=59;i>=0;--i){
        for(int j=st;j<n;++j){
            if((b[j]>>i) & 1){
                swap(b[st], b[j]);
                break;
            }
        }
        if(((b[st]>>i) & 1) == 0) continue;
        for(int j=0;j<n;++j){
            if(j==st) continue;
            if((b[j]>>i) & 1) b[j] ^= b[st];
        }
        ++st;
    }
    uint64_t p = 0;
    for(int i=0;i<n;++i){
        p = max(p, p^b[i]);
    }
    cout << x + 2*p << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>

int main()
{
  char ch;
  short int sum;

  do {
    sum = 0;

    fscanf(stdin, "%c", &ch);
    while (ch != '\n') {
      sum += (short int)atoi(&ch);
      fscanf(stdin, "%c", &ch);
    }

    if (sum != 0) {
      fprintf(stdout, "%hd", sum);
      putchar('\n');
    }
  } while (sum != 0);

    return 0;
}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      std::string ss; scan(ss);
      long t; scan(t);
      long n = ss.size();
      for(long i = 0; i < n; ++i) {
         if( ss[i] != 'a' and t >= 26 - (ss[i] - 'a') ) {
            t -= (26 - (ss[i] - 'a'));
            ss[i] = 'a';
         }
      }
      ss[n-1] = ((ss[n-1] - 'a') + t) % 26 + 'a';
      puts(ss.c_str());
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 512
//#include<cstdio>
//#include<cstdlib>
#include <iostream>
#include <vector>
#include <queue>
//#include<bitset>
//#include<string>
//#include<stack>
//#include<set>
//#include<unordered_set>
//#include<map>
//#include<unordered_map>
//#include<cstring>
//#include<complex>
//#include<cmath>
//#include<iomanip>
//#include<numeric>
#include <algorithm>
#include <stdio.h>
//#include<list>
//#include<functional>
//#include<cassert>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define m 1000000007
void pv(vector<ll> arr, ll size)
{

    for (ll i = 0; i < size; i++)
    {
        cout << arr[i] << ' ';
    }
}
void gv(vector<ll> &arr)
{
    ll size = arr.size();
    for (ll i = 0; i < size; i++)
    {
        cin >> arr[i];
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll H, W;
    cin >> H >> W;
    //vector<ll> arr(n);
    ll arr[H + 1][W + 1] = {0}, dp[H + 1][W + 1] = {0};
    for (ll i = 1; i <= H; i++)
    {
        for (ll j = 1; j <= W; j++)
        {
            char c;
            cin >> c;
            if (c == '#')
                arr[i][j] = 1;
            else
                arr[i][j] = 0;
        }
    }
    dp[1][1] = 1;
    for (ll i = 0; i <= H; i++)
    {
        for (ll j = 0; j <= W; j++)
        {
            if (i == 0 || j == 0)
                dp[i][j] = 0;
            else
            {
                if (arr[i][j] == 1)
                {
                    dp[i][j] = 0;
                    continue;
                }
                dp[i][j] = (dp[i][j] + dp[i][j - 1]) % m;

                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % m;
            }
            // cout << dp[i][j] << " ";
        }
        // cout << '\n';
    }
    cout << dp[H][W];
    return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"


signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    
    cin>>n>>k;
    int a[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    
    vector<int> cycle;
    cycle.push_back(1);
    bool visited[n+1];
    for(i=1;i<=n;i++)
    {
        visited[i]=false;
    }
    visited[1]=true;
    ans=a[1];
    
    while(visited[ans]==false)
    {
        cycle.push_back(ans);
        visited[ans]=true;
        ans=a[ans];
    }
    
   
    
    
    temp = cycle.size();
    if(k<temp)
    {
        cout<<cycle[k]<<endl;
    }
    
    else
    {
        k=k-temp;
        ans=a[cycle[temp-1]];
        i=-1;
        for(auto it : cycle)
        {
            i++;
            if(it==ans)
            {
                count=i;
                break;
            }
            
        }
        
        cycle.erase(cycle.begin() , cycle.begin()+i);
        
        
        temp=cycle.size();
        
        cout<<cycle[k%temp]<<endl;
    }
   
    
    
}

Measured memory_bytes: 7092
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld n,r,s,i,j,t,k,p,q,b;string s1,s2,s3,s4;
    cin>>n;lld a[n];map<lld,lld>m;
    rep(i,0,n)
    {
        cin>>a[i];
        m[a[i]]++;
    }s=0;
    for(auto it=m.begin();it!=m.end();it++)
    {
        if((it->first)<=(it->second))
            s=s+(it->second)-(it->first);
        else
            s=s+it->second;
    }
    cout<<s;
}

Measured memory_bytes: 7040
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<stack>
#include<tuple>
using namespace std;
#define INF 1100000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    int r; cin>>r;
    cout<<r*r<<endl;
}



Measured memory_bytes: 256
N = int(input())
even = True if N % 2 == 0 else False
print(N*(N-1)//2-N//2)
for i in range(1, N):
  for j in range(i+1, N+1):
    if even and i + j != N+1 or not even and i + j != N:
      print(i, j)

Measured memory_bytes: 42864
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 1100000
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

const ll inf = 1e18;
ll dp[2][maxn];
int w[110];
int v[111];
int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        int n, W;
        cin >> n >> W;
        for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
        for (int i = 1; i < maxn; i++) dp[0][i] = inf;

        for (int i = 1; i <= n; i++) {
            int t = i % 2;
            for (int j = 0; j < maxn; j++) dp[t][j] = inf;
            for (int j = 0; j < maxn; j++) {
                dp[t][j] = min(dp[t][j], dp[!t][j]);
                if (j - v[i - 1] >= 0) dp[t][j] = min(dp[t][j], dp[!t][j - v[i - 1]] + w[i - 1]);
            }
        }

        ll ans = 0;
        for (int i = 0; i < maxn; i++) {
            if (dp[n % 2][i] <= W) ans = i;
        }
        cout << ans << endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

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

int main() {
  int t, n;
  for (int x=0; x<4; x++) {
    cin >> t >> n;
    if (t==1) {
      cout << 6000*n << endl;
    }
    if (t==2) {
      cout << 4000*n << endl;
    }
    if (t==3) {
      cout << 3000*n << endl;
    }
    if (t==4) {
      cout << 2000*n << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3136
def main():
    N = int(input())
    A = list(map(int, input().split(" ")))
    B = [0] * N
    for i in range(N):
        B[i] = A[i] - i - 1
    B.sort()
    answer = 0
    if N % 2:
        median = B[(N - 1) // 2]
        for b in B:
            answer += abs(b - median)
    else:
        median = [B[N // 2], B[N // 2 - 1]]
        for b in B:
            answer += abs(b - median[0])
        tmp = 0
        for b in B:
            tmp += abs(b - median[1])
        answer = min(answer, tmp)
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 25744
N = int(input())
A = list(map(int, input().split()))

for i in A:
    if i % 2 == 0 and i % 3 != 0 and i % 5 != 0:
        result = 'No'
        break
    else:
        result = 'Yes'

if result == 'No':
    print('DENIED')
else:
    print('APPROVED')

Measured memory_bytes: 9112
# スペース区切りの整数の入力
M, D = map(int, input().split())

# 1-M月 1-D日
count = 0
m_list = []

for d in range(1, D + 1):
    d10 = d // 10
    d1 = d % 10

    if d10 < 2:
        continue
    if d1 == 1:
        continue

    if d10 * d1 in range(1, M + 1):
        count += 1
print(count)

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

#define FLASH ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"

int32_t main()
{
    FLASH;
    int n; 
    cin>>n;
    int k;
    cin>>k;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
     ans+=min(arr[i],abs(k-arr[i]));
    }
    cout<<2*ans<<endl;
}

Measured memory_bytes: 3692
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

class program
{
    static public int mod = 1000000007;
    static void Main()
    {
        int[] nm = inta();
        int[] a = inta();
        int t = nm[0] - a.Sum();
        if (t < 0) t = -1;
        Write(t);

    }

    static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; }
    static string rstr() { return ReadLine(); }
    static int rint() { return int.Parse(ReadLine()); }
    static long rlong() { return long.Parse(ReadLine()); }
    static string[] stra() { return ReadLine().Split(' '); }
    static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); }
    static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; }
    static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } }
    static long LCM(long a, long b) { return a * b / GCD(a, b); }
    static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } }
    static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); }
}


Measured memory_bytes: 28880
package main

import "fmt"

func main() {
  var s, t string
  fmt.Scan(&s, &t)
  l := len(s)
  for i:=0; i<l;i++{
    if s[i] != t[i] {
      fmt.Println("No")
      return
    }
  }
  fmt.Println("Yes")
}

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

int dp[202][202]={};
const int INF=-1145141919;

int main() {
	int d,n,ans=0;
	int t[202]={},maxC[202]={},minC[202]={},hade[202]={};
	cin>>d>>n;
	
	for(int i=1;i<=d;i++){
		cin>>t[i];
	}
	for(int i=0;i<n;i++){
		cin>>minC[i]>>maxC[i]>>hade[i];
	}
	for(int i=0;i<202;i++)
		for(int j=0;j<202;j++)
			dp[i][j]=INF;
	
	for(int i=0;i<n;i++){
		if(t[1] <= maxC[i] && t[1] >= minC[i])
			dp[1][i]=0;
	}
	for(int i=2;i<=d;i++){			//??\??°
		for(int j=0;j<n;j++){		//??¨??\??????
			if(dp[i-1][j]!=INF){
				for(int k=0;k<n;k++){	//?????\??????
					if(t[i]<=maxC[k] && t[i]>=minC[k]){ //????????????
						dp[i][k]=max(dp[i-1][j]+abs(hade[k]-hade[j]),dp[i][k]); //??¨??\??????????´?????????¨?????\??????????´??????????????????¶??????
					}
				}
			}
		}
	}
	for(int k=0;k<n;k++){
		ans=max(dp[d][k],ans);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  string s;
  char s1[10],s2[10],s3[10];
  cin >> s1 >> s2 >> s3;
  
  s = "";
  s += toupper(s1[0]);
  s += toupper(s2[0]);
  s += toupper(s3[0]);
  
  cout << s << endl;
  
}


Measured memory_bytes: 256
#include <cstdio>
#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;

const double EPS = 1.0e-10;

class Node
{
public:
    string s;
    double similarity;
    Node *left, *right;
    set<string> descendant;
};

void deleteNode(Node* node){
    if(node != NULL){
        deleteNode(node->left);
        deleteNode(node->right);
        delete node;
    }
}

int checkDissymmetry(Node* x, Node* y)
{
    if(x == NULL)
        return 0;

    if(abs(x->similarity - y->similarity) < EPS){
        int ret = checkDissymmetry(x->left, y->left);
        if(ret == 0)
            ret = checkDissymmetry(x->right, y->right);
        return ret;
    }

    if(x->similarity < y->similarity)
        return 1;
    else
        return -1;
}

Node* solve(const string &s, int& i)
{
    if(s[i] == 'x'){
        Node* node = new Node;
        node->s = "x";
        node->similarity = 0.0;
        node->left = node->right = NULL;
        node->descendant.insert("x");
        ++ i;
        return node;
    }

    Node* node = new Node;
    ++ i;
    node->left = solve(s, i);
    ++ i;
    node->right = solve(s, i);
    ++ i;

    node->descendant = node->left->descendant;
    for(set<string>::iterator it=node->right->descendant.begin(); it!=node->right->descendant.end(); ++it)
        node->descendant.insert(*it);

    int common = 0;
    set<string>::iterator it1 = node->left->descendant.begin();
    set<string>::iterator it2 = node->right->descendant.begin();
    while(it1 != node->left->descendant.end() && it2 != node->right->descendant.end()){
        if(*it1 == *it2)
            ++ common;
        if(*it1 < *it2)
            ++ it1;
        else
            ++ it2;
    }
    node->similarity = common / (double)node->descendant.size();

    if(checkDissymmetry(node->left, node->right) == -1)
        swap(node->left, node->right);
    node->s = '(' + node->left->s + ' ' + node->right->s + ')';
    node->descendant.insert(node->s);

    return node;
}

void swapNode(Node* node, bool isRight)
{
    if(node->left == NULL)
        return;

    if(isRight)
        swap(node->left, node->right);

    swapNode(node->left, false);
    swapNode(node->right, true);

    node->s = '(' + node->left->s + ' ' + node->right->s + ')';
}

int main()
{
    for(;;){
        string s;
        getline(cin, s);
        if(s == "0")
            return 0;

        int i = 0;
        Node *node = solve(s, i);
        swapNode(node, false);
        cout << node->s << endl;

        deleteNode(node);
    }
}

Measured memory_bytes: 1360
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;string s;
	cin>>s;
	int ans = 0;
	rep(i, s.size()/2){
		if(s[i] != s[s.size()-1-i]){
			ans ++;
		}
	}
	cout << ans <<endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

 public class Main{
    public static void main (String[] args){
        Scanner sc = new Scanner (System.in);
        double r = sc.nextDouble();
        double answer1 = 2.0*r*Math.PI;
        double answer2 = r*r*Math.PI;
        System.out.printf("%.6f %.6f",answer2,answer1);
        sc.close();
    }
}


Measured memory_bytes: 28360
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        TreeSet<Long> ts = new TreeSet<Long>();
        while ( n-- > 0 ) {
            long temp = in.nextLong();
            if(ts.remove(temp)) continue;
            else ts.add(temp);
        }
        System.out.println(ts.size());
    }
}

Measured memory_bytes: 63356
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long h, w;
    int n;
    cin >> h >> w >> n;
    map<pair<int, int>, long long>mp;
    vector<long long>cnt(10, 0);
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        for(int j = a - 2; j <= a; j++){
            for(int k = b - 2; k <= b; k++){
                if(j > 0 && k > 0 && j + 2 <= h && k + 2 <= w){
                    mp[{j, k}]++;
                }
            }
        }
    }
    cnt[0] = (h - 2) * (w - 2) - mp.size();
    map<pair<int, int>, long long>::iterator it;
    for(it = mp.begin(); it != mp.end(); it++){
        cnt[it->second]++;
    }
    for(int i = 0; i <= 9; i++){
        cout << cnt[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 59860
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q; cin >> q;
    while(q--){
        int n; cin >> n;
        map<int,int> used;
        int cnt=0;
        while(n>=10){
            int ma=0;
            for(int i=10;;i*=10){
                if(n<i)break;
                ma=max(ma,(n%i)*(n/i));
            }
            if(used[ma]){
                cnt=-1;
                break;
            }
            used[ma]=1;
            cnt++;
            n=ma;
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
typedef long long int ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<vint> vvint;
const ll LINF = 9000000000000000000ll;
const int INF = 2000000000;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    float a;
    float ans = 0;
    rep(i, n){
        cin >> a;
        ans += 1 / a;
    } 
    ans = 1 / ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int x,y,r,a;
  scanf("%d %d",&x,&y);
  if(1<=x && y<= 10^9){
    if(y>x){
      a=x;
      x=y;
      y=a;
    }
    while(y>0){
	r=x%y;
	x=y;
	if(r==0) break;
	y=r;
	  }
      printf("%d\n",y);

  }
  return 0;
}

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

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);
	
	int n, m;
	cin >> n >> m;
	int res = (n * (n - 1) / 2) + (m * (m - 1) / 2);
	cout << res << endl;

	return 0;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	int n = s.size(), m = t.size();
	int res = 1e9;
	for (int i = 0; i < n - m + 1; ++i) {
		int diff = 0;
		for (int j = 0; j < m; ++j)
			if (s[i + j] != t[j])
				diff++;
		res = min(res, diff);
	}
	cout << res << '\n';
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll sum[252521];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  string s;
  cin>>s;
  int n=s.size();
  sum[n]=0;
  int ten=1;
  FORR(i, 0, n){
    int x=s[i]-'0';
    sum[i]=(x*ten+sum[i+1])%2019;
    ten=(ten*10)%2019;
  }
  // REP(i, n+1){
  //   cout<<sum[i]<<" \n"[i==n];
  // }
  sort(sum, sum+n+1);
  ll ans=0;
  int l=0, r=0;
  while(l<n+1){
    while(r<n+1 && sum[l]==sum[r]){
      ++r;
    }
    ans+=(r-l)*(r-l-1)/2;
    // DEBUG(l);DEBUG(r);
    l=r;
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 5260
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 1e9;
int main() {
	int d, g;
	cin >> d >> g;
	vector<int> p(d), c(d);
	rep(i,d) cin >> p[i] >> c[i];
	int ans = INF;
	for (int bit = 0; bit < (1 << d); bit++) {
		int t = 0;
		int cnt = 0;
		for (int i = 0; i < d; i++) {
			if (bit & (1 << i)) {
				t += p[i] * (i+1) * 100 + c[i];
				cnt += p[i];
			}
		}
		for (int i = d-1; i >= 0; i--) {
			if (bit & (1 << i)) continue;
			for (int j = 1; j < p[i]; j++) {
				if (t >= g) break;
				t += (i+1) * 100;
				cnt++;
			}
			break;
		}
		if (t >= g) ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list> 
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string>
#include<fstream>
#include<set>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define ld long double
#define vi vector<int>
#define vll vector<long long>
#define pi pair<int,int>
#define pll pair<long long,long long>
#define mp make_pair
#define B begin()
#define E end()
#define S size()
#define m9 1000000007
#define endl "\n"
using namespace std;
 
 

 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powmod(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = powmod(x, y/2, m) % m; 
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
} 

 
ll mul_inv(ll a, ll b) {
    ll b0 = b, t, q;
    ll x0 = 0ll, x1 = 1ll;
    if (b == 1ll) return 1ll;
    while (a > 1ll) {
        q = a / b;
        t = b, b = a % b, a = t;
        t = x0, x0 = x1 - q * x0, x1 = t;
    }
    if (x1 < 0ll) x1 += b0;
    return x1;
}
 
 
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define pin(a) for(auto x:a)cout<<x<<" ";cout<<endl
#define fck(a) cout<<a;exit(0)
#define vvll vector<vector<ll> >
#define A(b) b.begin(),b.end()
#define vpi std::vector<pll>
#include <array>
#include <stack>
#define arr2 array<ll,2>
#define arr3 array<ll,3>
#define varr2 vector<array<ll,2> >
#define varr3 vector<array<ll,3> >
//include<bits/stdc++.h>
 
 
bool fa(vll &x,vll &y){return x[0]<y[0];}
bool fa1(vll &x,vll &y){return x[1]<y[1];}
bool f1(pll &x,pll &y){return x.second>y.second;}
bool f2(pll &x,pll &y){
    return x.first>y.first;
}
 
 
bool f3(ll &x,ll &y){
    return x>y; 
    }


const ll maxn=2e5+2;





int main()
{ fastio;
//freopen("input.txt, "r", stdin); 
//freopen("output.txt", "w", stdout);

ll s;cin>>s;
vll dp(s+1,0ll);
dp[3]=1;
dp[1]=0;dp[0]=1;dp[2]=0;
for(ll i=4;i<=s;i++){
for(ll t=i-1;t>=0;t--){
    if(i-t>=3){
        dp[i]+=dp[t];
        dp[i]%=m9;
    }
}
}
p1(dp[s]);



return 0;
}





  







Measured memory_bytes: 3664
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

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

    int N;
    cin >> N;
    vector<pair<int, int>> points;
    for (int i = 0; i < N; i++)
    {
        int x, y;
        cin >> x >> y;
        pair<int, int> p = make_pair(x, y);
        points.push_back(p);
    }

    double total_distance = 0;
    vector<int> order(N);
    for (int i = 0; i < N; ++i)
    {
        order[i] = i;
    }

    int num_patterns = 0;
    do
    {
        double d = 0;
        for (int i = 0; i < N - 1; ++i)
        {
            pair<int, int> p1 = points.at(order.at(i));
            pair<int, int> p2 = points.at(order.at(i + 1));
            d += sqrt(pow(p2.first - p1.first, 2) + pow(p2.second - p1.second, 2));
        }
        total_distance += d;
        ++num_patterns;
    } while (next_permutation(order.begin(), order.end()));

    double ans = total_distance / num_patterns;

    cout << std::fixed << std::setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 256