akhauriyash/Code-Regression huggingface dataset:
import Control.Applicative
import qualified Data.IntMap as IMap

main = do
    [n,k] <- map read . words <$> getLine  :: IO [Int]
    list <- sequence (replicate n ((\[x,y]->(x,y)) . map read . words <$> getLine)) :: IO [(Int,Int)]
    print $ solve k list

solve :: Int -> [(Int,Int)] -> Int
solve k list = fd k dic
    where dic = make list

fd k dic = if b >= k then a else (fd (k-b) dic_)
    where ((a,b),dic_) = IMap.deleteFindMin dic

make :: [(Int,Int)] -> IMap.IntMap Int
make list = foldl append start list
    where start = IMap.fromList (zip [1..100000] (repeat 0))

append :: IMap.IntMap Int -> (Int,Int) -> IMap.IntMap Int
append dic (a,b) = IMap.update (\y -> Just (y+b)) a dic


Measured memory_bytes: 121212
#include<bits/stdc++.h>
using namespace std;
#define int long long
#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

string s;
bool used[30][30];

signed main()
{
    cin >> s;
    int N = s.size();
    for(int i = 0; i < N; i++){
        used[i][s[i] - 'a'] = true;
        if(i == 0)continue;
        for(int j = 0; j < 26; j++){
            used[i][j] |= used[i - 1][j];
        }
    }
    for(int i = 0; i < 26; i++){
        used[N][i] = used[N - 1][i];
    }
    s = s + 'a';
    N++;
    //cout << s << endl;
    /*for(int i = 0; i < N; i++){
        printf("%d ", i);
        for(int j = 0; j < 26; j++){
            if(used[i][j])printf("%c", 'a' + j);
        }
        printf("\n");
    }*/
    for(int i = N - 1; i >= 0; i--){
        for(int j = s[i] - 'a'; j < 26; j++){
            if(!used[i][j]){
                s[i] = 'a' + j;
                for(int k = 0; k < s.size(); k++){
                    if(s[k] == '\0')break;
                    printf("%c", s[k]);
                }
                printf("\n");
                return 0;
            }
        }
        s[i] = '\0';
    }
    printf("-1\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;

int main(){
	int n;scanf("%d",&n);
	int Min=INT_MAX;
	rep(i,n){
		int a;scanf("%d",&a);
		int cnt=0;
		while(a%2==0){
			a/=2;cnt++;
		}
		Min=min(Min,cnt);
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,ans,ny[1000001],jc[1000001],p=998244353;
ll ksm(ll x,ll y){
	ll xlh=1;
	while(y){
		if(y&1)xlh=xlh*x%p;
		x=x*x%p;
		y/=2;
	}
	return xlh;
}
ll C(ll x,ll y){
	return jc[x]*ny[y]%p*ny[x-y]%p;
}
void solve(){
	ll i;
	for(i=1;i<=m;i++)ans=(ans+C(i*2,i)*C(n+m-i*2,n-i)%p)%p;
}
int main(){
	ll i;
	scanf("%lld%lld",&n,&m);
	if(n<m)swap(n,m);
	jc[0]=ny[0]=1;
	for(i=1;i<=1000000;i++)jc[i]=jc[i-1]*i%p;
	ny[1000000]=ksm(jc[1000000],p-2);
	for(i=1000000-1;i;i--)ny[i]=ny[i+1]*(i+1)%p;
	solve();
	ans=ans*ksm(2,p-2)%p*ksm(C(n+m,m),p-2)%p;
	printf("%lld",(ans+n)%p);
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    ll x;
    cin >> x;
    ll ans = 0;
    ans += (x/11)*2;
    if(x%11==0) ans += 0;
    else if(x%11<=6) ans += 1;
    else ans += 2;
    cout << ans << endl;
    
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    Vl A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    Vl ans(N);
    for (ll i = 0; i < N; i++) {
        if (i & 1) {
            ans[0] -= A[i] * 2;
        }
        else {
            ans[0] += A[i] * 2;
        }
    }
    ans[0] /= 2;
    for (ll i = 1; i < N; i++) {
        ans[i] = A[i - 1] * 2 - ans[i - 1];
    }

    for (ll i = 0; i < N; i++) {
        cout << ans[i] << " ";
    }
    cout << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>
int main(){
    int r,D,x[100];
    scanf("%d %d %d",&r,&D,&x[0]);
    for(int i=1;i<=10;i++){
        x[i]=r*x[i-1]-D;
            printf("%d\n",x[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

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

  sort(s.begin(),s.end());
  //unique
  s.erase(unique(s.begin(),s.end()),s.end());
  string alph = "abcdefghijklmnopqrstuvwxyz";
  if(s.size() == 26) cout <<"None" << endl;
  else{
    int i ;
    for(i = 0; i < s.size(); i++) {
      if(s[i] != alph[i]){
        cout << (char)('a' + i) << endl;
        return 0;
      }
    }
    cout << alph[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

long gcd(long a, long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

int main()
{
   long a,b,c,d;
   cin >> a >> b >> c >> d;

   long num = b-a+1;
   long ans = (b/c) + (b/d) - (b/lcm(c,d)) + ((a-1)/lcm(c,d)) - ((a-1)/c) - ((a-1)/d);
   
   cout << num - ans << endl;
   return 0;
}

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

int main(){
    vector<int> a(5);
    rep(i,5) {cin >> a[i]; if(a[i] == 0) cout << i+1 << endl;}
}

Measured memory_bytes: 3608
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    mylist = LI()
    shift = 1000000007
    S = sum(mylist)
    res = 0
    
    for i in mylist:
        S-=i
        if S==0:
            break
        res += (S*i)%shift
    

    print(int(res % shift))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 95252
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		//sc??¨dice??????????????????????????????
		Scanner sc = new Scanner(System.in);
		Dice dice = new Dice(sc);

		//????????????????????????
		String command = sc.next();
		dice.com(command);

		System.out.println(dice.gettopNum());
		sc.close();
	}
}




class Dice {
	//?????£?????????
	private int[] dice = new int[6];

	//???????????????????????????????????????
	Dice(Scanner scan){
		for(int i = 0; i < 6; i++){
			this.dice[i] = scan.nextInt();
			//????????????
			//System.out.println("this.dice[" + i + "]" + this.dice[i]);
		}
	}

	void com(String command){
		//????????????char????????????
		for(int i = 0; i < command.length(); i++){
			char action = command.charAt(i);
			/*
			dice.roll(action);
		}
	}

	//???????????????????????\????????????
	void roll(char action){

			 */
			//??????????????´?????????????????????????????¢?????????
			int temp = dice[0];

			//????§??????¨??¢?????????????????????????????????????????????
			switch(action){
			case 'N':
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = temp;
				break;

			case 'S':
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = temp;
				break;

			case 'E':
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = temp;
				break;

			case 'W':
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = temp;
				break;

			default :
				break;
			}
		}
	}

	int gettopNum(){
		return dice[0];
	}
}

Measured memory_bytes: 26352
import java.util.*;

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

        int n = sc.nextInt();
        Integer[] list = new Integer[n];

        for(int i = 0; i < n; i++){
            list[i] = sc.nextInt();
        }

        Arrays.sort(list);
        
        int t = list[0];
        int ans = 1;

        for(int i = 1; i < n; i++){
            if(list[i] != t){
                t = list[i];
                ans++;
            }
        }

        System.out.println(ans);

        sc.close();
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 998244353;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

//入出力高速化(非同期化)
void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}


int main(void) {
    long long R, G, B, N;
    cin >> R >> G >> B >> N;
    long long ans = 0;
    for (long long r = 0; r <= 3000; r++) {
        for (long long g = 0; g <= 3000; g++) {
            if (N-R*r-g*G >= 0) {
                long long b = (N-R*r-g*G) / B;
                if (r*R + g*G + b*B == N) ans++;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
from itertools import accumulate
n,k=map(int,input().split())
p=list(map(int,input().split()))
accum=[]
for i in range(n):
  if p[i]%2:
    accum.append(1+(p[i]-1)/2)
  else:
    accum.append(1.5+(p[i]-2)/2)
accum=list(accumulate(accum))
ans=accum[k-1]
for i in range(1,n-k+1):
  ans=max(ans,accum[i+k-1]-accum[i-1])
print(ans)

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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int r, c, n;

bool f(int x, int y) {
	return x == 0 || x == r || y == 0 || y == c;
}

int val(int x, int y) {
	if (y == 0) return x;
	if (x == r) return r + y;
	if (y == c) return r + c + r - x;
	if (x == 0) return r + c + r + c - y;
}

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

	vector<pii> vec;

	rep(i, n) {
		int a = in(), b = in(), c = in(), d = in();
		if (f(a, b) && f(c, d)) {
			vec.pb(pii(val(a, b), i));
			vec.pb(pii(val(c, d), i));
		}
	}

	sort(all(vec));

	stack<int> st;
	st.push(-1);
	rep(i, vec.size()) {
		if (st.top() == vec[i].sc) {
			st.pop();
		} else {
			st.push(vec[i].sc);
		}
	}

	print(st.size() == 1 ? "YES" : "NO");
}


Measured memory_bytes: 2420
N = int(input())
MN = [ (mark,number) for mark in ['S', 'H', 'C', 'D'] for number in range(1,14) ]
for _ in range(N):
    mark,number = input().split()
    MN.remove((mark,int(number)))
for (mark, number) in MN:
    print(mark, number)

Measured memory_bytes: 7636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

const int INF = 1e9;
const int MOD = 1e9+7;

int main(void){
    ll a, b, c, d, e, f;
	while(cin >> a >> b >> c >> d >> e >> f, a+b+c+d+e+f != 0){
        a += d;
        b += e;
        c += f;
        ll m = min(a, min(b, c));
        ll ans = 0;
        REP(i, 3){
            if(m - i < 0) continue;
            ll k = (a - i) / 3;
            k += (b - i) / 3;
            k += (c - i) / 3;
            ans = max(ans, k + i);
        }
        cout << ans << endl;
    }
	
	return 0;
}

Measured memory_bytes: 1160
x,y = map(int,input().split())
lst1 = [1,3,5,7,8,10,12]
lst2 = [4,6,9,11]
if (x in lst1) and (y in lst1):
    print("Yes")
elif (x in lst2) and (y in lst2):
    print("Yes")
else:
    print("No")


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

int main(){
  int n;
  cin >> n;
  vector<int> s(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  int count = 0;
  if(n<3){
    cout << "0" << endl;
  }else{  
    for(int i=0;i<n;i++){
      for(int j=i;j<n;j++){
        for(int k=j;k<n;k++){
          if(s[i]!=s[j] && s[j]!=s[k] && s[i]!=s[k] && s[i]+s[j]>s[k] && s[j]+s[k]>s[i] && s[k]+s[i]>s[j]){
            count++;
          }
        }
      }
    }
    cout << count << endl;
  }
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cmath>
#include <vector>


using namespace std;



int main()
{
	string in;

	cin >> in;

	if (string::npos != in.find('7'))
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}

Measured memory_bytes: 3576
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
char s[1000005];
using P=pair<int,int>;
int main(){
  int H,W,K,gx,gy;
  P start;
  scanf("%d %d %d\n%d %d %d %d\n",&H,&W,&K,&start.first,&start.second,&gx,&gy);
  vector<vector<int>> dist(H,vector<int>(W));
  for(int i=0;i<H;++i){
    fgets(s,10000000,stdin);
    for(int j=0;j<W;++j){
      dist[i][j]=(s[j]=='.')*1e6;
    }
  }
  queue<P> que;
  dist[--start.first][--start.second]=0;
  que.push(start);
  while(!que.empty()){
    P x=que.front();que.pop();
    for(int i=1;i<=K;++i){
      if(x.first-i<0||dist[x.first-i][x.second]<=dist[x.first][x.second])break;
      if(dist[x.first-i][x.second]!=dist[x.first][x.second]+1){
        que.push(P(x.first-i,x.second));
        dist[x.first-i][x.second]=dist[x.first][x.second]+1;
      }
    }
    for(int i=1;i<=K;++i){
      if(x.first+i>=H||dist[x.first+i][x.second]<=dist[x.first][x.second])break;
      if(dist[x.first+i][x.second]!=dist[x.first][x.second]+1){
        que.push(P(x.first+i,x.second));
        dist[x.first+i][x.second]=dist[x.first][x.second]+1;
      }
    }
    for(int i=1;i<=K;++i){
      if(x.second-i<0||dist[x.first][x.second-i]<=dist[x.first][x.second])break;
      if(dist[x.first][x.second-i]!=dist[x.first][x.second]+1){
        que.push(P(x.first,x.second-i));
        dist[x.first][x.second-i]=dist[x.first][x.second]+1;
      }
    }
    for(int i=1;i<=K;++i){
      if(x.second+i>=W||dist[x.first][x.second+i]<=dist[x.first][x.second])break;
      if(dist[x.first][x.second+i]!=dist[x.first][x.second]+1){
        que.push(P(x.first,x.second+i));
        dist[x.first][x.second+i]=dist[x.first][x.second]+1;
      }
    }
  }
  if(dist[--gx][--gy]==1e6)puts("-1");
  else printf("%d\n",dist[gx][gy]);
}

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

int main() {
  int N, A, B, plan1, plan2;
  cin >> N >> A >> B;
  
  plan1 = N * A;
  plan2 = B;
  
  if ( plan1 <= plan2 ) {
  	cout << plan1 << endl;
  }else {
  	cout << plan2 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int H;
	int W;
	

	while (cin >> H >> W,H || W)
	{
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if ((i+j)%2==1)
				{
					cout << ".";
				}
				else cout << "#";
			}

			cout << endl;
		}

		cout << endl;

	}
	return 0;
}



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

int main(){
  int N;
  cin>>N;
  if (N>2000){
    cout<<"1"<<endl;
    return 0;
  }
  int dp[2000];
  for (int i=0;i<2001;i++){
    dp[i]=0;
  }
  dp[100]=1;
  dp[101]=1;
  dp[102]=1;
  dp[103]=1;
  dp[104]=1;
  dp[105]=1;
 
  for(int i=1;i<2001;i++){
    if(i>100){
      if(dp[i-100]==1){
        dp[i]=1;
      }
    }
    
      if(i>101){
      if(dp[i-101]==1){
        dp[i]=1;
      }
      }
    
              if(i>102){
      if(dp[i-102]==1){
        dp[i]=1;
      }
              }
    
              if(i>103){
      if(dp[i-103]==1){
        dp[i]=1;
      }
              }
    
                      if(i>104){
      if(dp[i-104]==1){
        dp[i]=1;
      }
                      }
    
      if(i>105){
      if(dp[i-105]==1){
        dp[i]=1;
      }
      }
  }
  cout<<dp[N]<<endl;

  return 0;
}


    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll> mm[20][150],dp3[20][2][150];
ll n,sum=0,pro=1,ans=0;;
string s;
ll dfs(ll p,ll f,ll ss,ll m){
  if(dp3[p][f][ss].find(m)!=dp3[p][f][ss].end()) return dp3[p][f][ss][m];
  ll res=0;
  if(p==n) return f&&ss==0&&m==1;
  if(f){
    for(ll i=0;i<10;i++) if((i<=ss)&&(m%(i+1)==0)) res+=dfs(p+1,1,ss-i,m/(i+1));
  }else{
    for(ll i=0;i<s[p]-'0';i++) if((i<=ss)&&(m%(i+1)==0)) res+=dfs(p+1,1,ss-i,m/(i+1));
    ll i=s[p]-'0';
    if((i<=ss)&&(m%(i+1)==0)) res+=dfs(p+1,0,ss-i,m/(i+1));
  }
  return dp3[p][f][ss][m]=res;
}
ll dfs2(ll p,ll ss,ll m){
  if(p==n) return (ss==0&&m<pro);
  if(mm[p][ss].find(m)!=mm[p][ss].end()) return mm[p][ss][m];
  ll res=0;
  for(ll i=0;i<10;i++) if(i<=ss) res+=dfs2(p+1,ss-i,m*(i+1));
  return mm[p][ss][m]=res;
}
int main(){
  cin>>s;
  n=s.size();
  for(ll i=0;i<n;i++) sum+=s[i]-'0',pro*=(ll)(s[i]-'0'+1);
  ll dp[15][150]={};
  dp[0][0]=1;
  for(ll i=0;i<n;i++) for(ll j=0;j<150;j++) for(ll k=0;k<10;k++) dp[i+1][j+k]+=dp[i][j];
  for(ll j=0;j<sum;j++) ans+=dp[n][j];
  ans+=dfs(0,0,sum,pro)+dfs2(0,sum,1);
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define int unsigned long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int n;
vint g[101];
vector<Pi> es;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> n;
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
    es.emplace_back(a, b);
  }

  if(n == 2) {
    cout << 1 << " " << 2 << endl;
    return 0;
  }

  int col = LLONG_MAX, leaf = LLONG_MAX;
  rep(i, n) {
    vint dep(n);
    vint mxch(n);
    function<void(int, int)> dfs = [&](int u, int p) {
      int cnt = 0;
      for(int v : g[u]) {
	if(v == p) continue;
	dep[v] = dep[u]+1;
	dfs(v, u);
	++cnt;
      }
      chmax(mxch[dep[u]], cnt);
    };
    dep[i] = 0;
    dfs(i, -1);
    int d = *max_element(all(dep));
    int l = mxch[0];
    reps(j, 1, n) {
      if(mxch[j]) l *= mxch[j];
    }
    if(d+1 < col) {
      col = d+1;
      leaf = l;
    } else if(d+1 == col) {
      chmin(leaf, l);
    }
  }
  for(Pi p : es) {
    vint dep(n);
    vint mxch(n);
    function<void(int, int)> dfs = [&](int u, int p) {
      int cnt = 0;
      for(int v : g[u]) {
	if(v == p) continue;
	dep[v] = dep[u]+1;
	dfs(v, u);
	++cnt;
      }
      chmax(mxch[dep[u]], cnt);
    };
    dep[p.first] = dep[p.second] = 0;
    dfs(p.first, p.second);
    dfs(p.second, p.first);
    int d = *max_element(all(dep));
    int l = mxch[0]*2;
    reps(j, 1, n) {
      if(mxch[j]) l *= mxch[j];
    }
    if(d+1 < col) {
      col = d+1;
      leaf = l;
    } else if(d+1 == col) {
      chmin(leaf, l);
    }
  }
  cout << col << " " << leaf << endl;

  return 0;
}


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

int main() {
  int k;
  cin >> k;
  
  int x = 0;
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        x += gcd(a, gcd(b, c));
      }
    }
  }
  
  cout << x;
    
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0;i < n;i++) cin >> a[i];
  std::sort(a.begin(),a.end());
  cout << a[n-1]-a[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
int h,w,k;
cin>>h>>w>>k;
string s[h];
for(int i=0;i<h;i++)cin>>s[i];
string q;
for(int i=0;i<w;i++)q.push_back('.');
int a[h][w];int p=1,g;
for(int i=0;i<h;i++){

    if(s[i]==q){
        a[i][0]=-1;
        continue;
    }

    for(int j=0;j<w;j++){
        a[i][j]=p;
        if(s[i][j]=='#')p++;
    }
    g=w-1;
    while(a[i][g]==p){
        a[i][g]--;
        g--;
    }

}
g=0;
while(a[g][0]==-1)g++;
for(int i=0;i<g;i++){
    for(int j=0;j<w;j++)cout<<a[g][j]<<' ';
    cout<<endl;
}
p=g;
for(int i=g;i<h;i++){
    if(a[i][0]!=-1)p=i;
    for(int j=0;j<w;j++)cout<<a[p][j]<<' ';
    cout<<endl;
}
return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
typedef long long ll;

struct edge
{
    int to;
    ll score;
};

using Graph = vector<edge>;

int main()
{
    int N;
    ll K, ans = -10e15;
    cin >> N >> K;
    vector<ll> P(N, 0);
    vector<ll> C(N, 0);
    Graph graph(N);
    for (int i = 0; i < N; i++)
    {
        cin >> graph[i].to;
        graph[i].to--;
    }
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
    }

    for (int i = 0; i < N; i++)
    {
        graph[i].score = C[graph[i].to];
    }

    for (int i = 0; i < N; i++)
    {
        int cycle_c = 0;
        ll cycle_s = 0;
        int index = i;
        while (true)
        {
            cycle_c++;
            cycle_s += graph[index].score;
            index = graph[index].to;
            if (index == i)
            {
                break;
            }
        }

        ll now_s = 0;
        int now_c = 0;
        while (true)
        {
            now_c++;
            now_s += graph[index].score;

            if (now_c > K)
                break;

            int n = (K - now_c) / cycle_c;
            ll score = now_s+max(0ll,cycle_s)*n;
            ans = max(ans,score);

            index = graph[index].to;
            if (index == i)
                break;
            
        }
    }

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

Measured memory_bytes: 3736
s_dash = input()
t = input()
len_s = len(s_dash)
len_t = len(t)
candidates = set()

for i in range(len_s - len_t + 1):
    part_s = s_dash[i:i+len_t+1]
    flag = True
    for j,k in zip(part_s,t):
        if j=='?' or j==k:
            continue
        else:
            flag = False
            break
    if flag:
        candidates.add(s_dash[0:i].replace("?","a")+t+s_dash[i+len_t::].replace("?","a"))

ret = 'UNRESTORABLE'
if len(candidates)>0:
    ret = min(candidates)
print(ret)

Measured memory_bytes: 3064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "map"

using namespace std;
const long long int MOD = 1000000007;

int N,M;
char letter[2][100][100];
int ans;



int main() {
	cin >> N>>M;
	if (N == 1)N = 14;
	if (M == 1)M = 14;
	if (N > M)cout << "Alice\n";
	else if (N < M)cout << "Bob\n";
	else cout << "Draw\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstring>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
#define all(v) v.begin(), v.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

int main(){
    int n, m;
	while(cin >> n >> m, n|m){
		vector<vi> G(n);
		rep(i, m){
			int a, b;
			cin >> a >> b;
			a--, b--;
			G[a].push_back(b);
			G[b].push_back(a);
		}
		vector<int> f(1, 0);
		rep(i, G[0].size()){
			f.push_back(G[0][i]);
		}
		set<int> s;
		rep(i, f.size()){
			s.insert(f[i]);
			rep(j, G[f[i]].size()){
				s.insert(G[f[i]][j]);
			}
		}
		cout << s.size()-1 << endl;
	}
    return 0;
}

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

int main() {
  int n, i, m;
  int ans = 1;
  cin >> n;
  cin >> m;
  while (cin >> i) {
    if (i <= m) ans++;
    m = min(i, m);
  }
  printf("%d\n", ans);
  return 0;}


Measured memory_bytes: 256
fun main (args:Array<String>) {
    val (summerVacationDays, _ ) = readLine()!!.split(" ").map(String::toInt)
    val homeworkDay = readLine()!!.split(" ").map(String::toInt).sum()
    if(homeworkDay > summerVacationDays){
        print("-1")
        return
    }
    print(summerVacationDays - homeworkDay)

}


Measured memory_bytes: 39404
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
c = 0
d = 0
for i in range(N):
    if a[i] == d:
        if c == 0:
            c = a[i]
            d = 0
        else:
            print(c * a[i])
            exit()
    else:
        d = a[i]
print(0)


Measured memory_bytes: 14252
MOD = 10**9 + 7
S = int(input())

dp = [0] * (S+1)
dp[0] = 1
for i in range(1, S+1):
    for j in range(0, (i-3)+1):
        dp[i] += dp[j]
        dp[i] %= MOD

print(dp[S])


# dp:=最後に切った場所がiの場合の数

Measured memory_bytes: 9124
#include<stdio.h>
#include<inttypes.h>

int
main(int argc, char *argv[])
{
        uint_fast8_t i;
        uint_fast64_t a;

        scanf("%"SCNdFAST64, &a);
        for (i = a - 1; i > 0; i--)
                a *= i;
        printf("%"PRIdFAST64"\n", a);

        return 0;
}

Measured memory_bytes: 588
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int flag=1;
	if(a==b||b==c||a==c)
	{
		if(a==b&&b==c) cout<<"No"<<endl;
		else
		cout<<"Yes"<<endl;
	}
	else
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
//url:
//problem name: 

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int X,Y; cin >> X >> Y;
    cout << X + Y/2 << endl;
}


Measured memory_bytes: 3552
#define _CRT_SECURE_NO_WARNINGS
#include <array>
#include <algorithm>
#include <cstdio>

using namespace std;

const int NMax = 40;
const int abMax = 10;
const int cMax = 100;

const int INF = cMax * NMax + 1;

const int abNMax = abMax * NMax;

array<int, NMax> a;
array<int, NMax> b;
array<int, NMax> c;

array<array<array<int, abNMax + 1>, abNMax + 1>, NMax + 1> dp;

int main()
{
    int N, Ma, Mb;
    if (scanf("%d%d%d", &N, &Ma, &Mb) < 3) return 0;

    // 0-indexed
    for (int i = 0; i < N; i++)
    {
        if (scanf("%d%d%d", &a[i], &b[i], &c[i]) < 3) return 0;
    }

    // none dp[0][0][0] = 0;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= abNMax; j++)
        {
            for (int k = 0; k <= abNMax; k++)
            {
                dp[i][j][k] = INF;
            }
        }
    }

    // none
    dp[0][0][0] = 0;

    // update dp[i + 1]
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j <= abNMax; j++)
        {
            for (int k = 0; k <= abNMax; k++)
            {
                if (dp[i][j][k] == INF) continue;

                // not select
                dp[i + 1][j][k]
                    = min(dp[i][j][k], dp[i + 1][j][k]);

                // select
                dp[i + 1][j + a[i]][k + b[i]]
                    = min(
                        dp[i][j][k] + c[i],
                        dp[i + 1][j + a[i]][k + b[i]]);
            }
        }
    }

    int ans = INF;
    for (int i = 1; i < abNMax; i++)
    {
        for (int j = 1; j < abNMax; j++)
        {
            if (i * Mb == j * Ma) ans = min(ans, dp[N][i][j]);
        }
    }

    if (ans == INF) printf("%d\n", -1);
    else printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 25856
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

//comb(fac, ifac, MOD, n, k)でnCk
ll comb(ll fac[], ll ifac[], ll m, int n, int k){
    ll c = fac[n];
    c *= ifac[n-k], c %= m;
    c *= ifac[k], c %= m;
    return c;
}

//perm(fac, ifac, MOD, n, k)でnPk
ll perm(ll fac[], ll ifac[], ll m, int n, int k){
    return(fac[n]*ifac[n-k])%m;
}

int main(){
    ll r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    //1〜nまでのmod(m)における逆元
    ll n = 3e6, m = MOD, inv[n+1];
    rep2(i, 1, n){
        inv[i] = 1;
        ll now = i, k = m-2;
        while(k > 0){
            if(k%2 == 1) inv[i] *= now, inv[i] %= m;
            now *= now, now %= m;
            k /= 2;
        }
    }
    //i!とi!の逆元
    ll fac[n+1], ifac[n+1];
    fac[0] = 1, ifac[0] = 1;
    rep2(i, 1, n){
        fac[i] = (fac[i-1]*i) % m;
        ifac[i] = (ifac[i-1]*inv[i]) % m;
    }
    ll ans = 0;
    ans += comb(fac, ifac, m, r2+c2+2, c2+1);
    ans += MOD-comb(fac, ifac, m, c2+r1+1, r1);
    ans += MOD-comb(fac, ifac, m, r2+c1+1, c1);
    ans += comb(fac, ifac, m, r1+c1, r1);
    cout << ans%MOD << endl;
}

Measured memory_bytes: 70528
#include <iostream>

using namespace std;

int main() {
    int N, q;
    
    cin >> N;
    int S[N];
    for(int i = 0; i < N; ++i){
        cin >> S[i];
    }
    
    cin >> q;
    int T[q];
    for(int i = 0; i < q; ++i){
        cin >> T[i];
    }
    
    int n = 0;
    
    for(int i = 0; i < q; ++i){
        for(int j = 0; j < N; ++j){
            if(T[i] == S[j]){
                n++;
                break;
            }
        }
    }
    
    cout << n << endl;
    
    return 0;
}

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

int main(){
  	int N, A, B;
  	cin >> N >> A >> B;
  	long long res=0;
  	for(int i=0;i<=N;i++){
      	int tmp=i, sum=0;
      	while(1){
          	sum+=tmp%10;
          	if(tmp/10 == 0) break;
          	else tmp/=10;
        }
      	if(A<=sum && sum<=B) res+=i;
    }
  	cout << res << endl;
}

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

struct stor{
  int a;
  int b;
};

int asc(const void *p, const void *q){
  struct stor *P = (struct stor*)p;
  struct stor *Q = (struct stor*)q;
  return P->a - Q->a;
}

int main(void){
  int n, m;
  scanf("%d %d", &n, &m);
  
  struct stor num[n];
  int i;
  
  for(i = 0; i < n; i++){
    scanf("%d %d", &num[i].a, &num[i].b);
  }
  
  qsort(num, n, sizeof(struct stor), asc);
  
  unsigned long sum = 0;
  for(i = 0; m > 0; i++){
    if(m < num[i].b){
      sum += (num[i].a * m);
    }
    else{
      sum += (num[i].a * num[i].b);
    }
    m -= num[i].b;
  }
  printf("%lu\n", sum);
  return 0;
}

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long N, long long D, long long X, std::vector<long long> A){
    int ans = 0;
    REP(i, N) {
        int count = 0;
        while (true) {
            if (A[i] * count + 1 <= D) count++;
            else break ;
        }
        ans += count;
    }
    cout << ans + X << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, D, X, std::move(A));
    return 0;
}


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

int main(){
  string S;
  cin >> S;

  set<char> c;

  for (int i = 0; i < S.size(); i++)
  {
    if (c.count(S.at(i))){
      cout << "no" << endl;
      return 0;
    }
    else{
      c.insert(S.at(i));
    }
  }
  cout << "yes" << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int ar[n+2],a1[n+2],a2[n+2],s;
    for(int i=1;i<=n;i++)
    {
        cin>>ar[i];
    }
    a1[0]=0;a2[n+1]=0;
    for(int i=1;i<=n;i++)
    {
        a1[i]=__gcd(a1[i-1],ar[i]);
    }
    for(int i=n;i>=1;i--)
    {
        a2[i]=__gcd(a2[i+1],ar[i]);
    }
    s=0;
    for(int i=1;i<=n;i++)
    {
       s=max(s,__gcd(a1[i-1],a2[i+1]));
    }
    cout<<s<<endl;
}


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

//https://atcoder.jp/contests/dp/tasks

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
    return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int h,w;
vector<string> G;

bool sealed(const int i,const int j){
    if(i<0 || j<0 || h<=i || w<=j || G[i][j] == '#') return true;
    return false;
}

int main(){
    cin >> h >> w;
    G.assign(h,"");
    rep(i,h) cin >> G[i];

    vector<vector<mint>> dp;
    dp.assign(h,vector<mint>(w,0));
    dp[0][0] = 1;

    rep(i,h)rep(j,w){
        if(sealed(i,j)) continue;
        if(!sealed(i,j+1)) dp[i][j+1] += dp[i][j];
        if(!sealed(i+1,j)) dp[i+1][j] += dp[i][j];
    }

    cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 12936
s = input()


if s == "SUN":
    print(7)
if s == "MON":
    print(6)
if s == "TUE":
    print(5)
if s == "WED":
    print(4)
if s == "THU":
    print(3)
if s == "FRI":
    print(2)
if s == "SAT":
    print(1)


Measured memory_bytes: 2940
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    string s;
    bool flag = false;
    cin >> s;
    rep(i, s.size()){
        if(s[i] != 'h' || s[i+1] != 'i'){
            cout << "No" << endl;
            return 0;
        }
        i++;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()

if s[0] == 'R' and s[1] == 'R' and s[2] == 'R':
    print(3)
elif (s[0] == 'R' and s[1] == 'R') or (s[1] == 'R' and s[2] == 'R'):
    print(2)
elif (s[0] == 'R' or s[1] == 'R' or s[2] == 'R'):
    print(1)
else:
    print(0)


Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define forn(i, n) for(int i = 0; i < int__(n); i++) 
#define sz(a) int__(a.size())
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
const int MAX = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=998244353;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int x,int y){return y!=0 ? gcd(y,x%y) : x;}
 
int__ main() {
	fast;
	int n; cin >> n;
	vi h(n);
	for(int i=0;i<n;i++) cin >> h[i];
	vi dp(n+3,1e12);
	dp[0] = 0;

	for(int i=0;i < n;i++) {
		dp[i+1] = min(dp[i+1], abs(h[i] - h[i+1]) + dp[i]);
		dp[i+2] = min(dp[i+2], abs(h[i] - h[i+2]) + dp[i]);
	}
	// watch(dp);
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 int main(){
   int n;
   cin >> n;
   vector<vector<int>> dat(n,vector<int>(3));
   for(int i=0;i<n;i++)
     cin >> dat.at(i).at(0) 
     >> dat.at(i).at(1) >> dat.at(i).at(2);
   vector<vector<int>> score(n,vector<int>(3,0));
   for(int i=0;i<3;i++)
     score.at(0).at(i)+=dat.at(0).at(i);
   for(int i=1;i<n;i++){
     score.at(i).at(0)=
       max(score.at(i-1).at(1),score.at(i-1).at(2))
       +dat.at(i).at(0);
     score.at(i).at(1)=
       max(score.at(i-1).at(0),score.at(i-1).at(2))
       +dat.at(i).at(1);
     score.at(i).at(2)=
       max(score.at(i-1).at(1),score.at(i-1).at(0))
       +dat.at(i).at(2);
   }
   cout << max(score.at(n-1).at(0),
               max(score.at(n-1).at(1),
               score.at(n-1).at(2)))
     << endl;
   /*for(int i=0;i<n;i++){
     for(int j=0;j<3;j++)
       cout << score.at(i).at(j) << ' ';
     cout << endl;
   }*/
 }

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

int main(){
	int A,B;
  	cin >> A >> B;
  	int cnt = 0;
  	string S;
  	for(int i = A; i<= B; i++){
		S = to_string(i);
    	if(S[0] == S[4] && S[1] == S[3]){

          	cnt++; 
        }
    }
  	cout << cnt << endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        vector<char> a(8);
        rep(i, 8) cin >> a[i];

        sort(ALL(a));
        string minv = "";
        rep(i, 8) minv += a[i];

        sort(ALL(a), greater<char>());
        string maxv = "";
        rep(i, 8) maxv += a[i];

        OP(stoi(maxv) - stoi(minv));
    }

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    string S[N];
    for(int i = 0; i<N; i++) {
        cin >> S[i];
    }
    map<string,int> chk;
    for(int i = 0; i<N; i++) {
        chk[S[i]]++;
    }
    int res = 0;
    for(auto a : chk) {
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 25376
A, B, C = map(int, input().split())
i = 1
rec = []
while True:
  hoge = (A * i - C) % B
  if hoge == 0:
    print('YES')
    exit()
  i += 1
  if hoge in rec:
    print('NO')
    exit()
  else:
    rec.append(hoge)

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

using namespace std;

const int mod=1e9+7;

void add_self(int &a,int b){
	
	a=(a+b)%mod;
}

int main(){
	
	int n,m;
	scanf("%d%d",&n,&m);
	char arr[n][m];
	vector<vector<int> > dp(n,vector<int>(m));
	for(int i=0;i<n;i++){
		
		for(int j=0;j<m;j++){
			
			cin>>arr[i][j];
		}
	}
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		
		for(int j=0;j<m;j++){
			
			if(arr[i][j]=='#'){
				dp[i][j]=0;
			}
			else{
				if(j>0)
					add_self(dp[i][j],dp[i][j-1]);
				if(i>0)
					add_self(dp[i][j],dp[i-1][j]);
			}
			
		}
		
	}
	printf("%d",dp[n-1][m-1]);
	
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll a, p;
  cin >> a >> p;
  cout << (a*3+p) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

ll cnt[101010];
pair<ll,int> P[101010];

int main(){
  int N; cin>>N;
  map<ll,int> mp;
  rep(i,N){
    ll a; cin>>a;
    P[i]=make_pair(a,-(i+1));
    mp[a]++;
  }
  sort(P,P+N);
  reverse(P,P+N);
  P[N]=make_pair(0,-N);
  int ind=0;
  ll sum=0;
  while(ind<N){
    ll f=P[ind].first;int s=-P[ind].second;
    sum+=mp[f];
    int next=min(N,ind+mp[f]);
    ll f2=P[next].first;int s2=-P[next].second;
    cnt[s]+=max(1LL,f-f2)*sum;
    if(s<s2) P[next]=make_pair(f2,-s);
    ind=next;
  }
  for(int i=1;i<=N;i++) cout<<cnt[i]<<endl;
  return 0;
}


Measured memory_bytes: 9728
use std::io;
use std::collections::VecDeque;


/// https://beta.atcoder.jp/contests/arc077/tasks/arc077_a
fn main() {
    let n = read_one::<usize>();
    let an = read::<isize>();
    let mut v = VecDeque::new();
    for i in 0..n {
        if i % 2 == 0 { v.push_back(an[i]); }
        else { v.push_front(an[i]); }
    }

    let mut v = v.into_iter().map(|x| x.to_string()).collect::<Vec<_>>(); 
    if n % 2 != 0 {
        v.reverse();
        println!("{}", v.join(" "));
    } else {
        println!("{}", v.join(" "));
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 17644
#include <stdio.h>

int V[1000000],dx[4]={-1,0,1,0},dy[4]={0,-1,0,1},head=0,tail=0;

struct P{
  int f[9];
  int space;
  int path;
};

struct P Q[1000000];

void enqueue(struct P a){
  int next=(tail+1)%1000000;
  Q[tail]=a;
  tail=next;
}

struct P dequeue(){
  struct P b;
  b=Q[head];
  head=(head+1)%1000000;
  return b;
}

int sort(struct P p){
  int i,j,k,cnt,a=0;
  for(i=0,k=1;i<9;k*=++i){
    for(j=0,cnt=0;j<i;j++){
      if(p.f[j]<p.f[i]){
	cnt++;
      }
    }
    a+=cnt*k;
  }
  return a;
}

int isTarget(struct P p){
  int i;
  for(i=0;i<9;i++){
    if(p.f[i]!=i+1){
      return 0;
    }
  }
  return 1;
}

int bfs(struct P s){
  int r,a,sx,sy,tx,ty;
  struct P u,v;
  s.path=0;
  enqueue(s);
  V[sort(s)]=1;
  while(head!=tail){
    u=dequeue();
    if(isTarget(u)==1){
      return u.path;
    }
    sx=u.space/3;
    sy=u.space%3;
    for(r=0;r<4;r++){
      tx=sx+dx[r];
      ty=sy+dy[r];
      if(tx<0||ty<0||tx>=3||ty>=3){
	continue;
      }
      v=u;
      a=v.f[u.space];
      v.f[u.space]=v.f[tx*3+ty];
      v.f[tx*3+ty]=a;
      v.space=tx*3+ty;
      if(V[sort(v)]!=1){
	V[sort(v)]=1;
	v.path++;
	enqueue(v);
      }
    }
  }
  return -1;
}

int main(){
  int i;
  struct P in;
  for(i=0;i<9;i++){
    scanf("%d",&in.f[i]);
    if(in.f[i]==0){
      in.f[i]=9;
      in.space=i;
    }
  }
  printf("%d\n",bfs(in));
  return 0;
}


Measured memory_bytes: 10956
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;

int main() {
  LL n, k, x, ans = 2000000001;

  cin >> n >> k;
  vector<LL> v, deff;
  rep(i, n) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());

  rep(i, n - k + 1) {
    LL h_min = v[i];
    LL h_max = v[i + k - 1];
    LL diff = h_max - h_min;
    ans = min(diff, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400