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

const ll M = 1e9+7;
void madd(ll& a, ll b) {
    a += b;
    if (a >= M) a -= M;
}
ll mult(ll a, ll b) {
    return (1LL*a*b) % M;
}
ll modexp(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b&1) res = mult(res,a);
        a = mult(a,a);
        b >>= 1;
    }
    return res;
}
ll inverse(ll x) {
    return modexp(x,M-2);
}
const ll maxn = 1e5+5;
ll n, k, a[maxn];

ll fac[maxn], ifac[maxn];
ll choose(ll n, ll r) {
    if (n < r) return 0;
    return mult(fac[n],mult(ifac[r],ifac[n-r]));
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> k;
    fac[0] = 1;
    ifac[0] = 1;
    for (ll i = 1; i < maxn; i++) {
        fac[i] = mult(fac[i-1],i);
        ifac[i] = inverse(fac[i]);
    }
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a,a+n);
    ll mx = 0;
    for (ll i = 0; i < n; i++) {
        ll add = mult(choose(i,k-1),a[i]);
        //cout << i << ": " << add << '\n';
        madd(mx,add);
    }
    ll mn = 0;
    for (ll i = 0; i < n; i++) {
        ll add = mult(choose(n-i-1,k-1),a[i]);
        //cout << i << ": " << add << '\n';
        madd(mn,add);
    }
    //cout << "mx = " << mx << '\n';
    //cout << "mn = " << mn << '\n';
    cout << ((mx-mn+M)%M) << '\n';
}



Measured memory_bytes: 2560
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 998244353;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] ans = {"pon","pon","hon","bon","hon","hon","pon","hon","pon","hon"};

        System.out.println(ans[N % 10]);


    }

}









Measured memory_bytes: 35800
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 
//Available in Snips
#define fi(i, x, y)   for (__typeof(x) i = x; i < y; i ++)
#define fir(i, x, y)  for (__typeof(x) i = x; i > y; i --)
#define fv(x)   for (auto itr = x.begin(); itr != x.end(); itr ++)
#define fvr(x)  for (auto itr = x.end() - 1; itr != x.begin() - 1; itr --)

bool check(string s){
	int n = s.size();
	for(int i=0;i<n/2;i++){
		if(s[i]==s[n-1-i]){
			continue;
		} else {
			return false;
		}
	}
	return true;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
	int n;
	cin >> n;
	double d = (double) n / (double) 3;
	printf("%.12f\n", (double) (d*d*d));
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=int(input()),int(input())
    X=list(map(int,input().split()))
    ans=0
    for i in range(n):
        if X[i]<=0: ans+=abs(X[i])
        elif X[i]>=k: ans+=X[i]-k
        else: ans+=min(X[i],k-X[i])
    print(ans*2)
resolve()

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
ll ans = 0;
string S;
set<int> R, G, B;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> S;
    for(int i = 0; i < N; i++){
        if(S[i] == 'R') R.insert(i);
        if(S[i] == 'G') G.insert(i);
        if(S[i] == 'B') B.insert(i);
    }
    for(auto u : R){
        for(auto v : G){
            int x = max(u, v);
            int y = min(u, v);
            ans += B.size();
            int d = x - y;
            if(B.find(x + d) != B.end()) ans--;
            if(d % 2 == 0 && B.find(y + (d / 2)) != B.end()) ans--;
            if(B.find(y - d) != B.end()) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define int long long int
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
#define MOD 998244353
#define output(x) for (auto a:x) cout<<a<<" ";cout<<endl;
#define output2(x) for (auto a:x) cout<<a.fi<<" "<<a.se<<endl;
 
int power(int x,int y,int mod) 
{ 
 	int ret = 1;
 	x = x % mod;
 	while (y){
 		if(y&1) ret = (ret*x)%mod;
 		y = y>>1;
 		x = (x*x)%mod;
    } 
    return ret%mod; 
}

int isprime(int x)
{
	for (int i=2;i*i<=x;i++)
		if (x%i==0) return 0;
	return 1;
}

void solve()
{	
	string s,t;
	cin>>s>>t;
	int n = s.size();
	int m = t.size();
	vector<vector<int>> dp(n+1,vector<int>(m+1));
	for (int i=0;i<=n;i++){
		for (int j=0;j<=m;j++){
			if (min(i,j)==0){
				dp[i][j]==0;
			}
			else if (s[i-1]==t[j-1]){
				dp[i][j] = dp[i-1][j-1]+1;
			} else {
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	string out;
	int i = n,j = m;
	while (i>0&&j>0){
		if (s[i-1]==t[j-1]){
			out.pb(s[i-1]);
			i--,j--;
		} else if (dp[i-1][j]>dp[i][j-1]){
			i--;
		} else j--;
	} 
	reverse(out.begin(), out.end());
	cout<<out<<endl;
}
 
 
signed main(){
	// int t;
	// cin>>t;
	// while (t--)	
	solve();	
 
}
	

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string x;
  int k;
  cin>>k>>x;
  if(x.length()>k){
    cout<<x.erase(k)<<"...";
  }
  else{
    cout<<x;
  }
}

Measured memory_bytes: 3644
#print(ord('a')) # 97
abc = ''
for i in range(97 ,97+26):
    abc += chr(i)
#print(abc)

S = input()
K = int(input())
ans = ''
for i,s in enumerate(S):
    if ord(s) > ord('a') and 26 - (ord(s) - ord('a')) <= K and i!=len(S)-1:
        ans += 'a'
        #K -= 26 - (ord(s) - ord('a'))
        K -= 26 - (ord(s) - ord('a'))
        #print(K)

    elif i != len(S)-1:
        ans += s
    else:
        #ans += chr(ord(s) + K%26)
        ans += abc[(ord(s) + K%26-ord('a'))%26]
        #print(ans)

print(ans)

Measured memory_bytes: 3444
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 3003

int n;
ll a[N];
ll memo[N][N];

ll dfs(int p, int q, int t) {
  if(memo[p][q] != -1) {
    return memo[p][q];
  }
  if(t) {
    return memo[p][q] = min(dfs(p+1, q, 0) - a[p], dfs(p, q-1, 0) - a[q-1]);
  } else {
    return memo[p][q] = max(dfs(p+1, q, 1) + a[p], dfs(p, q-1, 1) + a[q-1]);
  }
}

int main() {
  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n+1) rep(j, n+1) memo[i][j] = -1;
  rep(i, n+1) memo[i][i] = 0;
  cout << dfs(0, n, 0) << endl;
  return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[101]={};
    for (int i=1;i<=9;i++)
    {
        for (int j=1;j<=9;j++)
        {
            a[i*j]=1;
        }
    }
    if (a[n]==1)
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}

Measured memory_bytes: 3764
// Problem : E - Picking Goods
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_e
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 3005

//Solution

int n,m,k;
int a[N][N], dp[N][N][4];

int f(int x, int y, int cnt){
    if(x > n || y > m) return 0;
    int &ret = dp[x][y][cnt];
    if(~ret) return ret;
    ret = 0;
    if(a[x][y] == 0){
        ret = max(ret,f(x+1,y,0));
        ret = max(ret,f(x,y+1,cnt));
    } else {
        ret = max(ret,f(x+1,y,0));
        ret = max(ret,f(x,y+1,cnt));
        if(cnt < 3) ret = max(ret,a[x][y]+f(x,y+1,cnt+1));
        if(cnt < 3) ret = max(ret,a[x][y]+f(x+1,y,0));
    }
    return ret;
}

void solve(){
    cin>>n>>m>>k;
    while(k--){
        int x,y,v;
        cin>>x>>y>>v;
        a[x][y] = v;
    }
    memset(dp,-1,sizeof(dp));
    cout<<f(1,1,0)<<'\n';
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 356700
#include <stdio.h>

int main(void){
    int A,B;
    int i;
    int plug = 1;
    int count = 0;
    scanf("%d",&A);
    scanf("%d",&B);
    while(plug<B){
        plug += A-1;
        count++;
    }
    printf("%d\n",count);
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}


int main() {
  int N;
  cin >> N;
  vector< int > P(N);
  cin >> P;
  int ret = 0;
  for(int i = 1; i + 1 < N; i++) {
    auto s = minmax({P[i - 1], P[i], P[i + 1]});
    if(s.first != P[i] && s.second != P[i]) {
      ++ret;
    }
  }
  cout << ret << endl;
}







Measured memory_bytes: 256
S = raw_input()
K = input()

L = []
c = 0
for i in range(len(S)+1):
  if i==len(S):
    L += [c]
    continue
  if i==0:
    c = 1
    continue
  if S[i]==S[i-1]:
    c += 1
  else:
    L += [c]
    c = 1

if len(L)==1:
  print len(S)*K/2
elif S[0]==S[-1]:
  print L[0]/2+L[-1]/2+sum(l/2 for l in L[1:-1])*K+(L[0]+L[-1])/2*(K-1)
else:
  print sum(l/2 for l in L)*K


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

int main()
{
    int N,K,Q;
    cin >> N >> K >> Q;
  	vector<int>vec(N,K-Q);
  
  	for(int i = 0;i < Q;i++){
      int A;
      cin >> A;
      ++vec.at(A-1);
    }
  	for(int i = 0;i < N;i++){
      if(vec.at(i) > 0){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
  
    return 0;
}

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

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> a(N);

  for (auto& a_i: a) {
    cin >> a_i;
    a_i--;
  }
  // ボタン1が光ってる
  int on_index = 0;
  vector<bool> on_once(N, false);
  bool is_ok = true;

  int count = 0;
  while (true) {
    count++;
    if (a.at(on_index) == 1) {
      break;
    }
    if (on_once.at(on_index)) {
      is_ok = false;
      break;
    }
    on_once.at(on_index) = true;
    on_index = a.at(on_index);
  }

  if (is_ok) {
    printf("%d\n", count);
  } else {
    printf("%d\n", -1);
  }
}

int main() {
  answer1();
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

    int A, B, X;

    cin >> A >> B >> X;
    if(A+B < X){
        cout << "NO" << endl;
    }else if( X < A){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }

    

    return 0;
}


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

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

const int N = 8;
const int M = N * (N-1) / 2;

vector<int> e[N + 2];
vector<int> visited;
static int ans = 0;


int judge(){
  int count;
  for(auto &elem : visited){
    if(elem != 1){
      return 0;
    }
  }
  return 1;
}

void dfs(int now){
  visited[now] = 1;
  if(judge() == 1){ ++ans; }
  for(auto &next : e[now]){
    if(visited[next] == 1) continue;
    //cout <<endl << "now : " << now << " next : " << next << " visited[next] : " << visited[next] ;
    dfs(next);
    visited[next] = 0;
  }
}

int main(){
  int a, b;
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < n ; i++){
    visited.emplace_back(0);
  }

  for(int i = 0; i < m ; i++){
    cin >> a >> b;
    --a;
    --b;
    e[a].emplace_back(b);
    e[b].emplace_back(a);
  }

  dfs(0);

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
using namespace std;
char s[55], t[55];
int main() {
     scanf( "%s%s", s, t );
     int n = strlen( s );
     int m = strlen( t );
     if( n < m ) {
          cout << "UNRESTORABLE" << endl;
          return 0;
     }
     bool res = false;
     for( int i = n - m + 1; i >= 0; i-- ) {
          bool flag = false;
          for( int j = 0; j < m; j++ ) {
               if( s[i + j] == '?' )continue;
               if( s[i + j] != t[j] ) {flag = true;break;}
          }
          if( !flag ) {
               for( int j = 0; j < m; j++ ) {
                    s[i + j] = t[j];
               }
               res = true;
               break;
          }
     }
     if( !res ) {
          cout << "UNRESTORABLE" << endl;
     } else {
          for( int i = 0; i < n; i++ ) {
               if( s[i] == '?' )
                    s[i] = 'a';
          }
          cout << s << endl;
     }
     return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,s[40],t[40],ans;
int main(void){
    cin>>a>>b;
    a--;
    a=max(a,0LL);
    for(ll i=1;i<41;i++){
        if(i==1){
            if(a%4==0||a%4==3)s[0]=0;
            else s[0]=1;
        }
        else s[i-1]=max(0LL,(a%(1LL<<i)-(1LL<<(i-1))+1)%2);
    }
    for(ll i=1;i<41;i++){
        if(i==1){
            if(b%4==0||b%4==3)t[0]=0;
            else t[0]=1;
        }
        else t[i-1]=max(0LL,(b%(1LL<<i)-(1LL<<(i-1))+1)%2);
    }
    for(ll i=0;i<40;i++){
        ans+=(1LL<<i)*(abs(s[i]-t[i]));
        //cout<<ans<<s[i]<<t[i]<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
k, n = map(int, input().split())
x = list(map(int, input().split()))

dist = [x[i] - x[i - 1] for i in range(1, n)]
dist.append(x[0] + k - x[n - 1])

# print(len(dist))
ans = k - max(dist)

print(ans)

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

typedef long long ll;
typedef pair<int,int> ii;

int f(int x) {
	int ret=0;
	while(x)
		ret+=x%10, x/=10;
	return ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	cout << (n%f(n)==0 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import math

S = list(map(int,input().split()))

A = list(map(int,input().split()))

X=S[1]
Y=S[2]

if S[0]==1:
	print(int(math.fabs(A[-1]-Y)))
else:
	r1=math.fabs(A[-1]-Y)
	r2=math.fabs(A[-2]-A[-1])

	if r1<r2:
		print(int(r2))
	else:
		print(int(r1))


Measured memory_bytes: 3188
from bisect import bisect_left
def main():
    h, w, m = map(int, input().split())
    bombs = set()
    cnt_row, cnt_col = [0]*(h+1), [0]*(w+1)
    for _ in range(m):
        y, x = map(int, input().split())
        cnt_row[y] += 1
        cnt_col[x] += 1
        bombs.add((y, x))
    max_cnt_row = max(cnt_row)
    max_cnt_col = max(cnt_col)
    idx_row = []
    idx_col = []
    for i in range(h+1):
        if cnt_row[i] == max_cnt_row:
            idx_row.append(i)
    for j in range(w+1):
        if cnt_col[j] == max_cnt_col:
            idx_col.append(j)
    ans = max_cnt_row + max_cnt_col - 1
    for i in idx_row:
        for j in idx_col:
            if not (i, j) in bombs:
                ans = max_cnt_row + max_cnt_col
                break
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 176688
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b) cout << c << endl;
  else if (b == c) cout << a << endl;
  else if (a == c) cout << b << endl;
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<ll> v;
    ll ans=0;
    while(n){
        ans+=n%10;
        v.push_back(n%10);
        n/=10;
    }
    chmax(ans, ll((v.size() - 1) * 9));
    reverse(ALL(v));
    ll sum=0;
    //debug(v);
    rep(i,v.size()-1){
        if(v[i]!=0){
            ll temp=sum+v[i]-1+9*(v.size()-(i+1));
            chmax(ans,temp);
            sum+=v[i];
            //cout<<temp<<"\n";
        }
    }
    cout<<ans<<"\n";
}


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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>



void solve() {
    string s;
    cin >> s;
    if (s[SZ(s) - 1] == 's')
        cout << s << "es" << '\n';
    else
        cout << s << "s" << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<int> data;

    rep(i, n){
        int temp;
        cin >> temp;
        data.push(temp);
    }

    rep(i, m){
        int d = data.top();
        data.pop();
        data.push(d/2);
    }

    ll ans = 0;
    rep(i, n){
        ans += data.top();
        data.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int t;
  if(c%b==0)t=c/b;
  if(c%b!=0)t=c/b+1;
  if((t-1)*d>=a)cout<<"No";
  else cout<<"Yes";
  return 0;
}

Measured memory_bytes: 3636
class Dice
  attr :top, :front, :right, :left, :back, :bottom
  def initialize a,b,c,d,e,f
    @top = a; @front = b; @right = c; @left = d; @back = e; @bottom = f
  end
  def rotN
    t = @top; @top = @front; @front = @bottom; @bottom = @back; @back = t
  end
  def rotE
    t = @top; @top = @left; @left = @bottom; @bottom = @right; @right = t
  end
  def rotW
    t = @top; @top = @right; @right = @bottom; @bottom = @left; @left = t
  end
  def rotS
    t = @top; @top = @back; @back = @bottom; @bottom = @front; @front = t
  end
  def rotV
    t = @front; @front = @left; @left = @back; @back = @right; @right = t
  end
end

a,b,c,d,e,f = gets.split.map {|s| s.to_i}
die = Dice.new(a,b,c,d,e,f)
n = gets.to_i
for i in 1..n
  t,f = gets.split.map {|s| s.to_i}
  if die.right == t
    die.rotW
  elsif die.left == t
    die.rotE
  else
    until die.top == t
      die.rotN
    end
  end
  until die.front == f
    die.rotV
  end
  puts die.right
end

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

int main(){
    int n;
    cin>>n;
    map<int,int> m;
    rep(i,n-1){
        int a;
        cin>>a;
        m[a]++;
    }
    rep(i,n){
        cout<<m[i+1]<<endl;
    }
}


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

if a.even? || b.even? || c.even?
    p 0
else
    k = nil
    [a,b,c].permutation{|l|
        t = l[0]*((l[2]/2+1)*l[1] - l[2]/2*l[1] )  # a*((c/2+1)*b - c/2*b ) 
        k = t if !k||t<k
    }
    p k
end


#寝坊した…_(：3 」∠ )_


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int x;
  cin >> x;
  for (int i = x; ; i++) {
    bool f = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) f = false;
    }
    if (f) {
      cout << i << endl;
      return;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int h, w, n;
	int a[10001];
	int c[101][101];
	int p = 1;

	cin >> h >> w >> n;
	FOR(i, 1, n) {
		cin >> a[i];
	}
	FOR(i, 1, h) {
		if (i % 2 == 1) {
			FOR(t, 1, w) {
				if (a[p] != 0) {
				}
				else {
					p++;
				}
				c[i][t] = p;
				a[p]--;
			}
		}
		else {
			RFOR(t, w, 1) {
				if (a[p] != 0) {
				}
				else {
					p++;
				}
				c[i][t] = p;
				a[p]--;
			}
		}
	}

	FOR(i, 1, h) {
		FOR(t, 1, w) {
			cout << c[i][t] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
    int h,w; cin >> h >> w;
    long long ans = 1e9;
    if(h%3 == 0) ans = min(ans,0LL); else ans = min(ans,1LL*w);
    if(w%3 == 0) ans = min(ans,0LL); else ans = min(ans,1LL*h);
    for(int i=1;i<h;i++){
        long long v = 1LL*i*w;
        long long w1 = 1LL*(h-i)*w;
        long long w2 = 1LL*(h-i) * (w/2);
        w1 -= w2;
        ans = min(ans,max(v,max(w1,w2))-min(v,min(w1,w2)));
    }
    swap(h,w);
    for(int i=1;i<h;i++){
        long long v = 1LL*i*w;
        long long w1 = 1LL*(h-i)*w;
        long long w2 = 1LL*(h-i) * (w/2);
        w1 -= w2;
        ans = min(ans,max(v,max(w1,w2))-min(v,min(w1,w2)));
    }
    cout << ans << endl;
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

double f(int N, int h, int n) {
    return 1.0 * h * n * N / (4 * h * n - h * N - n * N);
}
using Int = long long;
int main() {
    int N;
    cin >> N;
    rep(h, 3501) rep(n, 3501) if (h && n) {
        double w = f(N, h, n);
        if (w > 0 && w == Int(w)) {
            cout << h << " " << n << " " << Int(w) << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  vector<int> A(N); rep(i,N) cin >> A[i];
  vector<int> B(1001000, 0);
  rep(i,N){
    B[A[i]]++;
  }
  ll ans = 0;
  rep(i,N){
    vector<ll> res;
    for(ll j=1; j*j<=A[i]; j++){
      if(A[i]%j==0){
        res.pb(j);
        if(A[i]/j != j) res.pb(A[i]/j);
      }
    }
    int cnt = 0;
    rep(j,sz(res)){
      if(res[j]!=A[i] && B[res[j]]) {
        cnt++;
        break;
      }
      else if(res[j]==A[i]&&B[res[j]]>1){
        cnt++;
        break;
      }
    }
    if(cnt){
      ans++;
    }
  }
  cout << N-ans << endl;
  return 0;
}


Measured memory_bytes: 7960
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (int)(n) - 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--)

using namespace std;

int N;
vector<int> G[200000];
int h[200000];
int d;

void dfs(int u, int p) {
  vector<int> a = {0, 0};
  for (int v : G[u]) if (v != p) {
    dfs(v, u);
    h[u] = max(h[u], h[v] + 1);
    a.push_back(h[v] + 1);
  }
  sort(a.rbegin(), a.rend());
  d = max(d, a[0] + a[1]);
}

int main() {
  cin >> N;
  REP(i, N-1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(0, -1);
  static bool dp[200001];
  dp[0] = false;
  dp[1] = true;
  dp[2] = false;
  for (int i = 3; i <= 200000; i++) {
    dp[i] |= !dp[i-1];
    dp[i] |= !dp[i-2];
  }
  cout << (dp[d+1] ? "First" : "Second") << '\n';
}


Measured memory_bytes: 45056
#!/usr/bin/env python3
N = int(input().strip())

suretsu = (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)

print(suretsu[N - 1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i,n)cin>>a[i];
    ll ans = 0;

    ll mi = 0;
    rep(i,n){
        if(i==0){
            ans += a[i] - 1;
            mi = 1;
        }else{
            if(a[i]<=mi){
                continue;
            }if(a[i]==mi+1){
                mi = a[i];
            }else{
                ll loop = (a[i] - (mi+2)) / (mi+1);
                ans += loop;
                ans++;
            }
        }
    }

    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 1024
/**
*    author:  yuya1234
*    created: 08.07.2020 11:39:37
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define ALL(v) (s).begin(), (s).end()
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  ll n;
  cin>>n;

  cout<<(n-1)*n/2<<endl;

  return 0;
}

Measured memory_bytes: 3564
import java.util.Scanner;

public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        String s;
        s = next();
        if(s.equals("ABC")) print("ARC");
        else print("ABC");
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    vector<ll> a;

    rep(i, n) {
        ll ai;
        cin >> ai;
        a.push_back(ai);
    }

    multiset<ll> st;
    set<ll> check;
    ll csum[n + 1];
    csum[0] = 0;
    ll ans = 0;

    rep2(i, n) {
        csum[i] = csum[i - 1] + a[i - 1];
        st.insert(csum[i]);
        check.insert(csum[i]);
    }

    for (auto k : check) {
        ll cnt = st.count(k);
        if (k == 0) ans += cnt;
        if (cnt >= 2) ans += cnt * (cnt - 1) / 2;

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 22128
import std.algorithm,
       std.string,
       std.range,
       std.stdio,
       std.conv;

void main() {
  int   N  = readln.chomp.to!(int);
  int[] ns = readln.chomp.split.to!(int[]);
  int   x  = ns[$-1];
  ulong[21][101] dp;

  dp[0][ns[0]]++;

  foreach (i; 1..(N-1)) {
    foreach (j; 21.iota) {
      int a = j + ns[i];
      int b = j - ns[i];

      if (0 <= a && a <= 20) {
        dp[i][a] += dp[i - 1][j];
      }
      if (0 <= b && b <= 20) {
        dp[i][b] += dp[i - 1][j];
      }
    }
  }

  writeln(dp[N-2][x]);
}

Measured memory_bytes: 2464
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int r; cin>>r;
  cout << r*r << endl;
  return 0;
}

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

struct Point{
	double x,y;
};

void koch(int n, struct Point a, struct Point b){
	if(n==0){return;}
	
	struct Point s,t,u;
	double th=M_PI*60.0/180.0;
	
	s.x=(2.0*a.x+1.0*b.x)/3.0;
	s.y=(2.0*a.y+1.0*b.y)/3.0;
	t.x=(1.0*a.x+2.0*b.x)/3.0;
	t.y=(1.0*a.y+2.0*b.y)/3.0;
	u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
	u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
	
	koch(n-1,a,s);
	printf("%.8f %.8f\n",s.x,s.y);
	koch(n-1,s,u);
	printf("%.8f %.8f\n",u.x,u.y);
	koch(n-1,u,t);
	printf("%.8f %.8f\n",t.x,t.y);
	koch(n-1,t,b);
}

int main(){
	struct Point a,b;
	int n;
	
	scanf("%d",&n);
	
	a.x=0.0;
	a.y=0.0;
	b.x=100.0;
	b.y=0.0;
	
	printf("%.8f %.8f\n",a.x,a.y);
	koch(n,a,b);
	printf("%.8f %.8f\n",b.x,b.y);
	
	return 0;
}


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

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

using namespace std;

const double inf=1e8;

int d[31][31];
int c[31][31];
double dist[31][31][31];

int n,m,s,g;

typedef tuple<double,int,int,int> state;
void dijkstra(){
	rep(i,n+1)rep(j,31)rep(k,n+1) dist[i][j][k]=inf;
	state init=make_tuple(0.0,s,0,0);
	dist[s][0][0]=0;
	priority_queue<state,vector<state>,greater<state>>q;
	q.push(init);
	while(!q.empty()){
		double cost;
		int cur,v,prev;
		tie(cost,cur,v,prev)=q.top();q.pop();
		rep(i,n+1){
			if(prev==i) continue;
			if(d[cur][i]==inf) continue;
			for(int dv=-1;dv<=1;++dv){
				int ncur=i,nv=v+dv,nprev=cur;
				if(nv<=0||c[nprev][ncur]<nv) continue;
				double ncost=cost+1.0*d[nprev][ncur]/(nv);
				if(dist[ncur][nv][nprev]>ncost){
					dist[ncur][nv][nprev]=ncost;
					q.push(make_tuple(ncost,ncur,nv,nprev));
				}
			}
		}
	}
	double ans=inf;
	rep(i,n+1) ans=min(ans,dist[g][1][i]);
	cout.precision(10);
	if(ans==inf)
		cout << "unreachable" << endl;
	else
		cout << fixed << ans << endl;
}

int main(void){
	while(cin >> n >> m){
		if(n==0&&m==0) break;
		cin >> s >> g;
		rep(i,n+1)rep(j,n+1) d[i][j]=c[i][j]=inf;
		rep(i,m){
			int x,y,dd,cc;
			cin >> x >> y >> dd >> cc;
			d[x][y]=d[y][x]=dd,c[x][y]=c[y][x]=cc;
		}
		dijkstra();
	}
	return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return 0;
}

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

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

    for(int i=0;i<S.length();i++){
        for(int j=0;j<N;j++){
            if(S[i]=='Z')
                S[i] = '@';
            S[i] = S[i] + 1;
        }
    }

    cout << S << endl;

}


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

/*リスト一式*/
/*NDDTで置換する型を変更してリストのデータを指定*/
typedef char NDDT;
typedef struct node{
  NDDT data;
  struct node *next;
  struct node *prev;
} NODE;
typedef struct list{
  int size;
  NODE *front;
  NODE *back;
} LIST;
NODE *new_node(NDDT d){
  NODE *ret = (NODE *)malloc(sizeof(NODE));
  ret->data = d;
  ret->next = NULL;
  ret->prev = NULL;
  return ret;
}
void new_list(LIST *list){
  list->back = NULL;
  list->front = NULL;
  list->size = 0;
}
void push_back(NDDT d, LIST *list){
  NODE *new = new_node(d);
  if(list->size == 0){
    list->front = list->back = new;
  }else{
    list->back->next = new;
    new->prev = list->back;
    list->back = new;
  }
  list->size++;
}
void push_front(NDDT d, LIST *list){
  NODE *new = new_node(d);
  if(list->size == 0){
    list->front = list->back = new;
  }else{
    list->front->prev = new;
    new->next = list->front;
    list->front = new;
  }
  list->size++;
}
int pop_back(LIST *list){
  if(list == NULL || list->size == 0){
    return 1;
  }
  if(list->size == 1){
    free(list->back);
    list->front = list->back = NULL;
    list->size = 0;
    return 0;
  }
  NODE *bk = list->back;
  NODE *nbk = bk->prev;
  free(bk);
  nbk->next = NULL;
  list->back = nbk;
  list->size--;
  return 0;
}
int pop_front(LIST *list){
  if(list == NULL || list->size == 0){
    return 1;
  }
  if(list->size == 1){
    free(list->back);
    list->front = list->back = NULL;
    list->size = 0;
    return 0;
  }
  NODE *fr = list->front;
  NODE *nfr = fr->next;
  free(fr);
  nfr->prev = NULL;
  list->front = nfr;
  list->size--;
  return 0;
}
/*ここまでリスト一式*/


int main(void){
  LIST list;
  new_list(&list);
  int n;
  char s[105];
  scanf("%d", &n);
  scanf("%s", s);
  int co = 0;
  for(int i = 0; i < n; i++){
    char now = s[i];
    if(now == '(') push_back(now, &list);
    else if(list.size != 0){
      pop_back(&list);
    }else{
      co++;
    }
  }

  for(int i = 0; i < co; i++){
    printf("(");
  }
  for(int i = 0; i < n; i++){
    printf("%c", s[i]);
  }
  for(int i = 0; i < list.size; i++){
    printf(")");
  }
  printf("\n");
  while(list.size != 0){
    pop_back(&list);
  }
  return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

template <typename T> T mod(const T& x, const T& M) {
    T ans = x % M;
    if (ans < 0) { ans += M; }
    return ans;
}

void update(vector<vll>& dp, vvi& curr, int x, int i) {
    rep(prev, 0, 13) {
        dp[i][curr[x][prev]] = (dp[i][curr[x][prev]] + dp[i - 1][prev]) % MOD;
    }
}

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

    string s;
    cin >> s;

    vvi curr(10, vi(13));
    rep(x, 0, 10) {
        rep(prev, 0, 13) { curr[x][prev] = mod(10 * prev + x, 13); }
    }

    int n = s.size();
    vector<vll> dp(n + 1, vll(13, 0));
    dp[0][0] = 1;

    rep(i, 1, n + 1) {
        char c = s[i - 1];

        if (c == '?') {
            rep(x, 0, 10) { update(dp, curr, x, i); }
            continue;
        }
        update(dp, curr, (int)(c - '0'), i);
    }
    cout << dp.back()[5] << endl;

    return 0;
}

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

const int MAXN=205;
const double eps=1e-7;

int n,f[MAXN];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n*2;i++) scanf("%d",&f[i]);
    sort(f+1,f+n*2+1);
    int ans=0;
    for(int i=1;i<=n;i++) ans+=f[i*2-1];
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N, M;
    cin>> N >> M;
    scc_graph graph(N);
    REP(i, 0, M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph.add_edge(a, b);
        graph.add_edge(b, a);
    }
    vvi list = graph.scc();
    /*
    for(auto l :list){
        for(auto i: l){
            cout << i << " ";
        }
        cout << endl;
    }*/
    cout << list.size() - 1 << endl;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < c&&c < b) {
		cout << "Yes" << endl;
	}
	else if (b < c&&c < a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

const long long int MOD = 1e9 + 7;
int n,k,a,b;
vector <int> adj[100001];
bool visited[100001];
long long int res = 1;

void dfs(int now,int depth)
{
	visited[now] = true;
	if(depth==0)
	{
		res = ((res%MOD)*(k%MOD)%MOD);
		res%=MOD;
	}
	long long int t = k-1;
	if(depth>0)
	{
		t--;
	}
	for(auto next : adj[now])
	{
		if(visited[next]==false)
		{
			if(t<0)
			{
				cout << 0 << '\n';
				exit(0);
			}
			res = ((res%MOD)*(t%MOD)%MOD)%MOD;
			res%=MOD;
			t--;
			dfs(next,depth+1);
		}
	}
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n >> k;

    for(int i=0;i<n-1;i++)
    {
    	cin >> a >> b;
    	adj[a].push_back(b);
    	adj[b].push_back(a);
    }

    memset(visited,false,sizeof(visited));

    dfs(1,0);

    cout << res << '\n';
    
    return 0;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];



void solve() {
  int a,b; cin >> a >> b;
  cout << (a-1)*(b-1) <<endl;

}

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


Measured memory_bytes: 256
# AOJ 0539: Pizza
# Python3 2018.7.1 bal4u

import bisect

while True:
	d = int(input())
	if d == 0: break
	n, m = int(input()), int(input())
	p = [0] + [int(input()) for i in range(n-1)] + [d]
	p.sort()
	ans = 0
	for i in range(m):
		k = int(input())
		if k > 0:
			t = bisect.bisect_left(p, k)
			ans += min(k-p[t-1], p[t]-k)
	print(ans)


Measured memory_bytes: 10724
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public static readonly long MOD = ((long)1e9 + 7);
	public void Solve()
	{
		int N = GetInt();
		long K = GetLong();
		int[] A = Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();

		long X = 0;
		for(int i = 0; i < N; i++)
			for(int j = 0; j < i; j++)
				if(A[j] > A[i])
					X++;

		long Y = 0;
		for(int i = 0; i < N; i++)
		{
			for(int j = 0; j < N; j++)
			{
				if(A[j] < A[i])
					Y++;
			}
		}

		long tmp = ((K * (K - 1)) / 2) % MOD;
		long ans = ((X * K) % MOD + (Y * tmp) % MOD) % MOD;
		Console.WriteLine(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
}


Measured memory_bytes: 13396