akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
    
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        int n;cin>>n;
        int a[4]={0};
        rep(i,n){
            string s;cin>>s;
            if(s=="AC"){
                a[0]++;
            }
            if(s=="WA"){
                a[1]++;
            }
            if(s=="TLE"){
                a[2]++;
            }
            if(s=="RE"){
                a[3]++;
            }
        }
        cout<<"AC x "<<a[0]<<endl;
        cout<<"WA x "<<a[1]<<endl;
        cout<<"TLE x "<<a[2]<<endl;
        cout<<"RE x "<<a[3]<<endl;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3620
def solve():
    N = int(input())
    T = list(map(int, input().split()))
    M = int(input())
    for _ in range(M):
        P, X = map(int, input().split())
        # print(T[:P-1]+[X]+T[P:])
        print(sum(T[:P-1]+[X]+T[P:]))
        
solve()

Measured memory_bytes: 2940
import java.util.*;
import java.lang.*;
import java.io.*;
 
class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        String u, nl = System.getProperty("line.separator");
        StringBuilder
            p = new StringBuilder(1000),
            d = (new StringBuilder(100)).append("."),
            s = (new StringBuilder(100)).append("#"),
            k = new StringBuilder(100);
        Scanner r = new Scanner(System.in);
        int h, w, ww;
        d.append(d).append(d).append(d).append(d);
        s.append(s).append(s).append(s).append(s);
        ww = d.length();
        while (0 != ((h = r.nextInt()) | (w = r.nextInt()))) {
            while (w > ww) {
                d.append(d);
                s.append(s);
                ww = d.length();
            }
            p.append(u = s.substring(0, w)).append(nl);
            k.setLength(0);
            k.append(d.substring(0, w)).append(nl)
            .replace(0, 1, "#").replace(w - 1, w, "#");
            while (2 != h--) {
                p.append(k);
            }
            p.append(u).append(nl).append(nl);
        }
        System.out.print(p);
    }
}

Measured memory_bytes: 18376
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int n;
        cin >> n;
        set<int>s;
        int i,x;
        for(i=0; i<n; i++){
            cin >> x;
            s.insert(x);
        }
        if(s.size()==n) cout << "YES" << '\n';
        else cout << "NO";
        
        

}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	ll n,m,tr,res=0;
	cin>>n>>m>>tr;
	vector<string> v(n);
	for(ll i=0;i<n;i++)
	cin>>v[i];
	ll t=n+m;
	ll val=pow(2,t);
	for(ll i=0;i<val;i++){
		vector<ll> r,c;
		ll cnt=0,x=i;
		while(x){
			if(x&1){
				if(cnt<n)
				r.push_back(cnt);
				else
				c.push_back(cnt-n);
			}
			x>>=1;
			cnt++;
		}
		vector<string> temp=v;
		for(ll j=0;j<sz(r);j++)
		for(ll k=0;k<m;k++)
		temp[r[j]][k]='R';
		for(ll j=0;j<sz(c);j++)
		for(ll k=0;k<n;k++)
		temp[k][c[j]]='R';
		ll sum=0;
		for(ll j=0;j<n;j++)
		for(ll k=0;k<m;k++)
		if(temp[j][k]=='#')
		sum++;
		if(sum==tr)
		res++;
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
	solve();
}


Measured memory_bytes: 4088
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
numk={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dp=[0]+[-1]*(N+1)
for i in range(N):
    for j in A:
        if i+numk[j]<=N:
            dp[i+numk[j]]=max(dp[i+numk[j]],dp[i]+1)
m=N
ans=[]
while m>0:
    for i in A:
        if m-numk[i]>=0 and dp[m-numk[i]]==dp[m]-1:
          m-=numk[i]
          ans.append(str(i))
          break
print("".join(ans))

Measured memory_bytes: 3696
import math

N = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [abs(X-Y) for (X,Y) in zip(x, y)]

print(sum(z))

z2 = [Z ** 2 for Z in z]
z3 = [Z ** 3 for Z in z]

print(math.sqrt(sum(z2)))
print(math.pow(sum(z3),1/3))
print(max(z))

Measured memory_bytes: 7876
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <queue>

auto
distance (
    std::vector<std::string> maze,  // copy
    std::size_t max_r,
    std::size_t max_c,
    std::size_t start_r,
    std::size_t start_c)
{
    using T = std::tuple<std::size_t, std::size_t, int>;
    std::queue<T> que;
    auto distance = 0;
    que.push({start_r, start_c, 0});
    maze[start_r][start_c] = '#';
    while ( !que.empty() ) {
      std::size_t cur_r;
      std::size_t cur_c;
      int depth;
      std::tie(cur_r, cur_c, depth) = que.front();
      distance = depth;
      que.pop();

      // Go up
      if ( 0 < cur_r && maze[cur_r - 1][cur_c] == '.' ) {
        que.push({cur_r - 1, cur_c, depth + 1});
        maze[cur_r - 1][cur_c] = '#';
      }
      // Go right
      if ( cur_c + 1 < max_c && maze[cur_r][cur_c + 1] == '.' ) {
        que.push({cur_r, cur_c + 1, depth + 1});
        maze[cur_r][cur_c + 1] = '#';
      }
      // Go down
      if ( cur_r + 1 < max_r && maze[cur_r + 1][cur_c] == '.' ) {
        que.push({cur_r + 1, cur_c, depth + 1});
        maze[cur_r + 1][cur_c] = '#';
      }
      // Go left
      if ( 0 < cur_c && maze[cur_r][cur_c - 1] == '.' ) {
        que.push({cur_r, cur_c - 1, depth + 1});
        maze[cur_r][cur_c - 1] = '#';
      }
    }
    return distance;
}

int
main ()
{
    int h, w;
    std::cin >> h >> w;

    std::vector<std::string> maze(h);
    for (auto & row : maze) {
      std::cin >> row;
    }

    auto d = 0;
    for (std::size_t i = 0; i < h; ++i) {
      for (std::size_t j = 0; j < w; ++j) {
        if ( maze[i][j] == '.' ) {
          d = std::max(d, distance(maze, h, w, i, j));
        }
      }
    }

    std::cout << d << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const int inf = 1e9;
const int mod = 1e9+7;

bool in[200005], out[200005];
int n, m;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, m){
    int a, b;
    cin >> a >> b;
    if(a == 1){
      in[b] = true;
    }
    if(b == n){
      out[a] = true;
    }
  }
  FOR(i, 1, n + 1){
    if (in[i] && out[i]){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll solve()
{
    string s, t;

    cin >> s >> t;

    unordered_map<char, vector<int>> charPos;

    for (int i = 0; i < s.length(); ++i)
        charPos[s[i]].push_back(i);
    
    ll counter = 0;
    ll lastPos = -1;

    for (int i = 0; i < t.length(); ++i)
    {
        if (charPos[t[i]].empty())
            return -1;

        auto it = std::upper_bound(charPos[t[i]].begin(), charPos[t[i]].end(), lastPos);

        if (it == charPos[t[i]].end())
        {
            ++counter;
            lastPos = -1;

            it = std::upper_bound(charPos[t[i]].begin(), charPos[t[i]].end(), lastPos);
        }

        lastPos = *it;
    }

    return counter * s.length() + (lastPos + 1);
}

int main()
{
    cout << solve() << endl;

    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

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

  bool flag = true;
  for (int i = 0; i < H; ++i){
    for (int j = 0; j < W; ++j){
      if (field[i][j] == '#'){
        bool tmp = false;
        if (j - 1 >= 0) if (field[i][j - 1] == '#') tmp = true;
        if (j + 1 < W)  if (field[i][j + 1] == '#') tmp = true;
        if (i - 1 >= 0) if (field[i - 1][j] == '#') tmp = true;
        if (i + 1 < H)  if (field[i + 1][j] == '#') tmp = true;
        if (!tmp) flag = false;
      }
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL n;
  string s;
  cin >> n >> s;
  VI ct(26, 1);
  REPx(x, s) ct[x-'a']++;
  LL ans = 1;
  REPx(x, ct)
  {
    ans *= x;
    ans %= MOD;
  }
  cout << ans-1 << endl;

  return 0;
}

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

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

  vector<pair<ll,int>> fs;
  for (ll i = 2; i*i<=n; ++i){
    int x = 0;
    while (n%i ==0){
      n /= i;
      ++x;
    }
    fs.emplace_back(i,x);
  }
  if (n != 1) fs.emplace_back(n,1);
  
  int ans = 0;
  for (auto p : fs){
    int x = p.second;
    int b = 1;
    while(b <= x){
      x -= b;
      b++;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


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

const long long MAXN = 3001;

double dp[MAXN][MAXN];
double p[MAXN];

int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i+1][j+1] += dp[i][j]*p[i];
            dp[i+1][j] += dp[i][j]*(1-p[i]);
            
        }
    }
    double ans = 0;
    for(int i=(n+1)/2;i<=n;i++){
        ans+=dp[n][i];
    }
    cout<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

ll N;
vector<ll> A(200010);
ll eval(ll b){
    ll sum = 0;
    rep(i,N){
        sum += abs(A[i] - b);
    }
    return sum;
}

int main(){
    cin >> N;
    ll ans = 1e18;
    ll sum = 0;
    rep(i,N){
        cin >> A[i];
        A[i] -= (i+1);
        //A[i] = abs(A[i]);
    }
    sort(A.begin(),A.begin()+N);
    //PR(A,N);
    ans = min(eval(A[N/2]), eval(A[N/2 + 1]));
    //if(N>1){
    //    cmin(ans, eval(A[N/2-1]));
    //}
    cout << ans << endl;
}

Measured memory_bytes: 1792
n = int(input())
d = list(map(int,input().split()))
m = max(d)
if(d[0] != 0 or m >= n):
    print(0)
else:
    s = [0] * (m+1)
    for i in d:s[i] += 1
    if(0 in s or s[0] != 1):
        print(0)
    else:
        t = 1
        for i in range(1,m+1):
            t *= s[i-1]**s[i]
            t %= 998244353
        print(t)


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

class Program
{
    static void Main(string[] args)
    {
        var nd = Console.ReadLine().Split();
        var n = int.Parse(nd[0]);
        var d = int.Parse(nd[1]);

        var X = new int[n][];
        for (int i = 0; i < n; i++)
        {
            X[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        }

        var ans = 0;
        for (int i = 0; i + 1 < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                if (m1(X[i], X[j])) ans++;
            }
        }

        Console.WriteLine(ans);
    }

    static bool m1(int[] y, int[] z)
    {
        var ans = 0;
        for (int i = 0; i < y.Length; i++)
        {
            ans += (y[i] - z[i]) * (y[i] - z[i]);
        }

        return Math.Sqrt(ans) % 1 == 0;
    }
}


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

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    if(B - A + 1 <= 2 * K){
        for(int i = A; i <= B; i++) cout << i << endl;
    }else{
        for(int i = A; i <= A + K - 1; i++) cout << i << endl;
        for(int i =B - K + 1; i <= B; i++) cout << i << endl; 
    }
}


Measured memory_bytes: 3616
n = int(raw_input())
  
d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
t = [0]
  
def DFS_visit(s):
    st[s] = 1
    t[0] += 1
    d[s] = t[0]
    for e in range(n):
        if M[s][e] == 1 and st[e] == 0:
            DFS_visit(e)
    st[s] == 2
    t[0] += 1
    f[s] = t[0]
  
def DFS():
    for s in range(n):
        if st[s] == 0:
            DFS_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])
      
for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        M[G[0]-1][G[2+j]-1] = 1
  
DFS()

Measured memory_bytes: 6516
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const long long INF = LLONG_MAX / 2;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i];
    v.insert(v.begin(), 0);
    ++ n;

    vector<vector<long long> > dp(1, vector<long long>(m+1, 0));
    for(int i=1; i<n; ++i){
        vector<vector<long long> > nextDp(i+1, vector<long long>(m+1, INF));
        for(int j=0; j<i; ++j){
            for(int k=0; k<=m; ++k){
                nextDp[i][k] = min(nextDp[i][k], dp[j][k] + max(0, v[i] - v[j]));
                if(k > 0)
                    nextDp[j][k-1] = min(nextDp[j][k-1], dp[j][k]);
            }
        }
        dp = move(nextDp);
    }

    long long ans = INF;
    for(int i=0; i<n; ++i)
        ans = min(ans, dp[i][0]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1664
class SegmentTree
  ROOT = 1
  private_constant :ROOT

  attr_reader :size

  def initialize(n, x = 0)
    @size = 1
    @size *= 2 while @size < n
    @sum = Array.new(2 * @size){x}
    @parent = Array.new(2 * @size)
    @lchild = Array.new(2 * @size)
    @rchild = Array.new(2 * @size)
    (2 * @size).times do |i|
      @parent[i] = i / 2
      @lchild[i] = i * 2
      @rchild[i] = i * 2 + 1
    end
  end

  def update(i, v)
    i += @size
    @sum[i] = v
    until i == ROOT
      i = @parent[i]
      @sum[i] = @sum[@lchild[i]].gcd(@sum[@rchild[i]])
    end
  end

  def sum(l, r)
    sum_dfs(l, r, ROOT, 0, @size)
  end
  def sum_dfs(a, b, i, l, r)
    return 0       if b <= l || r <= a
    return @sum[i] if a <= l && r <= b
    m = (l + r) / 2
    sum_dfs(a, b, @lchild[i], l, m).gcd(sum_dfs(a, b, @rchild[i], m, r))
  end
end

N=gets.to_i
A=gets.split.map &:to_i

segtree = SegmentTree.new(N)
A.each.with_index do |a, i|
  segtree.update(i, a)
end
res = 0
N.times do |i|
  l = i.zero? ? 0 : segtree.sum(0, i)
  r = i+1==N  ? 0 : segtree.sum(i+1, N)
  d = l.gcd(r)
  res = [res, d].max
end
p res


Measured memory_bytes: 19340
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.S;
		var ans="";
		if(s=="Sunny"){ans="Cloudy";}
		else if(s=="Cloudy"){ans="Rainy";}
		else {ans="Sunny";}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13140
def valid?(a, b, c)
  a <= b + c && b <= c + a + 1 && c <= a + b + 1
end
 
def calc(rear, front, west, east, north, south, buffer)
  same = true
  buffer.size.times do |i|
    a = rear + front
    b = west + east
    c = north + south
 
    if east > 0 && valid?(b - 1, c, a)
      rear, front, west, east = east - 1, west, rear, front
      y = 69
    elsif north > 0 && valid?(c - 1, a, b)
      rear, front, north, south = north - 1, south, front, rear
      y = 78
    elsif south > 0 && valid?(c - 1, a, b)
      rear, front, north, south = south - 1, north, rear, front
      y = 83
    #elsif west > 0 && valid?(b - 1, c, a)
    else
      rear, front, west, east = west - 1, east, front, rear
      y = 87
    end
     
    if same
      x = buffer[i]
      return if x < y
      same = false if x > y
    end
    buffer[i] = y
  end
end
 
def find(target, limit)
  buffer = [99] * limit
  target.permutation(6).to_a.uniq.each do |rear, front, west, east, north, south|
    a = rear + front
    b = west + east
    c = north + south
    if valid?(a, b, c)
      calc(rear, front, west, east, north, south, buffer)
    end
  end
  buffer[0] == 99 ? nil : buffer
end
 
loop do
  target = gets.split.map!(&:to_i)
  break if target.all?(&:zero?)
  p, q = gets.split.map!(&:to_i)
  result = find(target, q)
  puts result ? result[p-1...q].pack('C*') : 'impossible'
end

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

using namespace std;
const int maxn=100005;
typedef long long ll;
ll dp[105][100005];
int n,w[maxn],v[maxn],m;

int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d %d",&w[i],&v[i]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i][j]=max(dp[i-1][j],j>=w[i]?dp[i-1][j-w[i]]+(ll)v[i]:0);
		}
	}
	printf("%lld\n",dp[n][m]);
}

Measured memory_bytes: 78592
from sys import stdin
input = stdin.readline

def dfs(k, path, n):
    """連結情報path,頂点の個数Nが与えられたとき
    頂点Kから各頂点までの距離をlistで返す"""
    from collections import deque # deque(),popleft()
    dist = [-1] * n
    dist[k] = 0
    que = deque([])
    que.append(k)
    while que:
        label = que.popleft()
        for i,c in path[label]: # 頂点labelと連結している頂点iと距離c
            if dist[i] == -1:
                dist[i] = dist[label] + c
                que += [i] # 次に調べる頂点に
    return dist

n = int(input())
path = [[] for i in range(n)]
# path = [{1,2}] * 3
# print(path)
for i in range(n-1):
    a, b, c = map(int, input().split())
#     print(a,b,c)
    path[a-1] += [(b-1, c)]
    path[b-1] += [(a-1, c)]

q, k = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(q)]
dis = dfs(k-1, path, n)
for i in range(q):
    print(dis[xy[i][0] - 1] + dis[xy[i][1] - 1])


Measured memory_bytes: 68112
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

#input=sys.stdin.readline

s=list(map(int,input()))
n=len(s)
n0=n1=0
for i in range(n):
    if s[i]==1:
        n1+=1
    else:
        n0+=1
print(n-max(n0,n1)+min(n0,n1))

Measured memory_bytes: 70744
#include <stdio.h>
#include <math.h>

int min(int a,int b){
    if(a>b) return b;
    else return a;
}

int main(void){
    int n,h[101000];
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&h[i]);
    int cost[101000];
    cost[0]=0;
    for(int i=1;i<n;i++){
        if(i==1) cost[i]=abs(h[i]-h[0]);
        else{
            cost[i]=min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1]));
        }
    }
    printf("%d",cost[n-1]);
    return 0;
}

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)

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


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

using namespace std; using ll=long long; const ll LNF=1e18; const int INF = 1e9+1; const ll M = 1e9+7;
typedef pair<int,int> P;

int main() {
  int n,l; cin>>n>>l;
  int mn = 1e9, sm=0;
  for(int i=0;i<n;i++) {
    sm += l + i;
    if (abs(mn) > l+i) mn=l+i;
  }
  cout<<sm-mn<<endl;
}

Measured memory_bytes: 256
import bisect
from collections import deque
N = int(input())
ans = deque()

for _ in range(N):
    a = int(input())
    ind = bisect.bisect_left(ans, a)
    if ind == 0:
        ans.appendleft(a)
    else:
        ans[ind-1] = a
print(len(ans))


Measured memory_bytes: 7284
#include <iostream>
using namespace std;
long long dp[100][21];
int main()
{
    int n;
    cin>>n;
    int s;
    cin>>s;
    dp[0][s]=1;
    for(int i=1;i<n-1;++i){
        int nn;
        cin>>nn;
        for(int j=0;j<21;++j){
            if(dp[i-1][j]&&j+nn>=0&&j+nn<=20)dp[i][j+nn]+=dp[i-1][j];
            if(dp[i-1][j]&&j-nn>=0&&j-nn<=20)dp[i][j-nn]+=dp[i-1][j];
        }
    }
    int ans;
    cin>>ans;
    cout<<dp[n-2][ans]<<endl;
}

Measured memory_bytes: 1172
import java.util.Scanner;

public class Main {
    public static void main(String[] args ) {
        Scanner scanner = new Scanner(System.in);
        int[] a = new int[26];
        while(scanner.hasNext()){
            String s = scanner.nextLine();
            for(int i = 0; i < s.length(); i++) {
                char c = Character.toLowerCase(s.charAt(i));
                if('a' <= c && c <= 'z')
                    a[c - 'a']++;
            }
        }

        for(int i = 0; i < 26; i++)
            System.out.println((char)((int)'a' + i) + " : " + a[i]);
    }
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, X, T;
    cin >> N >> X >> T;
    cout << N / X * T + !!(N % X) * T << endl;
    return 0;
}


Measured memory_bytes: 3592
h,w,n = map(int,input().split())
grids = {}
D = [1,-1,0]
for _ in range(n):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  
  for dx in D:
    for dy  in D:
      na,nb = a+dx,b+dy
      if not(0<na<h-1 and 0<nb<w-1):
        continue
      if(na,nb) not in grids:
        grids[(na,nb)] = 0
      grids[(na,nb)] += 1
      
        
        
ans = [0 for _ in range(10)]

for v in grids.values():
  ans[v]+=1

ans[0] = (h-2)*(w-2)-sum(ans)

for a in ans:
  print(a)

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

int H, W;
vector<string> S;
struct position {
    int x;
    int y;
    int count;
};
queue<position> q;

int main() {
    cin >> H >> W;
    S.resize(H);
    rep(i, H) cin >> S[i];

    int mx = 0;
    rep(h, H) rep(w, W) {
        if (S[h][w] == '#') continue;

        vector<string> A(H);

        copy(all(S), A.begin());
        q.push({h,w,0});

        while (!q.empty()) {
            position now = q.front();
            int x        = now.x;
            int y        = now.y;
            int count    = now.count;
            mx = max(mx,count);
            q.pop();

            A[x][y] = '#';
            bool flag = false;
            if (x != 0 && A[x - 1][y] != '#') {
                q.push({x - 1, y, count + 1});
                A[x - 1][y] = '#';
            }
            if (y != 0 && A[x][y - 1] != '#') {
                q.push({x, y - 1, count + 1});
                A[x][y - 1] = '#';
            }
            if (x != H - 1 && A[x + 1][y] != '#') {
                q.push({x + 1, y, count + 1});
                A[x + 1][y] = '#';
            }
            if (y != W - 1 && A[x][y + 1] != '#') {
                q.push({x, y + 1, count + 1});
                A[x][y + 1] = '#';
            }
        }
    }

    cout << mx << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] count) {

		Scanner scan = new Scanner(System.in);

		int A500 = Integer.parseInt(scan.next());

		int B100 = Integer.parseInt(scan.next());

		int C50 = Integer.parseInt(scan.next());

		int Xtotal = Integer.parseInt(scan.next());

		scan.close();

		// start

		int result = 0;

		int counts = C50 * B100 * A500;
		int[][] array = new int[counts][3];

		for (int i = 0; i <= C50; i++) {
			for (int j = 0; j <= B100; j++) {
				for (int j2 = 0; j2 <= A500; j2++) {
					if ((50 * i + 100 * j + 500 * j2) == Xtotal) {
						result++;
					}

				}

			}

		}

		System.out.println(result);
	}

}


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

int main() {

	string str;

	cin >> str;

	if (str.size() == 2) {
		cout << str << endl;
	}
	else {
		cout << str[2] << str[1] << str[0] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int a1, a2, a3; cin >> a1 >> a2 >> a3;
  if (a1 + a2 + a3 >= 22) {
    cout << "bust\n";
  }else {
    cout << "win\n";
  }

  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

#define DBG 0

int N=50;
int K=250;
int A[50][50];

int cnt;

int q(int y1,int x1,int y2,int x2){
    if((y2-y1)*(x2-x1)==0)return 0;
    if(DBG){int res=0;
    for(int y=y1;y<y2;y++)for(int x=x1;x<x2;x++)res+=A[y][x];
    return res;
    }
else{
    cout<<"? "<<y1<<" "<<x1<<" "<<y2-1<<" "<<x2-1<<endl;
    int p;cin>>p;
    return p;
}
}

void dfs(int y1,int x1,int y2,int x2,int p){
    if(y1==y2)return;
    if(x1==x2)return;

    if((y2-y1)*(x2-x1)==p){
        for(int y=y1;y<y2;y++)for(int x=x1;x<x2;x++)A[y][x]=1;
        return;
    }

    if(p==0)return;
    int y3=(y1+y2)/2;
    int x3=(x1+x2)/2;

    int pl=q(y1,x1,y2,x3);
    int pu=q(y1,x1,y3,x2);

    int p11,p12,p21,p22;

    if(pl==0){
        p11=p21=0;
        p12=pu;
        p22=p-pu;
    }
    else if(pl==p){
        p12=p22=0;
        p11=pu;
        p21=p-pu;
    }
    else if(pu==0){
        p11=p12=0;
        p21=pl;
        p22=p-pl;
    }
    else if(pu==p){
        p21=p22=0;
        p11=pl;
        p12=p-pl;
    }
    else{
        p11=q(y1,x1,y3,x3);
        p12=pu-p11;
        p21=pl-p11;
        p22=p-p11-p12-p21;
    }

    dfs(y1,x1,y3,x3,p11);
    dfs(y1,x3,y3,x2,p12);
    dfs(y3,x1,y2,x3,p21);
    dfs(y3,x3,y2,x2,p22);
}

signed main(){
    if(DBG){
    vector<pint>v;
    rep(i,N)rep(j,N)v.pb({i,j});
    srand((unsigned)time(NULL));
    random_shuffle(all(v));

    for(int i=0;i<K;i++){
        A[v[i].fi][v[i].se]=1;
    }
    dfs(0,0,N,N,K);
    int cnt=0;
    rep(i,N)rep(j,N)cnt+=A[i][j];
    cout<<cnt<<endl;
    }

    else{
    int tmp;
    cin>>tmp;cin>>tmp;cin>>tmp;
    int mod;cin>>mod;
    dfs(0,0,N,N,K);

    int p=1;
    int res=0;
    rep(i,N)rep(j,N){
        res=(res+p*A[i][j])%mod;
        p=p*2%mod;
    }

    cout<<"! "<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 720
def solve():
    a, b, c, d = map(int, list(input()))
    op = ["+", "-"]
    ans = ""
    for op1 in range(2):
        for op2 in range(2):
            for op3 in range(2):
                s = "a"+op[op1]+"b"+op[op2]+"c"+op[op3]+"d"
                if eval(s) == 7:
                    return str(a)+op[op1]+str(b)+op[op2]+str(c)+op[op3]+str(d)+"=7"


print(solve())


Measured memory_bytes: 61852
N, A, B, C = map(int, input().split())
ans = "Yes\n"
def step(add, remove):
    global A
    global B
    global C
    global ans
    ans += add
    ans += "\n"
    if add == "A":
        A += 1
    elif add == "B":
        B += 1
    else:
        C += 1
    if remove == "A":
        A -= 1
    elif remove == "B":
        B -= 1
    else:
        C -= 1

def getvalue(variable):
    global A
    global B
    global C
    if variable == "A":
        return A
    elif variable == "B":
        return B
    else:
        return C

res = ""
for _ in range(N):
    act = input()
    if A == 0 and B == 0 and C == 0:
        ans = "No"
        res = ""
        break
    elif A != 0 and B != 0 and C != 0:
        step(act[0], act[1])
    elif ((A == 0) != (B == 0)) != (C == 0):
        if res == "":
            if getvalue(act[1]) == 0:
                step(act[1], act[0])
            elif getvalue(act[0]) == 0 :
                step(act[0], act[1])
            else:
                res = act
        else:
            if res[0] in act:
                i = (act.index(res[0])+1)%2
                step(res[0], res[1])
                step(act[i], res[0])
                res = ""
            else:
                i = (act.index(res[1])+1)%2
                step(res[1], res[0])
                step(act[i], res[1])
                res = ""
    else:
        if getvalue(act[0]) != 0:
            step(act[1], act[0])
        elif getvalue(act[1]) != 0:
            step(act[0], act[1])
        else:
            ans = "No"
            res = ""
            break
if res != "":
    step(res[0], res[1])
    res = ""
if ans[-1] == "\n":
    ans = ans[:-1]
print(ans)


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

int main(){
  int N,S;
  cin >> N;
  S=N%10;
  if(S==2 || S==4 || S==5 || S==7 || S==9 ){
    cout << "hon" <<endl;
  }
  if(S==0||S==1||S==6||S==8){
    cout << "pon" <<endl;
  }
  if(S==3){
    cout << "bon" <<endl;
  }
}


Measured memory_bytes: 3604
#include<iostream>

using namespace std;


int main(){
	int candy,i,j;

	while(cin >> candy){
		while(candy > 39){
			candy = candy - 39;
		}

		if(candy>9){
			cout << "3C" << candy << endl;
		}else{
			cout << "3C0" << candy << endl;
		}
	}
}

Measured memory_bytes: 1160
#include <stdio.h>

void merge_sort(int x[], int n)
{
	static int y[262144] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, S[262144];
	const int bit[19] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144};
	scanf("%d", &N);
	for (i = 0; i < bit[N]; i++) scanf("%d", &(S[i]));
	merge_sort(S, bit[N]);
	if (S[bit[N]-1] == S[bit[N]-2]) {
		printf("No\n");
		fflush(stdout);
		return 0;
	}
	
	int j, k, count[19] = {1}, tmp[19];
	for (i = bit[N] - 2; i >= 0; i--) {
		for (j = 1; j <= 18; j++) tmp[j] = 0;
		for (j = i, k = 0; j >= 0 && S[j] == S[i]; j--) {
			for (; k < N && count[k] == 0; k++);
			if (k == N) {
				printf("No\n");
				fflush(stdout);
				return 0;
			}
			count[k]--;
			count[k+1]++;
			tmp[k+1]++;
		}
		i = j + 1;
		for (j = 1; j <= 18; j++) count[j] += tmp[j];
	}
	if (i < 0) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
int dist[100][100];
int n,m;
long long inf=100000000;
int main(int argc,char const* argv[])
{
  vector <int> a(1000,0);
  vector <int> b(1000,0);
  vector <int> c(1000,0);
  cin >> n >> m;
  for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
	{
	  if(i==j) dist[i][j]=0;
	  else dist[i][j]=inf;
	}
    }
  for(int i=0;i<m;i++)
    {
      cin >> a[i] >> b[i] >> c[i];
      a[i]--,b[i]--;
    }
  for(int i=0;i<m;i++)
    {
      dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
      dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
    }
  for(int k=0;k<n;k++)
    {
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
	    }
	}
    }
  int answer=m;
  for(int i=0;i<m;i++)
    {
      bool shortest=false;
      for(int j=0;j<n;j++) if(dist[j][a[i]]+c[i]==dist[j][b[i]]) shortest=true;
      if(shortest==true)
	{
	  answer--;
	}
    }
  cout << answer << endl;
  return 0;
}


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

typedef long long ll;

const ll N = 1e5+1;

const ll MAX = (1LL<<62);

struct edge {
	ll v, w;
	edge(ll _v = -1, ll _w = -1): v(_v), w(_w) {}
	bool operator<(const edge& o) {
		return w < o.w;
	}
};

vector<edge> adj[N];
int n, q, k;
ll dist[N];

void dfs (int u) {
	for (edge e : adj[u]) {
		if (dist[u]+e.w < dist[e.v]) {
			dist[e.v] = dist[u]+e.w;
			dfs(e.v);
		}
	}
}

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		int u, v, w; cin >> u >> v >> w;
		adj[u].push_back(edge(v,w));
		adj[v].push_back(edge(u,w));
	}

	cin >> q >> k;

	for (int i = 1; i <= n; i++)
		dist[i] = MAX;
	dist[k] = 0;
	dfs(k);

	while (q--) {
		int u, v; cin >> u >> v;
		cout << dist[u]+dist[v] << endl;
	}


	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, K; cin >> N >> K;
    vector<ll> a(N+1, 0);
    for(int i=1; i<=N; ++i) cin >> a[i];

    ll ans = 0;
    vector<ll> cum(N+1, 0), poscum(N+1, 0);
    for(int i=1; i<=N; ++i){
        cum[i] = cum[i-1] + a[i];
        if(a[i] > 0) poscum[i] = poscum[i-1] + a[i];
        else poscum[i] = poscum[i-1];
    }

    for(int left=1; left<=N+1-K; ++left){
        ll tmp = max(0LL, cum[left+K-1] - cum[left-1]);
        tmp += poscum[left-1] + (poscum[N]-poscum[left+K-1]);
        chmax(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <functional>
#include <string>
#include <cstring>
#include <sstream>
#include <deque>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> Q;

const int inf1=2e9+9;
const ll inf2=8e18+9;
const ll mol=998244353;
const int maxn=2e5+9;
const ll maxx=1e12+9;

int n,k,ar[maxn];
int d[maxn];

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&ar[i]);
    while(k--)
    {
        memset(d,0,sizeof d);
        for(int i=1;i<=n;i++)
        {
            d[max(1,i-ar[i])]++;
            d[min(n+1,i+ar[i]+1)]--;
        }
        bool flag=true;
        for(int i=1,tmp=0;i<=n;i++)
        {
            tmp+=d[i];
            ar[i]=tmp;
            if(ar[i]!=n) flag=false;
        }
        if(flag) break;
    }
    for(int i=1;i<=n;i++) printf("%d ",ar[i]);
    printf("\n");
}


Measured memory_bytes: 4784
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>  
#include <cstdlib>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

int main(){
    int N;
    cin >> N;
    map<int, int> mp;
    for (int i = 2; i <= N; i++) {
        int A;
        cin >> A;
        mp[A]++;
    }
    
    
    rep1(i,N) {
        cout << mp[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 12956
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cstdio>

using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
	int N,x;
	ll total=1;
	int S[100005]={};
	S[0]=3;
	cin >> N;
	for(int i=0;i<N;i++){
	    cin >> x;
	    total=total*(S[x]-S[x+1])%1000000007;
	    S[x+1]++;
	}

    cout << total << endl;

	return 0;
}


Measured memory_bytes: 640
x = int(input())
job = []
for i in range(x):
    j, t = list(map(int, input().split()))
    job.append([t, j])
fi = 0
f = 0
job = sorted(job)
for i in range(x):
    if f + job[i][1] > job[i][0]:
        print("No")
        fi = 1
        break
    else:
        f += job[i][1]
if fi == 0:
    print("Yes")

Measured memory_bytes: 37984
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <iomanip>
static const double PI = 3.14159265359;
int main()
{
	int64_t N, M;
	std::cin >> N >> M;
	int64_t day = 0;
	for (int64_t i = 0; i < M; ++i) {
		int64_t A;
		std::cin >> A;
		day += A;
		if (day > N) {
			std::cout << "-1" << std::endl;
			return 0;
		}
	}
	std::cout << N - day << std::endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int N, M;
int adj[101][101];
int dis[101][101];
int main()
{
    scanf("%d%d", &N, &M);
    for(int i=0; i<N; ++i)
        for(int j=0; j<i; ++j)
            adj[i][j] = dis[i][j] = adj[j][i] = dis[j][i] = 0x3f3f3f3f;
        
    for(int i=0; i<M; ++i)
    {
        int a, b, c; scanf("%d%d%d", &a, &b, &c); --a; --b;
        dis[a][b] = dis[b][a] = adj[a][b] = adj[b][a] = c;
    }
    for(int k=0; k<N; ++k)
        for(int i=0; i<N; ++i)
            for(int j=0; j<N; ++j)
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
    int ans = 0;
    for(int i=0; i<N; ++i)
        for(int j=0; j<i; ++j)
            if(adj[i][j] != 0x3f3f3f3f && dis[i][j] != adj[i][j])
                ++ans;
    printf("%d\n", ans);
}

Measured memory_bytes: 384
a,b = gets.split.map(&:to_i)

if (1..12).to_a.include?(a) && (1..12).to_a.include?(b)
  if a > b
    puts 'Alice'
  elsif a <b
    puts 'Bob'
  else
    puts 'Draw'
  end
elsif a == 13 && b == 13
  puts 'Draw'
elsif a == 13 && b == 1
  puts 'Bob'
elsif a == 13 && b != 1
  puts 'Alice'
elsif b == 13 && a == 1
  puts 'Alice'
elsif b == 13 && a != 1
  puts 'Bob'
end

Measured memory_bytes: 1788