akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    string S;
    cin>>S;
    int A = (int)S.at(0)-(int)'0';
    int B = (int)S.at(1)-(int)'0';
    int C = (int)S.at(2)-(int)'0';
    int D = (int)S.at(3)-(int)'0';
        int num = 0;
        num +=A;
        for (int j = 0; j < 2;j++){

            num += j == 0 ? B : -B;
            char b = j == 0 ? '+' : '-';
            for (int k = 0; k < 2;k++){
                char c = k == 0 ? '+' : '-';
                for (int l = 0; l < 2;l++){
                    char d = l == 0 ? '+' : '-';
                    num = A;
                    num += b == '+' ? B : -B;
                    num += c == '+' ? C : -C;
                    num += d == '+' ? D : -D;
                    if(num==7){
                        cout << A << b << B << c << C << d << D << "=7" << endl;
                        return 0;
                    }
                }
            }
        
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int a, b, q;
    cin >> a >> b >> q;
    set<ll> s, t;
    rep(i, a){
        ll x;
        cin >> x;
        s.insert(x);
    }
    rep(i, b){
        ll x;
        cin >> x;
        t.insert(x);
    }
    s.insert(-1001001001001001);
    s.insert(1001001001001001);
    t.insert(-1001001001001001);
    t.insert(1001001001001001);
    rep(i, q){
        ll x;
        cin >> x;
        auto it = s.upper_bound(x);
        it--;
        ll ls = *it;
        it = t.upper_bound(x);
        it--;
        ll lt = *it;
        ll rs = *s.lower_bound(x);
        ll rt = *t.lower_bound(x);
        ll ans = 0;
        ans = min({
            max(x - ls, x - lt),
            max(rs - x, rt - x),
            min(rt + x - 2 * ls, 2 * rt - x - ls),
            min(rs + x - 2 * lt, 2 * rs - x - lt)
        });
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 12544
#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]
ab = [[int(str) for str in input().strip().split()] for _ in range(M)]


def solve():
    ab.sort(key=lambda x: x[1])
    ans = 0
    broken = 0
    for a, b in ab:
        if a < broken:
            continue
        broken = b
        ans += 1
    print(ans)

solve()


Measured memory_bytes: 22840
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128

const int maxn = 202;
string s[maxn];
int vis[maxn];
int n;
int bfs(int u) {
	queue<int> q;
	q.push(u);
	int res = 0;
	vis[u] = 1; 
	while(!q.empty()) {
		int x = q.front(); q.pop();
		res = max(res, vis[x]);
		for(int i = 0; i < n; ++i) {
			if(s[x][i] == '1') {
				if(!vis[i]) {
					q.push(i);
					vis[i] = vis[x] + 1;
				} else if(vis[i] == vis[x]) {
					return -1;
				}
			}
		}
	}
	return res;
}

signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	std::vector<pii> d(n);
	for(int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	int res = -1;
	for(int i = 0; i < n; ++i) {
		memset(vis, 0, sizeof(vis));
		res = max(res, bfs(i));
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from pprint import pprint
from collections import deque

s = sys.stdin.readline().strip()

n = len(s)
q = deque()
q.append([])
for _ in range(n-1):
    q_tmp = deque()
    while q:
        tmp = q.popleft()
        # pprint(tmp)
        for i in [0, 1]:
            tmp2 = tmp[:]
            tmp2.append(i)
            q_tmp.append(tmp2)
    q = q_tmp
# pprint(q)

ans = 0
while q:
    code = q.popleft()
    tmp_str = s[0]
    for i, s_i in enumerate(s):
        if i == 0:
            continue
        tmp_str += "" if code[i-1] == 0 else "+"
        tmp_str += s_i
    # print(tmp_str)
    ans += sum(map(int, tmp_str.split("+")))

print(ans)

Measured memory_bytes: 42348
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

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

fn main() {
  let s: String = read();
  let q: i32 = read();
 
  let mut t: VecDeque<char> = s.chars().collect::<VecDeque<char>>();
  let mut flip = false;
  
  for _ in 0..q {
    let ti: i8 = read();
    if ti == 1 {
      flip = !flip;
      continue;
    }
    
    let fi: i8 = read();
    let ci: String = read();
    let cci = ci.chars().nth(0).unwrap();
 
    if fi == 1 && !flip || fi == 2 && flip {
      t.push_front(cci);
    } else {
      t.push_back(cci);
    }
  }
  
  let ans: String = t.iter().map(|&s| s).collect::<String>();
  println!("{}",
    if flip { ans.chars().rev().collect::<String>() }
    else { ans }
  );
}

Measured memory_bytes: 6652
#include <cstdio>
typedef long long LL;
const int MAXN = 1e5+1;
const int MAXM = 4e5+1;
struct Edge
{
	int to;
	Edge *next;
	Edge(){}
	Edge(int v, Edge *e):to(v),next(e){}
	void* operator new(size_t);
}EData[MAXM], *head[MAXN];
void* Edge::operator new(size_t)
{
	static Edge *P = EData;
	return P++;
}
void addEdge(int a, int b)
{
	head[a] = new Edge(b, head[a]);
	head[b] = new Edge(a, head[b]);
}
int size[MAXN], col[MAXN];
bool dfs(int p, int from, int c = 1)
{
	size[p] = 1;
	col[p] = c;
	bool flag = 1;
	for(Edge *e=head[p]; e; e=e->next)
		if(!col[e->to])
		{
			flag &= dfs(e->to, p, -c);
			size[p] += size[e->to];
		}
		else if(col[e->to] == c)
			flag = 0;
	return flag;
}
int main()
{
	int N, M, i, x, y, z, a, b;
	scanf("%d%d", &N, &M);
	for(i=0; i<M; ++i)
	{
		scanf("%d%d", &a, &b);
		addEdge(a, b);
	}
	x = y = z = 0;
	for(i=1; i<=N; ++i)
		if(!col[i])
		{
			bool f = dfs(i, i);
			if(size[i] == 1) ++x;
			else if(f) ++y;
			else ++z;
		}
	printf("%lld\n", LL(2*N-x)*x + LL(y+z)*y*2 + LL(z)*z);
}

Measured memory_bytes: 11648
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erase(unique(all(v)),v.end());
#define pvec(v) rep(i,v.size()){ cout << v[i] << " ";}
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}





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

	ll a=0, b=0, c=0, ans = 0, n, ret = 0, m, d;
	string s;
	vi v(3);
	rep(i, 3) cin >> v[i];
	sort(all(v));
	cout << abs(v[0] - v[1]) + abs(v[2] - v[1]) << endl;
	return 0;
}

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

int main() {
  int n, i, j, k_new, k_max = 0, ans = 1;
  cin >> n;
  for (i = 1; i <= n; i++) {
    j = i;
    k_new = 0;
    while (j % 2 == 0) {
      j /= 2;
      k_new += 1;
    }
    if (k_new > k_max) {
      k_max = k_new;
      ans = i;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	long int n, sum = 0, i;
	scanf("%ld", &n);
	for ( i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) {
			//無視//
		}
		else {
			sum = sum + i;
		}
	}
	printf("%ld", sum);
}

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

namespace _0030
{
    
    class Program
    {

        
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            //4文字以上が前提
            if(str.Length < 4)
            {
                Console.WriteLine("WA");
                return;
            }

            //1文字目はA
            if(str[0] != 'A')
            {
                Console.WriteLine("WA");
                return;
            }

            //2文字目は小文字
            if (char.IsUpper(str[1]))
            {
                Console.WriteLine("WA");
                return;
            }
           
            int ccnt = 0;  //Cの入っている数のカウント

            //Cが入っている区間
            for(int i = 2; i < str.Length - 1; i++)
            {
                if(str[i] == 'C')
                {                    
                    ccnt++;
                }
                else
                {
                    //C以外の大文字がでたらWA
                    if (char.IsUpper(str[i]))
                    {
                        Console.WriteLine("WA");
                        return;
                    }
                }               
                
            }

            //Cが2つ以上出てたらWA
            if (ccnt != 1)
            {
                Console.WriteLine("WA");
                return;
            }

            //最後の1文字は小文字
            if (char.IsUpper(str[str.Length - 1]))
            {
                Console.WriteLine("WA");
                return;
            }
            else
            {
                Console.WriteLine("AC");
            }        
       
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int N;
int check=0;

int main(void){
 int N;
 int k=0;
 vector<int> A;

 cin>>N;

 for(int i=0;N!=0; i++){
  k=N%2;
  if(i%2==0)N-=abs(k);
  else N+=abs(k);
  A.push_back(abs(k));
  N/=2;
 }
 
 if(A.size()==0)std::cout<<0<<std::endl;
 else{
  for(int i=A.size()-1;i>=0; i--)std::cout<<A[i];
  std::cout<<std::endl;
 }
}



Measured memory_bytes: 256
n, *h = map(int, open(0).read().split())
dp = [0] + [float("inf")] * -~n
for i in range(1, n):
  dp[i] = min(dp[i-a] + abs(h[i] - h[i-a]) for a in [1,2])
print(dp[n - 1])

Measured memory_bytes: 20404
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	long long n,s;
	cin>>n>>s;
	vector<long long>vec;
	for(int i=0;i<n;i++)
	{
	    long long x;
	    cin>>x;
	    vec.push_back(x);
	}
	long long int dp[n+1][3001];
	long long ans=0;
	for(int i=n-1;i>=0;i--)
	dp[i][0]=n-i+1;
	long long md=998244353;
	dp[n-1][vec[n-1]]=1;
	for(int i=n-2;i>=0;i--)
	{
		for(int j=1;j<=3000;j++)
		{
			dp[i][j]=dp[i+1][j]+(j>=vec[i]?dp[i+1][j-vec[i]]:0);
            dp[i][j]%=md;
		}
	}
	for(int i=0;i<n;i++)
	{
	    ans+=dp[i][s];
	    ans%=md;
	}
	cout<<ans<<endl;
}
int main()
{
    int t=1;
    while(t--){
	solve();
    }
    return 0;
}   

Measured memory_bytes: 70656
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

ll N;

void solve()
{
    if (N % 2 == 1) {
        cout << 0 << endl;
    } else {
        ll ans = 0;
        ll n = N / 2;
        while (n > 0) {
            ans += (n /= 5);
        }
        cout << ans << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String s =	sc.next();
	int min = 1000;
	for(int i = 0; i<s.length()-2; i++) {
            String str = s.substring(i,i+3);
	    int x = Math.abs(753-Integer.parseInt(str));
	    if(min>x) min = x;
	}
        System.out.println(min);
    }
}

Measured memory_bytes: 25172
T = str(input())
counter = 0

for index1, rep1 in enumerate(T):
    if rep1 in "ATGC":
        temp_counter =0
        
        for rep2 in T[index1:]:
            if rep2 in "ATGC":
                temp_counter+=1
            else:
                break

        if temp_counter > counter:
            counter = temp_counter

print(counter)

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split();
        long H = int.Parse(input[0]);
        long N = int.Parse(input[1]);
        input = Console.ReadLine().Split();
        long[]A = new long[N]; 
        for(long i = 0; i < N; i++)
        {
            A[i] = int.Parse(input[i]);
        }
        long sum = A.Sum();
        if (H <= sum) { Console.WriteLine("Yes"); }
        else { Console.WriteLine("No"); }
    }
}

Measured memory_bytes: 16992
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,K;
#define Maxn 100010
int h[Maxn];
int main(){
	scanf("%d%d",&n,&K);
	int ans=0;
	for(register int i=1;i<=n;++i){
		scanf("%d",&h[i]);
		if(h[i]>=K)ans++;
	} 
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 640
N = int(input())
s = str(input())
t = str(input())

if s == t:
    print(N)
else:
    for i in range(N,0,-1):
        #print(s[N-i:],t[0:i],)
        if s[N-i:]==t[0:i]:
            print(2*N-i)
            break
    else:
        print(2*N)

Measured memory_bytes: 9016
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

// DAG - directed acyclic graph

const int nax = 1e5 + 5;
vector<int> edges[nax];
int in_degree[nax]; // the number of edges going to 'b'
int dist[nax];
bool visited[nax];

void dfs(int a) {
    assert(!visited[a]);
    visited[a] = true;
    for(int b : edges[a]) {
        dist[b] = max(dist[b], dist[a] + 1);
        --in_degree[b];
        if(in_degree[b] == 0) {
            dfs(b);
        }
    }
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    while(m--) {
        int a, b;
        scanf("%d%d", &a, &b);
        edges[a].push_back(b);
        ++in_degree[b];
    }
    for(int i = 1; i <= n; ++i) {
        if(!visited[i] && in_degree[i] == 0) {
            dfs(i);
        }
    }
    int answer = 0;
    for(int i = 1; i <= n; ++i) {
        answer = max(answer, dist[i]);
    }
    printf("%d\n", answer);
}

Measured memory_bytes: 14740
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// Hamming Distance; ハミング距離
// ：文字数が等しい文字列sとtの不一致箇所の数を返す。[O(|s|)]
long long HammingDistance(const string &s, const string &t){
    long long stringSize = (long long)s.size(), distance = 0;
    for(long long i=0; i<stringSize; i++) if(s[i] != t[i]) distance++;
    return distance;
}

int main(){
    Init();
    string s, t;
    cin >> s >> t;

    ll ans = INFLL;
    for(ll i=0; i<(ll)s.size()-(ll)t.size()+1; i++){
        chmin(ans, HammingDistance(s.substr(i, t.size()), t));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
//const ll MOD=100000;
const ll MAX=1e7;
const ll INF=(1ll<<55);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r];
}
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll A; cin>>A;
    string B; cin>>B;
    ll C=0;
    C+=B[0]-'0';
    C*=10;
    C+=B[2]-'0';
    C*=10;
    C+=B[3]-'0';
    ll ans=A*C/100;
  cout<<ans<<endl;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int min(int a,int b){
	return a>b?b:a;
}
int abs(int a){
	return a>0?a:-a;
}
int main(){
	int n,l,sum=0,minn=300,sign;
	cin>>n>>l;
	int u=n+l-1;
	for(int i=l;i<=u;i++){
		if(abs(i)<=minn){
			minn = min(minn,abs(i));
			if(i>0){
				sign=1;
			}
			else{
				sign=-1;
			}
		}
		sum+=i;
	}
	cout<<sum-sign*minn;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}


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

  string s;
  cin >> s;

  ll index = -1;
  rep(i,s.size()){
    if(s[i]=='C'){
      index = i;
      break;
    }
  }
  if(index < 0 ) {
    cout << "No" << endl;
    return 0;
  }

  FOR(i,index,s.size()){
    if(s[i] == 'F'){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 2000

void solve(int, int);
int A[N];
int n;
int flag=0;
int j=0;

void solve(int i,int m){

  int sum=0;

  if(i != n){
  
      solve(i+1,m);
      solve(i+1,m - A[i]);
      
    
  }
  
  else if(m == 0){
    flag = 1;
    
  }
  
}

int main(){

  int M[N],q,i;
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  
  for(i = 0; i < q; i++){
    flag = 0;
    scanf("%d",&M[i]);
    solve(0,M[i]);

    if(flag == 1) printf("yes\n");
    else printf("no\n");
  }
  
  



  return 0;
}

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

///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{

	int n;
	cin >> n;
	while (n--)
	{
		int ball[10];

		for (int i = 0; i < 10; ++i)
		{
			cin >> ball[i];
		}

		bitset<10> direction;
		int all = 1024;
		while (all-- > 0)
		{
			direction = static_cast<bitset<10> >(all);
			bool perfect = true;
			int left = 0;
			int right = 0;
			for (int i = 0; i < 10; ++i)
			{
				if (direction[i])
				{
					if (ball[i] > left)
					{
						left = ball[i];
					}
					else
					{
						perfect = false;
						break;
					}
				}
				else
				{
					if (ball[i] > right)
					{
						right = ball[i];
					}
					else
					{
						perfect = false;
						break;
					}
				}
			}
			if (perfect)
			{
				break;
			}
		}

		if (all >= 0)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1152
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
sa_min = abs(t - h[0] * 0.006 - a)
ans = 1
for i in range(1, n):
    if abs(t - h[i] * 0.006 - a) <= sa_min:
        sa_min = abs(t - h[i] * 0.006 - a)
        ans = i + 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

class input
{
public:
    input()
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var) { return std::cin >> var, *this; }
    template <class T>
    inline input& operator,(T& var) { return *this >> var; }

    template <class T>
    inline T read()
    {
        T var;
        std::cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            std::cin >> *head;
            ++head;
        }
    }

    template <class T>
    inline std::vector<T> read(std::size_t n)
    {
        std::vector<T> res;
        res.reserve(n);

        for (std::size_t i = 0; i < n; ++i) {
            T tmp;
            std::cin >> tmp;
            res.emplace_back(tmp);
        }
        return res;
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            std::cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

    template <class T, class... Args>
    void impl(T&& v, Args&&... args)
    {
        cout << std::forward<T>(v) << ' ';
        impl(std::forward<Args>(args)...);
    }
    template <class T>
    void impl(T&& v)
    {
        cout << std::forward<T>(v);
    }

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class... Args>
    void operator()(Args&&... args)
    {
        impl(std::forward<Args>(args)...);
        cout << '\n';
    }
    template <class... Args>
    void noreturn(Args&&... args)
    {
        impl(std::forward<Args>(args)...);
    }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
            }
            cout << x;
            first = false;
        }
        cout << '\n';
    }
};

void prog()
{
    input in;
    output out;

    auto n = in.read<int>();
    auto h = in.read<int>(n);
    int res = 1;
    int m = h.front();
    for (auto i : boost::irange(1, n)) {
        if (m <= h[i]) ++res;
        m = std::max(m, h[i]);
    }
    out(res);
}

int main()
{
    prog();
    return 0;
}


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

int main(void)
{
    int N;
    int D, X;
    cin >> N;
    cin >> D >> X;
    int A[N];
    for(int i = 0; i < N; i++)
        cin >> A[i];

    int sum = 0;
    for(int i = 0; i < N; i++)
        if(D % A[i] == 0)
            sum += (D / A[i]);
        else
            sum += (D / A[i]) + 1;

    sum += X;

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    Sd = input()
    T = input()

    i1 = [i for i, x in enumerate(Sd) if x == T[0]]
    i2 = [i for i, x in enumerate(Sd) if x == '?']
    indexes = (i1 + i2)[::-1]
    s = list(Sd)
    for i in indexes:
        for j in range(len(T)):
            if i + len(T) <= len(Sd):
                if s[i+j] == T[j] or s[i+j] == '?':
                    s[i+j] = T[j]
                    continue
            s = list(Sd)
            break
        else:
            ans = ''.join(s)
            ans = ans.replace('?', 'a')
            print(ans)
            exit()

    print('UNRESTORABLE')

main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string str, w1, w2;
	int a, b, c, n;
	int da[26];
	cin>>n;
	while(n>0){
		getline(cin, str);
		if( str.size()==0) continue;
		for(a=1;a<26;a+=2){
			if(a==13) continue;
			for(b=0;b<26;b++){
				w1 = "that"; w2 = "this";
				for(c=0;c<4;c++){
					w1[c] = (char) ('a' + ((a*(w1[c]-'a')+b) % 26));
					w2[c] = (char) ( 'a' + ((a*(w2[c]-'a')+b) % 26));
				}
				// 見つかればbreak
				if( str.find(w1) != string::npos || str.find(w2) != string::npos) break;
			}
			if(b<26) break; // 上記のif文が実行されたのであればb<26が成り立つ
		}
		
		for(c=0;c<26;c++){
			da[ (a*c+b) % 26 ] = c;
		}
		for(c=0;c<str.size();c++){
			if(str[c] == ' ') cout <<' ';
			else cout << (char) ('a' + da[ str[c] - 'a'] );
		}
		cout<<endl;
		n--;
	}
	return 0;
}

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

using namespace std;
int n,m,k,sum = 0;
char a[10][10];
bool avail[10][10];
void reset(){
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) avail[i][j] = false;
}
int main(){
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++){
        string s;
        cin >> s;
        for (int j = 1; j <= m; j++){
            a[i][j] = s[j - 1];
            if (a[i][j] == '#') sum++;
        }
    }
    for (int i = 0; i <= n; i++) a[i][0] = '.';
    for (int j = 0; j <= m; j++) a[0][j] = '.';
    int ans = 0;
    for (int i = 0; i < (1LL << (n + 1)); i += 2)
        for (int j = 0; j < (1LL << (m + 1)); j += 2){
            reset();
            int cnt = 0;
            for (int mask = 0; mask <= n; mask++)
                if ((i >> mask) & 1 == 1){                
                    for (int cj = 1; cj <= m; cj++)
                        if (avail[mask][cj] == false && a[mask][cj] == '#'){
                        avail[mask][cj] = true;
                        cnt++;
                        }
                }            
            for (int mask = 0; mask <= m; mask++)
                if ((j >> mask) & 1 == 1){                  
                    for (int ci = 1; ci <= n; ci++)
                        if (avail[ci][mask] == false && a[ci][mask] == '#'){
                            avail[ci][mask] = true;
                            cnt++;
                        }
                }
            if (sum - cnt == k) ans++;
        }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>   
using namespace std;   
  
int main()   
{   
    int n;   
    while (cin >> n, n)   
    {   
        char name[10];   
        int win[10] = {0};   
        int lose[10] = {0};   
  
        for (int i = 0; i < n; ++i)   
        {   
            cin >> name[i];   
            for (int j = 0; j < n - 1; ++j)   
            {   
                int s;   
                cin >> s;   
                if (s == 0)   
                    win[i]++;   
                if (s == 1)   
                    lose[i]++;   
            }   
        }   
  
        for (int i = n - 1; i > -1; --i)   
            for (int j = 0; j < n - i; ++j)   
                for (int k = 0; k < n; ++k)   
                    if (win[k] == i && lose[k] == j)   
                        cout << name[k] << endl;   
  
    }   
  
    return 0;   
}  

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include<stdlib.h>
typedef long long ll;

using namespace std;

int main()
{
	int a,b;
	int ans=0;
	string n;
	
	cin>>a>>b;
	for(int i=a;i<b+1;i++)
	{
		n = to_string(i);
		if(n[0]==n[4]&&n[1]==n[3])
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val Array(n, k) = io.StdIn.readLine().split(' ').map(_.toInt)
  val k2 = k * 2
  val matrix = Array.fill(k2)(Array.fill(k2)(0))
  (0 to n-1).foreach { i =>
    val temp = io.StdIn.readLine().split(' ')
    matrix(temp(0).toInt % k2)((temp(1).toInt + (if (temp(2) == "B") 0 else k)) % k2) += 1
  }
  for {
    i <- (0 to k2-1)
    j <- (1 to k2-1)
  } matrix(i)(j) += matrix(i)(j-1)
  for {
    j <- (0 to k2-1)
    i <- (1 to k2-1)
  } matrix(i)(j) += matrix(i-1)(j)
  val cnt =
    (matrix(k-1)(k-1)) +
    (matrix(k2-1)(k2-1) - matrix(k-1)(k2-1) - matrix(k2-1)(k-1) + matrix(k-1)(k-1))
  var max = Math.max(cnt, n - cnt)
  for { 
    i <- (0 to k-1)
    j <- (0 to k-1)
  } {
    val cnt = 
      (matrix(i)(j)) +
      (matrix(i+k)(j+k) - matrix(i+k)(j) - matrix(i)(j+k) + matrix(i)(j)) +
      (matrix(k2-1)(j) - matrix(i+k)(j)) +
      (matrix(i)(k2-1) - matrix(i)(j+k)) +
      (matrix(k2-1)(k2-1) - matrix(k2-1)(j+k) - matrix(i+k)(k2-1) + matrix(i+k)(j+k))
    max = Math.max(Math.max(cnt, n - cnt), max)
  }
  print(max)
}


Measured memory_bytes: 76400
unittest
{
	assert( [ "5", "1 3 5 4 2" ].parse.expand.solve == 2 );
	assert( [ "9", "9 6 3 2 5 8 7 4 1" ].parse.expand.solve == 5 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	return tuple( ps );
}

auto solve( long[] ps )
{
	auto ans = 0L;
	for( auto i = 1L; i + 1 < ps.length; i++ )
	{
		ans += ( ( ps[ i - 1 ] < ps[ i ] && ps[ i ] < ps[ i + 1 ] ) || 
		         ( ps[ i + 1 ] < ps[ i ] && ps[ i ] < ps[ i - 1 ] ) );
	}
	return ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char a[105][105];
int main()
{
	int n,m,b,c;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	cin>>a[i][j];
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		if(a[i][j]=='#')
		continue;
		a[i][j]='0';
		if(a[i+1][j-1]=='#')
		a[i][j]++;
		if(a[i+1][j]=='#')
		a[i][j]++;
		if(a[i+1][j+1]=='#')
		a[i][j]++;
		if(a[i][j+1]=='#')
		a[i][j]++;
		if(a[i][j-1]=='#')
		a[i][j]++;
		if(a[i-1][j+1]=='#')
		a[i][j]++;
		if(a[i-1][j]=='#')
		a[i][j]++;
		if(a[i-1][j-1]=='#')
		a[i][j]++;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
	    cout<<a[i][j];
	    cout<<endl;
	}
	
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import           Data.List             (unfoldr)


readIntsLn :: IO [Int]
readIntsLn = unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine

main :: IO ()
main = do
  n <- readLn
  ps <- readIntsLn
  print $ solve n ps

solve :: Int -> [Int] -> Int
solve _ ps = length . filter (\(p, q) -> p <= q) $ zip ps qs where
  qs = scanl1 min ps


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    map<int ,int > mp;
    rep(i,3){
        int k;  cin >> k;
        mp[k]++;
    }

    if(mp[5]==2 && mp[7]==1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 510;
const int MAXC = 40;
int64_t N, C, ans = (1LL << 62);
int cs[MAXN][MAXN];
int ds[MAXC][MAXC];
int memo[3][MAXC];

void init()
{
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < MAXC; j++)
      memo[i][j] = -1;
}

int64_t calc(int r, int c)
{
  int64_t s0 = 0, s1 = 0, s2 = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if ((i + j) % 3 == 0)
        s0 += ds[cs[i][j]][c];
      else if ((i + j) % 3 == 1)
        s1 += ds[cs[i][j]][c];
      else
        s2 += ds[cs[i][j]][c];
    }
  }
  memo[0][c] = s0;
  memo[1][c] = s1;
  memo[2][c] = s2;
  return memo[r][c];
}

int main()
{
  cin >> N >> C;
  for (int i = 0; i < C; i++)
    for (int j = 0; j < C; j++)
      cin >> ds[i][j];
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      cin >> cs[i][j];
      cs[i][j]--;
    }
  }
  init();
  for (int a = 0; a < C; a++)
  {
    for (int b = 0; b < C; b++)
    {
      for (int c = 0; c < C; c++)
      {
        if (a == b || b == c || c == a)
          continue;
        int64_t da = memo[0][a] == -1 ? calc(0, a) : memo[0][a];
        int64_t db = memo[1][b] == -1 ? calc(1, b) : memo[1][b];
        int64_t dc = memo[2][c] == -1 ? calc(2, c) : memo[2][c];
        ans = min(ans, da + db + dc);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4572
if __name__=="__main__":
    ind = [0, 0, 0, 0]
    for i in range(3):
        x, y = input().split(' ')
        x = int(x);
        y = int(y);
        ind[x - 1] += 1
        ind[y - 1] += 1
    sum = 0;
    for i in ind:
        sum += (i & 1)
    if sum == 0 or sum == 2:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  int count=0;
  while(1){
    if(a<b)break;
    b*=2;
    count++;
  }
  while(1){
    if(b<c)break;
    c*=2;
    count++;
  }
  if(count<=k){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
 
int main()
{
  int N,M,R;
  cin >> N >> M >> R;
  vector<int> r(R);
  for(int i = 0;i<R;i++){
    cin >> r[i];r[i]--;
  }
  vector<vector<int>> d(N,vector<int>(N,INF));
  for(int i = 0, a, b, c;i<M;i++){
    cin >> a >> b >> c;a--,b--;
    d[a][b] = d[b][a] = min(d[a][b], c);
  }
  for(int k=0;k<N;k++)
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
        d[i][j]=min(d[i][j], d[i][k] + d[k][j]);
  sort(r.begin(),r.end());
  int res = INF;
  do{
    int dis = 0;
    for(int i = 1;i < R;i++)
      dis += d[r[i - 1]][r[i]];
    res = min(res, dis);
  } while(next_permutation(r.begin(),r.end()));
  cout << res << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

 
int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	
	ll N;
	cin>>N;
	vector<ll> T(N);
	FDS(i,N){
		cin>>T[i];
	}
	ll ans=T[0];
	ll t=0;
	FDS(i,N){
	    t=ans;
		ans=L_C_M(t,T[i]);
	}
	cout<<ans<<endl;
}

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

int saghf(int a , int b) {
 
  if(a%b == 0){
    return a/b;
  } else {
   	return a/b +1; 
  }
}

int main() {
   
  int l , r , d;
  cin >> l >> r >> d;
  int a = saghf(l,d);
  int b = r/d;
  cout << b-a+1 << "\n";
  
}

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

int main() {
  int r, g, b;
  string res = "NO";

  cin >> r >> g >> b;

  if ((r*100 + g*10 + b)%4 == 0)
    res = "YES";

  cout << res << endl;

  return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

ll MOD = 1000000007;
ll addmod(ll a, ll b){
  return (a + b) % MOD;
}

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

  vector<ll> dp(N+1,0);
  dp[0] = 1;
  ll last = 0;
  ll mp[200001] = {0};
  REP(i,1,N+1){
    ll c;
    cin >> c;
    ll left = mp[c];
    if(c==last) dp[i] = dp[i-1];
    else if(left==0) dp[i] = dp[i-1];
    else{
      dp[i] = addmod(dp[i-1], dp[left]);
    }
    mp[c] = i;
    last = c;
  }
  
  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 3328
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	v := make([]int,n)
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i])
	}

	odd := make(map[int]int)
	for i :=0; i < n; i +=2 {
		_, exist := odd[v[i]]
		if exist {
			odd[v[i]] += 1
		}else{
			odd[v[i]] = 1
		}
	}

	even := make(map[int]int)
	for i:=1; i < n; i +=2 {
		_, exist := even[v[i]]
		if exist {
			even[v[i]] += 1
		}else{
			even[v[i]] = 1
		}
	}

	odd_key,odd_max := max_values(odd)
	even_key,even_max := max_values(even)
	
	if even_key == odd_key {
		
		delete(even, even_key)
		_,even_max_2 := max_values(even)
		big_even := odd_max + even_max_2
		delete(odd, odd_key)
		_,odd_max_2 := max_values(odd)
		big_odd := odd_max_2 + even_max

		if big_even > big_odd {
			even_max = even_max_2
		}else {
			odd_max = odd_max_2
		}
	}
	
	kazu := n - odd_max - even_max
	fmt.Println(kazu)
}


func max_values(m map[int]int) (int,int) {
	vs := 0
	key := 0 
	for k, v := range m {
		if vs < v {
			vs =  v
			key = k
		}
	}
	return key,vs
}
		




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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;

double const pi = 3.14159265359;

double calcAngle(double h, double m)  
{  
    // validate the input  
    if (h <0 || m < 0 || h >12 || m > 60)  
        printf("Wrong input");  
  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
  
    // Calculate the angles moved  
    // by hour and minute hands  
    // with reference to 12:00  
    double hour_angle = 0.5 * (h * 60 + m);  
    double minute_angle = 6 * m;  
  
    // Find the difference between two angles  
    double angle = abs(hour_angle - minute_angle);  
  
    // Return the smaller angle of two possible angles  
    angle = min(360.0 - angle, angle);  
  
    return angle;  
}  

int32_t main()
{
    IOS;

    int tt=1;
	//cin >> tt;
	while (tt--)
	{
		cout << fixed;
		cout << setprecision(12);
		int X,Y,c,d; cin >> X >> Y >> c >> d;
		double angle = calcAngle(c,d);
		angle = pi/180.0 * angle;
		double Cos = cos(angle);
		double Ans = pow(X,2LL) + pow(Y,2LL) - 2 * X * Y * Cos;
		cout << sqrt(Ans) << endl; 
	}
    return 0;
}


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

int main(){
	int squ=0;
	int rho=0;
	int len1,len2,dia;
	while(scanf("%d",&len1)!=EOF){
		scanf(",%d,%d",&len2,&dia);
		if(len1==len2)rho++;
		if(hypot(len1,len2)==dia)squ++;
	}
	cout<<squ<<endl;
	cout<<rho<<endl;
	return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>

int main(){
	int H,W,i,j;
	while(scanf("%d %d",&H,&W),H>0&&W>0){
	for(i=0;i<H;++i){
		for(j=0;j<W;++j){
			if(i==0||i==H-1||j==0||j==W-1){
				printf("#");
			}else{
				printf(".");
			}
		}
		printf("\n");
	}
	printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using std::cout;
using std::cin;
using std::endl;
using std::vector;


int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    const ll MAX = 10000005;
    static ll factor[MAX] = {};
    for(ll i=1; i<=N; i++){
        ll index = i;
        while(index<MAX){
            factor[index]++;
            index += i;
        }
        ans += i * factor[i];
        // cout << i << " " << f(i) << endl;

    }

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

Measured memory_bytes: 81728
#include <math.h>
#include <stdio.h>

int rel_l_l( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4 ) {
	int rel;

	rel = 0;
	if ( fabs( ( x1 - x2 ) * ( x3 - x4 ) + ( y1 - y2 ) * ( y3 - y4 ) ) < 1e-10 )
		rel = 1;
	else if ( fabs( ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 ) ) < 1e-10 ) {
		rel = 2;
		if ( fabs( ( x1 - x3 ) * ( y3 - y4 ) - ( y1 - y3 ) * ( x3 - x4 ) ) < 1e-10 )
			rel = 3;
	}

	return rel;
}

int main( void ) {
	int n;

	scanf( "%d", &n );
	while ( n-- ) {
		double x1, y1, x2, y2, x3, y3, x4, y4;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4 );		
		puts( rel_l_l( x1, y1, x2, y2, x3, y3, x4, y4 ) >= 2 ? "YES" : "NO" );
	}

	return 0;
}

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

long long N, W, w[109], v[109], dp[109][100009];

int main() {
	cin >> N >> W;
	for (int i = 1; i <= N; i++) cin >> w[i] >> v[i];
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= 100000; j++) dp[i][j] = (1LL << 60);
	}
	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= 100000; j++) {
			if (dp[i - 1][j] == (1LL << 60)) continue;

			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
			dp[i][j + v[i]] = min(dp[i][j + v[i]], dp[i - 1][j] + w[i]);
		}
	}
	long long rem = 0;
	for (int i = 0; i <= 100000; i++) {
		if (dp[N][i] <= W) rem = i;
	}
	cout << rem << endl;
	return 0;
}

Measured memory_bytes: 80128
# 1軒のホテルがあります。 このホテルの宿泊費は、次のようになっています。
# ・最初の K泊までは、1泊あたり X円
# ・K + 1 目以降は、1泊あたり Y円
# 高橋君は、このホテルに N泊連続で宿泊することにしました。
# 高橋君の宿泊費は合計で何円になるか求めてください。

# 制約
# 1 ≤ N, K ≤ 10000
# 1 ≤ Y < X ≤ 10000
# N, K, X, Y はいずれも整数である

# 標準入力から、N, K, X, Yを取得する
input_n = int(input())
input_k = int(input())
input_x = int(input())
input_y = int(input())

# 宿泊費を計算して出力する
result = 0

for i in range(input_n):
    if i < input_k:
        result += input_x
    else:
        result += input_y

print(result)

Measured memory_bytes: 9080
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define mod 1000000007;
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n+1],brr[n+1],crr[n];
    arr[0]=0;
    brr[0]=0;
    crr[0]=0;
    for(int i=1;i<=n;i++)
    cin>>arr[i];
    for(int i=1;i<=n;i++)
    cin>>brr[i];
    for(int i=1;i<n;i++)
    cin>>crr[i];
    ll ans=0,temp=-1;
    for(int i=1;i<=n;i++)
    {
        if(arr[i]-1==temp)
        {
            ans+=brr[arr[i]]+crr[temp];
            temp=arr[i];
        }
        else
        {
            ans+=brr[arr[i]];
            temp=arr[i];
        }
    }
    cout<<ans;

    

    return 0;
}

Measured memory_bytes: 256
a = list(map(int, input().split()))
res = 0
x = a[0] % 4
if x != 0:
    for i in range(4-x):
        res = res ^ (a[0] + i)
    a[0] = a[0] + 4 - x
        
m = (a[1] - a[0]) % 4 + 1
if m != 0:
    for i in range(m):
        res = res ^ (a[1] - i)
    
print(res)




Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,x,sum;
string s;
 
int main(){
  cin>>n;
  for(x=1;sum<n;x++)sum+=x;
  x--;
    for(int i=0;i<x;i++)s+=')';
    for(int i=0;i<x;i++)s+='(';
    swap(s[x],s[x-(sum-n)]);
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3316