akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

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

		int N = Integer.parseInt(sc.next());

		int[] L = new int[N + 1];
		for (int i = 1; i <= N; i++) {
			L[i] = Integer.parseInt(sc.next());
		}

		sc.close();

		Arrays.sort(L);
//		for (int i = 1; i <= N; i++) {
//			System.out.println(L[i]);
//		}

		int count = 0;
		for (int i = 1; i <= N - 2; i++) {
			for (int j = i + 1; j <= N - 1; j++) {
				int min = Math.max(L[i] - L[j], L[j] - L[i]);
				int max = L[i] + L[j];

				min++;
				int Le1 = j + 1;
				int Ri1 = N + 1;
				while (Le1 < Ri1) {
					int M = (Le1 + Ri1) / 2;
					if (L[M] >= min) {
						Ri1 = M;
					} else {
						Le1 = M + 1;
					}
				}

				int Le2 = j + 1;
				int Ri2 = N + 1;
				while(Le2 < Ri2) {
					int M = (Le2 + Ri2) / 2;
					if(L[M] >= max) {
						Ri2 = M;
					}else {
						Le2 = M + 1;
					}
				}

				count += Le2 - Le1;
			}
		}

		System.out.println(count);

	}
}


Measured memory_bytes: 26456
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main()
{
    int n;
    cin>>n;
    vin p(n);
    rep(i,n)cin>>p[i];
    int sum=p[0];
    int tmp=p[0];
    rep2(i,1,n){
        if(i>0&&p[i]<tmp){
            sum-=tmp-p[i]-1;
            tmp=p[i];
        }
        if(tmp==1)break;
    }
    cout<<sum<<endl;
}

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

int main()
{
    int N;
    cin>>N;
    int arr[N];
    for(int i=0; i<N; i++){
        cin>>arr[i];
    }

    int ans=0;
    int check[N];
    for(int i=0; i<N; i++){
        check[arr[i]-1] = i;
    }
    int counter = 1;
    int curr = check[0];
    for(int i=1; i<N; i++){
        if(check[i]>curr){
            curr = check[i];
            counter++;
        }

        else{
            ans = max(ans,counter);
            counter = 1;
            curr = check[i];
        }
    }
    ans = max(ans,counter);

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int n,top;
int a[200005],s[200005],ans1[200005],ans2[200005];
int main()
{
    int n;
    cin>>n;
    LL ans=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=n;i;i--)
	{
		while(top&&a[s[top]]>a[i])top--;
		ans1[i]=s[top]?s[top]:n+1;
		s[++top]=i;
	}
    reverse(a+1,a+n+1);
    top=0;
    for(int i=n;i;i--)
	{
		while(top&&a[s[top]]>a[i])top--;
		ans2[i]=s[top]?n-s[top]+1:0;
		s[++top]=i;
	}
    for(int i=1;i<=n;i++){
        ans+=1LL*(ans1[i]-i)*(i-ans2[n-i+1])*a[n-i+1];
//        cout<<ans1[i]<<" "<<ans2[n-i+1]<<endl;
//    cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include<math.h>
#include <vector>
#include <numeric>

using namespace std;

int main() {

    int N;
    cin >> N;

    int numCounter = 0;
    for (int i = 1; i <= N; ++i) {

        int counter = 0;
        for (int j = 1; j <=i; j+=2) {
            if (i % j == 0) {
                ++counter;
            }
        }

        if (counter == 8) {
            ++numCounter;
        }
    }
    cout << numCounter << endl;
}

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

using namespace std;

int main(void)
{
    string n;
    cin >> n;
    int cnt = 0;
    for (int i = 0; i < n.length();i++){
        cnt += n[i] - '0';
    }
    if(cnt==1)
        cout << 10 << endl;
        else
            cout << cnt << endl;
        return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0;i < N;i++) {
			A[i] = sc.nextInt();
		}
		sc.close();
		int sum = 0;
		for(int i = 0;i < N;i++) {
			if(A[i] == 1) sum += D; 
			else if(D / A[i] >= 1) {
				sum += (D / A[i]) + 1;
				if(D % A[i] == 0) sum--;
			}
			else if(D / A[i] == 0) sum++;
		}
		sum += X;
		System.out.println(sum);
	}
	
}


Measured memory_bytes: 21588
n = int(input())
A = list(map(int, input().split()))

A.sort()

m = A[-1] / 2
diff = abs(A[0] - m)
r = A[0]
for a in A:
    tmp = abs(a - m)
    if tmp < diff:
        diff = tmp
        r = a

print(int(2 * m), r)


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

int main(){
  int a, b;

  int memo[5] = {};

  for(int i = 0;i < 3;i++){
    cin >> a >> b;
    memo[a]++;
    memo[b]++;
  }

  for(int i = 1;i <= 4;i++){
    if(memo[i] >= 3){
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}



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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  double h;
  cin >> h;
  ll n = 0;
  while(h > 0) {
    h = floor(h / 2);
    n++;
  }
  ll ans = 2;
  REP(i,n-1) {
    ans *= 2;
  }
  
  cout << ans - 1;
  
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    ll ans=0,now=0;
    for(int i=0;i<n;i++){
        int a;cin >> a;
        if(!i){
            ans+=a-1;
            now++;
        }
        else if(a==now+1){
            now++;
            continue;
        }
        else{
            ans+=(a-1)/(now+1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <iomanip>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){

//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    int x,y;
    cin >> x >> y;
    string res;
    int list[] = {1,3,5,7,8,10,12};

    bool flg1 = false;
    bool flg2 = false;

    if(x == 2 || y == 2)
    {
        res = "No";
    }
    else
    {
        REP(i,7)
        {
            if(x == list[i])flg1 = true;
            if(y == list[i])flg2 = true;
        }
        if(flg1 == flg2)
        {
            res = "Yes";
        }
        else
        {
            res = "No";
        }
        
    }
    
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr double INF{1e9};
constexpr int MAGIC_PRIME{1000000000 + 7};
constexpr array<int, 4> dy{-1, 1, 0, 0};
constexpr array<int, 4> dx{0, 0, -1, 1};
constexpr int div_ru(int a, int b)
{
    return (a - b + 1) / b;
}
ll pow_mod(ll b, ll e, ll m)
{ // https://atcoder.jp/contests/atc002/tasks/atc002_b
    ll r = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            r = (r * b) % m;
        b = (b * b) % m;
    }
    return r;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m);

    for (int i = 0; i < m; i++)
    {
        cin >> l[i] >> r[i];
    }

    vector<int> imos(n + 1);
    for (int i = 0; i < m; i++)
    {
        imos[l[i] - 1]++;
        imos[r[i] - 1 + 1]--;
    }

    for (int i = 1; i < n; i++)
    {
        imos[i] += imos[i - 1];
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (imos[i] == m)
            ans++;
    }

    cout << ans << endl;

    return 0;
}
// 　　　　　　_......_
// 　　　　 , ´　 <＊y　♪
// 　　　　 i,（i ﾉﾉﾊ）_）
// 　　　　ﾉ_iﾊﾟ ヮﾟﾉﾊ
// 　　　 　 ,´i'_ｿﾉj,〈つ　))
// 　　　　〈_,ﾉ＾＾＾ヽ.´
// 　　　　 .＾＾i_ｿ_ｿ^´
// 　　　　 ￣￣ ￣　
// vector<vector<int>> mm(h, vector<int>(w, -1));


Measured memory_bytes: 1408
#include <cstdio>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;


int main(void) {
  int n;
  scanf("%d", &n);
  for(int i = 1; ; ++i) {
    if(i*i > n) {
      printf("%d\n", (i-1)*(i-1));
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
namespace AtCoder.ABC064
{
    class RGBCard
    {
        public static void Main()
        {
            var rgb = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();
            WriteLine((rgb[1] * 10 + rgb[2]) % 4 == 0 ? "YES" : "NO");
        }
    }
}

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

using namespace std;
int main(void) {
	int n, l;
	string input;


	vector<string> data;
	cin >> n >> l;

	for (int i = 0; i < n; i++) {
		cin >> input;
		data.push_back(input);
	}
	sort(data.begin(), data.end());

	for (int i = 0; i < data.size(); i++)
		cout << data.at(i);

	cout << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;

int main()
{
    vector<ll>a(4);
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    vector<ll> b(10,0);
    for (ll i = 0; i < 4;i++){
        b[a[i]]++;
    }
    if(b[1]>0&&b[9]>0&&b[7]>0&&b[4]>0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e6 + 3;
lli lol[3000][3000], acc[3000][3000];
const lli mod = 1e9 + 7;
lli r1, r2, c1, c2;

lli fat[maxN], invFat[maxN];
lli modPow(lli x, lli y)
{
  lli ans = 1;
  while (y)
  {
    if (y & 1LL) ans = ans * x % mod;
    x = x * x % mod, y >>= 1LL;
  }
  return ans;
}
lli inv(lli x)
{
  return modPow(x, mod - 2);
}
lli choose(lli nn, lli kk)
{
  if (nn < kk) return 0;
  if (nn < mod) return fat[nn] * invFat[kk] % mod * invFat[nn - kk] % mod;
  lli ans = 1;
  while (nn || kk)
  {
    lli nnn = nn % mod, kkk = kk % mod;
    nn /= mod, kk /= mod;
    ans = ans * choose(nnn, kkk) % mod;
  }
  return ans;
}

lli f(lli r, lli c)
{
  return choose(r + c, c);
}

lli g(lli r, lli c)
{
  // f(0 to r, 0 to c)
  return f(r + 1, c + 1);
}

int main()
{
  fat[0] = 1;
  for (lli i = 1; i < maxN; i++)
    fat[i] = i * fat[i - 1] % mod;
  for (int i = 0; i < maxN; i++)
    invFat[i] = inv(fat[i]);

  while (scanf("%lld %lld %lld %lld", &r1, &c1, &r2, &c2) != EOF)
  {
    DEBUG {
      int nn = 3000;
      for (int i = 0; i < nn; i ++)
        lol[i][0] = lol[0][i] = 1;
      lol[0][0] = 1;

      for (int i = 1; i < nn; i ++)
        for (int j = 1; j < nn; j ++)
          lol[i][j] = (lol[i][j - 1] + lol[i - 1][j]) % mod;
      for (int i = 1; i < nn; i ++)
        for (int j = 1; j < nn; j ++)
          acc[i][j] = (acc[i - 1][j] + acc[i][j - 1] - acc[i - 1][j - 1] + lol[i][j] + mod) % mod;

      int n = 10;
      for (int i = 0; i < n; i ++)
        for (int j = 0; j < n; j ++)
          printf("%6lld%c", lol[i][j], j < n - 1 ? ' ' : '\n');
      for (int i = 0; i < n; i ++)
        for (int j = 0; j < n; j ++)
          printf("%6lld%c", acc[i][j], j < n - 1 ? ' ' : '\n');

      lli qq = 0;
      for (int i = r1; i <= r2; i ++)
        for (int j = c1; j <= c2; j ++)
          qq = (qq + lol[i][j]) % mod;

      lli ans = g(r2, c2) - g(r1 - 1, c2) - g(r2, c1 - 1) + g(r1 - 1, c1 - 1);
      printf("%lld %lld\n", ans, qq);
    }
    lli ans = (g(r2, c2) - g(r1 - 1, c2) - g(r2, c1 - 1) + g(r1 - 1, c1 - 1) + mod + mod) % mod;
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 33024
import sys,itertools
N,M,X=map(int,input().split())
ALL=[]
cost=0
for i in range(N):
  listA=list(map(int,input().split()))
  ALL+=[listA]
  cost+=listA[0]
for i in range(1,M+1):
  SUM=0
  for k in range(N):
    SUM+=ALL[k][i]
  if SUM<X:
    print(-1)
    sys.exit()
cost2=10**9    
for take in range(1,N+1):
  takeL=list(itertools.combinations(list(range(N)),take))
  for t in takeL:
    for i in range(1,M+1):
      SUM=0
      cost3=0
      for k in range(take):
        SUM+=ALL[t[k]][i]
        cost3+=ALL[t[k]][0]
      if SUM<X:
        break
      if i==M:
        cost2=min(cost2,cost3)
print(cost2)      

Measured memory_bytes: 9292
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    long K;
    cin >> N >> K;

    vector<int> A(N);
    for (int n = 0; n < N; n++) {
        cin >> A[n];
    }

    int tentou = 0;
    int zyunretu = 0;
    for (int n = 0; n < N; n++) {
        for (int m = n + 1; m < N; m++) {
            if (A[m] < A[n]) {
                tentou++;
            } else if (A[m] > A[n]) {
                zyunretu++;
            }
        }
    }

    cout << (((K * (K + 1) / 2) % MOD) * tentou % MOD + ((K * (K - 1) / 2) % MOD) * zyunretu % MOD) % MOD << "\n";

    return 0;
}


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

int main() {

  int A;
  int B;

  cin >> A >> B;

  if (A > B) {
    exit (1);
  }

  if (A < 9999 || B > 100000) {
    exit (1);
  }

  int sum = 0;
  for (int i = A ; i <= B ; i++) {
    string k;
    k = to_string (i);

    int kl = (int)(k.length ());
    string k1 = k.substr (0, (kl - 1)/2);

    string k2 = k.substr ((kl - 1)/2 + 1, kl - 1);

    string k3;
    for (int j = (int)(k2.length ()) - 1 ; j > -1 ; j--) {
      k3 += k2[j];
    }

    // cout << k1 << " : " << k2 << " : " << k3 << endl;
    if (k1 == k3) {
       sum += 1;
    }
  }

  cout << sum << endl;
  
}


Measured memory_bytes: 3692
def solve(a):
 n = len(a)
 cost = [[0 for i in range(n)] for j in range(n)]
 for length in range(2, n+1):
  for i in range(0, n-length+1):
   k = i+length-1
   def f(i,j,k):
    return cost[i][j-1]+cost[j][k]+M[i][0]*M[j-1][1]*M[k][1]
   cost[i][k] = min([f(i,j,k) for j in range(i+1,k+1)])
 return cost[0][n-1]
n = input()
M = []
for i in range(n):
 M.append(map(int, raw_input().split()))
print solve(M)

Measured memory_bytes: 6488
#include <iostream>
#include <cmath>

using namespace std;

int a,b,x;

const double eps = 1e-8;

#define PI 3.14159265

bool check(double d)
{
    double v;
    d = tan(PI*d/180);
    if(a*d < b)
        v = a*b-0.5*a*a*d;
    else
        v = 0.5*b*b/d;
    
    return x > v*a;
}

int main()
{
    cin >> a >> b >> x;
    
    double l = 0, r = 90;
    while((r-l) > eps) {
        double mid = (l+r)/2;
        if(check(mid)) r = mid;
        else l = mid;
    }
    
    printf("%.8lf",r);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

string solve(){
    string a,b;
    cin >>a >>b;
    int A = a.size(), B = b.size();

    rep(i,A-B+1){
        bool ok = true;
        rep(j,B){
            if(b[j]=='_') continue;
            if(a[i+j] != b[j]) ok = false;
        }
        if(ok) return "Yes";
    }
    return "No";
}

int main(){
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3208
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (int argc, char const *argv[])
{
    int64_t N;
    char A[101], B[101], C[101];
    int64_t i, ans = 0;

    scanf("%"PRId64, &N);
    scanf("%s", A);
    scanf("%s", B);
    scanf("%s", C);

    for (i = 0; i < N; i++) {
        if (A[i] == B[i] && B[i] == C[i]) {
            continue;
        }
        if (A[i] == B[i] || B[i] == C[i] || C[i] == A[i]) {
            ans += 1;
            continue;
        }
        ans += 2;
    }

    printf("%"PRId64"\n", ans);
}


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

int main(){
  int N;
  cin >> N;
  vector<int>H(N);
  for (int i=0; i<N; i++)
    cin >> H.at(i);
  
  int max=0,cnt=0;
  for (int i=0; i<N-1; i++){
    if (H.at(i) >= H.at(i+1)){
      cnt++;
    }else{
      if (max < cnt)
        max = cnt;
      cnt = 0;
    }
  }
  if (max < cnt)
    max = cnt;
  cout << max << endl;
}


Measured memory_bytes: 640
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
//cin.tie(0);
//ios::sync_with_stdio(false);
const llint mod=1000000007;
const llint big=4.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<int>&ar,int in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<int>&ar,int in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
vector<vector<int>>go;
vector<bool>need;
string str;
int hru=0;
int solve(int ter,int per){
	//あるパスを選んで、その頂点のパリティによって減らす
	//白なら-2ということ
	if(!need[ter]){return 0;}
	int ha=0,hb=0;
	for(auto it:go[ter]){
		if(it==per){continue;}
		maxeq(hb,solve(it,ter));
		if(ha<hb){swap(ha,hb);}
	}
	if(str[ter]=='W'){ha+=2;}
	maxeq(hru,ha+hb);
	return ha;
}
int main(void){
	int n,i;cin>>n;
	go.res(n);need.res(n);
	for(i=1;i<n;i++){
		int x,y;cin>>x>>y;x--;y--;
		go[x].pub(y);
		go[y].pub(x);
	}
	for(i=0;i<n;i++){need[i]=true;}
	vector<int>ed(n);
	queue<int>que;
	for(i=0;i<n;i++){
		ed[i]=go[i].size();
		if(ed[i]<=1){que.push(i);}
	}
	//cerr<<"de"<<__LINE__<<endl;
	cin>>str;
	while(que.size()>0){
		int ter=que.front();que.pop();
		if(str[ter]=='W'){continue;}
		else{
			need[ter]=false;
			for(auto it:go[ter]){
				if(need[it]){
					ed[it]--;
					if(ed[it]==1){que.push(it);}
				}
			}
		}
	}
	int ans=0,ninu=0;
	for(i=0;i<n;i++){
		if(need[i]){
			ninu++;
			ans+=2;
			int ki=0;
			for(auto it:go[i]){
				if(need[it]){ki++;}
			}
			if(str[i]=='B'){ki++;}
			
			if(ki%2==0){ans++;str[i]='W';}
			else{str[i]='B';}
		}
	}
	if(ninu==1){ans+=2;}
	//cerr<<str<<endl;
	for(i=0;i<n;i++){if(need[i]){solve(i,-1);cout<<ans-hru-2<<endl;return 0;}}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 13312
N = int(input())
S = sorted(["".join(sorted(input())) for _ in range(N)])

res = 0
ns = S[0]
c = 0
k = 1
for i in range(1, N):
    if S[i] == ns:
        c += k
        k += 1
    else:
        if c != 0:
            res += c
        c = 0
        k = 1
        ns = S[i]

if c != 0:
    res += c

print(res)


Measured memory_bytes: 11408
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0080

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>

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

using namespace std;

//マクロ定義
#define ALL(v) (v).begin(),(v).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); ++i)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define SORT(x) sort(begin(x),end(x))
#define SELECT_SORT(x, n) sort(begin(x),begin(x)+n)
#define SWAP(type, a, b) do {type tmp = a; a = b; b = tmp;} while (0)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))

//定数
#define INF 2000000000000
#define MAX 10

//DEBUG用
#define BAR() cout << "----------------------------" << endl;
#define DUMP(v) (cerr << #v << ": " << v << endl)
#define PRINT(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

double formula(double x, double q){
	return x - ( (pow(x, 3) - q) / ( 3*pow(x,2) ) );
}

int main()
{
	cout.precision(7);
	cout.setf(ios::fixed);
	
	double q;
	double ans;
	while(cin >> q && q != -1)
	{
		ans = q/2;
		while(true){
			if(fabs( pow(ans,3) - q ) < 0.00001*q){ break; }
			ans = formula(ans,q);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1352
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
	ggr
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	for(;;){
		int x,y;
		cin>>x>>y;
		if(x==0&&y==0)break;
		if(x<y){
			cout<<x<<" "<<y<<endl;
		}
		if(x>y){
			cout<<y<<" "<<x<<endl;
		}
		if(x==y){
			cout<<x<<" "<<y<<endl;
		}
	}
}



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

using namespace std;

using ll = long long;

bool Solve() {
    string s, t;
    cin >> s >> t;

    const int ns = s.size(), nt = t.size();
    if (ns < nt) return false;

    for (int i = ns - nt; 0 <= i; --i) {
        bool is_match = true;
        for (int j = 0; j < nt; ++j)
            if (s[i + j] != '?' && s[i + j] != t[j]) is_match = false;

        if (is_match) {
            s.replace(i, nt, t);
            for (int j = 0; j < ns; ++j)
                if (s[j] == '?') s[j] = 'a';

            cout << s << '\n';
            return true;
        }
    }

    return false;
}

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

    if (!Solve()) cout << "UNRESTORABLE\n";

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

vi v;

int main() {
  int n;
  S(n);
  rep(i,0,n) {
    int x;
    S(x);
    v.pb(x);
  }
  sort(all(v));
  if(v[0] == v.back()) {
    if(v[0] == n - 1 || v[0] * 2 <= n) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
    return 0;
  }
  if(v[n-1] - v[0] > 1) {
    printf("No\n");
    return 0;
  }
  int cnt = 0;
  rep(i,0,v.size()) if(v[i] == v[0]) cnt++;
  if((cnt <= v[0] && n >= cnt + (v[0] - cnt + 1) * 2)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 892
import numpy as np
 
x1,y1,x2,y2 = map(int,input().split())
 
x1y1 = np.array([x1,y1])
x2y2 = np.array([x2,y2])
 
vector = x1y1 - x2y2
rotation = np.array([[0,1],
                     [-1,0]])
rotated_vector = np.dot(rotation,vector)
x3y3 = x2y2 + rotated_vector
x4y4 = x3y3 + vector
 
print(*x3y3,end=" ")
print(*x4y4)

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

using namespace std;

int main() {
	int n; scanf("%d", &n);
	int a[n], b[n], c[n]; // a -> 0, b -> 1, c -> 2

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

	int dp[n][3];

	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for(int i=1; i<n; i++) {
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
	}

	printf("%d\n", max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])));

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <map>
#include<string>
#include<vector>

using namespace std;

int main() {
	int n, num = 0, re = 0;
	cin >> n;
	for (int i = 0; i <= n; i++)
	{
		num = 0;
		if (i % 2 != 0)
			for (int j = 1; j <= n; j++)
			{
				if (i%j == 0)
					num++;
			}
		if (num == 8)
			re++;
	}
	cout << re << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7, N = 4e5+5;
vector<ll> all;
int ftree[N];
void add(ll x){
    //cout << "add: " << x << '\n';
    x = lower_bound(all.begin(),all.end(),x)-all.begin()+1;
    for(int i = x; i < N; i += i&(-i))
        ftree[i] += 1;
}
int get(ll x){
    //cout << "get: " << x << ' ';
    x = lower_bound(all.begin(),all.end(),x)-all.begin()+1;
    int ans = 0;
    for(int i = x; i > 0; i -= i&(-i))
        ans += ftree[i];
    //cout << ans << '\n';
    return ans;
}
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i){
        scanf("%d",&arr[i]);
        arr[i] -= k;
    }
    {
        all.push_back(0);
        ll psum = 0;
        for(int i = 0; i < n; ++i){
            psum += arr[i];
            //all.push_back(-psum);
            all.push_back(psum);
        }
        sort(all.begin(),all.end());
        all.erase(unique(all.begin(),all.end()),all.end());
    }
    add(0);
    ll psum = 0;
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        psum += arr[i];
        ans += get(psum); //smaller than or equal to -psum
        add(psum);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define ARRIN(a, n) REP(i, n) cin>>a[i];
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

class unionfind{
  public:
  int Num;
  vector<int> par; //親の番号
  vector<int> height; //木の高さ(ランク)

  unionfind(int N):
    par(vector<int>(N, 0)), height(vector<int>(N, 0)), Num(N) {}


  //初期化
  void init(){
    REP(i, Num){
      par[i] = i;
      height[i] = 0;
    }
  }

  //xの親番号を返す、再帰処理あり
  int root(int x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  //xとyの親番号が同一か判定する
  bool same(int x, int y){
    return root(x) == root(y);
  }

  //xとyのある木を結合する
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x == y) return; //親が同一なら結合済み。

    if(height[x] < height[y]) par[x] = y;
    else {
      par[y] = x;
      if(height[x] == height[y]) height[x]++;
    }
  }
};

int main(){
  int n, k, l;
  cin>>n>>k>>l;
  unionfind ro(n);
  unionfind ra(n);
  map<P, LL> mp;
  ro.init();
  ra.init();
  LL ans, r;
  int t1, t2;
  REP(i, k){
    cin>>t1>>t2;
    --t1;
    --t2;
    ro.unite(t1, t2);
  }

  REP(i, l){
    cin>>t1>>t2;
    --t1;
    --t2;
    ra.unite(t1, t2);
  }

  REP(i, n){
    ++mp[make_pair(ro.root(i), ra.root(i))];
  }
  REP(i, n){
    r=mp[make_pair(ro.root(i), ra.root(i))];
    ECHO(r);
  }
  return 0;
}


Measured memory_bytes: 15104
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::{i32, i64, u32, u64, f64};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

//#[proconio::fastout]

fn main() {
    input!{
        n: usize,
        m: usize,
        submits: [(usize, String); m],
    }
    let mut ans = 0;
    let mut wa = 0;
    let mut pens: Vec<i32> = vec![0; n];
    let mut state = vec![false; n];
    for submit in submits {
        if &submit.1 == "AC" {
            if ! state[submit.0 - 1] {
                ans += 1;
                wa += pens[submit.0 - 1];
                state[submit.0 - 1] = true;
            }
        } else {
            if ! state[submit.0 - 1] { pens[submit.0 - 1] += 1; }
        }
    }
    println!("{} {}", ans, wa);
}



Measured memory_bytes: 10492
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if (u == s)
    {
        cout << a - 1 << " " << b << endl;
    }
    else
    {
        cout << a << " " << b - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
c = {}
for k in range(N):
    if c.get(A[k]) is None:
        c[A[k]] = 1
    else:
        c[A[k]] += 1

x = 0
for i in c:
    x += c[i]*(c[i]-1)//2
for i in range(N):
    print(x+1-c[A[i]])

Measured memory_bytes: 86476
#include <iostream>
using namespace std;
using ll = long long;

int N;
int h[200010],a[200010];
ll dp[200010];

ll query(int x){
    ll ret = 0;
    for(int i = x;0 <  x; x -= x & -x) ret = max(ret,dp[x]);
    return ret;
}

void update(int x,ll v){
    for(int i = x;x <= N; x += x & -x) dp[x] = max(dp[x],v);
}

int main(){
    cin >> N;
    for(int i=1;i<=N;++i) cin >> h[i];
    for(int i=1;i<=N;++i) cin >> a[i];
    for(int i=1;i<=N;++i){
        ll t = query(h[i]) + a[i];
        update(h[i],t);
    }
    cout << query(N) << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
 
using namespace std;
 
const int N = 2e5 + 12, bs = 500;
const ll inf = 1e9;
const double EPS = 0.000001;

int n, k;
ll gr[N], a[N];

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

	cin >> n >> k;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	for(int i = k + 1;i <= n;i++){
		if(a[i] > a[i - k]){
			cout << "Yes\n";
		}
		else{
			cout << "No\n";
		}
	}
}

Measured memory_bytes: 5252
n = int(input())
s = [input() for i in range(n)]
d = {}

for i in range(n):
  if s[i] in d:
    d[s[i]] += 1
  elif not(s[i] in d):
    d[s[i]] =1
    
sort_d = sorted(d.values(),reverse=True)
max = sort_d[0]

ans =[]

for j in d:
  if d[j] == max:
    ans.append(j)

ans.sort()

for i in range(len(ans)):
  print(ans[i])



Measured memory_bytes: 35220
#C - One Quadrillion and One Dalmatians
N = int(input())
A = []
for i in range(1,20):
    a = N%26
    if a == 0:
        N -= 26
        A.append(26)
    else:
        N -= a
        A.append(a)
    if N<=0:
        break
    N //= 26
ans = [chr(j-1+ord('a')) for j in A]
print(''.join(reversed(ans)))

Measured memory_bytes: 8992
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <string>
#include <cstdio>
#include <cmath>
#include <iostream>


#define vpii vector< pair<int,int> >
#define vi vector<int>

#define for0(i,a) for(int i=0;i<a;i++)
#define pii              pair <int,int>
#define pll              pair <long long,long long>
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define ull              unsigned long long
#define f                first
#define s                second
#define sqr(x)           (x)*(x)
#define VI               vector <int>
#define DBG              pf("Hi\n")
#define MOD              1000000007
#define SZ(a)            (int)a.size()
#define sf(a)            scanf("%d",&a)
#define sfl(a)           scanf("%lld",&a)
#define sff(a,b)         scanf("%d %d",&a,&b)
#define sffl(a,b)        scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)
#define loop(i,n)        for(int i=0;i<n;i++)
#define loop1(i,n)       for(int i=1;i<=n;i++)
#define REP(i,a,b)       for(int i=a;i<b;i++)
#define RREP(i,a,b)      for(int i=a;i>=b;i--)
#define intlim           2147483648
#define ull              unsigned long long
// #define gcd(a, b)        __gcd(a, b)
// #define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define mk(x1,y1) make_pair(x1, y1)
#define maxl 100000
#define psz 20
#define Fin      freopen("input.txt","r",stdin)
#define Fout     freopen("output.txt","w",stdout)


/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}

//bool check(int N,int pos){return (bool)(N & (1<<pos));}
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
using namespace std;

int main(){

	ll h1, m1, h2, m2, k;

	scanf("%lld%lld%lld%lld%lld", &h1, &m1, &h2, &m2, &k);

	ll total2 = (h2 * 60) + m2;
	ll total1 = (h1 * 60) + m1;

	ll total = total2 - total1;

	printf("%lld\n", max(0LL, total - k));

    return 0;
}








Measured memory_bytes: 3816
package main

import (
	"fmt"
)

func main() {
	var a, b, c []byte
	fmt.Scan(&a, &b, &c)
	S := [3][]byte{a,b,c}
	var next byte = 0
	for {
		if len(S[int(next)]) == 0 {
			fmt.Printf("%s\n", string(next+'A'))
			return
		}
		next, S[next] = S[next][0] - 'a', S[next][1:]
	}
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int N,D,X,A,ans=0;
    cin >> N;
    cin >> D >> X;
    for(int i=0;i<N;i++){
            cin >> A;
            ans += 1+(D-1)/A;
    }
    cout << X+ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String str = sc.next();
    int count=0;
    int max=0;
    for(int i=0;i<n;i++){
      if(str.charAt(i)=='D'){
        count--;
      }else{
        count++;
      }
      if(count>max){
        max = count;
      }
    }
    System.out.println(max);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <list>
#include <queue>
#include <stack>
#include <map>
#define modulus 1000000007
using namespace std;

long long n;
vector<long long> arr(2000005);

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

long long lcm(long long a, long long b){
    return (a*b)/gcd(a,b);
}

int main(){
    int n;
    cin >> n;
    int d = n % 10;
    if(d == 2 || d == 4 || d == 5 || d == 7 || d == 9){
        cout << "hon" << endl;
    }
    else if(d == 0 || d == 1 || d == 6 || d == 8) cout << "pon" << endl;
    else cout << "bon" << endl;
}

Measured memory_bytes: 18688
using System;
using System.Collections.Generic;
public class ABC124C {
    public static void Main() {
        int ans0 = 0, ans1 = 0;
        string S = System.Console.ReadLine();
        for (int i = 0; i < S.Length; i++) {
            if (i % 2 == 0) {
                if (S[i] == '0') ans1 += 1;
                else ans0 += 1;
            } else {
                if (S[i] == '0') ans0 += 1;
                else ans1 += 1;
            }
        }
        if (ans0 <= ans1) System.Console.WriteLine(ans0);
        else System.Console.WriteLine(ans1);
    }
}

Measured memory_bytes: 13144
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
ll k;
vector<pii> v;

int solve(){
    cin >> n >> k;
    for(int i = 0, a, b; i < n; ++i){
        cin >> a >> b;
        pii p = mp(a, b);
        v.pb(p);
    }
    sort(all(v));
    ll sum = 0;
    for(int i = 0; i < n; ++i){
        sum += v[i].s;
        if(sum >= k) return v[i].f;
    }
    return v[0].f;
}

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

    cout << solve() << "\n";
    
    return 0;
}


Measured memory_bytes: 1400
abc = input().split(' ')

a = int(abc[0])
b = int(abc[1])
c = int(abc[2])

ans = "No"
if(a == b and b != c):
    ans = "Yes"
elif(b == c and a != b):
    ans = "Yes"
elif(c == a and a != b):
    ans = "Yes"

print(ans)

Measured memory_bytes: 3064
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, a, b, c = LI()
ans = []
D = {'A':a, 'B':b, 'C':c}
sx = SR(n)
for i in range(n):
    s = sx[i]
    s1 = s[0]
    s2 = s[1]
    if D[s1] == D[s2] == 0:
        print('No')
        exit()
    elif D[s[0]] == D[s[1]] == 1 and i + 1 < n:
        if s1 in sx[i + 1]:
            D[s1] += 1
            D[s2] -= 1
            ans += [s1]
        else:
            D[s2] += 1
            D[s1] -= 1
            ans += [s2]
    else:
        if D[s1] > D[s2]:
            ans += [s2]
            D[s1] -= 1
            D[s2] += 1
        else:
            ans += [s1]
            D[s1] += 1
            D[s2] -= 1

print('Yes')
print(*ans, sep='\n')

Measured memory_bytes: 94864
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  x -= a;
  int c = x / b;
  int ans = x - (b * c);
  cout << ans << endl;
}


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

using namespace std;

int R, C, K;
char grid[805][805];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int dis[805][805];

bool inside(int r, int c){
  return 1<=r && r<=R && 1<=c && c<=C;
}

void bfs(int sr, int sc){
  queue<pair<int,int>> q;
  memset(dis, -1, sizeof(dis));

  q.push({sr, sc});
  dis[sr][sc] = 0;
  while(!q.empty()){
    pair<int,int> state = q.front();
    q.pop();

    int r = state.first;
    int c = state.second;
    for(int d=0; d<4; d++){
      int nxr = r+dx[d];
      int nxc = c+dy[d];
      if(!inside(nxr, nxc)) continue;
      if(dis[nxr][nxc] != -1 || dis[r][c] + 1 > K) continue;
      if(grid[nxr][nxc] == '#') continue;

      dis[nxr][nxc] = dis[r][c] + 1;
      q.push({nxr, nxc});
    }
  }
}

int ceil(int x, int y){
  return x/y + ((x%y) != 0);
}

int min(int a, int b, int c, int d){
  return min(min(a,b), min(c,d));
}

int getAns(){
  int ans = 1e9;
  for(int i=1; i<=R; i++){
    for(int j=1; j<=C; j++){
      if(dis[i][j] == -1) continue;
      // cout << min(i-1, j-1, R-i, C-j) << endl;
      ans = min(ans, ceil(
        min(i-1, j-1, R-i, C-j),
        K
      ));
    }
  }

  return ans + 1;
}

int main(){
  cin >> R >> C >> K;
  int sr = 0, sc = 0;
  for(int i=1; i<=R; i++){
    for(int j=1; j<=C; j++){
      cin >> grid[i][j];
      if(grid[i][j] == 'S'){
        sr = i;
        sc = j;
      }
    }
  }

  bfs(sr, sc);
  cout << getAns() << endl;
  return 0;
}

Measured memory_bytes: 3964
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val n = readInt()
    val a = readLongList()
    val q = readInt()
    var sumA: Long = a.sum()
    val counter = Array(100001) { 0L }
    a.forEach {
        counter[it.toInt()] = counter[it.toInt()]+1
    }
    val res = mutableListOf<Long>()
    for (i in 0 until q) {
        val (b, c) = readIntList()
        val bNum = counter[b]
        counter[b] = 0L
        counter[c] += bNum
        val d: Long = c * bNum - bNum * b
        sumA += d
        res.add(sumA)
//        println(counter.sliceArray(0..10).joinToString(separator = ","))
    }
    res.forEach {
        println(it)
    }
}


Measured memory_bytes: 69064