akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = Integer.parseInt(s.nextLine());
        String prevWord = null;
        String currWord = null;
        Set<String> set = new HashSet<>();
        boolean isValid = true;
        for(int i = 0; i< n ;i++) {
            currWord = s.nextLine();
            if(set.contains(currWord)) {
                isValid = false;
            }
            set.add(currWord);
            if( isValid && i != 0 ) {
                if(prevWord.charAt(prevWord.length() - 1) != currWord.charAt(0)) {
                    isValid = false;
                }
            }
            prevWord = currWord;
        }
        System.out.println(isValid ? "Yes" : "No");
    }
}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};
 
 
int main(void){
	int N;
	cin>>N;

	ll dp[100]={};
	dp[0]=2;dp[1]=1;
	FOR(i,2,90) dp[i]=dp[i-1]+dp[i-2];
	print(dp[N]);
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc140/tasks/abc140_c
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)
	bi := []int{}
	for i := 0; i < n-1; i++ {
		bi = append(bi, nextInt(sc))
	}

	ai := []int{}
	// B0 >= max(A0, A1)なので、B0で初期化する
	ai = append(ai, bi[0])
	ai = append(ai, bi[0])

	// B1 >= max(A1, A2)なので、Ai = min(Bi, Bi+1)で上書き
	for i := 1; i < len(bi); i++ {
		ai[i] = int(math.Min(float64(bi[i]), float64(ai[i]))) // Ai
		ai = append(ai, bi[i])                                // Ai+1
	}

	res := 0
	for _, a := range ai {
		res += a
	}
	fmt.Println(res)
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for( int i = 0; i < N; i++ ) cin >> d.at(i);
  sort(d.begin(), d.end());
  
  int count = 0;
  int ue = 0;
  for( int i = 0; i < N; i++ ){
    if( d.at(i) > ue ){
      ue = d.at(i);
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define powerof2 ()
#define mp make_pair
#define pi acos(-1)
using ll = long long;
const ll M = 1000000007;
const ll M1= 998244353;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
ll power(ll x,ll y){
	if(y==0)
		return 1;
	ll res=power(x,y/2);
	res=(res*res);
	if(y&1)
		res=(res*x);
	return res;
}
 
ll powermod(ll x,ll y,ll mod){
	if(y==0)
		return 1;
	ll res=powermod(x,y/2,mod);
	res=(res*res)%mod;
	if(y&1)
		res=(res*x)%mod;
	return res;
}
/*ll binarysearch(ll va)
{
	ll n=1;
	ll l=va+1,u=n;
	ll st=num.order_of_key(va);
	while(l+1<u)
	{
		m=(l+u)/2;
		ll in=num.order_of_key(m);
		if(in-st==m-va)
		{
			l=m;
		}
		else
		{
            u=m;
		}
	}
	if(num1.find(l)==num1.end())
		return l;
	return u;
}*/
void solve(){
	int r,g,b;
	cin>>r>>g>>b;
	int k;
	cin>>k;
	int cnt=0;
	while(g<=r || b<=g){
		if(g<=r){g*=2;
		cnt++;}
		if(b<=g){
			b*=2;
			cnt++;
		}
	}
	if(cnt>k) cout<<"No\n";
	else cout<<"Yes\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
 
    for(int i=1;i<=t;i++)
    {//cout<<"Case #"<<i<<": ";
    solve();}
    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main(void){
	int a[4][3][10],b,f,r,v,i,j,k,n;
	char x,d;
	scanf("%d",&n);
	for(i=0;i<4;++i){
		for(j=0;j<3;++j){
			for(k=0;k<10;++k)a[i][j][k]=0;
		}
	}
	for(i=0;i<n;++i){
		scanf("%*c%d %d %d %d",&b,&f,&r,&v);
		a[b-1][f-1][r-1]=v+a[b-1][f-1][r-1];
		if(a[b-1][f-1][r-1]<0)a[b-1][f-1][r-1]=0;
		if(a[b-1][f-1][r-1]>9)a[b-1][f-1][r-1]=9;
	}

	for(i=0;i<4;++i){
		for(j=0;j<3;++j){
			for(k=0;k<10;++k){
				printf(" %d",a[i][j][k]);
			}
		printf("\n");
		}
	if(i==3)break;
	for(n=0;n<20;++n)printf("#");
	printf("\n");
	}

	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int n;
long long int A[100000];

// max_{R} xor_R  + (A xor xor_R)
// max_{R} xor_R and ~A

int main(){
  int i;
  long long int a=0, b, c, z=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lld", A+i);
    a ^= A[i];
  }

  for(b=1LL<<59;b;b>>=1){
    if(b&a) continue;
    for(i=0;i<n;i++){
      if(A[i]&b) break;
    }
    if(i==n) continue;
    if(!(z&b)) z ^= A[i];
    c = A[i];
    for(;i<n;i++){
      if(A[i]&b) A[i] ^= c;
    }
  }

  printf("%lld\n", 2*(z&~a) + a);

  return 0;
}


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

using namespace std;
typedef long long ll;
#define mp make_pair

const int N = 2e5 + 10;
ll a[N];
ll n, k;

ll F[4 * N];

void inc(int i, ll delta) {
	for (; i < n + 1; i = (i | (i + 1)))
		F[i] += delta;
}

ll sum(int r) {
	if (r == 0)
		return 0;
	r--;
	ll res = 0;
	for (; r >= 0; r = (r & (r + 1)) - 1)
		res += F[r];
	return res;
}

ll sum(int l, int r) {
	return sum(r) - sum(l);
} 

ll pref_sum[N];
ll num[N];
int len;

int get_pos(ll t) {
	return lower_bound(num, num + len, t) - num; 
}

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= k;
	}
	pref_sum[n] = 0;
	for (int i = 0; i < n; i++) {
		pref_sum[i + 1] = pref_sum[i] + a[i];
		num[i + 1] = pref_sum[i + 1];
	}
	sort(num, num + n + 1);
	len = unique(num, num + n + 1) - num;
	for (int i = 1; i < n + 1; i++) {
		inc(get_pos(pref_sum[i]), 1);	
	}
	//for (int i = 0; i < n + 1; i++)
	//	cout << pref_sum[i] << " " << get_pos(pref_sum[i]) << endl;
	ll res = 0;
	for (int i = 0; i < n; i++) {

		int pos = get_pos(pref_sum[i]);
		res += sum(pos, n + 1);
//		cout << pos << " " << res << endl;
		inc(get_pos(pref_sum[i + 1]), -1);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    vector<int> v(9, 0);
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        v[min(a/400,8)]++;
    }
    for (int i = 0; i < 8; ++i) {
        if(v[i]) ans++;
    }
    cout << max(ans,1) << " " << ans+v[8] << "\n";
    return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int a, b; cin >> a >> b;
    if (a == 1) a += 13;
    if (b == 1) b += 13;
    cout << (a > b ? "Alice" : a < b ? "Bob" : "Draw") << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
s = [input() for i in range(n)]
sc = [Counter(list(_s)) for _s in s]

ans = ''
for i in range(26):
    cnt = float('inf')
    for _sc in sc:
        cnt = min(cnt, _sc[chr(ord('a')+i)])
    ans+=chr(ord('a')+i)*cnt
print(ans)


Measured memory_bytes: 9436
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

const mod = 1000000007

//const mod = 1000000000000000003

func mpow(a, b int) int {
	if b == 0 {
		return 1
	} else if b%2 == 0 {
		tmp := mpow(a, b/2)
		return tmp * tmp % mod
	}
	return mpow(a, b-1) * a % mod
}

var fracMemo = []int{1, 1}

func mfrac(n int) int {
	if len(fracMemo) > n {
		return fracMemo[n]
	}
	if len(fracMemo) == 0 {
		fracMemo = append(fracMemo, 1)
	}
	for len(fracMemo) <= n {
		size := len(fracMemo)
		fracMemo = append(fracMemo, fracMemo[size-1]*size%mod)
	}
	return fracMemo[n]
}

var ifracMemo = []int{1, 1}

func mifrac(n int) int {
	if len(ifracMemo) > n {
		return ifracMemo[n]
	}
	if len(ifracMemo) == 0 {
		fracMemo = append(ifracMemo, 1)
	}
	for len(ifracMemo) <= n {
		size := len(ifracMemo)
		ifracMemo = append(ifracMemo, ifracMemo[size-1]*mpow(size, mod-2)%mod)
	}
	return ifracMemo[n]
}

func nCr(n, r int) int {
	if n == r {
		return 1
	}
	if n < r || r < 0 {
		return 0
	}
	ret := 1
	ret *= mfrac(n)
	ret %= mod
	ret *= mifrac(r)
	ret %= mod
	ret *= mifrac(n - r)
	ret %= mod
	return (ret)
}

var C [52][52]int // C[n][k] -> nCk

func combTable(N int) {
	C[0][0] = 1
	for i := 1; i <= N; i++ {
		for j := 0; j <= N; j++ {
			if j == 0 || j == i {
				C[i][j] = 1
			} else {
				C[i][j] = C[i-1][j-1] + C[i-1][j]
			}
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)

	N, P := getInt(), getInt()
	d1 := 0
	d2 := 0
	for i := 0; i < N; i++ {
		a := getInt()
		if a%2 == 0 {
			d2++
		} else {
			d1++
		}
	}

	off := 0
	if P == 1 {
		off = 1
	}

	combTable(51)

	ans := 0
	for i := 0; i <= d2; i++ {
		for j := off; j <= d1; j += 2 {
			// out(i, j, "C", d2, i, "C", d1, j)
			ans += C[d2][i] * C[d1][j]
		}
	}
	out(ans)
}


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

using namespace std;

typedef long long LL;

const int N = 1010;

string s, t;

int main()
{
    cin >> s;

    bool flag = true;
    if(s[0] != 'A') flag = false;

    int cnt = 0;
    for(int i = 2; i < s.size() - 1; i++)
        if(s[i] == 'C')
            cnt++;
    if(cnt != 1) flag = false;

    for(int i = 0; i < s.size(); i++)
        if(s[i] != 'A' && s[i] != 'C' && s[i] >= 'A' && s[i] <= 'Z')
            flag = false;

    if(flag) puts("AC");
    else puts("WA");
    return 0;
}


Measured memory_bytes: 256
n = int(input())

ranges = []

for i in range(n):
    x, l = map(int, input().split())
    ranges.append([max(x-l, 0), x+l])

ranges.sort(key=lambda x: x[1])

start = 0
ans = 0
for range in ranges:
    if range[0] >= start:
        start = range[1]
        ans += 1

print(ans)

Measured memory_bytes: 21336
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0,loop;
    string str;
    ll x,y,z;
    cin>>str;
    string s;
    cin>>s;
    for(ll i=str.length()-s.length();i>=0;i--){
        sum=0;
        rep(j,s.length()){
            if(str[i+j]!=s[j]) sum++;
        }
        mini=min(sum,mini);
    }

    cout<<mini<<endl;
    return 0;
}


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

void solve() {
	string s; cin >> s;
	string res;
	for (char c: s) {
		if (c == 'B') {
			if (res.size()) res.pop_back();
		} else {
			res.push_back(c);
		}
	}
	cout << res;
}

int main() {
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
    int n,ans=0;
    cin>>n>>s;
    for(int i=0;i+2<n;i++)
    {
        if(s.substr(i,3)=="ABC") ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

ll v,e;
vector< vector< edge< ll > > > g;
ll dp[15][1<<15];
ll f(ll x,ll mask){
    if(x==0&&mask==(1<<v)-1)return 0;
    if(dp[x][mask]!=-1)return dp[x][mask];
    ll ret=LINF;
    rep(i,g[x].size()){
        if((mask>>g[x][i].to&1)==0){
            chmin(ret,f(g[x][i].to,mask|1<<g[x][i].to)+g[x][i].cost);
        }
    }
    return dp[x][mask]=ret;
}
void solve(){
    cin>>v>>e;
    g=vector< vector< edge< ll > > >(v);
    rep(i,e){
        ll s,t,d;cin>>s>>t>>d;
        g[s].push_back(edge<ll>(t,d));
    }
    memset(dp,-1,sizeof(dp));
    ll ans=f(0,0);
    cout<<(ans==LINF?-1:ans)<<endl;
}

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



Measured memory_bytes: 7064
object Main extends App {
  val n = scala.io.StdIn.readInt()
  val pInput = scala.io.StdIn.readLine()
  val pArray = pInput.split(" ").map(_.toInt).toVector
  var target = pArray.head
  var compareArray = pArray.tail
  var tempResult = 0

  var maxKey = 0
  var result = 1

  compareArray.foreach { p =>
    if (target > p) {
      result = result + 1
      target = p
    }
  }
  println(result)
}

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

long long f(long long n) {
  if (n % 4 == 0) return n;
  if (n % 4 == 1) return 1;
  if (n % 4 == 2) return n + 1;
  return 0;
}

int main() {
  long long a, b;
  cin >> a >> b;
  cout << (f(b) ^ f(a - 1)) << endl;
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
int A[500];
int r[500];
int main() {
	int N, K;
	cin >> N >> K;
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}
	vector<ll> div;
	for (ll i = 1; i*i <= sum; i++) {
		if (sum%i == 0) {
			div.push_back(i);
			if (i*i < sum) div.push_back(sum / i);
		}
	}
	ll ans = 0;
	for (ll d : div) {
		for (int i = 0; i < N; i++) r[i] = A[i] % d;
		sort(r, r + N);
		ll s = 0;
		for (int i = 0; i < N; i++) s += r[i];
		bool ok = 0;
		ll x = 0;
		for (int i = 0; i <= N; i++) {
			ll y = d * (N - i) + x - s;
			if (max(x, y) <= K) {
				ok = 1;
				break;
			}
			if (i < N) x += r[i];
		}
		if (ok) ans = max(ans, d);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys
S = input()
sec = int(S)
if(sec < 86400):
    if(sec >= 0):
        h = int(sec / 3600)
        sec = sec % 3600
        m = int(sec / 60)
        s = sec % 60
        print(h,end="")
        print(":",end="")
        print(m,end="")
        print(":",end="")
        print(s)

Measured memory_bytes: 7660
Program exawizardsB

integer n,x,y,i
character(100) s

read(*,*) n
read(*,*) s

x=0
y=0

do i=1,n
 if (s(i:i)=="R") then
  x=x+1
 else
  y=y+1
 end if
end do
 
if (x>y) then
 write(*,*) 'Yes'
else
 write(*,*) 'No'
end if

stop
end

Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
using namespace std;
int tu[100][100];
int a[100];
int d[100];
int n;
void bfs(int x){
    queue<int> q;
    q.push(x);
    for(int i=0;i<n;i++)d[i]=10000000;
    d[x]=0;
    int u;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(int i=0;i<n;i++){
            if(tu[u][i]==0)continue;
            if(d[i]!=10000000)continue;
            d[i]=d[u]+1;
            q.push(i);
        }
        }
        for(int i=0;i<n;i++){
            printf("%d ",i+1);
            if(d[i]==10000000)printf("-1");
            else printf("%d",d[i]);
            printf("\n");
        }
}
int main(){
    scanf("%d",&n);
    int v,m,k;
    for(int i=0;i<n;i++){
        scanf("%d%d",&v,&m);
        v--;
        for(int j=0;j<m;j++){
            scanf("%d",&k);
            k--;
            tu[v][k]=1;
        }
    }
    bfs(0);
    return 0;
}


Measured memory_bytes: 2732
/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define con continue;
#define MOAE                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
void coutv(vector<ll> v)
{
    for (auto it : v)
        cout << it << " ";
    cout << endl;
}
bool can(ll x, ll y)
{
    return y <= 2 * x;
}
int main()
{
    MOAE;
    ll a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
const int mod = 998244353;

int h1, m1, h2, m2, k;

inline int addMod(int a, int b) {
	return (a += b) >= mod ? a - mod : a;
}

inline ll quickpow(ll base, ll pw) {
	ll ret = 1;
	while (pw) {
		if (pw & 1) ret = ret * base % mod;
		base = base * base % mod, pw >>= 1;
	}
	return ret;
}

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	read(h1), read(m1), read(h2), read(m2), read(k);
	cout << h2 * 60 + m2 - h1 * 60 - m1 - k << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  int num;
  int tmp;

  int n; cin >> n;
  string s; cin >> s;

  vector<int> mem(n);
  
  tmp = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != '#') tmp++;
    mem[i] = tmp;
  }

  // num = n;
  num = min(mem[n - 1], n - mem[n - 1]);

  // for (int i = 0; i <= n; ++i) {
  for (int i = 1; i < n; ++i) {
    int tmp;

    // if (i == 0) { // bbbbbb
    //   tmp = mem[n - 1];
    // } else if (i == n) { // wwwwww
    //   tmp = n - mem[n - 1];
    // } else { // wwwbbb
    tmp = i + mem[n - 1] - 2 * mem[i - 1];
    // }
    num = min(num, tmp);
  }
  
  cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mod 998244353
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
ll fac[200005];
ll ifac[200005];
ll modexp(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b%2)
		return (a*modexp((a*a)%mod,b/2))%mod;
	else
		return modexp((a*a)%mod,b/2);
}
ll ncr(ll x,ll y)
{
	if(x<y)
		return 0;
	ll res=(fac[x]*ifac[x-y])%mod;
	res=(res*ifac[y])%mod;
	return res;
}
void calc()
{
	fac[0]=1;ifac[0]=1;
	ll f=1,i;
	for(i=1;i<=200000;i++)
	{
		f=(f*i)%mod;
		fac[i]=f;
		ifac[i]=modexp(fac[i],mod-2);
	}
}
int main()
{
	ios;
	calc();
	ll n,m,k,i,sum=0,res;
	cin>>n>>m>>k;
	for(i=0;i<=k;i++)
	{
		res=(ncr(n-1,i)*m)%mod;
		res=(res*modexp(m-1,n-i-1))%mod;
		sum=(sum+res)%mod;
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 6740
import itertools

N, M = map(int, input().split())
S = []
for i in range(M):
    tmp = list(map(int, input().split()))
    S.append([tmp[1:]])
P = list(map(int, input().split()))


origin_list = [0, 1]
all_way = []
for i in itertools.product(origin_list, repeat=N):
    all_way.append(i)

ans = 0
for way in all_way:
    light = 0
    for i, s in enumerate(S):
        small_sum = 0
        for ss in s:
            for sss in ss:
                if way[sss - 1] == 1:
                    small_sum += 1
            if small_sum % 2 == P[i]:
                light += 1
        if light == M:
            ans += 1

print(ans)

Measured memory_bytes: 3192
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; string s; cin >> N >> s;

    int ans = 0;
    for(int i=0; i<=N; i++) {
        string A = s.substr(0, i), B = s.substr(i);

        vector<int> cntA(26), cntB(26);
        for(int j=0; j<A.length(); j++) cntA[ A[j] - 'a' ]++;
        for(int j=0; j<B.length(); j++) cntB[ B[j] - 'a' ]++;
        
        int tmp = 0;
        for(int j=0; j<26; j++) tmp += (cntA[j] > 0 and cntB[j] > 0);
        chmax(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N, W;
    cin >> N >> W;
    vll w(N), v(N);
    auto dp = make_v<ll>(N + 1, W + 1); // dp[i][j] := i番目までの品物で重さjにするときの最大価値
    rep(i, N)
    {
        cin >> w[i] >> v[i];
    }
    rep(i, N)
    {
        rep(j, W + 1)
        {
            if (j - w[i] >= 0)
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }
    cout << dp[N][W];
    return 0;
}

Measured memory_bytes: 80256
import numpy as np


def inpl():
    return list(map(int, input().split()))


H, N = inpl()
AB = [inpl() for i in range(N)]

A, B = np.array(AB, dtype=np.int64).reshape(N, 2).T

dp = np.zeros(H + 1, dtype=np.int64)
for i in range(1, H + 1):
    dp[i] = np.amin(dp[np.maximum(i - A, 0)] + B)

print(dp[H])


Measured memory_bytes: 12560
n = int(input())

s_list = [""]*n

for i in range(n):
    s_list[i] = input()

s_list.sort()

ans_list = [s_list[0]]
pre_s = s_list[0]
count = 1
max_count = count

if len(s_list) == len(set(s_list)):
    ans_list = s_list
        
    ans_list.sort()

    for s in ans_list:
        print(s)

    exit()


for i in range(1,n):
    if pre_s == s_list[i]:
        count += 1
        if count == max_count:
            ans_list.append(s_list[i])
        if count > max_count:
            max_count = count
            ans_list = [s_list[i]]
    else:
        pre_s = s_list[i]
        count = 1

ans_list.sort()

for s in ans_list:
    print(s)


    

Measured memory_bytes: 29592
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i]%2 == 1) cnt++; 
  }
  cnt%2 == 1 ? dump("NO") : dump("YES");
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int x=sqrt(double(n));
	cout<<x*x<<endl;
}
	


Measured memory_bytes: 256
import sys
n,k = input().split()

N = int(n)
K = int(k)

if N < K:
    print("NO")
    #sys.exit()
    
elif N == 1 and K == 1:
    print("YES")
    #sys.exit()

elif N % 2 == 0:
    if 2 * K <= N:
        print("YES")
    else:
        print("NO")

elif N % 2 == 1:
    if 2 * K <= N+1:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 3060
def count(n, ps):
    res = 0
    for i in range(1, n - 1):
        qs = (ps[i - 1], ps[i], ps[i + 1])
        if ps[i] == sorted(qs)[1]:
            res += 1
    return res


def main():
    n = int(input())
    ps = [int(p) for p in input().split()]
    res = count(n, ps)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}

signed main(){
  string s,t;
  cin>>s>>t;
  int len=s.size();
  rep(i,s.size()){
      string u;
      u+=s.back();
      u+=s.substr(0,len-1);
      //cout<<u<<endl;
      if(u==t){
        cout<<"Yes"<<endl;
        return 0;
      }
      s=u;
  }
  cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
data = {}
N = int(input())
for i in input().split():
    if i not in data:
        data.update({i: 1})
    else:
        data[str(i)] += 1

ok = 0

if len(data.keys()) > 3:
    pass
elif len(data.keys()) == 1:
    if list(data.keys())[0] == "0":
        ok = 1
elif len(data.keys()) == 2:
    if "0" in data.keys() and data["0"] == N/3:
        ok = 1
else:
    sum = 0
    for i, count in data.items():
        if not count == N/3:
            ok = -1
            break
        sum = sum ^ int(i)
    if ok == 0 and sum == 0:
        ok = 1

if ok == -1:
    ok = 0
print("Yes" if ok else "No")


Measured memory_bytes: 14068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
constexpr ll INF = 1LL<<60;

int main() {
    ll n, m;
    cin >> n >> m;

    vector<ll> v0, v1;
    FOR(i, 2, (n+1)/2+1) {
        if(i%2==0) v0.push_back(i);
        else v1.push_back(i);
    }
    dump(v0);
    dump(v1);

    ll t = -1;
    bool first = true;
    REP(i, m) {
        if(2*i+1 < v0.back()) cout << i+1 << " " << v0.back()-i << "\n";
        else {
            if(first) {
                t = i;
                first = false;
            }
            cout << v0.back()+1+i-t << " " << v0.back()+v1.back()-i+t << "\n";
        }
    }

    // vector<ll> pos(n);
    // REP(i, n) pos[i] = i;
    
    // vector<PII> v;
    // REP(i, n) {
    //     dump(pos);
    //     v.push_back({pos[0], pos[1]});
    //     v.push_back({pos[0], pos[2]});
    //     v.push_back({pos[0], pos[3]});

    //     ll hold = pos[n-1];
    //     for(ll i=n-1; i>=1; --i) pos[i] = pos[i-1];
    //     pos[0] = hold;
    // }
    // sort(ALL(v));
    // dump(v);
    // v.erase(unique(ALL(v)), v.end());
    // dump(v);

    return 0;
}


Measured memory_bytes: 4056
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	ll kotae = -2e18;

	chmax(kotae, A * C);
	chmax(kotae, A * D);
	chmax(kotae, B * C);
	chmax(kotae, B * D);

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	auto F = [&](int x, int y) {return max(to_string(x).length(), to_string(y).length()); };
	for (int i = sqrt(N); i >= 1; i--)if (N%i == 0) {
		cout << F(i, N / i) << endl;
		break;
	}
	return 0;
}

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

int main(){
  	int A, B, C, D;
  	
  	cin >> A >> B >> C >> D;
  
  	if((A+B) > (C+D))	cout << "Left" << endl;
  	else if ((A+B) == (C+D))	cout << "Balanced" << endl;
  	else	cout << "Right" << endl;
  
  	return 0;
}

Measured memory_bytes: 256
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

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

	    int N=gi();
        Map<Long, Integer> map=new TreeMap<>(Collections.reverseOrder());

	    for(int i=0; i<N; i++) {
	        long a=gl();
	        if(map.containsKey(a)) {
	        	map.put(a, map.get(a)+1);
	        } else {
	        	map.put(a, 1);
	        }
	    }
	    
	    long x=0;
	    long y=0;
	    for(Map.Entry<Long, Integer> e : map.entrySet()) {
	    	int v=e.getValue();
	    	if(v>1) {
	    		if(x==0) {
	    			x=e.getKey();
	    			if(v>3) {
	    				y=e.getKey();
	    				break;
	    			}
	    		} else {
	    			y=e.getKey();
	    			break;
	    		}
	    	}
	    }

		System.out.println(x*y);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 64536
my ($H, $W) = split(/ /, <STDIN>);
my $C;
my $i = 0;
while (my $c = <STDIN>) {
        chomp $c;
        my $j = 0;
        foreach my $v (split(//,$c)) {
                $C->{$i}->{$j} = $v;
                $j++;
        }
        $i++;
}
foreach my $i (0..$H-1){
        foreach my $j (0..$W-1){
                if ($C->{$i}->{$j} eq '#'){
                        if (
                                   ( defined($C->{$i+1}->{$j}) && $C->{$i+1}->{$j} eq '#')
                                or ( defined($C->{$i-1}->{$j}) && $C->{$i-1}->{$j} eq '#')
                                or ( defined($C->{$i}->{$j+1}) && $C->{$i}->{$j+1} eq '#')
                                or ( defined($C->{$i}->{$j-1}) && $C->{$i}->{$j-1} eq '#')
                        ) {
                        } else {
                                print 'No';
                                exit 0;
                        }
                }
        }
}
print 'Yes';

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>
#include <cassert>

using namespace std;
using lint = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
using pql = priority_queue<lint>;
using si = set<int>;
#define mii = map<int, int>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, f, n) for (int i = (f); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define pb(x) push_back((x))
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20
#define yes "Yes"
#define no "No"

constexpr lint MOD = 1e9 + 7;
const double PI = acos(-1);
lint A, B, C, D, E, F, G, H, I, J, K, L, M, N;
lint O, P, Q, R, S, T, U, V, W, X, Y, Z;
// string s;
// lint ans;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> X;

	for (lint i = -1000; i <= 1000; i++) {
		for (lint j = -1000; j <= 1000; j++) {
			if (i*i*i*i*i - j*j*j*j*j == X) {
				cout << i << space << j << endl;
				return 0;
			}
		}
	}

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<bitset>
typedef long long LL;
typedef double DB;
#define REP(i,s,t) for(register int i=s;i<=t;++i)
#define PER(i,s,t) for(register int i=s;i>=t;--i)
#define FOREDGE(i,x,v) for(int i=fir[x],v=to[i];i;i=nex[i],v=to[i])
template<typename T>inline T in(){
    T ans=0;bool b=0;char ch=getchar();
    while(ch<'0'||ch>'9')b=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')ans=ans*10+ch-48,ch=getchar();
    return b?-ans:ans;
}
#define II in<int>()
#define IL in<LL>()
//<-----QAQ----->
int n,m,d;
char ch[5]="RYGB";
int main(){
    n=II,m=II,d=II;
    REP(i,1,n){
        REP(j,1,m){
            int x=((m+i+j)/d)&1,y=((m+i-j)/d)&1;
            putchar(ch[x*2+y]);
        }
        puts("");
    }
}

Measured memory_bytes: 512
#ifndef LOCAL
    #pragma GCC optimize("O3")
    #endif
    #include "bits/stdc++.h"
    using namespace std;
    #define sim template <class c
    #define ris return *this
    #define dor > debug &operator<<
    #define eni(x)                                                                    \
        sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
        {
    sim > struct rge
    {
        c b, e;
    };
    sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
    sim > auto dud(c *x) -> decltype(cerr << *x, 0);
    sim > char dud(...);
    struct debug
    {
    #ifdef LOCAL
        ~debug()
        {
            cerr << endl;
        }
        eni(!=) cerr << boolalpha << i;
        ris;
    } eni(==) ris << range(begin(i), end(i));
    }
    sim, class b dor(pair<b, c> d)
    {
        ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d)
    {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
            *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
    }
    #else
        sim dor(const c &)
        {
            ris;
        }
    #endif
    }
    ;
    #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
    #define fastio                        \
        ios_base::sync_with_stdio(false); \
        cin.tie(0);
    #define endl '\n'
    typedef long long ll;
    typedef long double ld;
    const ll MOD = 1e9 + 7;
    const ll N = 1e5 + 10;
    
int arr[26];
    int main()
    {
        fastio
 ll n;
    cin >> n;
    vector<ll> ds;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ds.push_back(i);
            if (n / i != i) {
                ds.push_back(n / i);
            }
        }
    }
    ll best_dist = n-1;
    for (auto d : ds) {
        best_dist = min(best_dist, d + n/d - 2);
    }
    cout << best_dist << endl;




        return 0;
    }

Measured memory_bytes: 384
a1=int(input())
L=[a1,]
ans=0

for i in range(1000000):
    if L[i]%2==0:
        next=int(L[i]/2)
    else:
        next=3*L[i]+1
    if next in L:
         ans=i+2
         break
    L.append(next)


print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
vector<int>ansl;
string s;
int ary[100005] = {0};
char mp[22][22];
int cnt = 0;
int d_x[] = {0,1,0,-1};
int d_y[] = {1,0,-1,0};
int W,H;

void dfs(int x,int y){
  mp[y][x] = '#';
  cnt++;
  for(int d = 0;d<4;d++){
    int nx = x+d_x[d],ny = y+d_y[d];
    if((nx>=0)&&(ny>=0)&&(ny<H)&&(nx<W)&&(mp[ny][nx] == '.')){
      dfs(nx,ny);
    }
  }
}
int main(){
  cin >>W>>H;

  while((W!=0)&&(H!=0)){
    cnt = 0;
    for(int i = 0;i<22;i++){
      for(int j = 0;j<22;j++){
        mp[i][j] = '#';
      }
    }
    for(int i = 0;i<H;i++){
      for(int j = 0;j<W;j++){
        cin >>mp[i][j];
      }
    }
    for (int y = 0; y < H; y++){
      for (int x = 0; x < W; x++) {
        if (mp[y][x] == '@') {
          dfs(x, y);
        }
      }
    }
    cout <<cnt<<endl;
    cin >>W>>H;
  }
  return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

#define loop(i,n) for(int i=1;i<=n;i++)
int score[102];
P order[102];
int r[102];

int main(){
  int n,a,b,c,d;
  cin>>n;
  loop(i,n)score[i]=0;
  loop(i,n*(n-1)/2){
    cin>>a>>b>>c>>d;
    if(c>d)score[a]+=3;
    else if(c<d)score[b]+=3;
    else score[a]++,score[b]++;
  }
  loop(i,n){
    order[i]=P(score[i],i);
  }
  sort(order+1,order+n+1,greater<P>());
  int ps=-1,pr=0;
  loop(i,n){
    if(ps==order[i].first)r[order[i].second]=pr;
    else pr=r[order[i].second]=i,ps=order[i].first;
  }
  loop(i,n)cout<<r[i]<<endl;
  return 0;
}

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	for (char c; (c = getchar()) != '\n';) {
		if (c >= 65 && c <= 90)
			cout << (char)(c + 32);
		else if (c >= 97 && c <= 122)
			cout << (char)(c - 32);
		else
			cout << c;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1112
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    private static final String ex1 = "15\n" +
            "1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n" +
            "9\n" +
            "5 4 3 2 1 2 3 4 5";
    private static final String ex2 = "7\n" +
            "100 200 500 700 1200 1600 2000\n" +
            "6\n" +
            "100 200 500 700 1600 1600";

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

//        solve(new Scanner(ex1));
//        solve(new Scanner(ex2));
    }

    private static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());  // 1 <= N <= 200,000
        String[] line = scanner.nextLine().split(" ");
        int[] D = Arrays.stream(line).mapToInt(Integer::parseInt).toArray();  // 1 <= d <= 10 ** 9
        int M = Integer.parseInt(scanner.nextLine());  // 1 <= M <= 200,000
        line = scanner.nextLine().split(" ");
        int[] T = Arrays.stream(line).mapToInt(Integer::parseInt).toArray();  // 1 <= t <= 10 ** 9

        Map<Integer, Integer> count = new HashMap<>();

        for (int i = 0; i < N; i ++) {
            count.put(D[i], count.getOrDefault(D[i], 0) + 1);
        }

        for (int i = 0; i < M; i ++) {
            if (! count.containsKey(T[i])) {
                System.out.println("NO");
                return;
            }

            int c = count.get(T[i]);

            if (c <= 0) {
                System.out.println("NO");
                return;
            }

            count.put(T[i], c - 1);
        }

        System.out.println("YES");
    }
}


Measured memory_bytes: 109664
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int M=1e5+5;
struct node{
	int w,c;
}a[M];
priority_queue<int> q;
inline int read()
{
	int x=0,f=1; char ch=0;
	while(!isdigit(ch)) f=(ch=='-'?-1:1),ch=getchar();
	while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
bool cmp(const node &a,const node &b)
{
	return a.w<b.w||(a.w==b.w&&a.c>b.c);
}
int main()
{
	int n=read(),k=read();
	for(register int i=1;i<=n;i++){
		a[i].w=read(); a[i].c=read();
	}
	sort(a+1,a+n+1,cmp);
	int now=1,ans=0;
	for(register int i=1;i<=k;i++){
		while(now<=n&&a[now].w<=i){
			q.push(a[now++].c);
		}
		if(!q.empty()) ans+=q.top(),q.pop();
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		int pmonth = -1, pday = -1;
		vector< vector<int> > io(1000);
		vector<int> counters(1000);
		vector<int> integral(24 * 60 + 1);
		for(int t = 0; t <= n; ++t){
			int month, day, hour, minute, id;
			string type;
			if(t < n){
				cin >> month; cin.ignore();
				cin >> day >> hour; cin.ignore();
				cin >> minute >> type >> id;
			}else{
				month = -2;
				day = -2;
				hour = minute = id = 0;
			}
			if(pmonth != month || pday != day){
				for(int i = 0; i < io.size(); ++i){
					if(io[i].size() % 2 == 1){ io[i].push_back(24 * 60); }
				}
				fill(integral.begin(), integral.end(), 0);
				for(int i = 0; i < io[0].size(); ++i){
					integral[io[0][i]] += (i % 2 == 0 ? 1 : -1);
				}
				for(int i = 0, s = 0; i < integral.size(); ++i){
					s += integral[i];
					integral[i] = s;
				}
				for(int i = 0, s = 0; i < integral.size(); ++i){
					const int tmp = s + integral[i];
					integral[i] = s;
					s = tmp;
				}
				for(int i = 1; i < io.size(); ++i){
					for(int j = 0; j < io[i].size(); j += 2){
						counters[i] +=
							integral[io[i][j + 1]] - integral[io[i][j]];
					}
				}
				for(int i = 0; i < io.size(); ++i){ io[i].clear(); }
			}
			io[id].push_back(hour * 60 + minute);
			pmonth = month;
			pday = day;
		}
		cout << *max_element(counters.begin(), counters.end()) << endl;
	}
	return 0;
}

Measured memory_bytes: 1284
from decimal import Decimal

Q, H, S, D = map(int, input().split())
N = int(input())

# 1リットルあたりの単価を出す
s = min([Q*4, H*2, S])
d = Decimal(D)/2

# Nが2で割れる時はリッターあたりの最安値*N
if N%2==0:
    print(int(N*min(s, d)))

# Nが2で割れない時は、N-1までは最安値で買って、残り1リットルはsの単価で買う
else:
    print(int((N-1)*min(s, d) + s))

Measured memory_bytes: 5204
#include<bits/stdc++.h>
using namespace std;
vector<int>a;
#define mod 1000000007
int main()
{
   long long int n,k;
   cin>>n>>k;
   a.resize(n);
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
   }
  unsigned long long post,prev,count=0;
   for(int i=0;i<n;i++)
   {
       prev=0;
       post=0;
       for(int j=0;j<n;j++)
       {
           if(a[j]<a[i])
           {if(j<i) prev++;
            if(j>i) post++;
           }
       }
       count+=(post*((k*(k+1)/2)%mod)%mod);
       count=count%mod;
       count+=(prev*((k*(k-1)/2)%mod)%mod);
       count=count%mod;
       //cout<<a[i]<<' '<<post<<' '<<prev<<endl;
   }
   cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())

i0 = 2
i1 = 1
if n>1:
    for i in range(n-1):
        ans = i0+i1
        i0 = i1
        i1  = ans
if n==0:
    print(2)
elif n==1:
    print(1)
else:
    print(ans)

Measured memory_bytes: 3060
// AOJ 0142: Nature of Prime Numbers
// 2017.8.16 bal4u@uu
// 2017.11.21

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

#define MAX  10000
#define HALF 5000
int sqr[HALF+5];
int a[HALF+5];
int d[HALF+5];
char f[MAX+5];

char prime[MAX+5];
int tbl[24] = {
  3,  5,  7, 11, 13, 17, 19, 23, 29, 31,
 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
 79, 83, 89, 97 };
int sqp[24] = {
  9,25,49,121,169,289,361,529,841,961,
1369,1681,1849,2209,2809,3481,3721,4489,5041,
5329,6241,6889,7921,9409 };

int main()
{
	int n;
	int i, j, k, b, m;
	char buf[10];

	for (i = 0; i < 24; i++) {
		k = tbl[i];
		for (j = sqp[i]; j < MAX; j += k) prime[j] = 1;
	}
	for (i = 1; i <= 5000; i++) sqr[i] = i*i;

	while (fgets(buf, 10, stdin) && *buf != '0') {
		n = atoi(buf), k = n >> 1;
		// 4m+3????´???°
		if (!prime[n] && (n & 3) == 3) {
			sprintf(f, "%d", k-1);
			while(k--) puts(f);
			continue;
		}

		// ???????\???°????????????????????????????¨????
		memset(d, 0, sizeof(d));
		memset(f, 0, sizeof(f));
		for (m = 0, i = 1; i <= k; i++) {
			b = sqr[i] % n;
			if (!f[b]) f[b] = 1, a[m++] = b;
		}
		for (i = 0; i < m; i++) {
			for (j = 0; j < i; j++) {
				if (b = a[i] - a[j]) {
					if (b < 0) b += n;
					if (b > k) b = n - b;
					d[b]++;
				}
			}
		}
		for (i = 1; i <= k; i++) printf("%d\n", d[i]<<1);
	}
	return 0;
}

Measured memory_bytes: 1844