akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7
//前処理テーブルの大きさ指定
const int MAX = 1200000; // = 10^6 + 2*(10^5)
//ちなみに、1024MBで持てる最大長の配列は10^8程度

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる。
  ll cost; // e.costでその辺の重みにアクセスできる。
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける。
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す。
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N;
  cin >> N;
  ll ans = 1;
  bool ok = false;
  for (int i = 0; i < N; i++) {
    ll A;
    cin >> A;
    if (A == 0) {
      ok = false;
      ans = 0;
      break;
    }
    if (ans > (1000000000000000000 / A)) {
      ok = true;
      ans = 0;
    }
    else {
      ans *= A;
    }
  }
  if (ok) {
    cout << -1 << endl;
  }
  else {
    cout << ans << endl;
  }
}


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

int main(){
    int a,b;
    char op;
    while(cin >> a >> op >> b,op != '?'){
        if(op=='+'){
            cout << a+b << endl;
        }
        if(op=='-'){
            cout << a-b << endl;
        }
        if(op=='*'){
            cout << a*b << endl;
        }
        if(op=='/'){
            cout << a/b << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3092
// i_m_arin

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef map<ll,ll> mpll;
typedef set<ll> stll;

#define f(i, a, n) 	for(ll i=a; i<(ll)n; i++)
#define f2(i, a, b) for(ll i=a; i<=(ll)b; i++)
#define pb 			push_back
#define ff 			first
#define ss 			second
#define pf			push_front
#define mp			make_pair
#define all(a)		(a).begin(),(a).end()
#define decimal(x)	fixed<<setprecision(x)
#define fsort(a)	sort(all(a))
#define rsort(a)	sort(all(a),greater<>())
#define fast_io		ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem0(a)		memset(a,0,sizeof(a))
#define mem1(a)		memset(a,-1,sizeof(a))
#define lcm(a,b)	(a*b)/__gcd(a,b)
#define ub(v,x)		upper_bound(all(v),x)-v.begin()
#define lb(v,x)		lower_bound(all(v),x)-v.begin()

const ld PI  = acos(-1);
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll SIZE= 100000;


void solve(){

ll n;
cin>>n;

vpll vp;
f(i,0,n){
	ll x,y;
	cin>>x>>y;
	vp.pb({x,y});
}
f(i,2,n){
	if(vp[i-2].ff==vp[i-2].ss && vp[i-1].ff==vp[i-1].ss && vp[i].ff==vp[i].ss){
		cout<<"Yes"<<endl;
		return;
	}
}
cout<<"No"<<endl;

}


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

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

int main() {
	long n, mi = 10000000000;
  	cin >> n;
    int ans = 1;
  	vector<long> p(n);
  	for(long i = 0; i< n; i++){
      cin >> p[i];
    }
  	for(long i = 0; i < n; i++){
        if(mi > p[i]){
            ans++;
            mi = p[i];
        }

    }
    cout << ans-1 << endl;
}



Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
#include <numeric>
#include <stack>
using namespace std;

string S;
int N;
stack<int> d;
int t;
int ans = 0;

int main() {
	cin >> S;
	N = S.length();
	d.push(S[0] - '0');
	for (int i = 1; i < N; i++) {
		t = S[i] - '0';
		if (d.empty()) {
			d.push(t);
		}else {
			if (t == d.top()) {
				d.push(t);
			}
			else {
				d.pop();
				ans += 2;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
from heapq import heappop, heappush

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [-a for a in A]
B.sort()

for i in range(M):
    b = heappop(B)
    heappush(B, b / 2)
result = 0
for b in B:
    result = result + int(-b)
print(result)




Measured memory_bytes: 14184
n,s = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for i in range(s+1)] for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(s+1):
        if j - A[i] >= 0:
            dp[i+1][j]=(dp[i][j]*2+dp[i][j-A[i]])%mod
        else:
            dp[i+1][j]=(dp[i][j]*2)%mod
print(dp[n][s])

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

int main(){
    using namespace std;
    unsigned long N, H;
    cin >> N >> H;
    unsigned long ans{0}, tmp{0};
    for(unsigned long i = 1, h; i < N; ++i){
        cin >> h;
        if(h > H){
            ans = max(ans, tmp);
            tmp = 0;
        }else{
            ++tmp;
        }
        swap(h, H);
    }
    cout << max(ans, tmp) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, k;
    char s[11];
    cin >> n >> s >> k;
    k -= 1;
    for (int i = 0; s[i] != '\0'; i++)
    {
        if (s[i] != s[k]) s[i] = '*';
    }
    cout << s;
}

Measured memory_bytes: 256
#include <stdio.h>
#define A 80
#define B 65
#define C 50
#define D 30
#define AB -1
int main(void)
{
	int m, f, r, a;
	char grade;
	while(scanf("%d%d%d", &m, &f, &r), (m != AB) || (f != AB) || (r != AB)){
		a = m + f;
		if((m == AB) || (f == AB) || (a < D)){
			grade = 'F';
		}else if(a >= A){
			grade = 'A';
		}else if((a < A) && (a >= B)){
			grade = 'B';
		}else if((a < B) && (a >= C)){
			grade = 'C';
		}else if((a < C) && (a >= D)){
			grade = 'D';
		}
		if((a < C) && (a >= D) && (r >= C)){
			grade = 'C';
		}
		printf("%c\n", grade);
	}
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;

#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i = a; i < b; i++)
#define FORD(i,a,b) for(ll i=(a);i>=(int)(b);i--)
#define sf(n) scanf("%lld", &n)
#define sfc(x) scanf("%c", &x)
#define pf(x) printf("%lld", x)
#define pff(x) printf("%lf", x)
#define pfc(x) printf("%c", x)
#define pfs(x) printf("%s", x)
#define sf2(a,b) scanf("%lld %lld", &a, &b)
#define sf3(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define pfn(n) printf("%lld\n", n)
#define pfs(n) printf("%lld ", n)
#define ff first
#define ss second   
#define mem(a,b) memset(a,b,sizeof(a))
#define sz size()
#define ll long long
#define all(c) (c).begin(),(c).end()
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
const ll INF = 2e18;

bool prime[1000009];    
unordered_map<ll,ll> largest_factor;
void SieveOfEratosthenes(ll n)
{
    memset(prime,true, sizeof(prime)); 
    prime[1]=false;
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p){
                prime[i] = false;
                largest_factor[i]=p;
            }

        }
    }
}


ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}


ll mod_power(ll a,ll b,ll m){
    ll res=1;
    a%=m;
    while(b){
        if(b&1){
            res=res*a%m;
        }
        a=a*a%m;
        b>>=1;
    }
    return res;
}
ll n,m,x;
map<pair<ll,vi>,ll> dp;
ll a[14][14];
ll c[14];
ll fun(ll i,vi v){
    bool flag=true;
    FOR0(j,m)if(v[j]<x)flag=false;
    if(flag)return 0;
    if(i>=n)return 2e18;
    if(dp[mp(i,v)]!=0)return dp[mp(i,v)];

    vi v1;
    FOR0(j,m)v1.pb(v[j]+a[i][j]);

    return dp[mp(i,v)] = min(c[i]+fun(i+1,v1),fun(i+1,v));
}


int main(){
    fast
    
    cin>>n>>m>>x;


    FOR0(i,n){
        FOR0(j,m+1){
            if(j==0)cin>>c[i];
            else cin>>a[i][j-1];
        }
    }
    vi v(m,0);
    ll ans = fun(0,v);
    if(ans>=1e9)ans=-1;
    cout<<ans<<endl;

}

Measured memory_bytes: 4428
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  int n, k, q ;
  cin >> n >> k >> q ;
  vector<int> a(q) ;
  for(int i=0;i<a.size();i++){
    cin >> a.at(i) ;
  }

  vector<int> score(n,k-q) ;
 
  for(int i=0;i<a.size();i++){ 
         score.at(a.at(i)-1) += 1 ;     
  }
    
   for(int i=0;i<score.size();i++){
     if(score.at(i)<=0)
    cout << "No" << endl;
       else
    cout << "Yes" << endl;
   }
     
    return 0 ;
 
}


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

int n,k,s,ans;

void A(int r,int p,int q){
	if(r==k){
		if(q==s)ans++;
		return;
	}
	for(int i=p+1;i<=n;i++) A(r+1,i,q+i);
}

int main(){
	while(scanf("%d%d%d",&n,&k,&s),n||k||s){
		ans=0;A(0,0,0);printf("%d\n",ans);
	}
}

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

int main(void) {
    string str;
    while(cin>>str) {
        if(str=="-") return 0;
        int m,h;
        cin>>m;
        for(int i=0;i<m;i++) {
            cin>>h;
            string sub=str.substr(0,h);
            str+=sub;
            str.erase(0,h);
        }
        cout<<str<<endl;
    }
    return 0;
}

Measured memory_bytes: 3228
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	int n;
	pair<pair<string,int>, int> sp[110];
	cin >> n;
	for (int i = 0; i < n; i++) 
	{ 
		cin >> sp[i].first.first >> sp[i].first.second; 
		sp[i].first.second *= -1;
		sp[i].second = i;
	}
	sort(sp, sp + n);
	for (int i = 0; i < n; i++) { cout << sp[i].second + 1 << endl; }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    map<string,int>mp;
    int n;
    cin>>n;
    string last,s;
    for(int i=0; i<n; i++)
    {
        cin>>s;
        if(i)
        {
            if(mp[s])
            {
                cout<<"No"<<endl;
                return 0;
            }
            int sz=last.length();
            if(last[sz-1]!=s[0])
            {
                cout<<"No"<<endl;
                return 0;
            }

        }

        mp[s]++;
        last=s;

    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3684
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
 
using ull = unsigned long long int;
using ll = long long int;
using du = double;
using ld = long du;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vdu = vector<du>;
using vs = vector<string>;
using vc = vector<char>;
using si = set<int>;
using sll = set<ll>;
using sdu = set<du>;
using sld = set<ld>;
using pii = pair<int, int>;
using pll = pair<ll,ll>;
using pdu = pair<du,du>;
using pld = pair<ld,ld>;
using pis = pair<int,string>;
 
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define sp(x) setprecision(x)<<fixed
#define loop(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pi acos(-1)
#define meme(a,x) memset(a,x,sizeof(a))
#define all(a) a.begin(),a.end()
 
//debugger
 
#ifdef KAIZER
#include "debug.h"
#else
#define debug(x...)
#endif
//debugger
 
//functions
bool check_pow(ll a)
{
    if((a&(a-1))==0) return true;
    else return false;
}
ld my_pow(ld a,int b)
{
    ld ans=1;
    for(int i=0;i<b;i++) ans*=a;
    return ans;
}
ll digits(ll a)
{
    string line=to_string(a);
    return line.size();
}
bool prime_check(ll a)
{
    bool flag=true;
    for(ll i=2;i<=sqrt(a);i++)
    {
        if(a%i==0) {flag=false; break;}
    }
    return flag;
}
bool comp(const pair<int,int> &a , const pair<int,int> &b)
{
    if(a.ff!=b.ff) return a.ff>b.ff;
    else return a.ss<b.ss;
}
bool comp2(const ll &a, const ll &b)
{
     return a>b;
}
 
//functions

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    FASTIO;
    ll n,ans=0;
    cin>>n;
    int a[n];
    loop(i,n) cin>>a[i];
    sort(a,a+n,greater<int>());
    loop(i,n)
    {
        if(i%2==0) ans+=a[i];
        else ans-=a[i];
    }
    cout<<ans<<endl;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int n;
ll p;
string s;
ll dp[maxn];
ll ans=0;

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

  cin>>n>>p;
  cin>>s;
  // 10 won't have a mod inverse if p==2 or p==5
  if (p==2) {
    for (int i=0; i<n; i++) {
      if ((s[i]-'0')%2==0) ans += i+1;
    }
  } else if (p==5) {
    for (int i=0; i<n; i++) {
      if ((s[i]-'0')%5==0) ans += i+1;
    }
  } else {
    ll cur = 0;
    dp[0] = 1;
    ll pw10 = 1;
    for (int i=n-1; i>=0; i--) {
      cur = (cur+pw10*(s[i]-'0')%p)%p;
      ans += dp[cur];
      dp[cur]++;
      pw10 = 10LL*pw10%p;
    }
  }
  cout<<ans<<endl;
  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 720
#include <iostream>
#include <cstdint>

int main(){
  std::uint64_t x;

  std::cin >> x;

  auto n = 2* (x / 11);
  
  auto k = x % 11;

  if(0 != k){
    if(k <= 6){
      n += 1;
    }else{
      n += 2;
    }
  }

  std::cout << n << std::endl;

  return 0;
}


Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		var sc = new java.util.Scanner(System.in);
		var n = sc.next().charAt(0);

		if('a'<=n && n <='z' ) {
			System.out.println('a');
		}else {
			System.out.println('A');
		}
	}
}

Measured memory_bytes: 35700
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.begin()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

  int n; cin >> n;
  int d[100010];
  rep(i, n) {
    cin >> d[i];
  }

  sort( d, d + n );

  int mid = n / 2;
  cout << d[mid] - d[mid-1] << endl;

  return 0;
}



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

/* 繰り返し自乗法. */
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合.
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

signed main() {
    int H, N;
    cin >> H >> N;

    bool ret = false;
    ll sum = 0;
    rep (i, N) {
        ll a;
        cin >> a;
        sum += a;
        if (sum >= H) {
            ret = true;
            break;
        }
    }

    if (ret == true) cout << "Yes" << endl;
    else             cout << "No"  << endl;

}



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

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

    int n;
    cin >> n;

    int res = 0;
    for (int i = 1; i * i <= n; ++i){
        res = max(res, i*i);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<28)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    int x, y, a, b, c, p[100000], q[100000], r[100000], rg[300000];
    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i < a; i++)cin >> p[i];
    for (int i = 0; i < b; i++)cin >> q[i];
    for (int i = 0; i < c; i++)cin >> r[i];
    sort(p, p + a, greater<>());
    sort(q, q + b, greater<>());
    sort(r, r + c, greater<>());
    for (int i = 0; i < x; i++)rg[i] = p[i];
    for (int i = 0; i < y; i++)rg[i + x] = q[i];
    for (int i = 0; i < c; i++)rg[i + x + y] = r[i];
    sort(rg, rg + x + y + c, greater<>());
    ll ans = 0;
    for (int i = 0; i < x + y; i++)ans += rg[i];
    cout << ans;
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
using namespace std;
#define ll long long

int main(){
  string s;
  cin >> s;
  int n;
  n = s.size();
  ll ans=0;
  for(int bit=0; bit<(1<<(n-1)); bit++){
    ll a;
    a = s[0]-'0';
    for(int i=0; i<n-1; i++){
      if(bit & (1<<i)){
        ans += a;
        a = 0;
      }
      a = a*10 + s[i+1]-'0';
    }
    ans += a;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;



int main(void){
  int N;
  vector<int> neko;
  cin >> N;
  for(int i =0; i < N; i++){
    int tmp;
    cin >> tmp;
    neko.push_back(tmp);
  }
  long x = accumulate(neko.begin(), neko.end(),0LL);
  double ave = round( (double)x/neko.size() );

  long sum = 0;
  for(int i =0; i < N; i++){
    sum += pow(abs(neko[i] - ave),2);
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define MP make_pair
#define fi first
#define se second 
#define pb push_back
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int N=3010,maxn=3000;
int cj[N],inv[N];
int dp[N][N];
int f[N],g[N],h[N];
int ans;
int n,mod;

int power(int x,int y,int mod){
	int ret=1;
	for(;y;y>>=1,x=1ll*x*x%mod){
		if(y&1)	ret=1ll*ret*x%mod;
	}
	return ret;
}

void init(){
	int i;
	cj[0]=1;rep(i,1,maxn)	cj[i]=1ll*cj[i-1]*i%mod;
	inv[maxn]=power(cj[maxn],mod-2,mod);inv[0]=1;
	for(i=maxn-1;i;i--)	inv[i]=1ll*inv[i+1]*(i+1)%mod;
}

int C(int n,int m){
	if(n<m)	return 0;
	return 1ll*cj[n]*inv[m]%mod*inv[n-m]%mod;
}

int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);	
	register int i,j;
	int now,cur,tot,x;
	scanf("%d%d",&n,&mod);
	init();
	dp[0][0]=1;
	rep(i,1,n)	rep(j,0,i){
		dp[i][j]=(dp[i][j]+1ll*dp[i-1][j]*(j+1))%mod;
		dp[i][j+1]=(dp[i][j+1]+dp[i-1][j])%mod;
	}
	rep(i,0,n){
		cur=0;
		f[0]=1;x=power(2,n-i,mod);f[1]=x;
		rep(j,2,i){
			x=(x-1+mod)%mod;
			f[j]=1ll*f[j-1]*x%mod;
		}
		g[0]=1;
		rep(j,1,i)	g[j]=(g[j-1]+1ll*f[j]*inv[j])%mod;
		tot=power(2,power(2,n-i,mod-1),mod);
		h[0]=1;x=power(2,n-i,mod);
		rep(j,1,i)	h[j]=1ll*h[j-1]*x%mod;
		rep(j,0,i){
			now=1ll*dp[i][j]%mod*h[j]%mod;
			now=1ll*now*tot%mod;
			//now=1ll*now*C(i,j)%mod;
			cur=(cur+now)%mod;
		}
		cur=1ll*C(n,i)*cur%mod;
		if(i&1)	ans=(ans-cur)%mod;
		else ans=(ans+cur)%mod;
	}
	//ans=(power(2,power(2,n,mod-1),mod)-ans)%mod;
	ans=(ans+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 34176
char S[4040];
i,j;c[99],t;
main(N)
{
	for(scanf("%d%s",&N,S);i<N;c[S[i++]]++)for(j=i;j>=0;j-=2)t-=(S[i]^S[i+j>>1]^S[j])==87;
	printf("%ld",1L*c[66]*c[71]*c[82]+t);
}

Measured memory_bytes: 1724
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        int v = 1000 - n;
        int coins[] = {500, 100, 50, 10, 5, 1};
        int pos = 0, ans = 0;
        while(v > 0)
        {
            while(v - coins[pos] < 0) pos++;
            v -= coins[pos];
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 3092
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int N;
ll A[202020];


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

	cin >> N;
	map<ll, ll>mp;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		mp[i-A[i]]++;
	}

	ll ans = 0;
	for (int i = 0; i < N; i++) {
		mp[i-A[i]]--;
		ans += mp[A[i] + i];
	}
	puts(ans);

	return 0;
}

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

int main(){
        int k,s;
        int ans = 0;
        cin >> k >> s;
        rep(x,k+1) rep(y,k+1){
                int z = s-x-y;
                if(0<=z && z <= k) ans++;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-31 12:23:12
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

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

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

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

template<class T> std::vector<T> divisor(T n) {
  std::vector<T> res;
  for (T i = 1; i * i <= n; ++i) {
    if (n % i == 0){
      res.push_back(i);
      if (i * i != n){
        res.push_back(n / i);
      }
    }
  }
  std::sort(res.begin(), res.end());

  return res;
}

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

  int64 n; cin >> n;
  vector<int64> v = divisor(n);

  auto f = [](int64 x, int64 y) -> int {
    return max(to_string(x).size(), to_string(y).size());
  };

  int ans = 1e9;

  for (int64 e : v) {
    ans = min(ans, f(e, n / e));
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  int n, d;
  while(cin >> n >> d, n || d) {
    vector< vector<int> > mis(n);
    vector<int> pot(n, 0);
    rep(i, n) {
      int m; cin >> m;
      rep(j, m) {
	int c; cin >> c;
	mis[i].push_back(c);
	pot[i] += c;
      }
    }
#define check (*max_element(all(pot)) - *min_element(all(pot)) <= d)
    bool flag = check;
    while(flag && *max_element(all(pot)) != 0) {
      flag = false;
      rep(i, n) {
	if(pot[i] > 0) {
	  pot[i] -= mis[i].back();
	  if(check) {
	    mis[i].pop_back();
	    flag = true;
	  } else {
	    pot[i] += mis[i].back();
	  }
	}
      }
    }
    cout << (*max_element(all(pot)) == 0 ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 3108
#include <vector>
#include <stdio.h>
using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  int p[n + 1];
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  int a[n + 1];
  int b[n + 1];
  int k = 30000;
  for (int i = 1; i <= n; ++i) {
    a[i] = i * k;
    b[i] = k * (n - i + 1);
  }

  for (int i = 1; i <= n; ++i) {
    a[p[i]] += i;
  }
  for (int i = 1; i <= n; ++i) {
    printf("%d", a[i]);
    if (i == n) {
      puts("");
    } else {
      printf(" ");
    }
  }
  for (int i = 1; i <= n; ++i) {
    printf("%d", b[i]);
    if (i == n) {
      puts("");
    } else {
      printf(" ");
    }
  }  
  return 0;
}


Measured memory_bytes: 768
n,y  = list(map(int,input().split()))

if y/n > 10000:
  print('-1 -1 -1')
  exit()
elif y < n*1000:
  print('-1 -1 -1')
  exit()
else:
  for a in range(y//10000 +1):
    for b in range(y//5000 +1):
      if n-a-b >= 0:
        if 10*a + 5*b + (n-a-b) == (y/1000):
          print(*[a,b,n-a-b])
          exit()

print('-1 -1 -1')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVETSE(c) reverse((c).begin(),(c).end())
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define ALL(a)  (a).begin(),(a).end()
// int gcd(int a,int b){return b?gcd(b,a%b):a;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> T maxt(T x,T y) {
    if (x>y) return x;
    else return y;
}
template<class T> T mint(T x,T y) {
    if (x>y) return y;
    else return x;
}
//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

long long m = 1e9+7, mod = 1e9+7;
//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

/* //約数列挙
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}*/


int main() {
  int a,b;
  scanf("%d %d",&a,&b);
  int ma = maxt(a,b),mb=mint(a,b);
  string str(ma,'0'+mb);
  cout << str << "\n";
}

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


int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  string ans = "Yes";
  
  while(a >= 0 && b >= 0){
    c -= b;
    if(c <= 0) break;
    a -= d;
    if(a <= 0) ans = "No";
  }
   
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
const ll mod2= 998244353;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

const ll N=1100000;
struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};
 
ll a[110000],b[110000];
int main(){
    ll n,M,ans=0;
    cin>>n>>M;
    UnionFind UF(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        UF.unite(A, B);
    }
    rep(i,1,n+1){
        if(UF.same(i,1)==false){
            ans++;
            UF.unite(i,1);
        }
    }
    cout<<ans<<endl;
   // rep(i,1,N+1)cout<<UF.root(i)<<endl;

}


Measured memory_bytes: 7480
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			long[] nab = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			long n = nab[0];
			long a = nab[1];
			long b = nab[2];

			if (a > b || (n == 1 & a != b)) {
				Console.WriteLine(0);
				return;
			}

			long ans = (b * (n - 1) + a) - (a * (n - 1) + b) + 1;
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 13268
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(num_card, num_gate, inputs):
    gate_card = list(map(lambda x: string_to_int(x), inputs))
    min_card = 1
    max_card = num_card
    for d in gate_card:
        if d[0] > min_card:
            min_card = d[0]
        if d[1] < max_card:
            max_card = d[1]

    if max_card - min_card >= 0:
        return max_card - min_card + 1
    return 0


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(M))
    print(ret)


Measured memory_bytes: 34804
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    l = max(a)
    r = 0
    best = l / 2
    for target in a:
        if abs(best - r) >= abs(best - target):
            r = target

    print(str(l) + " " + str(r))


Measured memory_bytes: 14428
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<sstream>
#include<set>
#include<queue>
#include<algorithm>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair

int n,m,p,C[100];
vector<vector<pair<int,int> > > e;
int d[100];
bool v[100],u[100];
double togoal[100],prob[100];

int main(){
	while(cin>>n>>m>>p,n){
		e.clear(); e.resize(n);
		rep(i,m){
			int a,b,c; cin>>a>>b>>c;
			e[a].pb(mp(b,c)); e[b].pb(mp(a,c));
		}
		rep(i,p)cin>>C[i];
		
		rep(i,n)d[i]=1<<28; d[0]=0;
		priority_queue<pair<int,int> > Q; Q.push(mp(0,0));
		while(!Q.empty()){
			int c=Q.top().second,cc=Q.top().first; Q.pop();
			if(c==n-1)break;
			if(d[c]<-cc)continue;
			fr(i,e[c])if(d[i->first]>-cc+i->second)
			d[i->first]=-cc+i->second,Q.push(mp(cc-i->second,i->first));
		}
		
		rep(i,n)u[i]=v[i]=0;
		rep(i,n)prob[i]=0,togoal[i]=0;
		togoal[n-1]=1; v[n-1]=1;
		Q=priority_queue<pair<int,int> >(); Q.push(mp(d[n-1],n-1));
		while(!Q.empty()){
			int c=Q.top().second; Q.pop();
			fr(i,e[c])if(d[i->first]+i->second==d[c]){
				togoal[i->first]+=togoal[c];
				if(!v[i->first])v[i->first]=1,Q.push(mp(d[i->first],i->first));
			}
		}
		Q=priority_queue<pair<int,int> >(); Q.push(mp(0,0));
		prob[0]=1; u[0]=1;
		while(!Q.empty()){
			int c=Q.top().second; Q.pop();
			fr(i,e[c])if(v[i->first]&&d[i->first]==d[c]+i->second)
			{
				prob[i->first]+=prob[c]*togoal[i->first]/togoal[c];
				if(!u[i->first])u[i->first]=1,Q.push(mp(-d[i->first],i->first));
			}
		}
		rep(i,p)printf("%.7f\n",prob[C[i]]); puts("");
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, c;
  string s, t;
  cin >> s >> t;
  c=0;
  rep(i,0,3) if(s.at(i)==t.at(i)) c++;
  co(c);
  
  return 0;
}


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

const long long MOD = 1000000007LL;
const long long INF = 1e18;

long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

pair<int, int> arr[200005];
int dsu[200005];
long long ranks[200005];

int find(int node){
    if(node == dsu[node]) return node;
    return dsu[node] = find(dsu[node]);
}

void combine(int a, int b){
    a = find(a); b = find(b);
    if(a == b) return;
    if(ranks[a] <= ranks[b]){
        dsu[a] = b;
        ranks[b] += ranks[a];
    } else {
        dsu[b] = a;
        ranks[a] += ranks[b];
    }
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    long long total = 0;
    int n; cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> arr[i].first;
        arr[i].second = i;
        dsu[i] = i; ranks[i] = 1;
    }

    sort(arr, arr + n);
    reverse(arr, arr + n);

    bitset<200005> vis;

    for(int i = 0; i < n; ++i){
        long long left = 1, right = 1, num = arr[i].first;
        int pos = arr[i].second;
        if(pos + 1 < n && vis[pos + 1]){
            right = 1 + ranks[find(pos + 1)];
            combine(pos, pos + 1);
        }
        if(pos > 0 && vis[pos - 1]){
            left = 1 + ranks[find(pos - 1)];
            combine(pos, pos - 1);
        }
        total += num * left * right;
        vis[pos] = 1;
    }

    cout << total;

    return 0;
}


Measured memory_bytes: 4224
#include<stdio.h>

static const int N = 100;
int min(int,int);
int main() {
  int i,j,k,l,n,v,A[N+1],B[N+1][N+1];

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

  for (i = 1 ; i <= n ; i++) {
    B[i][i] = 0;
  }
  for(l = 2 ; l <= n ; l++) {
    for(i = 0 ; i <= n-l+1 ; i++) {
      j = i + l - 1;
      B[i][j] = (1<<21);
      for(k = i ; k <= j-1 ; k++) {
	B[i][j] = min(B[i][j], B[i][k] + B[k+1][j] + A[i-1] * A[k] * A[j]);
      }
    }
  }
  printf("%d\n",B[1][n]);
  return 0;
}

int min(int a,int b){
  return a < b ? a:b;
}



Measured memory_bytes: 2112
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
typedef pair<pair<int, int>, int> PP;

const ll INF = 1e15;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main(void) {
	int N, K; cin >> N >> K;
	ll ans = 0;
	vector<int> V;
	for (int i = 0; i < N; i++) {
		int v; cin >> v;
		V.push_back(v);
	}

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			if (i + j > N || i + j > K)continue;
			vector<int>hand;
			ll sum = 0;
			for (int k = 0;k < i; k++) {
				hand.push_back(V[k]);
				sum += V[k];
			}
			for (int k = N-1; k >= N-j; k--) {
				hand.push_back(V[k]);
				sum += V[k];
			}
			sort(hand.begin(), hand.end());
			for (int k = 0; k < hand.size(); k++) {
				if (k + 1 > K - i - j)break;
				if (hand[k] < 0)sum -= hand[k];
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
N = int(input())
S = input()
ans, gap = S.count('R') * S.count('G') * S.count('B'), 1
while gap * 2 + 1 <= N:
    ans -= sum([1 for i in range(N - gap * 2)
                if {'R', 'G', 'B'} == {S[i], S[i + gap], S[i + 2 * gap]}])
    gap += 1
print(ans)


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

#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<string> A(n), B(m);
    for(int i = 0; i < n; i++) cin >> A[i];
    for(int i = 0; i < m; i++) cin >> B[i];

    bool ans = false;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i + m - 1 >= n || j + m - 1 >= n) continue;
            bool flag = true;
            for(int k = 0; k < m; k++){
                for(int l = 0; l < m; l++){
                    if(A[i + k][j + l] != B[k][l]) flag = false;
                }
            }
            if(flag) ans = true;
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vl A(N);
  rep(i,N) {
    cin >> A[i];
  }
  ll ans = 0;
  srep(i,1,N) {
    if(A[i-1]>A[i]) {
      ans += A[i-1]-A[i];
      A[i]=A[i-1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4760
n,k=map(int,input().split())
s=list(input())
ct=0
for i in range(n-1):
  if s[i]=='R' and s[i+1]=='L':
    ct+=1
x=ct
ct-=min(ct,k)
ct*=2
if s[0]==s[n-1]:
  ct+=1
elif s[0]=='L':
  if x<k:
    ct+=1
  else:
    ct+=2
else:
  if x<=k:
    ct+=1
print(n-ct)

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  while(a>=b && (k>0))
  {
    b=b*2;
    k--;
  }
  while(b>=c && k>0)
  {
    c=c*2;
    k--;
  }
  if(c>b && b>a)
    cout<<"Yes\n";
  else
    cout<<"No\n";
}

Measured memory_bytes: 3592
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int N, M;
  while(cin>>N>>M && N){
    vector<int> s(N), t(N);
    vector<int> rope(M);
    REP(i, N) scanf("%d %d", &s[i], &t[i]);
    REP(i, M) scanf("%d", &rope[i]);
    sort(rope.begin(), rope.end());
    vector<int> sum_mod[2] = {vector<int>(M), vector<int>(M)};
    REP(i, M - 1){
      sum_mod[0][i + 1] = sum_mod[0][i] + ((i % 2 == 0) ? (rope[i + 1] - rope[i]) : 0);
      sum_mod[1][i + 1] = sum_mod[1][i] + ((i % 2 == 1) ? (rope[i + 1] - rope[i]) : 0);
    }
    ll ans = 0;
    REP(i, N){
      bool rev = (s[i] > t[i]);
      if(rev) swap(s[i], t[i]);
      int b_idx = upper_bound(rope.begin(), rope.end(), s[i]) - rope.begin();
      int e_idx = upper_bound(rope.begin(), rope.end(), t[i]) - rope.begin();
      if(b_idx == e_idx){
        ans += (t[i] - s[i]);
        //if(!rev) printf("%d->%d %lld\n", s[i], t[i], ans - tmp);
        //else printf("%d->%d %lld\n", t[i], s[i], ans - tmp);
        continue;
      }
      assert(b_idx < e_idx);
      e_idx--;
      if(!rev){
        int mod = (b_idx + 1) % 2;
        ans += sum_mod[mod][e_idx] - sum_mod[mod][b_idx];
        ans += (rope[b_idx] - s[i]);
        if(e_idx % 2 == mod){
          ans += (t[i] - rope[e_idx]);
        }
      }else{
        int mod = (e_idx) % 2;
        ans += sum_mod[mod][e_idx] - sum_mod[mod][b_idx];
        ans += (t[i] - rope[e_idx]);
        if((b_idx + 1) % 2 == mod){
          ans += (rope[b_idx] - s[i]);
        }
      }
      //if(!rev) printf("%d->%d %lld\n", s[i], t[i], ans - tmp);
      //else printf("%d->%d %lld\n", t[i], s[i], ans - tmp);
    }
    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll N;
    cin >> N; N--;
    vector<int> ans;
    while (true) {
        ans.push_back(N % 26);
        N /= 26;
        if (N == 0) break;
        N -= 1;
    }
    reverse(ALL(ans));

    vector<char> ans2;
    char alpha[26];
    REP(i, 26) alpha[i] = 'a' + i;
    REP(i, ans.size()) {
        cout << alpha[ans[i]];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
/*
alias g='g++ -std=c++17 -O2 pra.cpp'
cd programming
cd cpp
cd practice

*/
#define rep(i, n) for(int i=0; i<(n); i++)
using veci = vector<int>;
using ll = long long;
using P = pair<string, int>;
int c[10010];
int a[2020202];
int b[2000200];
struct trump{
    char mark;
    int number, order;
};
trump p[100100];
int partition(trump a[], int w, int r){//配列の最後の要素の値を基準に分割
    int x=p[r].number;
    int i=w-1;//iが小さいほうのまとまりをみる下限
    for (int j=w; j<r; j++){//jが大きいほうのまとまりを見る下限
        if (p[j].number <= x){
            i++;
            swap(p[i], p[j]);
        }
    }
    swap(p[i+1], p[r]);
    return i+1;
}
void quicksort(trump a[], int w, int r){
    if (w<r){
        int q = partition(a, w, r);//基準ごとに大、中、小となるような
        //分割を繰り返し、結局全体で見てソートされているような状態にする
        quicksort(a, w, q-1);
        quicksort(a, q+1, r);
    }
}
int main(){
    int n;
    cin >> n;
    rep(i, n){
        cin >>p[i].mark >> p[i].number;
        p[i].order = i;
    }
    quicksort(p, 0, n-1);
    bool stable_judge = true;
    for (int i=1; i<n; i++){
        if (p[i].number == p[i-1].number && p[i].order < p[i-1].order) stable_judge = false;
    }
    if (stable_judge) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    rep(i, n){
        cout << p[i].mark << " " << p[i].number;
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4268