akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

int main()
{
	fast;
	ll n; cin>>n; ll ans = 0;
	for(ll i = 1; i <= n; i++)
	{
		for(ll j = 1; j <= n; j++)
		{
			for(ll k = 1; k <= n; k++)
			{
				ans += gcd(i,gcd(j,k));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

using pii = pair<int, int>;

double kyori(pii x, pii y) {
  return sqrt(pow(x.first - y.first, 2) + pow(x.second - y.second, 2));
}

inline void Main() {
  // code
  int n;
  pii a[(int)1e5];
  cin>>n;
  rep(i, n) {
    cin>>a[i].first;
    a[i].second = i+1;
  }
  sort(a,a+n);
  rep(i, n) {
    if(i!=0) cout<<' ';
    cout<<a[i].second;
  }
  cout<<endl;
}

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


Measured memory_bytes: 1664
let n = Int(readLine()!)!

let w = readLine()!.split(separator: " ").map { Int($0)! }

var sum = w.reduce(0, +)

var ans = Int.max

var curSum = 0
for i in 0..<w.count {
  ans = min(ans, abs(2 * curSum - sum))
  curSum += w[i]
}
print(ans)

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

int F[102][102];

void
DFS (int Y, int X, int A)
{
  if (F[Y][X] != A)
    return;

  F[Y][X] = 7;

  DFS (Y - 1, X, A);
  DFS (Y, X + 1, A);
  DFS (Y + 1, X, A);
  DFS (Y, X - 1, A);
}

int
main ()
{
  int w, h;
  int xs, ys;
  int xg, yg;
  int n;
  int c, d, x, y;

  while (true)
    {
      cin >> w >> h;
      if (w == 0 && h == 0)
	break;
      cin >> xs >> ys;
      cin >> xg >> yg;
      cin >> n;

      for (int i = 0; i < n; i++)
	{
	  cin >> c >> d >> x >> y;
	  if (d == 0)
	    {
	      for (int a = 0; a < 4; a++)
		{
		  for (int b = 0; b < 2; b++)
		    {
		      F[y + b][x + a] = c;
		    }
		}

	    }
	  else
	    {
	      for (int a = 0; a < 2; a++)
		{
		  for (int b = 0; b < 4; b++)
		    {
		      F[y + b][x + a] = c;
		    }
		}
	    }

	}


      if (F[ys][xs] == 1 || F[ys][xs] == 2 || F[ys][xs] == 3
	  || F[ys][xs] == 4 || F[ys][xs] == 5)
	{
	  DFS (ys, xs, F[ys][xs]);
	}

      if (F[yg][xg] == F[ys][xs])
	{
	  cout << "OK" << endl;
	}
      else
	{
	  cout << "NG" << endl;
	}
   
    /*for (int y = 0; y < h; y++)
	{
	  for (int x = 0; x < w; x++)
	    {
	      cout << F[y][x];
	    }
         cout << endl;
	}*/
   
    for (int y = 1; y <= h; y++)
	{
	  for (int x = 1; x <= w; x++)
	    {
	      F[y][x] = 0;
	    }
	}

    
   
    }

  return 0;
}

Measured memory_bytes: 3048
def f(n, d, s, k):
    if d == 0:
        k -= 1
        if k == 0:
            print(s)
            exit(0)
        return k

    if n - 1 >= 0:
        k = f(n - 1, d - 1, s + (n - 1) * (10 ** (d - 1)), k)

    k = f(n, d - 1, s + (n) * (10 ** (d - 1)), k)

    if n + 1 <= 9:
        k = f(n + 1, d - 1, s + (n + 1) * (10 ** (d - 1)), k)
    return k


k = input()
k = int(k)

l = [1, 2, 3, 4, 5, 6, 7, 8, 9]

if k <= 9:
    print(k)
    exit(0)

k = k - 9

for i in range(1, 100000):
    for j in l:
        k = f(j, i, j * (10 ** i), k)


Measured memory_bytes: 3064
N, T = [int(i) for i in input().split()]

min_cost = 1001

for i in range(N):
    c, t = [int(i) for i in input().split()]
    if t <= T:
        if c <= min_cost:
            min_cost = c
            
if min_cost == 1001:
    print('TLE')
else :
    print(min_cost)

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

using namespace std;

int dp[101][10001];
int main() {
    int N;
    cin >> N;
    vector<int> S;
    for(int i = 0; i < N; i++) {
        int s;
        cin >> s;
        S.push_back(s);
    }
    
    dp[0][0] = 1;
    
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 10001; j++) {
            if (dp[i][j] != 0) {
                dp[i + 1][j + S[i]] |= dp[i][j];
            }
            dp[i + 1][j] |= dp[i][j];
        }
    }
    
    for(int j = 10000; j >= 0; j--) {
        if (dp[N][j] != 0 && (j % 10 != 0)) {
            cout << j << endl;
            break;
        }
        if (j == 0) {
            cout << 0 << endl;
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> s;

  int l_c = 0, r_c = 0;
  int tmp_l = 0, tmp_r = 0;
  REP(i, n) {
    if(s[i] == '(') tmp_l++;
    else if(tmp_l > 0) tmp_l--;
  }

  l_c = tmp_l;
  for(int i = n - 1; i >= 0; i--) {
    if(s[i] == ')') tmp_r++;
    else if(tmp_r > 0) tmp_r--;
  }
  r_c = tmp_r;

  REP(i, tmp_l) {
    s.insert(s.length(), ")");
  }

  REP(i, tmp_r) {
    s.insert(0, "(");
  }

  cout << s << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
const int mo = 1e8;
const int MAXL = 5e5+5;
const int MAXN = 62505;
char buf[MAXL];
int calc(int x)
{
	int ret = 0;
	while (x)
	{
		ret += x % 10;
		x /= 10;
	}
	return ret;
}
struct Big
{
	int d[MAXN], L, sum[MAXN];
	void Read()
	{
		int len = fread(buf, 1, MAXL, stdin);
		while(!isdigit(buf[len-1])) --len;
		int i, E = 1, t = 0;
		for(i=len-1; i>=0; --i)
		{
			t += E * (buf[i] - '0');
			E *= 10;
			if(E >= mo)
			{
				d[L++] = t;
				t = 0;
				E = 1;
			}
		}
		if(t) d[L++] = t;
		if(!L) ++L;
	}
	void operator *= (const int x)
	{
		int t = 0, i;
		for(i=0; i<L; ++i)
			t = d[i]*x+t, d[i] = t%mo, t /= mo;
		if(t) d[L++] = t;
	}
	void Init()
	{
		for(int i=L; i>=0; --i)
			sum[i] = sum[i+1] + calc(d[i]);
	}
	void operator += (const int x)
	{
		int i;
		for(d[i=0]+=x; d[i]>=mo; ++d[++i])
			d[i] -= mo;
		if(i >= L) L = i+1;
		for(; i>=0; --i)
			sum[i] = sum[i+1] + calc(d[i]);
	}
}X;
int main()
{
	X.Read();
	X *= 9;
	X.Init();
	X += 9;
	int C = 9;
	while (C < X.sum[0])
		X += 9, C += 9;
	printf("%d\n", C/9);
}

Measured memory_bytes: 1152
n, k = map(int, input().split())
P = list(map(int, input().split()))

import numpy as np

max_v = np.sum(P[:k])

#print(max_v)
j = 0
cum = 0

temp_max = max_v

for i in range(k, n):
  temp_max += P[i]
  temp_max -= P[i-k]
  if temp_max>max_v:
    max_v = temp_max
    j=i-k
              
ans = (max_v+k)/2
print(ans)
#print(max_v)

Measured memory_bytes: 25060
#include <iostream>
#include <cctype>

using namespace std;

int main()
{
  char ch[1201];
  int i=0;
  
    cin.getline(ch,1201,'\n');
//    cout << ch <<"\n";
    
    for(i=0;ch[i]!='\0';i++)
    {
//        cout << ch[i] <<"\n";
      if(islower(ch[i]))
      {
        cout << static_cast<char>(toupper(ch[i]));
        continue;
      }
      if(isupper(ch[i]))
        cout << static_cast<char>(tolower(ch[i]));
      else 
        cout << ch[i];
    }
   
   cout << "\n";
}

Measured memory_bytes: 1096
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main(){
  int i;
  char s[256];
  char t;
  int r;

  scanf("%s",s);
  r = strlen(s);

  if(r==2){
    printf("%s\n",s);
  }
  if(r==3){
    t = s[0];
    s[0] = s[2];
    s[2] = t;
    printf("%s\n",s);
  }

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
static const int N=100;

int main()
{
  int M[N][N];
  int n,u,k,v;
  int i,j;

  cin>>n;

  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  M[i][j]=0;
	}
    }

  for(i=0;i<n;i++)
    {
      cin>>u>>k;
      u--;
      for(j=0;j<k;j++)
	{
	  cin>>v;
	  v--;
	  M[u][v]=1;
	}
    }

  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  if(j)cout<<" ";
	  cout<<M[i][j];
	}
      cout<<endl;
    }

  return 0;
}




Measured memory_bytes: 3136
n=int(input())
marchlist=[0]*5
for i in range(n):
    tmps=input()
    fs=tmps[0]
    if fs == "M":
        marchlist[0] = marchlist[0] + 1
    elif fs == "A":
        marchlist[1] = marchlist[1] + 1
    elif fs == "R":
        marchlist[2] = marchlist[2] + 1
    elif fs == "C":
        marchlist[3] = marchlist[3] + 1
    elif fs == "H":
        marchlist[4] = marchlist[4] + 1
counter=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            counter += marchlist[i]*marchlist[j]*marchlist[k]
print(counter)

Measured memory_bytes: 9248
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s;
	cin >> s;
	cout << s.substr(0, 5) << " " << s.substr(6, 7) << " " << s.substr(14, 5) << endl;
	return 0;
}



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

int main() {
	int q;
	long long n,i,k,j,sum=0,count=0,ans=0,m,a,b;
	cin>>a>>b>>k;
	m=a;
	a=a-k;
    if(a<0)
    {
        cout<<0<<" ";
        k=k-m;
        b=b-k;
        if(b<=0)
        cout<<0;
        else cout<<b;
        
    }
    else
    {
        cout<<a<<" "<<b;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

char win(char c){
    if(c == 'r'){
        return 'p';
    }
    else if(c == 's'){
        return 'r';
    }
    else {
        return 's';
    }
}

char oth(char c1,char c2)
{
    string list = "rsp";

    REP(i,list.size()){
        if(c1 != list[i] && c2 != list[i]){
            return list[i];
        }
    }
    return 'r';
}

int main(void)
{
    int n, k;
    ll r, s, p;
    string t;
    string w;

    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;

    w = t;

    REP(i,n){
        w[i] = win(t[i]);
    }

    vector<vector<char>> table(k);
    vector<vector<char>> orig(k);
    REP(i, k)
    {
        for (int j = 0; j + i< w.size();j+=k){
            table[i].push_back(w[i + j]);
            orig[i].push_back(w[i + j]);
        }
    }


    REP(i,k){
        for (int j = 0; j < table[i].size()-1;j++)
        {
            if(table[i][j] == table[i][j+1]){
                if(j == table[i].size()-2){
                    table[i][j + 1] = win(table[i][j]);
                }
                else{
                    table[i][j + 1] = oth(table[i][j + 2], table[i][j]);
                }
            }
        }
    }



    ll sum = 0;

    REP(i,table.size())
    {
        REP(j,table[i].size()){
            if(table[i][j] == 'r' && table[i][j] == orig[i][j]){
                sum += r;
            }
            else if(table[i][j] == 's' && table[i][j] == orig[i][j]){
                sum += s;
            }
            else if(table[i][j] == 'p' && table[i][j] == orig[i][j]){
                sum += p;
            }
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 10112
/**
 * AOJ #1159: Next Mayor (ICPC Domestic 2009)
 */

#include <stdio.h>

#define MAX_N 50

/**
 * Return the id of the winner of the game with n people and p pebbles.
 */
int winner(int n, int p)
{
  static int kept[MAX_N];
  int bowl, person, i;

  /* initialize */
  for (i = 0; i < MAX_N; i++) kept[i] = 0;
  bowl = p;
  person = 0; /* the next candidate */

  /* the game */
  for (;;) {
    if (bowl == 0) {
      bowl = kept[person];
      kept[person] = 0;
    } else {
      bowl--;
      kept[person]++;
      if (kept[person] == p) return person; /* winner */
    }
    person = (person + 1) % n;
  }
}

int main()
{
  int n, p;
  for (;;) {
    scanf("%d%d", &n, &p);
    if (n == 0 && p == 0) break;
    printf("%d\n", winner(n, p));
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d; cin >> a >> b >> c >> d;
  if(a+b > c+d) cout << "Left" << endk;
  else if(a+b == c+d) cout << "Balanced" << endk;
  else cout << "Right" << endk;
  return 0;
}


Measured memory_bytes: 3560
using System;

namespace regio
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            string str;
            string[] arr;

            int age, a, b;

            str = Console.ReadLine();

            age = int.Parse(str);

            if (age == 1)
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                str = Console.ReadLine();
                a = int.Parse(str);
                str = Console.ReadLine();
                b = int.Parse(str);

                Console.WriteLine("{0}", a + b);
            }

        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
using namespace std;
int main(void){
	int num=0;
	cin>>num;
	int count=0;
	bool before=false;
	for(int i=1;i<=num;i++){
		int a=0;
		cin>>a;
		if(a==i){
			if(!before){
				count++;
				before=true;
			}else{
				before=false;
			}
		}else{
			before=false;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

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

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // nPk - permutation
    mint p(int n, int k) {
        return fact[n] * ifact[n - k];
    }
};

bool parity(ll num) {
    bool res = false;
    for (ll i = 2; i * i <= num; i++) {
        while (num % i == 0) {
            res ^= true;
            num /= i;
        }
    }
    if (num > 1ll) res ^= true;
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<mint> dp(k + 1);
    for (ll i = 1; i <= k; i++) {
        dp[i] = mint(k / i).pow(n);
    }
    mint ans;
    vector<mint> exact(k + 1, mint(0));
    for (ll i = k; i >= 1; i--) {
        exact[i] = dp[i];
        for (ll multi = i * 2; multi <= k; multi += i) {
            exact[i] -= exact[multi];
        }
        ans += mint(i) * exact[i];
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 4748
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int a[100001],grp[100001];

int main()
{
	int		i,j,n,ans;
	
	scanf("%d", &n);
	for(i=1;i<=n;i++) scanf("%d", &a[i]);

	ans = 1;
	grp[ans] = a[1];
	
	for(i=2;i<=n;i++) {
		if (grp[ans] >= a[i]) {
			grp[++ans] = a[i];
		} else {
			for(j=1;j<=ans;j++) {
				if (grp[j]<a[i]) {
					grp[j] = a[i];
					break;
				}
			}
		}
	}

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


	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
    int N;
    cin >> N;
    vi x(N);
    for(int i = 0; i < N; i++) {
        cin >> x[i];
    }
    int ans = 1e6;
    for(int i = 1; i < 100; i++) {
        int pow = 0;
        for(int j = 0; j < N; j++) {
            pow += (x[j] - i) * (x[j] - i);
        }
        ans = min(ans, pow);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>

using namespace std;

#define MIN first
#define MAX second
constexpr int MAX_S = 252;
constexpr int INF = (1 << 29);

string S;
pair<int, int> mem[MAX_S][MAX_S];

void init(int N)
{
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            mem[i][j] = {+INF, -INF};
        }
    }
}

void update_max(int& l, int r)
{   
    if (l < r) l = r;
}

void update_min(int& l, int r)
{
    if (l > r) l = r;
}

// テ・ツ個コテゥツ鳴禿」ツ?ョpair(MIN, MAX)
pair<int, int> rec(int L, int R)
{
    pair<int, int>& res = mem[L][R];
    if (res != make_pair(+INF, -INF)) {
        return res;
    }
    
    if (R - L == 0) {
        int v = S[L] - '0';
        return (res = make_pair(v, v));
    }

    if (S[L] == '(' && R - L > 2) {
        update_min(res.MIN, rec(L + 1, R).MIN);
        update_max(res.MAX, rec(L + 1, R).MAX);
        return res;
    }

    if (S[R] == ')' && R - L > 2) {
        update_min(res.MIN, rec(L, R - 1).MIN);
        update_max(res.MAX, rec(L, R - 1).MAX);
        return res;
    }
    
    for (int i = L + 1; i <= R - 1; i++) {
        char c = S[i];   
        if (c != '+' && c != '-') continue;                 
        
        auto res_l = rec(L, i - 1); // Left
        auto res_r = rec(i + 1, R); // Right

        if (c == '+') {            
            update_min(res.MIN, res_l.MIN + res_r.MIN);
            update_max(res.MAX, res_l.MAX + res_r.MAX);            
        }
        if (c == '-') {           
            update_min(res.MIN, res_l.MIN - res_r.MAX);
            update_max(res.MAX, res_l.MAX - res_r.MIN);
        }
    } 
    return res;
}

void solve()
{
    int N = S.size();
    init(N);
    cout << rec(0, N - 1).MAX << endl;    
}

int main()
{
    cin >> S;
    solve();    
    return 0;
}

Measured memory_bytes: 3580
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
      	int b = sc.nextInt();
      	int c = sc.nextInt();
      
        int co = 3;
      
      if(a==b){co--;}
      if(a==c){co--;}
      if(b==c){co--;}
      if(a==b&&b==c){co=1;}
      
      System.out.print(co);
      
    }
    }

Measured memory_bytes: 23636
n = int(input())

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

ans = 0

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


Measured memory_bytes: 31472
#include<iostream>
#include<algorithm>
using namespace std;
int N,Q;
int A[1<<17];
main()
{
    cin>>N>>Q;
    for(int i=0;i<N;i++)cin>>A[i];
    sort(A,A+N);
    for(;Q--;)
    {
        int L,R;cin>>L>>R;
        cout<<upper_bound(A,A+N,R)-lower_bound(A,A+N,L)<<endl;
    }
}


Measured memory_bytes: 3560
#include <iostream>
#include <string>
using namespace std;
int main() {
  int A1,A2,A3;
  std::cin >> A1 >> A2 >> A3;
  if (A1+A2+A3 >= 22) {
    std::cout << "bust" << '\n';
  }
  else{
    std::cout << "win" << '\n';
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e18+100;
const int inf = 2e9+100;
const int nmax = 2e5+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;


int sub[nmax];

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

    int n,m;
    cin>>n>>m;
    for(int i=1; i<=m; i++){
        int x;
        cin>>x;
        n-=x;
    }
    if(n<0) cout<<"-1"<<endl;
    else cout<<n<<endl;

}


Measured memory_bytes: 3652
// ＡＢＣの過去問を解くだけだよ
// フォント x:小文字 X:大文字

/*
問題文
3行3列の正方形状のマス目があり、各マスには英小文字が書かれています。
上からi行目、左からj列目のマスに書かれた文字は、c_i,jです。

マス目の左上と右下を結ぶような対角線上のマス目に書かれた文字を、左上から順に読んでできる3文字の文字列を出力してください。
 */

#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector<vector<char>> c(3, vector<char>(3));

    for (int i = 0; i < 3; ++i)
    {
        string S;
        cin >> S;
        for (int j = 0; j < 3; ++j)
        {
            c[i][j] = S[j];
        }
    }

    for (int i = 0; i < 3; ++i)
    {
        cout << c[i][i];
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    cin >> N;

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    LL ans = 0;
    int next = 1;
    rep(i, N) {
        if (A[i]==next) {
            ++next;
        } else {
            ++ans;
        }
    }

    if (next == 1) {
        ans = -1;
    }

    cout << ans << endl;

    return 0;
}


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

void solve(string &S, int k, char c){
	if(k == S.size()){
		cout << S << endl;
		return;
	}
	for(char x = 'a'; x <= c + 1; x++){
		S[k] = x;
		solve(S, k + 1, max(c, x));
	}
}

int main(){
	int N;
	scanf("%d", &N);
	string S(N, '$');
	solve(S, 0, 'a' - 1);
	return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
int main(void){
	
	int a, b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}
	if(a>b){
		printf("a > b\n");
	}
	if(a==b){
		printf("a == b\n");
	}
	
	return 0;
	
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
   int a,b;
   int i;
   cin >> a >> b;
   cout << b*(int)pow((b-1),a-1) << endl;
   return 0;
  }

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

	#pragma GCC target ("avx2")
	#pragma GCC optimization ("O3")
	#pragma GCC optimization ("unroll-loops")

	#define boost ios::sync_with_stdio(0); cin.tie(0);
	#define int long long

	const int N = 1e5 + 10;
	const int MOD = 1e9 + 7;

	int32_t main(){
	    boost;
	    
	    //code
	    int n;
	    cin >> n;
	    
	    int a = n/100;
	    int b = n%100;

	    if(a > 0 and a <= 12 and b > 0 and  b <= 12){
	    	cout << "AMBIGUOUS";
	    }
	    else if(a > 0 and a <= 12){
	    	cout << "MMYY";
	    }
	    else if(b > 0 and b <= 12){
	    	cout << "YYMM";
	    }
	    else{
	    	cout << "NA";
	    }
	    return 0;
	}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
ll n, k;
vector<vector<ll>> matpow(vector<vector<ll>> a, vector<vector<ll>> b) {
	vector<vector<ll>> ret(n, vector<ll>(n, 0));
	REP(i, n) REP(j, n) {
		REP(k, n) ret[i][j] += (a[i][k] * b[k][j]) % MOD;
		ret[i][j] %= MOD;
	}
	return ret;
}

vector<vector<ll>> _pow(vector<vector<ll>> a, ll kkk) {
	vector<vector<ll>> ret(n, vector<ll>(n, 0));
	REP(i, n) ret[i][i] = 1;
	if(kkk == 0) return ret;
	if(kkk % 2) ret = matpow(ret, a);
	return matpow(ret, _pow(matpow(a, a), kkk / 2));
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	vector<vector<ll>> a(n, vector<ll>(n));
	REP(i, n) REP(j, n) cin >> a[i][j];
	vector<vector<ll>> ans = _pow(a, k);
	ll ansans = 0;
	REP(i, n) REP(j, n) ansans += ans[i][j];
	cout << (ansans % MOD + MOD) % MOD << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 5504
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
ll n,ans=0;
vector<ll> a;
int main(){ //srand((unsigned)time(NULL));
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool flag=1;
  while(flag){
    flag = 0;
    for (int i = n-1; i >= 1; i--) {
      if(a[i] < a[i-1]){
        swap(a[i],a[i-1]);
        flag = 1;
        ans++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << (i==n-1 ? "":" ");
  }cout << endl;
  cout << ans << endl;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define mp unordered_map
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    ll n,m,i,j;
    cin>>n>>m;

    vector<ll>adj[n];

    unordered_map<ll, vector<ll> >mp;

    for(i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    bool vis[n];
    memset(vis,false,sizeof(vis));
    ll x=1;

    for(i=0;i<n;i++)
    {
        if(!vis[i])
        {
            queue<ll>q;
            q.push(i);
            vis[i]=true;
            mp[x].pb(i);

            while(!q.empty())
            {
                ll p = q.front();
                q.pop();
                for(j=0;j<adj[p].size();j++)
                {
                    if(!vis[adj[p][j]])
                    {
                        q.push(adj[p][j]);
                        vis[adj[p][j]]=true;
                        mp[x].pb(adj[p][j]);
                    }
                }
            }
            x++;
        }
    }

    ll ans = -1;

    for(auto it:mp)
    {
        vector<ll>v = it.se;
//        for(i=0;i<v.size();i++)
//        {
//            cout<<v[i]<<" ";
//        }
        n = v.size();
        ans = max(ans,n);
    }
    cout<<ans<<endl;
}


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

using ll = long long;
const int MAX = 1e5;

// 隣接リストを用いた深さ優先探索（再帰ver.） O(|V|+|E|)
vector<int> color(MAX, 0);

void dfs(const vector<vector<int>> &G, vector<ll> &num, int u, int now) {
  color[u] = 1; // GRAY
  for (int i = 0; i < G[u].size(); i++) {
    if (color[G[u][i]] == 0) dfs(G, num, G[u][i], now);
  }
  color[u] = 2; // BLACK
  num[u] = now;
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n, m; // n:頂点数 m:辺数
  cin >> n >> m;
  
  if (n == m + 1) {
    cout << "0\n";
    return 0;
  }
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  vector<vector<int>> G(n); // G:頂点数nのグラフの隣接リスト
  
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    //u--;
    //v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではコメントアウト
  }
  
  vector<ll> num(n, -1);
  int now = 0;
  for (int i = 0; i < n; i++) {
    if (color[i] == 0) {
      dfs(G, num, i, now);
      now++;
    }
  }
  
  vector<vector<ll>> x(now);
  for (int i = 0; i < n; i++) {
    x[num[i]].emplace_back(a.at(i));
  }
  
  now--;
  now *= 2;
  if (now > n) {
    cout << "Impossible\n";
    return 0;
  }
  
  ll ans = 0;
  priority_queue<ll, vector<ll>, greater<ll>> pq;
  for (int i = 0; i < x.size(); i++) {
    sort(x[i].begin(), x[i].end());
    for (int j = 0; j < x[i].size(); j++) {
      if (j == 0) {
        ans += x[i].at(j);
        now--;
      }
      else pq.push(x[i].at(j));
    }
  }
  
  while (now > 0) {
    ans += pq.top();
    pq.pop();
    now--;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 10368
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;


#[fastout]
fn main() {
    input! {
    n: usize,
    m: usize,
    mut a: [usize; n]
    }
    let a2 = a.iter().map(|x| x / 2).collect::<Vec<_>>();
    let mut l = a2[0];
    for i in 0..n - 1 {
        if div_two(a2[i]) != div_two(a2[i + 1]) {
            print!("0");
            return;
        }
        l = l / gcd(&l, &a2[i + 1]) * a2[i + 1];
    }
    let ans: usize = (m / l + 1) / 2;
    println!("{}", ans);
}

// O(log(N))
fn gcd(a: &usize, b: &usize) -> usize {
    let (mut x, mut y) = if a < b { (*b, *a) } else { (*a, *b) };
    let mut r = x % y;
    while r != 0 {
        x = y;
        y = r;
        r = x % y;
    }
    y
}

fn div_two(n: usize) -> usize {
    let mut n = n;
    let mut res = 0;
    while n % 2 == 0 {
        n /= 2;
        res += 1;
    }
    res
}


Measured memory_bytes: 4484
// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;

int main() {

	fast
	string s;
	cin>>s;
	if(s=="ABC")
		cout<<"ARC\n";
	else
		cout<<"ABC\n";
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FI          freopen("input.txt", "r", stdin)
#define FO          freopen("output.txt", "w", stdout)
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef unsigned long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 2e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {0, -1}, dy[] = {-1, 0};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
class UnionFind{
    private:
        vi p,rank,size;
        int numSets,maxSubSet;
    public:
        UnionFind(int N){
            //index 0
            size.assign(N,1);//tamaño del conjunto
            numSets = N;
            maxSubSet = 1;
            rank.assign(N,0);
            p.assign(N,0);
            for(int i = 0; i < N; i++)
                p[i] = i;
        }
    int findSet(int i){
        return (p[i] == i) ? i : p[i] = findSet(p[i]);
    }
    bool isSameSet(int i,int j){return findSet(i) == findSet(j);}
    void unionSet(int i,int j){
        int x = findSet(i);
        int y = findSet(j);
        if(x != y){
            numSets--;
            if(rank[x] > rank[y]){
                p[y] = x;
                size[x] += size[y];
                maxSubSet = max(size[x],maxSubSet);
            }else{
                p[x] = y;
                size[y] += size[x];
                if(rank[x] == rank[y])
                    rank[y]++;
                maxSubSet = max(size[y],maxSubSet);
            }
        }
    }
    int numDisjointSets(){
        return numSets;
    }
    int sizeOfSet(int i){
        return size[findSet(i)];
    }
    int getmaxSubSet(){
        return maxSubSet;
    }
};
void solve(){
    int n, m;
    cin >> n >> m;
    UnionFind UF(n);
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        UF.unionSet(u, v);
    }
    cout << UF.getmaxSubSet() << '\n';
}
int main(){
    FIN;
    int t = 1;
    for(int i = 1; i <= t; i++){
        solve();
    }
    //EjecuteTime;
    return 0;
}       

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

using namespace std;

int main(){
	int k;
	cin>>k;
	bool flag=false;
	int ans=0;
	int tot=0;
	for(int i=1;i<1e6;i++){
		tot=(tot*10+7)%k;
		if(tot==0){
			flag=true;
			ans=i;
			break;
		}
	}
	if(flag){
		cout<<ans<<endl;
	}else{
		cout<<-1<<endl;
	}
}

Measured memory_bytes: 3624
import math

def binary_search(A, key):
    left = 0
    right = len(A)
    while left < right:
        mid = math.floor((left + right) / 2)
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return -1

n = int(input())
S = [int(x) for i, x in enumerate(input().split()) if i < n]
q = int(input())
T = [int(x) for i, x in enumerate(input().split()) if i < q]
count = 0
for key in T:
    if binary_search(S, key) > -1:
        count += 1
print(count)

Measured memory_bytes: 19204
#include <iostream>
#include <cmath>

using namespace std;

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

    int d = 0;
    int a = n;
    while(a != 0){
        d++;
        a /= 10;
    }


    int ans = 0;
    for(int i = 0; i < d; i++){
        if(i % 2 == 0 && i != d - 1){
            ans += pow(10, i + 1) - pow(10, i);
        }else if(i % 2 == 0 && i == d - 1){
            ans += n - pow(10, i) + 1;
        }
    }

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

Measured memory_bytes: 256
"""
cosA=((AB)**2 + (AC)**2 - (BC)**2)/2(AB)(AC)
三角形の求め方
三辺もしくは二辺+1角度わかれば行ける
＜正弦定理＞<余弦定理>
"""
import math
a = [int(i) for i in input().split()]

zisin = a[0]#時針は1分で0.5度動く
kakudo_z = a[2]*30+a[3]*0.5
hunsin = a[1]#分針は1分で6度動く
kakudo_h = a[3]*6
kakudo = abs(kakudo_h-kakudo_z)
if kakudo > 180:
    kakudo = 360 - kakudo
if kakudo != 90:
    print (f'{math.sqrt(a[0]**2+a[1]**2-(math.cos(math.radians(kakudo)))*2*a[0]*a[1]):0.20f}')
else:
    print(f'{math.sqrt(a[0]**2+a[1]**2):0.20f}')

Measured memory_bytes: 9504
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        double W = sc.nextDouble();
        double H = sc.nextDouble();
        double x = sc.nextDouble();
        double y = sc.nextDouble();
        double ans;
        int flag=0;
        sc.close();

        ans = W*H/2;

        if(x == W/2 && y == H/2){
            flag = 1;
        }

        System.out.println(ans + " " + flag);

    }
}

Measured memory_bytes: 23252
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

signed main()
{
    int n; cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    vi ans(4 * n + 1, -1);

    int l = 4 * n / 2 - 1, r = 4 * n / 2 + 1;

    ans[4 * n / 2] = a[0];
    rep(i, n - 1) {
        if (i % 2) {
            ans[l] = a[i + 1];
            l--;
        } else {
            ans[r] = a[i + 1];
            r++;
        }
    }

    vi o;

    for (int i = 0; i < (int)ans.size(); ++i) {
        if (ans[i] != -1) {
            while (ans[i] != -1) {
                o.PB(ans[i]);
                i++;
            }
            break;
        }
    }

    if (n % 2 == 0) reverse(all(o));

    rep(i, o.size()) {
        if (i) cout<<' ';
        cout<<o[i];
    }
    cout<<endl;
}


Measured memory_bytes: 7028
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
    string str, mostfind = "", mostlong = "";
    map<string, int> many;
    while(cin >> str){
        if(many[mostfind] < ++many[str]){
            mostfind = str;
        }
        if(mostlong.size() < many.size()){
            mostlong = str;
        }
    }
    cout << mostfind << " " << mostlong << "\n";
}


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

int main(void){
        int N, K;
        cin >> N >> K;
        ll s[N+1];
        ll se[N+1];
        rep(i,N) {
                int p;
                cin >> p;
                s[i] = (p+1);
        }
        se[0] = 0;
        rep(i,N) {
                se[i+1] = se[i] + s[i];
        }
        ll ans = 0;
        for (int i = 0; i <=N-K; i++) {
                ans = max(ans, se[i+K]-se[i]);
        }
        cout << setprecision(10) << (double)ans/2.0 << endl;

        return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

const double EPS = 1e-8;

typedef complex<double> Point;
typedef Point P;
typedef vector<Point> Line;
typedef Line L;
typedef vector<Point> Pol;
double dot(P a, P b){return real(conj(a) * b);}
double cross(P a, P b){return imag(conj(a) * b);}
P vec(L l){return l[1] - l[0];}
int sign(double x){ return x > EPS ? 1 : x < -EPS ? -1 : 0; }
int ccw(P a, P b, P c) {
    b -= a; c -= a;
    return sign(cross(b,c)) ? : dot(b,c) < 0 ? 2 : norm(b) < norm(c) ? -2 : 0;
}
Point next(Pol p, int k) {
    return p[ (k+1) % p.size() ];
}
bool iSS(L s, L t) {
    auto ok = [](L a, L b){return ccw(a[0],a[1],b[0]) * ccw(a[0],a[1],b[1]) <= 0;};
    return ok(s,t) && ok(t,s);
}
double dLP(L l, P p){return abs(cross(vec(l), p - l[0])) / abs(vec(l));}
double dSP(L s, P p){
    if(sign(dot(vec(s), p - s[0])) <= 0) return abs(p - s[0]);
    if(sign(dot(-vec(s), p - s[1])) <= 0) return abs(p - s[1]);
    return dLP(s, p);
}
double dSS(L s, L t){return iSS(s,t) ? 0.0 : min({dSP(s, t[0]), dSP(s, t[1]), dSP(t, s[0]), dSP(t, s[1])});}
double dist(Pol p, Pol q) {
    double res = 1e18;
    REP(i, p.size()){
        Line l = {p[i], next(p, i)};
        REP(j, q.size()) {
            Line m = {q[j], next(q, j)};
            res = min(res, dSS(l, m));
        }
    }
    return res;
}
double distL(Line l, Pol q) {
    double res = 1e18;
    REP(j, q.size()) {
        Line m = {q[j], next(q, j)};
        res = min(res, dSS(l, m));
    }
    return res;
}
int main(){
    double W;
    int N;
    while(cin >> W >> N && W > 0) {
        vector<Pol> pols(N);
        REP(i, N) {
            int K;
            cin >> K;
            Pol p(K);
            REP(j, K) {
                double x, y;
                cin >> x >> y;
                p[j] = {x, y};
            }
            pols[i] = p;
        }
        Line left = {{0, 0}, {0, 1e4}};
        Line right = {{W, 0}, {W, 1e4}};

        double d[203][203] = {};
        REP(i, N+2) REP(j, N+2) d[i][j] = (i == j ? 0 : 1e18);

        d[0][1] = d[1][0] = W;

        REP(i, N) REP(j, N) d[i+2][j+2] = dist(pols[i], pols[j]);
        REP(i, N) d[0][i+2] = d[i+2][0] = distL(left, pols[i]);
        REP(i, N) d[1][i+2] = d[i+2][1] = distL(right, pols[i]);
        // REP(i, N) REP(j, pols[i].size()) d[0][i+2] = d[i+2][0] = min(d[0][i+2], pols[i][j].real());
        // REP(i, N) REP(j, pols[i].size()) d[1][i+2] = d[i+2][1] = min(d[0][i+2], W - pols[i][j].real());

        REP(k, N+2) REP(i, N+2) REP(j, N+2) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        // REP(i, N+2) REP(j, N+2) printf("d[%d][%d] = %f\n", i, j, d[i][j]);

        printf("%.12f\n", d[0][1]);
    }
    return 0;
}

Measured memory_bytes: 1620
//be naame khodaa
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second
#define pb push_back
#define sz(x) ((int)(x).size())

inline int in(){ int x, y; y = scanf("%d", &x); return x; }

const int N = -1;
const int MOD = 1e9 + 7;

int cnt[26];

int main(){
	int n = in();
	string s;
	cin >> s;
	for (int i = 0; i < n; i++)
		cnt[s[i]-'a']++;
	ll ans = 1;
	for (int i = 0; i < 26; i++)
		ans = ans*(cnt[i]+1)%MOD;
	ans = (ans + MOD - 1)%MOD;
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


const int MAX_N = 3005;
double p[MAX_N];
double dp[MAX_N][MAX_N];

int main2() {

  int N; cin >> N;
  REP(i, N) cin >> p[i];

  CLR(dp, 0);
  dp[0][0] = 1.0;
  REP(i, N) {
    REP(j, N) {
      if (i + j < N) {
        dp[i+1][j] += p[i+j] * dp[i][j];
        dp[i][j+1] += (1.0 - p[i+j]) * dp[i][j];
      }
    }
  }

  double ans = 0;
  REP(i, N+1) {
    int j = N - i;
    if (i > j) ans += dp[i][j];
  }
  printf("%.10f\n", ans);
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 70784