akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
using namespace std;
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; }
const int INF = 1e18;
void solve(int N,int M){
  int s,g1,g2;cin >> s >> g1 >> g2;
  s--,g1--,g2--;
  vector<vector<int>> dist(N,vector<int>(N,INF));
  for(int i=0;i<N;i++) dist[i][i] = 0;
  for(int i=0;i<M;i++){
    int a,b,c;cin >> a >> b >> c;
    a--;b--;
    dist[a][b]=c;
  }
  for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++){
    chmin(dist[i][j],dist[i][k]+dist[k][j]);
  }
  int ans = INF;
  for(int t=0;t<N;t++){
    chmin(ans,dist[s][t]+dist[t][g1]+dist[t][g2]);
  }
  cout << ans << endl;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(1){
    int N,M;cin >> N >> M;
    if(N==0) break;
    solve(N,M);
  }
  return 0;
}



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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int n;
    cin >> n;
    VI av(n);
    REP(i, n) cin >> av[i];
    SORT(av);
    VI hurui(1000001, 0);
    int ans = 0;
    REP(i, n) {
        if (hurui[av[i]] == 0) {
            if (av[i] != av[i+1]) ans += 1;
            REP(j, 1000000 / av[i]) {
                hurui[av[i] * (j + 1)] = 1;
            }
        }
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 7848
N, K = map(int,input().split())
h = list(map(int,input().split()))

dp = [0]*N

for i in range(N-1):
    if i >= K:
        x = dp[i]+abs(h[i+1]-h[i])
        for j in range(1,K):
            x = min(x,dp[i-j]+abs(h[i+1]-h[i-j]))
            
    else:
        x = dp[i]+abs(h[i+1]-h[i])
        for j in range(1,i+1):
            x = min(x,dp[i-j]+abs(h[i+1]-h[i-j]))
    
    dp[i+1] = x            



print(dp[-1])

Measured memory_bytes: 52448
#include<stdio.h>
#include<string.h>
typedef long long lnt;
lnt a[12],b[12],c[12];
char x[12];
int main(){
	lnt ans=0,p,q,s,t,i,tmp,k;
	scanf("%s",&x);
	a[0]=1;b[0]=1;
	for(int k=1;k<=11;k++){
		a[k]=a[k-1]*2;
		b[k]=b[k-1]*10;
	}
	s=strlen(x);
	c[1]=c[0]=1;
	for(k=2;k<=11;k++) c[k]=c[k-1]*2;
	for(k=0;k<s;k++){
		t=x[k]-'0';
		tmp=0;
		for(i=k;i<s;i++){
			tmp+=c[i-k]*b[s-i-1];
		}
		ans+=a[k]*t*tmp;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
N, M = map(int, input().split())
obs_list = list(map(int, input().split()))
ans = [0] * N

for i in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    if obs_list[a] <= obs_list[b]:
        ans[a] += 1
    if obs_list[b] <= obs_list[a]:
        ans[b] += 1

print(ans.count(0))

Measured memory_bytes: 20080
#include<stdio.h>
int main(){
	int a,b,c,d,k,n,q,x;
	scanf("%d%d",&n,&k);
	for(q=0;q<k;q++){
		scanf("%d%d",&a,&b);
		c=n-a+1;
		d=n-b+1;
		x=a;
		if(x>b)x=b;
		if(x>c)x=c;
		if(x>d)x=d;
		x=x%3;
		if(x==0)x=3;
		printf("%d\n",x);
	}
	return 0;
}


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

#define IOS cin.tie(0);ios::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)     for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?' ':'\n'); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
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 int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    SCIN(s);
    int ans=0;
    Rep(i,1,s.size()){
        if(s[i-1]!=s[i])ans++;
    }
    printf("%d\n",ans);

    return 0;
}


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

int main() {
  int x, n;
  cin >> x >> n;
  int t = 0, str = 100, k = 0, ans = 0;

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  for (int i = -102; i <= 220; i++) {
    t = 0;
    for (int j = 0; j < n; j++) {
      if (a.at(j) == i) {
        t = 1;
      }
      }
    if (t == 1) {
      continue;
    }
    k = i - x;
    if (k < 0) {
      k = -1 * k;
    }
    if (k < str) {
      str = k;
      ans = i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<math.h>
#define PI 3.141592653589793238

int main(){
  double x = 0, y = 0, nowdig = 90;
  int a, b;
  while(1){
    scanf("%d,%d", &a, &b);
    if(a == 0 && b == 0)break;
    x += (double)a * cos(nowdig * PI / 180); 
    y += (double)a * sin(nowdig * PI / 180);
    nowdig -=  b;
  }
  printf("%d\n%d\n", (int)x, (int)y);
  return 0;
}

Measured memory_bytes: 604
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};
use std::collections::*;
use maplit::*;
use num::Integer;
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF : usize = 1000000007;

#[fastout]
fn main() {
  input! {
    n : usize, m : usize,
  };
  input! {
    a : [usize; n],
  };
  
  let mut h = BinaryHeap::new();
  for x in &a {
    h.push(*x);
  }
  
  for _ in 0..m {
    let v = h.pop().unwrap();
    h.push(v / 2);
  }
  
  println!("{}", h.iter().sum::<usize>());
}

Measured memory_bytes: 4832
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define req(i,a,b) for(ll i=(a);i>=(b);--i)
#define name "a"
#define pb push_back
#define sz size()
#define ff first
#define ss second
#define xd '\n'
#define dc " "
#define Truong_Thanh_Minh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair < ll , ll > ii;
const ll maxn = 2e5+7, oo = 1e18, base = 311, mod = 1e9+7;
const double PI = 3.141592654;
ll t, n, a[maxn], s[maxn], res;
int main()
{
    Truong_Thanh_Minh
    //freopen(name".inp","r",stdin);
    //freopen(name".out","w",stdout);
    cin >> n;
    rep (i, 1, n)
    {
        cin >> a[i];
        s[i] = s[i-1] + a[i];
        s[i] %= mod;
    }
    rep (i, 1, n - 1)
    {
        res += a[i] * ((s[n] - s[i] + mod)%mod);
        res %= mod;
    }
    cout << res;
}


Measured memory_bytes: 6720
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push_back
#define ITR ::iterator


#define MOD 1000000009LL
#define EPS 1e-8



int main(){
	string s = "kogakubu10gokan", t;
	int n, q, y;
	cin >> n >> q;
	for(int i = 0; i < n; ++i){
		cin >> y >> t;
		if(y > q){ break; }
		s = t;
	}
	cout << s << endl;
}

Measured memory_bytes: 1208
@K=(<>!~$"+$',map$'&($t=1<<$_)&&($'|$t-1)^$t,1..29);map{($A,$B)=split;$i=0;$x[$i]+=($A|$_)<=$_&&$B,$i++for@K}<>;printf sort{$b<=>$a}@x

Measured memory_bytes: 17792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int selectionSort(int A[], int N) {
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		int minj = i;
		for (int j = i + 1; j < N; j++) {
			if (A[j] < A[minj]) {
				minj = j;
			}
		}
		swap(A[i], A[minj]);
		if (i != minj)
			cnt++;
	}
	return cnt;
}

int main() {
	int N; cin >> N;
	int A[100];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int cnt = selectionSort(A, N);
	for (int i = 0; i < N; i++) {
		cout << A[i];
		if (i != N - 1)cout << " ";
	}
	cout << endl;
	cout << cnt << endl;

	return 0;
}

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

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

    signed int a[n+1], b[n];
    for(int i=0; i<n+1; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        cin>>b[i];
    }

    signed long ans = 0;
    for(int i = 0; i<n; i++){
        int add = min(a[i], b[i]);
        a[i] -= add;
        b[i] -= add;
        ans += add;

        if(b[i] > 0){
            add = min(a[i+1], b[i]);
            a[i+1] -= add;
            b[i] -= add;
            ans += add;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#include <math.h>

long long mod = (long long)1e9+7;

long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long >A(N+5, 0);
  long long maxvalue = 0;
  for (long long i=0; i<N; i++){
    scanf("%lld",&A[i]);
    maxvalue = fmax(maxvalue, A[i]);
  }

  long long ans = 0;
  long long multiple = 1;

  int i=0;
  while(maxvalue>0){
    long long count = 0;
    for (long long j=0; j<N; j++){
      //if ((A[j] & 1) != 0){
      if ((A[j] % 2) == 1){
        count++;
      }
      A[j] /= 2;
    }
    maxvalue /= 2;
    //printf("count=%lld\n",count);
    long long aho = (count * (N-count)) % mod;
    ans += aho * multiple;
    ans %= mod;
    multiple *= 2;
    //multiple = modpow(2,i);
    multiple %= mod;
    //printf("ans=%lld\n",ans);
    i++;
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
string s[101];
int ii[101];
int jj[101];
int main(){
  int h,w;
  cin >> h >> w;
  rep(i,0,h - 1) cin >> s[i];
  rep(i,0,h - 1) rep(j,0,w - 1) if(s[i][j] == '#') ii[i] = jj[j] = 1;
  rep(i,0,h - 1) if(ii[i]){
    rep(j,0,w - 1) if(jj[j]){
      cout << s[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import deque
def main():
    n,m=map(int,input().split())
    graph=[[] for _ in range(n)]
    for i in range(m):
        a,b=map(int,input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    queue=deque([0])
    visited=[False]*n
    visited[0]=True
    ans=[0]*n
    while queue:
        node=queue.popleft()
        for xnode in graph[node]:
            if visited[xnode]:continue
            ans[xnode]=node+1
            visited[xnode]=True
            queue.append(xnode)
    print("Yes")
    for a in ans[1:]:
        print(a)


if __name__=='__main__':
    main()

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

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

class Octahedra{
	public:
		string color[8];
		void right(){
			string tmp[8];
			rep(i,8) tmp[i]=color[i];
			color[0]=tmp[4],color[1]=tmp[5],color[2]=tmp[1],color[3]=tmp[0];
			color[4]=tmp[7],color[5]=tmp[6],color[6]=tmp[2],color[7]=tmp[3];
		}
		void top(){
			string tmp[8];
			rep(i,8) tmp[i]=color[i];
			color[0]=tmp[4],color[1]=tmp[0],color[2]=tmp[3],color[3]=tmp[7];
			color[4]=tmp[5],color[5]=tmp[1],color[6]=tmp[2],color[7]=tmp[6];
		}
		void rotation(){
			rep(i,3) swap(color[i],color[i+1]);
			rep(i,3) swap(color[i+4],color[i+1+4]);
		}

		bool operator<(Octahedra a) const{
			rep(i,8) if(color[i]!=a.color[i]) return color[i]<a.color[i];
			return color[7]<a.color[7];
		}
};

set<Octahedra> s;

int main(void){
	while(1){
		string color[8];
		rep(i,8) cin >> color[i];
		if(cin.eof()) break;

		s.clear();
		sort(color,color+8);

		do{
			Octahedra in;
			rep(i,8) in.color[i]=color[i];

			bool check=true;
			rep(i,4){
				rep(j,4){
					rep(k,4){
						if(s.find(in)!=s.end()){
							check=false;
							i=4,j=4,k=4;
						}
						in.rotation();
					}
					in.right();
				}
				in.top();
			}

			if(check) s.insert(in);

		}while(next_permutation(color,color+8));
		cout << s.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1384
from collections import deque,Counter
from itertools import permutations,combinations,combinations_with_replacement

N = int(input())
rows = [input()[0] for _ in range(N)]

cnt = Counter(rows)

ans = 0
for k in combinations(["M","A","R","C","H"],3):
    ans += cnt[k[0]]*cnt[k[1]]*cnt[k[2]]

print(ans)


Measured memory_bytes: 4216
N, M = map(int, input().split())


i = max((N - 2), 0) * max((M - 2), 0)
s = max((M - 2), 0) if N == 1 else 0
v = max((N - 2), 0) if M == 1 else 0
c = 1 if N == 1 and M == 1 else 0


print(i+s+c+v)


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

int main() {
int W, H, x, y, r;
cin >> W >> H >> x >> y >> r;
if(x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}


Measured memory_bytes: 3104
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}

static const ULLONG UL_HUGE_DIVIDER = 1000000007LLU;
static const LLONG LL_HUGE_DIVIDER = 1000000007LL;

//static void ABC111D_RobotArms();
static void ABC113B_Palace();

#if 1
int main()
{
	//ABC111D_RobotArms();
	ABC113B_Palace();
	fflush(stdout);
	return 0;
}
#endif

static void ABC113B_Palace()
{
	int N, T, A;
	scanf(" %d %d %d", &N, &T, &A);

	double diffMin = 100000.0;
	int diffMinIdx = -1;
	auto ht = new int[N];
	for (int i = 0; i < N; i++) {
		scanf(" %d", &ht[i]);
		double tmpDiff = tp_abs<double>((double)A - ((double)T - ((double)ht[i] * 0.006)));
		if (diffMin > tmpDiff) {
			diffMinIdx = i + 1;
			diffMin = tmpDiff;
		}
	}
	printf("%d\n", diffMinIdx);
	delete[] ht;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}


ll n;

ll func(ll num, ll add, bool seven, bool five, bool three){
	num = num*10 + add;
	
	if(num > n){
		return 0;
	}
	
	
	int ret;
	if(seven&&five&&three) ret = 1;
	else ret = 0;
	
	ret += func(num, 7, true, five, three);
	ret += func(num, 5, seven, true, three);
	ret += func(num, 3, seven, five, true);
	return ret;
}

int main(){	
	cin >> n;
	
	ll ans = func(0,0,false,false,false);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3644
# Here your code !
h, w = gets.chomp.split.map &:to_i
n = gets.chomp.to_i
a = gets.chomp.split.map &:to_i
ans = Array.new(h){Array.new(w,0)}
f = 0
y = x = 0
table = []
a.each.with_index(1) do |d, i|
  d.times{table.push(i)} 
end
i = 0
while true
  break if(i == table.size)
  if(x >= w)
    x = w - 1
    f = 1
  elsif(y >= h)
    y = h - 1
    f = 2
  elsif(x < 0)
    x = 0
    f = 3
  elsif(y < 0)
    y = 0
    f = 0
  elsif(ans[y][x] != 0)
    case f
    when 0 then
      x -= 1
    when 1 then
      y -= 1
    when 2 then
      x += 1
    when 3 then
      y += 1
    end
    f += 1
    f %= 4
  else
    if(ans[y][x] == 0)
      ans[y][x] = table[i] 
      i += 1
    end
  end
  case f
  when 0 then
    x += 1
  when 1 then
    y += 1
  when 2 then
    x -= 1
  when 3 then
    y -= 1
  end
end
ans.each{|aa|puts aa.join(" ")}

Measured memory_bytes: 3836
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007


int main(){
	char str[110];
	scanf("%s", str);
	int len = strlen(str);
	int final = len-1, first = 0, count = 0;
	while(final-first>0){
		if(str[first] != str[final]){
			count++;
		}
		first++;
		final--;
	}
	
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

signed main()
{
	int N; cin >> N;
	vector<int> a(N), b(N);

	long long sa = 0, sb = 0;

	for (int i = 0; i < N; ++i) cin >> a[i], sa += a[i];
	for (int i = 0; i < N; ++i) cin >> b[i], sb += b[i];

	if (sb - sa < 0) {
		cout << "No" << endl;
		return 0;
	}

	long long sousa = sb - sa, counter = 0;
	
	for (int i = 0; i < N; ++i) {
		if (a[i] < b[i]) {
			counter += (b[i] - a[i] + 1) / 2;
		}
	}

	if (counter <= sousa) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main(){
    ll N,M,K;
    cin>>N>>M>>K;
    vector<ll> A(N),B(M);
    rep(i,N) cin>>A[i];
    rep(i,M) cin>>B[i];
    vector<ll> v(N),w(M);
    rep(i,N){
        if(i==0) v[i]=A[i];
        else v[i] = v[i-1]+A[i];
    }
    rep(i,M){
        if(i==0) w[i]=B[i];
        else w[i] = w[i-1] + B[i];
    }
    int ans = 0LL;
    auto it = upper_bound(w.begin(),w.end(),K);
    chmax(ans,(int)(it-w.begin()));
    rep(i,N){
        if(K<v[i]) break;
        auto ite = upper_bound(w.begin(),w.end(),K-v[i]);
        int t = ite - w.begin();
        chmax(ans,i+t+1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9504
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;
struct UnionFind{
    vector<int> par,sizes;
    UnionFind(int n):par(n+1),sizes(n+1,1){
        rep2(i,1,n)par[i]=i;
    }
    int find(int x){
        return (x==par[x]?x:par[x]=find(par[x]));
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return ;
        if(sizes[x]<sizes[y]){
            swap(x,y);
        }
        par[y]=x;
        sizes[x]+=sizes[y];
    }
    bool same(int x,int y) {return (find(x)==find(y));}
    int size(int x) {return sizes[find(x)];}
};
int solve_min(vector<pii> G,int n){
    UnionFind uf(n);
    for(auto e:G){
        uf.unite(e.first,e.second);
    }
    int cnt=0;
    rep2(i,1,n){
        if(uf.par[i]==i)cnt++;
    }
    return cnt-1;
}

main(){
    int n,m;
    cin>>n>>m;
    vector<pair<pii,ll>> v;
    rep(i,m){
        int a,b,c;cin>>a>>b>>c;
        v.pb({{a,b},c});
    }
    sort(all(v),[](pair<pii,ll> x,pair<pii,ll> y){
        return x.first.second<y.first.second;
    });
    vector<pair<int,ll>> dp;
    dp.pb({1,0});
    int pre=0;
    int now=0;
    for(auto p:v){
        int l=p.first.first,r=p.first.second;
        ll c=p.second;
        int t=(lower_bound(all(dp),pair<int,ll>{l,0})-dp.begin());
        if(t>now)continue;
        ll tmp=dp[t].second+c;
        while(dp[now].second>tmp){
            now--;
            dp.erase(dp.end());
        }
        // for(auto p:dp){
        //     cout<<p.first<<" "<<p.second<<endl;
        // }
        // cout<<endl;
        if(dp[now].first<r){
            dp.pb({r,tmp});
            now++;
        }
    }
    if(dp[now].first==n){
        cout<<dp[now].second;
    }
    else cout<<-1;
}


Measured memory_bytes: 4848
function main() {
	input = input[0].split(' ');
	a = parseInt(input[0]);
	b = parseInt(input[1]);
	c = parseInt(input[2]);

	array = [a, b, c];
	array.sort();
	msg = array[0] + ' ' + array[1] + ' ' + array[2];
	console.log(msg);
}

var input = "";

process.stdin.resume();
process.stdin.setEncoding("utf-8");
process.stdin.on("data", function(chunk) {
	input += chunk;
});

process.stdin.on("end", function() {
	input = input.split("\n");
	main();
})

Measured memory_bytes: 15672
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
chance = sum(b)-sum(a)
for i in range(n):
    if a[i]<b[i]:
        chance -= (b[i]-a[i]+1)//2

if chance < 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 40432
use proconio::input;
use std::cmp::*;

fn main() {
    input! {
        n: usize,
        a: [i64;n]
    }

    let mut ai: Vec<(i64, i64)> = a.iter().enumerate().map(|(i, &a)| (a, i as i64)).collect();
    //    let mut ai: Vec<(i64, i64)> = a.iter().enumerate().map(|(i, &a)| (a, i as i64)).collect();
    ai.sort();
    ai.reverse();
    // 降順に並んだ。
    // println!("{:?}", ai);
    //for (a, i) in &ai {
    //    println!("{},{}", a, i);
    //}
    let minimum = 0;
    let mut dp = vec![vec![minimum; n + 1]; n + 1];
    dp[0][0] = 0;

    for (i, &(a, j)) in ai.iter().enumerate() {
        for l in 0..i + 1 {
            let r = i - l;
            dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + a * (j - (l as i64)));
            dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + a * ((n - 1 - r) as i64 - j));
        }
    }
    let mut ans = 0;
    for l in 0..n {
        let r = n - l;
        ans = max(dp[l][r], ans);
    }
    println!("{}", ans);
    //   println!(        "{}",        dp.iter().map(|d| d.iter().max().unwrap()).max().unwrap());
}


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

					using namespace std;
					typedef long long ll;
					
					int main()
					{
						int n, m, s = 0;
						cin >> n >> m;
						for(int i = 0; i < m; i++)
						{
							int x;
							cin >> x;
							s += x;
						}
						if(n - s < 0)
							cout << -1;
						else cout << n - s;	
					}

Measured memory_bytes: 3624
def c_alternating_path(H, W, Grid):
    from itertools import product
    from collections import deque

    ans = 0
    is_visited = [[False] * W for _ in range(H)]
    for h, w in product(range(H), range(W)):
        if Grid[h][w] == '#' and not is_visited[h][w]:
            count_white, count_black = 0, 0
            q = deque([(h, w)])
            while q:
                row, col = q.popleft()
                if is_visited[row][col]:
                    continue

                is_visited[row][col] = True
                if Grid[row][col] == '#':
                    count_black += 1
                else:
                    count_white += 1

                for dr, dc in [(0, -1), (1, 0), (0, 1), (-1, 0)]:
                    nr, nc = row + dr, col + dc
                    if (0 <= nr < H and 0 <= nc < W
                        and Grid[row][col] != Grid[nr][nc]
                            and not is_visited[nr][nc]):
                        q.append((nr, nc))
            ans += count_black * count_white
    return ans

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(c_alternating_path(H, W, Grid))

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

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
using namespace std;
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

namespace prime {
    vector<bool> is_not_prime{1, 1, 0};

    void make_is_not_prime(int N) {
        int l = is_not_prime.size();
        if (l >= N + 1) {
            return;
        }
        is_not_prime.resize(N + 1);
        for (int i = 2; i <= N; i++) {
            if (!is_not_prime[i]) {
                for (int j = max(((l + i - 1) / i) * i, i + i); j <= N; j += i) {
                    is_not_prime[j] = 1;
                }
            }
        }
    }

    vector<ll> list(ll a, ll b) {
        //{a, b)
        a = max(2LL, a);
        set<ll> st;
        for (ll i = a; i < b; i++) {
            st.insert(i);
        }
        ll l = sqrt(b);
        make_is_not_prime(l);
        for (ll i = 2; i <= l; i++) {
            if (!is_not_prime[i]) {
                for (ll j = max(((a + i - 1) / i) * i, i + i); j < b; j += i) {
                    st.erase(j);
                }
            }
        }
        vector<ll> res;
        for (auto x:st) {
            res.push_back(x);
        }
        return res;
    }

    bool is_prime(ll N) {
        if (N == 2) return true;
        for (int i = 2, j = sqrt(N) + 1; i <= j; i++) {
            if (N % i == 0)return false;
        }
        return N >= 2;
    }

    vector<pair<ll, ll>> integer_factorization(ll N) {
        vector<pair<ll, ll>> res;
        if (is_prime(N)) {
            res.push_back(make_pair(N, 1));
            return res;
        }
        auto s = list(0, N / 2 + 1);
        for (ll p:s) {
            ll r = 0;
            for (int i = 0;; i++) {
                if (N % p == 0) {
                    N /= p;
                    r++;
                } else {
                    break;
                }
            }
            if (r) {
                res.push_back(make_pair(p, r));
                if (N == 1)break;
            }
        }
        return res;
    }
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    ll N;
    cin >> N;
    ll s[1000] = {};
    rrep(i, N) {
        for (auto x:prime::integer_factorization(i)) {
            s[x.first] += x.second;
        }
    }
    ll ans = 1;
    for (int i = 0; i < 1000; i++) {
        ans *= s[i] + 1;
        ans %= mod;
    }
    cout << ans << endl;
}

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

namespace ABC113_A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] line = ReadIntAr();
            Console.WriteLine(line[0] + (line[1]/2));
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}


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

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

int main(){
    int x;
    cin >> x;
    int ans = 0;
    rep(i,x)rep(j, x)rep(k,x){
        ans += gcd(i,gcd(j,k));
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int i,num[3];
  for(i=0; i<3; i++)
  {
   scanf("%d", &num[i]); 
  }
  if (num[0] == 7)
  {
    if(num[1] == 5 && num[2] == 5)
    {
      printf("YES");
    }
    else
    {
     printf("NO"); 
    }
  }
  else if(num[1] == 7)
  {
    if(num[0] == 5 && num[2] == 5)
    {
      printf("YES");
    }
    else
    {
     printf("NO"); 
    }
  }
  else if(num[2] == 7)
  {
    if(num[0] == 5 && num[1] == 5)
    {
      printf("YES");
    }
    else
    {
     printf("NO"); 
    }
  }
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
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 ll INF = 1LL << 60;
const int MOD = 1000000007;

int n, k;
ll h[100010];

ll dp[100010];

int main() {
    cin >> n >> k;
    rep(i, n) cin >> h[i];
    rep(i, 100010) dp[i] = INF;

    dp[0] = 0;
    for(int i = 1; i < n; i++) {
        for(int j = 1; j <= k; j++) {
            if(i - j >= 0) {
                chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            }
        }
    }

    cout << dp[n - 1] << endl;
    
    return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
from fractions import gcd
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
def gyaku(a):
    return pow(a,mod-2,mod)
if n==1:
    print(1)
else:
    gya=[0]*(n)
    g=A[0]
    l=A[0]
    gya[0]=gyaku(A[0])
    for i in range(n-1):
        g=gcd(l,A[i+1])
        l*=(A[i+1]//g)
        gya[i+1]=gyaku(A[i+1])
    ans=0
    for i in range(n):
        ans+=l*gya[i]
        ans%=mod
    print(ans)

Measured memory_bytes: 6200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++)cin >> A[i];

  set<int> values;
  for(int i=0;i<N;i++){
    values.insert(A[i]);
  }

  if(values.size()==N){
    cout << "YES" << endl;
  }
  else{
    cout << "NO"<< endl;
  }

  return 0;
}

Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	int n, m, a;
	while (cin >> n >> m >> a && n&&m&&a) {
		vector<pair<pair<int, int>,int>>data(m);
		for (int i = 0; i < m; ++i) 
			cin >> data[i].first.first >> data[i].first.second >> data[i].second;
		sort(data.begin(), data.end(),greater<pair<pair<int,int>,int>>());
		int cur = a;
		for (int i = 0; i < m; ++i) {
			if (data[i].first.second == cur) cur = data[i].second;
			else if (data[i].second == cur) cur = data[i].first.second;
		}
		cout << cur << endl;
	}
	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = 1e9;
const ll INFll = 1e18;
#define put(n) cout<<(n)<<endl
#define Cout(n) cout<<(n)
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define MP make_pair
#define pb(q) push_back(q)
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K,x;
    cin>>N>>K;
    vector<ll> minus,plus;
    FOR(i,0,N){
        cin>>x;
        if(x<0) minus.pb(x);
        else plus.pb(x);
    }

    reverse(all(minus));
    minus.insert(minus.begin(),0);
    plus.insert(plus.begin(),0);

    ll ans = INFll;

    FOR(i,0,minus.size()){
        if(0 <= K-i && K-i < plus.size()){
            ans = min(ans,-minus[i] + plus[K-i] + min(-minus[i],plus[K-i]));
        }
    }

    put(ans);

}

Measured memory_bytes: 1656
#include<stdio.h>
int main()
 {
     int a,b;
     scanf("%d %d", &a, &b);
     if(a==b)
        printf("%d", 2*a);
     else if(a>b)
        printf("%d", 2*a-1);
     else
        printf("%d", 2*b-1);
 
     return 0;
 }

Measured memory_bytes: 1704
S=input()
T=input()

lt=len(T)
ls=len(S)
if ls<lt:flg=0
else:
 for i in range(ls-lt,-1,-1):
  flg=1
  for j in range(i,i+lt):
    s=S[j]
    if s=='?' or s==T[j-i]: continue
    flg=0
    break
  if flg:break
if flg:
    print((S[0:i]+T+S[i+lt:ls]).replace('?','a'))
else:
    print('UNRESTORABLE')

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

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

	if(10 <= n) cout << r << endl;
	else cout << 100*(10-n)+r << endl;

	return 0;
}


Measured memory_bytes: 256
p = int(input())
b_list = [0 for _ in range(p-1)]
a_list = list(map(int,input().split()))
def frac(n):
    if a_list[n] == 1:
        t = 1
        for j in range(p-1):
            b_list[j] -= t
            t = (t*n)%p
if a_list[0] == 1:
    b_list[0] -= 1
for i in range(p-1):
    frac(i+1)
b_list.reverse()
print(a_list[0],end = ' ')
for j in b_list:
    print(j % p,end = ' ')


Measured memory_bytes: 3700
package main

import (
	"fmt"
)

func main() {
	var h, w, k int
	const m = 1000*1000*1000 + 7
	fmt.Scan(&h, &w, &k)

	var z [9][2]int
	z[0][0] = 1
	z[0][1] = 1
	z[1][0] = 1
	z[1][1] = 1
	for i := 2; i < 9; i++ {
		z[i][0] = z[i-1][0] + z[i-1][1]
		z[i][1] = z[i-1][0]
	}

	var dp [101][8]int
	dp[0][0] = 1
	for i := 1; i < h+1; i++ {
		for j := 0; j < w; j++ {
			dp[i][j] = (dp[i-1][j] * (z[j][0] * z[w-j-1][0])) % m
		}
		for j := 0; j < w-1; j++ {
			k := z[j][0] * z[w-j-2][0]
			dp[i][j] = (dp[i][j] + k*dp[i-1][j+1]) % m
			dp[i][j+1] = (dp[i][j+1] + k*dp[i-1][j]) % m
		}
	}
	fmt.Println(dp[h][k-1])
}


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

int main() {
  int N;
  string S;
  bool a=0;
  cin >> N;
  
  for (int i=0; i<N; i++) {
    cin >> S;
    if (S == "Y") {
      a = 1;
      break;
    }
  }
  
  if (a==1) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
A,B,C,X,Y = map(int,input().split())
if A > 2*C and B > 2*C:
    print(2*max([X,Y])*C)
elif A > 2*C:
    if X > Y:
        print(2*C*X)
    else:
        print(2*C*X+B*(Y-X))
elif B > 2*C:
    if X > Y:
        print(A*(X-Y)+2*C*Y)
    else:
        print(2*C*Y)
elif A+B > 2*C:
    if X > Y:
        print(2*min([X,Y])*C + abs(X-Y)*A)
    else:
        print(2*min([X,Y])*C + abs(X-Y)*B)
else:
    print(A*X+B*Y)

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

namespace AOJ.Volume0
{
    public class TheCodeDoctorLoved
    {
        public static int Main()
        {
            var toBit = new Dictionary<char, string>()
            {
                { ' ', "101" },{ '\'', "000000" },{ ',', "000011" },{ '-', "10010001" },
                { '.',"010001" },{'?',"000001" },{'A',"100101" },{'B',"10011010" },
                { 'C',"0101" },{'D',"0001" },{'E',"110" },{'F',"01001" },
                { 'G',"10011011" },{'H',"010000" },{'I',"0111" },{'J',"10011000" },
                { 'K',"0110" },{'L',"00100" },{'M',"10011001" },{'N',"10011110" },
                { 'O',"00101" },{'P',"111" },{'Q',"10011111" },{'R',"1000" },
                { 'S',"00110" },{'T',"00111" },{'U',"10011100" },{'V',"10011101" },
                { 'W',"000010" },{'X',"10010010" },{'Y',"10010011" },{'Z',"10010000" }
             };

            var toChar = new Dictionary<string, char>()
            {
                { "00000",'A' },{"00001",'B' },{"00010",'C' },{"00011",'D' },{"00100",'E' },
                { "00101",'F' },{"00110",'G' },{"00111",'H' },{"01000",'I' },{"01001",'J' },
                { "01010",'K' },{"01011",'L' },{"01100",'M' },{"01101",'N' },{"01110",'O' },
                { "01111",'P' },{"10000",'Q' },{"10001",'R' },{"10010",'S' },{"10011",'T' },
                { "10100",'U' },{"10101",'V' },{"10110",'W' },{"10111",'X' },{"11000",'Y' },
                { "11001",'Z' },{"11010",' ' },{"11011",'.' },{"11100",',' },{"11101",'-' },
                { "11110",'\'' },{"11111",'?' }
            };

            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                string bit = "";
                foreach (var c in input) { bit += toBit[c]; }
                // 5????????????????????£?????????
                string output = "";
                while (bit.Length > 0)
                {
                    string tmp = bit.Length >= 5 ? bit.Substring(0, 5) : bit;
                    // 5????????\????????´??????'0'????£????
                    if (tmp.Length < 5) { tmp = tmp.PadRight(5, '0'); }
                    output += toChar[tmp];
                    bit = bit.Length >= 5 ? bit.Substring(5) : "";
                }

                Console.WriteLine(output);
            }

            return 0;
        }
    }
}

Measured memory_bytes: 9976
import copy

h, w = map(int, input().split())
C = []
for i in range(10):
    c = list(map(int, input().split()))
    C.append(c)

num_dict = {}
for i in range(-1,10):
    new = {i:0}
    num_dict.update(new)

for i in range(h):
    A = list(map(int, input().split()))
    for a in A:
        num_dict[a] += 1

DP = copy.deepcopy(C)

for k in range(10):
    for i in range(10):
        for j in range(10):
            DP[i][j] = min(DP[i][j], DP[i][k] + DP[k][j])

ans = 0
for m in range(0, 10):
    ans += DP[m][1] * num_dict[m]

print(ans)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[100001],d[101][101];
int main()
{
    ll i,h,w,n;
    cin>>h>>w;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    ll j=1;
    ll k=1;
    ll f=0;
    for(i=1; i<=n; i++)
    {
        while(a[i]>0)
        {if(f==0)
        {
            while(a[i]>0)
            {
                d[k][j++]=i;
                a[i]--;
                //cout<<"1 "<<a[i]<<endl;
                if(j>w)
                {
                    k++;
                    j=w;
                    f=1;
                    break;
                }
            }
        }
        if(f==1)
        {
            while(a[i]>0)
            {
                d[k][j--]=i;
                a[i]--;
                //cout<<"2 "<<a[i]<<endl;
                if(j<1)
                {
                    k++;
                    j=1;
                    f=0;
                    break;
                }
            }
        }}
    }
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            cout<<d[i][j];
            if(j<w)
            {
                cout<<" ";
            }
        }
        cout<<endl;
    }
    cout<<endl;
    return 0;
}



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

if(400 <= N <= 599):
    print("8\n")
elif(600 <= N <= 799):
    print("7\n")
elif(800 <= N <= 999):
    print("6\n")
elif(1000 <= N <= 1199):
    print("5\n")
elif(1200 <= N <= 1399):
    print("4\n")
elif(1400 <= N <= 1599):
    print("3\n")
elif(1600 <= N <= 1799):
    print("2\n")
else:
    print("1\n")


Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
int temp[1000];
int main()
{
  int n;
  cin>>n; 
  vector<int>v;
  
  int c=0;
  while(n!=0)
  {
    int r=n%10;
    n/=10;
    v.push_back(r);
    c++;
  }
  
  int ok=0;
  for(auto x:v)
     if(x==2)
        ok++;
    cout<<ok<<"\n";    
  
  //int mx=0;
  
  
  //for(int i=0;i<c;i++){
    //temp[i]=temp[v[i]]++;
    //mx=max(mx,temp[i]);
    //cout<<temp[i];
  //}
  //if(mx>=1)
    //cout<<mx<<"\n";
    //else cout<<"0"<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>;

int main()
{
    long long int n;
    long long int h[100000];
    scanf("%lld",&n);
    for(int i = 1 ; i <= n ; i ++ )
    {
        scanf("%lld",&h[i]);
    }
    int sum = 0;
    int num = 0;
    for(int i = 1 ; i < n ; i ++ )
    {
        if(h[i] >= h[i + 1])
            sum ++ ;
        else
        {
            if(sum >= num)
                num = sum;
            sum = 0;
        }
    }
    if(sum >= num)
        num = sum;
    printf("%d\n",num);
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int T[101][1001];
int L,X;
int N[2];
int E[2][1001], S[2][1001];

int main() {
  while(cin >> L >> N[0] >> N[1] >> X && (L || N[0] || N[1] || X)) {
    for(int k = 0; k < 2; ++k) {
      for(int i = 0; i < N[k]; ++i) {
	string name;
	cin >> name >> E[k][i] >> S[k][i];
      }
    }

    for(int i = 0; i <= N[1]; ++i)
      fill(T[i], T[i]+1001, (i == 0 ? 0 : -1));

    int *e, *s;
    e = E[1]; s = S[1];

    for(int k = 0; k < N[1]; ++k) {
      for(int i = N[1]; i >= 1; --i) {
	for(int j = L; j >= 1; --j) {
	  if(j-e[k]<0) break;
	  if(T[i-1][j-e[k]] == -1) continue;
	  T[i][j] = max(T[i][j], T[i-1][j-e[k]]+s[k]);
	}
      }
    }

    int ans = 0;
    e = E[0]; s = S[0]; 
    for(int x = X; x <= N[1]; ++x) {
      for(int i = 0; i < N[0]; ++i) {
	if(L-e[i]<0) continue;
	if(T[x][L-e[i]] == -1) continue;
	ans = max(ans, T[x][L-e[i]] + s[i]);
      }
      for(int i = 0; i < N[0]; ++i) {
	if(L-e[i]<0) continue;
	for(int j = i+1; j < N[0]; ++j) {
	  if(L-(e[i]+e[j])<0) continue;
	  if(T[x][L-(e[i]+e[j])] == -1) continue;
	  ans = max(ans, T[x][L-(e[i]+e[j])] + s[i]+s[j]);
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1324
def dot(a,b):
    return a[0]*b[0] + a[1]*b[1]

x1,y1,x2,y2 = [int(i) for i in input().split()] 
q = int(input())
for i in range(q):
    x,y = [int(i) for i in input().split()]
    a = [x2-x1,y2-y1]
    b = [x-x1,y-y1]
    co = dot(a,b) / dot(a,a)
    print(a[0]*co+x1,a[1]*co+y1)

Measured memory_bytes: 7760
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b[li],a[li],k,flag,t;
lo cev;
string s;
vector<lo> v;

int main(void){
	scanf("%lld %lld",&n,&m);
	for(lo i=max(-100000ll,m-n+1);i<=min(100000ll,m+n-1);i++){
		printf("%lld ",i);
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        int max_dist = 0;
        a[0] = sc.nextInt();
        for(int i=0;i<n-1;i++){
            a[i+1] = sc.nextInt();
            max_dist = Math.max(max_dist, a[i+1]-a[i]);
        }
        max_dist = Math.max(max_dist, (k-a[n-1])+a[0]);
        System.out.println(k-max_dist);
    }
}


Measured memory_bytes: 65020