akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
n = int(input())
list =input().split(" ")
odd_list = []
even_list = []
for i in range(n):

    if i % 2 == 0:
        even_list.append(list[i])
    else:
        odd_list.append(list[i])
Count_even_list = Counter(even_list)
Count_odd_list = Counter(odd_list)


if len(set(list)) == 1:
    print(int(len(list) / 2))
elif Count_even_list.most_common()[0][0] == Count_odd_list.most_common()[0][0]:
    print(min(len(even_list) - Count_even_list.most_common()[1][1] + len(odd_list) - Count_odd_list.most_common()[0][1],len(even_list) - Count_even_list.most_common()[0][1] + len(odd_list) - Count_odd_list.most_common()[1][1]))
else:
    print(len(even_list) - Count_even_list.most_common()[0][1] + len(odd_list) - Count_odd_list.most_common()[0][1])

Measured memory_bytes: 23496
import sys
input = sys.stdin.readline
import math

def main():
    a, b, x = [int(x) for x in input().split()]
    b_now = x / (a * a)
    menseki = b_now * a
    ans_a = menseki * 2 / b

    if a * a * b == x:
        print(0)
        exit()

    if ans_a <= a:
        z = math.degrees(math.atan(ans_a / b))
        print(90 - z)
        exit()
    else:
        menseki = a * b - menseki
        ans_b = menseki * 2 / a
        z = math.degrees(math.atan(a / ans_b))
        print(90 - z)
        exit()



if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! {
        n: usize,
        c: u64,
        k: usize,
        mut t: [usize; n]
    }
    let mut bus = 0;
    let mut capacity = 0;
    let mut time = 0;
    t.sort();
    for i in 0..n {
        if capacity == 0 {
            capacity = c;
            bus += 1;
            time = t[i];
        }
        if t[i] <= time + k {
            capacity -= 1;
        } else {
            capacity = c - 1;
            bus += 1;
            time = t[i];
        }
    }
    println!("{}", bus);
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)

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

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define JD



int main(int argv, char* argc[])
{
    FASTIO

    #ifndef JD
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif


    ll n;
    cin>>n;
    vii v(n+1,0);
    for(ll x=1;x*x<=n;++x)
    {
        for(ll y=1;y*y<=n;++y)
        {
            for(ll z=1;z*z<=n;++z)
            {
                ll k = x*x + y*y + z*z + x*y + y*z + z*x;
                if(k>n) break;
                ++v[k];
            }
        }
    }
    
    for(ll i=1;i<=n;++i)
        cout<<v[i]<<"\n";

    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef pair<string,int> P;
int main(){
  int n,m;
  cin>>n;
  map<string,int> mp;
  for(int i=0; i<n; ++i){
    string s; cin>>s;
    mp[s]++;
  }
  cin>>m;
  for(int i=0; i<m; ++i){
    string s; cin>>s;
    mp[s]--;
  }
  int max_profit=0;
  for(map<string,int>::iterator ite=mp.begin(); ite!=mp.end(); ++ite){
    if( ite->second > max_profit){
      max_profit = ite->second;
    }
  }
  cout << max_profit <<endl;
  return 0;
}


Measured memory_bytes: 764
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    unsigned long long N, M;
    cin >> N >> M;

    unsigned long long sc_set = min(N, M / 2);
    N -= sc_set;
    M -= sc_set * 2;

    unsigned long long c_set = M / 4;
    M -= c_set;

    cout << sc_set + c_set << endl;
    return 0;
}


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


using namespace std;


int main()
{
	string s;
	int k;
	cin >> k;
	cin >> s;
	if (s.length() > k)
	{
		cout << s.substr(0, k) << "...";
	}
	else
	{
		cout << s;
	}
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
	int lucky;
	int seven;

	scanf("%d", &lucky);
	seven = lucky / 100 % 10;
	if (seven == 7)
	{
		printf("Yes\n");
		return (0);
	}
	seven = lucky / 10 % 10;
	if (seven == 7)
	{
		printf("Yes\n");
		return (0);
	}
	seven = lucky % 10;
	if (seven == 7)
	{
		printf("Yes\n");
		return (0);
	}

	printf("No\n");
	return (0);
}


Measured memory_bytes: 1656
import sys

n = list(input())
order10 = len(n)

if len(n)==1:
    print(n[0])
    sys.exit()

if n.count('9')==len(n):
    ans = 9*len(n)
    print(ans)
else:
    n2 = []
    for i in range(1,len(n)):
        n2.append(n[i])

    ans = int(n[0])-1 + 9*(len(n)-1)
    if n2.count('9')==len(n2):
        ans += 1
    print(ans)


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    V<int> a(n + 1);
    for(int i = 0; i < n; i++) cin >> a[i + 1];

    V<int> b(n + 1);
    for(int i = n; i > 0; i--){
        int sum = a[i];
        for(int j = i + i; j <= n; j+=i){
            sum += b[j];
        }
        b[i] = sum % 2;
    }

    V<int> ans;
    for(int i = 1; i <= n; i++){
        if(b[i]) ans.push_back(i);
    }

    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        if(i != ans.size() - 1) cout << ans[i] << ' ';
        else cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 5220
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int x[101], y[101], h[101];
int idx;
int main() {
  int n;
  cin >> n;
  
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> h[i];
    if (h[i] != 0) {
      idx = i;
    }
  }

  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      int v = max(h[idx] + abs(i - x[idx]) + abs(j - y[idx]), 0);
      bool ok = true;
      for (int k = 0; k < n; k++) {
        if(h[k] != max(v - abs(i - x[k]) - abs(j - y[k]), 0)) {
          ok = false;
        }
      }
      if (ok) {
        cout << i << " " << j << " " << v << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
string i2s(int x){
  stringstream ss;
  ss<<x;
  string res;
  ss>>res;
  return res;
}
bool check(int x){
  string str=i2s(x);
  for(int i=0;i+1<(int)str.size();i++){
    if(str[i]+1 != str[i+1])return false;
  }
  return true;
}
int n,ans=-1;
int a[1000];
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    for(int j=0;j<i;j++){
      int num=a[i]*a[j];
      if(check(num))ans=max(ans,num);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3224
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut a: Vec<u32> = read_vec();
    let mut b: Vec<u32> = read_vec();
    let mut count: u64 = 0;
    for i in (0..n).rev() {
        if b[i] > a[i+1] {
            count += a[i+1] as u64;
            b[i] -= a[i+1];
            a[i+1] = 0;
        }
        else {
            count += b[i] as u64;
            a[i+1] -= b[i];
            b[i] = 0;
        }
        if b[i] > a[i] {
            count += a[i] as u64;
            b[i] -= a[i];
            a[i] = 0;
        }
        else {
            count += b[i] as u64;
            a[i] -= b[i];
            b[i] = 0;
        }
    }
    println!("{}", count);
}

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

namespace program{
    public class AtCoder{
        public static void Main(string[] args){
            // 整数の入力
    		long X = long.Parse(Console.ReadLine());
    		long money = 100;
    		int nen;
    		for(nen = 0; money < X; nen++){
    		    money = (long)(money * 1.01);
    		}
    		Console.WriteLine(nen);
        }
    }
}


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

int main(){
    int N;
    cin>>N;
    vector<long int>A=vector<long int>(N);
    for (int i=0; i<N; i++) {
        cin>>A[i];
    }
    
    long int s=A[0];
    long int l=s;
    for (int i=1; i<N; i++) {
        if (A[i]<s) {
            s=A[i];
        }
        if (A[i]>l) {
            l=A[i];
        }
    }
    long int ans=(l-s);
    if (ans<0) {
        ans=-ans;
    }
    
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#define MIN(x,y) x=min(x,y)
using namespace std;

const int N=100005;
const int inf=1000000000;

int n,a[N],bin[20],cnt[70005],f[70005],w[20];
vector<int> vec[20];

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

void dp(int S)
{
	for (int i=0;i<bin[16];i++) cnt[i]=cnt[i>>1]+(i&1),vec[cnt[i]].push_back(i),f[i]=inf;
	f[S]=0;
	for (int i=16;i>0;i--)
		for (int j=0;j<vec[i].size();j++)
		{
			int s=vec[i][j];
			if (f[s]==inf) continue;
			for (int x=0;x<16;x++)
				for (int y=0;y<16;y++)
				{
					if (!(s&bin[x])||!(s&bin[y])||x==y) continue;
					MIN(f[s^bin[x]^bin[x^y]^bin[y]],f[s]+1+((s&bin[x^y])>0));
				}
		}
}

int main()
{
	bin[0]=1;
	for (int i=1;i<=16;i++) bin[i]=bin[i-1]*2;
	n=read();
	for (int i=1;i<n;i++)
	{
		int x=read(),y=read(),z=read();
		a[x+1]^=z;a[y+1]^=z;
	}
	for (int i=1;i<=n;i++) w[a[i]]++;
	int S=0,ans=0;
	for (int i=1;i<=15;i++) ans+=w[i]/2,w[i]%=2,S+=bin[i]*w[i];
	dp(S);
	printf("%d",ans+f[0]);
	return 0;
}

Measured memory_bytes: 1536
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
 

#define    int                      long long int
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1110111110111
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    ppl                      pair < int , pll>              //pair of ll and pair ll 
#define    sp(x)                    setprecision(x)
 
int32_t main()
{       
    speed upp
    int n,m,ans=0;
    string s1,s2,s="";
    cin>>s1>>s2;
    n=sz(s1);
    m=sz(s2);
    int a[n+1][m+1];
    memset(a,0,sizeof(a));
    f(i,1,n)
    {
        f(j,1,m)
        {
            if(s1[i-1]==s2[j-1])
                a[i][j]=a[i-1][j-1]+1;
            else
                a[i][j]=max(a[i][j-1],a[i-1][j]);
            ans=max(ans,a[i][j]);
            // cout<<a[i][j]<<"  ";
        }
        // cout<<endl;
    }
   
    int i=n;
        for(int j=m;j>0&&i>0;)
        {
            if(a[i][j]==ans && s1[i-1]==s2[j-1])
            {
                s=s+s1[i-1];
                ans--;
                i--;
                j--;
            }
            else if(a[i][j-1]==ans)
                j--;
            else 
                i--;
        }
    
    reverse(all(s));
    cout<<s;
}

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

int main(){
    ll a;
    double b;
    cin>>a>>b;
    int c=round(b*100);
    cout<<a*c/100<<endl;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define mp(x,y)         make_pair(x,y)
#define all(c)          c.begin(), c.end()
#define ff              first
#define ss              second
#define nl              '\n'
#define inf             1e9+7
 
int main()
{
	ninja
	int t; 
	int x,a;cin>>x>>a;
	if(x<a)
		cout<<0;
	else
		cout<<10;
}



Measured memory_bytes: 256
import math
MOD = 10**9 + 7

def mod_pow(x, mod):
    xx = [1, x]
    def _pow(y, x=x):
        nonlocal xx
        if y == 0:
            return 1
        while len(xx) <= math.log(y, 2)+1:
            v = xx[-1] * xx[-1]
            v %= mod
            xx.append(v)
        i = 1
        result = 1
        while y > 0:
            if y % 2 == 1:
                result *= xx[i]
                result %= mod
            y = y >> 1
            i += 1
        return result
    return _pow

pow10 = mod_pow(10, MOD)
pow9 = mod_pow(9, MOD)
pow8 = mod_pow(8, MOD)

def f(n):
    ans = pow10(n) - (2 * pow9(n) - pow8(n))
    ans %= MOD
    return ans


def main():
    N = int(input())
    ans = f(N)
    print(ans)

if __name__ == '__main__':
    main()


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

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

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

	sort(p, p+n);
	int min = 1e9;
	int ans = 0;
	int j = 0;
	for (int i = 0; i <= 100+1; i++) {
		if (abs(i-x) < min && p[j] != i) {
			min = abs(i-x);
			ans = i;
		}
		if (p[j] == i) {
			j++;
		}
	}
	if (n == 0) {
		ans = x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
w,h,n = map(int, input().split())
x1 = [0] #1 left border of white area
x2 = [w] #2
y1 = [0] #3
y2 = [h] #4
for i in range(n):
  x,y,a = map (int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y1.append(y)
  elif a ==4:
    y2.append(y)

left = max(x1)
right = min(x2)
bottom = max(y1)
top = min(y2)


ans =max(0, right - left)*max(0, top - bottom)

print(ans)

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

int main(){
	int R,C,gki,ggki,rin;
	unsigned tmp,ary[10010];
	while(1){
		cin>>R>>C;
		if(R==0&&C==0){
			break;
		}
		for(int i=0;i<C;i++){
			ary[i]=0;
		}
		for(int i=0;i<R;i++){
			for(int j=0;j<C;j++){
				cin>>tmp;
				ary[j]+=(tmp<<(R-i-1));
			}
		}
		ggki=0;
		for(unsigned u=0;u<(unsigned)(1<<(R-1));u++){
			gki=0;
			//cout<<"u="<<u<<" ";//
			for(int i=0;i<C;i++){
				tmp=ary[i]^u;
				//cout<<"ary["<<i<<"]="<<ary[i]<<" ";//
				//cout<<"tmp("<<i<<")="<<tmp<<" ";//
				rin=0;
				for(int j=0;j<R;j++){
					if((tmp>>j)&1) rin++;
				}
				
				rin=max(rin,R-rin);
				//cout<<"rin("<<i<<")="<<rin<<" ";//
				gki+=rin;
			}
			//cout<<gki<<endl;//
			ggki=max(ggki,gki);
		}
		cout<<ggki<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  string s; cin >> s;
  vector<int> backet(26);

  rep(i, s.size()) {
    backet[s[i]-'a']++;
  }
  bool flag = true;
  rep(i, 26) {
    if(backet[i]%2 != 0) flag = false;
  }

  cout << (flag ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 256
n, c, k = map(int, input().split())
t = []
for _ in range(n):
    t.append(int(input()))
ans = 0
time_cnt = 0
mem_cnt = 1
t.sort()
for i in range(n - 1):
    time_cnt += t[i + 1] - t[i]
    mem_cnt += 1
    # print(time_cnt)
    if time_cnt > k or mem_cnt > c:
        time_cnt = 0
        mem_cnt = 1
        ans += 1
if mem_cnt == 0:
    ans += 1
elif mem_cnt > 0:
    ans += 1
print(ans)



Measured memory_bytes: 81044
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int x,y; cin >> x >> y;

    FOR(i,0,101){
        FOR(j,0,101){
            if(i+j==x){
                if(2*i+4*j == y){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


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

typedef long long ll;

const int N = 2000006;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int a,b,c;
	cin>>a>>b>>c;
	int k;
	cin>>k;
	
	int cnt = 0;
	while(b <= a){
		b*=2;
		cnt++;
	}
	while(c <= b){
		c*=2;
		cnt++;
	}
	if(cnt <= k){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	
	return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
using ll = long long;

int n, m, a[100010];
ll total = 0;
priority_queue<int> pq;
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
		total += a[i];
		pq.emplace(a[i]);
	}

	for (int i = 0; i < m; i++) {
		int h = pq.top();
		pq.pop();

		int af = h >> 1;
		total -= h - af;
		pq.emplace(af);
	}
	printf("%lld\n", total);
}

Measured memory_bytes: 1148
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer cur=nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
    
  NodePointer t = nil->prev;
  if ( t == nil ) return;
   deleteNode(t);
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
}


void insert(int key){
 
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  //   your code 
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;

 

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ) {scanf("%d",&key);insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      }
      else {
	scanf("%d",&key);delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 33076
N=gets.to_i

edges=Array.new(N){Array.new}
ret=[]

(N-1).times do |i|
    a,b=gets.split.map(&:to_i)
    e=[a-1,b-1,-1]
    ret << e
    edges[e[0]] << e
    edges[e[1]] << e
end

k=0
N.times do |i|
    k=[k,edges[i].size].max
end

stack=[[[-1,0,-1],-1]]
while !stack.empty?
    e,from=stack.pop
    to= e[0]==from ? e[1] : e[0]
    nextcol=(e[2]+1)%k
    edges[to].each do |toe|
        next if toe[0]==from || toe[1]==from
        toe[2]=nextcol
        stack << [toe,to]
        nextcol=(nextcol+1)%k
    end
end

puts k
ret.each do |e|
    puts e[2]+1
end

Measured memory_bytes: 18300
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    long long ans = 0;
    if(N % 2 == 0){
        for(int i = 0; i < N; i++){
            if(i < N / 2){
                if(i == N / 2 - 1) ans -= A[i];
                else ans -= 2*A[i];
            }
            else{
                if(i == N / 2) ans += A[i];
                else ans += 2 * A[i];
            }
        }
        cout << ans << endl;
        return 0;
    }
    long long res = 0, res2 = 0;
    for(int i = 0; i < N; i++){
        if(i <= N / 2 - 1) {
            res -= 2 * A[i];
            res2 += 2* A[N - 1 - i];
        }
        else{
            if(i == N / 2 || i == N / 2 + 1){
                res += A[i];
                res2 -= A[N - 1 - i];
            }
            else{
                res += A[i] * 2;
                res2 -= 2 * A[N - 1 - i];
            }
        }
    }
    cout << max(res2, res) << endl;
}

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

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
/*-------------------------------------------------*/
using CostType = long long;
struct Edge {
  int src, dst;
  CostType cost;
  Edge(int src_, int dst_, CostType cost_ = 0) : src(src_), dst(dst_), cost(cost_) {}
  inline bool operator<(const Edge &rhs) const {
    return cost != rhs.cost ? cost < rhs.cost : dst != rhs.dst ? dst < rhs.dst : src < rhs.src;
  }
  inline bool operator<=(const Edge &rhs) const { return cost <= rhs.cost; }
  inline bool operator>(const Edge &rhs) const {
    return cost != rhs.cost ? cost > rhs.cost : dst != rhs.dst ? dst > rhs.dst : src > rhs.src;
  }
  inline bool operator>=(const Edge &rhs) const { return cost >= rhs.cost; }
};

vector<int> color;
bool dfs(const vector<vector<Edge> > &graph, int ver, int now) {
  color[ver] = now;
  for (Edge e : graph[ver]) {
    int nx = e.dst;
    if (color[nx] == now || (color[nx] == 0 && !dfs(graph, nx, -now))) return false;
  }
  return true;
}
bool is_bipartite(const vector<vector<Edge> > &graph) {
  int sz = graph.size();
  color.assign(sz, 0);
  REP(i, sz) if (color[i] == 0) {
    if (!dfs(graph, i, 1)) return false;
  }
  return true;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  long long n; int m; cin >> n >> m;
  vector<vector<Edge> > graph(n);
  REP(i, m) {
    int a, b; cin >> a >> b; --a; --b;
    graph[a].emplace_back(Edge(a, b));
    graph[b].emplace_back(Edge(b, a));
  }
  if (is_bipartite(graph)) {
    long long black = 0, white = 0;
    REP(i, n) {
      if (color[i] == 1) ++black;
      else ++white;
    }
    cout << black * white - m << '\n';
  } else {
    cout << n * (n - 1) / 2 - m << '\n';
  }
  return 0;
}


Measured memory_bytes: 8448
import numpy as np
import sys
buf = sys.stdin.buffer

N, M, Q = map(int, buf.readline().split())
city = np.zeros((N + 1, N + 1), np.int32)
LRpq = np.array(buf.read().split(), np.int32)

LR = LRpq[:2 * M]
L = LR[::2]
R = LR[1::2]

pq = LRpq[2 * M:]
p = pq[::2]
q = pq[1::2]

np.add.at(city, (L, R), 1)
np.cumsum(city, axis=0, out=city)
np.cumsum(city, axis=1, out=city)

p -= 1
answer = city[q, q] - city[p, q] - city[q, p] + city[p, p]
print('\n'.join(answer.astype(str)))

Measured memory_bytes: 45732
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){

  string S;
  cin >> S;
  int ans = INF;
  int count = 0;
  for(int i=0; i < S.size(); i++){
    if(i % 2 == 0 and S[i] != '0'){
        count++;
    } else if (i % 2 ==1 and S[i] != '1'){
        count++;
    }
  }
  ans = min(ans, count);
  count = 0;

  for(int i=0; i < S.size(); i++){
    if(i % 2 == 0 and S[i] != '1'){
        count++;
    } else if (i % 2 ==1 and S[i] != '0'){
        count++;
    }
  }
  ans = min(ans, count);
  cout << ans << endl;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

int main() {
  string s, t;
  cin>>s>>t;

  cout<<t<<s<<endl;

  return 0;
}


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


int main() {

    int n;
    cin >> n;
    string ans;
    if (100 <= n && n <= 111) ans = "111";
    else if (112 <= n && n <= 222) ans = "222";
    else if (223 <= n && n <= 333) ans = "333";
    else if (334 <= n && n <= 444) ans = "444";
    else if (445 <= n && n <= 555) ans = "555";
    else if (556 <= n && n <= 666) ans = "666";
    else if (667 <= n && n <= 777) ans = "777";
    else if (778 <= n && n <= 888) ans = "888";
    else if (889 <= n && n <= 999) ans = "999";
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int A[100005];
int B[100005];
int C[100005];

ll cnt[100005];

int main(){

	int N;

	scanf("%d",&N);

	int i;

	for(i=0;i<N;i++){
		scanf(" %d",&A[i]);
	}
	for(i=0;i<N;i++){
		scanf(" %d",&B[i]);
	}
	for(i=0;i<N;i++){
		scanf(" %d",&C[i]);
	}

	sort(A,A+N);
	sort(B,B+N);
	sort(C,C+N);

	int pos=0;
	for(i=0;i<N;i++){
		while(1){
			if(pos>=N||C[pos]>B[i]){break;}
			pos++;
		}
		cnt[i]=(ll)(N-pos);
	}

	for(i=N-1;i>=1;i--){
	cnt[i-1]+=cnt[i];
	}


	ll ans=0ll;

	pos=0;
	for(i=0;i<N;i++){
		while(1){
			if(pos>=N||B[pos]>A[i]){break;}
			pos++;
		}
		if(pos<N){
			ans+=cnt[pos];
		}
	}

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 2304
A,B = map(int,input().split())
S=input()

P=len(S)

X=0

for i in range(A):
    if S[i]!="-":
        X=X+1
        
if S[A]=="-":
       X=X+1
        
for i in range(A+1,B+A+1):
    if S[i]!="-":
        X=X+1

if X==P:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    string s;
    cin >> a >> s;
    if(a>=3200) cout << s << endl;
    else cout << "red" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define BIGINF (int) 4e18 + 7
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define INF  (int)2e9 + 7
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

int V = 100005;


int main () {
    //freopen("inputf.txt", "r", stdin);
    //freopen("outputf.txt", "w", stdout);
    int n, c;

    long long dp[V];
    SCD(n);
    SCD(c);
    int w[105], v[105];
    for (int i = 0; i < n; i++) {
    	SCD(w[i]);
    	SCD(v[i]);
    }
   	memset(dp, BIGINF, sizeof(dp));
    long long ans = 0;
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
    	for (int j = V - v[i]; j >= 0; j--) {
    		dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
    	}
    }

    for (int i = 0; i <= V; i++)
    	if (dp[i] <= c) ans = i;
    printf("%lld", ans);

    return 0;
}



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

int main()
{
	int64_t n, k, mod = 1000000007;
	cin >> n >> k;
	vector<int64_t> as(n - 1), bs(n - 1);
	for (int64_t i = 0; i < n - 1; i++)
	{
		cin >> as[i] >> bs[i];
		as[i]--;
		bs[i]--;
	}

	vector<vector<int64_t>> g(n);
	for (int64_t i = 0; i < n - 1; i++)
	{
		g[as[i]].emplace_back(bs[i]);
		g[bs[i]].emplace_back(as[i]);
	}

	vector<int64_t> cnt(n, 0);

	int64_t ans = 1;

	auto f = [&](auto &h, int64_t now = 0, int64_t par = -1, int64_t parpar = -1) -> void {
		int64_t cur = 0;
		if (par != -1)
		{
			cur += cnt[par];
		}
		if (parpar != -1)
		{
			cur++;
		}

		(ans *= max(int64_t(0), k - cur)) %= mod;

		cnt[now]++;
		for (auto &next : g[now])
		{
			if (next == par)
			{
				continue;
			}
			h(h, next, now, par);
			cnt[now]++;
		}
	};

	f(f);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10752
/*
g++ -std=c++11 -o2 -Wall Yahoo2019A.cpp -o .\out\Yahoo2019A.out
.\out\Yahoo2019A.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  if ((n % 2 == 0 && 2*k <= n) || (n % 2 == 1 && 2*k-1 <= n)) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}


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 n, m, c;
    cin >> n >> m >> c;

    vector<int> B(m);
    int ans = 0;
    rep(i, m) { cin >> B.at(i); }
    rep(i, n) {
        int sum = 0;
        rep(i, m) {
            int tmp;
            cin >> tmp;
            sum += tmp * B[i];
        }
        if(sum + c > 0) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

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

    int f[10001];
    for (int i = 1; i <= n; i++) f[i] = 0;

    for (int i = 0; i < 5; i++) {
        cout << 0 << endl;
        if (i + 1 >= n) break;
    }
    for (int i = 6; i <= n; i++) {
        for (int x = 1; x * x < i; x++) {
            for (int y = 1; y * y <= i - x * x; y++) {
                double z = (-1 * (x + y) + sqrt(-3 * x * x - 3 * y * y - 2 * x * y + 4 * i)) / 2;
                if (floor(z) == z && z > 0) f[i]++;
            }
        }
        cout << f[i] << endl;
    }
}

Measured memory_bytes: 3648
#include<stdio.h>
int main()
{
  char s[5];
  scanf("%s",s);
  int cnt=0,i,j;
  for(i=0;i<4-1;i++){
    for(j=i+1;j<4;j++){
      if(s[i]==s[j])
        cnt++;
    }
  }
  if(cnt!=2) printf("No");
  else printf("Yes");
}

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

struct Diameter{
    vector<int> center;
    int N;

    pair<vector<int>, vector<int>> calc_dist(int start, const vector<int> G[]){
        vector<int> dist(N, -1), prev(N);
        dist[start] = 0;
        prev[start] = -1;
        queue<int> que;
        que.push(start);
        while(que.size()){
            int i = que.front(); que.pop();
            for(auto j : G[i]){
                if(dist[j] == -1){
                    dist[j] = dist[i]+1;
                    prev[j] = i;
                    que.push(j);
                }
            }
        }
        return {dist, prev};
    }

    int calculate(int n, const vector<int> G[]){
        N = n;
        auto res1 = calc_dist(0, G);
        auto d1 = res1.first;
        int v1 = max_element(d1.begin(), d1.end()) - d1.begin();
        auto res2 = calc_dist(v1, G);
        auto d2 = res2.first;
        auto p2 = res2.second;
        int v2 = max_element(d2.begin(), d2.end()) - d2.begin();
        int diam = d2[v2];
        while(v2 != -1){
            if(d2[v2] == diam/2 || d2[v2] == (diam+1)/2) center.push_back(v2);
            v2 = p2[v2];
        }
        return diam;
    }
};

vector<int> edges[200000];

int main(){
    int N;
    cin >> N;
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }

    Diameter diam;
    int D = diam.calculate(N, edges);
    cout << (D%3 == 1 ? "Second" : "First") << endl;
    return 0;
}


Measured memory_bytes: 18260
import copy
s=list(input())
mylist=[""]*(len(s)+(len(s)-1))
for i in range(len(s)):
    mylist[2*i]=s[i]
ans=0
for i in range(2**(len(s)-1)):
    l=copy.deepcopy(mylist)
    for j in range(len(s)-1):
        if (i>>j&1):
            l[2*j+1]="+"
    ans+=eval("".join(l))
print(ans)


Measured memory_bytes: 9212
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        String ans = solve(R);

        System.out.println(ans);
    }

    private static String solve(int R) {
        if (R < 1200) {
            return "ABC";
        } else if (R < 2800) {
            return "ARC";
        }

        return "AGC";
    }
}


Measured memory_bytes: 23636
#include <cstdio>
#include <algorithm>

typedef long long LL;
const int MN = 2005;

int N, X, A[MN * 2], B[MN * 2];
LL Ans;

int main() {
	scanf("%d%d", &N, &X);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &A[i]);
		A[N + i] = B[i] = A[i];
		Ans += B[i];
	}
	for (int k = 1; k < N; ++k) {
		LL Sum = (LL)k * X;
		for (int i = 1; i <= N; ++i) {
			B[i] = std::min(B[i], A[N + i - k]);
			Sum += B[i];
		}
		Ans = std::min(Ans, Sum);
	}
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

#define LEN 100005

typedef struct pp{
  char name[100];
  int time;
} Process;

void enqueue(Process);
Process dequeue();

Process p[LEN];
int head, tail, n;

int main(){
  int i, q, alltime = 0;
  Process x;
  int p_t;
  
  scanf("%d %d", &n, &q);

  for(i = 1 ; i <= n ; i++){
    scanf("%s", (p + i)->name);
    scanf("%d", &p[i].time);
  }
  head = 1;
  tail = n + 1;

  while(head != tail){
    x = dequeue();

    if(x.time < q)p_t = x.time;
    else p_t = q;

    alltime += p_t;
    x.time -= p_t;

    if(x.time > 0)enqueue(x);
    else printf("%s %d\n", x.name, alltime);    
  }

  return 0;
}

void enqueue(Process x){
  p[tail] = x;
  tail = (tail + 1) % LEN;  
}

Process dequeue(void){
  Process dq = p[head];
  head = (head + 1) % LEN;
  return dq;  
}



Measured memory_bytes: 11924
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define POPCNTI(a) __builtin_popcount(a)
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <bits/stdc++.h>
 
using namespace std;
using namespace  __gnu_pbds;
 
// #ifndef _LOCAL_DEFINE
// inline int getchar_unlocked(){return _getchar_nolock();}
// inline void putchar_unlocked(char c) {_putchar_nolock(c);}
// #endif
 
typedef long long ll;  
typedef pair<int,int> pr; 
 
const ll MOD = 1e9 + 7,OOl=LLONG_MAX;
const int N = 1e6+1, M = 1e6+1, OO = INT_MAX,OOmem = 0x4f4f4f4f;
 
inline void WRITE_CHAR(char c)  {putchar_unlocked(c);}
 
template<typename T> 
inline bool READn (T &result) {
  int minus = 1;
  char ch;
  result=0;
  ch = (char) getchar_unlocked();
  if(ch!='-') while (!isdigit(ch) && ch!=EOF) ch= (char) getchar_unlocked(), minus = (ch == '-'? -1 : minus);
 
  if(ch==EOF) return false;
  while (isdigit(ch))  result = result*10 + (int) (ch - '0'),ch = (char) getchar_unlocked();
  
  result *= minus;
  return ch != '\n';
}
template<typename T>
inline void WRITEn(T x) {
  if (x < 0) {putchar_unlocked('-'); x = -x; }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = (char)('0' + x % 10);
    x /= 10;
  }
  while (x);
  do  { putchar_unlocked(*--writePtr); }
  while (writePtr > writeBuffer);
}
inline bool Read_CHAR(char &c)
{
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  c = READ_CHARACTER;
  return true;
} 
inline bool READ_CHAR_ARRAY(char (&x)[N]) {
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  char *ptr = &x[0];
  while ((READ_CHARACTER != '\n' && READ_CHARACTER != '\t' && READ_CHARACTER != ' ' && READ_CHARACTER != EOF)) *ptr++ = READ_CHARACTER, READ_CHARACTER = (char)getchar_unlocked();
  *ptr = '\0';
  return true;
}
inline void WRITE_CHAR_ARRAY(const char *x) {
  while(*x != '\0')
    putchar_unlocked(*x++);
}
int cost[N],n,dp[N];
int main()
{
  
  READn(n);
  for(int i=0;i<n;++i) READn(cost[i]);
  dp[0]=0;
  for(int i=1;i<n;++i)
  {
    if(i-1>=0) dp[i] = dp[i-1]+abs(cost[i]-cost[i-1]);
    if(i-2>=0) dp[i] = min(dp[i],dp[i-2]+abs(cost[i]-cost[i-2]));
  }
  WRITEn(dp[n-1]);
  return 0;
}


Measured memory_bytes: 4736
import math
N = int(input())
N += 1
ans = 0
for i in range(1,N):
  for j in range(i,N):
    for k in range(j,N):
      x = math.gcd(i,j)
      x = math.gcd(x,k)
      if i == j and j == k:
        ans += x
      elif i == j or j == k:
        ans += x*3
      else:
        ans += x*6
print(ans)
        
         



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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int A, B; cin >> A >> B;
    cout << A*B << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <limits>

using lint = long long;

struct Point {
    lint x, y, dx, dy;
};

const std::string dir = "RLUD";
const std::vector<lint>
    dxs{1, -1, 0, 0},
    dys{0, 0, 1, -1};

constexpr lint INF = 5e8;

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

    std::vector<Point> ps(n);
    for (auto& p : ps) {
        char d;
        std::cin >> p.x >> p.y >> d;
        p.x *= 2, p.y *= 2;

        for (int i = 0; i < 4; ++i) {
            if (d == dir[i]) {
                p.dx = dxs[i];
                p.dy = dys[i];
            }
        }
    }

    auto sim = [&](lint t) {
        lint xmin = INF * 2, xmax = -INF * 2,
             ymin = INF * 2, ymax = -INF * 2;

        for (const auto& p : ps) {
            lint x = p.x + p.dx * t,
                 y = p.y + p.dy * t;
            xmin = std::min(xmin, x);
            xmax = std::max(xmax, x);
            ymin = std::min(ymin, y);
            ymax = std::max(ymax, y);
        }

        return std::make_pair(xmax - xmin, ymax - ymin);
    };

    auto area = [&](lint t) {
        lint dx, dy;
        std::tie(dx, dy) = sim(t);
        return dx * dy;
    };

    lint ans = std::numeric_limits<lint>::max();

    for (int d = -2; d <= 2; ++d) {
        lint ok = 0, ng = INF;
        // okの左側傾き <= d

        while (ng - ok > 1) {
            lint mid = (ok + ng) / 2;

            lint pdx, ndx;
            std::tie(pdx, std::ignore) = sim(mid - 1);
            std::tie(ndx, std::ignore) = sim(mid);

            (ndx - pdx <= d ? ok : ng) = mid;
        }
        ans = std::min(ans, area(ok));

        ok = 0, ng = INF;
        while (ng - ok > 1) {
            lint mid = (ok + ng) / 2;

            lint pdy, ndy;
            std::tie(std::ignore, pdy) = sim(mid - 1);
            std::tie(std::ignore, ndy) = sim(mid);

            (ndy - pdy <= d ? ok : ng) = mid;
        }
        ans = std::min(ans, area(ok));
    }

    std::cout << ans / 4
              << (ans % 4 == 0
                      ? ""
                      : ans % 4 == 1
                            ? ".25"
                            : ans % 4 == 2
                                  ? ".5"
                                  : ".75")
              << std::endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    int N = 3;
    vector<vector<int>> c(N, vector<int>(N));
    for(int i=0; i<N; i++) for(int j=0; j<N; j++){
        cin >> c[i][j];
    }

    vector<int> a(N, 0), b(N, 0);
    for(int i=0; i<N; i++){
        b[i] = c[0][i];
    }
    for(int i=0; i<N; i++){
        a[i] = c[i][0] - b[0];
    }

    bool ok= true;
    for(int i=0; i<N; i++) for(int j=0; j<N; j++){
        if(a[i]+b[j] != c[i][j]){
            ok = false;
        }
    }
    if(ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}   

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
N = int(readline())
S = np.zeros(N+1,'U1')
S[1:] = list(readline().rstrip().decode('utf-8'))
Q = int(readline())
query = map(int,readline().split())

isD = S == 'D'
isM = S == 'M'
isC = S == 'C'

cumD = isD.cumsum(dtype=np.int64)
cumM = isM.cumsum(dtype=np.int64)

for K in query:
    x = cumD.copy(); x[K:] -= cumD[:-K]
    x *= isM
    x[K+1:] -= isD[1:-K] * (cumM[K:-1] - cumM[:-K-1])
    print((x.cumsum() * isC).sum())


Measured memory_bytes: 58428
import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
import itertools
import copy

n = int(input())



def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

if is_prime(n):
    print(1)
    exit()

if n == 1:
    print(0)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

nums = factorization(n)

ans = 0

for i in range(len(nums)):
    num = nums[i][1]

    for j in range(1,10*8):
        num -= j
        ans += 1
        if (num < j+1):
            break

print(ans)

Measured memory_bytes: 27204