akhauriyash/Code-Regression huggingface dataset:
from collections import deque

h,w = map(int,input().split())

sx,sy = map(int,input().split())
gx,gy = map(int,input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1

l = [list(input()) for i in range(h)]

dp = [[float("INF")]*w for i in range(h)]

dp[sx][sy] = 0

q = deque([])
q.append([sx,sy])
dx = [0,0,1,-1]
dy = [1,-1,0,0]
count = 0
while True:
    cq = []
    while q:
        x,y = q.popleft()
        cq.append((x,y))
        for i in range(4):
            nx = x+dx[i]
            ny = y+dy[i]
            if 0 <= nx < h and 0 <= ny < w and l[nx][ny] == "." and dp[nx][ny] > count:
                dp[nx][ny] = count
                q.append([nx,ny])
    if dp[gx][gy] < float("INF"):
        print(dp[gx][gy])
        exit()
    count += 1
    if len(cq) == 0:
        break
    for x,y in cq:
        for i in range(-2,3):
            for j in range(-2,3):
                nx = x+i
                ny = y+j
                if 0 <= nx < h and 0 <= ny < w and l[nx][ny] == "." and dp[nx][ny] > count:
                    dp[nx][ny] = count
                    q.append([nx,ny])

if dp[gx][gy] == float("INF"):
    print(-1)


Measured memory_bytes: 135332
using System;
class Program
{
	static void Main()
	{
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int x = int.Parse(input[1]);
        int y = int.Parse(input[2]);
        int[] result = new int[n * 2];
        int kouho1 = 0;
        int kouho2 = 0;
        int kouho3 = 0;
        int kyori = 0;
        for (int i = 1; i <= n - 1; i++) {
            // Console.WriteLine("test");
            for (int j = i+1; j <= n; j++) {
                kyori = 0;
                if (i == j || i >= j){
                    continue;
                } else {
                    //Console.WriteLine(i + "," + j);
                    kouho1 = j - i;
                    kouho2 = Math.Abs(x - i) + 1 + Math.Abs(j - y);
                    kouho3 = Math.Abs(y - i) + 1 + Math.Abs(j - x);
                    //Console.WriteLine(kouho1 + "," + kouho2 + "," + kouho3);
                    //Console.WriteLine("test5");
                    if (kouho1 > kouho2)
                    {
                        kyori = kouho2;
                        //Console.WriteLine(kyori);
                    } else {
                        kyori = kouho1;
                    }
                    /* else {
                        kyori = kouho3;
                    }
                    */
                    if (kyori > kouho3){
                        kyori = kouho3;
                        //Console.WriteLine(kyori);
                    }
                    //Console.WriteLine(kyori);
                    // Console.WriteLine("test6");
                    //Console.WriteLine(kyori);
                    // Console.WriteLine(n);
                    result[kyori] = result[kyori] + 1;
                    //Console.WriteLine("test3");
                }
            }
            //Console.WriteLine("test4");
        }
        for (int k = 1; k < n; k++) {
            Console.WriteLine(result[k]);
        }
        //Console.WriteLine(result);
	}

    static string equalCheck(string target1,string target2){
        if (target1 == target2){
            return "Yes";
        } else {
            return "No";
        }
    }
/*
    static int NotEqualCheck(int target1,int target2,int shokiti){
        if (target1 > target2){
            return target2;
        } else {
            return shokiti;
        }
    }
*/
}

Measured memory_bytes: 13268
#include <stdio.h>
int main(){
  int n,v[20],c[20],sum=0;
  scanf("%d",&n);
  for (int i=0;i<n;i++) scanf("%d",&v[i]);
  for (int i=0;i<n;i++) scanf("%d",&c[i]);
  for (int i=0;i<n;i++){
    if (v[i]>c[i]) sum=sum+v[i]-c[i];
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 128
def main():
    n=int(input())
    ans=0
    a,b=[],[]
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append(ai)
        b.append(bi)
    for i in range(n-1,-1,-1):
        if (a[i]+ans)%b[i]!=0:
            ans+=b[i]-(a[i]+ans)%b[i]
    print(ans)
if __name__=="__main__":
    main()

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

int main() {
  int N, A, B, G;
  cin >> N >> A >> B;
  G = N * A;
  if ( G <= B ) {
    cout << G << endl;
  }
  else if ( G >= B ) {
    cout << B << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		int T;
		cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		cout << T*T << endl;
		return 0;
	}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using pint = pair<int,int>;

int main() {
    int N; cin >> N;
    vector<pint> res;
    int dame = N;
    if (N % 2 == 1) --dame;

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            if (j <= i || j == dame) continue;
            res.push_back(pint(i, j));
        }
        --dame;
    }

    cout << res.size() << endl;
    for (auto p : res) {
        cout << p.first << " " << p.second << endl;
    }
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (h, w) = readLine()?.split(" ")?.map(String::toLong) ?: return
    if (h == 1L || w == 1L) {
        println("1")
        return
    }
    val a1 = w / 2L + w % 2L
    val b1 = h / 2L + h % 2L
    val a2 = w / 2L
    val b2 = h / 2L
    println((a1 * b1 + a2 * b2).toString())
}


Measured memory_bytes: 38080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int l,r,d,counter=0;
	cin>>l>>r>>d;
	for(int i=l;i<=r;i++)
	{
		if(i%d==0)
		{
			counter++;
		}
	}
	cout<<counter<<endl;
	return 0;
}

Measured memory_bytes: 3524
#include<cstdlib>
#include<map>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include <iostream>
#define ll long long
using namespace std;
int main()
{
    int n;
    int k=-1;
    int a[100010];
    cin>>n;
    if(n==0)
    {
        cout<<n<<endl;
        return 0;
    }
    while(n)
    {
        a[++k]=n%(-2);
        n/=-2;
        if(a[k]==-1)
        {
            a[k]=1;
            n++;
        }
    }
    for(int i=k;i>=0;i--)
        cout<<a[i];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)

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

constexpr int MAXN = 5 + 1000;
int a[MAXN];

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int n,m,s=0; cin >> n >> m;
  int tot = 0;
  foi (i,0,n) {
    cin >> a[i];
    s += a[i];
  }

  int lb = s/(4*m);
  if (s % (4*m)) lb++;

  foi (i,0,n) {
    if (a[i] >= lb) tot++;
  }

  if (tot >= m) cout << "Yes" << '\n';
  else cout << "No" << '\n';
  return 0;
}


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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<pair<int, int>> vpii;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 4000000000; //4*10^9;
constexpr auto MOD = 1000000007; //10^9+7;

int main()
{
    int k,s;
    cin >>k>>s;

    int ans = 0;

    rep(x, k + 1)rep(y, k + 1) {
        int z = s - x - y;

        if (z < 0 || k < z) continue;

        if (x < y&&y < z) { ans += 6;}
        if (x == y && y != z) { ans += 3;}
        if (x == y && y == z) { ans++;}
    }

    cout << ans << endl;
    
}


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

int main()
{
  ll n,l=0;
  cin>>n;
  ll a[n],b[n];
  for(ll i=0;i<n;i++)
    cin>>a[i]>>b[i];

     for(ll i=0;i<n;i++)
     {
         if(a[i]==b[i])
         {
             
         
            l++;
            if(l>=3)
                break;
         }
            else
            {
                l=0;
            }
     }
     string p;
     l>=3?p="Yes":p="No";
     
     cout<<p<<endl;
}




Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int mod = 1000000007;
const int N = 200020;

int dp[N];
int last[N];

signed main() {
  int n;
  cin >> n;

  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];

  memset(dp, 0, sizeof(dp));
  memset(last, -1, sizeof(last));

  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    int x = a[i];
    if(last[x] == -1) {
      dp[i] = dp[i - 1];
    } else if (last[x] == i - 1){
      dp[i] = dp[i - 1];
    } else {
      int idx = last[x];
      dp[i] = dp[i - 1] + dp[idx];
      dp[i] %= mod;
    }
    last[x] = i;
  }

  cout << dp[n] << '\n';

  return 0;
}

Measured memory_bytes: 8028
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  long long ans=0;
  for(int i=0;i<(1<<(n-1));i++){
    long long tmp=0;
    for(int j=0;j<n-1;j++){
      tmp*=10;
      tmp+=s[j]-'0';
      if(i&(1<<j)){
        ans+=tmp;
        tmp=0;
      }
    }
    tmp*=10;
    tmp+=s[n-1]-'0';
    ans+=tmp;
  }
  cout<<ans<<endl;
  return 0;
}


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

long long N, M, R, r[211], A[1 << 18], B[1 << 18], C[1 << 18], dist[211][211], minx = (1 << 30);

int main() {
	cin >> N >> M >> R;
	for (int i = 1; i <= R; i++) cin >> r[i];
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) dist[i][j] = (1 << 30); dist[i][i] = 0; }
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i] >> C[i];
		dist[A[i]][B[i]] = C[i]; dist[B[i]][A[i]] = C[i];
	}
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
		}
	}
	int G[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };

	do {
		long long sum = 0;
		for (int i = 0; i < R - 1; i++) sum += dist[r[G[i]]][r[G[i + 1]]];
		minx = min(minx, sum);
	} while (next_permutation(G, G + R));

	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */
namespace utils{

    class Repeater{
        int st;
        int ed;
        int d;
    public:
        class rep_iterator{
            int i; int d;
        public:
            rep_iterator(int x, int pd) :i(x), d(pd) {}

            int& operator*(){ return i; }
            bool operator==(const rep_iterator& k) const { return i == k.i; }
            bool operator!=(const rep_iterator& k) const { return i != k.i; }
            rep_iterator& operator++(){ i+=d; return *this; }
        };

        explicit Repeater(int N) :st(0), ed(N), d(1) {}
        Repeater(int b, int e) :st(b), ed(e), d(1) {if(st > ed){ st--; ed--; d = -1; } }

        rep_iterator begin() const{ return rep_iterator(st, d); }
        rep_iterator end() const{ return rep_iterator(ed, d); }

    };

    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;


void sub_main(istream &is) {
    ll N, M;
    is >> N >> M;
    if(!is) return;
    vector<ll> A(N);
    for (auto &&a : A) { is >> a; } // end a
    map<ll, ll> C;
    for (auto &&i : Repeater(0, M)) {
        ll b, c;
        is >> b >> c;
        C[c] += b;
    } // end i

    sort(ALL(A));
    auto pt = A.begin();
    auto pct = C.rbegin();
    while(pct != C.rend() and pt != A.end()){
        if(pct->first > *pt) {
            *pt = pct->first;
            pt++;
            pct->second--;
        }
        else{
            break;
        }
        if(pct->second == 0) pct++;
    }

    ll ans = accumulate(ALL(A), 0ll);
    cout << ans << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_D.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 7296
use std::io::*;
use std::str::FromStr;

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

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let x = read::<i64>();
  let mut dist: HashMap<i64, i64> = HashMap::new();
  let mut max_v = 0;
  let mut min_v = 0;
  let mut ans = 0;

  for i in 0..x {
    let x_i = read::<i64>();
    let current = dist.entry(x_i).or_insert(0);
    *current += 1;
    max_v = max(max_v, x_i);
    min_v = min(min_v, x_i);
  }

  for i in min_v..max_v + 1 {
    let mut sum: i64 = 0;
    sum += match dist.get(&(i + 1)) {
      Some(s) => *s,
      None => 0,
    };
    sum += match dist.get(&(i)) {
      Some(s) => *s,
      None => 0,
    };
    sum += match dist.get(&(i - 1)) {
      Some(s) => *s,
      None => 0,
    };
    ans = max(ans, sum);
  }

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



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

int main(){
    int m, f, r;
    while (true){
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;
        if (m == -1 || f == -1){
            cout << "F" << endl;
        }
        else {
            if ((m + f) >= 80){
                cout << "A" << endl;
            }
            else if ((m + f) >= 65 && (m + f) < 80){
                cout << "B" << endl;
            }
            else if ((m + f) >= 50 && (m + f) < 65){
                cout << "C" << endl;
            }
            else if ((m + f) >= 30 && (m + f) < 50){
                if (r >= 50) {
                    cout << "C" << endl;
                }
                else {
                    cout << "D" << endl;
                }
            }
            else {
                cout << "F" << endl;
            }
        }
    }
}


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

using namespace std;

int main(int argc, char *argv[])
{
    string s, t;
    cin >> s >> t;
    int slen = s.size();
    int tlen = t.size();
    vector<vector<int>> dp(slen + 1, vector<int>(tlen + 1));
    for (int i = 1; i <= slen; i++) {
        for (int j = 1; j <= tlen; j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = 1 + dp[i -  1][j - 1];
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    int i = slen;
    int j = tlen;
    string res;
    while (i > 0 && j > 0) {
        if (s[i - 1] == t[j - 1]) {
            res = s[i - 1] + res;
            --i; --j;
        } else {
            if (dp[i - 1][j] == dp[i][j]) i--;
            else j--;
        }
    }
    cout << res << endl;
    //cout << dp[slen][tlen] << endl;
    return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

vi G[55];
int a[22], b[22], u[55], v[55], d[55], pa[55];

void dfs(int u, int p = -1, int depth = 0) {
	d[u] = depth;
	pa[u] = p;
	for(int v:G[u]) if(v != p)
		dfs(v, u, depth + 1);
}

void go(int i, bool ok[][55]) {
	int aa = a[i], bb = b[i];
	if(d[aa] > d[bb]) swap(aa, bb);
	while(d[aa] < d[bb]) {
		ok[pa[bb]][bb] = ok[bb][pa[bb]] = true;
		bb = pa[bb];
	}
	if(aa == bb) return;
	while(aa != bb) {
		ok[pa[bb]][bb] = ok[bb][pa[bb]] = true;
		ok[pa[aa]][aa] = ok[aa][pa[aa]] = true;
		aa = pa[aa];
		bb = pa[bb];
	}
}

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=0;i<n-1;i++) {
		cin >> u[i] >> v[i];
		G[u[i]].PB(v[i]);
		G[v[i]].PB(u[i]);
	}
	dfs(1);
	int m;
	cin >> m;
	for(int i=0;i<m;i++)
		cin >> a[i] >> b[i];
	int ans = 0;
	for(int i=0;i<(1<<m);i++) {
		bool ok[55][55] = {};
		for(int j=0;j<m;j++) {
			if(i>>j&1) {
				go(j, ok);
			}
		}
		int c = 0;
		for(int j=0;j<n-1;j++)
			if(!ok[u[j]][v[j]])
				c++;
		c = 1LL << c;
		if(__builtin_popcount(i)&1) c = -c;
		ans += c;
	}
	cout << ans << endl;
}





Measured memory_bytes: 384
A, B = map(int, input().split())
S = input()

def judge(S):
	if S[A] != "-":
		return False
	if len(S) != A+B+1:
		return False

	S = S[:A] + S[A+1:]

	if not S.isdigit():
		return False
	return True

print("Yes") if judge(S) else print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>

#define INF 100000

using namespace std;
typedef pair<int, int> paii;

int N, M, L, K, A, H;
bool fridge[1000] = {0};
int amat[1001][1001];
int dist[1001][500];

void solve()
{
	queue<paii> qu;	//first...点、second...残り時間
	
	for(int i = 0; i < N; i++)
	{
		for(int j = 0; j <= M; j++){
		
			if(i != A)
				dist[i][j] = INF;
			else
				dist[i][j] = 0;
		}
	}
	
	qu.push(make_pair(A, M));
	
	while(!qu.empty()){
		
		paii p = qu.front();
		qu.pop();
		
		int v = p.first;
		int t = p.second;
		
		if(fridge[v]){
			for(int i = t+1; i <= M; i++){
				if(dist[v][t]+i-t < dist[v][i]){
					
					dist[v][i] = dist[v][t]+i-t;
					qu.push(make_pair(v, i));
				}
			}
		}
		
		for(int i = 0; i < N; i++){
			
			int nt = t - amat[v][i];
			int nd = dist[v][t] + amat[v][i];
			
			if(v!=i && amat[v][i] != 0 && nd < dist[i][nt] && nt >= 0){
				
				dist[i][nt] = nd;
				qu.push(make_pair(i, nt));
			}
		}
	}
	
	int res = INF;
	
	for(int i = 0; i <= M; i++)
			res = min(dist[H][i], res);
	
	if(res < INF)
		cout << res << endl;
	else
		cout << "Help!" << endl;
	
	return;
}

int main()
{
	
	while(cin >> N >> M >> L >> K >> A >> H, N)
	{
		memset(fridge, false, sizeof(fridge));
		memset(amat, 0, sizeof(amat));
		
		fridge[A] = true;
		fridge[H] = true;
		
		for(int i = 0; i < L; i++)
		{
			int a;
			cin >> a;
			fridge[a] = true;
		}
		
		for(int i = 0; i < K; i++)
		{
			int x, y, t;
			cin >> x >> y >> t;
			amat[x][y] = t;
			amat[y][x] = t;
		}
		
		solve();
	}
	
	return 0;
}

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

m = 2+n%2
dp = [[-10**18]*m for i in range(n+2)]
dp[0][0] = 0
for i in range(n):
    for j in range(m):
        if i%2 == j%2:
            x = a[i]
        else:
            x = 0
        if dp[i+1][j] < dp[i][j] + x:
            dp[i+1][j] = dp[i][j] + x
        if j+1 < m and dp[i+1][j+1] < dp[i][j]:
            dp[i+1][j+1] = dp[i][j]
print(max(dp[n][m-2], dp[n][m-1]))


Measured memory_bytes: 65724
#include<stdio.h>

int main(){
  int hour, minute, second, allsecond1, allsecond2;
  int hour1, minute1, second1;
  int hour2, minute2, second2;

  while(1){
    scanf("%d %d %d", &hour, &minute, &second);
    if(hour == -1 && minute == -1 && second == -1) break;

    allsecond1 = 7200 - (3600 * hour + 60 * minute + second);
    hour1 = allsecond1 / 3600;
    minute1 = (allsecond1 - hour1 * 3600) / 60;
    second1 = allsecond1 - hour1 * 3600 - minute1 * 60;

    allsecond2 = allsecond1 * 3;
    hour2 = allsecond2 / 3600;
    minute2 = (allsecond2 - hour2 * 3600) / 60;
    second2 = allsecond2 - hour2 * 3600 - minute2 * 60;

    if(minute1 >= 10)
      printf("0%d:%d", hour1, minute1);
    else
      printf("0%d:0%d", hour1, minute1);

    if(second1 >= 10)
      printf(":%d\n", second1);
    else
      printf(":0%d\n", second1);


    if(minute2 >= 10)
      printf("0%d:%d", hour2, minute2);
    else
      printf("0%d:0%d", hour2, minute2);

    if(second2 >= 10)
      printf(":%d\n", second2);
    else
      printf(":0%d\n", second2);
  }

  return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        var list = new List<decimal>();
        foreach(string s in input)
        {
            list.Add(decimal.Parse(s));        
        }

        decimal result = Math.Truncate(list[0] * list[1]);
        Console.WriteLine(result);
    }

}

Measured memory_bytes: 27952
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
void solve() {
  char c; cin >> c;
  if(c >= 'a') cout << 'a' << '\n';
  else cout << 'A' << '\n';
}
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  while(t--) solve();
  return 0;
}

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

int main(){
  char s[11];
  scanf("%s", s);
  if(strlen(s)%2 == 1){
    printf("No");
    return 0;
  }
  for(int i=0;i< strlen(s);i++){
    if(i%2==0&&s[i]!='h'){
      printf("No");
      return 0;
    }
    if(i%2==1&&s[i]!='i'){
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,1,1,0,-1,-1,-1};
const static int ty[] = {-1,-1,0,1,1,1,0,-1};
 
static const double EPS = 1e-8;

int main(){
  int N;
  while(~scanf("%d",&N)){
    int dp[100100];
    memset(dp,0,sizeof(dp));

    for(int i=0;i<N;i++){
      int lower,upper;
      scanf("%d %d",&lower,&upper);
      dp[lower - 1]++;
      dp[upper]--;
    }

    int res = 0;
    int sum = 0;
    for(int participants=0;participants<=100001;participants++){
      sum += dp[participants];
      if(sum >= participants) res = participants;
    }
    printf("%d\n",res);
  }
}

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

using namespace std;
/*---------------------SAUGATA KUNDU---------------------------*/

#define int long long int
#define INF (int)1e9+5
#define MoD (int)1e9 + 7
#define debug(a) cerr << '[' << a << ']' << '\n'

#define clear(a) memset(a, 0, sizeof(a))
#define fo(i, a, b) for(int i = a; i < b; i++)
#define fos(i, b) for(int i = 0; i < b; i++)
#define foe(i, a) for(auto &i: a)
#define re(i, a, b) for(int i = b; i > a; i--)
#define pb push_back
#define all(c) c.begin(), c.end()
#define sz(x) (int)(x).size()
#define Fast ios::sync_with_stdio(0);cin.tie(0)
//data_structures
#define vt vector
#define que queue
#define sta stack
#define pque priority_queue
#define dque deque

#define point(pt) vt<int>::iterator pt
template<typename T> void read(vt<T> &a){
	fos(i, sz(a)) cin >> a[i];
}

#define endl '\n'
template<typename T> void write(vt<T> a){
	fos(i, sz(a)) cout << a[i] << ' ';
	cout << endl;
}
int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89};
string alpha = "abcdefghijklmnopqrstuvwxyz";
void solve(){
	int n, ans=0;

	cin >> n;
	for(int i=1; i<n; i++){
	   for(int j=1; j<n; j++){
		   if(i*j >= n) break;
		   ans++;
	   }
	}

	cout << ans << endl;
}/*5
1 1
2 2
3 4
5 5
6 6*/

int32_t main() {
	Fast;

	int t=1;
	for(int i=1; i<=t; ++i) {
		solve();
	}

}

Measured memory_bytes: 3648
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=100005;
int n,rt,m,cnt;
int a[maxn],dp[maxn][2],dp2[maxn],d[maxn];
bool exi[maxn];
vector<int>edge[maxn];
char c[maxn];

void dfs1(int x,int p){
	if(c[x]=='W')exi[x]=true;
	rep(i,edge[x].size()){
		int y=edge[x][i];
		if(y==p)continue;
		dfs1(y,x);
		exi[x]|=exi[y];
		if(exi[y])d[x]++;
	}
	if(!exi[x])m--;
} 

void dfs2(int x,int p){
	dp[x][0]=-INF;
	dp[x][1]=dp2[x]=1+a[x];
	bool leaf=true;
	rep(i,edge[x].size()){
		int y=edge[x][i];
		if(y==p||!exi[y])continue;
		leaf=false;
		dfs2(y,x);
		dp2[x]=max(dp2[x],dp2[y]);
		dp2[x]=max(dp2[x],dp[x][0]+dp[y][1]);
		dp2[x]=max(dp2[x],dp[x][1]+max(dp[y][0],dp[y][1]));
		dp[x][0]=max(dp[x][0],dp[y][0]+a[x]+1);
		dp[x][1]=max(dp[x][1],dp[y][1]+a[x]+1);
	}
	if(leaf)dp[x][0]=1+a[x],dp[x][1]=-INF;
	dp2[x]=max(dp2[x],max(dp[x][0],dp[x][1]));
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	m=n;
	REP(i,n-1){
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].pb(v);
		edge[v].pb(u);
	}
	scanf("%s",c+1);
	REP(i,n)if(c[i]=='W')cnt++,rt=i;
	if(!cnt){
		puts("0");
		return 0;
	}
	if(cnt==1){
		puts("1");
		return 0;
	}
	dfs1(rt,0);
	int ans=(m-1)*2;
	REP(i,n)if(exi[i]){
		a[i]=(c[i]=='W')^((d[i]+(i!=rt))&1);
		ans+=a[i];
		if(!a[i])a[i]=-1;
	}
	dfs2(rt,0);
	printf("%d\n",ans-dp2[rt]);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


signed main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    swap(a, b);
    if(a * 2 > h || b * 2 > w){
        cout << "No" << endl;
        return 0;
    }

    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            bool f = (i < a) ^ (j < b);
            cout << f;
        }
        cout << endl;
    }
}


Measured memory_bytes: 1280
N, M = map(int, input().split())
low = 1
high = 1e+5
for i in range(M):
    L, R = map(int, input().split())
    if low < L:
        low = L 
    if R < high:
        high = R
if low > high:
    print(0)
else:
    print(int(high-low+1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1000000007;

int main() {
  ll N, M;
  cin >> N >> M;
  ll ans = min(N, M/2);
  if (M<2) ans = 0LL;
  else if (M-2*N>=4) ans += (M-2*N)/4;
  cout << ans << endl;
}

Measured memory_bytes: 256
// AtCoder Beginner Contest 124 - Problem B: Great Ocean View (https://atcoder.jp/contests/abc124/tasks/abc124_b)
#include <iostream>
#include <vector>

using namespace std;

int solve(int N, const vector<int>& hs)
{
    int ans = 0, m = hs[0];

    for (int i = 1; i < N; ++i)
    {
        if (hs[i] >= m)
            ++ans;

        m = max(m, hs[i]);
    }

    return ans + 1;
}

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

    vector<int> hs(N);

    for (int i = 0; i < N; ++i)
        cin >> hs[i];

    cout << solve(N, hs) << '\n';

    return 0;
}
    


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define MAX_N 200010
#define ll long long
using namespace std;

int bit[MAX_N+1],n;
ll sum(ll i){
	ll s = 0;
	while(i>0){
		s += bit[i];
		i -= i& -i;
	}
	return s;
}
//1-originにする
void add(ll i, ll x){
	while(i<=n){
		bit[i] += x;
		i += i&-i;
	}
}


long long b_sort(string from, string to){
	ll i,k=to.size(),a[MAX_N],ans=0;
	queue<ll> que[26];
	for(i=0;i<k;i++){
		que[to[i]-'a'].push(i+1);
	}
	
	for(i=0;i<k;i++){
		a[i] = que[from[i]-'a'].front();
		que[from[i]-'a'].pop();
	}

	for(i=0;i<MAX_N;i++){
		bit[i] = 0;
	}
	
	for(i=0;i<k;i++){
		ans += i - sum(a[i]);
		add(a[i],1);
	}
	return ans;
}

int main(){
	int i,k,cnt[26]={0},c = 0,a[26]={0};
	string s,l,mid,t,r;
	cin >> s;
	n = s.size();
	for(i=0;i<n;i++){
		a[s[i]-'a']++;
	}
	for(i=0;i<26;i++){
		if(a[i]%2==1){
			c++;
			k = i;
		}
	}
	
	if(c>=2){
		cout << -1 << endl;
		return 0;
	}else{
		for(i=0;i<n;i++){
			if(a[s[i]-'a']%2==1 && cnt[s[i]-'a'] == a[s[i]-'a']/2){
				mid.push_back(s[i]);
				cnt[s[i]-'a']++;
			}else if(cnt[s[i]-'a']<a[s[i]-'a']/2){
				cnt[s[i]-'a']++;
				l.push_back(s[i]);
			}
		}
		t = l;
		reverse(l.begin(),l.end());
		if(c==1){
			t += mid;
		}
		t += l;
		cout << b_sort(s,t) << endl;
	}
}


Measured memory_bytes: 5120
def main():
    from builtins import int, map, list, print, min
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    A = input_number_list()
    B = input_number_list()
    ans = 0
    for i in range(N):
        hp = B[i]
        if A[i] > 0:
            hp = B[i] - A[i]
            ans += B[i] if A[i] > B[i] else A[i]
        if hp > 0:
            ans += hp if A[i+1] > hp else A[i+1]
            A[i + 1] -= hp

    print(ans)


if __name__ == '__main__':
    main()


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

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

	if(a == b) {
		cout << "a == b" << endl;
	} else if(a > b) {
		cout << "a > b" << endl;
	} else {
		cout << "a < b" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long n,a=1,m; cin>>n;
  m=pow(10,9)+7;
  for(int i=1; i<=n; i++){
    a*=i;
    if(a>m) a%=m;
  }
  cout<<a;
}

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

// EPS
constexpr double EPS = 1e-9;
/// --- Geometory Library {{{ ///
using Point = complex<int>;
#define X real()
#define Y imag()
#define dot(a, b) real(conj(a)*b)
#define cross(a, b) imag(conj(a)*b)
#define norm abs

// +1 : ccw
// -1 : cw
// +2 : a--b--c
// -2 : b--c--a
//  0 : b--a--c
// int ccw(Point a, Point b, Point c) {
//   b -= a; c -= a;
//   if(cross(b, c) > EPS) return +1;
//   if(cross(b, c) < -EPS) return -1;
//   if(dot(b, c) < 0) return 0;
//   if(norm(b) < norm(c)) return +2;
//   return -2;
// }
//
// double arg(Point a, Point b) {
//   return acos(dot(a, b) / norm(a) / norm(b));
// }
/// ---}}} ///

bool para(Point a, Point b, Point c) {
  b -= a; c -= a;
  return b.X * c.Y == b.Y * c.X;
}

constexpr ll mod = 998244353;

/// --- modulo Library {{{ ///
constexpr ll extgcd(ll a, ll b, ll& x, ll& y) {
  if(b==0) {
    x = 1; y = 0;
    return a;
  }
  ll d = extgcd(b, a % b, y, x);
  y -= (a / b) * x;
  return d;
}
constexpr ll modpow(ll a, ll b, ll mod = 1e9 + 7) {
  a = (a % mod + mod) % mod;
  ll r = 1;
  while(b){
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}
constexpr ll modinv(ll a, ll mod = 1e9 + 7) {
  a = (a % mod + mod) % mod;
  ll x = 0, y = 0;
  extgcd(a, mod, x, y);
  return (x % mod + mod) % mod;
}
template<int N, int mod = 1e9 + 7> struct Factorial {
  int arr[N+1], inv[N+1];
  int operator[](int i) const { return arr[i]; }
  constexpr Factorial(): arr(), inv() {
    arr[0] = 1;
    for(int i = 1; i <= N; i++) {
      arr[i] = (ll) i * arr[i - 1] % mod;
    }
    inv[N] = modinv(arr[N], mod);
    for(int i = N-1; i >= 0; i--) {
      inv[i] = (ll) (i + 1) * inv[i + 1] % mod;
    }
  }
  int C(int n, int r) const {
    if(n < 0 || r < 0 || n < r) return 0;
    return (ll) arr[n] * inv[r] % mod * inv[n - r] % mod;
  }
};
/// }}}--- ///

constexpr Factorial<200, mod> fact;

bool done[200][200];

// 点集合のうち,(同一直線上の点のみを選ぶ)を覗いた集合の数とスコアが一致
// O(N^3)
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; cin >> n;
  vector<Point> p(n);
  for(int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    p[i] = Point(x, y);
  }
  ll ans = modpow(2, n, mod) - fact.C(n, 2) - n - 1;
  ans %= mod;
  for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) {
    if(done[i][j]) continue;
    int cnt = 2;
    vector<int> vs;
    vs.emplace_back(i);
    vs.emplace_back(j);
    for(int k = j + 1; k < n; k++) {
      if(para(p[i], p[j], p[k])) cnt++, vs.emplace_back(k);
    }
    for(int s = 0; s < (int) vs.size(); s++) for(int t = s + 1; t < (int) vs.size(); t++) {
      done[vs[s]][vs[t]] = 1;
    }
    ans -= modpow(2, cnt, mod) - fact.C(cnt, 2) - cnt - 1;
    ans %= mod;
  }
  cout << (ans + mod) % mod << endl;
}



Measured memory_bytes: 256
#include <iostream>

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

    char prev = '*';
    int l = 0;
    for(const char &c : S){
        if(c != prev){
            ++l; prev = c;
        }
    }

    if(l == 1 || l & 1){
        std::cout << S[0] << std::endl;
    }else{
        std::cout << 'o' << std::endl;
    }
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){

  int N;  cin >> N;
  vector<int> d(N);
  for(int i = 0 ; i < N ; i++)    cin >> d[i];
  sort(d.begin() , d.begin() + N);

  cout << d[N / 2 ] - d[N / 2 - 1] << endl;


  return 0;
}

Measured memory_bytes: 640
def main():
    A, V = map(int, input().split())
    B, W = map(int ,input().split())
    T = int(input())
    
    if W < V:
        if abs(A - B) <= abs(W - V)*T:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9108
import numpy as np
from sys import stdin

def get_result(data):
    K, N = data[0]
    A = data[1]
    tmp = A[0]
    inter_dist = []
    for i in range(1, len(A)):
        inter_dist.append(A[i]-tmp)
        tmp = A[i]
    inter_dist += [K-A[-1]+A[0]]
    ans = sum(inter_dist) - max(inter_dist)
    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Measured memory_bytes: 43948
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  vector<int> l(n+1);
  rep(i, n) cin >> l[i];
  l[n] = INF;
  sort(l.begin(), l.end());
  rep(i, n) {
    rep(j, n) {
      if (i >= j) continue;
      int sum = l[i] + l[j], idx;
      auto itr = lower_bound(l.begin(), l.end(), sum);
      idx = distance(l.begin(), itr) - j - 1;
      ans += idx;
    }
  }

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

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

ll dp[200][200][256];//iまでのj個でkをつくる
ll fact[200];
ll a[200];
int main() {
	fact[0]=1;
	for(ll i=1;i<200;i++)fact[i]=(fact[i-1]*i)%MOD;
	ll n,k;scanf("%lld%lld",&n,&k);
	rep(i,n)scanf("%lld",&a[i]);
	dp[0][0][0]=1;
	rep(i,n){
		rep(j,n){
			rep(t,256){
				dp[i+1][j][t]=(dp[i+1][j][t]+dp[i][j][t])%MOD;
				dp[i+1][j+1][t^a[i]]=(dp[i+1][j+1][t^a[i]]+dp[i][j][t])%MOD;
			}
		}
	}
	ll cnt=0;
	for(ll j=0;j<=n;j++){
		cnt=(cnt+(dp[n][j][k]*fact[j])%MOD)%MOD;
	}
	printf("%lld\n",cnt);
}


Measured memory_bytes: 20992
N, K = gets.split.map(&:to_i)
ary = []
N.times do
  ary << gets.split.map(&:to_i)
end
ary.sort! { |(a1,b1), (a2,b2)| a1<=>a2 }
cnt = 0
while true do
  ab = ary.shift
  cnt += ab[1]
  if cnt >= K
    puts ab[0]
    exit
  end
end  

Measured memory_bytes: 10616
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  string s;cin>>s;
  ll k;cin>>k;
  ll ans = 0;
  ll count = 0;
  rep(i,s.size()){
    if(i==0) continue;
    if(s[i] == s[i-1]){
      count++;
      i++;
    }
  }
  ll x=1,y=1;
  rep(i,s.size()){
    if(i==0) continue;
    if(s[i] != s[i-1]) break;
    x++;
  }
  REP(i,s.size()){
    if(i==s.size()-1) continue;
    if(s[i] != s[i+1]) break;
    y++;
  }
  if(x == s.size()){
    cout<<(s.size() * k)/2<<endl;
    return 0;
  }else{
    if(x%2 == 1 && y%2 == 1 && s[0] == s.back()){
      ans += (k-1);
    }
  }
  ans += count * k;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 636
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};const isPrime=(n:number):boolean=>{if(n<2)return false;const suq=Math.sqrt(n);for(let i=2;i<=suq;i++){if(n%i==0){return false;}}return true;};
const main=()=>{
  let n=tn(),ar=tnn(n),ans=ar[0]
  for(let i=1;i<n;i++){
    ans=gcd(ar[i],ans)
  }
  to(ans)
}
main()


Measured memory_bytes: 27724
N, M, *AB = [int(_) for _ in open(0).read().split()]


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        elif self.rank[x] > self.rank[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.root[self.find(x)]


uf = UnionFind(N)
for a, b in zip(AB[::2], AB[1::2]):
    uf.unite(a, b)
ans = max(uf.size(i) for i in range(1, N + 1))
print(ans)


Measured memory_bytes: 57488
#include <stdio.h> 
#include <string.h>
int henkan(char x[]) {
	int z = 1;
	int y = 0;
	int j = 0;
	for (y = 0; y<10; y++) {
		if (x[y] == 'm') {
			j = j + z * 1000;
		}
		if (x[y] == 'c') {
			j = j + z * 100;
		}
		if (x[y] == 'x') {
			j = j + z * 10;
		}
		if (x[y] == 'i') {
			j = j + z * 1;
		}
		if ('2' <= x[y] && x[y] <= '9') {
			z = x[y]-'0';
		}
		else {
			z = 1;
		}

	}
	return j;
}
int main() {
	int n = 0;
	scanf("%d", &n);
	int i = 0;
	int b = 0;
	int c = 0;
	

	for (i = 0; i < n; i++) {
		char a[10] = {};
		char d[10] = {};
		scanf("%s %s", a, d);
		b = henkan(a) + henkan(d);

		if ((b / 1000) > 1) {
			c = b / 1000;
			printf("%d", c);
		}
		if (b / 1000 >= 1) {
			printf("m");
		}
		b %= 1000;

		if ((b / 100) > 1) {
			c = b / 100;
			printf("%d", c);

		}
		if (b / 100 >= 1) {
			printf("c");
		}
		b %= 100;

		if ((b / 10) > 1) {
			c = b / 10;
			printf("%d", c);
		}
		if (b / 10 >= 1) {
			printf("x");
		}
		b %= 10;

		if (b > 1) {
			printf("%d", b);
		}
		if (b >= 1) {
			printf("i");
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2536
//MIPT Cryptozoology 17.2
#pragma comment(linker, "/STACK:512000000")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(bool);
void precalc();
clock_t start;
#define FILENAME ""

int main() {
#ifdef AIM
    string s = FILENAME;
    //assert(!s.empty());
    freopen("/home/alexandero/ClionProjects/cryptozoology/input.txt", "r", stdin);
#else
    //freopen(FILENAME ".in", "r", stdin);
    //freopen(FILENAME ".out", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    start = clock();
    int t = 1;
    cout.sync_with_stdio(0);
    cin.tie(0);
    precalc();
    cout.precision(10);
    cout << fixed;
    //cin >> t;
    int testNum = 1;
    while (t--) {
        //cout << "Case #" << testNum++ << ": ";
        //cerr << testNum << endl;
        solve(true);
        //cerr << testNum - 1 << endl;
    }
    cout.flush();
#ifdef AIM1
    while (true) {
      solve(false);
  }
#endif

#ifdef AIM
    cout.flush();
    cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif

    return 0;
}

void precalc() {
}

template<typename T>
inline T nxt() {
    T cur;
    cin >> cur;
    return cur;
}

#define int li
//const int mod = 1000000007;

void solve(bool read) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    if (a[n - 1] != 2) {
        cout << "-1\n";
        return;
    }
    int L = 2, R = 2;
    for (int i = n - 2; i >= -1; --i) {
        R += a[i + 1] - 1;
        //cout << L << " " << R << endl;
        if (i < 0) break;
        if (L % a[i]) {
            L += (a[i] - L % a[i]);
        }
        if (R % a[i]) {
            R -= (R % a[i]);
        }
        if (L > R) {
            cout << "-1\n";
            return;
        }
    }
    cout << L << " " << R << endl;
}

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

int n,k;  
string s;

int main() {
  cin >> n >> k;
  cout << ((n+1)/2>=k?"YES":"NO") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int H,W;
char mp[1007][1007];
ll dp[1007][1007];

int main()
{
	io();
	cin>>H>>W;
	for(int i=1;i<=H;++i)
		for(int j=1;j<=W;++j){
			cin>>mp[i][j];
		}
	dp[1][1]=(ll)1;
	for(int i=1;i<=H;++i){
		for (int j=1;j<=W;++j){
			if(mp[i][j]=='#')continue;
			if(mp[i-1][j]=='.'&&mp[i][j-1]=='.')
				dp[i][j]=((dp[i][j]+dp[i-1][j])%mod+dp[i][j-1])%mod;
			else if(mp[i-1][j]=='.')
				dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
			else dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
		}
	}
	cout<<dp[H][W]<<endl;
	return 0;
}


Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<utility>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define P pair<int, int>

using namespace std;


int main(){
	int n;
	int ways[31];
	ways[0] = 1, ways[1] = 1, ways[2] = 2;
	loop(i,3,31){
		ways[i] = ways[i - 1] + ways[i - 2] + ways[i - 3];		
	}

	while (1){
		cin >> n;
		if (n == 0){
			break;
		}
		int ans;
		ans = ways[n] / 3650;
		if (ways[n] % 3650){
			ans++;
		}


		cout << ans << endl;
	}

}

Measured memory_bytes: 1160