akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s){
		int a=0,b=0;
		rep(i,s.size()-2){
			if(s[i]=='J'&&s[i+1]=='O'&&s[i+2]=='I')a++;
			if(s[i]=='I'&&s[i+1]=='O'&&s[i+2]=='I')b++;
		}
		cout<<a<<endl<<b<<endl;
	}
}



Measured memory_bytes: 3216
#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;
    cin >> N;
    vector<int> L(N);
    rep(i,N) cin >> L[i];

    vector<int> tmp(3);

    int ans = 0;

    
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=j+1;k<N;k++){
                if(L[i] == L[j] or L[j] == L[k] or L[k] == L[i]) continue;
                tmp[0] = L[i];
                tmp[1] = L[j];
                tmp[2] = L[k];
                sort(tmp.begin(), tmp.end());
                if(tmp[0] + tmp[1] > tmp[2]) ans++;
            }
        }
    }
    cout << ans << endl;
    
    return 0; 
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, string, int> T;
int main() {
    int N;
    cin >> N;
    set<string> se;
    vector<T> v(N);
    for (int i = 0; i < N; i++) {
        string s;
        int p;
        cin >> s >> p;
        se.insert(s);
        v[i] = T(p, s, i + 1);
    }
    sort(v.begin(), v.end(), greater<T>());
    for (auto s : se) {
        for (int i = 0; i < N; i++) {
            if (get<1>(v[i]) == s) {
                cout << get<2>(v[i]) << endl;
            }
        }
    }
}

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

using namespace std;

int main(void){
        string s;
        long long int k;
        int only1 = 1, ans;

        cin >> s >> k;

        for (int i = 1; i <= s.size(); i++){
                if (s[i-1] == '1'){
                        if (i == k){
                                ans = 1;
                                break;
                        }
                }
                else {
                        ans = s[i-1] - '0';
                        break;
                }
        }

        cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;


int main(){long N, M;
cin >> N >> M;
vector<pair<long, long>> v;
    v.push_back(make_pair(0, 0));
erep(i, M){
    long a1, a2;
    cin >> a1 >> a2;
    v.push_back(make_pair(a1, a2));
} 
map<pair<long, long>, long> s;//順番を記録
erep(i, M){
    s[pair<long, long>(v[i].first, v[i].second)] = i;
}
vector<string> ans(M+1);
sort(eall(v));
    long tmp = 1;
erep(i, M){
    
    if(v[i].first == v[i-1].first) tmp++;
    else tmp = 1;
    long x = s[pair<long, long>(v[i].first, v[i].second)];
    string tmp1, tmp2;
    tmp1 = to_string(v[i].first);
    tmp2 = to_string(tmp);
    long tmp1s = tmp1.size();
    long tmp2s = tmp2.size();
    rep(j, 6-tmp1s){
        tmp1 = '0' + tmp1;
    }
    rep(j, 6-tmp2s){
        tmp2 = '0' + tmp2;
    }
    // cout << tmp1 << ' ' << tmp2 << endl;
    ans[x] = tmp1+tmp2;

}
erep(i, M){
    show(ans[i]);
}




return 0;
}

Measured memory_bytes: 14832
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  cout<<48-n<<endl;

}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    map<string, int> a;
    int n;
    cin >> n;

    rep(i, n) {
        string tmp;
        cin >> tmp;
        a[tmp] += 1;
    }

    cout << "AC x " << a["AC"] << endl;
    cout << "WA x " << a["WA"] << endl;
    cout << "TLE x " << a["TLE"] << endl;
    cout << "RE x " << a["RE"] << endl;

    return 0;
}

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

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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;

int main(){
  ll X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  vector<ll> A(X),B(Y),C(Z);
  for(ll i = 0LL; i < X; i++) cin>>A[i];
  for(ll i = 0LL; i < Y; i++) cin>>B[i];
  for(ll i = 0LL; i < Z; i++) cin>>C[i];
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  reverse(A.begin(),A.end());
  reverse(B.begin(),B.end());
  reverse(C.begin(),C.end());
  priority_queue<vector<ll>> q;
  q.push({A[0]+B[0]+C[0],0,0,0});
  vector<ll> ans;
  map<vector<ll>,bool> m;
  m[{0,0,0}] = true;
  for(ll i = 0LL; i < K; i++){
    vector<ll> t = q.top();
    ans.push_back(t[0]);
    q.pop();
    if(t[1]<X-1LL&&!m[{t[1]+1LL,t[2],t[3]}]) {
      q.push({t[0]-A[t[1]]+A[t[1]+1LL],t[1]+1LL,t[2],t[3]});
      m[{t[1]+1LL,t[2],t[3]}]=true;
    }
    if(t[2]<Y-1LL&&!m[{t[1],t[2]+1LL,t[3]}]) {
      q.push({t[0]-B[t[2]]+B[t[2]+1LL],t[1],t[2]+1LL,t[3]});
      m[{t[1],t[2]+1LL,t[3]}]=true;
    }
    if(t[3]<Z-1LL&&!m[{t[1],t[2],t[3]+1LL}]) {
      q.push({t[0]-C[t[3]]+C[t[3]+1LL],t[1],t[2],t[3]+1LL});
      m[{t[1],t[2],t[3]+1LL}]=true;
    }
  }
  for(auto x:ans)cout<<x<<endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
 
using namespace std;
 
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> v_lamps(N);
 
	for (int n = 0; n < N; ++n) {
		int temp;
		scanf("%d", &temp);
		v_lamps[n] = temp;
	}
 
	for (int ik = 0; ik < K; ++ik) {
		vector<int> b(N + 1, 0);
		for (int in = 0; in < N; ++in) {
			int l = max(0, in - v_lamps[in]);
			int r = min(in+v_lamps[in]+1, N);
			b[l]++;
			b[r]--;
		}

		for (int in = 0; in < N; ++in) {
			b[in + 1] += b[in];
		}

		b.pop_back();
		if (v_lamps == b) break;
		v_lamps = b;

	}
 
	for (auto lamp : v_lamps) {
		cout << lamp << " ";
	}
	cout << endl;
 
	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const ll INF = 1e18;
const ld PI = acos((ld) - 1);

int main () {
	int d, t, s;
	cin >> d >> t >> s;
	cout << (t * s >= d ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <algorithm>
#include <iomanip>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define ld long double
 
#define mp make_pair
#define pb push_back

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define ft first
#define sd second
#define endl "\n"
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
const long double pi=asin(1)*2;
 
const ll M=1000000007;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll pow1(ll a,ll b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=(res*a)%M;
		}
        a=(a*a)%M;
        b>>=1;
    }
    return res%M;
}
const ll N =100001;



int main()
{
	fast;
	int t;
	t=1;
//	cin>>t;
	while(t--)
	{
		ll n,x,t;
		cin>>n>>x>>t;
		ll a;
		if(n%x==0){
			a=n/x;
		}
		else{
			a=n/x+1;
		}
		cout<<a*t<<endl;
	}
	return 0;
}

Measured memory_bytes: 3580
/**
 * Created by hiramekun at 18:47 on 2020-04-04.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]

ans = 10 ** 18
for i in range(2 ** N):
    cost = 0
    each_alg = [0 for _ in range(M)]
    for j in range(N):
        if (i >> j) & 1:
            cost += CA[j][0]
            for k in range(M):
                each_alg[k] += CA[j][k+1]
    if min(each_alg) >= X:
        ans = min(ans, cost)

if ans == 10**18:
    print('-1')
else:
    print(ans)

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

int main()
{
    int N; cin >> N;
    vector<string>  w(N);
    for (int i = 0; i < N; i++){
        cin >> w[i];
    }

    //同じ文字列があるかどうか
    for (int i = 0; i < N; i++){
        for (int j = i + 1; j < N; j++){
            if (w[i] == w[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    //しりとりできてるかな
    for (int i = 0; i < N - 1; i++){
        if (w[i].back() != w[i + 1].front()){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  double l,ans = 0;
  cin >> l;
  ans = (l/3)*(l/3)*(l/3);
  cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np


N,M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
Diff = [X[k+1]-X[k] for k in range(len(X)-1)]
Diff.sort()
for _ in range(N-1):
  if len(Diff) > 0:
    Diff.pop(-1)
  else:
    break

print(sum(Diff))

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

int main() 
{
    int N,Q,len;
    string S;

    cin >> N >> Q >> S;
    len = 0;
    
    int data[ S.length() + 1 ] = { 0 };

    for( int i=1 ; i<S.length() ; i++ )
    {
        if( S[i-1] == 'A' && S[i] == 'C' ) len++;
        data[ i ] = len;
    }

    for( int i=0 ; i<Q ; i++ )
    {
        int start, end;
        cin >> start >> end;
        cout << ( data[ end-1 ] - data[ start-1 ] ) << endl;
    }
}

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


typedef long long ll;
const ll P = 1e9 + 7;

ll mul(ll a, ll b) {
    return (a * b) % P;
}

ll fact(ll x) {

    ll res = 1;
    for(ll i = 1; i < x + 1; ++i) {
        res = mul(res, i);
    }
    return res;
}

int main()
{


    ll n, m;
    cin >> n >> m;

    if(abs(n - m) > 1)
        puts("0");
    else {

        if(n == m) {
            cout << mul(2LL, mul(fact(n), fact(m))) << endl;
        }
        else {
            cout << mul(fact(n), fact(m)) << endl;
        }

    }

    return 0;

}


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

using namespace std;

int main() {
    int n;  cin >> n;
    vector<int> v(n,0);
    for (int i = 0; i < n-1; i++) {
        int p;  cin >> p;
        v[p-1]++;
    }

    for (int i = 0; i < n; i++)
        cout << v[i] << endl;

    return 0;
}

Measured memory_bytes: 3976
#c dp version
n,m = map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()) )
from collections import deque
a=deque(a)
mod=10**9 + 7

dp=[0]*(n+2)
dp[0]=0
dp[1]=1
aa=0
if len(a)>0:
    aa=a.popleft()
for i in range(2,n+2):
    if i-1 == aa:
        dp[i]=0
        if len(a)>0:
            aa=a.popleft()
    else:
        dp[i]=( dp[i-1]+dp[i-2] )%mod
print(dp[-1])

Measured memory_bytes: 52568
N = input()
one_digit = int(N) % 10
if one_digit == 2 or one_digit == 4 or one_digit == 5 or one_digit == 7 or one_digit == 9:
  print("hon")
elif one_digit == 0 or one_digit == 1 or one_digit == 6 or one_digit == 8:
  print("pon")
else:
  print("bon")



Measured memory_bytes: 9112
h, w    = list(map(lambda v:int(v), input().split()))
input()
colors  = list(map(lambda v:int(v), input().split()))

color_idx   = 0
color_output_count  = 0
res     = []

for y in range(h):
    row = []
    for x in range(w):
        row.append(color_idx + 1)
        color_output_count += 1
        if (colors[color_idx] == color_output_count):
            color_idx   += 1
            color_output_count  = 0

    if (y % 2) == 1:
        row.reverse()

    res.append(row)


for y in range(h):
    for x in range(w):
        print(str(res[y][x]) + " ", end="")
    print("")


Measured memory_bytes: 4080
import sys
input = sys.stdin.readline

n = int(input())

from collections import defaultdict

d = defaultdict(int)

for i in range(n):
    s = list(input().rstrip())
    s.sort()
    d["".join(s)] += 1

ans = 0

for i in d.keys():
    ans += d[i]*(d[i] - 1)//2

print(ans)

Measured memory_bytes: 58844
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const S = input[0][0];

  for (let i = 2; i < S.length; i += 2) {
    const firstHalf = S.slice(0, (S.length - i) / 2);
    const secondHalf = S.slice((S.length - i) / 2, i * -1);

    if (firstHalf === secondHalf) {
      return S.length - i;
    }
  }

  return 0;
};

console.log(main(read()));


Measured memory_bytes: 29588
n = int(input())
a = list(map(int, input().split()))

def gcd(x, y):
    if x < y:
        return gcd(y, x)
    elif y == 0:
        return x
    elif x % y == 0:
        return y
    else:
        return gcd(y, x % y)

x = [0]*n
y = [0]*n

for i in range(1, n):
    x[i] = gcd(x[i-1], a[i-1])
for i in range(n-1, 0, -1):
    y[i-1] = gcd(y[i], a[i])

z = [gcd(x[i], y[i]) for i in range(n)]

print(max(z))

Measured memory_bytes: 14076
#include <bits/stdc++.h>
#define rep(i,x,n) for(int (i)=(x);(i)<(n);(i)++)
#define sort(v) sort(v.begin(),v.end())
using namespace std;

int isAnagram(string s, string t);

int main(){
    
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,0,n){
        cin >> s[i];
        sort(s[i]);
    }

    long long ans=0;
    unordered_map<string,int> um;

    rep(i,0,n){
        if(um[s[i]]!=0){
            ans+=um[s[i]];
        }
        um[s[i]]++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 17700
#include <iostream>
using namespace std;
#define mod 1000000007
int main () {
  long long n, m;
  cin >> n >> m;
  if (n > m) {
    swap(n, m);
  }
  long long ans = 1;
  if (n == m || n == m - 1) {
    for (int i = 0; i < m; i++) {
      ans = ans * (i + 1);
      ans = ans % mod;  
    }  
    if (n == m - 1) {
      for (int i = 0; i < n; i++) {
        int sub = m - 1 - i;
        ans = ans * (sub);
        ans = ans % mod;  
      }   
    }
    else {
      for (int i = 0; i < n; i++) {
        int sub = m - i;
        ans = ans * sub;
        ans = ans % mod; 
      }  
      ans = ans * 2 % mod;
    }
    cout << ans << endl;
  }
  else {
    cout << 0 << endl;  
  }
    
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>

#define pb push_back
#define pf push_front
#define st first
#define nd second
#define sz(x) ((int)x.size())
#define ins insert
#define fastio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define pi acos(-1.0)
using namespace std;

const int maxn=2e5+10;
const int maxe=1e6+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int gcd(int a,int b){
    while(b){
        a%=b;
        swap(a,b);
    }
    return a;
}

struct sgt{
    struct tree{
        int l,r,lazy,ans;
    }tree[maxn<<2];
    void build(int root,int l,int r){
        tree[root].l=l,tree[root].r=r,tree[root].ans=tree[root].lazy=0;
        if(tree[root].l==tree[root].r)return;
        int mid=(l+r)>>1;
        build(root<<1,l,mid);
        build(root<<1|1,mid+1,r);
    }
    void push_down(int root){
        if(tree[root].lazy){
            tree[root<<1].ans=tree[root<<1].l+tree[root].lazy;
            tree[root<<1|1].ans=tree[root<<1|1].l+tree[root].lazy;
            tree[root<<1|1].lazy=tree[root<<1].lazy=tree[root].lazy;
            tree[root].lazy=0;
        }
    }
    void change(int root,int l,int r,int x){
        int tl=tree[root].l,tr=tree[root].r;
        int mid=(tl+tr)>>1;
        if(tl>=l&&tr<=r){
            tree[root].ans=tree[root].l+x;
            tree[root].lazy=x;
            return;
        }
        push_down(root);
        if(l<=mid)change(root<<1,l,r,x);
        if(r>mid)change(root<<1|1,l,r,x);
        tree[root].ans=min(tree[root<<1].ans,tree[root<<1|1].ans);
    }
    int ask(int root,int l,int r){
        int tl=tree[root].l,tr=tree[root].r;
        int mid=(tl+tr)>>1;
        if(tl>=l&&tr<=r){
            return tree[root].ans;
        }
        push_down(root);
        if(r<=mid)return ask(root<<1,l,r);
        else return ask(root<<1|1,l,r);
    }

}sg;

int n,m;
int main(){
    scanf("%d%d",&n,&m);
    int lmost=1;
    sg.build(1,1,m);
    for(int i=1;i<=n;++i){
        int l,r;
        scanf("%d%d",&l,&r);
        if(lmost<l){
            sg.change(1,l,r,sg.ask(1,l-1,l-1)-(l-1));
        }
        else if(lmost>=l&&lmost<=r){
            sg.change(1,lmost,r,inf);
            lmost=r+1;
        }
        if(lmost>m)puts("-1");
        else printf("%d\n",i+sg.ask(1,1,m));
    }
}


Measured memory_bytes: 11840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int cnt = 0;
		for(int i = 1 ; i <= N ; i++) {
			cnt += i;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 21588
n,m=map(int,input().split())
ass=[tuple(map(int,input().split())) for i in range(m)]
ass.sort(key=lambda x:x[1])

acum = []

def ifsatisfied(ab):
    for x in acum:
        if ab[0]<x <=ab[1]:
            return(True)
    return(False)

for ab in ass:
    if (acum == [] or ab[0]>=acum[-1]):
        acum.append(ab[1])

print(len(acum))


Measured memory_bytes: 18160
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b,c,t;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b){
		t=a;
		a=b;
		b=t;
	}
	if(a>c){
		t=a;
		a=c;
		c=t;
	}
	if(b>c){
		t=b;
		b=c;
		c=t;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}


Measured memory_bytes: 3212
/*
ID: kiwio
LANG: C++14
TASK: 
*/

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

int a, b, x;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(NULL);/*
#ifndef turtle
	ofstream cout (".out");
	ifstream cin (".in");
#endif*/
	cin >> a >> b >> x;
	if (x<a or x>a+b) {
		cout << "NO";
	}
	else {
		cout << "YES";
	}
 }

Measured memory_bytes: 256
n,m,q = map(int,input().split())
abcd = [list(map(int,input().split())) for i in range(q)]
ls = [1]
ans=0
def dfs(n,m,i,ls):
    global ans
    global abcd
    temp=0
    if len(ls)==n:
        for j in abcd:
            if ls[j[1]-1] - ls[j[0]-1] == j[2]:
                temp+=j[3]
        ans=max(ans,temp)
    else:
        for j in range(i,m+1):
            dfs(n,m,j,ls+[j])
dfs(n,m,1,ls)
print(ans)

Measured memory_bytes: 9176
#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;
    cin >> n >> m;
    int h[n];
    rep(i, n) cin >> h[i];

    int a, b;
    int cnt[n] = {0};
    rep(i, m) {
        cin >> a >> b;
        a--; b--;
        if (h[a] > h[b]) cnt[b] = 1;
        if (h[a] < h[b]) cnt[a] = 1;
        if (h[a] == h[b]) {
            cnt[a] = 1;
            cnt[b] = 1;
        }
    }
    int ans = 0;
    rep(i, n) {
        if (cnt[i] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4324
//author: JainBot27
//Created on: 08/22/20
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;


#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, y, z) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, z, 0)
#define trav(x, y) for(auto&x:y)


const string nl = "\n";
using ll = int64_t;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;


template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }


#ifdef D 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif



signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vi a(n); trav(x, a) cin >> x;
    int ma = 0;
    ll ans =0;
    trav(x, a){
        ckmax(ma, x);
        ans += ma - x;
    }
    cout << ans << nl;
}
/*
 * Stuff I should try:
 * Is it Monotonic? -> Binary Search
 * Is N small? -> Bitsets or other exponential
 * Edge Cases? Look Carefully 
 * Can't figure anything out? Brute Force and see patterns
 * Try to prove greedies
 * Prefix Sums, Amortization, DP, Data Structures
*/


Measured memory_bytes: 4040
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

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

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll a,b,v,w,t;
void input(){
    fast_io();
    cin >> a >> v;
    cin >> b >> w;
    cin >> t;
}

#define NO do{cout <<"NO" << endl; return 0;}while(false);
#define YES do{cout <<"YES" << endl; return 0;}while(false);

int solve(){
    if(w>=v) NO
    ll diff = abs(a-b);
    if(diff>(v-w)*t) NO
    else YES
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3640
import bisect
import collections


def main6():
    values = collections.defaultdict(int)
    element_count = 0

    q = int(input())

    for _ in range(q):
        com, *para = map(int, input().split())

        if   com == 0:
            values[para[0]] += 1
            element_count += 1
            print(element_count)

        elif com == 1:
            print(values[para[0]])

        elif com == 2:
            element_count -= values[para[0]]
            values[para[0]] = 0

        elif com == 3:

            if para[0] == para[1]:
                for _ in range(values[para[0]]):
                    print(para[0])

            elif  abs(para[0] - para[1]) < 10:

                for i in range(para[0], para[1] + 1):
                    for _ in range(values[i]):
                        print(i)
            
            else:
                key_list = [k for k, v in values.items() if v != 0]
                key_list = sorted(key_list)

                lb = bisect.bisect_left(key_list, para[0])
                rb = bisect.bisect_right(key_list, para[1])

                for s in key_list[lb:rb] :
                    for _ in range(values[s]):
                        print(s)

main6()


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

int main(){
  int64_t L,R;
  cin>>L>>R;
  if(R-L>=2019){
    cout<<0<<endl;
  }
  else{
  int64_t Lmod,Rmod;
  Lmod=L%2019;
  Rmod=R%2019;
  int min=2018;
  if(Lmod>=Rmod){
    cout<<0<<endl;
  }
  else{
    for(int i=Lmod;i<Rmod;++i){
      for(int j=i+1;j<=Rmod;++j){
        if((i*j)%2019<min){
          min=(i*j)%2019;
        }
      }
    }
  }
  cout<<min<<endl;
}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int 		  	long long
#define f(i,n)        	for(int i=0;i<(n);++i)
#define fa(i,a,n)     	for(int i=a;i<=(n);++i)
#define fd(i,a,n)     	for(int i=a;i>=(n);--i)
#define tc 			  	int t;cin>>t;f(testcase,t)
#define pii             pair<int,int>
#define allx 			x.begin(),x.end()
#define tr(c,i) 		for(auto i = c.begin(); i != c.end(); i++)
#define present(c,x) 	(c.find(x) != c.end())
#define cpresent(c,x) 	(find(allc,x) != c.end())
#define	PI 3.1415926535897932
void c_p_c() {

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

}
void solve() {
	string s;
	cin >> s;
	int n = s.length();
	if (s[n - 1] == 's') {
		s += "es";
	}
	else
		s += "s";
	cout << s;
}

int32_t main() {

	c_p_c();
	//tc
	solve();
	return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define     int                 ll
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
	int n,m,k; cin>> n >> m >> k;
	vector<int> a(n+1), b(m+1);
	for(int i = 0; i < n; ++i) {
		cin >> a[i+1];
		a[i+1] += a[i];
	}
	for(int i = 0; i < m; ++i) {
		cin >> b[i+1];
		b[i+1] += b[i];
	}
	int ans=0;
	for(int i = 0, j = m; i <= n; ++i) {
		if(a[i] > k)
			break;
		while(a[i] + b[j] > k){
			--j;
		}
		ans=max(i+j, ans);
	}
	cout << ans;
}

signed main() { 
    IO();
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}
	

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

using namespace std;

int main() {
  int n;
  cin>>n;
  vector<int> arr;
  int adjacent = 1;
  int result = 0;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin>>tmp;
    if (tmp == i + 1) {arr.push_back(i);}
  }
  int j = 0;
  int N = arr.size();
  while (j < N) {
    if (j + 1 < N && arr[j] + 1 == arr[j + 1]) {
      adjacent++;
      j++;
      continue;
    }
    if (adjacent != 1) {
      result += (adjacent + 1) / 2;
      adjacent = 1;
      j++;
    }
    else {
      result++;
      j++;
    }
  }
  cout<<result;
  
  return 0;
}

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

using namespace std;

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

    vector<int> color(9, 0);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (a < 3200) {
            color[a / 400] = 1;
        } else {
            color[8]++;
        }
    }
    
    int x = accumulate(color.begin(), color.end() - 1, 0);
    int y = color[8];

    int ansMin = (x == 0) ? 1 : x;
    int ansMax = x + y;

    cout << ansMin << " " << ansMax << endl;
    return 0;
}

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

int main(){
    int H,W;
    cin>>H>>W;
    string str[110];
    for(int i=0;i<H;i++){
        cin>>str[i];
    }
    vector <bool> a(H,false);
    vector <bool> b(W,false);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(str[i][j]=='#'){
                a[i]=true;
                b[j]=true;
            }
        }
    }
    for(int i=0;i<H;i++){
        if(a[i]){
            for(int j=0;j<W;j++){
                 if(b[j]){
                cout<<str[i][j];
                }
            }
            cout<<endl;
        }
        }
    }


Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    input! {
        n: usize,
        t: usize,
        mut ab: [(usize, usize); n],  // Vec
    }

    // sort ab
    ab.sort_unstable_by(|(a0,_),(a1,_)|a0.cmp(a1));
    let ab = ab;

    // compute maximum manzokukans without the last order
    let mut table :Vec<Vec<usize>> = vec![vec![0;t];n];
    for i in 0..n {
        for j in 0..t {
            let (a, b) = ab[i];
            // The case where meal No.i is not eaten
            let manzoku0 = if i > 0 {
                table[i-1][j]
            } else {
                0
            };
            // The case where meal No.i is eaten
            let manzoku1 = if i > 0 && j >= a {
                table[i-1][j-a] + b
            } else if j >= a {
                b
            } else {
                0
            };

            table[i][j] = manzoku0.max(manzoku1);
        }
    }
    let table = table;

    let mut maxmanzoku = 0;
    for i in 0..n {
        let (_, b) = ab[i];
        for j in 0..t {
            let withoutlast = if i > 0 {
                table[i-1][j]
            } else {
                0
            };
            let manzoku = withoutlast + b;
            maxmanzoku = maxmanzoku.max(manzoku);
        }
    }

    println!("{}", maxmanzoku);
}


Measured memory_bytes: 72476
#include <stdio.h>
#include <ctype.h>

int main()
{
  char input_st;
  int i;
  int counter[26] = {0};
  /*
  for(i = 0 ; i <= 26 ; i++)
    counter[i] = 0;
*/
  while(scanf("%c", &input_st) != EOF)
  {
    if(isupper(input_st))
    {
      i = input_st - 'A';
      counter[i]++;
    }
    else if(islower(input_st))
    {
      i = input_st - 'a';
      counter[i]++;
    }
  }

  for(i = 0 ; i < 26 ; i++)
    printf("%c : %d\n", 'a' + i, counter[i]);
}



Measured memory_bytes: 2120
#include<stdio.h>

void sort(int *ary, int begin, int end){
  int i, j, work, pivot;

  pivot=ary[(begin+end)/2];
  i=begin;
  j=end;

  while(1){
    while(ary[i]<pivot) ++i;
    while(ary[j]>pivot) --j;

    if(i>=j) break;
    work=ary[i];
    ary[i]=ary[j];
    ary[j]=work;

    i++;
    j--;
  }
  if(begin<i-1) sort(ary, begin, i-1);
  if(j+1<end) sort(ary, j+1, end);
}

int main(){
  int n, k, i, j, total=0;
  scanf("%d %d", &n, &k);
  int p[n];

  for(i=0; i<n; i++)
    scanf("%d", &p[i]);

  sort(p, 0, n-1);
  for(i=0; i<k; i++)
    total+=p[i];

  printf("%d\n", total);
  return 0;
}


Measured memory_bytes: 1684
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


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

	int mx = 0;
	for (int i=1; i<N-1; i++) {
		string s1 = S.substr(0, i);
		string s2 = S.substr(i, N-i);
		set<char> set1;
		set<char> set2;
		rep(i, s1.size()) {
			set1.insert(s1[i]);
		}
		rep(i, s2.size()) set2.insert(s2[i]);
		int cnt = 0;
		for (auto e1 : set1) {
			for (auto e2 : set2) {
				if (e1==e2) cnt++;
			}
		}
		mx = max(mx, cnt);
	}
	cout << mx << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll h=in(),n=in();
    map<ll,ll>waza;
    for(ll i=0;i<n;++i){
        ll a=in(),b=in();
        if(waza.count(a)==0||waza[a]>b)waza[a]=b;
    }

    constexpr ll inf=1e9;
    auto ans=vec2<ll>(waza.size()+1,h+1,inf);
    ans[0][0]=0;
    auto itr=waza.begin();
    for(ll i=1;i<=waza.size();++i,++itr){
        ll d=itr->first,m=itr->second;
        for(ll j=0;j<=h;++j){
            for(ll k=0;;++k){
                ans[i][j]=min(ans[i][j],ans[i-1][max(0ll,j-k*d)]+k*m);
                if(j-k*d<0)break;
            }
        }
    }
    cout<<ans.back().back()<<endl;
}


Measured memory_bytes: 80640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
	if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
	fact.resize(n+5);
	inv_fact.resize(n+5);
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= n; i++){
		fact[i] = (fact[i-1] * i) % mod;
		inv_fact[i] = exp(fact[i], mod-2, mod);
	}
}

ll komb(ll a, ll b){
	if(a < b) return 0;
	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 5e3+5;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	vector<ll> cnt(1e5 + 5, 0);
	ll sum = 0;
	for(int i = 0; i < n; i++){
		int s; cin>>s;
		sum += s;
		cnt[s]++;
	}
	int q; cin>>q;
	while(q--){
		int a, b; cin>>a>>b;
		sum -= 1ll*a*cnt[a];
		sum += 1ll*b*cnt[a];
		cnt[b] += cnt[a];
		cnt[a] = 0;
		cout<<sum<<"\n";
	}
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
int main(){
    double orz,mmin = 1e9,mmax = -1;
    while(~scanf("%lf",&orz)){
        mmax = max(mmax,orz);
        mmin = min(mmin,orz);
    }
    printf("%.1f\n",mmax-mmin);
    return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
int gcd(int a,int b) {return __gcd(a,b);}//if you use gcc to compile, use this

signed _main(){
  int K; cin >> K;
  int ans=0;
  for(int i=1;i<=K;i++) for(int j=1;j<=K;j++) for(int k=1;k<=K;k++){
    int t=gcd(i,j);
    ans+=gcd(t,k);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3648
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Debug.Trace
main :: IO ()
main = B.getLine >>= print . solve

solve :: B.ByteString -> Int 
solve l = edit $ foldl' ff (0, 1) [(n - 1),(n - 2)..0]
    where
        edit (acc, p) = add acc p
        
        n = B.length l
        ff (acc, p) i
            | c == '1' = (acc `add` mul p b, mul p 2)
            | otherwise = (acc, p)
            where
                c = B.index l $ n - i - 1
                b = pow 3 i

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

infixl 6 `add`
infixl 7 `mul`

add :: Int -> Int -> Int
add x y = val $ x + y

mul :: Int -> Int -> Int
mul x y = val $ x * y

inv :: Int -> Int
inv x = pow x $ modVal - 2

pow :: Int -> Int -> Int
pow b e
    | e == 0 = 1
    | odd e = mul b . pow b $ e - 1
    | otherwise = mul v v
    where
        v = pow b $ e `div` 2

val :: Int -> Int
val = (`mod` modVal)

modVal :: Int
modVal = 10 ^ 9 + 7

primes :: [Int]
primes = build [2..]
    where
        build (x : xs) = x : build (filter (\n -> n `mod` x /= 0) xs)
        
isPrime :: Int -> Bool
isPrime n = check primes
    where
        check (x : xs)
            | x == n = True
            | x > n = False
            | otherwise = check xs

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

const int MAX_LEN = 10005;
const int MAX_D = 105;
const int MOD = (int)1e9 + 7;

int dp[MAX_LEN][MAX_D][2];

char k[MAX_LEN];
int len;
int d;

int solve(int pos, int mod, int flag) {
    if (pos >= len) return mod == 0;
    if (dp[pos][mod][flag] != -1) return dp[pos][mod][flag];

    int& ans = dp[pos][mod][flag];
    ans = 0;
    for (int i = 0; i <= 9; i++) {
        if (flag == 0) {
            int digit = k[pos] - '0';
            if (i > digit) break;
            ans += solve(pos + 1, (mod + i) % d, i < digit);
        } else {
            ans += solve(pos + 1, (mod + i) % d, flag);
        }
        ans %= MOD;
    }
    ans %= MOD;
    return ans;
}

int main(void) {
    scanf(" %s", k);
    scanf(" %d", &d);

    len = strlen(k);
    memset(dp, -1, sizeof(dp));
    int ans = solve(0, 0, 0);
    printf("%d\n", (ans - 1 + MOD) % MOD);

    return 0;
}


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

#define PB emplace_back

using namespace std;

const int N = 1e5+100;

long long int dp[N], du[N], n, m;

vector<long long int> v[N];

struct node{
    vector<long long int> pre, ar, suf;
}nd[N];

void out(node co) {
    for(int u: co.ar) cout << u << ' ';
    cout << '\n';
    for(int u: co.pre) cout << u << ' ';
    cout << '\n';
    for(int u: co.suf) cout << u << ' ';
    cout << '\n';
}

bool ok(node &r) {
    long long int ad = 1;
    r.pre.PB(1);
    for(int i = 0 ; i < r.ar.size() ; i++ ) {
        ad*=r.ar[i];
        ad%=m;
        r.pre.PB(ad);
    }
    reverse(r.ar.begin(),r.ar.end());
    ad = 1;
    r.suf.PB(1);
    for(int i = 0 ; i < r.ar.size() ; i++ ) {
        ad*=r.ar[i];
        ad%=m;
        r.suf.PB(ad);
    }
    reverse(r.ar.begin(),r.ar.end());
}

long long int del(node &r, long long int x) {
    return (r.pre[x]*r.suf[r.ar.size()-x-1])%m;
}

void dfs2(int x=0, int px=-1, int tu = -1) {
    du[x]=1;
    if(px!=-1) {
        du[x]+=du[px]*((nd[px].ar.size()!=1)?del(nd[px],tu):1);
        du[x]%=m;
    }
    int tt = 0;
    for(int u: v[x]) {
        if(u!=px) dfs2(u,x,tt++);
    }
}

void dfs(int x=0, int px=-1) {
    dp[x]++;
    for(int u : v[x]) {
        if(u!=px) dfs(u,x), dp[x]=(dp[x]*(dp[u]+1))%m;
    }
    if(px!=-1) nd[px].ar.PB(dp[x]+1);
    ok(nd[x]);
}

int main () {
    cin >> n >> m;
    for(int i = 0 ; i < n - 1 ; i++ ) {
        long long int u1, u2;
        cin >> u1 >> u2;
        u1--;
        u2--;
        v[u1].PB(u2);
        v[u2].PB(u1);
    }
    dfs();
    dfs2();
    for(int i = 0 ; i < n ; i++ ) {
        cout << (dp[i]*du[i])%m << '\n';
    }
}


Measured memory_bytes: 30208
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
static constexpr double PI = 3.1415926535897932;

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

	template <typename T>
	auto scan(T &d) ->
		typename std::enable_if<std::is_same<T, std::string>::value>::type {
		d = std::string();
		int c = 0;
		while (c < 'a' || 'z' < c)
			c = fgetc(stdin);
		while ('a' <= c && c <= 'z') {
			d.push_back(c);
			c = fgetc(stdin);
		}
	}
	template <typename T>
	auto scan(T &d) ->
		typename std::enable_if<std::is_same<T, double>::value>::type {
		scanf("%lf", &d);
	}
	template <typename T>
	auto scan(T &d) ->
		typename std::enable_if<std::is_signed<T>::value ==
		std::is_same<T, std::string>::value>::type {
		d = 0;
		int c = 0;
		while (c < '0' || '9' < c)
			c = fgetc(stdin);
		while ('0' <= c && c <= '9') {
			d = d * 10 + c - '0';
			c = fgetc(stdin);
		}
	}
	template <typename T>
	auto scan(T &d) ->
		typename std::enable_if<std::is_signed<T>::value !=
		std::is_same<T, double>::value>::type {
		d = 0;
		int c = 0;
		bool f = 0;
		while (c < '0' || '9' < c) {
			if (c == '-')
				f = 1;
			c = fgetc(stdin);
		}
		while ('0' <= c && c <= '9') {
			d = d * 10 + c - '0';
			c = fgetc(stdin);
		}
		if (f)
			d = -d;
	}

int main(void)
{
	uint64 n, m;
	scan(n);scan(m);
	if (n == 1) {
		if (m == 1) {
			puts("1");
		}
		else {
			printf("%lu\n", m - 2);
		}
	}
	else if (m == 1) {
		printf("%lu\n", n - 2);
	}else printf("%lu\n", (n - 2)*(m - 2));
	return 0;
}

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

int main() {
  int n, m = 0;
  string s;
  cin >> n >> s;
  rep(i, n-1){
    unordered_set<char> a, b;
    int c = 0;
    rep(j, n){
      if(j <= i) a.insert(s[j]);
      else b.insert(s[j]);
    }
    for(auto d: a){
      if(b.count(d)) ++c;
    }
    m = max(m, c);
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int[]A = new int[N];
		int ans = 0;
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
			if(i%2==0 && A[i]%2==1){
				ans++;
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 17844
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

int main()
{

	int n, s[1000] = {};
	double a, m, t;

	while (1) {
		cin >> n;
		if (n == 0) break;

		m = t = 0;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
			m += s[i];
		}
		m = m / n;
		for (int i = 0; i < n; i++) {
			t += (s[i] - m) * (s[i] - m);
		}
		a = sqrt(t / n);
		cout << fixed << a << endl;
	}

	return 0;
}

Measured memory_bytes: 1240