akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range1(i,a,b,c) for(int i = int(a);i <= int(b);i+=int(c))
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define sz(v) ((int)((v).size()))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int a[3];
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    int c1,c2;
    c1=c2=0;
    lp(i,3){
        if(a[i]==5)c1++;
        else if(a[i]==7)c2++;
    }
    if(c1==2&&c2==1)puts("YES");
    else puts("NO");
    
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
 
#define fto(i, x, y) for(auto i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(auto i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(auto i = (x); i <= (y); i += a)
#define ftoit(it, var) for (auto it = var.begin(); it != var.end(); ++it)
 
#define ii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
 
#define vi vector<int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>
 
#define eb emplace_back
#define ef emplace_front
#define lb lower_bound
#define ub upper_bound
 
#define oo 1000000007
#define OO 1000000000000000007LL
 
using namespace std;
 
#define Pro "tmp"
#define maxN 1000007

map <int, int> cnt;
int a[maxN];

int main() {
    int n;
    scanf("%d", &n);

    fto(i, 1, n) scanf("%d", &a[i]);

    set <int> st;
    fto(i, 1, n) {
        st.insert(a[i]);
        ++cnt[a[i]];
    }

    if (st.size() > 3) {
        puts("No");
        return 0;
    }

    if (st.size() == 1) {
        if (*st.begin() == 0) {
            puts("Yes");
            return 0;
        }
        else {
            puts("No");
            return 0;
        }
    }

    if (n%3) {
        puts("No");
        return 0;
    }

    if (st.size() == 2) {
        if (*st.begin() == 0) {
            if (cnt[0] == n/3) puts("Yes");
            else puts("No");
            return 0;
        }
        else {
            puts("No");
            return 0;
        }
    }

    if (st.size() == 3) {
        int a = *st.begin();
        int b = *(++st.begin());
        int c = *(++++st.begin());
        if ((a^b) == c && (a^c) == b && (b^c) == a && cnt[a] == n/3 && cnt[b] == n/3 && cnt[c] == n/3) puts("Yes");
        else puts("No");
        return 0;
    }

    puts("No");
    return 0;
} 

Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

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

int main() {
    ll L, R; cin >> L >> R;

    ll res = 2018;

    for (ll i = L; i <= L + 5000LL && i <= R; ++i) {
        for (ll j = i+1; j <= L + 5000LL && j <= R; ++j) {
            res = min(res, (i%2019)*(j%2019)%2019);
        }
    }
    cout << res << endl;
}


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

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 1e5+5;

int n,q,a[N],b[N];
string s;



int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>q;
    cin>>s;

    for(int i=1;i<=n;i++){
        if(s[i-1]=='A'&&s[i]=='C')a[i]=a[i-1]+1,b[i]=1;
        else a[i]=a[i-1];
    }

    while(q--){
        int l,r;
        cin>>l>>r;

        int ans=a[r]-a[l-1];
        if(b[r])ans--;

        cout<<ans<<"\n";
    }

    return 0;
}


Measured memory_bytes: 1872
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for (int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define EB emplace_back
#define FORE(a, b) for (auto &&a:b)
#define FIND(s, n) (s.find(n) != s.end())

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;

void func2(PII ta, LL &t, LL &a) {
    LL mint = t, mina = a;
    LL tt, aa, ttt, aaa;
    tie(ttt, aaa) = ta;
    while (mint > tt || mina > aa) {
        tt += ttt; aa += aaa;
    }
    t = tt; a = aa;
}

void func3(PII ta, LL &t, LL &a) {
    LL mint = t, mina = a;
    LL tt, aa, ttt, aaa;
    tie(ttt, aaa) = ta;
    LL kake = max(mina / aaa, mint / ttt);
    bool f = (mina % aaa) || (mint % ttt);
    tt = ttt * (kake);
    aa = aaa * (kake);
    if (tt < mint || aa < mina) {
        tt += ttt;
        aa += aaa;
    }
    t = tt; a = aa;
}

int main(void) {
    LL N; cin >> N;
    VPII ta(N);
    REP(i, N) {
        int t, a;
        scanf("%d%d", &t, &a);
        ta[i] = MP(t, a);
    }
    LL t, a;
    tie(t, a) = ta[0];
    FOR(i, 1, N) {
        //cerr << t << " " << a << endl;
        if (ta[i].first >= t && ta[i].second >= a) {
            tie(t, a) = ta[i];
        } else if (ta[i] == MP(1, 1)) {
            t = max(t, a);
            a = t;
        } else {
            func3(ta[i], t, a);
        }
    }
    cout << t + a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <sstream>
#include <numeric>
#include <stack>
#include <sstream>
#include <set>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int64_t n,m ;
    cin >> n >> m ;
    vector<int> x(m) ;
    for (size_t i = 0; i < m; i++)
    {
        cin >> x.at(i) ;
    }
    if (m == 1 || n >= m)
    {
        cout << 0 << endl ;
        return 0 ;
    }
    sort(x.begin(),x.end()) ;
    vector<int> d(m-1) ;
    for (size_t i = 0; i < m-1; i++)
    {
        d.at(i) = x.at(i+1) - x.at(i) ;
    }
    sort(d.begin(),d.end());
    int64_t ans = 0 ;
    for (size_t i = 0; i < n-1; i++)
    {
        d.pop_back() ;
    }
    ans = accumulate(d.begin(),d.end(),0) ;
    cout << ans << endl ;
    
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
    using namespace std;
    # define ll long long int
    vector<int>graph[200005];
    

    int main(){
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        string s,t;
        cin>>s>>t;
        int count=0;
        for(int i=0;i<s.size();i++){
            if(s[i]!=t[i])
                count++;
        }
        cout<<count<<endl;

    }

Measured memory_bytes: 8472
/*
  AOJ 2547
  Title:Carpet
  @kankichi573
*/
#include <stdio.h>
int N,a,stack[200000],sp;

main()
{
  int i;
  int ret;

  scanf("%d",&N);
  ret=1;sp=0;
  scanf("%d",&stack[0]);
  for(i=1;i<N;i++)
    {
      scanf("%d",&a);
      if(a > stack[sp])
	{
	  stack[++sp]=a;
	  ret++;
	}
      if(a < stack[sp])
	{
	  while(sp>=0 && a < stack[sp])
	    sp--;
	  if(a > stack[sp])
	    {
	      stack[++sp]=a;
	      ret++;
	    }
	}
    }
  printf("%d\n",ret);
  return(0);
}

Measured memory_bytes: 1376
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    char[] S = sc.next().toCharArray();
    boolean isBeauty = true;
    for(int i=0; i<S.length; i++){
      if(i%2 == 0 && S[i] == 'L'){
        isBeauty = false;
        break;
      }else if(i%2 !=0 && S[i] =='R'){
        isBeauty = false;
        break;
      }
    }
    if(isBeauty){
      System.out.print("Yes");
    }else{
      System.out.print("No");
    }
  }
}

Measured memory_bytes: 24020
#include <stdio.h>

int main(void) {
  long n,sum=0,i;
  scanf("%ld",&n);
  for(i=1;i<n+1;i++){
    if(i%3!=0&&i%5!=0){
      sum=sum+i;
    }
  }
  printf("%ld",sum);
  return 0;
}

Measured memory_bytes: 1700
#include <stdio.h>

int main(void)
{
  int scrA[4];
  int scrB[4];
  int sumA,sumB;

  scanf("%d %d %d %d", &scrA[0], &scrA[1], &scrA[2], &scrA[3]);
  scanf("%d %d %d %d", &scrB[0], &scrB[1], &scrB[2], &scrB[3]);

  sumA=scrA[0]+scrA[1]+scrA[2]+scrA[3];
  sumB=scrB[0]+scrB[1]+scrB[2]+scrB[3];

  if(sumA>=sumB) printf("%d\n", sumA);
  if(sumA<sumB) printf("%d\n", sumB);

  return 0;
}


Measured memory_bytes: 592
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	n, c, k := scanInt(sc), scanInt(sc), scanInt(sc)
	ts := nextIntSlice(sc, n)
	fmt.Println(resolve(n, c, k, ts))
}

func resolve(n, c, k int, ts []int) int {
	sort.Sort(sort.IntSlice(ts))
	var idx, trackNum int

	limit := ts[0] + k
	idx, sum := 0, 1
	for i := 1; i < len(ts); i++ {
		if sum == c {
			sum = 0
			trackNum++
			idx += c
			limit = ts[idx] + k
		} else if limit < ts[i] {
			sum = 0
			trackNum++
			idx = i
			limit = ts[idx] + k
		}
		sum++
	}
	trackNum += (sum + c - 1) / c
	return trackNum
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// package: gocom
// packed src of [/Users/masumi/dev/src/github.com/masu-mi/gamemo/lib/gocom/next.go] with goone.

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 4288
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm];
int main()
{
   ll n,m,i,j,t,a,b,c,p,k,kk; 
   cin>>n>>k;
   for(i=0;i<n;i++)
   cin>>d[i];
   sort(d,d+n);
   ll s=0;
   for(i=0;i<k;i++)
   s+=d[i];
   cout<<s<<endl;
	  
	 
} 

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()



//library mod int
template <int mod>
struct modint{
    ll x;

    //constructor
    modint(ll x=0): x((x%mod+mod)%mod){}

    //unary operator
    modint operator-() const { return modint(mod-x);}
    modint inv() const { return this->pow(mod-2);}
    

    //compound assignment
    modint& operator+=(const modint& a){
        if((x+=a.x)>=mod) x-=mod;
        return *this;
    }
    modint& operator-=(const modint& a){
        if((x-=a.x)<0) x+=mod;
        return *this;
    }
    modint& operator*=(const modint& a){
        (x*=a.x)%=mod;
        return *this;
    }
    modint& operator/=(const modint& a){
        return *this *= a.inv();
    }

    //arithmetic
    modint operator-(const modint a) const {return modint (*this) -= a ; }
    modint operator+(const modint a) const {return modint (*this) += a ; }
    modint operator*(const modint a) const {return modint (*this) *= a ; }
    modint operator/(const modint a) const {return modint (*this) /= a ; }
    //n should not be smaller than 0.
    modint pow(ll n) const{
        auto x=modint(1);
        auto m=*this;
        while(n>0){
            if(n&1) x*=m;
            n>>=1;
            m*=m;
        }
        return x;
    }

    //compare
    bool operator==(const modint& a) const {return x==a.x ; }
    bool operator!=(const modint& a) const {return x!=a.x ; }

    //I/O
    friend istream& operator>>(istream& is, modint& a ) noexcept {return is >> a.x ; }
    friend ostream& operator<<(ostream& os, const modint& a ) noexcept {return os << a.x ; }

};

//modの調整
constexpr int mod = 1e9 + 7;
using mint = modint<mod>;






mint comb(int n, int r){
    r=min(r,n-r);
    mint ans=1;
    rep(i,r){
        ans*=(n-i);
        ans*=(mint(i+1).inv());
    }
    return ans;
}


int main(){
    int n,a,b;
    cin>>n>>a>>b;
    mint ans=mint(2).pow(n)-1;
    ans-=comb(n,a);
    ans-=comb(n,b);
    cout<<ans<<endl;
    return 0;
}

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

int func(int U, int D){
    double res = (double)U / D;
    return floor(res + 0.5);
}
    

int main(){
    int N;
    cin >> N;
    int sum = 0;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum += A[i];
    }
    int ave = func(sum, N);
    int ans = 0;
    
    for(int i = 0; i < N; i++)ans += (ave - A[i]) * (ave - A[i]);
    
    cout << ans << endl;
}

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

int main()
{
    int n;
    char a[8][10], b[8][5];
    for( int i = 0; i < 8; i++ )
        for( int j = 0; j < 10; j++ )
            a[i][j] = '*';

    for( int i = 0; i < 8; i++ )
        for( int j = 0; j < 10; j++ )
        {
            a[2][j] = '=';
            if( j / 5 == 1 )
                a[0][j] = ' ';
            else
                a[1][j] = ' ';
        }

    for( int i = 3; i < 8; i++ )
    {
        a[i][i-3] = ' ';
        a[i][i+2] = ' ';
    }

    bool judge = false;
    while( cin >> n )
    {
        if( judge )
            cout << endl;

        int c = 5;
        while( c-- )
        {
            for( int i = 0; i < 8; i++ )
                b[i][c] = a[i][n%10];
            n /= 10;
        }
        for( int i = 0; i < 8; i++ )
        {
            for( int j = 0; j < 5; j++ )
                cout << b[i][j];
            cout << endl;
        }
        judge = true;
    }
    return 0;
}



Measured memory_bytes: 3084
#include "iostream"

using namespace std;

int main() {
	int N;
	int a = 0;
	int b;

	scanf("%d", &N);
	b = N;

	while (b > 0) {
		a += b % 10;
		b /= 10;
	}

	if (N % a == 0)
		printf("Yes");
	else
		printf("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int N,M,Q;
vector<vector<ll>> Alist;
int main(){
  cin>>N>>M>>Q;
  Alist.resize(Q,vector<ll>(4));
  for(ll i=0;i<Q;i++){
    cin>>Alist.at(i).at(0)>>Alist.at(i).at(1)>>Alist.at(i).at(2)>>Alist.at(i).at(3);
  }
  ll maximum=0;
  vector<ll> vec(N);
  int count;
  ll maxforpairs;
  for(int a=0;a<M;a++){
    for(int b=a;b<M;b++){
      for(int c=b;c<M;c++){
        for(int d=c;d<M;d++){
          for(int e=d;e<M;e++){
            for(int f=e;f<M;f++){
              for(int g=f;g<M;g++){
                for(int h=g;h<M;h++){
                  for(int i=h;i<M;i++){
                    for(int j=i;j<M;j++){
                      count=0;
                      maxforpairs=0;
                      if(count<N){count++;vec.at(count-1)=a;}
                      if(count<N){count++;vec.at(count-1)=b;}
                      if(count<N){count++;vec.at(count-1)=c;}
                      if(count<N){count++;vec.at(count-1)=d;}
                      if(count<N){count++;vec.at(count-1)=e;}
                      if(count<N){count++;vec.at(count-1)=f;}
                      if(count<N){count++;vec.at(count-1)=g;}
                      if(count<N){count++;vec.at(count-1)=h;}
                      if(count<N){count++;vec.at(count-1)=i;}
                      if(count<N){count++;vec.at(count-1)=j;}
                      for(ll k=0;k<Q;k++){
                        if(vec.at(Alist.at(k).at(1)-1)-vec.at(Alist.at(k).at(0)-1)==Alist.at(k).at(2)){maxforpairs+=Alist.at(k).at(3);}
                      }
                      maximum=max(maximum,maxforpairs);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout<<maximum<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int a[m],sum=0;
	for(int i=0;i<m;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n)
	cout<<-1<<endl;
	else
	cout<<n-sum<<endl;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES

#include <iostream>
#include <math.h> 
#include <vector>
#include <algorithm>
#include <iomanip>      // std::setprecision
#include <map>
#include <unordered_map>
#include <string>
#include <set>
#include <unordered_set>

using namespace std;

int main()
{
	int N;
	std::cin >> N;
	int state = 0;
	int sol = 0;
	for (int i = 0; i < N; i++)
	{
		char input;
		std::cin >> input;
		switch (input)
		{
		case 'A':
			state = 1;
			break;
		case 'B':
			if (state == 1)
			{
				state = 2;
			}
			else
			{
				state = 0;
			}
			break;
		case 'C':
			if (state == 2)
			{
				sol++;
			}
			state = 0;
			break;
		default:
			state = 0;
			break;
		}
	}
	std::cout << sol << std::endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(readline())
a = list(map(int, read().split()))
ans = 0
cnt = 1
for a_ in a:
    if a_ == cnt:
        cnt += 1
    else:
        ans += 1


print(ans if ans != n else -1)


Measured memory_bytes: 21960
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
 
void solve(){
    int n;
    cin >> n;
    vector <int> a(n);
    ll ans = 0;
    for(int &x : a)
        cin >> x;
    int mx = a[0];
    for(int i = 1; i < n; ++i){
        mx = max(mx, a[i]);
        ans += mx - a[i];
    }
    cout << ans;
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

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

int main(void){
    multiset<int> mlS;
    multiset<int>::iterator begin, end;
    int q;
    cin >> q;

    for(int i=0; i<q; i++){
        int cmd;
        cin >> cmd;
        if(cmd==0){
            int x;
            cin >> x;
            mlS.insert(x);
            cout << mlS.size() << "\n";
        }
        else if(cmd==1){
            int x;
            cin >> x;
            cout << mlS.count(x) << "\n";
        }
        else if(cmd==2){
            int x;
            cin >> x;
            mlS.erase(x);
        }
        else if(cmd==3){
            int L,R;
            cin >> L >> R;
            begin = mlS.lower_bound(L);
            end = mlS.upper_bound(R);
            for(; begin!=end; begin++){
                cout << *begin << "\n";
            }
        }
    }
    return 0;
}


Measured memory_bytes: 12264
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
// #define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }
  void solve()
  {
int n;
cin>>n;
vector<pi64> v(n);
i64 mx=INT_MIN,mn=INT_MAX,mn1=INT_MAX,mx1=INT_MIN;
forn(i,n)
{
	cin>>v[i].fi>>v[i].se;
mx=max(mx,v[i].fi+v[i].se);
mn=min(mn,v[i].fi+v[i].se);
mx1=max(mx1,v[i].fi-v[i].se);
mn1=min(mn1,v[i].fi-v[i].se);
}
// cout<<mx1<<" "<<mx1<<" ";


cout<<max(abs(mn-mx),abs(mn1-mx1));
  }
  
  int main()
  {
ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
    #endif
int t=1;
while(t--)
{
  solve();
}

    return 0;
  }


Measured memory_bytes: 6356
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;
#define ASCII 48
int main() {
	int n;
	cin >> n;
	
	int digit = 2;
	int total = 0;
	while (true) {
		if (digit % 2 == 0) {	//　奇数桁計算
			total += (int)pow(10, digit - 1) - (int)pow(10, digit - 2);
		}
		digit++;
		if (pow(10, digit - 2) > n)break;
	}
	if (digit % 2 == 1 && digit >= 3) {
		total -= (pow(10, digit - 2) - n) - 1;
	}
	
	cout << total << endl;

	return 0;
}


Measured memory_bytes: 256
# coding: utf-8

def beki(num:int):
    if num == 1:
        return [1]
    ans = [1]
    for i in range(2, num + 1):
        for j in range(2, num+1):
            tmp = pow(i,j)
            if tmp > num:
                break
            ans.append(tmp)
    return set(ans)

n = int(input().rstrip())
beki_list = beki(n)
print(max(beki_list))


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;

namespace oasobi
{
    static class MainClass
    {
        public static void Main()
        {
            var list = new List<int> { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

            int K = int.Parse(Console.ReadLine());

            int k = K - 1;

            Console.WriteLine(list[k]);
        }
    }
}

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

string T="MARCH";
string S;
ll N,C[5],ans;

int main(void){
    cin >> N;
    rep(i,N){
        cin >> S;
        rep(i,5)if(T[i] == S[0])C[i]++;        
    }
    
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++)    ans+=C[i]*C[j]*C[k];

        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 9000000000000000000 //9e18:極めて大きい値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define LOGMAXR 18 // floor(log2(10^5)) + 1: 配列の最大のrangeのlog
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素

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


Measured memory_bytes: 3164
N, *A = map(int, open(0).read().split())

x = sorted([(a, p) for p, a in enumerate(A)], reverse=True)
dp = [[0] * (N + 1) for _ in range(N + 1)]
for i, (a, p) in enumerate(x):
    for j in range(i + 1):
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + a * (p - j))
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a * (N - (i - j) - 1 - p))
        
print(max(dp[-1]))


Measured memory_bytes: 95932
n, k = input().split()
n = int(n)
k = int(k)
listnum = input().split()
newlist = []
sumnum = 0

listnum = [int(n) for n in listnum]
newlist = sorted(listnum)
for b in range(k):
    sumnum = sumnum + newlist[b]
print(sumnum)

Measured memory_bytes: 9196
import scala.io.StdIn.{readInt,readLine}

object Main extends App {
  println {
    Iterator.continually(readInt).takeWhile(_ != 0).map { n =>
      var max = (0,0)
      for(i<-1 to n) {
        val e = readLine.split(" ").map(_.toInt)
        val sum = e(1)+e(2)
        if(sum > max._2)
          max = (e(0),sum)
      }
      max._1 + " " + max._2
    }.mkString("\n")
  }
}

Measured memory_bytes: 155976
N = int(input())
dp = [0]*(N+1)
money = [1]
p = 1
while p <= N:
    p = p*6
    money.append(p)
p = 1
while p <= N:
    p = p*9
    money.append(p)
lenM = len(money)

for i in range(1,N+1):
    L = [dp[i - money[j]] + 1 for j in range(lenM) if i - money[j] >= 0]
    dp[i] = min(L)

print(dp[N])

Measured memory_bytes: 3828
import math
a,b=input().split()
c=int(a)
d1=100*c*int(b[0])
d2=10*c*int(b[2])
d3=1*c*int(b[3])
ds=d1+d2+d3
if ds<100:
  print(0)
else:
  print(str(ds)[:-2])
   


Measured memory_bytes: 8984
import java.util.*;

public class Main {

  public static int INF = 10000000;
  public static int H;
  public static int W;
  public static String[][] maze;
  public static int[][] d;
  public static int[] dx = {1, 0, -1, 0};
  public static int[] dy = {0, 1, 0, -1};

  public static class P {
    public int first;
    public int second;
    public P (int first, int second) {
      this.first = first;
      this.second = second;
    }
  }

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    H = sc.nextInt();
    W = sc.nextInt();

    maze = new String[H][W];

    for (int i = 0; i < H; i++) {
      String s_ = sc.next();
      maze[i] = s_.split("");
    }

    sc.close();

    d = new int[H][W];

    for (int i = 0; i < H; i++) {
      Arrays.fill(d[i], INF);
    }

    int result = bfs() + 1;

    int countBlack = 0;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (maze[i][j].equals("#")) {
          countBlack++;
        }
      }
    }

    if (d[H-1][W-1] == INF) {
      System.out.println(-1);
    } else {
      System.out.println(H*W - countBlack - result);
    }
  }

  public static int bfs() {

    Queue<P> que = new ArrayDeque<>();

    que.add(new P(0, 0));
    d[0][0] = 0;

    while (!que.isEmpty()) {
      
      P p = que.poll();
      
      if ((p.first == H - 1) && (p.second == W - 1)) {
        break;
      }

      for (int i = 0; i < 4; i++) {
        
        int nFirst = p.first + dx[i];
        int nSecond = p.second + dy[i];

        if (0 <= nFirst && nFirst < H && 0 <= nSecond && nSecond < W && !(maze[nFirst][nSecond].equals("#")) && d[nFirst][nSecond] == INF) {
          que.add(new P(nFirst, nSecond));
          d[nFirst][nSecond] = d[p.first][p.second] + 1;
        }

      }

    }

    return d[H-1][W-1];

  }

}

Measured memory_bytes: 23380
n = gets.to_i

answer = Array.new(n,0)

def func3(x,y,z)
  if x==y && y==z
    1
  elsif x==y || y==z || z==x
    3
  else
    6
  end
end

1.upto(n) do |x|
  break if (x**2+1**2+1**2+x*1+1*1+1*x) > n
  x.upto(n) do |y|
    break if (x**2+y**2+1**2+x*y+y*1+1*x) > n
    y.upto(n) do |z|
      if (x**2+y**2+z**2+x*y+y*z+z*x) > n
        break
      end
      answer[(x**2+y**2+z**2+x*y+y*z+z*x)-1]+=func3(x,y,z)
    end
  end
end

answer.each do |a|
  puts a
end


Measured memory_bytes: 14220
#include<bits/stdc++.h>
#define int long long int
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define inf 10000000000001
#define all(x) (x).begin(),(x).end()
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(auto i=s;i<n;i++)
#define rloop(i,n,b) for(auto i=n-1;i>=b;i--)
using namespace std;
	
signed main()
{
	fastio(0);
	int n;
	cin>>n;
	int a[n];
	loop(i,0,n) cin>>a[i];
	
	int dp[n][n],prefix[n+1];
	init(dp,0);
	init(prefix,0);
	prefix[1] = a[0];
	loop(i,2,n+1) prefix[i] = prefix[i-1] + a[i-1]; 
	// dp[i][j] = min cost for piling up slimes of range [i,j] = min m (dp[i][m] + dp[m+1][j] + prefix[i][j]) , m E [i,j-1].
	for(int j=0;j<n;j++)
	{
		for(int i=j-1;i>=0;i--)
		{
			int mn = inf;
			for(int m=i;m<j;m++)
				mn = min(mn, dp[i][m] + dp[m+1][j] + prefix[j+1] - prefix[i]);
			dp[i][j] = mn;
		}
	}

	cout<<dp[0][n-1]<<endl;
	return 0;		
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <tuple>
using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) << endl;
    
}


Measured memory_bytes: 256
#include<stdio.h>
 int main(void)
 {
     int N,L[1000],R[1000];
     int i,S=0;

     scanf("%d",&N);

     for(i=0;i<N;i++)
       scanf("%d%d",&L[i],&R[i]);

     for(i=0;i<N;i++)
       S+=R[i]-L[i]+1;

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

     return 0;
 }



Measured memory_bytes: 128
s = str(input())
s1 = set(s)
s2 = list(s)
cnt = 0
if len(s1) != 2:
    print("No")
else:
    for i in range(1,len(s2)):
        if s[0] == s[i]:
            cnt += 1
    if cnt == 1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
	string S, T;
	cin >> S >> T;
	ll answer = 10000000000000;
	rep(i, S.size() - T.size() + 1) {
		ll b = 0;
		rep(j, T.size()) {
			if (S.at(i + j) != T.at(j)) { b++; }
		}
		answer = min(answer, b);
	}
	cout << answer << endl;
}

Measured memory_bytes: 3636
'use strict'

const mod = 1e9 + 7

function solve(N, K, A) {
  if (K === 0) {
    return 1
  }
  var dp = new Array(K+1).fill(0)
  var prefix = new Array(N).fill(0).map(e => new Array(K+1).fill(0))

  for (var i = 0; i < N; i++) {
    for (var j = 0; j <= K; j++) {
      if (i === 0) {
        dp[j] = j <= A[i] ? 1 : 0
        prefix[i][j] = j > 0 ? ((prefix[i][j-1] + dp[j]) % mod) : dp[j]
      } else {
        dp[j] = (j-1 - A[i]) >= 0 ? (((prefix[i-1][j] - prefix[i-1][j - A[i] - 1]) % mod) + mod) % mod : prefix[i-1][j]
        prefix[i][j] = j > 0 ? ((prefix[i][j-1] + dp[j]) % mod) : dp[j]
      }
    }
  }
  return dp[K]
}

function main(input) {
  var lines = input.split("\n")
  var NK = lines[0].split(' ').map(l => parseInt(l))
  var N = NK[0]
  var K = NK[1]
  var A = lines[1].split(' ').map(l => parseInt(l))
  var ans = solve(N, K, A)
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 113840
A, B, H, M = map(int, input().split()) 
import numpy as np

thetaA = M / 60 * 2 *np.pi
thetaB = (H+M/60) / 12 * 2 *np.pi
theta = thetaA - thetaB if thetaA >= thetaB else thetaB - thetaA
if theta > 180:
    theta = 180 - theta 

c = np.sqrt(A**2 + B**2 - 2 * A * B * np.cos(theta))

print(c)

Measured memory_bytes: 27196
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string S;
    cin >> S;
    if(S.size()%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    bool ok = true;
    for(int i = 0; i < S.size(); i++){
        if(i%2 == 0 && S[i] != 'h') ok = false;
        if(i%2 == 1 && S[i] != 'i') ok = false;
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
'use strict';
process.stdin.on('data', function(chunk) {
    var inputs = chunk.toString().trim().split(' ');
    var a = Number(inputs[0]);
    var b = Number(inputs[1]);
    if (a < b) {
        console.log('a < b');
    } else if (a > b) {
        console.log('a > b');
    } else {
        console.log('a == b');
    }
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15452
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll n;
  cin >> n;
  ll ans = 0LL;
  ll a = n-1;
  for(ll i = 1; i<=n-1; i++) {
    while(i*a>n-1) a--;
    ans += a;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    if i==1:
        p=i
        break
ans=0
ans+=(p+k-1)//(k-1)
p=n-1-p-(k-1-p%(k-1))
ans+=(p+k-2)//(k-1)
print(ans)

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	string s;
	cin >> s;

	if(s[1]=='B'){
		cout << "ARC" << endl;
	}
	else{
		cout << "ABC" << endl;
	}

}

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

Measured memory_bytes: 3652
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		int A[] = new int[N];
		int min = 1000000000;
		int max = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if(A[i] < min) min = A[i];
			if(A[i] > max) max = A[i];
		}
		System.out.println(max - min);
	}
}


Measured memory_bytes: 23892
using System;
using System.Linq;

namespace abc063_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(x[0] + x[1] < 10 ? x.Sum().ToString() : "error");
        }
    }
}

Measured memory_bytes: 13268
n, k = gets.split(" ").map(&:to_i)
em  = []
em = gets.split(" ").map(&:to_i)

em.sort!
count = n - 1
#p em

if k > em.length
  k = em.length
end
while k > 0
  em[count] = 0
  count -= 1
  k -= 1

end
#p em
p em.inject(:+)


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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;


int main(){
  IO; int N; cin >> N;
  string t;
  vpi t1, t2;
  int m, s;
  REP(i,N){
    cin >> t;
    m = s = 0;
    FORE(i,t){
      s += (i=='('?1:-1);
      MIN(m,s);
    }
    (s >= 0 ? t1 : t2).emplace_back(m, s);
  }
  SORT(t1);
  sort(ALL(t2), [&](pi&a, pi&b){return a.S-a.F > b.S-b.F;});
  ll v = 0;
  FORD(i,t1.size(),0){
    if(v+t1[i].F < 0){
      cout << "No" << endl;
      return 0;
    }
    v += t1[i].S;
  }
  FORE(i,t2){
    if(v+i.F < 0){
      cout << "No" << endl;
      return 0;
    }
    v += i.S;
  }
  cout << (v ? "No" : "Yes") << endl;
}


Measured memory_bytes: 11304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7 ;
#define pb push_back
#define all(v) v.begin(),v.end()
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n,m,k,l,y,x,z=0,ans=0,lang; string s ; bool ok ;
  map < ll , ll > mp ;

void solve()
{
    vector < vector < ll > > occ;
    vector < ll > v ;
    occ.clear(); occ.resize(30);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        v.pb(x);
        bitset<30> b(x);

        for(int j=0;j<30;j++)
        if(b[j]) occ[j].pb(i);


    }
    ans = 0 ;
    for(int i = 0 ;i<n ; i ++)
    {
        bitset<30> b(v[i]);
        ll tmp = n ;
        ll ind=i;
        for(int j=0;j<30;j++)
            {

            if(b[j])
                {
                   ind = upper_bound(all(occ[j]),i) - occ[j].begin();
                    if(ind==occ[j].size()) ind=n;
                    else ind=occ[j][ind];

                    tmp = min(tmp,ind-1);

                }
                else
                {
                        ind = upper_bound(all(occ[j]),i) - occ[j].begin();
                        if(ind==occ[j].size()) ind=n;
                        else ind=occ[j][ind];

                        ind = upper_bound(all(occ[j]),ind) - occ[j].begin();

                        if(ind==occ[j].size()) ind=n;
                        else ind=occ[j][ind];

                        tmp = min(tmp,ind-1);

                }



            }
        ans +=tmp-i+1;


    }


    cout<<ans<<'\n';
    }



int main()
{


    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    //freopen("test.in","r",stdin);
    //freopen("out.txt","w",stdout);
    int t;

     solve();

    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL a, b;
    cin >> a >> b;
    if(llabs(a - b) <= 1) cout << "Brown";
    else cout << "Alice";
    cout << endl;

    return 0;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int dp[100010], nxt[100010];

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    vector<int> s(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    sort(s.rbegin(), s.rend());
    dp[x] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= 100000; j++) nxt[j] = 0;
        for(int j = 0; j <= 100000; j++){
            if(j < s[i]){
                nxt[j] += dp[j] * (n - i) % mod;
                nxt[j] %= mod;
            }else{
                nxt[j % s[i]] += dp[j];
                nxt[j % s[i]] %= mod;
                nxt[j] += dp[j] * (n - i - 1) % mod;
                nxt[j] %= mod;
            }
        }
        swap(dp, nxt);
        // for(int j = 0; j <= 19; j++) cout << j << ' ' << dp[j] << endl;
    }
    int ans = 0;
    for(int i = 0; i <= 100000; i++){
        // if(i <= 19) cout << i << ' ' << dp[i] << endl;
        ans += i * dp[i] % mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
#define lg 18
//<<fixed << setprecision(9)
bool arr[21][21];
int n;
int dp[21][1<<21];
ll rec(int m,int f)
{
    if(m==-1) return 1;
    if(dp[m][f]!=-1) return dp[m][f];
    else
    {
        int i;
        dp[m][f]=0;
        rep(i,0,n)
        {
            if(arr[m][i] && (f&(1<<i)))
            {
                dp[m][f]+=rec(m-1,f^(1<<i));
                dp[m][f]%=mod;
            }
        }
        return dp[m][f];
    }
}

int main()
{
    int i,j,t;
    //boost;
    scanf("%d",&n);
    char c;
    getchar();
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            c=getchar();
            arr[i][j]=c-'0';
            getchar();
        }
    }
    rep(i,0,n)
    {
        rep(j,0,1<<21)
        {
            dp[i][j]=-1;
        }
    }
    int f=1<<n ;
    f--;
    printf("%lld",rec(n-1,f));
    

    return 0;
}



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

int h, w, n;
const int mask = (1 << 10) - 1;


bool ableToDeleteAll(vector<vector<int> > field, int i, int j, int rem) {
  swap(field[i][j], field[i][j+1]);
  //cout << "try: " << i <<"," << j << endl;

  bool changed = true;
  bool isFirst = true;
  while(changed && rem > 0) {
    changed = isFirst;
    if (!isFirst) for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        int c = field[i][j] & mask;
        if (c != '.') {
          if (j <= w - n) {
            int l = j + 1;
            int k;
            for (k = 1; l < w; k++, l++) {
              if ((field[i][l] & mask) != c) break;
            }
            if (k >= n) {
              changed = true;
              //printf("%d,%d kara %d,%d\n", i,j, i,j+k-1);
              for (l = j; l < j + k; l++) {
                field[i][l] |= mask+1;
              }
            }
          }
          if (i <= h - n) {
            int l = i + 1;
            int k;
            for (k = 1; l < h; k++, l++) {
              if ((field[l][j] & mask) != c) break;
            }
            if (k >= n) {
              changed = true;
              //printf("%d,%d kara %d,%d\n", i,j, i+k-1,j);
              for (l = i; l < i + k; l++) {
                field[l][j] |= mask+1;
              }
            }
          }
           
        }
      }
    }
    
    isFirst = false;

    for (int j = 0; j < w; j++) {
      int down = 0;
      for (int i = h - 1; i >= 0; i--) {
        int c = field[i][j];
        if ((c & mask+1) != 0 || c == '.') {
          down++;
          if (c != '.') rem--;
        }
        else {
          field[i + down][j] = field[i][j];
        }
        if(down > 0) field[i][j] = '.';
      }
    }

    // disp
    /*for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cout <<(char)(field[i][j]&mask);
      }
      cout << endl;
    }*/

  } /*w*/

  //cout << "rem: " << rem << endl;
  return rem == 0;
}

int main() {
  cin >> h >> w >> n;
  vector<vector<int> > field(h, vector<int>(w));
  int numBlocks = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      field[i][j] = c;
      if (c != '.') numBlocks++;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w - 1; j++) {
      if (/*field[i][j] != '.' && field[i][j+1] != '.'
          && */field[i][j] != field[i][j+1]) {
        if (ableToDeleteAll(field, i, j, numBlocks)) {
          cout << "YES" << endl;
          return 0;
        }
      }
    }
  }
  cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 0