akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;

int main(){
   int n;
   vector<pair<int,int>> mati;
   int x,y;
   cin >> n;
   REP(i,n){
      cin >> x >> y;
      mati.push_back(make_pair(x,y));
   }
   
   int ne = 1;
   for(int i=1; i<=n; i++) ne *= i; 
   
   vector<int> v;
   REP(i,n) v.push_back(i);
   
   double kyori=0.0;
   do{
      REP(i,n-1){
         kyori += sqrt( (mati[v[i]].first-mati[v[i+1]].first)*(mati[v[i]].first-mati[v[i+1]].first)
            +(mati[v[i]].second-mati[v[i+1]].second)*(mati[v[i]].second-mati[v[i+1]].second) );
      }
      
   }while(next_permutation(v.begin(), v.end()));
   
   printf("%.12f\n",kyori/ne);
   
   return 0;
}

Measured memory_bytes: 256
function Main(input) {
    var abcd = input.split('/n')[0].split(' ');
    var a = parseInt(abcd[0], 10);
    var b = parseInt(abcd[1], 10);
    var c = parseInt(abcd[2], 10);
    var d = parseInt(abcd[3], 10);
    
    if (Math.abs(c-a) <= d || (Math.abs(c-b) <= d && Math.abs(b-a) <= d)) {
        console.log('Yes');
    } else {
        console.log('No');
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7624
s=input()
l=len(s)
x=[0]*l
for i in range(l):
  for j in range(i,l):
    if j-i>0:
      x[j]+=int(s[i])*(2**i)*(2**(j-i-1))
    else:
      x[j]+=int(s[i])*(2**i)
a=0
for i in range(l):
  a+=x[i]*(10**(l-i-1))
print(a)

Measured memory_bytes: 3060
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
a=0
for i in range(H):
  if set(A[i-a])==set(['.']):
    del A[i-a]
    a+=1
b=0
for i in range(W):
  for j in range(H-a):
    if A[j][i-b]=='#':
      break
    if j==H-a-1:
      for k in range(H-a):
        del A[k][i-b]
      b+=1
for i in range(len(A)):
  print(''.join(A[i]))

Measured memory_bytes: 65696
main = do
    a <- read <$> getLine
    b <- read <$> getLine
    c <- read <$> getLine
    x <- read <$> getLine
    print $ solve a b c x

{-500円玉a枚と100円玉b枚と50円玉c枚でx円を払い方法の数-}
solve :: Int -> Int -> Int -> Int -> Int
solve a b c x = sum [g b c (x - 500*c') | c' <- [0..a] ]

{-100円玉b枚と50円玉c枚でx円を払う方法の数-}
g :: Int -> Int -> Int -> Int
g b c x = sum [h c (x - 100*b') | b' <- [0..b] ]

{-50円玉c枚でx円を払う方法の数-}
h :: Int -> Int -> Int
h c x | x >= 0 = if 50 * c >= x then 1 else 0
      | x < 0 = 0


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

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(void){

  int N;
  cin >> N;
  long long a[N][3];

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

  long long dp[N+1][3];
  for (int i=0; i<N+1; ++i){
    for (int j=0; j<3; ++j){
      dp[i][j] = 0;
    }
  }

  for (int i=0; i<N; ++i){
    for (int j=0; j<3; ++j){
      for (int k=0; k<3; ++k){
        if (j == k){;}
        else{
          chmax(dp[i+1][j], dp[i][k] + a[i][k]);
        }
      }
    }
  }

  long long int res = 0;
  for (int i=0; i<3; ++i){
    chmax(res, dp[N][i]);
  }

  cout << res << endl;
  return 0;
}



Measured memory_bytes: 4992
import numpy as np

H,W,K=map(int,input().split())
C=[]
for _ in range(H):
    c=input()
    a=[b for b in c]
    C.append(a)

answer=0

C=tuple(C)
A=[]

hs=[]
ws=[]
suuji=[i for i in range(H)]
for i in range(2 ** H):
  skill=[]
  for j in range(H):
    if ((i >> j) & 1):
        skill.append(suuji[j])
  hs.append(skill)
del hs[0]
suuji=[i for i in range(W)]
for i in range(2 ** W):
  skill=[]
  for j in range(W):
    if ((i >> j) & 1):
        skill.append(suuji[j])
  ws.append(skill)
del ws[0]

suuji=0
for h in hs:
    for w in ws:
        number=0
        D=np.array(C)
        for h_ in h:
            D[h_,:]=0
        for w_ in w:
            D[:,w]=0
        for c in D:
            for c_ in c:
                if c_=='#':
                    number+=1
        if number==K:
            answer+=1
for h in hs:
    number=0
    D=np.array(C)
    for h_ in h:
        D[h_,:]=0

    for c in D:
        for c_ in c:
            if c_=='#':
                number+=1
    if number==K:
        answer+=1
for h in ws:
    number = 0
    D = np.array(C)
    for h_ in h:
        D[:, h_] = 0

    for c in D:
        for c_ in c:
            if c_ == '#':
                number += 1
    if number == K:
        answer += 1

number=0
D=np.array(C)
for d in D:
    for d_ in d:
        if d_=='#':
            number+=1
if number==K:
    answer+=1

print(answer)


Measured memory_bytes: 27116
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    int l,r,d;
    int cnt=0;
    scanf("%d %d %d",&l,&r,&d);
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)cnt++;
    }
    printf("%d",cnt);
    return 0;
}



Measured memory_bytes: 3808
n = int(input())
a = list(map(int,input().split()))
a = [0] + a + [0]
ans = 0

for i in range(n+1):
  ans = ans + abs(a[i+1] - a[i])

for i in range(1,n+1):
  judge = ans
  judge = judge - abs(a[i+1] - a[i]) - abs(a[i-1] - a[i]) + abs(a[i+1] -a[i-1])
    
  print(judge)

Measured memory_bytes: 14048
N = int(input())
t=[0]
x,y=[0],[0]
for i in range(N):
    tmpt,tmpx,tmpy = (int(i) for i in input().split())
    t.append(tmpt)
    x.append(tmpx)
    y.append(tmpy)

ans = 'Yes'

for i in range(N):
    if t[i+1]-t[i]<abs(x[i+1]-x[i])+abs(y[i+1]-y[i]):
        ans = 'No'
        break
    elif ((t[i+1]-t[i])-(abs(x[i+1]-x[i])+abs(y[i+1]-y[i])))%2!=0:
        ans = 'No'
        break

print(ans)

Measured memory_bytes: 11724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in(argv[1]);
    // cin.rdbuf(in.rdbuf());
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    ans = N * A;
    if(ans > B) {
        ans = B;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

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


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

int main(){
  double a;
  while(cin >> a){
    double sum = a;
    double now = a;
    for(int i=2;i<=10;i++){
      if(i%2 == 0){
	now *= 2.0;
      } else {
	now /= 3.0;
      }
      sum += now;
    }
    printf("%.8f\n",sum);
  }
}

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


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

    int totalShimaCnt = 0;
    for(int k = 1; k <= 100; k++){
        int shimaCnt = 0;
        bool streak = false;
        for(int i = 0; i < N; i++){
            if(h[i] >= k){
                if(!streak){
                    shimaCnt++;
                    streak = true;
                }
            } else {
                streak = false;
            }
        }
        totalShimaCnt += shimaCnt;
    }

    cout << totalShimaCnt << endl;
    return 0;
}


Measured memory_bytes: 3568
#include<iostream>
using namespace std;
int main(){
  int a,b,c,cnt;
  while(cin>>a>>b>>c){
    cnt=0;
    for(int i=1;i<=10;i++){
      if(i==a||i==b||i==c)continue;
      if(a+b+i<=20)cnt++;
    }
    if(cnt>=4)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
N,K=map(int,input().split())
ad=dict()
al=ad.keys()
for i in range(N):
    a,b=map(int,input().split())
    if not a in ad:
        ad[a]=b
    else:
        ad[a]+=b

bk=bin(K)
lbk=len(bk)-2
k1=2**(lbk-1)-1
kl=[]
for i in range(lbk):
    ki=str(bk)[i+2]
    if ki=='1':
        kk=2**(lbk-1-int(i))
        kl.append((K-kk)|(kk-1))
kl.append(K)
kll=[0for i in range(len(kl))]
for i in range(len(kl)):

    for n in al:
        if n | kl[i]==kl[i]:
            kll[i]+=ad[n]
print(max(kll))

Measured memory_bytes: 17928
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

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

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ull)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int T;
void input(){
    fast_io();
    cin >> T;
}

unordered_map<ull,ull> dp;
ull dfs(ull x,ull a,ull b,ull c,ull d){
    if(x==0) return 0;
    if(x==1) return d;
    if(x==2) return min(2*d,a+d);
    if(dp[x]) return dp[x];
    ull ret = 1e18;
    ull r3 = x%3;
    ull r5 = x%5;
    ret = min(ret,d*x);
    if(x%2==0) ret = min(ret,a+dfs(x/2,a,b,c,d));
    else {
        ret = min(ret,a+d+dfs((x+1)/2,a,b,c,d));
        ret = min(ret,a+d+dfs((x-1)/2,a,b,c,d));
        }
    if(x%3==0) ret = min(ret,b+dfs(x/3,a,b,c,d));
    else{
        ret = min(ret,b+d*(3-r3)+dfs((x+3-r3)/3,a,b,c,d));
        ret = min(ret,b+d*r3+dfs((x-r3)/3,a,b,c,d));
    }
    if(x%5==0) ret = min(ret,c+dfs(x/5,a,b,c,d));
    else{
        ret = min(ret,c+d*(5-r5)+dfs((x+5-r5)/5,a,b,c,d));
        ret = min(ret,c+d*r5+dfs((x-r5)/5,a,b,c,d));
    }
    return dp[x] = ret;
}

int solve(){
    for (int i = 0; i < T; i++)
    {
        ull n,a,b,c,d;
        cin >> n >> a >> b >> c >> d;
        cout << dfs(n,a,b,c,d) << endl;
        dp.clear();
    }
    
    return 0;
}   

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

Measured memory_bytes: 4212
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}
#define int long long
signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    V<int> freq(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a; a--;
        freq[a]++;
    }
    sort(freq.begin(), freq.end());
    V<int> fsm(n + 1);
    for (int i = 0; i < n; i++) {
        fsm[i + 1] = fsm[i] + freq[i];
    }


    for (int k = 1; k <= n; k++) {
        int lw = 0, up = n + 1;
        while (up - lw > 1) {
            int md = (lw + up) / 2;
            int idx = lower_bound(freq.begin(), freq.end(), md) - freq.begin();
            int u = fsm[idx] + (n - idx) * md;
            if (u >= md * k) lw = md;
            else up = md;
        }
        cout << lw << "\n";
    }

    dbg(freq);


    return 0;
}


Measured memory_bytes: 5632
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    h, a = gets.split.map(&:to_i)

    sum = gets.split.map(&:to_i).inject(0) do |s, i|
      s += i
    end
    # puts sum

    if sum < h
      puts "No"
    else
      puts "Yes"
    end
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 8316
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class Rect
{
public:
    Rect() {}
    Rect(int x1, int y1, int x2, int y2)
    : ld(make_pair(MIN(x1, x2), MIN(y1, y2))),
    ru(make_pair(MAX(x1, x2), MAX(y1, y2)))
    {}
    ~Rect() {}

    bool in(pair<int, int>& x)
    {
        return ld.first <= x.first  && ld.second <= x.second && ru.first >= x.first && ru.second >= x.second;
    }

    s64 size()
    {
        return (s64)(ru.first - ld.first) * (s64)(ru.second - ld.second);
    }

private:
    pair<int, int> ld;
    pair<int, int> ru;
};

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

    int N, K;
    cin >> N >> K;

    vector< pair<int, int> > p(N);
    rep (i, N)
    {
        cin >> p[i].first >> p[i].second;
    }

    s64 ans = 4 * 1e18;
    for (int i = 0; i < N; ++i)
    {
        for (int j = i + 1; j < N; ++j)
        {
            for (int m = 0; m < N; ++m)
            {
                for (int n = m + 1; n < N; ++n)
                {
                    Rect rect(p[i].first, p[m].second, p[j].first, p[n].second);
                    int num = 0;
                    rep (k, N)
                    {
                        if (rect.in(p[k]))
                        {
                            ++num;
                        }
                    }
                    if (num >= K)
                    {
                        ans = MIN(rect.size(), ans);
                    }
                }
            }
        }
    }

    cout << ans << "\n";
    return 0;
}



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

int main()
{
    int K,A,B;
    cin >> K;
    cin >> A >> B;
    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

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

int main(){
  int n; cin>>n;
  vector<ll> v(n+1,0),w(n,0);
  for(int i=0;i<=n;i++)
  cin>>v[i];
  for(int i=0;i<n;i++)
  cin>>w[i];

  ll ans=0;
  for(int i=0;i<n;i++){
      ll x=min(w[i],v[i]);
      ans+=x;
      w[i]-=x; v[i]-=x;
      x= min(w[i],v[i+1]);
      ans+=x;
      w[i]-=x; v[i+1]-=x;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1792
//input macro begin
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//input macro end

fn main() {
    input! {
        s: chars,
    }

    let s: Vec<i64> = s.iter().map(|&x| (x as u8 - '0' as u8) as i64).collect();

    let mut ans = (100 * s[0] + 10 * s[1] + s[2] - 753).abs();

    for i in 0..s.len() - 2 {
        if ans > (100 * s[i] + 10 * s[i + 1] + s[i + 2] - 753).abs() {
            ans = (100 * s[i] + 10 * s[i + 1] + s[i + 2] - 753).abs();
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;


public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		int			eventCountMax = 0;
		int 		outCount 	= 0;
		int			point		= 0;

		boolean[] 	bases = new boolean[]{false, false, false};

		List<Integer> list = new ArrayList<Integer>();

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		eventCountMax = Integer.parseInt(reader.readLine());


		for(int i = 0; i < eventCountMax; i++){

			while(outCount != 3){
				String command = reader.readLine();

				if(command.equals("HIT")){
					if	(bases[2]){ point++; 		 bases[2] = false;}
					if	(bases[1]){ bases[2] = true; bases[1] = false;}
					if	(bases[0]){ bases[1] = true; bases[0] = false;}

					bases[0] = true;
				}else if(command.equals("HOMERUN")){
					for(boolean flag : bases) if(flag) point++;
					bases = new boolean[]{false, false, false};
					point++;
				}else if(command.equals("OUT")){
					outCount++;
				}
			}

			list.add(point);
			point = 0;
			bases = new boolean[]{false, false, false};
			outCount=0;
		}

		for(int score : list) System.out.println(score);
	}

}

Measured memory_bytes: 9580
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
char a[1000005];
int dp[1000005][3][3];
const int modo=998244353;
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    scanf("%s",a);
    int n=strlen(a);
    int i;
    for (i=1;i<n;i++)
    {
        if (a[i]==a[i-1])
        {
            break;
        }
    }
    int ans=0;
    if (i==n)
    {
        ans++;
    }
    for (i=1;i<n;i++)
    {
        if (a[i]!=a[i-1])
        {
            break;
        }
    }
    if (i==n)
    {
        puts("1");
        return 0;
    }
    int cnt=0;
    for (i=0;i<n;i++)
    {
        cnt+=((a[i]-'a')%3);
        cnt%=3;
    }
    if (n==3)
    {
        int i,j;
        for (i=0;i<3;i++)
        {
            for (j=i+1;j<3;j++)
            {
                if (a[i]==a[j]) break;
            }
            if (j!=3) break;
        }
        if (i==3)
        {
            puts("3");
            return 0;
        }
    }
    dp[1][0][0]=1;
    dp[1][1][1]=1;
    dp[1][2][2]=1;
    for (i=1;i<=n;i++)
    {
        int j,k;
        for (j=0;j<3;j++)
        {
            for (k=0;k<3;k++)
            {
                int l;
                for (l=0;l<3;l++)
                {
                    if (k==l) continue;
                    dp[i+1][(j+k)%3][k]+=dp[i][j][l];
                    dp[i+1][(j+k)%3][k]%=modo;
                }
            }
        }
    }
    int p=1;
    for (i=1;i<n;i++)
    {
        p=(long long)p*3%modo;
    }
    ans+=p;
    ans%=modo;
    for (i=0;i<3;i++)
    {
        ans-=dp[n][cnt][i];
        ans%=modo;
    }
    ans+=modo;
    ans%=modo;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 8576
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<int> L(2 * n);

    rep(i, 2 * n)
    {
        cin >> L[i];
    }

    sort(L.begin(), L.end());
    int result = 0;
    rep(i, n)
    {
        result += min(L[2 * i], L[2 * i + 1]);
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);


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

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  reverse(ALL(a));

  ll u = 2;
  ll l = 2;
  rep(i, n) {
    if (u < a[i]) {
      cout << -1 << endl;
      return 0;
    }

    ll x = l / a[i] + (l % a[i] == 0 ? 0 : 1); // a[i] の倍数で l 以上となる最小値は a[i] の何倍か？
    if (u < x * a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ll y = (u + a[i] - 1) / a[i] + (u % a[i] == 0 ? 1 : 0);  // a[i] の倍数で初めて u を超えるのは a[i] の何倍か？
    if (y * a[i] - 1 < l) {
      cout << -1 << endl;
      return 0;
    }
    l = x * a[i];
    u = y * a[i] - 1;
//    cerr << a[i] << "  " << l << " " << u << endl;
  }

  cout << l << " " << u << endl;

  return 0;
}


Measured memory_bytes: 3992
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
//typedef __int64 LL;
typedef long long int LL;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;
int main()
{
	LL n;
	LL ans=MOD;
	cin>>n;
	while(n>=100)
	{
		ans=min(ans,(LL)abs((n%1000)-753));
		n/=10;
	}
	cout<<ans<<"\n";
	return 0;
}

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

int main(){
    // //実験
    // cout<<char('A'+2)<<endl;
    //成功。型変換すればおｋ
    int n;cin>>n;
    string S;cin>>S;
    for(int i=0;i<S.size();i++){
        S[i] = char( (S[i] + n -'A') % 26 +'A');
    }
    cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
template < class R > inline void Readin( R &K ) {bool F=K=0;char C=getchar();while(C<'0'||C>'9')
{if(C=='-')F=1;C=getchar();}while(C<='9'&&C>='0')K=(K<<1)+(K<<3)+C-'0',C=getchar();if(F)K=-K;}
template < class R > inline bool Checkmax( R &A , R B ) { return A < B ? A = B , 1 : 0 ; }
template < class R > inline bool Checkmin( R &A , R B ) { return A > B ? A = B , 1 : 0 ; }
int N , T[105] , Min = 1 << 30 , Max ;
int main() {
	Readin( N ) ;
	if( N == 2 )
		return not printf( "Possible\n" ) ;
	while( N-- ) {
		register int X ;
		Readin( X ) ;
		Checkmin( Min , X ) ;
		Checkmax( Max , X ) ;
		++T[X] ;
	}
	for(register int i = Min ; ++i <= Max ; )
		if( T[i] < 2 )
			return not printf( "Impossible\n" ) ;
	if( ( Min * 2 == Max and T[Min] == 1 ) or ( Max / 2 == Min - 1 and T[Min] == 2 ) )
		return not printf( "Possible\n" ) ;
	return not printf( "Impossible\n" ) ;
}

Measured memory_bytes: 256
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int n;cin>>n;
	string s[n];
	int a[n],sum=0;
	for(int i=0;i<n;i++)cin>>s[i]>>a[i];
	string ss;cin>>ss;
	for(int i=0;i<n;i++){
		sum-=a[i];
		if(ss==s[i])break;
	}
	for(int i=0;i<n;i++)sum+=a[i];
	cout<<sum<<endl;
}

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

int main()
{
    ll n,k;

    cin>>n>>k;
    bool a[k+1];
    for(ll i=0;i<=k;i++)
        a[i]=false;

    ll v[n];
    for(int i=0;i<n;i++)
        cin>>v[i];
    for(int i=1;i<=k;i++)
        for(int j=0;j<n;j++)
            if(v[j]<=i)
                a[i]|=(!a[i-v[j]]);
    cout<<(a[k]?"First":"Second")<<endl;
    return 0;
}


Measured memory_bytes: 384
n1 = int(input())

n2 = [int(i) for i in input().split()]

r1 = 0

for i1 in range(n1):
    if i1 == 0:
        r1 += n2[0]
    elif i1 == n1 - 1:
        r1 += n2[n1 - 2]
    else:
        r1 += min(n2[i1 - 1],n2[i1])

print(r1)

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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 2e5+5;

void solve() {

  int n;
  cin>>n;
  int ans = 0;
  rep(i,1,4)
    ans += round(pow(n,i));
  cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
   //cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}




int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}


int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

int main()
{
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> l.at(i);
  }
  int sum = 0;
  int count = 0;
  for(i = 0; i < n; i++)
  {
    if(sum <= x) count++;
    sum += l.at(i);
  }
  if(sum <= x) count++;
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=500010, inf=1e9;
int n, cnt;
int a[maxn];

template<typename T>
inline void read(T &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;
}

int main()
{
	read(n); read(cnt);
	for(int i=1;i<=n;i++) read(a[i]);
	sort(a+1, a+1+n);
	int ans=0, flag=0;
	for(int i=1;i<=n;i++)
	if(cnt>=a[i])
	{
		cnt-=a[i];
		ans++;
	}
	else 
	{
		flag=1;
		break;
	}
	if(!flag && cnt) ans--;
	printf("%d\n", ans);
}

Measured memory_bytes: 764
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int[] abc = new int[3];
      abc[0] = Integer.parseInt(sc.next());
      abc[1] = Integer.parseInt(sc.next());
      abc[2] = Integer.parseInt(sc.next());
      Arrays.sort(abc);
      int difa = abc[2] - abc[0];
      int difb = abc[2] - abc[1];
      if(difa%2 == 0 && difb%2 == 0) System.out.println(difa/2 + difb/2);
      else if(difa%2 == 1 && difb%2 == 1) System.out.println(difa/2 + difb/2 + 1);
      else System.out.println(difa/2 + difb/2 + 2);
  }
}

Measured memory_bytes: 25684
#include<stdio.h>
int main()
{
	const char *s[][5] = 
	{
		{"wa","","nn","","wo"},
		{"a","i","u","e","o"},
		{"ka","ki","ku","ke","ko"},
		{"sa","si","su","se","so"},
		{"ta","ti","tu","te","to"},
		{"na","ni","nu","ne","no"},
		{"ha","hi","hu","he","ho"},
		{"ma","mi","mu","me","mo"},
		{"ya","","yu","","yo"},
		{"ra","ri","ru","re","ro"},
	};
	char str[1024];
	scanf("%s",str);
	for(int i=0; str[i]; i+=2)
	{
		int x=str[i]-'0';
		char c=str[i+1];
		int y=(c=='T'?0:c=='L'?1:c=='U'?2:c=='R'?3:4);
		printf("%s",s[x][y]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 972
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int n, a;
	cin >> n >> a;
	cout << n * n - a;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y)
{
    int res = 1;
    x = x % M;
    while (y > 0)
    {   if (y & 1)
        res = (res*x) % M;
        y = y>>1;
        x = (x*x) % M;
    }
    return res;
}
int main()
{
	IOS;
	int n,k;
	cin>>n>>k;
	vector<double>v;
	rep(i,0,n)
	{
		double x;
		cin>>x;
		v.pb(x);
	}
    int a[n+1];a[0]=0;
    rep(i,0,n)
    a[i+1]=a[i]+v[i];
    int i=0,j=k,x,y,m=-1;
    while(j<n+1)
    {
    	if(m<a[j]-a[i])
    	{
    		m=a[j]-a[i];
    		x=i;y=j;
		}
		i++;j++;
	}
	double ans=0;
	for(int i=x;i<y;i++)
	{
		ans+=((v[i]+1.000)/2.00);
	}
	cout<<fixed;
	cout<<setprecision(9)<<ans;
}


Measured memory_bytes: 2800
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

struct edge{
  ll to, w;
  edge(){}
  edge(ll a, ll b){
    to = a; w = b;
  }
};

int main(){
  ll N;
  cin >> N;
  vector<vector<edge>> G(N);
  for(int i = 0; i < N-1; i++){
    ll u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    G.at(u).push_back(edge(v, w));
    G.at(v).push_back(edge(u, w));
  }
  vector<bool> flag(N, true);
  flag.at(0) = false;
  vll d(N, INF);
  d.at(0) = 0;
  queue<ll> que;
  que.push(0);
  vi color(N, -1);
  color.at(0) = 0;
  while(!que.empty()){
    ll n = que.front(); que.pop();

    for(int i = 0; i < G.at(n).size(); i++){
      ll next = G.at(n).at(i).to;
      if(flag.at(next)){
        flag.at(next) = false;
        d.at(next) = d.at(n) + G.at(n).at(i).w;
        if(d.at(next) % 2 == 0) color.at(next) = 0;
        else color.at(next) = 1;
        que.push(next);
      }
    }
  }
  for(auto x: color) cout << x << endl;
}

Measured memory_bytes: 9088
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

# https://atcoder.jp/contests/abc054/tasks/abc054_c

# N = 頂点の数(= 数字の数)
# M = 辺の数(= aの行数)

N, M = map(int, input().split())
graph = [ [0 for _ in range(N)] for _ in range(N) ]
visited = [False] * N

for i in range(M):
    a, b = map(int, input().split())
    graph[a-1][b-1] = 1
    graph[b-1][a-1] = 1

#print(graph)

# u は 0-index
def dfs(u):
    if False in visited:
        pass
    else:
        return 1

    count = 0
    for i in range(N):
        if graph[u][i] == False: continue
        if visited[i]: continue

        visited[i] = True
        count += dfs(i)
        visited[i] = False

    return count

visited[0] = True
count = dfs(0)
print(count)

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

int n, m, cnt = 0;
bool a[1005] = {0};

int main() {
  int i, x;
  cin >> n >> m;
  for(i = 0; i < m; ++i) {
    cin >> x;
    --x;
    a[x] = 1;
  }
  for(i = 0; i < m; ++i)
    if(!a[i]) ++cnt;
  cout << cnt << endl;
  return 0;
}


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


using namespace std;
int main()
{
string a,b,c;
int s,t;

cin>>a>>b;
cin>>s>>t;
cin>>c;

if(c==a){
    cout<<s-1<<" "<<t<<endl;
}
else{
 cout<<s<<" "<<t-1<<endl;
}












return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;
ll n ;
vector<ll> c(0);
vector<ll> mem;
vector<vector<ll>> place(200001,vector<ll>(0));

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

ll f(ll x){
    if(x==n-1) return 1;
    if(mem.at(x)!=-1) return mem.at(x);
    ll ret = f(x+1);
    ll y = c.at(x);
    ll add = 0;
    auto it = upper_bound(place.at(y).begin(),place.at(y).end(),x);
    if(it!=place.at(y).end()) add = f(*it);
    ret = (ret + add)% mod;
    mem.at(x) = ret;
    return ret;
}


// main starts here

int main(){
    cin >> n;
    ll prev = INF;
    rep(i,n){
        ll a; cin >> a;
        if(a!=prev) c.emplace_back(a);
        prev = a;
    }
    n = c.size();
    rep(i,n) place.at(c.at(i)).emplace_back(i);
    mem.resize(n,-1);
    cout << f(0) << endl;
}


Measured memory_bytes: 20592
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n;
	cin>>n;
	set<ll> se;
	rep(i,0,n){
		ll a;
		cin>>a;
		se.insert(a);
	}
	cout << se.sz << endl;
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long

LL N,M,ans,r,a,b,C[100002];


pair<LL, LL>d;
int main() {
	vector<LL> L,R;
	cin >> N>>M;
	for (int i = 0; i < N; i++) {
		C[i] = 0;
	}
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		C[a]++;
		C[b + 1]--;
	}
	for (int i = 2; i <= N; i++) {
		C[i] = C[i] + C[i - 1];
	}
	for (int i = 1; i < N + 1; i++) {
		if (C[i] == M) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 1024
import java.util.*;

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

      long a = sc.nextLong();
      long b = sc.nextLong();

      long ans = 1;

      long gcdab = euku(a,b);

      int n = (int)Math.sqrt(gcdab);

      for(int i=2;i<=n;i++){
        if(gcdab%i==0){
          ans++;
          while(gcdab%i==0){
            gcdab /= i;
          }
        }
      }

      if(gcdab!=1){
        ans++;
      }

      System.out.println(ans);

    }

    public static long euku(long a,long b){

      if(a%b!=0){
        return euku(b,a%b);
      }
      else{
        return b;
      }

    }

}


Measured memory_bytes: 23124
def solve():
    N = int(input())
    D, X = map(int, input().split())
    ans = X
    A = [int(input()) for _ in range(N)]
    for a in A:
        d = 1
        while d <= D:
            ans += 1
            d += a
    print(ans)



if __name__ == "__main__":
    solve()

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define sz(x) (int)(x).size()
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(), x.end()
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin>>n>>m;
    vector<string> grid(n);
    rep(i,0,n) cin>>grid[i];
    vector<vector<bool>>
        sol1(n,vector<bool>(m)),
        sol2(n,vector<bool>(m));
    rep(j,0,m) {
        sol1[0][j] = true;
        sol2[n-1][j] = true;
    }
    rep(i,1,n-1) rep(j,1,m-1) {
        if(j&1) {
            sol1[i][j] = true;
            if(grid[i][j]=='#') sol2[i][j] = true;
        }
        else {
            sol2[i][j] = true;
            if(grid[i][j]=='#') sol1[i][j] = true;
        }
    }
    rep(i,0,n) {
        rep(j,0,m) cout<<(sol1[i][j]?'#':'.');
        cout<<"\n";
    }
    cout<<"\n";
    rep(i,0,n) {
        rep(j,0,m) cout<<(sol2[i][j]?'#':'.');
        cout<<"\n";
    }
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int mx = (n-1) * (n-2) / 2;
  if(mx < k){
    cout << -1 << endl;
    return 0;
  }
  vector<P> ans;
  int num = mx - k;
  for(int i = 2; i <= n; i++){
    ans.push_back({1, i});
  }
  int add = mx - k;
  vector<P> edge;
  for (int i = 2; i < n; i++){
    for (int j = i + 1; j <= n; j++){
      edge.push_back({i, j});
    }
  }
  rep(i, add) ans.push_back(edge[i]);
  cout << ans.size() << endl;
  rep(i, ans.size()){
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}

Measured memory_bytes: 3680
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXW = 10010;
int N, W;
int C[110][MAXW];
int v[110];
int w[110];

int main() {
    scanf("%d %d", &N, &W);
    memset(C, 0, sizeof(C));
    for (int i = 1; i <= N; i++) {
        scanf("%d %d", &v[i], &w[i]);
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j >= w[i]) C[i][j] = max(C[i-1][j], C[i-1][j-w[i]] + v[i]);
            else C[i][j] = C[i-1][j];
        }
    }
    printf("%d\n", C[N][W]);
    return 0;
}

Measured memory_bytes: 7512
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int n=0,m=0;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;

  return 0;
}

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

int main() {
  int n,m,c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for(int i=0;i<m;i++)
    cin >> b.at(i);
  vector<vector<int>> a(n,vector<int>(m));
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> a.at(i).at(j);
    }
  }
  int lsum = 0;
  int count = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      lsum += a.at(i).at(j) * b.at(j);
    }
    if( lsum + c > 0 )
      count++;
    lsum = 0;
  }
  cout << count <<endl;    
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

signed main(){
 
	lli n;
	cin>>n;
	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];

	sort(a.begin(),a.end());

	/*小さい順にマージしていって、次のやつをマージできるかどうかの判定を行っていく*/
	vector<lli> data(n);
	data[0] = a[0];
	REP(i,1,n){
		data[i] = data[i-1]+a[i];
	}

	lli ans = 0;
	REP(i,0,n-1){
		if(data[i]*2 >= a[i+1])ans++;
		else ans = 0;
	}

	cout<<ans+1<<endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int i, n, a=0;
  string c;
  cin >> n;
  for (i=0;i<n;i++) {
    cin >> c;
    if (c=="Y"){
      a = 1;
      break;
    }
  }
  if(a==0) {
    cout << "Three" << endl;
  }else{
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AOJ.Volume0
{
    public class BombsChain
    {
        private struct Point
        {
            public int X;
            public int Y;
        }

        public static void Main()
        {
            int data_cnt = int.Parse(Console.ReadLine());
            for (int counter = 1; counter <= data_cnt; counter++)
            {
                Console.ReadLine();

                // 平面を読み込む
                int[,] ground = new int[8, 8];
                for (int j = 0; j < 8; j++)
                {
                    string line = Console.ReadLine();
                    for (int k = 0; k < 8; k++) { ground[k, j] = int.Parse(line.Substring(k, 1)); }
                }
                // 最初の爆弾位置
                int x = int.Parse(Console.ReadLine()) - 1;
                int y = int.Parse(Console.ReadLine()) - 1;

                // キューに積んで処理開始
                var q = new Queue<Point>();
                q.Enqueue(new Point { X = x, Y = y });
                while (q.Count > 0)
                {
                    var p = q.Dequeue();
                    ground[p.X, p.Y] = 0;
                    // 上下左右から爆弾を探す
                    for (int j = 1; j <= 3; j++)
                    {
                        // 上
                        if (p.Y - j >= 0)
                        {
                            if (ground[p.X, p.Y - j] == 1) { q.Enqueue(new Point { X = p.X, Y = p.Y - j }); }
                        }
                        // 下
                        if (p.Y + j <= 7)
                        {
                            if (ground[p.X, p.Y + j] == 1) { q.Enqueue(new Point { X = p.X, Y = p.Y + j }); }
                        }
                        // 左
                        if (p.X - j >= 0)
                        {
                            if (ground[p.X - j, p.Y] == 1) { q.Enqueue(new Point { X = p.X - j, Y = p.Y }); }
                        }
                        // 右
                        if (p.X + j <= 7)
                        {
                            if (ground[p.X + j, p.Y] == 1) { q.Enqueue(new Point { X = p.X + j, Y = p.Y }); }
                        }
                    }
                }
                // 出力
                Console.WriteLine(string.Format("Data {0}:", counter));
                for (int j = 0; j < 8; j++)
                {
                    string line = "";
                    for (int k = 0; k < 8; k++) { line += ground[k, j]; }
                    Console.WriteLine(line);
                }
            }
        }
    }
}

Measured memory_bytes: 6036
import Data.List

main :: IO ()
main = do
  s <- getLine
  putStrLn $ show (solve (read s))

solve :: Int -> Int
solve s = solve' [] s 0 where
  solve' :: [Int] -> Int -> Int -> Int
  solve' list s i
    | (length $ nub list) < (length $ list) = i
    | even s = solve' (list ++ [s]) (s `div` 2) (i + 1)
    | odd s = solve' (list ++ [s]) (3 * s + 1) (i + 1)
    | otherwise = 0


Measured memory_bytes: 1020