akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  // d[i][j]: i-jの最短距離
  // next[i][j]: i-jの最短経路中のiの次の点
  // indeces[i][j]: i-jを直接つなぐ辺のインデックス
  vector<vector<int>> d(n, vector<int>(n, -1)), next(n, vector<int>(n, -1)),
      indeces(n, vector<int>(n, -1));
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b] = c;
    d[b][a] = c;
    next[a][b] = b;
    next[b][a] = a;
    indeces[a][b] = i;
    indeces[b][a] = i;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (d[j][i] < 0 || d[i][k] < 0) {
          continue;
        }

        int new_dist = d[j][i] + d[i][k];
        if (d[j][k] < 0 || new_dist < d[j][k]) {
          d[j][k] = new_dist;
          next[j][k] = next[j][i];
        }
      }
    }
  }

  vector<bool> used(m, false);
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (i == j) {
        continue;
      }

      // i-jの最短経路を復元
      int cur = i;
      while (cur != j) {
        if (indeces[cur][next[cur][j]] != -1) {
          used[indeces[cur][next[cur][j]]] = true;
        }
        cur = next[cur][j];
      }
    }
  }

  cout << count(used.begin(), used.end(), false) << '\n';
}

Measured memory_bytes: 3672
#include<iostream>
#include<queue>
#include<algorithm>
#include<numeric>
#include<string>
#include<map>
#include<bitset>
#include<cmath>

using namespace std;
using int_greater_PQ = priority_queue<int,vector<int>,greater<int>>;


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


    cout<<r*r<<endl;
    
    return 0;
}

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

int n,q;
int num;
vector<int> a;

bool can_make_m_from_a(int m,int it) {
  if(m == 0)
    return true;
  else if(m < 0)
    return false;
  else if(it == n)
    return false;
  else
    return (can_make_m_from_a(m-a[it],it+1) || can_make_m_from_a(m,it+1));
}

int main() {
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> num;
    a.push_back(num);
  }
  cin >> q;
  for(int i=0;i<q;i++) {
    int m;
    cin >> m;
    if(can_make_m_from_a(m,0))
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }

}

Measured memory_bytes: 1208
A = []

for i in range(3):
    for number in input().split():
        A.append(int(number))

N = int(input())

for _ in range(N):
    ball = int(input())
    if ball in A:
        A[A.index(ball)] = 0


def bingo(card):
    # 横の確認
    if sum(card[:3]) == 0 or sum(card[3:6]) == 0 or sum(card[6:]) == 0:
        return True

    # 縦
    if sum(card[::3]) == 0 or sum(card[1::3]) == 0 or sum(card[2::3]) == 0:
        return True

    # 斜め
    if sum(card[::4]) == 0 or sum(card[2:7:2]) == 0:
        return True


if bingo(A):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N, M, Q; 
vector<vector<int>> mtrx;
int ans;

void dfs(vector<int> A)
{
	if (A.size() == N + 1) {
      	int now = 0;
      	for (int i = 0; i < Q; i++) {
        	if (A[mtrx[i][1]] - A[mtrx[i][0]] == mtrx[i][2]) {
            	now += mtrx[i][3];
            } 
        }
      	ans = max(ans, now);
    	return;
    }
  	A.push_back(A.back());
  	while (A.back() <= M) {
      	dfs(A);
    	A.back()++;
    }
}

int main()
{
	cin >> N >> M >> Q;
  	mtrx = vector<vector<int>>(Q, vector<int>(4));
  	for (int i = 0; i < Q; i++) {
      	for (int j = 0; j < 4; j++) {
        	cin >> mtrx[i][j];
        }
    }
  	dfs(vector<int>(1, 1));
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 3644
import java.io.*;
import java.util.*;
import java.lang.*;

import static java.util.Arrays.*;
import static java.util.Collections.reverseOrder;

/**
 * Created by locona on 2016/06/02.
 */
public class Main  {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int i = 0;
        Integer [] mountains = new Integer[10];
        String line;
        while((line = br.readLine()) != null) {
            mountains[i++] = Integer.valueOf(line);
            if(i >= 10) break;
        }
        sort(mountains, Comparator.reverseOrder());
        for(i=0; i < 3; i++) {
            out.println(mountains[i]);
        }
        out.flush();
    }
}

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

namespace ABC112A
{
    class Program
    {
        static void Main(string[] args)
        {
            int b, c, s;
            s = int.Parse(Console.ReadLine());

            if (s == 1)
            {
                Console.WriteLine("Hello World");
            }
           
            
                if (s == 2)
            {
                b = int.Parse(Console.ReadLine());
                c = int.Parse(Console.ReadLine());
                Console.WriteLine(b + c);
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int J[70000];

int main(){
	
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		long long int S = 0;
		for(int i = 0; i < n; i++){
			int p;
			cin >> p;
			S += p;
		}
		for(int i = 0; i < n - 1; i++){
			cin >> J[i];
		}
		sort(J, J + n - 1);
		long long int ans = S * n;
		for(int i = n - 2; i >= 0; i--){
			S += J[i];
			ans = max(ans, S * (i + 1));
		}
		cout << ans << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3264
(let* ((n (read))
       (arr (make-array n :initial-element 0 :element-type 'fixnum))
       (dparr (make-array (1+ n) :initial-element most-positive-fixnum :element-type 'fixnum)))
  (loop :for k :from 0 :upto (1- n) :do(setf (aref arr k) (read)))
  (setf (aref dparr 0) 0)
  (setf (aref dparr 1) (abs (- (aref arr 0) (aref arr 1))))
  (loop :for k :from 2 :upto (1- n)
        :do (setf (aref dparr k)
                  (min (+ (aref dparr (- k 2))
                          (abs (- (aref arr (- k 2)) (aref arr k))))
                       (+ (aref dparr (- k 1))
                          (abs (- (aref arr (- k 1)) (aref arr k)))))))
  (princ (aref dparr (1- n))))

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

ll f(ll x){
    if(x%2==1)return 3*x+1;
    return x/2;
}

int main(){
   ll s;cin >>s;
   map<ll,int>mp;
   ll i=1;
   while(1){
       mp[s]++;
       if(mp[s]>=2){
           break;
       }
       s=f(s);
       i++;
   }
   cout <<i<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[200004];
int main(){
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];sort (a+1,a+1+n);
	for (int i=2;i<=n;i++) if (a[i]==a[i-1]){
		cout<<"NO";return 0;
	}
	cout<<"YES";
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main(void){
    long long A, A_c, B, K;
    cin >> A >> B >> K;
    A_c = A;
    A -= min(A, K);
    K -= min(A_c, K);
    B -= min(B, K);
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define ford(i,a,b) for(int i=b;i>=a;i--)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    int n,m;
    cin >> n>>m;
    readarr(h,n);
    vi adj[n];
    for(int i=0;i<m;i++){
    	int x,y;
    	cin >> x >> y;
    	adj[x-1].pb(y-1);
    	adj[y-1].pb(x-1);
    }
    vector<bool> vis(n);
    int ans=0;
    for(int i=0;i<n;i++){
    	if(vis[i]) continue;
    	int x=0;
    	vis[i]=1;
    	for(auto k:adj[i]){
    		if(h[i]>h[k]){
    			vis[k]=1;
    			x++;
    		}
    	}
    	if(x==adj[i].size()) ans+=1; 
    }
    cout<<ans<<endl;
    return 0;
}

/* Pooja Yadav */

Measured memory_bytes: 10256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ret = 0
for i in range(int(min(X / 500, A) + 1)):
  for j in range(int(min((X - i * 500) / 100, B) + 1)):
    for k in range(int(min((X - i * 500 - j * 100) / 50, C) + 1)):
      if i * 500 + j * 100 + k * 50 == X:
        ret += 1
print(ret)

Measured memory_bytes: 40176
#include <bits/stdc++.h>
#define MAXF 1200000
#define PI 3.1415926535897932384626433832795028841971693993751058209749445
using namespace std;
typedef long long LL;
 
int BIT[MAXF];
void upd(int x, int v){
	int c = x;
	while(c < MAXF){
		BIT[c] = max(BIT[c], v);
		c += c & -c;
	}	
}
 
int q(int x){
	int c = x;
	int a = 0;
	while(c > 0){
		a = max(a, BIT[c]);
		c -= c & -c;
	}
	return a;
}
 
int main(){
	for(int i = 0; i < MAXF; i++) BIT[i] = 0;
	LL ans = 0;
	LL xxxxx1, yyyyy1, xxxxx2, yyyyy2;
	cin >> xxxxx1 >> yyyyy1 >> xxxxx2 >> yyyyy2;
	LL xxxxx3, yyyyy3, xxxxx4, yyyyy4;
	xxxxx3 = xxxxx1; yyyyy3 = yyyyy1; xxxxx4 = xxxxx2; yyyyy4 = yyyyy2;
	ans += 100 * abs(xxxxx1-xxxxx2) + 100 * abs(yyyyy1-yyyyy2);
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i];
	}
	map<int,int> a, a2, cc;
	if(xxxxx1 > xxxxx2){
		xxxxx1 = 2e8-xxxxx1;
		xxxxx2 = 2e8-xxxxx2;
		for(int i = 0; i < n; i++){
			x[i] = 2e8-x[i];
		}
	}
	if(yyyyy1 > yyyyy2){
		yyyyy1 = 2e8-yyyyy1;
		yyyyy2 = 2e8-yyyyy2;
		for(int i = 0; i < n; i++){
			y[i] = 2e8-y[i];
		}
	}
	a[xxxxx1] = a[xxxxx2] = a[yyyyy1] = a[yyyyy2] = 1;
 
	for(int i = 0; i < n; i++){
		a[x[i]] = a[y[i]] = 1;
	}
	int z = 0;
	for(map<int,int>::iterator it = a.begin(); it != a.end(); it++){
		z++;
		cc[(*it).first] = z;
	}	
	xxxxx1 = cc[xxxxx1];
	xxxxx2 = cc[xxxxx2];
	yyyyy1 = cc[yyyyy1];
	yyyyy2 = cc[yyyyy2];
	LL circles = 0;
	for(int i = 0; i < n; i++){
		x[i] = cc[x[i]]; y[i] = cc[y[i]];
	}
 
	vector<pair<int,int> > newt;
	for(int i = 0; i < n; i++){
		if(x[i] < xxxxx1 || x[i] > xxxxx2 || y[i] < yyyyy1 || y[i] > yyyyy2) continue;
		newt.push_back(make_pair(x[i], y[i]));
	}
	sort(newt.begin(), newt.end());
	for(int i = 0; i < newt.size(); i++){
		//cout<< newt[i].first << " " << newt[i].second << endl;
		LL f = q(newt[i].second) + 1;
		upd(newt[i].second, f);
		circles = max(f,circles);
		//cout << newt[i].first << " " << newt[i].second << endl;
		//cout << f << endl;
	}
	double t = ans;
	//cout << circles << endl;
	t += (PI*(double)5.0 - (double(20.0))) * (double)circles;
	if(circles > abs(xxxxx3-xxxxx4) || circles > abs(yyyyy3 - yyyyy4) ){
		t += (PI*(double)5.0);
	}
	printf("%.15lf\n", t);
}

Measured memory_bytes: 46200
import sys
#input = sys.stdin.readline
def solve():
  n = int(input())
  s = input()
  ans = 0
  for i in range(0,1000):
    t1,t2,t3 = 0,0,0
    c3 = str(i%10)
    c2 = str((i//10)%10)
    c1 = str(i//100)
    for t in range(n):
      if not t1:
        if s[t] == c1:
          t1 = 1
      elif not t2:
        if s[t] == c2:
          t2 = 1
      elif not t3:
        if s[t] == c3:
          t3 = 1
      
    
      if t1 and t2 and t3: 
        ans += 1
        break
  print(ans)
solve()

Measured memory_bytes: 41436
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 01/08/2020

from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

n, k = iia()
arr = iia()
dp = [False for i in range(k + 1)]
for i in range(k + 1):
    for j in arr:
        if i >= j and not dp[i - j]:
            dp[i] = True
if dp[-1]:
    print('First')
else:
    print('Second')

Measured memory_bytes: 79740
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string s;
    cin >> s;
    size_t n = s.length();

    int c_0 = 0;
    int c_1 = 0;
    for (int i=0; i < n; ++i){
        if (s[i]=='0'){
            c_0+=1;
        }else{
            c_1+=1;
        }
    }
    cout << min(c_0, c_1)*2 << endl; 
}

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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define MOD (int)10e9+7

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

ll n;

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

    cin >> n;
    
    if((n&1)) {
        cout << 0 << endl;
        return 0;
    }
    ll cnt = 0;
    for(ll i=10; i <= n; i*=5) {
        cnt+=n/i;
    }
    cout << cnt << endl;
    return 0;

}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int a, b, c, d, x, y,z;
	
	cin >> a >> b >> c >> d;

	z = a + b + c + d;
	x = z / 60;
	y = z%60;

	cout << x<<endl;
	cout << y << endl;

	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 2000000009
int cnt[50];
int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    rep(i,n){
    	char a[105];
    	cin>>a;
    	rep(j,m) cnt[a[j]-'a']++;
    }
    if (n==1&&m==1){
    	cout<<"Yes";
    	return 0;
    }
    int need=(n/2)*(m/2);
    rep(i,50){
    	while (need&&cnt[i]>=4){
    		cnt[i]-=4;
    		need--;
    	}
    }
    if (need>0){
    	cout<<"No";
    	return 0;
    }
    //cout<<"check1";
    need=0;
    if (n%2) need+=m/2;
    if (m%2) need+=n/2;
    int spe=0;
    if (n%2==1&&m%2==1) spe=1;
    rep(i,50){
    	while(need&&cnt[i]>=2){
    		cnt[i]-=2;
    		need--;
    	}
    	if (spe&&cnt[i]%2){
    		spe=0;
    		cnt[i]--;
    	}
    }
    if (need>0||spe){
    	cout<<"No";
    	return 0;
    }
    //cout<<"check2"<<endl;
    rep(i,50){
    	if (cnt[i]){
    		cout<<"No";
    		return 0;
    	}
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
N = int(input())
f = []
for i in range(N):
    raw = int(''.join(input().split()),2)
    f.append(raw)
p = []
for i in range(N):
    raw = list(map(int,input().split()))
    p.append(raw)
def lapCount(n,m):
    return bin(n&m).count("1")
ans = -1000000001
for state in range(1,1024):
    cand = 0
    for i in range(N):
        c = lapCount(state,f[i])
        cand += p[i][c]
    ans = max(ans,cand)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <chrono>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong pow(int x, int n) {
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

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

    string s;
    cin >> s;

    if (s.size() != 26) {
        char add = 'a';
        for (int i = 0; i < 26; ++i) {
            if (s.find((char)(add + i)) == string::npos) {
                cout << s << (char)(add + i) << endl;
                break;
            }
        }
    } else if (s.size() == 26 && s[0] == 'z'){
        cout << -1 << endl;
    } else {
        int pos = 25;
        char search = s[pos];
        bool flag = true;
        while (flag) {
            for (int i = (int)search + 1; i <= 122; ++i) {
                if (s.substr(0, pos).find((char)i) == string::npos) {
                    cout << s.substr(0, pos) << (char) i << endl;
                    flag = false;
                    break;
                }
            }
            --pos;
            search = s[pos];
        }
    }

    return 0;
}

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

using namespace std;

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

	int n, m;
	cin >> n >> m;

	vector<vector<int> > G(n);
	for(int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
	}

	vector<bool> vis(n);

	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if(!vis[i]) {
			int cnt = 0;
			queue<int> q;
			q.emplace(i);
			vis[i] = true;
			while(!q.empty()) {
				int u = q.front();
				q.pop();
				cnt += 1;
				for(int v : G[u]) {
					if(!vis[v]) {
						vis[v] = true;
						q.emplace(v);
					}
				}
			}
			ans = max(ans, cnt);
		}
	}

	cout << ans << '\n';

	return 0;
}


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

using namespace std;
const int MAX = 3004;
int dp[MAX][MAX];

void read(){
    freopen("in.txt", "r", stdin);
}

int getLcsLength(string s, string t){
    int m = s.size(), n = t.size();

    for(int i = 0; i <= m; i++){
        dp[i][0] = 0;
    }

     for(int i = 0; i <= n; i++){
        dp[0][i] = 0;
    }

    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(s[i - 1] == t[j - 1]){
                dp[i][j] = 1 + dp[i - 1][j - 1];
            }
            else{
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
            }
        }
    }
    return dp[m][n];
}


string getString(const string &s, const string &t){
    string ans = "";
    int i = s.size(), j = t.size();
    while(true){
        if(s[i - 1] == t[j - 1]){
                ans += s[i - 1];
                i--, j--;
                if(i == 0 || j == 0){
                    break;
                }
        }
        else{
            if(dp[i][j - 1] > dp[i - 1][j]){
                j--;
                if(j == 0){
                    break;
                }
            }
            else{
                i--;
                if(i == 0){
                    break;
                }
            }
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;

}

int main(){
   // read();
    string s, t; cin >> s >> t;
    int lcs_length  = getLcsLength(s, t);
    cout << getString(s, t);
    return 0;
}




Measured memory_bytes: 35456
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let m: usize = input();

    let ans = if n == 1 && m == 1 {
        1
    } else if n == 1 {
        m - 2
    } else if m == 1 {
        n - 2
    } else {
        (n - 2) * (m - 2)
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
struct block {
	int a, b, c, d;
};
block b[100000];


//入
int c[402];
//出
int e[402];

vector<int> G[402];
bool chked[402];
bool exi[402];
queue<int> q;


void solve() {
	int n, h;
	cin >> n >> h;
	int num = 0;

	rep(i, n) {
		cin >> b[i].a >> b[i].b >> b[i].c >> b[i].d;
		if (b[i].c > 0) {
			e[b[i].c]++;
			exi[b[i].c] = true;
			if (b[i].d > 0) {
				c[h + b[i].d]++;
				G[b[i].c].push_back(h + b[i].d);
				exi[h + b[i].d] = true;
			}
			else {
				c[b[i].b]++;
				G[b[i].c].push_back(b[i].b);
				exi[b[i].b] = true;
			}
		}
		else {
			e[h + b[i].a]++;
			e[401]++;
			exi[401] = true;
			if (b[i].d > 0) {
				c[h + b[i].d]++;
				G[401].push_back(h + b[i].d);
				G[h + b[i].a].push_back(h+b[i].d);
				exi[h + b[i].d] = true;
			}
			else {
				c[b[i].b]++;
				G[h + b[i].a].push_back(b[i].b);
				G[401].push_back(b[i].b);
				exi[b[i].b] = true;
			}
		}
	}
	int th = 0;
	int s = 0;
	rep1(i, h) {
		int dif = c[i] - e[i];
		if (dif < 0) {
			cout << "NO" << endl; return;
		}
		rep(j, dif) {
			exi[i] = true;
			G[i].push_back(401);
		}
		s += dif;
	}
	/*if (s == 0) {
	cout << "NO" << endl; return;
	}*/
	int st = 0;
	Rep1(i, h + 1, 400) {
		int dif = c[i] - e[i];
		if (dif > 0) {
			cout << "NO" << endl; return;
		}
		st += c[i];
	}
	if (s + st != e[401]) {
		cout << "NO" << endl; return;
	}

	bool exiroad[402][402] = {};
	rep(i, 402) {
		if (!exi[i])continue;
		fill(chked, chked + 402, false);
		q.push(i); chked[i] = true;
		while (!q.empty()) {
			int x = q.front(); q.pop();
			rep(j, G[x].size()) {
				int to = G[x][j];
				if (chked[to])continue;
				chked[to] = true; q.push(to);
			}
		}
		rep(j, 402) {
			if (chked[j]) {
				exiroad[i][j] = true;
			}
		}
	}
	rep(i, 402) {
		if (!exi[i])continue;
		Rep(j, i + 1, 402) {
			if (!exi[j])continue;
			if (!exiroad[i][j] || !exiroad[j][i]) {
				cout << "NO" << endl; return;
			}
		}
	}
	cout << "YES" << endl;
}

int main() {
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
int main(){
	map<string, int> mp;
	mp["SUN"] = 0;
	mp["MON"] = 1;
	mp["TUE"] = 2;
	mp["WED"] = 3;
	mp["THU"] = 4;
	mp["FRI"] = 5;
	mp["SAT"] = 6;
	char s[5];
	scanf("%s", s);
	printf("%d\n", 7 - mp[s]);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int L;
ll dp[200010][5];
ll A[200010];
ll bsum[200010];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> L;
    for(int i = 0; i < L; ++i){
        cin >> A[i];
        for(int j = 0; j <= 4; ++j){
            dp[i + 1][j] = linf;
        }
    }
    for(int i = L - 1; i >= 0; --i){
        bsum[i] = A[i] + bsum[i + 1];
    }
    dp[0][4] = bsum[0];
    for(int i = 0; i <= L; ++i){
        chmin(dp[i + 1][1], dp[i][0]);
        chmin(dp[i + 1][1], dp[i][1] + (A[i] + 1) % 2);
        chmin(dp[i + 1][1], dp[i][2] + (A[i] + 1) % 2);

        chmin(dp[i + 1][2], dp[i][0] + (A[i] == 0 ? 2 : A[i] % 2));
        chmin(dp[i + 1][2], dp[i][2] + (A[i] == 0 ? 2 : A[i] % 2));

        chmin(dp[i + 1][3], dp[i][1] + (A[i] == 0 ? 2 : A[i] % 2));
        chmin(dp[i + 1][3], dp[i][3] + (A[i] == 0 ? 2 : A[i] % 2));

        chmin(dp[i][4], dp[i][1] + bsum[i]);
        chmin(dp[i][4], dp[i][2] + bsum[i]);
        chmin(dp[i][4], dp[i][3] + bsum[i]);
        dp[i + 1][4] = dp[i][4];

        dp[i][0] += A[i];
        dp[i + 1][0] = dp[i][0];
    }
    cout << dp[L][4] << endl;
    return 0;
}

Measured memory_bytes: 11264
S = [list(map(int, input().split())) for i in range(3)]
C1=S[0][0]
C2=S[0][1]
C3=S[0][2]
C4=S[1][0]
C5=S[1][1]
C6=S[1][2]
C7=S[2][0]
C8=S[2][1]
C9=S[2][2]

if C4-C1==C6-C3 and C6-C3==C5-C2 and C7-C1==C8-C2 and C8-C2==C9-C3:
    print('Yes')
else:print('No')

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  while (true) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 and y == 0) return;
    if (x > y) swap(x, y);
    cout << x << " " << y << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}



Measured memory_bytes: 3020
n=int(input())
h=list(map(int,input().split()))
ans=0
ans=min(h)
l=[min(h)]*n
#print(l)
while l!=h:
    x=0
    for i in range(n):
        if x==0:
            if i!=n-1:
                if l[i]!=h[i]:
                    l[i]+=1
                    x=1
            else:
                if l[i]!=h[i]:
                    l[i]+=1
                    x=1
                    ans+=1
        elif i!=n-1:
            if l[i]!=h[i]:
                l[i]+=1
            else:
                ans+=1
                break
        else:
            if l[i]!=h[i]:
                l[i]+=1
                ans+=1
            else:
                ans+=1
    #print(l,ans)
print(ans)

Measured memory_bytes: 3064
n, d = gets.split.map(&:to_i)
array = []
n.times do
  array << gets.split.map(&:to_i)
end

count = 0

n.times do |i|
  n.times do |j|
    if i == j
      next
    end

    square = 0
    d.times do |k|
      square += (array[i][k] - array[j][k]) ** 2
    end
    route = square ** (0.5)
    if route.to_i == route
      count += 1
    end
  end
end

 p count / 2

Measured memory_bytes: 1916
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vishal Burman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            out.println((a * b) + " " + (2 * (a + b)));
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}




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

int main()
{
	int a,b,c,d;
	scanf("%d %d %d %d", &a,&b,&c,&d);
	 
	if(max(a,c)<=min(b,d)) cout << min(b,d)-max(a,c);
	else cout << 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	ll A[3];
	cin >> N >> A[0] >> A[1] >> A[2];
	vector<ll> l(N);
	REP(i, N) cin >> l[i];
	ll ma = 1;
	REP(i, N) ma *= 4;
	ll res = LLONG_MAX/3;
	REP(i, ma){
		ll tmp = i;
		vector<ll> v(N);
		REP(j, N){
			v[j] = tmp%4;
			tmp /= 4;
		}

		ll tmp_val = 0;
		vector<ll> count(3, 0);
		REP(j, N){
			REP(k, 3){
				if(v[j]==k){
					if(count[k]!=0) tmp_val += 10;
					count[k] += l[j];
				}
			}
		}
		if(count[0] ==0 || count[1] == 0 || count[2] == 0) continue;
		REP(k, 3){
			tmp_val += abs(count[k]-A[k]);
		}
		res = min(tmp_val, res);
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> data, ans(N);
  int count = 1;
  for(int i = 0; i < N - 1; i++){
    if(S.at(i) == S.at(i + 1)){
      count++;
    } else {
      data.push_back(count);
      count = 1;
    }
  }
  data.push_back(count);
  count = 0;
  for(int i = 0; i < data.size() / 2; i++){
    count += data.at(i * 2);
    if(data.at(i * 2) % 2 == 0){
      ans.at(count - 1) += data.at(i * 2) / 2;
      ans.at(count) += data.at(i * 2) / 2;
    } else {
      ans.at(count - 1) += (data.at(i * 2) / 2) + 1;
      ans.at(count) += data.at(i * 2) / 2;
    }
    if(data.at(i * 2 + 1) % 2 == 0){
      ans.at(count - 1) += data.at(i * 2 + 1) / 2;
      ans.at(count) += data.at(i * 2 + 1) / 2;
    } else {
      ans.at(count - 1) += data.at(i * 2 + 1) / 2;
      ans.at(count) += (data.at(i * 2 + 1) / 2) + 1;
    }
    count += data.at(i * 2 + 1);
  }
  for(int i = 0; i < N; i++)cout << ans.at(i) << ' ';
  cout << endl;
  return 0;
}

Measured memory_bytes: 1528
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
using pll = pair<ll, ll>;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using ti3 = tuple<int, int, int>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
int dp[2][51];
int main() {
	string a, b, c;
	while (cin >> a, a != "0") {
		cin >> b >> c;
		vector<vll> dp(2, vll(51));
		dp[0][0] = 1;
		reverse(ALL(a));
		reverse(ALL(b));
		reverse(ALL(c));
		rep(i, a.length()) {
			rep(j, 2) {
				int x = (a[i] == '?' ? (i == a.length() - 1 ? 1 : 0) : a[i] - '0');
				do {
					int y = b[i] == '?' ? (i == a.length() - 1 ? 1 : 0) : b[i] - '0';
					do {
						if (c[i] == '?' || (x + y + j) % 10 == c[i] - '0')dp[x + y + j>9][i + 1] =(dp[x + y + j>9][i + 1]+ dp[j][i])%(ll)(1e9+7);
						y++;
					} while (b[i] == '?'&&y != 10);
					x++;
				} while (a[i] == '?'&&x < 10);
			}
		}
		cout << dp[0][a.length()] << endl;
	}
}

Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	while (cin >> n)
	{
		int ans = 0;
		for (int i = 0; i < (600 / n); i++)
		{
			ans += (i * n * n * i * n);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> pint;
typedef map <int,int> mapii;
typedef map <char,int> mapci;
typedef map <string,int> mapsi;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <char> vc;
typedef set <int> si;
typedef set <ll> sll;
typedef set <char> sc;
#define pb(i) push_back(i) ;
#define ms(arr) memset(arr,0,sizeof(arr))
#define deb(x) cout<< #x <<" "<< x<<endl;
#define loop(i,n) for(int i=0;i<n;i++)
#define Loop(i,k,n) for(ll i=k;i<=n;i++)
#define testcase int t;cin>>t; while(t--)

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    int d=a-b;
    int e=c-d;
    if(e>=0)
        cout<<e;
    else
        cout<<0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

bool dp(int i, int x, const vector<int> xs, char x_or_y){// i回目にxにいられるかどうか                                                                                          
  if(i == 0){
    if(x == 0) return true;
    else return false;
  }

  int sum = 8000;
  int memo_size = 2 * sum + 1;
  bool memo[i][memo_size];
  for(int a=0; a<i; a++)
    for(int b=0; b<memo_size; b++)
      memo[a][b] = false;

  // 境界条件                                                                                                                                                                   
  if(x_or_y == 'x')
    memo[0][sum+xs[0]] = true;
  else if(x_or_y == 'y'){
    memo[0][sum+xs[0]] = true;
    memo[0][sum-xs[0]] = true;
  }

  for(int a=1; a<i; a++){
    for(int b=0; b<memo_size; b++){
      if(memo[a-1][b]){
        memo[a][b+xs[a]] = true;
        memo[a][b-xs[a]] = true;
      }
    }
  }

  return memo[i-1][sum+x];
}

int main(){
  string s;
  int x, y;
  cin >> s >> x >> y;
  int i = 0;
  vector<int> iter_xs, iter_ys;
  while(i < s.size()){
    int iter_x = 0, iter_y = 0;
    while(s[i] != 'T' && i < s.size()){
      iter_x++; i++;
    }
    iter_xs.push_back(iter_x);
    i++;
    while(s[i] != 'T' && i < s.size()){
      iter_y++; i++;
    }
    iter_ys.push_back(iter_y);
    i++;
  }
  if(dp(iter_xs.size(), x, iter_xs, 'x') && dp(iter_ys.size(), y, iter_ys, 'y'))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

#ifdef LOCAL 
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

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




const int maxn = 111;
int w[maxn];
int n;

int main() 
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &w[i]);
    }
    int ans = 1e9;
    int sm1 = 0;
    int sm2 = accumulate(w, w + n, 0);
    for (int i = 0; i < n; ++i) {
        sm1 += w[i];
        sm2 -= w[i];
        ans = min(ans, abs(sm1 - sm2));
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 256
n,m=map(int,input().split())
if m==0:
    print(0)
    exit()
ans=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    ans[a-1].append((b-1))
    ans[b-1].append((a-1))
v=[]#全ての点を訪問済み
def dfs(now,visited=[]):
    
    if len(visited)==n:
        v.append([visited])
        return
    for j in ans[now]:
        if j not in visited:
            dfs(j,visited+[j])
dfs(0,[0])
print(len(v))


Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
int main() {
  int l;
  cin >> l;
  int a[l];
  for (int i = 0; i < l; i++){
    cin >> a[i];
  }
  
  int total = 0;
  for (int i = 0; i < l; i++){
    for (int j = i + 1; j < l; j++){
      total += a[i] * a[j];
    }
  }
  cout << total;
}

Measured memory_bytes: 256
MOD = 998244353

N = int(input())
Ss = input()

iRs, iGs, iBs = [], [], []
for i, S in enumerate(Ss):
    if S == 'R':
        iRs.append(i)
    elif S == 'G':
        iGs.append(i)
    else:
        iBs.append(i)

iMins, iMaxs, iRests = [], [], []
for iRGB in zip(iRs, iGs, iBs):
    iRGB = sorted(iRGB)
    iMins.append(iRGB[0])
    iRests.append(iRGB[1])
    iMaxs.append(iRGB[2])

ans = 1
iiMin = iiMax = 0
for ii, iRest in enumerate(iRests):
    while iiMin < N and iMins[iiMin] < iRest:
        iiMin += 1
    while iiMax < N and iRest > iMaxs[iiMax]:
        iiMax += 1
    ans *= (iiMin-ii) * (N-iiMax-(N-1-ii))
    ans %= MOD

factN = 1
for i in range(1, N+1):
    factN = (factN * i) % MOD

print(ans*factN % MOD)


Measured memory_bytes: 18400
#include <stdio.h>

int main(){
  int n,i,j,m=0;
  char s[55],c[3]={'A','B','C'};
  scanf("%d",&n);
  scanf("%s",&s);
  i=0;
  for(j=0;j<n;j++){
    if(c[i]==s[j]){
      i++;
    }else{
      if(s[j]==c[0]){
        i=1;
      }else{
        i=0;
      }
    }
    if(i==3){
      i=0;
      m++;
    }
  }
  printf("%d",m);
  return(0);
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (auto &v : vec)
    cin >> v;

  bool init = true;
  int status = 0;
  int cnt = 1;
  for (int i = 1; i < n; ++i) {
    if (vec[i-1] == vec[i]) {
    }
    else if (vec[i-1] < vec[i]) {
      if (status == -1) {
        ++cnt;
        status = 0;
      }
      else {
        status = 1;
      }
    }
    else {
      if (status == 1) {
        ++cnt;
        status = 0;
      }
      else {
        status = -1;
      }
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 3780
import java.util.*;

/**
 * TheBalanceoftheWorld
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        loop: while (true) {
            String str = sc.nextLine();

            if (str.equals("."))
                break;
            char array[] = str.toCharArray();

            Stack<Character> stack = new Stack<Character>();

            for (int i = 0; i < array.length; i++) {
                switch (array[i]) {
                case '(':
                    stack.add('(');
                    break;
                case ')':
                    try {
                        if (stack.pop() != '(') {
                            System.out.println("no");
                            continue loop;
                        }
                    } catch (Exception e) {
                        System.out.println("no");
                        continue loop;
                    }
                    break;
                case '[':
                    stack.add('[');
                    break;
                case ']':
                    try {
                        if (stack.pop() != '[') {
                            System.out.println("no");
                            continue loop;
                        }
                    } catch (Exception e) {
                        System.out.println("no");
                        continue loop;
                    }

                    break;
                }
            }

            if (stack.empty()) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }

        }
    }
}


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

int main ()
{
     long long int A,B,i;
     scanf("%lld %lld",&A,&B) ;

     i=1;
     while(1){
        if((A*i)%B==0)break ;

        else i++;
     }
    printf("%lld\n",A*i) ;

     return 0 ;
}


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

int main(void) {
	int h[101]={};
	int w[101]={};
	int ha[101]={};
	int wa[101]={};
	int j,k;
	int i=0;
	do{
		i++;
		scanf("%d",&h[i]);
		scanf("%d",&w[i]);
	}while(!((h[i]==0)&&(w[i]==0)));
	i=0;
	do{
		i++;

		int flag=0;
		int tmph=0;
		int tmpw=0;

		int taikaku=0;
		taikaku=(h[i]*h[i])+(w[i]*w[i]);

		for(j=h[i]+1;j<w[i];j++){
			tmpw=sqrt(taikaku-j*j);
			if(((tmpw*tmpw)==(taikaku-j*j))&&!(j==tmpw)){
				ha[i]=j;
				wa[i]=tmpw;
				flag=1;
				break;
			}
		}
		if(flag==0){
			for(k=1;k<101;k++){
				taikaku++;
				for(j=1;j<101;j++){
					if(taikaku<=j*j){
						break;
					}

					tmpw=sqrt(taikaku-j*j);
					if((tmpw*tmpw)==(taikaku-j*j)&&!(j==tmpw)){
						ha[i]=j;
						wa[i]=tmpw;
						flag=1;
						break;
					}
				}
				if(flag==1){
					break;
				}
			}

		}




	}while(!((h[i]==0)&&(w[i]==0)));
	i=1;
	do{

		printf("%d %d\n",ha[i],wa[i]);
		i++;


	}while(!((h[i]==0)&&(w[i]==0)));


	return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;
LL dp[8][1001][1001];

int main(){
  int n,m;
  cin >> n >> m;
  vector<LL> x(n+1),y(n+1),z(n+1);
  for(int i=1;i<=n;i++){
    cin >> x[i] >> y[i] >> z[i];
  }
  for(int i=0;i<8;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<m;k++){
        dp[i][j][k]=-1000000000000000000;
      }
    }
    for(int j=0;j<n;j++) dp[i][j][0]=0;
    for(int j=1;j<=n;j++){
      for(int k=1;k<=m;k++){
        dp[i][j][k]=max(dp[i][j-1][k],dp[i][j-1][k-1]+x[j]*(1-i/4*2)+y[j]*(1-i%4/2*2)+z[j]*(1-i%2*2));
      }
    }
  }
  LL ans=-1000000000000000000;
  for(int i=0;i<8;i++){
    ans=max(ans,dp[i][n][m]);
  }
  cout << ans << endl;
  return 0;
}


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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)


int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll a,b;
        cin>>a>>b;
        cout<<a*b;

    }
    return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;
public class Main{
	static boolean map[][]=new boolean[12][12];
	static int ans=0; 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			for(int i=0;i<12;i++){
				char[] c = sc.next().toCharArray();
				for(int j=0;j<12;j++){
					map[i][j]=c[j]=='1';
				}
			}
			int ans=0;
			for(int i=0;i<12;i++){
				for(int j=0;j<12;j++){
					if(map[i][j]){
						dfs(i, j);
						ans++;
					}
				}
			}
			System.out.println(ans);
		}	
	}
	public static void dfs(int x,int y){
		map[x][y] = false;
		int x_c[]={1,0,-1,0};
		int y_c[]={0,1,0,-1};
		for(int i=0;i<4;i++){
			int x1=x+x_c[i];
			int y1=y+y_c[i];
			if(0<=x1&&0<=y1&&x1<12&&y1<12&&map[x1][y1])//
				dfs(x1, y1);		
		}
	}
}

Measured memory_bytes: 15356
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

for i in range(N - K):
  if T[K + i] == T[i]:
    T[K + i] = 0
    
print(T.count('r') * P + T.count('s') * R + T.count('p') * S)

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define ll long long
#define pll pair<ll,ll>
// typedef tree <ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define vvi vector<vi>
#define P_Q priority_queue<ll>
#define p_q priority_queue<ll,vi,greater<ll>>
#define pb push_back
#define popb pop_back
#define ub upper_bound
#define lb lower_bound
#define loop(i,x,y,z) for(int i=x; i<=y; i+=z)
#define loopR(i,x,y,z) for(int i=x; i>=y; i-=z)
#define all(x) begin(x), end(x)
#define allR(x) rbegin(x), rend(x)
#define sum(x) accumulate(all(x),0LL)
#define minE(x) *min_element(all(x))
#define maxE(x) *max_element(all(x))
#define watch(x) cout<<(#x)<<" is "<<x<<'\n'
#define display(v,c) for(auto x:v) cout<<x<<c;
#define setbits(x) __builtin_popcount(x)
#define ctoi(x) (int)((x)-'0')
#define endl "\n"

int main(){
	IOS
	// do magic here
	ll n;
	cin>>n;
	ll ans=LLONG_MAX;
	vector<pll> factPairs;
	for(ll i=1; i*i<=n; i++) if(n%i==0) factPairs.pb({i,n/i});
	for(auto x:factPairs){
		ans=min(ans,x.first+x.second-2);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=405;

ll n;

ll solve(){
	ll ans=LLONG_MAX;
	for(ll i=1;i<=sqrt(n);i++){
		if(n%i==0){
			ans=min(ans,i+n/i-2);
		}
	}
	return ans;
}

int main(){
	//fri("in.txt");
	//fro("out.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	cout<<solve();
	


return 0;
}

Measured memory_bytes: 256