akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll a;
  cin>>a;
  ll c=1;
  vector<ll>vec(a);
  for(ll i=0;i<a;i++){
    cin>>vec.at(i);
    if(vec.at(i)!=0&&c>0){
     if(1000000000000000000/vec.at(i)<c){
       c=-1;
     }
      else{
        c=c*vec.at(i);
      }
    }
    else if(vec.at(i)==0){
      c=0;
    }
  }
  cout<<c<<endl;  
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin>>n;
	int a,b; cin>>a>>b;
	cout<<min(n*a, b)<<endl;
	return 0;
}

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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    ll n; cin >> n;
    VL h(n);
    rep(i,n) cin >> h[i];

    VL dp(n,0);
    dp[1] = abs(h[1] - h[0]);
    rep2(i,2,n){
        ll cost1 = dp[i-1] + abs(h[i] - h[i-1]);
        ll cost2 = dp[i-2] + abs(h[i] - h[i-2]);
        dp[i] = min(cost1, cost2);
    }

    cout << dp[n-1] << endl; 

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll m, n;
	cin >> n >> m;
	vector<ll>a(n),b(n),c(m),d(m);
	for (ll i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (ll i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}
	vector<ll>x(n,LLONG_MAX);
	ll saisyouj = 0,mae;
	for (ll i = 0; i < n; i++) {
		for (ll j =0; j <m; j++) {
			mae = x[i];
			x[i] = min((abs(a[i] - c[j]) + abs(b[i] - d[j])), x[i]);
			if (mae != x[i]) {
				saisyouj = j;
			}
		}
		cout << saisyouj + 1 << endl;

	}
}



Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main(void){
    int n;
    map<int, int> m;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        m[a]++;
    }
    bool f=false;
    if(m.size()==1){
        int a=(m.begin()->first);
        if(a*2<=n||a==n-1)f=true;
    }else if(m.size()==2){
        int a=(m.begin()->first);
        if(m[a]+m[a+1]==n){
            if(2*a+2-m[a]<=n&&a+1>m[a])f=true;
        }
    }
    if(f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

if (N <= 81):
    if (N <= 9):
        print("Yes")
    elif (N < 20 and N & 1 == 0):
        print("Yes")
    elif (N < 30 and N % 3 == 0):
        print("Yes")
    elif (N < 40 and N % 4 == 0):
        print("Yes")
    elif (N < 50 and N % 5 == 0):
        print("Yes")
    elif (N < 60 and N % 6 == 0):
        print("Yes")
    elif (N < 70 and N % 7 == 0):
        print("Yes")
    elif (N < 80 and N % 8 == 0):
        print("Yes")
    elif (N == 81):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.*;

import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();


	public List<Integer> getPrimeList(int max){
		LinkedList<Integer> primes=new LinkedList<Integer>();

		PLoop:for(int i=2;i<max;i++){
			if(i%7==1 || i%7==6){
				for(int prime:primes){
					if(i%prime==0){
						continue PLoop;
					}
					if( prime*prime>i){
						break;
					}
				}
				primes.add(i);
			}
		}
		return primes;
	}

	public void run() {
		List<Integer> plist=getPrimeList(300000);

		while(true){
			int n=sc.nextInt();
			if(n==1)
				break;

			List<Integer> res=new LinkedList<Integer>();
			for(int p:plist){
				if(n%p==0)res.add(p);
			}
			pr(n+":");
			for(int r:res){
				pr(" "+r);
			}
			ln();
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

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

using namespace std;

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

typedef long long ll;

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

 ll n;
  cin >> n;
 vector<ll> r(n+1,0);
  rep(i,1,n+1) {
    long p;
    cin >> p;
    r[p]=i;
  }
  rep(i,1,n) cout << 30000*i << " ";
   cout << 30000*n << endl;
  
  rep(i,1,n) cout << 30000*(n-i)+r[i] << " ";
   cout << r[n] << endl;
  
}


Measured memory_bytes: 768
if __FILE__ == $0
  while line = gets
    xmn1, ymn1, xmx1, ymx1, xmn2, ymn2, xmx2, ymx2 = line.split.map{|i| i.to_f}
    if !(xmn1 > xmx2 || xmn1 > ymx2 || xmx1 < xmn2 || ymx1 < ymn2)
      puts "YES"
    else
      puts "NO"
    end
  end
end

Measured memory_bytes: 6108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0); cin.tie(0);
#define FL(i,a,n) for(ll i=a;i<n;i++)
#define even(x) (((x)%(2))==(0))
#define odd(x) (((x)%(2))==(1))
#define meme(x) memset(x, 0, sizeof(x))
#define mod 1000000007

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int Log(int x){
	int i = 0;
	for(i = 0; (1LL << i) <= x; i++);
	    return i;
}

ll power(ll x, ll y, ll p) { 
    ll res = 1;    x = x % p;  
    while(y > 0) {
        if(y & 1) res = (res*x) % p; 
        y = y>>1;    x = (x*x) % p; 
    } return res; 
}


// Utility function to check whether a 
// number is prime or not 
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
  
// Function to check whether given number 
// has three distinct factors or not 
bool isThreeDisctFactors(long long n) 
{ 
    // Find square root of number 
    int sq = (int)sqrt(n); 
  
    // Check whether number is perfect 
    // square or not 
    if (1LL * sq * sq != n) 
        return false; 
  
    // If number is perfect square, check 
    // whether square root is prime or 
    // not 
    return isPrime(sq) ? true : false; 
} 

int main()
{
	string s,t;
	cin>>s>>t;
	int flag=0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!=t[i])
		flag=1;
	}
	if(flag==1)
	cout<<"No\n";
	else
	cout<<"Yes\n";
}

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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)

int a,b;
int main()
{
    

    cin>>a>>b;
    if(a>b and b!=1 || a==1 and b!=1)
        cout<<"Alice";
    else if(b>a and a!=1 || b==1 and a!=1)
        cout<<"Bob";
    else if(a==b)
        cout<<"Draw";
}




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

int main(){
    string s;
    cin >> s;
    int n = s.size()+1;
    s='>'+s+'<';
    vector<int> ans(n,-1);
    rep(i,n){
        if(s[i]=='>'&&s[i+1]=='<'){
            ans[i]=0;
            int j = i+1;
            while(j<n+1){
                if(s[j]=='<'){
                    ans[j] = max(ans[j], j-i);
                    j++;
                }
                else break;
            }
            j=i-1;
            while(j>=0){
                if(s[j+1]=='>'){
                    ans[j]= max(ans[j], i-j);
                    j--;
                }
                else break;
            }
        }
    }
    ll sum=0;
    rep(i,n){
        sum += ans[i];
    }
    cout << sum << endl;
    return 0;
}

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

const int N=100;

int main(){
	int n,p[N+1],m[N+1][N+1];//m代表所需乘法运算的最小次数 
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>p[i-1]>>p[i];//存储矩阵的行数
	
	for(int i=1;i<=n;i++)
		m[i][i]=0; //初始化所需乘法运算所需最小次数
	
	for(int l=2;l<=n;l++){
		for(int i=1;i<=n-l+1;i++){
			int j=i+l-1;
			m[i][j]=(l<<21);//????
			for(int k=i;k<=j-1;k++){
				m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	} 
	
	cout<<m[1][n]<<endl;
	
	return 0;
}


Measured memory_bytes: 3152
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

signed main()
{
	int X;
	cin >> X;

	int ans = 0;
	for (int i = 1; i <= 1000; i++)
	{
		for (int j = 2; j <= 1000; j++)
		{
			int n = pow(i, j);
			if (n > X) break;
			if (n <= X)
			{
				ans = max(ans, n);
			}
		}
	}
	cout << ans << endl;
}



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

// c++ allows passing an array with
// atleast one dimension defined

int happy_dp(int p[][3], int n)
{
    int dp[n][3];
    for(int j=0; j<3; j++)
        dp[0][j] = p[0][j];
    
    for(int i=1; i<n; i++)
    {
        dp[i][0] = max(dp[i-1][1] , dp[i-1][2]) + p[i][0];
        dp[i][1] = max(dp[i-1][2] , dp[i-1][0]) + p[i][1];
        dp[i][2] = max(dp[i-1][0] , dp[i-1][1]) + p[i][2];
    }
    
    int max = dp[n-1][0];
    for(int i=1; i<3; i++)
        if(dp[n-1][i] > max)
            max = dp[n-1][i];
    return max;
}

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

    int p[N][3];

    for(int i=0; i<N; i++)
        for(int j=0; j<3; j++)
            cin >> p[i][j];

    cout << happy_dp(p, N);
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1
#define j0 gray_cat_j0

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e18 + 16;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

ll LIM = 1e12;

ll ans;

set<pair<ll, ll> > pp;
map<ll, ll> dis;

ll a, b, c, d;

void add(ll n, ll v) {
	if (v >= ans) {
		return;
	}
	if (dis.count(n)) {
		if (dis[n] > v) {
			pp.erase(mp(dis[n], n));
			dis[n] = v;
			pp.insert(mp(v, n));
		}
	} else {
		dis[n] = v;
		pp.insert(mp(v, n));
	}
}

void process() {
	ll v = pp.begin()->_1, n = pp.begin()->_2;
	//cout << n << " " << v << endl;
	pp.erase(pp.begin());
	if (n <= LIM && LIM / d >= n) {
		ans = min(ans, v + d * n);
	}
	if (n <= 1) {
		return;
	}
	if (v >= ans) {
		return;
	}
	
	if (n % 2 == 0) {
		add(n / 2, v + a);
	} else {
		add(n / 2, v + a + d);
		add(n / 2 + 1, v + a + d);
	}
	
	if (n % 3 == 0) {
		add(n / 3, v + b);
	} else if (n % 3 == 1) {
		add(n / 3, v + b + d);
	} else {
		add(n / 3 + 1, v + b + d);
	}
	
	if (n % 5 == 0) {
		add(n / 5, v + c);
	} else if (n % 5 == 1) {
		add(n / 5, v + c + d);
	} else if (n % 5 == 2) {
		add(n / 5, v + c + d + d);
	}  else if (n % 5 == 3) {
		add(n / 5 + 1, v + c + d + d);
	} else {
		add(n / 5 + 1, v + c + d);
	}
}

void solve(){
	pp.clear();
	dis.clear();
	ans = LL_INF;
	ll n;
	cin >> n >> a >> b >> c >> d;
	//cout << n << " " << a << " " << b << " " << c << " " << d << endl;
	dis[n] = 0;
	pp.insert(mp(0, n));
	while(!pp.empty()) {
		process();
	}
	cout << ans << endl;
}

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    cin >> t;
    while(t--){
        solve();    
    }
}


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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    int mx = 0;
		int sum = 0;
    rep(i, N) {
        cin >> L[i];
        mx = max(mx, L[i]);
				sum += L[i];
    }
    if (sum - mx * 2 <= 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

int n,i,j,t,k,s,minj;
t=0;
scanf("%d\n ",&n);

int a[n];

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

for(i=0;i<n;i++){
 minj=i;
  for(j=i;j<n;j++){
   if(a[minj]>a[j]){
    minj=j;
    }
   }
  if(i != minj){
  s=a[i];
  a[i]=a[minj];
  a[minj]=s;
  t++;
  }
}

for(k=0;k<n-1;k++){
  printf("%d ",a[k]);
 }
printf("%d\n",a[n-1]);
printf("%d\n",t);

return 0;
}



Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define endl "\n"
#define ing long long
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

#define w first
#define t second
#define c first
#define d second

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

    int M, N;
    vector<pair<int,int>> in, cd;
    vector<int> dp, sum1, sum2;

    cin>>M>>N;

    in.resize(M);
    sum1.resize(M+1,0);
    sum2.resize(M+1,0);
    cd.resize(N);
    dp.resize((1<<N) + 10);
    
    for(int i = 0; i < M; i++){
        cin>>in[i].w>>in[i].t;
        sum1[i+1] += in[i].w;
        sum2[i+1] += in[i].t;
        sum1[i+1] += sum1[i];
        sum2[i+1] += sum2[i];
        // cout<<"i = "<<i+1<<" sum1 "<<sum1[i+1]<<endl;
        // 
        // cout<<"i = "<<i+1<<" sum2 "<<sum2[i+1]<<endl;
    }

    for(int i = 0; i < N; i++){
        cin>>cd[i].c>>cd[i].d;
    }

    dp[0] = -1;

    for(int i = 1; i < (1<<N); i++){
        int maximum = -1 ;
        for(int j = 0; j < N; j++){
            int bit = i&(~(1<<j));
            
            //cout<<"bit = "<<bit<<" "<<i<<endl;
            if(bit == i) continue;
            int num = dp[bit];
            int W = 0, T = 0;
            maximum = max(num, maximum);
            int x = 0,  y = 0;

            if(num == M-1){
                cout<<M<<endl;
                return 0;
            }
            //if(num != -1)
                x = sum1[num+1] +cd[j].c;
                //if(num != -1)
                y = sum2[num+1]+ cd[j].d;
            
            /*
            for(int k = num+1; k < M; k++){
                W += in[k].w;
                T += in[k].t;
                if(W > cd[j].c || T > cd[j].d) break;

                maximum = max(k,maximum);
            }

            */
            int temp1 = upper_bound(sum1.begin(), sum1.end(), x) - sum1.begin();
            int temp2 = upper_bound(sum2.begin(), sum2.end(), y) - sum2.begin();
            // cout<<i<<" "<<j<<" "<<temp1<<" "<<temp2<<endl;
            // cout<<"x = "<<x<<" y = "<<y<<" num = "<<num<<" temp = "<<min(temp1,temp2)-1<<endl;
            maximum = max(min(temp1,temp2)-2, maximum);
            
        }
        dp[i] = maximum;
        //cout<<i<<" "<<maximum<<endl;
    }

    cout<<dp[(1<<N)-1]+1<<endl;
    
    return 0;
}



Measured memory_bytes: 5984
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;


int fast_expo(int b, int pow){
  int ans = 1;
  while(pow > 0) {
    if(pow % 2 == 1) {
      ans = ans*b%mod;
    }
    b = b*b%mod;
    pow /= 2;
  }
  return ans;
}
int facts[(int)2e5+5];

int comb(int n, int a) {
  int x = facts[n];
  int xx = facts[a];
  int xxx = facts[n-a];
  int ans = x*fast_expo(xx, mod-2)%mod;
  return ans * fast_expo(xxx, mod-2) % mod;

}

signed main() {
  int n, k;
  cin >> n >> k;
  facts[0] = 1;
  for(int i = 1; i <= n;i++) {
    facts[i] = facts[i-1]*i % mod;
  }
  int ans = 0;
  k = min(k,n);
  for(int i = 1; i <= k;i++) {
    ans += comb(n, i) * comb(n-1, n-1-i)%mod;
    ans = ans%mod;
  }
  cout << ans + 1<< endl;
}


Measured memory_bytes: 1792
/*
  Author: @yash_31
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#define ll long long int
#define eb emplace_back
#define fatafat ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define ft first
#define sd second
#define mkpr make_pair
#define deb(x) std::cout<<#x<<":"<<x<<endl;
#define whole(x) (x).begin(),(x).end()
#define revwhole(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define fbo find_by_order
#define ook order_of_key
#define init0(x) memset(x,0,sizeof(x));

using namespace std; 
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> gharKaSet;
 
const int maxlimit=2e5+2;
const ll inf=1e18;
//TTBDC

int main()
{
  fatafat
  int n,k;
  cin>>n>>k;
  vector<ll> v(n);
  ll dp[n];
  for(int i=0;i<n;i++){cin>>v[i];dp[i]=inf;}
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=1;j<=k;j++){
      if(i+j<n)dp[i+j]=min(dp[i+j],dp[i]+abs(v[i+j]-v[i]));
    }
  }
  cout<<dp[n-1];
  return 0;
}

Measured memory_bytes: 4760
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
LL read() {
    LL k = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9')
        k = k * 10 + c - 48, c = getchar();
    return k;
}
int f[100010], c[100010], a[100010];
int main() {
    int n = read(), m = read();
    for(int i = 1; i <= m; ++i)
        a[i] = read(), c[i] = read();
    memset(f, 127/3, sizeof(f)); f[0] = 0;
    for(int i = 1; i <= 15000; ++i) {
        for(int j = 1; j <= m; ++j) {
            if(a[j] <= i) f[i] = min(f[i], f[i-a[j]] + c[j]);
        }
    }
    int ans = 2147483647;
    for(int i = n; i <= 100000; ++i) ans = min(ans, f[i]);
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
std::vector<long long int> v;
int main() {
     long long int n;
	cin >> n;
	long long int g = 0;
	for(long long int i=0;i<n;i+=1){
	     long long int x;
	     cin >> x;
	     g = __gcd(g,x);
	}
	cout << g << endl;
	return 0;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b == c || b + c == a || c + a == b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#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 <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

ll gcd(ll a, ll b) {
    while(b) {
        ll tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

pair<ll, ll> normalize(ll A, ll B) {
    assert(A != 0 ||  B != 0);
    if (A == 0)
        return pair<int, int>{0, 1};
    if (B == 0)
        return pair<int, int>{1, 0};
    if (B < 0) {
        A = -A;
        B = -B;
    }
    assert(B >= 0);
    ll g = gcd(abs(A), abs(B));
    A /= g;
    B /= g;
    return pair<ll, ll>{A, B};
}

ll MOD=1000000007;
inline ll add_m(ll a, ll b) { return (a + b) % MOD; }
inline ll sub_m(ll a, ll b) { return (a - b + MOD) % MOD; }
inline ll mul_m(ll a, ll b) { return (a * b) % MOD; }
ll pow_m(ll a, ll b) {
    ll r = 1LL;
    while(b) {
        if(b & 1LL)
            r = mul_m(r, a);
        a = mul_m(a, a);
        b >>= 1;
    }
    return r;
}

int main(void)
{
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    REP(i, N)
        cin >> A[i] >> B[i];
    int countAB0 = 0;
    map<pair<ll, ll>, int> countC;  // A/B
    map<pair<ll, ll>, int> countR;  // -B/A

    REP(i, N) {
        if (A[i] == 0 && B[i] == 0) {
            countAB0++;
        }
        else {
            countC[normalize(A[i], B[i])]++;
            countR[normalize(-B[i], A[i])]++;
        }
    }

    set<pair<ll, ll> > used;
    vector<pair<int, int> > w;
    REP(i, N) {
        if (A[i] != B[i]) {
            pair<ll, ll> key = normalize(A[i], B[i]);
            pair<ll, ll> rkey = normalize(-B[i], A[i]);
            if (used.count(key) == 0) {
                w.push_back({countC[key], countR[key]});
                used.insert(key);
                used.insert(rkey);
            }
        }
    }

    ll ret = 1;
    REPV(w, i) {
        ll m = pow_m(2, w[i].first);
        m = add_m(m, pow_m(2, w[i].second));
        m = sub_m(m, 1);
        ret = mul_m(ret, m);
    }
    cout << add_m(sub_m(ret, 1), countAB0) << endl;
    
    return 0;
}


Measured memory_bytes: 70440
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  ll N;
  while(cin>>N && N){
    ll tmp = 1;
    int ans = 0;
    while(tmp < N){
      tmp *= 3;
      ans++;
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n+1),b(n+1);
  for(int i=0;i<n+1;i++){ cin >> a.at(i); }
  for(int i=0;i<n;i++){ cin >> b.at(i); }
  b.at(n) = 0;
  
  ll ans = 0;
  
  for(int i=0;i<n+1;i++){
    if( a.at(i) >= b.at(i) ){
      ans += b.at(i);
    }else if( a.at(i) < b.at(i) ){
      ans += a.at(i);
      if( i == n ) break;
      if( a.at(i+1) > b.at(i) - a.at(i) ){
        a.at(i+1) -= b.at(i) - a.at(i);
        ans += b.at(i) - a.at(i);
      }else if( a.at(i+1) <= b.at(i) - a.at(i) ){
        ans += a.at(i+1);
        a.at(i+1) = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 1000040

const int  m = 1000033;
const int  m2= 1000003;
//7069 - 60
char stack[MAX][15];
int h1(long long);
int h2(long long);
int insert(long long,int);
long long sti(char *);

int main(){
  int val,i,j,n,dic=0,dicc=MAX,index2=0,vall;
  char op[15],s[15];
  int exist=-1,index=0;

  while(scanf("%d",&n) != EOF){
    dic=0,dicc=MAX;
    for(i=0;i<=MAX;i++)strcpy(&stack[i][0],"not");
    for(i=0;i<n;i++){
      exist=-1;
      scanf("%s %s",op,s);
      if(op[0] == 'i'){
	index=0;
	while(1){
	  val = insert(sti(&s[0]),index);
	  if(strcmp(&stack[val][0],"not") == 0){
	    strcpy(&stack[val][0],&s[0]);
	    break;
	  }
	  else index++;
	  if(index == MAX)break;
	}
      }
      else if(op[0] =='f'){
	index2=0;
	while(1){
	  vall=insert(sti(s),index2);
	  if(strcmp(stack[vall],s) == 0){
	    exist=1;
	    break;
	  }
	  else if(strcmp(&stack[vall][0],"not") == 0){
	    break;
	  }
	  index2++;
	  if(index2 == MAX)break;
	}
	if(exist == 1)printf("yes\n");
	else printf("no\n");
      }
    }
  }
  return 0;
}


int h1(long long k){
  return k%m;
}

int h2(long long k){
  return 1+k%m2;
}

int insert(long long k,int i){
  return (h1(k) + i*h2(k))%m;
}

long long sti(char *s){
  long long i=0,sum=0;
  while(s[i] != '\0'){
    sum+=s[i]-'A';
    sum*=10;
    i++;
  }
  return sum;
}

Measured memory_bytes: 14000
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,cnt[26];
string str;
int ans;
int main()
{
    scanf("%d",&n);
    cin>>str;
    for(int i=0;i<n;i++) cnt[str[i]-'a']++;
    ans=1;
    for(int i=0;i<26;i++) ans=1LL*ans*(cnt[i]+1)%MOD;
    ans--;if(ans<0) ans+=MOD;
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 512
import itertools, collections

n = int(input())
a = list(map(int, input().split()))

accum = [0] + list(itertools.accumulate(a))
lst = collections.Counter(accum).most_common()
ans = 0
for i in range(len(lst)):
    if lst[i][1] == 1:
        break
    else:
       ans += lst[i][1] * (lst[i][1]-1) // 2
#print(accum)
#print(lst)
print(ans)


Measured memory_bytes: 48016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

struct rakuda{
	ll k, l, r;

	void input(){
		cin >> k >> l >> r;
	}
};

bool asc(rakuda &a, rakuda &b){
	return a.k < b.k;
}

void solve(){
	ll n;
	cin >> n;
	vector<rakuda> a(n);
	rep(i, n) a[i].input();

	sort(all(a), asc);
	vector<rakuda> b, c;
	rep(i, n){
		if (a[i].l >= a[i].r) b.pb(a[i]);
		else
			c.pb(a[i]);
	}
	reverse(all(c));

	ll ans = 0;
	priority_queue<ll> pq;
	rep(i, b.size()){
		ans += b[i].l;
		pq.push(b[i].r - b[i].l);
		while(pq.size() > b[i].k){
			ans += pq.top();
			pq.pop();
		}
	}
	while (!pq.empty()) pq.pop();
	rep(i, c.size()){
		ans += c[i].r;
		pq.push(c[i].l - c[i].r);
		while(pq.size() > n - c[i].k){
			ans += pq.top();
			pq.pop();
		}
	}
	co(ans);
}

int main(void){
	ll t;
	cin >> t;
	rep(i, t) solve();

	return 0;
}


Measured memory_bytes: 14512
def main():
    import sys
    N=int(sys.stdin.readline())
    A=list(map(int,sys.stdin.readline().split()))
    if N==2:
        print(A[0])
        return

    
    A.sort(reverse=True)
    score=A[0]
    count=1
    
    
    for a in A[1:]:
        score+=a
        count+=1
        if count==N-1:
            break

        score+=a
        count+=1
        if count==N-1:
            break
    
    print(score)

main()

Measured memory_bytes: 92112
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <ctime>

#ifndef ONLINE_JUDGE
#include "LocalDebug.h"
#else 
#define dbg(...)
#endif

#define int long long

void go () {
	int n; std::cin >> n;
	std::vector <int> a (n+1);
	std::vector <long long> up (n+1);
	for (int i = 0; i <= n; ++i) 
		std::cin >> a[i];
	long long sum = 0, have, sons;
	if (n == 0 && a[0] != 1) {
		std::cout << -1 << "\n";
		exit (0);
	}
	up[0] = 1 - a[0];
	have = up[0];
	for (int i = 1; i <= n; ++i) {
		if (have < 1e18) have = have * 2;
		sons = a[i];
		up[i] = have - sons;
		have -= sons;
		if (up[i] < 0 || (up[i]==0 && i < n)) {
			std::cout << -1 << "\n";
			exit (0);
		}
	}
	dbg (up);
	sons = a[n]; have = 0;
	sum += sons + have;
	have = a[n];
	for (int i = n-1; i >= 0; --i) {
		if ((have + 1) / 2 > up[i]) {
			std::cout << -1 << "\n";
			exit (0);
		}
		have = std::min (have, up[i]);
		sons = a[i];
		sum += have + sons;
		have = have + sons;
		dbg (i, up[i], have, sons, sum);
	}
	std::cout << sum << "\n";
}

int32_t main () {
	int T = 1;
	time_t tic = clock();
	while (T--) go();
	time_t toc = clock();
	std::cerr << __FILE__ << " execution time : " << 1000.0 * (toc - tic) / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


Measured memory_bytes: 5120
#include<iostream>
using namespace std;
int main(){
	int a, b, c, d, L, R;
	cin>>a;
	cin>>b;
	cin>>c;
	cin>>d;
	L = a + b;
	R = c + d;
	if(L == R){
		cout<<"Balanced"<<endl;
	}
	if(L > R){
		cout<<"Left"<<endl;
	}
	if(L < R){
		cout<<"Right"<<endl;
	}
}


Measured memory_bytes: 256
S = input()
judgeList = ['A', 'C', 'G', 'T']
maxLength = 0
currentLength = 0
for i, v in enumerate(S):
    if v in judgeList:
        currentLength += 1
    else:
        maxLength = max(currentLength, maxLength)
        currentLength = 0
maxLength = max(currentLength, maxLength)
print(maxLength)


Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(1000000)

def make_adlist(n):
  adlist = [[] for _ in range(n)]
  for _ in range(n-1):
    a, b = map(lambda x:int(x)-1, input().split())
    adlist[a] += [b] 
    adlist[b] += [a]
  return adlist

def dfs(adlist, s, dist, d):
  for nxt in adlist[s]:
    if dist[nxt] == -1:
      dist[nxt] = d
      dfs(adlist, nxt, dist, d+1)

def main():
  n, u, v = map(int, input().split())
  u -= 1
  v -= 1
  adlist = make_adlist(n)
  t_dist = [-1]*n
  t_dist[u] = 0
  dfs(adlist, u, t_dist, 1)
  a_dist = [-1]*n
  a_dist[v] = 0
  dfs(adlist, v, a_dist, 1)
  ans = 0 
  for i in range(n):
    if t_dist[i] < a_dist[i]:
      ans = max(ans, a_dist[i]-1)
  print(ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 101028
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int vis[N],match[N],A[N][N],a[N][N],c[N],n,m,b[N][N],now[N][N];
vector<int > v[N][N];
int dfs(int x){
	for (int i=1;i<=n;i++)
		if (!vis[i]&&A[x][i]){
			vis[i]=1;
			if (!match[i]||dfs(match[i])){
				match[i]=x;
				return 1;
			}
		}
	return 0;	
}
int main(){
//	freopen("sort.in","r",stdin);
//	freopen("sort.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)scanf("%d",&a[i][j]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			v[i][(a[i][j]-1)/m+1].push_back(j);
	for (int j=1;j<=m;j++){
		for (int i=1;i<=n;i++)
			for (int k=1;k<=n;k++)
				if (now[i][k]!=(int)v[i][k].size())A[i][k]=1;
				else A[i][k]=0;
		memset(match,0,sizeof match);
		for (int i=1;i<=n;i++){
			memset(vis,0,sizeof vis);
			dfs(i);
		}
		for (int k=1;k<=n;k++){
			int i=match[k];
			b[i][j]=a[i][v[i][k][now[i][k]]];
			now[i][k]++;
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++)printf("%d ",b[i][j]);
		puts("");
	}
	for (int i=1;i<=m;i++){
		for (int j=1;j<=n;j++)c[j]=b[j][i];
		sort(c+1,c+n+1);
		for (int j=1;j<=n;j++)b[j][i]=c[j];
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++)printf("%d ",b[i][j]);
		puts("");
	}	
}

Measured memory_bytes: 1024
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

bool ok(int n){
	char buf[100];
	sprintf(buf, "%d", n);
	int m = strlen(buf);
	rep(i, m) if(buf[i] != buf[m - i - 1]) return 0;
	return 1;
}

int main(){
	int n;
	cin >> n;
	rep(i, n){
		if(ok(n - i)){
			cout << n - i << endl;
			return 0;
		}
		if(ok(n + i)){
			cout << n + i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;

int n, snuke;
vector<int> conn[N];
int par[N], depth[N];

void init(int v, int p, int d) {
    depth[v] = d;
    par[v] = p;
    for (auto u : conn[v]) {
        if (u != par[v]) init(u, v, d + 1);
    }
}

int black = 0;
void count(int v) {
    ++black;
    for (auto u : conn[v]) {
        if (u != par[v] && u != snuke) count(u);
    }
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    snuke = n - 1;
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        conn[a].push_back(b);
        conn[b].push_back(a);
    }

    init(0, -1, 0);

    int times = (depth[snuke] - 1) / 2;
    for (int i = 0; i < times; ++i) snuke = par[snuke];

    count(0);
    if (black > n - black) cout << "Fennec";
    else cout << "Snuke";
}


Measured memory_bytes: 16076
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll a,b;
	cin >> a >> b;
	cout << lcm(a,b) << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,(input().split())))
b = list(map(int,(input().split())))

nega = []
c = 0
gap = [0]*N
for i in range(N):
    gap[i] = a[i]-b[i]
    if gap[i] > 0:
        c += gap[i]
    elif gap[i] < 0:
        nega.append((-gap[i])//2)

nc = sum(nega)

if nc >= c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 40944
#include <stdio.h>
#include <algorithm>
using namespace std;

const int MAXN = 105;
const int MAX_W = (int)1e5 + 5;
const long long INF_LL = (long long)1e16;

long long dp[MAX_W];
int w[MAXN];
int v[MAXN];

int main(void) {
    int n, W;

    scanf(" %d %d", &n, &W);
    for (int i = 1; i <= n; i++) {
        scanf(" %d %d", &w[i], &v[i]);
    }

    for (int i = 1; i <= W; i++) {
        dp[i] = -INF_LL;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = W; j >= w[i]; j--) {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    long long ans = 0;
    for (int i = 1; i <= W; i++) {
        ans = max(ans, dp[i]);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 896
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <bitset>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    ll dist = abs(a - b);
    ll catchUp = (abs(v) - abs(w)) * t;
    if (catchUp >= dist)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3136
def read_i
  gets.chomp.split(' ').map(&:to_i)
end

a,b,k = read_i

num = a < b ? a : b
divisor = []

num.times do |i|
  n = i + 1
  if (a % n == 0) && (b % n == 0)
    divisor << n
  end
end
puts divisor[-k]

Measured memory_bytes: 1788
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int N;
    cin >> N;
    int n = 0;
    for (int i = 1; i < N+1; i+=2){
        int counter = 0;
        double M = sqrt(i);
        for (int j = 1; j < M; j+=2){
            if ((i % j) == 0){
                counter += 1;
                if (i != j*j){
                    counter += 1;
                }
            }
        }
        if (counter == 8) n += 1;
    }
    cout << n << endl;
}

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

int main()
{
	int N;
	long long X;
	scanf("%d%lld", &N, &X);
	std::vector<long long> x(N + 1);
	for (int i{1}; i <= N; i++)
	{
		scanf("%lld", &x[i]);
		x[i] += x[i - 1];
	}
	
	long long min{1LL << 60};
	// turnを1<= turn <=nで固定
	for (int turn{1}; turn <= N; turn++)
	{
		// 往復そのものに必要なエネルギー、拾うのと捨てるのに必要なエネルギー、2k+1の1のエネルギー
		long long sum{2 * (x[N] - x[N - turn]) + (N + turn) * X + x[N]};
		int k;
		for (k = 1; N - k * turn >= 0; k++)
		{
			sum += 2 * k * (x[N - (k - 1) * turn] - x[N - k * turn]);
			if (sum > min) break;
		}
		if (sum > min) continue;
		sum += 2 * k * x[N - (k - 1) * turn];
		min = std::min(min, sum);
	}
	printf("%lld\n", min);

	return 0;
}

Measured memory_bytes: 1792
s = input()

CNT_MAX = 1 << (len(s) - 1)

def get_sum(s, sp):
    ret = 0
    start = end = len(s)
    for i in range(len(bin(sp))-2):
        if bool((sp >> i) & 1):
            start = len(s) - i - 1
            ret += int(s[start:end])
            end = start
    ret += int(s[0:end])
    return ret
    
ans = 0
for i in range(CNT_MAX):
    ans += get_sum(s, i)
    #print(get_sum(s, i))
print(ans)

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	if(n <= 999) cout << "ABC" << endl;
	else cout << "ABD" << endl;
	return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct node{
    int id;
    double cost;

    bool operator<(const node & right) const {
        return cost > right.cost;
    }
};

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

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

    double sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;

    int n;
    cin >> n;

    vector<double> x(n + 2), y(n + 2), r(n + 2);
    x[0] = sx;
    y[0] = sy;
    r[0] = 0;
    x[n + 1] = gx;
    y[n + 1] = gy;
    r[n + 1] = 0;
    REP(i, 1, n + 1){
        cin >> x[i] >> y[i] >> r[i];
    }

    vector<double> cost(n + 2, DBL_MAX);
    priority_queue<node> que;
    que.push({0, 0.0});
    while(!que.empty()){
        node now = que.top();
        que.pop();
        if(!chmin(cost[now.id], now.cost)){
            continue;
        }
        rep(i, n + 2){
            double ncost = now.cost + max(sqrt(pow(x[i] - x[now.id], 2.0) + pow(y[i] - y[now.id], 2.0)) - r[i] - r[now.id], 0.0);
            if(i != now.id && cost[i] > ncost){
                que.push({i, ncost});
            }
        }
    }

    cout << fixed << setprecision(12) << cost[n + 1] << endl;

    return 0;
}

Measured memory_bytes: 10608
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    s0 = "#"
    s1 = "."
    for i in range(w - 1):
        if i % 2 == 0:
            s0 += "."
            s1 += "#"
        else:
            s0 += "#"
            s1 += "."

    for i in range(h):
        if not i % 2:
            print(s0)
        else:
            print(s1)
    print("")


Measured memory_bytes: 5612