akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

typedef struct _node{
    int key;
    struct _node *left;
    struct _node *right;
}NODE;
NODE* makeNode(int x){
    NODE *n=(NODE*)malloc(sizeof(NODE));
    n->key=x;
    n->left=NULL;
    n->right=NULL;
    
    return n;
}
NODE* insert(NODE *t,int x){
    if(t==NULL)return makeNode(x);

    if(t->key<x)t->right=insert(t->right,x);
    else t->left=insert(t->left,x);
    
    return t;
}
void inorder(NODE *t){
    if(t==NULL)return;
    
    if(t->left!=NULL)inorder(t->left);
    printf(" %d",t->key);
    if(t->right!=NULL)inorder(t->right);
    
    return;
}
void preorder(NODE *t){
    if(t==NULL)return;
    
    printf(" %d",t->key);
    if(t->left!=NULL)preorder(t->left);
    if(t->right!=NULL)preorder(t->right);
    
    return;
}

int main(void){
    NODE *root;
    root=NULL;
    
    int n;
    scanf("%d\n",&n);
    
    char com[6+1];
    int x;
    while(n--){
        scanf("%s",com);
        switch(com[0]){
            case 'i':
                //insert
                scanf("%d\n",&x);
                root=insert(root,x);
                break;
            case 'p':
                //print
                inorder(root);
                printf("\n");
                preorder(root);
                printf("\n");
                break;
        }
    }
    
    return 0;
}



Measured memory_bytes: 17328
def solve():
    from bisect import bisect_right
    N, W = map(int, input().split())
    a = [tuple(map(int, input().split())) for _ in [0]*N]

    def bitdp(items):
        n = len(items)
        dp = [(0, 0) for _ in [0]*(2**n)]
        for bitset in range(1, 2**n):
            for item_num, (item_v, item_w) in enumerate(items):
                if bitset & 2**item_num:
                    w, v = dp[bitset-2**item_num]
                    if w+item_w <= W:
                        dp[bitset] = (w+item_w, v+item_v)
                    break

        dp.sort()
        l, maxv, inf = [(0, 0)], 0, float("inf")
        append = l.append
        for item, (w, v), (nextw, _) in zip(dp, dp, dp[1:]+[(inf, inf)]):
            if w < nextw and maxv < v:
                append(item)
                maxv = v
        return l

    dp1 = bitdp(a[:N//2])
    dp2 = bitdp(a[N//2:])

    inf = float("inf")
    result = 0
    for w, v in dp1:
        total = v + dp2[bisect_right(dp2, (W-w, inf))-1][1]
        if result < total:
            result = total

    print(result)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 181732
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque

def main():
    K = int(input())
    # cnt = 0
    # dq = deque(['1','2','3','4','5','6','7','8','9'])
    # while cnt < K:
    #     cnt += 1
    #     d = dq.popleft()
    #     a = int(d[-1])
    #     if a == 0:
    #         dq.append(d+str(0))
    #         dq.append(d+str(1))
    #     elif a == 9:
    #         dq.append(d+str(8))
    #         dq.append(d+str(9))
    #     else:
    #         for i in range(a-1, a+2):
    #             dq.append(d+str(i))
    # print(d)

    runrun_lst = []
    def rec(num_of_digit, runrun_val):
        runrun_lst.append(runrun_val)
        if num_of_digit == 10: return
        for i in range(-1, 2):
            add = (runrun_val%10) + i
            if 0 <= add <= 9: rec(num_of_digit+1, runrun_val*10+add)

    for v in range(1, 10):
        rec(1, v)
    runrun_lst.sort()
    print(runrun_lst[K-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 19680
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	auto start = high_resolution_clock::now(); 

	int n;
	cin >> n;
	vector<int> l(n);

	int max_side = -1;
	int sum = 0;
	for(int i = 0 ; i < n ; i++){
		cin >> l[i];
		max_side = max(max_side, l[i]);
		sum += l[i];
	}

	sum = sum - max_side;

	if (max_side < sum ){
		cout << "Yes";
	}
	else{
		cout << "No";
	}

	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 256
function Main(input) {
  input = input.split('');
  
  var total = 0;
  
  for(var i = 0; i < input.length-1 ; i++){
  	total = total + parseInt(input[i], 10);
  }
  
  console.log("%s", total % 9 ? "No" : "Yes");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 34692
import sys
input = sys.stdin.readline

mod = 10**9+7

n,k = map(int,input().split())
res = 0

for i in range(k,n+2):
    mi = (i-1)*i//2
    ma = (n+n-i+1)*i//2

    res = (res+ma-mi+1)%mod

print(res)

Measured memory_bytes: 63484
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}
unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}
int tow(int n) {//2のn乗を求めるらしい
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
	//dominoに借りたやつです
}
/*
  for A以上B未満でI探索 for (int I = A; i <= B; i++)

  string s = to_string(i);　iをstringでsに変換

  char　小文字のほうが32大--------------------大文字と小文字の境=93

  大文字→小文字 文字列のn文字目を大文字で出力→ (char)toupper(a[n])

  pow(a,b) → aのb乗を求める

  s1.erase(n) 文字列s1の、n文字目以降削除
  */
int a=0, b=0, c = 0;
string s = "";

int main(void) {
	//vector,set,map,stack,queue,deque,priority_queue

	int n;
	cin >> n;
	vint a(n);
	vcin(a, n);
	sort(a);
	cout << a[n / 2] - a[n / 2 - 1] << rt;

	please AC;
}

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

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

    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        ans += min(x - 0, k - x) * 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int       long long
#define w(x)      int x; cin>>x; while(x--)

void oj()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    return;
}

int32_t main()
{
    // oj();
    int a,b;
    cin>>a>>b;
    cout<<a*b;
    return 0;
}

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

int main(void){
  vector<int> N(4);
  for(int i = 0; i < 4; i++) cin >> N[i];
  std::sort(N.begin(), N.end());
  if(N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9){
    cout << "YES" << endl;
  }else{
    cout << "NO"  << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
s = [0]*n
sum = 0

for i in range(n):
    sum+=a[i]
    s[i]=sum
min = 2000000000
for i in range(n-1):
    d=abs(s[i]*2-s[n-1])
    if d < min:
        min =d
print(min)


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

void trace(int A[], int N) {
    for (int i = 0; i < N; i++){
        if (i > 0){
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
}

void bubbleSort(int A[], int N){
    int flag = 1;
    int cnt = 0;
    int tmp;
    for(int i=0;flag;i++){
        flag = 0;
        for(int j= N-1; j >= i+1; j--){
            if (A[j] < A[j-1]){
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                cnt++;
            }
        }
    }
    trace(A, N);
    cout << cnt << endl;
} 

int main(){
    int N;
    cin >> N;
    int A[N];
    for (int i=0; i < N; i++) {
        cin >> A[i]; 
    }
    bubbleSort(A, N);
    return 0;
}


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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i = a; i < b; i++)

int V, E;
vvi conn(100002);
vi vis(100002);
vb trail(100002);
vb cut(100002);

int dfs_min(int v, int depth, int parent) {
  if(vis[v] > 0) return vis[v];
  vis[v] = depth;
  trail[v] = true;

  int minHit = depth;
  rep(i,0,(int)conn[v].size()) {
    if(conn[v][i] != parent && (vis[conn[v][i]] == 0 || trail[conn[v][i]])) {
      int hit = dfs_min(conn[v][i], depth+1, v);
      minHit = min(minHit, hit);
      if(hit >= depth && conn[v].size() > 1)
	cut[v] = true;
    }
  }

  trail[v] = false;
  return minHit;
}

int main() {
  cin >> V;
  cin >> E;
  rep(e,0,E) {
    int s, t;
    cin >> s;
    cin >> t;
    conn[s].push_back(t);
    conn[t].push_back(s);
  }

  dfs_min(0, 1, -1);
  if(V > 1) {
    cut[0] = false;
    bool remember = cut[1];
    fill(all(vis), 0);
    dfs_min(1, 1, -1);
    cut[1] = remember;
  }

  rep(v,0,V)
    if(cut[v])
      cout << v << '\n';
}



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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;

  cout << s[0] << s[1] << s[2] << '\n';
  return 0;
}

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

map<string,int> M;

int str2int(string S){
    if(M.find(S)==M.end()){
        int n = M.size();
        M[S]=n;
    }
    return M[S];
}

int E[200][200];//[a][b]=a to b

int main(){
    int N;
    while(cin>>N,N){
        fill(E[0],E[200],10000);
        M.clear();
        for(int i=0;i<N;i++){
            string S;
            cin>>S;
            for(int c=0;c<S.size();c++){
                if(S[c]=='-'){
                    string S1=S.substr(0,c);
                    string S2=S.substr(c+1,S.size()-c-1);
                    int i1=str2int(S1);
                    int i2=str2int(S2);
                    E[i1][i2]=1;
                    break;
                }
            }
        }
        int m = M.size();
        cout<<m<<endl;
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                if(E[i][j]==1||E[j][i]==1) continue;
                //cond1
                bool b=false;
                for(int k=0;k<m;k++){
                    if(k==i||k==j) continue;
                    if((E[i][k]==1||E[k][i]==1)&&(E[j][k]==1||E[k][j]==1)){
                        b=true;
                        break;
                    }
                }
                //cond2,3
                for(int k=0;k<m;k++){
                    if(k==i||k==j) continue;
                    if((E[k][i]==1&&E[j][k]==1)||(E[i][k]==1&&E[k][j]==1)){
                        b=false;
                        break;
                    }
                }
                if(b) E[i][j]=E[j][i]=0;
            }
        }
        //WF
        for(int i=0;i<m;i++) E[i][i]=0;
        for(int k=0;k<m;k++){
            for(int i=0;i<m;i++){
                for(int j=0;j<m;j++){
                    E[i][j]=min(E[i][j],E[i][k]+E[k][j]);
                }
            }
        }
        int Q;
        cin>>Q;
        for(int i=0;i<Q;i++){
            string S;
            cin>>S;
            for(int c=0;c<S.size();c++){
                if(S[c]=='-'){
                    string S1=S.substr(0,c);
                    string S2=S.substr(c+1,S.size()-c-1);
                    int i1=str2int(S1);
                    int i2=str2int(S2);
                    if(i1>=m||i2>=m||E[i1][i2]%2==0){
                        cout<<"NO"<<endl;
                    }else{
                        cout<<"YES"<<endl;
                    }
                    break;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3264
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define int long long
using namespace std;
const int maxn = 1e5+10;
const int inf = 1e15;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
vector<pair<int,int> > p[maxn];
priority_queue<pair<int,int> > q;
int ans[maxn];
signed main(){
	n=read();m=read();
	for(register int i=2;i<=n;i++)p[i].push_back(make_pair(i-1,0ll));	
	for(register int i=1;i<=m;i++){
		int l=read(),r=read(),c=read();
		p[l].push_back(make_pair(r,c));
	}
	for(register int i=1;i<=n;i++)ans[i]=inf;
	q.push(make_pair(0,1));
	ans[1]=0;
	while(!q.empty()){
		int x=q.top().first,y=q.top().second;q.pop();
		if(ans[y]<x)continue;
		int len=p[y].size();
		for(register int i=0;i<len;i++){
			if(ans[p[y][i].first]>ans[y]+p[y][i].second){
				ans[p[y][i].first]=ans[y]+p[y][i].second;
				q.push(make_pair(-ans[p[y][i].first],p[y][i].first));
			}
		}
	}
	if(ans[n]==inf)puts("-1");
	else printf("%lld\n",ans[n]);
	return 0;
}

Measured memory_bytes: 10104
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));

int main() {

	ll n;
	vector<ll> a(5);
	cin >> n;
	ll ans = 5, mini = n;

	rep(i, 0, 5) {
		cin >> a[i];
		mini = min(mini, a[i]);
	}

	ans += (n - 1) / mini;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

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


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};


int main(){
    IOS;
    make2(ll,a,b); make(ll,x);
    ll ans=b/x;
    if(a>0) ans-=(a-1)/x;
    else ans++;
    cout<<max(0ll,ans)<<endl;



    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N) cin >> p.at(i);
  sort(p.begin(), p.end()); 
  
  int sum = 0;
  rep(i, K) sum += p.at(i);
  cout << sum << endl;
}


Measured memory_bytes: 3608
package main

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

func main() {
	buf.Split(bufio.ScanWords)

	s := scanString()
	if s == "AAA" || s == "BBB" {
		fmt.Printf("%s", "No")
		return
	}
	fmt.Printf("%s", "Yes")
}

var buf = bufio.NewScanner(os.Stdin)

func scanInt() int {
	buf.Scan()
	i, _ := strconv.Atoi(buf.Text())
	return i
}

func scanInts(n int) []int {
	a := make([]int, n)
	for k, _ := range a {
		a[k] = scanInt()
	}
	return a
}

func scanString() string {
	buf.Scan()
	return buf.Text()
}

func scanStrings(n int) []string {
	a := make([]string, n)
	for k, _ := range a {
		a[k] = scanString()
	}
	return a
}


Measured memory_bytes: 640
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

struct Restaurant {
  string city;
  int point;
  int index;
};

static bool greaterR(Restaurant a, Restaurant b) {
  bool f = true;
  if (a.city > b.city) {
    f = false;
  } else if (a.city == b.city) {
    f = a.point > b.point;
  }

  return f;
}

void main() {
  int n = readln.chomp.to!(int);
  Restaurant[] restaurants;

  for (int i = 0; i < n; i++) {
    string[] buf = readln.chomp.split;
    restaurants ~= Restaurant(buf[0], buf[1].to!(int), i + 1);
  }

  sort!(greaterR)(restaurants);

  foreach (e; restaurants) {
    e.index.writeln;
  }
}


Measured memory_bytes: 256
import copy
N = int(input())
X = list(map(int, input().split()))
tmp_X = copy.deepcopy(X)
tmp_X.sort()
m1 = tmp_X[N // 2]
m2 = tmp_X[N // 2 - 1]
for x in X:
    if x < m1:
        print(m1)
    else:
        print(m2)

Measured memory_bytes: 32568
n,m = map(int,input().split())
tmp,p,s = [],[],[]

for i in range(m):
  tmp = input().split()
  p.append(int(tmp[0])-1)
  s.append(tmp[1])

pas = [0] * n
pena = [0] * n

for i in range(m):
  if pas[p[i]] == 0:
    if s[i] == 'WA':
      pena[p[i]] += 1
    elif s[i] == 'AC':
      pas[p[i]] = 1


print('{} {}'.format(sum(pas),sum([pas[i]*pena[i] for i in range(n)])))


Measured memory_bytes: 16088
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;


int main()
{
	int N;
	vector<string> S;
	int count = 1;

	cin >> N;

	for(int i=0; i<N; i++){
		string tmp;
		cin >> tmp;
		S.push_back(tmp);
	}

	sort(S.begin(), S.end());

	for(int i=0; i<N-1; i++){
		if(S[i] != S[i+1]){
			count++;
		}
	}
	 
	cout << count;

	return 0;
	
}

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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t,n;
    vector<int>v;
    cin>>t;
    while(t--)
    {
        cin>>n;
        if(!(n%2))
        {
            v.push_back(n);
        }
    }
    for(int i=0;i<v.size();i++)
    {
        if((v[i]%3!=0)&&(v[i]%5!=0))
        {
            cout<<"DENIED"<<endl;
            return 0;
        }
    }
    cout<<"APPROVED"<<endl;
    return 0;
}

Measured memory_bytes: 256
import fractions

A,B,C,D = map(int,input().split())

E =C*D//fractions.gcd(C,D)

if A%C == 0:
    C_div = B//C - A//C + 1
else:
    C_div = B//C - A//C

if A%D == 0:
    D_div = B//D - A//D + 1
else:
    D_div = B//D- A//D


if A%E == 0:
    CandD_div  = B//E - A//E + 1
else:
    CandD_div  = B//E- A//E


ans = B - A + 1 - (C_div + D_div - CandD_div)
print(ans)


Measured memory_bytes: 5052
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  n = InputLine.to_i
  x = InputLine.to_ia

  a = [1e+8.to_i] * (n + 1)
  n.times do |i|
    a[i + 1] = [x[i], a[i]].min
  end
  
  c = 0
  n.times do |i|
    c += 1 if a[i] > x[i]
  end
  puts c.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 1; i <= N; i++){
        cin >> A[i];
    }
    vector<int> hani(N+1);
    hani[0] = 0;
    for(int i = 0; i < N; i++){
        hani[i+1] = max(A[i+1], hani[i]);
    }

    vector<int> gyaku(N+1);
    gyaku[N+1] = 0;
    for(int i = N; i > 0; i--){
        gyaku[i] = max(A[i], gyaku[i+1]);
    }

    for(int i = 1; i <= N; i++){
        int ans = max(hani[i-1], gyaku[i+1]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  string ans = "Yes";
  for(int i = 0; i < a; i++)
    if(s[i] == '-')
      ans = "No";
  if(s[a] != '-')
    ans = "No";
  for(int i = a+1; i < a+b+1; i++)
    if(s[i] == '-')
      ans = "No";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#import numpy as np
#import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    S = first_input[0]
    W = first_input[1]

    if W>=S:
        print("unsafe")
    else:
        print("safe")

if __name__ == '__main__':
    main()


Measured memory_bytes: 61840
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


const int DIV[3] = {2, 3, 5};

ll solve(ll n, const vector<ll> &coin, ll d, map<ll, ll> &memo) {
    if (memo.count(n)) return memo[n];
    if (n == 0) return 0;
    if (n == 1) return d;
    
    ll res = 1e18;
    if (n <= 1000000000000000000 / d) chmin(res, n * d);
    rep(i, 3) {
        ll down = n / DIV[i] * DIV[i];
        if (down == 0) chmin(res, n * d);
        else chmin(res, (n - down) * d + coin[i] + solve(down / DIV[i], coin, d, memo));
        ll up = (n + DIV[i] - 1) / DIV[i] * DIV[i];
        chmin(res, (up - n) * d + coin[i] + solve(up / DIV[i], coin, d, memo));
    }
    return memo[n] = res;
}

int main() {
    int t;
    cin >> t;
    rep(_, t) {
        vector<ll> coin(3);
        ll n, d;
        cin >> n >> coin >> d;
        map<ll, ll> memo;
        cout << solve(n, coin, d, memo) << endl;
    }
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main() {
  ll n; cin>>n;
  double a[n];
  rep(i,n) cin>>a[i];
  double sum =0;

  rep(i,n) sum+=1/a[i];
  cout<<fixed<<setprecision(5)<<1/sum<<endl;
  
}


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

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10);x/=10;}reverse(all(res)); return res;}

void solve() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans=0;
  rep(i,101){
    if(a<=i&&i<=b&&c<=i&&i<=d) ans++;
  }
  if(ans>0) ans--;
  out(ans);
}

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


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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    string s;
    cin >> s;
    for(char x:s){
        cout << (char)((x-'A'+n)%26 +'A');
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
K = int(input())
A, B = map(int, (input().split()))
lst = []
for i in range(A, B+1):
    if i % K == 0:
        result = "OK"
        lst.append(result)
        break
    else:
        result = "NG"
        lst.append(result)
print(lst[-1])

Measured memory_bytes: 9052
n,m=gets.split.map &:to_i
a=[nil]*n
b=[]
n.times{|i|a[i]=gets.split.map &:to_i}
m.times{|i|b.push(gets.to_i)}
n.times{|i|s=0
m.times{|j|s+=a[i][j]*b[j]}
p s}

Measured memory_bytes: 8824
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
f = [0]
for i in range(1,400):
    f.append(0)
for i in range(400,800):
    f.append(1)
for i in range(800,1200):
    f.append(2)
for i in range(1200,1600):
    f.append(3)
for i in range(1600,2000):
    f.append(4)
for i in range(2000,2400):
    f.append(5)
for i in range(2400,2800):
    f.append(6)
for i in range(2800,3200):
    f.append(7)
for i in range(3200,4801):
    f.append(-1)
n = I()
a = LI()
k = [1 for i in range(8)]
s = 0
t = 0
for i in a:
    if f[i] >= 0:
        if k[f[i]]:
            k[f[i]] = 0
            s += 1
    else:
        t += 1
print(max(s,1),min(s+t,n))
"""

#D
n = I()
s = S()
ans = []
k = 0
for i in range(n):
    if s[i] == ")":
        k += 1
    else:
        if k > 0:
            ans += ["("]*k
            k = 0
        k -= 1
if k < 0:
    ans += [")"]*(-k)
else:
    ans = ["("]*k+ans
i = 0
if len(ans) == 0:
    for i in s:
        print(i,end = "")
else:
    while ans[i] == "(":
        i += 1
        if i == len(ans):break
    for j in range(n):
        ans.insert(i+j,s[j])
    for i in ans:
        print(i,end = "")
print()
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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


int func(string A, string B){
	int ans = 0;

	if(A.length() == B.length())
	{
		for(int i=0;i<A.length();i++)
		{
			if((A[i] - '0') > (B[i] - '0'))
			{
				ans =1;
				break;
			}
			else if((A[i] - '0') < (B[i] - '0'))
			{
				ans = 2;
				break;
			}
		}
	}
	else if(A.length() > B.length()){
		ans = 1;
	}
	else
	{
		ans = 2;
	}

	return ans;
}

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

	switch(func(A,B)){
		case 0:
			cout << "EQUAL" <<endl;
			break;
		case 1:
			cout << "GREATER" << endl;
			break;
		case 2:
			cout << "LESS" << endl;
			break;
		default:
			break;

	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

int main(){
  int n,a;
  cin>>n>>a;
  n=n%500;
  if(n<=a)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
N,X = map(int,input().split())
L = [int(_) for _ in input().split()]
INF = 10**12
D = [INF]*(N+1)
D[0] = 0
for i in range(1,N+1):
    D[i] = D[i-1] + L[i-1]
n = [1 for _ in D if _ <= X]
print(sum(n))

Measured memory_bytes: 3064
#include <stdio.h>
#define N 36
 
typedef struct card
{
    char moji;
    char num;
}cards;
 
int main(){
  int n,i,j,flag,minj;
  cards A[N],B[N],temp;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%c",&A[i].moji,&A[i].num);
  }
 
  for(i=0;i<n;i++)B[i]=A[i];
 
      /*??????????????????*/
    for(i=0;i<n;i++){
      flag = 1;
      while(flag){
        flag = 0;
        for(j=n-1;1<=j;j--){
          if(B[j].num<B[j-1].num){
            temp = B[j-1];
            B[j-1] = B[j];
            B[j] = temp;
            flag = 1;
          }
        }
      }
    }
 
  for(i=0;i<n-1;i++)printf("%c%c ",B[i].moji,B[i].num);
    printf("%c%c",B[n-1].moji,B[n-1].num);
  printf("\nStable\n");
 
  /*??????¬?????????§????????????*/
  for(i=0;i<n-1;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(A[j].num < A[minj].num){
        minj = j;
      }
    }
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
  }
 
  for(i=0;i<n-1;i++)printf("%c%c ",A[i].moji,A[i].num);
  printf("%c%c",A[n-1].moji,A[n-1].num);
    flag = 1;
  for(i=0;i<n;i++)if(A[i].moji!=B[i].moji) flag = 0;
    if(flag)printf("\nStable\n");
    else printf("\nNot stable\n");
 
  return 0;
}

Measured memory_bytes: 2752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[] = sc.next().split("");
		String b[] = sc.next().split("");
		String c[] = sc.next().split("");
		if (a[a.length - 1].equals(b[0]) && b[b.length - 1].equals(c[0]))
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}

Measured memory_bytes: 22612
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    int a, b; cin >> a >> b;
    if (a < b) puts("a < b");
    else if (a > b) puts("a > b");
    else puts("a == b");
}


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

int main() {
  int a, b;
  string ans;
  cin >> a >> b;
  if((a % 2 == 0) || (b % 2 == 0)) {
    ans = "Even";
  }
  else {
    ans = "Odd";
  }
  cout << ans << endl;
}


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

#define ln "\n"
#define SORT(X) sort(X.begin(), X.end())
#define SORTi(X) sort(X.begin(), X.end(), greater<ll>())
#define REP(x, a, b) for (auto x = a; x <= b; x++)
#define REPi(x, b, a) for (auto x = b; x >= a; x--)
#define REPit(x, A) for (auto x = A.begin(); x != A.end(); x++)
#define REPr(x, A) for (auto x : A)
#define ll long long
#define ull unsigned long long
#define PB push_back
#define EB emplace_back
#define UMP unordered_map
#define UST unordered_set

using namespace std;

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

    int A, B, C;
    cin >> A >> B >> C;
    int tmp = 0;
    REP(i, 1, B)
    {
        tmp = (A * i);
        if (tmp % B == C)
        {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end



int main(){
   ll a,b,c; scanf("%lld%lld%lld",&a,&b,&c);
   if(a%2==0||b%2==0||c%2==0)puts("0");
   else printf("%lld\n",min({a*b,b*c,c*a}));
   return 0;
}


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

using namespace std;
typedef long long ll;
int maxn = 1e8;
int T;

int main() {
    int a,b,n;
    cin>>n;
    a=n%10;
    b=n/10;
    if(a==9||b==9)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

llint n, Q;
llint a[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	
	llint l, r;
	for(int q = 0; q < Q; q++){
		cin >> l >> r;
		cout << upper_bound(a+1, a+n+1, r) - lower_bound(a+1, a+n+1, l) <<endl;
	}
	return 0;
}


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

int main(int argc, char* argv[]) {
  int N, M, C;
  std::cin >> N >> M >> C;
  std::vector<int> Bs(M);
  for (auto&& B : Bs) {
    std::cin >> B;
  }
  int A;
  int cnt = 0;
  for (int j = 0; j < N; j++) {
    int sum = C;
    for (int i = 0; i < M; i++) {
      std::cin >> A;
      sum += A * Bs[i];
    }
    if (sum > 0) {
      cnt++;
    }
  }
  std::cout << cnt << std::endl;
  return 0;
}


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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    ll a;
    ll r = 0;
    ll g = 0;
    ll b = 0;
    ll ans = 1;
    REP(i, n) {
        cin >> a;
        if (a == 0) {
            if (r == 0) {
                r++;
                ans *= 3LL;
                ans %= MOD;
            }
            else if (g == 0) {
                g++;
                ans *= 2LL;
                ans %= MOD;
            }
            else if (b == 0) b++;
            else ans = 0;
        } else {
            ll x = 0;
            bool z = false;
            if (r == a) {
                x++;
                if (!z) {
                    z = true;
                    r++;
                }
            }
            if (g == a) {
                x++;
                if (!z) {
                    z = true;
                    g++;
                }
            }
            if (b == a) {
                x++;
                if (!z) {
                    z = true;
                    b++;
                }
            }
            ans *= x;
            ans %= MOD;
        }
    }
    cout << ans << EOL;

}


Measured memory_bytes: 256
li = [ int(it) for it in input()]
K = int(input())


big = 1e19

def pows(v,p):
  _p = p
  r = 1
  t = v
  for i in range(100000):
    if (r>big):
      return big
    if (_p%2)==1:
      r *= t
    _p//=2
    if (_p==0):
      return r
    t **= 2

m = 0
for it in li:
  m += pows(it,5000000000000000)
  if (m>=K):
    print (it)
    break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x))

using namespace std;

const int MOD = (int) 1e9 + 7;

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

string str;
int fr[26];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> str;
    for(auto it : str) {
        fr[it - 'a']++;
    }
    int ans = 1;
    for(i = 0; i < 26; i++) {
        ans = (1LL * ans * (fr[i] + 1)) % MOD;
    }
    ans += MOD - 1;
    mod(ans);
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int dir(char[],char[]);
int main(){
    int n,a,t=0,h=0;
    char T[108],H[108];
    scanf("%d",&n);

    for(int i=0;i<n;i++){
        scanf("%s %s",T,H);
        a=dir(T,H);
        if(a==0){
            t+=3;
        }else if(a==1){
            h+=3;
        }else{
            t++;
            h++;
        }
    }

    printf("%d %d\n",t,h);
    return 0;
}

int dir(char x[],char y[]){
    int c=0;
    while(x[c]!='\0'||y[c]!='\0'){
        if(x[c]<y[c]){
            return 1;
        }else if(x[c]>y[c]){
            return 0;
        }else{
            c++;
            continue;
        }
        c++;
    }
    return 2;
}


Measured memory_bytes: 2076
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
//#include<bits/stdc++.h>
#define int long long
#define all(x) begin(x), end(x)
#define SZ(x) ((int)(x).size())
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define F first
#define S second

#define de(x) if(x && x == MODE)
#define MODE 1

using namespace std;

typedef pair<int, int> pii;

const int INF = 1e18;
const int maxn = 1e5 + 7;


vector<int> A, B;
int32_t main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x, y;
		cin >> x >> y;
		A.PB(x + y); 
		B.PB(x - y);
	}
	sort (all(A));
	sort (all(B));
	
	cout << max(A.back() - A.front(), B.back() - B.front()) << "\n";
}


Measured memory_bytes: 6232
import itertools

n,m = map(int,input().split())
E = [list(map(int,input().split())) for i in range(m)]
G = [[] for i in range(n)]
for i in range(m):
    G[E[i][0]-1] += [E[i][1]-1]
    G[E[i][1]-1] += [E[i][0]-1]

ans = 0
for p in itertools.permutations(range(1,n)):
    if p[0] in G[0] and all([p[i] in G[p[i-1]] for i in range(1,n-1)]):
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

int main(){
	int n;

	cin >> n;
	
	vector<int> p(n, 0);
	for (size_t i = 0; i < n; ++i) {
		int tmp;
		cin >> tmp;
		p[i] = tmp;
	}

	vector<int> sorted_p;
	sorted_p = p;
	sort(begin(sorted_p), end(sorted_p));

	int cnt = 0;
	for (size_t i = 0; i < n; ++i) {
		if (p[i] != sorted_p[i]) {
			cnt++;
		}
	}

	if (cnt == 2 || cnt == 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  string s;
  cin >> s;

  if( s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int limit = 50;

int n;  //頂点数
int m;  //辺数
int a[limit], b[limit];

bool graph[limit][limit];  //グラフの隣接行列
bool visited[limit];  // visited[i] : 頂点iを訪問済みかどうか

void dfs(int v) {
    //頂点vを訪問済みにする
    visited[v] = true;
    //vに隣接している未訪問の頂点v2を調べる
    rep(v2, n) {
        //vに隣接していなかったらダメ
        if(!graph[v][v2]) {
            continue;
        }
        //訪問済みだったらダメ
        if(visited[v2]) {
            continue;
        }
        //v2が条件を満たすときは新たにv2からdfsを始める
        dfs(v2);
    }
}

int main() {
    cin >> n >> m;

    //無向グラフの入力
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    int ans = 0;
    //取り除く辺を全探索
    rep(i, m) {
        //a[i]とb[i]を結ぶ辺を取り除く
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

        //頂点をすべて未訪問にする
        rep(j, n) {
            visited[j] = false;
        }

        //頂点0からdfsをスタート
        dfs(0);

        bool bridge = false;
        //dfs後に未訪問の頂点があれば取り除いた辺は橋
        rep(j, n) {
            if(!visited[j]) {
                bridge = true;
            }
        }

        //取り除いた辺が橋だったらansを1増やす
        if(bridge) {
            ans++;
        }

        //a[i]とb[i]を結ぶ辺をつなぐ
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

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

Measured memory_bytes: 256