akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    string s;
    cin >> a >> b >> s;
    bool ans = s[a] == '-';
    for(int i = 0; i < a; i++) {
        ans &= isdigit(s[i]);
    }
    for(int i = 0; i < b; i++) {
        ans&= isdigit(s[a + 1 + i]);
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.array;
import std.algorithm;
import std.conv;

void main() {
    auto buf = readln.chomp.split.map!(x => x.to!int);
    int N = buf[0];
    int x = buf[1];
    ulong[] a = readln.chomp.split.map!(x => x.to!ulong).array;

    ulong count = 0;

    foreach(i; 0 .. N) {
        if (i == 0) {
            if (a[i] > x) {
                count += a[i] - x;
                a[i] -= count;
            }
            continue;
        }
        ulong sum = a[i-1] + a[i];
        if (sum > x) {
            count += sum - x;
            a[i] -= sum - x;
        }
    }
    writeln(count);
}


Measured memory_bytes: 3784
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define INF 100000000

const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;

ll gcd(ll a, ll b) {
    ll tmp, r;
    if(a<b) {
        tmp = a;
        a = b;
        b = tmp;
    }

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

    return b;
}

int main(void) {
	ll k, sum=0;
	cin >> k;
	for(ll a=1;a<k+1;a++) {
	  for(ll b=1;b<k+1;b++) {
		for(ll c=1;c<k+1;c++) {
          sum += gcd(gcd(a,b), c);
		}
	  }	
	}

	cout << sum << endl;
}


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

int main(){
	string s;
	cin>>s;
	s+='R';
	int p=-1,i,j=-1,q;
	//  RRR LLL
	for(int t=0;t<s.length();++t){
		if(s[t]=='R'){
			if(j==-1){//R part
				if(p==-1){p=t;}
			}else{//RL complete, calculate
				q=t-1;
//				printf("p=%d i=%d j=%d q=%d\n",p,i,j,q);
				for(int f=p;f<i;++f)printf("0 ");
				printf("%d ",1+(i-p)/2+(q-j)-(q-j)/2);
				printf("%d ",1+(q-j)/2+(i-p)-(i-p)/2);
				for(int f=j+1;f<=q;++f)printf("0 ");
				j=-1;
				p=t;
			}
		}else{
			if(j==-1){//L part
				i=t-1;
				j=t;
			}
		}
	}
    return 0;
}


Measured memory_bytes: 640
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define int long long
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (ll i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((ll)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <ll, ll> pii ;
typedef vector <ll> vi ;
typedef vector <pii> vii ;
typedef queue <ll> qi ;
typedef queue <pii> qii ;
typedef set <ll> si ;
typedef map <ll, ll> mii ;
typedef map <string, ll> msi ;
const ll maxn = 2e6 + 100 ;
const ll inf = 0x3f3f3f3f ;
const ll iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 998244353 ;
const double eps = 1e-7 ;
template <class T = ll> T chmin(T &a, T b) { return a = min(a, b);}
template <class T = ll> T chmax(T &a, T b) { return a = max(a, b);}
template <class T = ll> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

int n;

char s[maxn];

vi edge[maxn];

int ans = linf;

int sum[maxn], f[maxn];

void dfs(int now, int fa)
{
	sum[now] = s[now] == '1', f[now] = 0;
	for(int to : edge[now])
	{
		if(to == fa) continue;
		dfs(to, now);
		sum[now] += sum[to], f[now] += f[to] + sum[to];
	}
}

int check(int now, int fa)
{
	int pos = 0;
	for(int to : edge[now])
	{
		if(to == fa) continue;
		if(!pos || f[to] > f[pos]) pos = to;
	}
	if(!pos) return 0;
	int tmp = check(pos, now) + sum[pos];
	if(f[now] - f[pos] - sum[pos] >= tmp) return f[now] & 1;
	return tmp - (f[now] - f[pos] - sum[pos]);
}

signed main()
{
	n = read();
	scanf("%s", s + 1);
	rep(i, 1, n - 1)
	{
		int u = read(), v = read();
		edge[u].pb(v), edge[v].pb(u);
	}
	rep(i, 1, n)
	{
		dfs(i, 0);
		if(!check(i, 0)) ans = min(ans, f[i] / 2);
	}
	printf("%lld\n", ans == linf ? -1 : ans);
	return 0;
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key,vi a) {
    int left = -1;
    int right = (int)a.size();
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        
        if (isOK(mid, key,a)) right = mid;
        else left = mid;
    }
    return right;
}

int modpow(int a,int b,int p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    char A[h][w];
    bool pass[h][w];
    rp(i,h){
        cin>>A[i];
        rp(j,w){
            pass[i][j]=(A[i][j]=='#'?false:true);
        }
    }
    int x=0;
    rp(i,h){
        while(x<w){
            pass[i][x]=true;
            if(i==h-1&&x==w-1){
                break;
            }elif(i==h-1&&x<w-1){
                if(A[h-1][x+1]=='#'){
                    x++;
                }else{
                    cout << "Impossible" << endl;
                    return 0;
                }
            }elif(i<h-1&&x==w-1){
                if(A[i+1][w-1]=='#'){
                    break;
                }else{
                    cout << "Impossible" << endl;
                    return 0;
                }
            }else{
                if(A[i+1][x]=='#'){
                    if(A[i][x+1]=='.'){
                        break;
                    }else{
                        cout << "Impossible" << endl;
                        return 0;
                    }
                }elif(A[i][x+1]=='#'){
                    if(A[i+1][x]=='.'){
                        x++;
                    }else{
                        cout << "Impossible" << endl;
                        return 0;
                    }
                }else{
                    cout << "Impossible" << endl;
                    return 0;
                }
            }
        }
    }
    bool all_ok=true;
    rp(i,h){
        rp(j,w){
            if(pass[i][j]==false){
                all_ok=false;
            }
        }
    }
    if(all_ok){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

N, C  = map(int, input().split())
x_cw = []   # 時計
x_acw = []  # 反時計
v_cw = []     # 寿司
for i in range(N):
    x,v = map(int, input().split())
    x_cw.append(x)
    v_cw.append(v)
v_acw = v_cw[::-1]
x_acw = [C - x for x in x_cw[::-1]]
x_cw = [0] + x_cw
x_acw = [0] + x_acw
# print(x_cw)
# print(x_acw)
v_cw1 = [v_cw[i]-(x_cw[i+1]-x_cw[i]) for i in range(N)]        # 時計回り折り返さない
v_cw2 = [v_cw[i]-2*(x_cw[i+1]-x_cw[i]) for i in range(N)]     # 時計回り折返しが入るとき
v_acw1 = [v_acw[i]-(x_acw[i+1]-x_acw[i]) for i in range(N)]        # 反時計折り返さない
v_acw2 = [v_acw[i]-2*(x_acw[i+1]-x_acw[i]) for i in range(N)]     # 反時計折返しがはいるとき

acc_cw1 = list(accumulate(v_cw1))
acc_acw1 = list(accumulate(v_acw1))
acc_cw2 = list(accumulate(v_cw2))
acc_acw2 = list(accumulate(v_acw2))

acc_acw1 = acc_acw1[::-1]
acc_cw1 = acc_cw1[::-1]


max_cw2 = []
m = 0
# 右スタート、左バックパターン
for c in acc_cw2:
    m = max(c,m)
    max_cw2.append(m)
ans_cw = acc_acw1[0] #初期値
for i in range(1,N):
    ans_cw = max(ans_cw, max_cw2[i-1]+acc_acw1[i])

# 左スタート、右バックパターン
m = 0
max_acw2 = []
for c in acc_acw2:
    m = max(c, m)
    max_acw2.append(m)
ans_acw = acc_cw1[0] # 初期値 
for i in range(1,N):
    ans_acw = max(ans_acw, max_acw2[i-1]+acc_cw1[i])
ans = max(ans_acw,ans_cw)
print(max(0,ans))


Measured memory_bytes: 96984
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  ll n,k;
  cin >> n >> k;
  ll cnt = 0,cnts = 0;
  ll ans = 0;
  if(k % 2 == 1){
    cnt += n/k;
    ans += cnt*cnt*cnt;
  }
  else{
    for(int i = 1; i <= n; i++){
      if(i%k == 0) cnt++;
      if(i%k == k/2) cnts++;
    }
    ans += cnt*cnt*cnt;
    ans += cnts*cnts*cnts;
  }
    
  cout << ans << endl;
  
}

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

typedef vector<int> vi;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii > vii;
typedef vector<vi > vvi;

int a, f, s, d;
int x, y, z, afs;
int main(){
    cin >> a >> f >> s >> d;
    x = max(a,s);
    y = min(f,d);
    afs = y - x;
    if(afs < 0) puts("0");
    else
        cout << afs << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (l, r) = readLine()!!.split(' ').map(String::toLong)
    if (r - l >= 2019) {
        println(0)
        return
    }
    var min = Long.MAX_VALUE
    for (i in l until r) {
        for (j in (l + 1)..r) {
            min = Math.min(min, ((i) * (j) % 2019))
        }
    }
    println(min)
}

Measured memory_bytes: 38336
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < (ll) b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= (ll) b ; i-= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nuintptr)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX= 3e3+6;
const ll inf =1e9;

int main(){
	ll n,m,a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a) cout<<k<<endl;
	else if(k<=(a+b)) cout<<a<<endl;
	else cout<<a-(k-a-b)<<endl;
}	

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
using namespace std;


void solve(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> masu(H, vector<char>(W, ' '));

    for(int h=0; h<H; h++){
        string s;
        cin >> s;
        for(int w=0; w<W; w++){
            masu[h][w] = s[w];
        }
    }

    // Hを削減する
    vector<vector<char>> masu2;
    for(int h=0; h<H; h++){
        bool can_delete = true;
        for(int w=0; w<W; w++){
            if(masu[h][w] != '.'){
                can_delete = false;
                break;
            }
        }

        if(!can_delete){
            vector<char> tmp(W);
            for(int w=0; w<W; w++){
                tmp[w] = masu[h][w];
            }
            masu2.push_back(tmp);
        }
    }

    //Wを削減する
    vector<vector<char>> masu3;
    for(int w=0; w<W; w++){
        bool can_delete = true;
        for(int h=0; h<H; h++){
            if(masu2[h][w] != '.'){
                can_delete = false;
                break;
            }
        }
/*
        if(!can_delete){
            for(int h=0; h<H; h++){
                masu3.push_back(N, 0);

            }
        }
*/
    }
}

void solve2(){
    int H, W;
    cin >> H >> W;
    vector<string> masu(H);

    for(int h=0; h<H; h++){
        string s;
        cin >> s;
        //masu[h].push_back(s);
        masu[h] = s;
    }

    vector<vector<bool>> printable(H, vector<bool>(W, true));

    // Hを走査
    for(int h=0; h<H; h++){
        bool can_delete = true;
        for(int w=0; w<W; w++){
            if(masu[h][w] != '.'){
                can_delete = false;
            }
        }

        if(can_delete){
            for(int w=0; w<W; w++){
                printable[h][w] = false;
            }
        }
    }

    // Wを走査
    for(int w=0; w<W; w++){
        bool can_delete = true;
        for(int h=0; h<H; h++){
            if(masu[h][w] != '.'){
                can_delete = false;
            }
        }

        if(can_delete){
            for(int h=0; h<H; h++){
                printable[h][w] = false;
            }
        }
    }

    // print
    for(int h=0; h<H; h++){
        int skip_count = 0;
        for(int w=0; w<W; w++){
            if(printable[h][w]){
                printf("%c",masu[h][w]);
            }
            else{
                skip_count++;
            }
        }
        if(skip_count != W){
            printf("\n");
        }
    }
    return;
}

int main(void){
    solve2();
    return 0;
}


Measured memory_bytes: 256
n = int(input())
flag = 0
ans = 0
for i in range(n):
    n1, n2 = map(int, input().split())
    if n1 == n2:
        flag += 1
        ans = max(ans, flag)
    else:
        flag = 0
if ans >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9172
#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(u==NIL||k==u->key)
    return u;
  if(k<u->key)
    return treeSearch(u->left,k);
  else
    return treeSearch(u->right,k);

}

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

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL || z->right==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)
    return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}
void preorder(Node u){
  if(u==NIL)
    return;
  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: 25136
#include <bits/stdc++.h>
#define INF 114514810
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)

using namespace std;

double a[12], sum = 0;

int main(){
	while (cin >> a[0]){
		FOR(i, 1, 10){
			if (!(i % 2)) a[i] = a[i - 1] / 3;
			else a[i] = a[i - 1] * 2;
		}
		REP(i, 10) sum += a[i];
		cout.precision(10);
		cout << sum << endl;
		sum = 0;
	}
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define ll  long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
bool sortinrev(const pair<pair<string,ll>,ll> &a,
               const pair<pair<string,ll>,ll> &b)
{    if(a.f.f==b.f.f)
            return (a.f.s>b.f.s);
     return (a.f.f<b.f.f);
}
void solve()
{   ll n,m,k,y,x,res=0,l,cnt0=0,z,sum1=0,cnt1=0,h,res1,cnt=0,sum=0;
    cin>>n;
    res=0;
    rep(i,0,n)
    {
        cin>>x;
        res=max(res,x);
        sum+=x;
    }
    sum-=res;
    if(sum>res)
        cout<<"Yes";
    else
        cout<<"No";

}
int main()
{   speed_up
    ll t;
   //cin>>t;
    t=1;
    while(t--)
        solve();
}


Measured memory_bytes: 256
# ABC095C
A,B,C,X,Y=map(int,input().split())

minp=10**9+1
for i in range(X+1):
    p=0
    p+=A*i
    numab=(X-i)*2
    p+=numab*C
    p+=max(0,(Y-X+i))*B
    minp=min(minp,p)
for i in range(Y+1):
    p=0
    p+=B*i
    numab=(Y-i)*2
    p+=numab*C
    p+=max(0,(X-Y+i))*A
    minp=min(minp,p)
    
print(minp)

Measured memory_bytes: 39664
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
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();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	int n;
	cin>>n;
	REP(i,n){
		int y,m,d;
		cin>>y>>m>>d;
		int cnt=0;
		while(y!=1000||m!=1||d!=1){
			cnt++;
			d++;
			int maxd=(m%2?20:19);
			if(y%3==0){
				maxd=20;
			}
			if(d>maxd){
				d=1;
				m++;
				if(m>10){
					m=1;
					y++;
				}
			}
		}
		cout<<cnt<<endl;
	}
}

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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> num(N);
	for (int i = 0; i < N; i++)num[i] = -1;
	int s, c;

	for (int i = 0; i < M; i++) {
		cin >> s >> c;
		if (num[s - 1] == -1)num[s - 1] = c;
		else {
			if (num[s - 1] != c) {
				cout << -1;
				return 0;
			}
		}

	}
	if (num[0] == 0) {
		if (N != 1) {
			cout << -1;
			return 0;
		}
	}
	for (int i = 0; i < N; i++) {
		if (num[i] == -1)num[i] = 0;
	}
	if (num[0] == 0) {
		if (N != 1)num[0] = 1;
	}

	for (int i = 0; i < N; i++)cout << num[i];

	return 0;
}

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

const int maxn = 1e5 + 28;

vector <pair<int, int>> v;
bool mark[maxn];
long long ans, sum;
stack <int> v2;
int type;

int main() {
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		v.push_back({ y, x });
	}
	sort(v.rbegin(), v.rend());
	for (int i = 0; i < k; i++) {
		sum += v[i].first;
		if (!mark[v[i].second]) {
			type++;
			mark[v[i].second] = 1;
		}
		else v2.emplace(v[i].first);
	}
	ans = sum + ((long long)type * type);
	for (int i = k; i < n; i++) {
		sum += v[i].first;
		if (!mark[v[i].second]) {
			type++;
			mark[v[i].second] = 1;
		}
		else v2.emplace(v[i].first);
		if (v2.empty()) break;
		sum -= v2.top();
		v2.pop();
		ans = max(ans, (sum + ((long long)type * type)));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
#include <cstdio>

int main(void)
{
  int i,j,H,W;

  for(;;){
    scanf("%d %d", &H, &W);
    if(H==0&&W==0) break;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	if(j==W-1) printf("#\n");
	if(j!=W-1) printf("#");
      }
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 1016
import java.util.*

fun main() {
    val n = nextInt()
    nextLine()
    val a = IntArray(n){nextInt()}
    val count = IntArray(n+1)
    var total = 0L
    for (i in a) {
        total += count[i]
        count[i]++
    }
    println(buildString {
        for (i in 0 until n) {
            append(total - (count[a[i]] - 1)).append('\n')
        }
    })
}

val scanner = Scanner(System.`in`)
fun next(): String = scanner.next()
fun nextInt() = scanner.nextInt()
fun nextLong() = scanner.nextLong()
fun nextLine() = scanner.nextLine()
fun nextList() = nextLine().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")

fun main(args: Array<String>) = main()

Measured memory_bytes: 76468
#include<bits/stdc++.h>
using namespace std;
#define PI          acos(-1)
#define INF         100000000
#define sc(n)       scanf("%d",&n);
#define ssc(n)      scanf("%s",n);
#define lsc(n)      scanf("%lld",&n);
#define dsc(n)      scanf("%lf",&n);
#define csc(n)       scanf("%c",&n);
#define LL          long long int
#define UI          unsigned int
#define ULL         unsigned long long int
#define DB          double
#define pii         pair<int,int>
#define VI          vector<int>
#define MII         map<int,int>
#define PB          push_back
#define MP          make_pair
#define M(mx,a)     mx=max(mx,a)
#define IT          ::iterator
#define all(a)      a.begin(),a.end()
#define mems(a,b)   memset(a,b,sizeof(a))
#define F(i,a,b)    for(i=a;i<b;i++)
#define IN(n,aa)    for(i=0;i<n;i++)scanf("%d",&aa[i]);
#define PNT(n,aa)   for(i=0;i<n;i++)printf("%lld ",aa[i]);
#define mod         1000000007
#define NUM         10000009
#define NUM2        1000000000


int main()
{
    int T=1,QQ=0;
    //cin >> T ;
    while(T--)
    {
        double a,b,c,d;
        cin >> a >> b >> c >> d ;
        cout << setprecision(9) << fixed << a*b/2 << " " ;
        if(c==a/2&&d==b/2)cout << 1;
        else cout << 0;
    }
}

//printf("Case %d: ",++QQ);


Measured memory_bytes: 3732
#include "bits/stdc++.h"
using namespace std;
int main() {
	string S;
	cin >> S;
	vector<int>C(26);
	for (int i = 0; i < S.size(); i++) {
		C.at(S.at(i) - 97)++;
	}
	char ch = 'a';
	for (int i = 0; i < 26; i++) {
		if (C.at(i) == 0) {
			ch += i;
			cout << ch << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
const ll INF = 1LL << 60;
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;

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

ll memo[3000];
ll dfs(ll rem){
    if (memo[rem]!=-1){
        return memo[rem]%MOD;
    }
    if (rem<3) return memo[rem]=0;
    if (rem==3){
        return memo[rem]=1;
    }
    memo[rem]=1;
    for (ll i=rem-3;i>=3;i--){
        memo[rem]+=dfs(i);
        memo[rem]%=MOD;
    }
    return memo[rem];
}

int main() { 
    fill(memo,memo+3000,-1);
    ll n;
    cin >> n;
    dfs(n);
    cout << memo[n] << endl;
    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
using namespace std;
const int MAX=400;
int main(){
    int a,b;
    cin>>a>>b;
    int c;
    if(b<10){
        c=a*10+b;
    }else if(b<100){
        c=a*100+b;
    }else{
        c=a*1000+b;
    }
    
    for(int i=0;i<MAX;i++){
        if(c==i*i){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <list>
//#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
typedef long long ll;

int main(){
    int n,pre,h,flag=0;
    cin >> n;
    cin >> pre;
    FOR(i,1,n){
        cin >> h;
        if(h<pre){
            flag=1;
            break;
        }
        else if(h>=pre+1){ pre = h-1;}
      
    }

    flag ? cout << "No" << endl : cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
    private static final int BIG_NUM = 2000000000;
    private static final int MOD = 1000000007;
    
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String input_str[] = new String[2];
        Deque<String> list = new ArrayDeque<>();
        StringBuilder ans  = new StringBuilder();
        
        try {
            int N = Integer.parseInt(br.readLine());
            
            for(int loop = 0; loop < N; loop++) {
                input_str = br.readLine().split("\\s+");
                
                if(input_str[0].equals("insert")) {
                    list.addFirst(input_str[1]);
                }else if(input_str[0].equals("delete")) {
                    list.remove(input_str[1]);
                }else if(input_str[0].equals("deleteFirst")) {
                    list.removeFirst();
                }else if(input_str[0].equals("deleteLast")) {
                    list.removeLast();
                }
            }
            
            if(!list.isEmpty()) {
                ans.append(list.getFirst());
                list.removeFirst();
            }
            while(!list.isEmpty()) {
                ans.append(" ").append(list.getFirst());
                list.removeFirst();
            }
            
            System.out.println(ans.toString());
        
            
        } catch(NumberFormatException e) {
            e.printStackTrace();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 599800
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int MOD = 998244353;
int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}   
int fp(int a, int p) {
    int ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = mod(ans * c);
        c = mod(c * c);
    }   
    return ans;
}   
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }
void add(int &a, int b) { a = mod(a + b); }

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n;
    cin >> n;
    vector <int> a(n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    vector <int> dp(sum + 1);
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = sum; j >= 0; --j) {
            if (dp[j]) {
                add(dp[j+a[i]],dp[j]);
                add(dp[j],dp[j]);
            }   
        }   
    }   
    int bad = 0;
    for (int x = 0; x <= sum; ++x)
        if (x * 2 >= sum)
            add(bad, dp[x] * 3);
    
    if (sum % 2 == 0) {
        int w = sum/2;
        vector <int> dp1(sum+1);                    
        dp1[0] = 1;
        for (int i = 0; i < n; ++i) {
            for (int j = sum; j >= 0; --j) {
                if (dp1[j]) {
                    add(dp1[j+a[i]],dp1[j]);
                }   
            }   
        }   
        add(bad, -dp1[w]*3);
    }                       

    int all = 1;
    for (int i = 0; i < n; ++i)
        all = mod(all * 3);
    cout << mod(all - bad) << endl;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 100000
int n;
int a[N], b[N];
vector<int> e[N];
int m;
int v[N], p[N];
ll lb[N], ub[N];
bool used[N];

bool dfs(ll u, ll l, ll r, ll &l2, ll &r2){
	if(ub[u]!=INF && (r+ub[u])%2==1) return false;
	chmax(lb[u], l);
	chmin(ub[u], r);
	used[u] = true;
	for(int w: e[u]){
		if(used[w]) continue;
		if(!dfs(w, lb[u]-1, ub[u]+1, lb[u], ub[u])) return false;
	}
	if(lb[u]>ub[u]) return false;
	chmax(l2, lb[u]-1);
	chmin(r2, ub[u]+1);
	return true;
}

int main(){
	cin>>n;
	rep(i, n-1){
		cin>>a[i]>>b[i];
		a[i]--; b[i]--;
		e[a[i]].pb(b[i]);
		e[b[i]].pb(a[i]);
	}
	rep(i, n){
		lb[i] = -INF;
		ub[i] = INF;
	}
	cin>>m;
	rep(i, m){
		cin>>v[i]>>p[i];
		v[i]--;
		lb[v[i]] = ub[v[i]] = p[i];
	}
	ll l, r;
	bool f = true;
	mset(used, 0); f &= dfs(v[0], p[0], p[0], l, r);
	//rep(i, n) cout<<lb[i]<<" "<<ub[i]<<endl;
	mset(used, 0); f &= dfs(v[0], p[0], p[0], l, r);
	mset(used, 0); f &= dfs(v[0], p[0], p[0], l, r);
	if(!f) cout<<"No"<<endl;
	else {
		cout<<"Yes"<<endl;
		rep(i, n) cout<<ub[i]<<endl;
	}
	return 0;
}


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

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

#define all(x) x.begin(), x.end()
#define imie(x) cout << "[" << #x " = " << x << "] "
#define nl cout << "\n"

void solve() {
	ll x, k, d;
	cin >> x >> k >> d;
	ll step = abs(x) / d;
	if(k >= step) {
		ll new_x = abs(x) - (step *d);
		k -= step;
		if(k % 2 == 0) {
			cout << new_x;
		}
		else {
			new_x -= d;
			cout << abs(new_x);
		}
	}
	else {
		ll new_x = abs(x) - (k*d);
		cout << new_x;
	}
}
int main(void) {
    
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
  
    //int t;
    //cin >> t;

	//for(int i = 1; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	//}

	return 0;
}


Measured memory_bytes: 3572
while True:
    m,f,r=map(int,input().split())
    if(m+f+r==-3):
        break
    if(m==-1 or f==-1):
        print('F')
    elif(m+f>=80):
        print('A')
    elif(m+f<80 and m+f>=65):
        print('B')
    elif((m+f<65 and m+f>=50) or r>=50):
        print('C')
    elif(m+f<50 and m+f>=30):
        print('D')
    elif(m+f<30 and m+f>=0):
        print('F')


Measured memory_bytes: 5596
#include <stdio.h>
 
int main(){
  int n,m,l;
  int a[100][100],b[100][100],i,j,k;
 unsigned long int c[100][100];
  scanf("%d %d %d",&n,&m,&l);
  for(i=0; i<n; i++){
    for(j=0; j<m; j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=0; i<m; i++){
    for(j=0; j<l; j++){
      scanf("%d",&b[i][j]);
    }
  }
  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      c[i][j]=0;
    }
  }//----       
 for(i=0; i<n; i++){//                                                         
    for(j=0; j<l; j++){
      for(k=0; k<m; k++){
        c[i][j]+=(a[i][k]*b[k][j]);
      }
    }
  }
  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      if(j==l-1)printf("%ld\n",c[i][j]);
      else printf("%ld ",c[i][j]);
    }
  }
  return 0;
}


Measured memory_bytes: 2144
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] DR = { 1, 0, -1, 0 };
	static int[] DC = { 0, 1, 0, -1 };

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int[] L = new int[N];
			int[] R = new int[N];
			int[] T = new int[N];
			int[] B = new int[N];
			TreeSet<Integer> setX = new TreeSet<Integer>();
			TreeSet<Integer> setY = new TreeSet<Integer>();
			for (int i = 0; i < N; ++i) {
				L[i] = sc.nextInt();
				setX.add(L[i]);
				T[i] = sc.nextInt();
				setY.add(T[i]);
				R[i] = sc.nextInt();
				setX.add(R[i]);
				B[i] = sc.nextInt();
				setY.add(B[i]);
			}
			setX.add(-1);
			setX.add(10000000);
			setY.add(-1);
			setY.add(10000000);
			int[] posX = new int[setX.size()];
			int idx = 0;
			for (int p : setX) {
				posX[idx++] = p;
			}
			int[] posY = new int[setY.size()];
			idx = 0;
			for (int p : setY) {
				posY[idx++] = p;
			}
			long[][] v = new long[posY.length][posX.length];
			boolean[][] visited = new boolean[posY.length][posX.length];
			for (int i = 0; i < N; ++i) {
				L[i] = Arrays.binarySearch(posX, L[i]);
				R[i] = Arrays.binarySearch(posX, R[i]);
				T[i] = Arrays.binarySearch(posY, T[i]);
				B[i] = Arrays.binarySearch(posY, B[i]);
				for (int j = B[i]; j < T[i]; ++j) {
					for (int k = L[i]; k < R[i]; ++k) {
						v[j][k] |= (1L << i);
					}
				}
			}
			int ans = 0;
			for (int i = 0; i < posY.length; ++i) {
				for (int j = 0; j < posX.length; ++j) {
					if (visited[i][j]) continue;
					++ans;
					ArrayDeque<Integer> q = new ArrayDeque<Integer>();
					q.add((i << 10) + j);
					visited[i][j] = true;
					while (!q.isEmpty()) {
						int pos = q.poll();
						int cr = pos >> 10;
						int cc = pos & 0x3FF;
						for (int k = 0; k < 4; ++k) {
							int nr = cr + DR[k];
							int nc = cc + DC[k];
							if (nr < 0 || posY.length <= nr || nc < 0 || posX.length <= nc || visited[nr][nc]) continue;
							if (v[cr][cc] != v[nr][nc]) continue;
							visited[nr][nc] = true;
							q.add((nr << 10) + nc);
						}
					}
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 62324
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
using namespace std;
 
const ll N =(1e5+5);
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll LOG = 29;

long long binpow(long long a, long long b) {
     a %= MOD;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD ;
        a = (a * a)%MOD ;

        
        b >>= 1;
    }
    res%=MOD;
    return res;
}

void solve(){
    ll n,m;
    cin>>n>>m;
    ll grid[n+1][m+1];
    for(int i =1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            grid[i][j]=1;
        }
    }
    for(int i =1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            grid[i][j]^=1;
            vll dx = {-1,0,1};
            vll dy = {-1,0,1};
            bool done[n+1][m+1];
            for(int x =1;x<=n;x++)
                for(int y =1;y<=m;y++)
                    done[x][y]=false;
            for(int k=0;k<3;k++){
                ll x = dx[k]+i;
                for(ll k2 = 0;k2<3;k2++)
                {ll y = dy[k2]+j;
                                if(x >= 1 && x <= n && y>= 1 && y<=m){
                                    if(done[x][y]==false){
                                                                        grid[x][y]^=1;done[x][y]=true;}
                                }}
            }
        }
    }
    ll ans = 0;
    for(int i =1;i<=n;i++){
        for(int j = 1;j<=m;j++)
            if(grid[i][j])ans++;
        //cout<<endl;
    }
    cout<<ans<<endl;
}



void solve2(){
    ll n,m;
    cin>>n>>m;
    if(n>m) swap(n,m);
    if(n==1){
        if(m==1){
            cout<<1<<endl;
        }
        else if(m==2){
            cout<<0<<endl;
        }
        else{
            cout<<(m-n-1)<<endl;
        }
        return;

    }
    ll a = (n-2)*(n-2);
    ll d = m-n;
    cout<<a+(n-2)*d<<endl;
}


int main()
{
    ios_base::sync_with_stdio(0);
     cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve2();
    }
     
 
 
    return 0;     
    
        
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
  	vector<ll> v={a,b,c};
  	sort(all(v));
    if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)) cout << "Yes" << ednl;
    else cout << "No" << ednl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String S = sc.next();
      int s = S.length()-1;
      String[] op = new String[s];
      long ans=0;
      for(int i=0;i<(Math.pow(2,s));i++){
        for(int p=0;p<s;p++){
        op[p]="";
        }
        for(int j=0;j<s;j++){
          if((1&i>>j)==1){
            op[j]="a";
          }
        }
        String str="";
        for(int k=0;k<s;k++){
          str = str+String.valueOf(S.charAt(k))+op[k];
        }
        str = str+String.valueOf(S.charAt(s));
        String[] a = str.split("a");
        for(int l=0;l<a.length;l++){
          ans+=Long.parseLong(a[l]);
        }
      }
      System.out.println(ans); 
    }
}

Measured memory_bytes: 42804
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int n, cnt = 0, tmp;
    vector<int> a;
    cin >> n;
    rep(i, n){
        cin >> tmp;
        a.push_back(tmp);
    }

    rep(i, n){
        while(a[i] % 2 == 0){
            a[i] /= 2;
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 384
// ３つの整数を読み込み、それらを値が小さい順に並べて出力するプログラムを作成して下さい。
// 【入力】
// ３つの整数が空白で区切られて与えられます。
// 【出力】
// 小さい順に並べ替えた３つの整数を１行に出力して下さい。
// 整数の間に１つの空白を入れて下さい。
// 【制約】
// 1 ≤ ３つの整数 ≤ 10,000
// 【例】
// 入力：3 8 1、出力：1 3 8
#include<iostream>
using namespace std;

int main( void) {
  int a, b, c;
  int swapVal;

  cin >> a >> b >> c;

  if ( a > b) {
    swapVal = a;
    a = b;
    b = swapVal;
  }

  if ( a > c) {
    swapVal = a;
    a = c;
    c = swapVal;
  }

  if ( b > c) {
    swapVal = b;
    b = c;
    c = swapVal;
  }

  cout << a << " " << b << " " << c << endl;

  return 0;
}



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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b, c; cin >> a >> b >> c;
    for(int i = 1; i <= max(a,b); i++){
        if(a%i == 0 && b% i==0 && c%i!=0){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


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

int main(){
    int N,K,d,a;
    cin >> N >> K;
    vector<int> vec(N);
    for(int i=0;i<K;i++){
        cin >> d;
        for(int j=0;j<d;j++){
            cin >> a;
            vec[a-1]++;
        }
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(vec[i]==0)
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
class Node:
    def __init__(self, char: str):
        self.before = None
        self.char = char
        self.next = None

class Linked_List:
    def __init__(self):
        self.head = None
        self.tail = None
    
    def add_head(self, node):
        if self.head is None:
            self.head = node
            self.tail = node
        else:
            node.next = self.head
            self.head.before = node
            self.head = node

    def add_tail(self, node):
        if self.tail is None:
            self.head = node
            self.tail = node
        else:
            node.before = self.tail
            self.tail.next = node
            self.tail = node

    def show(self, is_reversed: bool):
        ret = []
        node = self.tail if is_reversed else self.head
        while not node is None:
            c = ''.join(list(node.char)[::-1]) if is_reversed else node.char
            ret.append(c)
            node = node.before if is_reversed else node.next
        print(''.join(ret))

S = input()
Q = int(input())
ll = Linked_List()
ll.add_head(Node(S))
is_reversed = False

for _ in range(Q):
    query = input()
    if query[0] == '1':
        is_reversed = False if is_reversed else True
    else:
        t, f, c = query.split()
        if is_reversed:
            c = ''.join(list(c)[::-1])
        if f == '1':
            if is_reversed:
                ll.add_tail(Node(c))
            else:
                ll.add_head(Node(c))
        else:
            if is_reversed:
                ll.add_head(Node(c))
            else:
                ll.add_tail(Node(c))

ll.show(is_reversed)


Measured memory_bytes: 38876
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
 
template < typename T > using index_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)


const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;

int main() 
{

    fast();
      
    // #ifndef ONLINE_JUDGE
    //         freopen("input.txt", "r", stdin);
    //         freopen("output.txt","w",stdout);
    // #endif
    
    // ll n,k;
    // cin>>n>>k;
    // vector<pa>q(n);
    // f(i,0,n)
    // {
    //     cin>>q[i].S>>q[i].F;
    // }
    // sort(all(q));

    ll n;
    cin>>n;
    map<string,ll>maps;
    str s;
    f(i,0,n)
    {
        cin>>s;
        sort(all(s));
        // cout<<s<<edl;
        maps[s]++;
    }
    ll c=0;
    for(auto s:maps)
    {
    
        
        c+=s.S*(s.S-1)/2;
    }
    cout<<c;
 
    
    





  

    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=2e5+20;
int n,fa[maxn],v[maxn];
int ff[maxn];

struct node {
	int num1,num0,id;
};

inline bool operator <(node a,node b)
{
	ll A=1ll*a.num1*b.num0,B=1ll*b.num1*a.num0;
	return A!=B?A<B:a.id<b.id;
}

set<node>s;

int num[maxn][2];

int fin(int x){ return x==ff[x]?x:ff[x]=fin(ff[x]);}

inline void init()
{
	n=read();
	REP(i,2,n)fa[i]=read();
	REP(i,1,n)ff[i]=i;
	REP(i,1,n)num[i][v[i]=read()]++;
	REP(i,2,n)
	{
		node x=(node){num[i][1],num[i][0],i};
		s.insert(x);
	}
}

ll ans;

inline void doing()
{
	while(!s.empty())
	{
		node t=*s.begin(); s.erase(t);
		int x=t.id,fat=fin(fa[x]);
		if(fat>1)s.erase((node){num[fat][1],num[fat][0],fat});
		ans+=1ll*num[fat][1]*num[x][0];
		REP(op,0,1)num[fat][op]+=num[x][op];
		ff[x]=fat;
		if(fat>1)s.insert((node){num[fat][1],num[fat][0],fat});
	}
	printf("%lld\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 16640