akhauriyash/Code-Regression huggingface dataset:
N,A,B,C,D=map(int,input().split())
if(N%A==0):
    a=int(N/A)
else:
    a=int(N/A+1)
if(N%C==0):
    b=int(N/C)
else:
    b=int(N/C+1)

X=B*a
Y=D*b

if X<=Y:
    print(X)
else:
    print(Y)


Measured memory_bytes: 5600
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N ;cin >> N;
  ll ans = 1;
  ll till = sqrt(N)+1;
  rep(i,till){
    if(i == 0)continue;
    if(N%i == 0) ans = i;
  }
  ans = max(ans, N/ans);
  
  cout << to_string(ans).size() << endl;  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> W(N);
	for (int i = 0; i < N; i++) cin >> W[i];
	int ans = 100000;
	for (int T = 0; T < N - 1; T++) {
		int S1 = 0, S2 = 0;
		for (int i = 0; i < N; i++) {
			if (i <= T) S1 += W[i];
			else S2 += W[i];
		}
		ans = min(ans, abs(S1 - S2));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
#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);
}

int N, M;
int k[11], s[11][100];
int p[100];

int main() {
    COME_LET_THE_GAMES_BEGIN();
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    for (int i = 0; i < M; i++) {
        cin >> p[i];
    }
    ll ans = 0;
    for (int i = 0; i < (1 << N); i++) {
        bool flag = true;
        for (int j = 0; j < M; j++) {
            int a = 0;
            for (int l = 0; l < k[j]; l++) {
                if (i >> (s[j][l]) & 1) {
                    a++;
                }
            }
            if (a % 2 != p[j]) {
                flag = 0;
            }
        }
        if (flag)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll x,y,z;
  cin >> x >> y >> z;
  set<vector<ll> > s;
  vector<ll> v(3);
  v[0]=x,v[1]=y,v[2]=z;
  s.in(v);
  ll ans=0;
  while(1) {
    if(x%2||y%2||z%2) break;
    ll xx=y/2+z/2;
    ll yy=x/2+z/2;
    ll zz=x/2+y/2;
    x=xx,y=yy,z=zz;
    v[0]=x,v[1]=y,v[2]=z;
    if(s.count(v)) {
      pr(-1);
      return;
    }
    s.in(v);
    ans++;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 764
n = int(input())

div_count = 0
sum = 0

for i in range(3,n+1,2):
    a = i
    j = 2
    div_count = 0
    while(j <= a):
        #print("a is",a)
        #print("j is",j)
        if a % j == 0:
            div_count += 1
            a //= j
            j += 1
        else:
            j += 1
    if div_count == 3:
        sum += 1

print(sum)



Measured memory_bytes: 3060
(d, g), *s = [list(map(int, i.split())) for i in open(0)]
def c(i,t,l):
    if i==d:
        if t>=g:
            return sum(l)
        else:
            m=d-l[::-1].index(0)
            e = (t - g) // (m * 100)
            if -e < s[m-1][0]:
                return sum(l)-e
            else:
                return 10**3
    return min(c(i+1,t,l+[0]),c(i+1,t+s[i][0]*-~i*100+s[i][1],l+[s[i][0]]))
print(c(0,0,[]))

Measured memory_bytes: 3064
from functools import lru_cache
N = int(input())
K = int(input())

@lru_cache(None)
def f(N, K):
    if K == 0: return 1
    if N < 10:
        if K == 1: return N
        return 0
    q, r = divmod(N, 10)
    ret = 0
    ret += f(q, K-1) * r
    ret += f(q-1, K-1) * (9-r)
    ret += f(q, K)
    return ret

print(f(N, K))  

Measured memory_bytes: 3940
#include <stdio.h>

int main()
{
	long long int x,y,z;
	long long int t;
	
	scanf("%lld %lld %lld",&x,&y,&z);
	
	t = x;
	x = y;
	y = t;
	
	t = x;
	x = z;
	z = t;
	
	printf("%lld %lld %lld\n",x,y,z);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}

int modinv(int a){ return power(a,mod-2);}

void solve()
{
	int n,k,i,ans=1,sum1=0,sum2=0;
	cin>>n>>k;
	for(i=0;i<k;i++){
		sum1+=i;sum2+=n-i;}
	for(i=k;i<=n;i++)
	{
		//cout<<sum1<<"  "<<sum2<<endl;
		int val=(sum2-sum1+1+mod)%mod;
		ans=(ans+val)%mod;
		sum1+=i;
		sum2+=n-i;
	}
	cout<<ans<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	while(t--)	solve();
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define N 200005

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
    int l;
    cin>>l;
    double s = l/3.0;
    cout<<setprecision(16)<<s*s*s;
	return 0;
}


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back
#define t top()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define ll long long
#define oo 1e17
#define int long long

const int N = 2e5 + 5;
int n , k;
int a[N] , dp[N];

main()
{
    //freopen("K.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    FOR(i , 1 , n)
        cin >> a[i];
    FORD(i , k , 1)
    {
        FOR(j , 1 , n)
            if((i + a[j]) == k + 1 || (i + a[j] <= k && dp[i + a[j]] == 0))
                dp[i] = 1;
    }
    if(dp[1] == 1)
        cout << "First";
    else
        cout << "Second";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

//------------------------------------------------------

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

    auto M = [&](char p1, char p2) {
        return (p1 == 'T' && p2 == 'F' ? 'F' : 'T');
    };
    int n;
    cin >> n;
    char p[n];
    rep(i, n) cin >> p[i];
    char now = M(p[0], p[1]);
    for (int i = 2; i < n; ++i) {
        now = M(now, p[i]);
    }
    cout << now << endl;
    return 0;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head
 
void solve(){
    int n;
    cin >> n;
    int a, b;
    if (n == 1){
        cout << "Hello World" << '\n';
        return;
    }
    else{
        cin >> a >> b;
        cout << a + b << '\n';
    }
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
	int N;
	cin >> N;
	int l[N], r[N];
	int ans = 0;
	for(int i = 0; i < N; i++){
		cin >> l[i] >> r[i];
		ans += (r[i] - l[i] + 1);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
int n;
int a[401];
int dp[401][401];
int csum[401];
int fun(int s,int e)
{
    if(s>=e) return 0;
    int &ret=dp[s][e];
    if(~ret)
        return ret;
    ret=1e18;
    for(int i=s;i<e;i++)
    {
        ret=min(ret,fun(s,i)+csum[i]-(!s?0:csum[s-1])+fun(i+1,e)+csum[e]-csum[i]);
    }
    return ret;
}
signed main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(!i) csum[i]=a[i];
        else csum[i]=csum[i-1]+a[i];
    }
    cout<<fun(0,n-1)<<endl;
	return 0;
}



Measured memory_bytes: 4928
#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>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];

  int ans = 0, pre = -1;
  rep(i,n){
    int ai = a[i]-1;
    ans += b[ai];
    if(ai == pre+1) ans += c[pre];
    pre = ai;
  }
  cout << ans << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli n, m = 200000;
	cin >> n;
	lli count = 0;

	for (int i = 0; i < n; i++) {
		lli p;
		cin >> p;
		if (p <= m)
			count++;
		m = min(p,m);
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	K, _ := strconv.Atoi(StrStdin(1)[0][0])
	var sum int = 0

	for a := 1; a <= K; a++ {
		for b := 1; b <= K; b++ {
			for c := 1; c <= K; c++ {
				sum += gcd3(a, b, c)
			}
		}
	}

	fmt.Println(sum)
}

func gcd3(a, b, c int) int {
	return gcd(gcd(a, b), c)
}

func StrStdin(num int) [][]string {
	var stringInput [][]string
	scanner := bufio.NewScanner(os.Stdin)

	for i := 0; i < num; i++ {
		scanner.Scan()
		if s := scanner.Text(); s != "" {
			stringInput = append(stringInput, strings.Split(strings.TrimSpace((scanner.Text())), " "))
		} else {
			break
		}
	}

	return stringInput
}

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


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

namespace ConsoleApp1
{
    static class BBuffet
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var dishes = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var manzoku1s = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var manzoku2s = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();

            int prevDish = -1;
            int sum = 0;
            foreach (var dish in dishes)
            {
                sum += manzoku1s[dish - 1];
                if (dish - prevDish == 1)
                {
                    sum += manzoku2s[prevDish - 1];
                }
                prevDish = dish;
            }

            Console.WriteLine(sum);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13268
#include <stdio.h>

typedef struct node_t {
	int val;
	struct node_t *next;
} node;

node* new_node(int val) {
	static int it = 0;
	static node pool[500000];
	pool[it] = (node){ val, NULL };
	return &pool[it++];
}

node* st[1000];
node* en[1000];

int main(void)
{
	int n, q, com, t, x;
	node *tmp;
	scanf("%d%d", &n, &q);
	while (q--) {
		scanf("%d%d", &com, &t);
		if (com == 0) {
			scanf("%d", &x);
			tmp = new_node(x);
			if (!en[t]) st[t] = en[t] = tmp;
			else en[t]->next = tmp, en[t] = tmp;
		}
		else if (com == 1) {
			tmp = st[t];
			while (tmp) {
				if (tmp->next)
					printf("%d ", tmp->val);
				else
					printf("%d", tmp->val);
				tmp = tmp->next;
			}
			puts("");
		}
		else {
			st[t] = en[t] = NULL;
		}
	}
	return 0;
}



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

int a[110];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	sort(a, a + n, greater<int>());
	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans += (i % 2) ? -a[i] : a[i];
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pb push_back
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6;
using namespace std;

int n;
double sum = 0;
vector<double> a;

signed main(){
  cin >> n;
  
  for(int i = 0; i < n; i++){
    int inp; cin >> inp;
    a.pb(inp);
  }
  sort(a.begin(), a.end());
  sum = a[0];
  for(int i = 1; i < n; i++){
    sum = (sum + a[i])/2;
  }
  cout << sum << endl;
  
  
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
initSum=sum(a)
for i in range(n):
    if b[i]>=a[i]:
        b[i]=b[i]-a[i]
        a[i]=0
    else:
        a[i]=a[i]-b[i]
        b[i]=0
    if b[i]>=a[i+1]:
        b[i]=b[i]-a[i+1]
        a[i+1]=0
    else:
        a[i+1]-=b[i]
        b[i]=0
print(initSum-sum(a))


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

typedef long long ll;
typedef pair<int, int> ii; 

int main(int argc, char const *argv[]) {
	string s; int cnt = -1; cin >> s;
	for(int i = 0, j = 0; i < s.size(); i = j, cnt++) 
		while(s[j] == s[i] && j < s.size()) j++;
	cout << cnt << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>

typedef long long int64;

int main(void) {
  int64 n, k;
  std::cin >> n >> k;
  int64 q = n % k;
  int64 d = std::abs(q - k);
  std::cout << std::min(q, d) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, dp[100005];
vector<long long>arr[100005];
bool vis[100005];

long long int dfs(long long int v){
	if(vis[v]){
		return dp[v];
	}
	vis[v]=1;
	long long best=0;
	for(auto a:arr[v]){
		best=max(best, dfs(a)+1);
	}
	return dp[v]=best;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> n >> m;
	for(int i=1;i<=m;i++){
		cin >> x >> y;
		arr[x].push_back(y);
	}
	long long total=0;
	for(int i=1;i<=n;i++){
		total=max(total, dfs(i));
	}
	cout << total << endl;
}


Measured memory_bytes: 8704
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int N = sc.nextInt();
    int M = sc.nextInt();
    boolean[] used = new boolean[M];
    UnionFind uf = new UnionFind(N + M);
    for (int i = 0; i < N; i++) {
      int K = Integer.parseInt(sc.next());
      for (int j = 0; j < K; j++) {
        int L = Integer.parseInt(sc.next()) - 1;
        uf.union(i, N + L);
        used[L] = true;
      }
    }
    int size = uf.size(0);
    for (int i = 0; i < M; i++) {
      if (!used[i]) ++size;
    }
    System.out.println(size == N + M ? "YES" : "NO");
  }

  static class UnionFind {
    int[] set;

    UnionFind(int n) {
      set = new int[n];
      Arrays.fill(set, -1);
    }

    void union(int a, int b) {
      int rtA = root(a);
      int rtb = root(b);
      if (rtA == rtb) {
        return;
      }
      set[rtA] += set[rtb];
      set[rtb] = rtA;
    }

    boolean find(int a, int b) {
      return root(a) == root(b);
    }

    int root(int a) {
      if (set[a] < 0) {
        return a;
      } else {
        set[a] = root(set[a]);
        return set[a];
      }
    }

    int size(int a) {
      return -set[root(a)];
    }
  }

}


Measured memory_bytes: 38168
n,m =  map(int,input().split())
a = [[] for i in range(n)]

for i in range(n):
    a[i] = list(map(int,input().split()))

b = [[0]*1 for i in range(m)]

for i in range(m):
    b[i] = int(input())

for row in range(n):
    ans = 0
    for col in range(m):
        ans += a[row][col]*b[col]
    print(ans)


Measured memory_bytes: 6020
{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections #-}
{-# OPTIONS_GHC -O2 #-}


import Control.Arrow
import Control.Concurrent
import Control.Monad
import Data.Bits
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as C
import Data.Char
import Data.Complex
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Maybe
import Data.Monoid
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace
import System.IO


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

dv :: Int -> Int -> Double
dv x y = fromIntegral x / fromIntegral y

main :: IO ()
main = do
    [x,k,d] <- map abs <$> r'
    let baseSteps = floor (dv x d)
    print $ if baseSteps >= k
        then (x - d*k)
        else let y = x `rem` d in
            if odd (k - baseSteps) then (d-y) else y







Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <set>

using namespace std;

int main() {
  string s;
  int k;
  vector<string> sub;
  cin >> s >> k;
  int n = s.size();

  for (int i=0; i<n; i++) {
    for (int j=1; j<=k; j++) {
      sub.push_back( s.substr(i, j) );
    }
  }

  sort(sub.begin(), sub.end());
  sub.erase(unique(sub.begin(),sub.end()), sub.end());
  cout << sub[k-1] << endl;
}

Measured memory_bytes: 1160
#include<cstdio>
#define LL long long
#define Max(a,b) a>b?a:b
int main()
{
	int n,x,y;
	LL A,B,c;
	scanf("%d",&n);
	scanf("%lld%lld",&A,&B);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		c=Max((A-1)/x+1,(B-1)/y+1);
		A=c*x,B=c*y;
	}
	printf("%lld\n",A+B);
}

Measured memory_bytes: 128
A,B,C,D = map(int,input().split())

X_cand=[A,B]
if A<=0<=B:
    X_cand.append(0)

Y_cand=[C,D]
if C<=0<=D:
    Y_cand.append(0)

ans=-float("inf")

for x in X_cand:
    for y in Y_cand:
        ans=max(ans,x*y)

print(ans)


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

struct UnionFindTree {
  vector<int> par, rank;
  UnionFindTree(int n) {
    par.reserve(n);
    rank.reserve(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }

  int find(int i) {
    if (par[i] == i) {
      return i;
    } else {
      return par[i] = find(par[i]);
    }
  }

  void unite(int i, int j) {
    i = find(i);
    j = find(j);
    if (i == j) return;

    if (rank[i] < rank[j]) {
      par[i] = j;
    } else {
      par[j] = i;
      if (rank[i] = rank[j]) rank[i]++;
    }
  }

  bool same(int i, int j) {
    return find(i) == find(j);
  }
};

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

int main() {
  int n, q;
  cin >> n >> q;
  UnionFindTree uft(n);

  REP(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      uft.unite(x, y);
    } else {
      cout << (uft.same(x, y) ? 1 : 0) << endl;
    }
  }
}

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

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

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  using P = pair<Int, Int>;
  vector<P> v;
  for(Int i=0;i<n;i++){
    Int x,y;
    cin>>x>>y;
    v.emplace_back(x+y,x-y);
  }
  Int iu=v[0].first,au=v[0].first;
  Int iv=v[0].second,av=v[0].second;
  for(Int i=0;i<n;i++){
    chmin(iu,v[i].first);
    chmax(au,v[i].first);
    chmin(iv,v[i].second);
    chmax(av,v[i].second);
  }
  //cout<<iu<<" "<<au<<":"<<iv<<" "<<av<<endl;
  auto check1=
    [&](Int d)->Int{
      for(Int i=0;i<n;i++){
	if(v[i].first<=iu+d&&v[i].second<=iv+d) continue;
	if(au-d<=v[i].first&&av-d<=v[i].second) continue;
	return 0;
      }
      return 1;
    };
  auto check2=
    [&](Int d)->Int{
      for(Int i=0;i<n;i++){
	if(v[i].first<=iu+d&&av-d<=v[i].second) continue;
	if(au-d<=v[i].first&&v[i].second<=iv+d) continue;
	return 0;
      }
      return 1;
    };
  
  Int l=-1,r=(au-iu)+(av-iv);
  while(l+1<r){
    Int m=(l+r)>>1;
    if(check1(m)||check2(m)) r=m;
    else l=m;
  }
  cout<<r<<endl;
  return 0;
}



Measured memory_bytes: 4936
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100000
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll x;

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


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

namespace ABC0603
{
	class Program
	{
		static void Main(string[] args)
		{
			var param = Console.ReadLine().Split(' ').Select(i => Convert.ToInt32(i)).ToArray();

			if(param[0] + param[1] >= 10)
			{
				Console.WriteLine("error");
			}
			else
			{
				Console.WriteLine(param[0] + param[1]);
			}

		}
	}
}


Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
#define pp long long int
#define pb push_back
int main()
{
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    pp a,b; cin>>a>>b;
    if(a>=13) cout<<b<<endl;
    else if(a<=5) cout<<0<<endl;
    else cout<<(b/2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N, K;
pii ps[100010];
int t[100010], d[100010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  REP(i, N) cin >> ps[i].second >> ps[i].first;
  sort(ps, ps+N, greater<pii>());
  int sum = 0, kind = 0;
  set<int> st;
  priority_queue<int, vector<int>, greater<int>> q;
  REP(i, K) {
    sum += ps[i].first;
    if (st.count(ps[i].second) == 0) {
      st.EMP(ps[i].second);
      kind++;
    } else {
      q.EMP(ps[i].first);
    }
  }

  int ans = sum + kind*kind;
  FOR(i, K, N) if (!q.empty()) {
    if (st.count(ps[i].second) == 0) {
      st.EMP(ps[i].second);
      sum -= q.top(); q.pop();
      sum += ps[i].first;
      kind++;
      chmax(ans, sum + kind*kind);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n;
 cin>>n;
 vector<int> h(n),dp(n);
 for(int i=0;i<n;i++) cin>>h[i];
 dp[n-1]=0;
 dp[n-2]=abs(h[n-1]-h[n-2]);
 for(int i=n-3;i>=0;i--){
  dp[i]=min(dp[i+1]+abs(h[i+1]-h[i]),dp[i+2]+abs(h[i+2]-h[i]));
 }
 cout<<dp[0]<<endl;
 return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

#define MOD 1000000007

using namespace std;

int dp[105][4][4][4];

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

	//AGCT
	//0123
	//AGC?
	//?AGC! ?012
	//A?GC! 0?12
	//AG?C! 01?2
	//ACG?
	//?ACG! ?021
	//GAC?
	//?GAC! ?102
	
	dp[0][3][3][3]=1;
	
	for(int len=0;len<n;len++)
		for(int i=0;i<4;i++)
			for(int j=0;j<4;j++)
				for(int k=0;k<4;k++)
				{
					if(dp[len][i][j][k]==0)continue;

					for(int nx=0;nx<4;nx++)
					{
						if(j==0 and k==1 and nx==2)continue;
						if(i==0 and k==1 and nx==2)continue;
						if(i==0 and j==1 and nx==2)continue;
						if(j==0 and k==2 and nx==1)continue;
						if(j==1 and k==0 and nx==2)continue;

						dp[len+1][j][k][nx]+=dp[len][i][j][k];
						dp[len+1][j][k][nx]%=MOD;
					}
				}


	int ans=0;
	for(int i=0;i<4;i++)
		for(int j=0;j<4;j++)
			for(int k=0;k<4;k++)
			{
				ans+=dp[n][i][j][k];
				ans%=MOD;
			}

	cout << ans << endl;


}


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

#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
    cin >> n >> k;
    ll answ  = 0;
    for (ll i = 1; i <= n; i++){
        ll x;
        cin >> x;
        if (x < k-x){
            answ += 2*x;
        } else {
            answ += 2*(k-x);
        }
    }
    cout << answ << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io;


/// https://beta.atcoder.jp/contests/agc015/tasks/agc015_a
fn main() {
    let (n, a, b) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };
    let ans = if a > b { 0 }
    else if n == 1 {
        if a == b { 1 }
        else { 0 }
    } else {
        (b - a) * (n - 2) + 1
    };

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

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

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

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

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


Measured memory_bytes: 4352
#include <iostream>
#include<cstdio>
using namespace std;
int main(void){
   int a,b;
   char op;
   
    while(1){
        cin>>a>>op>>b;
        
    if(op=='?')break;
    if(op=='+'){
        cout<<a+b<<"\n";
    }
    if(op=='-'){
        cout<<a-b<<"\n";
    }
    if(op=='*'){
        cout<<a*b<<"\n";
    }
    if(op=='/'){
        cout<<a/b<<"\n";
    }
    }
   }
   


Measured memory_bytes: 3044
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int sum1=0,sum2=0;
  int m;
  for(int i=0;i<4;i++){
    cin >> m;
    sum1+=m;
  }
  for(int i=0;i<4;i++){
    cin >> m;
    sum2+=m;
  }
  if(sum1>=sum2){
    cout << sum1 << endl;
  } else{
    cout << sum2 << endl;
  }
  return(0);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> mochi;
    int tmp;
    REP(i, N) {
        cin >> tmp;
        mochi.push_back(tmp);
    } 
    sort(mochi.begin(), mochi.end());
    mochi.erase(unique(mochi.begin(), mochi.end()), mochi.end());
    cout << mochi.size() << endl;
}

Measured memory_bytes: 256
from sys import stdin
from functools import reduce 

# 標準入力から読み込み
inputs = [list(map(int, input().split())) for _ in range(2)]
inputs = inputs[1]

if (0 in inputs):
  output = 0
else:
  output = reduce((lambda x, y: -1 if (x * y) > 1e18 or x < 0 or y < 0  else (x * y)), inputs)

print(output)

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

int main(){
    string s;cin >> s;
    vector<char> v;

    for (int i=0;i<s.size();i++){
        char tmp = s[i];

        if (tmp == '0') {
            v.push_back('0');
        } else if (tmp == '1') {
            v.push_back('1');
        } else if (tmp == 'B') {
            if (v.size() != 0){
                v.pop_back();
            }
        }
    }

    for (auto& ch:v){
        cout << ch;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int n;
  int k;
  cin >> n >> k;
  vector<int> h(n + 1);
  vector<int> dp(n + 1);
  for( int i = 1 ; i <= n ; i++ ){
    int tmp;
    cin >> tmp;
    h[i] = tmp;
  }
  dp[1] = 0;

  for( int i = 2 ; i <= n ; i++ ){
    int minc = 2e9;
    for( int j = 1 ; j <= k && i - j >= 1 ; j++ ){//j is delta
      minc = min(minc , dp[i-j] + abs( h[i] - h[i-j])  );
    }
    dp[i] = minc; 
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1024
import sys

for i in sys.stdin:
    i = i.split(" ")
    x, y = int(i[0]), int(i[1])
    if x == y == 0:
        break
    elif x <= y:
        print("{0} {1}".format(x, y))
    else:
        print("{0} {1}".format(y, x))

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

int n, cnt[4];
string a, verdict[4] = {"AC", "WA", "TLE", "RE"};

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

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a;

		for (int j = 0; j < 4; j++) {
			if (verdict[j] == a) {
				cnt[j]++;
			}
		}
	}

	for (int j = 0; j < 4; j++) {
		cout << verdict[j] << " x " << cnt[j] << '\n';
	}

	return 0;
}

Measured memory_bytes: 3636
import collections
import itertools
import math
import statistics
import datetime
from bisect import bisect_left
import heapq

__author__ = 'sudoplox // Sudhanshu'
__contact__ = "sudoplox[at]gmail.com"


def BinarySearch(a, x):
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    else:
        return -1


def fibonacci(n):
    a = 0
    b = 1
    if n < 0:
        print("Incorrect input")
    elif n == 0:
        return a
    elif n == 1:
        return b
    else:
        for i in range(2, n):
            c = a + b
            a = b
            b = c
        return b


def ngreatestelem(lis, n):
    return heapq.nlargest(n, lis)


def nsmallestelem(lis, n):
    return heapq.nsmallest(n, lis)


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def sieve():
    # Complexity: O(n * log2(log2(n)))
    primes[1] = 1
    primes[2] = 2
    j = 4
    while j < 1000000:
        primes[j] = 2
        j += 2
    j = 3
    while j < 1000000:
        if primes[j] == 0:
            primes[j] = j
            i = j * j
            k = j << 1
            while i < 1000000:
                primes[i] = j
                i += k
        j += 2


def possiblepermutations(lis):
    return itertools.permutations(lis)


sieve = False
if sieve:
    primes = [0] * 1000000

# for _ in range(int(input())):
#     n = int(input())
#     s = input()
#     arr = list(map(int, input().split(" ")))

arr = list(map(int, input().split()))
print(arr.index(0)+1)


Measured memory_bytes: 77476
#include <bits/stdc++.h>
#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long LL;

const int maxn= 200000+10;
int a[maxn], b[maxn], N, M;
bool cmp(int x, int y){ return  x>y;}


int main(){

	scanf("%d",&N);
	for (int i=0; i<N; i++) scanf("%d",&a[i]);
	sort(a, a+N, cmp);
	scanf("%d", &M);
	for (int i=0; i<M; i++) scanf("%d", &b[i]);
	sort(b,b+M, cmp);
	bool ok= (N>=M);
	for (int i=0,j=0; i<M; i++){
		while (j<N && a[j] !=b[i]) j++;
		if ( j==N)ok= false;
		j++;
	}
	if (ok ) printf("YES\n");
		else printf("NO\n");
	return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
string st;
long long i;
int main()
{
	cin>>st;
	for(i=0;i<st.size();i++)
	{
		if(st[i]=='9') {cout<<"Yes";return 0;}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 1LL<<50


int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        vector<int> c,x;
        rep(i,m){
            int a;
            cin>>a;
            c.pb(a);
        }
        rep(i,n){
            int a;
            cin>>a;
            x.pb(a);
        }
        
        
        static ll dp[20100][260];
        rep(i,20100)rep(j,260)dp[i][j]=INF;
        dp[0][128]=0;
        
        for(int i=0;i<n;i++){
            rep(j,256){
                rep(k,m){
                    int val = j+c[k];
                    if(val>255)val=255;
                    if(val<0)val=0;
                    int pow2 = (x[i]-val)*(x[i]-val);
                    dp[i+1][val] = min(dp[i+1][val] , dp[i][j]+pow2);
//                    if(j-c[k]>=0 && j-c[k]<=255)dp[i][j] = min(dp[i][j],dp[i-1][j-c[k]]+pow2);
                }
            }
        }
        ll mini=INF;
        rep(i,256){
            mini = min(mini,dp[n][i]);
        }
        cout<<mini<<endl;
        
    }
}

Measured memory_bytes: 42168
#include<stdio.h>
#include<string.h>

#define MAX 1010

int memo[MAX][MAX];

int max(int a, int b) {
	if (a >= b)return a;
	else return b;
}

int main() {
	int q;
	int x_len, y_len;
	char X[MAX], Y[MAX];

	for (int i = 0; i < MAX; i++) {
		memo[i][0] = 0;
		memo[0][i] = 0;
	}

	scanf("%d", &q);

	for (int i = 0; i < q; i++) {
		scanf("%s%s", X, Y);
		x_len = strlen(X); y_len = strlen(Y);
		for (int p = 1; p <= x_len; p++) {
			for (int q = 1; q <= y_len; q++) {

        if (X[p - 1] == Y[q - 1]) {
      		memo[p][q] = memo[p - 1][q - 1] + 1;
      	}
      	else {
      		memo[p][q] = max(memo[p - 1][q], memo[p][q - 1]);
      	}

			}
		}
		printf("%d\n", memo[x_len][y_len]);


	}
	return 0;
}



Measured memory_bytes: 5724
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;
		
		while((line = in.readLine()) != null){
			int size = Integer.parseInt(line);
			if(size==0) break;
			
			Body[] data = new Body[size];
			for(int n=0; n<size; n++){
				line = in.readLine();
				String[] tmp = line.split(" ");
				int id = Integer.parseInt(tmp[0]);
				int h = Integer.parseInt(tmp[1]);
				int w = Integer.parseInt(tmp[2]);
				data[n] = new Body(id, h, w);
			}
			
			int idx = 0;
			double min = Math.abs(data[0].bmi - 22.0);
			for(int n=1; n<size; n++){
				double delta = Math.abs(data[n].bmi - 22.0);
				if(delta < min){
					idx = n;
					min = delta;
				}
				else if(delta == min){
					if(data[idx].id > data[n].id){
						idx = n;
					}
				}
			}
			
			System.out.println(data[idx].id);			
		}
	}
}

class Body{
	int id;
	double bmi;
	
	public Body(int id, int height, int weight){
		this.id = id;
		this.bmi = (double)weight / (height * height / 10000.0);
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
typedef pair<int , int > pii;
#define MOD 1000000007
#define MOD1 998244353
#define ff first
#define ss second
#define bn cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define sz(a) int((a).size())
#define o(a) cout << a
#define MAX6 1000006
#define int ll
#define all(x) x.begin(), x.end()
#define ppii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define viii vector<ppii>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define MAX5 300005
#define MAX7 10000007
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,b,a)  for (__typeof((b)) i=(b);i>=(a);i--)
#define mem(a) memset(a,0,sizeof(a))
#define memneg(a) memset(a,-1,sizeof(a))
//#define se second
#define LN 14
#define LIM 22
#define MAX_ALPHA 26
const long long INF64 = 1e18;
const ll INF = 1e9;
const double PI = acos(-1);
#define ld long double
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
inline void max_self(ll &a, ll b)
{
  a = max(a,b);
}
 
inline void min_self(ll &a,ll b)
{
  a = min(a,b);
}
 
inline void add_self(ll &a, ll b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
inline void sub_self(ll &a, ll b) {
  a -= b;
  if (a < 0) a += MOD;
}
 
inline int mul(int a, int b) {
  return (int) ((long long) a * b % MOD);
}
 
 
ll gcd(ll a,ll b)
{
  if(b == 0)
    return a;
  else 
    return gcd(b, a%b);
}
 
 
int countDigits(int x)
{
  int cnt = 0;
  while(x)
  {
    x /= 10;
    cnt++;
  }
  return cnt;
}
 
 
ll binExpo(ll a,ll b)
{
  ll res = 1;
  while(b)
  {
    if(b&1)
      res = (res * a)%MOD;
    a = (a * a)%MOD;
    b /= 2;
  }
  return res%MOD;
}
 
int sum(int a) {
    int result = 0;
    while (a > 0) {
        result += a % 10;
        a /= 10;
    }
    return result;
}

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, k;
  cin>>n>>k;
  int dp[n+1];
  int h[n];
  for(int i = 0;i < n;i++){
    cin>>h[i];
  }
  for(int i = 0;i <= n;i++)
    dp[i] = INF64;
  dp[0] = 0;
  for(int i = 0;i < n;i++)
  {
    for(int j = 1;j <= k and i + j < n;j++)
    {
      dp[i+j] = min(dp[i+j], dp[i] + abs(h[i + j] - h[i]));
    }
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int a[3000];
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int sum=0;
  for(i=0;i<n;i++) sum+=a[i];
  printf("%d\n",sum-n);

}

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

Measured memory_bytes: 128
N = int(input())
a = [list(map(int, input().split())) for i in range(2)]
ma = 0
for i in range(2):
    for j in range(1,N):
        a[i][j] += a[i][j-1]
for i in range(N):
    if(i==0):
        ma = max(ma, a[0][i]+ a[1][N-1])
    else:
        ma = max(ma, a[0][i]+ a[1][N-1]- a[1][i-1])
print(ma)

Measured memory_bytes: 3064
function isInteger(x) {
    return Math.round(x) === x;
}

function Main(input) {
 	// 1行目がinput[0], 2行目がinput[1], …に入る
	var tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
//	var a = parseInt(tmp[0], 10);
//	var b = parseInt(tmp[1], 10);
  
	var a = tmp[0] + tmp[1];
     
    var result = isInteger(Math.sqrt (a)) ? "Yes": "No";
  
//    var result =  (a * b) % 2 ==1 ? "Even" : "Odd"
	//出力
	console.log('%s',result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));

Measured memory_bytes: 21064
#include<iostream>
#include<cstring>
#include<algorithm>
#define maxn 100010
using namespace std;
int n,l[maxn];
struct node{
	int xx1,xx2;
}a[maxn];
bool cmp(node u,node v){
	return u.xx2<v.xx2;
}
int ans=0;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int xx;
		scanf("%d%d",&xx,&l[i]);
		a[i].xx1=xx-l[i];
		a[i].xx2=xx+l[i];
	}
	sort(a,a+n+1,cmp);
	int end1;
	ans=1;
	end1=a[1].xx2;
	for(int i=2;i<=n;i++){
		if(a[i].xx1>=end1){
			ans++;
			end1=a[i].xx2;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1408
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let s = scan.chars();
    let cnt = count(&s);
    println!("{}", s.len()/2 - getd(&cnt, 'p'));
}

#[allow(dead_code)]
fn getd<S, T>(hmap: &std::collections::HashMap<S, T>, key: S) -> T
    where S : Eq + std::hash::Hash, T : Default + Copy {
    *hmap.get(&key).unwrap_or(&Default::default())
}

#[allow(dead_code)]
fn count<T: Eq + std::hash::Hash + Clone>(slice: &[T]) -> std::collections::HashMap<T, usize> {
    let mut hmap = std::collections::HashMap::new();
    for item in slice {
        *hmap.entry(item.clone()).or_insert(0) += 1;
    }
    hmap
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	int A,B,C;
	cin >> A >> B >> C;
	int mac=max(A,B);
	mac=max(mac,C);
	int mina=min(A,B);
	mina=min(mina,C);
	cout << mac-mina << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

Measured memory_bytes: 572