akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**6)
from collections import deque

# input
N = int(input())
Edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    Edges[a-1].append(b-1)
    Edges[b-1].append(a-1)

# process
# 頂点を2グループに分類
group = [-1]*N
group[0] = False
def categorize2g(pi, i, g):
    for ci in Edges[i]:
        if ci == pi:
            continue
        group[ci] = not g
        categorize2g(i, ci, not g)

categorize2g(-1, 0, 0)

# 順列を求める
ans = [0]*N
mod0 = [x for x in range(1, N+1) if x%3 == 0]
mod1 = [x for x in range(1, N+1) if x%3 == 1]
mod2 = [x for x in range(1, N+1) if x%3 == 2]
gtnum = sum(group)
if gtnum <= N//3:
    dq = deque(mod1+mod2+mod0)
elif N-gtnum <= N//3:
    dq = deque(mod0+mod1+mod2)
else:
    dq = deque(mod1+mod0+mod2)

if len(ans) == N:
    for i, g in enumerate(group):
        if g:
            ans[i] = dq.pop()
        else:
            ans[i] = dq.popleft()

# output
# print(group)
print(" ".join(map(str, ans)))


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

int main(){
  int a,b;
  cin >> a >> b;
  int p,q;
  p = a % 3;
  q = b % 3;
  if (p == 0 || q == 0 || (p + q) % 3 == 0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N = int(input())
    s = input()
    t = input()

    for i in range(N, 0, -1):
        if s[-i:] == t[:i]:
            print(2 * N - i)
            break
    else:
        print(2 * N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#蟻本参照
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
##redline,recursionlimit変更
v,e = map(int, input().split( ))

E = [[] for _ in range(v)]
revE = [[] for _ in range(v)]
used = [0]*v
kaeri = []
topo = [-1 for _ in range(v)]

for _ in range(e):
    s,t = map(int, input().split( ))
    E[s].append(t)
    revE[t].append(s)

q = int(input())

############
def dfs(v):
    used[v] = 1
    for u in E[v]:
        if not used[u]:
            dfs(u)
    kaeri.append(v)
    
def re_dfs(v,k):
    used[v] = 1
    topo[v] = k
    for u in revE[v]:
        if not used[u]:
            re_dfs(u,k)
###
for u in range(v):
    if not used[u]:
        dfs(u)
kaeri.reverse()        


used = [0]*v
k = 0
for u in kaeri:
    if not used[u]:
        k+=1
        re_dfs(u,k)
#print(topo)
for _ in range(q):
    u,v = map(int, input().split( ))
    if topo[u]==topo[v]:
        print(1)
    else:
        print(0)


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

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s=="Sunny")
        cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")
        cout<<"Rainy"<<endl;
    else if(s=="Rainy")
        cout<<"Sunny"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    for(int i=n;i<1000;i++){
        stringstream ss;
        ss<<i;
        string s = ss.str();
        if(s[0]==s[1] && s[1]==s[2]){
            cout<<i<<endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll INF = LLONG_MAX/3;
using P = pair<ll,int>;

const int N = 4004;

struct SegTree{
    int n; vector<P> dat;
    //初期化
    SegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<P>(2*n-1,{INF,N});
    }
    //k番目(0-indexed)の値をaに更新
    void update_min(int k, ll a, int idx){
        // printf("  UPD: %d %lld\n",k,a);
        k+=n-1;
        dat[k] = min(dat[k], {a,idx});
        //更新
        while(k>0){
            k=(k-1)/2;
            dat[k]=min(dat[2*k+1],dat[2*k+2]);
        }
    }
    //内部的に投げられるクエリ
    P _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return {INF,N};
        if(a<=l && r<=b) return dat[k];

        P vl=_query(a,b,2*k+1,l,(l+r)/2);
        P vr=_query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
    //[a,b)
    P query(int a, int b){
        return _query(a,b,0,0,n);
    }
};

ll dp[N][N];
int par[N][N];

int main(){
    int n;
    scanf(" %d", &n);
    vector<ll> a(n);
    rep(i,n) scanf(" %lld", &a[i]);

    vector<ll> s(n+1);
    for(int i=1; i<=n; ++i) s[i] = s[i-1]+a[i-1];

    fill(dp[0],dp[N],INF);
    dp[0][0] = -INF;

    fill(par[0],par[N],-1);

    for(int i=1; i<=n; ++i){

        vector<ll> v;
        rep(j,n+1){
            v.pb(s[j] + dp[i-1][j]);
        }
        sort(all(v));
        v.erase(unique(all(v)), v.end());
        // dbg(v);

        int V = v.size();
        SegTree st(V);

        rep(j,n+1){
            int idx = lower_bound(all(v), s[j]) - v.begin();
            P res = st.query(0,idx);
            // dbg(res);
            if(res.fi < INF && dp[i][j] > s[j] + res.fi){
                dp[i][j] = s[j] + res.fi;
                par[i][j] = res.se;
            }

            int uidx = lower_bound(all(v), s[j]+dp[i-1][j]) - v.begin();
            st.update_min(uidx, -s[j], j);

            // printf(" %d: idx %d  uidx %d\n",j,idx,uidx);
        }

        // printf(" --------- i %d\n",i);
        // rep(j,n+1) printf(" dp %d  %lld  , par %d\n",j,dp[i][j],par[i][j]);
    }

    int m = 0;
    rep(i,n+1){
        if(dp[i][n] < INF) m = i;
    }

    int now = n;
    vector<int> ans;
    rep(i,m-1){
        now = par[m-i][now];
        ans.pb(now);
        // printf("%d\n", now);
    }

    reverse(all(ans));

    printf("%d\n", m);
    rep(i,m-1) printf("%d%c", ans[i], " \n"[i==m-2]);
    return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, K;
    cin >> K >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll start = A[0];
    ll m = 0;
    vector<ll> B;
    rep2(i, 1, N) {
        B.push_back(A[i] - start);
        m = max(m, B[B.size() - 1]);
        start = A[i];
    }
    B.push_back(K - A[N - 1] + A[0]);
    m = max(m, B[B.size() - 1]);
    ll s = accumulate(B.begin(), B.end(), 0LL);
    cout << s - m << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 4084
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;

int mod;
int mult(int i, int j) { return (ll) i * j % mod; }
int add(int i, int j) {
    if((i += j) >= mod) i -= mod;
    return i;
}

int dp[100000];
int pd[100000];
int D[100000];
vvi vex;

int dfs(int i, int p) {
    dp[i] = 1;
    vi pref(1, 1), suf;
    for(int r : vex[i])
        if(r != p)
            dp[i] = mult(dp[i], add(1, dfs(r, i)));

    return dp[i];
}

void dfs2(int i, int p) {
    vi pref(1, 1), suf;
    
    for(int r : vex[i])
        if(r != p)
            pref.push_back(add(dp[r], 1));
    
    suf = pref;
    suf.push_back(1);
    reverse(suf.begin(), suf.end());
    suf.pop_back();
    for(int i = 1; i < pref.size(); ++i) {
        pref[i] = mult(pref[i], pref[i - 1]);
        suf[i] = mult(suf[i], suf[i - 1]);
    }
    
    reverse(suf.begin(), suf.end());
    
    int l = 0;
    for(int r : vex[i])
        if(r != p) {
            pd[r] = mult(mult(pref[l], suf[l + 1]), add(pd[i], 1));
            l += 1;
            dfs2(r, i);
        }
    
    D[i] = mult(dp[i], add(1, pd[i]));
    return ;
}

int main() {
    int n; cin >> n >> mod;
    vex.resize(n);
    int u, v;
    for(int i = 1; i < n; ++i) {
        cin >> u >> v;
        vex[--u].push_back(--v);
        vex[v].push_back(u);
    }
    
    dfs(0, 0);
    dfs2(0, 0);
    for(int i = 0; i < n; ++i)
        cout << D[i] << ' ';

    return 0;
}


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

using namespace std;

int main()
{
    while (true) {
        const int e = [] {
            int e;
            cin >> e;
            return e;
        }();
        if (e == 0) {
            return 0;
        }

        int min_ = 1'000'000 + 1;
        for (int z = 0; z * z * z <= e; ++z) {
            for (int y = 0; y * y + z * z * z <= e; ++y) {
                int x = e - z * z * z - y * y;
                if (x >= 0) {
                    min_ = min(min_, x + y + z);
                }
            }
        }
        cout << min_ << endl;
    }
}


Measured memory_bytes: 2992
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
  int R[MAX],n;
  cin>>n;
  for(int i=0;i<n;i++)cin>>R[i];
  int maxv=-2000000000;
  int minv=R[0];
  for(int i=1;i<n;i++){
    maxv=max(maxv,R[i]-minv);
    minv=min(minv,R[i]);
  }
  cout<<maxv<<endl;
  return 0;
}


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

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

  switch (N % 10)
  {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    cout << "hon" << endl;
    break;
  case 0:
  case 1:
  case 6:
  case 8:
    cout << "pon" << endl;
    break;
  case 3:
    cout << "bon" << endl;
    break;
  }
}


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

int N,K;

typedef vector<int> vec;
typedef vector<vec> mat;



void view(const vec& a){
  for(int i=0;i<a.size();i++)
    cout << a[i] << " ";
  cout << endl;
}

vec plusv(const vec&a, const vec&b ){
  vec ret = vec(a.size());
  for(int i=0;i<(int)ret.size();i++){
    ret[i] = a[b[i]];
  }
  return ret;
}

vec powv(vec a,int t){
  vec ret = vec(N);
  for(int i=0;i<N;i++) ret[i] = i;
  while( t > 0 ){
    if( t & 1 ){
      ret = plusv(ret, a);
    }
    a=plusv(a,a);
    t>>=1;
  }
  return ret;
}

vec getv(const mat& a){
  vec ret = vec(N);
  for(int i=0;i<N;i++) ret[i] = i;
  for(int i=0;i<(int)a.size();i++){
    for(int j=0;j<N-1;j++){
      if( a[i][j] )
        swap(ret[j],ret[j+1]);
    }
  }
  return ret;
}

vec A[256];

int cnt,len;
string buf;

vec expression();
int number(){
  int ret = 0;
  if( isdigit(buf[cnt]) ){
    ret = buf[cnt++]-'0';
    while( isdigit(buf[cnt]) ){
      ret *= 10;
      ret += buf[cnt++]-'0';
    }
    return ret;
  }
  return -1;
}

char chara(){
  if( 'A' <= buf[cnt] && buf[cnt] <= 'Z' ) return buf[cnt++];
  return -1;
}

vec kakko(){
  if( buf[cnt] == '(' ){
    cnt++;
    vec ret = expression();
    assert(buf[cnt] == ')');
    cnt++;
    return ret;
  }
  assert( 'A' <= buf[cnt]&& buf[cnt] <= 'Z' );
  return A[buf[cnt++]];
}



vec expression(){
  char c = chara();
  vec a;
  if( c == -1 ){
    int num = number();
    if( num == -1 ){
      a = kakko();
    } else {
      a = powv(kakko(),num);           
    }
  } else{
    a = A[(int)c];
  }
  if( cnt == len ) return a;
  if( buf[cnt] == '+' ){
    cnt++;
    vec b= expression();
    /*
      view(a);
      cout << " + ";
      view(b);
    */
    a = plusv(a,b);
  }
  return a;
}


int main(){
  cin >> N >> K;
  for(int i=0;i<K;i++){
    int h;
    char p;
    cin >> p >> h;
    mat amd( h, vec(N-1,0) );
    for(int y=0;y<h-1;y++)
      for(int x=0;x<N-1;x++)
        cin >> amd[y][x];    
    A[(int)p] = getv(amd);
    //view(A[(int)p]);
  }
  int E;
  cin >> E;
  for(int i=0;i<E;i++){
    cin >> buf;
    len=buf.size();
    cnt = 0;
    vec res = expression();
    for(int i=0;i<(int)res.size();i++){
      if( i ) cout << " ";
      cout << res[i]+1;
    }
    cout << endl;
  }

}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 55

ll N;
vector<ll> a;

int main()
{
    cin >> N;
    REP(i, N) {
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    //sort(a.begin(), a.end(), greater<ll>());
    ll ans = 0;
    while(1) {
        vector< pair<int, ll> > change;     // インデックス, 足す値
        REP(i, N) {
            if(a[i] >= N) {
                ll tmp = a[i] / N;
                a[i] = a[i] % N;
                change.push_back(make_pair(i, tmp));
                ans += tmp;
            }
        }
        if(change.size() == 0) { break; }
        REP(i, change.size()) {
            REP(j, N) {
                if(change[i].first != j) {
                    a[j] += change[i].second;
                }
            }
        }
    }

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

    return 0;
}


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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

def main():
    K = int(input())
    memo = [[-1] * 201 for i in range(201)]
    
    for a in range(1, 201):
        for b in range(1, 201):
            memo[a][b] = gcd(a, b)
    
    ans = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                ans += memo[memo[a][b]][c]
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9428
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define cout cout<<fixed<<setprecision(10)
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;}
// clang-format on

void solve(long long X, long long Y) {
  ll ans = 0;
  switch (X) {
  case 1:
    ans += 300000;
    break;
  case 2:
    ans += 200000;
    break;
  case 3:
    ans += 100000;
    break;
  default:
    break;
  }
  switch (Y) {
  case 1:
    ans += 300000;
    break;

  case 2:
    ans += 200000;
    break;

  case 3:
    ans += 100000;
    break;
  default:
    break;
  }
  if (X == 1 && Y == 1) {
    ans += 400000;
  }
  cout << ans << endl;
}

int main() {
  long long X;
  scanf("%lld", &X);
  long long Y;
  scanf("%lld", &Y);
  solve(X, Y);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define PI 2*acos(0)
#define INF 1e17
#define mx 2*1000000+5
using namespace std;
const ll int p=1e9+7;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    int num[4];
    memset(num,0,sizeof(num));
    int n,i,j,k,sum;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>s;
        if(s=="AC") num[0]++;
        if(s=="WA") num[1]++;
        if(s=="TLE") num[2]++;
        if(s=="RE") num[3]++;
    }
    cout<<"AC x "<<num[0]<<endl;
    cout<<"WA x "<<num[1]<<endl;
    cout<<"TLE x "<<num[2]<<endl;
    cout<<"RE x "<<num[3]<<endl;
    /* */
    return 0;
}


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

#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];

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

ll lcm(ll a, ll b){
   return a * b / gcd(a, b);
}

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

Measured memory_bytes: 256
// SPDX-License-Identifier: X11
// 2020-06-28

#include <stdio.h>

int main(void) {
  long N;
  scanf("%ld", &N);

  long n = 0,
       m;
  for (long i = 1; i <= N; i++) {
    m = N / i;
    n += (i * m * (m + 1) / 2);
  }

  printf("%ld\n", n);
}


Measured memory_bytes: 1728
s = input()
n = len(s)
x = [0]*(n-1)
for i in range(n-1):
    if s[i]=="R" and s[i+1]=="L":
        x[i]=1
    elif s[i]=="L" and s[i+1]=="R":
        x[i]=2

ans = [0]*n
sk = 0
sl = 0
for i in range(n-1):
    
    if (x[i]==0):
        sk += 1
    elif(x[i]==1):
        if (sk%2==1):
            ans[i]+=sk//2+1
            ans[i+1]+=sk//2+1+1
        else:
            
            ans[i]+=sk//2+1
            ans[i+1]+=sk//2+1
        sk = 0
        sl = i
    elif(x[i]==2):
        if (sk%2==1):
            ans[sl]+=sk//2+1
            ans[sl+1]+=sk//2
        else:
            ans[sl]+=sk//2
            ans[sl+1]+=sk//2
        sk = 0
if (x[n-2]==0):
    if (sk%2==1):
        ans[sl]+=sk//2+1
        ans[sl+1]+=sk//2
    else:
        ans[sl]+=sk//2
        ans[sl+1]+=sk//2
print(*ans)

Measured memory_bytes: 7288
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using System.Text;
     
    public class Program
    {
        public void Proc() {
            Reader.IsDebug = false;
            int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();


            int itemCount = inpt[0];
            int selMin = inpt[1];
            int selMax = inpt[2];

            decimal[] items = Reader.ReadLine().Split(' ').Select(a=>decimal.Parse(a)).OrderByDescending(a=>a).ToArray();

            decimal avg = items.Take(selMin).Average();

            decimal target = items[selMin-1];
            int selTargetMin = items.Take(selMin).Count(a=>a==target);
            int targetCount = items.Count(a=>a==target);
            int selTargetMax = Math.Min(selTargetMin + (selMax-selMin), targetCount); 
            if(avg != target) {
                selTargetMax = selTargetMin;
            }

            decimal ans = 0;
            for(int i=selTargetMin; i<=selTargetMax; i++) {
                ans += GetSelCount(0, targetCount, i);
            }
            Console.WriteLine(avg);
            Console.WriteLine(ans);

        }

        private long GetSelCount(int idx, int lastIndex, int remain) {
            if(remain == 0) {
                return 1;
            }

            if(idx >= lastIndex) {
                return 0;
            }


            if(!dic.ContainsKey(idx)) {
                dic.Add(idx, new Dictionary<int, long>());
            }
            if(dic[idx].ContainsKey(remain)) {
                return dic[idx][remain];
            }

            long ans = GetSelCount(idx+1, lastIndex, remain-1);
            ans += GetSelCount(idx+1, lastIndex, remain);
            dic[idx].Add(remain, ans);
            return ans;            
        }

        private Dictionary<int, Dictionary<int, long>> dic = new Dictionary<int, Dictionary<int, long>>();
        public class Reader {
            public static bool IsDebug = true;
            private static System.IO.StringReader SReader;
            private static string InitText = @"



4 2 3
10 20 10 10




";
            public static string ReadLine() {
                if(IsDebug) {
                    if(SReader == null) {
                        SReader = new System.IO.StringReader(InitText.Trim());
                    }
                    return SReader.ReadLine();
                } else {
                    return Console.ReadLine();
                }
            }
        }
        public static void Main(string[] args)
        {
            Program prg = new Program();
            prg.Proc();
        }
    }

Measured memory_bytes: 11604
import itertools

N = int(input())
MOD = 10**9 + 7

base = ['A', 'C', 'G', 'T']
base3 = list(itertools.product(base, repeat=3))
index_dict = dict(zip(base3, range(64)))


def is_NG(b, s):
  for i in range(4):
    lb = list(b) + [s]
    if i >= 1:
      lb[i-1], lb[i] = lb[i], lb[i-1]
    if ''.join(lb).count('AGC') == 1:
      return True
  return False


# 0:A->A->A, 1:A->A->C, 2:A->A->G, 3:A->A->T, ...
dp = [[0]*64 for i in range(N)]
dp[2] = [1] * 64
for b in [('A', 'G', 'C'), ('A', 'C', 'G'), ('G', 'A', 'C')]:
  dp[2][index_dict[b]] = 0


for i in range(3, N):
  for j in range(64):
    b = base3[j]
    if is_NG(b, 'C'):
      for s in 'AGT':
        idx = index_dict[(b[1], b[2], s)]
        dp[i][idx] += dp[i-1][j]
        dp[i][idx] %= MOD
    elif is_NG(b, 'G'):
      for s in 'ACT':
        idx = index_dict[('A', 'C', s)]
        dp[i][idx] += dp[i-1][j]
    else:
      for s in 'ACGT':
        idx = index_dict[(b[1], b[2], s)]
        dp[i][idx] += dp[i-1][j]
        dp[i][idx] %= MOD
        

ans = sum(dp[-1]) % MOD
print(ans)

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

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

    vector<int> a(n),b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];


    ll t = 0;
    rep(i,m) t += b[i];
    int j = m;
    int ans = 0;
    rep(i,n+1) {
        while(j > 0 && t > k) {
            j--;
            t -= b[j];
        }
        if (t > k) {
            break;
        }
        ans = max(i+j, ans);
        if (i >= n) break;
        t += a[i];
    }

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

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

int main(){
	int x,y,w,h,r;
	cin >> w >> h >> x >> y >> r;
	
	if((x<=w-r)&&(x>=r)&&(y<=h-r)&&(y>=r )) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int N,M;
    cin >> N >> M;
    vector<int> balls(N,1);
    vector<bool> red(N,false);
    red[0] = true;

    REP(_,M) {
        int x,y;
        cin >> x >> y;
        --x; --y;
        balls[x]--;
        balls[y]++;
        if (red[x]) red[y] = true;
        if (balls[x] == 0) red[x] = false;
    }
    cout << accumulate(ALL(red),0) << endl;
}

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

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

int main() {
    unsigned long long a {}, b {}, k {};
    cin >> a >> b >> k;

    unsigned long long temp {min(a,k)};
    a -= temp;
    k -= temp;
    b -= min(b,k);
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N, L;
    cin>>N>>L;
    vector<string> ss(N);
    rep(i, N) cin>>ss[i];
    sort(ss.begin(), ss.end());
    rep(i, N - 1) cout<<ss[i];
    cout<<ss[N - 1]<<endl;
}

Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef vector<pair<int,int>> vpii;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define sciii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sciiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld %lld",&a,&b)
#define sclll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c
#define scllll(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define print(a) printf("%d ",a)
#define println(a) printf("%d\n",a)
#define ln printf("\n")
#define pb(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define rep(i,s,n) for(int i=s;i<=n;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define repv(i,m) for(auto i = m.begin();i != m.end();i++)
#define FileIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 4000000000000000000LL;
/************************************* Chocolate *************************************/

int main() {
    int n,k;
    scii(n,k);
    vi height(n);
    rep(i, 0, n - 1) {
        sci(height[i]);
    }
    vll dp(n,INF);
    dp[0] = 0;
    rep(i,1,n-1){
        rep(j,1,k){
            if(i<j) break;
            dp[i] = min(dp[i],dp[i-j] + abs(height[i] - height[i-j]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

int main(){
   ll n,ans=0;
   cin >> n;
   string s;
   cin >> s;
   rep(i,n-1){
       if(s[i]==s[i+1]) continue;
       else ans++;
   }
   ans++;
   cout << ans;
}

Measured memory_bytes: 512
/*
created at 6.9.2015 by charis
last edited at 6.9.2015 by charis
*/

#include<iostream>
using namespace std;

int main(){
	int n, q;
	cin >> n ;
	int S[n];
	for(int i=0; i<n; i++){
		cin >> S[i] ;
	}
	cin >> q ;
	int T[q];
	for(int j=0; j<q; j++){
		cin >> T[j] ;
	}
	
	int C = 0 ;
	for(int j=0; j<q; j++){
		int t = T[j] ;
		for(int i=0; i<n; i++){
			if(S[i] == t){
				C++;
				break;
			}
		}
	}
	
	cout << C << endl;
	return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
#define N 20000001
 
int B[N], C[N], A[N], n;

 
     
 int main()
{
 
  int i;
  int max=0;
 
  scanf("%d",&n);
 
  for(i = 1;i <= n;i++)
    {
      scanf("%d", &A[i]);
      if(max< A[i])
    {
      max = A[i];
    }
    }
 
  CountingSort(max);
 
  for(i = 1;i <= n;i++)
    {
      if(i > 1) printf(" ");
      printf("%d",B[i]);
    }
  printf("\n");
  return 0;
}
 void CountingSort(int k)
{
  int i, j;
  for(i = 0; i <= k; i++)
    {
      C[i] = 0;
    }
  for(j = 1;j <= n;j++)
    {
      C[A[j]]++;
    }
  for(i = 1;i <= k;i++)
    {
      C[i] = C[i] + C[i - 1];
    }
  for(j = n;j > 0;j--)
    {
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }
}

Measured memory_bytes: 21076
n = gets.chomp.to_i
prices = gets.chomp.split(/\s+/).map(&:to_i)

amount = 1000
i = 0
nstock = 0

state = 0
(0..(n-1)).each do |i|
  if i == n-1
    state = 2
    amount += nstock * prices[i]
    nstock = 0
  end
  if state == 0
    if prices[i] < prices[i+1]
      nstock += amount / prices[i]
      amount = amount % prices[i]
      state = 1
    end
  end
  if state == 1
    if prices[i] > prices[i+1]
      amount += nstock * prices[i]
      nstock = 0
      state = 0
    end
  end
end

puts amount

Measured memory_bytes: 14224
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> P;
const int INF = 1 << 30;
const int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
int h[100000];
int main() {
	int N;
	cin >> N;
	int A, B;
	cin >> A >> B;
	rep(i, N) {
		cin >> h[i];
	}
	int l = -1, r = 1e9;
	while ((r - l) > 1) {
		LL m = (l + r) / 2;
		LL sum = 0;
		rep(i, N) {
			sum += (max(h[i] - B*m, 0LL)+(A-B-1)) / (A - B);
		}
		if (sum <= m) r = m; else l = m;
	}
	cout << r << endl;
}

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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e2 + 10, MAX_V = 2*MAX_N ;

struct ED {
	int t, f, r;
	ED() {}
	ED(int tt, int ff, int rr) :t(tt), f(ff), r(rr) {}
};
int H, W; char S[MAX_N][MAX_N];
vector<ED> Ed[MAX_V];
void add(int fr, int to, int fl) {
	Ed[fr].push_back(ED(to, fl, Ed[to].size()));
	Ed[to].push_back(ED(fr,  0, Ed[fr].size()-1));
}

int St, En, Ix[MAX_V], Lv[MAX_V];
bool bfs() {
	queue<int> Q;
	for(int i=St; i<=En; i++) Lv[i] = -1;
	Q.push(St); Lv[St] = 0;
	while(!Q.empty()) {
		int v = Q.front(); Q.pop();
		for(ED &e : Ed[v]) {
			if(Lv[e.t] == -1 && e.f > 0) {
				Lv[e.t] = Lv[v] + 1;
				Q.push(e.t);
			}
		}
	}
	return Lv[En] != -1;
}
int dfs(int v, int mf) {
	if(v == En) return mf;
	for(int &i = Ix[v], f; i<SZ(Ed[v]); i++) {
		ED &e = Ed[v][i];
		if(Lv[e.t] == Lv[v] + 1 && e.f > 0 && (f = dfs(e.t, min(mf, e.f))) > 0) {
			e.f -= f;
			Ed[e.t][e.r].f += f;
			return f;
		}
	}
	return 0;
}
int main() {
	cin >> H >> W;
	for(int i=0; i<H; i++) scanf("%s", S[i]);
	St = 0; En = H+W+1;
	for(int i=0; i<H; i++) for(int j=0; j<W; j++) {
		if(S[i][j] == 'o') {
			add(i+1, H+j+1, 1);
			add(H+j+1, i+1, 1);
		} else if(S[i][j] == 'S') {
			add(St, i+1, INF);
			add(St, H+j+1, INF);
		} else if(S[i][j] == 'T') {
			add(i+1, En, INF);
			add(H+j+1, En, INF);
		}
	}

	int flow = 0;
	while(bfs()) {
		for(int i=St; i<=En; i++) Ix[i] = 0;
		int f; while((f = dfs(St, INF)) != 0) flow += f;
	}
	if(flow >= INF) puts("-1");
	else printf("%d\n", flow);
	return 0;
}

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

int main()
{
    int a = 0;
    string s;
    cin >> s;
    if (s[0] == '1')
    {
        a++;
    }
    if (s[1] == '1')
    {
        a++;
    }
    if (s[2] == '1')
    {
        a++;
    }
    cout << a << endl;
}

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

using namespace std;

#define ll long long

int main (){

    ll a,b,c;

    cin>>a>>b>>c;

    if((a == b && a!=c && b != c) || (a == c && a!=b && b != c) || (c == b && a!=c && b != a)) cout<<"Yes"<<endl;

    else cout<<"No"<<endl;

    return 0;

}


Measured memory_bytes: 256
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline

# import sys
import heapq 
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13
 
# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
 

def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def insr2():
	s = input()
	return((s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
 ############ ---- Input Functions ---- #######End
 # #####   

def pr_list(a):
	print(*a, sep=" ")
def main():
	# tests =  inp()
	tests = 1
	mod = 1000000007
	limit = 10**18
	ans = 0
	m = [0,-1]
	for test in range(tests):
		[n,m] = inlt()
		grid = []
		for i in range(n):
			grid.append(insr())
		dp = [[0 for j in range(m)] for i in range(n)]
		dp[-1][-1] = 1
		move = {}
		move[(n-1,m-1)] =1
		while(move != {}):
			n_move = {}
			# print(dp)
			for i in move:
				
				if i[0]-1 >=0 and grid[i[0]-1][i[1]] == ".":
					dp[i[0]-1][i[1]] = (dp[i[0]-1][i[1]]+ dp[i[0]][i[1]])%mod
					n_move[ (i[0]-1,i[1]) ] =1
				if i[1]-1 >=0 and grid[i[0]][i[1]-1]  == "." :
					dp[i[0]][i[1]-1] = (dp[i[0]][i[1]-1]+ dp[i[0]][i[1]])%mod
					n_move[ (i[0],i[1]-1) ] =1
			move = n_move
		print(dp[0][0])


if __name__== "__main__":
	main()

Measured memory_bytes: 54736
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

int mod = 1e9 + 7;

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

    int N;
    cin >> N;
    string s;
    cin >> s;

    map<int, int> cnt;
    REP(i, s.size()) {
        char c = s[i];
        cnt[c - 'a']++;
    }

    int res = 1;
    REP(i, 26) {
        res = (res * (cnt[i] + 1)) % mod;
    }
    res -= 1;
    if (res < 0) res += mod;
    cout << res % mod << endl;
    return 0;
}


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

minval = 0
previous = 0
for i in range(len(A)):
    if i == 0:
        previous = A[0]
        continue

    diff = previous - A[i]

    if diff > 0:
        minval += diff
    previous = A[i] + diff if diff > 0 else A[i]

print(minval)

Measured memory_bytes: 32180
#include<iostream>
using namespace std;
int N,t=0;
int d[101][101],Ts[101],Te[101];
bool visit[101];
void graph(){
    int u,k,a;
    for(int i=1;i<=N;++i){
        cin>>u>>k;
        for(int j=0;j<k;++j){
            cin>>a;
            d[u][a]=1;
        }
        visit[i]=true;
    }
}
void dfs(int cur){
    t+=1;
    Ts[cur]=t;
    visit[cur]=false;
    for(int i=1;i<=N;++i){
        if(d[cur][i]==1&&visit[i]){
            dfs(i);
        }
    }
    t+=1;
    Te[cur]=t;
}
int main(){
    cin>>N;
    graph();
    for(int i=1;i<=N;++i){
        if(visit[i]) {
            dfs(i);
        }
    }
    for(int i=1;i<=N;++i){
        cout<<i<<" "<<Ts[i]<<" "<<Te[i]<<endl;
    }
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
// clang-format off
#define rep(i, j) for (long long i = 0; i < j; i++)
#define int long long
#define gcn(N) int N;cin >> N;
#define debug(var) do {std::cout << #var << " : "; view(var);} while (0)
template <typename T> void view(T e) { std::cout << e << std::endl; } template <typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>>& vv) { for (const auto& v : vv) { view(v); } } using namespace std; void before_main() { std::cout << std::fixed << std::setprecision(10); } namespace { struct before_main_caller { before_main_caller() { before_main(); } } caller; }
// clang-format on
signed main()
{
    int X;
    cin >> X;
    int ureshi = 0;
    ureshi += (X / 500) * 1000 + (((X % 500) / 5) * 5);
    cout << ureshi << endl;
}


Measured memory_bytes: 256
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#include "bits/stdc++.h"

namespace adaptor = boost::adaptors;

void solve() {
    std::stack<int64_t> S1;
    std::stack<std::pair<int64_t, int64_t> > S2;
    char ch;
    int64_t sum = 0;
    for (int64_t i = 0; std::cin >> ch; i++) {
        if (ch == '\\')
            S1.push(i);
        else if (ch == '/' && S1.size() > 0) {
            int64_t j = S1.top();
            S1.pop();
            sum += i - j;
            int64_t a = i - j;
            while (S2.size() > 0 && S2.top().first > j) {
                a += S2.top().second;
                S2.pop();
            }
            S2.push(std::make_pair(j, a));
        }
    }

    std::vector<int64_t> ans;
    while (S2.size() > 0) {
        ans.push_back(S2.top().second);
        S2.pop();
    }
    std::reverse(ans.begin(), ans.end());

    std::cout << sum << std::endl;
    std::cout << ans.size();
    for (int64_t i = 0; i < ans.size(); i++) {
        std::cout << " " << ans[i];
    }
    std::cout << std::endl;

    return;
}

int main() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}



Measured memory_bytes: 3240
#include <cstdio>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <algorithm>
#include <set>
#include <ctime>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

namespace FastIO {
	template<typename tp> inline void read(tp &x) {
		x=0; register char c=getchar(); register bool f=0;
		for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());
		for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());
		if(f) x=-x;
	}
	template<typename tp> inline void write(tp x) {
		if (x==0) return (void) (putchar('0'));
		if (x<0) putchar('-'),x=-x;
		int pr[20]; register int cnt=0;
		for (;x;x/=10) pr[++cnt]=x%10;
		while (cnt) putchar(pr[cnt--]+'0');
	}
	template<typename tp> inline void writeln(tp x) {
		write(x);
		putchar('\n');
	}
}
using namespace FastIO;


int main() {
    int a, b, c, d;
    read(a), read(b), read(c), read(d);
    for (int i = 1; i <= d; ++i) {
        for (int j = 1; j <= c; ++j) {
            putchar('1');
        }
        for (int j = 1; j <= b - c; ++j) {
            putchar('0');
        }
        puts("");
    }
    for (int i = 1; i <= a - d; ++i) {
        for (int j = 1; j <= c; ++j) {
            putchar('0');
        }
        for (int j = 1; j <= b - c; ++j) {
            putchar('1');
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(a,n) rep(i,0,n){cout<<(i ? " ":"")<<a[i];}cout<<endl;
#define pprint(a,m,n) rep(i,0,m){print(a[i],n);}
const int mod = 1e9+7;
const int size=1e5;
const long INF=1e10;
int main(){
	int N;cin>>N;
	priority_queue<pair<long,pair<int,int>>> pq;
	long c;
	long A[N][N];long len[N][N]={};
	rep(i,0,N)rep(j,0,N){
		cin>>c;
		A[i][j]=c;
		if(i>j) pq.push({-c,{i,j}});
	}
    //pprint(A,N,N);
	int v,u;
	while(!pq.empty()){
		v=pq.top().second.first;
		u=pq.top().second.second;
		pq.pop();
        bool flag=true;
		rep(i,0,N){
			if(i==v||i==u) continue;
			if(A[v][u]==A[v][i]+A[i][u]) flag=false;
            else if(A[v][u]>A[v][i]+A[i][u]){
                cout<<-1<<endl;
                return 0;
            }
		}
        if(flag){ len[v][u]=A[v][u];len[u][v]=A[u][v]; }
        else{ len[v][u]=INF;len[u][v]=INF; }
	}
    /*rep(i,0,N){
        rep(j,0,N) cout<<len[i][j];
        cout<<endl;
    }*/
	long sum=0;
	rep(i,0,N)rep(j,0,N){
        if(len[i][j]==INF) continue;
		sum+=len[i][j];
	}cout<<sum/2<<endl;
}

Measured memory_bytes: 2680
#include<stdio.h>

int main(){
    int i, n, r, min, max;
    long int sum;
    scanf("%d", &n);
    i = 1;
    scanf("%d", &r);
    min = r;
    max = r;
    sum = r;
    while(i < n){
        scanf("%d", &r);
        if(min > r) min = r;
        if(max < r) max = r;
        sum = sum + r;
        i++;
    }
    printf("%d %d %ld\n", min, max, sum);
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 200000;
const int MOD = 1000000007;
const int INF = 1e8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
//

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

    int res = 0;
    for(int i = 1; i <= t; i++) {
        if(i%a == 0) res+=b;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,i,j,k,x,s=0;
	cin>>n;
	vector<int>A;
	for(i=0;i<n;i++){
		cin>>x;
		A.push_back(x);
	}
    int m=A.size(); 
    sort(A.begin(), A.end());  
    for( int i = m-1;i>0; i--){ 
        int j = 0, k = i-1; 
        while( j < k){ 
            if( A[j] + A[k]> A[i]){ 
            	s+=k-j;
                k--;   
            } 
            else j++;   
        } 
    }
    cout<<s;
    return 0;
}

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

int main(){
	map<unsigned long long int, unsigned long long int> m;
	unsigned long long int n,q,a,b;
	cin>>n;
	q=n;
	while(q--){
		cin>>a>>b;
		if(m.find(b)!=m.end()){
			m[b]+=a;
		}else{
			m[b]=a;
		}
	}
	map<unsigned long long int, unsigned long long int>::iterator it;
	it=m.begin();
	unsigned long long int sum=0;
	int p=0;
	while(it!=m.end()){
		sum+=it->second;
		// cout<<sum<<" "<<it->first<<endl;
		if(it->first < sum){
			p=1;
			break;
		}
		it++;
	}
	if(p==1){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define pb push_back
const int mod=1e9+7;

int main(){
	ll n;
	while(cin >> n){
		cout<<n*n*3<<endl;
	}

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().abc99_b();
        }

        public void Solve()
        {

            string s = Console.ReadLine();
            bool Flag = true;
            bool Cflag = false;
            for (int i = 0; i < s.Length; i++)
            {
                if (i == 0)
                {
                    if (s[0] != 'A') Flag = false;
                }
                else if(2 <= i && i < s.Length - 1)
                {
                    if (('a' <= s[i] && s[i] <= 'z'))
                    {
                        continue;
                    }
                    else if(s[i] == 'C' && Cflag==false)
                    {
                        Cflag = true;
                        continue;
                    }

                    Flag = false;
                }
                else
                {
                    if (('a' <= s[i] && s[i] <= 'z')) continue;
                    Flag = false;
                }
            }

            if (Flag && Cflag) Console.WriteLine("AC");
            else Console.WriteLine("WA");
        }

        public void abc102_b()
        {
            int n = int.Parse(Console.ReadLine());

            List<int> a = Console.ReadLine().Split().Select(int.Parse).ToList();

            Int32 Amax = 0;
            Int32 Amin = Int32.MaxValue;

            for (int i = 0; i < n; i++)
            {
                Amax = Math.Max(Amax, a[i]);
                Amin = Math.Min(Amin, a[i]);
            }

            Console.WriteLine(Amax - Amin);
        }

        public void abc100_b()
        {

            var l = Console.ReadLine().Split(' ');
            int d = int.Parse(l[0]);
            int n = int.Parse(l[1]);
            int ans = 0;
            int num = 0;
            while (true)
            {
                int t = ++ans;
                int wn = 0;
                while(t % 100 == 0)
                {
                    t /= 100;
                    wn++;
                }
                if(wn == d)
                {
                    if(++num == n)
                    {
                        break;
                    }
                }
            }
            WriteLine(ans);
        }

        public void abc99_b()
        {
            var l = Console.ReadLine().Split(' ');
            int a = int.Parse(l[0]);
            int b = int.Parse(l[1]);
            int t = 0;
            for (int i = 1; i < b-a; i++)
            {
                t += i;
            }
            WriteLine(t - a);
        }
    }

}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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;
}

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

  if (X == 7 || X == 5 || X == 3) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n,k;
    cin>>n>>k;
    int cnt=0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x>=k)    cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 256