akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>

using namespace std;


// TODO

long long solve(string &s);

long long solve(string &s){
    int N = s.size();

  long long ans = 0;
  long long  count_lt = 0, count_gt = 0;

  int i = 0;
  
  while(i < N && s[i] == '>'){
    count_gt++;
      i++;
  }
  ans += (count_gt + 1) * count_gt  / 2;
  count_gt = 0;
  
  while(i < N){
    while(i< N && s[i] == '<'){
      count_lt++;
      i++;
    }
    while(i< N && s[i] == '>'){
    count_gt++;
    i++;
    }
    long long  mx = max(count_lt, count_gt);
    long long  mn = min(count_lt, count_gt);

    ans += (mx + 1) * mx / 2;
    ans += (mn - 1) * mn / 2;
    
    count_lt = 0;
    count_gt = 0;
  }
  return ans;
}

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

  
  cout << solve(s) << endl;
  
  return 0;
}


Measured memory_bytes: 900
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
#include<queue>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    double a,b;
    double h,m;
    cin>>a>>b>>h>>m;
    double akakudo,bkakudo;
    bkakudo=m*6.0;
    akakudo=h*30.0+m*0.5;
    double sita=min(abs(akakudo-bkakudo),abs(360-abs(akakudo-bkakudo)));

    double ans=a*a+b*b-2*a*b*cos(sita/180*3.1415926535);
    cout<<fixed<<setprecision(20)<<pow(ans,0.5)<<endl;
}


Measured memory_bytes: 4356
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
  ll x1,y1,x2,y2,x3,y3,x4,y4;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << x2-(y2-y1) <<" "<< y2+(x2-x1) <<" "<< x2-(y2-y1)-(y2+(x2-x1)-y2) <<" "<< y2+(x2-x1)+(x2-(y2-y1)-x2) << endl;
}

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

typedef long long ll;

#define N 100000001

int table[N];

void prim(){
    table[0]=table[1]=1;
    for(int i=2;i*i<N;i++){
        for(int j=2*i;j<N;j+=i){
            table[j]=1;
        }
    }
}

bool chepri(int n){
    if(n<2)return false;
    if(n==2)return true;
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int cou=0,a;
//    prim();
//    for(int i=0;i<n;i++){
//        cin >> a;
//        if(!table[a])cou++;
//    }
//    cout << cou << endl;

    for(int i=0;i<n;i++){
        cin >> a;
        if(chepri(a))cou++;
    }
    cout << cou << endl;
}



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

using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int H,W;
  cin>>H>>W;
  int a[H][W];
  int b[H][W];
  for(int i = 0;i<H;i++){
    for(int k = 0;k<W;k++){
      cin>>a[i][k];
    }
  }
  for(int i = 0;i<H;i++){
    for(int k = 0;k<W;k++){
      cin>>b[i][k];
    }
  }
  bool dp[H][W][30000];
  for(int i = 0;i<H;i++){
    for(int k = 0;k<W;k++){
      for(int m = 0;m<30000;m++){
        dp[i][k][m] = 0;
      }
    }
  }
  dp[0][0][abs(a[0][0]-b[0][0])] = 1;
  for(int i = 0;i<H;i++){
    for(int k = 0;k<W;k++){
      for(int m = 0;m<30000;m++){
        if(i != 0){
          if(dp[i-1][k][m] == 1){
            int temp1 = m + abs(a[i][k]-b[i][k]);
            int temp2 = abs(m-abs(a[i][k]-b[i][k]));
            dp[i][k][temp1] = 1;
            dp[i][k][temp2] = 1;
          }
        }
        if(k != 0){
          if(dp[i][k-1][m] == 1){
            int temp1 = m + abs(a[i][k]-b[i][k]);
            int temp2 = abs(m-abs(a[i][k]-b[i][k]));
            dp[i][k][temp1] = 1;
            dp[i][k][temp2] = 1;
          }
        }
      }
    }
  }
  for(int i = 0;i<30000;i++){
    if(dp[H-1][W-1][i] == 1){
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 187776
if __name__ == '__main__':
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [float('inf') for _ in range(10**5 + 1000)]

    dp[0] = 0
    for i in range(n):
        for j in range(1, k + 1):
            if i + j < len(h):
                dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])

    print(dp[n - 1])


Measured memory_bytes: 57056
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			a[i] = sc.next().toCharArray();
		}
		
		boolean[] rmRow = new boolean[h];
		boolean[] rmClm = new boolean[w];
		
		outer:
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i][j] == '#') continue outer; 
			}
			rmRow[i] = true;
		}
		
		outer:
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < h; j++) {
				if (a[j][i] == '#') continue outer; 
			}
			rmClm[i] = true;
		}
		
		for (int i = 0; i < h; i++) {
			if (rmRow[i]) continue;
			for (int j = 0; j < w; j++) {
				if (rmClm[j]) continue;
				System.out.print(a[i][j]);
			}
			System.out.println();
		}
		
		sc.close();
	}
}




Measured memory_bytes: 31868
#include <iostream>
#include <cstring>
using namespace std;
int main(void){
    // Your code here!
    while(1)
    {
        string word,t;
        cin>>word;
        if(word=="-")break;
        t=word+word;
        int k;//k回入力
        cin>>k;
        int p{};//p回分シャッフルする
        for(int i=0;i<k;i++)
        {
            int q;
            cin>>q;
            p+=q;
        }
        int u{};
        u=p%word.size();
        for(int x=0;x<word.size();x++)
        {
             cout<<t[x+u];
           
        }
        cout<<endl;
    }
    return 0;
}



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

int main(){
    int n;
    scanf("%d",&n);

    ll sum=0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                int ans=__gcd(i,j);
                int fans=__gcd(ans,k);
                sum+=fans;
            }
        }
    }
    printf("%lld\n",sum);

    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
int x[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int K;
    cin >> K;
    cout << x[K-1] <<endl;
    
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, m: usize,
        xyz: [[i64; 3]; n],
    }

    let mut vals = vec![vec![0; n]; 8];
    for i in 0..n {
        for bits in 0..1<<3 {
            let mut sum = 0;
            for j in 0..3 {
                let sign = 1 - 2*((bits>>j) & 1);
                sum += xyz[i][j] * sign;
            }
            vals[bits as usize][i] = sum;
        }
    }

    let mut ans = -1i64<<60;
    for vec in &mut vals {
        vec.sort();
        vec.reverse();
        ans = max(ans, vec.iter().take(m).sum::<i64>());
    }
    println!("{}", ans);
}


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

int main() {
    int h, w;
    while (true) {
        cin >> h >> w;
        if (h == 0 && w == 0) {
            break;
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 100005, P = 1000000007;

int n, x[N], inv[N], f[N];

int main() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(x[i]);
	}
	inv[1] = 1;
	for (int i = 2; i <= n; ++i) {
		inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
	}
	int fac = 1;
	f[0] = 0;
	for (int i = 1; i < n; ++i) {
		f[i] = (f[i - 1] + inv[i]) % P;
		fac = 1ll * fac * i % P;
	}
	int ans = 0;
	for (int i = 2; i <= n; ++i) {
		ans = (ans + 1ll * (x[i] - x[i - 1]) * f[i - 1]) % P;
	}
	print(1ll * ans * fac % P);
}


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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N, M, Q;
int dp[101010][20]; //dp[v][d]:=頂点vからdまでの距離を色dp[i][d]で塗った。
vec G[101010];

void rec(int v, int d, int c) {
  if (d < 0) return;
  if (dp[v][d] != 0) return;

  for (int i = d; i >= 0; i--) {
    if (dp[v][i] != 0) break;
    dp[v][i] = c;
  }

  for (auto x : G[v]) {
    if (dp[x][d - 1] != 0) continue;
    rec(x, d - 1, c);
  }
  return;
}

signed main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].pb(b);
    G[b].pb(a);
  }

  cin >> Q;
  vec q[101010];
  for (int i = Q - 1; i >= 0; i--) {
    int v, d, c;
    cin >> v >> d >> c;
    v--;
    q[i] = {v, d, c};
  }

  for (int i = 0; i < Q; i++) {
    rec(q[i][0], q[i][1], q[i][2]);
  }

  for (int i = 0; i < N; i++) {
    cout << dp[i][0] << endl;
  }

  return 0;
}


Measured memory_bytes: 28020
import math
p = 10**9 + 7

def h(n,r) :
    s = n+r-1
    x = (math.factorial(s) // ( math.factorial(r) * math.factorial(s-r) )) % p
    return x

S = int(input())
ans = 0
n = S // 3

for i in range(1,n+1) :
    a = S - 3*i
    ans += h(i,a) 
    ans = ans % p

print(ans)
    
    

Measured memory_bytes: 9016
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

const int maxN = 2e5 + 5, INF = 1e9 + 5;

vector<int> dp(maxN, INF), a(maxN);

int rc(int in) {
    if(dp[in] != INF) return dp[in];
    if(in == 0) {
        return dp[0] = 0;
    }
    if(in == 1) {
        return dp[1] = abs(a[1] - a[0]);
    }
    return dp[in] = min(rc(in - 1) + abs(a[in] - a[in - 1]), rc(in - 2) + abs(a[in] - a[in - 2]));
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    cout << rc(n - 1);
    return 0;
}


Measured memory_bytes: 7200
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <array>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    
    int a[n];
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }

    int cnt = 0;
    for(int i=0; i<n; i++) {
        
//        cout << a[i] << " : ";
        
        int numOfDivisor = 0;
        
        if( a[i] == 1 || (a[i] != 2 &&a[i]%2 == 0) ) { //1????????????2??\????????¶??°?????????
//            cout << "even\n";
            continue;
        }
        
        for(int j=3; j<=sqrt(a[i]); j+=2) {
            if( a[i]%j == 0 ) {
                numOfDivisor++;
//                cout << j << " ";
            }
        }
        
        
        if( numOfDivisor == 0) {
            cnt++;
            
//            cout << "***";
        }
        
//        cout << endl;
        
    }
    
    cout << cnt << endl;

    
    return 0;
}

Measured memory_bytes: 3072
L,A,B,M=map(x->parse(Int,x),split(readline()))
ans=0
function f(a,b,c,d,u,s)
	X,Y=ans,s
	if u>0
		X,Y=f(a*a%M,b*(a+1)%M,(b*d%M+c*(a+1)%M)%M,2*d%M,div(u,2),s)
	end
	if u%2==1
		X=(a*X%M+b*Y%M+B%M*c%M)%M
		Y=(Y+B%M*d%M)%M
	end
	X,Y
end
pre=0
g=1
for d=1:18
	l=pre-1
	r=L
	g*=10
	while r-l>1
		m=div(r+l,2)
		if A+B*m<g
			l=m
		else
			r=m
		end
	end
	ans,_=f(g%M,1,0,1,r-pre,(A%M+B%M*pre%M)%M)
	pre=r
end
println(ans)


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

int main()
{

ll n , k , mx=0;
cin >> n >> k ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
vector<ll> f(n);
rep(i, n){
  cin >> f[i];
}
sort(a.begin(),a.end()); 
sort(f.rbegin(),f.rend());
rep(i,n)mx=max(a[i]*f[i],mx);

auto judge = [&](ll val) {
  ll num=0;
  rep(i,n){
    if(a[i]*f[i]>val)num+=a[i]-val/f[i];
  }
  if(num>k)return false;
  else return true;
};
auto binarysearch = [&](ll lowerbound, ll upperbound) {
  if (!judge(lowerbound)) return -1LL;
  ll lower = lowerbound, upper = upperbound;
  while (1){
    if (judge((lower + upper) / 2)) lower = (lower + upper) / 2;
    else upper = (lower + upper) / 2;
    if (abs(upper - lower) <= 1){
      if (judge(upper)) return upper;
      else return lower;
    }
  }
};

cout << binarysearch(mx,0) << endl;
return 0;
}

Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main(void) {
	long long dp[4];
	for (int i = 0; i < 4; ++i) {
		cin >> dp[i];
	}

	for (int i = 0; i < 3; ++i) {
		dp[i+1] = min(dp[i+1],2*dp[i]); 
	}

	int N;
	cin >> N;
	long long res;
	res = (N/2)*dp[3];
	if (N%2 != 0) {
		res += dp[2];
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
S = input()
ans = 0
if S ==	'SUN':
    ans = 7
elif S == 'MON':
    ans = 6
elif S == 'TUE':
    ans = 5
elif S == 'WED':
    ans = 4
elif S == 'THU':
    ans = 3
elif S == 'FRI':
    ans = 2
else:
    ans = 1

print(ans)



Measured memory_bytes: 38300
import math

a, b = map(int,input().split())

if a%2==0:
    koho1=[(a*25)//2, ((a*25)//2) +12]
else:
    koho1=[int((a*12.5)+0.5), int((a*12.5)+11.5)]

koho2=[b*10, b*10+9]

if koho2[0]<=koho1[0] and koho1[0]<=koho2[1]:
    print(koho1[0])
elif koho1[0]<=koho2[0] and koho2[0]<=koho1[1]:
    print(koho2[0])
else:
    print(-1)

Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

ll f(ll low, ll high, ll val) {
    if (low >= high) {
        if(val)return 0;
        else if (low == high)return 10;
        return 1;
    }
    ll x = (val % (low * 10)) / low;
    ll y, l = low * 10, h = high / 10, z;
    if (x == 0) {
        z = low == 1 ? 9 : 10;
        return f(l, h, val) * z;
    } else {
        y = (x < 0 ? x + 10 : x - 10);
        if (x < y)swap(x, y);
        z = low == 1 ? 9 - x : 10 - x;
        ll res = 0;
        res += f(l, h, val + x*high - x*low)*z;
        z = 10 + y;
        if (low == 1)z -= 1;
        res += f(l, h, val + y*high - y*low)*z;
        return res;
    }
}

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

    ll N, ans = 0;
    cin >> N;

    for (ll i = 10; i <= (ll)1e18; i *= 10) {
        ans += f(1, i, N);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (1) {
		c = c - b;
		if (c < 1) {
			cout << "Yes" << endl;
			return 0;
		}
		a = a - d;
		if (a < 1) {
			cout << "No" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1E5+7;
ll arr[N];
const int MOD=998244353;
ll ksm(ll x, ll y){
	ll res=1;
	while(y){
		if(y&1) res=res*x%MOD;
		x=x*x%MOD;
		y>>=1;
	}
	return res%MOD;
}

int main(){
	ll n;
	cin>>n;
	ll summ=1;
	ll x;
	ll s=0;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(i==1&&x!=0) summ=0;
		arr[x]++;
		s=max(s,x);
	}
	for(int i=s;i>=0;i--){
		if(arr[i]==0) summ=0;
		if(i>1)	summ=summ*ksm(arr[i-1],arr[i])%MOD;
	}
	if(arr[0]>1) summ=0;
	printf("%lld\n",summ);
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

/**
 * Created by sonetsuyoshi on 2016/07/31.
 */
public class Main {

    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long count = 0;

        long[] a = new long[N];
        long[] b = new long[N];
        for(int i = 0 ; i < N; i++) {
            a[i] = sc.nextLong();
            b[i] = sc.nextLong();
        }

        for(int i = N - 1; i >= 0; i--) {
            long a1 = a[i] + count;
            long b1 = b[i];
            long c = (b1 - (a1 % b1)) % b1;
            count += c;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 51088
#include<stdio.h>

int main(){
	int A,B,C;
	int Resul;
	scanf("%d %d %d",&A,&B,&C);
	
	for(int x = 1;A*x<=C;x++)
	{
		if(A*x<=C){
			Resul+=B;
		}
	}
	
	printf("%d\n",Resul);
	return 0;
}

Measured memory_bytes: 128
def can_reach( S, start, end ):
    for i in range(start, end + 1):
        if S[i] == "#" and S[i+1] == "#":
            return False

    return True


N, A, B, C, D= map(int, input().split(" "))
S = "#" + input() + "#"


if can_reach(S, A, C) == False or can_reach(S, B, D) == False:
    print("No")
    exit()

if C > D:
    snuke_can_over = False
    for i in range(B, D+1):
        if S[i - 1] == '.' and S[i] == '.' and S[i + 1] == '.':
            snuke_can_over = True
            break


    if snuke_can_over is False:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 3636
from decimal import Decimal
from math import cos, radians, sin



class Point():
    def __init__(self, x, y):
        self.x = Decimal(x)
        self.y = Decimal(y)

    def output(self):
        print("{:.6f} {:.6f}".format(self.x, self.y))

    def calc_koch_apex(self, point):
        s_x = Decimal(2) / Decimal(3) * self.x + Decimal(1) / Decimal(3) * point.x
        s_y = Decimal(2) / Decimal(3) * self.y + Decimal(1) / Decimal(3) * point.y
        s = Point(s_x, s_y)

        t_x = Decimal(1) / Decimal(3) * self.x + Decimal(2) / Decimal(3) * point.x
        t_y = Decimal(1) / Decimal(3) * self.y + Decimal(2) / Decimal(3) * point.y
        t = Point(t_x, t_y)

        u_x = (t.x - s.x) * Decimal(cos(radians(60))) - \
              (t.y - s.y) * Decimal(sin(radians(60))) + s.x
        u_y = (t.x - s.x) * Decimal(sin(radians(60))) + \
              (t.y - s.y) * Decimal(cos(radians(60))) + s.y
        u = Point(u_x, u_y)

        return s, u, t


def kock(n, point1, point2):
    if n == 0:
        return


    s, u, t = point1.calc_koch_apex(point2)
    
    kock(n-1, point1, s)

    s.output()

    kock(n-1, s, u)

    u.output()

    kock(n-1, u, t)

    t.output()

    kock(n-1, t, point2)




n = int(input())

p1 = Point(0, 0)
p2 = Point(100, 0)


p1.output()

kock(n, p1, p2)

p2.output()



Measured memory_bytes: 6592
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
template <typename T> T max(T, T);
int gcd(int a, int b);

int main() {
    // source
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    s[k - 1] += 32;
    cout << s << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T max(T a, T b) {

    if (a > b) {
        return a;
    } else {
        return b;
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


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

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define ii pair <int,int>
#define ever (;;)

const int N = 100100;

int n,a[N],p[N];
set <int> s;
set <int> :: iterator it;
ll ans;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        p[a[i]] = i;
    }

    for(int i=n;i>=1;i--)
    {
        int pos = p[i];
        if( i == n )
        {
            s.insert(pos);
            continue;
        }

        int a1 = -1 , a2 = -1 , b1 = -1 , b2 = -1;

        it = s.upper_bound(pos);
        if( it != s.end() )
            a1 = *it;
        if( a1 != -1 )
        {
            it = s.upper_bound(a1);
            if( it != s.end() )
                a2 = *it;
        }

        it = s.lower_bound(pos);
        if( it != s.begin() )
        {
            it--;
            b1 = *it;
        }
        if( b1 != -1 )
        {
            it = s.lower_bound(b1);
            if( it != s.begin() )
            {
                it--;
                b2 = *it;
            }
        }

        if( b1 != -1 )
        {
            int len1 = b1 - b2;
            if( b2 == -1 )
                len1 = b1;
            int len2 = a1 - pos;
            if( a1 == -1 )
                len2 = n-pos+1;

            ans += 1LL * len1 * len2 * i;
        }
        if( a1 != -1 )
        {
            int len1 = a2 - a1;
            if( a2 == -1 )
                len1 = n-a1+1;
            int len2 = pos-b1;
            if( b1 == -1 )
                len2 = pos;

            ans += 1LL * len1 * len2 * i;
        }

        s.insert(pos);
    }

    printf("%lld\n",ans);
}


Measured memory_bytes: 5760
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
		while(true) {
			String x = sc.next();
			if(x.equals("0")) {
				break;
			}
			int sum = 0;
			for(int i = 0; i < x.length();i++) {
				sum += x.charAt(i) - '0';
			}
			System.out.println(sum);
		}
    }
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(a + b < c + d) {
    cout << "Right" << endl;
  }
  else if(a + b > c + d) {
    cout << "Left" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n; cin>>n;
	for(int j=0; j<n; j++){
		int y, m, d; cin>>y>>m>>d;
		int ans=0;
		for(int i=999; i>=y; i--){
			if(i%3==0) ans += 200;
			else ans += 195;
		}
		for(int i=1; i<m; i++){
			if(y%3==0 || i%2==1) ans -= 20;
			else ans -= 19;
		}
		ans -= d;
		cout << ans+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;

inline int read(){
	int sum=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
	return f*sum;
}

const int N=1000005;
struct node{int x,y;}p[N];
int n,H,W,ans=0;
int Y,a[N],b[N],que[N];

inline bool cmp(node a,node b){return a.x<b.x;}

inline void solve(int l,int r){
	if(l==r) return ;
	int mid=(l+r)>>1;
	for(int i=mid,y1=0,y2=H;i>=l;i--){
		a[i]=y1;b[i]=y2;
		if(p[i].y>=Y) y2=min(y2,p[i].y);
		if(p[i].y<=Y) y1=max(y1,p[i].y);
	}
	for(int i=mid+1,y1=0,y2=H;i<=r;i++){
		a[i]=y1;b[i]=y2;
		if(p[i].y>=Y) y2=min(y2,p[i].y);
		if(p[i].y<=Y) y1=max(y1,p[i].y);
	}
	for(int i=mid,j=i+1,h=1,t=0;i>=l;i--){
		while(j<=r&&a[j]<=a[i]){
			while(h<=t&&b[j]+p[j].x>=b[que[t]]+p[que[t]].x) t--;
			que[++t]=j++;
		}
		while(h<t&&min(b[i],b[que[h]])+p[que[h]].x<=min(b[i],b[que[h+1]])+p[que[h+1]].x) h++;
		ans=max(ans,(min(b[i],b[que[h]])-a[i]+p[que[h]].x-p[i].x)<<1);
	}
	for(int i=mid+1,j=i-1,h=1,t=0;i<=r;i++){
		while(j>=l&&a[j]<=a[i]){
			while(h<=t&&b[j]-p[j].x>=b[que[t]]-p[que[t]].x) t--;
			que[++t]=j--;
		}
		while(h<t&&min(b[i],b[que[h]])-p[que[h]].x<=min(b[i],b[que[h+1]])-p[que[h+1]].x) h++;
		ans=max(ans,(min(b[i],b[que[h]])-a[i]+p[i].x-p[que[h]].x)<<1);
	}
	solve(l,mid);solve(mid+1,r);
}

inline void work(){
	sort(p+1,p+n+1,cmp);
	Y=H>>1;
	p[n+1].x=W;p[0].x=0;
	p[n+1].y=p[0].y=Y;
	solve(0,n+1);
}

signed main(){
	W=read();H=read();n=read();ans=max(W+1,H+1)*2;
	for(int i=1;i<=n;i++) p[i].x=read(),p[i].y=read();
	work();
	swap(W,H);
	for(int i=1;i<=n;i++) swap(p[i].x,p[i].y);
	work();
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 15104
n, m = map(int,input().split())
pS = [input().split() for _ in range(m)]
correct = 0
flag = [False] * n
pena = [0] * n
sum = 0
for p, s in pS:
    p = int(p)
    if flag[p-1] == True:
        continue
    else:
        if s == "WA":
            pena[p-1] += 1
        elif s == "AC":
            sum += pena[p-1]
            correct += 1
            flag[p-1] = True
print(correct, sum)

Measured memory_bytes: 68824
#include<iostream>
#include<string>
using namespace std;
int main(){
	
	int n, a, b,ans1,ans2;
	cin >> n >> a >> b;
	ans1 = n*a;
	ans2 = b;
	if (ans1 <= ans2){ cout << ans1 << endl; }
	else{ cout << ans2 << endl; }

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=1e3+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=2e3+10;
	//------------------FIXED------------------
	int dp[N][N];
	void main()
	{
		int n=qread(),k=qread();dp[0][n+1]=1;
		fo(i,1,k-1)
		{
			int sum=dp[i-1][n+1];
			fd(j,n,2) dp[i][j]=(sum+((n-j+1)>(i-1))*dp[i-1][j])%MOD,add(sum,dp[i-1][j]);
		}int ans=0;fo(j,2,n+1) add(ans,dp[k-1][j]);fo(t,1,n-1-k) ans=ans*2%MOD;write(ans);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

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

using namespace std;

bool prime(int n){
    int i;
    for(i=2;i<n;i++){
        if(n%i==0){
            return false;
        }
    }
    for(i=2;i<(n+1)/2;i++){
        if((n+1)/2%i==0){
            return false;
        }
    }
    return true;
}
int main(){
    int j,q,ans;
    vector <int> v;
    cin >> q;
    int a[q],b[q];
    for(j=3;j<100000;j+=2){
        if(prime(j)){
            v.push_back(j);
        }
    }
    for(j=0;j<q;j++){
        cin >> a[j] >> b[j] ;
        ans = (upper_bound(v.begin(),v.end(),b[j]) - lower_bound(v.begin(),v.end(),a[j]));
        cout << ans << endl;
    }
}

Measured memory_bytes: 1408
package main

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

type entry struct {
	min int64
	max int64
}

func nextInt(s *bufio.Scanner) int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func solve(a []int64, n int) int64 {
	dp := make([][]entry, n)

	for i := 0; i < n; i++ {
		dp[i] = make([]entry, n-i)
		dp[i][0].min = -a[i]
		dp[i][0].max = a[i]
	}

	for j := 1; j < n; j++ {
		for i := 0; i < n-j; i++ {
			p := a[i] + dp[i+1][j-1].min
			q := dp[i][j-1].min + a[i+j]
			r := -a[i] + dp[i+1][j-1].max
			s := dp[i][j-1].max - a[i+j]

			dp[i][j].max = max(p, q)
			dp[i][j].min = min(r, s)
		}
	}

	return dp[0][n-1].max
}

func main() {
	s := bufio.NewScanner(bufio.NewReader(os.Stdin))
	s.Split(bufio.ScanWords)

	n := int(nextInt(s))
	a := make([]int64, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt(s)
	}

	fmt.Println(solve(a, n))
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 7;
vector <int> g[N];
int a[N], c[N];
int ptr = 1;
void dfs(int u, int p) {
    c[u] = a[ptr++];
    for (int v : g[u]) {
        if (v != p) {
            dfs(v, u);
        }   
    }   
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v); g[v].push_back(u);
    }   
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    int ans = 0;
    for (int i = 2; i <= n; ++i) ans += a[i];
    cout << ans << '\n';
    dfs(1, 1);
    for (int i = 1; i <= n; ++i) cout << c[i] << ' ';
    cout << '\n';
}   

Measured memory_bytes: 3584
#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.at(i);
	}
	sort(A.begin(), A.end());

	vector<int> dp(A.back()+1,0);
	for(int i=0; i<A.size(); i++){
		if(dp.at( A.at(i) ) > 0){
			dp.at( A.at(i) )++;
			continue;
		}
		int tmp = A.at(i);
		while( tmp < dp.size() ){
			dp.at( tmp )++;
			tmp += A.at(i);
		}
	}
	int ans=0;
	if(N==1){
		cout << 1 << endl;
		return 0;
	}
	for(int i=0; i < A.size(); i++){
		if( dp.at(A.at(i)) <= 1 ){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7920
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
public class Main 
{
    public static void main(String[] args) 
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(2, in, out);
        out.close();
    }

    static class TaskC 
    {
        static boolean prime(int n)
        {
            for(int i=2;i<=Math.sqrt(n);i++)
            {
                if(n%i==0)
                {
                    return false;
                }
            }
            return true;
        }

        static void reverse(long[] a,long start,long end)
        {
            long temp = 0;
            while(start<end)
            {
                temp = a[(int)start];
                a[(int)start] = a[(int)end];
                a[(int)end] = temp;
                start++;
                end--;
            }
        }


   
        
        public void solve(int testNumber, Scanner in, PrintWriter out) 
        {
           long n = in.nextLong();
           long[] a = new long[(int)n];
           int ans=0;
           for(int i=0;i<n;i++)
           {
            a[i] = in.nextLong();
           }

           long point = a[0];
           for(int i=1;i<n;i++)
           {
            if(a[i]>=point)
            {
                point = a[i];
                ans++;
            }
           }

           System.out.println(ans+1);
        }


      
        
        
        static long maxdiff(long[] arr,long size)
        {
            long max = arr[1]-arr[0];
            long min = arr[0];
            for(int i=1;i<(int)size;i++)
            {
                if(arr[i]-min>max)
                {
                    max = arr[i]-min;
                }
                if(arr[i]<min)
                {
                    min = arr[i];
                }

            }
            return max;
        }

                
    }

}

Measured memory_bytes: 21972
mod = 1000000007

N = int(input())
u = input()
d = input()

c = 1
t = 0

if u[t] == d[t]:
    t += 1
    c *= 3
    lh = 'l'
else:
    t += 2
    c *= 6
    lh = 'h'

while t < N:
    if u[t] == d[t]:
        t += 1
        if lh == 'l':
            c = (c * 2) % mod
        lh = 'l'
    else:
        t += 2
        if lh == 'l':
            c = (c * 2) % mod
        else:
            c = (c * 3) % mod
        lh = 'h'
print(c)


Measured memory_bytes: 3316
#制約が違うので価値をfor文にもっていく

n,w=map(int,input().split())
v=n*10**3
dp=[[100000000000] * (v+1) for i in range(n+1)]
#初期条件
dp[0][0]=0

W=[]
V=[]
for i in range(n):
    a,b=map(int,input().split())
    W+=[a]
    V+=[b]

#print(dp[0][0])
#print(W)
for i in range(n):
    #print(i)
    for sum_v in range(v+1):
        #print(sum_v)
        #重さが最小となるケース
        if sum_v>=V[i]:
            dp[i+1][sum_v]=min(dp[i][sum_v],dp[i][sum_v - V[i]] + W[i])
    
        #選ばない時
        else:
            dp[i+1][sum_v]=dp[i][sum_v]

#最適地の抽出
result=0
for i in range(v+1):
    if dp[n][i]<=w:
        result=i
#print(dp[n][:100])
print(result)

Measured memory_bytes: 120172
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int mod = 2019;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> t(n);
  rep(i,n) t[i] = s[n-1-i] - '0';
  
  int d = 1;
  vector<int> ds(n);
  rep(i,n) {
    ds[i] = (t[i]*d)%mod;
    d *= 10;
    d %= mod;
  }
  vector<int> sum(n+1);
  rep(i,n) sum[i+1] = (ds[i] + sum[i])%mod;

  vector<int> cnt(mod);
  rep(i,n+1) cnt[sum[i]]++;

  int ans = 0;
  rep(i,mod) ans += cnt[i]*(cnt[i]-1)/2;
  cout << ans << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int C = A / 500;
  for(int i = 0; i <= B; i++) {
    int D = 500 * C + i;
    if(A == D) {
      cout << "Yes" << endl;
      break;
    } else if (i == B) {
      cout << "No" << endl;
    }
  }

}


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

int main() {
    string s;cin>>s;
    int n = s.size();
    int ans = 0;
    rep(i,n-1)if(s[i+1]!=s[i])++ans;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3656
h,w,K=map(int,input().split())
mod=10**9+7
dp=[[0]*(w+1) for _ in range(h+1)]
dp[0][0]=1
for i in range(h):
    for j in range(w):
        for k in range(2**(w-1)):
            ok=True
            for l in range(w-2):
                if (k>>l)&1 and (k>>(l+1))&1:
                    ok=False
            if ok:
                if j>=1 and (k>>(j-1))&1:
                    dp[i+1][j-1]+=dp[i][j]
                    dp[i+1][j-1]%=mod
                elif j<=w-2 and (k>>j)&1:
                    dp[i+1][j+1]+=dp[i][j]
                    dp[i+1][j+1]%=mod
                else:
                    dp[i+1][j]+=dp[i][j]
                    dp[i+1][j]%=mod

print(dp[h][K-1])


Measured memory_bytes: 45420
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll a,b,x;
int32_t main(){
CODE_START;
cin >> a;
cin >> b;
cin >> x;
if(a==0){
    cout<<b/x+1;
}else {
cout<<b/x-(a-1)/x;
}
return 0;}


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

int dfs(long long x, int& n, bool has7, bool has5, bool has3) {
  if (x > n) return 0;
  return dfs(x * 10 + 7, n, true, has5, has3) +
         dfs(x * 10 + 5, n, has7, true, has3) +
         dfs(x * 10 + 3, n, has7, has5, true) + (has7 and has5 and has3);
}

int main() {
  int N;
  scanf("%d", &N);
  printf("%d", dfs(0LL, N, false, false, false));
  return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder output = new StringBuilder();

		int m ;
		int f ;
		int r ;
		String[] str ;//m,f,r???????????????????????????????????????str????????????????????????
		
		
		while(true) {
	 //??\???????????????????????????		
			 str = br.readLine().split(" ");
			 m = Integer.parseInt(str[0]);
			 f = Integer.parseInt(str[1]);
			 r = Integer.parseInt(str[2]);
	        if(m == -1 & f == -1 & r ==  -1)  break;
	        
	 //?????????????´¢?????????????????????       
	        if(m <= 50 | f <= 50 |r <= 100) {
	        	
		    	 if(m == -1 | f == -1) output.append("F\n");  //1????¨????????????????????????´???
		    	 
		    	 else if((m+f) >= 80) {         
		    		 output.append("A\n");
		    	 }
		    	 else if((m+f) >= 65) {
		    		 output.append("B\n");
		    	 }
		    	 else if((m+f) >= 50) {
		    		 output.append("C\n");
		    	 }
		    	 else if((m+f) >= 30 | r >= 50) {
		    		 if(r >= 50 ) {
		    			 output.append("C\n");
		    		 }else {
		    		     output.append("D\n");
		    		 }
		    	 }
		    	 else {
		    		 output.append("F\n");
		    	 }
		      }
	        
	     }

        System.out.print(output);

	br.close();
			
	}
}

Measured memory_bytes: 24152
#include<stdio.h>
int main(void)
{
	int x,a,b;
	scanf("%d %d %d",&x,&a,&b);
	if(x<a) a=a-x;
	else a=x-a;
	if(x<b) b=b-x;
	else b=x-b;
	if(a>b) printf("B\n");
	else printf("A\n");
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int main() {

	string s, p;
	int ii = 0, jj = 0;
	cin >> s;
	cin >> p;
	s += s;
	int cnt = 0;
	//cout << s << endl;
	for (int j = 0; j < s.length(); ++j) {
		if (s[j] == p[0]) {
			jj = j;
			cnt++;
			while (true) {
				if (cnt == p.length()) {
					cout << "Yes" << endl;
					return 0;
				}
				ii += 1;
				jj += 1;
				if (s[jj] != p[ii]) {
					break;
				}
				cnt++;
			}
		}
		ii = 0;
		jj = 0;
		cnt = 0;
	}
	cout << "No" << endl;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  unsigned long long a, b, c;
  string ans;
  cin >> a >> b >> c;
  if (a + b + 2 * sqrtl(a * b) < c) {
    ans = "Yes";
  } else {
    ans = "No";
  }
  cout << ans << endl;
}

signed main() {
  solve();

  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 rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin >> n;
    vector<ll> cnt(5);
    rep(i, n) {
        string s;
        cin >> s;
        if (s[0] == 'M') cnt[0]++;
        if (s[0] == 'A') cnt[1]++;
        if (s[0] == 'R') cnt[2]++;
        if (s[0] == 'C') cnt[3]++;
        if (s[0] == 'H') cnt[4]++;
    }

    ll ans = 0;
    rep(i, 5) rep(j, i) rep(k, j) {
        ans += cnt[i] * cnt[j] * cnt[k];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<(int)(r); i++)
#define rep_eq(i,l,r) for(int i=l; i<=(int)(r); i++)
#define all(vec) vec.begin(),vec.end()
#define allr(vec) vec.rbegin(),vec.rend()
using namespace std;

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

using ll=int64_t;

using vb=vector<bool>;
using vc=vector<char>;
using vs=vector<string>;
using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

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

  int N; cin >>N;
  vi A(N);
  rep(i,0,N) {cin >>A[i];}

  vi lmax(N);
  vi rmax(N);

  for (int i=1;i<N;i++) {
    lmax[i]=max(lmax[i-1],A[i-1]);
  }
  for (int i=N-2;-1<i;i-=1) {
    rmax[i]=max(rmax[i+1],A[i+1]);
  }

  rep(i,0,N) {
    cout <<max(lmax[i],rmax[i]) <<'\n';
  }

  return 0;
}


Measured memory_bytes: 5508