akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    REP(i, n + 1){
        cin >> a.at(i);
    }

    vector<ll> lb(n + 1, 0), ub(n + 1);
    for(ll i = n; i >= 0; --i){
        if(i + 1 <= n){
            ub.at(i) = a.at(i) + ub.at(i + 1);
        }else{
            ub.at(i) = a.at(i);
        }
        if(i <= 60){
            ub.at(i) = min(ub.at(i), 1LL << i);
        }

        if(i + 1 <= n){
            lb.at(i) = max(a.at(i) + lb.at(i + 1) / 2, 1LL);
        }else{
            lb.at(i) = max(a.at(i), 1LL);
        }
    }

    // for(ll i = n - 1; i >= 0; --i){
    //     lb.at(i) = max(lb.at(i), a.at(i) + lb.at(i + 1) / 2);
    //     ub.at(i) = min(ub.at(i), a.at(i) + ub.at(i + 1));
    // }
    for(ll i = 1; i <= n; ++i){
        lb.at(i) = max(lb.at(i), lb.at(i - 1) - a.at(i - 1));
        ub.at(i) = min(ub.at(i), 2 * (ub.at(i - 1) - a.at(i - 1)));
    }

    ll ans = 0;
    REP(i, n + 1){
        if(lb.at(i) > ub.at(i)){
            cout << -1 << endl;
            return 0;
        }
        ans += ub.at(i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5636
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int s;
	cin >> s;
	int number = 1;
	while (1) {
		if (s == 1 || s == 2 || s == 4) break;
		if (s % 2 == 0) {
			s /= 2;
			number++;
		}
		else {
			s = s * 3 + 1;
			number++;
		}
	}
	cout << number + 3 << endl;
	return 0;
}

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

using namespace std;

int64_t solve(int64_t k, int64_t a, int64_t b) {
  if (b - a <= 2) {
    return k + 1;
  }
  if (k < a + 1) {
    return k + 1;
  }
  int64_t ret = 0;
  k -= a + 1;
  ret += b;
  while (k >= 2) {
    k -= 2;
    ret += (b - a);
  }
  ret += k;
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t k, a, b;
  std::cin >> k >> a >> b;
  std::cout << solve(k, a, b) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	int n,a;
	cin>>n>>a;
	cout<<n*n-a<<endl;
	return 0;
}

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

#define int long long int
#define endl "\n"

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

	vector<double> arr(n+1);
	for(int i = 1 ; i <= n; i++)
		cin >> arr[i];

	vector<vector<double> > dp(n+1, vector<double>(n+1, 0.0));
	dp[0][0] = 1.000;

	for(int i = 1 ; i <= n ; i++){
		double heads = arr[i], tails = 1-arr[i];
		dp[0][i] = tails*dp[0][i-1];

		for(int j = 1; j <= i ; j++){
			dp[j][i] = (heads * dp[j-1][i-1]) +( tails*dp[j][i-1]);
		}
	}
	double ans = 0;

	for(int i = (n/2) + 1; i <=n; i++){
		ans+= dp[i][n];
	} 
	cout << setprecision(9) << ans << endl;

}

Measured memory_bytes: 70656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC127B
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToList();

            var x = nums[2];
            foreach (var i in Enumerable.Range(0, 10))
            {
                x = nums[0] * x - nums[1];
                Console.WriteLine(x);
            }
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
#define fi first
#define se second

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

int main(){
  int h, w; cin >> h >> w;
  vector<string> field(h);
  rep(i, h) cin >> field[i];

  vector<vi> dist(h, vi(w, -1));
  queue<pii> que;
  rep(i, h) rep(j, w) if(field[i][j] == '#'){
    dist[i][j] = 0;
    que.push(make_pair(i, j));
  }

  while(!que.empty()){
    pii pos = que.front();
    int x = pos.fi;
    int y = pos.se;
    que.pop();
    rep(i, 4){
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(nx<0 || h<=nx || ny<0 || w<=ny) continue;
      if(dist[nx][ny] == -1){
        dist[nx][ny] = dist[x][y] + 1;
        que.push(make_pair(nx, ny));
      }
    }
  }
 
  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, dist[i][j]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 13456
import heapq
import copy
N, K = map(int, input().split())
V = list(map(int, input().split()))

max_val = 0
left_hq = list()
left_val = 0
for left in range(N+1):
    if left > 0:
        heapq.heappush(left_hq,V[left-1])
        left_val += V[left-1]
        all_hq = copy.deepcopy(left_hq)
        all_val = left_val
        for right in range(N+1):
            if right+left > K or right+left > N :
                continue
            if right > 0:
                heapq.heappush(all_hq,V[-right])
                all_val += V[-right]
            
            temp_hq = copy.deepcopy(all_hq)
            temp_val = all_val
            for i in range(K-left-right):
                if len(temp_hq) == 0:
                    break
                else:
                    minus = heapq.heappop(temp_hq)
                    if minus > 0:
                        break
                    temp_val -= minus
                    
            if temp_val > max_val:
                max_val = temp_val
print(max_val)


Measured memory_bytes: 75816
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x,y,z,esc;
        
        x = sc.nextInt();
        y = sc.nextInt();
        z = sc.nextInt();
        
        esc = x;
        x = z;
        z = y;
        y = esc;
        
        System.out.println(x + " " +  y + " " + z);
    }
}


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

#define ll long long int
#define INFTY (1<<21)

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    ll N,H,W;
    cin>>N>>H>>W;
    int c = 0;
    for(int i = 0; i < N; i++){
        ll a,b;
        cin>>a>>b;
        if(a>=H&&b>=W) c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc;

	Main() {
		sc = new Scanner(System.in);
	}
	
	void calc() {
		int N = sc.nextInt();
		int K = sc.nextInt();
		int c = 0;
		for (int i = 0; i < N; i++) {
			int h = sc.nextInt();
			if (h >= K) c++;
		}
		System.out.println(c);
	}

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

Measured memory_bytes: 47844
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

// w := 幅, h := 高さ, len := 最も長い文字列の長さ
int w, h, len;
// memo[y][x] := (x,y) を調べたかどうか
bool memo[20][20];
// S := 登場した文字列
set<string> S;
// ans := 解の候補
vector<string> ans;

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

// memo の初期化
void clear_memo(){
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			memo[y][x] = false;
		}
	}
}

void f(const vector<string>& v, int sx, int sy){
	
	for(int i=0 ; i < 8 ; i++ ){
		string s;
		clear_memo();
		memo[sy][sx] = true;
		s.push_back( v[sy][sx] );
		int mx = (sx + dx[i] + w) % w;
		int my = (sy + dy[i] + h) % h;
		while( true ){
			// すでに調べているとき
			if( memo[my][mx] ) break;
			memo[my][mx] = true;
			
			s.push_back( v[my][mx] );
			if( S.count( s ) ){ // 2回目以降の登場した文字列
				if( len <= s.size() ){
					len = s.size();
					ans.push_back( s );
				}
			}else{ // 初めてならsetに追加
				S.insert( s );
			}
			mx = (mx + dx[i] + w) % w;
			my = (my + dy[i] + h) % h;
		}
	}
}

string solve(const vector<string>& v){
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			f(v,x,y);
		}
	}
	
	// 解がないとき
	if( ans.size() == 0 ){
		return "0";
	}
	vector<string> vs;
	for(int i=0 ; i < ans.size() ; i++ ){
		if( ans[i].size() == len ){
			vs.push_back( ans[i] );
		}
	}
	sort( vs.begin() , vs.end() );
	return vs[0];
}

int main(){
	while( cin >> h >> w , h || w ){
		// 初期化
		S.clear();
		ans.clear();
		len = 0;
		
		vector<string> v(h);
		for(int y=0 ; y < h ; y++ ){
			cin >> v[y];
		}
		string s = solve(v);
		cout << s << endl;
	}
}

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

int main() {
  const int M = 998244353;

  string S;
  int K;
  cin >> S >> K;

  vector<int> A;
  for (int i = 0; i < S.size(); ++i) {
    int j = i;
    while (j < S.size() && S[j] == '1') ++j;
    A.push_back(j - i);
    i = j;
  }

  const int N = A.size();
  vector<int> sa(N + 1);
  for (int i = N - 1; ~i; --i) sa[i] = sa[i + 1] + A[i];

  static int d[401][401][401];
  static int svd[402][401]; // sum vertical
  static int dgd[802][402]; // sum diagonal
  d[N][0][0] = 1;
  for (int i = N - 1; ~i; --i) {
    for (int t = 0; t <= min(K, 400); ++t) {
      for (int s = 0; s <= 400; ++s) {
        svd[s + 1][t] = (svd[s][t] + d[i + 1][s][t]) % M;
      }
    }
    for (int r = 0; r <= 400; ++r) {
      for (int c = 0; c <= r; ++c) {
        dgd[r][c + 1] = (dgd[r][c] + d[i + 1][r - c][c]) % M;
      }
      for (int c = 0; c <= 400 - r; ++c) {
        if (r > c) dgd[400 + r][c + 1] = 0;
        else dgd[400 + r][c + 1] = (dgd[400 + r][c] + d[i + 1][400 + r - c][c]) % M;
      }
    }
    for (int s = 0; s <= sa[i]; ++s) {
      for (int t = 0; t <= min(K, 400); ++t) {
        if (1 <= min(sa[i + 1], s - A[i])) {
          (d[i][s][t] += svd[s - (A[i] + 1) + 1][t]) %= M;
          (d[i][s][t] -= svd[s - (A[i] + min(sa[i + 1], s - A[i]))][t]) %= M;
        }
        if (max(A[i] - s, 0) <= min(A[i], t)) {
          (d[i][s][t] += dgd[s - A[i] + t][t - max(A[i] - s, 0) + 1]) %= M;
          (d[i][s][t] -= dgd[s - A[i] + t][t - min(A[i], t)]) %= M;
          /* for (int j = max(A[i] - s, 0); j <= min(A[i], t); ++j) { */
          /*   (d[i][s][t] += d[i + 1][s - (A[i] - j)][t - j]) %= M; */
          /* } */
        }
      }
    }
  }

  /* for (int i = N; ~i; --i) */
  /*   for (int j = 0; j <= 400; ++j) */
  /*     for (int k = 0; k <= 400; ++k) */
  /*       if (d[i][j][k]) */
  /*         printf("d[%d][%d][%d] = %d\n", i, j, k, d[i][j][k]); */

  int res = 0;
  for (int i = 0; i <= min(400, K); ++i) {
    (res += d[0][sa[0]][i]) %= M;
  }
  if (res < 0) res += M;

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 40676
import java.util.*;

class Main{

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

		int N = sc.nextInt();

		int ans = 0;

		for(int i = 1; i<10; i++){
			int a = 111;
			if((a*i) >= N){
				ans = a*i;
				break;
			}
		}

		System.out.println(ans);


	}
}

Measured memory_bytes: 21716
#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;
ll c[30],s[400][30],las[30],t[400];

int main()
{
	int D;
	cin >> D;
	rep(i,26)
	{
		cin >> c[i];
	}
	rep(i,D)
	{
		rep(j,26)
		{
			cin >> s[i][j];
		}
	}
	ll now = 0;
	for (ll i = 0; i < D; ++i)
	{
		ll best = -1 * 1e10;
		ll bestv = 0;
		rep(j,26)
		{
			ll tmp = 0;
			tmp += s[i][j];
			rep(k,26)
			{
				if (k != j)
				{
					tmp -= c[k] * (i+1 - las[k]);
				}
			}
			if (tmp > best)
			{
				best = tmp;
				bestv = j;
			}
		}
		//cout << bestv+1 << endl;
		now += best;
		t[i] = bestv;
		las[bestv] = i+1;
	}

	rep(i,100000)
	{
		ll r = rand() % (D-1);
		swap(t[r],t[r+1]);
		ll tmp2 = 0;
		rep(j,30)
		{
			las[j] = 0;
		}
		rep(j,D)
		{
			tmp2 += s[j][t[j]];
			las[t[j]] = j+1;
			rep(k,26)
			{
				tmp2 -= c[k] * (j+1 - las[k]);
			}
		}
		if (tmp2 > now)
		{
			now = tmp2;
		}
		else swap(t[r],t[r+1]);
	}
	rep(i,D)
	{
		cout << t[i]+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ios();
    int A, B, Q;
    cin >> A >> B >> Q;

    vector<ll> vs(A), vt(B), vq(Q);
    for(auto& i : vs){
        cin >> i;
    }
    for(auto& i : vt){
        cin >> i;
    }
    for(auto& i : vq){
        cin >> i;
    }

    REP(i, Q){
        ll x = vq[i];
        int si = (lower_bound(all(vs), x) - vs.begin()), ti = (lower_bound(all(vt), x) - vt.begin());
        vector<ll> s(2), t(2);
        s[0] = vs[si];
        t[0] = vt[ti];
        s[1] = vs[max(si - 1, 0)];
        t[1] = vt[max(ti - 1, 0)];
        ll d = INF;
        REP(j, 2){
            REP(k, 2){
                d = min(d, abs(s[j] - t[k]) + min(abs(s[j] - x), abs(t[k] - x)));
            }
        }
        cout << d << '\n';
    }

    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main(){
  int r,D,x_2000;
  vector<int> x(11);
  cin >> r >> D >> x_2000;
  x.at(0) = x_2000;
  for(int i = 0; i < 10; i++)
    x.at(i + 1) = r*x.at(i) - D;
  for(int i = 0; i < 10; i++)
    cout << x.at(i + 1) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int fib(int n);

int main() {
    int n;
    int dp[45];

    //?????????
    /* ??????3-1 */
    dp[0] = dp[1] = 1;
    /* ??????3-2 */

    //??\???
    cin >> n;

    //DP
    for (int i = 2; i <= n; i++) {
        /* ??????3-3 */
      dp[i] = dp[i-1] + dp[i-2];
    }

    //??????
    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,k,p[1010];
	cin >> n >> k;
	for(int i = 0;i < n;i++) cin >> p[i];
	sort(p,p + n);
	int sum = 0;
	for(int i = 0;i < k;i++) sum += p[i];
	cout << sum << endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;
ll ret[MAX];
void prime_factor(ll N){
  ll i;
  for(i=2;i*i<=N;i++){
    while(N%i==0){
      ret[i]++;
      N/=i;
    }
  }
  if(N!=1) ret[1] = 1;
}

void print_vector(ll *ret,ll N){
  ll i;
  repn(i,N){
    cout<<i<<" "<<ret[i]<<endl;
  }
}

long long fac[MAX], finv[MAX], inv[MAX];

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
// 前処理
  COMinit();
  ll N,M;cin>>N>>M;
  ll i,j,k,l;
  prime_factor(M);
  // print_vector(ret,M);
  ll ans = 1;
  for(i=1;i*i<=M;i++){
    if(ret[i]!=0){
      ans *= COM(N+ret[i]-1,N-1);
      ans %= MOD;
    }
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 12544
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

int main(){
    int h,w;
    cin>>h>>w;
    char a[h][w];
    rep(i,h){
        rep(j,w){
            cin>>a[i][j];
        }
    }

    rep(i,w+2) cout<<'#';
    cout<<endl;
    rep(i,h){
        cout<<'#';
        rep(j,w){
            cout<<a[i][j];
        }
        cout<< '#'<<endl;
    }
    rep(i,w+2)cout<<'#';
    return 0;
}

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

int main(){
  string s,t[4]={"maerd","remaerd","esare","resare"};cin>>s;
  reverse(s.begin(),s.end());
  bool f;
  
  while(s.size()){
    f=0;
    for(int i=0;i<4;i++) if(!(s.find(t[i]))){
      s=s.substr(t[i].size());
      f=1;
    }
    if(!f) break;
  }
  
  cout<<(f?"YES":"NO");
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
    int n, m; cin >> n >> m;
    vi x(m), y(m);
    rep(i, m) cin >> x[i] >> y[i], x[i]--, y[i]--;

    vi isR(n), num(n, 1);
    isR[0] = true;

    rep(i, m){
        int a = x[i], b = y[i];

        if(num[a] == 0) continue;

        if(isR[a]){
            isR[b] = true;
            if(num[a] == 1){
                isR[a] = false;
            }
        }
        num[a]--, num[b]++;
    }

    int res = 0;
    for(auto & e : isR){
        if(e == true){
            res++;
        }
    }
    cout << res << endl;

    return 0;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

const int N_MAX = 3010;



int main() {
    int n; cin >> n;
    int now_x = 0;
    int now_y = 0;
    int now_t = 0;
    rp(i, 0, n) {
        int x, y, t;
        cin >> t >> x >> y;
        int time = (t - now_t) - abs(x - now_x) - abs(y - now_y);
        if(time < 0 || time%2 == 1) {
            cout << "No" << endl;
            return 0;
        }
        now_x = x;
        now_y = y;
        now_t = t;
    }
    cout << "Yes" << endl;
    return 0;
}

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

int gcd(int x, int y)
{
  if(x < y) swap(x, y);
  while(y > 0) {
    int r = x%y;
    x = y;
    y = r;
  }
  return x;
}

int main()
{
  int x, y, d;
  cin >> x >> y;
  d = gcd(x, y);
  cout << d << endl;
  return 0;
}



Measured memory_bytes: 3088
def myfindall(s,ps):
    # start = 0
    matchlist =[]
    while True:
        tmp = s.find(ps)
        if tmp < 0 :
            break
        if len(matchlist)>0:
            matchlist.append(tmp+matchlist[-1]+1)
        else:
            matchlist.append(tmp)
        s = s[tmp+1:]
    return matchlist

instr = raw_input()
findstr = raw_input()
matchlist = myfindall(instr,findstr[0])
matchflag = False
y=0
for x in matchlist:
    if matchflag:
        break
    while True:
        if y >= len(findstr):
            print "Yes"
            matchflag = True
            break
        if x >= len(instr):
            x = 0
        if instr[x]==findstr[y]:
            x+=1
            y+=1
        else:
            y=0
            break
if not matchflag:
    print "No"

Measured memory_bytes: 6476
#include <stdio.h>
#define N 100
#define WHITE 0
#define BLACK 1
#define GRAY 2
 
int n,A[N][N],d[N],f[N],color[N],t=0;
 
 void DFSvisit(int u){
  int v;
 
  color[u] = GRAY;
  
  d[u] = ++t;
 
  for(v = 0 ; v < n ; v++){
    if(A[u][v]==1 && color[v]==WHITE)   DFSvisit(v);
  }
  color[u] = BLACK;
  f[u] = ++t;
 
}
 
 
int main(){
  int i,j,u,v,k;
  
  scanf("%d",&n);
 
  for(i = 0 ; i < n ; i++)
    for(j = 0 ; j < n ; j++)
      A[i][j] = 0;
  
  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&u,&k);
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      A[u-1][v-1] = 1;
    }
  }
 
  for(i = 0 ; i < n ; i++){
    color[i]=WHITE;
  }
 
  for(i = 0 ; i < n ; i++){
    if(color[i] == WHITE) DFSvisit(i);
  }
 
  for(i = 0 ; i < n ; i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
 
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    vector<int> B(N);
    REP(i, N) cin >> B[i];
    vector<int> C(N-1);
    REP(i, N-1) cin >> C[i];
    int ans = 0;
    REP(i, N) {
        ans += B[A[i]-1];
        if(i > 0 && A[i] == A[i-1] + 1) {
            ans += C[A[i]-2];
        }
    }
    cout << ans << endl;
}

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

#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef  long long  ll ;

int main()
{
  fastIO();


	ll n;
	cin>>n;
	cout<< pow(n,3) <<'\n';

 return 0;
 }


Measured memory_bytes: 4184
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,M; cin>>N>>M;
  vector<vector<pii>> A(N);
  rep(i,0,M){
    int L,R,D; cin>>L>>R>>D;
    A[L-1].pb(mp(R-1,D));
    A[R-1].pb(mp(L-1,-D));
  }
  vi F(N,INF);
  rep(i,0,N){
    if(F[i]==INF){
      F[i]=0;
      vi C;
      queue<pii> Q;
      Q.push(mp(i,0));
      while(Q.size()>0){
        int X=Q.front().first,Y=Q.front().second; Q.pop();
        C.pb(X);
        rep(i,0,A[X].size()){
          int P=A[X][i].first,R=Y+A[X][i].second;
          if(F[P]==INF){
            F[P]=R;
            Q.push(mp(P,R));
          }
          else{
            if(F[P]!=R){
              cout<<"No"<<endl;
              return 0;
            }
          }
        }
      }
      set<int> S;
      rep(j,0,C.size()) S.insert(F[C[j]]);
      int H=*rbegin(S),I=*begin(S);
      if(H-I>1000000000){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  }



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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read() 	        freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n) 	        scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n) 	        scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%ull",&n)
#define ull             unsigned long long int
#define endll           pf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps 	        1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())

bool Check(ll  N,int pos){return (bool)(N & (1LL<<pos));}
ll  Set(ll  N,int pos){	return N=N | (1LL<<pos);}
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod 1000000007
#define var    int i,j,k,n,m,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

int main()
{
	var;
    cin>>n>>m;
    if(n==1)
    {
        if(m!=1)
        {
            cout<<"Alice"<<endl;
        }
        else cout<<"Draw"<<endl;
        return 0;
    }
    if(m==1)
    {
        if(n!=1)
        {
            cout<<"Bob"<<endl;
        }
        else cout<<"Draw"<<endl;
        return 0;
    }

    if(n>m)cout<<"Alice"<<endl;
    else if(m>n)cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
}


Measured memory_bytes: 256
// Date: 2020-03-16

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 3000 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n;
char s[N];
LL dp[2][N], pre[2][N];

int main() {
    scanf("%d%s", &n, s+1);
    dp[0][1] = pre[0][1] = 1;
    int cur = 1;
    rep(i, 2, n) {
        rep(j, 1, i) {
            if(s[i-1] == '<') {
                if(j == 1) dp[cur][j] = 0;
                else dp[cur][j] = pre[cur^1][j-1];
            } else {
                if(j == i) dp[cur][j] = 0;
                else dp[cur][j] = (pre[cur^1][i-1]-pre[cur^1][j-1]+mod)%mod;
            }
        }
        rep(j, 1, i) pre[cur][j] = (pre[cur][j-1] + dp[cur][j]) % mod;
        cur ^= 1;
    }
    LL ans = 0;
    rep(i, 1, n) ans = (ans + dp[cur^1][i]) % mod;
    printf("%lld\n", ans);

    return 0;
}

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

using namespace std;

void solve() {
  int k;
  cin >> k;
  --k;
  vector<int> arr{1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                  1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << arr[k] << endl;
}

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


Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

using llint=__int128;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  lint n;
  cin>>n;

  vector<llint> a(n);
  bool found_zero=false;
  for(int i=0;i<n;i++){
    lint v;
    cin>>v;
    a[i]=v;
    if(v==0){
      cout<<0<<endl;
      return 0;
    }
  }

  llint result=a[0];
  llint limit=10;
  for(int i=0;i<17;i++){
    limit*=10;
  }
  for(int i=1;i<n;i++){
    result*=a[i];
    if(result>limit){
      cout<<-1<<endl;
      return 0;
    }
  }

  lint v=result;
  cout<<v<<endl;


  return 0;
}




Measured memory_bytes: 4784
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

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

int main()
{
    ll k;
    cin>>k;
    string s;
    cin>>s;
    if(s.size()<=k)
    cout<<s;
    else
    cout<<(s.substr(0,k)+"...");
}


Measured memory_bytes: 3600
#include<stdio.h>
#include<string.h>
int view(int *,int,char*);// 1 hairetu 2 nagasa
int swap(int *,int*);
int swapc(char *,char *);

int main(){
  int t,flag=1,i,j,n,a[36],b[36],*min;
  char ac[36],bc[36],*minc;
  char str[3];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %s",str);
    ac[i] = str[0];
    a[i] = str[1]-'0';
    b[i]=a[i];
    bc[i]=ac[i];
  } 
 while(flag){
    flag=0;
    for(j=n-1;j>0;j--){
      if(a[j]<a[j-1]){
	t=a[j];
	a[j]=a[j-1];
	a[j-1]=t;
swapc(&ac[j],&ac[j-1]);
	flag =1;
      }
    }
  }
  view(a,n,ac);
//printf("D2 C3 H4 S4 C9\n");

  printf("Stable\n");
    for(i=0;i<n-1;i++){
    min=&b[i];
minc=&bc[i];
    for(j=i+1;j<n;j++){
      if(*min>b[j]){
	min=&b[j];
	minc=&bc[j];
      }
    }
    if(min !=&a[i]){
    swap(&b[i],min);
	swapc(&bc[i],minc);
    }
  }
 view(b,n,bc);
ac[n] ='\0';
bc[n] = '\0';
//printf("D2 C3 S4 H4 C9\n");
    if(strcmp(ac,bc) != 0) printf("Not stable\n");
    else printf("Stable\n");
  return 0;
}

int view(int *a,int n,char *c){
  int i;
  for(i=0;i<n;i++) {
    printf("%c%d",c[i],a[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n");

}
int swap(int *a,int *b){
  int t;
        t = *a;
	*a = *b;
	*b = t;
}
int swapc(char *a,char *b){
  char t;
        t = *a;
	*a = *b;
	*b = t;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
void test_case()
{
	ll n, W;
	cin>>n>>W;
	ll w[n];
	ll v[n];
	for(ll i=0; i<n; i++){
		cin>>w[i]>>v[i];
	}
	ll dp[n][W+1];
	for(ll j=0; j<w[0]; j++){
		dp[0][j]=0;
	}
	for(ll j=w[0]; j<=W; j++){
		dp[0][j]=v[0];
	}
	for(ll i=1; i<n; i++){
		for(ll j=0; j<W+1; j++){
			if(j<w[i])
			dp[i][j]=dp[i-1][j];
			else 
			dp[i][j]=max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
		}
	}
	cout<<dp[n-1][W]<<endl;
}
int main ()
{
	fastio
	int t;
	t=1;
	while(t--)
	test_case();
	return 0;
	
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
typedef pair<int,int>P;
typedef pair<P,P>Q;
vector<Q>p;
int mp[309][309];
ll sum[90009];

int main(){
  int h,w,d;
  cin>>h>>w>>d;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>mp[i][j];
      p.push_back(Q(P(mp[i][j],j),P(i,0)));
    }
  }
  sort(p.begin(),p.end());

  for(int i=d;i<h*w;i++){
    int x1=p[i-d].fi.se;
    int y1=p[i-d].se.fi;
    int x2=p[i].fi.se;
    int y2=p[i].se.fi;
    sum[i+1]=sum[i-d+1]+abs(x1-x2)+abs(y1-y2);
  }

  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    cout<<sum[r]-sum[l]<<endl;
  }

  return(0);
}


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


int main() {

    char x, y;
    cin >> x >> y;
    char ans;
    if (x - 'A' < y - 'A') ans = '<';
    else if (x - 'A' > y - 'A') ans = '>';
    else if (x - 'A' == y - 'A') ans = '=';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;

void solve ()
{
    ll n,m,k,x,y = 0,res = 0,l,cnt = 0,sum = 0,z,sum1 = 0,cnt1 = 0,h,res1;
    cin >> n;
    ll pre[n],suf[n];
    ll ar[n];
    
	rep ( i , 0 , n )
        cin >> ar[i];
    
	pre[0] = ar[0];suf[n-1] = ar[n-1];
    
	rep ( i , 1 , n ) 
	    pre[i] = __gcd ( pre[i-1] , ar[i] );
    
	for ( ll i = n - 2 ; i >= 0 ; -- i ) 
	    suf[i] = __gcd ( ar[i] , suf[i+1] );
    
	ll ans = max ( suf[1] , pre[n-2] );
    
	rep ( i , 1 , n )
        ans = max ( ans , __gcd ( pre[i-1] , suf[i+1] ) );
    
	cout << ans;
	
}

int main ()
{
    ll t;
    
    t = 1;
    while ( t -- )
        solve ();
    
    return 0;
	 
}

Measured memory_bytes: 2560
n,k = map(int, input().split())

MOD = 10**9+7

f = [1]*(n+1)
for i in range(n):
  f[i+1] = f[i]*(i+1)%MOD
  
inv = [1]*(n+1)
inv[n] = pow(f[n], MOD-2, MOD)
for i in range(n,0,-1):
  inv[i-1] = inv[i] * i % MOD
  
def nCr(n, r):
  return f[n]*inv[n-r]*inv[r]%MOD

ans = 0
for i in range(min(n, k+1)):
  ans += nCr(n, i) * nCr(n-1, n-i-1) % MOD
  ans %= MOD
  #print(i, ans, nCr(n,i), nCr(n-1, n-i-1))
  
print(ans)

      
    
    

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

int main(){
	
	int a , b , c , x , y , z;
	cin >> a >> b >> c;
	//(a>b) ? (b>c) ? x=c , y=b , z=a : (c>a) ? x=b , y=a , z=c : x=b , y=c , z=a : (a>c) ? x=c , y=a , z=b :(c>b) ? x=a , y=b , z=c : x=a , y=c , z=b;
    //cout << x << " " << y << " " << z << endl;
	if (a>=b){
		if (b>=c) {
			cout << c << " " << b << " " << a << endl; 
		} else if (c>=a) {
			cout << b << " " << a << " " << c << endl;
		} else {
			cout << b << " " << c << " " << a << endl;
		}
	} else if (a<b){
		if (a>=c){
			cout << c << " " << a << " " << b << endl;
		} else if (c>=b){
			cout << a << " " << b << " " << c << endl;
		} else {
			cout << a << " " << c << " " << b << endl;
		}
	}
	return 0;
}

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


void solver() {
  string s;
  cin >> s;
  vector<char> s_;
  for (int i = 0 ; i < s.length(); i++) {
    s_.push_back(s[i]);
  }

  int q;
  cin >> q;

  bool flipped = false;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      flipped = !flipped;
    } else {
      int f;
      char c;
      cin >> f >> c;

      if (f == 1) {
        if (!flipped) {
          s_.insert(s_.begin(), c);
        } else {
          s_.push_back(c);
        }
      } else {
        if (!flipped) {
          s_.push_back(c);
        } else {
          s_.insert(s_.begin(), c);
        }
      }
    }
  }

  if (flipped) {
    reverse(s_.begin(), s_.end());
  }
  for (int i = 0; i < s_.size(); i++) {
    cout << s_[i];
  }
  cout << "\n";
  return;
}

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


Measured memory_bytes: 1144
// ConsoleApplication1.cpp : アプリケーションのエントリ ポイントを定義します。
//


#include <iostream>
#include <vector>
#include <string>
#include <queue>

#define SIRO 1000000

using namespace std;

typedef pair<int, int> point_t;

point_t operator+(const point_t &lhs, const point_t &rhs)
{
	point_t p = { lhs.first + rhs.first, lhs.second + rhs.second };
	return p;
}

bool operator==(const point_t &lhs, const point_t &rhs)
{
	return (lhs.first == rhs.first) && (lhs.second == rhs.second);
}



int main()
{
	int H, W;
	int black = 0;
	bool is_goal = false;

	cin >> H >> W;

	point_t start = make_pair(0, 0);
	point_t goal = make_pair(H - 1, W - 1);

	const point_t points[] = {
		{ -1, 0 },{ 1, 0 },{ 0, -1 },{ 0, 1 },
	};

	vector<vector<int>> map(H, vector<int>(W));

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char hoge;
			cin >> hoge;
			if (hoge == '#') {
				black++;
				map[i][j] = -1;
			}
			else if (hoge == '.') {
				map[i][j] = SIRO;
			}
		}
	}

	map[0][0] = 0;

	queue<point_t> q;
	q.push(start);



	// kaitou

	while (!q.empty()) {
		point_t current = q.front(); q.pop();

		if (current == goal) {
			is_goal = true;
			cout << H * W - black - 1 - map[current.first][current.second] << endl;
			break;
		}

		// currentから移動
		for (const auto &point : points) {

			point_t next = current + point;

			//移動先が白マスか
			//壁じゃない
			if ((0 <= next.first && next.first < H) && (0 <= next.second && next.second < W)) {
				//黒じゃない
				if (map[next.first][next.second] != -1) {
					if (map[next.first][next.second] == SIRO) {
						q.push(next);
						map[next.first][next.second] = map[current.first][current.second] + 1;
					}
				}
			}
		}


	}

	if (!is_goal) {
		cout << -1 << endl;
	}

	return 0;
}



Measured memory_bytes: 256
def main():
    n = int(input())
    A = list(map(int, input().split()))

    k = 10000
    B = [None] * n
    C = [0] * k
    for i in range(n):
        C[A[i]] += 1

    for i in range(1, k):
        C[i] += C[i-1]

    for i in range(n-1, -1, -1):
        B[C[A[i]] - 1] = A[i]
        C[A[i]] -= 1

    print(*B)


if __name__ == '__main__':
    main()



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

public class Main{

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

		char s[]=sc.next().toCharArray();
		Arrays.sort(s);
		String ss=String.valueOf(s);
		if(ss.equals("abc")){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, t, a;
  cin >> n >> t >> a;
  double min_val = 1e9;
  int ans = -1;
  rep(i, 0, n) {
    double h;
    cin >> h;
    double x = abs(a - (t - h * 0.006));
    if (min_val > x) {
      min_val = x;
      ans = i + 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def solve(n, m, lst):


    lst.sort()

    ans = 0
    r = m
    for v in lst:
        a, b = v
        if r <= b:
            ans += a * r
            break
        r -= b
        ans += a * b

    return ans

def main():
    n, m = input().split()
    n = int(n)
    m = int(m)
    lst = []
    for _ in range(n):
        a, b = input().split()
        a = int(a)
        b = int(b)
        lst.append((a, b))


    print(solve(n, m, lst))


if __name__ == '__main__':
    main()



Measured memory_bytes: 16956
#include <cstdio>
#include <cmath>
using namespace std;
int counter[200005];
int main(){
	int i, tmp;
	int n;
	long long ans=0;
	
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d", &tmp);
		if(tmp>200000)
			ans++;
		else
			counter[tmp]++;
	}
	for(i=1; i<=200000; i++)
		if(counter[i]!=i)
			if(counter[i]>i)
				ans+=counter[i]-i;
			else
				ans+=counter[i];
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m;
string s;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int d = c + b-a;
	if (d < 0)d = 0;
	cout << d << endl;
}


Measured memory_bytes: 256
//abc163_e.cpp
//Sun Apr 19 20:58:09 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<ll,ll> P;

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

	vector<P> yoji;
	for (int i=0;i<n;i++){
		ll a;
		cin >> a;
		yoji.push_back(P(a,i+1));
	}

	sort(yoji.begin(),yoji.end(),greater<P>());

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

	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (i+j<n){
				dp[i+1][j] = max(dp[i+1][j],dp[i][j]+yoji[i+j].first*abs(yoji[i+j].second-(i+1)));
				dp[i][j+1] = max(dp[i][j+1],dp[i][j]+yoji[i+j].first*abs(yoji[i+j].second-(n-j)));
			}
		}
	}

	ll ans = 0;
	for (int i=0;i<n;i++){
		ans = max(ans,dp[i][n-i]);
	}
	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 35004
n,k=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(k)]
accum=[0]*k
dp=[0]*(n+1)
dp[1]=1
mod=998244353
for num in range(2,n+1):
    for i in range(k):
        l,r=lr[i]
        if l<num<=r:
            accum[i]+=dp[num-l]
            accum[i]%=mod
            dp[num]+=accum[i]
        elif r<num:
            accum[i]+=dp[num-l]-dp[num-r-1]
            accum[i]%=mod
            dp[num]+=accum[i]
        dp[num]%=mod
print(dp[n])

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  char a=s[0];
  int cnt1=0,cnt=1;
  for(int i=0;i<n;i++){
  	 if(s[i]!=a){
  	 if(cnt!=0)
  	 cnt1++;
  	 cnt=1,a=s[i];}
  	 else cnt++;
  	
  }
  if(cnt>=1)cnt1++;
cout << cnt1;
	
}

Measured memory_bytes: 512
N, M = map(int, input().split())
A = set(int(input()) for _ in range(M))
mod = 10 ** 9 + 7

dp = [0] * (N+1)
dp[0] = 1
for i in range(1, N+1):
    if i in A:
        continue
    if i == 1:
        dp[i] = 1
        continue
    dp[i] = dp[i-1] + dp[i-2]

print(dp[N] % mod)


Measured memory_bytes: 460020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long inf = 1LL<<60;

int main(){
    int n;
    cin >> n;
    long long dp[100010];
    rep(i,100010) dp[i] = inf;
    dp[0]=0;

    for(int i=1;i<=n;i++){
        int power = 1;
        while(power<=i){
            dp[i]=min(dp[i],dp[i-power]+1);
            power *= 6;
        }
        power = 1;
        while(power<=i){
            dp[i]=min(dp[i],dp[i-power]+1);
            power *= 9;
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
typedef long long ll;
typedef pair<ll, ll> P;
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;
}

// ////////////////////////////////////////////

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 1000000007ll;

int main() {
    vector<ll> abc(3);
    REP(i, 3){
        cin >> abc[i];
    }
    ll k;
    cin >> k;

    ll ans = 0;
    REP(i, 3){
        if(k >= abc[i]){
            ans += abc[i] * (1 - i);
            k -= abc[i];
        }else{
            ans += k * (1 - i);
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;

bool used[110] = {false};
int n;
string s[110];
int p[110];

string findMinS() {
  string mins = "zzzzzzzzzz";
  for (int i = 0; i < n; i++) {
     if (used[i] == false) {
      if (s[i] < mins) {
        mins = s[i];
      }
    }
  }
  return mins;
}

int findMaxP(string mins) {
  int maxp = -1;
  int ansi = -1;
  for (int i = 0; i < n; i++) {
    if (used[i] == false) {
      if (s[i] == mins) {
        if (p[i] > maxp) {
          maxp = p[i];
          ansi = i;
        }
      }
    }
  }
  return ansi;
}

int main() {
 
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> p[i];
  }

  int count;

  while(count < n) {
    string mins = findMinS();
    int ansi = findMaxP(mins);
    cout << ansi + 1 << endl;
    used[ansi] = true;
    count++;
  }

/*
  used[2] = true;
  string mins = findMinS();
  cout << mins << endl;
  cout << findMaxP(mins) << endl;*/
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int X,Y;
  cin >> X >> Y;
  cout << X+Y/2 << endl;
  return 0;
}


Measured memory_bytes: 256