akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n , TotalK , a[110];
long long dp[101][100010] , mod = 1e9 + 7;

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

    dp[n][0] = 1;
    for(int i = n-1 ; i >= 0 ; i--)
        for(int k = 0 ; k <= TotalK ; k++)
            dp[i][k] = ((dp[i+1][k] + (k?dp[i][k-1]:0))%mod + (k > a[i] ? mod - dp[i+1][k-a[i]-1] : 0))%mod;
    cout << dp[0][TotalK] << '\n';
    return 0;
}


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

const int mod = 1000000007;

int main(){
    int n,x;
    cin >> n >> x;
    if(n*500>=x){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;

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

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

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main()
{
  int n;
  cin >> n;
  int zero = 0;
  map<pair<ll, ll>, P> mp;
  ll a, b;

  for (int i = 0; i < n; i++)
  {
    cin >> a >> b;
    if (a == 0 && b == 0)
    {
      zero++;
      continue;
    }
    if (a < 0)
    {
      a = -a;
      b = -b;
    }
    if (a == 0 && b < 0)
    {
      a = -a;
      b = -b;
    }
    ll g = gcd(a, b);
    a /= g, b /= g;
    if (b > 0)
    {
      mp[{a, b}].first++;
    }
    else
    {
      mp[{-b, a}].second++;
    }
  }

  mint ans = 1;
  for (auto p : mp)
  {
    int f = p.second.first, s = p.second.second;
    mint now = 1;
    now += mint(2).pow(f) - 1;
    now += mint(2).pow(s) - 1;
    ans *= now;
  }
  ans -= 1;
  ans += zero;
  cout << ans << endl;
}


Measured memory_bytes: 15920
line = gets.chomp.split('')
kind = line.sort.uniq
range = kind.size - 1

for i in 0..range do
    count = line.count(kind[i])
  if count % 2 != 0 then
	puts "No"
    break
  end
    if i == range then
      puts "Yes"
    end
end

Measured memory_bytes: 1788
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(){ 
	char s[200], s2[200],p[200];
	scanf("%s %s",s,p);
	strcpy(s2,s);
	strcat(s,s2);
	if(strstr(s,p) != NULL){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 540
n=int(raw_input())
for i in range(n):
    t=[int(x) for x in raw_input().split(':')]
    longdeg=t[1]*360/60.
    shortdeg=t[0]*360/12.+t[1]*30/60.
    (longdeg,shortdeg)=(max(longdeg,shortdeg),min(longdeg,shortdeg))
    dist=min(longdeg-shortdeg,360-(longdeg-shortdeg))
    if dist<30:
        print 'alert'
    elif dist>=90:
        print 'safe'
    else:
        print 'warning'

Measured memory_bytes: 4244
s = input()
k = int(input())
n = len(s)
substring_set = set([])

for i in range(n):
    for j in range(1,6):
        if i + j <= n:
            substring_set.add(s[i:i+j])
substring_list = list(substring_set)

print(sorted(substring_list)[k-1])

Measured memory_bytes: 40048
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main() {
    string s; cin >>s;
    int i = (int) s.size() - 1;
    vector<string> a = {"dreamer", "dream", "erase", "eraser"};
    while (i > 0) {
        bool ok = 0;
        for (auto ss : a) {
            int sz = (int) ss.size();
            ok = 1;
            for (int j = sz - 1, k = i; j >= 0; j--, k--) {
                if(ss[j] != s[k]) {
                    ok = 0;
                    break;
                }
            }
            if(ok) {
                i -= sz;
                break;
            }
        }
        if(!ok) {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";

}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    int ans = 0;
    cin >> n >> k;
    vector<int> h(n);
    rep (i, n) cin >> h[i];
    sort(h.begin(), h.end());
    rep (i, n) {
        if (h[i] >= k) ans++;
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <list>
#include <string>
using namespace std;
// enum command
// {
// 	insert,
// 	delete,
// 	deleteFirst,
// 	deleteLast
// };
void print_list(list<int>);
int main()
{
	int N;
	cin >> N;

	list<int> ls;
	string command;

	int n;

	for (int i = 0; i < N; i++)
	{
		cin >> command;
		if (command == "insert")
		{
			cin >> n;
			ls.push_front(n);
		}
		if (command == "delete")
		{
			cin >> n;
			list<int>::iterator it = ls.begin();

			while (it != ls.end())
			{
				if (*it == n)
				{
					it = ls.erase(it);
					break;
				}
				it++;
			}
		}
		if (command == "deleteFirst")
		{
			ls.pop_front();
		}
		if (command == "deleteLast")
		{
			ls.pop_back();
		}
	}
	print_list(ls);
}
void print_list(list<int> ls)
{
	list<int>::iterator prev_end = ls.end();
	prev_end--;

	for (list<int>::iterator it = ls.begin(); it != prev_end; it++)
	{
		cout << *it << ' ';
	}
	cout << ls.back() << endl;
}


Measured memory_bytes: 34296
def main():
    input()
    t = list(map(int, input().split()))
    m = 0
    flg = True
    for i in range(len(t)):
        if 0 == i or i == len(t) - 1:
            continue
        if t[i-1] < t[i]:
            t[i] -= 1
        if t[i - 1] <= t[i] <= t[i + 1]:
            pass
        else:
            print('No')
            exit()
    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 14396
#include <bits/stdc++.h>
#define LL long long
using namespace std;

int main()
{
    int n;
    LL even=0,odd=0;
    scanf("%d",&n);
    for(int i =1;i <=n;i++){
        int x;
        scanf("%d",&x);
        if(x%2==0)
            even++;
        else
            odd++;
    }
    printf("%lld\n",(LL)pow(3,n) - (LL)pow(2,even));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int H,W;
    cin >> H >> W;
    vector<string> s(H);
    REP(i, H) cin >> s[i];

    vector<vector<int>> m(H, vector<int>(W, INF));
    if(s[0][0]=='.') m[0][0] = 0;
    else m[0][0] = 1;
    queue<pii> q;
    q.push(pii(0,0));
    while(!q.empty()){
        auto f = q.front();q.pop();
        int x[]={1,0}, y[]={0,1};
        REP(i, 2){
            int dx = f.fi + x[i];
            int dy = f.se + y[i];
            if(0<=dx&&dx<H&&0<=dy&&dy<W){
                if(m[dx][dy]==INF) q.push({dx,dy});
                if(s[f.fi][f.se]!=s[dx][dy]&&s[dx][dy]=='#'){
                    chmin(m[dx][dy], m[f.fi][f.se]+1);
                }else{
                    chmin(m[dx][dy], m[f.fi][f.se]);
                }
            }
        }
    }
    pr(m[H-1][W-1]);
}

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

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int M[101][101];
int a[10001];

int main()
{
	int H, W, N;
	cin >> H >> W >> N;
	REP(i, N)
	{
		cin >> a[i];
	}

	int index = 0;
	REP(h, H)
	{
		REP(w, W)
		{
			while (a[index] == 0)
			{
				index++;
			}
			M[h][w] = index + 1;
			a[index]--;
		}
	}
	REP(h, H)
	{
		if (h % 2 == 1)
		{
			IREP(w, W - 1)
			{
				cout << M[h][w] << " ";
			}
		}
		else
		{
			REP(w, W)
			{
				cout << M[h][w] << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int n[1005],m[1005],a,b,c[1005],k,i,j;
    while(scanf("%d%d",&a,&b)==2)
    {
        c[1]=1,n[1]=1-a,m[1]=1-b;
        for(i=1;i<=999;i++)
        {
            if(i!=1)
            {
                c[i]=c[i-1]+i;
                n[i]=c[i]-a;
                m[i]=c[i]-b;
            }
        }
        for(i=1;i<=999;i++)
        {
            for(j=i+1;j<=999;j++)
            {
                if(n[i]==m[j])
                {
                    k=n[i];
                    break;
                }
            }
        }
        printf("%d\n",k);
    }
    return 0;
}


Measured memory_bytes: 128
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int a,b,c;
	cin>>a>>b>>c;
	if( (a+b+c) >= 22 ) cout<<"bust"<<endl;
	else cout<<"win"<<endl;


}

Measured memory_bytes: 3624
#include <stdio.h>

int main(void)
{
	int N;
	scanf("%d",&N);
	int w,i=0;
	w = N;
	int k,c,r,e;
	k = 0; c = 0;
	while(1){
		k  += N % 10;
		N = N/10;
		//printf("N = %d, c = %d, k = %d\n",N,c,k);
		if(N <= 0) break;
	}
	if(w % k==0) printf("Yes");
	else printf("No");
	return 0;
}





Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int ad[5],min=999;
  int k,i,j,ans=0;
  for(i=0; i<5; i++){
    scanf("%d",&ad[i]);
    if(ad[i]%10)ans+=ad[i]-ad[i]%10+10;
    else ans+=ad[i];
    if(min%10>=(ad[i]%10) && (ad[i]%10)!=0)min=ad[i];
  }
  if(min!=999){
  if(min%10)ans-=min-min%10+10;
  else ans-=min;
  ans+=min;
  }
  printf("%d\n",ans);
}

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

N=int(input())
A=list(map(int,input().split()))

mod=1000000007

DP=[0,0,0]
ANS=1

for a in A:
    ANS=ANS*DP.count(a)%mod
    if ANS==0:
        print(0)
        sys.exit()
    x=DP.index(a)
    DP[x]+=1

print(ANS)


Measured memory_bytes: 13876
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int K, N;
ll DP[1001][2001], f[4445], inv[4445], res[4444];


ll pw(ll x, int y) {
	ll a = 1;
	while (y) {
		if (y & 1) {
			a = a*x%mod998;
		}
		x = x*x%mod998;
		y >>= 1;
	}
	return a;
}

ll modinv(ll x) {
	return pw(x, mod998 - 2);
}

ll comb(int n, int r) {
	return f[n] * inv[r] % mod998 * inv[n - r] % mod998;
}

int main() {
	cin >> K >> N;
	f[0] = 1;
	for (ll i = 1; i <= 4444; ++i) {
		f[i] = f[i - 1] * i % mod998;
	}
	for (int i = 0; i <= 4444; ++i) {
		inv[i] = modinv(f[i]);
	}
	DP[0][0] = 1;
	for (int i = 0; i < K / 2; ++i) {
		ll t = 0;
		for (int j = 0; j <= N; ++j) {
			DP[i + 1][j] = (DP[i][j] + t) % mod998;
			t += DP[i][j] * 2;
			t %= mod998;
		}
	}
	for (int i = 2; i <= K; ++i) {
		if (i & 1) {
			for (int j = 0; j <= N; ++j) {
				res[i] += DP[i / 2][j] * comb(K - i + N - j, N - j);
				res[i] %= mod998;
			}
		}
		else {
			for (int j = 0; j <= N; ++j) {
				res[i] += DP[i / 2 - 1][j] * comb(K - i + N - j, N - j);
				res[i] %= mod998;
				if (j != N) {
					res[i] += DP[i / 2 - 1][j] * comb(K - i + N - j - 1, N - j - 1);
					res[i] %= mod998;
				}
			}
		}
	}
	if (K & 1) {
		res[K + 1] = (DP[K / 2][N] + DP[K / 2][N - 1]) % mod998;
	}
	else {
		res[K + 1] = DP[K / 2][N];
	}
	for (int i = K + 2; i <= K + K; ++i) {
		res[i] = res[K + K + 2 - i];
	}
	for (int i = 2; i <= K + K; ++i) {
		cout << res[i] << endl;
	}
}

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

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int a, b;
  cin >> a >> b;
  
  if(a == 1)
    a = 14;
  if(b == 1)
    b = 14;
  
  if(a==b)
    cout << "Draw" << endl;
  if(a > b)
    cout << "Alice" << endl;
  if(a < b)
    cout << "Bob" << endl;
  
  return 0;
}

Measured memory_bytes: 256
# a1+b1, a1+b2, a1+b3
# a2+b1, a2+b2, a2+b3
# a3+b1, a3+b2, a3+b3
c = [list(map(int, input().split())) for i in range(3)]
result = True
perm = ((0,1), (0,2), (1,2))
for p in perm:
  x0 = c[p[0]][0] - c[p[1]][0]
  x1 = c[p[0]][1] - c[p[1]][1]
  x2 = c[p[0]][2] - c[p[1]][2]
  if not (x0 == x1 and x1 == x2):
    result = False
    break
  y0 = c[0][p[0]] - c[0][p[1]]
  y1 = c[1][p[0]] - c[1][p[1]]
  y2 = c[2][p[0]] - c[2][p[1]]
  if not (y0 == y1 and y1 == y2):
    result = False
    break
if result: print('Yes')
else: print('No')

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{   
    string S;
    cin >> S;
    auto i1 = stoi(S.substr(0,2));
    auto i2 = stoi(S.substr(2));

    bool okYYMM = (i2>=1 && i2<=12);
    bool okMMYY = (i1>=1 && i1<=12);

    if     (okYYMM && okMMYY) cout<<"AMBIGUOUS"<<endl;
    else if(!okYYMM && !okMMYY) cout<<"NA"<<endl;
    else if(okYYMM) cout<<"YYMM"<<endl;
    else if(okMMYY) cout<<"MMYY"<<endl;

    return 0;
}

Measured memory_bytes: 256
// Date: 2020-03-07

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

LL n, p, cnt[N];
char s[N];

int main() {
    scanf("%lld%lld%s", &n, &p, s+1);
    LL ans = 0;
    if(p == 2) {
        rep(i, 1, n) if((s[i]-'0') % 2 == 0) ans += i;
    } else if(p == 5) {
        rep(i, 1, n) if(s[i] == '0' || s[i] == '5') ans += i;
    } else {
        cnt[0]++;
        LL sum = 0, fac = 1;
        for(int i = n; i >= 1; --i) {
            sum = (sum + (s[i]-'0')*fac) % p;
            ans += cnt[sum];
            cnt[sum]++;
            fac = fac * 10 % p;
        }
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int find_(int x,vector<pair<ll,ll>> &v){
    if(v[x].first<0) return x;
    v[x].first=find_(v[x].first,v);
    return v[x].first;
}

int same_(int a,int b,vector<pair<ll,ll>> &v){
    if(find_(a,v)==find_(b,v)) return 1;
    return 0;
}

void union_(int a,int b,vector<pair<ll,ll>> &v){
    if(same_(a,b,v)) return;
    int a_p=find_(a,v),b_p=find_(b,v);
    if(a_p>b_p) swap(a_p,b_p);
    v[a_p].first+=v[b_p].first; 
    v[a_p].second+=v[b_p].second;
    v[b_p].first=a_p;
}

/*
void print_v(vector<pp> v){
    rep(i,v.size()) cout<<v[i]<<" ";
    cout<<endl;
}

int size_(int a,vector<pp> &v){
    return -v[find_(a,v)];
}
*/

int main() {
    int h,w; cin>>h>>w;
    vector<string> s(h,"");
    rep(i,h) cin>>s[i];
    vector<pair<ll,ll>> v(h*w,mk(-1,0));
    rep(i,h*w){
        if(s[i/w][i%w]=='#') v[i].second=-1;
    }
    rep(i,(h-1)*w) if(s[i/w][i%w]!=s[i/w+1][i%w]) union_(i,i+w,v);
    rep(i,h*w){
        if(i%w==w-1) continue;
        if(s[i/w][i%w]!=s[i/w][i%w+1]) union_(i,i+1,v);
    }
    ll ans=0;
    rep(i,h*w){
        if(v[i].first<0)
        ans+=(-v[i].second)*(v[i].second-v[i].first);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2944
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF 2000000000

typedef long long ll;

pair<int,int> A[100001];

int main(){
    INT(N);
    REP1(i,N){
        INT(a);
        A[i] = make_pair(a,i);
    }
    sort(A,A+N);
    
    int counter = 0;
    REP1(i,N){
        if (i%2 == 0) {
            if(A[i].second%2 == 1){
                counter++;
            }
        }
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll d[33][33];
ll ct[33][3];
int main() {
	int n,c;
	scanf("%d %d ",&n,&c);
	for(int i=0;i<c;i++) {
		for(int j=0;j<c;j++) {
			scanf("%d ",&d[i][j]);
		}
	}
	memset(ct,0,sizeof(ct));
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			int t;
			scanf("%d ",&t);t--;
			ct[t][(i+j)%3]++;
		}
	}
	ll ma = 1LL<<50;
	for(int i=0;i<c;i++) {
		for(int j=0;j<c;j++) {
			if(i == j) continue;
			for(int k=0;k<c;k++) {
				if(j == k) continue;
				if(i == k) continue;
				ll tot = 0;
				for(int l=0;l<c;l++) {
					tot += ct[l][0]*d[l][i];
					tot += ct[l][1]*d[l][j];
					tot += ct[l][2]*d[l][k];
				}
				ma = min(ma,tot);
			}
		}
	}
	printf("%lld\n",ma);

}


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

#define MAX_N 100

using namespace std;

int main() {
    int N;
    scanf("%d", &N);
    int b[N], ans[MAX_N] = {0};
    vector<int> bvec;
    for (int i=0; i<N; i++) {
        scanf("%d", b+i);
        bvec.push_back(b[i]);
    }
    sort(b, b+N, greater<int>());
    for (int i=0; i<N; i++) {
        int a = b[i], n = (int)(bvec.rend() - find(bvec.rbegin(), bvec.rend(), a)) - 1;
        bvec.erase(bvec.begin() + n);
        int count = 0;
        bool inserted = false;
        for (int j=N-1; j>=0; j--) {
            if (ans[j] != 0) continue;
            if (count == n - a + 1) {
                ans[j] = a;
                inserted = true;
                break;
            }
            count++;
        }
        if (!inserted) {
            printf("-1\n");
            return 0;
        }
    }
    for (int i=0; i<N; i++) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    string s;
    cin >> s;
    int n = s.length();
    int ans = n;
    int ct = 0;
    for (int i = n-1; i >= 1; i-=2) {
        char one = s[i-1];
        char two = s[i];
        if (two == 'S') {
            if (ct >= 1) {
                ct--;
                ans -= 2;
            }
            if (one == 'S') {
                if (ct >= 1) {
                    ct--;
                    ans -= 2;
                }
            }
            else if (one == 'T') {
                ct++;
            }
        }
        else {
            if (one == 'S') {
                ans -= 2;
            }
            else if (two == 'T') {
                ct += 2;
            }
        }
    }
    cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    int len = s.size();
    int ans = 0;
    VI a(len);
    REP(i,0,len) a[i] = s[i] - '0';
    RREP(i,0,len) {
        if (a[i] > 9) {
            if (i == 0) ans += a[i] / 10;
            else a[i-1] += a[i] / 10;
            a[i] %= 10;
        }
        if (a[i] < 5) ans += a[i];
        else if (a[i] > 5) {
            ans += 10 - a[i];
            if (i == 0) ++ans;
            else a[i-1]++;
        } else {
            if (i == 0 || a[i-1] < 5) {
                ans += 5;
            } else {
                ans += 5;
                a[i-1]++;
            }
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 5252
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,h,w = LI()
    x = LI()
    t = [0 for i in range(w*n+1)]
    for i in range(n):
        if not i%2:
            t[i*w+x[i]] += 1
            t[(i+1)*w+x[i]] -= 1
        else:
            t[i*w-x[i]] += 1
            t[(i+1)*w-x[i]] -= 1
    for i in range(w*n):
        t[i+1] += t[i]
    ans = 0
    for i in t[:-1]:
        if i == 0:
            ans += h
    print(ans)
    return

#B
def B():
    def dfs(d,x):
        for i in range(d):
            print(".",end = "")
        print(lis[x])
        for y in v[x]:
            dfs(d+1,y)

    n = I()
    v = [[] for i in range(n)]
    lis = [None for i in range(n)]
    for i in range(n):
        k = I()
        lis[i] = input()
        if k > 0:
            v[k-1].append(i)
    dfs(0,0)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    B()



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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    ll N, M; cin >> N >> M;
    if(N == 1 && M == 1) cout << 1 << endl;
    else if(M == 1) cout << N - 2 << endl;
    else if(N == 1) cout << M - 2  << endl;
    else cout << (N - 2) * (M - 2) << endl;
}



Measured memory_bytes: 256
/*input
2 3 10

*/

#include <bits/stdc++.h>

using namespace std;

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

	long long a, b, c;
	cin >> a >> b >> c;
	long long l = 4*a*b;
	long long r = (c - a - b);
	if(r < 0) {
		cout << "No\n";
	}
	else {
		r = r * r;
		if(l < r) {
			cout << "Yes\n";
		}
		else cout << "No\n";
	}

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  vector<int> B(N + 1);
  vector<int> C(N + 1);

  for (int i = 1; i <= N; i++)
    cin >> A[i];
  for (int i = 1; i <= N; i++)
    cin >> B[i];
  for (int i = 1; i <= N - 1; i++)
    cin >> C[i];

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int d_curr = A[i];
    if (i > 1) {
      int d_prev = A[i - 1];
      if (d_prev + 1 == d_curr)
        ans += C[d_prev];
    }
    ans += B[d_curr];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define w(e) int e ; cin >> e ; while (e--)  
#define ll long long 
#define endl "\n"
#define mod  10000000007
#define pi 3.1415926535897932384626433
#define setbit(x) __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)  
/*
*/
int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a , b , c ,d ; cin >> a >> b >> c >> d ;
    int x , y ;
    if (a%d!=0)
    {
        x=(a/d)+1;
    }
    else 
        x=a/d;
    
    if (c%b!=0)
    {
        y=(c/b)+1;
    }
    else 
        y=c/b;    
    
    if (x>=y){
            cout << "Yes" << endl;  
    }
    else 
        cout << "No" << endl;
	return  0;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

template <class T>
inline void println(T val) {
  std::cout << val << '\n';
}

inline void Yes(bool cond) {
  println(cond ? "Yes" : "No");
}

inline void YES(bool cond) {
  println(cond ? "YES" : "NO");
}

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

  string s; cin >> s;
  int sum = 0;
  for (char c : s) sum += c & 15;
  Yes(!(sum % 9));

  return 0;
}


Measured memory_bytes: 3760
#include<iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a < b) {
		for (int i = 0; i < b; i++)cout << a;
		cout << endl;
	}
	else {
		for (int i = 0; i < a; i++)cout << b;
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// ^= -> ビットごとの排他的論理和を計算する
int par[100010], ran[100010], dw[100010];
void init() {
	rep(i, 100010) {
		par[i] = i;
		ran[i] = 0;
		dw[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	else {
		int r = find(par[x]);
		dw[x] += dw[par[x]];
		return par[x] = r;
	}
}
int weight(int x) {
	find(x);
	return dw[x];
}
void unite(int x, int y, int w) {
	w += weight(x);
	w -= weight(y);
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (ran[x] < ran[y]) {
		par[x] = y;
		dw[x] = -w;
	}
	else {
		par[y] = x;
		dw[y] = w;
		if (ran[x] == ran[y])ran[x]++;
	}
}
bool same(int a, int b) {
	return find(a) == find(b);
}
int diff(int x, int y) {
	return weight(y) - weight(x);
}
int n, m, l, r, d;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	init();
	rep(i, m) {
		cin >> l >> r >> d;
		if (!same(l, r)) {
			unite(l, r, d);
		}
		else if (diff(l, r) != d) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

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

typedef long long ll;

string S;
ll X, Y;
const ll LIMIT = 8000;
bitset<2 * LIMIT + 1> P[2];
ll C, D;
bool First = true;

int main() {
  cin >> S >> X >> Y;
  P[0][LIMIT] = 1;
  P[1][LIMIT] = 1;
  S += 'T';
  for (char c : S) {
    if (c == 'F') {
      ++C;
    } else {
      P[D] = First ? P[D] << C : (P[D] << C) | (P[D] >> C);
      D = 1 - D;
      C = 0;
      First = false;
    }
  }
  cout << (P[0][X + LIMIT] && P[1][Y + LIMIT] ? "Yes" : "No") << endl;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }
#define looppu(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . push_back (x) ;}
#define loopin(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . insert (x) ;}

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

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

signed main ()
{
    fastio
    lli n , x , sum = 0 , cnt = 0 ;
    cin >> n >> x ; n ++ ;
    lli a[n] ;
    loopcin(n , a ) ;
    loop(n)
    {
        sum += a[i] ;
        cnt ++ ;
        if (sum > x)
            break ;
    }
    cout << cnt << endl ;


    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a, happy = 0;
    scanf("%d", &a);
    if ( a >= 500){
        happy = a / 500;
        a = a - ( happy * 500 );
        happy = happy * 1000;
    }
    if ( a >= 5){
        happy = happy +(a / 5) * 5;
    }
    printf("%d", happy);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[][] yakusu=new int[168][1001];
		int[] sosu=new int[168];

		int[] eratosu=new int[1001];
		int counter=2;
		int s_c=1;
		sosu[0]=2;
		while(counter*counter<=1000) {
			for(int i=counter; i<=1000; i+=counter) {
				eratosu[i]++;
			}
			while(true) {
				counter++;
				if(eratosu[counter]==0) {
					break;
				}
			}
			sosu[s_c]=counter;
			s_c++;
		}

		for(int ax=counter+1; ax<=1000; ax++) {
			if(eratosu[ax]==0) {
				sosu[s_c]=ax;
				s_c++;
			}
		}					//エラトステネスの篩


		for(int i=2; i<=1000; i++) {
			int tmp=i;
			while(tmp>1) {
				for(int j=0; j<168; j++) {
					if(tmp%sosu[j]==0) {
						yakusu[j][i]++;
						tmp/=sosu[j];
					}
				}
			}
		}

		for(int i=0; i<168; i++) {
			for(int j=1; j<=1000; j++) {
				yakusu[i][j]=yakusu[i][j]+yakusu[i][j-1];
			}
		}

		long kotae=1;

		for(int i=0; i<168; i++) {
			kotae*=(yakusu[i][N]+1);
			kotae%=1000000007;
		}
		System.out.println(kotae);
	}
}

Measured memory_bytes: 20948
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <set>
# include <map>
# include <stack>
using namespace std;
# define M_PI 3.141592
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define pri_max 60000
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

int main()
{
	int n;
	while (cin >> n&&n)
	{
		cin.ignore();
		typedef pair<int, string> pis;
		vector<pis> v;
		vector<int> idx[200];
		for (int i = 0; i < n; i++)
		{
			string s;
			getline(cin, s);
			stringstream ss(s);
			while (getline(ss, s, ' '))
			{
				bool f = true;
				for (int l = 0; l < v.size(); l++)
				{
					if (v[l].second == s)
					{
						v[l].first++;
						f = false;
						break;
					}
				}
				if (f)
				{
					idx[s[0]].push_back(v.size());
					v.push_back(make_pair(1, s));
				}
			}
		}
		char c; cin >> c;
		if (idx[c].size())
		{
			vector<pis> vv;
			for (int i = 0; i < idx[c].size(); i++)
			{
				vv.push_back(v[idx[c][i]]);
				vv.back().first *= -1;
			}
			sort(vv.begin(), vv.end());
			//sort(vv.rbegin(), vv.rend());
			for (int i = 0; i < min(5, (int)vv.size()); i++)
			{
				cout << (i ? " " : "") << vv[i].second;
			}
			cout << endl;
		}
		else
		{
			cout << "NA" << endl;
		}
	}
}

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


int main(){


    long long int a,b,c,k;
    cin>>a>>b>>c>>k;
    int s = a*1 +b*0;
    int d = a+b;


    if(a >= k){

        int l = a-k;
        cout<<(a-l)<<endl;

    }
    else if(a < k && (a+b)>= k){

        cout<<a<<endl;

    }
    else{

        while(d != k){

            s -= 1;
            d++;

        }
        cout<<s<<endl;

    }


}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int m1,m2,d1,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  cout << (d2==1 ? 1 : 0) << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
    #define fastcin ios_base::sync_with_stdio(0);cin.tie(0)
    #define ll long long
    #define pb push_back
    #define F first
    #define S second
    #define pii pair<int,int>
    #define pli pair<long long , int>
    #define pil pair<int,long long>
    #define pll pair<long long,long long>
    #define vi vector<int>
    #define vl vector<long long>
    #define vb vector<bool>
    #define all(c) c.begin(),c.end()
    #define i(a,b) for( int i = a ; i < b ; ++i)
    #define j(a,b) for( int j = a ; j < b ; ++j)
	#define k(a,b) for( int k = a ; k < b ; ++k)			
    #define ri(a,b) for( int i = a ; i >= b ; --i)
    #define rj(a,b) for( int j = a ; j >= b ; --j)
    #define prod(a,b) (((ll)a)*((ll)b))
	#define ar cout << arr[i] << endl

using namespace std;

int solve(){
	int n;
	string s;
	cin >> n >> s;
	if(n<3200) cout << "red" << endl;
	else cout << s << endl;
	return 0 ;
}

int main(){
	fastcin;
	int q=1;
	//cin >> q;
	while(q--){
		solve();
	}		
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
const int MOD = (int)1e9 + 7;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()

int main(int argc, char const *argv[]) {
int A,B;
cin>>A>>B;
cout<<max(2*A-1,max(A+B,2*B-1))<<endl;;
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc109/tasks/abc109_c

#include <algorithm>
#include <iostream>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    long n, x;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x;
    int pos[n];

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

    int ans = abs(x - pos[0]);
    // 開始時点からの差分
    for (int i = 1; i < n; i++) {
        ans = gcd(ans, abs(x - pos[i]));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BTAKOYAKIFESTIVAL2019 solver = new BTAKOYAKIFESTIVAL2019();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTAKOYAKIFESTIVAL2019 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] d = in.readIntArray(n);

            long answer = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    answer += d[i] * d[j];
                }
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }
}



Measured memory_bytes: 21588
package main
import(
    "bufio"
    "fmt"
    "os"
    "sort"
    "strconv"
)
func main(){
	var n int
	fmt.Scan(&n)
 
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var ws works = make([]work, n)
	for i := range ws {
		sc.Scan()
		ws[i].time, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		ws[i].limit, _ = strconv.Atoi(sc.Text())
	}
    sort.Sort(ws)

    sum := int64(0)
    for _, w := range ws {
        sum += int64(w.time)
        if sum > int64(w.limit){
            fmt.Println("No")
            return
        }
    }
    fmt.Println("Yes")
}

type work struct{ time, limit int }
type works []work
 
func (w works) Len() int           { return len(w) }
func (w works) Swap(i, j int)      { w[i], w[j] = w[j], w[i] }
func (w works) Less(i, j int) bool { return w[i].limit < w[j].limit }


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int, int>

using namespace std;

int main() {
    //freopen("output.txt", "w", stdout);
    int n; cin >> n;
    vector<ll> arr;
    for (int i=0; i<n; i++) {
        double a; cin >> a;
        ll b = llround(a * 1e9);
        arr.push_back(b);
    }
    
    map<pii,int> mp;

    ll cnt = 0;
    for (int i=0; i<n; i++) {
        int t = -9, f = -9;
        while(arr[i] % 2 == 0) arr[i]/=2, t++;
        while(arr[i] % 5 == 0) arr[i]/=5, f++;
        
        for (auto i: mp) {
            pii tf = i.first;
            int v = i.second;

            if (tf.first + t >= 0 and tf.second + f >= 0) cnt += v;
        }

        mp[{t,f}]++;
    }
    cout << cnt << endl;
}

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

int main() {
    int N;
    cin >> N;
    int a;
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        cin >> a;
        if(i % 2 == 1 && a % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N, x; cin >> N >> x;
    vec a(N); readvec(a);

    int ans = 0;
    if(a[0] > x){
        ans += a[0] - x;
        a[0] = x;
    }
    FOR(i, 1, N){
        if(a[i] + a[i - 1] > x){
            ans += a[i] + a[i - 1] - x;
            a[i] -= a[i] + a[i - 1] - x;
        }
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 1024