akhauriyash/Code-Regression huggingface dataset:
def main():
  n,m = input_list()
  x = input_list()
  if len(x) == 1:
    print(abs(x[0] - m))
    exit(0)
  diffs = []
  for i in range(len(x)):
    d = abs(m - x[i])
    diffs.append(d)
  print(gcd_list(diffs))
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 16244
#include<iostream>
#define N 100000
using namespace std;

struct Node{
  int p,l,r;
};
Node t[N];

void print_node(int x){
  int s=t[x].l;
  if(s>=0) cout<<"["<<s;
  else if(s==-1){cout<<"[]";return;}
  while(1){
 if(t[s].r==-1) break;
 else cout<<", ";
 cout<<t[s].r;
 s=t[s].r;
  }
  cout<<"]";
}

int dep(int x){
  int cnt=0;
  if(t[x].p>=0) cnt=dep(t[x].p)+1;
  return cnt;
 }


int main(){
  int n,id,k,c;

  cin>>n;
  for(int i=0;i<n;i++)t[i].l=-1,t[i].p=-1,t[i].r=-1;

  for(int i=0;i<n;i++){
    cin>>id>>k;
    for(int j=0;j<k;j++){
      int befc=c;
      cin>>c;
      t[c].p=id;
      if(j>0)t[befc].r=c;
      else t[id].l=c;
    }
  }
   for(int i=0;i<n;i++){
cout<<"node "<<i<<": parent = "<<t[i].p<<", depth = ";
 cout<<dep(i)<<", ";
  if(t[i].l>=0 && t[i].p!=-1) cout<<"internal node, ";
  else if(t[i].p==-1) cout<<"root, ";
  else cout<<"leaf, ";
  print_node(i);
  cout<<endl;
  }


  return 0;
}

Measured memory_bytes: 2332
#include <iostream>
#include <vector>
using i64 = long long;

int main() {
    constexpr i64 inf = 1000000000000000000;
    int n;
    std::cin >> n;
    std::vector<i64> a(n);
    for (auto &e : a) std::cin >> e;

    for (auto e : a) {
        if (!e) {
            std::cout << 0 << std::endl;
            return 0;
        }
    }

    i64 ret = 1;
    for (const i64 e : a) {
        if (ret > inf / e) {
            std::cout << -1 << std::endl;
            return 0;
        }
        ret *= e;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 4052
N = int(input())
A = list(map(int, input().split()))

dic = {}

num = 1
for i in A:
    dic[num] = i
    num += 1

dic_sorted = sorted(dic.items(), key=lambda x:x[1])

# print(dic_sorted)
ans = ""
for i in dic_sorted:
    ans += str(i[0]) + " "

print(ans[:-1])



Measured memory_bytes: 26332
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < N; i++)
    {
        cout << S[i];
        cout << T[i];
    }
    cout << endl;
    
}


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

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

using namespace std;

int main(){
  int a,b,h;
  cin>>a;
  cin>>b;
  cin>>h;

  cout<<(a+b)*h/2;

  return 0;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -Wall #-}

-- foldM_ を使うとMLEするので…
foldM_' :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m ()
foldM_' _ _ [] = return ()
foldM_' f z (x:xs) = do
    z' <- f z x
    z' `seq` foldM_' f z' xs

readInt :: String -> Int
readInt = read

data BST a = Empty | Node a (BST a) (BST a)
    deriving (Show)

bstFind :: (Ord a) => BST a -> a -> BST a
bstFind Empty _ = Empty
bstFind node@(Node y l r) x
    | x == y    = node
    | x <  y    = bstFind l x
    | otherwise = bstFind r x

bstInsert :: (Ord a) => BST a -> a -> BST a
bstInsert Empty x = Node x Empty Empty
bstInsert node@(Node y l r) x
    | x == y    = node
    | x <  y    = Node y (bstInsert l x) r
    | otherwise = Node y l (bstInsert r x)

bstDelete :: (Ord a) => BST a -> a -> BST a
bstDelete Empty _ = Empty
bstDelete node@(Node y Empty Empty) x
    | x == y    = Empty
    | otherwise = node
bstDelete (Node y l Empty) x
    | x == y    = l
    | otherwise = Node y (bstDelete l x) Empty
bstDelete (Node y Empty r) x
    | x == y    = r
    | otherwise = Node y Empty (bstDelete r x)
bstDelete (Node y l r) x
    | x == y    = let z = bstMinimum r in
                          Node z l (bstDelete r z)
    | x <  y    = Node y (bstDelete l x) r
    | otherwise = Node y l (bstDelete r x)
    where
        bstMinimum :: (Ord a) => BST a -> a
        bstMinimum Empty             = error "invalid argument"
        bstMinimum (Node x' Empty _) = x'
        bstMinimum (Node _ l' _)     = bstMinimum l'

bstPreorder :: (Ord a) => BST a -> [a]
bstPreorder Empty = []
bstPreorder (Node x l r) = [x] ++ bstPreorder l ++ bstPreorder r

bstInorder :: (Ord a) => BST a -> [a]
bstInorder Empty = []
bstInorder (Node x l r) = bstInorder l ++ [x] ++ bstInorder r

doCmd :: BST Int -> [String] -> IO (BST Int)
doCmd node ("find":arg0:_) = do
    let x = readInt arg0
    let found = case bstFind node x of
                    Node{} -> True
                    Empty  -> False
    putStrLn $ if found then "yes" else "no"
    return node
doCmd node ("insert":arg0:_) = do
    let x = readInt arg0
    return $ bstInsert node x
doCmd node ("delete":arg0:_) = do
    let x = readInt arg0
    return $ bstDelete node x
doCmd node ("print":_) = do
    putStrLn . concatMap ((' ':) . show) $ bstInorder  node
    putStrLn . concatMap ((' ':) . show) $ bstPreorder node
    return node
doCmd _ _ = error "invalid command"

main :: IO ()
main = do
    _    <- getLine
    cmds <- fmap (map words . lines) getContents

    let bst = Empty :: BST Int

    foldM_' doCmd bst cmds



Measured memory_bytes: 75848
#include<bits/stdc++.h>
using namespace std;
int N,M;
double dp[600][600];
double a[600];
double b[600];

const double INF = 1e20;

double Sum(int l,int r){
  if(l==0)return b[r-1];
  return b[r-1]-b[l-1];
}

int main(){

  cin>>N>>M;
  for(int i=0;i<N;i++){
    cin>>a[i];
    b[i]=a[i];
    if(i>0)b[i]+=b[i-1];
  }


  for(int i=0;i<600;i++)
    for(int j=0;j<600;j++)
      dp[i][j]=-INF;
  dp[0][0]=0;

  double maxm=0.0;
  
  for(int i=1;i<=N;i++){
    for(int j=1;j<=M;j++){
      for(int k=i-1;k>=0;k--){
        dp[i][j]=max(dp[i][j], dp[k][j-1] + ( Sum(k,i) / (i-k) ) );
        if(i==N)maxm=max(maxm, dp[i][j]);
      }

      //      cout<<dp[i][j]<<' ';
    }
    //    cout<<endl;
  }

  
  printf("%.10f\n",maxm);
  return 0;
}



Measured memory_bytes: 6108
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

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

	ll t, i, x, j, y, 	z, k, n;
	cin>>n;
	if(n>=30)	ce("Yes")
		else ce("No")
}



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


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, m, s[110000], ans = 0;
bool t[110000];
int main() {
	cin >> n >> m;
	t[1] = true;
	REP(i, 110000)s[i] = 1;
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		if (t[a]) {
			t[b] = true;
			if (s[a] == 1) t[a] = false;
		}
		s[a]--;
		s[b]++;
	}
	REP(i, 110000)if (t[i])ans++;
	cout << ans << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set


int main() 
{
	ll n;
	cin>>n;
	ll sum = 0;
	REP(i,1,n+1){
		if((i % 3 != 0) && (i % 5 != 0))
			sum += i;
	}
	cout<<sum<<endl;
	return 0;
}  


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

string s;

int main() {
  cin >> s;
  int N = s.size();
  rep(i, N) {
    if (i % 2 == 0) cout << s[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 512
import collections
n=int(input())
s=list(input())
c=collections.Counter(s)
d=c["R"]*c["G"]*c["B"]
ln=n//3
cnt=0
for y in range(1,n+1):
    for x in range(0,n+1):
        if x+2*y>=n:break
        g0=s[x]
        g1=s[x+y]
        g2=s[x+2*y]
        if g0!=g1 and g1!=g2 and g0!=g2:cnt+=1
print(d-cnt)

Measured memory_bytes: 68888
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	int n; cin >> n;
	vector<string>s(n);
	rep(i, n)cin >> s[i];

	int m; cin >> m;
	vector<string>t(m);
	rep(i, m)cin >> t[i];

	map<string, int>mp;
	rep(i, n) {
		mp[s[i]]++;
	}
	rep(i, m) {
		mp[t[i]]--;
	}

	int ans = 0;
	int now = 0;
	rep(i,n) {
		now = mp[s[i]];
		ans = max(ans, now);
	}

	int gogi = 0;
	rep(i, m) {
		now = mp[t[i]];
		gogi = max(ans, now);
	}
	cout << max(gogi, ans) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int m[55][55];

void fill_(int x,int y,int i){
    if(m[x][y]!=1){
        return;
    }
    m[x][y]=i;
    for(int dx=-1;dx<=1;++dx){
        for(int dy=-1;dy<=1;++dy){
            if(dx||dy){
                fill_(x+dx,y+dy,i);
            }
        }
    }
}

int main(void){
    // Your code here!
    while(1){
        for(int i=0;i<55;++i)fill(m[i],m[i]+55,-1);
        
        
        int w,h;
        cin>>w>>h;
        if(w==0&&h==0)break;
        for(int x=0; x<h;++x){
            for(int y=0;y<w;++y){
                int t;cin>>t;
                m[x+1][y+1]=t;
            }
        }
        int res=0;
        for(int x=1;x<=h;++x){
            for(int y=1;y<=w;++y){
                if(m[x][y]==1){
                    ++res;
                    fill_(x,y,res+1);
                }
            }
        }
        cout<<res<<endl;
    }
}



Measured memory_bytes: 3252
W, H, N = map(int, input().split())

mask = {}
for i in range(1, 5):
  if i%2 == 1:
    mask[i] = 0
  elif i == 2:
    mask[i] = W
  elif i == 4:
    mask[i] = H

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    mask[a] = max(x, mask[a])
  elif a == 2:
    mask[a] = min(x, mask[a])
  elif a == 3:
    mask[a] = max(y, mask[a])
  elif a == 4:
    mask[a] = min(y, mask[a])


if mask[1] >= mask[2] or mask[3] >= mask[4]:
  ans = 0
else:
  ans =  (mask[1] - mask[2]) * (mask[3] - mask[4])
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define FOR(i, n, m) for (int i = (n); i < (m); ++i)

const int MAX = 5010;

int N, K;
vi A;
ll dp[MAX];

bool need(int mid) {
  ll x = A[mid];
  if (x >= K) return true;

  FOR (i, 1, MAX) dp[i] = 0;
  dp[0] = 1;
  REP (i, N) if (i != mid) {
    REPR (k, K) {
      if (dp[k]!=0 && k+A[i] < K) {
        dp[k+A[i]] = 1;
        if (k+A[i]+x >= K) return true;
      }
    }
  }

  return false;
}

int main() {

  cin >> N >> K;
  A = vi(N);
  REP (i, N) cin >> A[i];
  sort(A.begin(), A.end());

  int lo = -1, hi = N;
  while (hi-lo > 1) {
    int mid = (hi+lo)/2;

    if (need(mid)) hi = mid;
    else lo = mid;
  }

  cout << hi << endl;

}

Measured memory_bytes: 384
A, B = map(int, input().split())

if 0 <= A < B :
    ans = B - A
elif 0 < B < A :
    ans = A - B + 2
elif 0 == B and  0 < A :
    ans = A - B + 1
elif A < 0 < B :
    ans = abs(A+B) + 1
elif A < 0 and 0 == B :
    ans = B - A
elif B < 0 < A :
    ans = abs(A+B) + 1
elif A < B < 0 :
    ans = B - A
elif B < A < 0:
    ans = A - B + 2
elif A == 0 and  B < 0:
    ans = A - B + 1

print(ans)

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

int main(){
  size_t n,m; cin>>n>>m;
  int ss[11];
  for(int i=0; i<m; ++i){
    ss[i]=0;
  }
  for(int i=0; i<m; ++i){
    int k; cin>>k;
    for(int j=0; j<k; ++j){
      int s; cin>>s;
      ss[i]|=(1<<(s-1));
    }
  }
  int p[11];
  for(int i=0; i<m; ++i){
    cin>>p[i];
  }
  // for(const auto& s:ss){
  //   cout<<s<<'\n';
  // }
  int res=0;
  for(int bits=0; bits<(1<<n); ++bits){
    for(int i=0; i<m; ++i){
      if(__builtin_parity(ss[i]&bits)!=p[i]) goto exit;
    }
    ++res;
    exit:;
  }
  cout<<res<<'\n';
}

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

using namespace std;

int main() {
	string n;

	cin >> n;

	if (n[0] == n[1] && n[1] == n[2])
		cout << "Yes" << endl;
	else if (n[1] == n[2] && n[2] == n[3])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


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

int isPrime(int);
int main(void){
	int n, i, x, cnt = 0;
	
	scanf("%d\n", &n);
	for(i = 0; i < n; i++){
		scanf("%d\n", &x);
		if(isPrime(x)){
			cnt++;
		}
	}
	printf("%d\n", cnt);
	
	return 0;
}

int isPrime(int x){
	int root = sqrt(x);
	int div;
	for(div = 2; div <= root ; div++){
		if(x % div == 0){
			return 0;
		}else{
			continue;
		}
	}
	return 1;
}


Measured memory_bytes: 2140
#include <iostream>
#define ll long long
#define endl '\n'
using namespace std;

ll X, point = 0, a, b;

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

	cin >> X;

	a = X / 500; b = X % 500;
	point += (a * 1000);

	a = b / 5; b = b % 5;
	point += (a * 5);

	cout << point;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

struct Test{
  bool is_ok = false;
  int penalty_cnt = 0;
};

int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;
  vector<Test> seikou(N);
  for (auto i = 0;i < M;++i) {
    int num;
    string s;
    cin >> num >> s;
    if (seikou[num-1].is_ok == false) {
      if (s == "WA") {
        ++seikou[num-1].penalty_cnt;
      } else {
        seikou[num-1].is_ok = true;
      }
    }
  }
  int clear_cnt_game {};
  int penalty_cnt_game {};
  for (const auto& e : seikou) {
    if (e.is_ok == true) {
      ++clear_cnt_game;
      penalty_cnt_game += e.penalty_cnt;
    }
  }
  cout << clear_cnt_game << ' ' << penalty_cnt_game << '\n';
}


Measured memory_bytes: 1024
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 IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		while (!str.equals("0")) {
			List<String> num = new ArrayList<>();
			int n = Integer.parseInt(str);
			str = br.readLine();
			String[] readnum = str.split("");
			int end = readnum.length;
			if (end == 1) {
				num.add("1");
				end = 2;
				n--;
			}
			for (String number : readnum) {
				num.add(number);
			}
			for (int i = 0; i < n; i++) {
				end = num.size();
				int seq = 1;
				for (int j = 1; j < end; j++) {
					if (num.get(j - 1).equals(num.get(j))) {
						seq++;
					} else {
						String[] seqchar = ("" + seq).split("");
						for (String chara : seqchar) {
							num.add(chara);
						}
						num.add(num.get(j - 1));
						seq = 1;
					}
				}
				String[] seqchar = ("" + seq).split("");
				for (String chara : seqchar) {
					num.add(chara);
				}
				num.add(num.get(end - 1));
				num.subList(0, end).clear();

			}
			for (String chara : num)
				System.out.print(chara);
			System.out.println();
			str = br.readLine();
		}
	}
}

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

#define pout(n)  printf ("%d\n", n)
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main (){
  int n;
  scanf("%d",&n);

  pout(24-n+24);

  return 0;
}

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


int main()
{
	int N;
	cin>>N;
	vector<int> s(N);
	rep(i,N) cin>>s[i];
	vector<int> dp(N*100+1);
    dp[0]=true;
  	rep(i,N)
    {
      for(int j=N*100;j>=s[i];j--)
      {
        if(dp[j-s[i]]) dp[j]=dp[j-s[i]];
      }
    }
   	int ans=0;
  	rep(i,N*100+1)
    {
      if(i%10!=0&&dp[i]) ans=i;
    }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <string>
#include <string.h>

using namespace std;

int si(const string& s)
{
    if (s[0] == 'M') return 0;
    if (s[0] == 'A') return 1;
    if (s[0] == 'R') return 2;
    if (s[0] == 'C') return 3;
    if (s[0] == 'H') return 4;
    return -1;
}

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

    int ss[5] = {0};
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        int j = si(s);
        if (j != -1) ss[j]++;
    }

    long long res = 0;
    for (int a=0;a<3;++a) {
        for (int b=a+1;b<4;++b) {
            for (int c=b+1;c<5;++c) {
                res += (long long)ss[a] * ss[b] * ss[c];
            }
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

const ll MOD = 1e9 + 7;

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

int main() {
  int H, W;
  while (cin >> H >> W) {
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    vec<ll, 2> dp = make_v(H, W, 0ll);
    dp[0][0] = 1;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (grid[i][j] == '#') continue;
        for (int k = 0; k < 2; k++) {
          int ni = i + dy[k];
          int nj = j + dx[k];
          if (ni < H && nj < W && grid[ni][nj] != '#') {
            (dp[ni][nj] += dp[i][j]) %= MOD;
          }
        }
      }
    }
    cout << dp[H - 1][W - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 9216
def binarySearch(key, arr)
  if arr.size == 0 then
    false
  elsif arr.size == 1 then
    arr[0].to_i == key.to_i
  else
    m = arr.size / 2
    v = arr[m].to_i

    if key.to_i == v then
      true
    elsif key.to_i < v then
      binarySearch(key, arr.take(m))
    else
      binarySearch(key, arr.drop(m))
    end
  end
end


a_size = STDIN.gets.to_i
as = STDIN.gets.split(' ')

b_size = STDIN.gets.to_i
bs = STDIN.gets.split(' ')

n = 0
for i in bs
  if binarySearch(i, as) then
    n = n + 1
  end
end

puts n

Measured memory_bytes: 21964
n=int(input())
h=list(map(int,input().split()))+[0]

ans=0

for i in range(max(h)):
  for g in range(1,n+1):
    if h[g-1]!=0 and h[g]==0:
      ans+=1
  for g in range(n+1):
    if h[g]!=0:
      h[g]-=1
      
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int h1,m1,h2,m2,K;
    cin >> h1 >> m1 >> h2 >> m2 >> K;
    cout << (h2-h1)*60+m2-m1-K << endl;
}

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


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 200020
typedef long long ll;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
char s[N];
int n,c0,c1,now;
ll ans;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;++i){
		if(s[i]=='0')++c0;
		else ++c1;
	}
	for(int i=1;i<=c1;++i){
		ans+=(i+1)>>1;
	}
	for(int i=1;i<=n;++i){
		if(s[i]=='0'){
			++now;
		}
		else if(s[i]==s[i+1]){
			++i,ans+=c0;
		}
		else{
			ans+=c0-now+(i&1?(now+1)/2:now/2);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3968
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    void solve() {
        // Input
        int n = sc.nextInt();
        int[] S = new int[n];
        for (int i = 0; i < n; i++) {
            S[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int[] T = new int[q];
        for (int i = 0; i < q; i++) {
            T[i] = sc.nextInt();
        }
        // Solve
        Set<Integer> set = new HashSet<>();
        for (int s : S) {
            set.add(s);
        }
        int cnt = 0;
        for (int t : T) {
            if (set.contains(t)) {
                cnt++;
            }
        }
        // Output
        System.out.println(cnt);
    }

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



Measured memory_bytes: 68496
#include <iostream>
#include <ctime>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <queue>
#include <deque>
#include <climits>
#include <cstring>
#include <random>
#include <bitset>

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    #ifdef LOCAL
    assert(freopen("input.txt", "r", stdin));
    assert(freopen("output.txt", "w", stdout));
    #endif
    
    int n;
    cin >> n;
    int cnt1 = n / 2;
    int cnt2 = (n + 1) / 2;
    cout << cnt1 * cnt2 << '\n';
}


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

int main(){
  int H, R;
  cin>>H>>R;
  
  if( -H == R ) cout<<0<<endl;
  if( -R < H ) cout<<1<<endl;
  if( H < -R ) cout<<-1<<endl;

  return 0;

}


Measured memory_bytes: 3088
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
	
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

void dfs(int v,int cnt){
	
	
}

int main(){
	string s;
	int guu = 0,paa = 0,kati = 0,make = 0;
	
	cin >> s;
	
	rep(i,0,s.size()){
		if(s[i] == 'g'){
			if(guu >= paa+1){
				kati++;
				paa++;
			}
			else{
				guu++;
			}
		}
		else{
			if(guu >= paa+1){
				paa++;
			}
			else{
				guu++;
				make++;
			}
		}
	}
	
	cout << kati - make << endl;
	
	
  	return 0;
}





Measured memory_bytes: 512
#include<iostream>
#include<vector>

using namespace std;

/*
タイルは5種類
> : 東
< : 西
^ : 北
v : 南
. : なし

現在地のタイルが東西南北なら移動、
ピリオドなら終了して位置を出力する。

ループの判断
１度到達した位置は記録しておく。
２回目に到達したらループと判定する。

*/


struct Position {
	int xPos;
	int yPos;
};

Position moveNorth(Position pos) {
	return Position{ pos.xPos, pos.yPos - 1 };
}

Position moveSouth(Position pos) {
	return Position{ pos.xPos, pos.yPos + 1 };
}

Position moveWest(Position pos) {
	return Position{ pos.xPos - 1, pos.yPos };
}

Position moveEast(Position pos) {
	return Position{ pos.xPos + 1, pos.yPos };
}


int main() {
	int h, w;
	while (true) {
		cin >> h >> w;
		if (h == 0 && w == 0) {
			break;
		}
		Position hitoPos = {};
		vector<vector<char>> tiles(h);
		vector<vector<bool>> mark(h);
		for (int i = 0; i < h; i++) {
			tiles[i] = vector<char>(w);
			mark[i] = vector<bool>(w);
		}

		for (auto& a : tiles) {
			for (auto &b : a) {
				cin >> b;
			}
		}

		while (!mark[hitoPos.yPos][hitoPos.xPos]) {
			mark[hitoPos.yPos][hitoPos.xPos] = true;
			switch (tiles[hitoPos.yPos][hitoPos.xPos])
			{
			case '>':
				hitoPos = moveEast(hitoPos);
				break;
			case '<':
				hitoPos = moveWest(hitoPos);
				break;
			case '^':
				hitoPos = moveNorth(hitoPos);
				break;
			case 'v':
				hitoPos = moveSouth(hitoPos);
				break;
			}
		}
		if (tiles[hitoPos.yPos][hitoPos.xPos] == '.') {
			cout << hitoPos.xPos << ' ' << hitoPos.yPos << endl;
		}
		else {
			cout << "LOOP" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
N = int(input())
A = [int(x) for x in input().split()]

should_exit = False
ans = 0
while True:
    for i in range(N):
        if A[i] % 2 == 1:
            should_exit = True
        A[i] = A[i] // 2
    if should_exit:
        break
    ans += 1

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define P pair
#define X first
#define Y second
#define VSORT(v) sort(v.begin(), v.end())
#define VREV(v) reverse(v.begin(), v.end())
#define VMAX_P(v) max_element(v.begin(), v.end())
#define VMIN_P(v) min_element(v.begin(), v.end())
#define VMAX_IDX(v) distance(v.begin(), VMAX_P(v))
#define VMIN_IDX(v) distance(v.begin(), VMIN_P(v))
#define VCOPY(src, dst) copy(src.begin(), src.end(), back_inserter(dst))
#define SUPPER(src, dst) transform(src.begin(), src.end(), dst.begin(), toupper);
#define SLOWER(src, dst) transform(src.begin(), src.end(), dst.begin(), tolower);

using namespace std;
using ll = long long;

int main(int argc, const char *argv[])
{
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200)
    {
        cout << s << endl;
    }
    else
    {
        cout << "red" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,c;
	int n;
	int i;
	while(scanf("%d",&n)!=EOF){
		for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
			if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 576
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

int cmp (const void *a, const void *b) {
  i32 d = *(i32 *)a - *(i32 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n, x;
  scanf ("%" SCNi32 "%" SCNi32, &n, &x);
  i32 a[100];
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  qsort (a, n, sizeof (i32), cmp);
  i32 i = 0;
  while (i < n && a[i] <= x) {
    x -= a[i];
    i++;
  }
  if (i >= n && x > 0) i--;
  printf("%" PRIi32 "\n", i);
}

int main (void) {
  run ();
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
using namespace std;
const int mod = 1e9+7;
const int N = 2e5+5;
string s[3005];
double ans[3005][3005];
double p[3005];
main() {
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    ans[0][0] = 1;
    for (int i = 1; i <= n; i++)
    for (int j = 0; j <= n; j++) {
            if (j)
        ans[i][j] = ans[i-1][j-1]*p[i];
        ans[i][j] += ans[i-1][j]*(1-p[i]);
    }
    double x = 0;
    for (int i = n/2 + 1;i <= n; i++)
        x += ans[n][i];
    cout << fixed << setprecision(10) << x;


}



Measured memory_bytes: 74264
#include<iostream>
using namespace std;
int main(){
    int a[5],i,j,k,x=10,s=0;
    for(i=0;i<5;i++){
        cin >> a[i];
        if((a[i]+9)%10<x){
            x=(a[i]+9)%10;
            k=i;
        }
    }
    for(i=0;i<5;i++){
        if(i!=k){
            s+=(a[i]+9)/10*10;
        }
        else{
            s+=a[i];
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,capacity;
	cin>>n>>capacity;
	long long dp[n+1][capacity+1];
	memset(dp, 0, sizeof(dp[0][0]) * (n+1) * (capacity+1));
	long long weights[n+1];
	long long value[n+1];
	for(int i=1;i<=n;i++){
		cin>>weights[i]>>value[i];
	}
	for(long long i=1;i<=n;i++)
	{
		for(long long j=1;j<=capacity;j++)
		{
			if(weights[i]>j)
			{
				dp[i][j]=dp[i-1][j];
			}
			else if(j>=weights[i])
			{
				dp[i][j]=max(value[i]+dp[i-1][j-weights[i]],dp[i-1][j]);
			}
			
		}	
	}
	cout<<dp[n][capacity]<<endl;

		
	return 0;
}

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

using namespace std;

int main() {
  int e;
  while ((cin >> e) && e != 0) {
    int m = e;
    for (int z=0; z<=100; z++) {
      int zzz = z*z*z;
      if (zzz > e) break;
      for (int y=0; y<=100000; y++) {
        int yy = y*y;
        if (yy+zzz > e) break;
        int x = e - (yy+zzz);
        m = min(m, x+y+z);
      }
    }
    cout << m << endl;
  }
  return 0;
}

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

int main()
{
	long long n,k,ans=0;
	cin>>n>>k;
	for(long long i=n;i>k;i--){
		int w=0;
		while(w*i+(i-1)<=n) w++;
		int x=0>n-w*i-k+1?0:n-w*i-k+1;
		ans+=(w*(i-k)+x);
		if(k==0) ans--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>

#define INF 1 << 30
#define MOD 1000000007
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second
#define setp(x) setprecision(x)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

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

int main() { 
        int n;
        cin >> n;
        vi a(n);
        int sum = 0;
        rep(i, n) {
                cin >> a[i];
                sum += a[i];
        }
        int ave = sum / n;

        int ans = INF;
        int res;
        for (int j = -100; j <= 100; j++) {
                res = 0;
                rep(i, n) {
                        res += ((ave + j) - a[i]) * ((ave + j) - a[i]);
                }
                amin(ans, res);
        }
       
        D(ans);

        return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

int a,b;
char c;
while(c!='?'){
scanf("%d %c %d",&a,&c,&b);

if(c=='+')printf("%d\n",a+b);
else if(c=='-')printf("%d\n",a-b);
else if(c=='*')printf("%d\n",a*b);
else if(c=='/')printf("%d\n",a/b);
}
return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll A, B;
  char c;
  cin >> A >> c >> B;
  if (c == '+') {
    COUT(A + B);
  } else {
    COUT(A - B);
  }
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x&(-x))
#define lson        (rt<<1)
#define rson        (rt<<1|1)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 4e5 + 50;
ll mi[maxn<<2],le[maxn<<2],ri[maxn<<2],lazy[maxn<<2];
void build(int rt,int l,int r){
    mi[rt]=le[rt]=ri[rt]=INF;
    lazy[rt]=0;
    if(l!=r){
        int mid=(l+r)>>1;
        build(lson,l,mid);
        build(rson,mid+1,r);
    }
}
void add(int rt,ll val){
    mi[rt]+=val;
    le[rt]+=val;
    ri[rt]+=val;
    lazy[rt]+=val;
}
void down(int rt){
    add(lson,lazy[rt]);
    add(rson,lazy[rt]);
    lazy[rt]=0;
}
void up(int rt){
    le[rt]=min(le[lson],le[rson]);
    ri[rt]=min(ri[lson],ri[rson]);
    mi[rt]=min(mi[lson],mi[rson]);
}
void update1(int rt,int l,int r,int pos,ll val){
    if(l==r){
        mi[rt]=min(mi[rt],val);
        le[rt]=min(le[rt],val-l);
        ri[rt]=min(ri[rt],val+l);
    }else{
        int mid=(l+r)>>1;
        if(lazy[rt])down(rt);
        if(pos<=mid)update1(lson,l,mid,pos,val);
        else update1(rson,mid+1,r,pos,val);
        up(rt);
    }
}
void update2(int rt,int l,int r,int L,int R,ll val){
    if(L<=l and r<=R){
        add(rt,val);
    }else{
        int mid=(l+r)>>1;
        if(lazy[rt])down(rt);
        if(L<=mid)update2(lson,l,mid,L,R,val);
        if(R>mid)update2(rson,mid+1,r,L,R,val);
        up(rt);
    }
}
ll get(int rt,int l,int r,int L,int R,int ty){
    if(L<=l and r<=R){
        if(ty==1)return le[rt];
        else return ri[rt];
    }else{
        int mid=(l+r)>>1;
        if(lazy[rt])down(rt);
        ll res=INF;
        if(L<=mid)res=min(res,get(lson,l,mid,L,R,ty));
        if(R>mid)res=min(res,get(rson,mid+1,r,L,R,ty));
        return res;
    }
}
ll ans=INF;
void downdown(int rt,int l,int r){
    if(l==r){
//        cout<<l<<" "<<mi[rt]<<endl;
        ans=min(ans,mi[rt]);
    }
    else{
        int mid=(l+r)>>1;
        if(lazy[rt])down(rt);
        downdown(lson,l,mid);
        downdown(rson,mid+1,r);
    }
}
int pos[maxn];
int main() {
#ifdef local
    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n,q;cin>>n>>q;
    int a,b;cin>>a>>b;

    build(1,1,n);
    for(int i=1;i<=q;++i)
        cin>>pos[i];
    pos[0]=b;

    update1(1,1,n,a,0);
//    downdown(1,1,n);
//    cout<<endl;
    for(int i=1;i<=q;++i){
        int u=pos[i],pre=pos[i-1];

        ll mi=min( get(1,1,n,1,u,1)+u , get(1,1,n,u,n,2)-u);
        update2(1,1,n,1,n,abs(u-pre));
        update1(1,1,n,pre,mi);
//        downdown(1,1,n);
//        cout<<endl;
    }
    downdown(1,1,n);
    cout<<ans;






    return 0;
}


Measured memory_bytes: 24192
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    if N%10==3:
        s = 'bon'
    elif N%10 in [0,1,6,8]:
        s = 'pon'
    else:
        s = 'hon'
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(s)


Measured memory_bytes: 61656
#include<bits/stdc++.h>
// 打电话
#define SC scanf
using namespace std;

int k,ans,minx = 1e9,tot,ky;
int ver[5001],nex[5001],head[5001];

void add(int u,int v)
{
	ver[++tot] = v;
	nex[tot] = head[u];
	head[u] = tot;
}

void hmd(int now,int depth,int pre)
{
	if(depth > k/2)
	{
//		if(j && depth == k/2+1)
//			jiu = true;
		ans++;
	}
	for(int i = head[now]; i; i = nex[i])
	{
		int y = ver[i];
		if(y != pre)
			hmd(y,depth+1,now);
	}
	return;
}

int main()
{
	int n,u,v;
	SC("%d %d",&n,&k);
	for(int i = 1; i < n; i++)
	{
		SC("%d %d",&u,&v);
		add(u,v);
		add(v,u);
	}
	if(k%2 == 0)
		for(int i = 1; i <= n; i++)
		{
			ans = 0;
			hmd(i,0,0);
			minx = min(ans,minx);
		}
	else
	{
		for(int i = 1; i <= n; i++)
		{
			for(int ky = head[i]; ky; ky = nex[ky])
			{
				int gy = ver[ky];
				ans = 0;
				hmd(gy,0,i);
//				int sav = ans;
//				ans = 0;
				hmd(i,0,gy);
				minx = min(ans,minx);
			}

		}
	}
	printf("%d",minx);
}

Measured memory_bytes: 384
def a():
    n, k = map(int, input().split())
    if int(n / 2 + 0.5) >= k:
        print("YES")
    else:
        print("NO")


def B():
    root = [[0 for i in range(4)] for j in range(4)]
    for i in range(3):
        a, b = map(int, input().split())
        #print(a, b)
        root[a - 1][b - 1] = 1
        root[b - 1][a - 1] = 1

    cnt_one = 0
    cnt_two = 0
    for i in range(4):
        if sum(root[i]) == 1:
            cnt_one += 1
        if sum(root[i]) == 2:
            cnt_two += 1
    if cnt_one == 2 and cnt_two == 2:
        print("YES")
    else:
        print("NO")

#B()

def C():
    k, a, b = map(int, input().split())
    if a < b and b - a >= 2:
        cnt = a
        k -= (a - 1)
        cnt += k // 2 * (b - a)
        k -= k // 2 * 2
        cnt += k
        print(cnt)
    else:
        print(k + 1)
C()

Measured memory_bytes: 3064
//
//  main.cpp
//
// https://atcoder.jp/contests/abc126/tasks/abc126_d

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

int main() {
    int N;
    cin >> N;
    struct Edge {
        int from;
        int to;
        int parity;
    };
    vector<vector<Edge>> tree;
    tree.resize(N);
    for(int i = 0; i < N; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        tree[u-1].push_back({u-1, v-1, w % 2});
        tree[v-1].push_back({v-1, u-1, w % 2});
    }
    vector<bool> visited(N);
    vector<int> parity(N);
    vector<int> que;
    que.push_back(0);
    while (!que.empty()) {
        int vtx = que.back();
        que.pop_back();
        visited[vtx] = true;
        for (Edge e : tree[vtx]) {
            parity[e.to] = (parity[vtx] + e.parity) % 2;
            if (!visited[e.to]) {
                que.push_back(e.to);
            }
        }
    }
    for (int i = 0; i < N; i++) {
        if (parity[i]) {
            cout << "1" << endl;
        } else {
            cout << "0" << endl;
        }
    }
}



Measured memory_bytes: 7296
#include <iostream>
using namespace std;
int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    
    int lv = x - r;
    int rv = x + r;
    int tv = y + r;
    int bv = y - r;
    
    if (lv >= 0 && rv <= W && bv >= 0 && tv <= H) {
        cout << "Yes" << endl;   
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


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


namespace ABC044_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string w = Console.ReadLine();
            var c = w.ToCharArray();
            Array.Sort(c);
            var now = c[0];
            var cnt = 1;
            bool flag = true;
            for (int i = 1; i < w.Length; i++)
            {
                if (now == c[i])
                {
                    cnt++;
                }
                else
                {
                    if (cnt % 2==1)
                    {
                        flag = false;

                    }
                    else
                    {
                        cnt = 1;
                        now = c[i];
                    }
                }
            }
            if (cnt % 2 ==1 || !flag)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}


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

#define Omar45 ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define maxN 100005
const int inf=0x3f3f3f3f;

int arr[maxN], dp[maxN];

int main() {
	Omar45
    int n, k; cin >> n >> k;
    for (int i=0; i<n; i++) cin >> arr[i];
    for (int i=0; i<=n; i++) dp[i] = mod;
    dp[0] = 0;
    for (int i=0; i<n; i++){
        for (int j= i+1; j<=i+k; j++) {
            if (j<n) dp[j] = min(dp[j], dp[i] + abs(arr[i] - arr[j]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e9+7;
const ll mod= 1e9 + 7;


ll A,B,C,K,ans;

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

	cin >> A >> B >> C >> K;
	
	if (K > A) {
		ans = A;
		K -= A;

		if (K > B) {
			K -= B;

			if (K > 0) {
				ans -= K;

			}

		}


	}
	else ans = K;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3164