akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3", "unroll-loops")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <complex>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FIXED cout << fixed << setprecision(12);
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)])

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

signed main() {
    FAST; FIXED; RANDOM;
    string s;
    cin >> s;
    while (sz(s) < 15) s += 'o';
    int cnt = 0;
    for (auto i : s) cnt += i == 'o';
    if (cnt >= 8) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}   


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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    multiset<int, greater<int>> s;
    for(int i=0; i<n; i++){
        cin >> v[i];
        s.insert(v[i]);
    }
    for(int i=0; i<n; i++){
        if(v[i] == *s.begin()) {
            auto itr = s.begin();
            itr++;
            cout << *itr<< endl;
        }else{
            cout << *s.begin() << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 11776
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int X, Y;
	cin >> X >> Y;

    int ans = 0;
	if (X%Y==0) ans = -1;
	else {
		int i = 1;
		while (1) {
			if (X*i%Y) {
				ans = X*i;
				break;
			}
			i++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
import copy
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    A.sort()
    MAX = (10 ** 6) + 5
    prime = [True] * MAX
    ans = 0
    for i in range(1, N):
        if A[i] == A[i - 1] and prime[A[i]]:
            prime[A[i]] = False
            for j in range(A[i] * 2, MAX, A[i]):
                prime[j] = False
    for i in range(N):
        now = A[i]
        if prime[now]:
            ans += 1
            for j in range(now * 2, MAX, now):
                prime[j] = False
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 98104
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    vector<int> C(H * W);
    
    int k = 0;
    rep(i, N){
        rep(j, A[i]){
            C[k] = i + 1;
            k++;
        }
    }
//    voutput(C);
    rep(i, H){
        vector<int> R(W);
        rep(j, W){
            R[j] = C[i * W + j];
        }
        if(i % 2 == 1){
            reverse(all(R));
        }
        voutput(R);
    }
    
    return 0;
}

Measured memory_bytes: 384
def fib(n):
    if n==0 or n==1:
        return 1
    else:
        if f[n]!=0:
            return f[n]
        else:
            f[n]=fib(n-1)+fib(n-2)
            return f[n]
f=[0]*45
n=int(input())

print(fib(n))


Measured memory_bytes: 5600
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
 
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int A, B;
	cin >> A >> B;
	for (int i = 0; i < 100000; i++) {
		if ((floor)(0.08*i) == A && (floor)(0.10*i) == B) {
			puts(i);
			return 0;
		}
	}
	puts(-1);
 
	return 0;
}

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

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


const int INF = 1 << 30;
const int MOD = 1000000007;

vector<int> dp;

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

    vector<bool> b(n+10, true);
    int a;
//    a.assign(m+10, 0);
    for (int i=0; i<m; i++){
        cin >> a;
        b.at(a) = false;
    }

    dp.assign(n+10, 0);

/*
    for(int i=0; i<m; i++){
        b.at(a.at(i)) = false; // 壊れている段は false とする
    }
*/

    dp.at(0) = 1;
    if(b.at(1) == true) dp.at(1) = 1;
    for(int i=2; i<=n; i++){
        if(b.at(i) == true){
            dp.at(i) = dp.at(i-1) + dp.at(i-2);
            dp.at(i) %= MOD;
        }
    }

    cout << dp.at(n) << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,a[10000000],sum=0;
  map<int,int> date;
  vector<int> b;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    date[a[i]]++;
    if(date[a[i]]==1) b.push_back(a[i]);
  }
  for(int i=0;i<b.size();i++){
    sum+=(((date[b[i]]-1)*(date[b[i]])/2));
  }
  int save;
  for(int i=0;i<n;i++){
    save=sum;
    save-=(((date[a[i]]-1)*(date[a[i]])/2));
    save+=(((date[a[i]]-2)*(date[a[i]]-1)/2));
    cout<<save<<"\n";
  }
}
          
    

Measured memory_bytes: 13684
n=int(input())
w=[]
w.append(input())
t=1
for i in range(1,n):
    word=input()
    if word in w:
        t=0
        break
    if word[0]!=w[i-1][-1]:
        t=0
        break
    w.append(word)
if t==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62372
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;

int main() {
   string S;
   cin >> S;
   int flag = 0;

   if(S[0] != 'A') {
       flag = 1;
   }

   int counter = 0;
   for(int i = 2; i <= S.size()-2; i++) {
       if(S[i] == 'C') {
           counter++;
       }
   }
   if(counter != 1) {
       flag = 1;
   }

   for(int i = 1; i <= S.size()-1; i++) {
       if(S[i] == 'C') {
           continue;
       }
       if(islower(S[i]) == 0) {
           flag = 1;
           break;
       }
   }

   if(flag == 0) {
       cout << "AC";
   }
   else {
       cout << "WA";
   }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

ll gcd(ll a, ll b){
    if (a < b) swap(a,b);
    if (a % b == 0) return b;
    return gcd(b, a%b);
}

int main(){
    ll n,m;
    string s,t;
    
    cin >> n >> m;
    cin >> s;
    cin >> t;
    ll gcdnm = gcd(n,m);
    ll lcm = n * m / gcdnm;

    REP(i,gcdnm){
        if (s[i * (n/gcdnm)] != t[i * (m/gcdnm)]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << lcm << endl;
}

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

int main() {
    int N; cin >> N;
   vector<char> one(N);
   vector<char> two(N);
   for(int i = 0; i < N; i++) {
       cin >> one.at(i);
   }
    for(int i = 0; i < N; i++) {
       cin >> two.at(i);
   }
   for(int i = 0; i < N; i++) {
           cout << one.at(i) << two.at(i);
   }
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = k; i < j; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;

int main(){
    int n, m;
    while(cin >>n >>m && (n || m)){
        vector<P> p;
        FOR(i, m + 1, 1) p.push_back( P(0, m - i + 1) );

        REP(i, n){
            REP(j, m){
                int tmp; cin >>tmp;
                p[j].first += tmp;
            }
        }

        sort(p.rbegin(), p.rend());

        REP(i, m - 1) cout <<1 + m - p[i].second <<" ";
        cout <<1 + m - p[m - 1].second <<endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  int ans=1;
  rep(i,N){
    if(A[i]%2==0){
      if(A[i]%3&&A[i]%5) ans=0;
    }
  }
  if(ans) cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
}



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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template <typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

VI v[200000];

void add(ll *count, const int parent, const int idx, const ll val) {
    if (parent != -1) count[idx] += count[parent];
    for(int child: v[idx]) if(child != parent) add(count, idx, child, count[idx]);
}

int main() {
    int N, Q;
    cin >> N >> Q;
    
    times(N - 1) {
        int a, b;
        cin >> a >> b;
        v[a - 1].pb(b - 1);
        v[b - 1].pb(a - 1);
    }
    
    ll count[200000]; fill(count, count + 200000, 0);
    times(Q) {
        int p, x;
        cin >> p >> x;
        count[p - 1] += x;
    }
    add(count, -1, 0, 0);
    rep(i, N) {
        if(i != 0) cout << " ";
        cout << count[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 27392
// problem: "https://atcoder.jp/contests/abc161/tasks/abc161_b"

#include<bits/stdc++.h>

using namespace std;

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

    int i;
    vector<int>V(n);
    for(i=0;i!=n;i++)
        cin>>V[i];

    sort(V.begin(),V.end(),greater<int>());
    int s = 0;
    for(i=0;i!=n;i++)
        s += V[i];

    if(V[m-1] < s/(4.0*m))
        cout<<"No";
    else
        cout<<"Yes";

    return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
template<typename V> typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();

// clang-format on

bool dfs(vi v, int l, int r) {
  if (v.size() == 0) {
    return true;
  }
  bool hoge = false;
  if (v.back() > l) {
    vi _v  = v;
    int _l = v.back();
    _v.pop_back();
    hoge |= dfs(_v, _l, r);
  }
  if (v.back() > r) {
    vi _v  = v;
    int _r = v.back();
    _v.pop_back();
    hoge |= dfs(_v, l, _r);
  }
  return hoge;
}

main {
  int n;
  cin >> n;
  rep(_, n) {
    vi v(10);
    rep(i, 10) cin >> v[9 - i];
    cout << (dfs(v, 0, 0) ? "YES" : "NO") << endl;
  }
  return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

signed main(){
    int N,M;cin>>N>>M;
    UnionFindTree uf(N);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        uf.unite(a,b);
    }


    int sum=0;
    rep(i,N){
        if(uf.find(i)!=i)continue;
        if(uf.areSame(0,i)||uf.areSame(1,i))continue;
        sum+=uf.size(i);
    }

    int a=uf.size(0);
    int b=uf.size(1);
    if(a>b)swap(a,b);
    cout<<a*(a-1)/2+(b+sum)*(b+sum-1)/2-M<<endl;
    return 0;
}


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

int main(){//解答例参照した
    string s,t;
    cin >> s >> t;
    string ans;

    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());

    if( s < t ) ans = "Yes";
    else ans = "No";

    cout << ans << endl;
}

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

int main(){
	int n;
	cin >> n;
	double* a = new double[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	double bunsi = 0;
	for(int i=0;i<n;i++){
		bunsi += (1/a[i]);
	}
	double res = 1/bunsi;
	cout << fixed;
	cout << setprecision(10);
	cout << res << endl;
	return 0;
}


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

int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    int m1=0;
    int m2=0;
    rep(i,n){
        cin >> a[i];
        if(a[i]>m1){
            m2=m1;
            m1=a[i];
        }else if(a[i]>m2){
            m2=a[i];
        }
    }

    rep(i,n){
        if(a[i]==m1){
            cout << m2 << endl;
        }else{
            cout << m1 << endl;
        }
    }



    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<LL, int> II;

const int N = (int) 2e5 + 10;
int n, k, a[N];
II s[N];
int ft[N];

void Update(int i) {
	while (i <= n) {
		ft[i]++;
		i += i & -i;
	}
}

int Query(int i) {
	int ans = 0;
	while (i) {
		ans += ft[i];
		i -= i & -i;
	}
	return ans;
}

int main() {
	scanf("%d%d", &n, &k); n++;
	for (int i = 2; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i) s[i] = II(s[i - 1].first + a[i] - k, i);

	LL ans = 0; sort(s + 1, s + 1 + n);
	for (int i = 1; i <= n; ++i) {
		ans += Query(s[i].second);
		Update(s[i].second);
	}
	cout << ans;
	return 0;
}

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

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

    int ans = 100100100;
    for(int i=-100; i<=100; i++){
        int cost = 0;
        for(int j=0; j<n; j++){
            cost += (a[j]-i)*(a[j]-i);
        }
        ans = min(ans, cost);
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dl double
using namespace std;

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************
ll mod=1000000007;
void solve()
{
  ll n,k;
  cin >> n >> k;
  ll ans=0;
  for(ll i=k;i<=n+1;i++)
  {
      ll t1=i*(i-1)/2%mod;
      ll t2=n*(n+1)/2-(n-i)*(n-i+1)/2+mod;
      t2%=mod;
      ans+=t2-t1+1+mod;
      ans%=mod;
  }
  cout << ans << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 3716
d = {}
for i in range(int(input())):
  tmp = input()
  if tmp in d.keys():
    d[tmp]+=1
  else:
    d[tmp]=1
max_value = max(d.values())
keys = [k for k,v in d.items() if v == max_value]
for i in sorted(keys):
  print(i)

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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vector<int> primes;

	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}
map<int, int> primeFactors(int  n)
{
	mii factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors[2]++;

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		// int count = 0;
		while (n % i == 0)
		{
			factors[i]++;
			n /= i;
		}
	}
	if (n > 2)
		factors[n]++;
	return factors;
}

// Graph------------------------------------------------------------------------

int32_t main()
{
	FIO;
	// c_p_c();
// --------------------------------------------------
// Never GIVE UP !!!!

	int n;
	cin >> n;
	if (n % 1000 == 0)
		cout << 0 << endl;
	else
	{
		cout << (1000 - n % 1000) << endl;
	}


}




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

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

    vector<int> days;
    int low = a[0], high;
    bool isLowSearching = true;
    for(int i = 1; i < n; i++){
        if(isLowSearching){
            // 低いときを探して買って
            if(a[i] <= low) low = a[i];
            else{
                isLowSearching = false;
                high = a[i];
            }
        }
        if(!isLowSearching){
            // 高いときを探して売る
            if(a[i] < high || i == n - 1){
                days.push_back(low);
                days.push_back(high);
                isLowSearching = true;
                low = a[i];
            }else{
                high = a[i]; //a[i] >= high
            }
        }

    }

    long long int ans = 1000, stock = 0;
    for(int i = 0; i < days.size(); i += 2){
        stock = ans / days[i];
        ans = ans % days[i] + days[i + 1] * stock;
    }

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

Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s;
	cin>>s;
	int d=s.size();
	int c=0, p3=1;
	for(int i=1; i<d; i++){
		p3*=3;
		c+=p3;
	}
	int dp[2][2][2][2][10]={};
	dp[0][0][0][0][0]=1;
	for(int i=0; i<d; i++){
		for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][1][k][l][i+1]+=(dp[1][1][k][l][i]+dp[1][0][k][l][i]);
		for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][k][1][l][i+1]+=(dp[1][k][1][l][i]+dp[1][k][0][l][i]);
		for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][k][l][1][i+1]+=(dp[1][k][l][1][i]+dp[1][k][l][0][i]);
		if(3<s[i]-'0'){
			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][1][k][l][i+1]+=(dp[0][1][k][l][i]+dp[0][0][k][l][i]);
		}else if(3==s[i]-'0'){
			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[0][1][k][l][i+1]+=(dp[0][1][k][l][i]+dp[0][0][k][l][i]);
		}
		if(5<s[i]-'0'){
			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][k][1][l][i+1]+=(dp[0][k][1][l][i]+dp[0][k][0][l][i]);
		}else if(5==s[i]-'0'){
			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[0][k][1][l][i+1]+=(dp[0][k][1][l][i]+dp[0][k][0][l][i]);
		}
		if(7<s[i]-'0'){
			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][k][l][1][i+1]+=(dp[0][k][l][1][i]+dp[0][k][l][0][i]);
		}else if(7==s[i]-'0'){
			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[0][k][l][1][i+1]+=(dp[0][k][l][1][i]+dp[0][k][l][0][i]);
		}
	}
	cout<<dp[0][1][1][1][d]+dp[1][1][1][1][d]+c-3*((1<<d)-2)+3*(d-1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define F first
#define s second
#define int long long		
int x[214514];
int y[214514];
int z[214514];
int sum[214514];
signed main(){
	ic(n)
	rep(0,i,n){
		cin>>x[i];
	
	}
	rep(0,i,n){
		cin>>y[i];
	}	
	rep(0,i,n-1){
		cin>>z[i];
	}	
	int ans=0;
	rep(0,i,n){
		ans+=y[x[i]-1];
		if(x[i]-x[i-1]==1){
			ans+=z[x[i]-2];
		}
	}
	c(ans)
}				

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

#define MAX 100
int main(void){
    int N;
    int arr[MAX];
    int i,j;
    int mini;
    int tmp;
    int count = 0;
    
    cin >> N;
    for(i = 0; i < N; i++) cin >> arr[i];
    
    for(i = 0; i < N; i++){
        mini = i;
        for(j = i; j < N; j++){
            if(arr[j] < arr[mini]) mini = j;
        }
        
        if(i != mini){
            tmp = arr[i];
            arr[i] = arr[mini];
            arr[mini] = tmp;
            count++;
        }
    }
    
    cout << arr[0];
    for(i = 1; i < N; i++) cout << " " << arr[i];
    cout << endl << count << endl;
    
    return 0;
}

Measured memory_bytes: 3072
#include<iostream>
using namespace std;
#include<queue>
queue<int>mp;
#define N 105
#define INF 1<<21
int a[N][N];
int d[N];
int n;

void bfs(int s){
	mp.push(s);
	for (int i = 1;i <= n;i++){
		d[i] = INF;
	}
	d[s] = 0;
	int u;
	while (!mp.empty()){
		u = mp.front();
		mp.pop();
		for (int v = 1;v <= n;v++){
			if (a[u][v] == 0) continue;
			if (d[v] != INF) continue;
			d[v] = d[u] + 1;
			mp.push(v);
		}
	}
	for (int i = 1 ;i <= n;i++){
		if (d[i] == INF){
			cout << i << " " << "-1" << endl; 
		}
		else{
			cout << i << " " << d[i] << endl;
		}
	}
}

int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++){
		for (int j = 1;j <= n;j++){
			a[i][j] = 0;
		}
	}
	int x,m,y;
	for (int i = 1;i <= n;i++){
		cin >> x >> m;
		while (m--){
			cin >> y;
			a[x][y] = 1;
		}
	}
	bfs(1);
	return 0;
}


Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();

		int[] B = new int[M];
		for(int i = 0; i < M; i++) {
			B[i] = sc.nextInt();
		}

		int num = 0;
		long sum = 0;
		int count = 0;
		int[][] A = new int[N][M];
		for(int i = 0; i < N; i++) {
			sum = 0;
			for(int j = 0; j < M; j++) {
				num = sc.nextInt();
				A[i][j] = B[j] * num;
				sum += A[i][j];
			}
			if(sum + C > 0) {
				count++;
			}
		}

		System.out.println(count);

	}

}


Measured memory_bytes: 36572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,x;
  cin >> N >> A;
  
  x = N % 500;
  
  if(x == 0){
    cout << "Yes" << endl;
  }
   else if(x > A){
    cout << "No" << endl;
  }
   else{
    cout << "Yes" << endl;
  }
 
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

map<int,set<ii> > R;
map<int,set<ii> > C;
map<int,vector<int> > rows;
map<int,vector<int> > cols;
ii pt[111111];
ll ans;

int calcrow(int x, int l, int r)
{
	if(rows.find(x)==rows.end()) return 0;
	int lb = lower_bound(rows[x].begin(),rows[x].end(),l)-rows[x].begin();
	int rb = lower_bound(rows[x].begin(),rows[x].end(),r+1)-rows[x].begin();
	return rb-lb;
}

int calccol(int x, int l, int r)
{
	if(cols.find(x)==cols.end()) return 0;
	int lb = lower_bound(cols[x].begin(),cols[x].end(),l)-cols[x].begin();
	int rb = lower_bound(cols[x].begin(),cols[x].end(),r+1)-cols[x].begin();
	return rb-lb;
}

int d=0;
bool vis[111111];

void process(int u)
{
	vis[u]=1;
	int x=pt[u].fi; int y=pt[u].se;
	ans+=calcrow(x-d,y-d,y+d);
	ans+=calcrow(x+d,y-d,y+d);
	ans+=calccol(y-d,x-d+1,x+d-1);
	ans+=calccol(y+d,x-d+1,x+d-1);
	vi Q;
	if(!R[x-d].empty())
	{
		auto it = R[x-d].lower_bound(mp(y-d,-1));
		while(it!=R[x-d].end())
		{
			if((*it).fi<=y+d)
			{
				Q.pb((*it).se);
				C[(*it).se].erase(mp(x-d,(*it).se));
				it=R[x-d].erase(it);				
			}
			else break;
		}
	}
	if(!R[x+d].empty())
	{
		auto it = R[x+d].lower_bound(mp(y-d,-1));
		while(it!=R[x+d].end())
		{
			if((*it).fi<=y+d)
			{
				Q.pb((*it).se);
				C[(*it).se].erase(mp(x+d,(*it).se));
				it=R[x+d].erase(it);				
			}
			else break;
		}
	}
	if(!C[y+d].empty())
	{
		auto it = C[y+d].lower_bound(mp(x-d+1,-1));
		while(it!=C[y+d].end())
		{
			if((*it).fi<=x+d-1)
			{
				Q.pb((*it).se);
				R[(*it).se].erase(mp(y+d,(*it).se));
				it=C[y+d].erase(it);				
			}
			else break;
		}
	}
	if(!C[y-d].empty())
	{
		auto it = C[y-d].lower_bound(mp(x-d+1,-1));
		while(it!=C[y-d].end())
		{
			if((*it).fi<=x+d-1)
			{
				Q.pb((*it).se);
				R[(*it).se].erase(mp(y-d,(*it).se));
				it=C[y-d].erase(it);				
			}
			else break;
		}
	}
	for(int i=0;i<Q.size();i++) 
	{
		if(!vis[Q[i]]) process(Q[i]);
	}
}
 
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,s1,s2; cin>>n>>s1>>s2; s1--; s2--;
	for(int i=0;i<n;i++)
	{
		int x,y; cin>>x>>y;
		int px,py; px=x-y; py=x+y;
		pt[i].fi=px; pt[i].se=py;
		rows[px].pb(py); cols[py].pb(px);
		if(i!=s1) 
		{
			R[px].insert(mp(py,i)); C[py].insert(mp(px,i));
		}
	}
	/*
	for(int i=0;i<n;i++)
	{
		cerr<<pt[i].fi<<' '<<pt[i].se<<'\n';
	}
	*/
	for(auto it = rows.begin(); it != rows.end(); it++)
	{
		sort(it->se.begin(), it->se.end());
	}
	for(auto it = cols.begin(); it != cols.end(); it++)
	{
		sort(it->se.begin(), it->se.end());
	}
	d=max(abs(pt[s1].fi-pt[s2].fi),abs(pt[s1].se-pt[s2].se));
	//cerr<<d<<'\n';
	process(s1);
	ans>>=1;
	cout<<ans<<'\n';
}


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

int main() {
  int K , A, B ;
  int a=0;int b =0;
  cin >> K >> A >> B;
  a=A/K;
  b=B/K;
  if(A%K==0){
    cout << "OK" << endl;
  }else{
  if(b-a>=1){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
  }
}

Measured memory_bytes: 3592
#ARGUMENTS
#f: 2-d array that describes the field
#sy, sx: starting point
#h, w: height and width fo the field

$dx = [0,1,0,-1]
$dy = [1,0,-1,0]
def bfs(f, sy, sx, h, w, n, cur)
    steps = Array.new(h).map{Array.new(w,-1)}
    steps[sy][sx] = 0
    q = [[sy,sx]]
    visited = Array.new(h).map{Array.new(w)}
    visited[sy][sx] = true
    while q.size > 0
        sy, sx = q.shift
        for i in 0..3
            cy = sy + $dy[i]
            cx = sx + $dx[i]
            if cy.between?(0,h-1) && cx.between?(0,w-1) && !visited[cy][cx] && f[cy][cx]!= "X"
                q.push([cy,cx])
                visited[cy][cx] = true
                if cur == f[cy][cx].to_i
                    return [steps[sy][sx] + 1, cy, cx]
                end
                steps[cy][cx] = steps[sy][sx] + 1
            end
        end
    end
end

h, w, n = gets.split.map(&:to_i)
f = h.times.map{gets.chomp}
sy = sx = 0
f.each_with_index do |r,i|
    if r.include?("S")
        sy = i
        sx = r.index("S")
    end
end
ret = 0
1.upto(n) do |i|
    a = bfs(f, sy, sx, h, w, n, i)
    ret += a[0]
    sy = a[1]
    sx = a[2]
end
puts ret

Measured memory_bytes: 30784
import sys
import math
from itertools import permutations
input = sys.stdin.readline

def main():
    N = int(input())
    xy = [list(map(int, input().split())) for i in range(N)]
    d = [[0] * N for i in range(N)]

    for i in range(N):
        for j in range(i+1, N):
            t = math.sqrt((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)
            d[i][j] = t
            d[j][i] = t
    
    ans = 0
    count = 0
    for p in permutations(range(N)):
        count += 1
        for i in range(N-1):
            ans += d[p[i]][p[i+1]]
    print(ans / count)



if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x,ll y){
    if(y==0){
        return x;
    }else{
        return GCD(y, x % y);
    }
}
ll LCM(ll x,ll y){
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main()
{
    ll n;
    cin >> n;
    int MAX = 1e9;
    for (int i = 1; i <= sqrt(n);i++){
        if(n%i==0){
            string s = to_string(i);
            string t = to_string(n/i);
            int k = max(s.size(), t.size());
            MAX = min(k, MAX);
        }
    }
    cout << MAX << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    System.out.println((K % 2 == 0) ? K / 2 * K / 2 : K / 2 * (K / 2 + 1));
  }
}

Measured memory_bytes: 25172
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

vector<int> G[100 + 5];
int d[105];
bool travel[105];

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    int n;
    cin >> n;
    int u, k, now;
    for (int i = 1; i <= n; ++i) {
        cin >> u >> k;
        while (k--) {
            cin >> now;
            G[u].push_back(now);
        }
    }
    fill(d, d + 105, -1);
    queue<pair<int, int> > q;
    q.push({1, 0});
    while (!q.empty()) {
        int now = q.front().first;
        int distance = q.front().second;
        q.pop();
        if (travel[now]) continue;
        travel[now] = true;
        d[now] = distance;
        for (auto i : G[now]) {
            q.push({i, distance + 1});
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << i << ' ' << d[i] << '\n';
    }
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(ll x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,a[200004],K,r[200004],CNT,dat[200004];
ll d[200004],ans;
struct BIT{
	void add(int id){
		for (;id<=CNT;id+=(id&-id)) dat[id]++;
	}
	int ANS(int id){
		int ret=0;for (;id;id-=(id&-id)) ret+=dat[id];return ret; 
	}
}T;
map<ll,int>mp;
int main(){
	read(n),read(K);
	mp[0]=1;
	for (int i=1;i<=n;i++) read(a[i]),a[i]-=K,d[i]=d[i-1]+a[i],mp[d[i]]=1;
	for (map<ll,int>::iterator it=mp.begin();it!=mp.end();it++) it->second=++CNT;
	for (int i=1;i<=n;i++) r[i]=mp[d[i]];
	T.add(mp[0]); 
	for (int i=1;i<=n;i++){
		ans+=T.ANS(r[i]);
		T.add(r[i]);
	}
	write(ans);
}

Measured memory_bytes: 16640
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

int main()
{
  uint16_t a[5];
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

  uint16_t minMod10 = 10;
  for (auto& aa : a) {
    if (aa%10 > 0 && aa%10 < minMod10)
      minMod10 = aa%10;
  }

  uint16_t sum=0;
  if (minMod10==10) {
    for (auto& aa : a)
      sum += aa;
  } else {
    bool last = false;
    for (auto& aa : a) {
      if (!last && aa%10 == minMod10) {
	last = true;
	sum += aa;
      } else {
	if (aa%10==0)
	  sum += aa;
	else
	  sum += (aa/10+1)*10;
      }
    }
  }
  
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    System.out.println(H*W - h*W - H*w + h*w);
  }
}

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

int main() {
  int A, B, C, D, L , R;
  cin >> A >> B >> C >> D;

  L = A + B;
  R = C + D;
 
  if (L > R){
    cout << "Left" << endl;
  }else if (L == R){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,p;
	cin>>n>>p;
	string s;
	cin>>s;
	ll cnt=0;
	int size=s.size();
	vector<int>arr(size);
	for(int i=0; i<size; i++)
	 arr[i]=s[i]-48;
	if(p==2)
	{
		for(ll i=size-1; i>=0; i--)
		{
			if(arr[i]==0)
			{
				cnt+=i+1;
			}
			else if(arr[i]%2==0)
			{
				cnt+=(i+1);
			}
		}
	}
	else if(p==5)
	{
		for(ll i=size-1; i>=0; i--)
		{
			if(arr[i]==0)
			 cnt+=i+1;
			else if(arr[i]==5)
			 cnt+=(i+1);
		}
	}
	else
	{
		map<int,int>rel;
		rel[0]=1;
		vector<int>rem(size+1,0);
		ll pr=1%p;
		for(ll i=size-1; i>=0; i--)
		{
			rem[i]=(rem[i+1]+arr[i]*pr%p)%p;
			cnt+=rel[rem[i]];
			pr=pr*10%p;
			rel[rem[i]]++;
	    }
    }
    cout<<cnt;
	return 0;
}

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

using namespace std;
typedef pair<int, int> pii;

pii field[200009];
int result[200009];

int main() {
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> field[i].first;
        field[i].second = i;
    }
    sort(field, field+n);
    pii med_l = field[n/2-1];
    pii med_r = field[n/2];
    result[med_l.second] = med_r.first;
    result[med_r.second] = med_l.first;
    for(int t=0; t<n/2-1; t++) {
        result[field[t].second] = med_r.first;
    }
    for(int t=n/2+1; t<n; t++) {
        result[field[t].second] = med_l.first;
    }
    for(int i=0; i<n; i++) {
        cout << result[i] << endl;
    }
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

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

int main() {
  int h, w;
  cin >> h >> w;
  char field[h][w];
  int d[h][w];
  queue<P> que;
  rep(i,h) rep(j,w) {
    cin >> field[i][j];
    d[i][j] = -1;
    if (field[i][j] == '#') {
      que.push(P(i, j));
      d[i][j] = 0;
    }
  }

  while (!que.empty()) {
    P p = que.front(); que.pop();

    rep(i,4) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];

      if (nx < 0 || h <= nx) continue;
      if (ny < 0 || w <= ny) continue;
      if (field[nx][ny] == '#') continue;
      if (d[nx][ny] != -1) continue;
      que.push(P(nx, ny));
      d[nx][ny] = d[p.first][p.second] + 1;
    }
  }

  int res = 0;
  rep(i,h) rep(j,w) res = max(res, d[i][j]);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 13328
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;
int a[mx];
int t;
int n,m;
int res;

int main(){
	scanf("%d",&n);
	a[0]=-1;
	reg(i,1,n){
		scanf("%d",a+i);
	}

	reg(i,1,n){
		if(a[i]<=a[i-1]){
			m++;
		}else{
			m=0;
		}		
		res=max(m,res);		
	}
	printf("%d\n",res);
	return 0;
}




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

using namespace std;

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;
const int N = 1e5;
int s[N];

int main() {
  int n, k, q, a;
  fscanf(stdin, "%d%d%d ", &n, &k, &q);
  REP(i,n) s[i] = k - q;
  REP(i,q) {
    fscanf(stdin, "%d ", &a);
    s[a-1]++;
  }
  REP(i,n) puts(s[i]>0 ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 1024
K, A, B = map(int, input().split())

if B - A <= 2 or A + 1 > K:
    print(1 + K)
else:
    K -= (A - 1)
    ans = A
    ans += (K // 2) * (B - A)
    if K % 2 == 1:
        ans += 1
    print(ans)

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

using namespace std;

#define fo(i,n) for(int i=0; i<n; i++)
#define Fo(i,k,n) for(int i=k; i<n; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int N,K;
vl dp;
vi a;

ll mod = 1e9+7, sum = 0;

void add(int &a, ll b){
    a = a+b;
    if(a>=mod){
        a -= mod;
    }
}

void sub(int &a, ll b){
    a -= b;
    if(a<0){
        a += mod;
    }
}

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

    cin>>N>>K;
    a.resize(N+1);
    Fo(i,1,N+1){
        cin>>a[i];
        sum+=a[i];
    }
    dp.resize(K+1);
    if(sum<K){
        cout<<0<<endl;
    }else{
        Fo(i,0,min(a[1]+1, K+1))dp[i]=1;
        // cout<<dp[1]<<"ddd"<<endl;
        for(int i=2; i<=N; i++){
            int ele = a[i],sm=dp[K],pele=dp[K];
            int num=1;
            for(int j=K; j>=0; j--){
                // cout<<sm<<" "<<pele<<" "<<"ddsdsds"<<endl;
                int lmt = min(ele+1, j+1);
                if(j==K){
                    while(num<lmt){
                        add(sm, dp[j-num]);
                        // cout<<sm<<" "<<j<<" "<<num<<" "<<lmt<<" "<<dp[j-num]<<endl;
                        num++;
                    }
                }else{
                    sub(sm, pele);
                    if(j-ele>=0)add(sm, dp[j-lmt+1]);
                    // cout<<sm<<" "<<j<<" "<<dp[j-lmt+1]<<" "<<j-ele<<endl;
                }
                pele = dp[j];
                dp[j] = sm;
                // cout<<endl;
            }
        }
        cout<<dp[K]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int trainCost = a;
        if (a > b) trainCost = b;

        int busCost = c;
        if (c > d) busCost = d;

        System.out.println(trainCost + busCost);
    }
}


Measured memory_bytes: 23764
n, k = gets.split.map(&:to_i)
s, p, r = gets.split.map(&:to_i)
scores = { s: s, p: p, r: r }
total = 0
t = gets.chop.chars

n.times do |i|
  if t[i] == t[i - k] && i - k >= 0
    t[i] = nil
    next
  end

  total += scores[t[i].to_sym]
end

p total


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    if (n == 1) {
        cout << a[0] << endl;
        return 0;
    }

    vll b, c;
 

    rep(i, n) {
        if (i % 2)
            b.emplace_back(a[i]);
        else
            c.emplace_back(a[i]);
    }

    if (n % 2) {
        reverse(c.begin(), c.end());
        for (int i = 0; i < c.size(); i++) {
            cout << c[i] << " ";
        }
        for (int i = 0; i < b.size(); i++) {
            cout << b[i] << " ";
        }

        cout << endl;
    } else {
        reverse(b.begin(), b.end());

        for (int i = 0; i < b.size(); i++) {
            cout << b[i] << " ";
        }
        for (int i = 0; i < c.size(); i++) {
            cout << c[i] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 6668
def main():
    N = int(input())
    a = list(map(int,input().split()))
    a_set = set(a)
    if len(a_set) > 3:
        return('No')

    if len(a_set) == 1:
        if sum(a_set) == 0:
            return('Yes')
        else:
            return('No')

    elif len(a_set) == 2:
        a_1,a_2 = sorted(a_set)
        if a_1 == 0 and a.count(a_1)*3 == N:
            return ('Yes')
        else:
            return('No')

    else:
        a_1,a_2,a_3 = a_set
        if a.count(a_1) == a.count(a_2) and a.count(a_1) == a.count(a_3) and a.count(a_3) == a.count(a_2):
            if a_1^a_2 == a_3:
                return ('Yes')
            else:
                return('No')
        else:
            return('No')

print(main())


Measured memory_bytes: 20752
#define rep(i,n) for (int i=0;i<n;i++)
#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const long long INF = 1LL<<60;
 
int main(){
  int N,j=1;
  cin >> N;
  
  vector<int> dp(N+1,INT_MAX);
  vector<bool> torf1(N+1,false);
  vector<bool> torf2(N+1,false);
  

  /*  while(pow(9,j)<N+1){
      torf1.at(pow(9,j))=true;
      j++;
    }
  
    while(pow(6,j)<N+1){
      torf2.at(pow(6,j))=true;
      j++;
    }
  */
  
  dp.at(0)=0;
  
  for(int i=1;i<N+1;i++){
    
    while(pow(9,j)<=i){
        dp.at(i)=min(dp.at(i-pow(9,j))+1,dp.at(i));
      j++;
    }
    j=0;
    while(pow(6,j)<=i){

      	dp.at(i)=min(dp.at(i-pow(6,j))+1,dp.at(i));
      j++;
    }
    j=0;
    
    dp.at(i)=min(dp.at(i-1)+1,dp.at(i));
    
   // cout << dp.at(i) << endl;
  }
  
  cout << dp.at(N) << endl;
  
}

Measured memory_bytes: 768