akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const ll N=500001;
ll n,q,c[N],l[N],r[N],a[N],b[N],ans[N];
vector<pair<ll,ll>> x[N];

void add(ll x,ll v){
  for(int i=x;i<=n;i+=i&(-i))
    b[i]+=v;
}

int sum(ll x){
  ll v=0;
  for(int i=x;i>0;i-=i&(-i))v+=b[i];
  return v;
}

int main(){
  ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
  cin>>n>>q;
  for(int i=1;i<=n;i++)cin>>c[i];
  for(int i=1;i<=q;i++){
    cin>>l[i]>>r[i];
    x[r[i]].emplace_back(l[i],i);
  }
  for(int i=1;i<=n;i++){
    if(a[c[i]])add(a[c[i]],-1);
    a[c[i]]=i;
    add(i,1);
    for(auto [d,e]:x[i])ans[e]=sum(i)-sum(d-1);
  }
  for(int i=1;i<=q;i++)cout<<ans[i]<<endl;
}

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

using namespace std;

using ll = long long;

const ll MOD = 2019;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s; cin >> s;
    ll n = s.size();
    vector<ll> cnt(MOD);
    ll tmp = 0;
    cnt[tmp]++;
    ll mul = 1;
    for(ll i=n-1;i>=0;i--){
        // the value of a_{i+1}...a_n
        // 10^{n-(i+1)} a_{i+1} + ... + a_n
        tmp = (ll(s[i] - '0') * mul + tmp) % MOD;
        mul = (mul * 10) % MOD;
        // cout << tmp << endl;
        cnt[tmp]++;
    }
    ll ans = 0;
    for(ll m=0;m<MOD;m++){
        ans += (cnt[m] * (cnt[m] - 1) / 2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3676
import numpy as np

N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
AB = AB[np.argsort(AB[:, 0])]

cnt = 0
sum_A = 0
for a, b in AB:
    sum_A += a * b
    cnt += b
    if cnt > M:
        ans = sum_A - (cnt - M) * a
        break
else:
    ans = sum_A

print(ans)


Measured memory_bytes: 37876
program main
  implicit none
  integer(8) :: n, k, mi, ma, md, i
  integer(8), allocatable :: a(:)
  read *, n, k
  allocate (a(n))
  read *, a(:)
  call quicksort(a)

  ! 積がthres以下になるペアがk個以上ある最小のthres
  mi = -2 * 10_8 ** 18  ! NG
  ma = 2 * 10_8 ** 18  ! OK
  do i = 1, 70
    md = mi + (ma - mi) / 2
    if (isok(md)) then
      ma = md
    else
      mi = md
    end if
  end do

  print "(i0)", ma

  contains

  logical function isok(x)
    ! 積がx以下になるペアがk個以上ある
    integer(8), intent(in) :: x
    integer(8) :: i, cnt
    isok = .false.
    cnt = 0
    do i = 1, n
      cnt = cnt + count_lower(i, x)
      if (cnt >= k) then
        isok = .true.
        return
      end if
    end do
  end function isok

  integer(8) function count_lower(i, x)
    ! a(i) * a(j) <= x となるj>iの数
    integer(8), intent(in) :: i, x
    integer(8) :: j, mi, md, ma
    if (a(i) >= 0) then
      ! a(i) * a(j) <= x となる最大のjを求める
      mi = i  ! ok
      ma = n + 1  ! ng
      do j = 1, 30
        md = mi + (ma - mi) / 2
        if (a(i) * a(md) <= x) then
          mi = md
        else
          ma = md
        end if
        if (ma - mi <= 1) exit
      end do
      count_lower = mi - i
    else
      ! a(i) * a(j) <= x となる最小のjを求める
      mi = i  ! ng
      ma = n + 1  ! ok
      do j = 1, 30
        md = mi + (ma - mi) / 2
        if (a(i) * a(md) <= x) then
          ma = md
        else
          mi = md
        end if
        if (ma - mi <= 1) exit
      end do
      count_lower = n - (ma - 1)
    end if
  end function count_lower

  recursive subroutine quicksort(a)
    integer(8), intent(inout) :: a(:)
    integer(8) :: pivot, i, j, k, tmp, n
    real(8) :: r
    n = size(a)
    if (n <= 1) return
    i = 1
    j = n
    call random_number(r)
    k = 1 + floor(r * n)
    k = max(1_8, min(k, n))
    pivot = a(k)
    do
      do while (.not. pivot <= a(i))
        i = i + 1
      end do
      do while (.not. a(j) <= pivot)
        j = j - 1
      end do
      if (i >= j) exit
      tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
      i = i + 1
      j = j - 1
    end do
    call quicksort(a(1:i - 1))
    call quicksort(a(j + 1:n))
  end subroutine quicksort
end program main


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    bool maki;
    ll num=0;
    vector<ll> ans;
    for(int i=n;i>=1;i--){
        maki=false;
        for(int j=i-1;j>=i-m;j--){
            if(s[j]=='0'){

                maki=true;
                num=j;
                if(j==0){
                    break;
                }
            }
        }
        if(maki){
            ans.pb(i-num);
            if(i)i=num+1;

        }else{
            cout << -1<<endl;
            return 0;
        }

    }
    reverse(be(ans));
    for(int i=0;i<ans.size();i++){
        cout << ans[i]<<" ";
    }
    cout << endl;
    return 0;
}


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

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
	return b == 0 ? a : gcd(b, a%b);
}

int main(){
	int n;
  cin >> n;
  ll res = 1;
  for(int i = 0; i<n; i++){
  	ll t;
    cin >> t;
    ll g = gcd(res, t);
    res/=g;
    res*=t;
  }
  cout << res <<endl;
	return 0;
}

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

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const i64 INF = 1LL << 40;

using VP = vector<tuple<i64, i64>>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  VP pu, pr, pd, pl;
  REP(i, N) {
    i64 x, y;
    char u;
    cin >> x >> y >> u;
    if (u == 'R') {
      pr.emplace_back(x, y);
    } else if (u == 'L') {
      pl.emplace_back(x, y);
    } else if (u == 'U') {
      pu.emplace_back(x, y);
    } else {
      assert(u == 'D');
      pd.emplace_back(x, y);
    }
  }
  i64 ans = INF;

  // Rotates points by k*90 degrees.
  auto rotate = [&](const VP& p, int k) -> VP {
    VP res(p.size());
    REP(i, p.size()) {
      auto [x, y] = p[i];
      REP(j, k) {
        i64 tmp = x;
        x = -y;
        y = tmp;
      }
      res[i] = {x, y};
    }
    return res;
  };

  auto check_ud = [&](const VP& pu, const VP& pd) {
    map<i64, set<i64>> t;
    for (auto [x, y] : pd) {
      t[x].insert(y);
    }
    for (auto [x, y] : pu) {
      auto& s = t[x];
      auto it = s.lower_bound(y);
      if (it == s.end()) continue;
      ans = min<i64>(ans, (*it - y) * 5);
    }
  };

  auto check_dr = [&](const VP& pd, const VP& pr) {
    map<i64, set<i64>> t;
    for (auto [x, y] : pd) {
      t[y - x].insert(x);
    }
    for (auto [x, y] : pr) {
      auto& s = t[y - x];
      auto it = s.lower_bound(x);
      if (it == s.end()) continue;
      ans = min<i64>(ans, 10 * (*it - x));
    }
  };

  check_ud(pu, pd);
  check_ud(rotate(pr, 1), rotate(pl, 1));
  check_dr(pd, pr);
  check_dr(rotate(pl, 1), rotate(pd, 1));
  check_dr(rotate(pu, 2), rotate(pl, 2));
  check_dr(rotate(pr, 3), rotate(pu, 3));

  if (ans == INF) {
    cout << "SAFE" << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 34040
import sys
from collections import deque

n, m = map(int, input().split())
link = [ [] for i in range(n)]
for i in sys.stdin.readlines():
    a, b = map(int, i.split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

d = deque([0])
ans = [-1]*n
ans[0] = 0
while d:
    p = d.popleft()
    for v in link[p]:
        if ans[v] == -1:
            ans[v] = p+1
            d.append(v)

if -1 in ans:
    print("No")
else:
    print("Yes")
    print(*ans[1:], sep="\n")


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

int main() {
    int N, num;
    num=0;
    cin >> N;
 
    for (int i = 1; i <= N; i++) {
        if (i >= 10 && i <= 99) {
            continue;
        } else if (i >= 1000 && i <= 9999) {
            continue;
        } else if (i >= 100000 && i <= 999999) {
            continue;
        } 
 
        num++;
 
    }
 
    cout << num;
 
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	string str;
	cin >> str;

	if (str == "SAT") {
		cout << 1 << endl;
	}
	if (str == "FRI") {
		cout << 2 << endl;
	}
	if (str == "THU") {
		cout << 3 << endl;
	}
	if (str == "WED") {
		cout << 4 << endl;
	}
	if (str == "TUE") {
		cout << 5 << endl;
	}
	if (str == "MON") {
		cout << 6 << endl;
	}
	if (str == "SUN") {
		cout << 7 << endl;
	}
	return 0;
}


Measured memory_bytes: 888
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



int main() {
	int N;
	scanf("%d", &N);
	int T[100];
	for (int i = 0; i < N; i++) {
		scanf("%d", &T[i]);
	}
	int M;
	scanf("%d", &M);
	int P[100], X[100];
	for (int i = 0; i < M; i++) {
		scanf("%d %d", &P[i], &X[i]);
	}

	for (int i = 0; i < M; i++) {
		int ans = 0;
		for (int i = 0; i < N; i++) {
			ans += T[i];
		}
		ans -= (T[P[i]-1] - X[i]);
		printf("%d\n", ans);
	}


#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int v[N],c[N];
  for(int i=0;i<N;i++){
    cin>>v[i];
  }
  for(int i=0;i<N;i++){
    cin>>c[i];
  }
  int ans=0;
  for(int i=0;i<N;i++){
    if(v[i]-c[i]>0){
      ans+=v[i]-c[i];
    }
  }
  cout<<ans;
}

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

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

using namespace std;
using ll=long long;

const int INF = 100000;

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

    res = N / 2 + N % 2;
    cout << res;
    return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())

a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

if x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9108
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846

// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
// int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
// int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
// int x2[]={-2,-2,-1,-1,+1,+1,+2,+2};
// int y2[]={-1,+1,-2,+2,-2,+2,-1,+1};

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===

void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}

int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int x;cin>>x;
    if(x==1)
    cout<<0;
    else
    {
      cout<<1;
    }
    
} 

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  int k;
  cin >> k;
  string ss;
  cin >> ss;
  int s = ss.size();
  mint ans = 0;
  combination comb(k+s);
  rep(i, k+1){
    mint add = mint(25).pow(k-i) * mint(26).pow(i);
    add *= comb(k-i+s-1, k-i);
    ans += add;
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 35592
#include<stdio.h>
int main(void){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if( a >= b ){
		printf("No\n");
	}else if( b >= c ){
		printf("No\n");
	}else if( a >= c ){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
		
	return 0;
}

Measured memory_bytes: 1796
import sys
def input():
    return sys.stdin.readline()[:-1]
N,C=map(int,input().split())
l=[[0]*10**5 for i in range(C)]
for i in range(N):
    s,t,c=map(lambda x: int(x)-1,input().split())
    for j in range(s,t+1):
        l[c][j]=1
a=0
for i in range(10**5):
    t=0
    for j in range(C):
        if l[j][i]:
            t+=1
    if t>a:
        a=t
print(a)

Measured memory_bytes: 65496
#include <stdio.h>
#include <stdlib.h>

int main(void) {

  int h,w;
  scanf("%d %d", &h, &w);
  long a[h][w],b[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      scanf("%ld", &a[i][j]);
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      scanf("%ld", &b[i][j]);
    }
  }
  long ab[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ab[i][j] = labs(a[i][j]-b[i][j]);
    }
  }
  long limit = (h+w)*80;
  long ***dp;
  dp = (long ***)malloc(sizeof (long**) * 80);
  for (long i = 0; i < 80; i++) {
  	dp[i] = (long **)malloc(sizeof (long*) * 80);
    for (long j = 0; j < 80; j++) {
      dp[i][j] = (long *)malloc(sizeof (long) * (limit+1));
      for (long k = 0; k <= limit; k++) {
        dp[i][j][k] = 0;
      }
    }
  }
  long value = ab[0][0];
  dp[0][0][value] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i != 0) {
        for (long k = 0; k <= limit; k++) {
          if (dp[i-1][j][k] == 1) {
            value = labs(k+ab[i][j]);
            dp[i][j][value] = 1;
            value = labs(k-ab[i][j]);
            dp[i][j][value] = 1;
          }
        }
      }
      if (j != 0) {
        for (long k = 0; k <= limit; k++) {
          if (dp[i][j-1][k] == 1) {
            value = labs(k+ab[i][j]);
            dp[i][j][value] = 1;
            value = labs(k-ab[i][j]);
            dp[i][j][value] = 1;
          }
        }
      }
    }
  }
  for (long i = 0; i <= limit; i++) {
    if (dp[h-1][w-1][i] == 1) {
      printf("%ld\n", i);
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 640512
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double A = sc.nextDouble();
    double B = sc.nextDouble();
    double H = sc.nextDouble();
    double M = sc.nextDouble();
    
    double H1 = A*Math.sin(Math.toRadians(H*30+M*0.5));
    double H2 = A*Math.cos(Math.toRadians(H*30+M*0.5));
    double M1 = B*Math.sin(Math.toRadians(M*6));
    double M2 = B*Math.cos(Math.toRadians(M*6));
    
    System.out.println(Math.sqrt(Math.pow((H1-M1), 2) + Math.pow((H2-M2), 2)));
    
  }
}

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

using namespace std;
using lint = long long;

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

lint n, x, m, w, cnt1, cnt2;
vector<lint>vec;
bool used[100010];
int main() {
	cin >> n >> x >> m;

	lint a1 = x;
	while (true) {
		used[a1] = true;
		vec.push_back(a1);
		a1 = a1 * a1 % m;
		if (used[a1]) {
			w = a1;
			break;
		}
	}

	rep(i, vec.size()) {
		if (w == vec[i]) {
			cnt1 = i;
			break;
		}
	}

	// サイクルの長さ
	cnt2 = vec.size() - cnt1;

	if (n <= cnt1 + 1) { // サイクルに入らない
		cout << accumulate(vec.begin(), vec.begin() + n, 0LL) << endl;
	}
	else {
		// サイクルの前
		lint res = accumulate(vec.begin(), vec.begin() + cnt1, 0LL);
		
		// 1つのサイクルの総和
		n -= cnt1;
		lint sum1 = accumulate(vec.begin() + cnt1, vec.end(), 0LL);
		res += n / cnt2 * sum1;
		
		// 最後の余り
		n %= cnt2;
		res += accumulate(vec.begin() + cnt1, vec.begin() + cnt1 + n, 0LL);
		cout << res << endl;
	}
}


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

int main(){
  int n;
  while(cin >> n,n){
    vector<int> time;
    for (int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      time.push_back(tmp);
    }
    sort(time.begin(), time.end());
    long long int ans = 0;
    for (int i = 0; i < n - 1; i++){
      ans += time[i] * (n - (i + 1));
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1320
import sys
input = sys.stdin.readline
n,k,s=map(int,input().split())
if k==0:
    if s<10**9:
        a=s+1
    else:
        a=s-1
    ans=[]
    for i in range(n):
        ans.append(a)
    print(*ans)
    exit()
ans=[]
for i in range(n-k):
    if s<10**9:
        a=s+1
    else:
        a=s-1
    ans.append(a)
for j in range(k):
    ans.append(s)
print(*ans)


Measured memory_bytes: 49232
def pascal(xdata):
	for x in xrange(3):
		for y in xrange(3):
			for z in xrange(3):
				if xdata[x]**2 + xdata[y]**2 == xdata[z]**2:
					return True
	return False

N = input()
data = [map(int, raw_input().split()) for x in range(N)]

for x in data:
	if pascal(x):
		print "YES"
	else:
		print "NO"

Measured memory_bytes: 4304
#include <stdio.h>

int N[10001];

int main()
{
	int n, q;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &N[i]);

	scanf("%d", &q);
	int total = 0, k;
	for (int i = 0; i < q; i++)
	{
		scanf("%d", &k);
		int j = 0;
		N[n] = k;
		while (N[j] != k)
			j++;
		if (j < n)
			total++;
	}
	printf("%d\n", total);

	return 0;
}



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

int main() {
	int a, b; cin >> a >> b;
	cout << a / b << ' ' << a%b << ' ';
	printf("%.7lf\n", (double)a / b);
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int dp[100000];
vector<int> g[100000];
int n,m;
int dp_dfs(int s)
{
    // cout<<s+1<<" "<<dp[s]<<" "<<endl;
    if(dp[s]>=0) return dp[s];
    int maxx=-1;
    for(auto x:g[s]) maxx=max(maxx,dp_dfs(x));
    dp[s]=maxx+1;
    // cout<<endl<<s+1<<" "<<dp[s]<<" "<<endl;
    return dp[s];
}
int32_t main()
{
    IOS
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    int u,v;
    cin>>n>>m;
    for(int i=0;i<m;i++) {cin>>u>>v; g[u-1].push_back(v-1);}
    // for(int i=0;i<n;i++) {cout<<i+1<<": "; for(auto x:g[i]) cout<<x+1<<" "; cout<<endl;}
    int maxx=0;
    for(int i=0;i<n;i++) dp[i]=-1; 
    for(int i=0;i<n;i++)
    {
        maxx=max(maxx,dp_dfs(i));
        // cout<<endl;
    }
    cout<<maxx;
    return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<long> a(n);
    if(n%2 == 0){
		int r = n/2;
		int l = n/2 - 1;
        for(int i = 0; i < n; i++){
            int t;
            cin>>t;
            if(i%2 == 0){
                a[r]=t;
                r++;
            }
            else{
                a[l]=t;
                l--;
            }
        }
    }
    else{
		int r = n/2 + 1;
		int l = n/2;
        for(int i = 0; i < n; i++){
            int t;
            cin>>t;
            if(i%2==0){
                a[l]=t;
                l--;
            }
            else{
                a[r]=t;
                r++;
            }
        }
    }
    for(auto x:a)
        cout<<x<<" ";
}

Measured memory_bytes: 3712
import numpy as np

N, M = [int(i) for i in input().split()]
A = np.cumsum(np.array(input().split(), dtype=int)) % M
ans = 0

remainder = {}
for i in A:
    if i in remainder:
        remainder[i] += 1
    else:
        remainder[i] = 1

for key in remainder:
    ans += remainder[key] * (remainder[key] - 1) / 2

ans += remainder[0] if 0 in remainder else 0
print(int(ans))

Measured memory_bytes: 23840
from collections import deque
import sys
input = sys.stdin.readline

def main():
    S = list(input().strip())
    Q = int(input())

    d = deque(S)
    mode = True

    for _ in range(Q):
        query = input().split()

        if query[0] == "1":
            mode = not mode
        elif query[0] == "2":
            F, C = query[1], query[2]
            if F == "1":
                if mode:
                    d.appendleft(C)
                else:
                    d.append(C)
            elif F == "2":
                if mode:
                    d.append(C)
                else:
                    d.appendleft(C)

    s = list(d)
    if not mode:
        s = s[::-1]

    print(''.join(s))

if __name__ == "__main__":
    main()

Measured memory_bytes: 10868
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
 
typedef long long ll;
 
 
int main(){
	string s;
	cin >> s;
	if(s == "Sunny"){
		cout << "Cloudy" <<endl;
	
	}else if(s == "Cloudy"){
		cout << "Rainy" <<endl;
	
	}else{
		cout << "Sunny" <<endl;
	}
	
	
	
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
        int count=0, i, max=0;
        char s[4];
        scanf("%s", s);
        for(i=0;i<3; i++){
                if(s[i]=='R'){
                        count++;
                }else{
                        count=0;
                }
                if(max<count){
                        max=count;
                }
        }
        printf("%d", max);
        return 0;
}


Measured memory_bytes: 1732
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  string s;
  cin >> s;
  cout << s[0];
  cout << s.length()-2;
  cout << s[s.length()-1] << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    long long N, Q;
    cin >> N >> Q;
    long long sum = 0;
    for (int i = 0; i < Q; i++) {
        int t, k;
        cin >> t >> k;
        if (t == 1) {
            sum += k;
            sum %= N;
        } else {
            cout << (sum + k - 1) % N + 1 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 100001
#define ll long long
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N);
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}
vector<int> adj[N],dis(N),vis(N),indegree(N),topo;
int n,m;
void kahns()
{
    queue<int> q;
    for(int i=1;i<=n;i++)
    if(indegree[i]==0)
    q.push(i),dis[i]=0;
    while(!q.empty())
    {
        int temp = q.front();q.pop();
        topo.pb(temp);
        for(auto u:adj[temp])
        {
            indegree[u]--;
            if(indegree[u]==0)
            q.push(u);
        }
    }
}
void solve()
{
    cin>>n>>m;
    int x,y;
    dis.assign(n+1,INT_MAX);
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);indegree[y]++;
    }
    kahns();
    for(int i=0;i<topo.size();i++)
    {
        int v=topo[i];
        for(auto u: adj[v])
        {
            if(dis[u]>dis[v]-1)
            dis[u]=dis[v]-1;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    ans=max(ans,-dis[i]);
    cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 10872
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define MAX 1000000000000000000LL
long long inf=1000000007;
using namespace std;
int main(){
    int h,w,n;
    cin>>h>>w>>n;
    int a[10005];
    int color[105][105]={};
    
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    
    int k=1;
    
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(a[k]==0)k++;
            color[i][j]=k;
            a[k]--;
        }
    }
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w;j++){
            if(j!=1)cout<<" ";
            if(i%2==1)cout<<color[i][j];
            else cout<<color[i][w-j+1];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#define INF -1
#define N 2000005

int heap_size = 0, A[N];

void maxHeapify(int i){
  int l, r, largest, tmp;

  l = getLeft(i);
  r = getRight(i);
  if(l <= heap_size && A[l] > A[i]){
    largest = l;
  }else{
    largest = i;
  }
  if(r <= heap_size && A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

int getLeft(int i){
  return i *= 2;
}

int getRight(int i){
  return i = i * 2 + 1;
}

int getParent(int i){
  return i = i / 2;
}

int heapExtractMax(){
  int max;
  if(heap_size < 1){
    printf("error\n");
    return;
  }
    max = A[1];
    A[1] = A[heap_size];
    heap_size = heap_size - 1;
    maxHeapify(1);
    return max;
}

void heapIncreaseKey(int i, int key){
  int tmp;
  if(key < A[i]){
    return;
  }
  A[i] = key;
  while(i > 1 && A[getParent(i)] < A[i]){
    tmp = A[i];
    A[i] = A[getParent(i)];
    A[getParent(i)] = tmp;
    i = getParent(i);
  }
}

void maxHeapInsert(int key){
  heap_size = heap_size + 1;
  A[heap_size] = INF;
  heapIncreaseKey(heap_size, key);
}

main(){
  int i, key;
  char com[20];

  while(scanf("%s", com), strcmp(com, "end")){
    if(com[0] == 'i'){
      scanf("%d", &key);
      maxHeapInsert(key);
    }
    if(com[0] == 'e'){
      printf("%d\n", heapExtractMax());
    }
  }
  return 0;
}

Measured memory_bytes: 4696
from operator import mul
from functools import reduce
from collections import Counter

def ncr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n=int(input())
s=["".join(sorted(input())) for _ in range(n)]

c = Counter(s)
ans=0
for v in c.values():
    if v <= 1: continue
    ans += ncr(v, 2)

print(ans)

Measured memory_bytes: 20028
#include <bits/stdc++.h>
    #define INF 4000001
    using namespace std;
    int n,m;
    struct edge{int to,co;};
    vector<edge> g[100010];
    int dis[100010];
    set<int> disc[100010];
    int main()
    {
    	ios::sync_with_stdio(0);
    	cin.tie(0);
     
    	cin>>n>>m;
    	for(int i=0;i<m;i++)
    	{
    		int a,b,c;
    		cin>>a>>b>>c;
    		g[a].push_back({b,c});
    		g[b].push_back({a,c});
    	}
     
    	dis[1]=0;
    	for(int i=2;i<=n;i++)
    		dis[i]=INF;
    	priority_queue<pair<int,int>> q;
    	q.push({-dis[1],1});
    	while(q.size())
    	{
    		int now=q.top().second;
    		int d=-q.top().first;
    		q.pop();
    		if(dis[now]<d) continue;
    		for(edge j:g[now])
    		{
    			//cout<<j.to<<endl;
    			int nd=dis[now];
    			if(!disc[now].count(j.co)) nd++;
    			if(nd<dis[j.to])
    			{
    				dis[j.to]=nd;
    				disc[j.to].clear();
    				disc[j.to].insert(j.co);
    				q.push({-dis[j.to],j.to});
    			}
    			else if(nd==dis[j.to])
    			{
    				disc[j.to].insert(j.co);
    			}
    		}
    	}
    	if(dis[n]==INF)
    		cout<<-1<<endl;
    	else
    		cout<<dis[n]<<endl;
    }

Measured memory_bytes: 23412
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

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

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

	if (b - c >= 0)
		cout << "delicious" << endl;
	else if (b - c >= -a)
		cout << "safe" << endl;
	else
		cout << "dangerous" << endl;


	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC89_4
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split();
            int[] c = new int[] { 0, 0, 0, 0 };
            for (int i = 0; i < N; i++)
            {
                if (s[i] == "P")
                {
                    c[0] = 1;
                }
                else if (s[i] == "W")
                {
                    c[1] = 1;
                }
                else if (s[i] == "G")
                {
                    c[2] = 1;
                }
                else
                {
                    c[3] = 1;
                }
            }
            int sum = 0;
            for (int i = 0; i < 4; i++)
            {
                sum += c[i];
            }
            if (sum == 3)
            {
                Console.WriteLine("Three");
            }
            else
            {
                Console.WriteLine("Four");
            }
        }
    }
}


Measured memory_bytes: 13140
import sys
sys.setrecursionlimit(300000)
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = LMI()

d = defaultdict(int)
for i, a in enumerate(A):
    d[-a + i + 1] += 1

ans = 0
for i, a in enumerate(A):
    c = d[a + i + 1]
    if c > 0:
        ans += c
print(ans)


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

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define sz(c) int(c.size())
#define clr(v, d)   memset(v, d, sizeof(v))
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF             INT64_MAX
#define NINF            INT64_MIN

typedef long long ll;
//typedef pair<int, int> ii;
//typedef pair<ll, ll> pll;
//typedef vector<ii> vii;
//typedef vector<int> vi;
//typedef vector<pll> vll;
//typedef vector<ll> vl;
string s[]={"SUN", "MON", "TUE", "WED", "THU", "FRI",  "SAT"};
int main()
{
    ll n;
    cin>>n;
    string in;
    cin>>in;
    loop(i,in.size())
    {
        loop(j,n)
        {
            if(in[i]=='Z')
                in[i]='A';
            else
                in[i]++;
        }
    }
    cout<<in<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)
	slimes := strings.Split(s, "")
	result := 1
	var prevSlime string
	for i, slime := range slimes {
		if i == 0 {
			prevSlime = slime
		} else {
			if prevSlime != slime {
				result++
				prevSlime = slime
			} else {
				// do nothing
			}
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<P> D;
typedef pair<D, int> Q;

const int MN = 40400;
const ll MD = 1e9+7;

int d6[6][2] = {
    {1, 0},
    {1, -1},
    {0, -1},
    {-1, 0},
    {-1, 1},
    {0, 1},
};

bool near(P a, P b) {
    for (int i = 0; i < 6; i++) {
        P aa = a;
        aa.first += d6[i][0];
        aa.second += d6[i][1];
        if (aa == b) return true;
    }
    return false;
}


int n;
queue<Q> q;
set<D> used;

set<P> s;

D d; int dist;

int x;
void dfs(int i) {
//    cout << "dfsd " << i << endl; 
    if (i == n) {
        if (used.count(d)) return;
        for (int j = 0; j < n; j++) {
            for (int k = j+2; k < n; k++) {
                if (d[j] == d[k]) return;
                if (near(d[j], d[k])) return;
            }
        }
        for (int j = 0; j < n; j++) {
            if (s.count(d[j])) return;
        }
        used.insert(d);
        q.push(Q(d, dist+1));
        return;
    }
    if ((x & (1<<i)) == 0) {
        if (i == 0 || near(d[i-1], d[i])) dfs(i+1);
        return;
    }
    for (int j = 0; j < 6; j++) {
        d[i].first += d6[j][0];
        d[i].second += d6[j][1];
        bool f = true;
        if (i != 0 && !near(d[i-1], d[i])) f = false;
        if (f) {
            for (int j = 0; j < i-1; j++) {
                if (d[j] == d[i]) {
                    f = false;
                    break;
                }
                if (near(d[j], d[i])) {
                    f = false;
                    break;
                }
            }
        }   
        if (f) dfs(i+1);
        d[i].first -= d6[j][0];
        d[i].second -= d6[j][1];
    }
}

bool solve() {
    cin >> n;
    if (!n) return false;
    D v;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        v.push_back(P(x, y));
    }
    int k;
    cin >> k;
    s.clear();
    for (int i = 0; i < k; i++) {
        int u, v;
        cin >> u >> v;
        s.insert(P(u, v));
    }
    int X, Y;
    cin >> X >> Y;
    q = queue<Q>();
    used.clear();
    used.insert(v);
    q.push(Q(v, 0));
    int back = -1;
    while (q.size()) {
        tie(d, dist) = q.front(); q.pop();
        if (dist != back) {
//            cout << dist << endl;
            back = dist;
        }
        if (d[0] == P(X, Y)) {
            cout << dist << endl;
            return true;
        }
        for (x = 0; x < (1<<n); x++) {
            bool f = true;
            for (int j = 0; j < n-1; j++) {
                if ((x & (1<<j)) == 0) continue;
                if ((x & (1<<(j+1))) == 0) continue;
                f = false;
                break;
            }
            if (!f) continue;
//            cout << "dfs " << x << endl;
            dfs(0);
        }
    }
    assert(false);
}

int main() {
    while (solve()) {}
    return 0;
}

Measured memory_bytes: 37112
#include <stdio.h>

int main (void)
{
	int i,a, j;
	int max[3];
	int yama[10];

	for(i=0;i<10;i++)
	{
		scanf("%d",&yama[i]);

	}

	for(i=0;i<9;i++){
		for(j = i + 1; j < 10; j++){
			if(yama[i] < yama[j]){
				a = yama[i];
				yama[i] = yama[j];
				yama[j] = a;
			}
		}
	}
	for(i = 0; i < 3; i++){
		printf("%d\n", yama[i]);
	}

	return 0;
}

Measured memory_bytes: 600
#include <iostream>

int main(){
	int m, n,p,i;
	while (std::cin >> n >> m, n != 0 && m != 0){
		p = 0;
		for (i = 2; i <= n; i++){
			p = (p + m) % i;
		}
		std::cout << p+1 << "\n";
	}
}

Measured memory_bytes: 1164
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC target ("avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define orz ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);    
#define inp freopen("input.txt","r",stdin);freopen("out.txt","w",stdout); 
ll mod=1e9+7;
void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.tie(NULL);    
   
}
const int N=2e5+5;

ll pre[N][26];
int main() {
    io();
    ll i,j,k,n,m,prev=0,cnt=0;
    string s,t;

    cin>>s>>t;
    n=s.length();
    s+=s;
    for(i=2*n-1;i>=0;i--){
        for(j=0;j<26;j++){
            if(i!=(2*n-1))
                pre[i][j]=pre[i+1][j];
            else
                pre[i][j]=2*n;
            pre[i][s[i]-'a']=i;
        }
    }
    auto next = [&](const string &S) {
        int n1 = (int)S.size();
        vector<vector<int>> res(n1 + 1, vector<int>(26, n1));
        for(int i = n1 - 1; i >= 0; --i) {
            for(int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
            res[i][S[i] - 'a'] = i;
        }
        return res;
    };
    vector<vector<int>> nx = next(s);
    prev=-1;
    ll ans=-1;
    for(i=0;i<t.length();i++){
        prev=(ans+1)%n;
        k=nx[prev][t[i]-'a'];
        if(k==2*n){
            cout<<"-1";
            return 0;
        }
        ans +=  nx[prev][t[i]-'a'] - prev +1;

        
    }
    cout<<ans+1;
}





Measured memory_bytes: 67692
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <random>
#include <utility>
#include <map>
#include <vector>
#define REP(i,x) for(int i=0; i<(x); i++)

using namespace std;

int half(int a){
    if ((a%2)!= 0){
        return 0;
    } else {
        return half(a/2)+1;
    }
}

int main(int argc, const char * argv[]) {
    int a;
    cin >> a;
    int b[a];
    int c[a];
    REP(i, a){
        cin >> b[i];
        c[i] = half(b[i]);
    }
    int d = 10000;
    REP(i, a){
        if (c[i]<d){
            d=c[i];
        }
    }
    
    cout << d << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N, K;
  cin >> N >> K;
  if(N % K == 0)
    cout << 0 << endl;
  else
    cout << 1 << endl;
  return 0;
}



Measured memory_bytes: 764
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.*
import kotlin.math.*

fun main() {
    var fs = Atcoder.FastReader()
    var a = fs.readIntArray(5)
    for (i in 0 until a.size) {
        if(a[i] == 0){
            println("${i+1}")
            break
        }
    }

}
private fun gcd(i: Int, j: Int):Int {
    var max = max(i, j)
    var min = min(i, j)
    var rest:Int = max%min
    var oldRest:Int = min
    while (rest != 0) {
        max = min
        min = rest
        oldRest = rest
        rest = max%min
    }
    return oldRest
}
class Atcoder {
    internal class FastReader {
        private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))
        private var st: StringTokenizer? = null

        operator fun next(): String {
            while (st == null || !st!!.hasMoreElements()) {
                try {
                    st = StringTokenizer(br.readLine())
                } catch (e: IOException) {
                    e.printStackTrace()
                }

            }
            return st!!.nextToken()
        }

        fun nextInt(): Int {
            return Integer.parseInt(next())
        }

        fun nextLong(): Long {
            return java.lang.Long.parseLong(next())
        }

        fun nextDouble(): Double {
            return java.lang.Double.parseDouble(next())
        }

        fun nextLine(): String {
            var str = ""
            try {
                str = br.readLine()
            } catch (e: IOException) {
                e.printStackTrace()
            }
            return str
        }

        fun readIntArray(n: Int): IntArray {
            val a = IntArray(n)
            for (i in 0 until n) a[i] = nextInt()
            return a
        }

        fun readLongArray(n: Int): LongArray {
            val a = LongArray(n)
            for (i in 0 until n) a[i] = nextLong()
            return a
        }

        fun readDoubleArray(n: Int): DoubleArray {
            val a = DoubleArray(n)
            for (i in 0 until n) a[i] = nextDouble()
            return a
        }
    }
}


Measured memory_bytes: 34260
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first >> a[i].second;
	}

	sort(all(a), [](pair<int, int> &a, pair<int, int> &b)
		{
			if (a.first == b.first)
			{
				return a.second < b.second;
			}

			return a.first < b.first;
		});

	for (auto p : a)
	{
		println(p.first << " " << p.second);
	}
}



Measured memory_bytes: 3640
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            long k = sc.nextLong();
            boolean[] v = new boolean[n];
            long[] s = new long[n];
            int[] a = new int[n];
            for(int i=0; i<n; i++) {
                a[i] = sc.nextInt() - 1;
            }
            v[0] = true;
            long t = 0;
            int pos = 0;
            while(true) {
                t++;
                pos = a[pos];
                if(k == t) {
                    System.out.println(pos + 1);
                    return;
                }
                if(v[pos]) {
                    long p = t - s[pos];
                    k -= t;
                    k %= p;
                    while(k > 0) {
                        pos = a[pos];
                        k--;
                    }
                    System.out.println(pos + 1);
                    return;
                } else {
                    s[pos] = t;
                    v[pos] = true;
                }
            }

    }



}

Measured memory_bytes: 62836
#include <iostream>
#include <iomanip>
#include <vector>

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

using namespace std;
int main() { 
  int n,x;
  cin>>n>>x;
  vector<int> l(n);
  int ans=1,sum=0;
  rep(i,0,n){
    cin>>l[i];
    sum+=l[i];
    if(sum<=x) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
from itertools import*
input()
mod=10**9+7

x=[len(list(v))for k,v in groupby(input())]
if x[0]==1:
    ans=3
else:
    ans=6
if len(x)==1:
    print(ans)
else:
    for i in range(1,len(x)):
        if x[i-1]==1 and x[i]==1:
            ans*=2%mod
        elif x[i-1]==2 and x[i]==2:
            ans*=3%mod
        elif x[i-1]==1 and x[i]==2:
            ans*=2%mod
    print(ans%mod)

Measured memory_bytes: 3064