akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int A[500], B[500], C[500];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N - 1; ++i) {
    cin >> A[i] >> B[i] >> C[i];
  }
  
  for(int i = 0; i < N; ++i) {
    int sum = 0;
    for(int j = i; j < N - 1; ++j) {
      sum = max(sum, B[j]);
      sum = (sum + C[j] - 1) / C[j] * C[j];
      sum += A[j];
    }
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>

using namespace std;
set <string> ss;
string s;
int k;

int main() {

    cin >> s >> k;

    int i, j, n = s.length();

    for (i = 0; i < n; ++i) {
        for (j = 1; j <= 5; ++j) {
            if (i + j - 1 >= n) {
                continue;
            }
            ss.insert(s.substr(i, j));
        }
    }

    for (i = 1; i < k; ++i) {
        ss.erase(ss.begin());
    }
    cout << *ss.begin() << endl;


    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <class T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

string L;
vector<vector<int>> dp;
int rec(int d, bool istight) {
    if (d == 0)
        return dp[d][istight] = istight;
    bool n = L[d - 1] - '0';
    if (istight) {
        ll tmp = (~dp[d - 1][1] ? dp[d - 1][1] : rec(d - 1, true));
        return dp[d][1] = tmp * (n + 1) % MOD;
    } else {
        ll tmp1 = (~dp[d - 1][0] ? dp[d - 1][0] : rec(d - 1, false));
        ll tmp2 = (~dp[d - 1][1] ? dp[d - 1][1] : rec(d - 1, true));
        return dp[d][0] = (tmp1 * 3 + tmp2 * n) % MOD;
    }
}

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

    cin >> L;
    int len = L.length();

    dp.resize(len + 2, vector<int>(2, -1));
    dp[0][1] = 1;

    cout << (rec(len, true) + rec(len, false)) % MOD << endl;
    return 0;
}


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

int main()
{
    int n, p, t, a, x;
    cin >> n >> p;

    priority_queue<int> q[n];

    while (p--)
    {
        cin >> t;
        if (t == 0)
        {
            cin >> a >> x;
            q[a].push(x);
        }
        if (t == 1)
        {
            cin >> a;
            if (q[a].size() != 0)
                cout << q[a].top() << endl;
        }
        if (t == 2)
        {
            cin >> a;
            if (q[a].size() != 0)
                q[a].pop();
        }
    }
    return 0;
}


Measured memory_bytes: 4048
#include <cstdio>
    #define N 100001
    using namespace std;
     
    int a[N], p[N], n, m, r = 0;
    int f(int x) { return p[x] = p[x] == x ? x : f(p[x]); }
    void u(int x, int y) { p[f(x)] = f(y); }
     
    int main() {
    	scanf("%d%d", &n, &m);
    	for(int i = 1; i <= n; i++)
    		scanf("%d", a + i), p[i] = i;
    	for(int i = 1, x, y; i <= m; i++)
    		scanf("%d%d", &x, &y), u(x, y);
    	for(int i = 1; i <= n; i++)
    		r += f(i) == f(a[i]);
    	printf("%d", r);
    }

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
5 2 100
)");
#define cin input
#endif

int main()
{
	ll k, a, b;
	cin >> k >> a >> b;

	if (b - a > 2 && (k > a))
	{
		cout << (k + 1) + (b - a - 2) * ((k + 1 - a) / 2) << endl;
	} else
	{
		cout << (k + 1) << endl;
	}

	return 0;
}


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

typedef pair<int,int> P;

int H, W;

bool contains(int x, int y) {
  return 0 <= x && x < W && 0 <= y && y < H;
}

int main() {
  int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
  int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};

  while (cin >> H >> W) {
    vector<string> t(H);

    for (int i = 0; i < H; i++) {
      cin >> t[i];
    }

    vector<vector<int> > rawCnt(H, vector<int>(W, 0));
    queue<P> open;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (t[i][j] != '.') continue;

        for (int k = 0; k < 8; k++) {
          int nx = j + dx[k];
          int ny = i + dy[k];

          if (!contains(nx, ny)) continue;
          if (t[ny][nx] == '.') continue;

          rawCnt[ny][nx]++;

          if (rawCnt[ny][nx] == t[ny][nx] - '0') {
            open.push(P(nx, ny));
          }
        }
      }
    }

    int ans = 0;

    while (!open.empty()) {
      queue<P> nextOpen;

      while (!open.empty()) {
        P p = open.front();
        open.pop();

        for (int k = 0; k < 8; k++) {
          int nx = p.first + dx[k];
          int ny = p.second + dy[k];

          if (!contains(nx, ny)) continue;
          if (t[ny][nx] == '.') continue;

          rawCnt[ny][nx]++;

          if (rawCnt[ny][nx] == t[ny][nx] - '0') {
            nextOpen.push(P(nx, ny));
          }
        }
      }

      open = nextOpen;
      ans++;
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 6020
import java.io.*;
import java.util.StringTokenizer;

class Main {

    public static void main(String[] args) {
//        final FastScanner fs = new FastScanner("/Users/igorz/dev/google-prep/src/main/java/atcoder/abc100/input.txt");
        final FastScanner fs = new FastScanner();

        final int A = fs.nextInt();
        final int B = fs.nextInt();

        if (A <= 8 && B <= 8) {
            System.out.println("Yay!");
        } else {
            System.out.println(":(");
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int[] nextIntArray() {
            final int N = nextInt();
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 32684
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        final int N = sc.nextInt();
        int[] Ls = new int[N];
        for(int i = 0; i < N; i++) {
            Ls[i] = sc.nextInt();
        }

        Arrays.sort(Ls);

        int sum = 0;
        for(int i = 0;i < N - 1; i++) {
            sum += Ls[i];
        }

        System.out.println(Ls[N-1] < sum ? "Yes" : "No");
    }
}


Measured memory_bytes: 21716
let a = Int(readLine()!)!
let b = Int(readLine()!)!
let c = Int(readLine()!)!
let x = Int(readLine()!)!
var ans = 0
for i in 0...a {
  for j in 0...b {
    for k in 0...c {
      if 500 * i + 100 * j +  50 * k == x {
        ans += 1
      }
    }
  }
}
print(ans)

Measured memory_bytes: 7716
#include <stdio.h>

int main(){
	int n, ans = 0;
	scanf ("%d", &n);
	while (n>0){
		if (n>=25) n-=25;
		else if (n>=10) n-=10;
		else if (n>=5) n-=5;
		else n--;
		ans++;
	}
	printf ("%d\n", ans);
	return 0;
}


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

int N,M;

void solve(){
  map<char,char>mp;
  for(int i = 0 ; i < N ; i++){
    char a,b;
    cin >> a >> b;
    mp[a] = b;
  }
  cin >> M;
  for(int i = 0 ; i < M ; i++){
    char c;
    cin >> c;
    if(mp.find(c) != mp.end())cout << mp[c];
    else cout << c;
  }
  cout << endl;
}

int main(){
  while(cin >> N,N)solve();
}

Measured memory_bytes: 1188
#include<stdio.h>
int main(){
  int n,h1,h2,m1,m2,s1,s2,s,max,i;
  while(scanf("%d",&n),n){
    int d[100010]={0};
    while(n--){
      scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2);
      d[(h1*60+m1)*60+s1]++;
      d[(h2*60+m2)*60+s2]--;
    }
    for(i=s=max=0;i<100000;i++){
      s+=d[i];
      if(max<s)max=s;
    }
    printf("%d\n",max);    
  }
  return 0;
}

Measured memory_bytes: 996
#include<stdio.h>

int main() {
	int x, y, z;
	int bx, by, bz;
	scanf("%d %d %d", &bx, &by, &bz);
	x = bz;
	y = bx;
	z = by;
	printf("%d %d %d", x, y, z);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
    int n,q;
    cin >> n;
    vector<int> s(n);    
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    cin >> q;
    vector<int> t(q);
    for(int i = 0; i < q; i++){
        cin >> t[i];
    }
    int Max, Min, mid;
    
    int ans = 0;
    for(int i = 0; i < q; i++){
        Max = n;
        Min = 0; 
        mid = n/2;
        while(Max > Min){
            if(t[i] == s[mid]){
                ans ++;
                break;
            }else if(t[i] > s[mid]){
                Min = mid+1;
                mid = (Max+Min)/2;
            }else if((t[i] < s[mid])){
                Max = mid;
                mid = (Max+Min)/2;
            }
        }
    }
    
    cout << ans << endl; 
    return 0;
}
    




Measured memory_bytes: 3276
#include<stdio.h>
#include<math.h>
#define PI 3.14159265
#define EPS 0.000001
double A[2]={0,0};
int M,i,j,c,a,s;
int main()
{
	for(c=0;scanf("%d",&M),M;c++)
	{
		for(i=s=0;i<M-1;i++)
		{
			scanf("%d",&a);
			s+=a;
			A[c%2]+=sin(PI*((double)a/180))/2;
		}
		A[c%2]+=sin(PI*((360.0-s)/180))/2;
		if(A[0]>0&&A[1]>0)
		{
			if(A[0]==A[1])puts("0");
			else if(A[0]>A[1])puts("1");
			else puts("2");
			A[0]=A[1]=0;
		}
	}
	return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
    double a, b, C;
    cin >> a >> b >> C;
    double theta = acos(-1) * C / 180.0;
    double h = b * sin(theta);
    double s = (a * h) / 2.0;
    double c = sqrt(a*a + b*b - 2*a*b*cos(theta));
    printf("%lf\n%lf\n%lf\n", s, (a + b + c), h);
}

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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define fWrite          freopen ("out.txt","w",stdout);
#define TC              int t;cin >> t;FOR(tc,1,t)
#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define MEM(a,x)        memset(a,x,sizeof(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

#define Make(x,p)       (x | (1<<p))
#define DeMake(x,p)     (x & ~(1<<p))
#define Check(x,p)      (x & (1<<p))
#define popcount(x)     __builtin_popcount(x)

int main()
{
    int n;
    string str;
    cin >> n >> str;
    LL Red[n+5]={0},Green[n+5]={0},Blue[n+5]={0};
    ROF(i,n-1,0){
        Red[i]=Red[i+1];
        Green[i]=Green[i+1];
        Blue[i]=Blue[i+1];
        if(str[i]=='R') Red[i]++;
        else if(str[i]=='G') Green[i]++;
        else Blue[i]++;
    }

    LL ans=0;
    REP(i,n-2){
        FOR(j,i+1,n-2){
            if(str[i]==str[j]) continue;
            if((str[i]=='R' and str[j]=='G') or (str[j]=='R' and str[i]=='G')){
                LL cnt=Blue[j+1];
                int idx=j-i;
                if(str[j+idx]=='B') cnt--;
                ans+=cnt;
            }
            if((str[i]=='R' and str[j]=='B') or (str[j]=='R' and str[i]=='B')){
                LL cnt=Green[j+1];
                int idx=j-i;
                if(str[j+idx]=='G') cnt--;
                ans+=cnt;
            }
            if((str[i]=='B' and str[j]=='G') or (str[j]=='B' and str[i]=='G')){
                LL cnt=Red[j+1];
                int idx=j-i;
                if(str[j+idx]=='R') cnt--;
                ans+=cnt;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<cstring>
#include<functional>
#include<bitset>
using namespace std;
typedef	long long int ll;

int main(){
    string s;
    cin >> s;
    int left = 1;
    int right = s.size();
    char t;
    while(1){
        int l = (right+left)/2;
        if(left==l){
            for(int i = s.size()-right; i < right; i++){
                if(i==s.size()-right){
                    t = s[i];
                    continue;
                }
                if(t!=s[i]){
                    cout << left << endl;
                    return 0;
                }
            }
            cout << right << endl;
            return 0;
        }
        if(l <= s.size()/2){
            left = l;
            continue;
        }
        bool flag = 0;
        for(int i = s.size()-l; i < l; i++){
            if(i==s.size()-l){
                t = s[i];
                continue;
            }
            if(t!=s[i]){
                flag = 1;
            }
        }
        if(flag) right = l;
        else left = l;
    }
    cout << left << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a,b)<<" ";
	if(a+b<n)
	{
		cout<<"0";
		return 0;
	}
	else
	{
		cout<<a+b-n;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;cin>>n;
  string a,b,c;cin>>a>>b>>c;
  int ans=0;
  for(int i=0;i<n;i++){
    if(a[i]==b[i]&&a[i]==c[i])continue;
    else if(a[i]==b[i])ans++;
    else if(b[i]==c[i])ans++;
    else if(a[i]==c[i])ans++;
    else ans+=2;
  }
  cout<<ans<<endl;
}

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

int main () {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = -9223372036854775808;
  ans = max(a * c, ans);
  ans = max(a * d, ans);
  ans = max(b * c, ans);
  ans = max(b * d, ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;

struct Pos{
    int x;
    int y;
    int order;
};
bool asc_x(const Pos& l, const Pos& r) {
    return l.x < r.x;
}
bool asc_y(const Pos& l, const Pos& r) {
    return l.y < r.y;
}

struct Node{
    int x;
    int y;
    int order;
    Node* left;
    Node* right;
};

class Tree{
    Node* root;
    Node* makeTree(vector<Pos>& A, int l, int r, int depth){
        if (l > r) return nullptr;
        if (depth % 2) {
            sort(A.begin() + l, A.begin() + r + 1, asc_y);
        } else {
            sort(A.begin() + l, A.begin() + r + 1, asc_x);
        }
        int mid = (l + r) / 2;
        Node* p = new Node;
        p->x     = A[mid].x;
        p->y     = A[mid].y;
        p->order = A[mid].order;
        p->left  = makeTree(A,       l, mid - 1, depth + 1);
        p->right = makeTree(A, mid + 1,       r, depth + 1);
        return p;
    }
    void find_(Node* n, int sx, int tx, int sy, int ty, int depth, vector<int>& ans){
        if (n == nullptr) return;
        int n_, s, t;
        if (depth % 2) {
            n_ = n->y;
            s  = sy;
            t  = ty;
        } else {
            n_ = n->x;
            s  = sx;
            t  = tx;
        }
        if (n_ >= s) find_(n->left, sx, tx, sy, ty, depth + 1, ans);
        if (n->x >= sx && n->x <= tx && n->y >= sy && n->y <= ty) {
            ans.push_back(n->order);
        }
        if (n_ <= t) find_(n->right, sx, tx, sy, ty, depth + 1, ans);
    }
public:
    Tree(vector<Pos>& A){
        root = makeTree(A, 0, A.size() - 1, 0);
    }
    void find(int sx, int tx, int sy, int ty){
        vector<int> ans;
        find_(root, sx, tx, sy, ty, 0, ans);
        sort(ans.begin(), ans.end());
        for (int i = 0, s = ans.size(); i < s; i++) {
            printf("%d\n", ans[i]);
        }
        printf("\n");
    }
};

int main(){
    int n;
    scanf("%d", &n);
    vector<Pos> A(n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &(A[i].x), &(A[i].y));
        A[i].order = i;
    }
    Tree T(A);
    int q;
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        int sx, tx, sy, ty;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        T.find(sx, tx, sy, ty);
    }
    return 0;
}



Measured memory_bytes: 30892
import numpy as np

NKQ = list(map(int, input().split()))

N = NKQ[0]
K = NKQ[1]
Q = NKQ[2]

A = [int(input()) for i in range(Q)]

negative = np.ones(N, dtype="int")

for i in range(Q):
    negative[A[i]-1] = negative[A[i]-1] + 1

for i in range(N):
    if negative[i] > Q - K + 1:
        print("Yes")
    else:
        print("No")


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

int main() {
  string s, t, u;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  cin >> u;
  
  if(u == s){
  	a--;
  }else{
    b--;
  }
  
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String a = sc.next();
      String b = sc.next();
      String c = sc.next();
      String r1 = a.substring(0, 1);
      String r2 = b.substring(1, 2);
      String r3 = c.substring(2, 3);
		  System.out.println(r1+r2+r3);
   }
 }


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

typedef long long ll;

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

    int N, K, C;
    string S;

    cin >> N >> K >> C;
    cin >> S;

    vector<int> L(K); //zero index
    vector<int> R(K);

    int lLast = INT_MIN;
    int lIndex = 0;
    for (int i = 0; i < N; ++i) {
        if (lIndex >= K)
            break;
        if (S[i] == 'o' && i > lLast + C) {
            L[lIndex++] = i;
            lLast = i;
        }
    }

    int rLast = INT_MAX;
    int rIndex = K - 1;
    for (int i = N - 1; i >= 0; --i) {
        if (rIndex < 0)
            break;
        if (S[i] == 'o' && i < rLast - C) {
            R[rIndex--] = i;
            rLast = i;
        }
    }

    for (int i = 0; i < K; ++i) {
        if (L[i] == R[i]) {
            cout << L[i] + 1 << " ";
        }
    }

    cout << "\n";
    return 0;
}


Measured memory_bytes: 3348
N=int(input())
H=[[] for i in range(N+1)];H[0]=None # 人iがjを正直者だというようなj
U=[[] for i in range(N+1)];U[0]=None
for i in range(1,N+1):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        if y==1:
            H[i].append(x)
        elif y==0:
            U[i].append(x)

# print(H)
# print(U)

ans=0
for k in range(1<<N):
    f=[None]
    f.extend([k>>i&1 for i in range(N)])
    # print(f) #DB
    m=sum(f[1:]) # 正直者の人数
    if m<=ans:
        continue
    g=True # フラグ
    for i in range(1,N+1): # 人iについて
        if not g:
            break
        if not f[i]: # 正直者である場合に限る
            continue
        for j in H[i]: # 人iが正直者であると言及する人jについて
            if not f[j]: # jが不親切であったならば
                g=False
                break
        for j in U[i]: # 
            if f[j]:
                g=False
                break
    if g:
        ans=m

print(ans)

Measured memory_bytes: 48860
#include <iostream>
#include <string>
#include <vector>
#define sz(a) (int)(a).size()

using namespace std;

typedef vector<int> vi;
typedef long long ll;

int c(int a,int b){
	return abs(a-b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++)
		cin>>h[i];
	int dp[n];
	dp[0]=0;
	dp[1]=c(h[0],h[1]);
	for(int i=2;i<n;i++){
		dp[i]=dp[i-1]+c(h[i],h[i-1]);
		for(int j=2;j<=k && i-j>=0;j++){
			dp[i]=min(dp[i-j]+c(h[i],h[i-j]), dp[i]);
		}
	}
	cout<<dp[n-1]<<"\n";
	
}


Measured memory_bytes: 1024
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int i = 0; i < N; i++) a[i] = sc.nextInt();

        int numberOfTwoDivisoraFactor = 0;
        for(int i = 0; i < N; i++){
            numberOfTwoDivisoraFactor += numberOfTwoDivisoraFactor(a[i]);
        }

        out.println(numberOfTwoDivisoraFactor);
    }

    public static int numberOfTwoDivisoraFactor(long num){
        if(num > 0 && num % 2 == 0){
            return 1 + numberOfTwoDivisoraFactor(num / 2);
        }
        return 0;
    }
}


Measured memory_bytes: 34300
#include <stdio.h>
int main()
{
	int a, b;
	int area, round;
	 
	scanf("%d", &a);
	scanf("%d", &b);
	
	area = a*b;
	round = (a*2 + b*2);
	 
	 printf("%d %d\n", area ,round );
	 return 0;
}

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

int main(){
    int M,D; cin>>M>>D;
    int ans=0;
    int d_1,d_10;
    for(int i=4;i<=M;i++){
      for(int j=1;j<=D;j++){
        int d_1,d_10;
        d_1=j%10;
        d_10=(j-d_1)/10;
        if(d_1*d_10==i and d_1>=2 and d_10>=2) ans++;
      }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
Q, H, S, D = tuple(map(int, input().split()))
N = int(input())
min2l = min(8 * Q, 4 * H, 2 * S, D)
min1l = min(4 * Q, 2 * H, S)
print((N // 2) * min2l + (N % 2) * min1l)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s; cin>>s;
	int cnt[2][2]={0};
	For(i,0,sz(s)-1) cnt[i%2][s[i]-'0']++;
	cout<<min(cnt[0][0]+cnt[1][1],cnt[1][0]+cnt[0][1])<<"\n";
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r,d,x;
    cin>>r>>d>>x;
    rep(i,10){
      x=r*x-d;
      cout<<x<<endl;
    }
}

Measured memory_bytes: 764
L, N = map(int, raw_input().split())
X = [input() for _ in range(N)]

def f(T):
  n = len(T)
  S = [0]*(2*n+1)
  for i in range(2*n):
    S[i+1] = S[i]+T[i%n]
  a = S[n-1]
  ans = a
  for i in range(n-2):
    a += 2*(S[2*n-i*2-3]-S[n-i-1])
    a -= 2*(S[2*n-i-2]-S[2*n-i*2-2])
    a -= T[n-i-2]
    ans = max(ans, a)
  return ans

A = [X[0]]+[X[i+1]-X[i] for i in range(N-1)]+[L-X[-1]]
print max(f(A), f(A[::-1]))


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

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

int main() {
	int h, w, sx = 0, sy = 0, gx, gy,kabe = 0;
	int x, y;
	cin >> h >> w;
	gx = h - 1, gy = w - 1;

	vector<string> m(h);
	vector<vector<int>> dist(h,vector<int>(w,-1));
	queue<pair<int, int>> que;

	for (int i = 0; i < h; i++) {
		cin >> m[i];
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (m[i][j] == '#')kabe++;
		}
	}

	dist[sx][sy] = 0;
	que.push(make_pair(0, 0));

	while (!que.empty()) {
		pair<int, int>current = que.front();
		x = current.first;
		y = current.second;
		que.pop();
		for (int direction = 0; direction < 4; direction++) {
			int next_x = x + dx[direction];
			int next_y =y + dy[direction];
			if (next_x < 0 || next_x >= h || next_y < 0 || next_y >= w)continue;
			if (m[next_x][next_y] == '#')continue;

			if (dist[next_x][next_y] == -1) {
				que.push(make_pair(next_x, next_y));
				dist[next_x][next_y] = dist[x][y] + 1;
			}
		}
	}
	if (dist[h - 1][w - 1] != -1) cout << h * w - dist[h -1][w - 1] - 1 - kabe<< endl;
	else cout << -1 << endl;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

void addMapKey(map<long long, int> &m, long long k){
	if(m.count(k) == 0){
		m[k] = 1;
	}
	else{
		m[k]++;
	}
}

long long N, M;
map<long long, int> A;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> M;
	for(int i=0; i<N; i++){
		long long a;
		cin >> a;
		addMapKey(A, a);
	}

	for(int i=0; i<M; i++){
		long long b, c;
		cin >> b >> c;
		long long w = b;
		while(w > 0){
			long long u, v;
		    for(auto itr = A.begin(); itr != A.end(); itr++){
		    	u = itr->first;
		    	v = itr->second;
		    	if(u >= c) break;
		    	if(v <= w){
		    		A.erase(A.find(u));
		    		if(A.count(c)==0){
		    			A[c] = v;
		    		}
		    		else{
		    			A[c] += v;
		    		}
		    		w -= v;
		    	}
		    	else if(v > w){
		    		A[u] = v - w;
		    		if(A.count(c)==0){
		    			A[c] = w;
		    		}
		    		else{
		    			A[c] += w;
		    		}
		    		w = 0;
		    	}
		    	break;
		    }
			if(u >= c || w <= 0){
				break;
			}
		}
	}
	long long ans = 0;
	for(auto itr = A.begin(); itr != A.end(); itr++){
		long long u = itr->first;
		long long v = (long long)itr->second;
		ans += (u * v);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 10000
package main

import "fmt"

func main() {
	var r, g, b, k int
	fmt.Scan(&r, &g, &b, &k)
	red := r
	green := g
	blue := b
	n := 3

	for i := 1; i < k; i++ {
		n = n * 3
	}

	for i := 0; i < k; i++ {
		if green >= blue {
			blue *= 2
		} else if red >= green {
			green *= 2
		}
		if red < green && green < blue {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


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

int main(){
    string s; cin>>s;

    int a,z;
    for(int i=0;i<s.length();i++){
        if(s[i]=='A'){
            a=i;
            break;
        }
    }
    for(int i=0;i<s.length();i++){
        if(s[s.length()-1-i]=='Z'){
            z=s.length()-1-i;
            break;
        }
    }
    cout<<z-a+1<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define repins(a,n) vector<string> a(n);rep(i,n){cin>>a[i];}
#define repind(a,n) vector<double> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define ins(a) string a;cin>>a;
#define ind(a) double a;cin>>a;
template<class T>
inline void out(T a){cout<<a<<endl; }
inline void out(double a){ printf("%.10f\n", a);} 
#define all(x) (x).begin(),(x).end()
#define rep2(i,a,b) for(ll i=(a);i<(b);++i)
#define range(i,s,c) for(ll i=(s);i<(s+c);++i)
using vell = vector<ll>;
using ves = vector<string>;
using ved = vector<double>;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main()
{
	ins(s);
	rep(i,s.size()){
		cout<<"x";
	}
		cout<<endl;
}

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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i <= n / 7; i++){
        if((n - 7 * i) % 4 == 0){
            ans = 1;
            break;
        }
    }
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
  while(1){
    int H, W;
    cin>>H>>W;
    if(H == 0 && W == 0) break;

    int i, j;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	if((i + j) % 2 == 0) cout<<"#";
	else cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }

  return 0;
}



Measured memory_bytes: 3108
X,K,D=list(map(int,input().split()))
X=abs(X)
import sys

if X > 0 and X-K*D>=0:
    print(X-K*D)
    sys.exit()

M=X//D
Q=X%D

if M%2 == K%2:
    print(Q)
else:
    print(D-Q)



Measured memory_bytes: 61924
#include <bits/stdc++.h>
#define  Rep(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) Rep(i,0,(n))
#define  all(a) begin(a),end(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
 
int main()
{
    ull a,b,x;
    cin>>a>>b>>x;
    cout<<(a%x==0)+b/x-a/x<<endl;
    
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

const ll kazu = 2019;

int main()
{
    long double a, b, n;
    cin >> a >> b >> n;
    if (n < b) {
        cout << floor(a * n / b) << endl;
    } else {
        cout << floor(a - a / b) << endl;
    }
    return 0;
}


Measured memory_bytes: 3808
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll x;cin>>x;
    bitset<32>a(x);
    cout<<a<<endl;
    cout<<~a<<endl;
    cout<<(a<<1)<<endl;
    cout<<(a>>1)<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> vc(h);
    for (int i = 0; i < h; i++)
    {
        cin >> vc[i];
    }
    for (int i = 0; i < w + 2; i++)
    {
        cout << "#";
    }
    cout << endl;
    for (int i = 0; i < h; i++)
    {
        cout << "#";
        cout << vc[i];
        cout << "#";
        cout << endl;
    }
    for (int i = 0; i < w + 2; i++)
    {
        cout << "#";
    }
    cout << endl;
}

Measured memory_bytes: 256
from collections import deque

h, w = map(int,input().split())
ch, cw = map(int,input().split())
dh, dw = map(int,input().split())

maze = []
for i in range(h):
    t = list(input())
    maze.append(t)

maze[dh-1][dw-1] = "g"

dx = [0,0,1,-1]
dy = [1,-1,0,0]

ans = 0
queue = deque([(ch-1, cw-1)])
check = deque([])
while True:
    while queue:
        y, x = queue.popleft()
        check.append((y, x))
        for dxi, dyi in zip(dx, dy):
            if not (0<=x+dxi<w and 0<=y+dyi<h):
                continue
            if maze[y+dyi][x+dxi] == "g":
                print(ans)
                exit()
            if maze[y+dyi][x+dxi] != ".":#次の行き先が「街の中じゃない」もしくは「壁」
                pass
            else:
                queue.append((y+dyi, x+dxi))
                maze[y+dyi][x+dxi] = ans
    ans += 1
    while check:
        y, x = check.popleft()
        for i in range(-2,3):
            for j in range(-2,3):
                if not (0<=x+i<w and 0<=y+j<h):
                    continue
                if maze[y+j][x+i] == "g":
                    print(ans)
                    exit()
                if maze[y+j][x+i] != ".":
                    pass
                else:
                    maze[y+j][x+i] = ans
                    queue.append((y+j, x+i))
    if not queue:
        print(-1)
        exit()

Measured memory_bytes: 167816
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    ll ma = 0;
    rep(i, 10000) {
        if (i * (i+1) >= 2*N) {
            ma = i;
            break;
        }
    }
    for(ll i = ma; i > 0; i--) {
        if (N - i >= 0) {
            print(i);
            N -= i;
        }
    }
    return 0;
}

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

int main(){
 int i,n,tmp,max,min;
 cin >> n;
 max=0;min=1000000001;
 for(i=0;i<n;i++){
    cin >> tmp;
    if(tmp>max)max=tmp;
    if(tmp<min)min=tmp;
 }
 cout << max-min<<endl;
 return 0;
}

Measured memory_bytes: 256
A,B,C,K=map(int,input().split())

if K%2==0:
    ans=A-B
    if abs(ans)>10**18:
        print('Unfair')
    else:
        print(ans)
else:
    ans=B-A
    if abs(ans)>10**18:
        print('Unfair')
    else:
        print(ans)

Measured memory_bytes: 3060
l=[]
n,m=map(int,input().split())
for i in range(m):
  a,b=map(int,input().split())
  k=0
  if(a<n):
    k=n-a
  l.append(k)
l.sort()
ans=0
for i in range(0,m-1):
  ans+=l[i]
print(ans)


Measured memory_bytes: 5612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int[] a = nia(4);
        out.println(Math.max(a[0] * a[1], a[2] * a[3]));
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 8144
#include<stdio.h>
int main(void)
{
  long long a,b,n,sum;
  scanf("%lld %lld %lld",&n,&a,&b);
  if(a==0&b==0){
    puts("0");
    return 0;
  }
  if(n%(a+b)<=a){
    sum=a*(n/(a+b))+(n%(a+b));
  }else{
    sum=a*(n/(a+b))+a;
  }
  printf("%lld\n",sum);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
	set<char> S;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		char c;
		cin >> c;
		S.insert(c);
	}
	if (S.size() == 4)cout << "Four" << endl;
	else cout << "Three" << endl;
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<chrono>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,K;
ll A[100010],B,C,D,X,Y;
ll ans=0;
ll G[100010];
string S,T,U;
ll F[100010];
bool ok=true;
std::queue<ll> Q;
ll Z[]={1,2,3,6,7,8,9,0};

int main(){
    cin>>N>>K;
    REP(i,N)cin>>A[i];
    sort(A,A+N);
    REP(i,K){
        ans+=A[i];
    }
    cout<<ans;
    
}


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

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	long long k,a,b;
	cin >> k >> a >> b;
	
	if(a+1 >= b){
		cout << 1+k << endl;
 	}else{
		long long total;
		if(k+1 < a){
			total = k+1;
			k = 0;
		} else{
			total = a;
			k -= a-1;
		}
		
		total += (b-a)*(k/2);
		cout << total + k%2 << endl;
	}
	
    return 0;   
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int count = 0;
    if (a == b && b == c) count = 1;
    else if (a == b || b == c || c == a) count = 2;
    else count = 3;

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <cassert>

struct Mat {
    static int n;
    std::vector<int> mat;

    Mat(char d = '$', int x = 0) : mat(n * n) {
        std::iota(mat.begin(), mat.end(), 0);

        if (d == 'L') {
            int tmp = mat[n * x + (n - 1)];
            for (int i = n - 1; i > 0; --i) {
                mat[n * x + i] = mat[n * x + (i - 1)];
            }
            mat[n * x + 0] = tmp;

        } else if (d == 'R') {
            int tmp = mat[n * x + 0];
            for (int i = 0; i < n - 1; ++i) {
                mat[n * x + i] = mat[n * x + (i + 1)];
            }
            mat[n * x + (n - 1)] = tmp;

        } else if (d == 'U') {
            int tmp = mat[n * (n - 1) + x];
            for (int i = n - 1; i > 0; --i) {
                mat[n * i + x] = mat[n * (i - 1) + x];
            }
            mat[n * 0 + x] = tmp;

        } else if (d == 'D') {
            int tmp = mat[n * 0 + x];
            for (int i = 0; i < n - 1; ++i) {
                mat[n * i + x] = mat[n * (i + 1) + x];
            }
            mat[n * (n - 1) + x] = tmp;
        }
    }

    Mat operator*(const Mat& m) const {
        auto ret = Mat();
        for (int i = 0; i < n * n; ++i) {
            ret.mat[i] = m.mat[mat[i]];
        }
        return ret;
    }

    Mat pow(int n) const {
        auto ret = Mat();
        auto b = *this;
        while (n > 0) {
            if (n & 1) ret = ret * b;
            n >>= 1;
            b = b * b;
        }
        return ret;
    }
};

int Mat::n;

struct Parser {
    std::string s;
    int i;

    Mat seq() {
        Mat ret;
        while (i < (int)s.length() && s[i] != ')') {
            if (s[i] == '(') {
                ++i;
                auto m = seq();

                assert(s[i] == ')');
                ++i;

                int e = num();
                ret = ret * m.pow(e);
            } else {
                assert(std::isupper(s[i]));
                char c = s[i];
                ++i;
                int x = num() - 1;

                ret = ret * Mat(c, x);
            }
        }
        return ret;
    }

    int num() {
        int ret = 0;
        while (i < (int)s.length() && std::isdigit(s[i])) {
            int d = s[i] - '0';
            ret = ret * 10 + d;
            ++i;
        }
        return ret;
    }

    Mat parse(const std::string& _s) {
        s = _s;
        i = 0;
        return seq();
    }
};

void solve() {
    int n, l;
    std::string s;
    std::cin >> n >> l >> s;
    Mat::n = n;

    Parser parser;
    auto m = parser.parse(s);

    std::vector<int> ans(n * n);
    for (int i = 0; i < n * n; ++i) {
        ans[m.mat[i]] = i;
    }

    for (int i = 0; i < n * n; ++i) {
        std::cout << ans[i] + 1 << " \n"[i % n == n - 1];
    }
}

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

    solve();

    return 0;
}



Measured memory_bytes: 15948
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

const ll MOD = 1e9+7;
template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    string S; cin >> S;

    ll cnt[26] = {};
    for(auto c:S) cnt[c-'a']++;

    res = 1;
    for(int i = 0; i < 26;i++){
        res *= cnt[i]+1;
        res %=MOD;
    }
    res--;
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    // solve<ll>(0);
    cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

Measured memory_bytes: 3704
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Majk
 */

#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
using namespace std;

#define x first
#define y second
constexpr int MOD = 1000000007;

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

template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

namespace std {
    template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

// #include "../l/mod.h"

class C {
public:
	void solve(istream& cin, ostream& cout) {
		int N; cin >> N;
		int B; cin >> B;
		ll A[3] = {B, -1000000000000000LL, -1000000000000000LL};
		for (int i = 0; i < N-1; ++i) {
			char c; cin >> c;
			cin >> B;

			if (c == '+') {
				A[0] = max(A[0], max(A[1], A[2])) + B;
				A[1] = max(A[1], A[2]) - B;
				A[2] = A[2] + B;
			} else {
				A[2] = max(A[1], A[2]) + B;
				A[1] = max(A[1], max(A[0], A[2])) - B;
				A[0] = A[0] - B;
			}
		}

		cout << max(A[0], max(A[1], A[2])) << endl;
	}
};


int main() {
	ios_base::sync_with_stdio(false);
	C solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

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

    string ans;
    switch (d)
    {
    case 22:
        ans = "Christmas Eve Eve Eve";
        break;
    case 23:
        ans = "Christmas Eve Eve";
        break;
    case 24:
        ans = "Christmas Eve";
        break;
    default:
        ans = "Christmas";
        break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256