akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

vector<int>diss(const vector<int> goals, const vector<vector<int>>&edges) {
	queue<int>que;
	vector<int>memo(edges.size(),1e8);
	for (auto goal : goals) {
		memo[goal]=0;
		que.push(goal);
	}
	while (!que.empty()) {
		auto now(que.front());
		que.pop();
		for (auto e : edges[now]) {
			if (memo[e] > memo[now] + 1) {
				memo[e]=memo[now]+1;
				que.push(e);
			}
		}
	}
	return memo;
}

int main() {
	int Q;cin>>Q;
	while (Q--) {
		int N,M;cin>>N>>M;
		vector<vector<int>>edges(N+1);
		int natu,reno;cin>>natu>>reno;
		UnionFind uf(N+1);
		for (int i = 0; i < M; ++i) {
			int a,b;char ch;cin>>a>>b>>ch;
			if (ch == 'N') {
				edges[a].push_back(b);
				edges[b].push_back(a);
			}
			else {
				uf.unionSet(a,b);
			}
		}
		vector<int>reno_same;
		vector<int>goal_same;
		for (int i = 0; i <= N; ++i) {
			if(uf.root(i)==uf.root(reno))reno_same.push_back(i);
			if(uf.root(i)==uf.root(0))goal_same.push_back(i);
		}
		auto natu_dis(diss(vector<int>{natu}, edges));
		auto goal_dis(diss(goal_same, edges));
		auto reno_dis(diss(reno_same,edges));

		int ans=1e9;
		for (int i = 0; i <= N; ++i) {
			int sum=natu_dis[i]+goal_dis[i]+reno_dis[i];
			if(ans>sum)ans=sum;
		}
		if(uf.root(reno)==uf.root(0))ans=0;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 9984
#include<stdio.h>
#define N 100
#define INF 100000

int main(){
  int i,j,l,m[N+1][N+1],n,p[N+1],k,r;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1], &p[i]);
  }

  for(i=1;i<=n;i++){
    m[i][i] = 0;
  }

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i;k<j;k++){
	r = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
	if(m[i][j] > r) m[i][j] = r; 
      }
    }
  }
  printf("%d\n",m[i-1][j]);
  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool cmp(char a,char b)
{
	return a>b;
}
int main()
{
	string s,t;
	cin>>s;
	cin>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),cmp);
	if(s<t)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,k=parseMap(split(readline()))
    if a+k-1<b-k+1
        for i in a:a+k-1
            println(i)
        end
        for i in b-k+1:b
            println(i)
        end
    else
        for i in a:b
            println(i)
        end
    end

end
main()

Measured memory_bytes: 111916
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<set>
#include<string.h>
#include<map>
#include<vector>
#define pb push_back
#define ins insert 
#define mp make_pair
#define ll long long 
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 10000007
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll N,W;
    cin>>N>>W;
    ll weights[N+1],values[N+1],dp[N+1][W+1];
    for (int i = 1; i < N+1; ++i)
    {
        cin>>weights[i]>>values[i];
    }
    for (int i = 0; i < N+1; ++i)
    {
        for (int j = 0; j < W+1; ++j)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(weights[i]<=j)
                dp[i][j]=max(dp[i-1][j],values[i]+dp[i-1][j-weights[i]]);
            else 
                dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[N][W]<<endl; 
    return 0 ;
}


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

#define pb push_back

const int maxn = 3e5 + 10;

int x, y, r[maxn], c[maxn];
vector<int>  rr, cc;
set<pair<int,int> >st;
void solve()
{
  int h, w, m;
  cin >> h >> w >> m;
  int mr = 0, mc = 0;
  for (int i = 0; i < m; i++)
  {
    cin>>x>>y;
    st.insert(make_pair(x,y));
    r[x]++;
    c[y]++;
    if(mr<r[x])
      {
        mr=r[x];
        rr.clear();
        rr.pb(x);
      }
    else if(mr==r[x])
    {
      rr.pb(x);
    }
    if(mc<c[y])
      {
        mc=c[y];
        cc.clear();
        cc.pb(y);
      }
    else if(mc==c[y])
    {
      cc.pb(y);
    }
  }
  for(int i:rr)
    for(int j:cc)
    {
      if(st.count(make_pair(i,j)))
        continue;
      else 
        {
          cout<<mr+mc;
          return;
        }
    }
  cout << mr+mc-1;
}
signed main()
{
  solve();
  return 0;
}


Measured memory_bytes: 21852
n=int(input())
a=[int(i) for i in input().split()]
i=a[0]
j=sum(a)-i
ans=abs(i-j)
x=1
while (x+1)!=n:
    i+=a[x]
    j-=a[x]
    ans=min(ans,abs(i-j))
    x+=1
print(ans)

Measured memory_bytes: 24812
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int, int>> s(n), l(n);
    REP(i, n) {
        int a, b;
        cin >> a >> b;
        s[i] = make_pair(b, a);
    }
    REP(i, n)  {
        int c, d;
        cin >> c >> d;
        l[i] = make_pair(c, d);
    }
    sort(ALL(l));

    int ans = 0;
    REP(i, n) {
        int c = l[i].first;
        int d = l[i].second;
        sort(ALL(s), greater<pair<int, int>>());
        REP(j, s.size()) {
            int a = s[j].second;
            int b = s[j].first;
            if(a < c and b < d) {
                ans++;
                s.erase(s.begin() + j);
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//解説
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int N,C,X;
int D[33][33];
int t[3][33];
int main(void)
{
    scanf("%d%d",&N,&C);
    rep(i,C)rep(j,C)scanf("%d",&D[i][j]);
    rep(i,N)rep(j,N)scanf("%d",&X),t[(i+j)%3][X-1]++;
    int res=1<<30;
    rep(i,C)rep(j,C)if(i!=j)rep(k,C)if(i!=k&&j!=k)
    {
        int tt=0;
        rep(l,C)tt+=D[l][i]*t[0][l];
        rep(l,C)tt+=D[l][j]*t[1][l];
        rep(l,C)tt+=D[l][k]*t[2][l];
        if(tt<res)res=tt;
    }
    printf("%d\n",res);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <limits>
#include <unordered_map>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;


int main()
{
	int A, B, C, X, Y;
	std::cin >> A >> B >> C >> X >> Y;

	int ans = 0;
	if (A + B > 2 * C)
	{
		int minXY = min(X, Y);
		ans += C * minXY * 2;
		X -= minXY;
		Y -= minXY;
	}
	if (X == 0 && B > 2 * C)
	{
		ans += C * Y * 2;
	}
	else if (Y == 0 && A > 2 * C)
	{
		ans += C * X * 2;
	}
	else
	{
		ans += A * X;
		ans += B * Y;
	}
	std::cout << ans;
}

Measured memory_bytes: 384
namespace ABC127.A
{
    using static System.Console;
    using System.Linq;
    using System.Collections.Generic;
    public class Program
    {
        public static void Main(string[] args)
        {
            var l = ReadInputsAsInt().ToList();
            var A = l[0];
            var B = l[1];
            WriteLine(Solve(A, B));
        }

        public static int Solve(int a, int b)
        {
            return a >= 13 ? b :
                a >= 6 ? b / 2 : 0;
        }
        static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x));
    }
}

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

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

    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==N){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
def main():
  N,X,Y = map(int,input().split())
  V = [[] for _ in range(N)]
  
  for i in range(N-1):
    V[i].append(i+1)
    V[i+1].append(i)
  X -= 1
  Y -= 1
  V[X].append(Y)
  V[Y].append(X)
  #print(V)
  
  ans = [0 for _ in range(N)]
  INF = float('INF')
  for s in range(N):
    D = [INF for _ in range(N)]
    q = [s]
    d = 0
    while(q):
      q2 = []
      for v in q:
        D[v] = min(D[v],d)
        for u in V[v]:
          if D[u] == INF:
            q2.append(u)
      q = q2[:]
      d += 1
      #print(q,d,D)
    for i in range(N):
      ans[D[i]] += 1
  for i in range(1,N):
    print(ans[i]//2)

main()

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  string s;
  cin >> s;

  ll n = s.size();

  vector<ll> a(n + 1);

  rep(i, n) {
    if (s[i] == '<') {
      a[i + 1] = max(a[i] + 1, a[i + 1]);
    }
  }

  for (int i = n-1; i >= 0; i--) {
    if (s[i] == '>') {
      a[i] = max(a[i], a[i + 1] + 1);
    }
  }

  ll ans = accumulate(all(a), 0LL);

  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  string s[N]={},X;
  int t[N]={},flag=0,result=0;
  for (int i=0;i<N;i++){
    cin >> s[i] >> t[i];
  }
  cin >> X;
  for (int i=0;i<N;i++){
    if(flag == 1){
      result += t[i];
    }
    if(s[i]==X){
      flag = 1;
    }
  }
  cout << result;
}

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

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

    int ans = abs(A + B);

    if(ans %2 ==0){
        cout << ans / 2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        Integer count = 0;

        for(int i = 0; i < S.length(); i++){
            if(S.charAt(i) != T.charAt(i)){
                count ++;
            }
        }

        System.out.println(count);
    }
}


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

int gcd(int a,int b){
  if(b==0)return a;
  gcd(b,a%b);
}
int gcd(vector<int>a){
  int ans=a[0];
  for(int i=1;i<a.size();i++){
    ans=gcd(ans,a[i]);
  }
  return ans;
}
int main() {
  int n; 
  cin >>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  int kotae=gcd(a);
  cout<<kotae<<endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;

public class Main {
	static List<Integer> path;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		br.close();

		System.out.println(n - k + 1);
	}
}


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

typedef long long ll;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int c = 0;
    int sum = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    for (auto aa: a) {
        if (aa * 4 * m >= sum) {
            c++;
        }
    }
    if (c >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    ll C, D;
    cin>>N>>A>>B>>C>>D;
    --N;
    ll dif = abs(A - B), range = N * (D - C);
    bool yes = false;
    rep(i, N+1){
        ll temp = C*i - (N - i) * D;
        if(temp <= dif && temp + range >= dif) yes = true;
    }
    cout<<(yes ? "YES" : "NO")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

vector<char> ans;
vector<string> V;

void func(int ind,int& X,int& Y,char x,char y){
  if(X>Y){
    ans[ind]=y;
    X--,Y++;
  }else if(X<Y){
    ans[ind]=x;
    X++,Y--;
  }else{
    string nex=V[ind+1];
    if(nex[0]==x||nex[1]==x){
      ans[ind]=x;
      X++,Y--;
    }else{
      ans[ind]=y;
      X--,Y++;
    }
  }
}

void fin(){
  cout<<"No\n";
  exit(0);
}

int main(){
  int N,A,B,C;
  cin>>N>>A>>B>>C;
  V.resize(N);
  rep(i,N) cin>>V[i];
  V.push_back("AA");
  ans.resize(N);

  rep(i,N){
    if(V[i]=="AB"){
      if(A+B==0) fin();
      func(i,A,B,'A','B');
    }
    if(V[i]=="AC"){
      if(A+C==0) fin();
      func(i,A,C,'A','C');
    }
    if(V[i]=="BC"){
      if(B+C==0) fin();
      func(i,B,C,'B','C');
    }
  }
  cout<<"Yes\n";
  rep(i,N) cout<<ans[i]<<endl;
  return 0;
}


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

typedef long long ll;

int N;
int A[200005];
ll cnt;

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%d", A+i);
	if (A[0]) return printf("-1\n"), 0;
	for (int i = 0; i < N-1; ++i) if (A[i+1] - A[i] > 1) return printf("-1\n"), 0;
	for (int i = 0; i < N; ++i) if (A[i] >= A[i+1]) cnt += A[i];
	printf("%lld\n", cnt);
}

Measured memory_bytes: 1024
function Main(input){
	input = input.split(" ").map(a=>~~a);
  var D = input[0];
  var N = input[1];
  if(N==100){
  	if(D==0)return 101;
    if(D==1)return 10100;
    if(D==2)return 1010000;
  }
  return N * Math.pow(100,D);
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
1 11
`);

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...)                                                             \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    int n, m, s;
    struct G {
        i64 v, t, c;
        G(i64 a, i64 b, i64 c) : v(a), t(b), c(c) {}
    };
    vector<G> V[55];
    struct ND {
        i64 tim, u, s;
        ND(i64 a, i64 b, i64 c) : tim(a), u(b), s(c) {}
        bool operator<(const ND &p1) const { return tim > p1.tim; }
    };
    i64 dis[55][5555];
    void solve() {
        cin >> n >> m >> s;
        for (int i = 0; i < m; ++i) {
            int u, v, a, b;
            cin >> u >> v >> a >> b;
            V[u].emplace_back(v, b, a);
            V[v].emplace_back(u, b, a);
        }
        for (int i = 1; i <= n; ++i) {
            int c, d;
            cin >> c >> d;
            V[i].emplace_back(i, d, -c);
        }
        s = min(s, 5000);
        for (int i = 0; i < 55; ++i)
            for (int j = 0; j < 5555; ++j)
                dis[i][j] = 1e18;
        priority_queue<ND> que;
        dis[1][s] = 0;
        que.emplace(0, 1, s);
        while (que.size()) {
            auto [tim, u, s] = que.top();
            que.pop();
            for (auto [v, t, c] : V[u]) {
                if (s - c < 0 || s - c > 5000)
                    continue;
                if (dis[v][s - c] > tim + t) {
                    dis[v][s - c] = tim + t;
                    que.emplace(tim + t, v, s - c);
                }
            }
        }
        for (int i = 2; i <= n; ++i) {
            i64 ans = 1e18;
            for (int j = 0; j < 5555; ++j)
                ans = min(ans, dis[i][j]);
            cout << ans << "\n";
        }
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 11892
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define inf int(1e9)
#define half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int mod = 1000000007;

string n;

void solve() {
    ll ans = 0;
    bool has_no_9 = false;
    repr(i, n.length()) {
        int num = int(n[i] - '0');
        if (i == 0) {
            if (has_no_9) ans += (num - 1);
            else ans += num;
        } else {
            if (num != 9) has_no_9 = true;
            ans += 9;
        }
    }
    cout << ans << endl;
}

int main() {
    cin >> n;
    solve();
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	_ = readInt()
	s := []byte(readString())
	needleft := 0
	needright := 0
	for _, p := range s {
		if p == '(' {
			needright++
		} else {
			if needright > 0 {
				needright--
			} else {
				needleft++
			}
		}
	}
	for i := 0; i < needleft; i++ {
		printf("(")
	}
	printf("%s", string(s))
	for i := 0; i < needright; i++ {
		printf(")")
	}
	println()
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
n, k = gets.split.map(&:to_i)
n = n.to_f
result = 0.0
if n >= k
  result = (n-k+1) / n
end

k = k.to_f
old_k = k
coin = 1
while k >= 1
  k = k/2
  if k < n
    old_k = n+1 if old_k > n
    count = old_k.ceil - k.ceil
    result += count / n / 2**coin
  end
  coin += 1
  old_k = k
end

puts result


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    cout << N / 3 << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    long long a,b,p,q,i,l;
    cin>>a>>b;
    p=max(a,b);
    q=min(a,b);
    for(i=1;i>=1;i++)
    {
        l=p*i;
        if(l%q==0)
        {
            cout<<l<<endl;
            break;
        }
    }    
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
 
  if (A + B < C + D) {
    cout << "Right" << endl;
  }
 
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
 
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 3588
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	char s[n];
	scanf("%s", s);
	int tmp=0;
	int ans=0;
	for(int i=0; i<n; i++){
		if(s[i]=='I') tmp++;
		if(s[i]=='D') tmp--;
		if(ans<tmp) ans = tmp;
	}
	
	printf("%d", ans);
	return 0;
}

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

vector<ll> X, Xodd;
// vector<ll> solve(ll n, ll K, ll d) {
//     vector<ll> res;
//     rep(i, n) {
//         ll rest = n-i;
//         res.pb((X[rest] + d - i) / 2 / (X[rest-1] + 1));
//     }
//     return res;
// }
vector<ll> solve(const ll n, const ll K, const ll d) {
    vector<ll> res;
    assert(X[n] + d >= 0);
    ll tgt = (X[n] + d) / 2;
    // cout << d << " " << X[n] << " " << n << " " << X[n-1] << endl;
    // assert(tgt == (X[n]-1)/2);
    rep(i, n) {
        ll bsz = X[n-i-1]+1;
        ll idx = tgt / bsz;
        tgt -= idx * bsz;
        res.pb(idx);
        assert(0 <= idx && idx < K);
        if (tgt == 0) return res;
        --tgt;
        assert(tgt >= 0);
    }
    return res;
}
// const ll maxX = 1e12;
// const ll thX = maxX;
void init_X(const ll n, const ll K) {
    X.assign(n+1, 0);
    Xodd.assign(n+1, 0);
    rep(i, 1, n+1) {
        if (X[i-1] < 1e12) {
            X[i] = min((X[i-1] + 1) * K, linf);
        }
        else {
            X[i] = linf;
        }
        Xodd[i] = (X[i-1] + 1) * K % 2;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, K; cin >> K >> n;
    vector<ll> ans;
    init_X(n, K);
    // cout << X << endl;
    if (K % 2 == 0) {
        ans.pb(K/2-1);
        rep(i, 1, n) {
            ans.pb(K-1);
        }
    }
    else {
        rep(i, n) {
            if (X[n-i] < linf) {
                vector<ll> a = solve(n-i, K, -1-i);
                each(x, a) ans.pb(x);
                break;
            }
            else {
                ans.pb(K/2);
            }
        }
        // ans = solve(n, K, -1);
    }
    each(x, ans) ++x;
    cout << ans << endl;
}


Measured memory_bytes: 11244
from itertools import accumulate
n = int(input())
w = list(map(int, input().split()))

acm = [0]+list(accumulate(w))
acm_rev = [0]+list(accumulate(reversed(w)))
acm_rev.reverse()

wgt = 100
for i in range(n+1):
    wgt = min(wgt, abs(acm[i]-acm_rev[i]))
print(wgt)

Measured memory_bytes: 38256
n, k, q = gets.split.map(&:to_i)
w = q.times.map { gets.to_i }
p = [].fill(k - q, 0...n)
w.each { |i| p[i - 1] += 1 }
puts p.map { |j| j > 0 ? 'Yes' : 'No'}.join("\n")

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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(),greater<char>());
    if(s < t)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int M = 0;
    int N = 0;
    int out = 0;

    cin >> M >> N;

    // all = Mc2 + Nc2
    int mc2 = 0;
    int nc2 = 0;
    if(M != 0){
        mc2 = (M * (M-1)) / 2;
    }

    if(N != 0){
        nc2 = (N * (N-1)) / 2;
    }

    out = mc2 + nc2;

    cout << out << endl; 

    return 0;
}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define rep(i, n) for(int i = 0; i < n; i++)
const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
  int N, Q;
  cin >> N >> Q;
  //一番手前の黒の位置
  vi down(N - 2, N - 3);
  vi right(N - 2, N - 3);
  ll n = N;
  ll ans = (n - 2) * (n - 2);
  //左斜め上の黒のみの長方形の右辺と下辺
  int R = N - 3;
  int D = N - 3;
  rep(i, Q) {
    int a, x;
    cin >> a >> x;
    x -= 2;
    if(a == 1) {
      if(x > R) {
        ans -= down.at(x) + 1;
      }
      else {
        ans -= D + 1;
        for(int j = x; j <= R; j++) {
          down.at(j) = D;
        }
        R = x - 1;
      }
    }
    else {
      if(x > D) {
        ans -= right.at(x) + 1;
      }
      else {
        ans -= R + 1;
        for(int j = x; j <= D; j++) {
          right.at(j) = R;
        }
        D = x - 1;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4840
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int N, M, A, B; cin >> N >> M >> A >> B;
	vector<int>v;
	for (int i =0 ; i < N; ++i) {
		int a; cin >> a;
		if (a >= A)v.push_back(a);
		else break;;
	}
	if (N - v.size() < M) {
		while (1) {

			if (v.empty())break;
			if (v.back() <= B)v.pop_back();
			else {
				break;
			}
		}

	}
	cout << v.size() << endl;
	return 0;
}

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

const int N = 1e6 , M = 10 , inf = 1e9+5;
int n , mx , A[N][M] , dp[N][M];

main(){

  cin >> n;

  for(int i = 1 ; i <= n ; i++)
    for(int j = 1 ; j <= 3 ; j++)
      cin >> A[i][j];

  dp[1][1] = A[1][1] , dp[1][2] = A[1][2] , dp[1][3] = A[1][3];

  for(int i = 2 ; i <= n ; i++)
    for(int j = 1 ; j <= 3 ; j++)
      for(int z = 1 ; z <= 3 ; z++)
        if(z != j) dp[i][j] = max(dp[i][j],dp[i-1][z]+A[i][j]);

  for(int i = 1 ; i <= 3 ; i++)
    mx = max(mx,dp[n][i]);

  cout << mx << "\n";

}

Measured memory_bytes: 8448
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int inf = 1000000;

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

  char pre = s[0];
  int cnt = 0;
  for (int i = 1; i < s.size(); i++) {
    if (pre != s[i]) {
      pre = s[i];
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 512
n = input()
size = len(n)
n = int(n)
i = 1
ans = 0
while 2*i-1 < size:
  ans = ans + 9*(10**(2*i-2))
  i = i+1
if size%2==1:
  ans = ans + (n-10**(size-1)) + 1
  
print(ans)

Measured memory_bytes: 9164
#include <iostream>
#include <string>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}
	else if(a>b){
		cout<<"a > b"<<endl;
    }
    else if(a==b){
		cout<<"a == b"<<endl;
	}
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define M 1000000007
#define endl '\n'
#define ll long long
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	string str;
	cin>>str;

	str=str+'S';

	ll len=str.length();

	ll maxi=INT_MIN;
	ll count{0};
	for(ll i=0;i<len;i++){
		if(str[i]=='R'){
			count++;
		}
		else{
			if(count>maxi)
				maxi=count;
			count=0;
		}
	}

	cout<<maxi<<endl;

	return 0;
}



Measured memory_bytes: 3648
/*=============================================================================================================================/*
                                               Bismillahir Rahmanir Rahim

      _     ____  ___  ____   _   _  _         ___  ____   _         _     __  __
     / \   / ___||_ _|| __ ) | | | || |       |_ _|/ ___| | |       / \   |  \/  |
    / _ \  \___ \ | | |  _ \ | | | || |        | | \___ \ | |      / _ \  | |\/| |
   / ___ \  ___) || | | |_) || |_| || |___     | |  ___) || |___  / ___ \ | |  | |
  /_/   \_\|____/|___||____/  \___/ |_____|   |___||____/ |_____|/_/   \_\|_|  |_|

   _   __           __  __  __
  |_) (_  _  o__   /   (_  |_
  |_)o__)(_  || |  \__ __) |__

    ___                    _   _      _                _ _               __   ___                 _         _        _
   / __|_ _ ___ ___ _ _   | | | |_ _ (_)_ _____ _ _ __(_) |_ _  _   ___ / _| | _ ) __ _ _ _  __ _| |__ _ __| |___ __| |_
  | (_ | '_/ -_) -_) ' \  | |_| | ' \| \ V / -_) '_(_-< |  _| || | / _ \  _| | _ \/ _` | ' \/ _` | / _` / _` / -_|_-< ' \
   \___|_| \___\___|_||_|  \___/|_||_|_|\_/\___|_| /__/_|\__|\_, | \___/_|   |___/\__,_|_||_\__, |_\__,_\__,_\___/__/_||_|
                                                            |__/                           |___/


   FB: https://facebook.com/SIAsibul
   Gmail: asibulislam8@gmail.com

/*=============================================================================================================================*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(ll i=0;i<(n);i++)
#define f1(i,n) for(ll i=1;i<=(n);i++)
#define f2(i,a,n) for(ll i=(a);i<=(n);i++)
#define fr(i,n,a) for(ll i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define nl "\n"


const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;
const int MOD = 1e9 + 7;


int main(){
    int x; cin >> x;
    int ans = 0;
    if(x >= 400 && x <= 599) ans = 8;
    else if(x >= 600 && x <= 799) ans = 7;
    else if(x >= 800 && x <= 999) ans = 6;
    else if(x >= 1000 && x <= 1199) ans = 5;
    else if(x >= 1200 && x <= 1399) ans = 4;
    else if(x >= 1400 && x <= 1599) ans = 3;
    else if(x >= 1600 && x <= 1799) ans = 2;
    else if(x >= 1800 && x <= 1999) ans = 1;

    cout << ans << nl;
    return 0;
 }


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int a,b; cin >> a >> b;
    if(a < b) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
from itertools import repeat
def main():
    m = int(stdin.readline())
    dat = map(int, stdin.read().split(), repeat(10, 2 * m))
    s = sum(dat[i*2] * dat[i*2+1] for i in xrange(m))
    l = sum(dat[1::2])
    print l - 1 + (s - 1) / 9
main()


Measured memory_bytes: 23236
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>

#define MAX 1000

int main(void)
{
    char word[11];
    scanf("%s", word);
    int length = strlen(word);
    int found = 0;

    char text[MAX + 1];
    while (scanf("%s", text))
    {
        // scanf("%s", text);
        if (strcmp(text, "END_OF_TEXT") == 0)
            break;
        // for (int i = 0; i < strlen(text); i++)
        // {
        //     if (text[i] >= 'A' && text[i] <= 'Z')
        //         text[i] -= 'A' - 'a';
        // }
        for (int i = 0; i < strlen(text); i++)
        {
            text[i] = tolower(text[i]);
        }
        if (strcmp(text, word) == 0)
            found++;
    }
    printf("%d\n", found);
    return 0;
}


Measured memory_bytes: 2120
//
//  main.cpp
//  program
//
//  Created by h3032906 on 2016/11/24.
//  Copyright ?? 2016??´ h3032906. All rights reserved.
//

#include <iostream>

int main(int argc, const char * argv[]) {

    int n, a, b;
    int at = 0;
    int bt = 0;
    for( ; ; ){
        std::cin >> n;
        if(n == 0){
            break;
        }
        for(int i = 0; i < n; i++){
            std::cin >> a >> b;
            if(a > b){
                at = at + a + b;
            }
            else if(b > a){
                bt = bt + a + b;
            }
            else {
                at = at + a;
                bt = bt + b;
            }
        }
        std::cout << at << " " << bt << std::endl;
        at = 0;
        bt = 0;
    }
    return 0;
}

Measured memory_bytes: 3000
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,m) for(int j=0;j<m;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<ll> ve;
typedef vector< vector < int> > vee;
typedef vector<pair<ll,ll> > vepa;
typedef set<int>se;
typedef map<char,int> mpp;
const ll N=1e3+5;
ll arr[N],A[N],cnt[N];
bool visited[N];
bool f,ff;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
   ll n,sum(0);
   cin>>n;
   for(int i=0;i<=n;i++)
   {
       if(i%3!=0&&i%5!=0)sum+=i;
   }
   cout<<sum;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, K; cin >> n >> K;

    int res = 0;
    while(n > 0){
        n /= K;
        res++;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String arg[]){
        Scanner sc = new Scanner(System.in);
        Integer[] list = new Integer[3];
        for(int i = 0;i < 3; i++){
            list[i] = sc.nextInt();
        }
        Arrays.sort(list);
        System.out.println(list[0]+list[1]);

    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

bool is_ok(int64_t v, int64_t k, vector<int64_t>& as, vector<int64_t>& bs)
{
	int64_t kt = 0;

	FOR_LT(i, 0, as.size()) {
		int64_t r = (v / bs[i]);
		kt += max((int64_t)0, as[i] - r);
	}

	return (kt <= k);
}

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

	int64_t n, k; cin >> n >> k;

	vector<int64_t> as(n);
	vector<int64_t> bs(n);

	for (auto& a : as) {
		cin >> a;
	}
	for (auto& b : bs) {
		cin >> b;
	}

	sort(as.begin(), as.end(), greater<int64_t>());
	sort(bs.begin(), bs.end());

	int64_t cmax = 0;
	FOR_LT(i, 0, n) {
		cmax = max(cmax, as[i] * bs[i]);
	}

	int64_t bottom = 0, up = cmax;
	while (true) {

		if (bottom == up) break;

		int64_t mid = (bottom + up) / 2;
		if (is_ok(mid, k, as, bs)) {
			if (mid == bottom) {
				up = mid;
			}
			else {
				up = mid;
			}
		}
		else {
			if (mid == bottom) {
				bottom++;
			}
			else {
				bottom = mid;
			}
		}
	}

	cout << bottom << endl;

	return 0;
}

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

public class Main {
    static Deque<String> list = new ArrayDeque<>();

    public static void main(String[] args) throws IOException {
        StringBuilder ans = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] sp = new String[2];
       
            int n = Integer.parseInt(br.readLine());
            for (int i = 0; i < n; i++) {
                sp = br.readLine().split(" ");
                if (sp[0].equals("insert")) {
                    list.addFirst(sp[1]);
                } else if (sp[0].equals("delete")) {
                    list.remove(sp[1]);
                } else if (sp[0].equals("deleteFirst")) {
                    list.removeFirst();
                } else if (sp[0].equals("deleteLast")) {
                    list.removeLast();
                }
            }
            if (!list.isEmpty()) {
                ans.append(list.getFirst());
                list.removeFirst();
            }
            while (!list.isEmpty()) {
                ans.append(" ").append(list.getFirst());
                list.removeFirst();
            }
            System.out.println(ans.toString());
       
    }
}



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

void output(){
    cout << "vowel" << endl;
}
int main(){
    char c;
    cin >> c;
    if(c == 'a'){
        output();
    }
    else if(c == 'i'){
        output();
    }
    else if(c == 'u'){
        output();
    }
    else if(c == 'e'){
        output();
    }
    else if(c == 'o'){
        output();
    }
    else{
        cout<<"consonant"<<endl;
    }
    
}

Measured memory_bytes: 3608
x, y = map(int, input().strip().split())

# 鶴: c, 亀: t
#   c +   t = x
# 2 c + 4 t = y

found = False
for c in range(101):
    for t in range(101):
        if c + t == x and 2 * c + 4 * t == y:
            found = True

if found:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9108
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * 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;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int k = in.nextInt();
			List<Integer> pos = new ArrayList<>();
			List<Integer> neg = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				int x = in.nextInt();
				if (x >= 0) {
					pos.add(x);
				} else {
					neg.add(-x);
				}
			}
			Collections.reverse(neg);
			long[] sumP = sums(pos);
			long[] sumN = sums(neg);
			long ans = Long.MAX_VALUE;
			for (int p = 0; p <= k && p < sumP.length; p++) {
				int nn = k - p;
				if (nn < 0 || nn >= sumN.length) {
					continue;
				}
				ans = Math.min(ans, 2 * sumP[p] + 1 * sumN[nn]);
				ans = Math.min(ans, 1 * sumP[p] + 2 * sumN[nn]);
			}
			out.println(ans);
		}

		private long[] sums(List<Integer> a) {
			long[] s = new long[a.size() + 1];
			for (int i = 0; i < a.size(); i++) {
				s[i + 1] = s[i] + a.get(i);
				if (i > 0) {
					s[i + 1] -= a.get(i - 1);
				}
			}
			return s;
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

	}
}



Measured memory_bytes: 43524
#include <bits/stdc++.h>
using namespace std;
long int cal(long int n,long int x){
    if(n == -1) return 0;
    else return n/x +1;
}
int main(void){
    long int a,b,x;
    cin >> a >> b >> x;
    cout << cal(b,x) - cal(a-1,x) << endl;
}


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

int main(){

    int n,d,x;
    cin >>n >>d >>x;

    vector<int> a(n);

    rep(i,n) cin >>a[i];

    ll ans=x;

    rep(i,n){
        for(int j=0;j*a[i]+1<=d;j++){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

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

	int x = 0; 
	int y = 0;
	int temp = 1;
	rep(i, b) {
		x += a * temp;
		temp *= 10;
	}
	temp = 1;
	rep(i, a) {
		y += b * temp;
		temp *= 10;
	}
	
	if (a < b)cout << x << endl;
	else cout << y << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



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

    ll t = 1;
    ll s = 7;
    ll x = 0;
    ll ans = 1;
    rep(i, 2000001) {
        x += t * s;
        x %= K;
        if (x == 0) {
            cout << ans << endl;
            return 0;
        }
        ans++;
        t *= 10;
        t %= K;

    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3636