akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<string.h>
#include <math.h>
#include<iostream>
using namespace std;
typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         ld;

#define sf                  scanf
#define pf                  printf
#define srev                reverse(s.begin(),s.end())
#define sortstr             sort(s.begin(), s.end());
//#define gtl(s)              getline(cin, (s));
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define PI                  acos(-1)
#define Precision(a) cout << fixed << setprecision(a)
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


template <typename T> T Sqr(T x) { T n = x * x ; return n ;}
template <typename T> T Pow(T B,T P){ if(P==0) return 1; if(P&1) return B*Pow(B,P-1);  else return Sqr(Pow(B,P/2));}
template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
template <typename T> T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template <typename T> T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
//scanf("%[^\n]", str);
//sort(s,s+n,greater<int>());

int main()
{
    FasterIO
    string s, a, b;
    int x;
    cin >> s;
    x=s.length();
    a=s.substr(0, x/2);
    b=s.substr(x/2+1, x/2);
    if(a==b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char a1[10], a2[10], a3[10];
    scanf("%s %s %s",&a1, &a2, &a3);
    a1[0]=a1[0]-32;
    a2[0]=a2[0]-32;
    a3[0]=a3[0]-32;
    printf("%c%c%c", a1[0], a2[0], a3[0]);
    return 0;
}

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            var raw_inputs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var N = raw_inputs[0];
            var M = raw_inputs[1];

            var likes = Console
                    .ReadLine()
                    .Split(' ')
                    .Skip(1)
                    .Select(x => int.Parse(x))
                    .ToArray();

            for (int i = 1; i < N; i++)
            {
                var likes2 = Console
                    .ReadLine()
                    .Split(' ')
                    .Skip(1)
                    .Select(x => int.Parse(x))
                    .ToArray();

                likes = likes.Intersect(likes2).ToArray();
            }

            Console.WriteLine(likes.Count());
        }
    }
}


Measured memory_bytes: 11476
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

ll arr[200005];

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n)
    {
		ll tot = 0;

		for(i = 1; i <= n; i++) slld(arr[i]), tot ^= arr[i];

		for(i = 1; i <= n; i++)
		{
			ll x = tot ^ arr[i];

			cout << x << " ";
		}

		cout << '\n';
    }


}





Measured memory_bytes: 5104
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var cnt=0;
   while(n!=1){
      cnt++;
      if(n%2==0)n=n/2;
      else n=(3*n)+1;
   }
   console.log(cnt);
}

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

ll n,a,b,c;
string s,t;

int main(){
    cin>>s>>t;
    cin>>a>>b;
    string u;
    cin>>u;
    if(s==u){
        cout<<a-1<<' '<<b;
    }else if(t==u){
        cout<<a<<' '<<b-1;
    }else{
        cout<<a<<' '<<b;
    }
}

Measured memory_bytes: 256
/*Bismillahir Rahmanir Rahim*/
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf

#define sf1(a)			scanf("%d",&a);
#define sf2(a,b)		scanf("%d%d",&a,&b);

#define ll				long long

#define fin             freopen("input.txt","r",stdin);
#define fout            freopen("output.txt","w",stdout);

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,c=1,x;
	cin >> n;
	vector <int> v;
	
	for(int i=0;i<n;i++){
		cin >> x;
		if(x==c){
			c++;
			v.push_back(x);
			
		}
	}
	(v.size()>0)? cout << n-v.size() << endl : cout << -1 <<endl;
	return 0;
}



Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pi  3.14159265358979323846
#define mod 1000000007
#define pf push_front
#define pb push_back
#define flush fflush(stdout);
#define null NULL
#define test cout<<"#";
 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(null);
    ll x, y, a, b, c;
    cin>>x>>y>>a>>b>>c;
    priority_queue<ll> p;
    priority_queue<ll> q;
    priority_queue<ll> r;
    for(ll x1 = 0; x1 < a; x1++)
    {
        ll d;
        cin>>d;
        p.push(d);
    }
    for(ll x1 = 0; x1 < b; x1++)
    {
        ll d;
        cin>>d;
        q.push(d);
    }
    for(ll x1 = 0; x1 < c; x1++)
    {
        ll d;
        cin>>d;
        r.push(d);
    }
    vector<ll> v;
    ll a1 = x, b1 = y;
    while(a1!=0)
    {
        v.pb(p.top());
        p.pop();
        a1--;
    }
    while(b1!=0)
    {
        v.pb(q.top());
        
        q.pop();
        b1--;
    }
    while (c!=0)
    {
        v.pb(r.top());
        //cout<<r.top()<<"\n";
        r.pop();
        c--;
    }
    ll sum = 0;
    sort(v.begin(), v.end());
    /*for(ll x1 = 0; x1 < v.size(); x1++)
        cout<<v[x1]<<" ";*/
    ll e = v.size();
    for(ll z = e-1; z>=e-x-y; z--)
        sum += v[z];
    cout<<sum;
}
    


Measured memory_bytes: 8688
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;

int x,y;
int n;
int maze[100][100][11];//y,x,n
bool d[100][100][11];//y,x,n
int dx[] = {-1,0,1,-2,2,-2,2,-2,2,-1,0,1};
int dy[] = {-2,-2,-2,-1,-1,0,0,1,1,2,2,2};
int a,b;
struct P{
  int f,s,c;
  P(int f,int s,int c):f(f),s(s),c(c) {};
};

int bfs(){

  queue < P > que;
  que.push( P(y,x,0) );
  d[y][x][0] = true;
  P p = que.front();

  while( !que.empty() ){
    p = que.front(); que.pop();
 
    for(int i=0;i<12;i++){
      int nx = p.s + dx[i];
      int ny = p.f + dy[i];
      int cnt = p.c;

      if(nx >= 0 && ny >= 0 && nx <= 9 && ny <= 9 && maze[ny][nx][cnt] == 1){
	d[ny][nx][cnt+1] = true;
	que.push( P(ny,nx,cnt+1) );
      }
    }

  }
  return p.c;
}

int main(){

  while(true){
    cin >> x >> y;
    if(!x && !y) break;

    memset(maze,0,sizeof(maze));
    memset(d,false,sizeof(d));

    cin >> n;
    for(int i=0;i<n;i++){
      cin >> a >> b;
      for(int j=a-1;j<=a+1;j++){
	if(j < 0 || j > 9) continue;
	for(int l=b-1;l<=b+1;l++){
	  if(l < 0 || l > 9) continue;
	  maze[l][j][i] = 1;
	}
      }
    }

    bool ans;
    if(bfs() == n) ans = true;
    else ans = false;

    if(ans) cout << "OK\n";
    else cout << "NA\n";

  }
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong N, X, M;
  cin >> N >> X >> M;

  if (X == 0) {
    cout << 0 << endl;
    return 0;
  }
  else if (N == 1) {
    cout << X << endl;
    return 0;
  }

  vector<llong> visited;
  map<llong, llong> use;
  llong ans = 0;
  while (!use.count(X) && N--) {
    use[X] = visited.size();
    visited.push_back(X);
    ans += X;
    X = X * X % M;
  }

  llong sum = 0;
  for (int i = use[X]; i < visited.size(); i++) {
    sum += visited[i];
  }

  llong len = visited.size() - use[X];
  ans += N / len * sum;
  N %= len;
  for (int i = 0; i < N; i++) {
    ans += visited[use[X] + i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6600
#include <iostream>
#include <cmath>
#include <algorithm>

#define SIZE 50

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M;
    int load_num[SIZE] = {};
    cin >> N >> M;

    int a, b;
    for(int i=0; i<M; i++){
        cin >> a >> b;
        load_num[a-1]++;
        load_num[b-1]++;
    }
    for(int i=0; i<N; i++){
        cout << load_num[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!
    val map = HashMap<Char, ArrayList<Long>>()
    s.forEachIndexed { index, c ->
        val i = index.toLong()
        if (map[c] == null) {
            map[c] = arrayListOf(i, i + s.length)
        } else {
            with(map[c]!!) {
                add(i)
                add(i + s.length)
            }
        }
    }
    map.values.forEach { it.sort() }

    var lastIndex = -1L
    var ans = 0L
    t.forEach { c ->
        if (map[c] == null) {
            println("-1")
            return
        }
        val list = map[c]!!
        var b = list
                .binarySearch(lastIndex + 1)
                .let { if (it < 0) it.inv() else it }
        val p = list[b]
        ans += (p - lastIndex)
//        println("lastIndex: $lastIndex")
//        println("add: ${p - lastIndex}")
        lastIndex = p % s.length
    }
    println(ans)
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define repo(i,o,n) for(int i=o;i<(int)(n);i++)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int H,W,h,w;

main() {
    cin >> H >> W >> h >> w;
    cout << (H-h)*(W-w) << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <cmath>
#include <cassert>
#include <complex>
#include <algorithm>
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;

typedef complex<double> P;
const double EPS = 1e-8;
const double INF = 1e6;


double cross(const P a, const P b){
    return imag(conj(a)*b);
}

P crosspoint(const P x1,const P x2,const P y1,const P y2) {
    double A = cross(y2 - y1, x2 - x1);
    double B = cross(y2 - y1, y2 - x1);
    if (abs(A) < EPS && abs(B) < EPS) return x1; // same line
    if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
    return x1 + B / A * (x2 - x1);
}
P v[110];

bool isint(double x){
    if(abs(x -(double)(((int)(x+EPS+2000))-2000)) < EPS){
        return 1;
    }
    return 0;
}


int main(int argc, const char * argv[])
{
    int n;
    while(cin >> n && n != 0){
        int area = 0;
        int ymax = -2005;
        int ymin = 2005;
        rep(i,n){
            int fac,fad;
            cin >> fac >> fad;
            v[i]=P((double)fac,(double)fad);
            if(v[i].imag() > ymax)
                ymax = v[i].imag();
            if(v[i].imag() < ymin)
                ymin = v[i].imag();
        }
        v[n] = v[0];
        for(int y = ymin;y < ymax;y++){

            pair<int,int> edge[230];
            int k = 0;
            rep(i,n){
                if((v[i].imag() <= y && v[i+1].imag() <= y) || (v[i].imag() >= y+1 && v[i+1].imag() >= y+1)){
                    continue;}
                
                double co1 = crosspoint(P(-INF,y),P(INF,y),v[i],v[i+1]).real();
                double co2 = crosspoint(P(-INF,y+1),P(INF,y+1),v[i],v[i+1]).real();

                int xla,xra,xlb,xrb;
                if(isint(co1)){
                    xla = (int)(co1+EPS+2000)-2000;
                    xra = (int)(co1+EPS+2000)-2000;
                }else{
                    xla = (int)(co1+2000)-2000;
                    xra = ceil(co1+2000)-2000;
                }
                if(isint(co2)){
                    xlb = (int)(co2+EPS+2000)-2000;
                    xrb = (int)(co2+EPS+2000)-2000;
                }else{
                    xlb = (int)(co2+2000)-2000;
                    xrb = ceil(co2+2000)-2000;
                }
                edge[k].first = min(xla,xlb);
                edge[k].second = max(xra,xrb);
                k++;
            }
            sort(edge,edge+k);
            int prev = -INF;
            for (int i = 0;i < k;i += 2){
                area += edge[i+1].second - max(edge[i].first,prev);
                prev =  edge[i+1].second;
            }
        }
        cout << area << endl;
    }

}

Measured memory_bytes: 1172
from fractions import gcd
from functools import reduce

def main():
    lcm = lambda a, b: a * b // gcd(a, b)
    mod = 10 ** 9 + 7

    N, *A = map(int, open(0).read().split())

    L = reduce(lcm, A)
    print(sum(L // a for a in A) % mod)

main()

Measured memory_bytes: 6100
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, N);
    vector<i64> a(N);
    read(a);
    sort(all(a));
    print(a[N / 2] - a[N / 2 - 1]);

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<string>
#include<queue>
#include<deque>
#define INF 0x3f3f3f3f
using namespace std;
char a[100][100],b[100][100];
int n,m;
int main(){
	while(cin>>n>>m){
	    for(int i=0;i<n;i++){
	        scanf("%s",a[i]);
	    }
	    for(int i=0;i<m;i++){
	        scanf("%s",b[i]);
	    }
	    int flag=1;
	    for(int i=0;i<n;i++){
	        for(int j=0;j<n;j++){
	            if(a[i][j]==b[0][0]){
	                flag=0;
	                for(int x=0;x<m;x++){
	                    for(int y=0;y<m;y++){
	                        if(a[i+x][j+y]!=b[x][y]){
	                            flag=1;
	                            break;
	                        }
	                    }
	                }
	            }
	            if(flag==0)
	            {
	                cout<<"Yes";
	                goto a1;
	            }
	        }
	    }
	    cout<<"No";
	}
   a1: return 0;
}

Measured memory_bytes: 256
A, B = gets.chomp.split
cnt = 0
(A[0..1].to_i..B[0..1].to_i).each do |i|
    (1..99).each do |j|
        if i.to_s == j.to_s.rjust(2, '0').reverse
            (0..9).each do |k|
                n = i * 1000 + k * 100 + j
                cnt += 1 if n.between?(A.to_i, B.to_i)
            end
        end
    end
end
puts cnt

Measured memory_bytes: 1916
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

import javax.print.event.PrintJobListener;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int result = 0;
        Set<String> set = new HashSet<>();
        for (int i = 1; i < n; i++) {
            List<String> ss = new ArrayList<>();
            char[] a = s.substring(i).toCharArray();
            char[] b = s.substring(0, i).toCharArray();
            int tmp = 0;
            for (char c : b) {
                if (String.valueOf(a).contains(String.valueOf(c)) && !ss.contains(String.valueOf(c))) {
                    tmp++;
                    ss.add(String.valueOf(c));
                }
            }
            result = Math.max(result, tmp);
        }
        System.out.println(result);
    }
}

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

typedef long long ll;
ll n, a = 1;

ll f(ll p, ll q) {
	if (q == 0) return p;
	return f(q, p % q);
}

int main()
{
	ll t, t1;
	cin >> n;
	while (n--){
		scanf("%lld", &t);
		t1 = f(a, t);
		a = a / t1 * t;
	}
    cout << a << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

ll dp[301][90001];
ll dq[301][90001];
ll a[301];

ll mod = 998244353;

ll modpow(ll n, ll a) {
  if (a == 0)
    return 1;
  return modpow(n, a - 1) * n % mod;
}

int main() {
  ll N;
  cin >> N;
  ll sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 90001; ++j) {
      dp[i][j]=0;
      dq[i][j]=0;
    }
  }
  dp[0][0] = 1;
  dq[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 90001; ++j) {
      dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * 2) % mod;
      dq[i + 1][j] = (dq[i + 1][j] + dq[i][j]) % mod;
      dp[i + 1][j + a[i]] = (dp[i + 1][j + a[i]] + dp[i][j]) % mod;
      dq[i + 1][j + a[i]] = (dq[i + 1][j + a[i]] + dq[i][j]) % mod;
    }
  }
  ll ret = modpow(3, N);
  for (int i = 0; i < 90001; ++i) {
    if (i * 2 >= sum)
      ret = (ret-3 * dp[N][i]) % mod;
  }
  if (sum % 2 == 0) {
    ret = (ret+3 * dq[N][sum / 2]) % mod;
  }
  if (ret < 0)
    ret += mod;
  cout << ret << endl;
}


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

typedef long long ll;

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

    int n; cin >> n;
    vector<int> a(n);
    int x[20][20],y[20][20];
    for(int i=0;i<n;i++){
        cin >> a[i];
        for(int j=0;j<a[i];j++){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int ans = 0;
    for(int bit=0;bit<(1<<n);bit++){
        int cnt = 0;
        bool ng = false;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                cnt++;
                for(int j=0;j<a[i];j++){
                    if(y[i][j]==0 && bit&(1<<x[i][j])){
                        ng = true;
                        break;
                    }
                    if(y[i][j]==1 && !(bit&(1<<x[i][j]))){
                        ng = true;
                        break;
                    }
                }
            }
            if(ng) break;
        }
        if(!ng) ans = max(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

ae = [a, b, c, d, e]
for i in range(len(ae)-1):
    for j in range(i+1):
        if ae[i+1] - ae[j] > k:
            print(':(')
            sys.exit()

print('Yay!')


Measured memory_bytes: 3060
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        int H = sc.nextInt();
        int M = sc.nextInt();

        double hr = (H * 30) + 0.5 * M;
        double mr = (M * 6);
        
        double ra = Math.abs(hr - mr);
        //double ra = hr - mr;

        double ans = 0;

        ans = A * A +  B * B - (2 * A * B) * Math.cos(Math.toRadians(ra));

        System.out.println(Math.sqrt(ans));

        return;
    }

}

Measured memory_bytes: 35788
#include <iostream>

typedef long long ll;
using namespace std;

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

    int max_sum = 0;
    int x = 0;
    for (int i = 0; i < n; i++){
        if (s[i] == 'I'){max_sum++;}
        else {max_sum--;}

        x = max(x, max_sum);
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std;
int main(){
	string s;
	cin>>s;
	int minn=1e9;
	for(int i=0;i<s.length()-2;i++){
		int b=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
		if(abs(b-753)<minn){
			minn=abs(b-753);
		}
	}
	cout<<minn<<endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split()) 
h = list(map(int, input().split()))
l = [0]*n
for i in range(m):
    A, B= map(int, input().split())
    if h[A-1] < h[B-1]:
      l[A-1] +=1
    elif h[B-1] < h[A-1]:
      l[B-1] +=1
    else:
      l[A-1] +=1
      l[B-1] +=1
print(l.count(0))


Measured memory_bytes: 85004
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define dd double
#define fi first
#define se second
#define reverse(x) reverse(x.begin(),x.end())
#define sortsi(x) sort(x.begin(),x.end())
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
int MAX = 1e9 + 7; 

template <class T>
void print(vector<T>&v){
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
 
template <class T>
void print(vector<vector<T>>&v){
    for(int i=0;i<v.size();i++){
       for(int j=0;j<v[i].size();j++)cout<<v[i][j]<<" ";
       cout<<endl;
    }
    cout<<endl;
}
int modInverse(int a, int m) 
{ 
    int m0 = m; 
    int y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        int q = a / m; 
        int t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
void solve(){
    int n;
    cin>>n;
    vi v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    int ts = 0;
    for(int i=0;i<n;i++)ts+=v[i]%MAX;
    int tss = ((ts%MAX)*(ts%MAX))%MAX;
    int ss = 0;
    for(int i=0;i<n;i++)ss+=((v[i]%MAX)*(v[i]%MAX))%MAX;
    ss = ss%MAX;
    // cout<<tss<<" "<<ss<<endl;
    int num = (tss%MAX - (ss%MAX) + MAX)%MAX;
    num = ((num%MAX)*(modInverse(2,MAX)%MAX))%MAX;
    cout<<num<<endl;
    
}

int32_t main(){
    int t;
    // cin>>t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4764
using System;


class Program {
    static void Main (string[] args) {
        

        string[] a1 = Console.ReadLine ().Split (' ');
        int a = int.Parse(a1[0]);
        int b = int.Parse(a1[1]);

        string[] a2 = Console.ReadLine ().Split (' ');

        int c = 0;
        int d = 0;
        int rtn = 1;

        for(int i = 0;i < a;i++){
            c = int.Parse(a2[i]);
            d = c + d;
            if( d <= b){
                rtn ++;
            }
        }

        Console.WriteLine(rtn);
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int moves[100];
int ans[100007];
int n;
int solve(int k)
{
  if(ans[k])
    return ans[k];
  for(int i=0;i<n;i++)
  if(k>=moves[i])
  {
   if(solve(k-moves[i])==2)
      {
        ans[k]=1;
        return ans[k];
      }
  }
      ans[k]=2;
      return ans[k];
}
int main()
{
int k;
  cin>>n;
  cin>>k;
for(int i=0;i<n;i++)
{
  cin>>moves[i];
}  
ans[0]=2;
  if(solve(k)==2)
    cout<<"Second";
  else
    cout<<"First";

}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

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

    string n;
    cin >> n;
    
    int t = n.length();

    string ans;
    if (n[t - 1] == '3') ans = "bon";
    else if (n[t - 1] == '0' || n[t - 1] == '1' || n[t - 1] == '6' || n[t - 1] == '8') ans = "pon";
    else ans = "hon";

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3656
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int counter=0;
  if(s[0]=='1')++counter;
  if(s[1]=='1')++counter;
  if(s[2]=='1')++counter;

  cout << counter << endl;


  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	s := readR()
	a := make([]rune, 0)

	for i := 0; i < len(s); i++ {
		if len(a) != 0 {
			if a[len(a)-1] == 'S' && s[i] == 'T' {
				a = a[:len(a)-1]
				continue
			}
		}
		a = append(a, s[i])
	}
	fmt.Println(len(a))

}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

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

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 6028
#include<iostream>
#include<cstdio>
using namespace std;
const int N=305;
double dp[N][N][N];
int a[3],n;
double dfs(int,int,int);
int main(){
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
        for(int k=0;k<N;k++) dp[i][j][k]=-1e18;
    scanf("%d",&n);
    int x;
    for(int i=0;i<n;i++) scanf("%d",&x),a[x-1]++;
    printf("%.10lf",dfs(a[0],a[1],a[2]));
}
double dfs(int i,int j,int k){
    if(dp[i][j][k]>-1e16) return dp[i][j][k];
    if(i+j+k==0) return 0;
    double sum=0;
    if(i) sum+=1.0*i/(i+j+k)*dfs(i-1,j,k);
    if(j) sum+=1.0*j/(i+j+k)*dfs(i+1,j-1,k);
    if(k) sum+=1.0*k/(i+j+k)*dfs(i,j+1,k-1);
    sum+=1.0*n/(i+j+k);
    return dp[i][j][k]=sum;
}


Measured memory_bytes: 221952
#include<stdio.h>

int main()
{
 int N,i,j;
 scanf("%d",&N);
 int a[N],b[N];
 for (i=0;i<N;i++) {
  scanf("%d",&a[i]);
  b[i]=0;
 }
 int A=0, B=0;
 for (j=0;j<N;j++) {
  int max=0,k;
  for (i=0;i<N;i++) {
   if (a[i]>max && b[i]==0) {
    max=a[i];
    k=i;
   }
  }
  b[k]=1;
  if (j%2==0) {
   A+=max;
  } else {
   B+=max;
  }
 }
 printf("%d",A-B);
 return 0;
}

Measured memory_bytes: 128
# AtCoder Grand Contest 017
# B - Moderate Differences

import sys, re

def solve(args):
  N = args[0]
  A = args[1]
  B = args[2]
  C = args[3]
  D = args[4]
  for i in range(N):
    upper = i * D - (N - 1 - i) * C
    lower = i * C - (N - 1 - i) * D
    if lower <= B - A and B - A <= upper:
      return True
  return False

for line in sys.stdin:
  words = re.split(r'\s+', line.strip())
  args  = [int(w) for w in words]  # convert to int
  print('YES' if solve(args) else 'NO')


Measured memory_bytes: 18436
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    if( s.size() == 3 ) cout << s[2] << s[1] << s[0] << endl;
    else dump( s );
    return 0;  
}

Measured memory_bytes: 256
//iejr Header files
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <sstream>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <limits.h>
#include <ctime>
#include <cctype>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

//iejr: Type defination
typedef unsigned long long int             ULLN;
typedef long long int                      LLN;
typedef vector<int>                        VI;
typedef vector<vector<int> >               VVI;
typedef vector<string>                     VS;
typedef vector<vector<string> >            VVS;


//iejr: Compile Options
//#define C11_Standard
//
#ifdef C11_Standard
    #include <unordered_set>
    #include <unordered_map>

    #define HASHSET                  unordered_set
    #define HASHMAP                  unordered_map;
#endif // C11_Standard


//iejr: Local Debug
//#define INPUT_REDIRECTION
//#define OUTPUT_REDIRECTION


//iejr: Main Function
int main()
{

#ifdef INPUT_REDIRECTION
    freopen( "in.txt", "r", stdin );
#endif // INPUT_REDIRECTION

#ifdef OUTPUT_REDIRECTION
    freopen( "out.txt", "w", stdout );
#endif // OUTPUT_REDIRECTION

    int a,b, h;
    while( scanf( "%d%d%d", &a, &b, &h ) != EOF )  {
        int ret = ( a + b ) * h;
        ret /= 2;
        printf( "%d\n", ret );
    }

#ifdef INPUT_REDIRECTION
    fclose( stdin );
#endif // INPUT_REDIRECTION

#ifdef OUTPUT_REDIRECTION
    fclose( stdout );
#endif // OUTPUT_REDIRECTION

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define bod 100000007
/****************************/
using namespace std;
bool hn,hs,he,hw;
int main()
{
	string s;
	cin>>s;
	hn=hs=he=hw=false;
	rep(i,SZ(s))
	{
		if(s[i]=='N')
		{
			hn=true;
		}
		if(s[i]=='W')
		{
			hw=true;
		}
		if(s[i]=='E')
		{
			he=true;
		}
		if(s[i]=='S')
		{
			hs=true;
		}
	}
	if(!hn&&hs||!hs&&hn||!he&&hw||!hw&&he)
	{
		cout<<"No";
	}
	else
	{
		cout<<"Yes";
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 双方向グラフで幅優先探索

def main():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    #隣接リストの作成
    for i in range(M):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        graph[a].append(b)
        graph[b].append(a)

    from itertools import permutations
    L = list(permutations(range(N)))
    ret = 0
    for l in L:
        fg = 1
        if l[0]!=0:
            continue
        for k in range(N-1):
            if not l[k+1] in graph[l[k]]:
                fg = 0
                break
        if fg == 1:
            ret += fg
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 8052
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
   int N,K;
   string S;
   cin >> N >> S >> K;
   
   for(int i=0;i<N;i++){
       if(S[K-1] == S[i]){
       }else{
           S[i] = '*';
       }
   }
   cout << S << endl;
   
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  long long N, A, B, xx, x;
  long long ans = 0;
  cin >> N >> A >> B;
  cin >> xx;
  for(int i = 1; i < N; i++){
    cin >> x;
    if((x-xx)*A > B) ans += B;
    else ans += (x-xx)*A;
    xx = x;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

int gcd(int x, int y) {
	return y == 0 ? x: gcd(y, x % y);
}

const string YES = "Yes";
const string NO = "No";

void test(int A, int B, int C, int D) {
	set<int> S;
	if(A < C) {
		A += D;
	}
	for(;;) {
		S.insert(A);
		int t = A - ((A - C + B - 1) / B) * B;
		if(t < 0) {
			break;
		}
		A = t + D;
		if(S.find(A) != S.end()) {
			break;
		}
	}
	cout << "t" << (*S.begin()) - C << endl;
}
void solve() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	A -= B;
	if(A < 0 || D < B) {
		cout << NO << endl;
		return;
	}
	// test(A, B, C, D);
	if (A < C) {
		int tt = D - B;
		if (tt == 0) {
			cout << YES << endl;
			return;
		}
		A += (C - A + tt - 1) / tt * tt;
	}
	// Suppose: A >= C
	int r = gcd(B, D);
	int x = A - C;
	x = x - (x / r) * r;
	cerr << x << "," << C + x << "," << r << endl;
	if(C + x >= B) {
		cout << YES << endl;
	} else if(x == 0 && C + x + r >= B) {
		cout << YES << endl;
	} else {
		cout << NO << endl;
	}
}

signed main(){
	int T;
	cin >> T;
	for(int _ = 0; _ < T; ++_) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
// AOJ 2175: Whist
// 2017.11.5 bal4u@uu

#include <stdio.h>

int c[4][13][2];
char tr['Z'];

int main()
{
	int i, j, suit, rank, leader, max, winner;
	char buf[5], score[2], trump;

	tr['A'] = 14, tr['T'] = 10, tr['J'] = 11, tr['Q'] = 12, tr['K'] = 13;
	for (i = 2; i <= 9; i++) tr['0'+i] = i;

	while (scanf("%s", buf) && *buf != '#') {
		trump = *buf;
		for (i = 0; i < 4; i++) for (j = 0; j < 13; j++) {
			scanf("%s", buf);
			c[i][j][0] = tr[*buf], c[i][j][1] = *(buf+1);
		}

		score[0] = score[1] = 0;
		leader = c[0][0][1];
		for (j = 0; j < 13; j++) {
			winner = max = -1;
			for (i = 0; i < 4; i++) {
				rank = c[i][j][0], suit = c[i][j][1];
				if (suit != trump && suit != leader) continue;
				if (suit == trump) rank += 100;
				if (max < rank) max = rank, winner = i;
			}
			score[winner & 1]++;
			leader = c[winner][j+1][1];
		}
		if (score[0] > score[1]) printf("NS %d\n", score[0]-6);
		else                     printf("EW %d\n", score[1]-6);
	}
	return 0;
}

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

using namespace std;

typedef long long int ll;

int main() {
    
    int n;
    string s;
    cin >> n;
    cin >> s;
    
    map<char,int> m;
    
    for(int i = 0; i < n; ++i) {
        m[s[i]]++;
    }
    
    ll ans = 1;
    
    for(map<char,int>::iterator it = m.begin(); it != m.end(); ++it) {
        ans *= (ll)it->second + 1;
        ans %= 1000000007;
    }
    
    cout << ans-1 << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char ch;
int main()
{
    cin>>ch;
    if(ch=='a')
    {
    	cout<<"vowel"<<endl;
    	return 0;
	}
	if(ch=='e')
    {
    	cout<<"vowel"<<endl;
    	return 0;
	}
	if(ch=='i')
    {
    	cout<<"vowel"<<endl;
    	return 0;
	}
	if(ch=='o')
    {
    	cout<<"vowel"<<endl;
    	return 0;
	}
	if(ch=='u')
    {
    	cout<<"vowel"<<endl;
    	return 0;
	}
	cout<<"consonant"<<endl;
    return 0;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
ans = [-1]*N

flag = True

if N == 1:
    for _ in range(M):
        s, c = list(map(int, input().split()))
        if ans[s-1] == -1:
            ans[s-1] = c
        else:
            if ans[s-1] != c:
                flag = False
                break
    if flag:
        print(max(0, ans[0]))
    else:
        print(-1)

else:
    for _ in range(M):
        s, c = list(map(int, input().split()))
        if s == 1 and c == 0:
            flag = False
            break

        if ans[s-1] == -1:
            ans[s-1] = c
        else:
            if ans[s-1] != c:
                flag = False
                break

    if flag:
        ans[0] = max(1, ans[0])
        print("".join(["0" if e == -1 else str(e) for e in ans]))
    else:
        print(-1)


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

int main() {
    const ll mod = 998244353;
    int n;
    cin >> n;
    map<ll, ll> mp;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (i == 0 and x != 0) {
            cout << 0 << endl;
            return 0;
        }
        mp[x]++;
    }
    if (mp[0] != 1) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for (auto i : mp) {
        if (i.first == 0) continue;
        for (int j = 0; j < i.second; ++j) {
            ans *= mp[i.first - 1];
            ans %= mod;
        }
        ans %= mod;
    }
    cout << ans % mod << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int main()
{
	FAST_IO ;
	ll d,t,s;
	cin >> d >> t >> s;
	double x = d/(double)s ;
	if(x<=t)
		cout << "Yes\n" ;
	else
		cout << "No\n" ;
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define dame {cout<< "0" <<"\n"; return;}
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll dp[200010]; //i以降変化していないときの組み合わせ
ll lastC[200010];
//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    dp[0]=1;
    rep(i,N){
        dp[i+1]=dp[i];
        if(lastC[A[i]]!=0 and lastC[A[i]]!=i) dp[i+1]+=dp[lastC[A[i]]];
        lastC[A[i]]=i+1;
        dp[i+1]%=MOD;
    }
    cout<< dp[N] <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,Int k){
    Mint num(1),dom(1);
    for(Int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  vector<Int> cnt(n+100,0);
  cnt[0]=3;

  using M = Mint<Int>;
  M ans{1};
  for(Int a:as){
    if(cnt[a]==0) drop(0);
    ans*=M(cnt[a]);
    cnt[a]--;
    cnt[a+1]++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
def calculate_gcd(x, y):
   while(y):
       x, y = y, x % y
   return x

def calculate_lcm(x, y):
    lcm = (x*y)//calculate_gcd(x,y)
    return lcm


str = input()
list1=str.split(' ')
a=int(list1[0])
b=int(list1[1])

lcm= calculate_lcm(a,b)

print(lcm)


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

double inf = 1e10;

struct Data{
    vector<double> L = {inf, inf, inf};
    vector<double> R = {-inf, -inf, -inf};
    void add(int v, double w){
        L[v] = min(L[v], w);
        R[v] = max(R[v], w);
    }
    double get(double t){
        double nl = inf;
        double nr = -inf;
        for (int i = 0; i < 3; i++){
            nl = min(nl, L[i] + t * i);
            nr = max(nr, R[i] + t * i);
        }
        return nr - nl;
    }
    void event(vector<double> &times){
        for (int i = 0; i < 3; i++){
            for (int j = 0; j < i; j++){
                double t;
                t = (L[j] - L[i]) / (i - j);
                if (t > 0) times.push_back(t);
                t = (R[j] - R[i]) / (i - j);
                if (t > 0) times.push_back(t);
            }
        }
    }
};

int main(){
    int n;
    cin >> n;
    Data dx;
    Data dy;
    for (int i = 0; i < n; i++){
        int x, y; char d;
        cin >> x >> y >> d;
        if (d == 'R') dx.add(2, x), dy.add(1, y);
        if (d == 'L') dx.add(0, x), dy.add(1, y);
        if (d == 'U') dx.add(1, x), dy.add(2, y);
        if (d == 'D') dx.add(1, x), dy.add(0, y);
    }
    vector<double> times;
    times.push_back(0);
    times.push_back(inf);
    dx.event(times);
    dy.event(times);
    double ans = 1e18;
    for (int i = 0; i < times.size(); i++){
        ans = min(ans, dx.get(times[i]) * dy.get(times[i]));
    }
    cout << setprecision(20) << ans << endl;
}

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

int main() {
  char a, b;
  scanf("%c %c", &a, &b);
  if (a == 'H') {
    printf("%c\n", b);
  }
  else if (b == 'H') {
      printf("D\n");
  }
  else {
      printf("H\n");
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	private static void solve(){
		//Implement solution here.
		int N = ni();
		System.out.println((N - 2) * 180);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 25332