akhauriyash/Code-Regression huggingface dataset:
///*
#include<iostream>
using namespace std;

void smallersort_INT(int *x, int n);

int main() {

	int a[3], i;
	for (i = 0; i < 3; i++)cin >> a[i];
	smallersort_INT(a, 3);

	if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}

	return 0;
	
}
//*/

void smallersort_INT(int *x, int n) {
	int i, j, fake;

	for (i = 0; i < n; i++) {
		for (j = 0; j < n - 1; j++) {
			if (x[j] > x[j + 1]) {
				fake = x[j];
				x[j] = x[j + 1];
				x[j + 1] = fake;
			}
		}
	}
}

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

using namespace std;

int main(void) {
	string S;
	cin >> S;
	vector<int> count(3, 0);
	for (int i = 0; i < S.length(); i++) {
		count[S[i] - 'a']++;
	}
	if (*min_element(count.begin(), count.end()) + 1 >= *max_element(count.begin(), count.end())) cout << "YES" << endl;
	else cout << "NO" << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 760
def bubble_sort(c, n):
    for i in range(n):
        for j in range(n-1 , i, -1):
            if int(c[j][1:]) < int(c[j-1][1:]):
                c[j],c[j-1] = c[j-1],c[j]
    return c

def selection_sort(c, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if int(c[j][1:]) < int(c[minj][1:]):
                minj = j
        c[i],c[minj] = c[minj],c[i]
    return c

import copy
n = int(input())
c = input().split()
bc = bubble_sort(copy.deepcopy(c), n)
sc = selection_sort(copy.deepcopy(c), n)
print(*bc)
print("Stable")
print(*sc)
print("Stable" if sc == bc else "Not stable")


Measured memory_bytes: 6344
#include <iostream>
#include <cstdio>

using namespace std;

int main(){

	double p0x,p0y,p1x,p1y,p2x,p2y,tx,ty;
	int q;
	double a01,a2t,b01,b2t;

	cin>>p0x>>p0y>>p1x>>p1y;

	cin>>q;

	for(int i=0;i<q;i++){
		cin>>p2x>>p2y;
		if(p0x-p1x!=0) a01=(p0y-p1y)/(p0x-p1x);
		else a01=0;
		if(a01!=0) a2t=-1/a01;
		else a2t=0;
		b2t=p2y-a2t*p2x;
		b01=p0y-a01*p0x;
		if(a01-a2t!=0) tx=(b2t-b01)/(a01-a2t);
		else tx=0;
		ty=a01*tx+b01;
		if(p0x==p1x) ty=p2y;
		if(p0y==p1y) tx=p2x;
		ty=p2y-(p2y-ty)*2;
		tx=p2x-(p2x-tx)*2;
		printf("%.10f %.10f\n",tx,ty);
	}

	return 0;
}

Measured memory_bytes: 1248
N=int(input())
L=list(map(int,input().split()))
L.sort()

ans=0
for i in range(N-2):
    a=L[i]
    for j in range(i+1,N-1):
        b=L[j]
        if a==b:
            continue
        for k in range(j+1,N):
            c=L[k]
            if b==c:
                continue
            ans+=a+b>c

print(ans)


Measured memory_bytes: 9064
def read():
    antennas = [0] * 5
    for i in range(5):
        antennas[i] = int(input().strip())
    k = int(input().strip())
    return antennas, k


def solve(antennas, k):
    for i in range(0, 5):
        for j in range(0, i):
            if antennas[i] - antennas[j] > k:
                return ':('
    return 'Yay!'


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

vector<ll> tree;
vector<ll> arr;
void build_tree (ll start, ll end, ll node)
{
    if (start==end)
    {
        tree[node]=arr[start];
        return;
    }
    else
    {
        ll mid=(start+end)/2;
        build_tree(start,mid,2*node);
        build_tree(mid+1,end,2*node+1);
        tree[node]=__gcd(tree[2*node],tree[2*node+1]);
        return;
    }
}

ll query (ll l, ll r, ll start, ll end, ll node)
{
    if (l<=r)
    {
        if ((l<=start)&&(end<=r))
        {
            return tree[node];
        }
        else if ((end<l)||(r<start))
        {
            return arr[l];
        }
        else
        {
            ll mid=(start+end)/2;
            return __gcd(query(l,r,start,mid,2*node),query(l,r,mid+1,end,2*node+1));
        }
    }
    else
    {
        return -1;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    ll n;
    cin >> n;
    arr.resize(n);
    for (ll i=0;i<=n-1;i++)
    {
        cin >> arr[i];
    }

    tree.resize(4*n);
    build_tree(0,n-1,1);

    ll ans=LLONG_MIN;
    for (ll i=0;i<=n-1;i++)
    {
        ll gcd_first=query(0,i-1,0,n-1,1);
        ll gcd_second=query(i+1,n-1,0,n-1,1);

        ll local;
        if ((gcd_first!=-1)&&(gcd_second!=-1))
        {
            local=__gcd(gcd_first,gcd_second);
        }
        else if (gcd_first==-1)
        {
            local=gcd_second;
        }
        else if (gcd_second==-1)
        {
            local=gcd_first;
        }

        ans=max(ans,local);
    }

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

Measured memory_bytes: 7036
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;

static const int N = 100005;
vector<int> V[N], visit(N, 0), color(N, 0);
queue<int> Q;

void paint(int c) {
	while (Q.size() > 0) {
		int u = Q.front();
		Q.pop();
		color[u] = c;
		Loop(i, V[u].size()) {
			if (color[V[u][i]] == 0) {
				Q.push(V[u][i]);
			}
		}
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	Loop(i, m) {
		int s, t;
		cin >> s >> t;
		V[s].push_back(t);
		V[t].push_back(s);
	}
	//color painting
	int c = 0;
	Loop(i, n) {
		if (color[i] == 0) {
			c++;
			Q.push(i);
			paint(c);
		}
	}
	//end
	int q;
	cin >> q;
	Loop(i, q) {
		int s, t;
		cin >> s >> t;
		if (color[s] == color[t]) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    string s,t;
    cin >> s;
    cout << 700 + ((s[0] == 'o')+(s[1] == 'o')+(s[2] == 'o')) * 100 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false),cin.tie(0);
#define F first
#define S second
using namespace std;
typedef long long ll;
ll n,k,w,m;
const ll maxn=200005;
const ll mod=1e9+7;
typedef pair<ll,ll> pii;
ll num[200005];
ll fro[200005],bac[200005];
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;

		b>>=1;
	}
	return res;
}

int main()
{
    //IOS
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(cin>>m>>k)
    {
        if(m==0)
        {
            if(k==0) cout<<"0 0\n";
            else cout<<"-1\n";
            return 0;
        }
        if(m==1)
        {
            if(k==0) cout<<"0 0 1 1\n";
            else cout<<"-1\n";
            return 0;
        }
        if(k>=(1<<m))
        {
            cout<<"-1\n";
            return 0;
        }
        vector<ll> v;
        rep(i,(1<<m)) if(i!=k) v.pb(i);
        vector<ll> v2(v);
        reverse(v2.begin(),v2.end());

        for(auto i:v) cout<<i<<" ";
        cout<<k<<" ";
        for(auto i:v2) cout<<i<<" ";
        cout<<k<<"\n";
    }




}


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

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

	int cnt = 0;
	for(int i=0; i<N; i++){
		int D1, D2;
		cin >> D1 >> D2;
		if(D1 == D2) cnt++;
		else cnt = 0;

		if(cnt == 3){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

}


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


int main()
{
  string w, s;
  int count=0;
  
  cin >> w;
  
  while(1){
    cin >> s;
    
    if(s=="END_OF_TEXT")
      break;
    
    for(int i=0;i<s.size();i++){
    	s[i] = tolower(s[i]);
    }
    
    if(w==s)
      count++;
  }
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3156
N,M=map(int,input().split())
List = []
for i in range (M):
  List.append(list(map(int, input().split())))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
uni = UnionFind(N)
for i in range(M):
  uni.union(List[i][0]-1,List[i][1]-1)
res = 0
for i in range(N):
  res = max(res,uni.size(i))
print(res)

Measured memory_bytes: 49972
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int n, a[110];
	bool c = 1;
	cin >> n;
	for (int i = 1; i <= n;i++) {
		cin >> a[i];
		if (a[i]%2==0) {
			if (a[i]%3!=0&&a[i]%5!=0) {
				c = 0;
			}
		}
	}
	if (c) {
		cout << "APPROVED" << endl;
	}
	else {
		cout << "DENIED" << endl;
	}

}

Measured memory_bytes: 256
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

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

	int A, B, C, D;
	int ans = 0;

	cin >> A >> B >> C >> D;

	if (!(A < B &&  B < C && C < D) && !(C < D && D < A && A < B)) {
		if(A <= C && B <= D){
			cout << abs(B - C) << endl;
		}else if(A <= C && B >= D){
			cout << abs(D - C) << endl;
		}else if(A >= C && B >= D){
			cout << abs(D - A) << endl;
		}else if(A >= C && B <= D){
            cout << abs(B - A) << endl;
        }
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin>>n;
  vector mat(50, vecll(50, 0));
  ll ans = 0;
  REP(i,n) {
    string s;
    cin>>s;
    auto pos = s.find('.');
    ll num;
    if (pos == string::npos) {
      num = stoll(s) * 1000000000;
    } else {
      auto si = s.substr(0, pos);
      auto sf = s.substr(pos+1);
      while (size(sf) < 9) {
        sf += '0';
      }
      num = stoll(si) * 1000000000 + stoll(sf);
    }
    ll cnt2 = 0, cnt5 = 0;
    while (num % 2 == 0) {
      ++cnt2;
      num /= 2;
    }
    while (num % 5 == 0) {
      ++cnt5;
      num /= 5;
    }
    ll sy = max(0l, 18-cnt2);
    ll sx = max(0l, 18-cnt5);
    FOR(y,sy,50)FOR(x,sx,50) {
      ans += mat[y][x];
    }
    mat[cnt2][cnt5] += 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
int main(){
	int n,k,q; cin>>n>>k>>q;
	int arr[100000] = {};
	forloop(q){
		int sayi; scanf("%d", &sayi);
		arr[sayi-1]++;
	}
	forloop(n){
		if(q-arr[i] >= k){
			printf("No\n");
		}else{
			printf("Yes\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

int n,k;
int a[N];
int mem[2][N];

int dp(bool p,int sum)
{
    if (sum < 0) return p;
    int &ret = mem[p][sum];
    if (ret != -1) return ret;
    if (sum == 0) return ret = !p;
    ret = !p;
    if (!p)
    {
        REP(i,0,n-1)
        {
            ret = min(ret,dp(!p,sum-a[i]));
        }
    }
    else
    {
        REP(i,0,n-1)
        {
            ret = max(ret,dp(!p,sum-a[i]));
        }
    }
    return ret;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);
    memset(mem,-1,sizeof mem);
    cin >> n >> k;
    REP(i,0,n-1) cin >> a[i];
    if (dp(1,k)) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}


Measured memory_bytes: 5888
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main() {
	int n;
	cin >> n;
	map<string, int>a;
	map<string, int>::iterator it;
	for (int z = 0; z < n; z++) {
		string b;
		int c;
		cin >> b >> c;
		it = a.find(b);
		if (it == a.end())
			a.insert(map<string, int>::value_type(b, c));
		else
			a[b] += c;
	}
	it = a.begin();
	int k = a.size();
	for (int i = 0; i < k; i++) {
		string g = "AAAAAAAAA";
		map<string, int>::iterator it2;
		it = a.begin();
		while (it != a.end()) {
			if ((*it).first.length() < g.length()) {
				g = (*it).first;
				it2 = it;
			}
			else if (g.length() == (*it).first.length()) {
				for (int j = 0; j < g.length(); j++) {
					if (g[j] > (*it).first[j]) {
						g = (*it).first;
						it2 = it;
						break;
					}
					else if (g[j] < (*it).first[j]) {
						break;
					}
				}
			}
			it++;
		}
		cout << (*it2).first << " " << (*it2).second << endl;
		a.erase(it2);
	}
}

Measured memory_bytes: 3196
#include<stdio.h>
#define MAX 2000000

int n, A[MAX+1];

void maxHeapify(int i){
    int l = 2 * i, r = 2 * i + 1, largest, tmp; 

    if( l <= n && A[l] > A[i] ) largest = l;
    else largest = i;
    if( r <= n && A[r] > A[largest]) largest = r;

    if( largest != i ) {
        A[tmp] = A[i];
        A[i] = A[largest];
        A[largest] = A[tmp];
        maxHeapify( largest );
    }
}

int main(void){
  int i;

  scanf("%d", &n);
  for( i = 1; i <= n; i++ ) scanf("%d", &A[i]);

  for( i = n / 2; i > 0; i-- ) maxHeapify(i);
  
  for( i = 1; i <= n; i++ ) printf(" %d", A[i]);
  printf("\n");

  return 0;
}



Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std ;
const int N = 1e5 +10 ;
const int inf = 0x3f3f3f3f ;
struct st{int p,b,c;};
bool operator < (st a,st b){return a.c>b.c;}
inline int read(){
    char c;int f=1 ;
    while ((c=getchar())<'0' || c>'9') if (c=='-') f=-1 ;
    int res=c-'0' ;
    while ((c=getchar())>='0' && c<='9') res=res*10+c-'0' ;
    return res*f ; 
}
map<int ,vector<int> > E[N] ; 
map<int,int > d[N] ; 
vector <int> G[N];
priority_queue <st> q ;
int n,m;
int main(){
    n=read();m=read() ;
    for (int i=1;i<=m;i++){
        int a,b,c ;
        a=read();b=read();c=read();a--;b-- ;
        E[a][c].push_back(b) ;E[b][c].push_back(a) ;
        G[a].push_back(c) ;G[b].push_back(c) ; 
    }
    d[0][0]=0;q.push({0,0,0}) ;
    while(!q.empty()){ //一波Dijkstra 
        st p=q.top();q.pop() ;
        if (d[p.p][p.b]!=p.c){
            continue ;
        }
        if (d[p.p].find(0)==d[p.p].end() || d[p.p][0]>p.c){
            d[p.p][0]=p.c ;
            q.push({p.p,0,p.c}) ;
        }
        if (p.b==0){
            for (int i=0;i<G[p.p].size();i++){
                int v=G[p.p][i] ;
                if (d[p.p].find(v)==d[p.p].end() || d[p.p][v]>p.c+1){
                    d[p.p][v]=p.c+1 ;
                    q.push({p.p,v,p.c+1}) ;
                 }
             }
            continue ; 
        }
        for (int i=0;i<E[p.p][p.b].size();i++){
            int v=E[p.p][p.b][i] ;
            if (d[v].find(p.b)==d[v].end() || d[v][p.b]>p.c){
                d[v][p.b]=p.c ;
                q.push({v,p.b,p.c}) ;
            }
        }
    }
    int ans=inf ;
    for (map<int,int>::iterator p=d[n-1].begin();p!=d[n-1].end();p++) ans=min(ans,p->second) ;
    if (ans==inf) printf("-1\n") ;
    else printf("%d\n",ans) ;
}

Measured memory_bytes: 84784
#include <bits/stdc++.h>
#define repz(i, z, n) for(decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for(decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(all(v)))
#define MIN(v) (*min_element(all(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

using namespace std;
void debug_out(){ cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
typedef pair<int,int> P;

typedef long long ll;
typedef unsigned long long ul;
// 1s間で可能なループ回数2E+8回
// intの最大値2147483647~2E+9
// long longの最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<> push_back
// 連想配列map<key,value> insert,
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// 大文字65-90(-32)
// 小文字97-122(+32)
// 1E+9 +7
const ll mod = 1000000000+7;
int main(){
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  map<int,P> A;
  vector<vector<bool>> isused(3,vector<bool>(3));
  
  rep(i,3){
    rep(j,3){
      int temp; cin >> temp;
      A[temp]=MP(j,i);
    }
  }
  int n; cin >> n;
  rep(i, n){
    int temp; cin >> temp;
    if(A.count(temp)>0) isused[A[temp].F][A[temp].S] = true;
  }
  // rep(i,3){
  //   rep(j,3){
  //     cout << isused[j][i];
  //   }
  //   cout << endl;
  // }
  bool isbreak = false;
  rep(i,3){
    isbreak = isbreak or (isused[0][i] and isused[1][i] and isused[2][i]);
    isbreak = isbreak or (isused[i][0] and isused[i][1] and isused[i][2]);
    isbreak = isbreak or (isused[0][0] and isused[1][1] and isused[2][2]);
    isbreak = isbreak or (isused[0][2] and isused[1][1] and isused[2][0]);
  }
  
  if(isbreak) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

ll N,x,y;
const ll mod=1e9+7;

inline ll qpow(ll a,ll b)
{
	ll ans=1,base=a;
	while(b)
	{
		if(b&1) ans=(ans*base)%mod;
		base=(base*base)%mod; b>>=1;
	}
	return ans;
}

inline ll C(ll n,ll m)
{
	ll ans=1;
	for(int i=n-m+1;i<=n;i++) ans=(ans*i)%mod;
	for(int i=1;i<=m;i++) ans=(ans*qpow(i,mod-2))%mod;
	return ans;
}

int main()
{
	cin>>N>>x>>y;
	ll tmp=qpow(2,N),p1=C(N,x),p2=C(N,y);
	tmp--; tmp-=p1; tmp-=p2;
	tmp=(tmp%mod)+mod; tmp%=mod;
	cout<<tmp<<endl;
	return 0;
}

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


main(){
  
  int n,i;
  char X[N],Y[N];
  
  
  
  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%s%s",X+1,Y+1);
    Lcs(X,Y);
  }

  return 0;
  
}
int Lcs(char *X,char *Y)
{
  
  int m,n,i,j;
  int Z[N][N];
  
  m = strlen(X+1);
  n = strlen(Y+1);

  for(i = 0; i <= m; i++){
    Z[i][0] = 0;
  }
  for(j = 0; j <= n; j++){
    Z[0][j] = 0;
  }
  
  for(i = 1; i <= m; i++){
    for(j = 1; j <= n; j++){
      
      if(X[i] == Y[j]){
	Z[i][j] = Z[i-1][j-1] +1;
      }
      else if(Z[i-1][j] >= Z[i][j-1]){
	Z[i][j] = Z[i-1][j];
      }
      else {
	Z[i][j] = Z[i][j-1];
      }
    }
  }
  
  
  printf("%d\n",Z[i-1][j-1]);
}

Measured memory_bytes: 4544
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,k;
int a[100005];
signed main(){
//	freopen("0_normal_1.txt","r",stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	int Xor=0;
	for(int i=40;i>=0;i--){
		if(Xor+(1ll<<i)>k)continue;
		int cnt0=0;
		for(int j=1;j<=n;j++)cnt0+=((a[j]&(1ll<<i))==0)?1:0;
		if(cnt0*2ll<n)continue;
		Xor+=(1ll<<i);
	}
	int ans=0;
	for(int i=1;i<=n;i++)ans+=a[i]^Xor;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<sstream>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define each(i, c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

int n, m[100], p[100][100], k, l[100];

int main(){
	while(cin >> n, n){
		rep(i, n){
			cin >> m[i];
			rep(j, m[i]) cin >> p[i][j];
		}
		cin >> k;
		rep(i, k) cin >> l[i];
		
		int ans = -2;
		rep(i, n){
			rep(j, k){
				bool ok = 0;
				rep(h, m[i]) if(l[j] == p[i][h]) ok = 1;
				if(!ok) goto FAIL;
			}
			if(ans == -2) ans = i + 1;
			else ans = -1;
			FAIL:;
		}
		if(ans < 0) ans = -1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.size = [1 for i in range(N)]
        self.components = n  # 連結成分の数

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
            self.size[y] = self.size[x] + self.size[y] 

    def same(self, x,y):
        return (self.root(x) == self.root(y))

N, M = map(int,input().split())

UF = UnionFind(N)
for _ in range(M):
    A, B = map(int,input().split())
    UF.unite(A-1, B-1)

print(max(UF.size))



Measured memory_bytes: 24716
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int a, b;
int main(){
	scanf("%d%d", &a, &b);
	if(a+b == 15){
		printf("+\n");
	}else if(a*b == 15){
		printf("*\n");
	}else{
		printf("x\n");
	}
	return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> col(10, 0);

    while (N--) {
        int a; cin >> a;
        col[min(8, a/400)]++;
    }
    int mi = 0;
    for (int i = 0; i <= 7; i++) {
        if (col[i] != 0) mi++;
    }
    cout << max(1, mi) << ' ' << mi + col[8] << endl;
}


Measured memory_bytes: 256
t=gets.to_i


t.times{
    
a,b,c,d=gets.split.map(&:to_i)   
 
if a<b
    puts "No"
    next
end

if b>d
     puts "No"
    next
end
    
if b<=c+1
    puts "Yes"
    next
end


first=(a-b)%b


if (d-b).gcd(b)==1
  puts "No"
    next
end



left=(c+1)%b
right=(b-1)%b

if right<left
    right+=b
end



gcd=b.gcd(d-b)


aa=(left-first)/gcd

bb=first+aa*gcd


if bb<left && bb+gcd>right
    puts "Yes"
    
else
    puts "No"
end
    
    
}


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

long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 1e6+100;
typedef long long int lld;
typedef long long ll;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); i--)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
 
 
#define popcount __builtin_popcountll
 
ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}

ll findGcd(ll a, ll b){
    while(a != 0) { ll temp = b % a; b = a; a = temp; }
    return b;
}

vector<ll> Adj[lim], Set, Query[lim];
ll Array[lim], BArray[lim], dp[lim];
map<ll,ll> M, InverseMap, Map;

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
    lld T,i,p,j,l,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,temp,countA=0,indicator=0,pos,h,minA,maxA,type,n,ans=0,left,right;
    string A,B,C;
    A = "Yes", B="No";
    // cin>>T;
    // rep(tt,1,T) {
    // }
    cin>>n; indicator=0;
    rep(i,1,n) {
        cin>>x>>y;
        if(x==y) Array[i]=1;
        else Array[i]=0;
        if(i>2 and Array[i]==1 and Array[i-1]==1 and Array[i-2]==1) indicator=1;
    }

    if(indicator) cout<<A<<endl;
    else cout<<B<<endl;
    return 0;
}


Measured memory_bytes: 50476
using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();

        Console.WriteLine(Math.Max(0, c - (a-b)));
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

int main()
{
    int ara[3],i,j,p;
    for(i=0; i<3; ++i){
        cin>>ara[i];
    }
    for(i=0; i<3; i++){
        for(j=i; j<3; j++){
            if(ara[i]>ara[j]){p=ara[i];ara[i]=ara[j];ara[j]=p;}
        }
    }
    cout<<ara[2]-ara[0];
    return 0;

}


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

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define array(N, t) (t*)calloc(N, sizeof(t))
#define ll long long
#define INF ((1LL << 62) - (1LL << 31))
#define max(p, q)((p) > (q) ? (p) : (q))
#define min(p, q)((p) < (q) ? (p) : (q))

char N[200010];
int main(){
  scanf("%s", N);
  int sum = 0;
  for (int i = 0; N[i] != '\0'; i++) sum += N[i] - '0';
  if (sum % 9 == 0) {
    puts("Yes");
  } else {
    puts("No");
  }
}


Measured memory_bytes: 1780
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
#include <utility>
#include <ctime>
#include <cstdlib>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end(

int main() {
	long n;
	cin >> n;
	long ans = 1;
	for (long i = 1; i <= n; i++) {
		ans *= i;
		ans %= 1000000007;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
connected_nodes = defaultdict(lambda: {})

for _ in range(n-1):
  a, b = map(int, input().split())
  if a > b:
    a, b = b, a
  connected_nodes[a-1][b-1] = True
  connected_nodes[b-1][a-1] = True

cs = list(map(int, input().split()))

if n == 1:
  print(0)
  print(1)
  exit(0)
if n == 2:
  print(min(edges[0]))
  print('1 2')
  exit(0)

# n >= 3

cs = sorted(cs)
answer_sum = sum(cs) - cs[-1]

visiting = [0]
number_map = {}
number_map[0] = cs.pop()

while True:
  if len(number_map.keys()) == n:
    break
  node = visiting.pop()
  #print(f'now in {node}')
  #print(f'look for {connected_nodes[node]}')
  to_search = list(connected_nodes[node].keys())
  for neighbor in to_search:
    if neighbor in number_map:
      continue
    #print(f'look for {neighbor} from {node}')
    number_map[neighbor] = cs.pop()
    connected_nodes[node].pop(neighbor)
    connected_nodes[neighbor].pop(node)
    visiting.append(neighbor)


print(answer_sum)
print(' '.join([str(number_map[k]) for k in sorted(number_map.keys())]))


Measured memory_bytes: 9420
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

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

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int N;
    cin >> N;
    string answer = "ABC";
    cout << answer << N << endl;
    return 0;
}


Measured memory_bytes: 256
def comb(sum)
  ans=[]
  a=sum/200
  b=sum/300
  c=sum/500
  for i in 0.. a
    for j in 0.. b
      for k in 0.. c
        if 200*i+300*j+500*k == sum
          ans.push([i,j,k])
        end
      end
    end
  end
  return ans
end

def price(c)
  ans=0
  price=100000000
  p = [[1520,1870,2244],[380,550,850]]
  for i in 0.. c.length-1
    tp=0
    for j in 0.. 2
      t = c[i][j]/(5-j)
      tp += t*p[0][j]+(c[i][j]-t*(5-j))*p[1][j]
    end
    if tp<price
      price = tp
      ans = i
    end
  end
  puts price
end


while true
  g=gets.to_i
  if g==0 then break end
  price(comb(g))
end

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


//      DEEP


using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fwd(i,a,n) for(int i=a;i<=n;i++)
#define bak(i,a,n) for(int i=a;i>=n;i--)
#define all(v) v.begin(),v.end()
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef set<int> si;
const ll mod = 1e9 + 7;
ll power(ll x,ll y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}
ull gcd(ull x,ull y){
   if(y==0)return x;
   return gcd(y,x%y);
}
int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)cout<<k<<endl;
    else if(k>a && k<=a+b)cout<<a<<endl;
    else if(k>a+b && k<=a+b+c)cout<<a-(k-(a+b))<<endl;
    else cout<<a-c<<endl;
}









Measured memory_bytes: 3632
import numpy as np
import itertools

l=list(map(int,input()))

for item in list(itertools.product((1,-1),repeat=3)):
  if l[0]+np.dot(item,l[1:])==7:
    break
olist=["+" if o==1 else "-" for o in item]

result = [None]*(len(l)+len(olist))
result[::2] = list(map(str,l))
result[1::2] = olist
print("".join(result)+"=7")

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

bool c[5];
int main(){
    int a[3],b[3];
    for(int i=0;i<3;i++){
        cin>>a[i]>>b[i];
    }
    c[a[0]]=true;
    c[b[0]]=true;
    if(a[1]==b[0]){
        c[a[1]]=true;
        c[b[1]]=true;
        if(a[2]==b[1]){
            c[b[2]]=true;
        }
        else if(b[2]==b[1]){
            c[a[2]]=true;
        }
    }
    else if(b[1]==b[0]){
        c[a[1]]=true;
        c[b[1]]=true;
        if(a[2]==a[1]){
            c[b[2]]=true;
        }
        else if(b[2]==a[1]){
            c[a[2]]=true;
        }
    }
    else if(a[2]==b[0]){
        c[a[2]]=true;
        c[b[2]]=true;
        if(a[1]==b[2]){
            c[b[1]]=true;
        }
        else if(b[1]==b[2]){
            c[a[1]]=true;
        }
    }
    else if(b[2]==b[0]){
        c[a[2]]=true;
        c[b[2]]=true;
        if(a[1]==a[2]){
            c[b[1]]=true;
        }
        else if(b[1]==a[2]){
            c[a[1]]=true;
        }
    }
    if(a[1]==a[0]){
        c[a[1]]=true;
        c[b[1]]=true;
        if(a[2]==b[1]){
            c[b[2]]=true;
        }
        else if(b[2]==b[1]){
            c[a[2]]=true;
        }
    }
    else if(b[1]==a[0]){
        c[a[1]]=true;
        c[b[1]]=true;
        if(a[2]==a[1]){
            c[b[2]]=true;
        }
        else if(b[2]==a[1]){
            c[a[2]]=true;
        }
    }
    else if(a[2]==a[0]){
        c[a[2]]=true;
        c[b[2]]=true;
        if(a[1]==b[2]){
            c[b[1]]=true;
        }
        else if(b[1]==b[2]){
            c[a[1]]=true;
        }
    }
    else if(b[2]==a[0]){
        c[a[2]]=true;
        c[b[2]]=true;
        if(a[1]==a[2]){
            c[b[1]]=true;
        }
        else if(b[1]==a[2]){
            c[a[1]]=true;
        }
    }
    
    if(c[1]&&c[2]&&c[3]&&c[4]) cout<<"YES"<<endl;
    else  cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a;
    cin >> a;
    cout << 3 * a * a;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    int n;
    string s;
    cin>>n>>s;
    int rcnt = 0;
    int lcnt = 0;
    rep(i,0,n-1){
        if(s[i]=='(')++rcnt;
        else --rcnt;
        rcnt = max(rcnt, 0);
    }
    for(int i = n-1; i >= 0; --i){
        if(s[i]==')')++lcnt;
        else --lcnt;
        lcnt = max(lcnt, 0);
    }
    rep(i,1,lcnt)cout<<'(';
    cout<<s;
    rep(i,1,rcnt)cout<<')';
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 998244353
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type* arr = new type[n];
#define forn(i, n) for (int i = 1; i <= n; i++)
#define me0(x) memset(x, 0, sizeof(x))
#define me1(x) memset(x, -1, sizeof(x))
#define tests(x) \
    int x;       \
    cin >> x;    \
    while (x--)
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 2e5 + 2;
void run() {
    ios_base::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 n;
double p[3003], dp[3003][3003];

void solve() {
    cin >> n;
    forn(i, n) cin >> p[i];
    dp[1][0] = 1 - p[1];
    dp[1][1] = p[1];
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
        }
    }
    int heads = n / 2 + 1;
    double ans = 0;
    for (int i = heads; i <= n; i++) {
        ans += dp[n][i];
    }
    cout<< ps(ans,10);
}
int32_t main() {
    //run();
	solve();
    return 0;
}

Measured memory_bytes: 68992
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define debug puts
#define setp cout << fixed << setprecision(15)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
const int N=3e5+5;
const int MOD=998244353;
ll F[N], Finv[N], inv[N];//F是阶乘，Finv是逆元的阶乘
void init(){
    inv[1] = 1;
    for(int i = 2; i < N; i ++){
        inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD;
    }
    F[0] = Finv[0] = 1;
    for(int i = 1; i < N; i ++){
        F[i] = F[i-1] * 1ll * i % MOD;
        Finv[i] = Finv[i-1] * 1ll * inv[i] % MOD;
    }
}
ll c(int n, int m){//comb(n, m)就是C(n, m)
    if(m < 0 || m > n) return 0;
    return F[n] * 1ll * Finv[n - m] % MOD * Finv[m] % MOD;
}

int main(void){
    FAST_IO;
    init();
    ll n,a,b,k;
    cin >>n>>a>>b>>k;
    /// ax+by==k; x(0,n);
    ll ans=0;
    for(int x=0;x<=n;x++){
        if((k-a*x)%b==0){
            ll y=(k-a*x)/b;
//            cout << "~"<<c(n,x)<<endl;
//            cout << "~"<<c(n,y)<<endl;
            ans=(ans+c(n,x)%MOD*c(n,y))%MOD;
        }
    }
    cout << ans<< endl;
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int 
#define pb push_back
#define xx first
#define yy second
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll t;
	t=1;
	while(t--)
	{
		string a,b;
		cin>>a>>b;
		
		ll i,na=a.size(),nb=b.size();
		ll ans=nb;
		for(i=0;i<=na-nb;i++)
		{
		        ll j,k,cnt=0;
		        for(j=i,k=0;k<nb;k++,j++)
		        {
		            if(a[j]!=b[k])
		                cnt++;
		        }
		        ans=min(ans,cnt);
		}
		cout<<ans;
	}
}

Measured memory_bytes: 3628
//Moh_K_Imar .......
//28/08/2020  ... 11,30.
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll x=a+b; ll y=a+c; ll z=b+c;
    ll v=min(x,y);
    cout<<min(v,z)<<endl;

    return 0;
}



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

int main(){
  int a,b;
  cin >> a >> b;
  if(a == 1) a += 13;
  if(b == 1) b += 13; 
  if(a == b) puts("Draw");
  if(a > b) puts("Alice");
  if(a < b) puts("Bob");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,x,y) for(int i=(int)x;i<=(int)y;i++)
#define PER(i,x,y) for(int i=(int)x;i>=(int)y;i--)
#define FOR(i,x,y) for(int i=(int)x;i< (int)y;i++)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long LL;
typedef long double db;
typedef pair<int,int> PII;
const   int N=200005;
const   int P=1e9+7;

char s[N];
int sum[N],n,dp[N],Mn[1<<26];

void chkmin(int &x,int y){
	if(y<x) x=y;
}

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	memset(Mn,0x3f,sizeof Mn);
	memset(dp,0x3f,sizeof dp);
	dp[0]=0;
	Mn[0]=0;
	REP(i,1,n){
		sum[i]=sum[i-1];
		sum[i]^=1<<(s[i]-'a');
	}
	
	REP(i,1,n){
		dp[i]=min(dp[i],Mn[sum[i]]+1);
		FOR(j,0,26) dp[i]=min(dp[i],Mn[sum[i]^(1<<j)]+1);
		chkmin(Mn[sum[i]],dp[i]);
	}
	
	printf("%d\n",dp[n]);
    return 0;
}

Measured memory_bytes: 264192
import queue

n=int(input())

A=list(map(int,input().split()))

A.sort(reverse=True)

q=queue.Queue()

q.put(A[0])

ans=0
for i in range(1,n):
    ans+=q.get()
    q.put(A[i])
    q.put(A[i])

print(ans)

Measured memory_bytes: 31912
#include <bits/stdc++.h>
using namespace std;
int main() {
	double n,m,s;
	while(cin>>n>>m>>s,n){
		int ans=0;
		n+=100;
		m+=100;
		for(int i=1;i<1000;i++){
			for(int j=1,x,y;j<1000;j++){
				x=i*n/100;
				y=j*n/100;
				if(x+y==s){
					x=i*m/100;
					y=j*m/100;
					ans=max(ans,x+y);
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int N=2e5+20;
const int M=30;
struct Union_find{
	Union_find(int n){par.resize(n);for(int i=0;i<n;i++) par[i]=i;}
	int find(int x){return (par[x]==x)?x:par[x]=find(par[x]);}
	void unite(int a,int b){a=find(a),b=find(b);par[a]=b;}
	bool same(int a,int b){return find(a)==find(b);}
	vector<int> par;
};
int main()
{
	int n,k,l;
	cin>>n>>k>>l;
	Union_find uf1(n);
	for(int i=0;i<k;i++)
	{
		int u,v;
		cin>>u>>v;
		uf1.unite(u-1,v-1);//vector par[i]从0开始标号 
	}
	
	Union_find uf2(n);
	for(int i=0;i<l;i++)
	{
		int p,q;
		cin>>p>>q;
		uf2.unite(p-1,q-1);
	}
 
 
	map<P,int> mp;
	for(int i=0;i<n;i++)
	{
		mp[make_pair(uf1.find(i),uf2.find(i))]++;
	}
	for(int i=0;i<n;i++)
	{
		cout<<mp[make_pair(uf1.find(i),uf2.find(i))]; 
		if(i==n-1)
		cout<<endl;
		else
		cout<<' ';
	}
	return 0;
} 

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt=0,len,k;
ll ans;
void dfs(int x,ll i){
    if(len==x) {cnt++;if(cnt==k) {ans=i;}i/=10;return;}
    ll u=i%10;
    for(ll j=u-1;j<=u+1;j++){
        if(j<0 || j>9) continue;
        else{
            len++;
            dfs(x,i*10+j);
            len--;
        }
    }
}

int main(){
    cin>>k;
    for(int j=1;j<=10;j++){
        for(ll i=1;i<=9;i++){
            len=1;
            dfs(j,i);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N, i, t;  
  scanf("%d", &N);
  for (i=3; i<=N; i++) {
    if (i % 3 == 0) {
      printf(" %d", i);
    } else {
      t = i;
      while (t > 0) {
        if (t % 10 == 3) {
          printf(" %d", i);
          break;
        } else {
          t /= 10;
        }
      }
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600