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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll A[3010][3010];
ll dp[3010][3010][4];

int main()
{
    cout << fixed << setprecision(15);
    ll R, C, K;
    cin >> R >> C >> K;

    Fill(A, 0);
    Fill(dp, 0);

    REP(i, K){
        ll r, c, v;
        cin >> r >> c >> v;

        A[r-1][c-1] = v;
    }

    for(ll i=0; i<=R; i++){
        for(ll j=0; j<=C; j++){
            // 今のマス目を入れた場合の更新を行う
            for(ll k=2; k>=0; k--){
                dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k] + A[i][j]);
            }
            for(ll k=0; k<=3; k++){
                dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
                dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
            }
        }
    }

    cout << dp[R][C-1][0] << endl;

    return 0;
}

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

int main(void){
    int n;
    int b=0;
   // cout << "回数";
    cin >> n;
    bool c = true;
    int s = 0;
    int *a = new int [s];
    for(int i = 0 ; i < n; i++){
        // cout << "数値";
        // cout << i+1;
        cin >> a[i];
        cout << " ";
    }
    while(c){
        for(int i = 0; i < n; i++){
        if(a[i]%2 != 0){
        c = false;
        break;
        }
        a[i] = a[i]/2;
        b++;
    }
    }
    // for(int i = 0; i < n; i++){
    //    cout << a[i];
    //    cout << " ";
    //     }
        
        //cout << "割回数";
        cout << b/n;
        cout << endl;
    }

   


Measured memory_bytes: 256
s = input()
table = [0 for i in range(len(s))]
acgt = ['A', 'C', 'G', 'T']
for i in range(len(s)):
    if s[i] in acgt:
        table[i] += 1

count = 0
ans = 0
for i in table:
    if i:
        count += 1
        ans = max(ans, count)
    else:
        count = 0
print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;

// #define  part ..
#define listi vector<int > 
#define listll vector<long long >
#define pii pair<int ,int > 
#define pll pair<long long ,long long >
#define heap priority_queue<long long >

#define pb(a) push_back(a)
#define mod 998244353
#define maxx 200006
#define ll long long 
#define quick   ios_base::sync_with_stdio(NULL),cin.tie(0);
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// #define test int t;cin>>t;while(t--)
// end of #define 

// define globals ...




 int Main()
{ 

  
  int n;
  cin>>n;

  listll dp(n+2,1);

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


long long ans=0;
  for(int i=1;i<=n;i++){
   ans+= dp[i]*i;
  }
  cout<<ans<<endl;





  
  return 0;
}























// main function..
int main(){


    Main();
    
    
}


Measured memory_bytes: 81400
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define rep(i,strt,end) for(long long i = strt;i < end;i++)

long long powFive(long long trg){
    long long space = 1;
    rep(i,0,5){
        space *= trg;
    }
    return space;
}

int main(){
    long long x;
    cin >> x;
    rep(a,-130,130){
        rep(b,-130,130){
            if(powFive(a) - powFive(b) == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    //--------------
    return 0;
}

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

using namespace std;

int main() {
  long long a, b;
  cin >> a >> b;
  
  long long res = 0;
  if (b - a < 100) {
    for (long long i = a; i <= b; i++) {
      res ^= i;
    }
  } else {
    while (a % 4 != 0) {
      res ^= a;
      a++;
    }
    while (b % 4 != 3) {
      res ^= b;
      b--;
    }
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll k,n; cin>>k>>n;
    vector<ll> a(n),b(n);
    rep(i,n) cin>>a[i];
    rep(i,n-1) b[i]=a[i+1]-a[i];
    b[n-1] = (k-a[n-1])+(a[0]);

    sort(b.begin(), b.end());
    b.pop_back();
    cout << accumulate(b.begin(), b.end(), 0) << '\n';
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
 
int main(){
 int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(a > 0 && c > 0) {
    c -= b;
    if (c <= 0) {
      cout << "Yes" << endl;
      break;
    }
    a -= d;
    if (a <= 0){
      cout << "No" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
const int N=5010;
typedef long long ll;
ll dp[N][N];
int f[N][N],n,A,B,a[N],b[N];
int main(){
	cin>>n>>A>>B;
	for(int i=1;i<=n;++i)cin>>a[i],b[a[i]]=i;
	for(int i=n;i;--i)
		for(int j=1;j<=n;++j)f[i][j]=f[i+1][j]+(a[i]>j);
	memset(dp,0x3f,sizeof dp);memset(dp[n+1],0,sizeof dp[n+1]);
	for(int i=n;i;--i){
		dp[i][n+1]=0;
		for(int j=n;j;--j)
			if(a[i]<j)dp[i][j]=dp[i+1][j];
			else if(b[j]<i)dp[i][j]=dp[i][j+1];
			else{
				int u=b[j];
				if(u==i)dp[i][j]=dp[i+1][j+1];
				else dp[i][j]=min(dp[i][j+1]+B,dp[u+1][j+1]+(ll)A*(f[i][j]-f[u][j]));
			}
	}
	cout<<dp[1][1]<<endl;
	return 0;
}



Measured memory_bytes: 294400
N=int(input())
S=list(input())
counts = 0
tot = 0
r = [0]*N
b = [0]*N
g = [0]*N
R=0
B=0
G=0
"""
if S[0] == "R":
    r[0] +=1
if S[0] == "G":
    g[0] +=1
if S[0] == "B":
    b[0] +=1

"""
for i in range(N):
    if S[i] == "R":
        R+=1

    if S[i] == "B":
        B+=1
        
    if S[i] == "G":
        G+=1



        

for i in range(N):
    for j in range(1,(N-i-1)//2+1):
        if S[i] != S[i+j] and S[i+j] != S[i+2*j] and S[i] != S[i+2*j]:
            counts +=1


print(R*B*G-counts)

Measured memory_bytes: 68308
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int h,w;
  std::cin >> h >> w;
  vt<vt<char>> a(h+2,vt<char>(w+2));

  rep(i,h+2){
    rep(j,w+2){
      if(i == 0 || i == h+1 || j == 0 || j == w+1)
        std::cout << '#';
      else  {
        std::cin >> a[i][j];
        std::cout << a[i][j];
      }
    }
    std::cout << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
ss = []
n.times do
  ss << gets.chomp.chars.join
end
ans = []
('a'..'z').to_a.each do |s|
  cnt = 10 ** 20
  for i in 0..n-1 do
    cnt = [cnt, ss[i].count(s)].min
  end
  ans << s * cnt if cnt > 0
end
puts ans.join


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

int main() {
    int A, B, C, D;

    cin >> A >> B >> C >> D;
    if (A + B > C + D)
        cout << "Left" << endl;
    else if (A + B == C + D)
        cout << "Balanced" << endl;
    else
        cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a,b;
    int d,r;
    double f;
    
    scanf("%d %d",&a,&b);
    
    d = a/b;
    r = a%b;
    f = (double)a/b;
    
    printf("%d %d %.5f\n",d,r,f);
    
    return 0;
}


Measured memory_bytes: 2056
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    int d = b / a;
    if (d > c) {
      cout << c << '\n';
    } else {
      cout << d << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
//69行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size()) 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

//Simple Array Input
#define SAI int n;cin >> n;vi a(n);ain(a)
//Simple Graph Input
#define SGI(m) for(int i=0;i<m;i++){int a,b;cin >> a >> b;g[--a].pb(--b);g[b].pb(a);}
//Simple Tree Input
#define STI SGI(n-1)

typedef long long ll;
typedef long long integer;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){
    for(int i=0;i<a.size();i++)cout << a[i] << (i < a.size()-1 ? ' ' : '\n');
}
///////////////////////////////////////////////////////////

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
   	
    double r;cin >> r;
    cout << 3.1415 * 2.0 * r << '\n';

    return 0;
}
/*
 *!!CHECK!! 
 * 制約をよく読め：まず最も愚直な解法を考えろ
 * intの掛け算をしてる場合：overflowは大丈夫？
 * 制約の下限・上限は大丈夫？
 * 木構造は一直線にした時TLEしない？
 * */

/*
* DEBUG before you submit!
* 入力はされてる？
* vectorはサイズを初期化している？
* まずは変数が適切かをチェックする
* 特に二重ループ内部の変数が適切か？
* while文はカウンタがインクリメントされてるかチェック！
*/


Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int n, m; cin >> n >> m;
	cout << (n - 1) * (m - 1) << "\n";

	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

struct UFTree(T)
{
    struct Node
    {
        T parent;
        T rank = 1;
    }

    ///
    this(T n)
    {
        nodes.length = n;
        sizes.length = n;
        foreach (i, ref node; nodes) {
            node = Node(i.to!T);
            sizes[i] = 1;
        }
    }

    ///
    bool unite(T a, T b)
    {
        a = root(a);
        b = root(b);

        if (a == b) return false;

        if (nodes[a].rank < nodes[b].rank) {
            sizes[nodes[a].parent] += sizes[nodes[b].parent];
            nodes[b].parent = nodes[a].parent;
        } else {
            sizes[nodes[b].parent] += sizes[nodes[a].parent];
            nodes[a].parent = nodes[b].parent;
            if (nodes[a].rank == nodes[b].rank) nodes[a].rank += 1;
        }

        return true;
    }

    ///
    bool is_same(T a, T b)
    {
        return root(a) == root(b);
    }

    ///
    T size(T i)
    {
        return sizes[root(i)];
    }

private:
    Node[] nodes;
    T[] sizes;

    T root(T i)
    {
        if (nodes[i].parent == i) return i;

        return nodes[i].parent = root(nodes[i].parent);
    }
}

///
UFTree!T uftree(T)(T n)
{
    return UFTree!T(n);
}

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    auto uft = uftree(N+M);

    foreach (int n; 0..N) {
        foreach (l; readln.split.to!(int[])[1..$]) {
            uft.unite(n, N+l-1);
        }
    }

    foreach (int i; 0..N-1) {
        if (!uft.is_same(i, i+1)) {
            writeln("NO");
            return;
        }
    }
    writeln("YES");
}

Measured memory_bytes: 7428
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N;
    cin >> N;
    string C;
    cin >> C;
    ll ans = INF;
    ll sum_r[200010] = {}, sum_w[200010] = {};
    rep(i,0,N){
        if(C[i] == 'R'){
            sum_r[i+1]++;
        }else{
            sum_w[i+1]++;
        }
    }
    rep(i,0,N+1){
        sum_r[i+1] += sum_r[i];
        sum_w[i+1] += sum_w[i];
    }

    rep(i,0,N+1){
        ll vr = sum_w[i];
        ll vw = sum_r[N] - sum_r[i];
        ll v = min(vr, vw);
        ll res = v + vr - v + vw - v;
        ans = min(ans, res);


    }
    print(ans);

    

}

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

Measured memory_bytes: 6888
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n){
    while(a[i] % 2 == 0){
      a[i] /= 2;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct UnionFind {
  vector<ll> par, siz;

  UnionFind(ll n):par(n),siz(n,1) {
    for (ll i = 0; i < n; ++i) par[i] = i; //すべて根として初期化
  }

  ll root(ll x) {
    if (par[x] == x) return x;
    else return par[x] = root(par[x]);
  }

  void merge(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    if (rx == ry) return;
    if (siz[rx] < siz[y]) swap(rx, ry);
    par[rx] = ry;
    siz[ry] += siz[rx];
  }

  bool same(ll x, ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return siz[root(x)];
  }
};

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n, m;
  cin >> n >> m;
  vector<P> v(m);
  rep(i,m) {
    cin >> v[i].first >> v[i].second;
    v[i].first--; v[i].second--;
  }
  reverse(all(v));
  UnionFind uf(n);
  vector<ll> ans(m);
  ll cur = n*(n-1)/2;
  for (int i = 0; i < m; ++i) {
    ans[i] = cur;
    ll a = v[i].first, b = v[i].second;
    if (uf.same(a, b)) continue; //既に連結
    ll sa = uf.size(a), sb = uf.size(b);
    cur -= sa*sb;
    debug(a, b, cur);
    uf.merge(a, b);
  }
  reverse(all(ans));
  rep(i,m) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 5248
#include <iostream>

using namespace std;

int main()
{
    int n,a[105],ans=0,min1=999,max1=0,min2=9999999999;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        min1=min(min1,a[i]);
        max1=max(max1,a[i]);
    }
    for(int i=min1; i<=max1; i++)
    {
        ans=0;
        for(int j=0; j<n; j++)
        {
            ans+=(a[j]-i)*(a[j]-i);
        }
        min2=min(min2,ans);
    }
     cout<<min2;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

LL solve(LL x) {
  LL answer = 0ll;
  if (x%4==1 || x%4==2) answer = 1ll;
  FOR(i,1,50) {
    LL k = 1ll << i;
    LL l = x%(k*2);
    if(l<k) continue;
    answer += (1 - l%2) * k;
  }
  return answer;
}

int main(void)
{
  LL a,b;
  cin >> a >> b;
  cout << (solve(a-1) ^ solve(b)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int x, y;
  cin >> x >> y;

  int ans = 2100000000;
  if (x <= y) ans = min(ans, y - x);
  if (x <= -y) ans = min(ans, (-y - x) + 1);
  if (-x <= y) ans = min(ans, 1 + (y + x));
  if (-x <= -y) ans = min(ans, 1 + (-y + x) + 1);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int x,t;
	cin >> x >> t;
	cout << max(x - t, 0) << endl;
}

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

using namespace std;

int main(){
	
	int n;
	
	while(1){
		cin >> n;
		if(n==0) break;
		int s[n];
		
		for(int i=0;i<n;i++)
			cin >> s[i];
		
		sort(s,s+n);
		
		int sum=0;
		
		for(int i=1;i<n-1;i++){
			sum += s[i];
		}
		
		cout << sum/(n-2) << endl;
	}
	
	return 0;
}
	


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

int main() {
	long long		h,a,b,c,i,j,k,n,m,x,y,ans = 0;
	string	str;
	
	cin >> h;
	
	if (h==1) {
		cout << 1 << endl;
		return 0;
	}
	c = 1;
	while(1) {
		ans += c;
		c = c*2;
		h = h/2;
		if (h==1) {
			ans += c;
			break;
		}
		
	}
	cout << ans << endl;


}


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

int main(){
  long long N;
  cin >> N;
  vector<long long> A(N), B(N);
  long long Asum=0, Bsum=0;
  for (int i=0; i<N; i++){
    cin >> A[i];
    Asum += A[i];
  }
  for (int i=0; i<N; i++){
    cin >> B[i];
    Bsum += B[i];
  }
  if (Asum < Bsum) {
    cout << -1 << endl;
    return 0;
  }
  vector<long long> dif(N);
  for (int i=0; i<N; i++){
    dif[i] = A[i] - B[i];
  }
  sort(dif.begin(), dif.end());
  long long dep=0, ans=0;
  for (int i=0; i<N; i++){
    if (dif[i]>=0) break;
    dep += dif[i];
    ans++;
  }
  for (int i=N-1; i>=0; i--){
    if (dep >= 0) break;
    dep += dif[i];
    ans++;
  }
  cout << ans << endl;
}


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

int main()
{
    char a[4],b[4],ab[7];
    int i,h=0;

    scanf("%s %s",a,b);

    sprintf(ab,"%s%s",a,b);

    for(i=0;i<317;i++){
        if(atoi(ab)==i*i) h = 1;
    }

    if(h == 1) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 128
H,N = map(int,input().split())
T = []
for i in range(N):
    a,b = map(int,input().split())
    T.append([a,b])

M = max(T)[0]
dp = [10**9]*(H+M+1)
dp[0] = 0
for i in range(1,H+M+1):
    for j in range(N):
        if i - T[j][0] >= 0:
            dp[i] = min(dp[i],dp[i-T[j][0]]+T[j][1])

print(min(dp[H:H+M+1]))

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

int main(){
	int L,A,B,C,D,x,y;
	cin >>L >>A >>B >>C >>D;
	if(A%C==0)
		x=A/C;
		else
			x=A/C+1;
	if(B%D==0)
		y=B/D;
		else
			y=B/D+1;
	if(x<y)
		x=y;
		
	cout << L-x <<endl;

	return 0;
}

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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

int dp[1000005];

const long long MOD = 1e9+7;

int main(){
    int N, H, D;
    scanf("%d%d%d", &N, &H, &D);

    long long retainWays = 0;
    long long fact = 1;
    for(int i = 1; i <= N; i ++){
        fact = fact*i%MOD;
        retainWays += fact;
    }
    retainWays %= MOD;

    //printf("retainWays=%lld\n", retainWays);

    dp[0] = fact;
    long long slidingWindowSum = dp[0];
    for(int i = 1; i < H; i ++){
        dp[i] = slidingWindowSum*retainWays%MOD;

        slidingWindowSum += dp[i];
        if(i >= D){slidingWindowSum -= dp[i-D];}

        if(slidingWindowSum >= MOD){slidingWindowSum -= MOD;}
        else if(slidingWindowSum < 0){slidingWindowSum += MOD;}

        //printf("dp[%d]=%lld\n", i, dp[i]);
    }

    printf("%lld", slidingWindowSum);
    return 0;
}


Measured memory_bytes: 4096
#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>
signed main(){
  int A,B,K; cin>>A>>B>>K;
  int t=max(A-K,0LL);
  int X=K-(A-t);
  int a=max(0LL,B-X);
  cout<<t<<" "<<a<<endl;
  }



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int n, m;

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> n>> m;
        int d = 0;
        if (d >= m) {
                cout << "0";
                return 0;
        }
        for (int i = 0; i < n; i++) {
                int a; cin >> a;
                if (a + d > m) {
                        cout << i+1;
                        return 0;
                }
                d += a;
        }
        cout << n+1;
return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
    cin.sync_with_stdio(false);
    string s;
    cin >> s;
    int d[4] = {};
    rep(i, s.size()) {
        if (s[i] == 'N') d[0] = 1;
        else if (s[i] == 'W') d[1] = 1;
        else if (s[i] == 'S') d[2] = -1;
        else d[3] = -1;
    }

    if (d[0] + d[2] == 0 && d[1] + d[3] == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

vector<bool> checked(1000001,false);

long long int f(int counter,long long int a){
  if(checked[a]){
  return counter;
  }
  checked[a] = true;
  int ans = 0;
  if(a % 2 == 0){
    ans = f(counter + 1,a/2);
  }else{
    ans = f(counter + 1,3 * a + 1);
  }
  return ans;
}

int main(){
  int s = 0;
  cin >> s;
  long long int ans = f(1,s);
  
  cout << ans;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define dscan(a,b) scanf("%d %d",&a,&b);
#define scan(a) scanf("%d",&a);
#define pin(a) printf("%d\n",a)
#define pll(a) printf("%I64d\n",a);
#define inf 1000000009
#define infmx 1e18
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define all(x) x.begin(),x.end()
typedef pair<int,int>pi;
typedef pair<long long,long long>pll;
typedef vector<int>vi;
const int N=2100000;
ll mod=1e9+7;
int power(int a,int p){int r=1,y=a;while(p){if(p&1)r=(1LL*r*y)%mod;p>>=1;y=(1LL*y*y)%mod;}return r;}
int ara[N];
int main()
{
    IOS;
    int pd=0,px=0,py=0;
    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
        int d,x,y;cin>>d>>x>>y;
        int dif=abs(x-px)+abs(y-py);
        if(dif>d-pd)return 0*puts("No");
        else if(dif%2!=(d-pd)%2)return 0*puts("No");
        px=x,py=y,pd=d;
    }
    puts("Yes");
}


Measured memory_bytes: 3652
H,W=map(int,input().split())
A=[]
for i in range(H):
  A.append(list(map(int,input().split())))
path=[]
for i in range(H):
  for j in range(W):
    if i%2==0:
      path.append([i,j])
    else:
      path.append([i,W-j-1])
count=0
opr=[]
for i in range(len(path)-1):
  if A[path[i][0]][path[i][1]]%2==0:
    pass
  else:
    A[path[i][0]][path[i][1]]-=1
    A[path[i+1][0]][path[i+1][1]]+=1
    count+=1
    opr.append([path[i][0]+1,path[i][1]+1,path[i+1][0]+1,path[i+1][1]+1])

print(count)
for i in opr:
  print(*i)

Measured memory_bytes: 59844
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
ll n,x,i,r=1,d=0,k=0;
cin>>n>>x;
ll arr[n+1];
for(i=1;i<=n;i++)
    cin>>arr[i];
    for(i=1;i<=n;i++)
    {
        d=d+arr[i];
        if(d<=x)
            r++;
    }
    cout<<r<<endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split( ))

a = []

for _ in range(H):
    A = list(map(int, input().split( )))
    a.append(A)

i = 0
j = 0
cnt = 0
ans = []
for h in range(H):
    for w in range(W):
        if a[h][w]%2 ==1:
            if w != W-1:
                cnt += 1
                ans.append([h+1,w+1,h+1,w+2])
                a[h][w] -= 1
                a[h][w+1] += 1
            else:
                if h != H-1:
                    cnt += 1
                    ans.append([h+1,w+1, h+2, w+1])
                    a[h][w] -= 1
                    a[h+1][w] += 1
print(cnt)
for i in range(len(ans)):
    print(*ans[i])
                    
            

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

int main(){

    ll N;
    cin >> N;

    map<ll, ll > mp;
    for(ll i = 0; i < N; i++){
        ll t = 0; cin >> t;
        mp[t]++;
    }

    ll n = 0;
    if(N % 2 == 0){
        n = 1;
    }

    ll ans = 1;
    //奇数のとき中央の人は固定，偶数のとき全員に2通りの並べ方がある
    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        ll k = iter->first;
        ll h = iter->second;

        if(k == n){
            if(k == 0 && h == 1){

            }else if(k > 0 && h == 2){
                ans *= 2;
                ans %= MOD;
            }else{
                cout << 0 << endl;
                return 0;            
            }

        }else{
            cout << 0 << endl;
            return 0;          
        }

        n += 2;
    }

    cout << ans << endl;

}

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

int main() {

    while(true){
    
        // 1. input end check.
        int H, W;
        cin >> H >> W;
        
        if(H == 0 && W == 0) break;
        
        // 2. output answer.
        for(int i = 0; i < H; i++){
            string s;
            for(int j = 0; j < W; j++){
                if(i == 0 || i == H - 1) s += '#';
                if(i > 0 && i < H - 1 && j == 0)     s += '#';
                if(i > 0 && i < H - 1 && j == W - 1) s += '#';
                if(i > 0 && i < H - 1 && j > 0 && j < W - 1) s += '.';
            }
            cout << s << endl;
        }
        cout<< endl;
    
    }
    
    return 0;
    
}


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

int main()
{
    char a, b, c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a);s.insert(b);s.insert(c);
    if(s.count('a') && s.count('b') && s.count('c')){
        cout << "Yes" << endl;
    }else cout << "No" << endl;
}

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

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n,k;cin>>n>>k;

  int u = n*(n-1)/2-(n-1);
  if (k<=u){
    vector<pii> ans;
    rep(i, 1, n){
      ans.pb(mp(0, i));
    }
    int d = u - k;
    dump(d);
    rep(i,1,n)rep(j,i+1,n){
      if (d>0){
        ans.pb(mp(i,j));
        d--;
      }
    }

    cout << sz(ans) << endl;
    each(el, ans){
      cout << el.first+1 << " " << el.second+1 << endl;
    }
  }
  else{
    cout << -1 << endl;
  }
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int map[4][4];
int s(bool f,int n){
	if(f)//行n和 
	return map[n][1]+map[n][2]+map[n][3];
	else//列n和 
	return map[1][n]+map[2][n]+map[3][n];
}
void check(){
	int sum;
	for(sum=-1000;sum<=1000;sum++){
		map[1][3]=sum-map[1][1]-map[1][2];
		map[3][3]=sum-map[1][1]-map[2][2];
		map[3][2]=sum-map[1][2]-map[2][2];	
		map[2][3]=sum-map[1][3]-map[3][3];
		map[2][1]=sum-map[2][2]-map[2][3];
		map[3][1]=sum-map[1][1]-map[2][1];	
		if(((map[1][1]+map[3][3]==map[1][3]+map[3][1])&&(s(1,1)==s(1,2))&&(s(1,1)==s(1,3))&&(s(0,1)==s(1,1))&&(s(0,1)==s(0,2))&&(s(0,1)==s(0,3))))
		break;
	}
	return;
}
void print(){
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			cout<<map[i][j]<<" ";
		}
		cout<<"\n";
	}
}
int main(){
	cin>>map[1][1]>>map[1][2]>>map[2][2];
	check();
	//cout<<s(1,1)<<" "<<s(1,2)<<"\n";
	print();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//stayCalmNeverSettle
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
#define ll long long
#define x first
#define y second
#define pb push_back
#define pii pair<ll,ll>
#define vi vector<ll>
#define MOD 1000000007
#define INF 1000000000
using namespace std;

const int N = 1e5+5;
ll abc[N][3];
ll dp[N][3];

void solve(){
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)	
		cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
	dp[1][0] = abc[1][0];
	dp[1][1] = abc[1][1];
	dp[1][2] = abc[1][2];
	for(int i=2;i<=n;i++){
		dp[i][0] = abc[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = abc[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = abc[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	ll ans = dp[n][0];
	for(int i=0;i<3;i++){
		ans = max(ans,dp[n][i]);
	}
	cout << ans << endl;
}   
    
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 8188
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>

#define rep(i,m,n) for(int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<long long int> v;
vector<long long int> w;

int main() {
	int s, w;
	cin >> s >> w;
	if (w >= s)cout << "unsafe" << '\n';
	else cout << "safe" << '\n';
	return 0;
}

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

#define MOD 1000000007
#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()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec L(N+1, 0);
  L[0]=2;
  L[1]=1;
  for(ll i=2;i<=N;i++){
    L[i]=L[i-1]+L[i-2];
  }
  cout << L[N];
  return 0;
}


Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;

int main() {
    string X, Y;
    cin >> X >> Y;
    int M = X.size(), N = Y.size();
    vector<vector<int>> dp(M + 1, vector<int>(N + 1));
    for (int i = 0; i <= M; i++) dp.at(i).at(0) = i;
    for (int i = 0; i <= N; i++) dp.at(0).at(i) = i;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            int d = dp.at(i).at(j);
            if (X.at(i) != Y.at(j)) d++;
            d = min(d, dp.at(i).at(j + 1) + 1);
            d = min(d, dp.at(i + 1).at(j) + 1);
            dp.at(i + 1).at(j + 1) = d;
        }
    }
    cout << dp.at(M).at(N) << endl;
}


Measured memory_bytes: 6860
#include <stdio.h>

int main(void)

{

    long n, k;

    long m;

    scanf("%ld %ld",&n, &k);

    n = n % k;

    if (n < 0)

        n *= -1;

    m = n;

    if (n < k - n)

        printf("%ld", n);

    else

        printf("%ld", k - n);

    return (0);

}

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

using namespace std;

int main()
{
	int n;
	string str;

	while(cin >> n >> str && n)
	{
		string ss;
		while(n--)
		{
			int count=1;

			for(int i=0;i<str.length();i++)
			{
				string plus;

				if(str[i]==str[i+1])count++;
				else 
				{
					while(1)
					{
						string set;
						set=count%10+'0';
						plus.insert(0,set);
						//plus+=count%10+'0';
						count/=10;
						if(count==0)break;
					}
					ss+=(plus+str[i]);
					count=1;
				}
			}
			str=ss;
			ss.erase(ss.begin(),ss.end());
		}

		cout << str << endl;
	}
	

	return 0;
}

Measured memory_bytes: 1324
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		HS hs = new HS();

		for(int i = 0; i < k; i++){
			int r = scan.nextInt();
			int c = scan.nextInt();
			hs.add(i, r, c);
		}
		hs.solve();

		for(int r = 0; r < 8; r++){
			for(int c = 0; c < 8; c++)
				if(hs.isQuenn(r, c))
					System.out.print("Q");
				else
					System.out.print(".");
			System.out.println();
		}

		scan.close();
		System.exit(0);
	}
}

class HS{
	int[] row;
	int[] col;

	public HS(){
		row = new int[8];
		col = new int[8];
		for(int i = 0; i < 8; i++){
			row[i] = -1;
			col[i] = -1;
		}
	}

	public void add(int i, int r, int c){
		row[i] = r;
		col[i] = c;
	}

	public void solve(){
		int k = 0; // ??????????¨????
		for(; k < row.length; k++) // ??????????¨??????????????????????
			if(row[k] == -1) // k?????????????±??????????
				break;
		sol(k); // k??????????????????????????????????????????????§£???
	}
	private boolean sol(int k){
		if(k == 8) // ???????????????0??????7????????§????????????
			return true; // ????????????
		for(int r = 0; r < 8; r++)
			for(int c = 0; c < 8; c++)
				if(isAbl(r, c)){
					row[k] = r;
					col[k] = c;
					if(sol(k+1)) // ?¬??????????????????????????????????
						return true; // ????????????
					else{ // ??????????????£??????k???????????????????¶????
						row[k] = -1;
						col[k] = -1;
					}
				}
		return false;
	}
	private boolean isAbl(int r, int c){
		for(int k = 0; k < 8; k++){
			if(row[k] == -1) // row[k]???????¨??????????break??????return true??????
				break;
			if(row[k] == r || col[k] == c || row[k] + col[k] == r + c || row[k] - col[k] == r - c){
				// ??????????????????false?¨???????????????????????????????false????????????????????¨????????????????????????false??????????????????????????¨????????????????????????false??????????????????
				return false;
			}
		}
		return true;
	}

	public boolean isQuenn(int r, int c){
		for(int k = 0; k < 8; k++)
			if(row[k] == r && col[k] == c) // k??¨?????¨??????????????????
				return true; // ????????????
		return false; // ????????????
	}
}

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

using namespace std;
#define ll long long

int main (void) {
    string s;
    cin >> s;
    string ret;
    ret = "No";
    for(int i=0;i<s.size()-1;i++){
        if(s[i] != s[i+1]){
            ret = "Yes";
            break;
        }
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
#include<vector>
#include<math.h>
long long int mod = 1000000007;
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);


using namespace std;
int main() {

	//B
	int l[100];
	int i, n, j, k;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> l[i];
	}
	int counter = 0;
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			for (k = j + 1; k < n; k++) {
				if ((l[i] != l[j]) && (l[j] != l[k]) && (l[k] != l[i])) {
					if ((l[i] + l[j] > l[k]) && (l[j] + l[k] > l[i]) && (l[k] + l[i] > l[j])) {
						counter++;
					}
				}
			}
		}
	}
	cout << counter << endl;
	return 0;

	//C
	/*long long int x, k, d;
	cin >> x >> k >> d;
	if (x < 0)x = -x;
	if (x >= 0) {
		if (sqrt(x) > sqrt(k) * sqrt(d)) {
			cout << x - k * d << endl;
			return 0;
		}
		if ((k - (x / d)) % 2 == 0) {
			cout << x % d << endl;
			return 0;
		}
		else {
			cout << d - (x % d) << endl;
			return 0;
		}
	}*/
	

	//D
	/*
	int n, k;
	cin >> n >> k;
	int p[5000],c[5000];
	int i;
	for (i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	for (i = 0; i < n; i++) {
		cin >> c[i];
	}
	int loopnum = 0, j;
	int l[5000];
	int lpl[5000];
	for (i = 0; i < n; i++) {
		l[i] = -1;
		lpl[i] = 0;
	}
	int loopl;
	for (i = 0; i < n; i++) {
		if (l[i] == -1) {
			j = i;
			loopl = 0;
			while (l[j] == -1) {
				l[j] = loopnum;
				j = p[j];
				loopl++;
			}
			lpl[loopnum] = loopl;
			loopnum++;
		}
	}

	for (i = 0; i < loopnum; i++) {

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

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}


Measured memory_bytes: 3592
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(M)]
AB.reverse()    # 逆から考える

ans_list = [-1 for i in range(M)]
ans_list[M-1] = N*(N-1)//2

par = [i for i in range(N+1)]
rank = [0 for i in range(N+1)]
cnt = [1 for i in range(N+1)]

# 木の根を求める
def root(x):
    if par[x] == x:             # 根の時
        return x
    else:
        par[x] = root(par[x])   # 経路圧縮
        return par[x]

# xとyの属する集合を併合(ランク有)
def unite(x,y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
        cnt[y] += cnt[x]
    else:
        par[y] = x
        cnt[x] += cnt[y]
        if rank[x] == rank[y]:
            rank[x] += 1

for i in range(M-1):
    a,b = AB[i][0],AB[i][1]
    # 答えはans_list[M-2-i]を書き換える
    if root(a) == root(b):
        ans_list[M-2-i] = ans_list[M-1-i]
        continue
    else:
        ans_list[M-2-i] = ans_list[M-1-i] - cnt[root(a)]*cnt[root(b)]
        unite(a,b)
print('\n'.join(map(str,ans_list)))



Measured memory_bytes: 42016
#E
import numpy as np
n, m = list(map(int, input().split()))
lists = list(np.arange(1, n+1))
list1 = lists[:m]
list2 = lists[m:]
num = m
for i in range(m//2 +1):
    if num == 0:
        break
    print(list2[i],list2[m+1-i-1])
    num -= 1
    if num == 0:
        break
    print(list1[i],list1[m-i-1])
    num -= 1

Measured memory_bytes: 34968
///*.......................Shadman Sakib Utshob............................*///

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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

#define Boost           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define pb              push_back
#define inf             1e9+8
#define mp              make_pair
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define ll              long long
#define pii             pair<ll,ll >
#define MOD             1000000007
#define fileout         freopen("output.txt","w",stdout)
#define mem(x,i)        memset(x,i,sizeof x)
#define Ones(x)         __builtin_popcount(x);
#define PI              acos(-1.0)
#define ff              first
#define ss              second
#define T               int t;cin>>t;while(t--)
#define ok              cout<<"ok"<<endl;
#define all(x)          (x).begin(),(x).end()
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define nln	            cout<<endl;

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


}


Measured memory_bytes: 3636
import sys

n = input()

for t in range(n):
    ls = raw_input()
    ls = [map(int, list(raw_input())) for x in range(8)]

    sx, sy = input(), input()

    dx = [1,0,-1,0] + [2,0,-2,0] + [3,0,-3,0]
    dy = [0,1,0,-1] + [0,2,0,-2] + [0,3,0,-3]

    def isin(x, y): return 0 <= x < 8 and 0 <= y < 8
    def dfs(x, y):
        ls[y][x] = 0
        for d in range(len(dx)):
            xx, yy = x + dx[d], y + dy[d]
            if isin(xx, yy) and ls[yy][xx] == 1:
                dfs(xx, yy)

    dfs(sx-1, sy-1)

    print "Data {}:".format(t+1)
    for raw in ls:
        for col in raw:
            sys.stdout.write(str(col))
        sys.stdout.write('\n')

Measured memory_bytes: 4308