akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

struct edge{
  int to, w;
};

using graph = vector<vector<edge>>;

int main() {
  int n; cin >> n;
  graph g(n);

  REP(i, n-1){
    int u, v, w; cin >> u >> v >> w;
    --u; --v;

    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }

  vector<int> col(n, -1);
  function<void(int, int, int)> dfs = [&](int u, int bu, int d){
    if(d % 2 == 0)
      col[u] = 0;
    else
      col[u] = 1;

    for(auto e : g[u]){
      if(e.to != bu) dfs(e.to, u, d + e.w);
    }

  };

  dfs(0, -1, 0);

  for(int x : col) cout << x << endl;

  return 0;
}


Measured memory_bytes: 9728
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

s=S()
ans=0
tmp=0
for i in range(len(s)):
    if s[i]=='A' or s[i]=='C' or s[i]=='G' or s[i]=='T':
        tmp+=1
    else:
        ans=max(ans,tmp)
        tmp=0
ans=max(ans,tmp)
tmp=0
print(ans)


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

using namespace std;

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

    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }

    sort(l.begin(), l.end());
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
        sum += l[i];
    }

    if (l[n - 1] < sum) {
        puts("Yes");
    } else {
        puts("No");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    ll sum = 0;
    forn(n) {
        cin >> v[i];
        sum += v[i];
        sum %= mod;
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = (ans + (v[i] * ((sum - v[i] + mod)%mod)) % mod) % mod;
        // ans = (ans + (v[i] * v[i]) % mod) % mod;
    }
    // cout << ans << '\n';
    ans = (ans * (500000004)) % mod;
    cout << ans << '\n';
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

Measured memory_bytes: 4768
#include<stdio.h>
int main() {

  int in, in2, i, j, stock, box[1000], minDiff = 1000;
  int num1, num2;

  double ans, ans2;

  scanf("%d", &in);

  for(i = 0; i < in; i++) {
    scanf("%d", &in2);
    box[i] = in2;
  }

  for (i = 0; i < in-1; i++) {
    for (j = 0; j < in -1; j++) {
      if (box[j] > box[j+1]) {
	stock = box[j];
	box[j] = box[j+1];
	box[j+1] = stock;
      }
    }
  }
  
  num1 = box[in-1];
  num2 = box[in-2];

  for (i = 0; i < in - 3; i++) {
    if (minDiff > (box[i+1] - box[i])) {
      minDiff = (box[i+1] - box[i]);
    }
  }

  ans2 = (num1 + num2) / (double)minDiff;

  if(minDiff > num1 - num2) {
    minDiff = (num1 - num2);
    num1 = box[in-3];
    num2 = box[in-4];
  }

  if(minDiff > box[in-2] - box[in-3]) {
    minDiff = (box[in-2] - box[in-3]);
    num2 = box[in-4];
  }

  ans = (num1 + num2) / (double)minDiff;

  if(ans > ans2) printf("%f\n", ans);
  if(ans <= ans2) printf("%f\n", ans2);



}




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

using namespace std;

int main(void)
{
	string s;
	long long int count=0;
	cin >> s;

	for(int i=1;i<s.length();i++)
	{
		if(s[i-1]!=s[i])
		{
			count+=1;
		}
	}


	cout << count << endl;

	return 0;
}	


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
int main(){
    int n;
    cin >> n;
    priority_queue<pair<int, int>> Q;
    rep(i, n){
        int A;
        cin >> A;
        A *= (-1);
        Q.push(make_pair(A, i+1));
    }
    rep(i, n){
        cout << Q.top().second << " ";
        Q.pop();
    }
    cout << endl;
}

Measured memory_bytes: 4296
#include<bits/stdc++.h>
#define mes(a, b)  memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 2e5 + 20;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const ll    inf  = 1e9 + 10;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;
int vis[maxn];
int main(){
	int n,k;scanf("%d %d",&n,&k);
	for(int i = 1;i <= k;i++){
		int d;cin >> d;
		while(d--){
			int a;cin >> a;vis[a]++;
		}
	}
	int ans = 0;
	for(int i = 1;i <= n;i++) if(!vis[i]) ans++;
		cout << ans <<"\n";
}

Measured memory_bytes: 3764
// https://atcoder.jp/contests/abc172/tasks/abc172_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();
void solve2();

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, M, K;
  cin >> N >> M >> K;

  VL as(N);
  rep(i, N) cin >> as[i];

  VL bs(M);
  rep(i, M) cin >> bs[i];

  ll b_ct = M;
  ll sum = accumulate(all(bs), 0ll);

  ll res = 0;

  rep(a_ct, N + 1) {
    if (a_ct > 0) sum += as[a_ct - 1];

    while (b_ct > 0 && sum > K) {
      b_ct--;
      sum -= bs[b_ct];
    }

    if (sum > K) break;

    chmax(res, a_ct + b_ct);
  }

  cout << res << "\n";
}

void solve2() {
  ll N, M, K;
  cin >> N >> M >> K;

  VL as(N);
  rep(i, N) cin >> as[i];

  VL bs(M);
  rep(i, M) cin >> bs[i];

  VL b_acc(M + 1);
  rep(i, M) b_acc[i + 1] = b_acc[i] + bs[i];

  ll res = 0;
  ll a_sum = 0;

  rep(a_ct, N + 1) {
    if (a_ct > 0) a_sum += as[a_ct - 1];

    if (a_sum > K) break;

    ll b_max = K - a_sum;

    auto over_b_it = upper_bound(all(b_acc), b_max);
    ll b_ct = over_b_it - b_acc.begin() - 1;

    chmax(res, a_ct + b_ct);
  }

  cout << res << "\n";
}


Measured memory_bytes: 7956
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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;
}

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

int main() {
    string s;
    int N;
    cin >> N;
    map<ll, int> mp;
    rep(i, 0, N) {
        ll a;
        cin >> a;
        mp[a]++;
    }
    vector<ll> a;
    vector<ll> b;

    for (auto x: mp) {
        if (x.second >= 2) {
            a.push_back(x.first);
        }

        if (x.second >= 4) {
            b.push_back(x.first);
        }
    }  
    ll res = 0;
    if (a.size() <= 1 && b.size() == 0) {
        cout << 0 << endl;
        return 0;
    }

    if (a.size() >= 2) {
        res = a[a.size()-1] * a[a.size()-2];
    } 

    if (b.size() >= 1) {
        res = max(b[b.size()-1] * b[b.size()-1], res);
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 6528
# n, k, q = parse.(Int, readline() |> split)
n, k, q = map(split(readline(), " ")) do x
    parse(Int, x)
end

A = zeros(Int, n)
for i in 1:q
    a_i = parse(Int, readline())
    A[a_i] += 1
end

for a in A
    println(a > q - k ? "Yes" : "No")
end

Measured memory_bytes: 163256
x, n = list(map(int, input().split()))

if n != 0:
    p = list(map(int, input().split()))

    i = 0
    while True:
        if not (x - i in p):
            print(x - i)
            break
        elif not (x + i in p):
            print(x + i)
            break
        else:
            i += 1
        
else:
    print(x)

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int A,B;
	cin >> A >> B;
	cout << max( max(A+B,A*B),A-B) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  ll h; cin >> h;
  ll cnt=0, ans=1;
  while(h){ h /= 2; cnt++; }
  rep(i,cnt) ans *= 2;

  cout << ans-1;
  
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MAX 2000005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
 
 
ll n, m, i, j, k, t,r, a, b, c, d, l, w, tmp, g, ans, sum, cnt, neg1, flag, mn, mx, neg2;
ll arr[MAX], sz[MAX], crr[MAX];
vector<ll> v[MAX];
vector<ll> centroid;

int main()
{
    
    ios_base::sync_with_stdio(false);cin.tie(NULL);
   
        cin>>n>>m>>i>>j;
        ans = LLONG_MIN;
        ans = max(ans, n*i);
        ans = max(ans, n*j);
        ans = max(ans, m*i);
        ans = max(ans, m*j);
        cout<<ans;
    

    return 0;   
}

Measured memory_bytes: 50484
#include<stdio.h>

int main(){
    int a,b,c;
    char op;
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?') break;
        else if(op=='+') c=a+b;
        else if(op=='-') c=a-b;
        else if(op=='*') c=a*b;
        else if(op=='/') c=a/b;
        printf("%d\n",c);
    }
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll a[100002], b[100002];
    for(int i = 0; i <= n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] >= b[i]){
            a[i] -= b[i];
            ans += b[i];
        }
        else if(a[i] + a[i + 1] >= b[i]){
            ans += b[i];
            a[i + 1] -= b[i] - a[i];
        }
        else{
            ans += a[i] + a[i + 1];
            a[i + 1] = 0;
        }
    }
    cout << ans << endl;
}


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

#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

using namespace std;

typedef long long int lli;

int main(){
  string s;
  cin >> s;
  int b = 200010;
  int e = 0;
  REP (i, 0, s.size()) {
    if (s[i] == 'A') b = min(b, i);
    if (s[i] == 'Z') e = max(e, i);
  }
  cout << e - b + 1 << endl;
  return 0;
}


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

int main(void) {
  int n, ans = 0;

  if(scanf("%d", &n) == 1);

  for(int i = 1; i <= n; i += 2) {
    int count = 0;
    for(int j = i; j > 0; j--) {
      if(i % j == 0) {
        count++;
      }
    }
    if(count == 8) {
      ans++;
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {
  Scanner sc;

  class Point {
    int x, y;

    Point(int x_, int y_) {
      x = x_;
      y = y_;
    }
  }

  int[][] ofs = new int[][] { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } };

  void run() {
    for ( ;; ) {
      int w, h;
      w = ni();
      h = ni();
      if ( w == 0 ) {
        break;
      }

      boolean[][] W = new boolean[h + 2][w + 2];
      boolean[][] B = new boolean[h + 2][w + 2];
      char[][] field = new char[h + 2][w + 2];
      Queue<Point> wq = new LinkedList<Point>();
      Queue<Point> bq = new LinkedList<Point>();
      for ( int i = 1; i <= h; ++i ) {
        char[] str = sc.next().toCharArray();
        for ( int j = 1; j <= w; ++j ) {
          field[ i ][ j ] = str[ j - 1 ];
          if ( field[ i ][ j ] == 'W' ) {
            wq.add( new Point( j, i ) );
          }
          if ( field[ i ][ j ] == 'B' ) {
            bq.add( new Point( j, i ) );
          }
        }
      }

      while (wq.size() > 0) {
        Point e = wq.poll();
        for ( int[] v : ofs ) {
          Point np = new Point( e.x + v[ 0 ], e.y + v[ 1 ] );
          if ( field[ np.y ][ np.x ] == '.' && !W[ np.y ][ np.x ] ) {
            wq.add( np );
            W[ np.y ][ np.x ] |= true;
          }
        }
      }
      while (bq.size() > 0) {
        Point e = bq.poll();
        for ( int[] v : ofs ) {
          Point np = new Point( e.x + v[ 0 ], e.y + v[ 1 ] );
          if ( field[ np.y ][ np.x ] == '.' && !B[ np.y ][ np.x ] ) {
            bq.add( np );
            B[ np.y ][ np.x ] |= true;
          }
        }
      }

      int wc, bc;
      wc = bc = 0;
      for ( int i = 1; i <= h; ++i ) {
        for ( int j = 1; j <= w; ++j ) {
          if ( W[ i ][ j ] && B[ i ][ j ] )
            continue;
          if ( W[ i ][ j ] )
            ++wc;
          if ( B[ i ][ j ] )
            ++bc;
        }
      }

      System.out.println( bc + " " + wc );
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }

}

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

int main() {
  int n,m,s,c,x=10,y=10,z=10,sum=0;
  cin>>n>>m;
  
  for(int i;i<m;i++){
    cin>>s>>c;
    if((s==1&&c==0)&&n!=1){
      sum=1;
    }
    else if(n-s==0&&(z==10||z==c))
      z=c;
    else if(n-s==1&&(y==10||y==c))
      y=c;
    else if(n-s==2&&(x==10||x==c))
      x=c;
    else sum=1;
  }
  if(z==10)
    z=0;
  if(y==10)
    y=0;
  if(x==10)
    x=0;
  if(sum==1)
    cout << -1<<endl;
  else if(n==1)
    cout<<z<< endl;
  else if(n==2){
    if(y==0)
      y=1;
    cout<<10*y+z<< endl;
  }else if(n==3){
    if(x==0)
      x=1;
    cout<<100*x+10*y+z<< endl;
  }
  
  
    
    
  
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

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

	int n,m,x;
	cin >> n >> m >> x;

	vector<int> cost(n);
	vector<vector<int> > v(n, vector<int> (m,0));

	for(int i = 0; i<n; ++i)
	{
		cin >> cost[i];
		for(int j = 0; j < m; ++j)
		{
			cin >> v[i][j];
		}
	}

	int mini= -1;


	// check all the possiblities
	for(int bits = 1; bits < (1 << n); ++bits)
	{
		vector<int> currUnd(m,0);
		int currPrice = 0;
		// Go through the books
		for(int i = 0; i < n; ++i)
		{
			if((1 << i) & bits)
			{
				currPrice += cost[i];
				for(int j = 0; j< m; ++j)
				{
					currUnd[j]+= v[i][j];
				}
			}
		}
		bool ok  = true;
		for(int j = 0; j< m; ++j)
		{
			if(currUnd[j] < x)
			{
				ok = false;
				break;
			}
		}
		if(ok)
		{
			if(mini== -1)
				mini = currPrice;
			else
				mini = min(mini, currPrice);
		}
	}

	cout << mini;
    return 0;
}

Measured memory_bytes: 3664
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>


using namespace std;


int main(void){
  
  long long X,ans=0,tmp;
  
  
  cin >> X;

  tmp = X /500;

  X -=500*tmp;

  ans += tmp*1000;

  tmp = X /5;

  ans += tmp*5;

   
  cout << ans << endl;
  

  

  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}
//xとyのビットごとの排他的論理和
template<class T> T XOR(T x, T y)
{
	T n = 0;
	while (max(x, y) > pow(2, n)) n++;
	T ans=0;
	for (int i = 0; i <= n; i++)
	{
		T x1 = (x % (T)pow(2, i + 1)) / (T)pow(2, i);
		T y1 = (y % (T)pow(2, i + 1)) / (T)pow(2, i);
		if (x1 != y1) ans += (T)pow(2, i);
	}
	return ans;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int N, M;
	cin >> N >> M;
	if (N == M)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
int main() {
  cin >> n;
  lli x = 0, s = 0;
  while (s < n) {
    x++;
    s += x;
  }
  lli ig = s - n;
  for (lli i = 1; i <= x; ++i) {
    if (i != ig) cout << i << '\n';
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll MAX1 = 2e5+7,
	     MOD = 1e9+7;

ll n, m;
string s, t, ans;

int main(){
	fast_io;
	cin >> n >> s >> t;
	for (int i = 0; i < n; ++i)	ans += s[i], ans += t[i];
	cout << ans;
    return 0;
}
/*                     now or never                         */


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

ll n, m, ans;

int main(){
    cin >> n >> m;
    vector<ll> x(m), l(m - 1);
    for (int i = 0; i < m; i++){
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    for (int i = 0; i + 1 < m; i++){
        ll d = abs(x[i] - x[i + 1]);
        ans += d;
        l[i] = d;
    }
    sort(l.begin(), l.end(), greater<ll>());
    for (int i = 0; i < min(n - 1, m - 1); i++){
        ans -= l[i];
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N, M;
    string s, t;
    map<string, int> S, T;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> s;
        if (!S.count(s)) S[s] = 1;
        else S[s]++;
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        cin >> t;
        if (!T.count(t)) T[t] = 1;
        else T[t]++;
    }
    int Max = 0;
    for (auto p: S) {
        string u = p.first;
        int v = p.second;
        int m = v;
        if (T.count(u)) m -= T[u];
        Max = max(Max, m);
    }
    cout << Max << endl;
    return 0;
}

Measured memory_bytes: 3644
class KMP():
    def __init__(self, pattern):
        self.pattern = pattern
        self.n = len(pattern)
        self.create_k_table()
    
    def create_k_table(self):
        ktable = [-1]*(self.n+1)
        j = -1
        for i in range(self.n):
            while j >= 0 and self.pattern[i] != self.pattern[j]:
                j = ktable[j]
            j += 1
            if i+1 < self.n and self.pattern[i+1] == self.pattern[j]:
                ktable[i+1] = ktable[j]
            else:
                ktable[i+1] = j
        self.ktable = ktable

    def match(self,s):
        n = len(s)
        j = 0
        ret = [0]*n
        for i in range(n):
            while j >= 0 and (j == self.n or s[i] != self.pattern[j]):
                j = self.ktable[j]
            j += 1
            if j == self.n:
                ret[(i-self.n+1)%n] = 1 
        return ret

def main():
    s = input()
    t = input()
    n = len(s)
    m = len(t)
    # 最大は, (n-1)+m 
    # kn >= (n-1)+m
    # k >= 1 +(m-1)/n
    k = 1 - (-(m-1)//n)
    si = s*k
    a = KMP(t)
    b = a.match(si)
    edges = [[] for i in range(n)]
    for i in range(n):
        if b[i]:
            edges[i].append((i+m)%n)
    # loopを見つける
    # start地点をすべて試す
    # 進む方向、戻る方向について別々に求める
    visited = [0]*n
    loop = False
    ans = 0
    for i in range(n):
        # 他のパスから辿られている場合
        if visited[i]:
            continue
        visited[i] = 1
        # →に進む
        cur = i
        right = 0
        while b[cur]:
            nxt = (cur + m) % n
            if visited[nxt]:
                loop = True
                break
            visited[nxt] = 1
            cur = nxt
            right += 1
        cur = i
        left = 0
        while b[(cur-m)%n]:
            nxt = (cur-m) % n
            if visited[nxt]:
                loop = True
                break
            visited[nxt] = 1
            cur = nxt
            left += 1
        if not loop:
            ans = max(ans, right+left)
        else:
            ans = -1
            break
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 124004
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        double A = sc.nextDouble();
        double B = sc.nextDouble();
        double N = sc.nextDouble();
        double Nmax = N;

        if(B<=Nmax){
            if(Nmax != 1) Nmax = B - 1;
        }
        long ans1 = (int)((A*Nmax)/B);
        long ans2 = (long)A * (int)(Nmax/B);
        long ans3 = ans1 - ans2;
        System.out.println(ans3);
        
        /*public static int floor(double a){
            a += 0.5;
            if(a > 0) return((int)a);
            else return((int)a - 1);
        }*/
    }
}

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

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

using namespace std;

bool buyable(int money){
  if(money>=7)return buyable(max(0,money-7)) || buyable(max(0,money-4));
  if(money>=4)return buyable(max(0,money-4));
  if(money==0)return true;
  return false;
}

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

  if(buyable(n)){
    cout<<"Yes";
  }else{
    cout<<"No";
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

int main(void){
 int a,N;
 int cnt=0;
 vector<int> A;
 cin>>N;
 
 for(int i=0; i<N; i++){
  cin>>a;
  A.push_back(a);
 }
 for(int i=1; i<N;){
  if(A[i]!=A[i-1])i++;
  else {
   i+=2;
   cnt++;
  }
 }

 std::cout<<cnt<<std::endl;

   
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int n, v[40], c[40];
    int total[40];
    int sum = 0;
    int i, j, k;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &v[i]);
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &c[i]);
    }
    for (i = 0; i < n; i++) {
        total[i] = v[i] - c[i];
        if (total[i] >= 0) {
            sum += total[i];
        }
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
 
#define mod 1000000007

ll ebob(ll a, ll b){
	if(a == 0) return b;
	return ebob(b%a, a);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	vector<int> vec(n);
	bool check = 0;
	int u = 1;
	int res = 0;
	for(int i = 0; i < n; i++){
		cin>>vec[i];
		if(vec[i] != u){
			res++;
		}else{
			u++;
		}
		if(vec[i] == 1) check = 1;
	}
	if(!check){
		cout<<-1;
		return 0;
	}else{
		cout<<res;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

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

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

int main()
{
	int n;
	cin >> n;
	vector<int> wl(n);
	vector<int> el(n);
	string s;
	cin >> s;
	rep(i, n) {
		if (i - 1 >= 0) {
			wl[i] = wl[i - 1];
			el[i] = el[i - 1];
		}
		if (s[i] == 'W') {
			wl[i]++;
		}
		else{
			el[i]++;
		}
	}
	int ans = 1000000000;
	rep(i, n) {
		int ec = 0;
		int wc = 0;
		if (i - 1 > 0) {
			wc = wl[i - 1];
		}
		ec = el[el.size() - 1] - el[i];
		ans = min(ans, ec + wc);
	}
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}



Measured memory_bytes: 6232
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod=1e9+7;
ll power(ll a,ll b)
{
    ll result=1;
    while(b>0)
    {
        if(b%2==1)
        {
            result=(result*a)%mod;
        }
        a=(a*a)%mod;
        b/=2;
    }
    return result;
}
int main()
{
   vector<ll> fact(2e6,1);
   for(int i=2;i<2e6;i++)
   {
       fact[i]=(fact[i-1]*i)%mod;
   }
   ll n;
   cin>>n;
   ll result=power(10ll,n);
   ll result2=power(8ll,n);
   ll sum=0;
   for(int i=1;i<=n;i++)
   {
       ll val=(fact[n]*power(fact[i],mod-2))%mod;
       val=(val*power(fact[n-i],mod-2))%mod;
       val=(val*power(8,n-i))%mod;
       sum=(sum+val)%mod;
   }
   cout<<(result-result2-2*sum+2*mod)%mod;
    
}

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

using namespace std;

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

	int length = (int)S.length();

	for(int i = 0; i < length; i++){
		if(S.at(i) + N > 90){
			S.at(i) = S.at(i) + N - 26;
		}else{
			S.at(i) = S.at(i) + N;
		}
	}

	cout << S << endl;
	return 0;
}




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

using namespace std;

int main(){
	
	int N;
	
	int count[30];
	int count_min[30];
	
	cin >> N;
	
	for(int i = 0; i < 30; i++){
		count_min[i] = 1000;
	}
	
	for(int i = 0; i < N; i++){
		
		for(int j = 0; j < 30; j++){
			count[j] = 0;
		}
		string str;
		cin >> str;
		for(int j = 0; j < str.size(); j++){
			count[str[j] - 'a']++;
		}
		for(int j = 0; j < 30; j++){
			count_min[j] = min(count[j], count_min[j]);
		}
	}
	
	for(int i = 0; i < 30; i++){
		for(int j = 0; j < count_min[i]; j++){
			cout << (char)('a' + i);
		}
	}
	
	cout << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
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)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    int a,b,x;
    cin >> x >> a >> b;
    cout << (x - a) % b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int Number, i, j;
    float x[10], total;
    char name[5];

    scanf("%d", &Number);

    for(i = 0; i < Number; i++){
        scanf("%f",&x[i]);
        scanf("%s",name);

        if(name[0] == 'J'){
            total = total + x[i];
        }else if(name[0] == 'B'){
            x[i] = x[i] * 380000;
            total = total + x[i];
        }
    }
    printf("%f",total);
}

Measured memory_bytes: 384
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

// 隣り合う要素の積をすべて4の倍数に出来るか.
// まず4を因数にもつ合成数xの前後はok.
// 2を因数にもつ整数yは２つ隣り合う必要がある.
int main() {
  int n;in(n);
  vector<ll> A(n);
  loop(i,0,n) in(A[i]);
  int cnt4 = 0;
  int cnt2 = 0;
  for (auto &&a: A) {
    if (a%4==0) cnt4++;
    else if (a%2 == 0) cnt2++;
  }
  int cnt = n-(cnt2/2)*2; // ｙを2つペアにして消去.
  if (cnt <= cnt4*2 + 1) print("Yes");
  else print("No");
  return 0;
}


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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    double sm = 0.0, p = (1 << M);
    p = 1/p;
    int x = 1900*M + 100*(N - M);
    
    sm = x/p;
    int ans = (int)sm;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
//  LINK ZADATKA: http://code-festival-2017-quala.contest.atcoder.jp/tasks/code_festival_2017_quala_d

#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <fstream>
#include <cstring>
#include <string>
#include <climits>

using namespace std;

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define INF 999999999
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define _gcd __gcd
#define eps 1e-9

int n, m,k; char sol[550][550];
int main(){
	
	sd(n); sd(m);

	sd(k);
	int zbr, oduz;
	
	/*REP(i, n){
		REP(j, m){
			printf("%d %d  ", i+j, i-j);
		}
		printf("\n");
	}*/
	
	REP(i, n){
		REP(j, m){	
			zbr = i+j;
			oduz = i-j;
			zbr += MAXN;
			zbr /= k;
			oduz += MAXN;
			oduz /= k;
			zbr %= 2; oduz %= 2;
			//printf("%d %d ", zbr, oduz);
			if(zbr == 0 && oduz == 0) sol[i][j] = 'R';
			if(zbr == 0 && oduz == 1) sol[i][j] = 'G';
			if(zbr == 1 && oduz == 0) sol[i][j] = 'Y';
			if(zbr == 1 && oduz == 1) sol[i][j] = 'B';
		}
		//printf("\n");
	}
	
	REP(i, n) printf("%s\n", sol[i]);
	return 0;
}


Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int a, b;
    cin >> a >> b;
    cout << (1 + b - a) * (b - a) / 2 - b << endl;
}


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

using namespace std;

int main()
{
    int N;
    int A[210];
    
    cin>>N;
    for(int i =0; i < N; i++){
        cin>>A[i];
    }
    
    int ans = 0;
    
    while(true){
        bool f = false;
        for(int i =0; i < N; i++){
          if(A[i] % 2 == 1){
             f = true;
          }
          A[i] /= 2;
        }
        if(f){
            break;
        }
        ans++;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
 
typedef vector< vector< int > > Graph;
 
inline void dfs(int idx, const Graph& graph, vector< bool >& used, vector< int >& order){
  if(used[idx]) return;
  used[idx] = true;
  for(int i = 0; i < graph[idx].size(); i++) {
    dfs( graph[idx][i], graph, used, order);
  }
  order.push_back(idx);
}
inline void rdfs(int idx, const Graph& rgraph, vector< int >& cmp, const int& cnt){
  cmp[idx] = cnt;
  for(int i = 0; i < rgraph[idx].size(); i++) {
    if(cmp[rgraph[idx][i]] == -1) rdfs( rgraph[idx][i], rgraph, cmp, cnt);
  }
}
  
size_t StronglyConnectedComponents(const Graph& graph, const Graph& rgraph, vector< int >& cmp){
  size_t cnt = 0;
  cmp.assign( graph.size(), -1);
  static vector< bool > used(graph.size(), false);
  vector< int > order;
  for(int i = 0; i < graph.size(); i++) {
    dfs(i, graph, used, order);
  }
  reverse( order.begin(), order.end());
  for(int i = 0; i < order.size(); i++) {
    if(cmp[order[i]] == -1) rdfs( order[i], rgraph, cmp, cnt), cnt++;
  }
  return cnt;
}
 
typedef pair< int , int > Pi;
 
int main(){
  int n, m;
  cin >> n;
  cin >> m;
  Graph graph(n), rgraph(n); //?????????????????????????????????
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    --a, --b;
    graph[a].push_back(b);
    rgraph[b].push_back(a);
  }
  vector< int > cmp;
  int sz = StronglyConnectedComponents( graph, rgraph, cmp);
 
  vector< Pi > ret(n);
  for(int i = 0; i < n; i++){
    ret[i] = make_pair( cmp[i], i);
  }
  sort( ret.begin(), ret.end());
  bool flag = false;
  for(int i = 0; i < n; i++){
    cout << ret[i].second + 1 << endl;
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

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

    vector<int> dp(n,INF);
    dp[0]=0;

    for (int i = 0; i < n-1; i++)
    {
        for (int j = i+1; j < n && j <= i+k; j++)
        {
            chmin(dp[j],dp[i]+abs(h[j]-h[i]));
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N, M, X = (int(_) for _ in input().split())
    A = list(int(_) for _ in input().split())
    print(min(len([i for i in A if i < X]),len([i for i in A if i > X])))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

int main(){
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  //cout << sqrt(pow((x2-x1), 2) + pow((y2-y1), 2)) << endl;
  printf("%f\n", sqrt(pow((x2-x1), 2) + pow((y2-y1), 2)));
}



Measured memory_bytes: 3300
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main()
{
	int N, D;

	cin >> N >> D;


	std::vector<std::vector<int>> vector(N, std::vector<int>(D));

	for (int i = 0; i < N; ++i)
	{
		for (int d = 0; d < D; ++d)
		{
			cin >> vector[i][d];

		}
	}

	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		for (int j = i + 1; j < N; ++j)
		{
			int tmp = 0;
			for (int d = 0; d < D; ++d)
			{
				int tmp2 = (vector[i][d] - vector[j][d]);
				tmp += tmp2 * tmp2;
			}

			float tmp3 = sqrt(tmp);

			if (tmp3 - (int)tmp3 == 0)
			{
				ans++;
			}
		}

	}

	cout << ans;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>
#include <map>
#include <string>
#include <deque> 

using namespace  std;
typedef long long ll;
typedef pair<ll,ll> pii;

int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  string s;
  cin >> s;
  int r = 0, ret = 0;
  for(int i = 0; i < s.length(); ++i){
    if(r > 0){
      if(s[i] == 'g') ++ret;
      --r;
    }else{
      if(s[i] == 'p')
        --ret;
      ++r;
    }
  }
  cout << ret << "\n";
  return 0;
}

Measured memory_bytes: 512
import numpy as np


def main():
    s = input()

    b = []
    cnt = 0
    for i, e in enumerate(s):
        if e == "B":
            b.append(i)
            cnt += 1

    b = np.array(b)
    b_fin = np.arange(len(s) - cnt, len(s))

    ans = int(np.sum(b_fin - b))

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21956
import sys
fin = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush


def initialize(adj, s):
    MAX_NUM = float('inf')
    parent = {s: None}
    d = {vertex: MAX_NUM for vertex in adj.keys()}
    d[s] = 0
    return d, parent


def initialize_int(adj, s):
    """
    assume that all vertex in {0, 1, 2, ..., N - 1}
    """
    N = len(adj)
    MAX_NUM = float('inf')
    d = [MAX_NUM] * N
    d[s] = 0
    parent = [None] * N
    return d, parent


# Dijkstra can work using a minheap which does not have decrease_key.
# and also we do not have to implement Vertex class.
# Instead, we can use (distance, vertex).
# in this case, the time it takes is O(ElgE).
# E is at most O(V^2), thus O(ElgE) = O(ElgV).
def dijkstra_simple(adj, w, s):
    d, parent = initialize_int(adj, s)
    priority_queue = []
    heappush(priority_queue, (d[s], s))
    while priority_queue:
        distance, source = heappop(priority_queue) 
        for neighbor in adj[source]:
            new_distance = distance + w[(source, neighbor)]
            if new_distance < d[neighbor]:
                d[neighbor] = new_distance
                parent[neighbor] = source
                heappush(priority_queue, (new_distance, neighbor))
    return d


n, m, s, t = [int(elem) for elem in fin().split()]
s -= 1
t -= 1
adj = defaultdict(list)
yen_weights = dict()
snuuk_weights = dict()
for _ in range(m):
    u, v, a, b = [int(elem) for elem in fin().split()]
    u -= 1
    v -= 1
    for v1, v2 in [(u, v), (v, u)]:
        adj[v1].append(v2)
        yen_weights[(v1, v2)] = a
        snuuk_weights[(v1, v2)] = b

d_yen = dijkstra_simple(adj, yen_weights, s)
d_snuuk = dijkstra_simple(adj, snuuk_weights, t)
min_cost = float('inf')
min_cost_after_each_year_reversed = []
for vertex in reversed(range(n)):
    min_cost = min(min_cost, d_yen[vertex] + d_snuuk[vertex])
    min_cost_after_each_year_reversed.append(min_cost)

initial_money = 10**15
for cost in reversed(min_cost_after_each_year_reversed):
    print(initial_money - cost)


Measured memory_bytes: 99040
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
N = inp.shift() * 1
o = {}
for (i=0; i<26; i++) {
    o[String.fromCharCode(97 + i)] = 50
}
for (i=0; i<N; i++) {
    s = inp[i]
    t = {}
    for (j=0;j<s.length;j++) {
        if (!t[s[j]]) t[s[j]] = 0
        t[s[j]] += 1
    }
    for (j=0; j<26; j++) {
        c = String.fromCharCode(97 + j)
        if (t[c] && o[c] > t[c]) {
            o[c] = t[c]
        }
        if (!t[c]) {
            o[c] = 0
        }
    }
}
ans = ''
for (i=0; i<26; i++) {
    c = String.fromCharCode(97 + i)
    while (o[c] > 0) {
        ans += c
        o[c] -= 1
    } 
}
console.log(ans)


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

int main(void){
  int N, K;
  long long int ans = 0;

  cin >> N >> K;
  
  int l[N] = {0};
  int counter = 0;
  for(int i = 0; i < K; ++i){
    if((2*i) % K == 0){
      l[counter] = i;
      ++counter;
    } else {
      
    }
  }
  
  for(int i = 0; i < counter; ++i){
    long long int d1[counter] = {0};
    long long int d2[counter] = {0};
    long long int temp1 = 0;
    long long int temp2 = 0;

    while(l[i] + K*temp1 <= 0){

      ++temp1;
    }
    while(l[i] + K*d1[i] <= N){

      ++d1[i];
    }
    while(K - l[i] + K*temp2 <= 0){
      ++temp2;
    }
    while(K - l[i] + K*d2[i] <= N){

      ++d2[i];
    }
    if((d1[i] > temp1) && (d2[i] > temp2)){
      
    ans += (d1[i] - temp1)*(d1[i] - temp1)*(d2[i] - temp2);
    } else {
      
    }

    temp1 = temp2 =  0;
  }

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


Measured memory_bytes: 1024