akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int S = cin.nextInt();

        int aa = S / 100;
        int bb = S % 100;

        if (01 <= aa && aa <= 12)
        {
            if (01 <= bb && bb <= 12)
            {
                Console.WriteLine("AMBIGUOUS");
                return;
            }
            else
            {
                Console.WriteLine("MMYY");
                return;
            }
        }
        else
        {
            if (01 <= bb && bb <= 12)
            {
                Console.WriteLine("YYMM");
                return;
            }
            else
            {
                Console.WriteLine("NA");
                return;
            }
        }
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }

    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

Measured memory_bytes: 11092
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

vector<double> solve_expected(const vec<int, 2>& G) {
  int N = G.size();
  vector<double> dp(N, 0);
  dp[N - 1] = 0;
  for (int i = N - 2; i >= 0; i--) {
    for (int j : G[i]) dp[i] += dp[j];
    dp[i] /= G[i].size();
    dp[i] += 1;
  }
  return dp;
}

vector<double> solve_coef(const vec<int, 2>& G) {
  int N = G.size();
  vector<double> dp(N, 0);
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j : G[i]) dp[j] += dp[i] / G[i].size();
  }
  return dp;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, M;
  while (cin >> N >> M) {
    vec<int, 2> G(N);
    for (int i = 0; i < M; i++) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      G[a].push_back(b);
    }
    auto exp = solve_expected(G);
    auto coef = solve_coef(G);
    double res = exp[0];
    for (int i = 0; i < N; i++) {
      if (G[i].size() <= 1) continue;
      double expsum = 0;
      for (int j : G[i]) expsum += exp[j];
      for (int j : G[i]) {
        double oldVal = exp[i];
        double newVal = (expsum - exp[j]) / (G[i].size() - 1) + 1;
        double score = exp[0] + coef[i] * (newVal - oldVal);
        chmin(res, score);
      }
    }
    printf("%.20f\n", res);
  }
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 55;
ll pd[MAX][MAX][MAX*MAX];
int N, K, a[MAX];

ll solve(int i, int k, int s) {
	if(i == N && !k && !s) return 1;
	if(i == N || k < 0) return 0;
	if(s < 0) return 0;
	ll &ans = pd[i][k][s];
	if(ans != -1) return ans;
	return ans = solve(i+1, k, s) + solve(i+1, k-1, s-a[i]);
}

int main(int argc, char ** argv) {
	ll ans = 0;
	cin >> N >> K;
	rep(i, 0, N) cin >> a[i];
	REP(k, 1, 50) {
		memset(pd, -1, sizeof pd);
		solve(0, k, K*k);
		ans += pd[0][k][K*k];
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 71680
#include <iostream>
#include <vector>
#include <string>

#define ll long long

ll max2val(ll a, ll b) {
    if(a > b) {
        return a;
    }
    else {
        return b;
    }
}

int main() {
    ll N, M, K;
    ll ans, j;

    std::cin >> N;
    std::cin >> M;
    std::cin >> K;
    std::vector<ll> vecN(N, 0), vecM(M, 0);
    std::vector<ll> a(1), b(1);

    for(ll i = 0; i < N; i++) {
        std::cin >> vecN[i];
    }
    for(ll i=0; i < M; i++) {
        std::cin >> vecM[i];
    }

    for(ll i=0; i < N; i++) {
        a.push_back(a[i] + vecN[i]);
    }
    for(ll i=0; i < M; i++) {
        b.push_back(b[i] + vecM[i]);
    }
    
    ans = 0;
    j = M;
    for(ll i = 0; i < N+1; i++) {
        if(a[i] > K)
            break;
        while(b[j] > K - a[i]) {
            j -= 1;
        }
        ans = max2val(ans, i+j);
    }

    std::cout << ans;
}

Measured memory_bytes: 11104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
    char a;
    cin>>a;
    if (isupper(a)){
        cout<<'A'<<endl;
    }
    else{
        cout<<'a'<<endl;
    }
}

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

#include <vector>
int main(){
    int n;cin >> n;
    vector<int> a(n),b(n),c(n);
    for(int i=0; i<n; i++) cin >> a.at(i) >> b.at(i) >> c.at(i);
    vector<vector<int>> dp(n,vector<int>(3));
    dp[0][0] = a.at(0);
    dp[0][1] = b.at(0);
    dp[0][2] = c.at(0);
    for(int i=1; i<n;i++) {
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a.at(i);
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b.at(i);
        dp[i][2] = max(dp[i-1][1],dp[i-1][0])+c.at(i);
    }
    printf("%d\n",max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])));
}

Measured memory_bytes: 9792
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int MAXN = 100010;
const int INF = 1000000000;
const int MOD = 1000000007;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

int n;
char s[MAXN];

ll A[MAXN], C[MAXN], tot[MAXN];

int main()
{
	
	scanf("%s", s+1);
	n = strlen(s+1);
	A[0] = 0;
	for (int i = 1; i <= n; ++ i)
	{
		tot[i] = tot[i-1]+(s[i] == '?');
		if (s[i] == '?')
			A[i] = (A[i-1]*3+power(3, tot[i-1], MOD))%MOD;
		else if (s[i] == 'A')
			A[i] = (A[i-1]+power(3, tot[i-1], MOD))%MOD;
		else
			A[i] = A[i-1];
	}
	C[n+1] = 0;
	for (int i = n; i >= 1; -- i)
	{
		tot[i] = tot[i+1]+(s[i] == '?');
		if (s[i] == '?')
			C[i] = (C[i+1]*3+power(3, tot[i+1], MOD))%MOD;
		else if (s[i] == 'C')
			C[i] = (C[i+1]+power(3, tot[i+1], MOD))%MOD;
		else
			C[i] = C[i+1];
	}
	
	ll ans = 0;
	for (int i = 1; i <= n; ++ i)
		if (s[i] == '?' || s[i] == 'B')
			ans = (ans+A[i-1]*C[i+1])%MOD;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 2688
def solve():
    n, x = map(int, input().split())
    s = list(map(int, input().split()))
    cnt, tmp, prv = 0, 0, 0

    if s[0] > x:
        cnt += s[0] - x
        s[0] = x

    for y in s:
        if prv + y > x:
            tmp = prv + y - x
            cnt += tmp
            prv = y - tmp
        else:
            prv = y
    print(cnt)


solve()


Measured memory_bytes: 84588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  string s, t;
  cin >> s >> t;
  int len_s = size(s);
  int len_t = size(t);
  int l = -1, r = -1;
  set<string> st;
  rep(i, len_s - len_t + 1) {
    int cta = 0;
    rep(j, len_t) if (s[i + j] == t[j] or s[i + j] == '?') cta++;
    if (cta == len_t) {
      l = i, r = i + len_t;
      string tmp;
      rep(j, len_s) {
        if (l <= j and j < r)
          tmp += t[j - l];
        else if (s[j] == '?')
          tmp += 'a';
        else
          tmp += s[j];
      }
      //   deb1(tmp);
      st.insert(tmp);
    }
  }
  if (l == -1 and r == -1)
    out("UNRESTORABLE");
  else
    out(*st.begin());
}
int main(void) { solve(); }

Measured memory_bytes: 3632
#include <stdio.h>
int search(int S[],int n,int t){
  int i=0;
  S[n]=t;
  while (S[i]!=t)i++;
  return i==n;
}


int main(){
  int n,i,ans=0,S[10001],q,t;

  scanf("%d",&n);

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

  scanf("%d",&q);

   for(i=0;i<q;i++){
          scanf("%d",&t);
          if(!search(S,n,t))
              ans++;

     }

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



Measured memory_bytes: 2088
#include<bits/stdc++.h>
        #define ll  long long
        #define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        #define rep(i,a,b)  for(ll i=a;i<b;i++)
        #define pb push_back
        #define Max(x,y,z) max(x,max(y,z))
        #define f first
        #define s second
        #define lbd lower_bound
        #define sz(x)       (ll)x.size()
        #define pi 3.1415926536
        #define mod 1000000007
        #define MOD 998244353
        using namespace std;
        void solve()
        {
            ll n,m,k,res=0,l=0,r=0,z,sum1=0,cnt1=0,h,c,x,y;
            string t;
            cin>>x>>y;
            res=(x+y)/2;
            if((x+y)%2==0) cout<<res;
            else cout<<"IMPOSSIBLE";
            
            
        }
        int main()
        {   
            /*#ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
            #endif*/
     
            speed_up
            ll t;
            //cin>>t;
            t=1;
            while(t--)
                solve();
        }

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    sort(a.begin(), a.end());
    int ans = 0;
    rep(i, k)
    {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int n,ans=0;
    vector<int>a(9),c(9);
    rep(i,9)cin>>c[i];
    cin>>n;
    vector<int>b(n);
    rep(i,n)cin>>b[i];
    rep(i,n)rep(j,9){
    	if(b[i]==c[j])a[j]=1;
    }
    if((a[0]&a[3]&a[6])|(a[1]&a[4]&a[7])|(a[2]&a[5]&a[8])|(a[0]&a[1]&a[2])|(a[3]&a[4]&a[5])|(a[6]&a[7]&a[8])|(a[0]&a[4]&a[8])|(a[2]&a[4]&a[6])){
    	cout<<"Yes";
    }
    else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

int main(){
    int H, W, h, w;
    cin >> H >> W;
    cin >> h >> w;
    cout << H * W - h * W - w * H + (h * w) << endl;
    return 0;
}




Measured memory_bytes: 3644
fun main(args: Array<String>) {
    var fraction = Int.MAX_VALUE
    var ans = 0
    for (i in 0 until 5) {
        val dish = readInputLine().toInt()
        if (dish % 10 == 0) {
            ans += dish
        } else {
            ans += dish / 10 * 10 + 10
            if (dish % 10 < fraction) {
                fraction = dish % 10
            }
        }
    }
    
    if (fraction != Int.MAX_VALUE) {
        ans -= 10
        ans += fraction
    }
    
    println(ans)
}
 
fun readInputLine(): String {
    return readLine()!!
}

Measured memory_bytes: 33780
#include <stdio.h>
int main(int argc, char const *argv[])
{
    int n, a, b;
    scanf("%d", &n);

    if (n == 1)
    {
        /* code */
        printf("Hello World\n");
    }

    if (n == 2)
    {
        scanf("%d", &a);
        scanf("%d", &b);
        printf("%d\n", a + b);
    }

    if (n != 1 && n != 2)
    {
        return 0;
    }

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        StringBuilder result = new StringBuilder();
        
        int n = scanner.nextInt();
        
        int i = 1;
        do {
            int x = i;
            
            if (x % 3 == 0){
                
                result.append(" ");
                result.append(i);
                
            } else {
                
                do {
                    if (x % 10 == 3) {
                        result.append(" ");
                        result.append(i);
                        break;
                    }
                    x /= 10;
                    
                } while(x!=0);
                
            }
        } while(++i <= n);
        
        System.out.println(result);
        
        
    }
}


Measured memory_bytes: 27484
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair

const ll MaxN=3*1e5;

ll bit[MaxN];
void add(ll a, ll w) {
    for (ll x = a; x <= MaxN; x += (x & -x)) bit[x] += w;
}

ll sum(ll a) {
 ll ret = 0;
 for (ll x = a; x > 0; x -= (x & -x)) ret += bit[x];
 return ret;
}

int main(){
    ll N,K;
    cin>>N>>K;
    vec d;
    rep(i,N){
        ll x; cin>>x;
        d.pb(x-K);
    }
    vec r(N+1,0),s(N+1,0);
    rep(i,N) {
        r.at(i+1)=r.at(i)+d.at(i);
        s.at(i+1)=r.at(i+1);
    }
    sort(s.begin(),s.end());
    vec p(N+1);

    rep(i,N+1){
        p.at(i)=lower_bound(s.begin(),s.end(),r.at(i))-s.begin();
    }


    ll ans=0;
    rep(i,N+1){
        ans+=sum(p.at(i)+10);
        add(p.at(i)+10,1);
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 8176
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int x;
	cin>>x;
	LL now=0LL;
	FOR(i,0,x+2){
		now+=i;
		if(now>=x){
			cout<<i<<endl;
			break;
		}
	}
    return 0;
}


Measured memory_bytes: 504
#include "bits/stdc++.h"
using namespace std;
const int N=30;
int n,a[N],b[N],c[N],ans;
int main()
{
	cin>>n;
	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];

	for(int i=1;i<=n;i++)
	{
		ans+=b[a[i]];
		if(i>1 and a[i]==a[i-1]+1) ans+=c[a[i-1]];
	}

	cout<<ans;
}

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

int main() {
    int n,l;cin>>n>>l;
    vector<string> s(n);
    string result;
    for(int i=0;i<n;i++){
        cin>>s.at(i);
    }
    sort(s.begin(),s.end());
    for(int i=0;i<n;i++){
        result+=s.at(i);
    }
    cout<<result<<endl;
}


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

int main()
{
    int ans = 0;
    string s, t;
    cin >> s >> t;
    rep(i, s.length()) if (s[i] != t[i]) ans++;
    cout << ans << endl;
    return 0;
}

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

int main() {
  std::string s;
  std::cin >> s;
  const std::vector<std::string> a{"Sunny", "Cloudy", "Rainy"};
  auto i = std::find(a.begin(), a.end(), s) - a.begin();
  i = (i + 1) % 3;
  std::cout << a[i] << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int A[N];
int pre[21][N];

bool check(int id, int s) {
    for(int j = 0; j < 21; ++j)
        if(pre[j][id] - pre[j][s-1] > 1)
            return 0;
    return 1;
}

int main() {
    int n;
    cin>>n;
    for(int i = 1; i <= n; ++i) {
        cin>>A[i];
        for(int j = 0; j < 21; ++j) {
            pre[j][i] = pre[j][i-1];
            if(A[i] & (1<<j))
                pre[j][i]++;
        }
    }
    
    long long ans = 0;
    for(int i = 1; i <= n; ++i) {
        int lo = i, hi = n, found = -1;
        while(lo <= hi) {
            int mid = (lo + hi)/2;
            if(check(mid, i))
                lo = mid + 1, found = mid;
            else hi = mid - 1;
        }
        long long diff = found - i + 1;
        ans += diff;
    }
    
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
#define ll long long
#define rgi register int
#define rgl register long long
#define il inline

il int read() {
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main() {
	int a; std::cin >> a;
	int ans = 0;
	for(rgi i = 1; i <= a; ++i)
		if(i != a - i && i <= a - i)
			ans++;
	std::cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define int long long
using namespace std;

#define fin(i,n) for (int i = 0; i < n; i++)
#define fin2(i,a,b) for (int i = a; i < b; i++)
#define ford(i,n) for (int i = n-1; i >= 0; i--)
#define ford2(i,a,b) for (int i = a-1; i >= b; i--)
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define mod 1000000007
#define PI 3.1415926535897932384626
#define EXP1 2.718281828459045
#define BIG 1000000000000000000

#define sl(n) scanf("%lld", &n)
#define sll(n,m) scanf("%lld %lld", &n, &m)
#define slll(n,m,k) scanf("%lld %lld %lld", &n, &m, &k)
#define sllll(n,m,k,o) scanf("%lld %lld %lld %lld", &n, &m, &k, &o)
#define sd(n) scanf("%lf", &n)
#define sdd(n,m) scanf("%lf %lf", &n, &m)
#define sddd(n,m,k) scanf("%lf %lf %lf", &n, &m, &k)
#define sc(c) scanf(" %c", &c)
#define ss(s) scanf("%s", s)
#define sal(t,n) fin(iz,n) { scanf("%lld", &t[iz]); }
#define sad(t,n) fin(iz,n) { scanf("%lf", &t[iz]); }
#define gl(t) scanf(" %[^\n]", t);

#define pc(n) printf("%c\n", n)
#define ps(s) printf("%s\n", s)
#define pss(s) printf("%s\n", s.c_str())
#define pl(n) printf("%lld\n", n)
#define pll(n,m) printf("%lld %lld\n", n, m)
#define plll(n,m,k) printf("%lld %lld %lld\n", n, m, k)
#define pd(n) printf("%lf\n", n)
#define pdd(n,m) printf("%lf %lf\n", n, m)
#define pal(t,n) fin(rz,n) { printf("%lld ", t[rz]); } printf("\n")
#define pad(t,n) fin(rz,n) { printf("%lf ", t[rz]); } printf("\n")

#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
 
#define OK ps("OK")
#define OK1 ps("OK1")
#define OK2 ps("OK2")

#define ll int
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>

#define dll pair<ll, ll>
#define vdll vector<dll>
#define vvdll vector<vdll>

#define vb vector<bool>
#define vvb vector<vb>
#define vd vector<double>
#define vvd vector<vd>
#define vc vector<char>
#define vvc vector<vc>

#define all(v) v.begin(), v.end()
#define vlen(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second

const int bm = (int)(1e5) + 5;
int a[bm], b[bm];
bool vu[bm];
int n;
vdll rd;

signed main()
{
    sl(n);
    rd.reserve(2*n); 
    int sa = 0, sb = 0;
    fin(i, n) {
        sll(a[i], b[i]);
        sa += a[i];
        sb += b[i];
        rd.push_back({a[i], i});
        rd.push_back({b[i], i});
    }
    sort(all(rd));
    bool ok = false;
    int res = 0;
    fin(xi, n) {
        auto x = rd[xi];
        int ccx = x.fi, ind = x.se;
        if (vu[ind]) ok = true;
        vu[ind] = true;
        res += ccx;
    }
    if (! ok) {
        int ma = BIG;
        fin2(xi, n, 2*n) {
            auto x = rd[xi];
            int ccx = x.fi, ind = x.se;
            if (vu[ind]) {
                if (rd[n-1].se != ind) chmin(ma, ccx - rd[n-1].fi);
                else chmin(ma, ccx - rd[n-2].fi);
            }
            else chmin(ma, a[ind] + b[ind] - rd[n-1].fi - rd[n-2].fi);
        }
        res += ma;
    }
    chmin(res, sa);
    chmin(res, sb);
    pl(res);
}

Measured memory_bytes: 4992
# 標準入力からNとYを受け取る
N, Y = map(int, input().split())

ans = 0
for a in range(N + 1):  # 10000円の枚数を0 ~ Nの幅で全探索
    for b in range(N + 1):  # 5000円の枚数を0 ~ Nの幅で全探索
        c = N - (a + b)

        # お札の枚数が負になってはならない
        if c < 0:
            continue

        # 条件を満たす (a, b, c) の組み合わせが見つかったら終了
        if 10000 * a + 5000 * b + 1000 * c == Y:
            print(a, b, c)
            exit()

# 最後までみつからなかったらその旨を出力
print(-1, -1, -1)


Measured memory_bytes: 2940
K, S = map(int, input().split())
tmp1 = S
tmp2 = S
count = 0

for x in range(K + 1):
    tmp1 = S - x
    if tmp1 > 2 * K:
        continue
    tmp2 = min(K, tmp1)
    for y in range(tmp2 + 1):
        z = tmp1 - y
        if z <= K:
            count += 1

print(count)


Measured memory_bytes: 3060
main = do
  [a,b,c,x,y] <- map read . words <$> getLine :: IO [Int]
  let aa = min a $ c * 2
      bb = min b $ c * 2
      ab = min (a + b) $ c * 2
  if x < y
    then print $ ab * x + (y - x) * bb
    else print $ ab * y + (x - y) * aa

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(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))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

std::vector<std::string> split(std::string str, char del) {
    int first = 0;
    int last = str.find_first_of(del);

    std::vector<std::string> result;

    while(first < str.size()) {
        std::string subStr(str, first, last - first);

        result.push_back(subStr);

        first = last + 1;
        last = str.find_first_of(del, first);

        if(last == std::string::npos) {
            last = str.size();
        }
    }

    return result;
}

int D;

int main() {
    cin >> D;
    switch(D) {
    case 22:
        cout << "Christmas Eve Eve Eve"
             << "\n";
        break;
    case 23:
        cout << "Christmas Eve Eve"
             << "\n";
        break;
    case 24:
        cout << "Christmas Eve"
             << "\n";
        break;
    case 25:
        cout << "Christmas"
             << "\n";
        break;
    default:
        break;
    }
    return 0;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template <class Abel> 
struct BinaryIndexTree {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0; // to be set
    
    /* [1, n] */
    BinaryIndexTree(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    llong d, a;
    cin >> n >> d >> a;
    vector<pair<llong, llong> > XH(n);
    rep(i, n) {
        llong x, h;
        cin >> x >> h;
        XH[i] = make_pair(x, ceil((double)h / a));
    }
    sort(all(XH));
    vector<llong> X(n), H(n);
    rep(i, n) {
        X[i] = XH[i].first;
        H[i] = XH[i].second;
    }

    BinaryIndexTree<llong> BIT(n);
    rep(i, n) BIT.add(i + 1, i + 2, H[i]);

    llong ans = 0;
    int right_index;
    rep(i, n) {
        if (BIT.sum(i + 1, i + 2) <= 0) continue;
        ans += BIT.sum(i + 1, i + 2);
        right_index = upper_bound(all(X), X[i] + 2 * d) - X.begin();
        BIT.add(i + 1, right_index + 1, -BIT.sum(i + 1, i + 2));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
const int N=200000+5;
int A[N],n,mx1,mx2;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",A+i);
        if(A[i]>=mx1){
            mx2 = mx1;
            mx1 = A[i];
        }else if(A[i]>mx2){
            mx2=A[i];
        }
    }
    for(int i=0;i<n;++i)
        printf("%d\n",(A[i]==mx1)?mx2:mx1);
    return 0;
}


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


int main(){
    string s;cin>>s;
    bool flag=false;
    vector<string> a={"dream", "dreamer", "erase", "eraser"};
    while(s.size()){
        ll seven=s.end()-s.begin()-7LL;
        //cout<<seven<<endl;
        seven=max(seven,0LL);
        ll five=(s.end())-s.begin()-5LL;
        five=max(five,0LL);
        ll six=(s.end())-s.begin()-6LL;
        six=max(six,0LL);
        vector<ll> sfs={five,six,seven};
        bool flag=false;
        rep(i,4){
            rep(j,sfs.size()){
            //cout<<s.substr(sfs[j])<<" "<<sfs[j]<<endl;
            if(s.substr(sfs[j])==a[i]){
                s.erase(sfs[j],j+5);
                flag=true;
                break;
            }
            }
        if(flag){
            break;
        }
    }
    if(!flag){
        break;
    }
    }
    if(s.size()==0){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

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

const int H = 3;
const int W = 3;

inline int pos(int i, int j) {
  return i*W + j;
}

char solve(const string &s) {
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      if(s[pos(i,j)] == 's') continue;
      for(int di = -1; di <= 1; ++di) {
        for(int dj = -1; dj <= 1; ++dj) {
          if(di|dj) ; else continue;
          for(int l = 1; l <= 3; ++l) {
            if(l == 3) return s[pos(i,j)];
            int ni = i + di * l;
            int nj = j + dj * l;
            if(ni < 0 || ni >= H) break;
            if(nj < 0 || nj >= W) break;
            if(s[pos(ni,nj)] != s[pos(i,j)]) break;
          }
        }
      }
    }
  }
  return 'd';
}

int main() {
  string s;
  while(getline(cin, s)) {
    cout << solve(s) << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
//#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<double,double> P;
const ll INF = 4*1e18;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int h,w,k;bool s[20][1100];
signed main(){
  cin>>h>>w>>k;
  rep(i,h)rep(j,w){
    char c;cin>>c;
    s[i][j] = (c == '1');
  }
  int ans = INF;
  rep(i,1<<(h-1)){
    int sum = 0, c = 0, cnt[20];
    rep(j,20)cnt[j] = 0;
    vector<int> vec;
    bool can = true;
    rep(j,h-1){
      if(i&(1<<j)){
        sum++;
        vec.push_back(j);
      }
    }
    rep(j,w){
      rep(l,h){
        if(s[l][j])c++;
        if(i&(1<<l) || l == h-1){
          if(j == 0)cnt[l] = c;
          if(c > k){
            can = false;
            break;
          }
          c = 0;
        }
      }
    }

    repd(j,1,w){
      c = 0;
      bool reset = false;
      rep(l,h){
        if(s[l][j])c++;
        if(i&(1<<l) || l == h-1){
          cnt[l] += c;
          if(cnt[l] > k){
            reset = true;break;
          }
          c = 0;
        }
      }
      if(reset){
        sum++;
        c = 0;
        rep(l,h){
          if(s[l][j])c++;
          if(i&(1<<l) || l == h-1){
            cnt[l] = c;
            c = 0;
          }
        }
      }
    }
    if(can)chmin(ans, sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int b, f, r, v;;
	int house[5][4][11];
	int i, n;

	for (b = 1; b <= 4; b++) {
		for (f = 1; f <= 3; f++) {
			for (r = 1; r <= 10; r++) house[b][f][r] = 0;
		}
	}
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d%d%d", &b, &f, &r, &v);
		house[b][f][r] += v;
	}

	for (b = 1; b <= 4; b++) {
		for (f = 1; f <= 3; f++) {
			for (r = 1; r <= 10; r++) printf(" %d", house[b][f][r]);
			putchar('\n');
		}
		if (b < 4) puts("####################");
	}
	return 0;
}



Measured memory_bytes: 2048
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  rep(i, n) cin >> s[i] >> t[i];
  string x;
  cin >> x;

  int ans = 0;
  rep(i, n) ans += t[i];
  rep(i, n) {
    ans -= t[i];
    if (s[i] == x) break;
  }
  cout << ans << endl;






  
  return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())


from collections import Counter

cnt = Counter([])

n,k = li()

num = []
index = []

for _ in range(n):
    a,b = li()
    cnt[a] += b


res = k
for key in sorted(cnt.keys()):
    if res - cnt[key] <= 0:
        print (key)
        break
    
    res -= cnt[key]

Measured memory_bytes: 10856
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var tpls = new Tuple<int, int>[n];
        for (int i = 0; i < n; i++)
        {
            var ab = Console.ReadLine().Split();
            tpls[i] = Tuple.Create(
                int.Parse(ab[1]),
                int.Parse(ab[0]));
        }

        Array.Sort(tpls);

        var t = 0L;
        for (int i = 0; i < n; i++)
        {
            var a = tpls[i].Item2;
            var b = tpls[i].Item1;
            t += a;

            if (b < t)
            {
                Console.WriteLine("No");
                return;
            }
        }

        Console.WriteLine("Yes");
    }
}


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


def main():
    S = input().rstrip()
    if S == "RRR":
        print(3)
    elif S == "RRS":
        print(2)
    elif S == "SRR":
        print(2)
    elif S == "SSS":
        print(0)
    else:
        print(1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9100
(let* ((n (read))
       (a (make-array `(,(+ n 1)) :initial-element 0))
       (m 0)
       (dp)
       (c)
       (r 0))
  ;; read
  (loop :for i :from 1 :to n
        :do (setf (aref a i) (read)))
  ;;
  (setf a (sort a #'<))
  (setf m (aref a (1- (length a))))
  (setf dp (make-array `(,(1+ m)) :initial-element t))
  (setf c (make-array `(,(1+ m)) :initial-element nil))
  ;;
  (loop :for i :from 1 :to n
        :do (let ((x (aref a i)))
              (when (and (null (aref c x)) (aref dp x))
                (setf (aref c x) t)
                (loop :for y :from (* x 2) :upto m :by x
                      :do (setf (aref dp y) nil)))))
  ;;
  (loop :for i :from 1 :to n
        :if (and (or (= i n) (/= (aref a i) (aref a (1+ i))))
                 (or (= i 1) (/= (aref a (1- i)) (aref a i)))
                 (aref dp (aref a i)))
        :do (incf r))
  (format t "~A~%" r))


Measured memory_bytes: 88060
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
    string S,T;
    cin >> S >> T;

    T.pop_back();

    if(T == S){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3628
from collections import deque
N=input()
a=map(int, raw_input().split())
b=map(int, raw_input().split())

S=[]
def bfs(n,start,end):
	c=[set() for i in range(51)]

	for i in range(51):
		for j in range(1,n+1):
	 		c[i].add(i%j)

	for i in range(51):
	 	c[i].add(i)

	for i in range(51):
		for j in S:
			c[i].add(i%j)

	V=[ None for i in range(51) ]

	q = deque([]) 
	V[start]=1
	q.append(start)

	while len(q)!=0:
		v=q.popleft()
		for i in c[v]:
			if i==end:
				return True
			else:
				if V[i] is None:
					V[i]=1
					q.append(i)
	else:
		return False



for i in range(50,-1,-1):
	#print i
	for x,y in zip(a,b):
		#print i,x,y,bfs(i,x,y)
		if not bfs(i,x,y):
			if i==50:
				print -1
				quit()
			else:
				S.append(i+1)


ans=0
for i in S:
	ans+=2**i
print ans




Measured memory_bytes: 2812
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <iostream>
#include <utility>
#include <sstream>
#include <cstring>
#include <bitset>
#include <climits>
 
using namespace std;
#define  AS(arr)  (sizeof(arr)/sizeof(arr[0]))
#define ALL(c) (c).begin(),(c).end() 
#define SIZE(a) int((a).size())
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define REP(i,n) for(int i=0;i<(int)n;++i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef long long LL;
int main(void){
    int N, a[101];
    cin >> N;
    int total = 0;
    REP(i, N)
    {
        cin >> a[i];
        total += a[i];
    }
    int avg = round(((double)total) / N);
    int ret = 0;
    REP(i, N)
    {
        ret += pow(avg - a[i], 2);
    }
    cout << ret << endl;
    
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  const A = parseInt(input[0].split(" ")[0]);
  const B = parseInt(input[0].split(" ")[1]);

  console.log(A * B);
}
// デバッグ用
function debug() {
  var input = document.getElementById("input").value;
  Main(input);
}

//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30592
<?php
list($n) = ints();
$a = ints();
for ($i = 0; $i < $n; ++$i) {
    if (isset($cnt[$a[$i]])) $cnt[$a[$i]]++;
    else $cnt[$a[$i]] = 1;
}
if (isset($cnt[1])) {
    if ($cnt[1] > 1) exit('0');
    else exit('1');
}
ksort($cnt);
$max = max($a);
$isPrime = isPrimeArr($max);
$ans = 0;
foreach ($cnt as $i => $v) if ($v === 1 && $isPrime[$i]) $ans++;
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

function isPrimeArr($max)
{
    global $cnt;
    $arr = array_fill(0, $max + 1, true);
    $arr[0] = false;
    foreach ($cnt as $i => $v)
        for ($j = 2 * $i; $j <= $max; $j += $i) $arr[$j] = false;
    return $arr;
}


Measured memory_bytes: 69432
while 1:
    n=int(input())
    if n==0:break
    ans=[[0 for i in range(n)] for j in range(n)]
    y=n//2
    x=n//2-1
    for i in range(1,n**2+1):
        y=[y+1,y+1-n][y+1==n]
        x=[x+1,x+1-n][x+1==n]
        if ans[y][x]==0:ans[y][x]=str(i).rjust(4)
        else:
            y=[y+1,y+1-n][y+1==n]
            x=[x-1,x-1+n][x==0]
            ans[y][x]=str(i).rjust(4)
    for i in ans:print(''.join(map(str,i)))


Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 100010
int n;
bool t[N];
unordered_set<int> v[N];
unordered_set<int>::iterator it;
queue<int> Q;
void BFS(int x){
  if(v[x].size()==0)return;
  int to=*v[x].begin();
  t[to]=false;
  t[x]=false;
  //cout<<"%"<<x<<" "<<to<<endl;
  for(it=v[x].begin();it!=v[x].end();it++){
    v[*it].erase(x);
  }
  for(it=v[to].begin();it!=v[to].end();it++){
    v[*it].erase(to);
    if(v[*it].size()==1)Q.push(*it);
  }
}
int main(){
  cin>>n;
  lol(i,n-1){
    int a,b;cin>>a>>b;
    a--,b--;
    v[a].insert(b);
    v[b].insert(a);
  }
  lol(i,n)t[i]=true;
  lol(i,n)if(v[i].size()==1)Q.push(i);
  while(!Q.empty()){
    int x=Q.front();
    Q.pop();
    BFS(x);
  }
  int sum=0;
  lol(i,n)sum+=t[i];
  cout<<(sum>0?"First":"Second")<<endl;
  return 0;
}


Measured memory_bytes: 16512
#include<bits/stdc++.h>
using namespace std;
int digit(int n)
{
    int c=0;
    while(n>0)
    {
        n/=10;
        c++;
    }
    return c;
}
int power(int a ,int b)
{
    int i,j=1;
    for(i=1;i<=b;i++) j*=a;
    return j;
}
int main()
{

    int n,f,l,dig,tm,c=0,i,j;
    int a[10][10];
    cin>>n;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
        {
            a[i][j]=0;
        }
    }
    for(i=1;i<=n;i++)
    {
        dig=digit(i);
        tm=power(10,dig-1);
       // cout<<tm<<endl;
        f=i/tm;
        l=i%10;
        a[f][l]++;
       // cout<<i<<" "<<f<< " "<<l<<endl;
    }
    for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
        {
            // printf("G[%d][%d]=%d  G[%d][%d]=%d\n",i,j,a[i][j],j,i,a[j][i]);

            c+=(a[i][j]*a[j][i]);
        }
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int a[364][364];
int main()
{
	int n;lint out=0;
	cin>>n;
	rep(i,n) rep(j,n) cin>>a[i][j];
	rep(i,n) REP(j,i+1,n){
		int f=0;
		rep(k,n){
			if(k==i || k==j) continue;
			if(a[i][k]+a[k][j]<a[i][j]){
				cout<<-1<<endl;return 0;
			}
			if(a[i][k]+a[k][j]==a[i][j]) f=1;
		}
		if(f<1) out+=a[i][j];
	}
	cout<<out<<endl;
}


Measured memory_bytes: 640
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
                vector<string> store;
                int n, m;
                int check(int x, int y, int k){
                    int cnt = 0;
                    // cout<<x<<" ";
                    for(int i= 0 ; i < n; i++)
                        for(int j = 0; j < m; j++)
                            if(store[i][j] == '#' && (x&(1<<i))==0 && (y&(1<<j))==0){
                                ++cnt;
                            }

                    return cnt==k;
                }
                void solve(){
                    int k;
                    cin>>n>>m>>k;
                    store.resize(n, "");
                    for(int i = 0; i < n; i++)
                        cin>>store[i];
                    int ans = 0;
                    for(int i = 0; i < (1<<n); i++){
                        for(int j = 0; j < (1<<m); j++)
                            if(check(i, j, k)){
                                ++ans;
                            }
                    }
                    cout<<ans;
                }
                int main(){ 
                        hs;
                        ll t;
                        t=1;
                        // cin>>t;
                        for (int i=1; i<=t; i++){
                                //cout<<"Case #"<<i<<": ";
                                solve();
                         }
        return 0; 
}         
 


Measured memory_bytes: 3644