akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef tuple<long long, long long, int> P;
#define get(a, b) get<b>(a)
struct edge{
    int to;
    long long cost;
    long long coin;
};
struct dijkstra{//priority_queueを用いる
    vector<vector<edge>> G;
    vector<vector<long long>> d;
    long long INF;
    int n;
    dijkstra(int N){
        G.resize(N);
        INF = 1e18;
        d.resize(N, vector<long long> (3000, INF));
        n = N;
    }
    void add(int x, int y, long long cost1, long long coin){
        edge e1 = {x, cost1, coin}, e2 = {y, cost1, coin};
        G[x].push_back(e2);
        G[y].push_back(e1);

    }
    void add2(int x, long long cost1, long long coin){
        edge e1 = {x, cost1, coin};
        G[x].push_back(e1);
    }
    void solve(int S){
        priority_queue<P, vector<P>, greater<P>> que;
        int s = 0;//スタート地点
        d[s][S] = 0;
        que.push(P(0, S, 0));
        while(!que.empty()){
            P p = que.top();
            que.pop();
            int v = get(p, 2);
            long long now = get(p, 0);
            if(d[v][get(p, 1)] < now) continue;
            long long temp = get(p, 1);
            for(edge e: G[v]){
                if(v != e.to && e.coin <= temp && d[e.to][temp - e.coin] > now + e.cost){
                    d[e.to][temp - e.coin] = now + e.cost;
                    que.push(P(now + e.cost, temp - e.coin, e.to));
                }
                else if(v == e.to && temp + e.coin < 2700 && d[e.to][temp + e.coin] > now + e.cost){
                    d[e.to][temp + e.coin] = now + e.cost;
                    que.push(P(now + e.cost, temp + e.coin, e.to));
                }
            }
        }
    }
};
int main(){
    int N, M, S;
    cin >> N >> M >> S;
    if(S > 2700) S = 2700;
    dijkstra dijk(N);
    for(int i = 0; i < M; i++){
        int u, v;
        long long A, B;
        cin >> u >> v >> A >> B;
        u--;
        v--;
        dijk.add(u, v, B, A);
    }
    for(int i = 0; i < N; i++){
        long long C, D;
        cin >> C >> D;
        dijk.add2(i, D, C);
    }
    dijk.solve(S);
    for(int j = 1; j < N; j++){
        long long ans = dijk.INF;
        for(int i = 0; i < 3000; i++){
            if(dijk.d[j][i] != dijk.INF) ans = min(ans, dijk.d[j][i]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 7416
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    m, n, k = map(int, input().split())
    si, sj, ti, tj = map(lambda x : int(x) - 1, input().split())
    grid = [input() for _ in range(m)]

    dist = [[INF] * n for _ in range(m)]
    dist[si][sj] = 0
    D = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    queue = deque([(si, sj)])
    while queue:
        i, j = queue.popleft()
        for di, dj in D:
            for s in range(1, k + 1):
                ni, nj = i + s * di, j + s * dj
                if not (0 <= ni < m and 0 <= nj < n):
                    break
                if grid[ni][nj] == '@':
                    break
                if dist[ni][nj] <= dist[i][j]:
                    break
                if dist[ni][nj] > dist[i][j] + 1:
                    dist[ni][nj] = dist[i][j] + 1
                    queue.append((ni, nj))

    ans = dist[ti][tj]
    if ans == INF:
        ans = -1
    print(ans)
resolve()

Measured memory_bytes: 101644
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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

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

	int n,m; cin >> n >> m;
	vector<int> a(m);
	int sum = 0;
	rep(i,m){ cin >> a[i]; sum += a[i];}
	cout << ((sum > n) ? -1 : n - sum) << endl;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
bool unb(string s){
  set<char>se;
  se.insert(s[0]);
  se.insert(s[1]);
  se.insert(s[2]);
  if(se.size()<=2)return true;
  else return false;
}

int main(){
  string s;
  cin >> s;
  int n = s.length();
  bool chk = false;
  int left = -1;
  for(int i = 0;i<n-2;i++){
    if(unb(s.substr(i,3))){
      chk = true;
      left = i+1;
      break;
    }
  }
  if(n==2 && s[0]==s[1])cout << 1 << " "<<2 << endl;
  else if(chk){
    cout << left << " " << left+2 << endl;
  }else cout << -1 << " "<<-1<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;


int main(void)
{
	string S; cin >> S;
	int ans = 0;
	char tmp = S[0];
	rep(i, 1, S.length()) {
		if (S[i] != tmp) {
			ans++;
			tmp = S[i];
		}
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

void poll(int N, vector<string>& S) {
	int max_vote = 0;
	vector<string> votes;
	unordered_map<string, int> freq;
	for (string& vote: S)
		max_vote = max(++freq[vote], max_vote);
	for (auto& it: freq)
		if (it.second == max_vote)
			votes.push_back(it.first);
	sort(votes.begin(), votes.end());
	for (string& vote: votes)
		cout << vote << endl;
}

int main() {
	int N;
	cin >> N;
	vector<string> S(N);
	for (int i = 0; i < N; i++)
		cin >> S[i];
	poll(N, S);
	return 0;
}

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


int main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> v(H);
	for(int i=0; i<H; ++i) cin >> v[i];
	int ans=0;
	for(int i=0; i<(1<<H); ++i){
		for(int j=0; j<(1<<W); ++j){
			int cnt=0;
			for(int h=0; h<H; ++h){
				for(int w=0; w<W; ++w){
					if((i&(1<<h)) && (j&(1<<w)) && v[h][w]=='#') ++cnt;
				}
			}
			if(cnt==K) ++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
long long n, m, i, j, k, t, h, l, w;
int main(){
	cin>>n;
	for(h=1;h<=3500;h++){
		for(l=1;l<=3500;l++){
			if(4*h*l-n*h-n*l<=0) continue;
			if((n*h*l)%(4*h*l-n*h-n*l)==0){
				w=(n*h*l)/(4*h*l-n*h-n*l);
				cout<<w<<" "<<h<<" "<<l;
				return 0;
			}
		}
	}
	return 0;
}

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

const int MAX_N = int(1e6) + 10;

int n;
char s[MAX_N];
int cnt[3];

int main() {
	scanf("%d%s", &n, s);
	bool have_one = false;
	for (int i = 0; i < n; ++i) {
		if (s[i] == '2')
			have_one = true;
		cnt[s[i] - '1'] += ((n - 1) & i) == i;
	}
	if (cnt[1] & 1)
		puts("1");
	else {
		if (!have_one && (cnt[2] & 1))
			puts("2");
		else
			puts("0");
	}
}

Measured memory_bytes: 4668
/*
17D8101031C 杉山　祥吾 ID:keisei334 C++
*/

#include <iostream>

using namespace std;

#define N 100
#define M 100

int main(void){
  int X[N+1],A[M+1],n,m;

  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>X[i];
  }

  cin>>m;
  for(int i=1;i<=m;i++){
    cin>>A[i];
  }

  for(int i=1;i<=m;i++){
    if(X[A[i]]!=2019 && X[A[i]+1]-X[A[i]]!=1){
      X[A[i]]++;
    }
  }

  for(int i=1;i<=n;i++){
    cout<<X[i]<<"\n";
  }
  
  return 0;
}

/*実行結果
3
2 3 6
2
1 3
2
3
7

2
1 2016
4
2 2 2 2
1
2019

4
1001 1002 1003 1004
7
1 2 3 4 3 2 1
1002
1003
1004
1005
*/



Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  int x=0, y=0;
  cin >> n;

  for (int i=1; i <= n; i++)
  {
    x += 800;
    if (i%15 == 0)
    {
      y += 200;
    }
  }
  cout << x - y << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int P[N];
  
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  
  int minVal = INT_MAX;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if( P[i] <= minVal ){
      count++;
    }
    minVal = min(minVal, P[i]);
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include<queue>
#include<queue>
#define P pair<int,int>
using namespace std;

queue<P>operator +(queue<P>a, queue<P>b) {
	while (b.size()) {
		a.push(b.front()); b.pop();
	}
	return a;
}
queue<P>L;
int main() {
	int a;
	while (cin >> a, a) {
		int b, c, d, e; scanf("%d%d%d%d", &b, &c, &d, &e);
		queue<P>tmp;
		swap(L, tmp);
		L.push(P(1, a));
		for (int f = 0; f < b; f++) {
			int g, h; scanf("%d%d", &g, &h);
			queue<P>A, B, C;
			int sum = 0, j = 0;
			while (L.size()) {
				P i = L.front(); L.pop();
				sum += i.second - i.first + 1;
				if (j < g&&sum > g) {
					if (j < h&&sum > h) {
						A.push(P(i.first, i.first + (g - j) - 1));
						B.push(P(i.first + (g - j), i.first + (h - j) - 1));
						C.push(P(i.first + (h - j), i.second));
					}
					else {
						A.push(P(i.first, i.first + (g - j) - 1));
						B.push(P(i.first + (g - j), i.second));
					}
				}
				else {
					if (j < h&&sum > h) {
						B.push(P(i.first, i.first + (h - j) - 1));
						C.push(P(i.first + (h - j), i.second));
					}
					else {
						if (sum > h) {
							C.push(i);
						}
						else if (sum > g) {
							B.push(i);
						}
						else {
							A.push(i);
						}
					}
				}
				j += i.second - i.first + 1;
			}
			L = C + B + A;
		}
		int x = 0, y = 0;
		vector<P>W;
		while (L.size()) {
			P t = L.front(); L.pop();
			x += t.second - t.first + 1;
			if (x <= d&&x >= c) {
				if (y <= d&&y >= c) {
					W.push_back(P(t.first, t.second));
				}
				else {
					W.push_back(P(t.second - (x - c), t.second));
				}
			}
			else {
				if (y <= d&&y >= c) {
					W.push_back(P(t.first, t.first + d - y - 1));
				}
			}
			y += t.second - t.first + 1;
		}
		int ans = 0;
		for (P i : W) {
			ans += max(0, min(e, i.second) - i.first + 1);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3184
A, B, C, K = map(int, input().split())
Ts = 0
sA = K - A
if sA > 0:
    sB = sA - B
    if sB > 0:
        sC = sB - C
        if sC < 0:
            Ts = ((K - sA) * 1) + ((sA - sB) * 0) + (sB * -1)
        elif sC == 0:
            Ts = ((K - sA) * 1) + ((sA - sB) * 0) + (sB * -1)
    elif sB == 0:
        Ts = ((K - sA) * 1) + (sB * 0)
    else:
        Ts = ((K - sA) * 1) + ((sA - sB) * 0)
elif sA == 0:
    Ts = A * 1
else:
    Ts = K * 1
print(Ts)


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

signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	cout.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> bit(60,0);
	rep(i,n){
	    unsigned long long in;
	    cin>>in;
	    int cnt=0;
	    while(in){
	        bit[cnt]+=(in&1U);
	        in>>=1U;
	        cnt++;
	    }
	}
	int pw=1,ans=0;
	rep(i,60){
	    int b1=bit[i];
	    int b2=n-b1;
	    ans=(ans + (b1*b2)%1000000007*pw)%1000000007;
	    pw=pw*2%1000000007;
	}
	cout<<ans<<endl;
}


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

using namespace std;

const int INF = 1e9;
int n;
vector<int> edge[1100000];
int source[1100000]; //　入次数
vector<int> matches;
bool done[1100000];
int memo[1100000];

bool is_cyclic()
{
  queue<int> q;
  for (int match: matches) {
    if (source[match] == 0) {
      q.push(match);
    }
  }
  
  while (q.size()) {
    int match = q.front();
    q.pop();
    for (int next_match: edge[match]) {
      source[next_match]--;
      if (source[next_match] == 0) {
        q.push(next_match);
      }
    }
  }
  
  for (int match: matches) {
    if (source[match] > 0) {
      return true;
    }
  }
  
  return false;
}

// uを始点としたときの最長パス
int dfs(int u)
{
  if (done[u]) return memo[u];
  done[u] = true;
  int dist = 0;
  for (int v: edge[u]) {
    dist = max(dist, dfs(v) + 1);
  }
  return memo[u] = dist;
}

int main()
{
  cin >> n;
  
  matches.push_back(0);
  
  for (int i = 0; i < n; i++) {
    int last_match = 0;
    for (int j = 0; j < n-1; j++) {
      int a;
      cin >> a;
      a--;
      int next_match = min(i, a) * 1000 + max(i, a);
      edge[last_match].push_back(next_match);
      source[next_match]++;
      matches.push_back(next_match);
      last_match = next_match;
    }
  }
  
  if (is_cyclic()) {
    cout << -1 << endl;
    return 0;
  }
  
  cout << dfs(0) << endl;
  return 0;
}


Measured memory_bytes: 55276
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int x, y;

signed main() {
	cin >> x >> y;
	if (abs(x - y) <= 1)cout << "Brown" << endl;
	else cout << "Alice" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mm(a,b) memset(a,b,sizeof(a))
#define ACCELERATE (ios::sync_with_stdio(false),cin.tie(0))
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<long long,long long>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
#define E exp(1.0)
#define db double
#define ll long long
#define ld long double
#define ull unsigned long long
//#define io
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
//#define gc getchar
//char buf[1<<21],*p1=buf,*p2=buf;
//inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
//inline int read()
//{
//    int ret=0,f=0;char c=gc();
//    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
//    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
//    if(f)return -ret;return ret;
//}
char a[50],b[50];
int main()
{
    #ifdef io
    freopen("in.txt","r",stdin);
    #endif
    scanf("%s%s",a,b);
    int n=0;
    rep(i,0,2){
        if(a[i]==b[i])n++;
    }
    printf("%d\n",n);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int h,w,n,t=0;
    cin>>h>>w>>n;
    int a[n];
    vector<vector<int>>c(h,vector<int>(w));
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)for(int j=0;j<a[i-1];j++,t++)c[t/w][t%w]=i;
    for(int i=1;i<h;i+=2)reverse(c[i].begin(),c[i].end());
    for(int i=0;i<h*w;i++)cout<<c[i/w][i%w]<<(i%w==w-1?"\n":" ");
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}
int n;
string s;
vector<vector<lli>> dp;
vector<vector<lli>> pref;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	cin>>s;
	dp.assign(n,vector<lli>(n+1,0));
	pref.assign(n,vector<lli>(n+1,0));
	dp[0][1]=1;
	for(int i=1;i<n;i++){
		for(int j=1;j<=n;j++){
			pref[i-1][j]=add(pref[i-1][j-1],dp[i-1][j]);
		}
		for(int j=1;j<=i+1;j++){
			int l,r;
			if(s[i-1]=='<'){
				l=1;
				r=j-1;
			}
			else{
				l=j;
				r=n;
			}
			dp[i][j]=((pref[i-1][r]-pref[i-1][l-1])%mod+mod)%mod;			
		}
	}
	lli ans=0;
	for(int i=1;i<=n;i++){
		ans=add(ans,dp[n-1][i]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 141184
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int x;
    cin >> x;
    if(x>=30)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

pair = []

for c1 in range(2):
    for c2 in range(2):
        for c3 in range(2):
            for c4 in range(2):
                for c5 in range(2):
                    for c6 in range(2):
                        for c7 in range(2):
                            for c8 in range(2):
                                for c9 in range(2):
                                    for c10 in range(2):
                                        for c11 in range(2):
                                            for c12 in range(2):
                                                pair.append([c1, c2, c3, c4, c5,c6, c7, c8, c9, c10, c11,c12])


zenkingaku = []
for pattern in pair:
    rikaido = [0 for _ in range(m)]
    kingaku = 0
    _pattern = pattern[:n]
    for ca_i, p in enumerate(_pattern):
        if p == 1:
            kingaku += ca[ca_i][0]
            for ca_j in range(m):
                rikaido[ca_j] += ca[ca_i][ca_j+1] 

    for ca_j in range(m):
        if rikaido[ca_j] < x:
            kingaku = -1

    if kingaku == -1:
        continue

    zenkingaku.append(kingaku)

if not zenkingaku:
    zenkingaku = [-1]
print(min(zenkingaku))
        
                

Measured memory_bytes: 9708
#include<stdio.h>

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

    long long h[n];
    for(int i = 0;i < n;i++){
        scanf("%lld",&h[i]);
    }

    int j[m][2];
    int ans[n];
    
    for(int i = 0;i < n;i++){
        ans[i] = 0;
    }

    for(int i = 0;i < m;i++){
        scanf("%d %d",&j[i][0],&j[i][1]);
        if(ans[j[i][0]-1] < h[j[i][1]-1])ans[j[i][0]-1] = h[j[i][1]-1];
        if(ans[j[i][1]-1] < h[j[i][0]-1])ans[j[i][1]-1] = h[j[i][0]-1];
    }

    int count = 0;
    for(int i = 0;i < n;i++){
        if(h[i] > ans[i])count++;
    }

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

Measured memory_bytes: 3684
N = int(input())

def factorize(N):
    i = 2
    d = {}
    while i**2 <= N:
        while N%i == 0:
            N /= i
            if i in d.keys():
                d[i] += 1
            else:
                d[i] = 1
        i += 1
    if N > 1:
        d[N] = 1
    return d

c = 0
d = {}
for n in range(1,N+1):
    i = 2
    while i**2 <= n:
        while n%i == 0:
            n /= i
            if i in d.keys():
                d[i] += 1
            else:
                d[i] = 1
        i += 1
    if n > 1:
        if n in d.keys():
            d[n] += 1
        else:
            d[n] = 1

c2 = 0
c4 = 0
c14 = 0
c24 = 0
c74 = 0
for i in d.values():
    if i >= 2:
        c2 += 1
    if i >= 4:
        c4 += 1
    if i >= 14:
        c14 += 1
    if i >= 24:
        c24 += 1
    if i >= 74:
        c74 += 1
ans = c4*(c4-1)/2*(c2-2) + c24*(c2-1) + c14*(c4-1) + c74
print(int(ans))

Measured memory_bytes: 3444
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val (n, a, b) = br.readLine().split(" ").map { it.toInt() }
  val ans = Math.min(n * a, b)
  println(ans)
}

Measured memory_bytes: 35716
N = int(input())

if N == 2:
    print(1)
    exit()

if N == 3:
    print(2)
    exit()

ans = []
for n in range(1, int(N ** 0.5) + 1):
    if (N - 1) % n == 0:
        ans.append(n)
        ans.append((N - 1) // n)

for k in range(2, int(N ** 0.5) + 1):
    x = N
    while x % k == 0:
        x //= k

    if 1 in (x % k - k, x % k):
        ans.append(k)

print(len(set(ans)))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
   ll n,a,b,c,d;
   cin>>n>>a>>b>>c>>d;
   string s;
   cin>>s;
   int count=0;
   for(ll i=a-1;i<c-1;i++){
        if(s[i]=='#'&&s[i+1]=='#'){
            count++;
            break;
        }
    }
    for(ll i=b-1;i<d-1;i++){
        if(s[i]=='#'&&s[i+1]=='#'){
            count++;
            break;
        }
    }
    if(count!=0)cout<<"No"<<endl;
    else{
        if(c<d){
            cout<<"Yes"<<endl;
        }
        else {
            if(s[d-2]=='#'||s[d]=='#'){
                int count2=0;
                for(ll i=b-2;i<d-2;i++){
                    if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){
                        count2++;
                        break;
                    }
                }
               if(count2==0)cout<<"No"<<endl;
               else cout<<"Yes"<<endl;   
            }
           else cout<<"Yes"<<endl;
        }
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int sx,tx,sy,ty;
string ans;
int main()
{
	cin>>sx>>sy>>tx>>ty;
	for(int i=0;i<ty-sy;i++)
	{
		ans+='U';
	}
	for(int i=0;i<tx-sx;i++)
	{
		ans+='R';
	}
	for(int i=0;i<ty-sy;i++)
	{
		ans+='D';
	}
	for(int i=0;i<tx-sx;i++)
	{
		ans+='L';
	}
	ans+='L';
	for(int i=0;i<ty-sy+1;i++)
	{
		ans+='U';
	}
	for(int i=0;i<tx-sx+1;i++)
	{
		ans+='R';
	}
	ans+="DR";
	for(int i=0;i<ty-sy+1;i++)
	{
		ans+='D';
	}
	for(int i=0;i<tx-sx+1;i++)
	{
		ans+='L';
	}
	ans+='U';
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())
A.sort()
max_A=A[-1]

L=[ 0 for _ in range(max_A+1) ]
for a in A:
    L[a]+=1

for i,x in enumerate(L):
    if 1<x:
        L[i]=0

for a in A:
    for i in range(a*2,max_A+1,a):
        L[i]=0

print sum(L)

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


int main() {
    int N;
    cin >> N;
    vector<int> t(N);
    for(int i=0;i<N;i++) cin >> t[i];
    ll sum = accumulate(t.begin(), t.end(),0);
    int M;
    cin >> M;
    int p,x;
    for(int i=0;i<M;i++) {
        cin >> p >> x;
        cout << sum - t[p-1] + x << endl;
    }
}

Measured memory_bytes: 256
///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
#include<bits/stdc++.h>
using namespace std;
#define MAX 1e6+10
#define MOD 1000000007
#define PI 3.14159265359
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
const int N = 2e5 + 10;
ll aarray[200000+10];
ll magic[101][101];
vector<ll>primes;
bool prime[1000001];
map<ll,ll>mp;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    makefast__
    string str;
    ll i,j,n,m,k,t;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>aarray[i];
    }
    ll ans=0;
    set<pair<ll,pair<ll,ll>>>st;
    //cout<<mp[10]<<endl;
    for(i=1; i<=n-2; i++)
    {
        for(j=i+1; j<=n-1; j++)
        {
            for(k=j+1; k<=n; k++)
            {
                if(aarray[i]+aarray[j]>aarray[k]&&aarray[j]+aarray[k]>aarray[i]&&aarray[i]+aarray[k]>aarray[j])
                {
                    if(aarray[i]!=aarray[j]&&aarray[j]!=aarray[k]&&aarray[i]!=aarray[k])
                    ans++;

                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}




Measured memory_bytes: 3656
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    all_A = []
    for _ in range(N):
        a = int(input())
        A = []
        for _ in range(a):
            x, y = map(int, input().split())
            x -= 1
            A.append((x, y))
        all_A.append(A)

    res = 0
    for i in range(2 ** N):
        honest = []
        for j in range(N):
            if ((i >> j) & 1):
                honest.append(j)
        if len(honest) == 0:
            continue
        feasible = True
        for h in honest:
            for x, y in all_A[h]:
                if y == 1:
                    if x not in honest:
                        feasible = False
                        break
                else:
                    if x in honest:
                        feasible = False
                        break
        if feasible:
            res = max(res, len(honest))

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 46184
#include<stdio.h>
int main(){
  int h,w,n,a,b,c,d;
  int by[]={0,0,1,1,0,0,1,1,2,2,3,3};
  int bx[]={2,3,2,3,0,1,0,1,0,1,0,1};
  int Y[]={1,0,-1,0};
  int X[]={0,1,0,-1};
  int y[100010],x[100010],gy,gx,ny,nx,i,j,t,r;
  while(scanf("%d %d",&w,&h),h){
    scanf("%d %d %d %d %d",&x[0],&y[0],&gx,&gy,&n);
    int m[110][110]={};
    for(i=0;i<n;i++){
      scanf("%d %d %d %d",&a,&b,&c,&d);
      for(j=0;j<8;j++)m[d+by[j+b*4]][c+bx[j+b*4]]=a;
    }
    /*for(i=0;i<w;i++){
      for(j=0;j<h;j++)printf("%d ",m[i][j]);printf("\n");
      }//*/
    c=m[y[0]][x[0]];
    m[y[t=0]][x[0]]=6;
    for(r=1;r-t&&c;t++){
      for(i=0;i<4;i++){
	ny=y[t]+Y[i];
	nx=x[t]+X[i];
	if(m[ny][nx]-c)continue;
	m[y[r]=ny][x[r]=nx]=6;
	r++;
      }
    }
    printf("%s\n",m[gy][gx]-6?"NG":"OK");
  }
  return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n;
int a[MAXX];

int main()
{
    _FastIO;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a , a + n);
    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            ans += (a[i] * a[j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
   char s[100];
   scanf("%s",s);
   int l=strlen(s);
   int now=0;
   int ans=1000;
   for(int i=0;i<=l-3;i++)
   {
       int sum=0;
       for(int j=i;j<i+3;j++)
       {
           sum=sum*10+s[j]-'0';
       }
       //printf("%d\n\n",sum);
       ans=min(ans,abs(sum-753));
   }
   printf("%d",ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  string U;
  for (int i = 0; i < N; ++i) {
    U += S[i];
    U += T[i];
  }
  cout << U << endl;
  return 0;
}


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

all_sunuke = list(range(1, N+1))

have_sunuke = []

for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    have_sunuke += A

print(len(set(all_sunuke) - set(have_sunuke)))

Measured memory_bytes: 9072
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int t1, t2; 
  cin >> t1 >> t2;

  int a1, a2, b1, b2;
  cin >> a1 >> a2 >> b1 >> b2;

  int A = (a1-b1)*t1;
  int B = (a2-b2)*t2;

  if(A < 0){
    A *= -1; B *= -1;
  }
  B *= -1;

  if(A == B){
    cout << "infinity" << endl;
  }else if(A-B > 0){
    cout << 0 << endl;
  }else{
    int ans = A/(B-A)*2;
    if(A%(A-B) != 0) ans++;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 384
ans = [0 for _ in range(10001)]
for x in range(1, 101):
	for y in range(1, 101):
		for z in range(1, 101):
			w = x*x + y*y + z*z + x*y + y*z + z*x
			if w <= 10000:
				ans[w] += 1
print(*ans[1:int(input())+1], sep="\n")

Measured memory_bytes: 74120
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;


public class Main {
	static long[][] memo;;
	static int n;
	static int w;
	static int[] val;
	static int[] we;
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		String[] str = br.readLine().split(" ");
		 n = Integer.parseInt(str[0]);
		 w = Integer.parseInt(str[1]);
		memo = new long[n][w+1];
		for (int i = 0; i < n; i++) {
			Arrays.fill(memo[i],-1);
		}
		
		val = new int[n];
		we = new int[n];
		for (int i = 0; i < n; i++) {
			str = br.readLine().split(" ");
			val[i] = Integer.parseInt(str[1]);
			we[i] = Integer.parseInt(str[0]);
		}
		out.println(dp(0, w));	
		out.flush();
	}
	public static long dp(int v,int w) {
		if(v == n)
			return 0;
		
		if(memo[v][w] != -1) 
			return memo[v][w];
	
		long take = 0;
		long leave = dp(v+1, w);
		
		if(w-we[v] >= 0)
			take = dp(v+1, w-we[v])+val[v];
		
		return memo[v][w]= Math.max(take, leave);
	}

}



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

struct P{
  int x,y;
  long long z;
  bool operator <(const P &a){
    return x<a.x;
  }
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[204111];
int l[204111];

long long x,y,z,mod=1000000007;
string r;
//char r[1];
vector<int> v[1];
queue<int> q;
map<int,int> p;

int main()
{
  scanf("%d",&a);
  for(int t=1;t<=a;o[t]+=o[t-1],t++)
    scanf("%lld",&o[t]);
  x=987654321987654321;
  m=3;
  n=0;
  for(int t=2;t<=a-2;t++)
  {
    for(;min(o[t]-o[n],o[n])<min(o[t]-o[n+1],o[n+1]);n++);
    for(;min(o[m]-o[t],o[a]-o[m])<min(o[m+1]-o[t],o[a]-o[m+1]);m++);
    x=min(x,max(max(o[t]-o[n],o[n]),max(o[m]-o[t],o[a]-o[m]))-min(min(o[t]-o[n],o[n]),min(o[m]-o[t],o[a]-o[m])));
  }
  printf("%lld",x);
}



Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        String a = sc.next();
        String b = sc.next();
        int n = Integer.parseInt(a + b);
        for (int i = 0; i < Math.sqrt(n + 1); i++) {
            if (n == i * i) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 22356
#include <iostream>
#include <algorithm>

#define P 1000000007

using namespace std;

int main(){
    int n, m;
    long x[100000];
    long y[100000];
    cin >> n >> m;
    long x_sum = 0;
    long y_sum = 0;
    long x_diff = 0;
    long y_diff = 0;
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < m; i++){
        cin >> y[i];
    }
    sort(x, x+n);
    sort(y, y+m);
    x_sum = x[0];
    for(int i = 1; i < n;i++){
        x_diff = (x_diff + i*x[i] - x_sum)%P;
        x_sum = (x_sum + x[i])%P;
    }
    y_sum = y[0];
    for(int i = 1; i < m;i++){
        y_diff = (y_diff + i*y[i] - y_sum)%P;
        y_sum = (y_sum + y[i])%P;
    }
    cout << (x_diff*y_diff)%P << endl;
}

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

using namespace std;

typedef pair<string, int> P;

bool judge(string str) {
	for (int i = 0; i < str.size(); ++i) {
		if (str[0] != str[i]) return false;
	}
	return true;
}

char color(char a, char b){
	if((a == 'g' && b == 'r') || (a == 'r' && b == 'g'))return 'b';
	else if((a == 'b' && b == 'r') || (a == 'r' && b == 'b')) return 'g';
	else if((a == 'g' && b == 'b') || (a == 'b' && b == 'g')) return 'r';
}

int solve(string s) {

	queue<P> q;
	map<string, int> m;
	q.push(P(s, 0));

	while (!q.empty()) {
		P p = q.front();
		q.pop();
		if(m[p.first]) continue;
		string now = p.first;
		if (judge(now)) return p.second;
		m[p.first] = p.second;
		for (int i = 0; i < now.size() - 1; ++i) {
			if (now[i] != now[i+1]){
				char temp;
				string next;
				temp = color(now[i], now[i + 1]);
				next = now;
				next[i] = next[i + 1] = temp;
				q.push(P(next, p.second + 1));
			}
		}
	}
	return -1;
}

int main() {
	string worm;
	while (cin >> worm) {
		if (worm == "0") break;
		int count = solve(worm);
		if (count == -1) cout << "NA" << endl;
		else cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 4964
#include <stdio.h>
#include <string.h>
#include <algorithm>

#define lli long long int

using namespace std;

lli a[3010], t[3010][3010], j[3010][3010];

lli taro(lli left, lli right);

lli jiro(lli l, lli r) {
	lli depan, belakang;
	if (l == r)
		return (-1 * a[l]);
	if (j[l][r] != -1)
		return j[l][r];
	depan = taro(l + 1, r) - a[l];
	belakang = taro(l, r - 1) - a[r];
	j[l][r] = min(depan, belakang);
	return j[l][r];
}

lli taro(lli left, lli right) {
	lli d, b;
	if (left == right)
		return a[left];
	if (t[left][right] != -1)
		return t[left][right];
	d = jiro(left + 1, right) + a[left];
	b = jiro(left, right - 1) + a[right];
	t[left][right] = max(d, b);
	return t[left][right];
}

int main() {
	lli n, ans;
	scanf("%lld", &n);
	for (lli i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	memset(t, -1, sizeof t);
	memset(j, -1, sizeof j);
	ans = taro(1, n);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 141824
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100001][2];
vector<ll> g[100001];
bool vis[100001];
ll mod=1e9+7;
void dfs(ll cur)
{
    vis[cur]=1;
    if(g[cur].size()==1)
      {
      if(vis[g[cur][0]])
        {
        dp[cur][0]=dp[cur][1]=1; return;}
   } ll x1,x2;
      x1=x2=1;
    for(int i = 0;i<g[cur].size(); i++)
      {
      if(!vis[g[cur][i]])
        {
       ll y=g[cur][i];
         dfs(g[cur][i]);
        x1=(x1 *(dp[y][0]+dp[y][1]))%mod;
     x2=(x2 * dp[y][0])% mod; 
      }
      }
  dp[cur][0]=x1; dp[cur][1]=x2;
}
int main()
{
  ll n,i,u,v;
  cin>>n;
  for(i=0;i<n-1;i++)
    {
    cin>>u>>v;
    g[u].push_back(v);
    g[v].push_back(u);
    }
  dfs(1);
  cout<<(dp[1][0]+dp[1][1])% mod<<endl;
}


Measured memory_bytes: 14336
k,a,b=map(int,input().split())
if b<=a+2 or k<a+1:
    print(k+1)
    exit()
time=(k-a+1)//2
ans = (b-a)*(time-1)+b+(k-a+1)%2
print(ans) if ans >= k+1 else print(k+1)


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

int main()
{
	     //    #ifndef ONLINE_JUDGE
      //  // for getting input from input.txt
      //  freopen("input.txt", "r", stdin);
      //  // for writing output to output.txt
      //  freopen("output.txt", "w", stdout);
      // #endif
	int a[6],k=0;
	for (int i = 1; i <= 5; ++i)
	       {
	       	cin>>a[i];
	       }   
	for (int i = 1; i <= 5; ++i)
	    {
	    	if(a[i] == 0){
	    		k  = i;
	    	}
	    }    
	  cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 3624
n, m, x = map(int, input().split())
cl = []
al = []
for i in range(n):
    l = list(map(int, input().split()))
    cl.append(l[0])
    al.append(l[1:])
result = -1
for i in range(1<<n):
    price = 0
    unders = [0] * m
    for j in range(n):
        if((i>>j & 1) == 1):
            price+=cl[j]
            for k in range(m):
                unders[k] += al[j][k]
    for j in unders:
        if(j < x):
            break
    else:
        if(result == -1):
            result = price
        else:
            result= min(result, price)
                
print(result)

Measured memory_bytes: 73992
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>
#include<ctype.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    string a, b;
    cin >> a >> b;

    if(a.length() > b.length()){
        p("GREATER");
    }else if(a.length() < b.length()){
        p("LESS");
    }else{
        // same length
        if(a > b){
            p("GREATER");
        }else if(a < b){
            p("LESS");
        }else{
            p("EQUAL");
        }
    }
    
    return 0;
}

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

using namespace std;
using lint = long long;

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

    lint ans = 1;
    ans *= count(s.begin(), s.end(), 'R');
    ans *= count(s.begin(), s.end(), 'G');
    ans *= count(s.begin(), s.end(), 'B');

    for (int i = 0; i < N - 2; ++i) {
        auto x = s[i];
        for (int d = 1; i + 2 * d < N; ++d) {
            auto y = s[i + d];
            auto z = s[i + d + d];
            if (x != y and y != z and z != x) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
'use strict'

function Main(input) {
  let line = input.split(' ').map(x => Number(x));
  line.sort();

  let answer = 0;

  answer = Math.abs(line[1] - line[0]) + Math.abs(line[2] - line[1]);

  console.log(answer);

}

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

Measured memory_bytes: 21064
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.reverse()
B.reverse()


num = sum(B)

for i in range(n):
    if A[i] >= B[i]:
        A[i] -= B[i]
        B[i] = 0
    else:
        B[i] -= A[i]
        A[i] = 0
        if A[i+1] >= B[i]:
            A[i+1] -= B[i]
            B[i] = 0
        else:
            B[i] -= A[i+1]
            A[i+1] = 0

print(num - sum(B))


Measured memory_bytes: 19004
#include <algorithm>
#include <cstring>
#include <cstdio>

typedef long long LL;

const int MAXN = 200000;
const int MOD = 1000000007;
const int INF = 1000000001;

int N, X, Y, C[MAXN + 5], W[MAXN + 5];

int Min[MAXN + 5], Cnt[MAXN + 5];

int Fac[MAXN + 5], Inv[MAXN + 5];

int Pow(int x, int y) {
	int ret = 1;
	while (y) {
		if (y & 1)
			ret = (LL)ret * x % MOD;
		y >>= 1;
		x = (LL)x * x % MOD;
	}
	return ret;
}

int main() {
	scanf("%d%d%d", &N, &X, &Y);
	Fac[0] = 1;
	for (int i = 1; i <= N; i++)
		Fac[i] = (LL)Fac[i - 1] * i % MOD;
	Inv[N] = Pow(Fac[N], MOD - 2);
	for (int i = N - 1; i >= 0; i--)
		Inv[i] = (LL)Inv[i + 1] * (i + 1) % MOD;
	for (int i = 0; i <= N; i++)
		Min[i] = INF;
	for (int i = 1; i <= N; i++) {
		scanf("%d%d", &C[i], &W[i]);
		Cnt[C[i]]++;
		Min[C[i]] = std::min(Min[C[i]], W[i]);
	}
	int fir = std::min_element(Min + 1, Min + N + 1) - Min, sec = 0;
	for (int i = 1; i <= N; i++)
		if (i != fir && Min[i] < Min[sec])
			sec = i;
	for (int i = 1; i <= N; i++) { // 对于每个球
		if (W[i] != Min[C[i]] && W[i] + Min[C[i]] <= X) // 内部就可以交换
			continue;
		if (C[i] != fir && W[i] + Min[fir] <= Y) // 可交换出去
			continue;
		if (C[i] == fir && W[i] + Min[sec] <= Y) // 可交换出去
			continue;
		Cnt[C[i]]--; // 该球无法移动
	}
	int tot = 0, Ans = 1;
	for (int i = 1; i <= N; i++) // 合并每个颜色的连通块
		if (Min[i] + Min[fir] <= Y)
			Ans = (LL)Ans * Inv[Cnt[i]] % MOD, tot += Cnt[i];
	printf("%d", (LL)Ans * Fac[tot] % MOD);
}

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

int main() {
    int n; cin >> n;
    int A[n+1]; A[n] = 0; for (int i=0; i<n; i++) cin >> A[i];

    int out = 0, d = 0;
    for (int i=0; i < n+1; i++) {
        if (A[i] == 1) out++;
        else {
            d = max(out+1, d);
            out = 0;
        }
    }

    cout << d << endl;
}


Measured memory_bytes: 3100
#include<stdio.h>
#define rep(i,l,r) for(int i=l;i<r;i++)
typedef long long ll;

ll max(ll x, ll y) { return (x > y) ? x : y; }

int main() {
    ll n, a[100001],b[100001];
    scanf("%lld", &n);
    rep(i, 0, n) {
        scanf("%lld", &a[i]);
    }
    rep(i, 0, n) {
        scanf("%lld", &b[i]);
    }
    ll x = 0, y = 0;
    rep(i, 0, n) {
        if (a[i] > b[i]) x += a[i] - b[i];
        else y += (b[i] - a[i] ) / 2;
    }
    if (y>=x) printf("Yes");
    else printf("No");

    return 0;
}


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

int arr[3][3];

void markBingo(int num)
{
	for(int r = 0 ; r < 3 ; r++){
		for(int c = 0; c < 3; c++){
			if(arr[r][c] == num)
				arr[r][c] = -1;
		}
	}
}

bool checkHorizontal()
{
	bool ok = false;
	for(int r = 0; r < 3 ; r++){
		ok |= ((arr[r][0] == -1) && (arr[r][1] == -1) && (arr[r][2] == -1));
	}
	return ok;
}

bool checkVertical()
{
	bool ok = false;
	for(int c = 0; c < 3 ; c++){
		ok |= ((arr[1][c] == -1) && (arr[0][c] == -1) && (arr[2][c] == -1));
	}
	return ok;
}

bool checkDiagonal()
{
	bool ok = false;
	if(arr[1][1] == -1 && arr[0][0] == -1 && arr[2][2] == -1)
		ok = true;
	if(arr[1][1] == -1 && arr[2][0] == -1 && arr[0][2] == -1)
		ok = true;
	return ok;
}

bool solved()
{
	bool ok = false;
	ok |= checkHorizontal();
	ok |= checkVertical();
	ok |= checkDiagonal();
	return ok;
}

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


	for(int r = 0 ; r < 3 ; r++){
		for(int c = 0 ; c < 3 ; c++){
			cin >> arr[r][c];
		}
	}

	int N;
	cin >> N;
	
	while(N--)
	{
		int num;
		cin >> num;
		markBingo(num);
	}

	if(solved())
		cout << "Yes" << '\n';
	else cout << "No" << '\n'; 

	return 0;
}

Measured memory_bytes: 3600
n, m = map(int,input().split())
ps = list(list(map(str,input().split())) for _ in range(m))

check = [True] * (n+1)
wa = [0] * (n+1)
wa_ans = 0
for i in range(m):
    if ps[i][1] == 'AC' and check[int(ps[i][0])]:
        check[int(ps[i][0])] = False
        wa_ans += wa[int(ps[i][0])]
    if ps[i][1] == 'WA':
        wa[int(ps[i][0])] += 1
ans = 0
for i in check:
    if not i:
        ans += 1

print(ans,wa_ans)

Measured memory_bytes: 69976
#include<bits/stdc++.h>
using namespace std;
int main(){
      int a,b,c,d,e,f;
      cin>>a>>b;
      c=a+b;
      d=a-b;
      e=a*b;
      f=0;
      if(c>=d){
        f=c;
      }else{
        f=d;
      }
      if(f>=e){
        cout<<f<<endl;
      }else{
        cout<<e<<endl;
      }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> ball(N+1);
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    ++ball[a];
  }
  
  sort(ball.rbegin(), ball.rend());
  
  int leave_Ball = 0;
  
  for (int i = 0; i < K; ++i) {
    leave_Ball += ball[i];
  }
  
  int ans = N - leave_Ball;
  
  cout << ans << endl;

    
}


Measured memory_bytes: 1024