akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll dp[100050];
bool ng[100500];
ll N;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    ll M;
    cin >> M;
    while(M--) {
        ll in;
        cin >> in;
        ng[in] = true;
    }
    dp[0] = 1;
    dp[1] = 1;
    if(ng[1]) dp[1] = 0;
    for(int i = 2; i <= N; i++) {
        if(ng[i]) continue;
        dp[i] = (dp[i-2] + dp[i-1]) % mod;
        cerr << i << " " << dp[i] << endl;
    }
    cout << dp[N] << endl;
    return 0;
}


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

int main()
{   int a,b,c,d,n,k,i,j,x,y;
   scanf("%d %d %d %d",&a,&b,&c,&d);x=abs(a-c);
   y=abs(b-d);
   if(a>=c&&b>=d){
   
   n=c+(y);
   k=d-(x);
   i=a+y;
   j=b-x;
   }else if(a>=c&&b<=d){
    n=c-(y);
   k=d-(x);
   i=a-y;
   j=b-x;
   }else if(a<=c&&b>=d){
    n=c+(y);
   k=d+(x);
   i=a+y;
   j=b+x;   
   }else{
      n=c-(y);
   k=d+(x);
   i=a-y;
   j=b+x; 
   }
   printf("%d %d %d %d",n,k,i,j);
   return 0;
}



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

typedef pair<int, int> P;

#define ft first
#define sd second

int h, w;
int n;
long long res[10];
P p[100055];
set<P> s;
set<P> used;

void go(int x, int y) {
	if (x < 1 || x + 2 > h || y < 1 || y + 2 > w) return;
	if (used.find(P(x, y)) != used.end()) return;

	used.insert(P(x, y));

	int cnt = 0;

	for (int i = x; i <= x + 2; i++) {
		for (int j = y; j <= y + 2; j++) {
			if (s.find(P(i, j)) != s.end()) {
				cnt++;
			}
		}
	}

	res[cnt]++;
}
int main() {
	scanf("%d %d", &h, &w);
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d %d", &p[i].ft, &p[i].sd);
		s.insert(p[i]);
	}

	for (int i = 0; i < n; i++) {
		for (int x = p[i].ft - 2; x <= p[i].ft; x++) {
			for (int y = p[i].sd - 2; y <= p[i].sd; y++) {
				go(x, y);
			}
		}
	}

	long long sum = 0;

	for (int i = 1; i < 10; i++) sum += res[i];

	res[0] = 1ll * (h - 2) * (w - 2) - sum;

	for (int i = 0; i < 10; i++) printf("%lld\n", res[i]);

	return 0;
}

Measured memory_bytes: 47872
#include<iostream>
using namespace std;
int n;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
int t[300][300],u[300][300];

void roll(int d[],int dir){
  int tmp[6],z;
  for(int i=1;i<=6;i++){
    tmp[d[i]]=i;
  }

  if(dir==0){
    z=tmp[0];
    tmp[0]=tmp[3];
    tmp[3]=tmp[5];
    tmp[5]=tmp[1];
    tmp[1]=z;
    for(int i=0;i<6;i++)d[tmp[i]]=i;
  }else if(dir==1){
    z=tmp[0];
    tmp[0]=tmp[4];
    tmp[4]=tmp[5];
    tmp[5]=tmp[2];
    tmp[2]=z;
    for(int i=0;i<6;i++)d[tmp[i]]=i;
  }else if(dir==2){
    roll(d,0);roll(d,0);roll(d,0);
  }else if(dir==3){
    roll(d,1);roll(d,1);roll(d,1);
  }
}

void rec(int y,int x,int d[]){
  int dir,ny,nx;
  

  for(int i=6;i>=4;i--){
    dir=d[i]-1;
    ny=y+dy[dir],nx=x+dx[dir];
    if(dir<0||4<=dir)continue;
    if(ny<0||nx<0)continue;
    if(ny>201||nx>201)continue;


    if(u[ny][nx]<u[y][x]){
      roll(d,dir);
      rec(ny,nx,d);
      return;
    }
  }


  for(int i=1;i<=6;i++)
    if(d[i]==0)t[y][x]=i;
  u[y][x]++;
}

void init(){
  for(int i=0;i<300;i++)
    for(int j=0;j<300;j++)
      t[i][j]=u[i][j]=0;
}

void printf(){
  cout<<"============================="<<endl;
  for(int i=147;i<=152;i++){
    for(int j=147;j<=152;j++){
      cout<<t[i][j]<<' ';
    }
    cout<<endl;
  }
  cout<<"============================="<<endl;
}
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>>a>>b;
      if(a==1){
	if(b==2)c=3;
	else if(b==3)c=5;
	else if(b==4)c=2;
	else if(b==5)c=4;
      }else if(a==2){
	if(b==1)c=4;
	else if(b==3)c=1;
	else if(b==4)c=6;
	else if(b==6)c=3;
      }else if(a==3){
	if(b==1)c=2;
	else if(b==2)c=6;
	else if(b==5)c=1;
	else if(b==6)c=5;
      }else if(a==4){
	if(b==1)c=5;
	else if(b==2)c=1;
	else if(b==5)c=6;
	else if(b==6)c=2;
      }else if(a==5){
	if(b==1)c=3;
	else if(b==3)c=6;
	else if(b==4)c=1;
	else if(b==6)c=4;
      }else {
	if(b==2)c=4;
	else if(b==3)c=2;
	else if(b==4)c=5;
	else if(b==5)c=3;
      }
      
      int d[7];
      //  cout<<a<<b<<c<<endl;
      d[a]=0;
      d[b]=1;
      d[c]=2;
      d[7-b]=3;
      d[7-c]=4;
      d[7-a]=5;
      rec(150,150,d);

      //printf();
     
    }
    int ans[7]={};

    for(int i=0;i<300;i++)
      for(int j=0;j<300;j++)
	ans[t[i][j]]++;

    for(int i=0;i<6;i++){
      if(i)cout<<' ';
      cout<<ans[i+1];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1868
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(vector<int>& A, vector<int>& B, int m) {

        int n = A.size();
        vector<vector<int>> jobs(m + 1);
        for (int i = 0; i < n; ++i) {
            if (A[i] <= m) {
                jobs[m - A[i]].push_back(B[i]);
            }
        }

        multiset<int,greater<int>> M;
        long long res = 0;
        for (int i = m - 1; i >= 0; --i) {
            for (auto x : jobs[i]) {
                M.insert(x);
            }
            if (!M.empty()) {
                res += *M.begin();
                M.erase(M.begin());
            }
        }

        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    vector<int> B(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i] >> B[i];
    }

    Solution sol;

    cout << sol.solve(A, B, m) << "\n";

    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s;

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

    cin >> n;
    ll board[2][n];
    rep(i, 2){
        rep(j, n){
            cin >> board[i][j];
        }
    }
    rep(i, n){
        cnt = 0;
        rep(j, n){
            if(j < i){
                cnt += board[0][j];
            }else if(j == i){
                cnt += board[0][j];
                cnt += board[1][j];
            }else{
                cnt += board[1][j];
            }
        }
        mx = max(mx, cnt);
    }
    cout << mx << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = scn.nextInt();
		}
		int tmp;
		int count = 0;
		for (int i = 0; i < num.length; i++) {
			int minj = i;
			for (int j = i; j < num.length; j++) {
				if (num[j] < num[minj]) {
					minj = j;
				}
			}
			if (num[minj] != num[i]) {
				int temp = num[i];
				num[i] = num[minj];
				num[minj] = temp;
				count++;
			}
		}
		StringBuilder sb = new StringBuilder();
		for (int a = 0; a < num.length - 1; a++) {
			sb.append(num[a] + " ");
		}
		System.out.println(sb.append(num[num.length - 1]).toString());
		System.out.println(count);
	}
}



Measured memory_bytes: 26348
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

typedef long long LL;
static LL INF = (1LL<<62);

int lbound(vector<long long>&v, long long b){
	int s = 0, e = v.size() - 1;
	int l = v.size();
	int m;
	while(e - s > 1){
		m = (s + e) / 2;
		if(v[m] >= b){
			e = m;
		}
		else{
			s = m;
		}
	}
	if(v[max(s - 1, 0)] >= b) return max(s - 1, 0);
	else if(v[s] >= b) return s;
	else if(v[min(s + 1, l - 1)] >= b) return min(s + 1, l - 1);
	else return v.size();
}

LL A, B, Q;
vector<LL> S, T;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> A >> B >> Q;

	for(int i=0; i<A; i++){
		LL s;
		cin >> s;
		S.push_back(s);
	}

	for(int i=0; i<B; i++){
		LL t;
		cin >> t;
		T.push_back(t);
	}
	
	sort(S.begin(), S.end());
	sort(T.begin(), T.end());

	for(int i=0; i<Q; i++){
		LL x;
		cin >> x;

		LL d1 = 0, d2 = 0, d3 = 0, d4 = 0;;
		int ps, pt;

		ps = lbound(S, x);
		pt = lbound(T, x);
		if( ps == S.size() || pt == T.size() ){
			d1 = INF;
		}
		else{
			ps = min(lbound(S, x), (int)S.size()-1);
			pt = min(lbound(T, x), (int)T.size()-1);
			d1 += max(abs(S[ps]-x), abs(T[pt]-x));
		}

		if(x < S[0] || x < T[0]){
			d2 = INF;
		}
		else{
			ps = max(lbound(S, x) - 1, 0);
			pt = max(lbound(T, x) - 1, 0);
			d2 += max(abs(S[ps]-x), abs(T[pt]-x));
		}

		ps = lbound(S, x);
		pt = lbound(T, x);
		if(ps == S.size() && pt == T.size()){
			d3 = INF;
		}
		else if(ps == S.size()){
			d3 += abs(T[pt] - x);
			d3 += abs(S[ps-1] - T[pt]);
		}
		else if(pt == T.size()){
			d3 += abs(S[ps] - x);
			d3 += abs(T[pt-1] - S[ps]);
		}
		else{
        	ps = min(lbound(S, x), (int)S.size()-1);
        	pt = min(lbound(T, x), (int)T.size()-1);
        	if(S[ps] < T[pt]){
        		d3 += abs(S[ps] - x);
        		int p = max(lbound(T, S[ps]) - 1, 0);
        		d3 += abs(T[p] - S[ps]);
        	}
        	else{
        		d3 += abs(T[pt] - x);
        		int p = max(lbound(S, T[pt]) - 1, 0);
        		d3 += abs(S[p] - T[pt]);
        	}
		}

		ps = lbound(S, x);
		pt = lbound(T, x);
		if(x < S[0] && x < T[0]){
			d4 = INF;
		}
		else if(x < S[0]){
			d4 += abs(T[pt-1] - x);
			d4 += abs(S[0] - T[pt-1]);
		}
		else if(x < T[0]){
			d4 += abs(S[ps-1] - x);
			d4 += abs(T[0] - S[ps-1]);
		}
		else{
        	ps = lbound(S, x) - 1;
        	pt = lbound(T, x) - 1;
        	if(S[ps] > T[pt]){
        		d4 += abs(S[ps] - x);
        		int p = min(lbound(T, S[ps]), (int)T.size() - 1);
        		d4 += abs(T[p] - S[ps]);
        	}
        	else{
        		d4 += abs(T[pt] - x);
        		int p = min(lbound(S, T[pt]), (int)S.size() - 1);
        		d4 += abs(S[p] - T[pt]);
        	}
		}

		LL ans = min(d1, min(d2, min(d3, d4)));
		printf("%lld\n", ans);
	}
	return 0;
}

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

using namespace std;

using ll = long long;

bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b){
    return (a.second < b.second);
}

int main(){
    ll n; cin >> n;
    vector<pair<ll, ll>> v;
    for(ll i = 0; i < n; ++i){
        ll a, b; cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    sort(v.begin(), v.end(), sortbysec);
    ll cur = 0;
    for(ll i = 0; i < n; ++i){
        if(cur + v[i].first <= v[i].second){
            cur += v[i].first;
        }
        else{
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;

}


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

int main() {
    int n; cin >> n;
    int cnt = 0;
    auto dfs = [&](auto dfs, long long cur, int mask) {
        if (cur > n) return ;
        if (mask == 7) cnt++;
        dfs(dfs, cur * 10 + 7, mask | 4);
        dfs(dfs, cur * 10 + 5, mask | 2);
        dfs(dfs, cur * 10 + 3, mask | 1);
    };
    dfs(dfs, 0, 0);
    cout << cnt << endl;
    return 0;
}


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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int main() {
  long N, P; scanf("%ld%ld", &N, &P);
  map<long, long> primes;

  while (P % 2 == 0) {
    ++primes[2];
    P /= 2;
  }
  for (long i{3}; i * i <= P; i += 2) {
    while (P % i == 0) {
      ++primes[i];
      P /= i;
    }
  }
  if (P > 1) {
    ++primes[P];
  }

  long factor{1};
  for (auto& prime : primes) {
    for (long i{1}; N * i <= prime.second; ++i) {
      factor *= prime.first;
    }
  }

  printf("%ld\n", factor);
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
int gcd(int a,int b){
    if(b==0)return a;
    else return gcd(b,a%b);
}

int main(){
     int n;
     cin>>n;
     int ans=0;
     vector<int>a(n);
     rep(i,n)cin>>a[i];
     int x=a[0];
     rep(i,n-1){
         int y=a[i+1];
         x=gcd(x,y);
         ans=x;
     }
     cout<<ans<<endl;
}

Measured memory_bytes: 640
a, b, c, x = 4.times.map { gets.chomp.to_i }
cnt = 0 

(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      cnt += 1 if 500 * i + 100 * j + 50 * k == x
    end
  end
end

p cnt

Measured memory_bytes: 14372
using System;
using System.Linq;

namespace KEYENCE2020
{
    class A
    {
        static void Main(string[] args)
        {
            //long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            //long N = long.Parse(Console.ReadLine());
            //string S = Console.ReadLine();

            int H = int.Parse(Console.ReadLine());
            int W = int.Parse(Console.ReadLine());
            int N = int.Parse(Console.ReadLine());

            int count = 0;
            if (H <= W)
            {
                for (int i = 0; i < H; i++)
                {
                    count += W;
                    if (N <= count) { Console.WriteLine(i + 1); return; }
                }
            }
            else
            {
                for (int i = 0; i < W; i++)
                {
                    count += H;
                    if (N <= count) { Console.WriteLine(i + 1); return; }
                }

            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; cin >> n;
    if(n==1) cout << "Hello World" << endl;
    else{
        int a,b; cin >> a >> b;
        cout << a+b << endl;
    }
return 0;
}


Measured memory_bytes: 3576
sunukes, k = gets.split.map(&:to_i)

ary = Array.new(sunukes) { 0 }

k.times do |i|
  len = gets.to_i

  a = gets.split.map(&:to_i)
  a.each do |el|
    ary[el - 1] += 1
  end
end

puts ary.filter{|el| el == 0 }.count

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

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
	string s;
	cin>>s;
	int k=s.size();
	if(k<4)cout<<"No"<<endl;
	else {
		if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
/* ex4_3
    suuxxu */

#include <stdio.h>

int calculate(int numA, int numB);

int main(void){
    int heightA, heightB;

    // get inputs
    scanf("%d %d", &heightA, &heightB); // A B

    // output answer
    printf("%d\n", calculate(heightA, heightB));

    return 0;
}

int calculate(int numA, int numB){
    int diff, i, fact;

    diff = numB - numA;
    fact = 0;

    // calculate (diff)!
    for (i = 0; i < diff; i++){
        fact += i + 1;
    }

    // (diff)! is the actual height of the tower B
    return fact - numB;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(K):
    Imos = [0]*(N+1)
    for i, a in enumerate(A):
        Imos[max(0, i-a)] += 1
        Imos[min(N, i+a+1)] -= 1
    B = [0]*(N)
    b = 0
    for i in range(N):
        b += Imos[i]
        B[i] = b
    if A == B:
        break
    A = B

print(*A)

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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

vector<vector<ll>> dist;

void warshallFloyd(){
    int N = 10;
	rep(k,N)rep(i,N){
		if(dist[i][k] == LINF) continue;
		rep(j,N){
			if(dist[k][j] == LINF) continue;
			dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
		}
	}
}


int main(){
	int H,W; cin >> H >> W;
    dist.resize(10,vector<ll>(10));
    rep(i,10)rep(j,10){
        ll c; cin >> c;
        dist[i][j] = c;
    }
    
    warshallFloyd();
    
    ll ans = 0;
    rep(i,H)rep(j,W){
        int A; cin >> A;
        if(A != -1){
            ans += dist[A][1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
A = [0] + [int(_) for _ in input().split()] + [0]

costmax = abs(A[1])
costskip = []
for i in range(1, N + 1):
    costmax += abs(A[i + 1] - A[i])
    costskip += [abs(A[i+1] - A[i]) + abs(A[i] - A[i-1]) - abs(A[i+1]-A[i-1])]
[print(costmax - _) for _ in costskip]


Measured memory_bytes: 13792
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>

using ll = long long;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

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

int main() {
    int N;
    cin >> N;
    int A[N+1], B[N];
    for(int i = 0; i < N+1; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];

    ll count = 0;
    int now, next;

    for(int i = 0; i < N; i++) {
        if(B[i] > A[i]) {
            count += A[i];
            B[i] -= A[i];
            A[i] = 0;
            if (B[i] > A[i+1]) {
                count += A[i+1];
                B[i] -= A[i+1];
                A[i+1] = 0;
            } else {
                count += B[i];
                A[i+1] -= B[i];
                B[i] = 0;
            }
        } else {
            count += B[i];
            A[i] -= B[i];
            B[i] = 0;
        }
        
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1024
n=int(input())
s = [0]*n
for i in range(0,n):
  s[i]=str(input())
m=int(input())
t = [0]*m
for i in range(0,m):
  t[i]=str(input())
result=0
for i in range(0,n):
  p=s.count(s[i])-t.count(s[i])
  if p>result:
    result=p
print(result)


Measured memory_bytes: 3064
#include <stdio.h>
int x,i,f=0;
int main(){
    scanf("%d",&x);
    if(x==2){puts("2");return 0;}
    if(x%2==0)x++;
    while(f==0){
        f=1;
        for(i=3;i<=sqrt(x);i+=2)if(x%i==0)f=0;
        x+=2;
    }
    printf("%d",x-2);
    return 0;
}

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

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

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

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

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

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

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

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

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

signed main() {
  int N, W;
  cin >> N >> W;
  static int w[101010], v[101010];
  for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

  static int dp[110][101010];
  m0(dp);

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      if (j - w[i] < 0) {
        dp[i + 1][j] = dp[i][j];
      } else {
        dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
      }
    }
  }

  cout << dp[N][W] << endl;
  return 0;
}


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

int main(void) {
  string S;
  cin >> S;
  if(S.substr(0, 4) == "YAKI") cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 768
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    s = sys.stdin.readline().rstrip()
    s0 = s[0]
    s1 = s[1]
    if len(s) == 2 and s0 == s1:
        print(1,2)
        exit(0)

    for i in range(2,len(s)):
        x = s[i]
        if x == s0 or x == s1:
            print(i-1,i+1)
            exit(0)
        s0 = s1
        s1 = x

    print(-1,-1)


if __name__ == '__main__':
    main()

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : x;
}

string str;

bool check(long long n) {
	return (n & (n - 1)) == 0;
}

void hawawa()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

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


Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
int main()
{
	int a,b,c,x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	for(int i=0; i<=a; i++){
		for(int j=0; j<=b; j++){
			for(int k=0; k<=c; k++){
				if(500*i + 100*j + 50*k == x)
					ans++;
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int n;
    cin >> n;
    if(n%1000 == 0){
        cout << 0 << endl;
    }else{
        int temp = (n/1000)*1000;
        temp += 1000;
        cout << temp - n << endl;
    }
    
}






Measured memory_bytes: 3600
alist = [int(input())]
idx = 0
while 1:
  a = alist[idx]//2 if alist[idx] % 2 == 0 else int(alist[idx]*3 +1)
  idx += 1
  if a in alist: break
  else:
    alist.append(a)
print(idx+1)

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
using System.Linq;

static class DrawingLots
{
    static void Main()
    {
        var v = int.Parse( Console.ReadLine() );
        var h = int.Parse( Console.ReadLine() );

        Enumerable.Repeat<Func<string>>( Console.ReadLine, h )
            .Select( x => x().Split( ',' ).Select( int.Parse ) )
            .Select( Enumerable.ToArray )
            .Aggregate( Enumerable.Range( 1, v ), Sandwich )
            .ToList()
            .ForEach( Console.WriteLine );
    }

    static IEnumerable<int>
        Sandwich(IEnumerable<int> bans, int[] meat)
    {
        bans = bans.ToArray();
        foreach( var x in bans.Take( meat[0] - 1 ) )
            yield return x;
        yield return bans.ElementAt( meat[1] - 1 );
        foreach( var x in bans.Skip( meat[0] ).Take( meat[1] - meat[0] - 1 ) )
            yield return x;
        yield return bans.ElementAt( meat[0] - 1 );
        foreach( var x in bans.Skip( meat[1] ) )
            yield return x;
    }
}

Measured memory_bytes: 6028
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MOD 1000000007
// a^b mod MOD
ll powmod(ll a,ll b){
	ll out=1;
	ll p=a%MOD;
	while(b){
		if(b&1)out=out*p%MOD;
		p=p*p%MOD;
		b>>=1;
	}
	return out;
}
#define M 200010
vector<ll> fact;
void init(){
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// nCr
ll nCr(ll n,ll r){
	if(n<r)return 1;
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%MOD,MOD-2)%MOD;
	return out;
}
int main(){
	ll n,m,a,b;
	cin>>n>>m>>a>>b;
	ll out=0;
	init();
	rep(i,m-b){
		ll t=nCr(n-a+b+i-1,b+i);
		ll T=nCr(a-1+m-b-i-1,a-1);
		(out+=t*T%MOD)%=MOD;
	}
	cout<<out<<endl;
}








Measured memory_bytes: 1792
import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit = taskA

  def taskA(): Unit = {
    val r = sc.nextInt
    println(if (r < 1200) "ABC" else if (r < 2800) "ARC" else "AGC")
  }

  def taskB(): Unit = {
  }
}


Measured memory_bytes: 25524
#include <iostream>
#include <cstdio>

int main(){
    int W, H, N;
    int in[11100] = {};
    int ans[111][111];

    std::cin >> H >> W >> N;
    for(int i = 0; i < N; ++i){
        std::cin >> in[i];
    }

    int cnt = 1;
    for(int i = 0; i < H; ++i){
        if(i & 1){
            for(int j = W-1; j >= 0; --j){
                ans[i][j] = cnt;
                in[cnt-1]--;
                if(in[cnt-1] <= 0) cnt++;
            }
        }else{
            for(int j = 0; j < W; ++j){
                ans[i][j] = cnt;
                in[cnt-1]--;
                if(in[cnt-1] <= 0) cnt++;
            }
        }
    }

    for(int y = 0; y < H; ++y){
        for(int x = 0; x < W; ++x){
            std::cout << ans[y][x] << " ";
        }
        std::cout << std::endl;
    }
}


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

#define MAX 100000

int main() {
	int N, A[MAX], ans = 1;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int maxa, mina;
	maxa = INT_MIN;
	mina = INT_MAX;
	for (int i = 0; i < N - 1; i++) {
		maxa = max(maxa, A[i]);
		mina = min(mina, A[i]);
		if (maxa == mina)
			continue;
		if (A[i] == maxa && A[i] > A[i + 1]) {
			ans++;
			maxa = INT_MIN;
			mina = INT_MAX;
		} else if (A[i] == mina && A[i] < A[i+1]) {
			ans++;
			maxa = INT_MIN;
			mina = INT_MAX;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var D = one[0];
  var G = one[1] / 100;
  var plist = new Array(D);
  var blist = new Array(D);
  for(var i = 0; i < D; i++){
    var tmp = nextIntArray();
    plist[i] = tmp[0];
    blist[i] = tmp[1] / 100;
  }
  
  var min = 10000;
  var dp = new Array(G + 1).fill(min);
  //dp[i] = i点の時の最小正答数
  dp[0] = 0;
  for(var i = 0; i < D; i++){
    var count = plist[i];
    var bonus = blist[i];
    for(var j = G - 1; j >= 0; j--){
      for(var k = 1; k <= count; k++){
        var check = j + k * (i + 1);
        if(k == count){
          check += bonus;
        }
        var t = Math.min(G, check);
        dp[t] = Math.min(dp[t], dp[j] + k);
      }
    }
  }
  
  myout(dp[G]);
}


Measured memory_bytes: 34168
package main

import (
	"fmt"
)

func main() {
	var a string
	fmt.Scan(&a)

	if a == "Sunny" {
		fmt.Println("Cloudy")
	} else if a == "Cloudy" {
		fmt.Println("Rainy")
	} else {
		fmt.Println("Sunny")
	}
}

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

int main(){
  int n;
  vector<int> a;

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

  sort(a.begin(), a.end());

  bool ans = true;

  for(int i = 0; i < n-1; i++){
    if (a[i] == a[i+1]) ans = false;
  }

  if (ans) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#pragma GCC optimize ("O2")
#include<iostream>
using namespace std;
int main()
{
  int a;
  cin>>a;
  int asd[a+1],max1,max2;
  cin>>asd[1]>>asd[2];
  max1=max(asd[1],asd[2]);
  max2=min(asd[1],asd[2]);
  for(int i=3;i<=a;i++)
  {
  	cin>>asd[i];
  	if(asd[i]>max1)
  	{
  		max2=max1;
  		max1=asd[i];
  	}
  	else if(asd[i]>max2)max2=asd[i];
  }
  for(int i=1;i<=a;i++)
  {
  	if(asd[i]==max1)cout<<max2<<endl;
  	else cout<<max1<<endl;
  }
  return 0;
}

Measured memory_bytes: 2432
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: isize = iterator.next().unwrap().parse().unwrap();
    let t: isize = iterator.next().unwrap().parse().unwrap();

    return max(0, x - t).to_string();
}


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

int main() {
    double t, x;
    cin >> t >> x;

    double ans = t/x;
    printf("%.8f\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a) for(i = 0 ; i < a ; i++)
#define whln(t) while(t--)
#define whlp(t) while(t++)
ll i=0,j=0;


int main(void){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif
	ll x ;
	cin>>x ;

	if(x>=30)
		cout<<"Yes";
	else
		cout<<"No";
}
//   *****  *******   !
//   *		     *    !
//   ***       *      !
//   *       *        !
//   *****  *******   !

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include <queue>
using namespace std;
using ll = long long;

int N;
ll A[110000];

int main(void){

    ll ans = 0;
    ll B[110000] = {};

    cin >> N;
    for (int i = 1; i <= N;i++) cin >> A[i];
    ll max = 0;

    for (int i = 1; i <= N;i++) {
        B[A[i]]++;
        if (max < A[i]) max = A[i];
    }

    for (int i = 1; i <= max;i++){
        if (B[i] > 0) ans++;
    }

    if (ans % 2 == 0) ans--;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5280
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from sys import setrecursionlimit
from functools import lru_cache


def lcs(s1, s2):
    cost = [0]
    for c in s2:
        #print("c=", c)
        for i in reversed(range(len(cost))):
            index = s1.find(c, cost[i]) + 1
            if index:
                if i + 1 < len(cost):
                    cost[i + 1] = min(cost[i + 1], index)
                else:
                    cost.append(index)
            #print("i={}, index={}, cost={}".format(i, index, cost))
    return len(cost) - 1


def main():
    setrecursionlimit(10000)

    q = int(input())

    for _ in range(q):
        x = input()
        y = input()
        print(lcs(x, y))


if __name__ == '__main__':
    # print("TCCAGATGG")
    # print("TCACA")
    #print(lcs("TCCAGATGG", "TCACA"))
    main()



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

using namespace std;

int upcmp(const void *p,const void *q){
    return *(int*)p-*(int*)q;
}

int downcmp(const void *p,const void *q){
  return *(int*)q-*(int*)p;
}

int main(void){
  int N;
  cin >> N;
  if(N<=9){
    cout << N << endl;
  }
  else if(N>=10 && N<=99){
    cout << "9" << endl;
  }
  else if(N>=100 && N<=999){
    cout << N-90 << endl;
  }
  else if(N>=1000 && N<=9999){
    cout << "909" << endl;
  }
  else if(N>=10000 && N<=99999){
    cout << N-9090 << endl;
  }
  else{
    cout << "90909" << endl;
  }
}


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

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define loop(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define br                break
#define con               continue

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
 
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

priority_queue<pii, vector<pii>, greater<pii> >q;

#include<bits/stdc++.h>
using namespace std;
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output1.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
 
	int n,x,t;
	cin>>n>>x>>t;
	int ans = n/x;
	if(n%x)ans+=1;
	cout<<ans*t<<endl;
 
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 5232
import sys
input = sys.stdin.readline


def main():
    h, w = map(int, input().split())
    ch, cw = map(int, input().split())
    dh, dw = map(int, input().split())
    
    ch += 1
    cw += 1
    dh += 1
    dw += 1
    
    
    s = ["#"*(w+4)]
    s.append("#"*(w+4))
    for i in range(h):
        s.append("##" + input()[:-1] + "##")
    s.append("#"*(w+4))
    s.append("#"*(w+4))
    
    
    ans = [[-1]*(w+4) for _ in range(h+4)]
    for i in range(h+4):
        for j in range(w+4):
            if s[i][j] == "#":
                ans[i][j] = -2
    ans[ch][cw] = 0
    
    move = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    move2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), \
             (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2), \
             (0, -2), (0, -1), (0, 0), (0, 1), (0, 2), \
             (1, -2), (1, -1), (1, 0), (1, 1), (1, 2), \
             (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]
        
    not_yet = [(ch, cw)]
    one_time = []
    
    while len(not_yet) > 0:
        x, y = not_yet.pop()
        one_time.append((x, y))
        for (p, q) in move:
            v1, v2 = x+p, y+q
            if ans[v1][v2] == -1:
                not_yet.append((v1, v2))
                ans[v1][v2] = ans[x][y]
                
        if len(not_yet) == 0:
            while len(one_time) > 0:
                x2, y2 = one_time.pop()
                for (v1, v2) in move2:
                    i, j = x2+v1, y2+v2
                    if ans[i][j] == -1:
                        ans[i][j] = ans[x2][y2]+1
                        not_yet.append((i, j))
          
    print(ans[dh][dw])
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 84960
#include <stdio.h>
#include <vector>
#include <map>

auto solve(int N, int M) -> int
{
	using namespace std;
	vector<int> h(N);
	vector<int> w(M);

	for(int i = 0; i < N; i++)
	{
		int x;
		scanf("%d", &x);
		h[i] = x;
	}
	for(int i = 0; i < M; i++)
	{
		int x;
		scanf("%d", &x);
		w[i] = x;
	}

	map<int, int> eh;
	map<int, int> ew;
	for(int i = 0; i < N; i++)
	{
		int sum = 0;
		for(int j = i; j < N; j++)
		{
			sum += h[j];
			if(eh.find(sum) != ew.end())
				eh[sum]++;
			else
				eh[sum] = 1;
		}
	}
	for(int i = 0; i < M; i++)
	{
		int sum = 0;
		for(int j = i; j < M; j++)
		{
			sum += w[j];
			if(ew.find(sum) != ew.end())
				ew[sum]++;
			else
				ew[sum] = 1;
		}
	}

	int ans = 0;
	for(auto p : eh)
	{
		if(ew.find(p.first) != ew.end())
			ans += p.second * ew[p.first];
	}

	return ans;
}

auto main() -> int
{
	int n, m;
	while(1)
	{
		scanf("%d%d", &n, &m);
		if(!(n | m))
			break;
		printf("%d\n", solve(n, m));
	}
}

Measured memory_bytes: 27540
// code.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <bits/stdc++.h>


using namespace std;

int main()
{
long int h,n;
cin>>h>>n;
int a[n];
for(int i=0; i<n; i++){
	cin>>a[i];
}
int sum =0;
for(int i=0; i<n; i++){
	sum = sum+a[i];
}

if(h<=sum){
	cout<<"Yes";
}
else{
	cout<<"No";
}

}
	


Measured memory_bytes: 640
//  [amitdu6ey]
// g++ -std=c++11 -o2 -Wall filename.cpp -o filename
#include <bits/stdc++.h>
#define hell 1000000009
#define bug1(x) cout<<"$ "<<x<<" $"<<endl
#define bug2(x) cout<<"% "<<x<<" %"<<endl
#define bug3(x) cout<<"# "<<x<<" #"<<endl
#define ll long long
#define pb push_back
#define mp make_pair
#define tr(z) for(auto it=z.begin(); it!=z.end(); it++)
#define rloop(i,a,b) for(long long i=a; i>=b;i--)
#define loop(i,a,b) for(long long i=a; i<b; i++)
#define vbool vector< bool >
#define vvbool  vector< vector<bool> >
#define vchar vector<char>
#define vi vector<int>
#define vvi vector< vector<int> >
#define pll pair<long long, long long>
#define vll vector<long long>
#define vvl vector< vector<long long> >
#define ninf numeric_limits<long long>::min()
#define pinf numeric_limits<long long>::max()
#define comp(a,b) (abs(a-b)<1e-9) // to compare doubles
using namespace std;

void solve(){
    ll n, k;
    cin>>n>>k;
    vll h(n);
    loop(i,0,n) cin>>h[i];
    vll dp(n, pinf);
    dp[0] = 0;
    loop(i,1,n){
        loop(j,1,k+1){
            if(i-j < 0) continue;
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return;
}

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


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int N;
    double x[10], y[10];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i];
    }
    vector<int> v(N);
    iota(v.begin(), v.end(), 0);
    int count = 0;
    double dis = 0.0;
    do{
        for(int i = 1; i < N; i++){
            int prev = v[i-1], cur = v[i];
            dis += sqrt(pow(x[cur] - x[prev], 2) + pow(y[cur] - y[prev], 2));
        }
        count++;

    }while(next_permutation(v.begin(), v.end()));


    printf("%.10f\n", dis / (double)count);

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <limits>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
#define ll long long
#define rep(i_, start, end) for(ll i_=(ll)start; i_<(ll)end; i_++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");
 
int main(){
  ll n, k, r, s, p;
  ll ans = 0;
  char last;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  for (ll g=0; g<k; g++){
    last = '0';
    for (ll i=g; i<n; i+=k){
      if (t[i] == 'r'){
        if (last != 'r') {ans += p; last = 'r';}
        else last = '0';
      }else if (t[i] == 's'){
        if (last != 's') {ans += r; last = 's';}
        else last = '0';
      }else if (t[i] == 'p'){
        if (last != 'p') {ans += s; last = 'p';}
        else last = '0';
      }
    }
  }
  print(ans);
  
  return 0;
}

Measured memory_bytes: 512