akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 2e6 + 9, M = 1e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

set<ll> stA, stB;
set<ll> stC;

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  ll n, m;
  cin >> n >> m;
  for (ll i = 2; i * i <= n; ++i) {
    if(n % i == 0) {
      stA.insert(i);
      while(n % i == 0)
        n/= i;
    }
  }
  for (ll i = 2; i * i <= m; ++i) {
    if(m % i == 0) {
      stB.insert(i);
      while(m % i == 0)
        m/= i;
    }
  }
  if(n >= 2)
    stA.insert(n);
  if(m >= 2)
    stB.insert(m);
  for(auto it: stA) {
    if(stB.find(it) != stB.end()) {
      stC.insert(it);
    }
  }
  cout << stC.size() + 1;
  return 0;
}


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

#define ff first
#define ss second
using namespace std;
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)
inline void fastio() {ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);}

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};



int main() {
	fastio();

	ll n; cin >> n;
	ll h[n]; f(i, 0, n - 1) cin >> h[i];

	ll dp[n] = {INT_MAX};

	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);

	f(i, 2, n - 1) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}

	cout << dp[n - 1];

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N; cin >> N;
  int a[N]; rep(i,N) cin >> a[i];

  int idx = 1, cnt = 0;
  rep(i,N){
    if (a[i]==idx) idx++;
    else cnt++;
    
  }
  if (idx==1) cout << -1 << endl;
  else cout << cnt << endl;

  // cout << fixed << setprecision(6);
  return 0;
}



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int3(n, h, w);

    cout << (n - h + 1) * (n - w + 1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,s=0; int m,a; cin>>n>>m;
	for(int i=0; i<m;++i){
		cin>>a;
		s+=a;
	}cout<< ((n-s >= 0) ? (n-s) : -1 );
}					

Measured memory_bytes: 3636
N,K = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1],reverse=True)
C = {}
tot1 = 0
for i in range(K):
    t,d = A[i]
    if t not in C:
        C[t] = 0
    C[t] += 1
    tot1 += d
tot2 = len(C)
tot = tot1+tot2**2
cur = K
for i in range(K-1,-1,-1):
    t,d = A[i]
    if C[t]>1:
        tot1 -= d
        C[t] -= 1
        j = cur
        while j<N:
            t1,d1 = A[j]
            if t1 not in C:
                C[t1]=1
                tot1 += d1
                tot2 += 1
                if tot1+tot2**2>tot:
                    tot = tot1+tot2**2
                cur = j+1
                break
            else:
                j += 1
                cur = j
print(tot)

Measured memory_bytes: 72536
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
int main(){
    int n, m;
    cin>>n>>m;
    map<pair<int,int>, bool> answer;
    vector<pair<int,int>> v[2000];
    for(int i=0; i<m; i++){
        int a, b, c;
        cin>>a>>b>>c;
        answer[{min(a, b), max(a,b)}]=false;
        v[a].push_back({b, c});
        v[b].push_back({a, c});
    }
    for(int k=1; k<=n; k++){
        pair<int,int> distance[2000]; bool processed[2000]={false};
        priority_queue<pair<int,int>> q;
        for(int i =0; i<=n; i++) distance[i].first=INF;
        distance[k].first=0;
        q.push({0,k});
        while(!q.empty()){
            int a = q.top().second; q.pop();
            if(processed[a]==true) continue;
            processed[a] = false;
            for(auto nei: v[a]){
                if(distance[nei.first].first>distance[a].first+nei.second){
                    distance[nei.first].first = distance[a].first+nei.second;
                    distance[nei.first].second = a;
                    q.push({-distance[nei.first].first, nei.first});
                }
            }
        }
        for(int i =1; i<=n; i++){
            int j = distance[i].second;
            if(distance[i].first<INF){
                answer[{min(i, j), max(i, j)}] = true;
            }
        }
    }
    int count=0;
    for(auto a: answer){
        if(a.second==false) count++;
    }


    cout<<count;
    return 0;
}

Measured memory_bytes: 384
from collections import deque

print("Yes")

N, M = map(int, input().split())
net = [[] for _ in range(N+1)]
vect = [0]*(N+1)

for _ in range(M):
	A, B = map(int, input().split())
	net[A].append(B)
	net[B].append(A)

q = deque()
q.append(1)

while len(q)>0:
	t = q.popleft()
	for i in net[t]:
		if t != i and vect[i] == 0:
			vect[i] = t
			q.append(i)

for i in range(2, N+1):
	print(vect[i])

Measured memory_bytes: 33940
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 0;

ll n, k, low, up;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
	
	cin >> n >> k;
	low = k - k / 2;
	up = k / 2;
	for(ll i = 1; i <= low; i++){
		cout << i << " " << low * 2 - i + 1 << '\n';
	}
	for(ll i = 1; i <= up; i++){
		cout << low * 2 + i << " " << low * 2 + up * 2 - i + 2 << '\n';
	}
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#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(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(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=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;}
  *c=r0;*a=a0;*b=b0;
}

ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}

ll fact[2000100],fact_inv[2000100];

void init() {
  fact[0]=1;
  REP(i,1,2000100) fact[i]=fact[i-1]*i%MAX;
  fact_inv[2000050]=get_inv(fact[2000050],MAX);
  rrep(i,2000050)fact_inv[i]=fact_inv[i+1]*(i+1)%MAX;
}

ll nCr(ll N,ll K){
  if(K<0||K>N)return 0;
  return fact[N]*fact_inv[K]%MAX*fact_inv[N-K]%MAX;
}

void Main() {
  init();
  ll x,y;
  cin >> x >> y;
  ll l=0,r=MAX;
  while(l+1<r) {
    ll m=(l+r)/2;
    ll xx=x-m,yy=y-m*2;
    if(xx<=yy*2) l=m;
    else r=m;
  }
  ll n=l,m=(x-l)/2;
  y-=2*l;
  if((x-l)%2||y!=m) {
    pr(0);
    return;
  }
  pr(nCr(n+m,n));
}

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


Measured memory_bytes: 31488
//int a = s - '0'; 文字から数字
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;

//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main() {
	ll a, b, c, d;cin >> a >> b >> c >> d;
	cout << max(max(a * c, a * d),max(b * c, b * d)) << endl;
}	

Measured memory_bytes: 11044
#include<iostream>
using namespace std;
int H1,M1,H2,M2,K;
main()
{
	cin>>H1>>M1>>H2>>M2>>K;
	H1=H1*60+M1;
	H2=H2*60+M2;
	H2-=K;
	cout<<H2-H1<<endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(void) {
  int N;
  //int a[300010];
  cin >> N;
  int a[3*N];
  for (int i = 0; i < 3*N; i++) cin >> a[i];
  sort(a, a+3*N, greater<int>());
  //reverse(a, a+3*N);
  long int sum = 0;
  for (int i = 0; i < N; ++i) {
    sum += a[i*2+1];
    //cout << a[i] << endl;
  }
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<cmath>
#include<limits.h>
#include<algorithm>
#include<cstring>
using namespace std;

const long long inf=1e12;

int main()
{
  int n,t;
  cin>>n>>t;
  long long pricesum=0;
  
  vector<int> w(n),p(n);
  for(int i=0;i<n;i++)
  {
    cin>>w[i]>>p[i];
    pricesum+=p[i];
  }
  
  vector<long long> dp(pricesum+1,inf);
  
  dp[0]=0;
  for(int i=1;i<=n;i++)
      {
            for(int j=pricesum;j>=p[i-1];j--)
            {
                dp[j]=min(w[i-1]+dp[j-p[i-1]],dp[j]);      
          	}
      }
      
    long long ans=0;
    for(int j=1;j<=pricesum;j++)
      {
          if(dp[j]<=t)
          {
              ans=max(ans,(long long)j);
          }
      }
    
  cout<<ans<<endl;
  return 0;
}


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

int main(){
  int d;
  int c[27];
  int s[400][27];
  int t[400];
  static int last[27];//最後の開催日

  cin >> d;
  rep(i, 26)cin >> c[i+1];
  rep(i, d){
    rep(j, 26){
      cin >> s[i+1][j+1];
    }
  }

  for(int i=1;i<=d;i++){
    int mx = -INF;
    int mxi;
    for(int j=1;j<=26;j++){
      int tmp=0;
      tmp += s[i][j];
      for(int k=1;k<=26;k++){
        if(j!=k)tmp-=(i-last[k])*c[k];
      }
      if(tmp>mx){
        mx = tmp;
        mxi = j; 
      }
    }
    t[i]=mxi;
    last[t[i]]=i;
  }

  //
  int target = 0;
  rep(i, 26)last[i+1]=0;
  for(int i=1;i<=d;i++){
    target += s[i][t[i]];
    last[t[i]]=i;
    for(int j=1;j<=26;j++)target-=(i-last[j])*c[j];
  }

  pair<int, int> pr[26];
  rep(i, 26){
    pr[i] = pair<int, int>(c[i+1], i+1);
  }
  sort(pr, pr+26);
  
  //ここから焼きなまし法
  rep(l, 100){
    int aft = pr[l/5].second;
    for(int k=1;k<=d;k++){
      //k日目をaftに変更する
      int tmp = 0;
      rep(i, 26)last[i+1]=0;
      for(int i=1;i<=d;i++){
        if(i==k){
          tmp += s[i][aft];
          last[aft]=i;
          for(int j=1;j<=26;j++)tmp-=(i-last[j])*c[j];
          continue;
        }
        tmp += s[i][t[i]];
        last[t[i]]=i;
        for(int j=1;j<=26;j++)tmp-=(i-last[j])*c[j];
      }
      // cout << target << ":" << tmp << endl;
      if(tmp>target){
        t[k]=aft;
      }
    }
  }
  
  rep(i, d)cout << t[i+1] << endl;
  return 0;
}


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

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int tree[100000][3];
int root(int x){
	return tree[x][0]==x?x:(tree[x][0]=root(tree[x][0]));
}
void unon(int x, int y){
	x=root(x);
	y=root(y);
	if(x==y){
	}else if(tree[x][1]>tree[y][1]){
		tree[y][0]=x;
		tree[x][2]+=tree[y][2];
	}else if(tree[x][1]<tree[y][1]){
		tree[x][0]=y;
		tree[y][2]+=tree[x][2];
	}else{
		tree[y][0]=x;
		tree[x][1]++;
		tree[x][2]+=tree[y][2];
	}
}
int ans[100000];

int main(void){
	int n, m, k, i, j;
	int a[100000][2];
	scanf("%d%d%d", &n, &m, &k);
	for(i=0; i<n; i++){
		tree[i][0]=i;
		tree[i][1]=1;
		tree[i][2]=1;
	}
	for(i=0; i<m; i++){
		scanf("%d%d", &a[i][0], &a[i][1]);
		a[i][0]--; a[i][1]--;
		unon(a[i][0], a[i][1]);
	}
	for(i=0; i<n; i++){
		ans[i]=tree[root(i)][2]-1;
	}
	for(i=0; i<m; i++){
		if(tree[a[i][0]][0]==tree[a[i][1]][0]){
			ans[a[i][0]]--;
			ans[a[i][1]]--;
		}
	}
	for(i=0; i<k; i++){
		int b[2];
		scanf("%d%d", &b[0], &b[1]);
		b[0]--; b[1]--;
		if(tree[b[0]][0]==tree[b[1]][0]){
			ans[b[0]]--;
			ans[b[1]]--;
		}
	}
	for(i=0; i<n; i++){
		printf("%d ", ans[i]);
	} putchar(10);
}


Measured memory_bytes: 3072
fun main(args: Array<String>) {
    abc143c()
}

fun abc143c() {
    var result = 0

    val n = readLine()!!
    val s = readLine()!!

    var lastChar: Char? = null
    for (c in s) {

        if (lastChar == null) {
            lastChar = c
            result++
            continue
        }

        if (lastChar == c) {
            continue
        }

        lastChar = c
        result++
    }


    println(result)
}


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

int main(){
    int k, a, b, c = 0;

    cin >> k >> a >> b;

    for(int i = a; i <= b; i++){
        if(i % k == 0){
            c = 1;
            break;
        }
    }

    if(c){
        cout << "OK\n";
    }
    else{
        cout << "NG\n";
    }
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			String c = String.valueOf(a + b);
			System.out.println(c.length());
		}
		sc.close();
	}
}



Measured memory_bytes: 26188
package main

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

var sc = bufio.NewScanner(os.Stdin)

func contains(target string, list []string) bool {
	for _, r := range list {
		if target == r {
			return true
		}
	}
	return false
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()

	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextF64() float64 {
	sc.Scan()

	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func isInteger(x float64) bool {
	return math.Floor(x) == x
}

func Ave(s []int) int {
	val := 0
	for _, i := range s {
		val += i
	}
	return int(val / len(s))
}
func cal(i int) (sum int) {
	for i != 0 {
		sum += i % 10
		i /= 10
	}
	return
}
func max(a []int) (idx int, val int) {
	max := a[0]
	idx = 0
	for j, i := range a {
		if max < i {
			max = i
			idx = j
		}
	}
	return idx, max
}

func draw(i int, a []int) (l []int) {
	// p = a[i]
	for j := i; j < len(a); j++ {
		if j != len(a)-1 {
			a[j] = a[j+1]
		} else if j == len(a)-1 {
			a = a[:len(a)-1]
		}
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer([]byte{}, math.MaxInt64)
	h := nextInt()
	w := nextInt()
	var cnt int
	if w == 1 || h == 1 {
		cnt = 1
	} else {
		cnt = ((w+1)/2)*((h+1)/2) + (w/2)*(h/2)
	}

	fmt.Println(cnt)

}


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

int main() {
  int N, tmp, ans=0; cin >> N;
  vector<int> V(N, 0);
  for (int i=0; i<N; i++) cin >> V[i];
  for (int i=0; i<N; i++) {cin >> tmp;V[i]=max(V[i]-tmp, 0);}
  for (int i=0; i<N; i++) ans +=V[i];
  cout << ans << "\n";
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int dp[2][2222][2222];//I=0,J=1
int main()
{
	int n,m;
	string s,t;
	cin>>m>>n;
	cin>>s>>t;
	int M=0;
	memset(dp,0,sizeof(dp));
	for(int i=0;i<=m+1;i++)for(int j=0;j<=n+1;j++)dp[0][i][j]=-10000;
	for(int i=0;i<=m;i++)
	{
		for(int j=0;j<=n;j++)
		{
			/*if(s[i-1]=='I')dp[0][i][j]=dp[1][i-1][j]+1;
			else dp[1][i][j]=(dp[0][i-1][j]?dp[0][i-1][j]:-1)+1;
			if(t[j-1]=='I')dp[0][i][j]=max(dp[0][i][j],dp[1][i][j-1]+1);
			else dp[1][i][j]=max(dp[1][i][j],(dp[0][i][j-1]?dp[0][i][j-1]:-1)+1);
			cout<<dp[0][i][j]<<","<<dp[1][i][j]<<" ";
			M=max(M,dp[0][i][j]);
			if(s[i-1]=='I')
			{
				if(t[j-1]=='I')
				{
					dp[0][i][j]=max(dp[1][i-1][j],dp[1][i][j-1])+1;
				}
				else
				{
					dp[0][i][j]=dp[1][i-1][j]+1;
					dp[1][i][j]=max(dp[0][i][j-1],dp[0][i][j])+1;
				}
			}
			else
			{
				if(t[j-1]=='I')
				{
					dp[0][i][j]=dp[1][i][j-1]+1;
					dp[1][i][j]=max(dp[0][i-1][j],dp[0][i][j])+1;
				}
				else
				{
					dp[1][i][j]=max((dp[0][i-1][j]?dp[0][i-1][j]:-1)+1,(dp[0][i][j-1]?dp[0][i][j-1]:-1)+1);
				}
			}
			int res=0;
			if(s[i]=='I')res=max(res,dp[1][i-1][j]+1);
			if(t[j]=='I')res=max(res,dp[1][i][j-1]+1);
			dp[0][i][j]=res;
			res=0;
			if(s[i-1]=='O')res=max(res,dp[0][i-1][j]+1);
			if(t[j-1]=='O')res=max(res,dp[0][i][j-1]+1);
			dp[1][i][j]=res;*/
			if(i<m)
			{
				if(s[i]=='I')dp[0][i+1][j]=max(dp[0][i+1][j],dp[1][i][j]+1);
				else dp[1][i+1][j]=max(dp[1][i+1][j],dp[0][i][j]+1);
			}
			if(j<n)
			{
				if(t[j]=='I')dp[0][i][j+1]=max(dp[0][i][j+1],dp[1][i][j]+1);
				else dp[1][i][j+1]=max(dp[1][i][j+1],dp[0][i][j]+1);
			}
			//cout<<dp[0][i][j]<<","<<dp[1][i][j]<<" ";
			M=max(M,dp[0][i][j]);
		}
		//cout<<endl;
	}
	//cout<<endl;
	cout<<M<<endl;
}

Measured memory_bytes: 41768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string t;
    cin>>t;
    if(t.length()==(s.length()) +1)
    {
        string temp=t.substr(0,s.length());
        if(temp==s)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
      //  cout<<temp;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


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

bool compare_second(pair<int, int> a, pair<int, int> b) {
	if (a.second == b.second) return a.first > b.first;
	return a.second > b.second;
}

int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> A, B;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		int m = 0;
		int sum = 0;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == ')') {
				sum++;
				m = max(m, sum);
			} else {
				sum--;
			}
		}
		int x = m, y = m - sum;
		if (x == 0 && y == 0) continue;
		if (y - x >= 0) A.emplace_back(x, y);
		else B.emplace_back(x, y);
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end(), compare_second);
	A.insert(A.end(), B.begin(), B.end());
	int s = 0;
	for (auto p : A) {
		int x = p.first, y = p.second;
		if (s - x >= 0) {
			s = s - x + y;
		} else {
			cout << "No" << endl;
			return 0;
		}
	}
	if (s == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 18848
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

#define rep(i,n) for (int i=0; i < (n); ++i)
using namespace std;
using ll = long long ;
const int INF = 1001001001;

int main() {

    int k ;
    cin >> k ; 

    int x = 7%k ;
    set<int> s ;
    int ans = 1 ;
    while(s.count(x)==0){
        s.insert(x) ;
        if(x==0){
            cout << ans << endl ;
            return 0 ;
        }
        ans++ ;
        x = x*10+7 ;
        x = x%k ;
    }


    cout << -1 << endl;

    return 0 ;
}

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

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int A, B;
    cin >> A >> B;
    bool ans[4] = {true, true, true, true};
    ans[A] = false;
    ans[B] = false;
    for (int i = 1; i < 4; i++) {
        if (ans[i]) {
            cout << i << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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



int main(){
    int n, W; cin >> n >> W;
    VI w(n), v(n);
    REP(i, n) cin >> w[i] >> v[i];
    //i番目(1-order)まで, 　重さj で価値最大値
    vector<VLL> dp(n+1, VLL(W+1, 0));
    REP(i, n){
        REPS(j, W){
            if(j - w[i] >= 0)
                chmax(dp[i+1][j], dp[i][j-w[i]]+v[i]);

            chmax(dp[i+1][j], dp[i][j]);
        }
    }
    cout << dp[n][W] << "\n";
    return 0;
}


Measured memory_bytes: 80256
#include<iostream>
using namespace std;
int n,m;
bool check(string a[],string b[],int sx,int sy){
  for(int i=0;i<m;i++){
    for(int j=0;j<m;j++){
      if(a[sx+i][sy+j]!=b[i][j])return false;
    }
  }
  return true;
}
int main(){
  cin >> n >> m;
  string a[n],b[m];
  bool ans=false;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<m;i++){
    cin >> b[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i+m<=n&&j+m<=n){
        ans = check(a,b,i,j);
        if(ans) break;
      }
    }
    if(ans) break;
  }
  if(ans) cout <<"Yes\n";
  else cout <<"No\n";
}


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

ll nck(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

bool check(string s,int n,int m){
    string t=s.substr(n-1,m);
    string u=s.substr(n-1,m);
    reverse(u.begin(),u.end());
    //cout<<t<<endl;
    //cout<<u<<endl;
    if(u==t) return true;
    else return false;
}

int main(){
    //A
    /*
    int N,M;cin>>N>>M;
    if(N<=1&&M<=1) cout<<0<<endl;
    else cout<<nck(N,2)+nck(M,2)<<endl;
    */
   //B
   string s;cin>>s;
   int N=s.size();
   //string p="akasaka";
   //cout<<p.substr(5,7)<<endl;
   if(check(s,1,N)&&check(s,1,(N-1)/2)&&check(s,(N+3)/2,N-(N+3)/2+1))
        cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 256
// 26/01/20 // 12:19 PM //

#include <bits/stdc++.h>

using namespace std;

#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long

const int MAXN = (int)(3e3) + 10;

int n, a[MAXN];
int memo[2][MAXN];

int32_t main(){
    fastio;

    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];

    for(int l=n; l>=1; l--){
        for(int r=l; r<=n; r++){
            if(((r-l+1)&1)==(n&1))
                memo[l&1][r] = max(a[l] + memo[~l&1][r], a[r] + memo[l&1][r-1]);
            else
                memo[l&1][r] = min(memo[~l&1][r] - a[l], memo[l&1][r-1] - a[r]);
        }
    }

    cout << memo[1][n] << endl;

    return 0;
}



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

typedef vector<int> veci;
typedef pair<int,int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9+7)
#define fi first
#define se second

int main()
{
    ios::sync_with_stdio(false);
#ifdef LOCAL_TEST    
    int tcs;
    cin >> tcs;
    while (tcs-->0)
#endif        
{
    int n;
    cin >> n;

    int num;
    veci res;
    for (int i=0; i<n; ++i) {
        cin >> num;
        if (i%2==0) {
            res.push_back(num);
        } else {
            res.insert(res.begin(),num);
        }
    }

    if (n%2==0) {
        for (int i=0; i<int(res.size()); ++i)
            cout << res[i] << " \n"[i==int(res.size())-1];
    } else {
        for (int i=int(res.size())-1; i>=0; --i)
            cout << res[i] << " \n"[i==0];
    }
}}

Measured memory_bytes: 3188
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(n):
    s = 0
    for i in range(n):
        s+=(i+1)
    return s

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    return int(line)

def main():
    n = readQuestion()
    answer = solve(n)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
	long N;
	cin >> N;
	int A[1000001];
	for(int i=0;i<=1000000;i++){
		A[i] = 0;
	}
	long NC = N;
	for(int i = 2;i<=1000000;i++){
		while(NC % i == 0){
			NC /= i;
			A[i]++;
		}
		if(NC == 1) break;
	}
	int ans = 0;
	for(int i = 2;i<=1000000;i++){
		int j=1;
		while(A[i] >= j){
			A[i] -= j;
			ans++;
			j++;
		}
	}
	if(NC != 1)ans++;
	cout << ans << endl;
}


Measured memory_bytes: 7548
#include <stdio.h>

int main() {
	int a[4], b[4];
	int hit, blow;

	int i, j;

	while(scanf("%d", &a[0]) != EOF) {

		hit = 0;
		blow = 0;

		for(i = 1; i < 4; i++)
			scanf("%d", &a[i]);
		for(i = 0; i < 4; i++)
			scanf("%d", &b[i]);

		for(i = 0; i < 4; i++)
			for(j = 0; j < 4; j++)
				if(a[i] == b[j])
					blow++;

		for(i = 0; i < 4; i++)
			if(a[i] == b[i]) {
				hit++;
				blow--;
			}

		printf("%d %d\n", hit, blow);
	}

	return 0;
}

Measured memory_bytes: 596
//B - Choose Integers
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef unsigned long long ull;

int main(){
    int a , b , c;
    cin >> a >> b >> c;
    for(int i=a;i<=a*b ;i+=a){
        if( i%b == c ) { cout << "YES" << endl; return 0;}
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <stdio.h>
#include <iomanip>

using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){

    int M, D;
    cin >> M >> D;

    ll ans = 0;
    for(int m = 1; m <= M; m++){
        for(int d = 1; d <= D; d++){
            int d1 = d / 10;
            int d2 = d % 10;
            if(d1 >= 2 && d2 >= 2 && d1 * d2 == m){
                ans ++ ;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  double ans_bunbo = 0;
  
  for(int i=0; i<N; i++){
    cin >> A.at(i);
    ans_bunbo += 1.0 / A.at(i);
  }
  double ans = 1.0 / ans_bunbo;
  printf("%f", ans);
}




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

typedef long long int   ll;
#define int             ll
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
#define scan(n)         scanf("%lld",&n)
#define pb              push_back
#define PI              3.1415926535897932384626433832795
#define rep0            for(int i=0;i<n;i++)
#define rep1            for(int i=1;i<=n;i++)
#define inputar0(ar)    for(int i=0;i<n;i++)cin>>ar[i]
#define inputar1(ar)    for(int i=1;i<=n;i++)cin>>ar[i]
#define showar0(ar)     for(int i=0;i<n;i++)cout<<ar[i]<<" "
#define showar1(ar)     for(int i=1;i<=n;i++)cout<<ar[i]<<" "
int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
int binpow(int a,int b){int res=1;while(b>0){if(b%2){res=(res*a);b--;}a=(a*a);b/=2;}return res;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}
int mul(int a,int b){return ((a%mod)*(b%mod))%mod;}

int ar[10008];

void fun(){
    for(int a=1;a<100;a++){
        for(int b=1;b<100;b++){
            for(int c=1;c<100;c++){
                int x=a*a+b*b+c*c+a*b+b*c+c*a;
                if(x<=10000)
                    ar[x]++;
            }
        }
    }
}

signed main(){
    int t=1;
//    scan(t);
    fun();
    while(t--){
        int n;cin>>n;
        for(int i=1;i<=n;i++){
            cout<<ar[i]<<endl;
        }
    }
}


Measured memory_bytes: 3708
open System
open System.Collections.Generic

module InputUtility =
    let InputTokens = new Queue<string>()

    let EnsureInput () =
        if InputTokens.Count = 0 then
            let input = Console.ReadLine ()
            let s = input.Split ([|' '|], StringSplitOptions.RemoveEmptyEntries)
            if s.Length > 0 then
                for x in s do InputTokens.Enqueue(x)
                true
            else false
        else true

    let rec ReadNext () =
        if EnsureInput () then InputTokens.Dequeue ()
        else ReadNext ()

    let ReadNextInt () = ReadNext () |> int

    let Read2Int () = ReadNextInt (), ReadNextInt ()

    let Read3Int () = ReadNextInt (), ReadNextInt (), ReadNextInt ()

    let ReadListOf f n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop ((ReadNext () |> f) :: acc) (c-1)
        loop [] n

    let MultipleCaseWithId f =
        let caseNum = ReadNextInt ()
        let rec loop index =
            if index = caseNum then ()
            else
                f index
                loop (index + 1)
        loop 0

    let MultipleCase f = MultipleCaseWithId (fun _ -> f ())

    let ReadList n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop (ReadNext () :: acc) (c-1)
        loop [] n

open InputUtility

module _2017QualA =
    let private toBoolStr b = if b then "Yes" else "No"

    let private allPairs s1 s2 = seq { for a in s1 do for b in s2 do yield (a, b) }

    let private fLIP () =
        let n, m, k = Read3Int ()
        let check (a, b) = a * n + b * m = k + 2 * a * b
        allPairs [0..m] [0..n]
        |> Seq.exists check
        |> toBoolStr |> printfn "%s"

    let Entry = fLIP

_2017QualA.Entry ()

Measured memory_bytes: 16328
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
 
string solve(string s)
{
    int n = s.size();
    for(;;){
        for(int i=0; i<n; ++i){
            if('a' <= s[i] && s[i] <= 'z'){
                if(s[i] == 'z')
                    s[i] = 'a';
                else
                    ++ s[i];
            }
        }
        istringstream iss(s);
        string s1;
        while(iss >> s1){
            if(s1 == "the" || s1 == "this" || s1 == "that")
                return s;
        }
    }
}
 
int main()
{
    for(;;){
        string s;
        getline(cin, s);
        if(s == "")
            return 0;
 
        cout << solve(s) << endl;
    }
}


Measured memory_bytes: 3220
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	int a;
	int v;
	int a_max = 21;
	int v_max = 0;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d %d", &a, &v);
		if (v_max < v){
			v_max = v;
			a_max = a;
		}
		else if (v_max == v && a_max > a){
			a_max = a;
		}
	}
	
	printf("%d %d\n", a_max, v_max);
	
	return (0);
}

Measured memory_bytes: 600
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

int main() {
  //input
  long N;
  cin >> N;
  
  //main
  
  //output
  long ans = (1+N-1)*(N-1)/2;
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 

using namespace std;



int main(){

    int sx,sy,tx,ty;

    cin >> sx >> sy >> tx >> ty;

    string s;

    s = s + string(tx - sx, 'R');
    s = s + string(ty - sy, 'U');
    s = s + string(tx - sx, 'L');
    s = s + string(ty - sy, 'D');
    s = s + "D";
    s = s + string(tx - sx + 1, 'R');
    s = s + string(ty - sy + 1, 'U');
    s = s + "LU";
    s = s + string(tx - sx + 1, 'L');
    s = s + string(ty - sy + 1, 'D');
    s = s + "R";

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
d_a = input().split()

d = []
for i in range(n):
    d.append(int(d_a[i]))

ans = 0
for i in range(1,n-1):
    a = []
    a.append(d[i-1])
    a.append(d[i])
    a.append(d[i+1])
    
    asd = sorted(a)
    if asd[1] == d[i]:
        ans += 1
        

print(ans)



Measured memory_bytes: 3064
import numpy as np

a = input()
b = input()
c = input()
d = input()
e = input()

l = np.array(list(map(int, [a[-1], b[-1], c[-1], d[-1], e[-1]])))

idx = np.argmin(np.where(l == 0, 10, l))

times = list(map(int, [a, b, c, d, e]))

ans = 0
for i, t in enumerate(times):
  if i == idx:
    ans += t
  else:
    ans += np.ceil(t/10) * 10

print(int(ans))

Measured memory_bytes: 12396
//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];

void solve(){
    ll n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    vector<ll> dp(N, inf);
    dp[1] = 0;
    for(int i = 2; i <= n; ++i){
        for(int j = 1; j <= k; ++j){
            if(i > j)   dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
        }
    }
    cout << dp[n];
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro

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

int main(){
    ll N,W; cin >> N >> W;
    ll w[101],v[101]; rep(i,N) cin >> w[i] >> v[i];
    ll dp[110][100010] = {0}; // i個目までの価値の最大値，重さ
    
    for (int i = 1; i <= N; i++)
    {
        for (int sum = 0; sum <= W; sum++)
        {
            if(sum - w[i-1] >= 0){
                dp[i][sum] = max(dp[i][sum],dp[i-1][sum-w[i-1]] + v[i-1]);
            }
            dp[i][sum] = max(dp[i][sum],dp[i-1][sum]);
        }
    }
    
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 86144
module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

let read_int () = sf "%d " (fun x -> x)
let read_float () = sf "%f " (fun x -> x)
let read_str () = sf "%s " (fun x -> x)
let read_array read n = A.init n (fun _ -> read ())
let err s = raise (Failure s)

let range s t = A.init (t - s) @@ (+) s
let foreach fold_f init s t map_f =
  range s t |> A.map map_f |> A.fold_left fold_f init

let inf = int_of_float 1e18
let eps = 1e-11

module S = struct
  include String
  let of_array a = String.init (A.length a) (A.get a)
  let to_array s = A.init (String.length s) (String.get s)
end;;

let rec lucas hash x =
  if x = 0 then 2 else
  if x = 1 then 1 else
  if Hashtbl.mem hash x then Hashtbl.find hash x else
  let res = lucas hash (x - 1) + lucas hash (x - 2) in
  Hashtbl.add hash x res; res

let () =
  let n = read_int () in
  let hash = Hashtbl.create 10000 in
  pf "%d\n" @@ lucas hash n


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

int main(void){
    int N;
    cin>>N;
    vector<int> s(N);
    vector<int> noten;
    int sum = 0;
    for (int i=0;i<N;i++) {
        cin>>s[i];
        sum += s[i];
        if (s[i]%10!=0) noten.push_back(s[i]);
    }
    if (sum%10 != 0) {
        cout<<sum<<endl;
        return 0;
    }
    sort(noten.begin(),noten.end());
    if (noten.size()==0) {
        cout<<0<<endl;
    }
    else {
        cout<<sum-noten[0]<<endl;
    }

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld eps = 1e-12;
constexpr int inf = numeric_limits<int>::max() / 2;
constexpr int mod = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  ld r;
  cin >> r;
  cout << fixed << setprecision(10) << 2 * r * acos(-1.0) << endl;
}


Measured memory_bytes: 3808
#include<cstdio>
using namespace std;
int main(){
    int v;
    scanf("%d",&v);
    for(int q = 0;q < v; q++){
	int x,y,w,h;
    	scanf("%d%d%d%d",&x,&y,&w,&h);
    	w += x;
    	h += y;
        int n;
        scanf("%d",&n);
        int ans = 0;
        for(int i = 0;i < n; i++){
            int nx,ny;
            scanf("%d%d",&nx,&ny);
            if(x <= nx && nx <= w && y <= ny && ny <= h){
                ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1028
import java.util.*;
import java.io.*;
import java.text.*;
//Solution Credits: Taranpreet Singh
public class Main{
    //SOLUTION BEGIN
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int n = ni();
        double[][] prob = new double[1+n][1+n/2];
        prob[0][0] = 1.0;
        for(int i = 1; i<= n; i++){
            double p = 1-nd();
            for(int j = 0; j<= n/2; j++)prob[i][j] = (j>0?prob[i-1][j-1]:0)*p+prob[i-1][j]*(1-p);
        }
        double ans = 0.0;
        for(int i = 0; i<= n/2; i++)ans+=prob[n][i];
        pn(df.format(ans));
    }
    //SOLUTION END
    void hold()throws Exception{throw new Exception("Hold right there, Sparky!");}
    long mod = (long)1e9+7, IINF = (long)4e18;
    final int INF = (int)2e9, MX = (int)1e6+1;
    DecimalFormat df = new DecimalFormat("0.000000000000000");
    double PI = 3.1415926535897932384626433832792884197169399375105820974944, eps = 1e-8;
    static boolean multipleTC = false, memory = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        int T = (multipleTC)?ni():1;
        //Solution Credits: Taranpreet Singh
        pre();for(int i = 1; i<= T; i++)solve(i);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n(){return in.next();}
    String nln(){return in.nextLine();}
    int ni(){return Integer.parseInt(in.next());}
    long nl(){return Long.parseLong(in.next());}
    double nd(){return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }  
            return str;
        }
    }
}    

Measured memory_bytes: 82640
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define all(v) v.begin(), v.end()
  #define mod INT_MAX 
  int32_t main()
  { 
    /*#ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
    
    IOS
    int n;
    cin>>n;
    vector<int> v(n,0);
    for(int i=0;i<n;i++)
      {cin>>v[i];v[i]--;}
    int now=0,cnt=0;
    for( ; ;)
    {
      //on reaching button 2 break;
      if(now==1)
        {
          cout<<cnt;
          break;
        }
       cnt++;
       if(cnt>=n)
       {
        cout<<"-1";

        break;
       }
       now=v[now];
     //similar to finding parent or root in DSU
      //no need for hashmap in this implementation
     
    }
   
    return 0;
  }
    

Measured memory_bytes: 1024
sx, sy, tx, ty = map(int, input().split())

x = tx - sx
y = ty - sy

s = 'U'*y + 'R'*x +'U' + 'L'* (x+1) + 'D'*(y+1) + 'R'
s += 'R'*x + 'U'*y +'R' + 'D'* (y+1) + 'L'*(x+1) + 'U'
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#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 namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  string s="ABC", t;
  cin >> t;
  s += t;
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3572
S = input()
K = int(input())

i=0
a=0

while i<len(S):
  if i==len(S)-1:
    #open end
    break
  if S[i]==S[i+1]:
    a += 1
    i += 2
  else:
    i += 1
else:
  print(a*K)
  exit()
  
i=-1
b=0

while i<len(S):
  if i==len(S)-1:
    #open end
    print(a+b*(K-1))
    exit()
  if S[i]==S[i+1]:
    b += 1
    i += 2
  else:
    i += 1
else:
  print(a*((K+1)//2) + b*((K-1)//2))
  exit()

Measured memory_bytes: 3064
n, m = map(int, input().split())
double_dimension = [[0]*n for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    double_dimension[a-1][b-1] += 1
    double_dimension[b-1][a-1] += 1
for i in range(n):
    print(sum(double_dimension[i]))

Measured memory_bytes: 3060
#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 <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

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

  vector<ll> H(N);
  rep(i, N) cin >> H[i];

  bool judge = true;

  for(int i = N-1; i > 0; i--){
    if (H[i] >= H[i-1]) continue;
    else if (H[i] + 1 == H[i-1]){
      H[i-1] -= 1;
      continue;
    }
    else{
      judge = false;
      break;
    }
  }

  if(judge) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int N;
	scanf("%d",&N);
	int A[N];
	int i;
	for(i = 0; i < N; i++)
	{
		scanf("%d",&A[i]);
	}
	int w = 0;
	int max = 0;
	int max_2 = 0;
	int max_i;
	int max_2_i;
	for(i = 0;i<N;i++)
	{
		if(max < A[i]){
			max = A[i];
			max_i = i;
		}
	}
	for(i = 0; i < N; i++)
	{
		if(max == A[i] && i != max_i)
		{
			w = 1;
		}
		else if(max_2 < A[i] && i != max_i)
		{
			max_2 = A[i];
			max_2_i = i;
		}
	}
	if(w == 0)
	{
		for(i = 0; i < N; i++)
		{
			if(max_i == i) printf("%d\n",max_2);
			else printf("%d\n",max);
		}
	}
	else
	{
		for(i = 0; i < N; i++)
		{
			printf("%d\n",max);
		}
	}
	
	return 0;
}

Measured memory_bytes: 2304