akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

string boin[256];
string ciin[256];

void f(char bu, int dir){
    if(ciin[bu]=="y" || ciin[bu]=="w"){
        if(ciin[bu]=="y"){
            cout << "y";
            if(dir == 'T') cout << "a";
            if(dir == 'U') cout << "u";
            if(dir == 'D') cout << "o";
        } else {
            if(dir == 'U') cout << "nn";
            if(dir == 'T') cout << "wa";
            if(dir == 'D') cout << "wo";
        }
    } else {
        cout << ciin[bu] << boin[dir];
    }
}

int main(){
    ciin['1'] = "";
    ciin['2'] = "k";
    ciin['3'] = "s";
    ciin['4'] = "t";
    ciin['5'] = "n";
    ciin['6'] = "h";
    ciin['7'] = "m";
    ciin['8'] = "y";
    ciin['9'] = "r";
    ciin['0'] = "w";
    boin['T'] = "a";
    boin['L'] = "i";
    boin['U'] = "u";
    boin['R'] = "e";
    boin['D'] = "o";
    string s;
    while(cin >> s){
        rep(i,s.size()){
            f(s[i],s[i+1]);
            i+=1;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if (K < A) write(K);
    else if (K <= A + B) write(A);
    else write(A - (K - A - B));
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    int n,h;
    cin >> n >> h;
    vector<ll> a(n);
    vector<ll> b(n);
    REP(i,n){
        cin >> a[i] >> b[i];
    }

    ll amax = *max_element(all(a)); 
    sort(all(b));
    ll bigger_idx = upper_bound(all(b),amax) - b.begin();
    if(bigger_idx == b.size()){
        cout << (int)ceil((double)h / amax) << endl;
    }
    else {
        for(int i = b.size()-1;i>= bigger_idx;i--){
            h -= b[i];
            if(h <= 0){
                cout << n - i << endl;
                return 0;
            }
        }
        cout << (int)ceil((double)h / amax) + n - bigger_idx << endl;
    }

    return 0;
}

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

int n,m;
int a[50],b[50];
bool graph[50][50];
bool visited[50];

void dfs(int v){
    visited[v]=true;
    for(int v2=0;v2<n;v2++){
        if(graph[v][v2]==false) continue;
        if(visited[v2]==true) continue;
        dfs(v2);
    }
}

int main(){
  cin>>n>>m;
  
  for(int i=0;i<m;i++){
      cin>>a[i]>>b[i];
      a[i]--,b[i]--;
      graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  int ans=0;
  for(int i=0;i<m;i++){
      graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
      for(int j=0;j<n;j++) visited[j]=false;
      
      dfs(0);
      bool bridge=false;
      for(int j=0;j<n;j++){
          if(visited[j]==false) bridge=true;
      }
      if(bridge) ans++;
      graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int a,b;
	string s;
	cin >> a >> b >> s;
	
	bool ans = true;
	REP(i,s.size()){
		if(i == a){
			if(s[i]!='-') ans = false;
		}else{
			if('0' <= s[i] && s[i] <= '9'){
				
			}else{
				ans = false;
			}
		}
	}
	
	if(ans){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
	
	return 0;
}

Measured memory_bytes: 3532
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cmath>
#include<fstream>

int main(){
	int N;
	std::string s;
	int cnt=0;

	std::cin >> N >> s;

	for(auto s_ : s){
		if(s_ == 'R') cnt++;
	}
	if(cnt > N/2) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main(){
  int x1,x2,x3,x4,x5;  
std::cin>>x1>>x2>>x3>>x4>>x5;
if(x1==0)
    std::cout<<1<<std::endl;
   else if(x2==0)   
    std::cout<<2<<std::endl;
  else if(x3==0)
    std::cout<<3<<std::endl; 
   else if(x4==0)
    std::cout<<4<<std::endl; 
else
  std::cout<<5<<std::endl;
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	string n; cin >> n;
	int c = 0;
	if ((n[0] == n[1] && n[1] == n[2]) || (n[2] == n[1] && n[3] == n[2]))cout << "Yes";
	else cout << "No";
	


	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
using namespace std;

vl divisor(ll n){
	vl ret;
	for (ll i = 1; i*i <= n; ++i){
		if (n%i == 0){
			ret.push_back(i);
			if (i*i != n) ret.push_back(n / i);
		}
	}

	//これ入れたらオーダーちょい上がる
	sort(ret.begin(), ret.end());

	return ret;
}

int main(){
	ll a, b; cin >> a >> b;
	if (a%b == 0) cout << 0 << endl;
	else cout << 1 << endl;
	return 0;
}

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

using namespace std;
using int64 = long long;

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int sum = (h2 - h1) * 60;
    sum -= m1 - m2;
    
    cout << sum - k << endl;
}


Measured memory_bytes: 3192
#include <iostream>

#define MAX 2000

typedef long long int ll;
#define MOD (ll)(1e9 + 7)
using namespace std;

ll bio[MAX+1][MAX+1];

void init(int n){
  for(int i=0;i<n+1;i++){
    for(int j=0;j<n+1;j++){
      //init
      bio[i][j] = 0;
    }
  }
}

ll coef(int n,int k){
  //cout << "n,k:" << n << " " << k << endl;
  if(n < 0 || k < 0)
    return 0;
  if(k == 0){
    bio[n][k] = 1;
    return 1;
  }
  if(n == k){
    bio[n][k] = 1;
    return 1;
  }
  if(k > n)
    return 0;
  if(bio[n][k] != 0)
    return bio[n][k];

  ll x,y;
  x = coef(n-1,k-1);
  y = coef(n-1,k);
  bio[n-1][k-1] = x;
  bio[n-1][k] = y;
  bio[n][k] = (x+y)%MOD;
  //cout << "n,k:" << n << " " << k << " " << bio[n][k] << endl; 
  return bio[n][k];
}

ll count[MAX+1];

int main(void){
  int N,K;
  cin >> N >> K;
  init(N);
  for(int i=1;i<=K;i++){
    ll insert = coef(N-K+1,i);
    ll order = coef(K-1,i-1);
    count[i] = (insert*order)%MOD;
  }
  for(int i=1;i<=K;i++){
    cout << count[i] << endl;
  }
}


Measured memory_bytes: 31616
use proconio::{input, fastout};
use proconio::marker::Chars;

const MOD: usize = 2019;

#[fastout]
fn main() {
    input! {
        s: Chars
    }

    let s = s.iter().map(|i| i.to_digit(10).unwrap() as usize).collect::<Vec<_>>();

    let mut dp = vec![0; MOD];
    dp[0] = 1;
    let mut p = 1;
    let mut cur = 0;
    let mut ans = 0;

    for d in s.iter().rev() {
        cur = (cur + p * d) % MOD;
        ans += dp[cur];
        dp[cur] += 1;
        p = 10 * p % MOD;
    }

    println!("{}", ans);
}

Measured memory_bytes: 4616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int N;
    cin >> N;
    int p[N];
    rep(i ,N){
        cin >> p[i];
        p[i]--;
    }
    int count = 0;
    for(int i = 0; i < N; i++){
        if(i == p[i] && i+1 == p[i+1]){
            count++;
            i++;
        } else if (i == p[i]){
            count++;
            i++;
        }
    }
    cout << count;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int a,b;
  cin >> a >> b;
  if(a<=5){
    cout << 0 << endl;
  }else if(a<=12){
    cout << b/2 << endl;
  }else{
    cout << b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    string s; cin >> s;
    int start = 0;
    int end = 0;
    rep(i, s.length()){
        if(s[i]=='A'){
            start = i;
            break;
        }
    }
    for(int i=s.length()-1; i>=0; --i){
        if(s[i]=='Z'){
            end = i;
            break;
        }
    }
    pr(end-start+1);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, q;
	cin >> n >> q;
    vector<vector<int>> tr(n); 
    for(int i=1; i<n; ++i){
        int a, b;
        cin >> a >> b;
        --a; --b;
        tr[a].push_back(b);
        tr[b].push_back(a);
    }
    vector<int> v(n,0);
    for(int i=0; i<q; ++i){
        int p, x;
        cin >> p >> x;
        v[--p] += x;
    }

    stack<int> s; s.push(0);
    vector<int> flg(n,1); flg[0]=0;
    while(!s.empty()){
        int z=s.top();
        s.pop();
        for(int i : tr[z]){
            if(flg[i]){
                v[i] += v[z];
                s.push(i);
                flg[i]=0;
            }
        }
    }

	for(int i : v) cout << i << " ";
    cout << endl;
}

Measured memory_bytes: 16372
#26 A - Prefix and Suffix
N = int(input())
s = list(input())
t = list(input())
s_rev = list(reversed(s))

cnt = 0
for i in range(1,N+1):
    # s の部分文字列を後ろから取り出す
    tgt = list(reversed(s_rev[:i]))
    if tgt == t[:i]:
        cnt = len(tgt)
    
ans = s + t[cnt:]
print(len(ans))

Measured memory_bytes: 9096
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,ss;
	int sum=0,i,ta,len,a,b;
cin>>a>>b;
for(i=a;i<=b;i++){
	if(i==0){
		cout<<"Zero"<<endl;
		return 0;
	}
	if(i<0)sum++;
}
if(sum==0){
			cout<<"Positive"<<endl;
		return 0;
}
if(sum%2==0){
			cout<<"Positive"<<endl;
		return 0;
} 
if(sum%2!=0){
		cout<<"Negative"<<endl;
		return 0;
}
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long K = sc.nextLong();
    sc.close();

    long a = Long.max(0, A - K);
    long b = Long.max(0, B - Long.max(0, K - A));
    System.out.println(a + " " + b);
  }
}

Measured memory_bytes: 23764
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    string S; cin>>S;
    char flag = S[0];
    int S_len = S.size();
    vector<int> ans(S_len, 0);
    int cnt=0;
    for (int i = 0; i < S_len; ++i) {
        cnt++;
        if(S[i]!=S[i+1] || i==S_len-1) {
            if (S[i] == 'R') {
                ans[i] += (cnt+1) / 2;
                ans[i+1] += cnt / 2;
                cnt = 0;
            } else if (S[i] == 'L') {
                ans[i - cnt + 1] += (cnt+1) / 2;
                ans[i - cnt] += cnt / 2;
                cnt = 0;
            }
        }
    }

    for (int i = 0; i < S_len; ++i) {
        cout<<ans[i]<<" ";
    }


    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include <string.h>

int main(void){

    int n,k,r,s,p;
    int i=0;
    int cr=0, cs=0, cp=0;

    scanf("%d %d", &n, &k);
    
    char t[n+1], at[n+1];
    scanf("%d %d %d", &r, &s, &p);
    scanf("%s", &t);

    for(i = k; i<n; i++){
        if (t[i] == t[i-k]){
            t[i] = 'a';
        }
    }

    i=0;

    while(t[i] != '\0'){

        if(t[i]=='r'){
            cp++;
            at[i]='r';
        }else if(t[i]=='s'){
            cr++;
            at[i]='s';
        }else if(t[i]=='p'){
            cs++;
            at[i]='p';
        }
        i++;
    }

    printf("%d", (r*cr+s*cs+p*cp) );
}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------

int N;
LL a[MAX];
int cnt,ans;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;

    REP(i,N){
        cin >> a[i];
    }

    REP(i,N){

        if( i >= 1 && ( a[i] == a[i-1])){
            cnt++;
        }
        else{
            if(cnt % 2 == 1){
                cnt = cnt / 2 + 1;
                ans += cnt;
            }else{
                cnt = cnt/2;
                ans+= cnt;
            }

            cnt = 0;
        }

    }

    if(cnt % 2 == 1){
        cnt = cnt / 2 + 1;
        ans += cnt;
    }else{
        cnt = cnt/2;
        ans+= cnt;
    }

    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T>
using ordered_set =
       tree <T,null_type,less <T>,rb_tree_tag,tree_order_statistics_node_update> ;
///find_by_order()
///order_of_key()

template <class T,class U>
void maximize(T &x,U y){
    if(x < y)x=y;
}
template <class T,class U>
void minimize(T &x,U y){
    if(x > y)x=y;
}
template <class T>
T Abs(T x){
    return (x < (T)0 ? -x : x);
}
template <class T>
T safe_sqrt(T x){
    return sqrt(max(x,(T)0));
}
template <class T,class U,class V>
T addmod(T x,U k,V MOD){
    return ((x+k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T submod(T x,U k,V MOD){
    return ((x-k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T mul(T x,U y,V MOD){
    return ( (x % MOD) * (y % MOD) ) % MOD;
}

#define ll long long
#define pll pair <ll,ll>
#define pii pair <int,int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define emp emplace_back
#define MASK(i) ((1LL)<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)((c).size())
#define fn "test"    ///FILE_NAME_HERE

/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/

namespace task{

	const int N = 1e5 + 5;
	vector <int> adj[N];
	vector <int> topo;
	int f[N];
	bool vis[N];
	int n,m;

	void dfs(int u){
		vis[u] = true;
		for(int i = 0;i < sz(adj[u]);++i){
			int v = adj[u][i];
			if(vis[v])continue;
			dfs(v);
		}
		topo.emp(u);
	}

    void solve(){
    	cin>>n>>m;
    	for(int i = 1;i <= m;++i){
    		int u,v;
    		cin>>u>>v;
    		adj[u].emp(v);
    	}
    	for(int i = 1;i <= n;++i){
    		if(!vis[i]){
    			dfs(i);
    		}
    	}
    	for(int i = sz(topo) - 1;~i;--i){
    		int u = topo[i];
    		for(auto v : adj[u]){
    			maximize(f[v],f[u] + 1);
    		}
    	}
    	cout<<*max_element(f + 1,f + 1 + n);
    }
}

int main(void){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    task::solve();
}


Measured memory_bytes: 8824
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 1055050
ll dp[50][1<<20];
vector<ll> change(int x){
    vector <ll> v;
    int count=0;
    while(x){
        count++;
        if(x%2){v.pb(count);count=0;}
        x/=2;
    }
    return v;
}
int change2(vector<ll> v){
    ll now=1;
    ll ans=0;
    for(auto e:v){
        rep(i,e)now*=2;
        ans+=now/2;
    }
    return ans;
}
bool judge[N];
ll pw[50];
main(){
    ll n=in();
    ll x[3];
    rep(i,3)x[i]=in();
    int sum=x[0]+x[1]+x[2];
    vector<pair<vector<ll>,ll>> v;
    vector<ll> vvv;
    v.pb({vvv,1ll});
    ll ans=0;
    pw[0]=1;
    rep(i,20)pw[i+1]=pw[i]*2;
    dp[0][0]=1;
    vector<ll> tmp={2,3};
    vec all;
    rep(i,1<<sum){
        if((i&(1<<(x[2]-1))&&(i&(1<<(x[2]+x[1]-1))&&(i&1<<(sum-1)))))judge[i]=1;
        else all.pb(i);
    }
    rep(i,n){
        for(auto k:all){
            if(dp[i][k]==0)continue;
            rep2(j,1,7){
                ll next=(k*pw[j]+pw[j-1])%pw[sum];
                if(!judge[next])
                dp[i+1][next]=(dp[i][k]+dp[i+1][next])%MOD;
            }
            dp[i+1][0]=(dp[i+1][0]+dp[i][k]*3)%MOD;
        }
    }
    ll p=1;
    rep(i,n){
        p=p*10ll%MOD;
    }
    rep(i,1<<sum){
        p=(p-dp[n][i]+MOD)%MOD;
    }
    cout<<p<<endl;
}

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

#define LLINF (1LL<<60)
typedef long long ll;

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

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

//C++14 (GCC 5.4.1)
int main() {
    int N;
    cin >>N;

    vector<int> A(N),B(N),P(N);
    rep(i,N) cin >> A[i]>>B[i];
    rep(i,N) P[i]=i;
    sort(P.begin(),P.end(),[&](int a,int b){
        return B[a]<B[b];
    });
    //-----------------------------------
    bool is=true;
    
    /* rep(i,N) cout<< A[P[i]]<<B[P[i]]<<endl;*/

    int time=0;
    rep(i,N){
        time+=A[P[i]];
        if(time>B[P[i]]){
            is=false;
            break;
        } 
    }

    cout << ((is) ? "Yes" : "No") <<endl;
    return (0);
}

Measured memory_bytes: 2560
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 1e6 + 6, mod = (int) 0;
vector<int> adj[N];
int dfs(int v, int p = -1) {
	int res = 0;
	for (int u : adj[v])
		if (u != p) {
			res ^= dfs(u, v) + 1;
		}
	return res;
}
int main() {
	int n;
	cin >> n;
	for (int j = 0; j < n - 1; ++j) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	int res = dfs(0);
	if (res) {
		cout << "Alice\n";	
	} else {
		cout << "Bob\n";
	}
}





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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> mat;

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 n;
vector<double> v;

void solve() {
  cin >> n;
  v.resize(n);
  rep(i, 0, n) cin >> v[i];

  SORT(v);
  double ans = v[0];
  rep(i, 1, n) { ans = (ans + v[i]) / 2.0; }
  cout << ans << endl;
}

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

  cout << fixed << setprecision(10);

  solve();

  return 0;
}


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

const int maxn=106;
int x[maxn],n;
long long ans=2e18;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",x+i);
	sort(x+1,x+n+1);
	for(int i=x[1];i<=x[n];++i) {
		long long sum=0;
		for(int j=1;j<=n;++j) sum+=(x[j]-i)*(x[j]-i);
		ans=min(ans,sum);
	}
	printf("%lld",ans);
}

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

using namespace std;
#define ll long long int

int main()
{
    ll t;
    t = 1;
    // cin t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[n];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        ll p = 1;
        sort(a , a+n);
        for (int i =0 ; i < n ; i ++)
        {
            long double temp= 1000000000000000000 * 1.0;
            if((long double)a[i] > temp / p)
            {
                cout << "-1" << endl;
                return 0;
            }
            p = p *a[i];
        }
        cout << p <<endl;
    }
}


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

using ll = long long;
using std::cout;
using std::cin;

int main(){
    ll k,n;
    cin >> k >> n;
    std::vector<ll> distance(n);
    ll pos0, prev_pos;
    cin >> pos0;
    prev_pos = pos0;
    for(int i=0; i<n-1; i++){
        ll a;
        cin >> a;
        distance[i] = a-prev_pos;
        prev_pos = a;
    }
    distance[n-1] = k-prev_pos + pos0;

    std::sort(distance.begin(), distance.end());

    cout << k - distance[n-1] << "\n";
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int D = cin.nextInt();
        if (D == 25)
        {
            Console.WriteLine("Christmas");
        }
        else if (D == 24)
        {
            Console.WriteLine("Christmas Eve");
        }
        else if (D == 23)
        {
            Console.WriteLine("Christmas Eve Eve");
        }
        else if (D == 22)
        {
            Console.WriteLine("Christmas Eve Eve Eve");
        }
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

Measured memory_bytes: 11092
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long li;

int main(void) {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  c = min(c, a + b  +1);
  printf("%d\n", b + c);
}


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

int main(){
    char s1[10], s2[10], s3[10];
    char x, y, z;
    cin >> s1 >> s2 >> s3;
    x=toupper(s1[0]);
    y=toupper(s2[0]);
    z=toupper(s3[0]);
    cout << x << y << z << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;
int main(){
  int a,b; cin >>a >>b;
  cout <<a*b;
return 0;}

Measured memory_bytes: 3600
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let xx = (0..n).map(|_| read::<i32>()).collect::<Vec<_>>();
    let mut ans = i32::max_value();

    use std::cmp::min;
    for i in 0..n - k + 1 {
        let d = xx[i + k - 1] - xx[i];
        let d1 = xx[i].abs() + d;
        let d2 = (xx[i + k - 1]).abs() + d;
        ans = min(ans, min(d1, d2))
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
ABCK = list(map(int,input().split()))

A = ABCK[0]
B = ABCK[1]
C = ABCK[2]
K = ABCK[3]

count = 0

if A >= K:
    count = 1 * K
else:
    count = 1 * A  + (-1) * (K - (A + B))


print(count)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main() {
    int n;
    scanf("%d", &n);

    int count = 0;
    int d1, d2;
    rep(i, n) {
        scanf("%d %d", &d1, &d2);
        if (d1 == d2)
            count++;
        else
            count = 0;
        if (count == 3) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

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


int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n-1;i++){
		int b;
		cin >> b;
		a.at(b-1)++;
	}
	for(int i=0;i<n;i++){
		cout << a.at(i) << endl;
	}
}

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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

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

const int N = (int)1e5 + 123, mod = (int)1e9 + 7;

int n, ans, a[N];
int main(){    
	cin >> n;
	n += n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
 	sort(a, a + n);            

 	for(int i = 0; i < n; i+=2)
 		ans += a[i];
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  ll cnt = 0;
  for (int i = 0; i < S.length(); i++) {
    ll c = 1;
    int start = i;
    while (i + c < S.length() && S[i] == S[start + c]) {
      c++;
    }
    cnt = max(cnt, c);
  }
  if (cnt >= 3)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;

int h, w;
vector<string> s;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
vector< vector<bool> > visited;

long long int func(int sx, int sy) {
  if(visited[sy][sx]) return 0;
  visited[sy][sx] = true;
  queue< pair<int, int> > q;
  q.push({sx, sy});
  long long int a = 0, b = 0;
  while(!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first;
    int y = p.second;

    if(s[y][x] == '.') a++;
    else b++;

    for(int i=0; i<4; i++) {
      int tx = x + dx[i];
      int ty = y + dy[i];
      if(tx < 0 || ty < 0 || tx >= w || ty >= h) continue;
      if(s[y][x] == s[ty][tx]) continue;
      if(visited[ty][tx]) continue;
      visited[ty][tx] = true;
      q.push({tx, ty});
    }
  }
  return a*b;
}

int main() {
  cin >> h >> w;
  s.resize(h);
  visited.resize(h, vector<bool>(w, false));
  for(int i=0; i<h; i++) cin >> s[i];

  long long int cnt = 0;
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cnt += func(j, i);
    }
  }
  cout << cnt << endl;

  return 0;
}


//EOF


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

int main()
{
    char a[10],b[10],c[10];
    scanf("%s",a);
    scanf("%s",b);
    scanf("%s",c);
    if(a[strlen(a)-1]==b[0] && b[strlen(b)-1]==c[0])
        printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

    ll n,k;
    cin>>n>>k;
    vector<vector<ll>>v(n);
    for(int i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        x--;
        y--;
        v[y].push_back(x);
        v[x].push_back(y);
    }
    for(int i=0;i<n;i++)
    {
        cout<<v[i].size()<<endl;
    }

}


Measured memory_bytes: 3652
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

bool check(int s){
  for(int i = 1; i * i <= s; i++)
    if((s - i) % (2 * i + 1) == 0)
      return true;
  return false;
}

int main(){
  const int n = getInt();
  int cnt = 0;

  REP(i,n)
    if(!check(getInt())) cnt++;

  printf("%d\n", cnt);

  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    for(int i=0;i<a;i++){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
	cin.tie(0);	ios::sync_with_stdio(false);

  int i,N; cin >> N;
  i = N / 1000; if(N%1000!=0){i++;}
  cout << i * 1000 - N << endl;

  return 0;
}


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

void CompareAndPrint(int a, int b)
{
	if(a < b){
		cout << "a < b"  << endl;
	}else if(a == b){
		cout << "a == b" << endl;
	}else{
		cout << "a > b"  << endl;
	}
}

int main()
{
	int a, b;
	cin >> a >> b;
	CompareAndPrint(a, b);
	return 0;
}

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int N; cin >> N;
  int ans = 0;
  rep1(i, N) {
    if (i % 2 == 0) continue;
    int count = 0;
    rep1(j, i) {
      if (i % j == 0) count++;
    }
    if (count == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# code-festival-2016-qualaC - 次のアルファベット / Next Letter
from string import ascii_lowercase as abc


def main():
    S = input().rstrip()
    K = int(input())
    # dist[c] := distance to "a" through "z"
    dist = {c: 26 - i for i, c in enumerate(abc)}
    dist["a"] = 0
    A = [dist[i] for i in S]
    ans = ""
    for i, s in zip(A[:-1], S[:-1]):
        if 0 < i <= K:  # change s to "a" if possible
            ans += "a"
            K -= i
        else:
            ans += s
    # use the remaining K on A[-1] and combine with ans
    ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a"))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 5532
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

// MOD確認

int main(){
    long double A,B,H,M;
    cin >> A >> B >> H >> M;
    long double ans = 0;
    ans = sqrt(A * A + B * B - 2 * A * B * cos(PI * 2 * ((H / 12 + M / 60 / 12) - M / 60)));
    cout << setprecision(30) << fixed;
    cout << ans << endl;
} 


Measured memory_bytes: 4160
#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 A[1000000], n;

int binarySearch(int key) {
    int left = 0;
    int right = n;
    int mid;
    while(left < right) {
        mid = (left+right) / 2;
        if (key == A[mid]) return 1; //key を発見
        if (key > A[mid]) left = mid + 1;
        else if (key < A[mid]) right = mid;
    }
    return 0;
}

int main() {
    int i, q, k, sum = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &k);
        if (binarySearch(k)) sum++;
    }
    printf("%d\n", sum);

    return 0;
}


Measured memory_bytes: 3596
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int main() {
	ll n;
	cin>>n;
	ll ans = 0;
	for(ll i=1;i<=n;i++){
		ll t = n/i;
		int b1 = i,b2 = i*t;
		ll sum = (b1+b2)*t/2;
		ans+=sum;
	}
	cout<<ans<<endl;
//	cout<<cnt<<endl;
}

Measured memory_bytes: 3632
n,k=map(int,input ().split())
w=[]
v=[]
for _ in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
dp=[[-1 for i in range(k+1)] for j in range(n+1)]
for i in range(k+1):
    dp[0][i]=0
for i in range(n+1):
    dp[i][0]=0
for j in range(1,k+1):
    for i in range(1,n+1):
        if j>=w[i-1]:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1])
        else:
            dp[i][j]=dp[i-1][j]

print(dp[-1][-1])


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

bool IsPrime(int m)
{
    for(int i = 2; i <= sqrt(m * 1.0); i++){
        if(m % i == 0) return false;
    }
    return true;
}

int main()
{
    int i, n, a[10000], count;
    cin >> n;
    for(i = 0; i < n; i++) cin >> a[i];

    count = 0;
    for(i = 0; i < n; i++){
        if(IsPrime(a[i])) count++;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main {
    final double EPS = 1.0e-10;
    final int INF = 1 << 22;
    int m;
    int n;
    int bs[];

    void run() {
        Scanner sc = new Scanner(System.in);
        double r = 1.0 / Math.sqrt(3.0);
        double pi = Math.pow(Math.E, 1.1447298858494);
        while (true) {
            int n = sc.nextInt();
            if (n == 0)
                break;
            if (n % 3 == 0) {
                double th = pi / n;
                double area = 1.0 / 6 / (1.0 / r + 1.0 / Math.tan(th));
                System.out.printf("%.8f\n", 2 * n * area);
            } else {
                double th = pi / 3 / n;
                double area = 1.0 / 6 / (1.0 / r + 1.0 / Math.tan(th));
                System.out.printf("%.8f\n", 6 * n * area);
            }
        }
    }

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

Measured memory_bytes: 13000
h,w=map(int,input().split())
A=list('.'*(w+2))
MAP=[A]
for _ in range(h):
    MAP.append(list('_'+input()+'_'))
MAP.append(A)
for i in range(1,h+1):
    for j in range(1,w+1):
        if MAP[i][j]=='.':
            MAP[i][j]=str((MAP[i-1][j-1]+MAP[i-1][j]+MAP[i-1][j+1]+MAP[i][j-1]+MAP[i][j+1]
                            +MAP[i+1][j-1]+MAP[i+1][j]+MAP[i+1][j+1]).count('#'))
for i in range(1,h+1):
    print(''.join(MAP[i][1:w+1]))

Measured memory_bytes: 3188
#include<cstdio>
int a,b,c,i,j,n,s;
int main(void){
    scanf("%d%d%d%d",&a,&b,&c,&n);
    for (i=0;i<=a;i++)
     for (j=0;j<=b;j++)
      if ((n-i*500-j*100>=0)&&(n-i*500-j*100<=c*50)) ++s;
    printf("%d\n",s);
}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,w;
	ll		ans = 0;
	string	s;
	cin >> h >> w;
	vector<string>	ms(h);
	for(i=0;i<h;i++) cin >> ms[i];
	vector<int> x = {-1,0,+1,-1,+1,-1,0,+1};
	vector<int> y = {-1,-1,-1,0,0,+1,+1,+1};

	for(i=0;i<h;i++) for(j=0;j<w;j++) {
		ans = 0;
		if (ms[i][j]=='#') continue;
		for(k=0;k<8;k++) {
			if (i+x[k]>=0 && i+x[k]<h && j+y[k]>=0 && j+y[k]<w && ms[i+x[k]][j+y[k]]=='#') ans++;
		}
		ms[i][j]=ans+'0';
	}

	for(i=0;i<h;i++) cout << ms[i] << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

rn = S.count('R')
gn = S.count('G')
bn = S.count('B')

eqn = 0
for i in range(N):
    for j in range(i+1, N):
        k = j + (j-i)
        if k < N and S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            eqn += 1

ans = rn * gn * bn - eqn

print(ans)


Measured memory_bytes: 68004
import Control.Monad
import Control.Applicative
import Data.List

solve :: [[Int]] -> [String]
solve ([n,m,l]:matxs) =
    let (matA,matB) = splitAt n $ matxs in
    let mAB = [[sum $ zipWith (*) a b | b<-transpose matB] | a<-matA] in
    map (unwords . map show) mAB

main =
    mapM_ putStrLn =<< solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Int]]
    takeInputs = map (map read . words)

Measured memory_bytes: 12208
# union fine tree

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

# init
parent = [i for i in range(n)]
rank = [1] * n
size = [1] * n

def find(x):
	if parent[x] == x:
		return x
	else:
		parent[x] = find(parent[x])
		return parent[x]

def unite(x, y):
	x, y = find(x), find(y)
	if x == y:
		return 
	if rank[x] < rank[y]:
		parent[x] = y
		size[y] += size[x]
	else:
		parent[y] = x
		size[x] += size[y]
		if rank[x] == rank[y]:
			rank[x] += 1

def same(x, y):
	return find(x) == find(y)

def groupSize(x):
	return size[find(x)]

A, B = [0] * m, [0] * m
C, D = [0] * k, [0] * k

net = [[] for _ in range(n)]

for i in range(m):
	a, b = map(int, input().split())
	A[i] = a - 1
	B[i] = b - 1
	net[A[i]].append(B[i])
	net[B[i]].append(A[i])
	unite(A[i], B[i])

for i in range(k):
	c, d = map(int, input().split())
	C[i] = c - 1
	D[i] = d - 1
	if same(C[i], D[i]):
		net[C[i]].append(D[i])
		net[D[i]].append(C[i])

res = [0] * n
for i in range(n):
	res[i] = groupSize(i) - len(net[i]) - 1
print(*res)

Measured memory_bytes: 125544
n,m=map(int,input().split())
ids=[list(map(int,input().split())) for i in range(m)]
for i in range(m):
    ids[i].append(i)
ids.sort()
ans=[]
tmp=ids[0][0]
x=0
for i in ids:
    if tmp==i[0]:
        x+=1
        ans.append([i[2],i[0],x])
    else:
        tmp=i[0]
        x=1
        ans.append([i[2],i[0],x])
ans.sort()        
for i in ans:
    p,x=str(i[1]).zfill(6),str(i[2]).zfill(6)
    print(p,x,sep='')    


Measured memory_bytes: 42564