akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

struct E {
  string city;
  int score;
  int p;
};

bool cmp (const E a, const E b) {
  return ((a.city < b.city) || (a.city == b.city && a.score > b.score));
}

int main () {
  int n;
  cin >> n;
  vector<E> a (n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].city >> a[i].score;
    a[i].p = i + 1;
  }
  sort (a.begin(), a.end(), cmp);
  for (int i = 0; i < n; i++) {
    cout << a[i].p << '\n';
  }
  return 0;
}


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

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int ans = 0;

    for (int i = 1; i <= 100; i++) {
        int flag = 0;
        rep(j, n) {
            if (i <= h[j] && flag == 0)
                flag = 1;
            else if (i > h[j] && flag == 1) {
                ans++;
                flag = 0;
            }
        }
        if (flag == 1) {
            ans++;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 10000000000
#define PI 3.141592653589793

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}
	vector<vector<int>> table(n+1, vector<int>(0));
	vector<int> order(0);
	order.push_back(1);
	vector<int> ans(n+1, 0);
	ans[1] = 1;

	for (int i = 0; i < m; i++) {
		table[a[i]].push_back(b[i]);
		table[b[i]].push_back(a[i]);
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < table[order[i]].size(); j++) {
			int point = table[order[i]][j];
			if (!ans[point]) {
				ans[point] = order[i];
				order.push_back(table[order[i]][j]);
			}
		}
	}

	if (order.size() == n) {
		cout << "Yes" << endl;
		for (int i = 2; i < n + 1; i++) {
			cout << ans[i] << endl;
		}
	} else {
		cout << "No" << endl;
	}

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N){
        cin >> A.at(i);
    }

    bool flag = false;
    rep(i, N){
        if(A.at(i) % 2 == 0){
            if((A.at(i) % 3 != 0) && (A.at(i) % 5 != 0)){
                flag = true;
            }
        }
        if(flag){
            break;
        }
    }
    if(flag){
        cout << "DENIED" << endl;
    } else {
        cout << "APPROVED" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define N 100000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
#define square(x) x*x
using namespace std;
/**
        * @author :: Sawlani
        *
        */
int main()
{
    string s;
    cin >> s;

    if((s[2]==s[3])&&(s[4]==s[5]))
    cout << "Yes";
    else
    {
        cout << "No";
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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;
}
int main() {
  cout << fixed << setprecision(10);
  int a;
  cin >> a;
  cout << a*a+a+a*a*a << endl;
}


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

int times = 0;

void swap(int &a, int &b)
{
	int temp;
	temp = a;
	a = b;
	b = temp;
	times++;
}

int main(void)
{
	int n;
	cin >> n;
	vector<int>A(n);
	for (int i = 0; i < n; i++)
		cin >> A[i];
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j >= i + 1; j--) {
			if (A[j] < A[j - 1])
				swap(A[j], A[j - 1]);
		}
	}
	for (int i = 0; i < n; i++) {
		cout << A[i];
		if (i != n - 1)
			cout << " ";
		else
			cout << endl;
	}
	cout << times << endl;
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    string s;cin>>s;
    int cnt1=0;
    int cnt2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]-'0'!=i%2) cnt1++;
        else cnt2++;
    }
    cout << min(cnt1,cnt2) << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;main(){int h,w,d,q,a,l,r,i,j,sum[90001]={};vector<pair<int,int>>v(90001);cin>>h>>w>>d;for(i=0;i<h;i++)for(j=0;j<w;j++)cin>>a,v[a]=make_pair(i,j);for(i=d+1;i<=h*w;i++)sum[i]=sum[i-d]+abs(v[i].first-v[i-d].first)+abs(v[i].second-v[i-d].second);cin>>q;while(q--)cin>>l>>r,cout<<sum[r]-sum[l]<<'\n';}

Measured memory_bytes: 2176
/*
author:Rahul Chocha
school of eng. and applied science
*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define MAXI INT_MAX
#define MINI INT_MIN
#define din(t) long long t; cin >> t;
#define fi(i, l, r, d) for (i = l; i < r; i += d)
#define fd(i, l, r, d) for (i = l - 1; i >= r; i -= d)
#define pb push_back
#define mp make_pair


void speed_up()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}
void Inp_Out(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("A.01.inp", "r", stdin);
    // for writing output to output.txt
    //freopen("A.01.out", "w", stdout);
    #endif
}

int main()
{   

   	speed_up();
   	//Inp_Out();
	din(n)
	ll kk =ceil(n/(double)1000);
	cout<<(1000*kk)-n;


} 


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;
	cin >> n;
	cout << n/3 <<endl;
	return 0;
}

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

int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	if ((a[a.length() - 1] == b[0]) && (b[b.length() - 1] == c[0])) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
if n < 600:
    print(8)
elif n < 800:
    print(7)
elif n < 1000:
    print(6)
elif n < 1200:
    print(5)
elif n < 1400:
    print(4)
elif n < 1600:
    print(3)
elif n < 1800:
    print(2)
elif n < 2000:
    print(1)

Measured memory_bytes: 9180
// #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    set<string> st;
    rep(i,n){
        string s;cin >> s;
        st.insert(s);
    }

    cout << st.size() << endl;
}

Measured memory_bytes: 19248
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>

using namespace std;

const int INF = (1<<30) - 1;

bool is_prime[1299710];

void sieve(){
    memset(is_prime, true, sizeof(is_prime));
    is_prime[0] = is_prime[1] = false;
    for(int i=0; i<1299710; i++){
        if(is_prime[i]){
            for(int j=i*2; j<1299710; j+=i){
                is_prime[j] = false;
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    sieve();
    
    int N;
    while(cin>>N, N){
        if(is_prime[N]){
            cout << 0 << endl;
        }else{
            int r, l;
            r = l = N;
            while(!is_prime[r]) r--;
            while(!is_prime[l]) l++;
            cout << l-r << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 2468
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt() * 2;
	myout(Math.PI * N);
}


Measured memory_bytes: 29648
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int ds[2][100001];
int ns[2][100001];
vector<vector<int>> G;
void bfs(int x, int d, int i){
  queue<int> q, dis;
  q.push(x);
  dis.push(0);

  while(!q.empty()){
	x = q.front(); q.pop();
	d = dis.front(); dis.pop();
	if(ds[i][x] >= 0) continue;
	ds[i][x] = d;
	ns[i][d]++;
	for(int to: G[x]){
	  q.push(to);
	  dis.push(d+1);
	}
  }
}

int main(){
  fill((int*)ds, (int*)ds+2*100001, -1);
  fill((int*)ns, (int*)ns+2*100001, 0);

  int N, M, S, T;
  cin >> N >> M >> S >> T;
  --S, --T;
  G.assign(N, vector<int>());
  for(int i=0;i<M;++i){
	int x, y; cin >> x >> y;
	--x, --y;
	G[x].push_back(y);
	G[y].push_back(x);
  }
  bfs(S, 0, 0);
  bfs(T, 0, 1);

  long long ans = 0, d = ds[0][T];
  for(int i=0;i<=d-2;++i)
	ans += (long long)ns[0][i] * ns[1][d-2-i];
  cout << ans << endl;
}

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

int main(){
	string s;
  	int q;
  	cin >> s >> q;
  
  	string t;
  	rep(qi, q){
  		int ty;
      	cin >> ty;
      	if(ty == 1){
        	swap(s, t);
        } else {
        	int f; char c;
          	cin >> f >> c;
          	if(f == 1){
            	t+= c;
            } else {
            	s += c;
            }
        }
  	}
  
  	reverse(t.begin(), t.end());
  	t += s;
  	cout << t << endl;
}

Measured memory_bytes: 1128
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i) = 0; (i) <= (n); (i)++)
using namespace std;

int H, W, d;

char ch[2][2] = { {'R', 'Y'}, {'G', 'B'} };

signed main()
{
	cin >> H >> W >> d;
	REP(y, H)
	{
		REP(x, W)
		{
			int xx = (x + y) % (d * 2);
			int yy = (x - y) % (d * 2);
			if (xx < 0) xx = d * 2 + xx;
			if (yy < 0) yy = d * 2 + yy;
			int a = abs(xx) / d;
			int b = abs(yy) / d;
			cout << ch[a][b];
		}
		cout << endl;
	}
}

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

a = []
for i in range(n+1):
  if i % 3 == 0 and i % 5 == 0:
    continue
  elif i % 3 == 0:
    continue
  elif i % 5 == 0:
    continue
  else:
    a.append(i)
    
print(sum(a))

Measured memory_bytes: 30012
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n, pos;
	string str;

	cin>>n; cin.get( );
	while(n--){
		getline(cin, str); 
		while(pos = str.find("Hoshino"),pos!=string::npos){
			str.replace(pos, 7, "Hoshina");
		}
		cout<<str<<"\n";
	} 
	return 0;
}

Measured memory_bytes: 0
H, W, K = map(int, input().split())
MOD = 10**9 + 7

dp = [[0] * (W + 2) for _ in range(H + 1)]  # dp[h][w] = 上からh本通った後にwにいるパターン数
dp[0][1] = 1

preCnt = [0] * (W + 1)  # w本を任意に引けるときの数
for w in range(1, W + 1):
    cnt = 0
    for bit in range(1 << w):
        if bin(bit).count('11') == 0:
            cnt += 1
    preCnt[w] = cnt

def left(w):
    ret = 1
    ret *= preCnt[w - 3] if w - 3 > 0 else 1
    ret *= preCnt[W - w - 1] if W - w - 1 > 0 else 1
    return ret % MOD

def right(w):
    ret = 1
    ret *= preCnt[w - 2] if w - 2 > 0 else 1
    ret *= preCnt[W - w - 2] if W - w - 2 > 0 else 1
    return ret % MOD

def mid(w):
    ret = 1
    ret *= preCnt[w - 2] if w - 2 > 0 else 1
    ret *= preCnt[W - w - 1] if W - w - 1 > 0 else 1
    return ret % MOD

for h in range(1, H + 1):
    for w in range(1, W + 1):
        dp[h][w] += dp[h - 1][w - 1] * left(w)
        dp[h][w] += dp[h - 1][w] * mid(w)
        dp[h][w] += dp[h - 1][w + 1] * right(w)
        dp[h][w] %= MOD

print(dp[H][K])

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

int main() {
  int A, B, C, D;
  
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
  	cout << "Left" << endl;
  }
  else if (A + B == C + D) {
  	cout << "Balanced" << endl;
  }
  else {
  	cout << "Right" << endl;
  }
}



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

int main() {
  int N,C,K;
  cin >> N >> C >> K;
  vector<int>data(N);
  for(int i=0;i<N;i++){
    cin >> data.at(i);
  }
  sort(data.begin(),data.end());
  int count=0;
  pair<int,int>start;
  start.first=-1;
  for(int i=0;i<N;i++){
    if(start.first>=data.at(i)&&i-start.second<C){
    }
    else{
      count ++;
      start.first=data.at(i)+K;
      start.second=i;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <math.h>

#define deg_to_rad(deg) (((deg)/360)*2*M_PI)

using namespace std;

int main() {
  int a,b;
  int h,m;

  cin >> a >> b >> h >> m;

  double rh = 0, rm = 0;
  rh = h*30 + m*0.5f;
  rm = 6*m;

  while(rh >= 360){
    rh -= 360;
  }

  while(rm >= 360){
    rm -=360;
  }

  double diff = (rh >= rm) ? (rh-rm) : (rm - rh);

  double c = deg_to_rad(diff);

  double ans = sqrt(a*a + b*b - 2*b*a*cos(c));

  printf("%.20lf", ans);

  return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

void solve()
{
    int n;
    cin >> n;
    vector<int> imos(100001 + 10, 0);
    imos[0]++;
    imos[100001 + 1]--;
    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        imos[a]++;
        imos[b + 1]--;
    }
    int ans = 0;
    int cur = 0;
    rep(i, 100001 + 10)
    {
        cur += imos[i];
        // cerr << i << " " << cur << endl;
        if (i <= cur)
        {
            chmax(ans, i);
        }
    }
    cout << ans - 1 << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3480
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
 
using namespace std;
 
const int N = 100005;
const int mod = (int) 1e9 + 7;
 
int n, k;
int fact[N];
int inver[N];
int arr[N];
 
inline void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
 
inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += mod;
}
 
inline int mul(int a, int b) {
  return (int) ((long long) a * b % mod);
}
 
inline int fp(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
 
inline int inv(int x) {
  return fp(x, mod - 2);
}
 
int comb(int n, int k) {
  if (n <= 0 || k > n) return 0;
  int ans = mul(fact[n], inver[k]);
  ans = mul(ans, inver[n - k]);
  return ans;
}
 
int main() {
  fact[0] = 1;
  inver[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
    inver[i] = inv(fact[i]);
  }
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    add(ans, mul(arr[i], comb(i, k - 1)));
    sub(ans, mul(arr[i], comb(n - i - 1, k - 1)));
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n, l;
		cin >> n >> l;
		vector<string> ss(n);
		for(int i=0; i<n; i++)cin >> ss[i];
		sort(ss.begin(), ss.end());
		string ans = "";
		for(auto s:ss)ans += s;
		cout << ans << "\n";
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
class Dice():
  def __init__ (self):
    # 1:ue 2:syomen 3:migi 4:hidari 5:oku 6:shita
    self.position = [0,0,0,0,0,0]
    self.search_result = []
  
  def setNumber (self, num):
    for i,x in enumerate(num):
      self.position[i] = x
    #print(self.position)
      
  def roll(self, roll):
    for i in range(len(roll)):
      s = roll[i:i+1]
      p = self.position
      if s == 'E':
        self.setNumber([p[3], p[1], p[0], p[5], p[4], p[2]])
      elif s == 'W':
        self.setNumber([p[2], p[1], p[5], p[0], p[4], p[3]])
      elif s == 'S':
        self.setNumber([p[4], p[0], p[2], p[3], p[5], p[1]])
      elif s == 'N':
        self.setNumber([p[1], p[5], p[2], p[3], p[0], p[4]])

  def printTop(self):
    print(self.position[0])

  def searchRight(self, a, b):
    i1 = self.position.index(a)
    i2 = self.position.index(b)
    #print("i1:" + str(i1) + " i2:" + str(i2) )
    
    # 0
    if (i1 == 1 and i2 == 2) or (i1 == 2 and i2 == 4) or (i1 == 4 and i2 == 3) or (i1 == 3 and i2 == 1):
      self.search_result.append(self.position[0])
    # 1
    elif (i1 == 0 and i2 == 3) or (i1 == 3 and i2 == 5) or (i1 == 5 and i2 == 2) or (i1 == 2 and i2 == 0):
      self.search_result.append(self.position[1])
    # 2
    elif (i1 == 0 and i2 == 1) or (i1 == 1 and i2 == 5) or (i1 == 5 and i2 == 4) or (i1 == 4 and i2 == 0):
      self.search_result.append(self.position[2])
    # 3
    elif (i1 == 1 and i2 == 0) or (i1 == 0 and i2 == 4) or (i1 == 4 and i2 == 5) or (i1 == 5 and i2 == 1):
      self.search_result.append(self.position[3])
    # 4
    elif (i1 == 0 and i2 == 2) or (i1 == 2 and i2 == 5) or (i1 == 5 and i2 == 3) or (i1 == 3 and i2 == 0):
      self.search_result.append(self.position[4])
    # 5
    elif (i1 == 2 and i2 == 1) or (i1 == 1 and i2 == 3) or (i1 == 3 and i2 == 4) or (i1 == 4 and i2 == 2):
      self.search_result.append(self.position[5])
    
  def printResult(self):
    for i in self.search_result:
      print (i)


d = Dice()

n = list(int(x) for x in input().split())
d.setNumber(n)

q = int(input())
for i in range(q):
  a,b = (int(x) for x in input().split())
  d.searchRight(a,b)

d.printResult()


Measured memory_bytes: 5632
import java.util.*;

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

    if (s.equals("Sunny")) {
	  System.out.println("Cloudy");
    } else if (s.equals("Cloudy")) {
      System.out.println("Rainy");
    } else {
      System.out.println("Sunny");
    }
    
  }
}


Measured memory_bytes: 22228
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll
const long double pi = 3.14159265358979323846;

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    ll n = s.size();
    debug(s);
    if (s[n - 1] == 's')
        s += "es";
    else s += "s";

    cout << s << "\n";
}

Measured memory_bytes: 3660
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

c_list = []
rink_list = []
visited = set()
ans = -10 ** 10
for i in range(n):
    sum_c = c[i]
    j = p[i] - 1
    num = 1
    while i != j:
        sum_c += c[j]
        j = p[j] - 1
        num += 1

    sum_c = max(0, sum_c)
    # print(f'num:{num}')
    cnt = 1
    j = p[i] - 1
    tmp = c[i]
    ans = max(ans, tmp + sum_c * ((k - cnt) // num))
    while cnt < k and i != j:
        cnt += 1
        tmp += c[j]

        ans = max(ans, tmp + sum_c * ((k - cnt) // num))
        j = p[j] - 1

if ans == 0:
    ans = max(c)

print(ans)

Measured memory_bytes: 73680
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

n = readInt()
text = readStringList()
import collections
c  = collections.Counter(text)
if c['W'] == 0:
    print("0")
    exit()
i,j,count = 0,len(text)-1,0

while i <= j and i < len(text):
    if text[i] == 'W':
        while text[j] != 'R' and j > 0:
            j -= 1
        if i <= j and j > 0:
            text[i],text[j] = text[j],text[i]
            count += 1
    i += 1
print(count)



Measured memory_bytes: 10792
N=int(input())
b=list(map(int,input().split()))
ans=[]
for i in range(N):
    n=len(b)
    cond=True
    for j in range(n):
        if n-j==b[n-j-1]:
            del b[n-j-1]
            ans.append(n-j)
            cond=False
            break
    if cond:
        ans=[-1]
        break
for a in range(len(ans)):
    print(ans[len(ans)-a-1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

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

    string s;
    cin >> s;
    sort(all(s));
    cout << (s == "abc" ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int a,b,c,flag;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF)
	{
		flag=0;
		if(a+b==c)
		flag=1;
		if(a+c==b)
		flag=1;
		if(b+c==a)
		flag=1;
		if(flag==1)
		printf("Yes\n");
		else
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

bool dfs(vector<vector<char>>&cam, int s, int t) {
	int size = cam[s].size();
	int size1 = cam.size();
	int count = 0;
	for (int i = max(0, s - 1); 
		i< min(s + 2, size1); i++) {
		if (cam[i][t] == '#') {
			count++;
		}
	}
	for (int i = max(t - 1, 0);
		i< min(t + 2,size); i++) {
		if (cam[s][i] == '#'&&i!=t) {
			count++;
		}
	}
	if (count >= 2) {
		return true;
	}
	else {
		return false;
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<char>>cam(n,vector<char>(m));
	rep(i, n) {
		rep(j, m) {
			cin >> cam[i][j];
		}
	}
	bool flag = true;
	rep(i, n) {
		rep(j, m) {
			if (cam[i][j] == '#') {
				if (!dfs(cam, i, j)) {
					flag = false;
					j = m;
					i = n;
				}
			}
	     }
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

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

int main()
{
    int n, k;
    cin >> n >> k;

    vector<int> p(n);
    rep(i, n) cin >> p[i];

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

    int ans = 0;
    rep(i, k) ans += p[i];

    cout << ans << endl;
}

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

int main() {

  int N;
  cin >> N;
  bool P = false;
  bool W = false;
  bool G = false;
  bool Y = false;
  int number = 0;

  for (int i = 1; i <= N; i++) {
    string S;
    cin >> S;
    if (S == "P" && !P) {
      number += 1;
      P = true;
    } else if(S == "W" && !W) {
      number += 1;
      W = true;
    } else if(S == "G" && !G) {
      number += 1;
      G = true;
    } else if(S == "Y" && !Y) {
      number += 1;
      Y = true;
    }
  }
  if (number == 3) {
    cout << "Three" << endl;
  } else if (number == 4) {
    cout << "Four" << endl;
  }
  
}


Measured memory_bytes: 256
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner s=new Scanner(System.in);
		int h=s.nextInt();
		int a=s.nextInt();
		
		System.out.println((int)Math.ceil((double)h/a));
	}
}

Measured memory_bytes: 21844
n = int(input())
a = "abcdefghijklmnopqrstuvwxyz"
now = 0
tnp = 0
for i in range(1,1000):
    x = now + 26**i
    if (n<=x):
        tnp = i
        break
    now = x
x = n - now
ans = ""
for i in range(i):
    #print(x)
    if i==0:
        ans = a[x%26-1] + ans
    else:
        ans = a[x%26-1] + ans
    x = (x-1) // 26
    x += 1
print(ans)

Measured memory_bytes: 9088
#include<iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int max, min, loop, temp;
    max = 0;
    min = 1000000000;
    cin >> loop;

    for(int i = 0; i < loop; i++){
        cin >> temp;
        if(temp < min){
            min = temp;
        }
        if(temp > max){
            max = temp;
        }
    }
    cout << max - min << '\n';

    return 0;
}


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

using namespace std;

int main(){
	int n,k;
	cin>>k>>n;
	long long ans=0;
	for(int i=0;i<=k;i++)
	{
		if(i<=n)
			for(int j=0;j<=k;j++)
			{
				if(n-i-j>=0 && n-i-j<=k)
					ans++;
			}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String [] args) {
		Scanner s = new Scanner(System.in);
		while (true) {
			int n = s.nextInt();
			if (n == 0) break;
			int ans = -100000;
			int acc = 0;
			for (int i=0;i<n;i++) {
				acc += s.nextInt();
				ans = Math.max(ans, acc);
				if (acc < 0) acc = 0;
			}
			System.out.println(ans);
		}
	}
}



Measured memory_bytes: 35068
import sys
n=int(input())
task=[list(map(int,input().split())) for _ in range(n)]
task.sort(key=lambda x:x[1])
time=0
for i in range(n):
    time+=task[i][0]
    if task[i][1]<time:
        print('No')
        sys.exit()
print('Yes')


Measured memory_bytes: 53728
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N, M = [int(i) for i in input().strip().split()]
    A_list = [int(i) for i in input().strip().split()]
    num = 0

    for i in range(N):
        if A_list[i] >= sum(A_list) / (4 * M):
            num += 1
        else:
            continue

    if num >= M:
        return "Yes"
    else:
        return "No"


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9136
N = gets.to_i
A = gets.split(" ").map(&:to_i)

n = A.select{|n| n < 0}.count

ans = 0
if n % 2 == 0
  ans = A.map{|e| e.abs}.reduce(:+)
else
  ans = A.map{|e| e.abs}.reduce(:+)
  ans -= A.map{|e| e.abs}.min * 2
end
puts ans

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	inline int tc()
	{
		int c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		return c;
	}
}
using ae86::ty;
using ae86::tc;

const int _ = 1007;
const int go[2][4] = {{1,0,-1,0},{0,1,0,-1}};

int H,W,val[_][_],dis[_][_];

inline int bfs()
{
	memset(dis,63,sizeof(dis));
	queue<pair<int,int>> q;
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)
			if(val[i][j])dis[i][j]=0,q.emplace(i,j);

	while(!q.empty())
	{
		int x=q.front().first,y=q.front().second;
		q.pop();
		for(int k=0;k<4;k++)
		{
			int xx=x+go[0][k],yy=y+go[1][k];
			if(xx<=0 || xx>H || yy<=0 || yy>W)continue;
			if(dis[xx][yy]<=dis[x][y]+1)continue;
			dis[xx][yy]=dis[x][y]+1,q.emplace(xx,yy);
		}
	}
	
	int mx=0;
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)
			mx=max(mx,dis[i][j]);
	return mx;
}

int main()
{
	H=ty(),W=ty();
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)
			val[i][j]=tc()=='#';
	printf("%d\n",bfs());

	return 0;
}


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

struct card{
    char suit;
    int value;
};

void bubbleSort(card a[],int n){
    int flag=1;
    for(int i=0;i<n-1;++i){
        if(!flag)break;
        flag=0;
        for(int j=n-1;j>i;j--){
            if(a[j].value<a[j-1].value){
                flag=1;
                card t=a[j];
                a[j]=a[j-1];
                a[j-1]=t;
            }
        }
    }
}

void selectionSort(card c[],int n){
   int min;
    for(int i=0;i<n-1;++i){
        min=i;
        for(int j=i+1;j<n;++j){
            if(c[j].value<c[min].value)
                min=j;
        }
        if(min!=i){card t=c[i];c[i]=c[min];c[min]=t;}
    }
}

bool isStable(card c1[],card c2[],int n){
    for(int i=0;i<n;++i)
      if(c1[i].suit!=c2[i].suit)return false;
    
    return true;
}
void print(card c[],int n){
    for(int i=0;i<n;i++){
        if(i>0)cout<<' ';
        cout<<c[i].suit<<c[i].value;
    }
    cout<<endl;
}
int main(){
    int n;
    cin>>n;
    card c1[36],c2[36];
    for(int i=0;i<n;i++){
        cin>>c1[i].suit>>c1[i].value;
        c2[i]=c1[i];
    }
    
    bubbleSort(c1,n);
    selectionSort(c2,n);
    print(c1,n);
    cout<<"Stable"<<endl;
    print(c2,n);
    if(isStable(c1,c2,n))
        cout<<"Stable"<<endl;
        else
        cout<<"Not stable"<<endl;
    return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
	int n;
	cin >> n;
	
	int cnt=0;
	int ans=n;
	int tmp;
	for(int i=0; i<=n; i++){
		//i円は6の倍数で対応
		cnt=0;
		tmp=i;
		while(tmp){
			cnt+=tmp%6;
			tmp/=6;
		}

		tmp=n-i;
		while(tmp){
			cnt+=tmp%9;
			tmp/=9;
		}
		if(cnt<ans){
			ans=cnt;
		}
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
	int x,y,r,H,W;
	cin >> W >> H >> x >> y >> r;
	if(W >= x+r && x-r >= 0 && H >= y+r && y-r >= 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3124
#include <stdio.h>
#include <string.h>
int main()
{
    int a,b;
    char c;
    scanf("%d %c %d",&a,&c,&b);
    if(c=='+')
        printf("%d\n",a+b);
    else if(c=='-')
        printf("%d\n",a-b);
    return 0;
}


Measured memory_bytes: 128
a, b, m = map(int, input().split())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
li = []
for i in range(m):
  li.append(list(map(int, input().split())))
wa_1 = min(list_a) + min(list_b)
wa_2 = 10000000000
for i in range(m):
  wa_2 = min(wa_2, list_a[li[i][0]-1]+list_b[li[i][1]-1]-li[i][2])
print(min(wa_1, wa_2))

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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	printf("%d %d %d", a, b, c);
	return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,cost=0,cur_idx=0,prev_idx=0;
    cin>>n;
    ll arr[n+5],ans[n+5]={0};
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ans[0]=0;
    ans[1]=abs(arr[1]-arr[0]);
    for(ll i=2;i<n;i++)
    {
        ans[i]=min((ans[i-1]+abs(arr[i]-arr[i-1])),(ans[i-2]+abs(arr[i]-arr[i-2])));
        //cout<<ans[i]<<' ';
    }
   // cout<<'\n';
    cout<<ans[n-1]<<'\n';
    return 0;
}

Measured memory_bytes: 5160
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;
using llint = long long int;

int n, m;
vector<vector<int>> graph;

vector<bool> marked;
vector<int> nodes;
void mark(int node)
{
  marked[node] = true;
  nodes.push_back(node);
  for (int next : graph[node])
  {
    if (!marked[next])
    {
      mark(next);
    }
  }
}

int main()
{
  cin >> n >> m;
  vector<int> vec;
  vec.resize(n);
  graph.resize(n);
  marked.resize(n);
  for (int i = 0; i < n; i++)
  {
    int x;
    cin >> x;
    vec[i] = x - 1;
  }

  for (int i = 0; i < m; i++)
  {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (!marked[i])
    {
      nodes.clear();
      mark(i);
      set<int> connected(nodes.begin(), nodes.end());
      for (int from : nodes)
      {
        if (connected.count(vec[from]))
        {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14200
#include <bits/stdc++.h>
using namespace std;
int n,a[100][100],b[200],k,l,x,y,z,h,t,c;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
for(int i=1;i<=3;i++){
    for(int j=1;j<=3;j++){
        cin>>a[i][j];
    }
}
cin>>n;
for(int i=1;i<=n;i++){
    cin>>b[i];
}
sort(b,b+n);
for(int i=1;i<=n;i++){
if(a[1][1]==b[i])k++;
if(a[2][2]==b[i])k++;
if(a[3][3]==b[i])k++;

if(a[1][1]==b[i])l++;
if(a[1][2]==b[i])l++;
if(a[1][3]==b[i])l++;

 if(a[2][1]==b[i])x++;
 if(a[2][2]==b[i])x++;
 if(a[2][3]==b[i])x++;
 
 if(a[3][1]==b[i])y++;
 if(a[3][2]==b[i])y++;
 if(a[3][3]==b[i])y++;
 
 if(a[1][2]==b[i])c++;
 if(a[2][2]==b[i])c++;
 if(a[3][2]==b[i])c++;
 
 if(a[1][3]==b[i])t++;
 if(a[2][3]==b[i])t++;
 if(a[3][3]==b[i])t++;
 
 if(a[1][3]==b[i])z++;
 if(a[2][2]==b[i])z++;
 if(a[3][1]==b[i])z++;
 
 if(a[1][1]==b[i])h++;
 if(a[2][1]==b[i])h++;
 if(a[3][1]==b[i])h++;  
 
}
if(k==3||l==3||x==3||y==3||c==3||t==3||z==3||h==3)cout<<"Yes";
else cout<<"No";
return 0;}



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

void chmin(int& a, int b) {
  if (a > b) a = b;
}

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  
  int C[N+1] = {0};
  int A[N+1][M+1];
  
  for (int i = 0; i < N+1; i++) {
    for (int j = 0; j < M+1; j++) {
      A[i][j] = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i+1];
    for (int j = 0; j < M; j++) {
      cin >> A[i+1][j+1];
    }
  }
  
  
  int ans = 10000000;
  for (int bit = 1; bit < (1 << N); bit++) {
    bool cond = true;
    int cost = 0;
    int Us[N+1] = {0};
    
    for (int i = 0; i < N; i++) {
      if (bit & (1 << i)) {
        cost += C[i+1];
        for (int j = 1; j <= M; j++) {
          Us[j] += A[i+1][j];
        }
      }
    }
    
    for (int i = 1; i <= M; i++) {
      if (Us[i] < X) {
        cond = false;
        break;
      }
    }
    
    if (cond) {
      chmin(ans, cost);
    }
  }
  if (ans == 10000000) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }



}

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

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using usize = std::size_t;
using namespace std;

#define rep(i, max) for(i32 i = 0; i < (i32)max; ++i)
#define loop while(true)
#define allOf(collection) collection.begin(), collection.end()

unique_ptr<string> readLine() { unique_ptr<string> line(new string()); getline(cin, *line); return line; }
template<typename T1, typename T2> pair<T1, T2> readPair() { T1 res1; cin >> res1; T2 res2; cin >> res2; readLine(); return make_pair(res1, res2);}
template<typename T> unique_ptr<vector<T>> readVector(usize num, bool isForIndex = false) { unique_ptr<vector<T>> list(new vector<T>(num)); rep(i, num) { cin >> (*list)[i]; if(isForIndex) --(*list)[i]; } readLine(); return list; }
void readValues() { readLine(); }
template<typename H, typename... T> void readValues(H& head, T&&... tails){ H a; cin >> a; head = a; readValues(forward<T>(tails)...); }
void writeLine() { cout << endl; }
template<typename T> void write(const T& arg) { cout << arg; }
template<typename T> void writeLine(const vector<T>& arg){ if(arg.empty()) { writeLine(); return; } write(arg[0]); for(int i = 1; i < arg.size(); ++i){ write(" "); write(arg[i]); } writeLine(); }
template<typename T> void writeLine(const T& arg) { cout << arg << endl; }
void recursiveCombination(vector<i32>& indexes, i32 s, i32 rest, function<void(vector<i32>&)> f) { if (rest == 0) { f(indexes); } else { if (s < 0) return; recursiveCombination(indexes, s - 1, rest, f); indexes[rest - 1] = s; recursiveCombination(indexes, s - 1, rest - 1, f); } }
void foreachWithCombination(i32 n, i32 k, function<void(vector<i32>&)> f) { auto indexes = vector<i32>(k); recursiveCombination(indexes, n - 1, k, f); }
void foreachWithPermutaton(i32 n, function<void(vector<i32>&)> f) { auto indexes = vector<i32>(); indexes.reserve(n); rep(i, (usize)n) indexes.push_back(i); do f(indexes); while (next_permutation(allOf(indexes))); }
void foreachWithPermutaton(i32 n, i32 k, function<void(vector<i32>&)> f){ foreachWithCombination(n, k, [=](vector<i32>& combIndexes){ foreachWithPermutaton(k, [=](vector<i32>& permIndexes){ auto indexes = vector<i32>(); indexes.reserve(k); rep(i, (usize)k){ indexes.push_back(combIndexes[permIndexes[i]]); } f(indexes); }); }); }
void program();
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    program();
    cin.get();
}

void program() {
    i32 a;
    readValues(a);
    writeLine(a == 0 ? 1 : 0);
}

Measured memory_bytes: 3644
#include<cstdio>
using namespace std;
bool a[100005];
int n,m,sum,b[100005];
int main()
{
  a[1]=1;scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++)  b[i]=1;
  for(int i=1;i<=m;i++)
  {
    int x,y;scanf("%d%d",&x,&y);       
    if(a[x]==1) 
      {a[y]=1;if(b[x]==1) a[x]=0;}
    b[y]++;b[x]--;
  }
  for(int i=1;i<=n;i++)  sum+=a[i];
  printf("%d\n",sum);
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;

int check(int a[], int prog, int m)
{
    int t[9];
    int flag=0;
    for(int i=0;i<9;++i) t[i] = a[i];
    /*
    for(int i=0;i<9;++i)
    {
        for(int j=0;j<t[i];++j) cout << i;
    }
    cout << endl;
    */
    switch(prog)
    {
        case 0:
            for(int i=0;i<9;++i)
            {
                if(t[i] >= 2)
                {
                    t[i] -= 2;
                    flag = max(flag, check(t, ++prog, 0));
                    t[i] += 2;
                }
                if(flag) return 1;
            }
            return 0;
        default:
            for(int i=m;i<9;++i)
            {
                if(t[i] >= 3)
                {
                    t[i] -= 3;
                    if(check(t, prog+1, i)) return 1;
                    else t[i] += 3;
                }
                if(i >= 2 && t[i] > 0 && t[i-1] > 0 && t[i-2] > 0)
                {
                    --t[i];
                    --t[i-1];
                    --t[i-2];
                    if(check(t, prog+1, i)) return 1;
                    else
                    {
                        ++t[i];
                        ++t[i-1];
                        ++t[i-2];
                    }
                }
            }
            flag = 1;
            for(int i=0;i<9;++i) if(t[i]) flag=0;
            return flag;

    }
}
int convert(char n)
{
    switch(n){
        case '1': return 0;
        case '2': return 1;
        case '3': return 2;
        case '4': return 3;
        case '5': return 4;
        case '6': return 5;
        case '7': return 6;
        case '8': return 7;
        case '9': return 8;
    }
}
int main(){
    int n;
    int a[9];
    string str;
    vector<int> ans;
    while(cin >> str)
    {
        for(int i=0;i<9;++i) a[i] = 0;
        for(int i=0;i<str.size();++i) ++a[convert(str[i])];
        /*
        for(int i=0;i<9;++i)
        {
            for(int j=0;j<a[i];++j) cout << i;
        }
        cout << endl;
        */
        for(int i=0;i<9;++i)
        {
            if(a[i] < 4)
            {
                ++a[i];
                if(check(a, 0, 0)) ans.push_back(i+1);
                --a[i];
            }
        }
        if(ans.empty()) cout << 0 << endl;
        else
        {
            cout << ans[0];
            for(int i=1;i<ans.size();i++) cout << ' ' << ans[i];
            cout << endl;
        }
        ans.clear();
    }
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define       M                        1000000007
#define       ll                       long long
#define	      FIO		               ios_base::sync_with_stdio(false);cin.tie(NULL)
#define       ifor(st,lim)             for(int i=st;i<lim;i++)
#define       jfor(stt,llim)           for(int j=stt;j<llim;j++)
#define       eifor(st,lim)            for(int i=st;i<=lim;i++)
#define       ejfor(stt,llim)          for(int j=stt;j<=llim;j++)
#define       blank		                 cout<<'\n';
int n,k;
void solve()
{	
	int n; cin>>n;
	int a[n];
	ifor(0,n) { cin>>a[i];}

	ll suffixSum = 0;
	ll ans = 0;
	for(int i=n-1;i>=0;i--) {
		ans = (ans + (a[i]%M*suffixSum%M)%M)%M;
		suffixSum += a[i];
		suffixSum%=M;
	}
	cout<<ans;
	
}


int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
int t=1;
  while(t--){
    solve();
   } 
}



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


class Graph{
    int V;
    list<int> *adj;

    public:
        Graph(int V){
            this->V=V;
            adj=new list<int>[V+1]; 
        }
        void bfs();
        void addEdge(int u,int v)
        {
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
};
void Graph::bfs(){
    int V=this->V;
    bool*visited=new bool[V+1];
    for(int i=1;i<=V;i++)
    {
        visited[i]=false;
    }
    queue<int> q;
    q.push(1);
    visited[1]=true;
    int arr[V+1];
    while(!q.empty())
    {
        
        int u=q.front();
       
        q.pop();
        for(auto it=adj[u].begin();it!=adj[u].end();it++)
        {
            if(!visited[*it])
            {
                arr[*it]=u;
                visited[*it]=true;
                q.push(*it);
            }
        }
    }
    for(int i=1;i<=V;i++)
    {
        if(!visited[i])
        {
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
    for(int i=2;i<=V;i++)
    {
        cout<<arr[i]<<endl;
    }
}



int main(){
   int N,M;
   cin>>N>>M;
   Graph g(N);
   for(int i=0;i<M;i++)
   {
       int u,v;
       cin>>u>>v;
       g.addEdge(u,v);
   }
   g.bfs();
}

Measured memory_bytes: 19072