akhauriyash/Code-Regression huggingface dataset:
import numpy as np


def main():
    n = int(input())
    d = [list(map(int, input().split())) for i in range(n)]

    dp = np.zeros((n, 3), dtype='int')
    dp[0] = d[0]

    for i in range(1, n):
        dp[i][0] = max(dp[i - 1][1] + d[i][0], dp[i - 1][2] + d[i][0])
        dp[i][1] = max(dp[i - 1][0] + d[i][1], dp[i - 1][2] + d[i][1])
        dp[i][2] = max(dp[i - 1][0] + d[i][2], dp[i - 1][1] + d[i][2])

    print(max(dp[-1]))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 50636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
??°???????????¢

?????????????????°???????????????????????????????????°?????????????????????????????????

Input
??\????????\????????¢?????§?????????????????????

n
a1 a2 . . . an
n ?????°????????????????????????ai ??? i ???????????°?????¨????????????

Output
???????????°?????????????????????????????????????????°??????????´??????????????????????????????\?????????????????????????????°????????????????????\??????????????¨?????¨????????????????????????

Constraints
n ??? 100
0 ??? ai < 1000

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_A

 * @author wsKmatsuda
 *
 */
public class Main{

	public static void main(String[] args) {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			int num = Integer.parseInt(reader.readLine());
			String[] numData = reader.readLine().split(" ");
			outputReverseArray(numData);

		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	/**
	 *
	 * @param numData
	 */
	private static void outputReverseArray(String[] numData) {

		List<String> revList = new ArrayList<String>();
		for(int i=numData.length-1 ; i > -1; i--){
			revList.add(numData[i]);
		}
		for(int i=0;i<revList.size();i++){
			System.out.print(revList.get(i));
			if(i != revList.size()-1){
				System.out.print(" ");
			}
		}
		System.out.println();
	}

}

Measured memory_bytes: 24196
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
#define _GLIBCXX_DEBUG//only for debugging
#include <bits/stdc++.h>
#include <ext/rope>
#define VALHALLA cin.tie(0)->ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(13);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod=1e9+7;
/* VARIABLE DECLARATION START */
int fact[int(2e5+1)];
int inv[int(2e5+1)];
/*  FUCNTION TEMPLATE STARTS  HERE */

double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
 {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
 {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
bool isprime(ll n) {
    if (n == 2 || n == 3) return true;
    if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
        if (n % (i - 1) == 0 || n % (i + 1) == 0) {
            return false;
        }
    }
    return true;
}
inline ll exp(ll a, ll b, ll mod) {
    ll n = 1;
    ll p = a;
    while (b > 0) {
        if (b % 2 == 1) {
            n *= p;
            n %= mod;
        }
        p *= p;
        p %= mod;
        b /= 2;
    }
    return n;
}

inline bool comp(double a,double b)
{
  return (fabs(a-b)<epsilon);
}
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

/*  FUCNTION TEMPLATE ENDS HERE */
int main()
{
   VALHALLA  
   string s;cin>>s;
   string v;
  for(int i=0;i<sz(s);++i)
   {
      if(s[i]=='B')
      {
        if(sz(v)>0)
          v.pop_back();
      }
      else
        v.pb(s[i]);
   }
   
   cout<<v<<endl;


}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    n %= 10;
    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
        cout << "hon" << endl;
    }else if(n == 3){
        cout << "bon" << endl;
    }else{
        cout << "pon" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
import Data.List
-- n を k 進数
solve t n = loop t 0 
    where
        loop :: Int -> Int -> [Int]
        loop t i
            | t == 0 = []
            | otherwise =
                let
                    (t', k) = quotRem t n
                in
                    k : loop t' (i+1)

main = do
    [n, k] <- map read . words <$> getLine :: IO [Int]
    print $ length $ solve n k

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

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

const long long MOD = 1000000007;

int main(){
  ll h;
  ll k=0,ans=0,x=1;
  cin >> h;
  while(h!=1){
    h/=2;
    k++;
  }
  rep(i,k+1) x*=2;
  ans = x -1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<queue>
#include<vector>
using namespace std;
int main(){
    int N,Q;
    cin>>N>>Q;
    queue<pair<string,int>>P;
    for(int i=0;i<N;++i){
        string s;
        int t;
        cin>>s>>t;
        P.push({s,t});
    }
    int c=0;
    list<pair<string,int>> L;
    while(!P.empty()){
        string s=P.front().first;
        int x=P.front().second;
        if(x>Q){
            c+=Q;
            P.push({s,x-Q});
            P.pop();
        }else{
            c+=x;
            L.push_back({s,c});
            P.pop();
        }
    }
    for(auto&a:L) cout<<a.first<<' '<<a.second<<endl;
}

Measured memory_bytes: 7852
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

int main() {
    int n;
    cin >> n;
    vl data;
    InputV(data, n);
    int times = 0;
    long min;
    if(n ==1){
        cout << data[0] << endl;
        cout << 0 <<  endl;
        return 0;
    }
    F(i, 0, n){
        min = i;
        F(j, i, n){
            if(data[j] < data[min]){
                min = j;
            }
        }
        if(i != min){
        swap(data[i], data[min]);
        times++;
        }
    }
    printV(data);
    cout << times << endl;
}



Measured memory_bytes: 3140
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

using namespace std;
using ll = long long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

int main() {
    int N; cin >> N;
    int A; cin >> A;
    int B; cin >> B;

    cout << min(N * A, B) << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($A,$B) = explode(" ",trim(fgets(STDIN)));
//$A  = explode(" ",trim(fgets(STDIN)));
$t = $A*100+$B;
$cnt=0;
for($i=101;$i<=$t;$i+=101) {
  $cnt++;
}
printf("%d\n",$cnt);


Measured memory_bytes: 3828
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char op;
    while(1){
        cin>>a>>op>>b;
        if(op=='+'){
            cout<<a+b<<endl;
        }
        else if(op=='-'){
            cout<<a-b<<endl;
        }
        else if(op=='*'){
            cout<<a*b<<endl;
        }
        else if(op=='/'){
            cout<<a/b<<endl;
        }
        else if(op=='?'){
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int a,b,c,k;cin>>a>>b>>c>>k;
  int ans=a+b+c;
  int m=max(a,max(b,c));
  ans-=m;
  ans+=m*round(pow(2,k));
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
a=list(map(int,input().split()))
a.sort()
ans=0
while a[0] != a[2]:
  if a[2] == a[0] + 1:
    a[0] += 1
    a[1] += 1
    a.sort()
    ans += 1
  else:
    a[0] += 2
    a.sort()
    ans += 1
print(ans)

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

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

Measured memory_bytes: 3628
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;

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

class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int[] a = new int[2 * n];
        for (int i = 0; i < 2 * n; ++i)
            a[i] = in.nextInt();
        Arrays.sort(a);
        int res = 0;
        for (int i = 0 ;i < n; ++i)
            res += a[2 * i];
        out.printLine(res);
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buffer = new byte[10000];
    private int cur;
    private int count;

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

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

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

    public int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

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

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) {
                writer.print(' ');
            }
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

}



Measured memory_bytes: 8148
#include <stdio.h>
int main (){
	int h,w,r;
	for (int i=1; ; i++)
	{
		scanf ("%d %d",&h,&w);
		if (h==0 && w==0)
		{
			break;
		}
		for (int j=1;j<=h;j++)
		{
			for (int k=1;k<=w;k++)
			{
			r=(j+k)%2;
                if(r==1){
                    printf(".");
                }else{
                    printf("#");
                }
			}
			printf ("\n");
		}
		printf ("\n");
	}
	return 0;
}


Measured memory_bytes: 1964
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, R; cin >> N >> R;
  if (N >= 10) {
    cout << R << endl;
  }else {
    cout << 100 * (10 - N) + R << endl;
  }

  return 0;
}



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

using namespace std;

int main(void) {
	int a, b, c;
	int p, q, r;
	cin >> a >> b >> c;
	p = a + b;
	q = b + c;
	r = c + a;
	if (p > q) {
		if (q > r) {
			cout << r << endl;
		}
		else {
			cout << q << endl;
		}
	}
	else if (q > r) {
		if (r > p) {
			cout << p << endl;
		}
		else {
			cout << r << endl;
		}
	}
	else if (r > p) {
		if (p > q) {
			cout << q << endl;
		}
		else {
			cout << p << endl;
		}
	}
	else {
		cout << p << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
	int n, m, a[100], s[100], b[100][100];
	std::cin >> n >> m;
	for (int i = 0; i < n; ++i) {s[i] = 0;}
	for (int i = 0; i < m; ++i) {
		std::cin >> a[i];
	}
	for (int j = 0; j < m; ++j) {
		for (int i = 0; i < n; ++i) {
			std::cin >> b[j][i];
		}
	}
	for (int j = 0; j < m; ++j) {
		for (int i = 0; i < n; ++i) {
			if (a[j] == b[j][i]) {
				s[i] += 1;
			}
			if (a[j] != b[j][i]) {
				s[a[j]-1] += 1;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		std::cout << s[i] << std::endl;
	}
}


Measured memory_bytes: 3124
n = int(input())
if n >= 400:
  if n >= 600:
    if n >=800:
      if n >= 1000:
        if n >= 1200:
          if n >= 1400:
            if n >= 1600:
              if n >= 1800:
                print(1)
              else:
                print(2)
            else:
              print(3)
          else:
            print(4)
        else:
          print(5)
      else:
        print(6)
    else:
      print(7)
  else:
    print(8)
else:
  pass

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


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

    cout<< ((a*b > c*d) ? a*b : c*d ) <<endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <vector>
#include <set>
#include <queue>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <map>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace gnu_pbds;

#define F first
#define S second
#define ll long long
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define piii pair<int, pii>
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define int long long
// #define ld long double


const int N = 1e5 + 20, mod = 1e9 + 7, inf = 2e9 + 9;
const ll INF = 1e18 + 20;

int n, s, dp[101][N], w[101], v[101];
bool was[101][N];

signed main() { __
    // freopen("a.in", "r", stdin);
    // freopen("a.out", "w", stdout);
    cin>>n>>s;
    for(int i = 1; i <= n; i++) {
        cin>>w[i]>>v[i];
    }
    int ans = 0;
    for(int i = 0; i <= n; i++) was[i][0] = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= s; j++) {
            dp[i][j] = dp[i - 1][j];
            if(j >= w[i]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
//                was[i][j] = 1;
            }

        }
    }
    for(int i = 1; i <= s; i++) {
        ans = max(ans, dp[n][i]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 87040
#include <bits/stdc++.h>
//#define int long long
using namespace std;
using T = tuple<int, int, int>;

int main() {
    int n;
    cin >> n;
    vector<T> V(n * 2);
    int a, b, c;
    for (int i = 0; i < n; i++){
        cin >> a >> b;
        V[i] = T(a, b, 0);
    }
    for (int i = n; i < n * 2; i++){
        cin >> a >> b;
        V[i] = T(a, b, 1);
    }
    sort(V.begin(), V.end());

    int ans = 0;
    set<int> S;
    for (int i = 0; i < n * 2; i++) {
        tie(a, b, c) = V[i];
        if (c == 0) {
            S.insert(b);
        } else {
            auto it = S.lower_bound(b);
            if (it != S.begin()) {
                it--;
                S.erase(it);
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
 
for i in range(10**n):
    if len(str(i))!=n:
        continue
    if m == 0:
        print(i)
        exit()
    for j in range(m):
        if str(i)[sc[j][0]-1] == str(sc[j][1]):
            if j == m-1:
                print(i)
                exit()
        else:
            break
print(-1)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
	int a,b,x,y;
	cin>>a>>b>>x>>y;
	if(a+b>x+y)
	{
		cout<<"Left"<<endl;
		return 0;
	}
	if(a+b<x+y)
	{
		cout<<"Right"<<endl;
		return 0;
	}
	else
	{
		cout<<"Balanced"<<endl;
		return 0;
	}
}

Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_7_D
//p205.cpp

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r){
	if ( l >= r ) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root ));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve(){
	pos = 0;
	rec(0, pre.size() );
	for ( int i = 0; i < n; i++ ){
		if ( i ) cout << " ";
		cout << post[i];
	}
	cout << endl;
}

int main(){
	int k;
	cin >> n;

	for ( int i = 0; i < n; i++ ){
		cin >> k;
		pre.push_back(k);
	}

	for ( int i = 0; i < n; i++ ){
		cin >> k;
		in.push_back(k);
	}

	solve();

	return 0;
}




Measured memory_bytes: 3160
main :: IO ()
main = do
  [k,x] <- readParams
  putStrLn $ solve k x

readParams :: Read a => IO [a]
readParams = map read . words <$> getLine

solve :: Int -> Int -> String
solve = format .: range

format :: [Int] -> String
format = unwords . map show

range :: Int -> Int -> [Int]
range k x = [x-w..x+w]
  where w = k-1

infixr 8 .:
(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
(f .: g) x y = f $ g x y


Measured memory_bytes: 508
### main

expr = gets.strip
bans = gets.to_i

mf = eval expr

lr = expr[0].to_i
k = 1
while k < expr.length
  if expr[k] == '+'
    lr += expr[k + 1].to_i
  else
    lr *= expr[k + 1].to_i
  end
  k += 2
end

idx = 0
idx |= 1 if bans == mf
idx |= 2 if bans == lr

puts ["I", "M", "L", "U"][idx]

Measured memory_bytes: 6104
import math

R,G,B,N=map(int,input().split())
ans=0
x=[R,G,B]
x.sort(reverse=True)

for i in range(N//x[0]+1):
    n=N-i*x[0]
    for j in range(n//x[1]+1):
        if (n-j*x[1])%x[2]==0: ans+=1

print(ans)

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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define fore_(i, s, e) for(int i = s; i > e; i--)
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FAIL cout << -1 << endl; return 0
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

ll dp[10001][101][2];
ll cota = 1e9 + 7;
string number;
ll digits, r;
ll mod;

ll solve(ll pos, ll sum, ll to9) {
    if(pos == digits) return (sum % mod) == 0;
    if(dp[pos][sum][to9] > -1) return dp[pos][sum][to9];
    ll ret = 0;
    fore(i, 0, (to9 ? 10 : (number[pos] - '0') + 1)) {
        ret = (ret + solve(pos + 1, ((sum + i) % mod), i < (number[pos] - '0') or to9)) % cota;
    }
    dp[pos][sum][to9] = ret % cota;
    return ret;
}

int main() {
    FIN;
    memset(dp, -1, sizeof(dp));
    cin >> number >> mod;
    digits = number.size();
    r = solve(0, 0, 0);

    cout << (r + (cota - 1)) % cota << endl;

    return 0;
}

Measured memory_bytes: 16896
#include<iostream>
#include<map>
#include<string>
#include<cmath>

int main () {
  std::map<std::string,int> blue;
  std::map<std::string,int> data;
  std::map<std::string,int> red;
  int b_num, r_num;
  std::cin >> b_num;
  for (int i=0; i<b_num; i++) {
    std::string str;
    std::cin >> str;
    data[str] = 1;
    if (!blue.count(str)) {
      blue[str] = 1;
    }
    else {
      blue.at(str)++;
    }
  }
  std::cin >> r_num;
  for (int i=0; i<r_num; i++) {
    std::string str;
    std::cin >> str;
    data[str] = 1;
    if (!red.count(str)) {
      red[str] = 1;
    }
    else {
      red.at(str)++;
    }
  }
  int sum = 0;
  for (auto p: data) {
    int temp_sum=0;
    auto key = p.first;
    if (blue.count(key)) {
      temp_sum += blue.at(key);
    }
    if (red.count(key)) {
      temp_sum -= red.at(key);
    }
    sum = std::max(sum ,temp_sum);
  }
  std::cout << sum << std::endl;
}


Measured memory_bytes: 256
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [ for i in 1..n do yield stream.ReadLine().Split() |> Array.map f ]
  member this.ScanCharMatrix n = [ for i in 1..n -> stream.ReadLine().ToCharArray() ]
  member this.Close () = stream.Close()
 
let util = ABC(stdin)
 
let N = util.Scan1 int64
let xs = util.ScanVecV 5 int64
 
// 全ての移動手段が最小値であったとしても答えは変わらない
// その時、最後の集団の待ち時間に 5 を足せばよい
let m = Array.min xs
 
5L + N/m + (if N%m = 0L then -1L else 0L)
|> printf "%d"

Measured memory_bytes: 14172
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
const int mod=998244353;
int n,m;
string s;
map<string,int> ma;
void merge(string &a,string b)
{
	int len=a.length();
	for(int i=0;i<len;i++) if(b[i]=='0') a[i]='0';
}
int dp(string s)
{
	if(s.empty()) return 1;
	if(ma.count(s)) return ma[s];
	int ans=0,n=s.length();
	ans=(1ll+(s[0]=='1'))*dp(s.substr(1,n))%mod;
	for(int i=1;2*i<=n;i++)
	{
		string cur=s.substr(0,i);
		for(int j=2;i*j<=n;j++)
		{
			merge(cur,s.substr(i*(j-1),i*j));
			ans=(ans+1ll*dp(cur)*dp(s.substr(i*j,n))%mod)%mod;
		}
	}
	return ma[s]=ans;
}
int main()
{
	cin>>s;
	cout<<dp(s)<<endl;
}

Measured memory_bytes: 7992
#include <bits/stdc++.h>
using namespace std;
#define ll long long

//ライブラリ始まり

//定数
//円周率
const double pi = 3.1415926535897932384;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}
//素数判定 
//一つ一つの判定ではこっちの方が速い(一つ当たりO(√N))
//一方100までに何個あるかなどはEratosthenesの篩の方が良い（O(NlogN))
bool PN(int x) {
  if (x <= 1) return false; // 1や0,-1は素数ではない
  if (x == 2) return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) return false; // 割れたら素数じゃない
  }
  return true;
}
// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  long long ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}

//ライブラリ終わり
  
//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int A, B;
  cin >> A >> B;
  if (B >= A) {
    cout << A << endl;
  }
  else {
    cout << A - 1 << endl;
  }
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
using namespace std;

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  cout<<A+B+C-max(A,max(B,C))<<endl;
}


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

using namespace std;

typedef long long ll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
ll modpow(ll a,ll b){
  ll r=1;
  while(b){
    if(b&1)r=r*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return r;
}

const int MX = 10002521;
ll fact[MX];
ll ifact[MX];

int h,w,k;

int main(){
  scanf("%d%d%d",&h,&w,&k);
  
  fact[0] = 1;
  FOR(i,1,MX)fact[i] = fact[i-1]*i%MOD;
  ifact[MX-1] = modpow(fact[MX-1], MOD-2);
  FORR(i,1,MX)ifact[i-1] = ifact[i]*i%MOD;
  ll factk;
  if(k<MX){
    factk = fact[k];
  }else{
    factk = fact[MX-1];
    FOR(i,MX,k+1)factk = factk*i%MOD;
  }

  ll ans = 0;
  ll k16 = (k+1) * ifact[3] % MOD;
  FOR(p,max(0,k-w),min(h,k)+1){
    ll X = p;
    ll Y = k-X;
    ll ifxy = ifact[X] * ifact[Y] % MOD;
    ll val = k16 * (2*X*Y%MOD + 3*k + 6) % MOD;
    val = val>0 ? val-1 : MOD-1;
    ans += ifact[h-X] * ifact[w-Y] % MOD * val % MOD * ifact[X] % MOD * ifact[Y] % MOD;
  }
  ans %= MOD;

  ll hw = fact[h] * fact[w] % MOD;
  ans = ans * hw % MOD * factk % MOD;
  
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 156544
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		string str,s[4]={"lu","ru","ld","rd"};
		int f,ans=0;
		cin>>str;
		for(int i=0;i<4;i++){
			if(str==s[i])
			f=i;
		}
		for(int i=1;i<n;i++){
			cin>>str;
			for(int j=0;j<4;j++){
				if(str==s[j]){
					if(f+j==1 ||  f+j==5){
						ans++;
					}
					f=j;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int a, b; cin >> a >> b;
    if (a < b) {
		F0R(i, b) cout << a;
	} else {
		F0R(i, a) cout << b;
	}
	cout << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
// chctxdy
ll a[200005], e[200005];
ll n;
bool check(ll mid){
	for (ll i = 0; i < 2 * n - 1; i++) e[i] = (a[i] >= mid);
    for (ll i = 0; i < n - 1; i++){
        if (e[n - i - 1] == 0 && e[n - i - 2] == 0) return false;
        if (e[n + i - 1] == 0 && e[n + i] == 0) return false;
        if (e[n - i - 1] == 1 && e[n - i - 2] == 1) return true;
        if (e[n + i - 1] == 1 && e[n + i] == 1) return true;
    }
    if (e[0] == 0) return false;
    else return true;
}
void bs(){
    ll l = 1, r = 2 * n - 1;
    while (l < r){
    	ll mid = (l + r + 1) / 2;
    	if (check(mid)) l = mid;
    	else r = mid - 1;
	}
	cout << l << endl;
}
int main(){
	cin >> n;
    for (ll i = 0; i < 2 * n - 1; i++) cin >> a[i];
    bs();
    return 0;
}

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

using namespace std;
int main() {
    int n;
    int ans = 0;
    int max_num_div = 0;

    cin >> n;

    for (int i = 1; i <= n; i++) {
        int cur_num_div = 0;
        int tmp = i;
        while (1) {
            if ( tmp % 2 == 0) {
                cur_num_div++;
                tmp /= 2;
            } else {
                break;
            }
        }
        if (max_num_div <= cur_num_div) {
            max_num_div = cur_num_div;
            ans = i;
        }
    }

    cout << ans << endl;;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 pb(a) push_back(a)g
#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 selectionsort(vector<int>&A, int N){
  int i,j,t, sw =0,minj;
  REP(i,N-1){
    minj = i;
    FOR(j,i,N){
      if(A[j] <A[minj]) minj = j;
    }
    t =A[i]; A[i] = A[minj]; A[minj] = t;
    if(i != minj)sw++;
  }
  return sw;
}

int main(){
int N,i,sw;
cin >> N;
vector<int> A(100);
REP(i,N) cin >> A[i];
sw = selectionsort(A,N);

REP(i,N){
  if(i > 0) cout << " ";
  cout << A[i];
}
cout <<endl;
cout << sw<<endl;
return 0;
}



Measured memory_bytes: 3104
import itertools

N,M,Q = map(int,input().split())
q = []
ans = 0
c = 0
array = [int(i) for i in range(1,M+1)]

for i in range(Q):
    temp = list(map(int,input().split()))
    q.append(temp)

def check(A):
    score = 0
    i = 0
    for a,b,c,d in q:
        i += 1
        if A[b-1]-A[a-1] == c:
#            print(a,b,c,d)
            score += d
#    print(i)
    return score

h = itertools.combinations_with_replacement(array, N)
for v in h:
    ans = max(ans,check(v))
#    print(v)

"""
for i in range(2**M):
    len = 0
    A = []
    for j in range(M):
        if (i>>j) & 1:
            len += 1
            A.append(j+1)
    if len == N:
        print(A)
        ans = max(ans,check(A))
"""
print(ans)


Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

vector<string> cand;

void restore(string s, string t, int index) {
    rep(i, t.size()) {
        s[index + i] = t[i];
    }
    rep(i, s.size()) {
        if (s[i] == '?') s[i] = 'a';
    }
    cand.push_back(s);
}

int main()
{
    string s, t; cin >> s >> t;
    rep(i, s.size() - t.size() + 1) {
        bool isok = true;
        rep (j, t.size()) {
            if (s[i + j] == '?') continue;
            if (s[i + j] != t[j]) {isok = false; break;};
        }
        if (isok) restore(s, t, i);
    }
    sort(all(cand));
    cout << (cand.size() ? cand[0] : "UNRESTORABLE") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.io.PrintWriter;
import java.util.Arrays;;
import java.util.StringTokenizer;

/**
 * The Java template file for AtCoder online judge.
 */
public class Main {

  private static FastScanner scanner;
  private static PrintWriter printer;

  public static void solve() {
    int n = scanner.nextInt();
    int w = scanner.nextInt();
    int[] weights = new int[n];
    int[] values = new int[n];
    for (int i = 0; i < n; i++) {
      weights[i] = scanner.nextInt();
      values[i] = scanner.nextInt();
    }
    long result = 0;
    long[] dp = new long[w + 1];
    Arrays.fill(dp, Long.MIN_VALUE);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = w; j >= weights[i]; j--) {
        dp[j] = Math.max(dp[j], dp[j - weights[i]] + values[i]);
        result = Math.max(result, dp[j]);
      }
    }
    printer.println(result);
  }

  public static void main(String[] args) {
    scanner = new FastScanner();
    printer = new PrintWriter(System.out);
    solve();
    printer.flush();
  }

  private static class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner(Reader in) {
      br = new BufferedReader(in);
    }

    public FastScanner() {
      this(new InputStreamReader(System.in));
    }

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

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }

    public int[] readIntArray(int size) {
      int[] ret = new int[size];
      for (int i = 0; i < size; i++) {
        ret[i] = nextInt();
      }
      return ret;
    }
  }
}


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


int main() {
  int n;
  cin >> n;
  //配列に入れる
  vector<string> vec(n);
  for(int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  //アルファベット順にソートする
  sort(vec.begin(), vec.end());
  int a = 0;
  for(int i = 0; i < n - 1; i++) {
    if(vec.at(i) == vec.at(i + 1)) {
      a++;
    }
  }
  cout << n - a << endl;
}

Measured memory_bytes: 9536
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  int ans_open = 0;
  int ans_close = 0;
  int num_open = 0;
  int num_close = 0;

  rep(i, n) {
    if (s[i] == '(') {
      num_open++;
    } else {
       num_close++;
       if (num_close > num_open) {
         chmax(ans_open, num_close - num_open);
       }
    }
  }

  ans_close = max(ans_open + num_open - num_close, 0);

  // cout << ans_open << " " << ans_close << endl;

  rep(i, ans_open) cout << "(";
  cout << s;
  rep(i, ans_close) cout << ")";
  cout << endl;

  return 0;
}


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

using namespace std;

int main()
{
    int n,t,m,p,x;
    cin>>n;
    vector<int>v;
    for(int i=0;i<n;i++)
    {
        cin>>t;
        v.push_back(t);
    }
    int s=accumulate(v.begin(),v.end(),0);
    cin>>m;
    while(m--)
    {
        cin>>p>>x;
        cout<<s-v[p-1]+x<<endl;
    }
return 0;
}


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

int palindrome( char *s, int k, int n ){
    // 変数宣言
    int i;
    int result = 0;
    int result_total[100];
    int sum = 0;
    int count = 0;
    
    // 回文判定
    for( i = 0 ; i < n ; i++ ){
        if( s[i] == s[( n - 1 )- i ] ){
            count++;
        }
    }

    // 結果判定
    if( count == n ){
        result = 1;
    }

    return result;
}

int palindrome_end( char *s, int k, int n ){
    // 変数宣言
    int i;
    int result = 0;
    int count = 0;
    int sum = 0;
    
    // 回文判定
    for( i = 0 ; (( n + 3 ) / 2 ) - 1 < n - i ; i++ ){
        if( s[ k + i ] == s[(( n - 1 ) - i )] ){
            count++;
        }
    }

    // 結果判定
    if( count == ( n - 1 ) / 2 ){
        result = 1;
    }

    return result;
}

int main(void){
    // 変数宣言
    int n = 0;
    char s[100];
    int i;
    char *result = "No";
    int result_all = 0, result_start = 0, result_end = 0;
    int count = 0;

    // 入力処理
    scanf( "%s", s );

    // 演算処理
    n = strlen( s );

    // 文字列sの回文判定
    for( i = 0 ; i < n ; i++ ){
        if( s[i] == s[( n - 1 )- i ] ){
            count++;
        }
    }
    // 結果判定
    if( count == n ){
        result_all = 1;
    }
    count = 0;

    // 強い回文か判定（１）
    for( i = 0 ; i < ( n - 1 ) / 2  ; i++ ){
        if( s[i] == s[( n - 1 )- i ] ){
            count++;
        }
    }
    // 結果判定
    if( count == ( n - 1 ) / 2 ){
        result_start = 1;
    }
    count = 0;

    // 強い回文か判定（２）
    for( i = 0 ; (( n + 3 ) / 2 ) - 1 < n - i ; i++ ){
        if( s[ ((( n + 3 ) / 2 ) - 1) + i ] == s[(( n - 1 ) - i )] ){
            count++;
        }
    }
    // 結果判定
    if( count == ( n - 1 ) / 2 ){
        result_end = 1;
    }
    

    // 結果条件判定
    if( result_all == 1 && result_start == 1 && result_end == 1 ){
        result = "Yes";
    }

    // 出力
    printf( "%s", result );
    
    
    return 0;
}

Measured memory_bytes: 128
import java.io.PrintWriter
import java.util.*

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val sieve = Sieve(N)
    val facts = Counter<Int>()
    for (n in 1..N) {
        facts.addAll(sieve.fact(n))
    }
    println(facts.map.map { it.value + 1 }.fold(1L) { n, m -> (n * m) % 1000000007L })
}

class Sieve(N: Int) {
    private val primes: Array<Int>

    init {
        val que = ArrayDeque<Int>()
        val sieve = BooleanArray(N + 1) { true }
        sieve[0] = false
        sieve[1] = false
        for (i in 2..N) {
            if (!sieve[i]) continue
            que.push(i)
            for (j in (i * 2)..N step i) {
                sieve[j] = false
            }
        }
        primes = que.toTypedArray()
    }

    fun isPrime(v: Int) = primes.contains(v)

    fun fact(n: Int): HashMap<Int, Int> {
        val map = HashMap<Int, Int>()
        var tmp = n
        for (prime in primes) {
            if (tmp % prime == 0) {
                var cnt = 0
                while (tmp % prime == 0) {
                    tmp /= prime
                    cnt++
                }
                map[prime] = cnt
            }
        }
        if (tmp != 1) {
            map[tmp] = 1
        }
        return map
    }
}

class Counter<T> {
    val map = HashMap<T, Long>()

    fun add(k: T, d: Int = 1): Long {
        val v = map.getOrPut(k) { 0L }
        map[k] = v + d
        return v + d
    }

    fun addAll(m: Map<T, Int>) {
        for ((k, v) in m.entries) {
            add(k, v)
        }
    }

    override fun toString(): String {
        return map.toString()
    }
}

Measured memory_bytes: 33716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int m = 1e9 + 7;

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

    int n;
    cin >> n;
    ll ans = 1;
    for (int i = 0; i < n; i++)
    {
        ans *= (i + 1);
        ans %= m;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#define xx first
#define yy second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=3e5+10;
const int M=1e6+10;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
int n,siz[N];
vector<int> g[N];
LL fac[N],ans[N],mul[N];

LL qpow(LL x,LL k){
	LL res=1;
	while(k){
		if(k&1) res=res*x%mod;
		k>>=1;
		x=x*x%mod;
	}
	return res;
}

void predfs(int u,int fa){
	siz[u]=mul[u]=1;
	for(int v:g[u]){
		if(v==fa) continue;
		predfs(v,u);
		siz[u]+=siz[v];
		mul[u]=mul[u]*mul[v]%mod;
	}
	mul[u]=mul[u]*siz[u]%mod;
}

void dfs(int u,int fa,LL premul){
	LL down=premul;
	for(int v:g[u]) if(v!=fa) down=down*mul[v]%mod;
	ans[u]=fac[n-1]*qpow(down,mod-2)%mod;
	for(int v:g[u]) if(v!=fa) premul=premul*mul[v]%mod;
	for(int v:g[u]) if(v!=fa) dfs(v,u,premul*qpow(mul[v],mod-2)%mod*(n-siz[v])%mod);
}

int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
	predfs(1,0);
	dfs(1,0,1);
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 23540
n=int(input())
li=[]
for i in range(n):
  li.append([int(k) for k in input().split()])
dp=[[0 for i in range(3)] for j in range(n)]
dp[0]=li[0]

for j in range(1,n):
    for i in range(3):
        if(i==0):
            dp[j][i]=li[j][i]+max(dp[j-1][i+1],dp[j-1][i+2])
        elif(i==1):
            dp[j][i]=li[j][i]+max(dp[j-1][i-1],dp[j-1][i+1])
        elif(i==2):
            dp[j][i]=li[j][i]+max(dp[j-1][i-1],dp[j-1][i-2])    
       
#print(dp)
print(max(dp[n-1]))            

Measured memory_bytes: 45684