akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
A = list(map(int, input().split()))
cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
can_cost = sorted([cost[a] for a in A])
D = {}
for a in A:
    c = cost[a]
    D[c] = max(a, D.setdefault(c, -1))

min_cost = can_cost[0]
min_cost_num = D[min_cost]


def f2(v, l, num):
    L = list(str(v))
    min_cost = cost[int(num)]
    num = D.setdefault(min_cost + l, -1)
    if num == -1:
        return -1

    min_cost_num = D[min_cost]
    L[L.index(str(min_cost_num))] = str(num)
    L.sort(reverse=True)
    return int("".join(L))


def f(v, l):
    L = list(str(v))
    set_L = set(L)
    L2 = [f2(v, l, num) for num in set_L]
    return max(L2)

def g(K, r):
    temp = int("".join([str(min_cost_num)] * K))
    dp = [[-1 for _ in range(min(r, K) + 1)] for __ in range(r + 1)]
    dp[0][0] = temp

    for k in range(min(r, K)):
        for n in range(r):
            v = dp[n][k]
            if v == -1:
                continue
            for l in range(1, r - n + 1):
                dp[n + l][k + 1] = max(dp[n + l][k + 1], f(v, l))
    return max(dp[r])

K = N // min_cost
r = N - K * min_cost
res = g(K, r)
while res == -1:
    K -= 1
    r += min_cost
    res = g(K, r)
print(res)

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 100005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(int N, int pos){return (bool)(N & (1<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

ll nCr(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for(ll i = 0; i <= n; i++)
        for(ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1]);
    return C[k];
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    ll n, m;
    cin>>n>>m;
    cout<<nCr(n, 2)+nCr(m, 2)<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 256
from collections import deque

n,m,k = map(int,input().split())

cango = [[]for i in range(n)]
cannotgo=[[]for i in range(n)]
for i in range(m):
    a,b = (map(int,input().split()))
    a,b = a-1,b-1
    cango[a].append(b)
    cango[b].append(a)

for i in range(k):
    c,d =(map(int,input().split()))
    c,d = c-1,d-1
    cannotgo[c].append(d)
    cannotgo[d].append(c)
# print(a)
# cango = [[]for i in range(n)]
# for i in a:
#     cango[i[0]-1].append(i[1]-1)
#     cango[i[1]-1].append(i[0]-1)
# print(cango)

# cannotgo=[[]for i in range(n)]
# for i in c:
#     cannotgo[i[0]-1].append(i[1]-1)
#     cannotgo[i[1]-1].append(i[0]-1)
# # print(cannotgo)
alre = [False]*n
parent = [-1]*n
gro = {}
y = deque()
# print(gro)
for i in range(n):
    # if alre[i]==True:
    #     continue
    # gro[i]=set([i])
    y.append(i)
    leader = i
    cnt = 0 
    while len(y)>0:
        x = y.popleft()
        if parent[x]!=-1:
            continue
            # print(to)
        parent[x]=leader
        y.extend(cango[x])
        cnt +=1
    if cnt!=0:
        gro[leader]=cnt
# print(gro)
# print(parent)
ans = [0]*n
# print(ans)
for iam in range(n):
    # group = gro[parent[iam]]
    tmp_ans = gro[parent[iam]]
    tmp_ans -=1
    tmp_ans -= len(cango[iam])
    for block in cannotgo[iam]:
        if parent[block]==parent[iam] :
            tmp_ans -=1
    ans[iam]=tmp_ans
print(*ans, sep=' ')

Measured memory_bytes: 48460
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
template<class S>void tf(bool b,S t,S f){cout<<(b?t:f)<<endl;}
void OUT(bool b){tf(b,"YES","NO");}
void Out(bool b){tf(b,"Yes","No");}
void out(bool b){tf(b,"yes","no");}
template<class T>void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int ans=0,b=0,t;
	rep(i,n){
		cin>>t;
		if(t>b)ans+=t-b;
		b=t;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
const ld eps = 1e-9;
struct point {ld x, y; };
struct line {point a, b; };
void ReadPointInt(point &a) {read(a.x), read(a.y); }
void ReadLineInt(line &a) {ReadPointInt(a.a), ReadPointInt(a.b); }
point operator + (point a, point b) {return (point) {a.x + b.x, a.y + b.y}; }
point operator - (point a, point b) {return (point) {a.x - b.x, a.y - b.y}; }
point operator * (point a, ld b) {return (point) {a.x * b, a.y * b}; }
ld dot(point a, point b) {return a.x * b.x + a.y * b.y; }
ld operator * (point a, point b) {return a.x * b.y - a.y * b.x; }
ld moo(point a) {return sqrtl(a.x * a.x + a.y * a.y); }
ld dist(point a, point b) {return moo(a - b); }
point unit(point a) {
	ld tmp = moo(a);
	assert(tmp > eps);
	return a * (1.0 / tmp);
}
point Projection(point x, line a) {
	ld d = dot(x - a.a, a.b - a.a) / dist(a.a, a.b);
	return a.a + unit(a.b - a.a) * d;
}
int main() {
	line a; ReadLineInt(a);
	int q; read(q);
	while (q--) {
		point x; ReadPointInt(x);
		x = Projection(x, a);
		printf("%.10Lf %.10Lf\n", x.x, x.y);
	}
	return 0;
}


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

int main() {
    int W, a, b;
    cin >> W >> a >> b;
    
    if(b+W < a) {
        cout << a - (b+W);
    }
    else if(a+W < b) {
        cout << b - (a+W);
    }
    else {
        cout << 0;
    }

    cout << endl;
    return 0;
}

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

int compare(const void *a, const void *b){
	long long *A = (long long *)a;
	long long *B = (long long *)b;
	if (*A > *B) return 1;
	if (*A < *B) return -1;
	return 0;
}

int main(){
	long long N,x,i,ans=0;
	scanf("%lld%lld",&N,&x);
	long long a[N];
	for(i=0;i<N;i++)scanf("%lld",&a[i]);
	
	qsort(a,N,sizeof(long long),compare);
	for(i=0;i<N && x>=a[i];i++){
		x-=a[i];
		ans++;
	}
	
	if(x>0 && ans==N)ans--;
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
p [nil,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][gets.to_i]

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    string S;
    cin >> S;

    deque<char> Q;
    REP(i,0,SZ(S)) {
        if(S[i] == 'B') {
            if(!Q.empty()) Q.pop_back();
        } 
        else Q.push_back(S[i]);
    }
    while(!Q.empty()) {
        cout << Q.front();
        Q.pop_front();
    }
    cout << endl;

    return 0;
}

/*



*/

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

int main() {
    ll a;
    double b;
    cin >> a >> b;
    int c = b * 100 + 0.01;
    ll ans = a * c / 100;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <cstdio>
#include <algorithm>
 
using namespace std;
 
int rd() {
	int x = 0; char c = getchar();
	while (c > '9' || c < '0') c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
	return x;	
}
 
 
const int N = 2e5 + 5; 
long long n, m, sum, ans = 1e18, a[N], b[N], c[N];
 
int main() {
	n = rd(), m = rd();
	for (int i = 1; i <= n; i ++) a[i] = rd();
	for (int i = 2; i <= n; i ++) {
		int l = a[i - 1], r = a[i];
		if (l == r) continue;
		if (l < r) b[l + 1] ++, b[r + 1] --, c[r + 1] -= r - l;
		else b[l + 1] ++, b[r + m + 1] --, c[r + m + 1] -= r + m - l;
	}
	for (int i = 1; i <= 2 * m; i ++) b[i] += b[i - 1];
	for (int i = 1; i <= 2 * m; i ++) c[i] += c[i - 1] + b[i];
	for (int i = 1; i <= m; i ++) b[i] += b[i + m], c[i] += c[i + m], sum += b[i];
	for (int i = 1; i <= m; i ++) ans = min(ans, sum - c[i] + b[i]);
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
   cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
const int dh[4] = {0, 1, 0, -1};
const int dw[4] = {1, 0, -1, 0};

int main() {
    int N;
    cin >> N;
    vector<int> A(N), P(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        A[i] = i+1;
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    
    int a,b, cnt = 0;
    while (true) {
        if (A == P) a = cnt;
        if (A == B) b = cnt;
        cnt++;
        if (!next_permutation(A.begin(), A.end())) break;
    }
    cout << abs(a-b) << endl;
    return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

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

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 1e5+5;
string s;
ll n,result;

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  vector<ll> a(n),b(n),c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  VSORT(a);VSORT(b);VSORT(c);
  rep(i,n) {
    auto ite1 = lower_bound(ALL(a), b[i]);
    auto ite2 = upper_bound(ALL(c), b[i]);
    result += (ite1 - a.begin()) * (c.end() - ite2) ;
    // cout << ite1 - a.begin() << " : " << c.end() - ite2 << endl;
  }
  cout << result << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long

#define TASKNAME ""

using namespace std;

const int INF = 1e9 + 7;
const int MAXN = 1e5 + 7;
const double EPS = 1e-8;
const int LOGN = 30;

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
    #endif // MY
    int n;
    cin >> n;
    if (n % 10 == n / 100) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}


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

using namespace std;

const int mod = 1e9 + 7;


int N;
string A, B;
int dp[52][4][4];

int rec(int idx, int top, int bottom)
{
  if(idx == N) return (1);
  if(~dp[idx][top][bottom]) return (dp[idx][top][bottom]);
  int ret = 0;
  if(A[idx] == B[idx]) {
    for(int i = 1; i <= 3; i++) {
      if(top != i && bottom != i) {
        (ret += rec(idx + 1, i, i)) %= mod;
      }
    }
  } else {
    for(int i = 1; i <= 3; i++) {
      for(int j = 1; j <= 3; j++) {
        if(top != i && bottom != j && i != j) {
          (ret += rec(idx + 2, i, j)) %= mod;
        }
      }
    }
  }
  return (dp[idx][top][bottom] = ret);
}

int main()
{
  cin >> N;
  cin >> A;
  cin >> B;
  memset(dp, -1, sizeof(dp));
  cout << rec(0, 0, 0) << endl;
}



Measured memory_bytes: 256
import unittest
from io import StringIO

import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    L=[]
    while True:
        x=int(input())
        if x!=0:
            L.append(x)
        else: break
    M=max(L)


    # https://qiita.com/drken/items/dc53c683d6de8aeacf5a#dp-%E5%AE%9F%E8%A3%85%E3%81%AE%E9%A0%86%E5%BA%8F
    
    
    # dpテーブル dp[i]:= i段目まで登るための通り数
    dp = [0]*(M+1)
    """
    初期化の値は，
        最小化問題：INF, 
        最大化問題：-INF（0以上の値しか取らないなら-1, あるいは0でもいいかも)
        数え上げ問題：0
        確率問題：0
        Yes/No判定問題:False
    """
    
    # 初期条件
    dp[0] = 1
    
    # ループ
    for i in range(1,M+1):
    
        """
        dp[from] の値の更新が完了していればノード from からノード to への緩和を行っていい．貰うdpであれ配るdpであれ．
        両者の違いを意識すべきケースはcf. 
        https://qiita.com/drken/items/ace3142967c4f01d42e9#%E8%B2%B0%E3%81%86-dp-%E3%81%A8%E9%85%8D%E3%82%8B-dp-%E3%81%AE%E6%AF%94%E8%BC%83
        """
    
        dp[i]+=dp[i-1]
        if i>=2:
            dp[i]+=dp[i-2]
        if i>=3:
            dp[i]+=dp[i-3]
        
        
    
    # 出力
    
    for i in L:
        print(-(-dp[i] // 3650))
        
        
resolve()


Measured memory_bytes: 8404
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

int n;
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    int c = 0;
    REP(i, n) {
        if (v[i] != i + 1) c++;
    }
    // D(c);
    cout << (c <= 2 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 888
#include<cstdio>
using ll=long long;
constexpr ll p=1e9+7;
//dp[i][j]={s[0..i-1]とt[0..j-1]に含まれる空でない共通部分列の個数}
ll dp[2001][2001];
ll s[2000],t[2000];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)scanf("%lld",&s[i]);
    for(int j=0;j<m;j++)scanf("%lld",&t[j]);
    for(int i=0;i<=n;i++)dp[i][0]=0;
    for(int j=1;j<=m;j++)dp[0][j]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1])dp[i][j]=(1+dp[i][j-1]+dp[i-1][j])%p;
            else dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+p)%p;
        }
    }
    printf("%lld\n",(dp[n][m]+1)%p);
    return 0;
}

Measured memory_bytes: 31488
/****************************************

	LostMartian

****************************************/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;

template <typename Arg1>
void pn(Arg1&& arg1) {
	cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void pn(Arg1&& arg1, Args&&... args) { 
	cout << arg1 << " "; 
	pn(args...); 
}
template <typename Arg1>
void ps(Arg1&& arg1) { 
	cout << arg1 << " ";
}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args) { 
	cout << arg1 << " "; 
	ps(args...); 
}
template <typename Arg1>
void read(Arg1&& arg1) {
	cin >> arg1; 
}
template <typename Arg1, typename... Args>
void read(Arg1&& arg1, Args&&... args) { 
	cin >> arg1; 
	read(args...); 
}

#define rep(i,m,n) for(ll i=m; i<n; i++)
#define repr(i,m,n) for(ll i=m; i>=n; i--)
#define vll vector<ll >
#define vvl vector<vector<ll > >
#define pi pair<ll, ll >
#define vpi vector<pi >
#define pb push_back
#define mk make_pair
#define sz size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define ini(a, x) memset(a, x, sizeof(a))
#define d(x) cout<<"Value of "#x" = "<<x<<"\n";
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define LOCAL #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
	clock_t z = clock();
	FAST
	//LOCAL
	ll n, d;
	cin>>n>>d;
	ll x[n], y[n], ans=0;
	rep(i,0,n) {
		cin>>x[i]>>y[i];
		double xx=sqrt((x[i]*x[i])+(y[i]*y[i]));
		if(xx<=d) {
			ans++;
		}
	}
	cout<<ans;










	debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 6920
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
inline int read()
{
	register int x = 0 , f = 0; register char c = getchar();
	while(c < '0' || c > '9') f |= c == '-' , c = getchar();
	while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0' , c = getchar();
	return f ? -x : x;
}
int n , m , mod;
int dp[310][310][310];
int main()
{
	n = read(); m = read(); mod = read(); dp[0][1][0] = 1;
	for(int i = 0 ; i <= n ; ++i)
		for(int j = 1 ; j <= m ; ++j)
			for(int k = i ; k >= 0 ; --k) if(dp[i][j][k])
			{
				if(k) (dp[i][j][k-1] += dp[i][j][k]) %= mod;
				else (dp[i][j+1][i] += dp[i][j][k]) %= mod;
				(dp[i+1][j][k] += (LL)dp[i][j][k] * (k + 1) % mod) %= mod;
			}
	cout << dp[n][m][0] << '\n';
	return 0;
}

Measured memory_bytes: 114944
#include <stdio.h>

int main() {
  int number_n, i, count = 0, flag = 0;
  scanf("%d", &number_n);
  int number_array[number_n];
  for(i = 0; i < number_n; i++) {
    scanf("%d", &number_array[i]);
  }
  while(1) {
    for(i = 0; i < number_n; i++) {
      if(number_array[i] % 2 != 0) {
        flag = -1;
        break;
      } else {
        number_array[i] = number_array[i] / 2;
      }
    }
    if(flag == -1) break;
    count++;
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0,nn=(intl)(n);i<nn;++i)
#define Rep1(i,n) for(intl i=1,nn=(intl)(n)+1;i<nn;++i)
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);}
#define Input2(a,b) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);cin>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<intl>;
using vb = vec<bool>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
using si = set<intl>;
using vsi = vec<si>;
using mii = map<intl,intl>;
using vmii = vec<mii>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


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

intl modinv(intl a, intl p){
  if (a == 0){
    cout << "/0 at modinv"<<endl;
    exit(0);
  }
  if (a < 0){
    cout << "/- at modinv" <<endl;
    exit(0);
  }
  if (a==1){return 1;}
  if (a > p){return modinv(a%p, p);}

  return p - ( modinv(p%a,p) * (p/a) ) % p;
}

intl modcomb(intl n, intl k, intl p){
  if (k > n || k < 0 || n < 0){
    cout << "error at modcomb"<<endl;
    exit(0);
  }
  if (2*k > n){ k = n-k;}
  if (k ==0){return 1;}
  intl c=1;
  for (intl i = 0; i < k; i++){
    c =( c * ( (n-i) % p ) % p ) * modinv(i+1,p) % p;
  }
  return c;
}

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  constexpr intl mod = 1000000007;

  li n,a,b;
  cin >>n>>a>>b;

  li ans = modpow(2,n,mod) - modcomb(n,a,mod)-modcomb(n,b,mod)-1;
  ans%=mod;
  if(ans<0)ans+=mod;
  cout<<ans;
}


Measured memory_bytes: 3432
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private double calc(int n) { // 初期点数がnのとき、Kを超える確率を返す
		if (n >= K)
			return 1.0 / N;
		double x = Math.log((double) K / n) / Math.log(2);
		int p = (int) Math.ceil(x);
		return (1.0 / N) * Math.pow(1.0 / 2, p);
	}

	int N, K;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		N = sc.nextInt();
		K = sc.nextInt();

		double ans = 0;
		for (int i = N; i >= 1; i--) {
			ans += calc(i);
		}

		out.println(ans);

		sc.close();

	}

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

}


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

int main(){
  
  ll n;
  cin >> n;
  vector<vector<ll>> g(n+1);
  vector<pair<ll, ll>> rec;
  map<pair<ll, ll>, ll> color;
  ll cmax = 0;
 
  for(int j=1; j<=n-1; j++){
  	ll a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
    rec.push_back({a,b});
  }
  ll mx = 0;
  ll index;
  for(int i=1; i<=n; i++){
  	if(mx < g[i].size()){
      mx = g[i].size();
      index = i;
    }
  }
  vector<bool> seen(n+1, false);
  queue<ll> que;
  seen[index] = true;
  que.push(index);
  while(!que.empty()){
    ll i = que.front();
    que.pop();
    seen[i] = true;
    ll c = 1;
    ll ng = 0;		
    for(auto p : g[i]){
      if(seen[p]){
      	ll a = min(i, p);
        ll b = max(i, p);
        ng = color[{a,b}];
      }
    }
    for(auto p : g[i]){
      if(!seen[p]){
      	ll a = min(i, p);
        ll b = max(i, p);
        if(c == ng) c++;
        color[{a,b}] = c;
        c++;
        que.push(p);
      }
    }
  }
  cout << mx << endl;
  for(auto p : rec){
  	cout << color[p] << endl;
  }
}

Measured memory_bytes: 14320
a=input()
b=input()
c=input()
turn='a'
while(1):
    if turn=='a' and len(a)==0:
        print('A')
        exit()
    elif turn=='b' and len(b)==0:
        print('B')
        exit()
    elif turn=='c' and len(c)==0:
        print('C')
        exit()
    if turn=='a':
        turn=a[0]
        a=a[1:]
    elif turn=='b':
        turn=b[0]
        b=b[1:]
    elif turn=='c':
        turn=c[0]
        c=c[1:]

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int K, T;
    cin >> K >> T;
    vector<int> A(T);
    for (int i = 0; i < T; i++)
    {
        cin >> A[i];
    }
    int ans = *max_element(A.begin(), A.end()) * 2 - K - 1;
    if (ans < 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int memo[2][110], a[2][110], n;
int dp(int x, int y)
{
	if (x == 2) return 0;
	if (y == n) return 0;
	if (memo[x][y]) return memo[x][y];
	return max(dp(x+1, y), dp(x, y+1)) + a[x][y];
}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < n; j++) scanf("%d", &a[i][j]);
	}
	printf("%d\n", dp(0, 0));
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int a,b,d=0,r;
		double f;

	    Scanner sc = new Scanner(System.in);
	    a = sc.nextInt();
	    b = sc.nextInt();

	    r = a%b;
	    f = (double)a/(double)b;

	    while(a>=b) {
	    	a = a-b;
	    	d++;
	    }

	    System.out.println(String.format("%d %d %.6f",d,r,f));
	}


}



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

class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int num1=0,num2=0,num3=0;
        String s=br.readLine();
        int x = Integer.parseInt(s);
        if(x>=0 && x<86400){
            num1 = x / 3600; //??????????±???????
            num2 = (x % 3600) / 60; //???????±???????
            num3 = x % 60; //?§?????±???????
            System.out.println(num1+":"+num2+":"+num3);
        }
        
    }
}

Measured memory_bytes: 16872
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N, M;
	List<Integer> A;
	boolean result = false;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		this.N = Integer.parseInt(tokens[0]);
		this.M = Integer.parseInt(tokens[1]);
		tokens = in.readLine().split(" ");
		this.A = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			this.A.add(Integer.parseInt(tokens[i]));
		}
		Collections.sort(this.A);
		Collections.reverse(this.A);
	}

	void calc() {
		int sum = 0;
		for (int i = 0; i < N; ++i) {
			sum += A.get(i);
		}
		double threshold = sum / (4.0 * (double) M);
		int count = 0;

		for (int i = 0; i < N; ++i) {
			if (A.get(i) < threshold) {
				break;
			}
			++count;
		}
		if (count >= M) {
			result = true;
		}
	}

	void showResult() {
		System.out.println(result ? "Yes" : "No");
	}

}


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

int N;
vector<ll> v;

signed main()
{
	init();
	solve();
}

void init()
{
	cin >> N;
	CINV(v, N);
	sort(all(v));
}


void solve()
{
	int st = 0;
	ll total = v[0];
	ll res = N;
	ll mi = 1;
	while (st < N-1) {
		if (total * 2 < v[st+1]) {
			res -= mi;
			mi = 1;
		} else {
			mi++;
		}
		st++;
		total += v[st];
	}
	cout << res << endl;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int par[12345678];//親
int rnk[12345678];//木のランク
//n要素で初期化
void init(int n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i; rnk[i] = 0;
	}
}
//木の根を求める
int find(int x) {
	if (par[x] == x) { return x; }
	else { return par[x] = find(par[x]); }
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y) { return; }
	if (rnk[x] < rnk[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rnk[x] == rnk[y])rnk[x]++;
	}
}
//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}
int cost[12345678], kari[12345678];
signed main() {
	int n, m, a, s, t, x = 0, y = 0, ans = 0; cin >> n >> m;
	vector<vector<int>> v(123456); vector<int> S, cnt; init(n);
	for (int h = 0; h < n; h++) {
		cin >> a; cost[h] = a;
	}
	for (int h = 0; h < m; h++) {
		cin >> s >> t; unite(s, t);
	}
	for (int h = 0; h < n; h++) {
		int z = find(h); v[z].push_back(cost[h]);
		if (kari[z] == 0) { S.push_back(z); kari[z]++; }
	}
	for (int h = 0; h < S.size(); h++) {
		sort(v[S[h]].begin(), v[S[h]].end());
	}
	if ((S.size() - 1) * 2 > n) { cout << "Impossible" << endl; return 0; }
	if (S.size() == 1) { cout << 0 << endl; return 0; }
	for (int h = 0; h < S.size(); h++) {
		ans += v[S[h]][0]; cnt.push_back(v[S[h]][0]);
	}
	sort(cnt.begin(), cnt.end()); sort(cost, cost + n);
	for (int h = 0; h < (S.size() - 1) * 2 - S.size(); h++) {
		while (cost[x] == cnt[y]) {
			x++; y++;
		}
		ans += cost[x]; x++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13940
#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;
int n,i,j,mask,nr,b;
int a[25][25];
long long dp[3000005];
int main()
{
    cin>>n;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin>>a[i][j];

    dp[0]=1;
    for(mask=1;mask<(1<<n);mask++)
    {
        nr=__builtin_popcount(mask)-1;
        for(b=0;b<n;b++)
        {
            if(((mask>>b)&1) && a[nr][b])
            {
                dp[mask]+=dp[mask-(1<<b)];
                if(dp[mask]>mod)
                    dp[mask]-=mod;
            }

        }
    }

    cout<<dp[(1<<n)-1];
    return 0;
}


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

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

int k;
string s;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> k >> s;
    if(s.length() <= k) cout << s << '\n';
    else cout << s.substr(0, k) << "...\n";
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int a,b,c;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		int h, w;
		cin>>h>>w;
		if(h==0&&w==0) break;
		REP(i, h) {
			REP(j, w) {
				if(j == 0 || j == w - 1 || i == 0 || i == h - 1) cout<<'#';
				else cout<<'.';
			}
			cout<<endl;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 3068
#include<iostream>
#include<cstdio>
#include<map> 
#include<vector>
#include<cmath>
using namespace std;

int main()
{
	long long n,m;
	cin>>n>>m;
	if (n==1&&m==1) cout<<1<<endl;
	else if (n==1) cout<<m-2<<endl;
	else if (m==1) cout<<n-2<<endl;
	else cout<<(n-2)*(m-2)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  i++)
#define REP(i, n)    for(int i=0;   i<(n);  i++)
#define REP1(i, n)   for(int i=1;   i<=(n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul    = unsigned long;
using ll    = long long;
using ld    = long double;
using vint  = vector<int>;
using vll   = vector<ll>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;

int n, m;

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

  cin >> n >> m;
  vint a(m);
  REP(i, m) scan(a[i]);

  int dp[n+1];
  dp[0] = 1;
  auto itr = a.begin();

  auto itr2 = find(itr, a.end(), 1);
  if(  find(itr, a.end(), 1)==a.end() ){
    dp[1] = dp[0];
  }else{ dp[1] = 0; itr = itr2; };

  for(int i=2; i<=n; i++){
      itr2 = find(itr, a.end(), i);
    if( itr2 == a.end()  ){
      dp[i] = dp[i-1] + dp[i-2];
      dp[i] %= MOD;
    }else{ dp[i] = 0; itr = itr2; }
  }


  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 1024
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
ans=1
tmp=float('inf')
for i in range(n):
    if abs(tmp-a)>abs(t-h[i]*0.006-a):
        ans=i+1
        tmp=t-h[i]*0.006
    # print(tmp)
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (B / A > C) {
        cout << C << endl;
    } else {
        cout << B / A << endl;
    }
}

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


const int INF = 1000000000;

struct edge {
    int to;
    int cost;
    edge(int to, int cost) : to(to), cost(cost){ }
};
using Graph = vector<vector<edge>>;
int V;
Graph G;
vector<int> dist;

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    dist = vector<int>(V, INF);
    dist[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for (int i = 0; i < G[v].size(); ++i){
            edge e = G[v][i];
            if(dist[e.to] > dist[v] + e.cost){
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
}

int main(){
    cin >> V;
    int E;
    cin >> E;
    int r;
    cin >> r;
    G.resize(V);
    rep(i, E)
    {
        int from, to, cost;
        cin >> from >> to >> cost;
        G[from].push_back(edge(to, cost));
    }
    dijkstra(r);
    rep(i,V){
        if(dist[i]!= INF){
            cout << dist[i] << endl;
        }else{
            cout << "INF" << endl;
        }
    }
}


Measured memory_bytes: 12984
def dfs(v, N, visited, ret, route):
    if sum(visited) == N:
        return ret + 1
    
    visitable = []
    for pair in route:
        if v in pair:
            if visited[pair[0]] == 0:
                visitable.append(pair[0])
            elif visited[pair[1]] == 0:
                visitable.append(pair[1])
    
    for v in visitable:
        visited[v] = 1
        ret = dfs(v, N, visited, ret, route)
        visited[v] = 0
    
    return ret

N, M = map(int, input().split())
route = []
for i in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    route.append([a, b])
visited = [0] * N
visited[0] = 1
ret = dfs(0, N, visited, 0, route)
print(ret)

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int maxn = 3005;
const int mod = 1e9 + 7;
int n, m;
int dp[maxn * 2][maxn * 2][2];

void upd(int &x, int y) { x += y; if (x >= mod) x -= mod; }

int main() {
	scanf("%d %d", &n, &m);
	rep(i, n + 1) dp[0][i][i == 0] = 1;
	rep(i, m * 2) rep(j, n + i / 2 + 1) rep(f, 2) if (dp[i][j][f]) {
		int nj = j, nk = n + i / 2 * 2 - i - j;
		if (i & 1) nj ++, nk ++;
		if (nj) upd(dp[i + 1][nj - 1][f | (nj - 1 == 0)], dp[i][j][f]);
		if (nk) upd(dp[i + 1][nj][f], dp[i][j][f]);
	}
	int ans = 0;
	rep(i, n + m + 1) upd(ans, dp[m * 2][i][1]);
	printf("%d\n", ans);
	return 0;
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    bool flag = 1;
    int count = 0;
    for(int i=0;i<s.size();i++){
        if(flag) count++;

        if(i==s.size()-1) break;
        
        if(s[i]==s[i+1]) flag = 0;else flag = 1;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
// F - LCS
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S,T; cin>>S>>T;
	int Ns = S.size(), Nt = T.size();

	vector<vector<int>> dp(Nt+1, vector<int>(Ns+1));
	for(int t=1; t<=Nt; t++)
		for(int s=1; s<=Ns; s++)
			if(T[t-1]==S[s-1]) dp[t][s] = dp[t-1][s-1] + 1;
			else dp[t][s] = max(dp[t][s-1], dp[t-1][s]);

	string ans;
	int t = Nt, s = Ns;
	while(t>=1 && s>=1){
		if(dp[t][s]==dp[t][s-1]) s--;
		else if(dp[t][s]==dp[t-1][s]) t--;
		else{
			t--; s--;
			ans += S[s];
		}
	}
	reverse(ans.begin(), ans.end());
	cout<< ans <<endl;
}

Measured memory_bytes: 35584
s = input()

if s[0] == ">": s = "<" + s
if s[-1] == "<": s = s + "><"
if s[-1] == ">": s = s + "<"
lens = len(s)

a = []
c = 1
for i in range(1, lens):
    if s[i] == s[i-1]:
        c += 1
    else:
        a.append(c)
        c = 1

ans = 0
for i in range(0, len(a), 2):
    ans += a[i+1] * (a[i+1]-1) // 2
    ans += a[i] * (a[i]-1) // 2
    ans += max(a[i], a[i+1])

print(ans)

Measured memory_bytes: 6320
#include<cstdio>
#include<cmath>
int main(){
  double x1,y1,x2,y2;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  printf("%.7f\n",sqrt(pow(x2-x1,2)+pow(y2-y1,2)));
}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,from,to) for(int i=from; i<to; ++i)
#define REP(i,from,to) for(int i=from; i<=to; ++i)
using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i] << endl;
	}
	return out;
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	out << "[";
	size_t last = v.size() - 1;
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i];
		if (i != last) {
			out << ",";
		}
	}
	out << "]";
	return out;
}
const int maxh = 8;
int h, w, c;
int di[4] = { -1, 0, 1, 0 };
int dj[4] = { 0, 1, 0, -1 };
int ans;
int paint(vector<vector<int> >& p, int i, int j, int from, int to) { //from???????????????(i,j)???to??????????????????, p????????§??????
	p[i][j] = to;
	int cnt = 1; //(i,j)???to????????£????????§, ?????£?????°???1???
	rep(k,0,4)
	{
		int ni = i + di[k], nj = j + dj[k];
		if (0 <= ni && ni < h && 0 <= nj && nj < w && (p[ni][nj] == from)) {
			cnt += paint(p, ni, nj, from, to); //??£??\??????????????????????????????
		}
	}
	return cnt; //(i,j)????????????????????????to???????????????????????????
}

void dfs(vector<vector<int> >& p, int level) { //"????????????"level?????????????????´
	int ret = 0;
	REP(col, 1, 6)
	{
		if (col == p[0][0]) { //????????¨???????????????????????????(????????????)
			continue;
		}
		if (level == 5 && col != c) { //5????????????c??\??????????????´?????????
			continue;
		}
		vector<vector<int> > next = p; //???????????????p????????????next????????£???????????????
		if (level < 5) { //1-4???????????§?????¨????????????
			paint(next, 0, 0, next[0][0], col); //???col????????´??????
			dfs(next, level + 1); //next?????????????¬????
		} else {
			paint(next, 0, 0, next[0][0], c); //?????????????¨????c??§??????
			ret = paint(next, 0, 0, next[0][0], 0); //0??§???????????¨??§?????§???????????????????????°?????°????????????
			ans = max(ans, ret);
		}
	}
}

void solve() {
	while (cin >> h >> w >> c, h || w || c) {
		ans = 0;
		vector<vector<int> > p(h);
		rep(i,0,h)
		{
			p[i] = vector<int>(w);
			rep(j,0,w)
			{
				cin >> p[i][j];
			}
		}
		dfs(p, 1);
		cout << ans << endl;
	}
}

int main() {
	solve();
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  int P,Q,R;cin >> P >> Q >> R;
  cout << P+Q+R-max(P,max(Q,R)) << endl;
  return 0;
}


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

struct isikawakaito {
	char S[12];
	int P;
	int idx;
};

int sakuraitakahiro(const void* x, const void* y) {
	const struct isikawakaito *a = x, *b = y;
	int c = strcmp(a->S, b->S);
	if (c != 0) return c;
	return a->P > b->P ? -1 : a->P < b->P;
}

int N;
struct isikawakaito saitousouma[128];

int main(void) {
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%11s%d", saitousouma[i].S, &saitousouma[i].P) != 2) return 1;
		saitousouma[i].idx = i + 1;
	}
	qsort(saitousouma, N, sizeof(*saitousouma), sakuraitakahiro);
	for (i = 0; i < N; i++) {
		printf("%d\n", saitousouma[i].idx);
	}
	return 0;
}


Measured memory_bytes: 128
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var str=input.trim();
var cnt=0;
if(str.length%2==0){
   var a=str.slice(0,str.length/2);
   var b=str.slice(str.length/2,str.length);
}else{
   var a=str.slice(0,(str.length-1)/2);
   var b=str.slice((str.length+1)/2,str.length);
   var c=str.slice((str.length-1)/2,(str.length+1)/2);
   if(c!="i" && c!="w")cnt++;
}
b=b.split("").reverse().join("");
for(var i=0;i<a.length;i++){
   if(a[i]=="i" && b[i]=="i")continue;
   if(a[i]=="w" && b[i]=="w")continue;
   if(a[i]=="(" && b[i]==")")continue;
   if(a[i]==")" && b[i]=="(")continue;
   cnt++;
}
console.log(cnt);

Measured memory_bytes: 7384