akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

char grid[400][400];

int main(){

  int r,c;

  while(cin>>r>>c){

      for(int i=1;i<=r;i++)
        scanf("%s",grid[i]+1);

      for(int i=1;i<=r*2;i++){
        for(int j=1;j<=c;j++)
          printf("%c",grid[(i+1)/2][j]);
        puts("");
      }

  }



return 0;
}


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

using namespace std;

int main()
{
    int i,N,a[200005],ans,j;
    cin>>N;
    ans=0;
    j=1;
    for(i=1; i<=N; i++)
        scanf("%d",&a[i]);
    for(i=1; i<=N; i++)
    {
        if(a[i]==j)
            j++;
        else
            ans++;
    }
    if(ans==N)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
def max_heapify(A, i):
  l = i * 2
  r = l + 1
  largest = i
  if l <= H and A[l] > A[i]: largest = l
  if r <= H and A[r] > A[largest]: largest = r
  if largest != i:
    A[i], A[largest] = A[largest], A[i]
    max_heapify(A, largest)
 
def build_max_heap(A):
  for i in range(H // 2, 0, -1):
    max_heapify(A, i)
 
H = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
build_max_heap(A)
 
print(" " + " ".join(map(str, A[1:])))

Measured memory_bytes: 66268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  string s;
  cin >> n >> s;
  ll cnt = 0;
  rep(i, n-2) {
    if (s.substr(i, 3) == "ABC") cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N,K,A[201010];
    cin >> N >> K;
    REP(i,N) cin >> A[i];

    map<int,int> cnt;
    REP(i,N) cnt[A[i]]++;

    vector<int> v;
    fore(p, cnt) v.push_back(p.second);
    sort(v.begin(), v.end());

    int n= v.size();

    if(n <= K){
        printf("0\n");
    }
    else{
        int ans=0;
        for(int i=0; i<n-K;++i){
            ans += v[i];
        }
        printf("%d\n", ans);   
    }
}

Measured memory_bytes: 11516
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long H, long long A){
  if(H%A)
    std::cout << H/A + 1 << std::endl;
  else
    std::cout << H/A << std::endl;
}

int main(){
  long long H;
  scanf("%lld",&H);
  long long A;
  scanf("%lld",&A);
  solve(H, A);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forN(N) if(N >= 0)for(size_t i = 0;i < N;++i)
typedef unsigned long long ul ;

int main() {
  ul D;
  vector<int>c;
  vector<int>last;
  vector<vector<int>>s;
  cin >> D;
  forN(26){
    int t;
    cin >> t;
    c.push_back(t);
    last.push_back(-1);
  }
  forN(D){
    vector<int> tv;
    int maxI = -1;
    int maxN = -1;
    for(int j = 0;j < 26;++j){
      int t;
      cin >> t;
      tv.push_back(t);
      int nnn = (t + (c[j] * (i - last[j])));
      //cout << nnn << ",";
      if(maxN < nnn){
		maxN = t;
        maxI = j;
      }
    }
    cout << (maxI + 1) << endl;
    last[maxI] = i;
    s.push_back(tv);
  }
}


Measured memory_bytes: 3680
import numpy as np
N, M = list(map(int, input().split()))
X = [np.asarray(list(map(int, input().split()))) for i in range(N)]
count = 0
for i in range(N):
  for j in range(i+1, N):
    vec = X[i] - X[j]
    vec = np.dot(vec, vec.T)
    sq = int(np.sqrt(vec))
    if sq ** 2 == vec:
      count += 1
print(count)

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using Graph = vector<vector<int>>;

int n, m;
int ans = 0;
int c = 0;
vector<vector<int> > g;
vector<bool> seen;

void dfs(int i){
    seen[i] = true;
    c++;
    if(c == n) ans++;
    for(auto next : g[i]){
        if(seen[next]) continue;
        dfs(next);
    }
    seen[i] = false;
    c--;
}

int main() {
    cin >> n >> m;
    g.resize(n + 1);
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    seen.resize(n + 1, false);
    dfs(1);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int a[50], b[50], c[50],i;
	i = 1;
	while (1) {
		cin >> a[i] >> b[i] >> c[i];
		if (a[i] == -1&&b[i]== -1&&c[i]==-1) { break; }
		i++;
	}
	for (int m = 1;m <= i - 1;m++) {
		if (a[m] == -1 || b[m] == -1) { cout << "F" << endl; }
		else if (a[m] + b[m] >= 80) { cout << "A" << endl; }
		else if (a[m] + b[m] >= 65) { cout << "B" << endl; }
		else if (a[m] + b[m] >= 50) { cout << "C" << endl; }
		else if (a[m] + b[m] >= 30) {
			if (c[m] >= 50) { cout << "C" << endl; }
			else { cout << "D" << endl; }
		}
		else { cout << "F" << endl; }
	}
	return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>
int main()
{
	int n,m,k,i,j;
	scanf("%d",&n);
	m=n;
	k=0;
	while(m)
	{
		k+=m%10;
		m/=10;
	}
	if(n%k==0)
	puts("Yes");
	else puts("No");
} 

Measured memory_bytes: 128
Sp = input()
T = input()
len_Sp = len(Sp)
len_T = len(T)
ans = 'UNRESTORABLE'

i = len_Sp - len_T
while(i >= 0):
    isAns = True
    for j in range(len_T):
        if Sp[i + j] != T[j] and Sp[i + j] != '?':
            isAns = False
            break
    if isAns:
        ans = Sp[:i] + T + Sp[i + len_T:]
        ans = ans.replace('?', 'a')
        break
    i -= 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;


void solve(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b!=c)cout<<"Yes";
  else if(a==c&&b!=c)cout<<"Yes";
  else if(b==c&&a!=b)cout<<"Yes";
  else cout<<"No";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    string S;cin >> S;
    int sum = 0;
    rep(i,N){
        if(i == 0)continue;
        if(S[i] == S[i-1]){
            sum++;
        }
    }
    cout << N - sum << endl;
}



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

int main()
{
    char s[5];
    char tmp;

    scanf("%s",s);
    if( strlen(s) == 3 ){
        printf("%c%c%c\n",s[2],s[1],s[0]);
        return 0;
    }
    printf("%s\n",s);

    return 0;
}

Measured memory_bytes: 128
from sys import stdin
readline = stdin.readline


from itertools import product
from operator import itemgetter
from math import isinf


def scrap_top_left(picture):
    for py, px in product(range(len(picture)), repeat=2):
        if picture[py][px] != -1:
            return px, py


def is_match(window, picture, wx, wy):
    for py, px in product(range(len(picture)), repeat=2):
        if picture[py][px] == -1:
            continue
        if window[wy + py][wx + px] != picture[py][px]:
            return False
    return True


def search(window, picture):
    for wy, wx in product(range(len(window) - len(picture) + 1), repeat=2):
        if is_match(window, picture, wx, wy):
            px, py = scrap_top_left(picture)
            return wx + px + 1, wy + py + 1
    return float('inf'), float('inf')


# http://d.hatena.ne.jp/odz/20070622/1182497414
def rotate_clockwise(matrix):
    return [list(row) for row in zip(*reversed(matrix))]


while True:
    window_size, picture_size = map(int, readline().split())
    if window_size == 0:
        break
    window = [list(map(int, readline().split())) for _ in range(window_size)]
    picture = [list(map(int, readline().split())) for _ in range(picture_size)]
    top_left = []
    for _ in range(4):
        top_left.append(search(window, picture))
        picture = rotate_clockwise(picture)
    top_left = min(top_left, key=itemgetter(1, 0))
    if isinf(top_left[0]):
        print('NA')
    else:
        print(*top_left)

Measured memory_bytes: 7024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

  static class B {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int K = in.nextInt();
      String S = in.next();

      String res = S;

      if (S.length() > K) {
        res = S.substring(0, K) + "...";
      }

      out.print(res);
    }

  }
}



Measured memory_bytes: 38636
#include <stdio.h>

int main(){
    int k,x,val;
    
    scanf("%d %d",&k,&x);
    
    val=k*500;
    
    if(val>=x){
        printf("Yes\n");
    }
    
    else{
        printf("No\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] a = new Integer[N];
        
        int Alice = 0;
        int Bob = 0;
        
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, Collections.reverseOrder());
        
        for(int i = 0; i < N; i++){
            if((i % 2) == 0 ){
                Alice += a[i];
            }else{
                Bob += a[i];
            }
        }
        
        System.out.println(Alice - Bob);
    }
    
}


Measured memory_bytes: 27080
n=int(input())
a=list(map(int,input().split()))
if max(a)-min(a)>1:
    print("No")
else:
    b=a.count(max(a))
    c=n-b
    if c==0:
        if max(a)==n-1 or n>=2*max(a):
            print("Yes")
        else:
            print("No")
    else:
        if c<max(a) and 2*(max(a)-c)<=b:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 13964
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>

typedef long double ld;
typedef long long ll;

using namespace std;

void swap(int & a, int & b) {
	int t = a;
	a = b;
	b = t;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << endl;

	return 0;
}


Measured memory_bytes: 3520
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int r;
    cin >> r;
    double s = 2 *r *M_PI;
    printf("%.20f\n", s);

    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

int main() {
    int N; cin >> N;
    vector<pair<char, int>> A(2 * N);
    vector<int> idx_b(N + 1), idx_w(N + 1);
    for(int i = 0; i < 2 * N; ++i) {
        char c; int a; cin >> c >> a;
        A[i] = make_pair(c, a);
        if(c == 'B') idx_b[a] = i;
        else idx_w[a] = i;
    }

    vector<vector<int>> sum_b(N + 1, vector<int>(2 * N + 1));
    vector<vector<int>> sum_w(N + 1, vector<int>(2 * N + 1));
    for(int x = 0; x <= N; ++x) {
        for(int i = 0; i < 2 * N; ++i) {
            if(A[i].first == 'B') sum_b[x][i] += (A[i].second > x);
            else sum_w[x][i] += (A[i].second > x);
            sum_b[x][i + 1] = sum_b[x][i];
            sum_w[x][i + 1] = sum_w[x][i];
        }
    }

    vector<vector<int>> dp(N + 1, vector<int>(N + 1, INF));
    dp[0][0] = 0;

    auto f = [&](auto &&f, int b, int w) -> int {
        if(dp[b][w] != INF) return dp[b][w];
        if(b) dp[b][w] = min(dp[b][w], f(f, b - 1, w) + sum_b[b][idx_b[b]] + sum_w[w][idx_b[b]]);
        if(w) dp[b][w] = min(dp[b][w], f(f, b, w - 1) + sum_b[b][idx_w[w]] + sum_w[w][idx_w[w]]);
        return dp[b][w];
    };
    cout << f(f, N, N) << '\n';
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
 
#define INF 1120000000
#define MOD 1000000007
 
long mod_pow(long x, long n, long p=MOD){
  if(x==0) return 0;
  long res=1;
  x %= p;
  while(n>0){
    if(n&1) res=res*x%p;
    x=x*x%p;
    n>>=1;
  }
  return res;
}
inline long mod_inv(long x, long p=MOD){ return mod_pow(x%p, p-2, p); }
 
long fact[303];
 
long dp[2][303][303];
 
int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
 
  fact[0] = 1;
  rep(i,300) fact[i+1] = (i+1)*fact[i] %MOD;
 
  if(all_of(all(v), [](int x){return x==2;})){
    cout << fact[n-1] * mod_inv(2) %MOD << endl;
    return 0;
  }
 
  // dp[i][j][k] iまでj個使ってk個のサイクル外へのパス
  auto pre = dp[0];
  auto nxt = dp[1];
  fill(pre[0], pre[n], 0);
  pre[0][0] = 1;
  rep(i,n) if(v[i]>1){
    rep(j,n) rep(k,n){
      nxt[j][k] = pre[j][k];
      int pj = j-1;
      int pk = k - (v[i]-2);
      if(pj>=0 && pk>=0 && pre[pj][pk]>0){
        nxt[j][k] += pre[pj][pk] * (v[i]-1);
        nxt[j][k] %= MOD;
      }
    }
    swap(pre, nxt);
  }
 
  long ans = 0;
  rep(i,3,n) rep(j,1,n) if(pre[i][j]>0){
    // dbg(i,j,pre[i][j]);
    assert(n-i >= j);
    long tmp = fact[i-1] * fact[n-i-1] %MOD;
    tmp = tmp * j %MOD;
    tmp = tmp * pre[i][j] %MOD;
    ans += tmp;
  }
  ans %= MOD;
 
  long muls = 1;
  rep(i,n) muls = muls * fact[v[i]-1] %MOD;
 
  ans = ans * mod_inv(2*muls %MOD) %MOD;
 
  cout << ans << endl;
 
  return 0;
}

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

int main() {
    int N,K;
    cin >> N >> K;
    double ans = 0;
    for (int i=1; i<=N; i++) {
        int v = i;
        for (int t=0; t<20; ++t) {
            if (v>=K) {
                ans += 1.0 / (1<<t);
                break;
            }
            v *= 2;
        }
    }
    cout << fixed << setprecision(12);
    cout << ans/N << endl;
}


Measured memory_bytes: 3784
#include <iostream>
        #include <algorithm>
         
        using namespace std;
         
        #define MAX_N 100000
         
        int main() {
        	long long n, a, b, x[MAX_N];
         
        	cin >> n >> a >> b;
        	for (int i = 0; i < n; ++i) {
        		cin >> x[i];
        	}
        	
        	long long ans = 0;
        	for (int i = 1; i < n; ++i) {
        		ans += min(a * (x[i] - x[i - 1]), b);
        	}
         
        	cout << ans << endl;
         
        	return 0;
        }

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int x,n=0;
	cin>>x;
	 char s[x+1];
	 int a[x+1];
	 a[0]=0;
	for(int i=0;i<x+1;i++){
		cin>>s[i];
		if(s[i]=='I'){
			n++;	
			a[i+1]=n;	}
		else {
			n--;
			a[i+1]=n;	
			}
	}
	 int max=a[0];
		for(int i=0;i<x+1;i++){
			if(a[i]>=max)
				max=a[i];
		
		}
		cout<<max;
}

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

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

    int X = A + B;
    int Y = A - B;
    int Z = A * B;

    vector<int> vec;
    vec = {X, Y, Z};

    sort(vec.begin(),vec.end());

    cout << vec.at(2) << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.TreeSet;
import java.util.Arrays;
public class Main {
 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int j=1;
        while(true){
            int a=sc.nextInt();
            if(a==0)break;
            else System.out.println("Case "+j+": "+a);
            j++;
        }
}
}



Measured memory_bytes: 43180
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;


int main(){
  int N,count=0;
  string S;
  cin>>N>>S;

  for(int i=0;i<N;i++){
    if(S[i]=='(') count++;
    else{
      if(count>0) count--;
      else cout<<"(";
    } 
  }
  cout<<S;
  count=0;
  for(int i=N-1;i>=0;i--){
    if(S[i]==')') count++;
    else{
      if(count>0) count--;
      else cout<<")";
    } 
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cnt = 0;
  for(int i = 1; i < N; ++i){
    if(S[i] == 'W') cnt++;
  }
  int ans = cnt;
  for(int i = 1; i < N; ++i){
    if(S[i] == 'W') cnt--;
    if(S[i-1] == 'E') cnt++;
    ans = max(ans, cnt);
  }
  cout << N - 1 - ans << endl;
}


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

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

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    string S;
    cin >> S;
    ll cnt = 0;
    rep(i, S.length()/2) {
        cnt += S[i] != S[S.length()-1-i];
    }
    print(cnt);
    return 0;
}

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

using namespace std;

bool isIn(int x, int y, int n, int m){
     return 0 <= x && x <= n && 0 <= y && y <= m;
}

int main(){
    int n;
    cin >> n;
    for(int q=0; q < n; q++){
        int gx, gy;
        cin >> gx >> gy;
        int m;
        cin >> m;
        bool unreachable[20][20][20][20] = {0};
        for(int i=0; i < m; i++){
            int a, b, c, d;
            cin >> a >> b >> c >> d;
            unreachable[a][b][c][d] = true; unreachable[c][d][a][b] = true;
        }
        int dp[20][20] = {0};
        dp[0][0] = 1;
        for(int i = 0; i <= gy; i++){
            for(int j = 0; j <= gx; j++){
                if(isIn(j, i-1, gx, gy) && !unreachable[j][i-1][j][i]) dp[i][j] += dp[i-1][j];
                if(isIn(j-1, i, gx, gy) && !unreachable[j-1][i][j][i]) dp[i][j] += dp[i][j-1];
            }
        }
        if(dp[gy][gx] == 0) cout << "Miserable Hokusai!" << endl;
        else cout << dp[gy][gx] << endl;
    }
}

Measured memory_bytes: 1320
import math


def main():
    a, b, h, m = [int(x) for x in input().split()]
    theta_a = (60 * h + m) / 2
    theta_b = 6 * m
    xa = a * math.cos(math.radians(theta_a))
    ya = a * math.sin(math.radians(theta_a))
    xb = b * math.cos(math.radians(theta_b))
    yb = b * math.sin(math.radians(theta_b))
    ans = math.sqrt((xa - xb)**2 + (ya - yb)**2)
    return ans


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


Measured memory_bytes: 9492
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n+1),ans,b(n+1);
    Fr(i,n) cin>>a[i];
    iFr(i,n){
        int kari=a[i];
        for(int j=i+i;j<=n;j+=i) kari+=b[j];
        b[i]=kari%2;
        if(b[i]==1){
            ans.emplace_back(i);
        }
    }
    cout<<ans.size()<<endl;
    for(auto i:ans) cout<<i<<" ";
    cout<<endl;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  int N; cin >> N;
  vector<ui> A(N);
  for(auto& a : A) cin >> a;

  vector<ui> B{};
  B.reserve(N*2);
  for(int i = N - 1; i >= 0; i -= 2){
    B.push_back(A[i]);
  }
  if(N % 2 == 0){
    for(int i = 0; i < N; i += 2){
      B.push_back(A[i]);
    }
  }else{
    for(int i = 1; i < N; i += 2){
      B.push_back(A[i]);
    }
  }

  cout << B << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=2e5;
ll L;
int N;
ll X[MAX_N+2];
ll dif[MAX_N+1];
ll psm[MAX_N+1][2];
int main(){
	cin>>L>>N;
	REP(i,N){
		cin>>X[i+1];
	}
	X[0]=0;
	X[N+1]=L;
	ll ans=0;
	bool flg=false;
	REP(t,2){
		REP(i,N+1){
			dif[i]=X[i+1]-X[i];
		}
		psm[0][0]=0;
		REP(i,N){
			psm[i+1][0]=psm[i][0]+2*X[i+1];
		}
		psm[N][1]=0;
		for(int i=N;i>0;i--){
			psm[i-1][1]=psm[i][1]+2*(L-X[i]);
		}
		REP(i,N+1){
			if (i>(N-i)){
				ans=max(ans,psm[i][1]+psm[i][0]-psm[i-(N-i)][0]-X[i-(N-i)]*2*(N-i)+X[i-(N-i)]*(2*(N-i)+1)-min(X[i]-X[i-(N-i)],L-(X[i]-X[i-(N-i)])-dif[i]));
			}else if (i==N-i){
				ans=max(ans,psm[i][1]+psm[i][0]-min(X[i],L-X[i]-dif[i]));
			}
			if (ans==37 && !flg){
				cout<<t<<endl;
				cout<<i<<endl;
				flg=true;
			}
		}
		REP(i,N){
			X[i+1]=L-X[i+1];
		}
		sort(X,X+N+2);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    ll a,b,x;
    cin >> a >> b >> x;
    if (a == 0){
        cout << b / x + 1 << endl;
    }
    else{
        cout << b / x - (a - 1)/ x << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(a);
    cii(b);
    auto ans = a <= 8 && b <= 8
            ?"Yay!"
            :":(";
    co(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define fi first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
 
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	double l;
	cin>>l;
	cout<<fix( (l*l*l)/27 , 15);
	return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))

x = 0
ans = 0
for i in range(45,-1,-1):
    count = 0
    for j in a:
        if (j >> i) & 1:
            count += 1
    
    if n-count > count and x + (1<<i) <= k:
        ans += (n-count)* (1<<i)
        x += 1<<i
    else:
        ans += count*(1<<i)
print(ans)


Measured memory_bytes: 14708
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  i64 D;
  cin >> N >> D;
  D *= D;
  int r = 0;
  F0R(i, N) {
    i64 x, y;
    cin >> x >> y;
    if (x * x + y * y <= D)r++;
  }
  cout << r;
}
#endif


Measured memory_bytes: 3656
#include<cstdio>
//dp[i][j]=品物1,2,...,iからj(<=i)個選んだときの価値の総和の最大値
long long v[51],dp[51][51]={},pattern[51][51]={};
int main(){
  int n,a,b,i,j;
  scanf("%d%d%d",&n,&a,&b);
  for(i=1;i<=n;i++)scanf("%lld",&v[i]);
  dp[0][0]=0;
  for(i=1;i<=n;i++){
    dp[i][0]=0;
    pattern[i][0]=1;
    dp[i][i]=dp[i-1][i-1]+v[i];
    pattern[i][i]=1;
  }
  for(i=2;i<=n;i++){
    for(j=1;j<i;j++){
      //dp[i][j]=max(dp[i-1][j-1]+v[i],dp[i-1][j])
      if(dp[i-1][j-1]+v[i]>dp[i-1][j]){
        dp[i][j]=dp[i-1][j-1]+v[i];
        pattern[i][j]=pattern[i-1][j-1];
      }else if(dp[i-1][j-1]+v[i]==dp[i-1][j]){
        dp[i][j]=dp[i-1][j];
        pattern[i][j]=pattern[i-1][j-1]+pattern[i-1][j];
      }else{
        dp[i][j]=dp[i-1][j];
        pattern[i][j]=pattern[i-1][j];
      }
    }
  }
  int num=-1;
  long long pt;
  for(i=a;i<=b;i++){
    if(pattern[n][i]>0){
      if(num==-1 || dp[n][i]*num>dp[n][num]*i){
        num=i;
        pt=pattern[n][i];
      }else if(dp[n][i]*num==dp[n][num]*i){
        pt+=pattern[n][i];
      }
    }
  }
  printf("%lf\n%lld",1.0*dp[n][num]/num,pt);
  return 0;
}

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

int main() {
  int X,Y;
  cin >> X >> Y;
  bool ans = false;
  for(int i=0; i<X+1; i++){
      if(Y == 2*i + 4*(X - i)){
        ans = true;
        break;
      }
  }
  
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  ll num = 0;
  REP(i, N-1) { num += abs(A[i] - A[i + 1]); }
  num += abs(A[N - 1]) + abs(A[0]);
  cout << num - abs(A[0]) - abs(A[0]-A[1])+abs(A[1]) << endl;
  for (int i = 1; i < N - 1;i++){
    cout << num - abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]) << endl;
  }
    cout << num - abs(A[N - 2] - A[N - 1])-abs(A[N-1]) + abs(A[N - 2]) << endl;


}

Measured memory_bytes: 1664
#if 0



#endif // 0

#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN = (int) 35;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;
int H,W,S;
int f[MAXN][MAXN][MAXN][MAXN];
int g[MAXN][MAXN][MAXN][MAXN];
int a[MAXN][MAXN];
int TOTAL;
int MI;

int get_sum(int i,int j,int k,int t){
    return a[k][t]-a[k][j-1]-a[i-1][t]+a[i-1][j-1];
}

void DFS(int I,int J,int K,int T){
    f[I][J][K][T]=1;
    g[I][J][K][T]=get_sum(I,J,K,T);
    if(I==K&&J==T) return;
    if(g[I][J][K][T]<MI) return;
    for(int i=I;i<K;i++){
        if(f[I][J][i][T]==-1) DFS(I,J,i,T);
        if(f[i+1][J][K][T]==-1) DFS(i+1,J,K,T);
        if(g[I][J][i][T]>=MI&&g[i+1][J][K][T]>=MI){
            if(f[I][J][i][T]+f[i+1][J][K][T]>f[I][J][K][T]){
                f[I][J][K][T]=f[I][J][i][T]+f[i+1][J][K][T];
                g[I][J][K][T]=min(g[I][J][i][T],g[i+1][J][K][T]);
            }
            else if(f[I][J][i][T]+f[i+1][J][K][T]==f[I][J][K][T]){
                int cur_mi=min(g[I][J][i][T],g[i+1][J][K][T]);
                g[I][J][K][T]=max(g[I][J][K][T],cur_mi);
            }
        }
    }
    for(int j=J;j<T;j++){
        if(f[I][J][K][j]==-1) DFS(I,J,K,j);
        if(f[I][j+1][K][T]==-1) DFS(I,j+1,K,T);
        if(g[I][J][K][j]>=MI&&g[I][j+1][K][T]>=MI){
            if(f[I][J][K][j]+f[I][j+1][K][T]>f[I][J][K][T]){
                f[I][J][K][T]=f[I][J][K][j]+f[I][j+1][K][T];
                g[I][J][K][T]=min(g[I][J][K][j],g[I][j+1][K][T]);
            }
            else if(f[I][J][K][j]+f[I][j+1][K][T]==f[I][J][K][T]){
                int cur_mi=min(g[I][J][K][j],g[I][j+1][K][T]);
                g[I][J][K][T]=max(g[I][J][K][T],cur_mi);
            }
        }
    }
}

void work(){
    while(~scanf("%d%d%d",&H,&W,&S)){
        if(H==0&&W==0&&S==0) break;
        TOTAL=0;
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                scanf("%d",&a[i][j]);
                TOTAL+=a[i][j];
                a[i][j]+=a[i][j-1];
            }
        }
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                a[i][j]+=a[i-1][j];
            }
        }
//        for(int i=1;i<=H;i++){
//            for(int j=1;j<=W;j++){
//                printf("%d ",a[i][j]);
//            }
//            printf("\n");
//        }
        MI=TOTAL-S;
        memset(f,-1,sizeof(f));
        memset(g,-1,sizeof(g));
        DFS(1,1,H,W);
        printf("%d %d\n",f[1][1][H][W],g[1][1][H][W]-MI);
    }
}

int main(){
    work();
    return 0;
}



Measured memory_bytes: 14860
class Solver(object):
    def __init__(self):
        self.d, self.n = list(map(int, input().split(" ")))

    def solve(self):
        if self.n % 100 == 0:
            self.n += 1
        if self.d == 0:
            print(self.n)
        elif self.d == 1:
            print("{}00".format(self.n))
        else:  # d == 3
            print("{}0000".format(self.n))


if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
ll MOD = 1e9+7;
ll INF = 1LL<<60;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    vector<ll> t(n),a(n);
    rep(i,n)cin>>t[i];
    rep(i,n)cin>>a[i];
    vector<ll> lb1(n), ub1(n), lb2(n), ub2(n);
    rep(i,n){
        if(i==0){
            lb1[i]=t[i];
            ub1[i]=t[i];
            continue;
        }
        if(t[i]!=t[i-1]){
            lb1[i]=t[i];
            ub1[i]=t[i];
        }
        else{
            lb1[i]=1;
            ub1[i]=ub1[i-1];
        }
    }
    rep(j,n){
        ll i = n-j-1;
        if(i==n-1){
            lb2[i]=a[i];
            ub2[i]=a[i];
            continue;
        }
        if(a[i]!=a[i+1]){
            lb2[i]=a[i];
            ub2[i]=a[i];
        }
        else{
            lb2[i]=1;
            ub2[i]=ub2[i+1];
        }
    }
    ll ans = 1;


    rep(i,n){
        ll lb = max(lb1[i],lb2[i]);
        ll ub = min(ub1[i],ub2[i]);
        if(lb>ub){
            ans = 0;
            break;
        }
        ans = (ans*(ub-lb+1))%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())


H,W = inpl()
map = []
map.append(['.']*(W+2))
for y in range(H):
	map.append(['.'] + list(input()) + ['.'])
map.append(['.']*(W+2))

ans = [[0 for i in range(W)] for j in range(H)]

def check(x,y):
	global map
	tmp  = 0
	for yy in range(y-1,y+2):
		for xx in range(x-1,x+2):
			if map[yy][xx] == '#':
				tmp += 1
	return str(tmp)

for y in range(1,H+1):
	for x in range(1,W+1):
		if map[y][x] == '#':
			ans[y-1][x-1] = '#'
		else:
			ans[y-1][x-1] = check(x,y)

for an in ans:
	print(''.join(an))


Measured memory_bytes: 4452
#include <cstdio>
#define scanf __builtin_scanf
#include <vector>
#include <set>
using namespace std;

struct union_find_tree {
    std::vector<int> par, rank;
    union_find_tree(){}
    union_find_tree(int size)
    {
        par=std::vector<int>(size);
        rank=std::vector<int>(size);
        for(int i=0; i<size; ++i) par[i]=i;
    }
    int root(int x)
    {
        if (x==par[x]) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x, int y)
    {
        x=root(x);
        y=root(y);
        if (x==y) return;
        if (rank[x]<rank[y]) {
            par[x]=y;
        }
        else {
            par[y]=x;
            if (rank[x]==rank[y]) ++rank[x];
        }
    }
    bool same(int x, int y)
    {
        return root(x)==root(y);
    }
};

int x[100010], y[100010], z[100010], v[100010];
int main()
{
    int n, m; scanf("%d%d", &n, &m);
    for(int i=0; i<m; ++i) {
        scanf("%d%d%d", x+i, y+i, z+i);
        x[i]--;
        y[i]--;
    }

    union_find_tree uf(n);
    for(int i=0; i<m; ++i) uf.unite(x[i], y[i]);

    set<int> s;
    for(int i=0; i<n; ++i) s.insert(uf.root(i));
    printf("%d\n", int(s.size()));
}


Measured memory_bytes: 6784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[] = sc.next().split("");
		String s[] = sc.next().split("");
		String c[] = sc.next().split("");
		System.out.println(a[0] + s[0] + c[0]);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define F(i, l, r) for(long long i =l; i<=r; ++i)
#define REP(i, r) for(int i = 0; i<(int)r; ++i)
#define Fr(i, l, r) for(long long i= l; i>=r; --i)
#define RP (i, u) for(i = u-1; i>=0; --i)
#define pb push_back
#define X first
#define Y second
#define mk make_pair
#define sz size()
#define DEBUG(x) {cerr << #x << " = " << x << '\n';}
#define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}
#define Nmax 100009
#define BASE 1000009
#define name "  "
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf = 1e9;
template<class T> int getbit(T x, int pos) {return (x >> (pos-1)) & 1;}
template<class T> void turn_on(T &x, int pos) {x = x | ((T)1 << (pos-1));}
template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1 << (pos-1));}
template<class T> T sqr(T a) {return a*a;}
ll n, x, a, b;

int main()
{
  //  freopen(name".INP", "r", stdin);
  //  freopen(name".OUT", "w", stdout);
cin >> x >> a >> b;
 ll tmp = b-a;
 if(tmp > 0 && tmp <= x) cout<<"safe";
 else if(tmp<=0)
    cout<<"delicious";
    else if(tmp > x) cout<<"dangerous";

}


Measured memory_bytes: 256
# A - Colorful Subsequence AC (hint)
import collections
N = int(input())
S = input()
MOD = 10**9+7

cnt = collections.Counter(S)

# 文字の選び方
# 1 個選ぶ or 2 選ぶ or 3 個選ぶ or ... cnt 個選ぶ or 選ばない
# (cnt + 1) 通り
ans = 1
for value in cnt.values():
    ans = (ans*(value+1))%MOD
print(ans - 1)

Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std;
#define int 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++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int n;
    cin >> n;
    vi p(n);
    rep(i, n) {
        cin >> p[i];
        p[i]--;
    }

    vi a(n);
    rep(i, n) {
        a[i] = 20000 * (i + 1);
    }

    vi b(rall(a));

    rep(i, n) {
        b[p[i]] += i;
    }

    rep(i, n) {
        cout << a[i] << (i != n - 1 ? " " : "");
    }
    cout << endl;
    rep(i, n) {
        cout << b[i] << (i != n - 1 ? " " : "");
    }
    cout << endl;



}


Measured memory_bytes: 1152
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int n;cin>>n;
  int a[n]; rep(i, n) {cin>>a[i];}
  int b[n]; rep(i, n) {cin>>b[i];}

  int ma[n];
  int mb[n];

  int p2[30];p2[0]=1;
  rep(i, 1, 30) p2[i]=2*p2[i-1];

  string res = "";
  rrep(k, 29){
    rep(i, n) ma[i] = a[i]%p2[k+1];
    rep(i, n) mb[i] = b[i]%p2[k+1];
    sort(ma, ma+n);
    sort(mb, mb+n);

    int c=0;
    rep(i, n){
      int l=p2[k]-ma[i];
      int r=p2[k+1]-ma[i]-1;
      int l2=l+p2[k+1];
      int r2=r+p2[k+1];

      int p = upper_bound(mb, mb+n, r) - lower_bound(mb, mb+n, l);
      int q = upper_bound(mb, mb+n, r2) - lower_bound(mb, mb+n, l2);
      c += (p+q);
    }
    if (c%2==1) res+="1";
    else res+="0";
  }
  dump(res);
  cout << stoi(res, 0, 2) << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 8576