akhauriyash/Code-Regression huggingface dataset:
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    #divmod: 割り算の商と余りを同時に取得
    p,r = divmod(n, i)
    # print(f"i {i}, p {p}, r {r}")
    # print("1", p*max(0,i-k))
    # print("2", max(0,r-k+1))
    ans += p*max(0,i-k)+max(0,r-k+1)
print(ans if k != 0 else ans - n)


Measured memory_bytes: 9176
#include <stdio.h>

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

  char s[4010];
  scanf("%s", s);

  long long int r, g, b;
  r = g = b = 0;
  for (int i = 0; i < n; i++) {
    switch (s[i]) {
    case 'R':
      r++;
      break;
    case 'G':
      g++;
      break;
    case 'B':
      b++;
      break;
    }
  }

  long long int ans = r * g * b;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int k = 2 * j - i;
      if (k >= n) continue;
      ans -= (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]);
    }
  }

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

  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;

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

  ll k, n;
  cin >> n >> k;

  ll num = n/k;

  if(k%2 == 1){
    cout << num * num * num << '\n';
    return 0;
  }else{
    ll numm = (n + k/2) / k;
    cout << num * num * num + numm * numm * numm << '\n';
    return 0;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int main(void){
    string s;
    cin>>s;
    int ns=0,nt=0;
    REP(i,SZ(s)){
        if(s[i]=='T'&&ns==0)
            nt++;
        else if(s[i]=='T'&&0<ns)
            ns--;
        else if(s[i]=='S')
            ns++;
    }
    cout<<2*nt<<endl;
     return 0;
}

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

int main() {
    int N, X; cin >> N >> X;
    vector<int> d(N);
    rep(i, N){
        int x; cin >> x;
        d[i] = abs(x-X);
    }

    int ans = d[0];
    for (int i = 1; i < N; i++){
        ans = __gcd(ans, d[i]);
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
int main(){
    int N,Z,W;
    SCD3(N,Z,W);
    vector<int> a;

    REP(i,N){
        int x; SCD(x);
        a.PB(x);
    }

    if (N==1){
        PRINTD(abs(a[0] - W));
        return 0;
    }

    PRINTD(max(abs(a[N-1]-a[N-2]),abs(a[N-1]-W)));
}

Measured memory_bytes: 256
object Main extends App {

  import scala.io.StdIn._
  import scala.math.{max, abs}
  val Array(w, h, n) = readLine.trim.split(' ').map(_.toInt)
  val points = Array.tabulate(n){_ ⇒
    val Array(x, y) = readLine.trim.split(' ').map(_.toInt)
    Point(x, y)
  }
  println(
    (for (i ← 1 until n) yield {
      val Point(fromX, fromY) = points(i - 1)
      val Point(toX, toY) = points(i)
      if ((fromX - toX) * (fromY - toY) > 0) {
        max(abs(fromX - toX), abs(fromY - toY))
      }else {
        abs(fromX - toX) + abs(fromY - toY)
      }
    }).sum
  )
  case class Point(x: Int, y: Int)
}



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

struct event
{
  enum event_type { BEGIN, END, CUTOFF };
  event_type evt;
  int pos;
  int idx;
  event(event_type e, int p, int i = -1) : evt(e), pos(p), idx(i) {}
  bool operator<(const event& that) const { return pos < that.pos; }
};

int main()
{
  int N, M;
  cin >> N >> M;
  vector<pair<int,int> > intervals(N);
  for (int i = 0; i < N; i++) {
    cin >> intervals[i].first >> intervals[i].second;
  }
  vector<int> cutoffs(M);
  for (int i = 0; i < M; i++) {
    cin >> cutoffs[i];
  }

  vector<event> v;
  for (vector<pair<int,int> >::const_iterator it = intervals.begin(); it != intervals.end(); ++it) {
    v.push_back(event(event::BEGIN, min(it->first, it->second), it - intervals.begin()));
    v.push_back(event(event::END, max(it->first, it->second), it - intervals.begin()));
  }
  for (vector<int>::const_iterator it = cutoffs.begin(); it != cutoffs.end(); ++it) {
    v.push_back(event(event::CUTOFF, *it));
  }
  sort(v.begin(), v.end());
  vector<int> cnt(N, 0);
  int acc = 0;
  for (vector<event>::const_iterator it = v.begin(); it != v.end(); ++it) {
    switch (it->evt) {
      case event::BEGIN:
        cnt[it->idx] = acc;
        break;
      case event::END:
        cnt[it->idx] = acc - cnt[it->idx];
        break;
      case event::CUTOFF:
        ++acc;
        break;
    }
  }

  int on = 0, off = 0;
  int prev = 0;
  long long ans = 0LL;
  for (vector<event>::const_iterator it = v.begin(); it != v.end(); ++it) {
    ans += static_cast<long long>(it->pos - prev) * on;
    switch (it->evt) {
      case event::BEGIN:
        if (intervals[it->idx].first == it->pos || cnt[it->idx] % 2 == 0) {
          ++on;
        } else {
          ++off;
        }
        break;
      case event::END:
        if (intervals[it->idx].first == it->pos || cnt[it->idx] % 2 == 0) {
          --on;
        } else {
          --off;
        }
        break;
      case event::CUTOFF:
        swap(on, off);
        break;
    }
    prev = it->pos;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8324
#include <cstdio>

const int N = 100000;

int n;
int a[N];
int b[N];

int x, y, z;

int main(int argc, char *argv[]) {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
	   scanf("%d", &a[i]);
	   if (a[i] % 4 == 0)
		   x++;
		else if (a[i] % 2 == 0)
		   y++;
		else
		   z++;
	}
	if (z > 0) {
		b[0] = 1;
		z--;
	}
	else if (y > 0) {
		b[0] = 2;
		y--;
	}
	else {
		b[0] = 4;
		x--;
	}
	for (int i = 1; i < n; i++) {
		if (b[i - 1] == 1) {
			if (x > 0) {
				b[i] = 4;
				x--;
			}
			else {
				puts("No");
				return 0;
			}
		}
		if (b[i - 1] == 2) {
			if (y > 0) {
				b[i] = 2;
				y--;
			}
			else if (x > 0) {
				b[i] = 4;
				x--;
			}
			else {
				puts("No");
				return 0;
			}
		}
		if (b[i - 1] == 4) {
			if (z > 0) {
				b[i] = 1;
				z--;
			}
			else if (y > 0) {
				b[i] = 2;
				y--;
			}
			else if (x > 0) {
				b[i] = 4;
				x--;
			}
			else {
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 896
n = int(input())
a = [int(i) for i in input().split()]
b = [a[0]]
ans = 0
mod = 1000000007

for i in range(1,n):
  b.append(b[-1]+a[i])

for i in range(1,n):
  ans += a[n-i]*b[n-i-1]
  ans = ans % mod
  
print(ans)

Measured memory_bytes: 31500
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

//vector< vector<int> > v (size1, vector<int>(size2) );

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

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

	ll n,m;
	cin>>n>>m;
	vector<ll> A(m),B(m);
	FOR(i,0,m) cin>>A[i]>>B[i],A[i]--,B[i]--;

	UnionFind uf(n);
	ll ans = n*(n-1)/2;
	vector<ll> res;

	FOR(i,0,m){
		res.pb(ans);
		ll a = A[m-i-1], b = B[m-i-1];
		if (uf.issame(a,b)) continue;

		ll sa = uf.size(a), sb = uf.size(b);
		ans -= sa*sb;
		uf.merge(a,b);
	}

	REV(res);
	FOR(i,0,res.size()) cout<<res[i]<<endl;
	
}
//73

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

using namespace std;
using ll = unsigned long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
int main(){
    int a,b;
    cin>>a>>b;
    if(a > 12) cout << b << endl;
    else if(a <= 12 && a >= 6) cout << b/2 << endl;
    else if(a < 6 ) cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a, b, c,all=0;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

	all = a + b + c;
	if (all == a*2 ) {
		printf("Yes");
	}
	else
		if (all == b*2 ) {
			printf("Yes");
		}
		else
			if (all == c*2) {
				printf("Yes");
			}
			else
		printf("No");
		return 0;
}					

Measured memory_bytes: 128
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(0, n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l[i] == l[j] or l[i] == l[k] or l[j] == l[k]:
                continue
            if l[i]+l[j] > l[k] and l[k]+l[j] > l[i] and l[k]+l[i] > l[j]:
                ans += 1

print(ans)


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

int main() {
  int n;cin>>n;
  ll sm = 0;
  int gg[n+1][n+1];
  rep(i,n+1)rep(j,n+1) gg[i][j] = gcd(i,j);
  
  rep(i,n) rep(j,n) rep(k,n) {
    sm += gg[ gg[i+1][j+1] ][k+1];
  }
  cout << sm;
}


Measured memory_bytes: 3792
/*
[diverta2019-2] D - Squirrel Merchant
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int P = 2;
const int Q = 3;
const int MAX_N = 5000;
const int MAX_C = 5000;

int N;
int c[P][Q];
ll dp[MAX_N * MAX_C + 1];

ll solve() {
    ll W = N;
    for (int p = 0; p < P; p++) {
        int w[3], v[3];
        for (int q = 0; q < Q; q++) {
            w[q] = c[p][q];
            v[q] = c[p ^ 1][q] - c[p][q];
        }

        memset(dp, 0, sizeof(dp));
        for (int q = 1; q <= Q; q++) {
            for (int i = w[q - 1]; i <= W; i++) {
                dp[i] = max(dp[i], dp[i - w[q - 1]] + v[q - 1]);
            }
        }
        W += dp[W];
    }

    return W;
}

int main() {
    cin >> N;
    for (int p = 0; p < P; p++) {
        for (int q = 0; q < Q; q++) {
            cin >> c[p][q];
        }
    }

    cout << solve() << endl;

    return 0;
}


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

int main(){
    int H=0,N=0;
    cin >> H >> N;
    
    vector<int> AT(N,0);
    vector<int> MP(N,0);

    for(int i=0;i<N;i++){
       cin >> AT[i] >>MP[i];
    }

    int maxat=0;
    for(int i=0;i<N;i++){
        if(maxat<AT.at(i)){
            maxat=AT.at(i);
        }
        else{}
    }

    vector<int> HE(H+2*maxat,1000000000);                   /*最小値を求めたいので初期値はINF(答えとなりえないほど大きな値)にするとうまくいく*/
    HE.at(0) = 0;                                           /*HE.at(i) := iダメージを与える時にトキが受ける最小の魔力なので、i = 0(何もしない時)は0となる*/
    for(int i = 0; i <= H+maxat; i++){                      
        for(int j = 0;j<N;j++){
            if(i+AT.at(j) >= H+2*maxat)continue;           /*もし配列HEの外に代入しようとしているときはそのループを飛ばす*/
            if(HE.at(i)+MP.at(j)<HE.at(i+AT.at(j))){
                HE.at(i+AT.at(j))=HE.at(i)+MP.at(j);
            }
        }
        /*HEの初期値を変更した関係でループ変数(i)の更新をfor文中にした*/
        //while(HE.at(i)==0){
        //    i++;
        //}
    }
    int minmp=HE.at(H);
    for(int i=H+1;i<H+maxat+1;i++){
        if(minmp>HE.at(i)&&HE.at(i)!=0){
            minmp=HE.at(i);
        }
        else{}
    }
    cout << minmp << endl;


}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
#define lc (rt << 1)
#define rc (rt << 1) | 1
using namespace std;
typedef long long LL;
const int MAXN = 200005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, tot, type[MAXN];
LL k, X[MAXN], L[MAXN], R[MAXN], sor[MAXN], f[MAXN];
int cov[MAXN << 2];

void pushdown(int rt) {
	if (cov[rt]) {
		cov[lc] = cov[rc] = cov[rt];
		cov[rt] = 0;
	}
}

void Update(int rt, int b, int e, int l, int r, int cv) {
	if (l > r) return;
	if (l <= b && e <= r) {
		cov[rt] = cv;
		return;
	}
	int mid = (b + e) >> 1;
	pushdown(rt);
	if (l <= mid) Update(lc, b, mid, l, r, cv);
	if (r > mid) Update(rc, mid + 1, e, l, r, cv);
}

int Query(int rt, int b, int e, int p) {
	if (b == e || cov[rt]) return cov[rt];
	int mid = (b + e) >> 1;
	if (p <= mid) return Query(lc, b, mid, p);
	else return Query(rc, mid + 1, e, p);
}

LL Trans(int i) {
	int pre = Query(1, 1, tot, i);
	if (!pre) return 0;
	return f[pre] + (sor[L[pre]] - sor[i] + k) % k;
}

void init() {
	read(n); read(k);
	for (int i = 1; i <= n; ++i) {
		int x; read(x); read(type[i]);
		X[i] = X[i - 1] + x;
		if (type[i] == 1) {
			if (x * 2 > k) {
				printf("-1\n");
				exit(0);
			}
			L[i] = (k - X[i - 1] * 2 % k) % k;
			R[i] = (k - X[i] * 2 % k) % k;
		} else {
			L[i] = 0;
			R[i] = k - 1;
		}
		sor[++tot] = L[i];
		sor[++tot] = R[i];
	}
	sort(sor + 1, sor + tot + 1);
	tot = unique(sor + 1, sor + tot + 1) - (sor + 1);
	for (int i = 1; i <= n; ++i) {
		L[i] = lower_bound(sor + 1, sor + tot + 1, L[i]) - sor;
		R[i] = lower_bound(sor + 1, sor + tot + 1, R[i]) - sor;
	}
}

void solve() {
	for (int i = n; i >= 1; --i) {
		f[i] = Trans(L[i]);
		if (L[i] > R[i]) {
			Update(1, 1, tot, R[i] + 1, L[i] - 1, i);
		} else {
			Update(1, 1, tot, 1, L[i] - 1, i);
			Update(1, 1, tot, R[i] + 1, tot, i);
		}
	}
	LL ans = f[1];
	for (int i = 1; i <= tot; ++i) {
		ans = min(ans, Trans(i));
	}
	printf("%lld\n", ans + X[n] * 2);
}

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


Measured memory_bytes: 9984
#include<stdio.h>
#include<stdlib.h>

#define N 3

int Puzzle[N][N];
int tmp[N][N];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void empty(int *,int *);
int dfs(int ,int,int ,int ,int );
int cal(void);


int main(){
	int i,j,limit;
	int b,a,c;


	for(i =0;i < N; i++){
		for(j = 0 ; j < N ; j++){
			scanf("%d",&Puzzle[i][j]);
		}
	}
	empty(&a,&b);

	for(limit = 0; limit < 60 ; limit++){
		for(i = 0; i < N ; i++){
			for(j = 0; j < N ; j++){
				tmp[i][j] = Puzzle[i][j];
			}
		}
		c = dfs(a,b,-1,0,limit);
		if(c!= -1){
			printf("%d\n",c);
			break;
		}

		for(i = 0; i < N ; i++){
			for(j = 0 ; j < N ; j++){
				Puzzle[i][j] = tmp[i][j];
			}
		}
		c =-1;
		if(limit == 49)printf("%d\n",c);
	}

	return 0;
}

void empty(int *x,int *y){
	int i,j;
	for(i = 0; i < N ; i++){
		for(j = 0 ; j < N ; j++){
			if(!Puzzle[i][j]){
				*x = j;
				*y = i;
				return;
			}
		}
	}
}


int dfs(int x,int y,int p, int dep, int lim){
	int i,j,h,n1,n2,res;
	int cp;

	h = cal();

	if(h == 0)return dep;
	if(dep + h > lim) return -1;

	for(i = 0; i< 4; i++){
		n1 = x + dx[i];
		n2 = y + dy[i];

		if(~p && i == (p+2)%4) continue;
		if(!(0 <= n1 && n1 < 3 && 0 <= n2 && n2 < 3)) continue;

		cp = Puzzle[y][x];
		Puzzle[y][x] = Puzzle[n2][n1];
		Puzzle[n2][n1] = cp;

		res = dfs(n1,n2,i,dep+1,lim);
		if(~res)return res;

		cp = Puzzle[y][x];
		Puzzle[y][x] = Puzzle[n2][n1];
		Puzzle[n2][n1] = cp;

	}
	return -1;
}

int cal(void){
	int i,a;
	int sum = 0;

	for(i = 0; i< N+6 ; i++){
		a = Puzzle[i/3][i%3];
		if(a){
			a--;
			sum += abs(i/3 - a/3)  + abs(i%3 - a%3);
		}
	}
	return sum;
}



Measured memory_bytes: 2148
function main(input) {
    input = input.trim().split('\n')
    let n = parseInt(input[0])
    let a = input[1].split(' ').map(BigInt)

    const mod = BigInt(10**9 + 7)
    let sum = a.reduce((a,b)=>a+b, BigInt(0))

//  console.log(Number(sum))

    let ans=BigInt(0)
    for(let i=0; i<n; i++) {
        sum -= a[i]
        ans += a[i] * sum
        ans %= mod
    }
    console.log(Number(ans))

}
process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 73492
// https://atcoder.jp/contests/abc137/tasks/abc137_d
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    multimap<int, int> mp;
    REP(i, n) {
        int a, b;
        cin >> a >> b;
        mp.insert(PII(a, b));
    }
    priority_queue<int> q;
    // priority_queue<int, vector<int>, greater<int>> q;
    int income = 0;
    for (int i = 1; i <= m; i++) {
        auto r = mp.equal_range(i);
        for (auto x = r.first; x != r.second; x++) {
            q.push(x->second);
        }
        if (q.size() > 0) {
            income += q.top();
            q.pop();
        }
    }

    cout << income << endl;

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  sort(A.rbegin(),A.rend());
  long long sum=0;
  for(int i=1;i<N;i++){
    sum+=A.at(i/2);
  }
  cout << sum << endl;
}
  
    

Measured memory_bytes: 4036
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

map<char, int> m;

int main(){
  string s;
  cin >> s;
  
  for(int i = 0; i < s.size(); ++i){
      m[s[i]]++;
  }
  
  if(m.size() == 2){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())

# a = 10
# b = 2
# c = 10
# d = 3

while True:
#     print(a)
#     print(c)
    
    c = c - b
    
    if c <= 0:
        print('Yes')
        break
            
    a = a - d
            
    if a <= 0:
        print('No')
        break


Measured memory_bytes: 9036
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<string> genRoll(int H, int W){
	vector<string> res(H, string(W, '.'));
	int dx[] = {1, 0, -1, 0};
	int dy[] = {0, 1, 0, -1};
	int x[2] = {0, W-1};
	int y[2] = {0, H-1};
	int dir[2] = {0, 2};
	res[y[0]][x[0]] = 'R';
	res[y[1]][x[1]] = 'B';
	while(true){
		for(int i=0;i<2;i++){
			bool mark = false;
			for(int d=0;d<4;d++){
				int nx = x[i] + dx[(dir[i]+d)%4];
				int ny = y[i] + dy[(dir[i]+d)%4];
				if(nx < 0 || W <= nx || ny < 0 || H <= ny || res[ny][nx] != '.') continue;
				res[ny][nx] = "RB"[i];
				x[i] = nx;
				y[i] = ny;
				dir[i] = (dir[i]+d)%4;
				mark = true;
				break;
			}
			if(!mark) return res;
		}
	}
	return res;
}

int main(){
	int H, W;
	while(cin >> H >> W){
		vector<string> rb = genRoll(H, W);
		vector<string> vs(H);
		for(auto& s : vs) cin >> s;
		for(int i=0;i<2;i++){
			for(int j=0;j<H;j++){
				for(int k=0;k<W;k++){
					cout << ((rb[j][k] == "RB"[i] || vs[j][k] == '#') ? "#" : ".");
				}
				cout << endl;
			}
			if(i==0) cout << endl;
		}
	}
}


Measured memory_bytes: 1280
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (a, b): (i32, i32) = read();
    if a <= 0 && 0 <= b {
        println!("Zero");
    } else if a >= 1 {
        println!("Positive");
    } else {
        let d = b - a + 1;
        if d % 2 == 1 {
            println!("Negative");
        } else {
            println!("Positive");
        }
    }
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long s = in.nextLong();
		long limit = (long) Math.pow(10, 9);

		long x3 = limit - s % limit;
		long y3 = s / limit + 1;
		
		if(s == (long)Math.pow(10, 18)) {
			y3 = limit;
			x3 = 0;
		}
		
		System.out.println("0 0 1000000000 1 "  + x3 + " " + y3 );

		in.close();
	}
}


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

vector<int> x,y;
int main(){
    int N, M;
    int X, Y;
    cin >> N >> M;
    cin >> X >> Y;
    for (int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        x.push_back(tmp);
    }
    x.push_back(X);
    for (int i = 0; i < M; i++){
        int tmp;
        cin >> tmp;
        y.push_back(tmp);
    }
    y.push_back(Y);

    int max = *max_element(x.begin(),x.end());
    int min = *min_element(y.begin(),y.end());

    if (max < min){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }
}

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

int main() {
	int A, B;
	cin >> A >> B;
	
	int ans = 0;
	for (int i = A; i < B + 1; i++) {
		int s = i % 10;
		int t = i / 10000;
		int u = i / 10 % 10;
		int v = i / 1000 % 10;

		if (s == t && u == v) {
			ans++;
		} 
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
L,R = map(int,input().split())

if R - L > 2019:
  print(0)
else:
  minv = 2018 * 2018
  for i in range(L,R):
    for j in range(i+1,R+1):
      x = i % 2019
      y = j % 2019
      val = (x * y) % 2019
      if minv > val:
        minv = val
  print(minv)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}
const ll MOD = 1e9 + 7;
void solve() {
	int n;
	cin >> n;
	vl a(n + 1);
	rep(i, 1, n + 1)cin >> a[i];
	ll ans = 0ll;
	for (ll i = 0; i < 61; i++) {
		ll z = 0ll, o = 0ll;
		ll k = (1ll << i);
		rep(j, 1, n + 1) {
			if (k & a[j])o++;
			else z++;
		}
		ll kk = k;
		// if (i == 56) {
		// 	trace(k)
		// }
		k %= MOD;
		k = (((k * z) % MOD) * o) % MOD;
		ans = (ans + k) % MOD;
		ans %= MOD;
		// trace(i, kk, z, o, ans, k)
	}
	cout << ans << endl;
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

using namespace std;

int main() {
	long long n;
	cin >> n;
	long long ans = n;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i) continue;
		ans = min<long long>(ans, to_string(n / i).size());
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void){
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    printf("%.9lf %d\n",w*h/2.0,2*x==w&&2*y==h);
    return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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 string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    string S;
    cin >>S;

    //-----------------------------------
    bool is=false;
    rep(i,3)if(S[i]==S[i+1])is=true;
    cout << ((is) ? "Bad" : "Good") <<endl;
    return (0);
}

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

const int DIM = 1e5 + 5;

int arr[DIM], aux[DIM];

int main( void ) {
    ios::sync_with_stdio( false );
    cin.tie(); cout.tie();
    
    int n, a, b;
    cin >> n >> a >> b;
    
    for( int i = 1; i <= n; i ++ )
        cin >> arr[i];
    
    int pos = 1;
    for( int le = 1, ri = 1e9 / b + 1; le <= ri; ) {
        int md = ( le + ri ) >> 1;
        
        long long ans = 0;
        for( int i = 1; i <= n; i ++ ) {
            aux[i] = arr[i] - b * md;
            
            if( aux[i] >= 1 )
                ans += (int) ceil( 1.0 * aux[i] / (a - b) );
        }
        
        if( ans <= md )
            ri = md - 1;
        else
            le = pos = md + 1;
    }
    
    cout << pos << endl;
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define ll long long
#define inf 1000000007 //10^9+7
#define sort(vec) sort(vec.begin(),vec.end());
#define rever(vec) reverse(vec.begin(),vec.end());
#define unsort(vec) sort(vec); rever(vec);
#define gcd __gcd
using namespace std;
ll  like[100000];
map<ll,bool>mp;
bool pri(ll p);

int main() {
  like[0]=0;
  like[1]=0;
  for(ll i=1;i<100000;i+=2) {
    like[i]+=like[i-2];
    if(pri(i)) {
      if(pri((i+1)/2)) {
        like[i]+=1;
        mp[i]=true;
      }
    }
  }
  ll q;
  cin>>q;
  for(ll i=0;i<q;i++) {
    ll l,r;
    cin>>l>>r;
    if(mp[l]) {
      cout<<like[r]-like[l]+1<<endl;
    }
    else {
      cout<<like[r]-like[l]<<endl;
    }
  }
}

bool pri(ll p) {
  if(p==1) {
    return 0;
  }
  else {
    ll ans=0;
    for(ll i=2;i<=sqrtl(p);i++) {
      if(p%i==0) {
        ans++;
        break;
      } 
    }
    if(ans==0) {
      return 1;
    }
    else {
      return 0;
    }
  }
}

Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

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

    if(s.length() == 1) {
        cout << s[0] << endl;
        return 0;
    } 

    if(s[0] != '1') {

        cout << s[0] << endl;

    } else {

        int ind = 0;
        while (s[ind] == '1') {
            ind += 1;
        }
        
        if(ind >= k) {
            cout << '1' << endl;
        } else {
            cout << s[ind] << endl;
        } 
    } 
    
    return 0;
}

Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
ab = []
for i in range(n):
    a,b = lr()
    ab.append([a,b])
ab.sort(key=lambda x:x[0]+x[1], reverse=True)
ans = 0
for i,num in enumerate(ab):
    if i%2 == 0:
        ans+=num[0]
    else:
        ans-=num[1]
print(ans)


Measured memory_bytes: 97700
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;

    static int N;
    static int[] A;
    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt();
        A = cin.ArrayInt(N);
    }
    static void solve()
    {
        input();
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            while (A[i] % 2 == 0)
            {
                A[i] /= 2;
                ans++;
            }
        }
        WriteLine(ans);
    }

    
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

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



int main(){
   int n,m,x;
   cin >> n>>m >> x;
   vector<int> a(m);
   rep(i,m) cin >>a[i];
   int L=0,R=0;
   rep(j,m){
   for(int i =1;i<=x-1;++i){
       if(a[j]==i) L++;
   }
   for(int k = x+1 ; k<n;++k){
       if(a[j]==k) R ++;
   }
   
   }
   cout << min (L,R) << endl;
      }

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val count = readLine()!!.toInt()
    val list = mutableListOf<List<Char>>()
    repeat(count) {
        list.add(readLine()!!.toCharArray().sorted())
    }
    print(abc137c(list))
}

fun abc137c(list: MutableList<List<Char>>): Long {
    var anagramCount: Long = 0
    
//v1.0では使えない
//    list.groupingBy { it }.eachCount().filter { it.value > 1 }.forEach{
//        for (i in it.value - 1 downTo 1) anagramCount += i }

    list.groupBy { it }.mapValues { it.value.count() }.forEach{
        for (i in it.value - 1 downTo 1) anagramCount += i }

    return anagramCount
}

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

using namespace std;

typedef long long int ll;

#define mod (int) (1e9+7)

// vector<ll>primes;

// void swap(ll &a, ll &b){
// 	ll c=a;
// 	a=b;
// 	b=c;
// }

// bool is_prime(int a){
// 	//bool f=true;
// 	for(int i=2; i*i<=a; i++){
		
// 		if(a%i==0){
// 			return false;
// 		}
		
// 	}
	
// 	return true;
// }




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


 
 ll ncr(ll x, ll y){
 	ll ans=1;
 	
 	y=(y > x-y? x-y: y);
 	
 	for(ll i=0; i<y; i++){
 		ans=ans*(x-i);
 		ans=ans/(i+1);
 		ans=ans%mod;
 	}
 
 	
 	return ans;
 }

ll power(ll x, ll y){
    ll ans=1;
    while(y){
        if(y&1){
            ans=ans*x;
            ans=ans%mod;
        }
        
        x=x*x;
        x=x%mod;
        y=y>>1;
    }
    
    return ans;
    
}


 
void solve(){
	
	ll a,res=0; cin>>a;
    
    res+=a+(a*a)+(a*a*a);
    
    cout<<res<<"\n";

   return ;
	
}




int main(){
    ios_base::sync_with_stdio(0);
    
    cin.tie(0);
    
    int t=1;//cin>>t;
    
   
    
    // clock_t begin, end;
    
    // double time_spent;
    
    // begin = clock(); // Time taken till now.
    
    
    while(t--){
    
	  solve();
        
    }
    
 
    
   
   //end= clock(); // Total  Time taken till now.
   
   //time_spent= (end- begin) / CLOCKS_PER_SEC; 
   
   //cout<<time_spent<<"\n";
   
   
   
	
	return 0;
}



Measured memory_bytes: 3660
n=int(input())
l=list(map(int,input().split()))

dp=[0]*n
dp[0]=0
dp[1]=abs(l[1]-l[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))
print(dp[-1])


Measured memory_bytes: 13928
n,m = map(int,input().split())
ls = []
switch = []
for i in range(n):
    switch.append(i+1)
for i in range(m):
    ks = list(map(int,input().split()))
    ls.append(ks)
p = list(map(int,input().split()))


pattern = []
for i in range(2**n):
    pattern.append(list(bin(i)[2:].zfill(n)))

ans = 0

for i in pattern:
    turn = []
    count = 0
    on = 0
    for j in range(n):
        if i[j] == '1':
            turn.append(switch[j])
    for k in range(m):
        count = 0
        for l in range(1,ls[k][0]+1):
            if ls[k][l] in turn:
                #print(ls[k][l])
                count += 1
        if count % 2 == p[k]:
            on += 1
    if on == m:
        ans += 1
        #print(i,turn)
            
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;

}
//##################################################################
int main(){
    int a=D(),b=D(),c=D();
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
char str[105][105],row[105],column[105];
int main()
{

    int n,m;
    while(cin>>n>>m)
    {
        memset(row,0,sizeof(row));
        memset(column,0,sizeof(column));
        for(int i=0; i<n; i++)
            cin>>str[i];
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                if(str[i][j]=='#')
                    row[i]=1,column[j]=1;
            }
        }
        int flag=0;
        for(int i=0; i<n; i++)
        {
            flag=0;
            for(int j=0; j<m; j++)
            {
                if(row[i]==1&&column[j]==1)
                {
                    cout<<str[i][j];
                    flag=1;
                }
            }
            if(flag==1)
                cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll n, k;
    cin >> n >> k;
    
    if(k % 2 == 0){
        cout << (n / k) * (n / k) * (n / k) + ((n + k / 2) / k) * ((n + k / 2) / k) * ((n + k / 2) / k) << endl;
    }
    else{
        cout << (n / k) * (n / k) * (n / k) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll a, b, x;
  cin >> x >> a >> b;
  if(b-a<=0)cout << "delicious" << "\n";
  else if(b-a>x)cout << "dangerous" << "\n";
  else cout << "safe" << "\n";
  return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int a,b;cin>>a>>b;
  if(a*b%2==0)out("Even")
  else out("Odd")

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int d;
	ll g;
	cin >> d >> g;
	vector<ll> p(d), c(d);
	rep(i,d) cin >> p[i] >> c[i];
	int ans = 1e9;
	rep(S,(1<<d)){
		ll score = 0;
		int cnt = 0, next = -1;
		rep(j,d){
			if(S>>j & 1){
				score += p[j] * (j+1) * 100 + c[j];
				cnt += p[j];
			}
			else{
				next = j;
			}
		}
		if(score >= g) chmin(ans, cnt);
		if(next == -1) continue;
		rep(k,p[next]){
			if(score >= g) break;
			score += 100*(next+1);
			++cnt;
		}
		if(score >= g) chmin(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
int main () {
  string s;
  cin >> s;
  bool flag = true;
  for(int i = 0; i < s.length(); i++) {

    if((i&1) == 0){ 
      if(s[i] == 'L') {
	flag = false;
      }
      
    }
    
    if((i&1) == 1) { 
      if(s[i] == 'R' ) {
	flag = false;
      }
    }
  }
  
  if(flag) {
    cout << "Yes" << "\n";
  }else{
    cout << "No" << "\n";
  }
}

Measured memory_bytes: 256
import math
n = int(input())
v = []

for _ in range(n):
    v.append(int(input()))

n_prime = 0
for v_ in v:
    isprime = True

    if v_ <= 1:
        continue

    for i in range(1+int(math.sqrt(v_))):
        if i <= 1:
            continue
        if v_ % i == 0:
            isprime = False
            break

    n_prime = n_prime + isprime

print(n_prime)


Measured memory_bytes: 6000
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,v[30],c[30],ans=-1e9;

void dfs(int pos,int x,int y)
{
	if(pos==n)
	{
		ans=max(ans,x-y);
		return;
	}
	dfs(pos+1,x+v[pos],y+c[pos]);
	dfs(pos+1,x,y);
}

int main()
{
	cin>>n;
	rep(i,n) cin>>v[i];
	rep(i,n) cin>>c[i];
	dfs(0,0,0);
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  int denko = 1;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++){
    if (denko < K){
      denko *= 2;
    }else{
      denko += K;
    }
  }
   
  cout << denko << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int[][] count = new int[10][10];
        for (int i = 1; i <= n; i++) {
            String str = String.valueOf(i);
            int first = Integer.parseInt(String.valueOf(str.charAt(0)));
            int last = Integer.parseInt(String.valueOf(str.charAt(str.length() - 1)));
            count[first][last]++;
        }
        
        long ans = 0;
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                ans += count[i][j] * count[j][i];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 41776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X,Y;
		X= sc.nextLong();
		Y=sc.nextLong();
		long a=X;
		int i=1;
		for (;;i++) {
			a=a*2;
			if (a<0||a>Y) {
				break;
			}
		}
		System.out.println(i);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;

int main()
{
	IO;
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b;
 	return 0;
}







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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
char S[105], T[105];

int main(void) {
    scanf("%s", S);
    scanf("%s", T);   

  
    printf("%s%s\n", T, S);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>

long long mod = 1000000007;

long long left;
long long right;

long long sum(int a, int b);

int main(void) {
    int n, k;
    long long ret = 0;
    std::cin >> n >> k;
    if(n < k) {
        std::cout << 1 << std::endl;
        return 0;
    }
    left = sum(0, k - 1);
    right = sum(n - (k-1), n);

    ret += (right - left + 1);
    for(int i = k; i < n; ++i) {
        left += i;
        right += (n - i);

        ret += (right - left + 1);
        //std::cout << (right - left + 1) << std::endl;
        ret %= mod;
    }
    ret += 1;
    std::cout << ret  << std::endl;
}

long long sum(int a, int b) {
    long long ret = 0;
    for(int i = a; i <= b; ++i) {
        ret += i;
    }
    return ret;
}

Measured memory_bytes: 3620