akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;
constexpr ll mod = 1000000007LL;

// a - bをmodをとりつつ計算する.
ll submod(ll a, ll b) {
    return a > b ? (a - b) % mod : ((a - b) % mod + mod);
}

// x^nをmodをとりつつ求める
ll powmod(ll x, ll n) {
    if (n == 0LL)
        return 1LL;
    x %= mod;
    if (n % 2LL == 0) {
        return powmod((x * x) % mod, n / 2LL);
    } else {
        return (x * powmod((x * x) % mod, n / 2LL)) % mod;
    }
}

// xの逆元を求める.
ll modinv(ll x) {
    return powmod(x, mod - 2LL);
}

ll mfac[200000 + 1];

void initFac() {
    mfac[0] = mfac[1] = 1LL;
    for (int i = 2; i <= 200000; ++i) {
        mfac[i] = mfac[i - 1] * i % mod;
    }
}

// nPkを求める
ll perm(ll n, ll k) {
    if (k > n)
        return 0;
    return mfac[n] * modinv(mfac[n - k]) % mod;
}

// nCkを求める
ll comb(ll n, ll k) {
    if (k > n)
        return 0LL;
    else
        return mfac[n] * modinv(mfac[k] * mfac[n - k]) % mod;
}

ll dfs(int s, int p, const int K, const vector<vector<int>> &G) {
    ll pn;
    if (p == 1 && s == 1) {
        pn = perm(K - 1, G[s].size());
    } else if (G.size() - 1 > 0) {
        pn = perm(K - 2, G[s].size() - 1);
    } else
        pn = 1;

    for (auto &child : G[s]) {
        if (child == p)
            continue;

        pn *= dfs(child, s, K, G);
        pn %= mod;
    }

    return pn % mod;
}

int main() {
    initFac();

    int N, K;
    cin >> N >> K;
    vector<vector<int>> G(N + 1);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    if (N == 1)
        cout << K << endl;
    else if (N == 2) {
        cout << perm(K, 2) << endl;
    } else {
        if (K <= 2)
            cout << 0 << endl;
        else
            cout << (dfs(1, 1, K, G) * K % mod) << endl;
    }
    return 0;
}

Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    string t;
    cin >> t;
    ll g = GCD(n, m);
    rep(i, g){
        dump(s[i*n/g], t[i*m/g]);
        if(s[i*n/g] != t[i*m/g]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << LCM(n, m) << endl;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> G[1000000];
vector<pair<int, int> > bridge;
vector<int> articulation;
int ord[1000000], low[1000000];
bool vis[1000000];

void dfs(int v, int p, int &k)
{
	vis[v] = true;
	
	ord[v] = k++;
	low[v] = ord[v];
	
	bool isArticulation = false;
	int ct = 0;
	
	for (int i = 0; i < G[v].size(); i++){
		if (!vis[G[v][i]]){
			ct++;
			dfs(G[v][i], v, k);
			low[v] = min(low[v], low[G[v][i]]);
			if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
			if (ord[v] < low[G[v][i]]) bridge.push_back(make_pair(min(v, G[v][i]), max(v, G[v][i])));
		}
		else if (G[v][i] != p){
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}
	
	if (p == -1 && ct > 1) isArticulation = true;
	if (isArticulation) articulation.push_back(v);
}
// http://kagamiz.hatenablog.com/entry/2013/10/05/005213
int main()
{
	int n, m;
	
	scanf("%d %d", &n, &m);
	
	for (int i = 0; i < m; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		G[--x].push_back(--y);
		G[y].push_back(x);
	}
	
	int k = 0;
	for (int i = 0; i < n; i++){
		if (!vis[i]) dfs(i, -1, k);
	}
	
	printf("%d\n", bridge.size());
  /*
	sort(bridge.begin(), bridge.end());
	sort(articulation.begin(), articulation.end());
	
	printf("%d\n", articulation.size());
	
	for (int i = 0; i < articulation.size(); i++)
		printf("%d\n", articulation[i] + 1);
	
	printf("%d\n", bridge.size());
	
	for (int i = 0; i < bridge.size(); i++)
		printf("%d %d\n", bridge[i].first + 1, bridge[i].second + 1);
	*/
	
	return (0);
}


Measured memory_bytes: 26880
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
int main(int const argc, char const** argv){
  int n;
  std::cin >> n;
  std::vector<int> vec(n);
  for(int i = 0; i<n; ++i){
    std::cin >> vec[i];	
    // scanf("%d\n", & vec[i]);
  }
  int min = vec[0];
  int max = -2147483647;
  for(int i = 1; i<n; ++i){
    max = std::max(max, vec[i] - min);
    min = std::min(min, vec[i]);
  }
  std::cout << max << std::endl;
}

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

int main(){
    int N, ans;
    cin >> N;
    ans = N%10;
    if(ans == 3){
        cout << "bon" << endl;
    } else if(ans == 0 || ans == 1 || ans == 6 || ans == 8){
        cout << "pon" << endl;
    } else{
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3556
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
 */
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);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            int[] a = new int[50];
            int max = 0;
            for (int i = 0; i < a.length; i++) {
                a[i] = (int) (n % 10);
                max += a[i];
                n /= 10;
            }

            for (int i = a.length - 1; i >= 0; i--) {
                if (a[i] > 0) {
                    int sum = 0;
                    for (int j = a.length - 1; j > i; j--) {
                        sum += a[j];
                    }
                    sum += a[i] - 1;
                    sum += 9 * i;
                    max = Math.max(sum, max);
                }
            }

            out.println(max);
        }

    }

    static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream is) {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            this.br = br;
        }

        public String next() {
            if (st == null || !st.hasMoreTokens()) {
                String nextLine = null;
                try {
                    nextLine = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (nextLine == null)
                    return null;
                st = new StringTokenizer(nextLine);
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, p, ans = 0, ten = 1;
string s;

int main() {
	cin >> n >> p;
	vector<ll> d(n + 1);
	map<ll, ll> m;
	cin >> s;
	if (10 % p == 0) {
		rep(i, n) {
			if ((s[i] - '0') % p == 0)ans += i + 1;
		}
	}
	else {
		m[0] = 1;
		for (int i = n - 1; i >= 0; i--) {
			d[i] = (d[i + 1] + ten * (s[i] - '0')) % p;
			ten *= 10;
			ten %= p;
			ans += m[d[i]];
			m[d[i]]++;
		}

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

Measured memory_bytes: 2564
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,INF=0x3f3f3f3f;
typedef pair<int,int> pii;
int a[N],fa[N],vis[N],mi[N],V[N];
vector<pii >Q(N);
int find(int x)
{
    return x==fa[x]?x:(fa[x]=find(fa[x]));
}
int main()
{
    ios::sync_with_stdio(false);
    int n,m,tn=0;
    cin>>n>>m;
    for(int i=0; i<n; i++)
        cin>>a[i],fa[i]=i,mi[i]=INF;
    for(int i=0,u,v; i<m; i++)
    {
        cin>>u>>v,u=find(u),v=find(v);
        if(u!=v)fa[u]=v;
    }
    for(int i=0; i<n; i++)find(i);
    for(int i=0; i<n; i++)
    {
        if(!vis[fa[i]])V[tn++]=fa[i];
        vis[fa[i]]=1;
    }
    if(tn==1)cout<<0;
    else if((tn-1)*2>n)cout<<"Impossible";
    else
    {
        long long s=0;
        for(int i=0; i<n; i++)
            Q[i]=make_pair(a[i],fa[i]),mi[fa[i]]=min(a[i],mi[fa[i]]);
        for(int i=0; i<tn; i++)s+=mi[V[i]];
        if(tn!=2)sort(Q.begin(),Q.begin()+n);
        for(int i=0; i<n&&tn!=2; i++)
        {
            if(vis[Q[i].second])
            {
                vis[Q[i].second]=0;
                continue;
            }
            s+=Q[i].first,tn--;
        }
        cout<<s;
    }
    return 0;
}


Measured memory_bytes: 2944
import java.util.*;
import java.io.*;
class Main {
    public static long solve(int[] weight, int[] value, int w, int i, long[][] dp){
        if(i >= weight.length || w <= 0){
            return 0;
        }
        if(dp[i][w] != -1){
            return dp[i][w];
        }
        long ans = Long.MIN_VALUE;
        ans = Math.max(ans, solve(weight, value, w, i+1, dp));
        if(w-weight[i] >= 0){
            ans = Math.max(ans, value[i] + solve(weight, value, w-weight[i], i+1, dp));
        }
        dp[i][w] = ans;
        return ans;
    }
    public static void main(String args[] ) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	String[] s = br.readLine().trim().split(" ");
  		int n = Integer.parseInt(s[0]);
        int w = Integer.parseInt(s[1]);
      	int[] weight = new int[n];
        int[] value = new int[n];
        for(int i = 0; i < n; i++){
        	String[] str = br.readLine().trim().split(" ");
          	weight[i] = Integer.parseInt(str[0]);
          	value[i] = Integer.parseInt(str[1]);
        }
        
        long[][] dp = new long[n+1][w+1];
        for(int j = 0; j < dp.length; j++){
          for(int k = 0; k < dp[0].length; k++){
            dp[j][k] = -1;
          }
        }
        System.out.println(solve(weight, value, w, 0, dp));
    }
}


Measured memory_bytes: 126420
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  ll x, y;
  x = y = 0;
  for (int i = n-1; i > 0 && y == 0; i--) {
    if (a[i] == a[i-1]) {
      if (x == 0) x = a[i];
      else y = a[i];
      i--;
    }
  }
  dump(x*y);
  return 0;
}


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

using namespace std;

int main()
{
	string S;
	cin >> S;
	
	int n = S.size();
	vector<int> answer(n);
	
	int count = 0;
	// S[0]からLが来るまで、連続したRをカウントし、初めて出現したLとその直前のRに割り振る
	for (int i = 0; i < n; i++)
	{
		if (S[i] == 'R')
		{
			count++;
		}
		// Lが見つかった場合
		else {
			// 右側は切り捨て
			answer[i] += count / 2;
			// 左側は切り上げ
			answer[i - 1] += (count + 1) / 2;
			count = 0;
		}
	}
	
	
	// S[n - 1]からRが来るまで、連続したLをカウントし、初めて出現したRとその後ろにあるLに割り振る
	for (int i = n - 1; i >= 0; i--)
	{
		if (S[i] == 'L')
		{
			count++;
		}
		// Rが見つかった場合
		else {
			// 左側は切り捨て
			answer[i] += count / 2;
			// 右側は切り上げ
			answer[i + 1] += (count + 1) / 2;
			count = 0;
		}
	}
	
	// 出力
	for (int i = 0; i < n; i++)
	{
		cout << answer[i] << " ";
	}
	cout << endl;
	
	return 0;
}



Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from collections import deque

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

color = [-1] * n
def dfs(p, v, c):
    for nv in edge[v]:
        color[nv] = not c
        if nv == p:
            continue
        dfs(v, nv, not c)

dfs(-1, 0, 0)
white = sum(color)
black = n - white
if white > black:
    white, black = black, white
    color = [not item for item in color]

# Fill 0 mod 3 or not
if white <= n // 3:
    threes = [item for item in range(1, n+1) if item % 3 == 0]
    others = [item for item in range(1, n+1) if item % 3 != 0]
    array = deque(others + threes)
# Fill 1 mod 3 or 2 mod 3
else:
    threes = [item for item in range(1, n+1) if item % 3 == 0]
    twos = [item for item in range(1, n+1) if item % 3 == 2]
    ones = [item for item in range(1, n+1) if item % 3 == 1]
    array = deque(ones + threes + twos)

ans = [-1] * n
for i, is_white in enumerate(color):
    if is_white:
        ans[i] = array.pop()
    else:
        ans[i] = array.popleft()

print(*ans)

Measured memory_bytes: 167440
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cmath>
#include <string>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
ll val(string s) {
    ll ans = 0;
    REP(i,s.size()) {
        ans = 10LL * ans;
        ans += s[i] - '0';
    }
    return ans;
}

int main() {
    string S; cin>>S;
    int len = S.length();
    ll ans = 0;
    if(len <= 1) {
        ans += S[0] - '0';
    } else {
        const int bitmask = (1<<(len-1));
        REP(mask, bitmask) {
            //cout << mask << endl;
            int left = 0, right = 1;
            ll tmp = 0;
            string ss;
            REP(i,len-1) {
                if((mask >> i) & 1) {
                    right = i + 1;
                    ss = S.substr(left, right - left);
                    //cout << ss << endl;
                    ans += val(ss);
                    left = i + 1;
                }
            }
            ss = S.substr(left);
            ans += val(ss);
            //cout << ss << endl;
            //cout << "------" << endl;

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



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int k;
  cin >> k;
  if(k%2==0){
    cout << (k/2)*(k/2) << endl;
  }
  else{
    cout << (k/2)*(k/2+1) << endl;
  }
  return 0;
}
  

Measured memory_bytes: 256
// Chain Disappearance Puzzle
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int[][] field;
	static int h;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			h = sc.nextInt();
			if (h == 0)
				break;
			field = new int[h][5];
			for (int i = 0; i < h; i++)
				for (int j = 0; j < 5; j++)
					field[i][j] = sc.nextInt();
			System.out.println(disappear());
		}
		sc.close();
	}

	static int disappear() {
		int result = 0;
		boolean[][] bfield = new boolean[h][5];
		boolean canDelete = true;
		while (canDelete) {
			canDelete = false;
			for (int i = 0; i < h; i++) {
				Arrays.fill(bfield[i], false);
				for (int j = 0; j < 3; j++) {
					if (field[i][j] != 0 && field[i][j] == field[i][j + 1]
							&& field[i][j] == field[i][j + 2]) {
						bfield[i][j] = true;
						bfield[i][j + 1] = true;
						bfield[i][j + 2] = true;
						canDelete = true;
					}
				}
				for (int j = 0; j < 5; j++)
					if (bfield[i][j]) {
						result += field[i][j];
						field[i][j] = 0;
					}
			}
			for (int i = 0; i < 5; i++) {
				for (int t = h; t > 0; t--) {
					for (int j = 1; j < t; j++) {
						if (field[j][i] == 0) {
							int temp = field[j][i];
							field[j][i] = field[j - 1][i];
							field[j - 1][i] = temp;
						}
					}
					if (field[t - 1][i] == 0)
						break;
				}
			}
		}
		return result;
	}
}

Measured memory_bytes: 49948
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {

    ll N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;

    string T;
    cin >> T;

    ll score = 0;

    rep(i, N) {
        if (i < K) {
            if (T[i] == 'r') {
                score += P;
            }
            else if (T[i] == 's') {
                score += R;
            }
            else if (T[i] == 'p') {
                score += S;
            }
        }
        else {
            if (T[i] == 'r' && T[i- K] != 'r') {
                score += P;
            }
            else if (T[i] == 's' && T[i - K] != 's') {
                score += R;
            }
            else if (T[i] == 'p' && T[i - K] != 'p') {
                score += S;
            }
            else {
                T[i] = '.';
            }
        }
    }

    cout << score;

    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int n = -1;
	for (int i = 0; i < S.size() - T.size() + 1; i++) {
		if ((S.at(i) == T.at(0))||(S.at(i) == '?')) {
			bool b = true;
			string s = S.substr(i, T.size());
			
			for (int j = 0; j < s.size(); j++) {
				if ((s.at(j) != '?')&&(s.at(j) != T.at(j))) {
					b = false;
					break;
				}
			}

			if (b) {
				n = i;
			}
		}
	}

	if (n == -1) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	for (int i = 0; i < T.size(); i++) {
		S.at(n + i) = T.at(i);
	}

	for (int i = 0; i < S.size(); i++) {
		if (S.at(i) == '?') {
			S.at(i) = 'a';
		}
	}
	cout << S << endl;
}


Measured memory_bytes: 3584
N, K = gets.split.map(&:to_i)
D_array = gets.split.map(&:to_i)
ans = 0
N.upto(10*N) do |i|
  next if D_array.any? { |d| i.to_s.chars.map(&:to_i).include?(d) }

  puts i
  exit
end

Measured memory_bytes: 1788
n,m=map(int,input().split())
x=list(map(int,input().split()))
if n>=m:
    print("0")
    exit()
x.sort()
a=[0]
for i in range(m-1):
   a.append(x[i+1]-x[i])
a.sort(reverse=True)
for i in range(n-1):
    a[i]=0
print(sum(a))

Measured memory_bytes: 13968
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    string s;
    cin >> s;
    long long cnt = 0;
    long long ans = 0;
    int flagB=0;
    for(int i=0; i<(int) s.size(); i++){
        if(s[i]=='A'){
            if(flagB==1)cnt=0;
            cnt++;
            flagB=0;
        }else if(flagB == 1 && s[i]=='C'){
            ans+=cnt;
            flagB=0;
        }else if(flagB == 1 && s[i] == 'B'){
            cnt = 0;
        }else if(s[i]=='B'){
            flagB = 1;
        }else if(s[i]=='C'){
            cnt=0;
            flagB=0;
        }
        //cout << i+1 << ' ' << ans << endl;
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  cin>>N;
  int sum=0;
  vector<int> V(N),C(N);
  for(int i=0;i<N;i++) 
    cin>>V.at(i);
  for(int i=0;i<N;i++)
    cin>>C.at(i);
  for(int i=0;i<N;i++)
    if((V.at(i)-C.at(i))>0) 
      sum+=V.at(i)-C.at(i);
  cout<<sum<<endl; 
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 10000000007; //10^9+7

int main(){
  ll n;
  cin>>n;
  int i=1;
  while(i*i<=n){
    i++;
  }
  ll ans=(i-1)*(i-1);
  print(ans);
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
	int a, b, n, t1, t2, way[17][17];
	while(1){
		scanf("%d %d", &a, &b);
		if(!a && !b)break;
		scanf("%d", &n);
		for(int i = 1;i <= b;i++){
			for(int j = 1;j <= a;j++)way[i][j] = 0;
		}
		for(int i = 0 ;i < n;i++)scanf("%d %d", &t1, &t2), way[t2][t1] = -1;
		for(int i = 1;i <= a;i++){if(way[1][i] == -1)break;way[1][i] = 1;}
		for(int i = 1;i <= b;i++){if(way[i][1] == -1)break;way[i][1] = 1;}
		for(int i = 2;i <= b;i++){
			for(int j = 2;j <= a;j++){
				if(way[i][j] != -1){
					int w = 0, h = 0;
					if(way[i][j-1] != -1)w = way[i][j-1];
					if(way[i-1][j] != -1)h = way[i-1][j];
					way[i][j] = w + h;
				}
			}
		}
		printf("%d\n", way[b][a]);
	}
	return 0;
}

Measured memory_bytes: 2600
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    if (A % 2 == 1 && B % 2 == 1) System.out.println("Yes");
    else System.out.println("No");
  }
}

Measured memory_bytes: 21204
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	x = int(input())
	#b , c = tin()
	#s = input()
	na = x // 11
	nb = x % 11
	nc = 0 if nb == 0 else 1 if nb <= 6 else 2
	return na * 2 + nc
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 62096
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int N = 403, mod = 998244353;
template<typename T>
void read(T &x){
	int ch = getchar(); x = 0; bool f = false;
	for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
	for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
	if(f) x = -x;
}
void qmo(int &x){x += (x >> 31) & mod;}
int ksm(int a, int b){
	int res = 1;
	for(;b;b >>= 1, a = (LL) a * a % mod) if(b & 1) res = (LL) res * a % mod;
	return res;
}
template<typename T>
inline bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
int n, h[N], pw2[N], ans, f[N][N], g[N][N];
int solve(int l, int r, int val){
	if(l > r) return 0;
	int mid = l;
	for(Rint i = l + 1;i <= r;++ i) if(h[mid] > h[i]) mid = i;
	int lc = solve(l, mid-1, h[mid]), rc = solve(mid+1, r, h[mid]);
	for(Rint i = 0;i <= mid-l;++ i)
		for(Rint j = 0;j <= r-mid;++ j){
			int tmp = (LL) f[lc][i] * f[rc][j] % mod;
			qmo(f[mid][i+j] += tmp - mod); qmo(f[mid][i+j+1] -= tmp); qmo(g[mid][i+j+1] += tmp - mod);
			qmo(g[mid][i+j] += (LL) (f[lc][i] + g[lc][i]) * (f[rc][j] + g[rc][j]) % mod - mod); qmo(g[mid][i+j] -= tmp);
		}
	for(Rint i = 0;i <= r-l+1;++ i){
		f[mid][i] = (LL) f[mid][i] * ksm(pw2[r-l+1-i], h[mid] - val) % mod;
		g[mid][i] = (LL) g[mid][i] * ksm(pw2[r-l+1-i]-1, h[mid] - val) % mod;
	} return mid;
}
int main(){
	read(n); pw2[0] = f[0][0] = 1;
	for(Rint i = 1;i <= n;++ i){read(h[i]); qmo(pw2[i] = (pw2[i-1]<<1) - mod);}
	int rt = solve(1, n, 0);
	for(Rint i = 0;i <= n;++ i){qmo(ans += f[rt][i] - mod); qmo(ans += g[rt][i] - mod);}
	printf("%d\n", ans);
}

Measured memory_bytes: 5024
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \ }
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int N = 105, V = 1004;
const ll inf = (ll) 1e18;

ll dp[N*V];
// dp[v] := max weight attained with knapsack of value exactly v till some iteration
int n, mxv, W;
int w[N], v[N];

void solve() {
   for (int i = 1; i <= mxv; ++i) dp[i] = inf;
   dp[0] = 0;

   for (int i = 1; i <= n; ++i) for (int j = mxv; j >= 0; --j)
   {
      if (j >= v[i]) dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
   }

   int mx_val = 0;
   for (int val = mxv; val >= 0; --val) {
      if (dp[val] <= W) {
         mx_val = val;
         break;
      }
   }
   cout << mx_val << '\n';
}

signed main() {
   IOS; PREC;
   cin >> n >> W;
   mxv = 0;
   for (int i = 1; i <= n; ++i)
      cin >> w[i] >> v[i], mxv += v[i];
   solve();


   return EXIT_SUCCESS;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#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(i, 0, n)
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define FINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) ((a) <= (i) && (i) <= (b))
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(begin(a), end(a)); }
template <typename T> inline void REV(T& a) { reverse(begin(a), end(a)); }
template <typename T> inline void UNI(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <typename S, typename T> inline T LB(S& v, T a) { return *lower_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int LBP(S& v, T a) { return lower_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> inline T UB(S& v, T a) { return *upper_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int UBP(S& v, T a) { return upper_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> ostream& operator << (ostream& os, const pair<S, T>& p) { os << p.first << " " << p.second; return os; }
template <typename S, typename T> istream& operator >> (istream& is, pair<S, T>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator >> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

string s;

void _main() {
    cin >> s;
    int ans = 0;
    REP (i, SZ(s)) {
        ans += (s[i] == '2');
    }
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
main()
{
	long long int a, b;
	long long int i;
	cin >> a >> b;
	long long int x = b/0.1;
	for(i=x;i<x+1001;i++)
	{
		long long int x = i*(0.08);
		long long int x1 = i*(0.1);
		if(x == a && x1 == b)
		{
			
			cout << i  << endl;
			return 0;
		}
	}
	cout << -1;
	
	return 0;
}

Measured memory_bytes: 256
from collections import deque
h,w = map(int,input().split())
maze = [list(input()) for i in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if maze[i][j] == ".":
      visited = [[0 for k in range(w)] for l in range(h)]
      visited[i][j] = 1
      que = deque([])
      que.append((i,j,0))
      while que:
        (x,y,cnt) = que.popleft()
        for (nx,ny) in (x+1,y),(x-1,y),(x,y+1),(x,y-1):
          if 0<=nx<h and 0<=ny<w:
            if maze[nx][ny] == "." and visited[nx][ny] == 0:
              que.append((nx,ny,cnt+1))
              visited[nx][ny] = 1
      ans = max(ans,cnt)
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, m;
    cin >> n >> m;
    int sum = 0;
    if(n>1){
        sum += n*(n-1)/2;
    }
    if(m>1){
        sum += m*(m-1)/2;
    }
    cout << sum << endl;
    return 0;
}






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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#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++)


int main() {
    int a[5];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout << a[2]-a[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define E 1e-10
using namespace std;

int main()
{
    double a[3], b[3], d;

    cin >> a[0] >> a[1] >> a[2];
    cin >> b[0] >> b[1] >> b[2];

    d = sqrt( pow( a[0] - b[0], 2 ) + pow( a[1] - b[1], 2 ) );

    if( d > a[2] + b[2] )
        cout << 4 << endl;
    else if( fabs( d - a[2] - b[2] ) < E )
        cout << 3 << endl;
    else if( fabs( d + a[2] - b[2] ) < E || fabs( d + b[2] - a[2] ) < E )
        cout << 1 << endl;
    else if( d + a[2] < b[2] || d + b[2] < a[2] )
        cout << 0 << endl;
    else
        cout << 2 << endl;

    return 0;
}


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

using namespace std;

int main (void)
{
    long n, m;
    long cnt = 0L;

    cin >> n >> m;
    cnt = min(n, m / 2);
    m = m - cnt * 2;

    if (m >= 4) {
        cnt += m / 4;
    }
    
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int Prime(int n){
    int i;
    for(i=2;i<=(int)sqrt(n);i++){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}
int main(){
    int n,m,count,k;
    count = 0;
    cin >> n;
    for(k=0;k<n;k++){
        cin >> m;
        count += Prime(m);
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3108
using System;
using System.Collections.Generic;
using System.Linq;

namespace A
{

    class Program
    {
        public static void Main(string[] args)
        {
            var n = ReadLineInt();
            Console.WriteLine((n*2)*Math.PI);
            ReadLine();
        }

        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}

Measured memory_bytes: 27620
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = a;
        int ans = 0;
        while (a > 0) {
            ans += a%10;
            a /= 10;
        }
        System.out.println(b%ans==0?"Yes":"No");
    }
}

Measured memory_bytes: 21972
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] B = new int[n];

            int k = A.Max();

            CountingSort(A, B, k);

            Console.WriteLine(string.Join(" ", Array.ConvertAll(B, b => b.ToString())));
        }

        static void CountingSort(int[] a,int[] b,int k)
        {
            int[] c = new int[k + 1];
            int i, n = a.Length;

            for (i = 0; i < n; i++)
                c[a[i]]++;

            for (i = 1; i <= k; i++)
                c[i] += c[i - 1];

            for (i = n - 1; i >= 0; i--)
            {
                b[c[a[i]] - 1] = a[i];
                c[a[i]]--;
            }
        }
    }
}

Measured memory_bytes: 265600
N,M,*f = open(0).read().split()
N = int(N)
M = int(M)
A = f[:N]
B = f[N:]
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j:j+M] == B[0]:
            for k in range(1,M):
                if A[i+k][j:j+M] != B[k]:
                    break
            else:
                print('Yes')
                break
    else:
        continue
    break
else:
    print('No')

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
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);
        DPowerfulDiscountTickets solver = new DPowerfulDiscountTickets();
        solver.solve(1, in, out);
        out.close();
    }

    static class DPowerfulDiscountTickets {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
            int n = in.nextInt();
            int m = in.nextInt();
            int a[] = new int[n];
            long sum = 0;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                sum += a[i];
            }
            for (int i = 0; i < n; i++) {
                while (a[i] > 0) {
                    pq.add(a[i] - a[i] / 2);
                    a[i] /= 2;
                }
            }
            long temp = 0;
            for (int i = 0; i < m && pq.size() > 0; i++) temp += pq.poll();
            out.println(sum - temp);
        }

    }

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

    }
}



Measured memory_bytes: 129040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll x(n), y(n), h(n);
    ll c = 0;
    rep(i, n){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i]) c++;
    }
    vvvll ans(101, vvll(101, vll(c)));
    vvvll ans2(101, vvll(101, vll(n-c)));
    ll p = 0;
    ll p2 = 0;
    rep(i, n){
        if(h[i]){
            rep(j, 101)rep(k, 101){
                ans[j][k][p] = abs(j-x[i])+abs(k-y[i])+h[i];
            }
            p++;
        }else{
            rep(j, 101)rep(k, 101){
                ans2[j][k][p2] = abs(j-x[i])+abs(k-y[i]);
            }
            p2++;
        }
    }
    if(n-c > 0){
        rep(i, 101)rep(j, 101){
            sort(ALL(ans[i][j]));
            sort(ALL(ans2[i][j]));
            if(ans[i][j][0] == ans[i][j][c-1] && ans2[i][j][0] >= ans[i][j][0]){
                cout << i << " " << j << " " << ans[i][j][0] << endl;
                return 0;
            }
        }
    }else{
        rep(i, 101)rep(j, 101){
            sort(ALL(ans[i][j]));
            if(ans[i][j][0] == ans[i][j][c-1]){
                cout << i << " " << j << " " << ans[i][j][0] << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
        int n;
        scanf("%d", &n);
        vector<long long> a(n + 10);
        for (int i = 1; i <= n; i++) {
                scanf("%lld", &a[i]);
        }
        vector<vector<long long>> dp(n + 10, vector<long long>(2, 0LL));
        dp[1][0] = a[1];
        dp[2][1] = -a[1] - a[2];
        dp[2][0] = a[1] + a[2];
        for (int i = 3; i <= n; i++) {
                dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + a[i];
                long long fi = (i == 3 ? dp[i - 2][0] - a[i - 1] - a[i] : max(dp[i - 2][0], dp[i - 2][1]) - a[i - 1] - a[i]);
                dp[i][1] = max(fi, dp[i - 1][1] + 2LL * a[i - 1] - a[i]);
//                printf("%d %lld %lld\n", i, dp[i][0], dp[i][1]);
        }
        printf("%lld\n", max(dp[n][0], dp[n][1]));
        return 0;
}

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

typedef long long lint;
typedef pair<int, int> pii;

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int n, ans;
char S[5010];

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

	cin>>n>>(S+1);
	for(int a=1; a<=n; a++){
		for(int i=1, d=0; i+a<=n; i++){
			// S[i:i+x], S[i+a:i+a+x]
			while(i+d<i+a && i+a+d<=n && S[i+d]==S[i+a+d]) d++;
			ans = (ans<d ? d : ans);
			d = (d>0 ? d-1 : 0);
		}
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, c;
	ll d;
	edge(int _from = 0, int _to = 0, ll _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
void dfs(vector< vector< int > > &G, vector< bool > &done, int v) {
	done[v] = true;
	rep(i, G[v].size()) {
		int next = G[v][i];
		if (done[next])
			continue;
		dfs(G, done, next);
	}
}
int main() {
	cin >> N >> M;
	edges es(M);
	rep(i, M) {
		cin >> es[i].from >> es[i].to >> es[i].d;
		es[i].from--;
		es[i].to--;
	}
	vector< vector< int > > G1(N), G2(N);
	rep(i, M) {
		edge e = es[i];
		G1[e.from].push_back(e.to);
		G2[e.to].push_back(e.from);
	}
	vector< bool > done1(N, false), done2(N, false), done(N, false);
	dfs(G1, done1, 0);
	dfs(G2, done2, N - 1);
	rep(i, N) done[i] = done1[i] & done2[i];
	vector< ll > d(N, -LINF);
	d[0] = 0;
	bool f = true;
	rep(k, N) {
		rep(i, M) {
			edge e = es[i];
			if (d[e.from] != -LINF && done[e.to] && d[e.from] + e.d > d[e.to]) {
				if (k == N - 1) {
					f = false;
					break;
				}
				d[e.to] = d[e.from] + e.d;
			}
		}
	}
	//cout << d;
	if (!f)
		cout << "inf" << endl;
	else
		cout << d[N - 1] << endl;
	return 0;
}

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

using namespace std ;
const int INF = 1000000 ;
int main(){
	int nax = -INF ;
	int n ;
	scanf("%d", &n) ;
	vector<int>a(n) ;
	int sum = 0 ;
	for(int& i : a){
		scanf("%d", &i) ;
		nax = max(nax, i) ;
		sum += i ;
	}
	sum -= nax ;
	if(sum > nax)
		puts("Yes") ;
	else
		puts("No") ;
		
}




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> ;
const int INF = 1001001001;
int main () {
  int n , m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n , vector<int>(m));
  rep(i, n){
    cin >> c[i];
    rep(j, m){
      cin >> a[i][j];}
  }
  int ans = INF ;
  rep(s, 1<<n){
    int cost = 0;
    vector<int> total (m);
    rep(i,n){
      if(s>>i & 1){
        cost += c[i];
        rep(j,m){
          total[j] += a[i][j];}
      }
    }
    bool ok = true;
    rep(i, m){
      if (total[i] < x){
      ok = false ;}
    }
    if (ok) {
      ans = min(ans, cost);}
  }
  if ( ans == INF ) {
    cout << -1 << endl;}
  else {
  cout << ans << endl;
  }
return 0;
}
        

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

int main()
{
    string s;
    cin >> s;

    long long ans = 0;
    for(long long i = 0, b = 0; i < s.size(); i++)
    {
        if (s[i] == 'B') ++b;
        else ans += b;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640