akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ans = 0;
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++){
  if (s.substr(i, 1) == "+") ans += 1;
  else if (s.substr(i, 1) == "-") ans -= 1;
  }
  cout << ans << endl;
}

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

void func(char *A, int n) {
  for (int i = 0; i < 5; ++i) {
    int r = n % 10;
    A[i] = '0' + r;
    n /= 10;
  }
}

int main() {
  int A, B;
  cin >> A >> B;

  char N[5];
  int ans = 0;
  for (int i = A; i <= B; ++i) {
    func(N,i);
    if (N[0] == N[4] && N[1] == N[3]) ++ans;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int solve(int N, int M, vector<vector<int>> A)
{
    auto check = [&](int k)
    {
        if (M==1 && k>=N)
            return true;

        vector<int> V(M, true);

        for (int r=0; r<M-1; r++)
        {
            vector<int> C(M, 0);

            for (int i=0; i<N; i++)
                for (int j=0; j<M; j++)
                    if (V[A[i][j]])
                    {
                        C[A[i][j]]++;
                        break;
                    }

            int m = *max_element(C.begin(), C.end());
            if (m <= k)
                return true;

            for (int j=0; j<M; j++)
                if (C[j] == m)
                {
                    V[j] = false;
                    break;
                }
        }
        return false;
    };

    int ans = 512;
    for (int b=256; b>0; b/=2)
        if (check(ans-b))
            ans -= b;
    return ans;
}

int naive(int N, int M, vector<vector<int>> A)
{
    int ans = N;

    for (int b=1; b<(1<<M); b++)
    {
        vector<int> C(M);
        for (int i=0; i<N; i++)
            for (int j=0; j<M; j++)
            if (b>>A[i][j]&1)
            {
                C[A[i][j]]++;
                break;
            }
        ans = min(ans, *max_element(C.begin(), C.end()));
    }
    return ans;
}

int main()
{
    /*
    int N = 2;
    int M = 1;

    while (true)
    {
        vector<vector<int>> A(N, vector<int>(M));

        for (int i=0; i<N; i++)
        {
            for (int j=0; j<M; j++)
                A[i][j] = j;
            random_shuffle(A[i].begin(), A[i].end());
        }

        int a1 = solve(N, M, A);
        int a2 = naive(N, M, A);

        if (a1 != a2)
        {
            cout<<"solve: "<<a1<<endl;
            cout<<"naive: "<<a2<<endl;
            for (int i=0; i<N; i++)
            {
                for (int j=0; j<M; j++)
                    cout<<" "<<A[i][j];
                cout<<endl;
            }
        }
    }
    */

    int N, M;
    cin>>N>>M;
    vector<vector<int>> A(N, vector<int>(M));
    for (int i=0; i<N; i++)
    for (int j=0; j<M; j++)
    {
        int a;
        cin>>a;
        A[i][j] = a-1;
    }

    cout<<solve(N, M, A)<<endl;
    //*/
}


Measured memory_bytes: 1024
#include <iostream>
#include <ctype.h>

using namespace std;

int main (void)
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    cout << (char)toupper(s1[0]);
    cout << (char)toupper(s2[0]);
    cout << (char)toupper(s3[0]);
    cout << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

ll n;
vector<vector<ll> > f(110,vector<ll>(10));
vector<vector<ll> > p(110,vector<ll>(10));
ll inf=-1e10;

ll dfs(ll d,vector<ll> sum){
  if(d==10){
    if(count(begin(sum),end(sum),1)==0){
      return inf;
    }
    ll ret=0;
    ll cnt;
    rep(i,n){
      cnt=0;
      rep(j,10){
        if(sum[j]==1 && f[i][j]==1){
          cnt++;
        }
      }
      ret+=p[i][cnt];
    }
    return ret;
  }
  vector<ll> sum0(sum);
  vector<ll> sum1(sum);
  sum1[d]=1;
  ll ret0=dfs(d+1,sum0);
  ll ret1=dfs(d+1,sum1);
  return max(ret0,ret1);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n){
      rep(j,10){
        cin>>f[i][j];
      }
    }
    rep(i,n){
      rep(j,11){
        cin>>p[i][j];
      }
    }
    vector<ll> a(10,0);
    ll ans=dfs(0,a);
    cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())

int main() {
	string S;
	cin >> S;
	rep(i, S.size()) {
		int x = S.size() - i;
		if (x % 2 != 0)continue;
		bool flag = true;
		rep(j, x / 2) {
			if (S[j] != S[x / 2 + j]) {
				flag = false;
				break;
			}
		}
		if (flag&&x!=S.size()) {
			cout << x << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,k;
  cin>>n;
  string s;
  cin>>s;
  cin>>k;
  for(i=0;i<s.length();i++)
  {
    if(s[i]!=s[k-1]) s[i]='*';
  }
  cout<<s;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static Scanner sc;
	public static void main(String[]args) {
		sc = new Scanner(System.in);
		int front = sc.nextInt();
		int back = sc.nextInt();
		int divisor = sc.nextInt();
		while(front < 1 || 10000 < front);
		while(back < 1 || 10000 < back);
		while(divisor < 1 || 10000 < divisor);
		if(front > back) {
			int temp = front;
			front = back;
			back = temp;
		}
		int i;
		int count= 0;
		for(i = front; i <= back; i++) {
			if(divisor % i == 0)
				count++;
		}
		System.out.println(count);
	}
}



Measured memory_bytes: 26248
#include <iostream>
#include <algorithm>
#include <array>

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

    int n;
    std::cin >> n;
    std::array<std::array<std::array<int, 10>, 3>, 4> num{{}};
    for(int i=0; i<n; ++i){
        int b, f, r, v;
        std::cin >> b >> f >> r >> v;
        num[b-1][f-1][r-1] += v;
    }
    for(int i=0; i<4; ++i){
        for(int j=0; j<3; ++j){
            for(int k=0; k<10; ++k){
                std::cout << " " << num[i][j][k];
            }
            std::cout << "\n";
        }
        if(i!=3){
            std::cout << "####################\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s1,s2,s3; cin >> s1 >> s2 >> s3;
  s1[0]-=32;
  s2[0]-=32;
  s3[0]-=32;
  
  cout << s1[0] << s2[0] << s3[0] << endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

vector<vector<int>> G;
vector<int> ans;

void dfs(int v, int p) {
	for (auto to : G[v]) {
		if (to == p) continue;
		ans[to] += ans[v];
		dfs(to, v);
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, q;
	cin >> n >> q;
	G.resize(n);
	ans.resize(n, 0);
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	rep(i, q) {
		int p, x;
		cin >> p >> x;
		p--;
		ans[p] += x;
	}

	dfs(0, -1);

	rep(i, n) {
		cout << ans[i] << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 23552
import sys

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    X = int(input())
    ans = 0
    a = 100
    while True:
        ans += 1
        a = int(a*1.01)
        if a>=X:
            print(ans)
            break
if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

total_monster = 0
for i in range(n):
    monster = min(a[i], b[i])
    total_monster += monster
    a[i] -= monster
    b[i] -= monster
    monster = min(a[i + 1], b[i])
    total_monster += monster
    a[i + 1] -= monster
print(total_monster)


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

int main(){

  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double theta = 11 * M_PI * (60 * h + m) / 360;

  double c = sqrt(pow(a,2) + pow(b,2) - 2 * a * b * cos(theta));

  cout << setprecision(16) << c << endl;

  return 0;
}


Measured memory_bytes: 4232
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;
int main() {
	int N;
	scanf("%d", &N);
	bool vals[8];
	fill(begin(vals), end(vals), false);
	int max = 0, min = 0;
	for (int i = 0; i < N; i++) {
		int cur;
		scanf("%d", &cur);
		if (cur >= 3200) {
			max++;
		}
		else if (cur >= 2800) {
			if (!vals[7]) {
				min++;	
			}
			vals[7] = true;
		}
		else if (cur >= 2400) {
			if (!vals[6]) {
				min++;
			}
			vals[6] = true;
		}
		else if (cur >= 2000) {
			if (!vals[5]) {
				min++;
			}
			vals[5] = true;
		}
		else if (cur >= 1600) {
			if (!vals[4]) {
				min++;
			}
			vals[4] = true;
		}
		else if (cur >= 1200) {
			if (!vals[3]) {
				min++;
			}
			vals[3] = true;
		}
		else if (cur >= 800) {
			if (!vals[2]) {
				min++;
			}
			vals[2] = true;
		}
		else if (cur >= 400) {
			if (!vals[1]) {
				min++;
			}
			vals[1] = true;
		}
		else {
			if (!vals[0]) {
				min++;
			}
			vals[0] = true;
		}
	}
	max += min;
	if (min == 0) {
		min = 1;
	}
	printf("%d %d", min, max);
	return 0;
}

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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}


int main() {
    int k;
    string s;
    cin >> k >> s;
    string ans;
    if (s.size() <= k) {
        ans = s;
    }else {
        rep(i, k) {
            ans.push_back(s[i]);
        }
        rep(i, 3) {
            ans.push_back('.');
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] data = line.split("");
        if(data[0].equals(data[1]) && data[0].equals(data[2])){
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

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

long long GCD(long long a, long long b) {
	if (b != 0) {
		return GCD(b, a % b);
	}

	return a;
}


int main() {

	int N, X;
	cin >> N >> X;

	vector<long long> x(N+1);
	x[0] = X;

	for (int i = 1; i < N+1; i++)
	{
		cin >> x[i];
	}
	sort(x.begin(), x.end());

	long long ans = x[1] - x[0];
	for (int i = 1; i < N; i++)
	{
		ans = GCD(ans, x[i+1] - x[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	long[] arr;
	arr ~= RD;
	arr ~= RD;
	arr ~= RD;
	arr ~= RD;
	arr ~= RD;
	auto K = RD;
	
	bool ans = true;
	foreach (i; 0..5)
	{
		foreach (j; i+1..5)
		{
			if (abs(arr[i] - arr[j]) > K)
				ans = false;
		}
	}
	
	writeln(ans ? "Yay!" : ":(");
	stdout.flush();
	debug readln();
}

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 A, B, M; cin >> A >> B >> M;
  vector<int> a(A); rep(i, A) cin >> a[i];
  vector<int> b(B); rep(i, B) cin >> b[i];
  constexpr int INF = 1e9 + 10;
  int min_a = INF, min_b = INF;
  rep(i, A) min_a = min(min_a, a[i]);
  rep(i, B) min_b = min(min_b, b[i]);
  int ans = min_a + min_b;
  rep(i, M) {
    int x, y, c; cin >> x >> y >> c;
    x--; y--;
    ans = min(ans, a[x] + b[y] - c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
use std::io;
use std::str::FromStr;

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

fn main() {
    let n: f64 = input();
    let m = (n / 1.08).ceil();
    for i in 0..1 {
        if ((m + i as f64) * 1.08).floor() == n {
            println!("{}", m);
            return;
        } 
    }
    println!(":(");
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

ll f(ll h){
  if(h==1)return 1;
  return 1+2*f(h/2);
}

int main(){
  ll h;
  cin >> h;
  cout<<f(h)<<endl;
  return 0;
}

Measured memory_bytes: 256
# Field
module Field
  def self.search_square(grid)
    dp = Array.new(1000) { Array.new(1000, 0) }
  
    for i in 0...grid.size
      for j in 0...grid[i].size
        if grid[i][j] == '*'
          dp[i][j] = 0
        else
          if i > 0 && j > 0
            dp[i][j] = [dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]].min + 1
          else
            dp[i][j] = 1
          end
        end
      end
    end

    dp.flatten.max
  end
end

while line = gets
  n = line.chomp.to_i
  break if n == 0

  grid = []
  n.times do
    grid << gets.chomp.split('')
  end

  puts Field::search_square(grid)
end

Measured memory_bytes: 134804
#include<stdio.h>
int main()
{  int k,a,b,i,f=0;
   scanf("%d%d%d",&k,&a,&b);
   for(i=a;i<=b;i++)
   if(i%k==0)
   {  f=1;i=b+1;}
   if(f==1) printf("OK");
   else printf("NG");
} 

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

#define MAX 2000000000
#define MAX2 1000000
#define MAX3 2000000

struct node{
  
  unsigned int key;
  struct node *next;
  struct node *prev;
  
};


typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int);
void init();
void printList();
void deleteNode(NodePointer );
void deleteFirst();
void deleteLast();
void delete(int);
void insert(int);



int main(){
  
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;

  
  
  scanf("%d", &n);
  
  init();
  
  for ( i = 0; i < n; i++ ){
    
    scanf("%s%d", com, &key);
    
    if(!( 0 <= key && key <= MAX)){
      printf("error\n") ;
    }
    if ( com[0] == 'i' ) {
      insert(key); np++; size++;
    }
    else if ( com[0] == 'd' ) {
     
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) {
	  deleteFirst();
	}
	else if ( com[6] == 'L' ) {
	  deleteLast();
	}
      } else {
	delete(key); nd++; 
      }
      size--;
    }
    if ( size > MAX2 ) {
      printf("error\n");
    }
  }

  
  if(!( np+nd <= MAX3)){
    printf("error\n");
  }
  if(!( nd <= 20)){
    printf("error\n");
  }


  
  printList();

  return 0;
}



NodePointer listSearch(int key){
  
  NodePointer c = nil->next;
  
  while( c != nil && c->key != key ){
    c = c->next;
  }
  return c;
  
}

void init(){
  
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
  
}

void printList(){
  
  NodePointer cur = nil->next;
  int isf = 1;
  
  while(1){
    
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  
  t->prev->next = t->next;
  t->next->prev = t->prev;

  free(t);
  
}

void deleteFirst(){
  
  NodePointer t = nil->next;
  
  if ( t == nil ) return;
  deleteNode(t);
  
}

void deleteLast(){
  
  NodePointer t = nil->prev;
  
  if ( t == nil ) return;
  deleteNode(t);
  
}

void delete(int key){
  
  NodePointer t = listSearch(key);
  
  if ( t == nil ) return;
  deleteNode(t);
  
}


void insert(int key){
  
  NodePointer x;
  
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
  
}

Measured memory_bytes: 31660
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[110000];
int main(){
  ll n,cnt=-1,ans=0,st=1100000000;
  cin>>n;
  rep(i,0,n)cin>>a[i];
  sort(a,a+n);
  ll x=a[n-1];
  rep(i,0,n-1){
    if(st>abs(x-a[i]*2)){
      st=abs(x-a[i]*2);
      cnt=i;
      }
  }
  cout<<x<<" "<<a[cnt];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
const int N = 2e5 + 7;
const ll mod = 998244353;

int main() {
	fastIO;
	ll n, x, m;
	cin >> n >> x >> m;
	map<ll, int> first;
	set<ll> seen;
	ll prev = x;
	seen.insert(x);
	first[x] = 1;
	vector<ll> accum = {0, x};
	ll sum = x;
	int st = -1, len = 0;
	for (int i = 2; i <= 2*m+1; i++) {
		ll curr = (prev*prev)%m;
		if (seen.count(curr)) {
			st = first[curr];
			len = i - st;
			break;
		}
		else {
			first[curr] = i;
			seen.insert(curr);
		}
		sum += curr;
		accum.push_back(sum);
		prev = curr;
	}
	ll ans = 0;
	if (n < accum.size()) {
		ans = accum[n];
	}
	else {
		assert(st != -1);
		ans = accum[st-1];
		n -= st-1;
		ans += (n/len) * (accum.back() - accum[st-1]);
		ans += accum[st+(n%len)-1] - accum[st-1];
	}
	cout << ans;

}


Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define bit(k) (1<<(k))
#define all(a) (a).begin(),(a).end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define ub(s,x) upper_bound(all(s),x)-s.begin()
#define uniq(a) a.erase(unique(all(a)),a.end())
#define INF 1e9
#define debug(x) cout<<#x<<": "<<x<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
typedef long long ll;


using Cost = double;
using Edge = pair<Cost,int>;
// #define cost first.first
// #define to   first.second
// #define used second

int main(void){
    int n,m,p,a,b;
    while(cin>>n>>m>>p>>a>>b, m){
        a--,b--;
        int t[8];
        vector<vector<Edge>> g(m);
        rep(i,n) cin>>t[i];
        rep(i,p){
            int x,y,z;
            cin>>x>>y>>z;
            x--,y--;
            g[x].push_back({z,y});
            g[y].push_back({z,x});
        }
        vector<vector<double>> dp(m,vector<double>(1<<n,INF));
        using P = pair<Edge, int>;// <<cost, to>, used>
        priority_queue<P,vector<P>,greater<P>> qu;
        qu.push({{dp[a][0] = 0, a},0});
        while(qu.size()){
            P pr = qu.top(); qu.pop();
            int v = pr.first.second;
            int used = pr.second;
            if(dp[v][used] < pr.first.first) continue;
            for(Edge e : g[v]){
                rep(k,n){
                    if(used & bit(k)) continue;
                    double cost = e.first;
                    int to = e.second;
                    if( dp[to][used|bit(k)] > dp[v][used] + cost/t[k]){
                        dp[to][used|bit(k)] = dp[v][used] + cost/t[k];
                        qu.push({{dp[to][used|bit(k)], to},used|bit(k)});
                    }
                }
            }
        }
        double res = INF;
        rep(mask,1<<n){
            res = min(res, dp[b][mask]);
        }
        if(res == INF){
            cout<<"Impossible"<<endl;
        }else{
            printf("%.3f\n",res);
        }
        
    }
    return 0;
}



Measured memory_bytes: 5384
#include<iostream>
using namespace std;
int sum=0;
int a[100000],n;

int binarySearch(int a[], int head, int nail, int key)
{

	while (head < nail)
	{
		int mid = (head + nail) / 2;
		if (a[mid] > key) nail = mid ;
		else if (a[mid] < key) head = mid + 1;
		else return 1;
	}
	return 0;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int q, o;
	cin >> q;
	while (q--)
	{
		cin >> o;
		if(binarySearch(a, 0, n, o))sum++;
	}

	cout << sum << endl;
}


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

int main() {
	string a;
	cin>>a;
	if(a[0]==a[1]&&a[1]==a[2])cout<<"Yes"<<endl;
	else if(a[1]==a[2]&&a[2]==a[3])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
	}

Measured memory_bytes: 256
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int K,S; cin >> K >> S;
    int ans = 0;
    for(int x = 0; x <= K; x++) 
        for(int y = 0; y <= K; y++) {
            int z = S - (x+y);
            if(z >= 0 && z <= K) ans++;
        }

    cout << ans << endl;
}

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

#define N 10000
int main(){
  int n,A[N],i,j,count=0,flag,k1;
  double k2;

  scanf("%d",&n);

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

  for( j = 0 ; j < n ; j++ ){
    flag = 0;
    if( A[j] != 2){
      if( A[j]%2 == 1){
	k2 = sqrt(A[j]);
	k1 = ceil(k2);
	for( i = 2 ; i <= k1 ; i++ ) {
	  if( A[j] % i == 0 ) {
	    flag = 1;
	    break;
	  }
	}
	if( flag == 0 ) count++;
      }
    }
    else count++;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main()
{
   long long  w,h;
   char c;
    while(cin>>w>>h>>c)
    {
        if(c>='a'&&c<='z')
            c=c+('Z'-'z');
        for(int j=0;j<h;j++)
        {
            if(j==0||j==h-1)
            {
                for(int i=0;i<w;i++)
                    if(i==0||i==w-1)
                        printf("+");
                    else
                        printf("-");
            }
            else
            {
                for(int i=0;i<w;i++)
                    if(i==0||i==w-1)
                        printf("|");
                    else
                    {
                        if(j==(h/2)&&i==(w/2))
                            printf("%c",c);
                        else
                            printf(".");
                    }
            }

               cout<<endl;
        }

    }
    return 0;
}






Measured memory_bytes: 3112
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <math.h>
#include <functional>

int main(void) {
  int i, j, k, n, t, r, be = 0, d, x, l;
  scanf("%d%d%d", &n, &r, &l);
  int sn;
  std::pair<int, int> seg[4 * n], to[n];
  for(i = 0; i < n; ++i) to[i].first = 0, to[i].second = i;
  if((int)log2(n) == log2(n)) sn = log2(n);
  else sn = log2(n) + 1;
  for(i = pow(2, sn); i < pow(2, sn) + n; ++i) 
    seg[i].first = 0, seg[i].second = i - pow(2, sn);
  for(; i < pow(2, sn + 1); ++i) seg[i].first = 0, seg[i].second = 200000;
  i = pow(2, sn - 1);
  while(i) {
    for(j = i; j < 2 * i; ++j) {
      if(seg[j * 2] < seg[j * 2 + 1]) seg[j] = seg[j * 2];
      else seg[j] = seg[j * 2 + 1];
    }
    i /= 2;
  }
  int pp = pow(2, sn);
  for(i = 0; i < r; ++i) {
    scanf("%d%d%d", &d, &t, &x);
    to[seg[1].second].first += t - be;
    be = t;
    d--;
    seg[pp + d].first -= x;
    int now = (pp + d) / 2;
    while(now) {
      if(seg[now * 2] < seg[now * 2 + 1]) seg[now] = seg[now * 2];
      else seg[now] = seg[now * 2 + 1];
      now /= 2;
    }
  }
  to[seg[1].second].first += l - be;
  std::sort(to, to + n, std::greater< std::pair<int, int> >());
  printf("%d\n", to[0].second + 1);
  return 0;
}


Measured memory_bytes: 6876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll s = 0;
  int x = log10(n) +1;
  int nn = n;
  rep(i, 0, x) {
    ll c = nn%10;
    s += c;
    nn /= 10;
  }
  
  cout << (n % s == 0 ?"Yes" :"No") << "\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;
int main(){
    int N;
    cin>>N;
    int count=0;
    rep(i,25){
        rep(j,13){
            if(i*4+j*7==N){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]

mi,ma=0,2000
com=list(combinations(range(n),2))

def dist(p,q):
    a,b=p
    c,d=q
    return math.sqrt((a-c)**2+(b-d)**2)

while ma-mi>10**(-9):
    half=(ma+mi)/2
    # print(ma,mi,half)
    lst=[]
    for co in com:
        a,b=co
        ax,ay=xy[a]
        bx,by=xy[b]
        kyori=dist(xy[a],xy[b])
        if kyori/2>half:
            mi=half
            break
        else:
            h=math.sqrt(half**2-(dist(xy[a],xy[b])/2)**2)
            tyuuten=((ax+bx)/2,(ay+by)/2)
            tmp=h/kyori
            lst.append((tyuuten[0]+(ay-by)*tmp,tyuuten[1]-(ax-bx)*tmp))
            lst.append((tyuuten[0]-(ay-by)*tmp,tyuuten[1]+(ax-bx)*tmp))
    else:
        for co in lst:
            bx,by=co
            flag=1
            for i in range(n):
                ax,ay=xy[i]
                if (ax-bx)**2+(ay-by)**2>half**2+9e-7:
                    flag=0
                    break
            if flag==1:
                ma=half
                break
        else:
            mi=half
print(ma)


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

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 ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

// [left, right]内にvの倍数はあるか
bool in_range(ll v, ll left, ll right){
    if(left%v==0){
        return true;
    }

    ll r = left - left%v + v;
    if(right>=r){
        return true;
    }else{
        return false;
    }
}

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    ll mi = 2;
    ll ma = 2;
    for(int i=N-1; i>=0; i--){
        ll a = A[i];
        ll heri_max = a-1;

        if(ma%a==0 && mi%a==0){
            // no problem
        }else{
            p(-1);
            return 0;
        }

        ma += heri_max;
        mi = mi;

        // A[i-1]の倍率である必要
        if(i-1>=0){
            ll p = A[i-1];

            if(!in_range(p, mi, ma)){
                p(-1);
                return 0;
            }
            
            ma = ma - ma%p;
            if(mi%p!=0){
                mi = mi - mi%p + p;
            }
        }
    }
    p2(mi, ma);
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int n, x[100], y[100]; long long ret;
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
	for(int i = 1; i <= n; i++) ret += x[i % n] * y[(i + 1) % n] - x[(i + 1) % n] * y[i % n];
	cout << ret / 2 << (ret % 2 ? ".5" : ".0") << endl;
}

Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		long a,b,ans = 0,temp,kouyaku,n;
		String str;
		String[] s;
		str = bf.readLine();
		s = str.split(" ");
		a = Long.parseLong(s[0]);
		b = Long.parseLong(s[1]);
		if(a < b) {
			temp = a;
			a = b;
			b = temp;
		}
		while(a%b != 0) {
			temp = a%b;
			a = b;
			b = temp;
		}
		kouyaku = b;
		ans = 1;
		if(kouyaku != 1) {
			if(kouyaku%2 == 0) {
				ans++;
				while(kouyaku%2 == 0) {
					kouyaku /= 2;
				}
			}
			n = 3;
			if(kouyaku != 1) {
				while(kouyaku >= n*n) {
					if(kouyaku%n == 0) {
						ans++;
						while(kouyaku%n == 0) {
							kouyaku /= n;
						}
					}
					n += 2;
				}
			}
			if(kouyaku != 1) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
from collections import deque

h, w = list(map(int,input().split()))
s = [list(input()) for _ in range(h)]
dyx = [(1, 0), (-1, 0), (0, 1), (0, -1)]

q = deque()
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            continue
        q.append((i, j))
        d = [ [0] * w for _ in range(h) ]
        while q:
            y, x = q.popleft()
            for dy, dx in dyx:
                ny = y + dy
                nx = x + dx
                if ny == i and nx == j:
                    continue
                if 0 <= ny < h and 0 <= nx < w and d[ny][nx]==0 and s[ny][nx]==".":
                    d[ny][nx] = d[y][x] + 1
                    q.append((ny, nx))

        # (i, j)からスタートできるとき，最大遠いところを計算する
        for k in range(h):
            ans = max(ans, max(d[k]))
print(ans)

Measured memory_bytes: 48604
while True:
    H, W = list(map(int, input().split()))
    if H == 0 and W == 0:
        break
    for i in range(H):
        if i == 0 or i == H-1:
            print("#"*W)
        else:
            print("#"+"."*(W-2)+"#")
    print()


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
       fast;
       ll n,k;
       cin>>n>>k;
       ll arr[2005][2005];
       memset(arr,0,sizeof(arr));
       arr[0][0]=1;
       for(int i=0;i<=n;i++)
    	arr[i][0]=1;
       for(int i=1;i<=n;i++)
    		for(int j=1;j<=n;j++)
    			arr[i][j]=(arr[i-1][j-1]%MOD+arr[i-1][j]%MOD)%MOD;
    	for(int i=1;i<=k;i++)
    		cout<<(arr[n-k+1][i]%MOD*arr[k-1][i-1]%MOD)%MOD<<endl;
       return 0;
}


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

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int add(int x, int y) {
  x += y;
  if (x >= mod) {
    x -= mod;
  }
  return x;
}

int sub(int x, int y) {
  x -= y;
  if (x < 0) {
    x += mod;
  }
  return x;
}

int mul(int x, int y) {
  return (ll)x * y % mod;
}

int power(int x, int y) {
  int result = 1;
  for (; y; y >>= 1, x = mul(x, x)) {
    if (y & 1) {
      result = mul(result, x);
    }
  }
  return result;
}

pair<int, int> solve(int l, int r, int base, vector<int> &a) {
  int x = *min_element(a.begin() + l, a.begin() + r), coef = 1, all = 1, number = 0;
  for (int i = l; i < r; ++i) {
    if (a[i] != x) {
      int j = i;
      while (j + 1 < r && a[j + 1] != x) {
        ++j;
      }
      pair<int, int> value = solve(i, j + 1, x, a);
      i = j;
      coef = mul(coef, value.first);
      all = mul(all, add(value.first, value.second));
    } else {
      ++number;
    }
  }
  return make_pair(mul(coef, power(2, x - base)), add(mul(all, power(2, number)), mul(coef, sub(power(2, x - base), 2))));
}

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  printf("%d\n", solve(0, n, 0, a).second);
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> C(N);
	for (int i = 0; i < N; ++i) {
		cin >> C[i];
	}
	sort(C.begin(), C.end());
	int cnt = 0;
	vector<int> D(N);
	function<void(int, int)> dfs = [&](int pos, int pre) {
		for (int i : G[pos]) {
			if (i == pre) continue;
			dfs(i, pos);
		}
		D[pos] = C[cnt++];
	};
	dfs(0, -1);
	int sum = 0;
	for (int i = 0; i < N - 1; ++i) {
		sum += C[i];
	}
	cout << sum << endl;
	for (int i = 0; i < N; ++i) {
		if (i) cout << ' ';
		cout << D[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

try (Scanner sc = new Scanner(System.in);) {
			
			int n = sc.nextInt();
			int m = sc.nextInt();
			
			int a[][] = new int[n][m];
			int b[] = new int[m];
			int c[] = new int[n];
			
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < m; j++) {
					a[i][j] = sc.nextInt();
				}
			}
			for(int i = 0; i < m; i++) {
				b[i] = sc.nextInt();
			}
			
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < m; j++) {
					c[i] += a[i][j] * b[j];
				}
			}
			
			StringBuilder sb = new StringBuilder();
			
			for(int i = 0; i < n; i++) {
				sb.append(c[i]);
				sb.append("\n");
			}
			
			System.out.print(sb.toString());
		}
	}
}


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

int main(){
	int n; cin>>n;
	float d; cin>>d;
	float x[n]={0}, y[n]={0};
	int count=0;
	for(int i=0; i<n; i++) 
	{
		cin>>x[i]>>y[i];
		if(sqrt(pow(x[i],2)+pow(y[i],2))<=d) count++;
	}
	
	
	cout<<count<<endl;
	
}

Measured memory_bytes: 5372
k = int(input())
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(int(A[k-1]))

Measured memory_bytes: 3060
# from pprint import pprint
import math

# import collections

# n = int(input())
n, m = map(int, input().split(' '))
a = list(map(lambda x: int(x) * (-1), input().split(' ')))
# a = sorted(a, reverse=True)
# b = [math.log2(_a) for _a in a]


import heapq

q_a = heapq.heapify(a)

for m in range(m):
    x = heapq.heappop(a) * (-1)
    heapq.heappush(a, (x // 2) * (-1))

print(sum(a) * (-1))


Measured memory_bytes: 20576
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n = INT()
a = LIST()
l1 = [i+1+a[i] for i in range(n)]
l2 = [i+1-a[i] for i in range(n)]
c1 = Counter(l1)
c2 = Counter(l2)
res = 0
inter = set(l1) & set(l2)
for value in inter:
    res += c1[value]*c2[value]

print(res)

Measured memory_bytes: 173904
N, M = map(int, input().split())
Xs = list(map(int, input().split()))
Xs.sort()

distances = []
for i in range(len(Xs)-1):
    distances.append(Xs[i+1]-Xs[i])
distances.sort()

if N >= M:
    print(0)
else:
    print(sum(distances[:M-N]))


Measured memory_bytes: 13960
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
using namespace std;

/*
const int MAX_E=2*(100-1);
const int MAX_V=100;
const long long int INF=100000000;
struct edge { int from,to,cost;};
edge es[MAX_E];
//int d[MAX_V];
int V,E;
void shortest_path(int s,int e,vector<int>& d);
int main(){
	int n,k;
	while(cin >> n >> k&&n!=0&&k!=0){
		int V=n;
		int E=2*(n-1);
		vector<int> land(V);
		int l=0;
		for(int i=0; i<E; ++i){
			es[i].cost=-1;
			es[i].from=-1;
			es[i].to=-1;
		}
		for(int i=0; i<k; ++k){
			int m;
			cin >> m;
			if(m==0){
				int a,b;
				cin >> a >> b;
				shortest_path(a,b,land);
				cout << land[b] << "\n";
			} else if(m==1){
				int c,d,e;
				cin >> c >> d >> e;
				es[l].from=c;
				es[l].to=d;
				es[l].cost=e;
				es[l+1].from=d;
				es[l+1].to=c;
				es[l+1].cost=e;
				l+=2;
			}
		}
	}
	return 0;
}

void shortest_path(int s,int e,vector<int>& d){
	cout << "ok1\n";
	for(int i=0; i<V; ++i) {
		cout << "ok\n";
		d[i]=INF;
	}
	d[s]=0;
	while(true){
		cout << "ok2\n";
		bool update=false;
		for(int i=0; i<E; ++i){
			edge e=es[i];
			if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
		}
		if(!update) break;
	}
}
*/

const int INF=100000000;
int main(){
	int n;
	while(cin >> n&&n!=0){
		vector<int> color;
		for(int i=0; i<n; ++i){
			int t;
			cin >> t;
			color.push_back(t);
		}
		int maxDel=INF;
		for(int i=0; i<n; ++i){
			for(int j=1; j<=3; ++j){
				if(color[i]==j) continue;
				int up=i-1;
				int down=i+1;
				int sum=0;
				int c=1;
				int col=j;
				while(1){
					int nCal=-1;
					while(1){
						if(up<0) break;
						if(color[up]!=col){
							nCal=color[up];
							break;
						}
						up--;
						c++;
					}
					while(1){
						if(down>=n) break;
						if(color[down]!=col){
							if(nCal==-1) nCal=color[down];
							break;
						}
						++down;
						++c;
					}
					if(c>=4){
						sum+=c;
					} else{
						break;
					}
					c=0;
					if(nCal==-1){
						break;
					}else{
						col=nCal;
					}
				}
				maxDel=min(maxDel,n-sum);
			}
		}
		cout << maxDel << "\n";
	}
	return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n;
	cin >> n;
	VI a(n);
	REP(i, n)
		cin >> a[i];
	REP(i, n - 1)
		a[i + 1] = a[i] ^ a[i + 1];
	if (a[n - 1] == 0)
		cout << "Yes";
	else
		cout << "No";
}

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

int main() {
	string s;
	int h = 0, i = 0;
	bool ok = true;
	cin >> s;

	for (int j = 0; j < (int)s.size(); j++) {
		if (j % 2 == 0) {
			if (s.at(j) != 'h') {
				ok = !ok;
				break;
			}
			h++;

		}
		else {
			if (s.at(j) != 'i') {
				ok = !ok;
				break;
			}
			i++;
		}
	}
	if (ok && h != i)ok = !ok;
	if (ok)cout <<"Yes" << endl;
	else cout << "No"<< endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;
const int mod = 1e9 + 7;

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



long long modpow(long long base, long long n) {
	long long ret = 1;
	while (n > 0) {
		if (n & 1) {
			ret = ret * base % mod;
		}
		base = base * base % mod;
		n >>= 1;
	}
	return ret;
}

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

	// sum of nCk = 2^n
	long long ans = modpow(2, n) - 1;

	long long val_a = 1;
	long long val_b = 1;
	for (int i = 0; i < a; i++) {
		val_a = val_a * (n - i) % mod;
		val_a = val_a * modinv(a - i) % mod;
	}
	ans -= val_a;

	for (int i = 0; i < b; i++) {
		val_b = val_b * (n - i) % mod;
		val_b = val_b * modinv(b - i) % mod;
	}
	ans -= val_b;

	ans += 1LL * mod * 10;
	ans %= mod;

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


Measured memory_bytes: 256
#include<stdio.h>
#include <iostream>
using namespace std;


int main() {
  string  S,T;
  cin >> S >> T;
  int A,B;
  cin >> A >> B;
  string U;
  cin >> U;

  if(S==U){
    cout << A-1 << " " << B;
  }else{
    cout << A << " " << B-1;
  }

  return 0;
}



Measured memory_bytes: 256
import numpy as np
N,W = map(int, input().split())
# np.maximum https://www.sejuku.net/blog/69175
# 第一引数と第二引数の大小関係を要素ごとに比較して、大きい方を格納した配列を返します。
dp = np.zeros(W+1, dtype=np.int64)
for _ in range(N):
    w,v = map(int,input().split())
    # w以下ならvを足したもの、w以上ならそのままの値で、最大値を求める
    # 出力はw以上の配列として返す(それ以下は重さwなので関与しない)
    # 足す場合が前者、足さない場合が後者。その重さでの最大valueが保存されている
    np.maximum(dp[:W-w+1]+v,dp[w:],out=dp[w:]) 

print(dp[-1])

Measured memory_bytes: 14600
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let solve n q =
  let s = Array.init n (fun i -> i) in
  let rec find u =
    if u = s.(u) then u
    else begin
      s.(u) <- find s.(u);
      s.(u)
    end in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split_on_char ' ' (read_line ())) with
      | 0 :: x :: y :: _ -> s.(find x) <- find y
      | 1 :: x :: y :: _ -> print_endline (if find x = find y then "1" else "0")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split_on_char ' ' (read_line ())) with
  | [n; q] -> solve n q
  | _ -> ()

Measured memory_bytes: 4548
#include <bits/stdc++.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++)
typedef int64_t Int;

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

    vector<tuple<Int,int,int>> HXY(N);
    rep(i, N){
        Int H; int X, Y; cin >> X >> Y >> H;
        HXY[i] = tuple<Int,int,int>(H,X,Y);
    }

    sort(HXY.begin(), HXY.end());

    rep(x, 101) rep(y, 101){
        Int H0 = get<0>(HXY[N-1]); int X0 = get<1>(HXY[N-1]), Y0 = get<2>(HXY[N-1]);
        Int ans = H0 + abs(X0-x) + abs(Y0-y);
        bool valid = true;
        
        for(int i=0; i<N-1; i++){
            Int H = get<0>(HXY[i]); int X = get<1>(HXY[i]), Y = get<2>(HXY[i]);
            Int d = abs(X-x)+abs(Y-y);
          
            if((H != 0 && ans == H + d) || (H == 0 && ans <= d)) continue;
            else valid = false; 
        }

        if(valid) cout << x << " " << y << " " << ans << endl;
    } 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
// #include <fstream>

int main()
{
    int n, k;
    std::cin >> n >> k;
    std::vector<int> h(n), dp(n, INT32_MAX);
    for(int i=0; i<n; i++) std::cin >> h[i];

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    
    for(int i=2; i<n; i++)
    {
        for(int j=1; j<=k; j++)
        {
            if(i-j<0) break;
            dp[i] = std::min(dp[i-j]+abs(h[i]-h[i-j]), dp[i]);
        }
    }

    std::cout << dp[n-1] << std::endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3

vocab = set(['dream', 'dreamer', 'erase', 'eraser'])

def parse(s):
    stack = [0]
    while stack:
        i = stack.pop()
        if i == len(s):
            return True
        for w in vocab:
            if s[i:].startswith(w):
                stack.append(i + len(w))
    return False

s = input()
if parse(s):
    print('YES')
else:
    print('NO')

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

using namespace std;


int main(){

	long long N,a,b,arry[101];

	cin >>N;
	for(int i=0; i<N; i++){

		cin>>arry[i] ;


	}

	sort(arry,arry+N);

	a=b=0;
	for(int i=N-1; i>=0; i--){

		if(N%2 == (i+1) %2){
			
			
			a+=arry[i];

		}
		else b+=arry[i];

	//	cout <<arry[i] <<endl;

	}

	cout << a-b<<endl;
}


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

#define PB push_back
#define ld long double
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
#define ios ios_base::sync_with_stdio(0);
#define sz(s) (int)(s).size()
#define open(name) \
freopen(name".in", "r", stdin); \
freopen (name".out", "w", stdout);

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

const int N = 2e5 + 7;;
const int INF = 2e9 + 7;
const int logg = 20;
const double PI = 3.14;

using namespace std;

int n, m;
int dp[N], used[N];
vector <int> g[N];

void dfs(int v) {
    if (used[v]) return;
    used[v] ++;
    for (int i = 0; i < g[v].size(); i ++) {
        int to = g[v][i];
        if (!used[to]) dfs(to);
        dp[v] = max(dp[v], dp[to] + 1);
    }
}
void solve() {
    cin >> n >> m;
    for (int i = 1; i <= m; i ++) {
        int l, r;
        cin >> l >> r;
        g[l].PB(r);
    }
    int ans = 0;
    for (int i = 1; i <= n; i ++) if (!used[i]) dfs(i);
    for (int i = 1; i <= n; i ++) ans = max(ans, dp[i]);
    cout << ans;
}
int main() {
    ios;
    solve();
}


Measured memory_bytes: 14876
s = input()
n = len(s)
ans = "Yes"
if s != s[::-1]:
    ans = "No"
else:
    if s[:(n-1)//2] != s[:(n-1)//2:-1] or s[(n+3)//2-1:] != s[n:(n+3)//2-2:-1]:
        ans = "No"
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a/gcd(a,b)*b;}
// head
const int mxN = 1e5;
int n;
ll dp[mxN][3], a[3];
int main() {
	ios::sync_with_stdio(0); 
	cin.tie(0); cout.tie(0);
	
	cin >> n;
	rep(i, 0, n){
		rep(j, 0, 3) cin >> a[j];
		if(i == 0){
			rep(j, 0, 3) dp[i][j] = a[j];
			continue;
		}
		// i th day
		rep(j, 0, 3){
			// i-1 th day
			rep(k, 0, 3){
				if(j == k) continue;
				else{
					dp[i][j] = max(dp[i][j], dp[i-1][k] + a[j]);
				}
			}
		}
	}
	cout << *max_element(dp[n-1], dp[n-1] + 3);
	
}




Measured memory_bytes: 2560