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

long N, K, ans;
vector<long> A;

int main(void) {

    cin >> N >> K;
    A.resize(N, 0);

    for (long i = 0; i < K; i++) {
        long d; cin >> d;
        for (long j = 0; j < d; j++) {
            long a; cin >> a; a--;
            A[a]++;
        }
    }

    for (auto e: A) {
        if (e == 0) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3604
#include <stdio.h>
int main()
{
  int n,a,b,c;
  scanf("%d", &n);
  a = n/100;
  b = n/10%10;
  c = n%10;
  if(a == 7 || b == 7 || c == 7)
    printf("Yes");
  else
    printf("No");
  return (0);
}

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

typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

const int N = 1000;
const int M = 2000;

struct Edge {
  int u, v, w;
}e[M];

ll d[N];
bool neg[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i=0; i<m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    e[i].u = u-1;
    e[i].v = v-1;
    e[i].w = w;
  }
  for (int i=0; i<n; i++) {
    d[i] = -LINF; 
    neg[i] =false;
  }
  d[0] = 0;
  for (int i=0; i<n-1; i++) {
    for (int j=0; j<m; j++) {
      int u = e[j].u, v=e[j].v, w=e[j].w;
      if (d[u] + w > d[v]) d[v] = d[u] + w;
    }
  }
  for (int i=0; i<n; i++) {
    for (int j=0; j<m; j++) {
      int u = e[j].u, v=e[j].v, w=e[j].w;
      if (d[u] + w > d[v]) {
        d[v] = d[u] + w;
        neg[v] = true;
      }
    }
  }
  if (neg[n-1]) {
    cout << "inf" << endl;
    return 0;
  }
  cout << d[n-1] << endl;
  return 0;
}


Measured memory_bytes: 3672
#ifndef ___Class_RMQ
#define ___Class_RMQ

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>

// ------ RMQ Class ------ //
template<typename Type> class RMQ {
private:
	unsigned size_; std::vector<Type> dat;
	inline Type query_(unsigned a, unsigned b, unsigned k, unsigned l, unsigned r) {
		if (r <= a || b <= l) return std::numeric_limits<Type>::max();
		if (a <= l && r <= b) return dat[k];
		Type lc = query_(a, b, (k << 1), l, (l + r) >> 1);
		Type rc = query_(a, b, (k << 1) + 1, (l + r) >> 1, r);
		return std::min(lc, rc);
	}
public:
	RMQ() : size_(0), dat(std::vector<Type>()) {};
	RMQ(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RMQ(T begin_, T end_) {
		unsigned n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (unsigned i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (unsigned i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(unsigned i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
		}
	}
	inline Type query(unsigned l, unsigned r) {
		return query_(l, r, 1, 0, size_);
	}
};

#endif

#include <cstdio>
#pragma warning(disable : 4996)

int n, q, c, x, y;
int main() {
	scanf("%d%d", &n, &q);
	RMQ<int> Q(n);
	while (q--) {
		scanf("%d%d%d", &c, &x, &y);
		if (c == 0) Q.update(x, y);
		else printf("%d\n", Q.query(x, y + 1));
	}
	return 0;
}

Measured memory_bytes: 3424
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
	int arr[3];
	for(int i = 0; i < 3; i++) scanf("%d", &arr[i]);

	sort(arr, arr + 3);

	printf("%d\n", arr[2] * 10 + arr[0] + arr[1]);
	return 0;	
}


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

#define LL long long

#define FOR(INDEX, START, END) for (int INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (int INDEX = 0; INDEX < (COUNT); ++INDEX)

int main()
{
	map<int, bool> flags;
	int s;
	cin >> s;

	for (int i = 0; i <= 1000000; ++i) {
		if (flags[s]) {
			cout << i + 1 << endl;
			break;
		}
		flags[s] = true;

		if (s % 2 == 0) {
			s = s / 2;
		}
		else {
			s = 3 * s + 1;
		}
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {

  // 最大公約数
  public static long gcd (long m,long n) {
    if (m < n) return gcd(n,m);
    if (n == 0) return m;
    return gcd(n,m%n);
  }

  // 最小公倍数
  public static long lcm (long m,long n) {
    return m*n/gcd(m,n);
  }

  // 素数判定
  public static boolean isPrime (long n) {
    if (n == 2) return true;
    if (n < 2 || n%2 == 0) return false;
    double d = Math.sqrt(n);
    for (int i = 3; i <= d; i+=2) {
      if (n%i == 0) {
        return false;
      }
    }
    return true;
  }

  public static final long gcd3(long[] param) {
    int len = param.length;
    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
    for (int i = 1; i < len - 1; i++) {
        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
    }
    return g;
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();

    long[] data = new long[3];

    long sum = 0;

    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int h = 1; h <= k; h++) {
          data[0] = i;
          data[1] = j;
          data[2] = h;
          sum += gcd3(data);
        }
      }
    }

    System.out.println(sum);

  }

}


Measured memory_bytes: 36296
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int sum_temp(int A, int B, int C, int K) {
	return A*pow(2,K) + B + C;
}

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	int temp1 = sum_temp(A, B, C, K);
	int temp2 = sum_temp(B, A, C, K);
	int temp3 = sum_temp(C, A, B, K);
	cout << max({ temp1, temp2, temp3 }) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 100


int main(){
	char a[N + 1];
	bool c[26];
	f(i, N + 1)a[i] = 0;
	f(i, 26)c[i] = false;
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = false;
	ans = 0;
	scanf("%s", a);
	n = strlen(a);
	f(i, n){
		c[(a[i] - 97)] = true;
	}
	if (n < 26){
		f(i, 26){
			if (!c[i]){
				a[n] = i + 97;
				v = true;
				break;
			}
		}
	}
	else{
		for (int i = n - 1; i >= 1; i--){
			c[a[i] - 97] = false;
			if (a[i - 1] < a[i]){
				c[a[i-1] - 97] = false;
				for (int j = a[i - 1] - 96; j < 26; j++){
					if (!c[j]){
						a[i - 1] = 97 + j;
						c[j] = true;
						break;
					}
				}
				v = true;
				k = i;
				for (int j = i; j < n; j++)a[j] = 0;
				break;
			}
		}
	}


	if(v)printf("%s\n", a);
	else printf("-1\n");


	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

		int N = sc.nextInt();   //標準入力
		String Ns = Integer.toString(N) ;   //IntをStringに変換する

		int fx = 0;   //合計を初期化
		String ans = "No" ;   //解答の出力

		for(int i = 0; i < Ns.length(); i++) {   //リストの中身を合計する
			fx += Integer.parseInt(Ns.substring(i, i + 1));   //NsをStringからIntに変換する
		}

		if ( N % fx == 0 ) {
			ans = "Yes" ;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
import sys
sys.setrecursionlimit(10**6)
n = int(input())
inf = float("inf")
road = [dict() for _ in range(n+1)]
for _ in range(n-1):
  a,b,c = map(int, input().split())
  road[a][b] = c
  road[b][a] = c
q,k = map(int, input().split())
dfs = [inf]*(n+1)
dfs[k] = 0
def dodfs(x):
  for i in road[x]:
    if dfs[i] == inf:
      dfs[i] = dfs[x] + road[x][i]
      dodfs(i)
  return   
dodfs(k)
for _ in range(q):
  x,y = map(int, input().split())
  print(dfs[x] + dfs[y])

Measured memory_bytes: 140920
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.gir","r",stdin);freopen ("myfile.cik","w",stdout);
#define mod 1000000007
using namespace std;

ll n,ar[N],a,b,tut[N],sum,m;


int main()
{
	fast;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		int k;
		cin>>k;
		for(int j=1;j<=k;j++)
		{
			int tmp;
			cin>>tmp;
			tut[tmp]++;
		}
	}
	for(int i=1;i<=m;i++)
		if(tut[i]==n)
			sum++;
	cout<<sum;

}

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

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

int main()
{
	int a, b, g, l;
	while (cin >> a >> b)
	{
	    g = gcd(a, b); l = a / g * b;
		cout << g << ' ' << l << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, k;

void Mod(int &left){
   left %= mod;
   left += mod;
   left %= mod;
}

int32_t main(){_
   
   cin>>n>>k;

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

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

   if (k == n){
      int pro = 1;
      for (int i = 0; i < n; ++i)
      {
         pro *= a[i];
         Mod(pro);
      }
      cout<<pro;
      exit(0);
   }

   if (k % 2){
      if (a.back() == 0){
         cout<<0;
         exit(0);
      }
      else if (a.back() < 0){
         int pro = 1;
         for (int i = n-1; i >= n-k; --i){
            pro *= a[i];
            Mod(pro);
         }
         cout<<pro;
         exit(0);
      }
   }

   if ((k % 2 == 0) and a.back() <= 0){
      int pro = 1;
      for (int i = 0; i < n and k; i += 2)
      {
         int mult = a[i] * a[i+1];
         Mod(mult);
         pro *= mult;
         Mod(pro);
         k -= 2;
      }
      cout<<pro;
      exit(0);
   }
   
   int pro = 1, i = 0, j = n-1;
   if (k % 2){
      // i am sure that last element is > 0
      assert(a.back() > 0);
      pro = a.back();
      --k;
      --j;
   }

   while(k){
      int left = a[i] * a[i+1];
      int right = a[j] * a[j-1];
      if (left > right){
         Mod(left);
         pro *= left;
         Mod(pro);
         i += 2;
      }
      else{
         Mod(right);
         pro *= right;
         Mod(pro);
         j -= 2;
      }
      k -= 2;
   }

   cout<<pro;

   return 0;
}

Measured memory_bytes: 5080
#include <bits/stdc++.h>
using namespace std;
int main(){
	int r,c;
	while(1){
		cin>>r>>c;
		if(r==0)	return 0;
		int senbei[r][c];
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++)	cin>>senbei[i][j];
		}
		int ans=0;
		bool temp[r][c];
		for(int t=0;t<(1<<r);t++){
			for(int i=0;i<r;i++){
				for(int j=0;j<c;j++){
					temp[i][j]=senbei[i][j];
				}
			}
			for(int i=0;i<r;i++){
				if((t>>i)%2==1){
					for(int j=0;j<c;j++)	temp[i][j]^=1;
				}
			}
			int cnt=0;
			for(int i=0;i<c;i++){
				int omote=0,ura=0;
				for(int j=0;j<r;j++){
					if(temp[j][i])	omote++;
					else 	ura++;
				}
				cnt+=max(omote,ura);
			}
			ans=max(ans,cnt);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1648
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <random>

using ll = long long;

//vector
template <class T>
using vec = std::vector<T>;

void solve()
{
    using namespace std;
    
    string A, B, C;
    cin >> A >> B >> C;

    if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

}

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

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

void main() {
    immutable int INF = 1 << 30;

    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto K = s[2];
    auto C = readln.split.map!(to!int).array;
    auto G = new Tuple!(int, long)[][](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, s[2].to!long);
        G[s[1]-1] ~= tuple(s[0]-1, s[2].to!long);
    }

    if (K == 1) {
        writeln(0);
        return;
    }

    Tuple!(int, int, long)[] E;
    
    foreach (i; 0..N) {
        int n = C[i] == 0 ? i + N + 1 : C[i];
        foreach (j; G[i]) {
            int m = C[j[0]] == 0 ? j[0] + N + 1 : C[j[0]];
            if (j[0] > i) continue;
            if (n == m) continue;
            E ~= tuple(n, m, j[1]);
        }
    }

    E.sort!"a[2] < b[2]"();
    auto uf = new UnionFind(3*N);
    long ans = 0;
    int cnt = 0;

    foreach (e; E) {
        if (uf.find(e[0]) == uf.find(e[1])) continue;
        uf.unite(e[0], e[1]);
        ans += e[2];
        cnt += 1;
        if (cnt == K-1) {
            ans.writeln;
            return;
        }
    }

    writeln(-1);
}


class UnionFind {
    int N;
    int[] table;
    long[] cost;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        cost = new long[](N);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
        cost[x] += cost[y];
    }
}


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;

template< typename flow_t >
struct Dinic {
  const flow_t INF;

  struct edge {
    int to;
    flow_t cap;
    int rev;
    bool isrev;
  };

  vector< vector< edge > > graph;
  vector< int > min_cost, iter;

  Dinic(int V) : INF(numeric_limits< flow_t >::max()), graph(V) {}

  void add_edge(int from, int to, flow_t cap) {
    graph[from].emplace_back((edge) {to, cap, (int) graph[to].size(), false});
    graph[to].emplace_back((edge) {from, 0, (int) graph[from].size() - 1, true});
  }

  bool bfs(int s, int t) {
    min_cost.assign(graph.size(), -1);
    queue< int > que;
    min_cost[s] = 0;
    que.push(s);
    while(!que.empty() && min_cost[t] == -1) {
      int p = que.front();
      que.pop();
      for(auto &e : graph[p]) {
        if(e.cap > 0 && min_cost[e.to] == -1) {
          min_cost[e.to] = min_cost[p] + 1;
          que.push(e.to);
        }
      }
    }
    return min_cost[t] != -1;
  }

  flow_t dfs(int idx, const int t, flow_t flow) {
    if(idx == t) return flow;
    for(int &i = iter[idx]; i < graph[idx].size(); i++) {
      edge &e = graph[idx][i];
      if(e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
        flow_t d = dfs(e.to, t, min(flow, e.cap));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  flow_t max_flow(int s, int t) {
    flow_t flow = 0;
    while(bfs(s, t)) {
      iter.assign(graph.size(), 0);
      flow_t f = 0;
      while((f = dfs(s, t, INF)) > 0) flow += f;
    }
    return flow;
  }

  void output() {
    for(int i = 0; i < graph.size(); i++) {
      for(auto &e : graph[i]) {
        if(e.isrev) continue;
        auto &rev_e = graph[e.to][e.rev];
        cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl;
      }
    }
  }
};


signed main(){
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    Dinic<i64> f(n + 2);
    i64 sum = 0;
    for(int i = 1; i <= n; ++i){
        if(a[i] <= 0){
            f.add_edge(0, i, -a[i]);
        }else{
            sum += a[i];
            f.add_edge(i, n + 1, a[i]);
        }
    }
    for(int i = 1; i <= n; ++i){
        for(int j = i * 2; j <= n; j += i)
            f.add_edge(i, j, INF);
    }
    cout << sum - f.max_flow(0, n + 1) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ll = int64_t;
using VL = vector<ll>;
using VD = vector<double>;
using VVL = vector<VL>;

#define FOR(i, start, end) for(ll i = (start), (i ## xxxx_end)=(end); i < (i ## xxxx_end); ++i)
#define FORD(i, start, end) for(ll i = (start), (i ## xxxx_end)=(end); i > (i ## xxxx_end); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPD(i, n) FORD(i, n - 1, -1)

#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}

#define INF 1000000000000
#define MOD 10000007

ll N, W;
VVL WV, dp;

void solve() {
    cin >> N >> W;
    WV = VVL(N, VL(2));
    for (auto &i : WV) cin >> i[0] >> i[1];
    const ll V = N * 1000;
    // dp[i][j]: i個目まで価値の総和がj以上になるように選んだときの重さの最小値
    dp = VVL(N + 1, VL(V + 1, INF));
    dp[0][0] = 0;
    FOR(i, 1, N + 1) {
        const ll w = WV[i - 1][0];
        const ll v = WV[i - 1][1];
        REP(j, V + 1) {
            if(j < v) {
                dp[i][j] = dp[i - 1][j];
            }
            else {
                dp[i][j] = min(dp[i - 1][j], w + dp[i - 1][j - v]);
            }
        }
    }

    REPD(j, V + 1) {
        if(dp[N][j] <= W) {
            print(j);
            break;
        }
    }
}

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

Measured memory_bytes: 80256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    int N, M;
    cin >> N >> M;
    cout << N * M << endl;

    return 0;
}



Measured memory_bytes: 3120
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}
#[allow(unused_imports)]
use input::*;

fn main() {
    let s = str2vec(&input_line_str());
    let mut i = 0;
    while i < s.len() {
        print!("{}", s[i]);
        i += 2;
    }
    println!("");
}

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

int main(){
  int N;
  cin >> N;
  int d;
  set<int> s;
  for(int i=0;i<N;i++){
    cin >> d;
    s.insert(d);
  }
  cout << s.size() << endl;
  return 0;
}


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

int INF = 100100100;
using namespace std;

int h[] = {0, -1, 0, 1};
int w[] = {1, 0, -1, 0};

//座標zが迷路の枠からはみ出したらtrueを返す
bool over(int z, int size){
  bool flag = true;
  if(0<=z && z<size)
    flag = false;
    return flag;
}

int main(void){
  int i, j, k;
  int H, W;
  cin >> H >> W;
  char S[H][W];
  for(i=0; i<H; i++)
    for(j=0; j<W; j++)
      cin >> S[i][j];


  //次に処理する座標を入れていく
  queue< pair<int, int> > q;

  //(縦, 横)をメンバに持つ座標型の変数
  pair<int, int> now, next;
  int max = 0;
  
  //各マスをstartとして探索する
  for(i=0; i<H; i++){
    for(j=0; j<W; j++){
      //startから各地点までの距離を格納する二次元配列
      vector<vector<int>> dist(H, vector<int>(W, INF));
      dist[i][j] = 0;
      //壁からはスタートしない
      if(S[i][j] == '#')
	continue;
      //startをキューに入れる
      q.push(make_pair(i, j));
      while(!q.empty()){
	now = q.front();
	q.pop();
	//cout << "now : " << now.first << ", " << now.second << endl;
	for(k=0; k<4; k++){
	  int next_h = now.first  + h[k];
	  int next_w = now.second + w[k];
	  //cout << "  next (" << next_h << ", " << next_w << ") : ";
	  //nextが迷路からはみ出すなら次のkへ
	  if( over(next_h, H) || over(next_w, W) ){
	    //cout << "over" << endl;
	    continue;
	  }
	  next = make_pair(next_h, next_w);
	  //nextが壁なら次のkへ
	  if(S[next.first][next.second] == '#'){
	    //cout << "wall" << endl;
	    continue;
	  }
	  //nextが探索済みなら次のkへ
	  if(dist[next.first][next.second] != INF){
	    //cout << "visited" << endl;
	    continue;
	  }
	  //nextが未探索ならばキューに入れて距離をnowから計算する
	  q.push(next);
	  dist[next.first][next.second] = dist[now.first][now.second]+1;
	  //cout << "push" << endl;
	}	
      }
      //最後の点が，(i, j)からの距離が最大となる
      //その距離をHW個のstart地点から考えて最大値を更新していく
      if(dist[now.first][now.second] > max)
	max = dist[now.first][now.second];
    }
  }

  cout << max << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Deque<String> formula = new ArrayDeque<String>();
        Scanner scan = new Scanner(System.in);

        while(scan.hasNext())
        {
            String input = scan.next();
            double num2,num1;
            switch(input)
            {
                case "+":
                    num2 = Double.parseDouble(formula.poll());
                    num1 = Double.parseDouble(formula.poll());
                    formula.push(String.valueOf(num1+num2));
                    break;
                case "-":
                    num2 = Double.parseDouble(formula.poll());
                    num1 = Double.parseDouble(formula.poll());
                    formula.push(String.valueOf(num1-num2));
                    break;
                case "/":
                    num2 = Double.parseDouble(formula.poll());
                    num1 = Double.parseDouble(formula.poll());
                    formula.push(String.valueOf(num1/num2));
                    break;
                case "*":
                    num2 = Double.parseDouble(formula.poll());
                    num1 = Double.parseDouble(formula.poll());
                    formula.push(String.valueOf(num1*num2));
                    break;
                default:
                    formula.push(input);
                    break;
            }
        }
        double ans = Double.parseDouble(formula.poll());
        if(ans==(int)ans)
        {
            System.out.println((int)ans);
        }
        else
        {
            System.out.println(ans);
        }
    }
}

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

int main() {
  long A,B,K;
  cin >> A >> B >> K;
  
  if(K - A - B >= 0){
    cout << 0 << " " << 0 << endl;
  } else if (K - A >= 0){
    cout << 0 << " " << A + B - K << endl;
  } else {
    cout << A - K << " " << B << endl;
  }
}


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

int main(){
    int n,t,tim1,sec1,tim2,sec2,tot1,tot2;
    string s,na1,na2;
    char trash;
    stringstream ss;
    vector <pair<string,int> > ans;
    cin >> n >> t;
    cin.ignore();
    getline(cin,s); ss << s;
    ss>>tim1>>trash>>sec1>>na1>>tim2>>trash>>sec2>>na2;
    tot1 = tim2*60 + sec2;
    for(int i=1;i<n;i++){
        ss.clear();
        getline(cin,s); ss << s;
        ss>>tim1>>trash>>sec1>>na1>>tim2>>trash>>sec2>>na2;
        tot2 = tim1*60 + sec1;
        if(tot2 - tot1 >= t) ans.push_back(make_pair(na1,tot2-tot1));
        tot1 = tim2*60 + sec2;
    }
    cout << ans.size() << endl;
    for(int i=0;i<ans.size();i++){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

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

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

double dp[100011][22];
double dp2[100001];

int main() {
  dp[1][1] = 1;

  REP(i, 1, 100001) {
    rep(j, 20) {
      dp[i+1][j+1] = dp[i][j] * pow(0.5, j);
      dp[i+1][0] += dp[i][j] * (1.0 - pow(0.5, j));
    }
  }

  rep(i, 100001) {
    double sum = 0.0;
    REP(j, 1, 20) sum += dp[i+1][j];
    dp2[i+1] = sum + dp2[i];
  }
  
  int n;
  while(cin >> n && n)
    printf("%.10f\n", dp2[n]);

  return 0;
}

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    int n;  cin >> n;
    map<string,int> mp;

    rep(i,n){
        string s;   cin >> s;
        mp[s]++;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

pair<int, int> dir[8] = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 1, 1 }, { 1, 0 }, { 1, -1 }, { 0, -1 }, { 0, 1 } };

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

	int H, W;
	cin >> H >> W;

	vector<string> S_list;
	for (int i = 0; i < H; i++)
	{
		string S;
		cin >> S;

		S_list.push_back(S);
	}

	vector<vector<int>> result(H, vector<int>(W, -1));

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (S_list[i][j] == '#') continue;

			int cnt = 0;
			for (int k = 0; k < 8; k++)
			{
				int ny = i + dir[k].first;
				int nx = j + dir[k].second;
				if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;

				if (S_list[ny][nx] == '#') cnt++;
			}

			result[i][j] = cnt;
		}
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (result[i][j] == -1)
			{
				cout << "#";
			}
			else
			{
				cout << result[i][j];
			}
		}

		cout << "\n";
	}

	return 0;
}


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

A = list(map(int, input().split()))

visited = [False] * N

now = 1


while True:
    if K == 0:
        break
    visited[now-1] = True
    now = A[now-1]
    K -= 1
    if visited[now-1]:
        break


visited2 = [False] * N

while True:
    if K == 0:
        break
    visited2[now-1] = True
    now = A[now-1]
    K -= 1
    if visited2[now-1]:
        break

if K == 0:
    print(now)

else:
    K = K % visited2.count(True)
    while True:
        if K == 0:
            break
        now = A[now-1]
        K -= 1
    print(now)

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

int main(){
    int n,a=0,ans=0;
    cin>>n;

    for(int i=1; i<=n; i++){
        a=(int)log10((double)i)+1;
        if(a%2==1) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3884
import java.util.Scanner;

class Main {
	public static void main (String[] args) {

		Scanner scan = new Scanner(System.in);

		while (true) {
			int a = scan.nextInt();
			String op = scan.next();
			int b = scan.nextInt();

			int ans = 0;

			if (op.equals("?")) break;

			switch(op) {
			case "+":
				ans = a+b;
				break;
			case "-":
				ans = a-b;
				break;
			case "*" :
				ans = a*b;
				break;
			case "/" :
				ans = a/b;
				break;
			}

			System.out.println(ans);

		}

		}
	}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n)
    {
        cin >> x[i] >> y[i] >> h[i];
    }
    int idx;
    rep(i, n)
    {
        if (h[i] > 0)
        {
            idx = i;
            break;
        }
    }

    rep(cx, 100 + 1)
    {
        rep(cy, 100 + 1)
        {
            int H = h[idx] + abs(x[idx] - cx) + abs(y[idx] - cy);
            bool ck = true;
            rep(i, n)
            {

                if (h[i] != max(H - abs(x[i] - cx) - abs(y[i] - cy), 0))
                {
                    ck = false;
                    break;
                }
            }
            if (ck)
            {
                printf("%d %d %d", cx, cy, H);
            }
        }
    }
    return 0;
}


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

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int count = 0;
    for (int a = 0; a <= A; a++){
        for (int b = 0; b <= B;b++){
            for (int c = 0; c <= C;c++){
                if((500*a+100*b+50*c)==X){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}

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

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

using namespace std;
using lint=long long;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long y,const mint& m){ return m+y; }
mint operator*(long long y,const mint& m){ return m*y; }

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

	mint ans=0;
	for(lint i=k;i<=n+1;i++){
		ans+=i*(2*n-i+1)/2-i*(i-1)/2+1;
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 3624
from collections import deque
 
H,W=[int(s) for s in input().split()]
maze=[input() for _ in range(H)]
 
edge=[set() for _ in range(H*W)]
n=0
numcount=0
for h in range(H):
  for w in range(W):
    if maze[h][w]=='#':
      numcount+=1
      n+=1
      continue
    if h>0 and maze[h-1][w]=='.':
      edge[n].add(n-W)
    if h<H-1 and maze[h+1][w]=='.':
      edge[n].add(n+W)
    if w>0 and maze[h][w-1]=='.':
      edge[n].add(n-1)
    if w<W-1 and maze[h][w+1]=='.':
      edge[n].add(n+1)
    n+=1

def dfs(start):
  reach=deque([start])
  distance=[-1 for _ in range(H*W)]
  distance[n]=0
  while reach:
    _from=reach.popleft()
    for _to in edge[_from]:
      if not(_to in reach) and distance[_to]==-1:
        reach.append(_to)
        distance[_to]=distance[_from]+1
  return(max(distance))
 
n=0
ans=set()
for h in range(H):
  for w in range(W):
    if maze[h][w]=='.':
      ans.add(dfs(n))
    n+=1
print(max(ans))

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

const int MAX_D = (int)(10 + 5);

class pos_score {
public:
  int pos;
  int score;
  pos_score(int pos, int score) {
    this->pos = pos;
    this->score = score;
  };
};

bool operator< (const pos_score &si1, const pos_score &si2){
  return si1.score < si2.score;
};

int d, g;
int p[MAX_D], c[MAX_D];

priority_queue<pos_score> pos_score_queue;

int ans;

int main(void){
  scanf("%d %d", &d, &g);
  for (int i = 1; i <= d; ++i) {
    scanf("%d %d", &(p[i]), &(c[i]));
  }

  vector<int> v;

  for (int i = 1; i <= d; ++i) {
    v.push_back(i);
  }

  ans = 100 * 10 + 5;
  do {
    int cur_ans = 0;
    int total = 0;
    for (auto i: v) {
      if ((g - total) > p[i] * i * 100 + c[i]) {
        cur_ans += p[i];
        total += p[i] * i * 100 + c[i];
      }
      else {
        if ((g - total) > (p[i] * i * 100)) {
          cur_ans += p[i];
          total += p[i] * i * 100 + c[i];
        }
        else {
          int part_num = ceil((g - total) / (i * 100));
          cur_ans += part_num;
          total += part_num * i * 100;
        }
      }
      if (total >= g) break;
    }

    ans = min(ans, cur_ans);

  } while (next_permutation(v.begin(), v.end()));     // 次の順列を生成

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

  return 0;
}

Measured memory_bytes: 256
const double = Float64
const int = Int64
const vint = Vector{int}
const vdouble = Vector{double}

int(x) = parse(int,x)
parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  N = readint()[1]
  HT = Array{int,2}(undef,N,2)
  LT = Array{int,2}(undef,N,2)
  NH = 0; NL = 0

  for i in 1:N
    s = readline()
    
    h = 0
    t = 0
    for c in s
      if c=='('
        t += 1
      else
        t -= 1
        h = min(h,t)
      end
    end

    if t >= 0
      NH += 1
      HT[NH,:] .= h,t
    else
      NL += 1
      LT[NL,:] .= h-t , -t
    end
  end
  #println(HT)

  HT = HT[sortperm(HT[1:NH,1],rev=true),:]
  LT = LT[sortperm(LT[1:NL,1]),:]
  #println(HT)
  h = 0
  flag = true
  for i in 1:NH
    if h + HT[i,1] < 0
      flag = false
    end
    h += HT[i,2]
    #println(h)
  end
  for i in 1:NL
    if h - LT[i,2] + LT[i,1] < 0
      flag = false
    end
    h -= LT[i,2]
  end

  if flag && h==0
    println("Yes")
  else
    println("No")
  end

end

main()

Measured memory_bytes: 274584
# -*- coding: utf-8 -*-

import math

def readInts():
  return [int(s) for s in input().split(" ")]

def calc(K, n):
  p = math.ceil(math.log2(K / n))
  return (1.0 / 2) ** p

def main():
  N, K = readInts()
  ans = 0.0
  for n in range(1, N+1):
    r = 1.0 / N
    if n < K:
      r *= calc(K, n)
    ans += r
  print(ans)

if __name__ == "__main__":
  main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  REP(i,n) cin >> a[i];
  REP2(i,1,n){
    if(a[i] >= a[i-1]) continue;
    sum += a[i-1] - a[i];
    a[i] = a[i-1];
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  int result = N / max(H, W);
  if (N % max(H, W)) {
    result++;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
cA = ord('a')
P = {0: 0}
cur = 0

dp = [10**18]*(n+1)
dp[-1] = 0

for i in range(n):
    c = ord(s[i]) - cA
    dp[i] = dp[i-1] + 1
    cur ^= 1 << c
    # even
    if cur in P:
        dp[i] = min(dp[i], P[cur] + 1)
    # odd
    for k in range(26):
        need = cur ^ (1 << k)
        if need in P:
            dp[i] = min(dp[i], P[need] + 1)
    P[cur] = min(P.get(cur, 10**18), dp[i])
print(dp[n-1])

Measured memory_bytes: 71884
def main():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))

    ss = sum(a)
    if ss < x:
        print(n-1)
    elif ss == x:
        print(n)
    else:
        a.append(10 ** 12)
        a.sort()
        candy = 0
        for i in range(n+1):
            candy += a[i]
            if candy > x:
                print(i)
                break


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};

struct Scanner<R: Read> {
    reader: R,
    buffer: String,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader, buffer: String::new() }
    }

    // fn line(&mut self) -> String {
    //     self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
    //         .skip_while(|&c| c == '\n' || c == '\r')
    //         .take_while(|&c| !(c == '\n' || c == '\r'))
    //         .collect::<String>();
    //     self.buffer.clone()
    // }

    fn read_buffer(&mut self) {
        self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        self.read_buffer();
        if self.buffer.is_empty() {
            None
        } else {
            self.buffer.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            // writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n = sc.read();
    let k = sc.read();
    let w: Vec<u32> = sc.vec(n);

    let is_ok = |max_w: u32| {
        let mut i = 0;
        for _ in 0..k {
            let mut cur_w = 0;
            while i < n && cur_w + w[i] <= max_w {
                cur_w += w[i];
                i += 1;
            }
        }
        i == n
    };

    let (ok, _) = (0..31).fold((1000000000u32, 0), |(ok, bad), _| {
        let mid = (ok + bad) / 2;
        if is_ok(mid) { (mid, bad) } else { (ok, mid ) }
    });

    println!("{}", ok);
}



Measured memory_bytes: 9084
/* nothing is impossible */
#include <bits/stdc++.h> 
 
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define fi first
#define se second
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef long double ld;
typedef string st;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
const ll MOD = 1e9 + 7 ;
const ll INF=1e14;                                                                                           
ll mpow(ll a,ll b,ll p=MOD){a=a%p;ll res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}             
const ll N=1e6;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,k;
  cin>>n>>k;
  ll a[n],o=k;
  forn(i,n) cin>>a[i];
  sort(a,a+n);
  ll ans=0;
  ll ans1=0;
  for(ll i=0;i<n;i++)
  {
   k-=a[i];
   if(k<0) break;
   ans++;
  }  
  if(k>0)
    ans--;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
n = gets.to_s.to_i
s = gets.to_s.chomp.split('')

cnt = 0
n.times do |i|
  j = i + 1
  k = i + 2
  while k < n
    cnt += 1 if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
    j += 1
    k += 2
  end
end

puts s.count('R') * s.count('G') * s.count('B') - cnt

Measured memory_bytes: 14416
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

const ll V=1010;
ll dist[V],n;
using P=pair<int,int>;
vector<P> G[V];

bool bellman_ford(int s) {
  fill_n(dist,V,1e18);
  dist[s] = 0;
  rep(i,n){
    rep(v,n){
      for(P e:G[v]) {
        if (dist[v] != 1e18 && dist[e.second] > dist[v] + e.first) {
          dist[e.second] = dist[v] + e.first;
          if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
        }
      }
    }
  }
  return false;
}

int main(){
  ll e,r;cin>>n>>e>>r;
  ll s,t,d;
  rep(i,e){
    cin>>s>>t>>d;
    G[s].emplace_back(P(d,t));
  }
  if(bellman_ford(r)){
    cout<<"NEGATIVE CYCLE"<<endl;
    return 0;
  }

  rep(i,n){
    if(dist[i]>1e10){
      cout<<"INF"<<endl;
    }else{
      cout<<dist[i]<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    if (S[5] == '1'){
        cout << "TBD" << endl;
    }
    else if (S[6] == '4' or S[6] == '3' or S[6] == '2' or S[6] == '1'){
    cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
ll check753(ll M, ll num, ll count7, ll count5, ll count3){
    ll nexta, nextb, nextc, next7, next5, next3, count=0;
    if(num>M){
        return 0;
    }
    nexta = num * 10 + 7;
    next7 = count7+1;
    if(count5!=0 && count3!=0 && nexta<=M){
      	count++;
    }
    nextb = num * 10 + 5;
    next5 = count5+1;
    if(count7!=0 && count3!=0 && nextb<=M){
      	count++;
    }
    nextc = num * 10 + 3;
    next3 = count3+1;
    if(count7!=0 && count5!=0 && nextc<=M){
        count++;
    }
  	
  	return count+check753(M, nexta, next7, count5, count3)+check753(M, nextb, count7, next5, count3)+check753(M, nextc, count7, count5, next3); 
}
int main(){
    ll n, ans;
    cin >> n;
    ans = check753(n, 0, 0, 0, 0);

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


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A,B;
  cin>>A>>B;
  cout<<(A+B)%24<<endl;
  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in();
	ll left=0,right=N,mid=0;
	ll leftS=0,rightS=0,midS=0;
	string S;
	auto func = [&](ll query,ll& sex){
		cout.flush();
		out(query);
		S=in<string>();
		if(S=="Vacant") exit(0);
		sex = S=="Male"?1:0;
	};
	func(left,leftS);
	rightS=leftS;
	REP(i,16){
		mid = (left+right)/2;
		func(mid,midS);
		
		if((left-mid)%2){
			if(leftS==midS){
				right = mid;
				rightS = midS;
			}
			else{
				left = mid;
				leftS = midS;
			}
		}
		else{
			if(leftS!=midS){
				right = mid;
				rightS = midS;
			}
			else{
				left = mid;
				leftS = midS;
			}
		}
	}
	for (int m=left+1; m<right; ++m) {
		func(m,leftS);
	}
	return 0;
}


Measured memory_bytes: 852