akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N, Q;
string S;
char T[200010];
char D[200010];
bool ok[200010];

bool check_right(int pos){
    for(int i = 0; i < Q; i++){
        if(T[i] == S[pos]){
            if(D[i] == 'L') pos--;
            if(D[i] == 'R') pos++;
        }
        if(pos >= N) return true;
    }
    return false;
}
bool check_left(int pos){
    for(int i = 0; i < Q; i++){
        if(T[i] == S[pos]){
            if(D[i] == 'L') pos--;
            if(D[i] == 'R') pos++;
        }
        if(pos < 0) return true;
    }
    return false;
}

int main(){


    cin >> N >> Q;
    cin >> S;
    for(int i = 0; i < Q; i++) cin >> T[i] >> D[i];
    {
        int lb = -1;
        int ub = N;
        while(ub - lb > 1){
            int mid = (ub + lb) / 2;
            if(check_right(mid)) ub = mid;
            else lb = mid;
        }
        for(int i = ub; i < N; i++){
            ok[i] = true;
        }
    }
    {
        int lb = -1;
        int ub = N;
        while(ub - lb > 1){
            int mid = (ub + lb) / 2;
            if(check_left(mid)) lb = mid;
            else ub = mid;
        }
        for(int i = 0; i <= lb; i++){
            ok[i] = true;
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(ok[i]) ans++;
    }
    
    cout << N - ans << endl;
    


    return 0;
}


Measured memory_bytes: 1156
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[[0,0] for _ in range(n)]
for i in range(n):
    c=0
    for j in range(i):
        if a[j]>a[i]:c+=1
    b[i][0]=c
    for j in range(i,n):
        if a[j]>a[i]:c+=1
    b[i][1]=c
ans=0
for i in range(n):
    ans=(ans+(k-1)*k//2*b[i][1]+b[i][0]*k)%(10**9+7)
print(ans)

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

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {	
		if (s[i] >= 'A' && s[i] <= 'Z')
			s[i] += 'a' - 'A';
	}
	int sum = 0;
	string t;
	while (1) {
		cin >> t;
		if (t == "END_OF_TEXT")
			break;
		for (int i = 0; i < t.size(); i++) {
			if (t[i] >= 'A' && t[i] <= 'Z')
				t[i] += 'a' - 'A';
		}
		if (t == s)
		sum++;
	}
	cout << sum << endl;
}



Measured memory_bytes: 3220
[n,q] = map(int,input().split())

t = [ 0 for _ in range(n) ]

max_idx = 0
max_val = 0

for _ in range(q):
    [a,v] = map(int,input().split())
    t[a-1] += v

    if max_idx == a-1:
        if v > 0:
            max_val = t[a-1]
        else:
            max_val = max(t)
            max_idx = t.index(max_val)
    elif t[a-1] > max_val:
        max_val = t[a-1]
        max_idx = a-1
    elif t[a-1] == max_val:
        if a-1 < max_idx:
            max_val = t[a-1]
            max_idx = a-1

    print("{} {}".format(max_idx+1,max_val))

Measured memory_bytes: 15768
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }

    let mut set = std::collections::HashSet::new();
    let mut wild = 0usize;
    for i in 0..n {
        if a[i] >= 3200 {
            wild += 1;
        } else {
            set.insert(a[i]/400);
        }
    }
    if wild == n {
        println!("{} {}", 1, wild);
    } else {
        println!("{} {}", set.len(), set.len() + wild);
    }
}

Measured memory_bytes: 4352
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	set<int> kb;
	int n; 
	cin >> n;
	REP(i, n){
		cin >> tmp;
		kb.insert(tmp);
	}
	if (kb.size() == n) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	//cout << ans << endl;
}

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

struct work
{
  long long a;
  long long b;
};

bool cmp(const work &ta, const work &tb) { return ta.b < tb.b; }

int main() {
  int n;
  cin >> n;
  vector<work> w;
  for ( int i = 0; i < n; i++ ) {
    long long ta, tb;
    cin >> ta >> tb;
    work tmp;
    tmp.a = ta; tmp.b = tb;
    w.push_back(tmp);
  }
  sort(w.begin(), w.end(), cmp);
  long long time = 0;
  string ans = "Yes";
  for ( int i = 0; i < n; i++ ) {
    time += w[i].a;
    if ( time > w[i].b ) { ans = "No"; break; }
  }

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

Measured memory_bytes: 6256
N,A,B = map(int,input().split())

def check_num(n):
  s  = str(n)
  array = list(map(int,s))
  return sum(array)


list_1 = [i for i in range(1,N+1)]

list_2 = []

for _ in list_1:
  if A<=check_num(_)<=B:
    list_2.append(_)
  else:
    pass
  
print(sum(list_2))
  

Measured memory_bytes: 9432
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>


using ll =  long long;

#define rep(i,n) for(int i= 0; i< (n); i++)

using namespace std;

int main(){

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

    int tmp=0;
    rep(i,n) tmp+=a[i];
    int cnt=0;

    rep(i,n){
        if(a[i]*(4*m)>=tmp) cnt++;
    }


    if(cnt>=m)
        cout<<"Yes"<<endl;
    else
        cout << "No" << endl;
    


    return 0;
}

Measured memory_bytes: 3584
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=100005;
#define ll long long
int pos[N],a[N];
ll p[N],d[N];
int to[N][64];
int main (){
	int n;scanf ("%d",&n);
	for (int i=1;i<=n;i++) scanf ("%lld",&p[i]),d[i]=p[i]-p[i-1];
	int m;ll k;
	scanf ("%d%lld",&m,&k);
	for (int i=1;i<=n;i++) a[i]=i;
	for (int i=1,x;i<=m;i++) {scanf ("%d",&x);swap(a[x],a[x+1]);}
	for (int i=1;i<=n;i++) to[a[i]][0]=i;
	for (int i=1;i<=60;i++)
		for (int j=1;j<=n;j++)
			to[j][i]=to[to[j][i-1]][i-1];
	for (int i=1;i<=n;i++){
		int now=i;
		for (int j=0;j<=60;j++)
			if (k&(1ll<<j)) now=to[now][j];
		pos[now]=i;
	}
	for (int i=1;i<=n;i++) p[i]=p[i-1]+d[pos[i]],printf ("%lld\n",p[i]);
	return 0;
}


Measured memory_bytes: 28672
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt int Q[100005]={0}
#define mp make_pair
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<int>()) 
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(int i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(int i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int,int> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=mpowe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
int main()
{
    fastio();
     
    int n,m;
    cin>>n>>m;
    cout<<(n*(n-1))/2+(m*(m-1))/2<<endl;
}

Measured memory_bytes: 256
N, L =  map(int, input().split())

app_list = [L+i for i in range(N)]

if app_list[0] >= 0:
  print(sum(app_list[1:]))
elif app_list[-1] <= 0:
  print(sum(app_list[:N-1]))
else:
  print(sum(app_list))

Measured memory_bytes: 3060
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
const int INF = 1e9;
const ll LINF = 1e18;
// clang-format on

void solve(long long N, std::vector<long long> a) {
  SORT_DESC(a);
  ll ans = 0;
  rep(i, N) {
    ans += a[i * 2 + 1];
  }
  ANS(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(3 * N);
  for (int i = 0; i < 3 * N; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;

  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];
  vector<ll> b(n);
  for(int i = 0;i < n;i++)cin >> b[i];

  ll sum = 0;
  for(int i = 0;i < n;i++)sum += a[i];
  
  vector<ll> rem;
  bool ex_above = false;
  for(int i = 0;i < n;i++){
    sum -= b[i];
    if(a[i] >= b[i])rem.push_back(a[i] - b[i]);
    else ex_above = true;
  }

  if(sum < 0){
    cout << -1 << endl;
    return 0;
  }

  sort(rem.begin(),rem.end());
  int num = 0;
  bool flag = true;
  for(int now:rem){
    if(sum >= now){
      sum -= now;
      num++;
    }
    flag = false;
  }

  if(sum > 0 && flag == true && ex_above == false)cout << n - num + 1 << endl;
  else cout << n - num << endl;

}

Measured memory_bytes: 2936
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct item {
    int w, v;
};

void knapsack1(){
    vector<item> items;
    int n, w;
    cin >> n >> w;
    long maxVal[n + 1][w + 1];
    items.push_back({0,0});
    for (int i = 0; i < n; i++) {
        int wt, vl;
        cin >> wt >> vl;
        items.push_back({wt, vl});
    }
    for (int i = 0; i <= w; i++){
        maxVal[0][i] = 0;
    }
    for (int i = 0; i <= n; i++){
        maxVal[i][0] = 0;
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= w; j++) {
            if (j < items[i].w) {
                maxVal[i][j] = maxVal[i - 1][j];
            }
            else
                maxVal[i][j] = max(maxVal[i - 1][j], maxVal[i - 1][j - items[i].w] + items[i].v);
        }
    }
    cout << maxVal[n][w];
}

int main() {
    knapsack1();
}




Measured memory_bytes: 79104
###
### atcorder test program
###

import sys

### math class
class math:
    ### pi
    pi = 3.14159265358979323846264338

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

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

    ### Prime number search
    def Pnum(self, a):
        if a == 1: return False
        for i in range(2,int(a**0.5)+1):
            if a % i == 0:
                return False
        return True

    ### Circle area
    def caria(self, r):
        return r*r*self.pi

math = math()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

#A, B, C = [int(x) for x in input().split()]

O = input()
E = input()

for i in range(len(O)):
    print(O[i], end="")
    if len(E) > i:
        print(E[i], end="")
print("")

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

using namespace std;

int main() {
  double A, B, H, M;
  
  cin >> A >> B >> H >> M;
  
  double H_angle = (H * 60 + M) / 2.0;
  double M_angle = M * 6;
  
  double ans = A * A + B * B - 2 * A * B * cos((M_angle - H_angle) * 3.14159265358979 / 180.0);
  
  cout << setprecision(10) << sqrt(ans) << endl;
  
  return 0;
}

Measured memory_bytes: 4108
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;


int main(int argc, char *argv[])
{
	int a, b, c;

	//input
	cin >> a >> b >> c;



	//calc
	string ans = "";

	if ((a == b && a != c) || (a == c && a != b) || (b == c && a != b)){
		ans = "Yes";
	}
	else{
		ans = "No";
	}



	//ans

	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 256
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll a[Max];
ll n;
void solve(){
	cin>>n;
	rep(i,0,n){
		cin>>a[i];
	}
	ll M = a[0];
	rep(i,1,n){
		M = max(M,a[i]);
		if(a[i]<M-1){
			cout<<"No";
			return ;
		}
	} 
	cout<<"Yes";
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>
 
using namespace std;
typedef long long ll;
 
int main(){
ll a,b,c;
cin>>a>>b>>c;
if(a+b<c){
cout<<2*b+a+1;
}
  else{
    cout<<b+c;
  }
  return 0;
 
}
 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
    string s,t; cin >> s >> t;
    ll n = s.size();
    ll m = t.size();
    vpl scnt(n+1,{0,0});
    vpl tcnt(n+1,{0,0});
    rep(i,n){
        scnt[i+1].first += scnt[i].first + (s[i]=='A');
        scnt[i+1].second += scnt[i].second + (s[i]=='B');
    }
    rep(i,m){
        tcnt[i+1].first += tcnt[i].first + (t[i]=='A');
        tcnt[i+1].second += tcnt[i].second + (t[i]=='B');
    }
    ll q; cin >> q;
    while(q--){
        ll a,b,c,d; cin >> a >> b >> c >> d;
        ll A = scnt[b].first-scnt[a-1].first-(tcnt[d].first-tcnt[c-1].first);
        ll B = scnt[b].second-scnt[a-1].second-(tcnt[d].second-tcnt[c-1].second);
        if(A<B) swap(A,B);
        if((A-B)%3==0) puts("YES");
        else puts("NO");
    }
}

Measured memory_bytes: 3968
n,a,b=map(int,input().split())
count=0
for i in range(1,n+1):
  i=str(i)
  sums=0
  for j in range(0,len(i)):
    sums+=int(i[j])
  if a<=sums<=b:
    count+=int(i)
print(count)

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    lint n;
    cin >> n;

    set<lint> st;
    for(lint i = 1 ; i * i <= n ; ++i){
        if(n % i == 0LL){
            lint m = i - 1;
            if(m != 0LL && n / m == n % m){
                st.insert(m);
            }
            m = n / i - 1;
            if(m != 0LL && n / m == n % m){
                st.insert(m);
            }
        }
    }

    lint ans = 0;
    for(auto x : st){
        ans += x;
    }
    cout << ans << endl;

    return 0;
}

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

int n, m;
int memo[25] = {0};
int dp[50005] = {0};

int main() {
  int i, j;
  cin >> n >> m;
  for(i = 0; i < m; ++i) cin >> memo[i];

  for(i = 1; i <= n; ++i) {
    dp[i] = 10000000;
    for(j = 0; j < m; ++j)
      if(memo[j] <= i)
        dp[i] = min(dp[i], dp[i - memo[j]] + 1);
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 3276
n = int(input())

if n == 1:
    print('a')
    exit()

ans = []


def dfs(s, c):
    for i in range(ord('a'), ord(c) + 2):
        now = s + chr(i)
        if len(now) == n:
            ans.append(now)
        elif i > ord(c):
            dfs(now, chr(i))
        else:
            dfs(now, c)


dfs('a', 'a')

for c in ans:
    print(c)


Measured memory_bytes: 12664
import sys
from fractions import gcd
from itertools import product, combinations
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    l, r = LI()
    mods = [[INF for i in range(2019)] for j in range(2019)]
    ans = INF
    for i, j in product(range(2019), range(2019)):
        mods[i][j] = i * j % 2019
    if r - l >= 2019:
        print(0)
        return
    l = l % 2019
    r = r % 2019
    if r > l:
        for i, j in combinations(range(l, r+1), 2):
            if i == j:
                continue
            ans = min(ans, mods[i][j])
        print(ans)
        return
    print(0)








if __name__ == "__main__":
    main()

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(d<=a||b<=c){
        cout<<0;
    }else if(c<=a&&d<=b){
        cout<<d-a;
    }else if(c<=a&&b<=d){
        cout<<b-a;
    }else if(a<=c&&d<=b){
        cout<<d-c;
    }else if(a<=c&&b<=d){
        cout<<b-c;
    }

    return 0;
}

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

int main(){
    int N, X, L[100];
    cin >> N >> X;
    for(int i=0; i<N; i++) cin >> L[i];

    int pos = 0, ans = 1;
    for(int i=0; i<N; i++){
        pos += L[i];
        if(pos <= X) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define ll long long
#define F first
#define FF first.first
#define FS first.second
#define S second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e16;
 
ll n, q=1, e, a[N], f[N], c[N], o, k, t, x, y, z, u, h, mx, mn, ans, Ans;
pair<ll,ll> p[N];
string s;
vector<int> v[N];
map <string, int> m;
 
main(){ios_base::sync_with_stdio(false), cin.tie(0);
   	
	cin>>n;
	
	for (int i=1; i<=n; i++){
		cin>>s;
		if(!m[s])ans++;
		m[s]=1;
	}
	cout<<ans;
}

Measured memory_bytes: 42708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
    while ( b != 0 ) {
        ll t = b;
        b = a % b;
        a = t;
    }
    return a;
}

map<ll, int> factorize(ll x) {
    map<ll, int> f;
    while ( x % 2 == 0 ) x /= 2, f[2]++;
    for( ll d = 3; d*d <= x; d+=2 ) {
        while ( x % d == 0 ) x /= d, f[d]++;
    }
    if ( x > 1 ) f[x]++;
    return f;
}

ll solve() {
    ll A, B;
    cin >> A >> B;
    ll g = gcd(A,B);
    auto f = factorize(g);
    return f.size() + 1;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

bool f(string s){
	string t = s;
	reverse(t.begin(), t.end());
	return s == t;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int n = s.size();
	int m = n / 2;
	string u = s.substr(0, m);
	string v = s.substr((n+3)/2-1, m);
	if(f(s) && f(u) && f(v)) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
N = int(input())
S = input()
answer = S.count('E')
if S[0] =='E':
    test = S.count('E') - 1
else:
    test = S.count('E')

for x in range(0,N-1):
    if S[x] == 'W':
        test += 1
    if S[x+1] =='E':
        test -= 1
    answer = min (answer,test)

print(answer)

Measured memory_bytes: 3668
#define rep(i, n) for(int i=0; i<n; i++)
template<class T> inline void chmin(T & a, const T b) { if (a > b) a = b; }

#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
const llong INF = (1LL << 60);
int main(void) {
	int h, n; cin >> h >> n;
	vector<int> A(n), B(n);
	rep(i, n) scanf("%d%d", &A[i], &B[i]);

	vector<vector<llong>> dp(n + 1, vector<llong>(h + 1, INF));
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= h; j++) {
			chmin(dp[i + 1][j], dp[i][j]);
			chmin(dp[i + 1][min(j + A[i], h)], dp[i + 1][j] + B[i]);
		}
	}

	cout << dp[n][h] << endl;

	return 0;
}

Measured memory_bytes: 78592
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
	string a,b;
	cin >> a >> b;
	int num = stoi(a + b);
	rep(i, sqrt(num) + 1) {
		if (i*i == num) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    long double a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    long double d=abs(b-a);
    long double T=d/(v-w);
    if(T>0&&T<=t)
    {
        cout<<"YES";
    }
    else
        cout<<"NO";
}



Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    int n,m;
    cin >> n >> m;
    map<int,int> cor;
    map<int,int> wro;
    vector<int> p(m);
    vector<string> s(m);
    for (int i=0;i<m;i++){
        cin >> p.at(i) >> s.at(i);
    }
    int nc=0;
    int wc=0;
    for (int i=0;i<m;i++){
        if(s.at(i)=="AC"&&cor[p.at(i)]!=1) {
            cor[p.at(i)]=1;
            nc++;
        }
        if(s.at(i)=="WA"&&cor[p.at(i)]!=1){
            wro[p.at(i)]++;
        }
    }
    for (int i=0;i<cor.size();i++){
        if(cor[i]==1)
            wc+=wro[i];
    }
    cout << nc << " " << wc << endl;
    return 0;
}

Measured memory_bytes: 15488
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807

signed main()
{
  int x=0,y=0,z=0,w=0,n=0,m=0;
  string s;
std::cin >> x>>y;
std::cout << 6-x-y << '\n';
}


Measured memory_bytes: 256
def kai(n):
    x=0
    while True:
        if n%2==0:
            n=n//2
            x+=1
        else:
            break
    return x

n=int(input())
if n==1:
    print(1)
else:
    a=[0]*(n+1)
    for i in range(1,n+1):
        a[i]=kai(i)

    print(a.index(max(a)))

Measured memory_bytes: 3060
n1 = int(input())

s1 = []
t1 = ""
d1 = {}
for i1 in range(n1):
    t1 = ''.join(sorted(input()))
    if d1.get(t1, 0) == 0:
        d1[t1] = 1
    else:
        d1[t1] += 1

r1 = 0

for v1 in d1.values():
    if v1 != 1:
        r1 += ((v1 * (v1 - 1)) // 2)

print(r1)

Measured memory_bytes: 17852
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
using namespace std;

int main(void){
    long long N;
    cin >> N;
    vector<long long>a(N);
    long long bai4 = 0;
    long long bai2 = 0;
    long long other = 0;
    for (long long i = 0;i < N;i++){
        cin >> a[i];
        if(a[i] % 2 == 0 && a[i] % 4 == 0){
            bai4++;
        }else if(a[i] % 2 == 0 && a[i] % 4 != 0){
            bai2++;
        }else{
            other++;
        }
    }
    if (N % 2 == 0){
        if (bai4 - other >= 0){
            cout << "Yes" << endl;
            return 0;
        }
    }else{
        if (bai4 - other >= -1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define f(a, b) for (i = a; i < b; i++)
#define fr(a, b) for (j = a; j >= b; j--)
#define fi(a, b) for (j = a; j < b; j++)
#define fii(a, b) for (k = a; k < b; k++)
#define answer cout<<endl<<"answer : ";
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi //lld t=0;cin>>t;while(t--){
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0;string s;bool flag=false;
        cin>>n>>k; lld a[n]; for(i=0;i<n;i++) cin>>a[i];
        lld dp[n];
        for(i=0;i<n;i++) dp[i]=INT_MAX;
        dp[0]=0;
        for(i=0;i<n;i++)
        {
            for(j=1;j<=k;j++)
                if(i+j<n)
                    dp[i+j]=min(dp[i+j],dp[i]+abs(a[i]-a[i+j]));
        }
        cout<<dp[n-1]<<endl;
	return 0;
}
/*  CODED BY:-
           __        __
 /\   /\  |__)  /\  |  \ |__| \ /  /\
/~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\

*/


Measured memory_bytes: 1792
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = LI()
    
    #DP[i][j]:=i日目に株j個持ってる場合の所持金最大値
    DP = [defaultdict(int) for _ in range(N+1)]
    DP[0][0] = 1000
    for i in range(N):
        for j,money in DP[i].items():
            #買わない
            DP[i+1][j] = max(DP[i+1][j], money)
            #売る
            DP[i+1][0] = max(DP[i+1][0], money + j*A[i])

        #0円のときのみ買う
        remain = DP[i][0]%A[i]
        buy = DP[i][0]//A[i]
        DP[i+1][0+buy] = max(DP[i+1][0+buy], remain)
    ans = DP[-1][0]
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 10856
#include <iostream>

using namespace std;

const int MAX_H = 100;
const int MAX_W = 100;

int H, W;
int dx[]={0,-1,1,0}, dy[]{1,0,0,-1};
int nx, ny;
int num;

char orchard[MAX_H][MAX_W+1];

void dfs(int x, int y, char tree){
	orchard[x][y]='x';
	
	for(int i=0;i<4;i++){
		nx=x+dx[i], ny=y+dy[i];
		if(nx>=0&&nx<W&&ny>=0&&ny<H&&orchard[nx][ny]==tree){
			dfs(nx, ny, tree);
		}
	}
	return;
}

int main(){
	while(cin >> H >> W && H && W){
		num=0;
		for(int j=0;j<H;j++)
			for(int i=0;i<W;i++){
				cin >> orchard[i][j];
			}
		for(int j=0;j<H;j++)
			for(int i=0;i<W;i++){
				if(orchard[i][j]!='x'){
					dfs(i,j,orchard[i][j]);
					num++;
				}
			}
		cout << num << endl;
	}
	return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n, m;
vector<vector<int>> edge;
vector<int> dp;

int dfs(int p){
    if(~dp[p]) return dp[p];
    int res = 0;
    for(auto&& i : edge[p]){
        res = max(1 + dfs(i), res);
    }
    return dp[p] = res;
}

int main(){
    cin >> n >> m;
    edge.resize(n);
    dp.resize(n, -1);
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        edge[x - 1].push_back(y - 1);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(~dp[i]) continue;
        ans = max(ans, dfs(i));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 8192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		a[0] = sc.nextInt();
		for (int i = 1; i < n; i++) {
			a[i] = a[i - 1] + sc.nextInt();
		}
		sc.close();

		long ans = Long.MAX_VALUE;
		for (int i = 0; i < n - 1; i++) {
			long x = a[i];
			long y = a[n - 1] - a[i];
			ans = Math.min(ans, Math.abs(x - y));
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 85776
#include<iostream>
using namespace std;
int main(){
	int h, w, i, j;
	while (cin >> h >> w, h || w){
		for (i = 0; i < h;++i){
			for (j = 0; j < w; ++j)
				cout << ((i % 2) ? ((j % 2) ? "#" : ".") : ((j % 2) ? "." : "#"));
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1152
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(x: u32) -> u32 {

    if x == 1 || x == 2 || x == 3 {
        return 1
    }

    let mut ret = 0;
    for b in 2..x {
        let mut last = 0;
        for p in 2.. {
            let i = b.pow(p);
            if i <= x {
                last = i;
            } else {
                break;
            }
        }
        if ret < last {
            ret = last;
        }
    }

    ret
}

fn main() {
    let x = parse_line!(u32);

    println!("{}", solve(x));
}

#[test]
fn solve_test() {
    assert_eq!(solve(10), 9);
    assert_eq!(solve(1), 1);
    assert_eq!(solve(999), 961);
    assert_eq!(solve(5), 4);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define MOD 1000000007
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    int n, k, x;
    cin >> n >> k;
    int ans = 0;
    imfor(i, n) {
        cin >> x;
        if (x < abs(k - x)) {
            ans += 2 * x;
        }
        else {
            ans += 2 * abs(k - x);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int h, w, k, cnt = 0;
vector< vector<int> > a;
string s[300];

int f(int y, int x, int z){
    if(a[y][x] != 0) return a[y][x];
    if(s[y][x] == '#'){
        return a[y][x] = ++cnt;
    }
    if(x+z >= 0 && x+z < w){
        int v = f(y, x+z, z);
        if(v > 0) return a[y][x] = v;
    }
    return 0;
}

int g(int y, int x, int z){
    if(a[y][x] != 0) return a[y][x];
    if(s[y][x] == '#'){
        return a[y][x] = ++cnt;
    }
    if(y+z >= 0 && y+z < h){
        int v = g(y+z, x, z);
        if(v > 0) return a[y][x] = v;
    }
    return 0;
}


int main(void){

    cin >> h >> w >> k;
    a.assign(h, vector<int>(w, 0));
    for(int i=0;i<h;i++){
        cin >> s[i];
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            f(i, j, 1);
        }
        for(int j=w-1;j>=0;j--){
            f(i, j, -1);
        }
    }

    for(int i=0;i<h;i++){
        int c = 0;
        for(int j=0;j<w;j++){
            if(a[i][j] == 0)c++;
        }
        if(c == w){
            for(int j=0;j<w;j++){
                g(i, j, 1);
            }
        }
    }

    for(int i=h-1;i>=0;i--){
        int c = 0;
        for(int j=0;j<w;j++){
            if(a[i][j] == 0)c++;
        }
        if(c == w){
            for(int j=0;j<w;j++){
                g(i, j, -1);
            }
        }
    }


    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}


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

int main()
{
	int r, c;
	int a[101][101] = { 0 };

	cin >> r >> c;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			a[i][c] += a[i][j];
		}
	}
	for (int j = 0; j < c; j++) {
		for (int i = 0; i < r; i++) {
			a[r][j] += a[i][j];
		}
	}
	for (int i = 0; i < r; i++) {
		a[r][c] += a[i][c];
	}

	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			cout << a[i][j];
			cout << ((j != c) ? " " : "\n");
		}
	}

	return 0;
}


Measured memory_bytes: 3168
import io.{StdIn => in}

object Main extends App {
  val ans = in.readLine match {
    case "a" => "vowel"
    case "i" => "vowel"
    case "e" => "vowel"
    case "u" => "vowel"
    case "o" => "vowel"
    case _   => "consonant"
  }
  println(ans)
}

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



void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  int ca = a;
  int x = (a%b);
  if(x == c%b) {
    cout << "YES";
    return;
  }
  a += ca;
  while((a%b) != x) {
    if(a%b == c%b) {
      cout << "YES";
      return;
    }
    a += ca;
  }
  cout << "NO";
}


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


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

int main() {
 int n,sum,mini;cin>>n;char s[n];for(int i=0;i<n;i++)cin>>s[i];
  int right[n+1],left[n+1];right[0]=left[0]=0;
  for(int i=1;i<n+1;i++){
    if(s[i-1]=='E'){
      right[i]=right[i-1]+1;left[i]=left[i-1];
    }
    else {
      left[i]=left[i-1]+1;right[i]=right[i-1];
    }
  }
  
  mini=min(right[n]-right[1],left[n-1]);
  for(int i=1;i<n-2;i++){
    if(right[n]-right[i+1]+left[i]<mini)mini=right[n]-right[i+1]+left[i];
  }
  
  
  cout<<mini<<endl;
}
  

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

int main(void)
{
	string N;
	int S;
	cin >> S;
	cin >> N;

	string ls = "", rs = "";
	
	string NN = N;
	string::size_type pos(N.find("()"));
	while (pos != string::npos) {
		N.replace(pos, 2, "");
		pos = N.find("()");
		S -= 2;
	}

	int l = 0, r = S - 1;

	while (l <= r) {
		if (l == r) {
			if (N[l] == '(')	rs += ')';
			else ls += '(';
			++l;
			--r;
			continue;
		}
		if (N[l] == '(' && N[r] == ')') {
			++l;
			--r;
		} else if (N[l] == ')' && N[r] == '(') {
			ls += '(';
			l++;
		}
		else if (N[l] == '(') {
			rs += ')';
			++l;
		} else if (N[r] == ')') {
			ls += '(';
			--r;
		}
	}

	cout << ls + NN + rs << endl;

	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    tree = [[] for _ in range(n)]
    for _ in range(m):
        L, R, D = map(int, input().split())
        tree[L - 1].append((R - 1, D))
        tree[R - 1].append((L - 1, -D))

    def dfs(v):
        for u, d in tree[v]:
            if depth[u] == f_inf:
                depth[u] = depth[v] + d
                dfs(u)
            else:
                if depth[u] != depth[v] + d:
                    print("No")
                    exit()

    depth = [f_inf for _ in range(n)]
    for i in range(n):
        if depth[i] == f_inf:
            depth[i] = 0
            dfs(i)

    print("Yes")


if __name__ == '__main__':
    resolve()


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


using namespace std;

using ll   = long long;
using ii   = pair < int , int >;
using i3   = pair < int , ii >;
using li   = pair < ll , int >;
using lii  = pair <  ll,  ii >;
using vi   = vector < int >;
using vl   = vector < ll >;
using vli  = vector < li >;
using vii  = vector < ii >;
using vi3  = vector < i3 >;
using vlii = vector < lii >;

const int N = 1e5 + 5;
const ll INF = 1e17;
const double eps = 1e-12 , PI = acos(-1);

int n , m;


void A(){
    scanf("%d %d" , &n , &m);

    printf("%d\n" , n <= 9 && m <= 9 ? n*m : -1);
}

void B(){
    scanf("%d" , &n);

    for(int i = 1 ; i*i <= n ; i ++){
            if(n%i == 0){
                    if(i <= 9 && n/i <= 9){
                            printf("Yes\n");
                            return;
                    }
            }
    }
    printf("No\n");
}

void C(){
    ll x;
    scanf("%lld" , &x);

    ll ans = INF;
    for(ll i = 1ll ; i*i <= x ; i ++){
            if(x%i == 0){
                    ans = min(ans , i + x/i);
            }
    }

    printf("%lld\n" , ans - (1ll * 2));
}

main(){

    A();
    //B();
    //C();

    return 0;
}


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

struct point {
  ll x, y;
  point(ll x_ = 0, ll y_ = 0) : x(x_), y(y_) {}
  friend point operator-(point a, point b) {
    return point(a.x - b.x, a.y - b.y);
  }
  friend bool operator<(point a, point b) {
    return a.x != b.x ? a.x < b.x : a.y < b.y;
  }
};

ll cross(point a, point b) {
  return a.x * b.y - a.y * b.x;
}

vector<point> convex_hull(vector<point> ps) {
  const int n = ps.size();
  if (n <= 2) return ps;
  sort(ps.begin(), ps.end());
  vector<point> a, b;
  rep(i, ps.size()) {
    while (a.size() >= 2 && cross(a.back() - a.rbegin()[1], ps[i] - a.back()) < 0) a.pop_back();
    a.push_back(ps[i]);
  }
  repr(i, ps.size()) {
    while (b.size() >= 2 && cross(b.back() - b.rbegin()[1], ps[i] - b.back()) < 0) b.pop_back();
    b.push_back(ps[i]);
  }
  a.pop_back();
  b.pop_back();
  a.insert(a.end(), b.begin(), b.end());
  return a;
}

constexpr double PI = acos(-1);

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N; cin >> N;
  vector<point> P(N);
  map<point, int> mp;
  rep(i, N) {
    ll x, y; cin >> x >> y;
    P[i] = point(x, y);
    mp[P[i]] = i;
  }
  P = convex_hull(P);
  vector<double> theta(P.size());
  for (int i = 0; i < P.size(); i++) {
    int j = (i + 1) % P.size();
    point d = P[j] - P[i];
    theta[i] = atan2(d.y, d.x) - PI / 2;
  }
  vector<double> ans(N);
  for (int i = 0; i < P.size(); i++) {
    int j = (i + P.size() - 1) % P.size();
    double t = theta[i] - theta[j];
    if (t < 0) t += 2 * PI;
    ans[mp[P[i]]] = t / (2 * PI);
  }
  rep(i, N) {
    cout << ans[i] << '\n';
  }
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void)
{
int A,B;
scanf("%d",&A);
scanf("%d",&B);
if(A+B>=A-B&&A+B>=A*B)
{printf("%d",A+B);}
else if(A-B>=A+B&&A-B>=A*B){printf("%d",A-B);}
else {printf("%d",A*B);}
return 0;
 }

Measured memory_bytes: 128
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


ANS = []
N = None

def recursive(table,pre,tmp_sum):
    global N
    for i in range(min(pre,N-tmp_sum),0,-1):
        work = []
        for k in range(len(table)):
            work.append(table[k])
        work.append(i)
        next_tmp_sum = tmp_sum+i

        if next_tmp_sum == N:
            ANS.append(work)
            continue
        recursive(work,i,next_tmp_sum)


while True:
    N = int(input())
    if N == 0:
        break

    ANS.clear()

    recursive([],BIG_NUM,0)
    for i in range(len(ANS)):
        print(' '.join(map(str,ANS[i])))



Measured memory_bytes: 14740
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;




void main() {
    long N, A, B;
    scan(N, A, B);
    auto d = abs(A - B);
    if (d % 2 == 0) {
        writeln(d / 2);
        return;
    }

    auto ans = min(A - 1, N - B) + (d + 1) / 2;
    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll a,b,c,A,B,C,cnt = 0;
    cin >> a >> b >> c;
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
        cout << 0 << endl;
    }else if (a == b && b == c) {
        cout << -1 << endl;
    }else{
        while (1) {
            if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
                cout << cnt << endl;
                break;
            }
            A = (b + c)/2;
            B = (a + c)/2;
            C = (a + b)/2;
            a = A;
            b = B;
            c = C;
            ++cnt;
        }
    }
    return 0;
}


Measured memory_bytes: 256
s = str(input())
a = list(s)
alpha = set(s)
temp = ""
temp2 = ""
ans = 0
answers = []
if(len(alpha) > 1):
    for letter in alpha:
        temp = s
        ans = 0;
        while(True):
            ans += 1
            for i in range(len(temp)-1):
                if temp[i] == letter or temp[i+1] == letter:
                    temp2 += letter
                else:
                    temp2 += temp[i]
            temp = temp2
            temp2 = ""
            lettercount = 0;
            for i in range(len(temp)):
                if temp[i] == letter:
                    lettercount += 1
            if lettercount == len(temp):
                break
        answers.append(ans)
    print(min(answers))
else:
    print(0)

Measured memory_bytes: 3064
def prime_fact(N):
  M = N
  primes = []
  K = 2

  while K*K <= M:
    while N%K == 0:
      primes.append(K)
      N = N//K
    K += 1
  
  if N != 1:
    primes.append(N)

  return primes

N = int(input())
nums = [0]*1000
ans = 1

for i in range(2,N+1):
  P = prime_fact(i)
  for j in range(len(P)):
    nums[P[j]-1] += 1

for k in range(1000):
  ans = ans*(nums[k]+1)%1000000007

print(ans)

Measured memory_bytes: 9216