akhauriyash/Code-Regression huggingface dataset:
use std::io;

fn main() {
    let values = parse_values::<u32>(2);
    let k = values[0];
    let x = values[1];
    let sum = 500 * k;
    if sum >= x {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn parse_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn parse_values<T: std::str::FromStr>(n: usize) -> Vec<T> {
    let line = parse_line::<String>();
    let mut split = line.split_whitespace();
    let mut values = Vec::with_capacity(n);
    for _ in 0..n {
        let v = split.next().unwrap().parse::<T>().ok().unwrap();
        values.push(v);
    }
    values
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;

LL inf = 1000000000000;
LL mod = 1000000007;

int main()
{
	string s1, s2, s3;
	LL a, b;

	cin >>s1 >> s2 >> a >> b >> s3;

	if (s3 == s1) {
		a--;
	}
	else {
		b--;

	}

	cout << a << " " << b << "\n";


	
}

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

ans = S.count('E')
if S[0] == 'E':
    ans -= 1

arr =[]
arr.append(ans)

for i in range(1,N,1):
    if S[i-1] == 'W':
        ans += 1
    if S[i] == 'E':
        ans -= 1
    arr.append(ans)

print(min(arr))


Measured memory_bytes: 92708
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
ll dp[2][4];
int now = 0;
int t[3];
ll p2[32];
bool use[100010];
int arr[256];
void Sequence() {
	char a, b;
	cin >> a >> b;
	if (a == b) {
		cout << "H" << endl;
	}else 
		cout << "D" << endl;
}
int main() {
	Sequence();
	return 0;
}



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

int main() {
    long long N, tmp, left, right;
    long long ans=0;
    vector<long long> ab(100, 0);
    string s;
    cin >> N;

    for(long long i=1; i<=N; i++){
	tmp=i;
	s=to_string(tmp);
	left=s[0]-'0';
	right=s[s.size()-1]-'0';

	if(left!=0 && right!=0)
	    ab[10*left+right]++;
    }

    for(long long i=11; i<=99; i++){
	tmp=i;
	s=to_string(tmp);
	left=s[0]-'0';
	right=s[s.size()-1]-'0';

	ans += ab[10*left+right]*ab[10*right+left];
    }

    cout << ans << endl;
}



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


int main(){
	int n;cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	vector<int> dp(n);
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-1] + abs(arr[i]- arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]) ) ;
	}
	cout<<dp[n-1];
	
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = 1LL<<55;
const Int mod = (1e9)+7;
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  set<int> S;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    S.insert(a);
  }

  int q;
  cin>>q;
  while(q--){
    int k;
    cin>>k;
    int ans = S.count(k);
    cout<<ans<<endl;
  }
  

  
  return 0;
}



Measured memory_bytes: 7820
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());

        String[] a = sc.nextLine().split(" ");
        int[] array = new int[num];
        for (int i = 0; i < num; i++) {
            array[i] = Integer.parseInt(a[i]);
        }

        int changeCount = 0;

        int minj;
        for (int i = 0; i < num; i++) {
            minj = i;

            for (int j = i; j < num; j++) {
                if (array[j] < array[minj]) {
                    minj = j;
                }
            }
            
            if (i != minj) {
                int tmp = array[i];
                array[i] = array[minj];
                array[minj] = tmp;
                changeCount++;
    
            }
        }
        
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        }
        System.out.println();

        System.out.println(changeCount);
    }
}

/**
1 bubbleSort(A, N) // N 個の要素を含む 0-オリジンの配列 A
2   flag = 1 // 逆の隣接要素が存在する
3   while flag
4     flag = 0
5     for j が N-1 から 1 まで
6       if A[j] < A[j-1]
7         A[j] と A[j-1] を交換
8         flag = 1

入力例 1
5
5 3 2 4 1
出力例 1
1 2 3 4 5
8
 */


Measured memory_bytes: 26168
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
using PII = pair<ll, ll>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())
#define MP make_pair

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);

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

    // input
    ll X; 
    cin >> X;

    FOR(t, 1, 100000){
      if(X<=t*(t+1)/2){
        p(t);
        return 0;
      }
    }
    
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
graph = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

s = 0 
visited = [False]*(N)
visited[0] = True
def search(s,visited):
    if sum(visited) == N :
        return 1
    else :
        ret = 0 
        for i in graph[s]:
            if visited[i] :
                continue
            visited[i] = True 
            ret += search(i,visited)
            visited[i] = False
    return ret
print(search(s,visited))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> sum_E(N);
  vector<int> sum_W(N);

  int sum = 0;
  for(int i=0; i<N; i++) {
    sum_W[i] = sum;
    if (S[i] == 'W') sum++;
  }
  sum = 0;
  for(int i=N-1; i>=0; i--) {
    sum_E[i] = sum;
    if (S[i] == 'E') sum++;
  }

  int mn = N;
  rep(i, N) {
    if (mn > sum_E[i] + sum_W[i]) mn = sum_E[i] + sum_W[i];
  }

  cout << mn << endl;

  return 0;
}


Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int b[] = new int[n-1];
		int a[] = new int[n];
		int ans = 0;

		for(int i = 0;i<n-1;i++){
			b[i] = sc.nextInt();
		}
		sc.close();

		for(int i = 0;i<n;i++){
			if(i == 0){
				a[i] = b[i];
			}else if(i == n-1) {
				a[i] = b[i-1];
			}else{
				a[i] = Math.min(b[i],b[i-1]);
			}
		}
		for(int i = 0;i<n;i++){
			ans += a[i];
		}

System.out.println(ans);
	}
}


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

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

  ll ans = n;
  set<ll> st;
  st.insert(n);
  while (true) {
    ll t;
    if (n >= k) t = n%k;
    else t = abs(k-n);
    ans = min(t, ans);
    n = t;
    if (st.count(t) > 0) break;
    st.insert(t);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include "algorithm"
#include "cmath"
#include "iomanip"
#include "iostream"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

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>
void drop(const T& x) {
  cout << x << endl;
  exit(0);
}

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

  ll N;
  cin >> N;
  V<ll> xs(N);
  rep(i, N) cin >> xs[i];

  ll ret = 1e18;

  rep1(x, 100) {
    ll sum = 0;

    rep(i, N) { sum += pow(xs[i] - x, 2); }

    chmin(ret, sum);
  }

  cout << ret << endl;

  return 0;
}


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

int main(void){
  double x1, y1, x2, y2;
  
  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  double diffx = pow(x1 - x2, 2.0);
  double diffy = pow(y1 - y2, 2.0);
  double distance = sqrt(diffx + diffy);

  printf("%lf\n", distance);
  return 0;
}

Measured memory_bytes: 652
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N = int(input())
    sl = [input().split() + [i+1] for i in range(N)]
    sl.sort(key=lambda x: (x[0], -int(x[1])))
    for i in sl:
        print(i[2])

if __name__ == '__main__':
    main()

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

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A.at(i);

    double ans = 0;
    for(int i = 0; i < N; i++) ans += (1. / A.at(i));
    ans = 1. / ans;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int inf=1001000000;
int n;
int a[100100];
int dp[100100];
// dp[i]=????????¨???????????????i?????????????°????//
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        dp[i]=inf;
    }
    for(int i=0;i<n;i++){
        auto it=lower_bound(dp,dp+n,a[i]);
        *it=a[i];
    }
    int ans=lower_bound(dp,dp+n,inf)-dp;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef vector<int> VI;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define OUT(v) cout<<v<<endl

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

  VI A;
  LL S = 0;
  REP(i, N) {
    int a;
    cin >> a;
    A.PB(a);
    S += a;
  }
  LL x_1 = S;
  REP(i, (N-1) / 2) {
    x_1 -= 2 * A[2 * i + 1];
  }
  int X[100000];
  X[0] = x_1;
  REP(i, N)
    X[i+1] = 2 * A[i] - X[i];
  REP(i, N-1)
    cout << X[i] << " ";
  cout << X[N-1] << endl;
  return 0;
}


Measured memory_bytes: 2168
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

int64 H, W;

int main() {
    cin >> H >> W;

    int64 ans = 1LL << 60;
    for (int j = 1; j <= H/2; ++j) {
        int64 s1 = j * W;
        int64 s2_1 = ((H-j)/2) * W, s3_1 = (H-j-(H-j)/2) * W;
        int64 d1 = max(s1, max(s2_1, s3_1)) - min(s1, min(s2_1, s3_1));

        int64 s2_2 = (H-j)*(W/2), s3_2 = (H-j)*(W-W/2);
        int64 d2 = max(s1, max(s2_2, s3_2)) - min(s1, min(s2_2, s3_2));
        ans = min(ans, min(d1, d2));
    }

    for (int j = 1; j <= W/2; ++j) {
        int64 s1 = j * H;
        int64 s2_1 = ((W-j)/2) * H, s3_1 = (W-j-(W-j)/2) * H;
        int64 d1 = max(s1, max(s2_1, s3_1)) - min(s1, min(s2_1, s3_1));

        int64 s2_2 = (W-j)*(H/2), s3_2 = (W-j)*(H-H/2);
        int64 d2 = max(s1, max(s2_2, s3_2)) - min(s1, min(s2_2, s3_2));
        ans = min(ans, min(d1, d2));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,n,i=0,j,c=0,p,mita[1000] ={0};
    cin >> x >> n;
    for(i=0;i<n;i++)
    {
        cin >> p;
        mita[p]=1; 
    }
    if(mita[x]==0)
    {
        cout << x << endl;
        return 0;
    }
    for(i=1;i<=n;i++)
    {
        if(mita[x-i]==0)
        {
            cout << x-i << endl;
            return 0;
        }
        if(mita[x+i]==0)
        {
            cout << x+i << endl;
            return 0;
        }
    }
    cout << x << endl;
    return 0;

}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

int main(){
    vl v(10.0);
    ll a,b,c,d; cin >> a >> b >> c >> d;
    v[a]++; v[b]++; v[c]++; v[d]++;
    if(v[1]&&v[4]&&v[7]&&v[9]) puts("YES");
    else puts("NO");
}

Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (a, b) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };

    if a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 {
      println!("Possible");
    } else {
      println!("Impossible");
    }
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    int N, M;
    cin >> N >> M;
    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll MOD = 1e9 + 7;

ll n, m, r;

ll p[9] = {};
ll q[9] = {};
ll v[9] = {};
ll d[201][201] = {};
ll ans = 1 << 29;

void wf() {
	repe(k, 1, n) {
		repe(i, 1, n) {
			repe(j, 1, n) {
				if (d[i][j] > d[i][k] + d[k][j]) {
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}
}
void dfs(ll n) {
	if (n == r + 1) {
		ll total = 0;
		rep(i, 1, r) {
			/*			cout << q[i] << " "*/;
			total += d[q[i]][q[i + 1]];
		}
		//cout << endl;
		ans = min(ans, total);
		return;
	}

	repe(i, 1, r) {
		if (!v[i]) {
			q[n] = p[i];
			v[i] = true;
			dfs(n + 1);
			v[i] = false;
		}
	}
}

int main()
{
	cin >> n >> m >> r;

	repe(i, 1, n) repe(j, 1, n) {
		if (i != j) {
			d[i][j] = 1 << 29;
		}
	}
	repe(i, 1, r) {
		cin >> p[i];
	}

	rep(i, 0, m) {
		ll A, B, T; cin >> A >> B >> T;
		d[A][B] = T;
		d[B][A] = T;
	}

	wf();

	dfs(1);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int x = max(max(a, b), c);
    int ans = 0;
    int shortage = 0;

    ans += (x - a) / 2;
    shortage += (x - a) % 2;
    ans += (x - b) / 2;
    shortage += (x - b) % 2;
    ans += (x - c) / 2;
    shortage += (x - c) % 2;

    if (shortage == 0)      cout << ans << endl;
    else if (shortage == 1) cout << (ans + 2) << endl;
    else                    cout << (ans + 1) << endl;

    return 0;
}

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

int main() {
  int W,H,N;
  cin>>W>>H>>N;
  vector<vector<int>> v(N, vector<int>(3));//0=しろ
  set<int> a1,a2,a3,a4;
  int x1=0,x2=W,y3=0,y4=H;
  rep(i,N) {
    cin>>v[i][0]>>v[i][1]>>v[i][2];
    if(v[i][2]==1) a1.insert(v[i][0]);
    else if(v[i][2]==2) a2.insert(v[i][0]);
    else if(v[i][2]==3) a3.insert(v[i][1]);
    else if(v[i][2]==4) a4.insert(v[i][1]);
  }
  if(a1.size()!=0)x1 = *rbegin(a1);
  if(a2.size()!=0)x2 = *begin(a2);
  if(a3.size()!=0)y3 = *rbegin(a3);
  if(a4.size()!=0)y4 = *begin(a4);  
  
  int ans=0;
  if(x2>x1&&y4>y3)ans=(x2-x1)*(y4-y3);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
     int N,a,b,c,d;
     cin>>N;
     a=N/1000;
     b=N/100;
     b=b%10;
     c=N/10;
     c=c%10;
     d=N%10;
     if(a==b&&b==c||b==c&&c==d)
cout<<"Yes";
else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define intt long long
using namespace std;
int i , j;
int main ()
{
    string s1,s2;
    cin >>s1 >> s2 ;
    int k = s1.size()+5;
    while ( k-- )
    {
        if ( s1 == s2 )
        {
            cout << "Yes\n";
            return 0;
        }
        s1 = s1.back() + s1;
        s1.pop_back();
//        cout << s1 << " " << s2 << endl;
    }
    cout << "No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

//ユークリッドの互除法
int euclidean_mdm(int A, int B) {
	if (A > B) {
		euclidean_mdm(B, A);
	}

	int temp;

	while (temp = A % B)
	{
		A = B;
		B = temp;
	}
	return B;
}

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

	int N;
	int tmp;

	cin >> N;

	vector<int> monster;

	REP(i, N) {
		cin >> tmp;
		monster.push_back(tmp);
	}

	tmp = monster[0];
	REP(i, N-1) {
		tmp = euclidean_mdm(tmp, monster[i + 1]);
	}

	cout << tmp << endl;

	return 0;
}

Measured memory_bytes: 892
// AtCoder ARC065 C - Daydream
// 2019.8.27 bal4u

#include <stdio.h>
#include <string.h>

#define gc() getchar_unlocked()

int ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	char *p = s--;
	do *++s = gc();
	while (*s > ' ');
	*s = 0;
	return s - p;
}

int N;
char S[100005];
				
int main()
{
	int i;
	
	N = ins(S);	
	i = 0; while (i < N) {
//printf("i=%d, N=%d\n", i, N);
		if (memcmp(S+i, "dream", 5) == 0 && memcmp(S+i+5, "erase", 5) == 0) i += 5;
		else if (memcmp(S+i, "dreamer", 7) == 0) i += 7;
		else if (memcmp(S+i, "dream", 5) == 0) i += 5;
		else if (memcmp(S+i, "eraser", 6) == 0) i += 6;
		else if (memcmp(S+i, "erase", 5) == 0) i += 5;
		else { puts("NO"); return 0; }
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll count_t = 0;
  ll count_a = 0;
  while (a > 0){
    a -= d;
    count_a++;
  }
  while(c>0){
    c -= b;
    count_t++;
  }
  if(count_t<=count_a){
    print("Yes");
  }
  else{
    print("No");
  }
}

Measured memory_bytes: 3640
n = int(input())
l=[]
for i in range(n):
  a,b = list(map(int,list(input().split())))
  l.append([a,b])
def fn(n,l):
  for i in range(n-2):
    if l[i][0]==l[i][1] and l[i+1][0]==l[i+1][1] and l[i+2][0]==l[i+2][1]:
      return 'Yes'
  return 'No'  
print(fn(n,l))

Measured memory_bytes: 9200
import java.util.*;

public class Main { 
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
	  String p = sc.next();
      int first = Integer.parseInt(p.substring(0,2));
      int second = Integer.parseInt(p.substring(2));
      
      boolean ff =0 < first&& first <= 12;
      boolean sf = 0 < second&&second <= 12;
 
      if (ff&&sf) {
        System.out.println("AMBIGUOUS");
    } else if (ff&&!sf) {
        System.out.println("MMYY");
    } else if (!ff&&sf) {
        System.out.println("YYMM");
     } else {
     System.out.println("NA");
      }
    }
}

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


void solve(){

    string s,t;
    cin>>s>>t;
    ll cnt=0,res=1000;
    for(ll i=0; i < s.size() - t.size() + 1; ++i){
        cnt = 0;
        for(ll j=0; j<t.size(); ++j){
            if(t[j] != s[i+j]){
                cnt++;
            }
        }

        res = min(res,cnt);
    }
    cout<<res;

}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int q;
    q=1;
    // cin>>q;
    while(q--) solve();


    return 0;
}


Measured memory_bytes: 3556
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <utility>
#include <memory>
#include <valarray>

using namespace std;

using ll = long long int;
#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanInt(M);
    vector<unordered_set<int>> edges(N);
    loop(i, M){
        int ai, bi;
        scanf("%d %d\n", &ai, &bi); --ai; --bi;
        edges[ai].emplace(bi);
        edges[bi].emplace(ai);
    }
    scanInt(Q);
    vector<tuple<int, int, int>> query(Q);
    loop(i, Q){
        int vi, di, ci;
        scanf("%d %d %d\n", &vi, &di, &ci); --vi;
        query[Q - 1 - i] = make_tuple(vi, di, ci);
    }
    vector<int> colors(N, 0);
    vector<int> filled(N, -1);
    loop(q, Q){
        queue<tuple<int, int>> next_nodes;
        next_nodes.emplace(get<0>(query[q]), get<1>(query[q]));
        auto& color = get<2>(query[q]);
        while (!next_nodes.empty()){
            auto node = get<0>(next_nodes.front());
            auto distance = get<1>(next_nodes.front());
            next_nodes.pop();
            if (colors[node] == 0) colors[node] = color;
            if (filled[node] < distance){
                filled[node] = distance;
                if (distance >= 1){
                    for (auto& next : edges[node]){
                        next_nodes.emplace(next, distance - 1);
                    }
                }
            }
        }
    }
    loop(i, N) printf("%d\n", colors[i]);
}


Measured memory_bytes: 19236
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000;
const int MOD = (int)1e9 + 7;
using P = pair<int, int>;
int H, W;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
vector<string> maze;
map<P, int> visited;

bool isIn(int y, int x, int H, int W)
{
    return 0 <= x && x < W && 0 <= y && y < H;
}

P dfs(int h, int w)
{
    if (visited[P(h, w)]) return P(0, 0);
    visited[P(h, w)]++;
    int black = 0;
    int white = 0;
    char currentChar = maze[h][w];
    if (currentChar == '#') black++;
    if (currentChar == '.') white++;
    P res = P(black, white);
    for (int i = 0; i < 4; i++)
    {
        int next_h = h + dy[i];
        int next_w = w + dx[i];
        if (!isIn(next_h, next_w, H, W)) continue;
        if (maze[next_h][next_w] == currentChar) continue;
        P tmp = dfs(next_h, next_w);
        res.first += tmp.first;
        res.second += tmp.second;
    }
    return res;
}

signed main()
{
    cin >> H >> W;
    for (int i = 0; i < H; i++)
    {
        string x;
        cin >> x;
        maze.push_back(x);
    }

    int cnt = 0;
    for (int h = 0; h < H; h++)
    {
        for (int w = 0; w < W; w++)
        {
            P res = dfs(h, w);
            cnt += res.first * res.second;
        }
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 32896
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

int main() {
    
    long long A[50];
    long long K;
    cin >> K;
    
    for ( int i = 0; i < 50; i++ ) {
        A[i] = i;
    }
    
    for ( int i = 0; i < 50; i++ ) {
        A[i] += K / 50;
    }
    
    for ( int i = 0; i < (K%50); i++ ) {
        for ( int j = 0; j < 50; j++ ) {
            A[j]--;
        }
        A[i] += 51;
    }
    
    cout << 50 << endl;
    for ( int i = 0; i < 49; i++ ) {
        cout << A[i] << " ";
    }
    cout << A[49] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int G[105][105];
int dis[105][105];
int n,m;
void floyd(){
    fore(k,0,n)
        fore(i,0,n)
            fore(j,0,n)
                dis[i][j] = min(dis[i][j],dis[i][k] + dis[k][j]);

}
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    fast;
    cin >> n >> m;
    int u,v,w;
    fore(i,0,105)
        fore(j,0,105)
            dis[i][j] = 1 << 20;
    fore(i,0,m){
        cin >> u >> v >> w;
        u--;
        v--;
        G[u][v] = G[v][u] = w;
        dis[u][v] = dis[v][u] = w;
    }
    
    floyd();
    int par = 0;
    fore(i,0,n)
        fore(j,0,n)
            par = max(par,dis[i][j]);
    int ans = 0;
    fore(i,0,n)
        fore(j,0,n)
            if(G[i][j] && G[i][j] > dis[i][j])
                ans++;
        
        
    cout << ans / 2 << '\n';
    return 0;   
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <stdlib.h>
using namespace std;
#define         rep(i,n)       for (int i = 0;i<(int)(n);i++)
#define         rep1(i,n)      for (int i = 1;i<=(int)(n);i++)
#define         sajo(str)      sort(str.begin(),str.end())
#define         pi             3.14159265359
#define         neli            printf("\n")
#define         gcd(a,b)       __gcd(a,b)
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         pf             printf
#define         sf             scanf
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
typedef long long int ll;

int main()
{

    FIO;
    int i,j,k,q,temp,n,x,f=0;int a[N];

    cin>>i>>j;
    if(i<10&&j<=9)
        cout<<i*j<<endl;
    else
        cout<<"-1"<<endl;

    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin >> n;

  vector<ll> a(n);
  REP(i, n)
    cin >> a[i];

  vector<ll> r = {1, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200};
  map<ll, ll> rmap;
  REP(i, n){
    REP(j, r.size()){
      if(a[i] < r[j]){
        rmap[j-1]++;
        break;
      }
      if(j == r.size() - 1)
        rmap[j]++;
    }
  }

  ll sum = 0;
  REP(j, r.size()){
    if(j == r.size()-1)
      sum += rmap[j];
    else if(rmap[j] != 0)
      sum++;
  }

  if(sum - rmap[r.size()-1] != 0)
    cout << sum - rmap[r.size()-1] << " " << sum << endl;
  else
    cout << 1 << " " << sum << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String str = sc.nextLine();
		int [] a = new int[n];
		for (int i=0; i<k; i++) {
			int d = sc.nextInt();
			str = sc.nextLine();
			for (int j=0; j<d; j++) {
				a[sc.nextInt() - 1] = 1;
			}
		}
		sc.close();
		int ans = 0;
		for (int i=0; i<n; i++) {
			if (a[i]== 0) {
				ans+=1;
			}
		}
		System.out.println(ans);
	}
}


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

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

Measured memory_bytes: 256
class RadixHeap:
    __slots__ = ["data", "last", "siz", "used"]

    # (max_key - min_key) <= C
    def __init__(self, N, C):
        self.data = [[] for i in range(C.bit_length() + 1000)]
        self.last = self.siz = 0
        self.used = [0] * N

    def push(self, x, key):
        # assert self.last <= x
        self.siz += 1
        self.data[(x ^ self.last).bit_length()].append((x, key))

    def pop(self):
        data = self.data
        used = self.used
        # assert self.siz > 0
        if not data[0]:
            i = 1
            while not data[i]:
                i += 1
            d = data[i]
            new_last, new_key = min(d)
            used[new_key] = 1
            for val in d:
                x, key = val
                if used[key]:
                    self.siz -= 1
                    continue
                data[(x ^ new_last).bit_length()].append(val)
            self.last = new_last
            data[i] = []
        else:
            new_last, new_key = data[0].pop()
            used[new_key] = 1
            self.siz -= 1
        return new_last, new_key

    def __len__(self):
        return self.siz

def dijkstra(N, G, s):
    que = RadixHeap(N, 10**9 + 1)

    dist = [10**18] * N
    dist[s] = 0
    que.push(0, s)
    while que:
        cost, v = que.pop()
        if dist[v] < cost:
            continue
        for w, c in G[v]:
            if cost + c < dist[w]:
                dist[w] = r = cost + c
                que.push(r, w)
    return dist

# ----------- #

n = int(input())
ABC = [tuple(int(x) for x in input().split()) for _ in range(n - 1)]
q, k = (int(x) for x in input().split())
queries = [tuple(int(x) for x in input().split()) for _ in range(q)]
G = [[] for _ in range(n)]
for a, b, c in ABC:
    a -= 1
    b -= 1
    G[a].append((b, c))
    G[b].append((a, c))
dist = dijkstra(n, G, k-1)
for x, y in queries:
    x -= 1
    y -= 1
    print(dist[x] + dist[y])


Measured memory_bytes: 132116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;


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(){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    long long max=-1000000000000000000;

    chmax(max, a*c);
    chmax(max, b*c);
    chmax(max, a*d);
    chmax(max, b*d);

    cout << max << endl;
    return 0;
}

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

int main(void) {                                                                
    int n, i;                                                                   
    char str[1002];                                                             
    char *pp;                                                                   
                                                                                
    scanf("%d ", &n);                                                           
                                                                                
    for (i = 0; i < n; i++) {                                                   
        fgets(str, 1002, stdin);                                                
        pp = str;                                                               
        while ((pp = strstr(pp, "Hoshino")) != NULL) {                          
            pp += 6;                                                            
            *pp = 'a';                                                          
        }                                                                       
        printf("%s", str);                                                      
    }                                                                           
                                                                                
    return 0;                                                                   
}

Measured memory_bytes: 604
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N ;
    cin >> N ;
    vector<ll> V(N), C(N);

    rep(i, N) cin >> V[i];
    rep(i, N) cin >> C[i];

    
    ll ans = 0 ;
    rep(i, N){
        if( V[i] > C[i]) {
            ans += (V[i]- C[i]) ;
        }
    }
    
    cout << ans << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  long long k,a,b;
  cin>>k>>a>>b;
  long long ans;
  if(b<=a+1){
    cout<<k+1<<endl;
  }else if(a+1>k){
    cout<<k+1<<endl;
  }else{
    if((k-a-1)%2==0){
      ans = b + (b-a)*((k-a-1)/2);
    }else{
      ans = b + (b-a)*((k-a-1)/2) + 1;
    }
    cout<<ans<<endl;
  }
    
  
  return 0;
}


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

using namespace std;

int main() {
    int32_t q;
    cin >> q;

    while (q--) {
        string X, Y;
        cin >> X >> Y;

        vector<int32_t> lcs((X.size()+1)*(Y.size()+1));
        fill(lcs.begin(), lcs.end(), 0);

        for (int32_t i = 1; i <= X.size(); i++) {
            for (int32_t j = 1; j <= Y.size(); j++) {
                lcs[i*(Y.size()+1)+j] = max(lcs[(i-1)*(Y.size()+1)+j], lcs[i*(Y.size()+1)+j-1]);
                if (X[i-1] == Y[j-1]) {
                    lcs[i*(Y.size()+1)+j] = max(lcs[i*(Y.size()+1)+j], lcs[(i-1)*(Y.size()+1)+j-1] + 1);
                }
            }
        }

        cout << lcs.back() << endl;

    }

    return 0;
}

Measured memory_bytes: 7028
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

class BIT {
  vector<int> num;
public:
  BIT (int n) {
    num.resize(n+1, 0);
  }
  void add(int i, int n) {
    while (i < num.size()) {
      num[i] += n;
      i += i & -i;
    }
  }
  int sum(int i) {
    int res = 0;
    while (i > 0) {
      res += num[i];
      i -= i & -i;
    }
    return res;
  }
  void clear() {
    for (int i = 1; i < num.size(); i++)
      num[i] = 0;
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<BIT> alf(26, BIT(n));
  rep(i, s.size())
    alf[s[i]-'a'].add(i+1, 1);
  rep(query, q) {
    int x;
    cin >> x;
    if (x == 1) {
      int i;
      char c;
      cin >> i >> c;
      --i;
      alf[s[i]-'a'].add(i+1, -1);
      alf[c-'a'].add(i+1, 1);
      s[i] = c;
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      int res = 0;
      rep(i, 26) {
        if (alf[i].sum(r)-alf[i].sum(l))
          res++;
      }
      cout << res << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 53660
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	while(cin >>a>>b>>c){
		bool card[11] = {0};
		double sum = 0;
		card[a] = card[b] = card[c] = true;
		for(int i=1;i<11;i++){
			if(a+b+i<=20 && !card[i]){sum++;}
		}
		if(sum/7 >= 0.5){cout <<"YES"<<endl;}
		else{cout <<"NO"<<endl;}
	}
	return 0;
}

Measured memory_bytes: 0
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
//fixed<<setprecision(10)<<ans<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,C;
    cin >> N >> C;
    vector<vector<pair<int,int>>> ST_groupBy_C(C);
    int s,t,c;
    int last = 0;
    REP(i,N){
        cin >> s >> t >> c;
        c--;
        chmax(last,t);
        ST_groupBy_C[c].push_back(mp(s,t));

    }
    vector<int> cnt(last+1);
    REP(c,C){
        sort(ALL(ST_groupBy_C[c]));
        int idx = 0;
        // debug(ST_groupBy_C[c])
        REP(now,last+1){
            if(idx>=ST_groupBy_C[c].size()){
                break;
            }
            tie(s,t) = ST_groupBy_C[c][idx];
            // cout << s << " " << now << " "<< t << " " << (s-1<=now && now <= t) << endl;
            if(s<=now && now <= t){
                cnt[now]++;
            }
            if (t <= now) idx++;


        }
        // cout << cnt;

    }
    int ans=0;
    for(auto c:cnt) chmax(ans,c);



    cout << ans << endl;
}

Measured memory_bytes: 1920
H, W = map(int, input().split())
gridlist = [list(input()) for i in range(H)]

matrix = [[1]*W for i in range(H)]

# print(matrix)
for i in range(H):
    for j in range(W):
        if gridlist[i][j] == '#':
            matrix[i][j] = 0

# print(matrix)

for i in range(H):
    for j in range(W):
        up = 0
        left = 0
        if matrix[i][j] == 0:
            continue
        if i==0 and j == 0:
            continue
        if i > 0:
            left = matrix[i-1][j]
        if j > 0:
            up = matrix[i][j-1]
        matrix[i][j] = left + up
        # print(matrix)

print(matrix[i][j] % (10**9 + 7))







Measured memory_bytes: 165260