akhauriyash/Code-Regression huggingface dataset:
n,m = gets.split.map(&:to_i)
b = [0,2,5,5,4,5,6,3,7,6]
a = gets.split.map(&:to_i)
for i in 0..m-1
    for j in 0..m-1
        next if i == j
        if b[a[i]] == b[a[j]]
            a[i],a[j] = a[j],a[i] if a[i] < a[j]
            a[j] = 0
        end
    end
end
a.delete(0)
a.sort!
t = a.size
c = Array.new(t){|i|b[a[i]]}
s = Array.new(n+1).map{Array.new(t,0)}
dp = Array.new(n+1,0)
n.times do |i|
    next if dp[i] == 0 && i != 0
    t.times do |j|
        break if i+c[j] > n
        if dp[i+c[j]] < dp[i]+1
            dp[i+c[j]] = dp[i]+1
        end
    end
end
(n-1).downto(0) do |i|
    t.times do |j|
        if i+c[j] <= n && dp[i+c[j]] == dp[i]+1 && (i+c[j] == n || s[i+c[j]].inject(:+) > 0)
            s[i] = Marshal.load(Marshal.dump(s[i+c[j]]))
            s[i][j] += 1
        end
    end
end
ans = []
t.times do |i|
    s[0][i].times do
        ans << a[i]
    end
end
puts ans.sort.reverse.join("")

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


int main()
{
	int n, m, i, j;
	int a[100][100] = {0};
	int b[100] = {0};
	int c = 0;

	cin >> n >> m;

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}
	for (j = 0; j < m; j++)
	{
		cin >> b[j];
	}

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			c += a[i][j] * b[j];
		}
		cout << c << endl;
		c = 0;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
const double PI=4*atan(1);
using namespace std;
#define MOD 1000000007

int findmin(int a,int b) {
    return a<b?a:b;
}
int findmax(int a,int b) {
    return a>b?a:b;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long n,q;
    cin>>n;
    long a[n];
    ull sum=0;
    unordered_map<long,long> um;
    for(long i=0;i<n;i++) {
		cin>>a[i];
		sum+=a[i];
		um[a[i]]++;
	}
	cin>>q;
	long b,c;
	while(q--) {
		cin>>b>>c;
		ull diff=um[b]*(c-b);
		um[c]+=um[b];
		um[b]=0;
		sum+=diff;
		cout<<sum<<"\n";
	}
    cout.flush();
    return 0;
}


Measured memory_bytes: 7840
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Cat {
  int sex;
  int weight;
  ll cute;
  Cat() {;}
  Cat(int s, int m, int c) : sex(s), weight(m), cute(c) {;}
  bool operator<(const Cat &rhs) const {
    return cute < rhs.cute;
  }
};

int Na, Nb, W;
int dp[2][10100];
Cat cats[1100];
bool existCat[2];

bool add(int &head) {
  if (head == Na + Nb) { return false; }
  int sex = cats[head].sex;
  existCat[sex] = true;
  for (int i = W; i >= 0; i--) {
    int weight = i + cats[head].weight;
    if (i != 0 && (weight > W || dp[sex][i] == -1)) { continue; }
    if (i == 0) {
      dp[sex][weight] = head;
    } else {
      dp[sex][weight] = max(dp[sex][weight], dp[sex][i]);
    }
  }
  head++;
  return true;
}

bool erase(int &tail) {
  if (tail == Na + Nb) { return false; }
  int sex = cats[tail].sex;
  bool exist = false;
  FOREQ(i, 1, W) {
    if (dp[sex][i] == tail) { dp[sex][i] = -1; }
    if (dp[sex][i] != -1) { exist = true; }
  }
  existCat[sex] = exist;
  tail++;
  return true;
}

int main() {
  scanf("%d %d %d", &Na, &Nb, &W);
  MEMSET(dp, -1);
  REP(i, Na) {
    int m, c;
    scanf("%d %d", &m, &c);
    cats[i] = Cat(0, m, c);
  }
  REP(i, Nb) {
    int m, c;
    scanf("%d %d", &m, &c);
    cats[i + Na] = Cat(1, m, c);
  }
  sort(cats, cats + Na + Nb);
  cats[Na + Nb] = Cat(-1, 2000000000, 2000000000);
  ll ans = 2000000000;
  existCat[0] = existCat[1] = false;
  int head = 0;
  int tail = 0;
  while (true) {
    while (!existCat[0] || !existCat[1]) {
      if (!add(head)) { break; }
    }
    if (!existCat[0] || !existCat[1]) { break; }
    ll M = 2000000000;
    ll pm[2] = { -2000000000, -2000000000 };
    FOREQ(i, 1, W) {
      REP(sex, 2) {
        if (dp[sex][i] >= 0) {
          M = min(M, i - pm[sex ^ 1]);
          pm[sex] = i;
        }
      }
    }
    ans = min(ans, max(M, cats[head - 1].cute - cats[tail].cute));
    //cout << head << " " << tail << " " << M << " " << cats[head - 1].cute - cats[tail].cute << endl;
    if (M > cats[head - 1].cute - cats[tail].cute) {
      if (!add(head)) { break; }
    } else {
      if (!erase(tail)) { break; }
    }
  }
  printf("%lld\n", ans);
}

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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)

/////////////////////GCD//////////////////////
ll gcd(ll a, ll b)
{
    if(b==0) return a;
    return gcd(b, a%b);
}


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
    ll x1, y1;
    ll d = extended_gcd(b, a%b, x1, y1);
    x=y1;
    y=x1-y1*(a/b);
    return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
    vector<bool> prime(n+1, true);
    for(int i = 2; i <= sqrt(n); i++)
    {
        if(prime[i])
        {
            for(int j = i*i; j<=n; j+=i)
            {
                prime[j]=false;
            }
        }
    }
    vector<int> all_primes;
    for(int i = 2; i <=n; i++)
    {
        if(prime[i]) all_primes.pb(i);
    }
    return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
    ll ans = 1;
    while(b)
    {
        if(b%2)
        {
            b--;
            ans = (ans%mod*a%mod)%mod;
        }
        b/=2;
        a = (a%mod*a%mod)%mod;
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, c;
    cin>>n>>m;
    // cout<<n<<endl;
    if(n>=13)
    {
        c=m;
    }
    else if(n>=6 and n<=12)
    {
        c=m/2;
    }
    else
    {
        c=0;
    }
    cout<<c<<endl;
}

Measured memory_bytes: 256
a,b,c,d=map(int,list(input()))
l=("+","-")
for q in range(2):
  for w in range(2):
    for e in range(2):
      if a+((-1)**q)*b+((-1)**w)*c+((-1)**e)*d==7:
        print(str(a)+l[q]+str(b)+l[w]+str(c)+l[e]+str(d)+"=7")
        exit()

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		vector<string> s(n);
		for (int i = 0; i < n; i++)
			cin >> s[i];
		for (int i = 1; i < n; i++) {
			int j;
			for (j = 0; s[i][j + 1] == '.'; j++);
			s[i][j] = '+';
			for (int _i = i - 1; s[_i][j] == '.'; _i--)
				s[_i][j] = '|';
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < s[i].length(); j++)
				if (s[i][j] == '.')
					s[i][j] = ' ';
			cout << s[i] << endl;
		}
	}
}

Measured memory_bytes: 1856
#for _ in range(int(input())):
n=int(input())
a=[int(x) for x in input().split()]  


p=[]
r=0
for x in a[::-1]:
   r+=x
   p.append(r)  
  
p=p[::-1]
ans=0
for i in range(0,n-1):

    ans+=(a[i]*p[i+1])
print(ans%1000000007)





Measured memory_bytes: 105016
def check(n, H, A, B):
    s = 0
    for h in H:
        s += max(-(-(h - n*B) // (A-B)), 0)
    if s <= n:
        return True
    else:
        return False


def main():
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    left = 0
    right = int(1e9)
    while left < right:
        center = (left + right) // 2
        if check(center, H, A, B):
            right = center
        else:
            left = center + 1
    print(left)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7072
a = input()

def main():
    ed = []
    for i in range(int(a)):
        neww = input()
        if i != 0:
            if ed[i-1][-1] != neww[0] or neww in ed:
                return 'No'
        ed.append(neww)

    return 'Yes'
                

if __name__ == '__main__':
    print(main())



Measured memory_bytes: 3316
n = int(input())
h = list(map(int, input().split()))

def cost(i,j):
    return abs(h[i] - h[j])

dp={}

dp[0]=0
dp[1]=cost(0,1)


for i in range(2,n):
    dp[i]=min(
        dp[i-1]+cost(i-1,i),
        dp[i-2]+cost(i-2,i)
    )

print(dp[n-1])

Measured memory_bytes: 23312
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(k==u->key && u==NIL) return u;
  else if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node a;
  if(x->right!=NIL) return treeMinimum(x->right);
  a=x->parent;
  while(x==a->right && a!=NIL){
    x=a;
    a=a->parent;
  }
  return a;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->right==NIL || z->left==NIL)  y=z;
  else y=treeSuccessor(z);
  if(y->left!=NIL) x=y->left;
  else x=y->right;
  if(x!=NIL) x->parent = y->parent;
  if(y->parent==NIL) root=x;
  else if(y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;
  if(y!=z) z->key=y->key;
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else if(z->key<y->key) y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

int main() {
  int A,B,C,X,Y,S=0;
  cin >> A >> B >> C >> X >> Y;
  
  if(A+B<=C*2){
    cout << A*X+B*Y << endl;
  }
  else{
    if(X>=Y){
      S+=C*2*Y;
      X=X-Y;
      if(A>=C*2){
        S+=C*2*X;
      }
      else{
        S+=A*X;
      }
    }
    else{
      S+=C*2*X;
      Y=Y-X;
      if(B>=C*2){
        S+=C*2*Y;
      }
      else{
        S+=B*Y;
      }
    }
    cout << S << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int arr[5],j=0;
  	for(int i=0;i<5;i++)
    {	
      	cin>>arr[i];
      	if(arr[i]==0)
        	j=i+1;
    }
  	cout<<j<<"\n";  	
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    ll r = 0;
    vector<vector<ll>> b(n,vector<ll>(21,0));
    vector<ll> rec(21,0);
    rep(i,n){
        rep(j,20){
            if (a[i]&(1ll<<j)) b[i][j]++;
        }
    }
    ll ans = 0;
    rep(l,n){
        bool ok = 1;
        while(ok && r < n){
            rep(k,20){
                if (rec[k]+b[r][k] > 1) ok = 0;
            }
            if (ok){
                rep(k,20) rec[k] += b[r][k];
                r++;
            }
        }
        ans += r-l;
        rep(i,21){
            rec[i] -= b[l][i];
        }
    }
    PRINT(ans);
}


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

using namespace std;

int
main(void){
	int f = 0, s = 0;
	vector<int> vec(3);
	for(int i = 0; i < 3; i++) cin >> vec[i];
	for(int i = 0; i < 3; i++){
		if(vec[i] == 5) f++;
		else if(vec[i] == 7) s++;
	}
	if(f == 2 && s == 1) cout << "YES";
	else cout << "NO";
}

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

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = c / b;
	if (c % b != 0)
		x++;
	int y = a / d;
	if (a % d != 0)
		y++;
	if (x <= y)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

map <P,ll> m;
ll used[55];
ll x[55];
ll y[55];
ll co;

void sol(ll k,ll p,ll q){
  if(m[P(x[k],y[k])]!=1) return; 
  else {
    co++;
    used[k]=1;
    ll xx=x[k];
    ll yy=y[k];
    while(m[P(xx,yy)]==1){
      m[P(xx,yy)]++;
      xx+=p;
      yy+=q;
    }
    xx=x[k]-p;
    yy=y[k]-q;
    while(m[P(xx,yy)]==1){
      m[P(xx,yy)]++;
      xx-=p;
      yy-=q;
    }
    return;
  }
}

int main(){
  ll i,j,k;
  ll n;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>x[i]>>y[i];
  }


  ll ans=1e8;
  if(n==1) {
    cout<<1<<endl;
    return 0;
  }


  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(k=0;k<n;k++){
        m[P(x[k],y[k])]=1;
      }
      for(k=0;k<n;k++) used[k]=0;
      ll p=x[j]-x[i];
      ll q=y[j]-y[i];
      co=0;
      for(k=0;k<n;k++){
        sol(k,p,q);
      }
      ans=min(ans,co);
    }
  }
  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> x(M), y(M);
    REP(i, M){
        scanf("%d %d", &x[i], &y[i]);
    }
    vector<int> r(N), sum(N);
    REP(i, N){
        r[i] = 0;
        sum[i] = 1;
    }
    r[0] = 1;

    REP(i, M){
        x[i]--; y[i]--;
        if(r[x[i]] == 0){
            sum[x[i]]--;
            sum[y[i]]++;
        }else{
            if(sum[x[i]] == 1){
                r[x[i]] = 0;
                r[y[i]] = 1;
                sum[x[i]]--;
                sum[y[i]]++;
            }else{
                r[y[i]] = 1;
                sum[x[i]]--;
                sum[y[i]]++;
            }
        }
    }
    int ans = 0;
    REP(i, N){
        if(r[i] == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.buffer.readline

n,Q = map(int,input().split())
c = [0] + list(map(int,input().split()))
dg = 10**6
dg2 = 10**12
res = [0]*Q
LRI = []
for i in range(Q):
    l,r = map(int,input().split())
    LRI.append(l*dg2 + r*dg + i)
LRI.sort()

#A1 ... AnのBIT(1-indexed)
BIT = [0]*(n+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return

fi = [[] for i in range(n+1)]
nxt = [-1]*(n+1)
for i in range(1,n+1):
    num = c[i]
    if len(fi[num]) == 0:
        BIT_update(i,1)
    else:
        nxt[fi[num][-1]] = i
    fi[num].append(i)

idx = 0

for i in range(1,n+1):

    while idx < Q:
        l,ri = divmod(LRI[idx],dg2)
        if l != i:
            break
        r,resi = divmod(ri,dg)
        res[resi] = BIT_query(r)
        idx += 1
    BIT_update(i,-1)
    if nxt[i] != -1:
        BIT_update(nxt[i],1)


print(*res,sep='\n')


Measured memory_bytes: 188512
#include<bits/stdc++.h>
    #define _USE_MATH_DEFINES
    using namespace std;
    
    #define ll long long int
    #define pb push_back
    #define rep(i , j , n) for(ll i = j ; i < n ; i++)
    #define per(i , j , n) for(ll i = j ; i >= n ; i--)
    #define all(x) x.begin(), x.end()
    typedef pair<int, int>	pii;
    typedef pair<ll, ll>	pl;
    typedef vector<int>		vi;
    typedef vector<ll>		vll;
    typedef vector<bool>	vb;

vll v(100005,0);


int main(){ 
    ll n;
    cin >> n;
    ll sum = 0;
    rep(i,0,n){
        ll x;
        cin >> x;
        v[x]++;
        sum += x;
    }
    ll q;
    cin >> q;
    rep(i,0,q){
        ll a,b;
        cin >> a >> b;
        sum += v[a]*(b - a);
        cout << sum << endl;
        v[b] += v[a];
        v[a] = 0;
    }

}

Measured memory_bytes: 3904
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iterator>
#include <numeric>
#include <functional>
#include <climits>



using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

int main(int argc, char *argv[]){
  string buf;
  cin >> buf;

  int x = 0;
  int y = 0;
  stack<int> st;
  priority_queue<pii, vector<pii>, greater<pii> > q;
  for (size_t i = 0; i < buf.size(); i++) {
    char c = buf[i];
    x++;
    switch(c){
    case '/':
      y++;
      if(!st.empty()){
        q.push(pii(st.top(), x));
        st.pop();
      }
      break;
    case '\\':
      y--;
      st.push(x);
      break;
    }
  }
  vector<int> ret;
  int total = 0;
  while(!q.empty()){
    pii p1 = q.top(); q.pop();
    int s = p1.second - p1.first;
    while(!q.empty() && q.top().second < p1.second){
      pii p2 = q.top(); q.pop();
      s += p2.second - p2.first;
    }
    ret.push_back(s);
    total += s;
  }
  cout << total << endl;
  if(ret.size() == 0){
    cout << ret.size() << endl;
    return 0;
  } else{
    cout << ret.size() << " ";
    for (size_t i = 0; i < ret.size()-1; i++) {
      cout << ret[i] << " ";
    }
    cout << ret.back() << endl;
  }
  return 0;
}

Measured memory_bytes: 1380
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b,c,d;
signed main()
{
	cin>>a>>b>>c>>d;
	if((a*b)%2==0){
		cout<<a*b/2<<".000000000";
	}else{
		cout<<a*b/2<<".500000000";
	}
	if(a%2==0&&b%2==0&&a/2==c&&b/2==d){
		cout<<" "<<1;
	}else{
		cout<<" "<<0;
	}
}

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

using namespace std;
#define ll long long
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define _all(a) a.begin(), a.end()

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int inf = 1e9 + 7;
const ll linf  = 1ll * inf * inf;
const int N = 1e5 + 7;
const int M = 51;
const int multipleTest = 0;

int gcd(int a, int b) {
	return a ? gcd(b % a, a) : b;
}

int nxt(int last, int mod) {
	while (last % 6 != mod) {
		++last;
	}
	return last;
}

void solve() {
	int n; cin >> n;
	if (n == 3) cout << "2 5 63";
	else if (n == 4) cout << "2 5 20 63";
	else if (n == 5) cout << "2 5 20 63 90";
	else {
		set<int> res;
		int sum = 0;
		for (int i = 2; n > sz(res); ++i) {
			if (i % 2 == 0 || i % 3 == 0) {
				res.insert(i);
				sum += i;
			}
		}
		int last = *res.rbegin() + 1;
		if (sum % 6 == 2) {
			res.erase(8);
			res.insert(nxt(last, 0));
		} else if (sum % 6 == 3) {
			res.erase(9);
			res.insert(nxt(last, 0));
		} else if (sum % 6 == 5) {
			res.erase(9);
			res.insert(nxt(last, 4));
		}
		for (int x : res) cout << x << ' ';
	}
}

int main() {
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin);
	//    freopen("out.txt", "w", stdout);
#endif
	int Test = 1;
	if (multipleTest) {
		cin >> Test;
	}
	for(int i = 0; i < Test; ++i) {
//		printf("Case #%d: ", i + 1);
		solve();
	}
#ifdef _LOCAL_
		cout << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}



Measured memory_bytes: 1788
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        String str=buf.readLine();
        double x=Double.parseDouble(str);
    
        String f=String.format("%.6f",(double)x*(double)x*3.141592653589);
        String t=String.format("%.6f",(double)x*2*3.141592653589);
        System.out.println(f+" "+t);
    }
}

Measured memory_bytes: 24784
#include <stdio.h>

int main(void){
    int maxBenefit=-2000000000,min,size,i,price;
    scanf("%d",&size);
    scanf("%d",&min);

    for(i=1;i<=size-1;i++){
        scanf("%d",&price);
        maxBenefit=maxBenefit>(price-min)?maxBenefit:(price-min);//更新最大利益：比较当前值与此前最小值的差和此前的最大利益
        min=min<price?min:price;//更新最小值
    }

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




Measured memory_bytes: 2108
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> //required
//#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define lb long double
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
//using namespace __gnu_pbds;

int main(){
	IOS;
	ll n, k;
	cin >> n >> k;
	ll a[n + 1];
	loop(i, 1, n + 1)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	ll ans = 0;
	loop(i, 1, k + 1)
		ans += a[i];
	cout << ans << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    cin >> n;
    if (n % 2 == 0)
        cout << n/2 - 1 << endl;
    else
        cout << n/2 << endl;
    return 0;
}




Measured memory_bytes: 256
H,W = map(int,input().split())
s = [input() for _ in range(H)]

DP = [[1000]+[0]*W for _ in range(H+1)]
re = [[0]*(W+1) for _ in range(H+1)]
DP[0] = [1000]*(W+1)
DP[0][1] = DP[1][0] = 0

for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i-1][j-1] == ".":
            DP[i][j] = min(DP[i-1][j],DP[i][j-1])
        else:
            u = DP[i-1][j]+1-re[i-1][j]
            l = DP[i][j-1]+1-re[i][j-1]
            DP[i][j] = min(u, l)
            re[i][j] = 1

print(DP[H][W])


Measured memory_bytes: 3188
#include<stdio.h>
int main()
{
	int N;scanf("%d",&N);
	int r=0,p,v;
	for(int i=0;i<N;i++)
	{
		p=v;
		scanf("%d",&v);
		if(p==v)r=r+1,v=0;
	}
	printf("%d",r);
	return 0;
}

Measured memory_bytes: 128
import math

A, B = map(int, input().split())
min1 = math.floor(A * 25/2)
max1 = math.ceil((A + 1) * 25/2)
ans_lis = []
ans1 = False
ans2 = False
for i in range(min1, max1):
  if A == math.floor(i * 2/25):
    ans1 = True
    ans_lis.append(i)
for x in ans_lis:
  if B == math.floor(x * 1/10):
    ans2 = True
    ans = x
    break
if ans1 == True and ans2 == True:
  print(x)
else:
  print(-1)

Measured memory_bytes: 9204
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
inf = float("inf")
N, M, L = map(int, input().split())
graph = np.zeros((N, N))
for _ in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C
shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="FW")
graph = np.full((N, N), inf)
for i in range(N):
    for j in range(N):
        if shortest_paths[i][j] <= L:
            graph[i][j] = 1

Q = int(input())
def int_(num_str):
    return int(num_str) - 1

costs = shortest_path(csr_matrix(graph), directed=False, method="FW")
for _ in range(Q):
    s, t = map(int_, input().split())
    print(int(costs[s][t])-1 if costs[s][t] != inf else -1)

Measured memory_bytes: 19284
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N; cin >> N;
    vector<ll> a(N);
    rep(i,N) cin>>a[i];
    for(int i=1;i<N;i++) a[i] += a[i-1];

    ll sum = a[N-1];
    ll ans = LINF;
    for(int i=0;i<N-1;i++){
        ll x = a[i];
        ll y = sum - x;

        ans = min(ans,abs(x-y));
    }
    cout << ans << endl;
}


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

namespace abc119d
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Readlong();
            var ABCDE = new long[5];
            for (long i = 0; i < 5; i++)
            {
                ABCDE[i] = Readlong();
            }
            var min = ABCDE.Min();
            var ans = 5 + N / min;
            if (N % min == 0)
            {
                ans--;
            }
            
            Console.WriteLine(ans);
#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(long a, long from, long to) => (from <= a && a <= to);
        private static long Readlong() => long.Parse(Console.ReadLine());
        private static List<long> ReadlongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static double ReadDouble() => double.Parse(Console.ReadLine());
        private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList();
        private static long ReadLong() => long.Parse(Console.ReadLine());
        private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static List<long> long2Digits(long a) => a.ToString().ToCharArray().Select(_ => long.Parse(_.ToString())).ToList();
        private static long BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す
            where Type : IComparable
        {
            var lower = 0;
            var upper = s.Count - 1;
            while (upper - lower > 1)
            {
                var mid = lower + (upper - lower) / 2;
                if (s[mid].CompareTo(target) <= 0)
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }

            }
            return lower;
        }
    }
}


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

lli k, a, b;

int main(void){
	cin >> k >> a >> b;
	if(k <= a){
		cout << 1+k << endl;
		return 0;
	}
	lli ans = 1;
	if(b < 2+a){
		ans+=a+1;
	}else{
		ans=b;
	}
	k=max(0LL, k-a-1);
	ans += (k/2*max(2LL, b-a) + k%2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int n;
  ll m;
  cin >> n >> m;
  vector<ll> a(n);
  ll ans = 0;
  map<ll,int> cnt;
  rep(i, n){
    cin >> a[i];
    a[i] %= m;
  }
  rep(i, n-1){
    a[i + 1] = (a[i] + a[i + 1]) % m;
  }
  rep(i, n){
    ans += cnt[a[i]];
    cnt[a[i]]++;
    if(a[i] == 0)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7860
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int a, b;
  cin >> a >> b;
  cout << a * b << "\n";
}



Measured memory_bytes: 3652
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    com_left = [0] * (N+1)
    com_right = [0] * (N+1)
    total = sum(A)
    for i in range(N):
        com_left[i+1] = com_left[i] + A[i]
        com_right[i] = total - com_left[i]
    ans = 2020202020
    for i in range(N):
        diff = abs(com_left[i] - com_right[i])
        ans = min(ans, diff)
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 82124
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
ll xpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		ll k = xpow(a, b / 2);
		return k * k;
	}
	if (b % 2 != 0)
		return a * xpow(a, b - 1);
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	fio;
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	sort(v.begin(), v.end());
	int cnt = 0;
	set<vector<int>> ans;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (v[i] + v[j] > v[k] and v[j] + v[k] > v[i] and v[i] + v[k] > v[j]) {
					/*set<int> s;
					s.insert(v[i]);
					s.insert(v[j]);
					s.insert(v[k]);
					if (s.size() == 3) {
						int a = v[i];
						int b = v[j];
						int c = v[k];
						vector<int> ve = {a, b, c};
						sort(ve.begin(), ve.end());
						ans.insert(ve);
					}*/
					int a = v[i], b = v[j], c = v[k];
					//cout << a << " " << b << " " << c << endl;
					//cout << i + 1 << " " << j + 1 << " " << k + 1 << endl;
					vector<int> ve = {i + 1, j + 1, k + 1};
					sort(ve.begin(), ve.end());
					if (a != b and b != c and a != c)
						ans.insert(ve);
				}
			}
		}
	}
	cout << ans.size() << endl;
	return 0;
}

Measured memory_bytes: 18816
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n, a, b;
llong h[100005];

bool check(llong k) {
    llong t = k;
    for (int i = 0; i < n; i++) {
        llong valid = k;
        llong invalid = -1;

        while (valid - invalid > 1) {
            llong mid = (valid + invalid) / 2;
            
            if (mid * a + (t - mid) * b >= h[i]) {
                valid = mid;
            }
            else {
                invalid = mid;
            }
        }

        if (valid * a + (t - valid) * b < h[i]) return false;

        k -= valid;
    }

    return true;
}

int main() {

    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    llong valid = 1ll << 33ll;
    llong invalid = -1;
    while (valid - invalid > 1) {
        llong mid = (valid + invalid) / 2;
        if (check(mid)) {
            valid = mid;
        }
        else {
            invalid = mid;
        }
    }

    cout << valid << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

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

class RMQ{
	int seg;
	vector<P> dat;
	public:
	RMQ(int siz) : seg(1){
		while(seg < siz) seg *= 2;
		dat.resize(seg * 2 - 1);
		for(int i = 0;i < seg * 2 - 1;i++) dat[i] = P(0,0);
	}
	void update(int a,int b,P x,int k = 0,int l = 0,int r = -1){
		if(r == -1) r = seg;
		if(b <= l || r <= a) return;
		if(a <= l && r <= b) {
			dat[k] = max(dat[k],x);
			return;
		}
		update(a,b,x,k * 2 + 1,l,(l + r) / 2);
		update(a,b,x,k * 2 + 2,(l + r) / 2,r);
	}
	int get(int i){
		i += seg - 1;
		P ret = dat[i];
		while(i){
			i = (i - 1) / 2;
			ret = max(dat[i],ret);
		}
		return ret.second;
	}
};

class EulerTour{
	int cnt;
	vector<int> first,last,depth;
	vector<vector<int> > g;
	public:
	EulerTour(int siz) : first(siz),last(siz),g(siz),depth(siz){}
	void add(int u,int v){
		g[u].push_back(v);
		g[v].push_back(u);
	}
	void dfs(int v,int par){
		if(par == -1) depth[v] = 0;
		else depth[v] = depth[par] + 1;
		first[v] = cnt++;
		for(int to : g[v]){
			if(to == par) continue;
			dfs(to,v);
		}
		last[v] = cnt++;
	}
	int build(int root){
		cnt = 0;
		dfs(root,-1);
		return cnt;
	}
	P get(int v){
		return P(first[v],last[v]);
	}
	int dep(int v){
		return depth[v];
	}
};

int main(){
	int n,m;
	while(scanf("%d %d",&n,&m),n){
		ll ans = 0ll;
		EulerTour et(n);
		for(int i = 1;i < n;i++){
			int p;
			scanf("%d",&p);
			et.add(i,p - 1);
		}
		RMQ rmq(et.build(0) + 1);
		for(int i = 0;i < m;i++){
			char c;
			int v;
			scanf("\n%c %d",&c,&v); v--;
			if(c == 'M'){
				P p = et.get(v);
				rmq.update(p.first,p.second + 1,P(et.dep(v),v));
			}
			else ans += rmq.get(et.get(v).first) + 1;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 17440
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
 
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N,M=LI()
    A=[]
    for i in range(M):
        A.append(I())

    tmp1=0
    tmp2=0
    tmp3=0
    out=1
    for n in range(N+1):
        # print(n)
        # print(n,A,tmp3)
        if A:
            if n==1 and A[0]==n:
                tmp1=0
                tmp2=0
                tmp3=0
                del A[0]
                if A:
                    if A[0]==n+1:
                        print("0")
                        exit()
                continue
            elif n!=0 and A[0]==n:
                out*=tmp3
                tmp1=0
                tmp2=0
                tmp3=0
                del A[0]
                if A:
                    if A[0]==n+1:
                        print("0")
                        exit()
                continue
        if tmp3==0:
            tmp3=1
        else:
            tmp1=tmp2
            tmp2=tmp3
            tmp3=tmp1+tmp2
        # print("outttt",A,n,tmp3)
    if tmp3>0:
        out*=tmp3
    print(out%1000000007)
if __name__ == "__main__":
    main()


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

int main(){
    long long x,y; cin >> x >> y;
    long long ans=1e11;
    if(-x<=y){
        ans=min(y+x+1,ans);
    }
    if(x<=y){
        ans=min(y-x,ans);
    }
    if(x<=-y){
        ans=min(-y-x+1,ans);
    }
    if(-x<=-y){
        ans=min(-y+x+2,ans);
    }
    cout << ans << 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 rrep(i,n) for(int i = 1; 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 maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<int,P> PP;

vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main()
{
	int n,m[30];
	cin >> n;
	rep(i,n) cin >> m[i];
	int ans =0;
	srep(i,1,n-1){
		int a[3];
		a[0] = m[i-1];
		a[1] = m[i];
		a[2] = m[i+1];
		sort(a,a+3);
		if(a[1] == m[i]) ans++;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;


//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let c: char = read::<String>().chars().next().unwrap();

    let next = (c as u8 + 1) as char;
    println!("{}",next);
}


Measured memory_bytes: 2172
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
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; }

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    std::ifstream in("b.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int n;
    cin >> n;

    vector<int> v(n), c(n);

    rep(i, n) {
        cin >> v[i];
    }
    rep(i, n) {
        cin >> c[i];
    }
    int ans = 0;
    rep(i, n) {
        if (v[i] > c[i])
        {
            ans += v[i] - c[i];
        }
    }
    cout << ans;

    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n][3],vec[n][3]={0};
  for(int i=0;i<n;i++)
  {
     for(int j=0;j<3;j++)
     {
         cin>>arr[i][j];
         if(i==0)
          {
              vec[i][j]=arr[i][j];
          }
          if(i>0)
          {
            vec[i][j%3]=arr[i][j%3]+max(vec[i-1][(j+1)%3],vec[i-1][(j+2)%3]);
         }
      }
  }
  int m = INT_MIN;
  for(int i=0;i<3;i++)
  {
    if(vec[n-1][i]>m)
    {
        m=vec[n-1][i];
    }
  }
  cout<<m;
}


Measured memory_bytes: 2688
a = gets.chomp.split(' ')

result1 = ''
result2 = ''

if a[0].to_i == a[1].to_i
  for num in 0..a[0].to_i - 1 do
    result1 = result1 + a[0]
  end
  puts result1
else
  for num in 0..a[1].to_i - 1 do
    result1 = result1  + a[0]
  end

  for num in 0..a[0].to_i - 1 do
    result2 = result2  + a[1]
  end

  if result1[0] > result2[1]
    puts result2
  else
    puts result1
  end
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define mp(a, b) make_pair(a, b)
#define newline cout << endl;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(),v.end()
using namespace std;

template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p)
{
    out << '(' << p.ff << ", " << p.ss << ')';
    return out;
}

template <typename T> ostream& operator<<(ostream& out, vector<T> const& v)
{
    int l = v.size();
    for (int i = 0; i < l - 1; i++)
        out << v[i] << ' ';
    if (l > 0)
        out << v[l - 1];
    return out;
}

template <typename T> void trace(const char* name, T&& arg1) { cout << name << " : " << arg1 << endl; }

template <typename T, typename... Args> void trace(const char* names, T&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    trace(comma + 1, args...);
}

/*Input*/
ll n,k;
const ll vsize = 1e6+100;
vector<ll> v(vsize), cost(vsize);
/*Input*/

int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    clock_t tStart = clock();
    int test;
    test = 1;
    /* cin >> test; */
    while (test--) {
        cin >> n >> k;
        for(int i = 0; i < n; i++){
            cin >> v[i];
        }
        cost[0] = 0;
        for(int i = 1; i < n; i++){
            cost[i] = 1e9;
            for(int j = i-1; j >= i-k && j >= 0; j--){
                cost[i] = min(cost[i], cost[j] + abs(v[i] - v[j]));
            }
        }
        cout << cost[n-1] << "\n";
    }
#ifdef LOCAL_DEFINE
    printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
#endif
    return 0;
}









Measured memory_bytes: 18640