akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define PB push_back
#define F first
#define S second
#define SZ(a) a.size()
#define MP(a,b) make_pair(a,b)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define NL << "\n"

#define mod 1000000007
#define pi 3.14159265359

  using namespace std;

  typedef long long ll;
  typedef pair<int, int> pii;
  typedef pair<int, string> pis;
  typedef pair<string, int> psi;
  typedef pair<ll, ll> pll;
  typedef pair<ll, string> pls;
  typedef pair<string, ll> psl;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<vi> vvi;
  typedef vector<vll> vvll;
  typedef vector<string> vs;
  typedef vector<pll> vpll;
  typedef double ld;

  string longestRepeatedSubstring(string str){
    int n = str.length();
    int LCSRe[n+1][n+1];

    //setting all to 0
    memset(LCSRe, 0, sizeof(LCSRe));

    string res; //to store result
    int res_length = 0; //to store length of result

    //building table in bottom-up manner
    int i, index = 0;
    for1(i,n){
      for(int j = i+1; j<=n; j++){
        //(j-1) > LCSRe[i-1][j-1] to remove overlapping
        if(str[i-1] == str[j-1] && LCSRe[i-1][j-1] < (j-i)){
          LCSRe[i][j] = LCSRe[i-1][j-1] + 1;

          //updating maximum length of the substring and updating the finishing index of the suffix
          if(LCSRe[i][j] > res_length){
          res_length = LCSRe[i][j];
          index = max(i, index);
        }
      } else {
        LCSRe[i][j] = 0;
      }
    }
  }

  //If we have non-empty result, the insert all characters from first character to last character of string
  if(res_length > 0)
    for(i = index - res_length + 1; i <= index; i++)
      res.push_back(str[i-1]);
  
  return res;

}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
 
  int n; cin >> n;
  string str; cin >> str;
  cout << longestRepeatedSubstring(str).length() NL;  
  
  return 0;
}




Measured memory_bytes: 98048
import math

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a
 
def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)
 

def f(b,n):
	if n < b:
		return n
	return f(b, n//b) + n%b
 
N = int(input())
S = int(input())

if N == S:
	print(N+1)
	exit()

if N < S:
	print(-1)
	exit()

for B in range(2, int(math.sqrt(N))+1):
	if(f(B,N)==S):
		print(B)
		exit()


for p in range(int(math.sqrt(N))+1, 0, -1):
	B = (N-S)/p + 1
	if(B==int(B) and f(int(B),N)==S):
		print(int(B))
		exit()


print(-1)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int i, n = scanner.nextInt();
        int min = scanner.nextInt();
        int max = Integer.MIN_VALUE;
        for(i = 1; i < n; ++i){
            int input = scanner.nextInt();
            max = Math.max(max, input - min);
            min = Math.min(min, input);
        }
        System.out.println(max);
        scanner.close();
    }
}


Measured memory_bytes: 98956
import heapq

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

Q = [[-A[1],-A[0]]]*2
heapq.heapify(Q)

ans = A[0]
for a in A[2:]:
    #print(Q)
    top = heapq.heappop(Q)
    ans += -top[0]

    heapq.heappush(Q, [-a,-top[0]])
    heapq.heappush(Q, [-a,-top[1]])
    #print(ans)
    
print(ans)


Measured memory_bytes: 135584
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[11];
char a[11];
int main()
{
	scanf("%s",s);
	int l=strlen(s);
	int m=-1;
	for(int i=0;i<l;i++){
		if(s[i]!='B'){
			m++;
			a[m]=s[i];
		}
		else if(m>=0)m--;
	}
	for(int i=0;i<=m;i++){
		cout<<a[i];
	}
	cout<<endl;
	return 0; 
}

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

using namespace std;

int main()
{
	long long n, m;
	string s, t;
	cin >> n >> m >> s >> t;
	long long ans = n / __gcd(n, m) * m;
	bool ok = true;
	for (int i = 0; i < __gcd(n, m); i++)
		if (s[ans / m * i] != t[ans / n * i])
			ok = false;
	if (ok)
		cout << ans << endl;
	else
		cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n-1):
    min = i+1
    for j in range(i+1,n):
        if a[min] > a[j]:
            min = j
    if a[i] > a[min]:
        a[i],a[min] = a[min],a[i]
        cnt += 1
for i in range(n):
    if i != n-1:
        print(a[i], end=' ')
    else:
        print(a[i])
print(cnt)


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

#define endl "\n"
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(),(x).end()
#define rect return 0
#define pause cout << endl; system("pause")
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(x) (int)(x).size()
#define Pi acos(-1.0)
#define bitcount __builtin_popcountll

#define TupleGet(name, index) std::get<(index)>(name)
#define FOR(a, b, c) for(int (a) = (b); (a) < (c); ++(a))
#define FORs(a, b, c) for(int (a) = (b); (a) <= (c); ++(a))
#define revFOR(a, b, c) for(int (a) = (b); (a) > (c); --(a))
#define revFORs(a, b, c) for(int (a) = (b); (a) >= (c); --(a))
#define foreach(it, a) for(auto it = (a).begin(); it != (a).end(); it++)

using namespace std;

// *** TYPEDEF'S, CONSTANTS AND FUNCTIONS *** //
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tii;
typedef vector<vector<int> > vvi;

/* |T| |I| |P| |S|
@ string abc = "abcdefghijklmnopqrstuvwxyz";
@ 'char' - 'a' ::: порядковый номер латинской буквы
@ 'digit' - '0' or 'digit' - 48 ::: (char) ---> (int)
@ 'A' = dec 65 'Z' = dec 90
  'a' = dec 97 'z' = dec 122
  '0' = dec 48 '9' = dec 57
@ Если страдает скорость ввода:
1) ios::sync_with_stdio(0);
   cin.tie(0);
2) юзать сканф
@ для стринга перевод i-того символа в другой регистр: a[i] = char (a[i] +- 32)  :::  32 == 'a' - 'A'
@ int n (m знаков) :::  n[1] = n / 10^(m-1) ; n[m] = n % 10 ; n[m-1] = (n % 100)/10 ; n[m-2] = (n % 1000)/100...
@ cout << fixed << setprecision(n) ::: n знаков после запятой, без "fixed" - всего n знаков
@ abs(x-y) < EPS ::: равентсво вещественных чисел x и y по точности EPS
@ x + EPS < y  или  x - EPS < y ::: сравнение больше-меньше для вещественных чисел по точности EPS
@ если цифру можешь записать из головы - так и пиши в программе, иначе - пиши ФОРМУЛУ
@ «экспонента» - целое число, показывающее, на сколько надо сдвинуть десятичную запятую в числе ::: 123e2 = 12300 , 123e-4 = 0.0123
@ если задача плохо решается при нумерации с единицы, иногда оказывается намного проще перейти к нумерации с нуля.
  Особенно задачах, где явно надо делить на равные части.
@ while(cin >>)  |||  while (getline(cin, )) ::: считывание, пока даются данные
@ ctrl+Z ::: конец файла в консоли
@ Глобальные массивы, чтобы не было ошибок; размер брать с запасом
@ Количество цифр N числа X в b-ичной записи, N = floor[ log[b](X) ] + 1
@ ios::sync_with_stdio(0); //ввод
@ cin.tie(0); cout.tie(0); //могут быть проблемы в интерактивных задачах (частый ввод-вывод)
*/

void C() {
    ll n;
    cin >> n;

    if (n == 0) {
        cout << 0;
        return;
    }

    string ans = "";
    while (n != 0) {
        ll mod = n - (n / (-2)) * (-2);
        n /= (-2);

        if (mod < 0) {
            mod += 2;
            n++;
        }

        ans += to_string(mod);
    }
    reverse(all(ans));
    cout << ans;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;

int divi(int n){
    int sum=0;
    while(n){
        sum+=n%10;
        n/=10;
    }
    return sum;
}

int main(){
    int N;
    cin >> N;
    int a,b;
    cin >> a >> b;
    int count=0;
    for(int i=1;i<=N;i++){
        if(divi(i)>=a&&divi(i)<=b) count+=i;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

const double eps=1e-5;
const int N = 200000;

int a[N + 50], n, k;

int Judge(long double x)
{
	long long cnt=0;
	for(int i = 1; i <= n && cnt <= k; i++) cnt += ceil(a[i] / x) - 1;
	return cnt <= k;
}

int main()
{
	scanf("%d%d",&n,&k);
    int maxx=0;
	for(int i=1;i<=n;i++) 
        scanf("%d",&a[i]), maxx = max(maxx, a[i]);

	double l = 0, r = maxx, mid;
	while(r - l > eps)
	{
		mid = (l + r) / 2.0;
		if(Judge(mid)) r = mid;
		else l = mid;
	}
    int ans = ceil((l + r) / 2) + eps;
    for (int i = max(1, ans - 10); i <= ans + 10; i++) if (Judge(i)) { printf("%d", i); return 0; }
}

Measured memory_bytes: 4060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

namespace AtCoder.Question
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var (n, k) = ReadHelper.ReadValue<int, int>();
            var s = ReadHelper.ReadValue<string>();
            Console.WriteLine(new string(s.Select((c, i) => (char)(i == k - 1 ? c + 32 : c)).ToArray()));
        }

        static class ReadHelper
        {
            internal static T ReadValue<T>()
            {
                return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
            }
            internal static (T1, T2) ReadValue<T1, T2>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)));
            }
            internal static (T1, T2, T3) ReadValue<T1, T2, T3>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)));
            }
            internal static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4)));
            }
            internal static T[] ReadValues<T>()
            {
                var input = Console.ReadLine().Split(' ');
                return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
            }
        }

        static class MathAlgorithm
        {
            internal static bool IsPrime(long n)
            {
                if (n == 2) return true;
                if (n < 2 || n % 2 == 0) return false;
                var sqrt = Math.Sqrt(n);
                for (int i = 3; i <= sqrt; i += 2) if (n % i == 0) return false;
                return true;
            }
            internal static IEnumerable<long> EnumeratePrimes(long n)
            {
                var i = 2L;
                while (i * i <= n)
                {
                    if (n % i == 0)
                    {
                        n /= i;
                        yield return i;
                    }
                    else
                    {
                        i += i == 2 ? 1 : 2;
                    }
                }
                if (n != 1) yield return n;
            }
        }
    }
}


Measured memory_bytes: 28032
n = int(input())
h = list(map(int,input().split()))
dp = [0, abs(h[0]-h[1])]
for i in range(n-2):
    dp.append(min(dp[-2] + abs(h[i]-h[i+2]), dp[-1] + abs(h[i+1]-h[i+2])))
print(dp[-1])

Measured memory_bytes: 20624
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = []
P = 0
for i in range(N):
    for j in range(i+1):
        P += A[j]
    for k in range(N-i):
        P += B[i+k]
    X.append(P)
    P=0

print(max(X))

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
void solveA(string s, ll k){
    int n = (int) s.size();
    if(n == 1){
        cout << k / 2 << endl;
        return;
    }
    auto f = [](string s) -> ll{
        show(s);
        ll res = 0;
        int len = (int) s.size();
        for(int i = 0; i < len - 1; i++){
            if(s[i] == s[i+1]){
                s[i+1] = '?';
                res++;
            }
        }
        return res;
    };
    vector<ll> a(10);
    string t;
    rep(i,10){
        t += s;
        a[i] = f(t);
    }
    show(a);
    rep(i,8){
        if(a[i+1] - a[i] != a[i+2] - a[i+1]){
            ll b = a[1] - a[0];
            ll c = a[2] - a[1];
            ll ans = a[0] + (b + c) * ((k-1) / 2);
            show(b,c);
            if(k%2==0)ans += b;
            cout << ans << endl;
            return;
        }
    }
    if(k < 3){
        cout << a[k-1] << endl;
    }else{
        cout << a[1] + (a[2] - a[1]) * (k - 2) << endl;
    }
}
int main(){
    string s;
    ll k;
    cin >> s >> k;
    solveA(s,k);
    {
        string t;
        rep(i,5){
            
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int W, H, N;
vector<string> board;
vector<vector<bool>> visit;

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

bool Search(int x, int y)
{
    if (board[y][x] == '#')
        board[y][x] = '.';

    if (!visit[y][x])
        return false;

    queue<pair<int, int>> que;
    que.push(make_pair(x, y));

    while (!que.empty()) {
        pair<int, int> now = que.front();
        que.pop();

        if (board[now.second][now.first] == 't')
            return true;

        for (int d = 0; d < 4; ++d) {
            int nx = now.first + dx[d];
            int ny = now.second + dy[d];

            if (nx < 0 || nx >= W || ny < 0 || ny >= H)
                continue;
            if (visit[ny][nx])
                continue;

            visit[ny][nx] = true;

            if (board[ny][nx] == '.')
                que.push(make_pair(nx, ny));
            else if (board[ny][nx] == 't')
                return true;
        }
    }

    return false;
}

int main()
{
    cin >> W >> H;
    board.resize(H);
    visit.resize(H, vector<bool>(W, false));

    for (int i = 0; i < H; ++i)
        cin >> board[i];

    cin >> N;
    int x[N + 1], y[N + 1];
    x[0] = y[0] = 0;
    for (int i = 1; i <= N; ++i)
        cin >> x[i] >> y[i];

    bool not_found = true;
    visit[0][0] = true;

    for (int t = 0; t <= N; ++t) {
        if (Search(x[t], y[t])) {
            cout << t << endl;
            not_found = false;
            break;
        }
    }

    if (not_found)
        cout << "-1\n";

    return 0;
}

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

using namespace std;
//#pragma GCC optimize("O3")

typedef long long ll;
typedef long double ld;
const int maxN = 2005;
int f[3][maxN][maxN];
int n, m, q;
char c[maxN][maxN];
int get(int a, int x1, int y1, int x2, int y2) {
    return f[a][x2][y2] - f[a][x1 - 1][y2] - f[a][x2][y1 - 1] + f[a][x1 - 1][y1 - 1];
}
int main() {
   // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> q;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> c[i][j];
            if (c[i][j] == '1') {
                f[0][i][j]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (c[i][j] == '1') {
                if (i + 1 <= n && c[i + 1][j] == '1') {
                    f[1][i][j]++;
                }
                if (j + 1 <= m && c[i][j + 1] == '1') {
                    f[2][i][j]++;
                }
            }
        }
    }
    for (int a = 0; a < 3; a++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                f[a][i][j] = f[a][i - 1][j] + f[a][i][j - 1] + f[a][i][j] - f[a][i - 1][j - 1];
            }
        }
    }
    while (q--) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int vert = get(0, x1, y1, x2, y2);
        int edge = 0;
        if (x2 > x1) edge += get(1, x1, y1, x2 - 1, y2);
        if (y2 > y1) edge += get(2, x1, y1, x2, y2 - 1);
        vert -= edge;
        cout << vert << '\n';
    }
    return 0;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    vector<int> v(n);
    map<int,int> v1,v2;
    rep(i,n){
        cin >> v[i];
        if(i%2==0)v1[v[i]]++;
        else v2[v[i]]++;
    }
    vector<pair<int,int> > p1;
    vector<pair<int,int> > p2;
    for(auto a1:v1){
        p1.push_back(make_pair(a1.second,a1.first));
    }
    for(auto a2:v2){
        p2.push_back(make_pair(a2.second,a2.first));
    }
    sort(all(p1));
    reverse(all(p1));
    sort(all(p2));
    reverse(all(p2));
    ll res = 0;
    if(p1[0].second != p2[0].second)res = (n/2-p1[0].first)+(n/2-p2[0].first);
    else{
        res = min((n/2-p1[1].first)+(n/2-p2[0].first),(n/2-p1[0].first)+(n/2-p2[1].first));
    }
    cout << res << endl;
}


Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(int argc, char **argv)
{
	ll n; cin >> n;
	vector<ll> a(n, 0);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	
	for (int i = 0; i < n; ++i)
		a[i] = a[i] - (i+1);

	sort(a.begin(), a.end());
	ll median = a[n/2];

	ll ans = 0;
	for (int i = 0; i < n; ++i)
		ans += abs(median - a[i]);

	std::cout << ans << std::endl;
}


Measured memory_bytes: 1792
class Unionfind():  # Unionfind
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):  # グループの根
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # グループの併合
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def groups(self):  # 全てのグループごとの要素
        members_dict = {}
        for i in range(self.N):
            if self.find(i) not in members_dict:
                members_dict[self.find(i)] = set()
            members_dict[self.find(i)].add(i)
        return members_dict


n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]

uf = Unionfind(n)
for x, y in xy:
    uf.union(x - 1, y - 1)

ans = 0
for lst in uf.groups().values():
    ans += sum((p[num] - 1 in lst) for num in lst)
print(ans)


Measured memory_bytes: 128468
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int a[300000];
ll smax[100001];
ll smin[100001];

int main()
{
	int N;
	ll sum = 0, ans = -(ll)1e15;
	priority_queue<int, vector<int>, greater<int> > pqM;
	priority_queue<int> pqm;

	cin >> N;
	rep(i, 3 * N) cin >> a[i];

	rep(i, 2 * N) {
		if (i < N) {
			sum += a[i];
			pqM.push(a[i]);
			if (i == N - 1) smax[i - (N - 1)] = sum;
		}
		else {
			if (pqM.top() < a[i]) {
				sum -= pqM.top();
				sum += a[i];
				pqM.pop();
				pqM.push(a[i]);
			}
			smax[i - (N - 1)] = sum;
		}
	}

	sum = 0;
	rrepc(i, 3 * N - 1, N) {
		if (i >= 2 * N) {
			sum += a[i];
			pqm.push(a[i]);
			if (i == 2 * N) smin[i - N] = sum;
		}
		else {
			if (pqm.top() > a[i]) {
				sum -= pqm.top();
				sum += a[i];
				pqm.pop();
				pqm.push(a[i]);
			}
			smin[i - N] = sum;
		}
	}

	repc(i, 0, N) {
		ans = max(ans, smax[i] - smin[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3832
s = input()
if s[1] =='R':
    if s[0] =='R' and s[2] =='R':
        print(3)
    elif s[0]=='R' or s[2] == 'R':
        print(2)
    else:
        print(1)
else:
    if s[0] != 'R' and s[2]!= 'R':
        print(0)
    else:
        print(1)

Measured memory_bytes: 9048
package main

import "fmt"

func main() {
	var K, S, r int
	fmt.Scan(&K, &S)
	for x := 0; x <= K; x++ {
		for y := 0; y <= K; y++ {
			z := S - x - y
			if 0 <= z && z <= K {
				r++
			}
		}
	}
	fmt.Println(r)
}

Measured memory_bytes: 512
# coding: utf-8

a, b, c = map(int, input().split())

x=a-b
y=b-c
z=c-a

if (x==0 and y !=0 and z !=0) or (x!=0 and y ==0 and z !=0) or (x !=0 and y !=0 and z ==0):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
from bisect import bisect_right
s = tuple(map(lambda c: ord(c) - ord("a"), input()))
t = tuple(map(lambda c: ord(c) - ord("a"), input()))
S, T = set(s), set(t)
if T & S != T:
    print(-1)
    quit()
d, l = [[] for _ in range(26)], [0] * 26
for idx, c in enumerate(s):
    d[c].append(idx)
    l[c] += 1
prev = -1
loop = 0
for c in t:
    idx = bisect_right(d[c], prev)
    if idx >= l[c]:
        loop += 1
        prev = d[c][0]
    else:
        prev = d[c][idx]
print((loop) * len(s) + prev + 1)

Measured memory_bytes: 8912
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		string s;
		cin >> s;
		string ns;
		int n = sz(s);
		rep(i,0,n/2) ns.pb(s[i]);
		string ns2;
		rep(i,n/2+1,n) ns2.pb(s[i]);
		if(ns!=ns2){
			cout<<"No";
			r0;
		}
		rep(i,0,sz(ns)){
			if(ns[i]!=ns[sz(ns)-i-1]){
				cout<<"No";
				r0;
			}
		}
		cout<<"Yes";
	}
}

Measured memory_bytes: 256
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
bc=sorted([list(map(int,input().split())) for i in range(m)], key=lambda x:x[1], reverse=True)

# print(bc)
# print(a)
tmp=[]
count=0
for i in range(m):
    for j in range(bc[i][0]):
        if count==n:
            break
        tmp.append(bc[i][1])
        count+=1


change=tmp[:n]
# print(tmp)
# print(change)

for i in range(len(change)):
    if change[i]>a[i]:
        a[i]=change[i]
    else:
        break
print(sum(a))

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int n;
   cin >> n;
   vec<int> v(n);
   rep (i, n) {
      cin >> v[i];
   }
   sort(all(v), greater<int>());

   int a = 0, b = 0;
   rep (i, n) {
      if (i%2==0) {
         a+=v[i];
      } else {
         b+=v[i];
      }
   }

   cout << a - b << endl;

   return 0;
}

Measured memory_bytes: 256
n=int(input())
zl,wl=[],[]
for i in range(n):
    x,y=map(int,input().split())
    z=x+y
    w=x-y
    zl.append(z)
    wl.append(w)
zl.sort()
wl.sort()
print(max(zl[-1]-zl[0],wl[-1]-wl[0]))

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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int n, m;
bool red[100001];
int cont[100001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  //stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  //if (stream2 == NULL) return 0;:w
#endif
  cin >> n >> m;
  red[0] = 1;
  for (int i = 0; i < n; i++) {
    cont[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    cont[x]--;
    if (cont[x] == 0) {
      if (red[x] == 1) {
        red[x] = 0;
        red[y] = 1;
        cont[y]++;
      } else {
        cont[y]++;
      }
    } else if (cont[x] > 0) {
      if (red[x] == 1) {
        red[y] = 1;
        cont[y]++;
      } else {
        cont[y]++;
      }
    } else {
      assert(1);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (red[i]) ans++;
  }
  cout << ans << endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT


signed main() {
  ull x;
  cin >> x;

  ull ok = 10000, ng = 0;
  while (ng+1 < ok) {
    ull m = (ok+ng)/2;
    ull t = 100;
    rep(i, m) {
      t *= 1.01;
      if (t >= x)
        break;
    }
    if (t >= x)
      ok = m;
    else
      ng = m;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i,s,t ) for(int i = s; i< t ; i++)
using VL = vector<LL>;
#define SZ(a) (int)a.size()

void fall(vector<string>& vs) { // swapして落ちるときもあるわね
	int H = SZ(vs); int W = SZ(vs[0]);
	FOR(j, 0, W) {
		for (int i = H - 1; i >= 0; i--){
			if (vs[i][j] == '.') {
				for (int k = i - 1; k >= 0; k--){
					if (vs[k][j] != '.') {
						swap(vs[k][j], vs[i][j]);
						break;
					}
				}
			}
		}
	}
}

// うんちなので消す
int unchi(vector<string>& vs, int N) {
	int H = SZ(vs); int W = SZ(vs[0]);
	vector<vector<int>>check(H, vector<int>(W, 0));
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			if (vs[i][j] == '.')continue;
			{// 右
				int cnt = 1;
				FOR(k, j + 1, W) {
					if (vs[i][k] == vs[i][j])cnt++;
					else break;
				}
				if (cnt >= N) {
					FOR(k, j, W) {
						if (vs[i][k] == vs[i][j])check[i][k] = 1;
						else break;
					}
				}
			}
			{// 下
				int cnt = 1;
				FOR(k, i + 1, H) {
					if (vs[k][j] == vs[i][j])cnt++;
					else break;
				}
				if (cnt >= N) {
					FOR(k, i, H) {
						if (vs[k][j] == vs[i][j])check[k][j] = 1;
						else break;
					}
				}
			}
		}
	}

	// check を消す
	int UNCHI = 0;
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			if (check[i][j])vs[i][j] = '.', UNCHI = 1;
		}
	}
	return UNCHI;
}

// 全部消えるか
int simi(vector<string> vs, int N) {
	int H = SZ(vs); int W = SZ(vs[0]);

	int update = 1;
	while (update) {
		update = 0;
		fall(vs);
		update |= unchi(vs, N);
		fall(vs);
	}

	FOR(i, 0, H) {
		FOR(j, 0, W) {
			if (vs[i][j] != '.')return 0;
		}
	}
	return 1;
}

// swapを全部シュミレーションする
void solve() {
	int W, H, N;
	cin >> H >> W >> N;
	vector<string>vs(H);
	FOR(i, 0, H) {
		cin >> vs[i];
	}
	int flag = 0;
	FOR(i, 0, H) {
		FOR(j, 0, W - 1) {
			swap(vs[i][j], vs[i][j + 1]);
			flag |= simi(vs, N);
			swap(vs[i][j], vs[i][j + 1]);
		}
	}
	cout << (flag ? "YES" : "NO") << endl;
}


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	solve();
	return 0;
}


Measured memory_bytes: 3220
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
int p,q,r;
signed main(){
  cin >> p >> q >> r;
  cout << min({p+q,p+r,q+r}) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int N, i, max = 0, others = 0;
  int line[11];
  scanf("%d", &N);
  for(i = 0; i < N; i++) {
    scanf("%d", &line[i]);
    if(max < line[i]) {
      max = line[i];
    }
    others += line[i];
  }
  others -= max;
  if(max < others) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String ans[]=new String[n];
		for(int i=0;i<n;i++){
		String s=sc.next();
		String ss[]=s.split(":");
		int h=Integer.parseInt(ss[0]);
	    int m=Integer.parseInt(ss[1]);
	    int k=Math.abs(60*h+m-12*m);
	    
	    if(k<60 || k>660 ){ans[i]="alert";}
	    else if(k>=180 && k<=540){ans[i]="safe";}
	    else {ans[i]="warning";}     
		
		}
		for(int i=0;i<n;i++){
			System.out.println(ans[i]);
		}
		}
		}

Measured memory_bytes: 21288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int h, w;
    cin >> h >> w;
    char a[h][w];
    rep(i, 0, h) {
        rep(j, 0, w) cin >> a[i][j];
    }

    queue<pair<int, int>> que;
    int dist[h][w];
    rep(i, 0, h) {
        rep(j, 0, w) dist[i][j] = -1;
    }

    rep(i, 0, h) {
        rep(j, 0, w) {
            if (a[i][j] == '#') {
                que.push({i, j});
                dist[i][j] = 0;
            }
        }
    }

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

    int ans = 0;
    while(!que.empty()) {
        int y = que.front().first;
        int x = que.front().second;
        que.pop();
        rep(i, 0, 4) {
            int y2 = y + dy[i];
            int x2 = x + dx[i];
            if (0 <= y2 && y2 < h && 0 <= x2 && x2 < w) {
                if (a[y2][x2] == '.' && dist[y2][x2] == -1) {
                    que.push({y2, x2});
                    dist[y2][x2] = dist[y][x] + 1;
                    ans = max(ans, dist[y2][x2]);
                }
            }
        }
    }

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


Measured memory_bytes: 13328
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define ss second
#define ff first 
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
const ll M=1000000007;
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0)return (power((x*x)%M,n/2))%M;else return ((x%M)*power(x,n-1)%M);}
ll ncr(int n,int r){if(r>n)return 0;if(r > n - r) r = n - r;ll ans = 1;
int i;for(i = 1; i <= r; i++){ans *= n - r + i;ans /= i;}return ans;}
ll nCrModpDP(ll n, ll r, ll p){ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1;
    for (ll i = 1; i <= n; i++){ 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll ncrmod(ll n, ll r, ll p){ 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
   return (ncrmod(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p;  
} 
ll modInverse(ll a,ll m) 
{ 
   ll m0 = m; 
   ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
       ll q = a / m; 
       ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string str;
cin>>str;
stack<char>sec;
sec.push(str[0]);
for(int i=1; i<str.length(); i++){
if(sec.empty()){
sec.push(str[i]);
}
else if(str[i]=='1'){
if(!sec.empty()){
if(sec.top()=='0')
sec.pop();
else
sec.push(str[i]);
}else{
sec.push(str[i]);
}
}
else if(str[i]=='0'){
if(!sec.empty()){
if(sec.top()=='1')
sec.pop();
else
sec.push(str[i]);
}else{
sec.push(str[i]);
}
}
}
int n=str.length();
// cout<<sec.size()<<"\n";
cout<<n-(sec.size());
return 0;
}

Measured memory_bytes: 3816
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_155
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long[] nk = ReadLongs();
            int n = (int)nk[0];
            long k = nk[1];
            long[] array = ReadLongs();
            Array.Sort(array);

            long bottom = long.MinValue / 8;
            long top = long.MaxValue / 8;
            while (bottom + 1 < top)
            {
                long mid = (bottom + top) / 2;
                long cnt = 0;
                for (int i = 1; i < n; i++)
                {
                    int ok = array[i] < 0 ? i - 1 : 0;
                    int ng = array[i] < 0 ? -1 : i;
                    if (array[i] * array[ok] > mid)
                    {
                        continue;
                    }
                    while (Abs(ok - ng) > 1)
                    {
                        int mid2 = (ok + ng) / 2;
                        if (array[i] * array[mid2] <= mid)
                        {
                            ok = mid2;
                        }
                        else
                        {
                            ng = mid2;
                        }
                    }
                    cnt += array[i] < 0 ? i - ok : ok + 1;
                }
                if (cnt < k)
                {
                    bottom = mid;
                }
                else
                {
                    top = mid;
                }
            }
            WriteLine(top);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 36700
#include <iostream>
int main(void){
    int n,x=0,y=0;
    std::cin>>n;
    for(int i=0;i<n;i++){
        int a;
        std::cin>>a;
       x=(x+1)*a;
       if(x>y){
           y=x;
       }
    }
    std::cout<<y+1<<std::endl;
    return 0;
}


Measured memory_bytes: 3132
import java.util.Arrays;
import java.util.Scanner;
class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        
        int[][] A = new int[n][m];
        int[] b = new int[m];
        int[] sum = new int[m];

        scanner.nextLine();
        for(int i=0;i<n;i++){
            String input = scanner.nextLine();
            String inputTmp[] = input.split(" ");
            int j = 0;
            for (String num : inputTmp) {
                A[i][j] = Integer.parseInt(num);
                j++;
            }
        }

        for(int i=0;i<m;i++){
            int num = scanner.nextInt();
            b[i] = num;
        }
        
        for(int[] a: A){
            int val = 0;
            for(int k = 0;k<m;k++){
                val += a[k] * b[k];
            }
            System.out.println(val);
        }
    }
}



Measured memory_bytes: 29832
w,h,n=map(int,input().split())
s=[[0 for i in range(h)] for j in range(w)]
for i in range(n):
	a,b,c=map(int,input().split())
	if c==1:
		for x in range(a):
			for y in range(h):
				s[x][y]=1
	elif c==2:
		for x in range(a,w):
			for y in range(h):
				s[x][y]=1
	elif c==3:
		for x in range(w):
			for y in range(b):
				s[x][y]=1
	else:
		for x in range(w):
			for y in range(b,h):

				s[x][y]=1
cnt=0
for i in range(w):
	for j in range(h):
		if s[i][j]==0:
			cnt+=1
print(cnt)



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

int main(){
  double n,m;
  cin >> n >> m;
  vector<int>a(n);
  double sum=0;
  rep(i,n){
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  if(a.at(m-1) >= sum/4/m){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
const int N = 5000 + 5, M = 50000 + 5, INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    int flag = -1;
    bool ans = false;
    while (n--) {
        int x, y;
        cin >> x >> y;
        if (x == y) {
            if (flag == -1 || flag == (x == y)) {
                flag = (x == y);
                cnt++;
                if (cnt >= 3) {
                    ans = true;
                }
            } else {
                flag = (x == y);
                cnt = 1;
            }
        } else {
            flag = 0;
            cnt = 1;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3064
import scala.io.StdIn

object Main{
  def main(args: Array[String]){
    val in = StdIn.readLine()
    var f = false

    for(i <- 1 to in.toInt){
      var x = i
      if(x % 3 == 0){
        print(" " + i)
      }
      else{
        do{
          if(x % 10 == 3){
            print(" " + i)
            f = true
          }

          x = x / 10
        }while(x != 0 && f == false)
        f = false
      }
    }

    println()
  }
}

Measured memory_bytes: 46988
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rng(i,a,b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define repd(i, n) for(ll i = (ll)(n)-1;i>=0;--i)
#define rngd(i,b,a) for(ll i = (ll)(b);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define ctoi(x) ((x)-'0')
#define sq(x) (x)*(x)
int main() {
  int n,q;
  cin>>n;
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i];
  }
  ll sum=0;
  cin>>q;
  vector<int> m(q);
  rep(i,q){
    cin>>m[i];
  }
  bool e[2000*20+1];
  rep(j,1<<n){
    sum=0;
    rep(k,n){
      if(j&(1<<k)){
        sum+=a[k];
      }
    }
    e[sum]=1;
  }
  rep(i,q){
    if(e[m[i]]){
      cout<<"yes"<<endl;
    }else{
      cout<<"no"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3108
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    vector <long long> a;
    auto f = [](int y) -> long long {
        long long x = y;
        return x * x * x * x * x;
    };
    set <long long> b;
    forn (i, -4000, 4001)
        a.pb(f(i));
    forn (i, 0, sz(a)) {
        long long x = a[i];
        auto j = lower_bound(all(a), n + x);
        if (*j == n + x) {
            cout << j - a.begin() - 4000 << " " << i - 4000 << "\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3784
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a,b,c,d = LI()
    g = fractions.gcd(c,d)
    t = c * d // g
    e = b // c - (a-1) // c
    f = b // d - (a-1) // d
    h = b // t - (a-1) // t

    return (b-a+1) - e - f + h


print(main())



Measured memory_bytes: 5076
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,q;
vector<vector<int>> G;
vector<ll> x,ans;

void dfs(int s,int par){
    //cout << s << " " << par << endl;
    if (par!=-1) ans[s]+=ans[par];
    ans[s]+=x[s];
    rep(i,G[s].size()){
        int t=G[s][i];
        //cout << t << endl;
        if (t==par) continue;
        dfs(t,s);
    }
}

void solve(){
    cin >> n >> q;
    ans.resize(n,0);
    G.resize(n,{});
    x.resize(n,0);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    rep(i,q){
        int p,x_;
        cin >> p >> x_;
        x[p-1]+=x_;
    }
    dfs(0,-1);
    rep(i,n) cout << ans[i] << " ";
}

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

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

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

  sort(a.begin(), a.end());

  int mul=0, now=a[0];
  for(int i=1; i<n; ++i){
    if(now==a[i])++mul;
    else now=a[i];
  }

  cout<<n-(mul+1)/2*2<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
   int n, m;           // input,  1<= n,m <= 100
   int A[100][100];    // input, A matrix
   int B[100];         // input, B vector
   int i, j;           // loop index
   int ans[100]={0};

   scanf("%d %d", &n, &m);
   for(i=0;i<n;i++){
      for(j=0;j<m;j++){
         scanf("%d", &A[i][j]);
      }
   }

   for(j=0;j<m;j++) scanf("%d", &B[j]);

   for(i=0;i<n;i++){
      for(j=0;j<m;j++){
         ans[i]+=A[i][j]*B[j];
      }
      printf("%d\n", ans[i]);
   }

   return 0;
}

Measured memory_bytes: 636
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	double r; cin >> r;
	printf("%.6f", 2 * r*M_PI);
}


Measured memory_bytes: 3784