akhauriyash/Code-Regression huggingface dataset:
// arc082.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
// 15:00~16:00

#include <iostream>
#include <fstream>
#include <time.h>

// #define _DEBUG (true)
#define _DEBUG (false)

unsigned int p[100000];
unsigned int q[100000];

unsigned int N = 0;
unsigned int result = 0;

void input()
{
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		std::cin >> p[i];
	}
}

void solve()
{
	// p(i) = iの箇所をtrue, p(i) ≠ iの箇所をfalseとする配列q[N]を作成
	for (int i = 0; i < N; i++) {
		if (p[i] == (i + 1)) {
			q[i] = true;
		}
		else {
			q[i] = false;
		}
	}

	// (q(i-1) = true) AND (q(i) = true)の箇所は(q(i) = false)とする
	// 1回の入れ替えで2箇所がp(i)≠iとなるため
	for (int i = 1; i < N; i++) {
		if ((q[i - 1] == true) && (q[i] == true)) {
			q[i] = false;
		}
	}

	// q[N]のtrueの数が必要スワップ回数
	for (int i = 0; i < N; i++) {
		if (q[i] == true) {
			result++;
		}
	}
}

void output()
{
	std::cout << result << std::endl;
}

int main()
{
#if(_DEBUG)
	// 標準入力をファイルに変更
	std::ifstream in("input.txt");
	std::cin.rdbuf(in.rdbuf());

	// 処理時間計測用
	clock_t start, end;
	start = clock();
#endif

	// 入力部
	input();

	// 処理部
	solve();

	// 出力部
	output();

#if(_DEBUG)
	// 処理時間を表示
	end = clock();
	std::cout << "処理時間：" << (double)(end - start) << "[ms]";
	getchar();
#endif
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ' ';  } return os;  }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

struct Edge {
  ll to,a,b;
  Edge(int to, int a, int b): to(to),a(a),b(b) {}
};

vector<Edge> G[50];
vector<ll> C, D;

typedef tuple<ll,ll,ll> T3;

const ll MAX = 3000;
const ll INF = 10000000000000;
int main() {
  ll n,m,s; cin >> n >> m >> s;
  s = min(MAX, s);

  loop(i,0,m) {
    ll u,v,a,b;
    cin >> u >> v >> a >> b;
    u--;v--;
    G[u].emplace_back(v,a,b);
    G[v].emplace_back(u,a,b);
  }

  C.resize(n); D.resize(n);
  loop(i,0,n) cin >> C[i] >> D[i];

  /* 入力ここまで */

  ll dp[n][MAX+1];
  {
    bool done[n][MAX+1];
    loop(i,0,n) loop(j,0,MAX+1) dp[i][j] = INF;
    memset(done, 0, sizeof(done));

    min_priority_queue<T3> Q;
    Q.emplace(0,0,s);
    dp[0][s] = 0;

    while (Q.size()) {
      ll dist,u,us;
      tie(dist,u,us) = Q.top(); Q.pop();
      // cout << vector<ll>{dist,u,us} << endl;
      done[u][us] = true;

      // 換金
      ll vs = min(MAX, us + C[u]), vd = dist + D[u];
      if (!done[u][vs]) {
        bool r = chmin(dp[u][vs], vd);
        if (r) Q.emplace(vd, u, vs);
      }

      // 頂点移動
      for (auto &&edge: G[u]) {
        int to = edge.to, a = edge.a, b = edge.b;
        if (us - a < 0) continue; // お金が足りない
        if (done[to][us - a]) continue; // すでに確定済み
        bool r = chmin(dp[to][us - a], dist + b);
        if (!r) continue;
        Q.emplace(dist + b, to, us - a);
      }
    }
  }

  loop(i,1,n) {
    ll ans = 10000000000000;
    loop(j,0,3001) ans = min(ans, dp[i][j]);
    cout << ans << endl;
  }
  return 0;
}


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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

struct S{
	string s;
	int i;
	char nx(){
		return s[i];
	}
	bool dig(){
		return '0'<=nx()&&nx()<='9';
	}
	void inc(){i++;}
};

int expr(S&);
int term(S&);
int fact(S&s);
int num(S&);

int expr(S&s){
	int a=term(s);
	while(1){
		if(s.nx()=='+'){
			s.inc();
			a+=term(s);
		}else if(s.nx()=='-'){
			s.inc();
			a-=term(s);
		}else
			break;
	}
	return a;
}

int fdiv(int a,int b){
	return a/b-((a^b)<0&&a%b);
}

int term(S&s){
	int a=fact(s);
	while(1){
		if(s.nx()=='*'){
			s.inc();
			a*=fact(s);
		}else if(s.nx()=='/'){
			s.inc();
			a/=fact(s);
			//a=fdiv(a,fact(s));
		}else
			break;
	}
	return a;
}

int fact(S&s){
	if(s.nx()=='('){
		s.inc();
		int a=expr(s);
		s.inc();
		return a;
	}else{
		int a=0;
		while(s.dig()){
			a=a*10+s.nx()-'0';
			s.inc();
		}
		return a;
	}
}

void slv(){
	S s;
	cin>>s.s;
	s.i=0;
	cout<<expr(s)<<endl;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n;cin>>n;
	rep(_,n)slv();
}



Measured memory_bytes: 3208
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Ti4 tuple<int, int, int, int>
#define Tlll tuple<ll, ll, ll>
#define PI 3.141592653589793

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

        string ans = "";
        string key[10];
        key[1] = ".,!? ";
        key[2] = "abc";
        key[3] = "def";
        key[4] = "ghi";
        key[5] = "jkl";
        key[6] = "mno";
        key[7] = "pqrs";
        key[8] = "tuv";
        key[9] = "wxyz";

        int idx = 0;
        while (idx < s.size()) {
            int sub = 0;
            if (s[idx] == '0') {
                idx++;  continue;
            }
            while (idx + sub < s.size() && s[idx] == s[idx + sub]) sub++;
            sub--;
            ans += key[s[idx] - 48][sub % key[s[idx] - 48].size()];
            idx += sub + 2;
        }
        cout << ans << endl;
    }
}



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

using namespace std;

#define il inline
#define re register
#define Rep(i, s, e) for (re int i = s; i <= e; ++i)
#define Dep(i, s, e) for (re int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)

const int H = 11;
const int W = 1010;

const int MAXVAL = 1030;

il int read() {
    int x = 0; bool f = true; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = false; c = getchar();}
    while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}

int h, w, K;
char s[W];

int sum[H][W];
il int Get(int c, int l, int r) {
    return sum[r][c] - sum[l - 1][c];
}

int tot, pos[H], now[H], tp[H];
int ans = 0x3f3f3f3f;

int main() {
    h = read(), w = read(), K = read();
    Rep(i, 1, h) {
        gets(s + 1);
        Rep(j, 1, w) sum[i][j] = sum[i - 1][j] + (s[j] == '1');
    }
    int MAX = (1 << (h - 1)) - 1;
    Rep(i, 0, MAX) {
    	memset(now, 0, sizeof(now));
        tot = 0; int tp_ans = 0;
        Rep(j, 0, h - 2) {
            if (i & (1 << j)) pos[++tot] = j + 1;
        }
        tp_ans = tot, pos[++tot] = h;
        bool failed = false;
        Rep(j, 1, w) {
        	Rep(k, 1, tot) {
        		tp[k] = Get(j, pos[k - 1] + 1, pos[k]);
        		if (tp[k] > K) {failed = true; break;}
			}
			if (failed) break;
        	Rep(k, 1, tot) {
        		now[k] += tp[k];
        		if (now[k] > K) {
        			Rep(l, 1, tot) now[l] = tp[l];
        			++tp_ans; break;
				}
			}
		}
	    if (failed) continue;
        ans = min(ans, tp_ans);
    } 
    return printf("%d", ans) & 0;
}


Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
s = [list(input()) for i in range(H)]

q = deque([(0, 0, 1)])

while q:
  h, w, c = q.popleft()
  if s[h][w] != ".": continue
  s[h][w] = c
  if h+1 == H and w+1 == W: break
  if 0 <= h-1: q.append((h-1, w, c+1))
  if h+1 < H : q.append((h+1, w, c+1))
  if 0 <= w-1: q.append((h, w-1, c+1))
  if w+1 < W : q.append((h, w+1, c+1))
else:
  print(-1)
  exit()

print(H*W - sum([sum([x == "#" for x in sh]) for sh in s]) - s[-1][-1])

Measured memory_bytes: 3316
U = 2*10**5
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
two = [1]*(U+1)
two_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
    two[i] = (two[i-1]*2)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
two_inv[U] = pow(two[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD
    two_inv[i-1] = (two_inv[i]*2)%MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[k]
    z %= MOD
    z *= fact_inv[n-k]
    z %= MOD
    return z
  
B, W = map(int, input().split())
p = 0
q = 0
for i in range(1, B+W+1):
  ans = 1 - p + q
  ans %= MOD
  ans *= two_inv[1]
  ans %= MOD
  print(ans)
  p += comb(i-1, B-1) * two_inv[i] % MOD
  p %= MOD
  q += comb(i-1, W-1) * two_inv[i] % MOD
  q %= MOD

Measured memory_bytes: 58584
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
    while(1){
        y%=x;
        if(y==0)return x;
        x%=y;
        if(x==0)return y;
    }
}
int main(){
    int n;
    cin>>n;
    int N=1000001;
    vector<int>furui(N);
    for(int i=0;i<N;i++)furui[i]=i;
    for(int i=2;i<=N;i++){
        if(furui[i]==i){
            for(int j=i*2;j<=N;j+=i)furui[j]=i;
        }
    }
    int a[n];
    set<int>s;
    bool b=1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        int A=a[i];
        while(furui[A]!=1){
            int f=furui[A];
            if(s.count(f))b=0;
            s.insert(f);
            while(A%f==0)A/=f;
        }
    }
    if(b){
        cout<<"pairwise coprime"<<endl;
        return 0;
    }
    int g=a[0];
    for(int i=1;i<n;i++){
        g=gcd(g,a[i]);
        if(g==1){
            cout<<"setwise coprime"<<endl;
            return 0;
        }
    }
    cout<<"not coprime"<<endl;
    return 0;
}

Measured memory_bytes: 14776
#include<stdio.h>

int main()
{
	int a=0,b=0,c=0;
	scanf("%d %d %d",&a,&b,&c);

	if(c+a<=c+b && c+a<=b+a )
		printf("%d\n",c+a);
	else if(c+b<=a+b && c+b<=a+c)
		printf("%d\n",c+b);
	else if(a+b<=c+a && a+b<=b+c)
		printf("%d\n",a+b);
		
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  ll A, B, C;
  cin >> A >>B >> C;
  if(A + B >= C) cout << B + C << endl;
  else cout << A + B + min(B, C) + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007LL
#define all(x) x.begin() , x.end()
#define ld long double
void solve();
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t = 1; //cin >> t;
	while (t--)
		solve();
	return 0;
}
void solve()
{
	ll n; cin >> n;
	ll arr[n]; for (auto &x : arr) cin >> x;
	ll res = 0;
	sort(arr , arr + n);
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			for (int k = j + 1; k < n; k++)
			{
				if (arr[i] != arr[j] and arr[j] != arr[k] and arr[k] < arr[i] + arr[j]) res++;
			}
		}
	}
	cout << res;
	return ;
}


Measured memory_bytes: 3656
s = input()
n = len(s)
a = s[:(n-1)//2]
b = s[((n+3)//2)-1:]
if a == b:
    a_rev = a[::-1]
    b_rev = b[::-1]
    if a == a_rev and b == b_rev:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 38384
#include <stdio.h>

int main(){
  int t, c=0, i ,j, m, n, a[100];
  scanf("%d", &n);
  for(i=0; i<n; i++)scanf("%d", &a[i]);
  for(i=0; i<n; i++){
    m = i;
    for(j=i; j<n; j++){
      if(a[j]<a[m]) m = j;
    }
    if(m != i){
      t = a[i];
      a[i] = a[m];
      a[m] = t;
      c++;
    }
  }
  for(i=0; i<n-1; i++)printf("%d ", a[i]);
  printf("%d\n%d\n", a[i],c);
  return 0;
}

Measured memory_bytes: 1820
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = map(int, input().split())
prices = [0] * n
for i in range(n):
    prices[i] = tuple(map(int, input().split()))
prices = sorted(prices)

ans = 0
for a, b in prices:
    if m <= b:
        ans += (a * m)
        break
    else:
        ans += (a * b)
        m -= b
print(ans)


Measured memory_bytes: 85204
#include <cstdio>
#include <algorithm>
using namespace std;
const int Max = 200000 + 5;
int n, a[Max], a2[Max];
struct cmpFunctor {
    inline bool operator() (const int& a, const int& b) const {
        return a > b;
    }
};

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        a2[i] = a[i];
    }
    sort(a + 1, a + n + 1, cmpFunctor());
    for (int i = 1; i <= n; i++) {
        int ans;
        if(a[1] == a2[i])
            ans = a[2];
        else
            ans = a[1];
        printf("%d\n", ans);
    }
    return 0;
}

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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    S = '0'+S;
    if(N==1){
        cout << 1 << endl;
        return 0;
    }else if(N==2){
        cout << (S[0]==S[1]? 1:2) << endl;
        return 0;
    }
    vector<vector<int>> dp(N+2,vector<int>(3,-1));
    dp[N][1] = 1;
    dp[N-1][2] = 1;
    for(int i=N-1;i>=1;i--){
        if(i+1<=N && S[i]!=S[i+1]) dp[i][1] = max(dp[i][1],dp[i+1][1]+1);
        if(i+2<=N){
            dp[i][1] = max(dp[i][1],dp[i+1][2]+1);
            dp[i][2] = max(dp[i][2],dp[i+2][1]+1);
        }
        if(i+3<=N && S.substr(i,2)!=S.substr(i+2,2)) dp[i][2] = max(dp[i][2],dp[i+2][2]+1);
    }
//    for(int k=1;k<3;k++) for(int i=1;i<=N;i++) cerr << dp[i][k] << (i!=N? " ":"\n"); 
    cout << max(dp[1][1],dp[1][2]) << endl;
}

Measured memory_bytes: 11456
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main(){
    string s;
    cin >> s;
    map<string, int> A;
    A["SUN"] = 7;
    A["MON"] = 6;
    A["TUE"] = 5;
    A["WED"] = 4;
    A["THU"] = 3;
    A["FRI"] = 2;
    A["SAT"] = 1;
    cout << A[s] << endl;
}


Measured memory_bytes: 3640
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
a = LI()
b = []
iodd = a[::2]
ieven = a[1::2]
if n % 2 == 0:
    b = ieven[::-1] + iodd
else:
    b = iodd[::-1] + ieven
print(*b)


Measured memory_bytes: 31016
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define rep2(i,a,n) for (int i = a; i < n; i++)
using namespace std;
int main() {
    int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
    long long res = 1000000000000000;
    long long cur = 0;
    int popular_pizza = max(X, Y);

    for (int i = 0; i <= popular_pizza; i++) {
        cur = i * 2 * C + A * max((X - i), 0) + B * max((Y-i), 0);
        if (res > cur) res = cur;
    }

    printf("%d\n", res);

    return 0;
}


Measured memory_bytes: 3672
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;
//Sieve of Eratosthenes
#define MAX_N 1'000'000
int prime[MAX_N];
bool isPrime[MAX_N + 1];
int sieve(ll n){
	int p = 0;
	fill(isPrime, isPrime+n+1, true);
	isPrime[0] = isPrime[1] = false;
	for(ll i=2; i<=n; i++){
		if(isPrime[i]){
			prime[p++] = i;
			for(ll j=2*i; j<=n; j+=i){
				isPrime[j] = false;
			}
		}
	}
}

int main(void){
	sieve(MAX_N);
	int x; cin >> x;
	rep2(i, x, MAX_N){
		if(isPrime[i]){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    string s;
    cin >> s;

    s.push_back('T');
    int n = s.size();

    int x, y;
    cin >> x >> y;

    vector<int> a[2];
    int c = 0, d = 0, f = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'F') {
            c++;
        } else {
            if (f == 0) {
                x -= c;
                f = 1;
            } else {
                a[d].push_back(c);
            }
            c = 0;
            d ^= 1;
        }
    }

    int b = 0;
    for (int d = 0; d < 2; d++) {
        bitset<8000> bs;
        bs.set(0);

        int m = a[d].size();
        for (int j = 0; j < m; j++) {
            int a1 = a[d][j];
            bs = bs >> a1 | bs << a1;
        }

        int z = abs(d == 0 ? x : y);
        if (z < 8000 && bs[z]) b++;
    }

    cout << (b == 2 ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    rep(i, 5) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

int main(){
	int k, n, t, mx = 0;
	cin >> k >> n;
	for(int i=0; i<n; i++){
		cin >> t;
		mx = max(mx, t);
	}
	cout << max(0, k-1-2*(k-mx)) << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int fib(int n);

int memo[45];

int main() {
  int n;

  //入力
  cin >> n;

  // 出力
  cout << fib(n) << endl;

  return 0;
}

int fib(int n){
  if( n == 0 || n == 1){
    return 1;
  }
  else if(memo[n] != 0){
    return memo[n];
  }
  else return memo[n] = fib(n-1) + fib(n-2);
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  int maxi = -1e9;
  for (int i = 0; i < n; i++) {
    if (maxi < --h[i]) maxi = --h[i];
    if(maxi>h[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

int main(void)
{
	
	string s;
	cin >> s;
	
	if (s[2] == s[3] && s[4] == s[5])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, L, R;
  cin >> N >> M;
  int LL=1;
  int RR=N;
  for (int i=0; i<M; i++) {
    cin >>L >>R;
    LL=max(LL, L);
    RR=min(RR, R);
  }
  RR=max(0, RR-LL+1);
  cout <<RR <<endl;
  return 0;
}


Measured memory_bytes: 256
//#include <GOD>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define len length	
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define freo freopen("output.txt","w",stdout)
#define frei freopen("input.txt","r",stdin)

const ll mod=1e9+7;
const ll maxn=1e2+10,maxa=1e3+10;

ll k;

int main(){
	FAST_IO;
	cin>>k;
	for(int i=0;i<k;i++){
		cout<<"ACL";
	}
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int x, a, b;
    cin>>x>>a>>b;
    cout<<(x-a)%b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main(){
	
	int N, M;
	cin >> N >> M;
	
	int ans = (N - M) * 100 + M * 1900;
	
	for(int i = 0; i < M; i++){
		ans *= 2;
	}
	
	cout << ans << endl;
	
	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 repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i=n; i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())

typedef long long ll;
typedef long double ld;
const ll mod = (ll)(1e9+7);//998244353;
const int N = (int)(1e6+5);

void pre() {

}

void solve() {
  ll l,r,d; cin>>l>>r>>d;
  int cnt = 0;
  repi(i,l,r) if(i%d == 0)  cnt++;
  cout<<cnt;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
  #endif
  int t = 1;
  pre();
  //cin>>t;
  rep(i,t)  {
//    cout<<"\nCase #"<<(i+1)<<"\n";
    solve();
    cout<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3544
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
l = inputIL()

l.sort(reverse=True)

A = l[::2]
B = l[1::2]

print(sum(A)-sum(B))


Measured memory_bytes: 65516
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    i = 0
    if not N:
        print(0)
        return
    ans = ""
    while N:
        if N>>i&1:
            ans += "1"
            N -= pow(-1,i%2==1) * 1<<i
        else:
            ans += "0"
        i+=1
    
    print(ans[::-1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 66284
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

string S;

int main() {
    cin >> S;

    for (int i = 0; i < S.length(); i++) {
        if (S[i] == '1') S[i] = '9';
        else if (S[i] == '9') S[i] = '1';
    }

    cout << S << endl;
}


Measured memory_bytes: 256
import Data.List

main = do
  _ <- getLine
  as <- getLine >>= return . map read . words :: IO [Integer]

  print $ min (sum $ zipWith (\a b -> abs (a-b)) as (f 0 as 1)) (sum $ zipWith (\a b -> abs (a-b)) as (f 0 as (-1)))
  
  where
    f _ [] _ = []
    f sum (x:xs) sign
      | sign < 0 = if sum + x > 0 then x : f (sum+x) xs (-sign) else (1-sum) : f 1 xs (-sign)
      | sign > 0 = if sum + x < 0 then x : f (sum+x) xs (-sign) else (-1-sum) : f (-1) xs (-sign)


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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 1e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

int a[N], b[N];

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int i = 0, tek = 0, sum = 0;
    while (i < s.size()) {
        char c = s[i];
        if (c == '<') {
           sum+= (++tek);
           i++;
        }
        else {
            int kol = 0;
            while (i < s.size() && c == s[i]) {
                kol++, i++;
            }
            if (kol > tek) sum+= (kol - tek);
            kol--;
            sum+= kol * (kol + 1) / 2;
            tek = 0;
        }
        //cout << sum << ' ' << i << endl;
    }
    cout << sum;
}


Measured memory_bytes: 1172
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;

int main()
{
	int b1, b2, b3;
	cin >> b1 >> b2 >> b3;

	if ((b1 == 1 && b2 == 0 && b3 == 0) ||
		(b1 == 0 && b2 == 1 && b3 == 0) ||
		b1 == 0 && b2 == 0 && b3 == 0) {
		cout << "Close" << endl;
	}
	else
		cout << "Open" << endl;
		
	return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
 
  if (A%500==0) {
    cout << "Yes" << endl;
  }
  
  else if (A%500<=B){
    cout << "Yes" << endl;
  }
  
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;

#define N 200050
#define mo 1000000007
int fac[N],inv[N];
void init(int lim)
{
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=lim;i++)
		fac[i]=(ll)fac[i-1]*i%mo;
	for(int i=2;i<=lim;i++)
		inv[i]=(ll)inv[mo%i]*(mo-mo/i)%mo;
	for(int i=2;i<=lim;i++)
		inv[i]=(ll)inv[i]*inv[i-1]%mo;
}

int C(int n,int m){return 0<=m && m<=n? (ll)fac[n]*inv[m]%mo*inv[n-m]%mo: 0;}

int pos[N];
int main()
{
	int n;scanf("%d",&n);
	int K;
	for(int i=1;i<=n+1;i++)
	{
		int c;scanf("%d",&c);
		if(!pos[c]) pos[c]=i;
		else K=n-(i-pos[c]);
	}
	init(200001);
	
	for(int i=1;i<=n+1;i++)
		printf("%d\n",(C(n+1,i)+mo-C(K,i-1))%mo);
}


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

#define fi first

#define se second

#define pb push_back

#define pob pop_back

#define eb emplace_back

#define start Tien_Dam_Sau

#define next Yeu_Tat_Ca

#define prev Cac_Hot_Girl

#define hash Tu_Mien_Nam

#define left Ra_Mien_Bac

#define right Chi_Can_Mat_Xinh

#define y0 Dang_Dap_Ngon

#define y1 Da_Trang_Non_Na

#define have La_Tien_Yeu_Het

#define ends Tien_Hua_Luon

#define tm Em_Muon_Lai_Chi

#define norm Nguyen_Van_Huong

#define yn Trieu_Thi_Ngoc_Minh

#define lr Tien_Thu_Khoa

#define sqr(val) (val * val)

#define gcd(a, b) abs(__gcd(a, b))

#define max3(a, b, c) max (a, max (b, c));

#define max4(a, b, c, d) max (a, max3 (a, b, c));

#define min3(a, b, c) min (a, min (b, c));

#define min4(a, b, c, d) min (a, min3 (b, c, d));

#define reset (a, val) memset (a, val, sizeof (a));

#define debug(val) cout << #val << " = " << val << '\n';

#define bitcount(n) __builtin_popcountll(n)

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

const int MAXN = 10 + 2e5;

const ll oo = 1 + 1e18;

const ll mod = 7 + 1e9;

typedef pair < int, int > ii;

typedef pair < int, ii > iii;

typedef pair < ll, ll > pll;

typedef pair < ll, pll > plll;

typedef vector < ii > vii;

typedef priority_queue < int > pqi;

typedef priority_queue < ii, vector < ii >, greater < ii > > pqii;

typedef set < int > :: iterator setit;

void file()
{
    #define TASK "ABC"

    freopen(TASK".inp","r",stdin);

    freopen(TASK".out","w",stdout);
}

void buff()
{
    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);
}

int n, ans = 0, a[MAXN];

vector < int > id[MAXN];

int main()
{
    buff();

  //  file();

    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];

        id[ a[i] ].push_back (i);
    }

    int cur_id = 0;

    for (int i = 1; i <= n; i++)
    {
        if (id[i].size() == 0) break;

        int pos = upper_bound (id[i].begin(), id[i].end(), cur_id) - id[i].begin();

        int now_id = id[i][pos];

        if (now_id <= cur_id) break;

        ans++;

        cur_id = now_id;
    }

    cout << (ans != 0 ? n - ans : -1);

    return 0;
}














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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define ford(i, b, a) for (int i = (int)(b); i >= a; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const int N = (int)1e5+77;
const ll inf = (ll) 1e15+77;
const ll mod = (ll) 998244353;
const ld pi = acos(-1);

int main() {
    fast;
    string s, t;
    cin >> s >> t;
    vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));
    for1(i, sz(s)) {
        for1(j, sz(t)) {
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            if (s[i - 1] == t[j - 1]) dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
        }
    }
    string ans = "";
    int i = sz(s), j = sz(t);
    while (i > 0 and j > 0) {
        if (s[i - 1] == t[j - 1]) ans += s[i - 1], i--, j--;
        else if (dp[i - 1][j] > dp[i][j - 1]) i--;
        else j--;
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int P; cin >> P;
  //int prices[] = { 500, 1000, 5000, 10000 };
  int ans = 0;
  while (P >= 500) {
    ans += 500;
    P -= 500;
  }
  cout << ans << endl;
}




Measured memory_bytes: 3112
import java.util.Scanner;

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

        int a = Integer.parseInt(s.next());
        int b = Integer.parseInt(s.next());
        int c = Integer.parseInt(s.next());
        int an = b / a;
        System.out.println(an < c ? an : c);
    }
}

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

int main()
{
    int N,X,T,a,x,n;
    cin>>N>>X>>T;

    if(N%X==0)
        x=(N*T)/X;

    else
    {
        x=(N/X)*T;
        x+=T;
    }

    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 3620
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let n = read::<i32>();   
    let ans = n * 800 - (n / 15) * 200;
    println!("{}",ans);
}

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

int main() {
  int A,B;
  cin >>A>>B;
  if(A!=1&&B!=1) {
    cout<<1;
  }
  if(A!=2&&B!=2) {
    cout<<2;
  }
  if(A!=3&&B!=3) {
    cout<<3;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fo(i,n) for(i=0;i<n;i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);


int main()
{
	  IOS
	  int t,n,m,i,j,l,r,c=0;
	  cin>>n>>m;
	  int arr[n+1],b[n+1];
	  for(i=0;i<=n;i++)arr[i]=0;
	  for(i=0;i<m;i++)
	  {
     cin>>l>>r;
     l--;
     r--;
    arr[l]++;
    if(r!=n-1)arr[r+1]-=1;
	  }
	  c+=(arr[0]>=m);
	  for(i=1;i<n;i++){arr[i]+=arr[i-1];c+=(arr[i]>=m);}
    cout<<c;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int A = in.nextInt();
		int B = in.nextInt();
		int K = in.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 1; i <= Math.max(A, B); i++) {
			if (A % i == 0 && B % i == 0) {
				list.add(i);
			}
		}
		System.out.println(list.get(list.size() - K));
	}
}


Measured memory_bytes: 23636
N=int(input())
s=[int(i) for i in input().split()]
ans=0
for c in range(1,N):
  k=0
  Score=0
  while k*c<N-1:
    a=N-1-k*c
    if ((N-1)%c==0 and k*c>=a) or a<=c:
      break
    Score+=s[k*c]+s[a]
    #print(c,k,Score)
    ans=max(Score,ans)
    k+=1
print(ans)

Measured memory_bytes: 63216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  rep(i, N) cin >> h[i];
  sort(all(h));

  int ans = 1e9;
  for (int i = 0; (i+K-1) < N; i++) {
    ans = min(ans, h[i+K-1]-h[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define LL long long
const LL INF=1e20;
LL sum[4];
LL t[3];
using namespace std;
LL n,m;
int main()
{
	scanf("%lld%lld",&n,&m);
    sum[0]=(LL)0;
	sum[1]=(LL)0;
	sum[2]=INF;
	sum[3]=INF;
	if(n%3==0||m%3==0)
	{
		printf("0");
	}
	else
	{
		LL x=m/2;
		LL y=m-m/2;
		LL a=n/2;
		LL b=n-n/2;
		if(n==2)
            sum[0]=INF;
		else
            sum[0]=m;
		if(m==2)
            sum[1]=INF;
        else
            sum[1]=n;
		for(LL i=1;i<n;i++)
		{
			t[0]=i*y;
			t[1]=i*x;
			t[2]=m*n-t[0]-t[1];
			sort(t,t+3);
			sum[2]=min(sum[2],t[2]-t[0]);
		}
		for(LL i=1;i<m;i++)
		{
			t[0]=i*b;
			t[1]=i*a;
			t[2]=m*n-t[0]-t[1];
			sort(t,t+3);
			sum[3]=min(sum[3],t[2]-t[0]);
		}
		sort(sum,sum+4);
		printf("%lld",sum[0]);
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int search(int A[],int n,int key){
	int i=0;
	A[n]=key;
	while(A[i]!=key){i++;}
	return i !=n;
}

int main(void){
	int i,n,A[100000],q,key;
	int cnt=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&key);
		if(search(A,n,key)){cnt++;}
	}
	
	printf("%d\n",cnt);
	
	return 0;
}


Measured memory_bytes: 2128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define sort(x) sort(ALL(x))
#define ALL(v) v.begin(), v.end()
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

void YNout(bool check){
	if(check)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return;
}

void Yayout(bool check){
	if(check) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	
	return;
}

/*
template <typename T>
void vecout(vector<T>& vecout_vec){
	
	rep(i,0,vecout_vec.size()){
		cout << vecout_vec.at(i) << endl;
	}
	
	return ;
}

template <typename T>
void vecin(vector<T>& vecin_vec, ll n){
	
	ll temp ;
	
	rep(i,0,n){
		cin >> temp;
		vecin_vec.push_back(temp);
		
	}
}

template <typename T>
void in(T& literal_in, T& literal_in2, ...){
	cin >> literal_in;
	in(literal_in2, ...);
	
	return;
}

template <typename T>
void in(T& literal_in){
	
	cin >> literal_in;
	
	return;
}

template <typename T>
void out(T& literal_out, T& literal_out2, ...){
	cout << literal_out << endl;
	out(literal_out2, ...);
	
	return;
}

template <typename T>
void out(T& literal_out){
	
	cout << literal_out << endl;
	
	return;
}
*/
signed main(){
	ll n;
	string s;
	ll type = 0;
	ll cnt[2] = {};
	
	cin >> n >> s;
	
	rep(i,0,n){
		
		
		
		if(type){
			if(s[i] == '('){
				cnt[1]++;
			}
			else{
				if(cnt[1] <= 0){
					type = 0;
					cnt[0]++;
				}
				else{
					cnt[1]--;
				}
			}
		}
		else{
			if(s[i] == '('){
				type = 1;
				cnt[1]++;
			}
			else{
				cnt[0]++;
			}
		}
		
		if(i != n-1){
			if(s[i] == ')' && s[i+1] == '('){
				type ^= 1;
			}
		}
	}
	
	rep(i,0,cnt[0]){
		cout << "(";
	}
	
	cout << s;
	
	rep(i,0,cnt[1]){
		cout << ")";
	}
	
	cout << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  ll x;
  cin>>x;
  ll ans = x/11;
  x -= ans*11;
  ans *= 2;
  if(x>0){
    x-=6;
    ans++;
  }
  if(x>0){
    x-=5;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim_i = (b); i < lim_i; i++)
#define REP(i, ...) REP_((i), __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Mar 14 21:00:02 JST 2020
 **/

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

const int K = 2001;

signed main() {
    string a, b, c;
    cin >> a >> b >> c;
    vector<bitset<K>> masks(26);
    REP(i, c.size()) {
        if (c[i] == '?') {
            REP(j, 26) masks[j][i + 1] = true;
        } else {
            masks[c[i] - 'a'][i + 1] = true;
        }
    }
    dump(masks);
    int ans = 1e9;
    REP(i, 0 - c.size() - b.size(), a.size() + c.size()) {
        string s(c.size(), '?');
        bool ok = true;
        REP(j, min(0, i), max((int)a.size(), i + (int)b.size())) {
            char c1 = 0 <= j && j < a.size() ? a[j] : '?';
            char c2 = 0 <= j - i && j - i < b.size() ? b[j - i] : '?';
            char c3 = -1;
            if (c1 == '?') {
                c3 = c2;
            } else if (c2 == '?') {
                c3 = c1;
            } else if (c1 == c2) {
                c3 = c1;
            } else {
                ok = false;
            }
            s.push_back(c3);
        }
        if (!ok) continue;
        REP(j, c.size()) s.push_back('?');
        bitset<K> cur;
        cur[0] = true;
        dump(s);
        REP(j, 0, (int)s.size()) {
            cur <<= 1;
            if (s[j] != '?') {
                cur &= masks[s[j] - 'a'];
            }
            cur[0] = true;
            if (cur[c.size()]) {
                dump(i, j, max((int)s.size() - (int)c.size(), j + 1) - min((int)c.size(), j - (int)c.size() + 1));
                chmin(ans, max((int)s.size() - (int)c.size(), j + 1) - min((int)c.size(), j - (int)c.size() + 1));
            }
        }
    }
    assert(ans < 1e9);
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.nextInt();
		int W = sc.nextInt();
		int[] a = new int[N];
		Arrays.setAll(a, i -> sc.nextInt());
		if(N == 1)
			System.out.println(Math.abs(a[0]-W));
		else
			System.out.println(Math.max(Math.abs(a[N-1] - W), Math.abs(a[N-2]-a[N-1])));
	}

}


Measured memory_bytes: 29012
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    rep(i,h){
        cin>>s[i];
    }
    rep(i,h){
        rep(j,s[i].size()){
            int dx[]={1,1,0,-1,-1,-1,0,1};
            int dy[]={0,-1,-1,-1,0,1,1,1};
            if(s[i][j]=='#') continue;
            int cnt = 0;
            for(int k=0;k<8;k++){
                int ni = i + dx[k], nj = j + dy[k];
                if(ni>=0 && ni<=h-1 && nj>=0 && nj<=w-1){
                    if(s[ni][nj]=='#') cnt++;
                }
            }
            s[i][j]=cnt+'0';
        }
    }
    rep(i,h) cout<<s[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define NMAX 102
using namespace std;
int main(){
	int N,L[NMAX],ans = 0;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> L[i];
	}
	for (int i = 0; i < N-2; ++i)
	{
		for (int j = i+1; j < N-1; ++j)
		{
			for (int k = j+1; k < N; ++k)
			{
				int a = L[i],b = L[j],c = L[k];
				if(L[i] != L[j] && L[i] != L[k] && L[j] != L[k]){
					if(a+b>max(a,max(b,c)) && a+c>max(a,max(b,c)) && b+c>max(a,max(b,c))){
						ans++;
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3640
import Data.List.Split

data Way = R | L

countTolls :: Way -> Int -> [Int] -> Int
countTolls R x tolls = length $ filter (x<) tolls
countTolls L x tolls = length $ filter (x>) tolls

judgeSmaller :: Int -> [Int] -> Int
judgeSmaller x tolls = min (countTolls R x tolls) (countTolls L x tolls)

main = do
	str <- getLine
	let sstr = splitOn " " str
	let nums = map (read :: String -> Int) sstr
	str' <- getLine
	let sstr' = splitOn " " str'
	let nums' = map (read :: String -> Int) sstr'
	let n = nums !! 0
	let m = nums !! 1
	let x = nums !! 2
	let way = judgeSmaller x nums'
	putStrLn $ show way
	
	

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

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

Measured memory_bytes: 3576
//2018-1-28
//miaomiao
//
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
#define pb push_back
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for(int i = (a); i >= (int)(b); --i)
 
#define N (100000 + 5)
const int P = 1e9 + 7;
 
inline int Mod(int a){return a >= P? a - P: a;}
 
struct node{
	int v, d;	
};
 
int n, m, s, t, fs[N], ft[N];
LL ds[N], dt[N];
vector<node> G[N];
 
bool inq[N];
 
void Spfa(int st, LL *dis){
	For(i, 1, n) dis[i] = 1ll << 60, inq[i] = false;
	queue<int> q;
	
	dis[st] = 0;
	q.push(st); inq[st] = true;
 
	while(!q.empty()){
		int now = q.front(); q.pop();
		inq[now] = false;
 
		For(i, 0, G[now].size() - 1){
			int v = G[now][i].v, md = G[now][i].d;
			
			if(dis[v] > dis[now] + md){
				dis[v] = dis[now] + md;
				if(!inq[v]){
					q.push(v); inq[v] = true;
				}
			}
		}
	}
}
 
vector<node> g[N];
int in[N];
 
void Work(int st, LL *dis, int *f){
	For(i, 1, n) g[i].clear(), in[i] = 0;
	For(u, 1, n) For(i, 0, G[u].size() - 1){
		int v = G[u][i].v, d = G[u][i].d;
		if(dis[u] + d == dis[v]){
			g[u].pb(G[u][i]); ++in[v];
		}
	}
 
	queue<int> q;
 
	f[st] = 1;
	For(i, 1, n) if(!in[i]) q.push(i);
 
	while(!q.empty()){
		int now = q.front(); q.pop();
 
		For(i, 0, g[now].size() - 1){
			int v = g[now][i].v;
			f[v] = Mod(f[v] + f[now]); --in[v];
			if(!in[v]) q.push(v);
		}
	}
}
 
int Solve(){
	int ret = 0;
	LL D = ds[t];
 
	For(i, 1, n) if(2 * ds[i] <= D){
		if(2 * ds[i] == D && 2 * dt[i] == D){
			ret = Mod(ret + 1ll * fs[i] * ft[i] % P * fs[i] % P * ft[i] % P);
			continue;
		}
 
		For(j, 0, G[i].size() - 1){
			int v = G[i][j].v, d = G[i][j].d;
			if(2 * dt[v] >= D) continue;
			if(ds[i] + d + dt[v] != D) continue;
			
			ret = Mod(ret + 1ll * fs[i] * ft[v] % P * fs[i] % P * ft[v] % P);
		}
	}
 
	return ret;
}
 
int main(){
	int u, v, w;
	
	scanf("%d%d%d%d", &n, &m, &s, &t);
	For(i, 1, m){
		scanf("%d%d%d", &u, &v, &w);
		G[u].pb((node){v, w}); G[v].pb((node){u, w});
	}
 
	Spfa(s, ds); Work(s, ds, fs);
	Spfa(t, dt); Work(t, dt, ft);

	int ans = 1ll * fs[t] * fs[t] % P - Solve();
	
	if(ans < 0) ans += P;
	printf("%d\n", ans);
 
	return 0;
}

Measured memory_bytes: 17968