akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define lint __int128
#define vi vector<int>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
#define pi 3.14159265358979323846264338327950
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    ll a , b , x ; cin >> a >> b >> x ;
    if(a == 0) cout << b / x  + 1 << endl ;
    else cout << b / x - (a - 1) / x << endl ;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[100010];

int main()
{
	int K;
	cin >> K;
	for (int i = 0; i < K; i++) cin >> A[i];
	ll ans = 2;
	for (int i = K - 1; i >= 0; i--) {
		ans = (ans + A[i] - 1) / A[i] * A[i];
	}
	ll num = ans;
	for (int i = 0; i < K; i++) {
		num -=  num % A[i];
	}
	if (num != 2) {
		cout << -1 << endl;
		return 0;
	}
	cout << ans << " ";
	ans = 2;
	for (int i = K - 1; i >= 0; i--) {
		ans = (ans / A[i] + 1) * A[i] - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		for(int n=0;n<N;n++) {
			int Year = sc.nextInt();
			int Month = sc.nextInt();
			int day = sc.nextInt();
			
			int count = 0;
			
			for(int i=Year;i < 1000;i++) {
				for(int j=Month;j <= 10;j++) {
					if(i % 3 != 0 && j % 2 == 0) {
						for(int k=day;k <= 19;k++) {
							count++;
						}
					}else{
						for(int k =day; k <=20 ; k++) {
							count++;
						}
					}
					day = 1;
				}
				Month = 1;
			}
			System.out.println(count);
		}
		sc.close();
	}

}


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

// 10^9
// 10^3 < 2^10
// 10^3 < 2^30

int log2(int x, int n) {
  int y = 1;
  for (int i = 1; i <= n; i++) {
    y *= 2;
    if (x % y != 0) {
      return i - 1;
    }
  }
  return n;
}

int main() {
  int n;
  cin >> n;
  int y = 30;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    int yy = log2(a, y);
    if (yy < y) {
      y = yy;
    }
  }
  cout << y << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define ll long long int

using namespace std;

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

    if(s.length()<= n) {
        cout << s << endl;
        return 0;
    }

    cout << s.substr(0, n) << "..." << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(){
int i,sum,pri;
while(1){
scanf("%d\n",&sum);
if(sum==0)break;
for(i=0;i<9;i++){
scanf("%d\n",&pri);
sum=sum-pri;
pri=0;
}
printf("%d\n",sum);
}
return 0;
}

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

const int INF = 1001001001;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n), c(m), d(m);
    rep(i, 0, n) cin >> a[i] >> b[i];
    rep(i, 0, m) cin >> c[i] >> d[i];
    vector<int> ans(n);
    rep(i, 0, n){
        int mn = INF;
        rep(j, 0, m){
            int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(dist < mn){
                mn = dist;
                ans[i] = j+1;
            }
        }
    }
    rep(i, 0, n) cout << ans[i] << endl;
    return 0;
}


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

int main(){
  int N; cin>>N;
  int sc[N]={};
  rep(i,N*(N-1)/2){
    int a,b,c,d; cin>>a>>b>>c>>d; 
    if(c>d) sc[a-1]+=3;
    else if(c<d) sc[b-1]+=3;
    else{ ++sc[a-1]; ++sc[b-1]; }
  }
  rep(i,N){
    int x=1;
    rep(j,N) if(j!=i && sc[i]<sc[j]) ++x;
    cout<<x<<endl;
  }
  return 0;
}

Measured memory_bytes: 3088
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  vl DP;
  ll count = 0;
  REP(i, S.size()) {
    if (i == 0 && S[i] == '0')
      DP.push_back(0);
    if (i > 0 && S[i] != S[i - 1]) {
      DP.push_back(count);
      count = 1;
    } else {
      count++;
    }
  }
  DP.push_back(count);

  ll right = 0;
  ll ans = 0;
  ll sum = 0;
  for (ll left = 0; left < DP.size(); left += 2) {
    while (right < DP.size() && (right - left) <= K * 2) {
      sum += DP[right];
      right += 1;
    }

    ans = max(ans, sum);
    // cout << left << "," << right << endl;

    if (right == left)
      right += 2;
    else {
      sum -= DP[left];
      sum -= DP[left + 1];
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
	int A,B,C,D;
	cin>>A>>B>>C>>D;
  
  int hidari =A+B;
  int migi =C+D;
  
  if(hidari<migi){
  cout<<"Right"<<endl;
  }
  
  else if(hidari==migi){
  cout<<"Balanced"<<endl;
  }
  
  else{
  cout<<"Left"<<endl;
  }
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};


struct Solver {
  std::array<std::string, 3> xs; 
  Solver() {
    S002 reader;
    reader >= xs;
  }
  void solve() {
    for(long i = 0; i < 3; ++i) {
      printf("%c", xs[i][0] - 'a' + 'A');
    }
    printf("\n");
  }    
  ~Solver() { fprintf(stderr, "--end--\n"); }
};
 

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	long n,a,b;
	cin>>n>>a>>b;
	if(a>b)cout<<0<<endl;
	else if(a==b)cout<<1<<endl;
	else if(n<2)cout<<0<<endl;
	else if(n<3)cout<<1<<endl;
	else cout<<(n-2)*(b-a)+1<<endl;
}

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

int main() {
	double a,b;
	int s1,s2,s3;
	cin >> a;
	s1 = a / 2;
	b = a / 2;
	if (s1 == b)s1 = 0;
	else s1 = 1;
	s2 = (a - s1) / 20;
	b= (a - s1) / 20;
	if (s2 == b)s2 = 0;
	else s2 = 1;
	s3 = (a - (s1 + 10 * s2)) / 100;
	cout << s1 +s2 + s3 << endl;
}

Measured memory_bytes: 256
/*PM1 問題８*/
#include <stdio.h>
int main()
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (0 <= x + r  && 0 <= x - r &&W >= x + r &&W >= x - r && 0 <= y + r && 0 <=y - r && H >= y + r && H >= y - r)
	{
		
		

			printf("Yes\n");
		
		
	}

	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0; i<n; i++)


using namespace std;

int main(){
    
    int n,d; cin >> n >> d;
    int r = 0;
    vector<int>v(1010,0);
    rep(i,n)
	cin>>v[i];
    sort(v.begin(),v.end(),greater<int>());
    if(v[0] <= d)
    {
	cout << "kusoge" << endl;
	return 0;
    }
    for(int j = 0;j <v.size();j++)
    {
	if (v[j]- d >0 )
	  r += v[j] - d;
	else 
		break;

    }
    cout << r << endl;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	string s;
	cin >> s;

	if (s[2] == s[3] && s[4] == s[5]) { cout << "Yes\n"; }
	else { cout << "No\n"; }

	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


vector<int> dx{1,0,-1,0};
vector<int> dy{0,-1,0,1};
int main() {
    int H,W; cin >> H >> W;
    vector<vector<char>> S(H+2, vector<char>(W+2, '.'));

    REP(i,H){
        string s; cin >> s;
        REP(j,W){
            S[i+1][j+1] = s[j];
        }
    }

    FOR(i,1,H+1){
        FOR(j,1,W+1){
            if(S[i][j] == '#'){
                bool ok = false;
                REP(n,4){
                    if(S[i+dy[n]][j+dx[n]] == '#') ok = true;
                }

                if(!ok){
                    cout << "No" << endl;
                    return 0;
                }
            }

        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

signed main(){
    int a, b;
    cin >> a >> b;
    cout << a*b << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> ans(n+1,0);
  rep(x,1,101) rep(y,1,101) rep(z,1,101) {
    int k = x*x + y*y + z*z + x*y + y*z + z*x;
    if (k > n) continue;
    ans[k]++;
  }
  rep(i,1,n+1) cout << ans[i] << endl;
  return 0;
}


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

using namespace std;

int broken[1024][1024];
bool vis[1024][1024];
char board[1024][1024];

int countBroken(int y, int x, int lev)
{
    int ret = 0;
    
    for (int i = -1; i <= 1; i++){
        for (int j = -1; j <= 1; j++){
            if (i == 0 && j == 0) continue;
            ret += (~broken[y + i][x + j] && broken[y + i][x + j] <= lev);
        }
    }
    
    return (ret);
}

int main()
{
    int w, h;
    
    scanf("%d %d", &h, &w);
    
    memset(broken, -1, sizeof(broken));
    memset(board, '.', sizeof(board));
    
    int ans = 0;
    queue<pair<int, int> > q;
    
    for (int i = 1; i <= h; i++){
        scanf("%s", board[i] + 1);
        for (int j = 1; j <= w; j++){
            if (board[i][j] == '.'){
                broken[i][j] = 0;
                vis[i][j] = true;
                q.push(make_pair(i, j));
            }
            else board[i][j] -= '0';
        }
    }
    
    while (q.size()){
        pair<int, int> x = q.front(); q.pop();
        
        int Y = x.first, X = x.second;
        ans = max(ans, broken[Y][X]);
        
        for (int i = -1; i <= 1; i++){
            for (int j = -1; j <= 1; j++){
                if (i == 0 && j == 0) continue;
                if (!vis[Y + i][X + j] && countBroken(Y + i, X + j, broken[Y][X]) >= board[Y + i][X + j]){
                    broken[Y + i][X + j] = broken[Y][X] + 1;
                    vis[Y + i][X + j] = true;
                    q.push(make_pair(Y + i, X + j));
                }
            }
        }
    }
    
    printf("%d\n", ans);
    
    return (0);
}

Measured memory_bytes: 7480
#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;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for(int i = (int)(n) - 1 - (int)(x); i >= 0; i--)

void printv(vector<int> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}

int N,K; // <=100
vector<int> d(100); // <=N
vector<vector<int>> A(100, vector<int>(100, 0));

int main(void){
    // Your code here!
    cin >>N>>K;
    rep(i,K) {
        int tmp;
        cin>>tmp;
        d[i] = tmp;
        rep(j,tmp){
            int a;
            cin>>a;
            A[i][j] = a;
        }
    }
    vector<bool> who(N, false);
    rep(i,K){
        rep(j,d[i]){
            //cout << "who:" << A[i][j] - 1 << endl;
            who[A[i][j] - 1] = true;
        }
    }
    int count = 0;
    rep(i,N){
        if(who[i] == false) count++;
    }
    cout << count;
    // printv(d);
    // printv(A[0]);
    
    
    return 0;
}


Measured memory_bytes: 3240
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i){
        cin >> a[i];
        -- a[i];
    }

    int ans = 0;
    for(int i=0; i<n; ++i){
        if(a[a[i]] == i)
            ++ ans;
    }
    ans /= 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
template<typename T> inline void chmin(T &a, T b){
	if(a > b) a = b;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	ll snuke = 0;
	ll arai = 0;
	rep(i, n) cin >> a[i], snuke += a[i];
	ll mn = 1LL << 62;
	for(int i = 0; i < n-1; i++){
		snuke -= a[i];
		arai += a[i];
		chmin(mn, abs(snuke-arai));
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int ans=0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int hako[]=new int[n];
		for(int i=1;i<=n;i++) {
			//hako[i]=sc.nextInt();
			int masu = sc.nextInt();
			if(masu%2==1 && i%2==1) {
				ans++;
			}
		}
		
		System.out.println(ans);
	}
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
  //  freopen ("in.txt", "r", stdin);

    int n;cin>>n;
    vector<vector<char>> c(n,vector<char>(10));
    FOR(i,n){
        FOR(j,10){
            cin>>c[i][j];
        }
        sort(c[i].begin(),c[i].end());
    }
    sort(c.begin(),c.end());
    ll ret=0;
    int acum=1;
    for(int i=1;i<n;++i){
        if (c[i]==c[i-1]) ++acum;
        else{
            ret += (ll)acum*(acum-1)/2;
            acum=1;
        }
    }
    ret += (ll)acum*(acum-1)/2;
    cout << ret;
}



Measured memory_bytes: 5760
# Green Bin
n = int(input())
s = [input() for i in range(n)]
m = 0
list = {}
for i in s:
  i = ' '.join(sorted(i))
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1
for i in list.values():
  l = i -1
  m = m + int(((l * (l + 1)) / 2))
print(m)

Measured memory_bytes: 25744
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t="keyence";
  cin>>s;
  for(int i=0;i<=7;i++){
    string a=t.substr(0,i),b=t.substr(i,7-i);
    if(a==s.substr(0,i)&&b==s.substr(s.size()-(7-i),7-i)){
      cout<<"YES";
      return 0;
    }
  }
  cout<<"NO";
}

Measured memory_bytes: 256
# coding: utf-8
DATA = """
314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 1000
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()

N, M = [int(i) for i in get_line().strip().split(" ")]
A = [int(i) for i in get_line().strip().split(" ")]

if N - sum(A) < 0:
    print (-1)
else:
    print (N - sum(A))

Measured memory_bytes: 9752
def resolve():
    n = int(input())
    a = []

    for i in range(n):
        row = list(map(lambda x: int(x) - 1, input().split()))
        row.reverse()
        a.append(row)

    q = set()

    def check(i):
        if len(a[i]) == 0:
            return
        j = a[i][-1]
        if i == a[j][-1]:
            p = (i, j) if i < j else (j, i)
            q.add(p)

    for i in range(n):
        check(i)

    day = 0
    while len(q) > 0:
        day += 1
        prev_q, q = q, set()

        for p in prev_q:
            (i, j) = p
            a[i].pop()
            a[j].pop()

        for p in prev_q:
            (i, j) = p
            check(i)
            check(j)

    for i in range(n):
        if len(a[i]) != 0:
            print(-1)
            return
    print(day)
    
resolve()


Measured memory_bytes: 67132
#include <iostream>

int main() {
    int n, k;
    char x;
    std::string s;
    std::cin >> n >> s >> k;
    x = s[k-1];
    for (char c : s) {
        if (c != x) std::cout << '*';
        else std::cout << c;
    }
    std::cout << '\n';
    return 0;
}

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

#define ll long long
const int MAX = 1'000'000;
int n;
ll cnt = 0;
string s[MAX];
map<string,ll> m;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
		sort(s[i].begin(), s[i].end());
		m[s[i]]++;
	}
	for(auto it=m.begin();it!=m.end();++it){
		ll c = it->second;
		cnt += c*(c-1)/2;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

const int maxn = 100 + 5;

int h, w;
char trees[maxn][maxn];
bool vis[maxn][maxn];
int dx[] = { -1, 1, 0, 0 }, dy[] = { 0, 0, -1, 1 };

void dfs(int x, int y) {
    vis[x][y] = true;
    for (int i = 0; i < 4; ++i) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx < 1 || nx > h || ny < 1 || ny > w) continue;
        if (vis[nx][ny] || trees[x][y] != trees[nx][ny]) continue;
        dfs(nx, ny);
    }
}

int main() {
    while (cin >> h >> w && h) {
        for (int i = 1; i <= h; ++i)
            for (int j = 1; j <= w; ++j) {
                cin >> trees[i][j];
                vis[i][j] = false;
            }
        int ans = 0;
        for (int i = 1; i <= h; ++i)
            for (int j = 1; j <= w; ++j)
                if (!vis[i][j]) dfs(i, j), ++ans;
        printf("%d\n", ans);
    }
    return 0;
}


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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

#define F first
#define S second

int main() {
	fastio();
	
	string s;
	cin >> s;

	if (s.back() == 's') {
		s.push_back('e');
		s.push_back('s');
	}
	else {
		s.push_back('s');
	}
	cout << s << "\n";

}

Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n/100000!=0) printf("90909\n");
    else if(n/10000!=0) printf("%d\n",(n-9999)+909);
    else if(n/1000!=0) printf("%d\n",(999-99)+9);
    else if(n/100!=0) printf("%d\n",(n-99)+9);
    else if(n>=9) printf("9\n");
    else if(n%2==0) printf("%d\n",n-1);
    else printf("%d\n",n);
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(c-c%a <= c && c-c%a >= b)
	{
		cout << "OK";
	}
	else
	{
		cout << "NG";
	}
}



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

int N, K, T[1 << 18];
vector<int>vec;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	sort(T, T + N);
	for (int i = 0; i < N - 1; i++) vec.push_back(T[i + 1] - T[i] - 1);
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());

	int sum = T[N - 1] - T[0] + 1;
	for (int i = 0; i < K - 1; i++) {
		if (i < vec.size()) sum -= vec[i];
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3856
s = input()
n = len(s)
for i in range(1,2**n):
  ans = [s[0]]
  for j in range(1,n):
    if (i>>j) & 1:
      ans.append("+")
    else:
      ans.append("-")
    ans.append(s[j])
  if eval("".join(ans)) == 7:
    ans.append("=7")
    print("".join(ans))
    exit()



Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
  int max_n = 100000;
  vector<bool> is_prime(max_n + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < is_prime.size(); i++) {
    if (!is_prime[i]) {
      continue;
    }

    for (int j = i * 2; j < is_prime.size(); j += i) {
      is_prime[j] = false;
    }
  }

  vector<int> cnts(max_n + 1, 0);
  for (int i = 1; i < cnts.size(); ++i) {
    if (is_prime[i] && is_prime[(i + 1)/2]) {
      cnts[i] = cnts[i - 1] + 1;
    } else {
      cnts[i] = cnts[i - 1];
    }
  }

  int q;
  cin >> q;

  vector<int> ans;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    ans.push_back(cnts[r] - cnts[l - 1]);
  }

  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 4276
#include <stdio.h>
#include <math.h>

int isprime(int);

int main()
{
  int i, end, numdata, data, primecount = 0;

  scanf("%d",&numdata);

  for(i = 0; i < numdata; i++) {
    scanf("%d",&data);
    primecount += isprime(data);
    // printf("%d  ",primecount);
  }

  printf("%d\n",primecount);

  return 0;
}

int isprime(int data)
{
  int i;

  if(data == 2) return 1;
  
  if(data < 2 || data % 2 == 0) return 0;

  for(i = 3; i <= sqrt(data); i = i+2) {
    if(data % i == 0) return 0;
  }
  
  return 1;
}



Measured memory_bytes: 2104
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const int M=3010;
long long dp[3100][3050][2];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)dp[0][i][i==0]=1;
	for(int i=0;i<b-1;i++){
		for(int j=0;j<a;j++){
			for(int k=0;k<2;k++){
				if(!dp[i][j][k])continue;
 
				if(j)dp[i+1][j-1][k||(j==1)]=(dp[i+1][j-1][k||(j==1)]+dp[i][j][k])%mod;
				dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k]*2)%mod;
				if(j+1<a)dp[i+1][j+1][k]=(dp[i+1][j+1][k]+dp[i][j][k])%mod;
			}
		}
	}
	long long ret=0;
	for(int i=0;i<a;i++){
		ret=(ret+dp[b-1][i][1])%mod;
	}
	ret=ret*4%mod;
	printf("%lld\n",ret);
}

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

using namespace std;

int64_t a,b;
int k;

int main()
{
  cin >> a >> b >> k;
  for (int i = 0; i < k; i++) {
    if (i % 2 == 0) {
      if (a % 2 == 1LL) a--;
      a /= 2;
      b += a;
    } else {
      if (b % 2 == 1LL) b--;
      b /= 2;
      a += b;
    }
  }


  cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 256
c = [list(map(int, input().split())) for i in range(3)]

isValid = False
if c[0][0] - c[0][1] == c[1][0] - c[1][1] == c[2][0] - c[2][1]:
    if c[0][0] - c[0][2] == c[1][0] - c[1][2] == c[2][0] - c[2][2]:
        if c[0][0] - c[1][0] == c[0][1] - c[1][1] == c[0][2] - c[1][2]:
            if c[0][0] - c[2][0] == c[0][1] - c[2][1] == c[0][2] - c[2][2]:
              isValid = True

if isValid:
    print("Yes")
else:
    print("No")


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

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;

#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        cout << A[i] << " ";
    }
    cout << endl;
}

inline void solve() {
    long long x;
    cin >> x;
    for (long long a = 0, a5 = 0; a5 <= x; ++a, a5 = a * a * a * a * a) {
        for (long long b = 0, b5 = 0; b5 + a5 <= x; ++b, b5 = b * b * b * b * b) {
            if (a5 + b5 == x) {
                cout << a << ' ' << -b << endl;
                return;
            }
        }
    }
    for (long long y = 1, y5 = 1; y5 <= x; ++y, y5 = y * y * y * y * y) {
        for (long long b = 0; 5 * b * y * (y * y * y + b * b * b) + 10 * b * b * y * y * (b + y) + y5 <= x; ++b) {
            if (5 * b * y * (y * y * y + b * b * b) + 10 * b * b * y * y * (b + y) + y5 == x) {
                cout << y + b << ' ' << b << endl;
                return;
            }
        }
    }
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    int t = 1;
    // cin >> t;

    for (int _ = 0; _ < t; _++) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>

int main(void){
	int n, m, t;
	int f[101] = {}, tar[101] = {}, score[101] = {};
	int i, j;
	
	scanf("%d", &n);
	
	scanf("%d", &m);
	
	for (i = 0; i < m; i++){
		scanf("%d", &t);
		tar[i] = t;
	}
	
	for (i = 0; i < m; i++){
		for (j = 0; j < n; j++){
			scanf("%d", &f[j]);
			
			if (f[j] == tar[i]) score[j]++;
			else score[tar[i]-1]++;
		}
	}
	
	for (i = 0; i < n; i++)	printf("%d\n", score[i]);
	
	return 0;
}

Measured memory_bytes: 596
package main

import (
  "fmt"
  "math"
)

func main() {
    var n int
	fmt.Scan(&n)
 
	x := make([]int, n)
	y := make([]int, n)
 
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i], &y[i])
    }
  
    l := float64(0)
  
    for i := 0; i < (n - 1); i++ {
      for j := (i + 1); j < n; j++ {
        dx := float64(x[i] - x[j])
        dy := float64(y[i] - y[j])
        l += math.Sqrt(dx * dx + dy * dy)
      }
    }
    fmt.Println(l * 2 / float64(n)) 
    }

Measured memory_bytes: 512
n = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(0, n):
    ni = input()
    if ni =="AC" : AC += 1
    elif ni =="WA" : WA += 1
    elif ni =="TLE" : TLE += 1
    elif ni =="RE" : RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))

Measured memory_bytes: 9192
//JSD
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#define ll long long
#define Mod 1000000007
using namespace std;
ll modular_exponentiation(ll a,ll b){
	if(b==0){
		return 1;
	}
	if(b==1){
		return a%Mod;
	}
	ll x=modular_exponentiation(a,b/2);
	x=(x*x)%Mod;
	if(b%2==1){
		x=(x*a)%Mod;
	}
	return x;
}
ll modular_divison(ll a,ll b){
    return (modular_exponentiation(b,Mod-2)*a)%Mod;
}

bool isPrime(ll n){
	if(n<=1) return 0;
	if(n==2 or n==3 ) return 1;
	if(n%2==0 or n%3==0) return 0;
	for(ll i=5;i*i<=n;i+=6){
		if(n%i==0 or n%(i+2)==0)
			return 0;
	}
	return 1;
}
struct primeFactorInfo{
	map<ll,ll> M;
	set<ll> S;
};
primeFactorInfo pfs(ll n){
	primeFactorInfo p;
	for(ll i=2;i<=sqrt(n);i++){
		if(n%i==0){
			p.S.insert(i);
			while(((n%i)==0)){
				p.M[i]++;
				n/=i;
			}
		}
	}
	if(n>1){
		p.M[n]++;
		p.S.insert(n);
	}
	return p;
}
void sieve(ll n,vector<ll>& v){
	bool isComposite[n+1]={0};
	isComposite[0]=isComposite[1]=1;
	for(ll i=2;i*i<=n;i++){
		if(!isComposite[i]){
			v.push_back(i);
			for(int j=2;j*i<=n;j++){
				isComposite[i*j]=1;
			}
		}
	}
}
primeFactorInfo pfsUsingSieve(ll n){
	primeFactorInfo p;
	vector<ll > v;
	sieve(n,v);
	for(auto i: v){
		if(n%i==0){
			p.S.insert(i);
			while(((n%i)==0)){
				p.M[i]++;
				n/=i;
			}
		}
	}
	if(n>1){
		p.M[n]++;
		p.S.insert(n);
	}
	return p;
}
int main(){
	ll h,a;
	cin>>h>>a;
	cout<<ceil((1.0*h)/a);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Node{
  int val;
  int startPosition;
  Node(int val, int p):val(val), startPosition(p){}
};
int main(){
  string str;
  cin >> str;
  stack<int> S;
  vector<Node>result;
  int t;
  for(int i = 0; i < str.size(); i++){
    if(str[i] == '\\'){
      S.push(i);
    }else if(str[i] == '/'){
      if(S.empty()){
        continue;
      }
      t = i - S.top();
      if(result.size()){
        int j = result.size()-1;
        while(j >= 0 and result[j].startPosition > S.top()){
          t += result.back().val;
          result.pop_back();
          j--;
        }
      }
      result.push_back(Node(t, S.top()));
      S.pop();
    }
  }
  int sum = 0;
  for(auto i: result){
    sum += i.val;
  }
  cout << sum << endl;
  cout << result.size();
  for(int i = 0; i < result.size(); i++){
    cout << " " << result[i].val;
  }
  cout << endl;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision; // int64_tは9*10^18まで

//ダイクストラ法(蟻本p97)
struct edge {
  int to, cost;
};
typedef pair<int, int> P; // firstは最短距離、secondは頂点の番号

#define MAX_V 100001
#define INF (int64_t)pow(10, 18)
int V;
vector<edge> G[MAX_V];
int64_t d[MAX_V];

void dijkstra(int s) {
  // greater<P>を指定することでfirstが小さい順に取り出せるようにする
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + MAX_V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  cin >> V;
  for(int i=0; i<V-1; i++){
    int a, b, c;
    cin >> a >> b >> c;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  int q, k;
  cin >> q >> k;
  int x[q], y[q];
  for(int i=0; i<q; i++)
    cin >> x[i] >> y[i];
  dijkstra(k);
  for(int i=0; i<q; i++){
    cout << d[x[i]]+d[y[i]]<<endl;
  }
  return 0;
}

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

const int maxn = 5000 + 5;
const long long inf = 1e18;
vector<int> g[maxn];
int a[maxn], sz[maxn];
long long dp[2][maxn][maxn];

void dfs(int x, int p) {
    sz[x] = 1;
    for (int i = 0; i < maxn; ++i) {
        dp[0][x][i] = inf;
        dp[1][x][i] = inf;
    }
    dp[a[x] < 0][x][0] = a[x];
    for (int i = 0; i < (int)g[x].size(); ++i) {
        int u = g[x][i];
        if (u == p) continue;
        dfs(u, x);
        vector<vector<long long>> nxt(2, vector<long long>(sz[x] + sz[u] + 1, inf));
        for (int i = 0; i <= sz[u]; ++i) {
            for (int j = 0; j <= sz[x]; ++j) {
                for (int a = 0; a < 2; ++a) {
                    for (int b = 0; b < 2; ++b)
                        nxt[a || b][i + j] = min(nxt[a || b][i + j], dp[a][u][i] + dp[b][x][j]);
                }
            }
        }
        sz[x] += sz[u];
        for (int i = 0; i <= sz[x]; ++i) {
            dp[0][x][i] = nxt[0][i];
            dp[1][x][i] = nxt[1][i];
        }
    }
    for (int i = sz[x] - 1; i >= 0; --i) {
        if (dp[0][x][i] < inf) 
            dp[0][x][i + 1] = min(dp[0][x][i + 1], 0ll);
        if (dp[1][x][i] < 0) 
            dp[0][x][i + 1] = min(dp[0][x][i + 1], 0ll);
    }
}

int main() {
    int n; scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    for (int i = 0; i < n - 1; ++i) {
        int x, y; scanf("%d%d", &x, &y);
        --x, --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0, -1);
    for (int i = 0; i <= n; ++i) {
        if (dp[0][0][i] < inf || dp[1][0][i] < 0) {
            printf("%d\n", i);
            return 0;
        }
    }
    throw;
}


Measured memory_bytes: 392704
N = int(input())
A = list(map(int, input().split()))

dp = [0 for i in range(N)]

for i in range(1,N):
  if i == 1:
    dp[i] = abs(A[i]-A[i-1])
  else:
    dp[i] = min(dp[i-1] + abs(A[i]-A[i-1]), dp[i-2] + abs(A[i]-A[i-2]))
print(dp[N-1])

Measured memory_bytes: 20540
//#include "stdafx.h"
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == ',')
			cout << " ";
		else
		cout << s[i];
	}
}

Measured memory_bytes: 3656
use std::io::*;
use std::str::FromStr;

fn main(){
    let n: usize = read();
    let m: usize = read();
    
    let mut pos: Vec<bool> = vec![false;n];
    let mut count: Vec<usize> = vec![1;n];
    pos[0] = true;
    for _ in 0..m {
        let x = read::<usize>() - 1;
        let y = read::<usize>() - 1;
        if pos[x] {
            pos[y] = true;
            if count[x] == 1 {
                pos[x] = false;
            }
        }
        count[x] -= 1;
        count[y] += 1;
    }
    println!("{}", 
        pos.into_iter().filter(|&x| x).count()
    );
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void) {

	int a, b, k;

	cin >> a >> b >> k;

	for (int i = a; i <= b; i++)
	{
		if (i <= a + k - 1|| i >= b - k + 1)cout << i << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
//
//AtCoder Beginner Contest 079
//D
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int H, W;
    cin >> H >> W;

    vector<vector<int>> c(10, vector<int>(10));
    REP(i,10)REP(j,10){
        cin >> c[i][j];
    }
    vector<int> aCnt(10,0);
    REP(h,H)REP(w,W){
        int a;
        cin >> a;
        if (a!=-1) aCnt[a]++;
    }
    
    REP(k,10)REP(i,10)REP(j,10){
        if (c[i][j]>c[i][k]+c[k][j]) c[i][j]=c[i][k]+c[k][j];
    }
    ll ans = 0;
    REP(i,10){
        ans += aCnt[i]*c[i][1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
//ported from ICPC2012rF
#include <iostream>
#include <string>
#include <vector>
#include <map>
#define SENTINEL 99999999
using namespace std;
typedef pair<int,int> pii;
map<int,int>h;
class union_find{
	vector<pii>parent;
	pii root(int a){
		if(parent[a].first==a)return parent[a];
		pii ret=root(parent[a].first);
		return parent[a]=make_pair(ret.first,ret.second+parent[a].second);
	}
public:
	union_find(int n): parent(n){for(int i=0;i<n;i++)parent[i]=make_pair(i,0);}
	int dist(int a,int b){
		pii x=root(a),y=root(b);
		if(x.first!=y.first)return SENTINEL;
		return x.second-y.second;
	}
	int unite(int a,int b,int w){
		pii x=root(a),y=root(b);
		if(x.first==y.first)return 0;
		parent[x.first]=make_pair(y.first,y.second-x.second -w-h[a]+h[b]); ///
		return 1;
	}
};
int main(){
	int N,Q,a,b,w;
	string s;
	cin>>N>>Q;
	union_find uf(N);
	for(;Q--;){
		cin>>s>>a>>b,a--,b--;
		if(s=="IN"){
			cin>>w;
			h[a]+=w,h[b]+=w;
			uf.unite(a,b,w);
		}else{
			w=uf.dist(a,b);
			if(w==SENTINEL)cout<<"WARNING"<<endl;
			else cout<< -w-h[a]+h[b]<<endl; ///
		}
	}
}

Measured memory_bytes: 4700
n,m = map(int,raw_input().split())

coins = map(int,raw_input().split())

dp = [i for i in range(n+1)]

for i in coins:
	for j in range(n+1):
		if j-i > -1:
			dp[j] = min(dp[j], dp[j-i] + 1)

print dp[n]


Measured memory_bytes: 7616
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;


int main(void){
	int N;cin>>N;
	int l[N];
	int r[N];
	rep(i,N){
		cin>>l[i];
		cin>>r[i];
	}
	int sum = 0;
	for(int t = 0; t < N; t++){
		sum += r[t] - l[t] + 1;
	}
	cout<<sum;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans= fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int>factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

string S,T;
int q,n,m;
P s[100010],t[100010];
signed main() {
	cin>>S>>T>>q;
	n=S.size(),m=T.size();
	rep(i,n) {
		if(S[i]=='A') {
			s[i+1].first++;
		}
		else {
			s[i+1].second++;
		}
		s[i+1]=s[i+1]+s[i];
	}
	rep(i,m) {
		if(T[i]=='A') {
			t[i+1].first++;
		}
		else {
			t[i+1].second++;
		}
		t[i+1]=t[i+1]+t[i];
	}
	rep(i,q) {
		int a,b,c,d;
		scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
		int cnta=(s[b].first-s[a-1].first)-(t[d].first-t[c-1].first);
		int cntb=(s[b].second-s[a-1].second)-(t[d].second-t[c-1].second);
		if((cnta-cntb)%3==0) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define int             long long
#define gcd(a, b)       __gcd(a, b)
#define here            cout<<"here";
#define lcm(a, b)       ((a)*1ll * (b)) / gcd(a, b)
#define pb              push_back
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define nl              "\n"
#define vi              vector<int>
#define vvi             vector<vector<int> >
#define F               first
#define S               second
#define lb              lower_bound
#define ub              upper_bound
#define pii             pair<int,int>
#define w(x)            int x; cin>>x; while(x--)
#define fre(i,a,n)      for (int i = a; i <= n; ++i)
#define fr(i,n)         for (int i = 0; i < n; ++i)
#define rf(i,n,a)       for (int i = n; i >=a; --i)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pqi		   priority_queue<int>
#define pqgi            priority_queue<int,vector<int>,greater<int>>
#define MN              min_element
#define MX              max_element
#define all(x)          x.begin(),x.end()
#define YN(ans)         ans ? cout << "YES" : cout << "NO";
#define d0(x)           cout<<(x)<<" "
#define d1(x)           cout<<(x)<<endl
#define d2(x,y)         cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z)       cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d)     cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e)   cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define max3(a,b,c)     max(max((a),(b)),(c))
#define max4(a,b,c,d)   max(max((a),(b)),max((c),(d)))
int pow(int a, int b, int m) {
	int ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % m;
		b /= 2;  a = (a * a) % m;
	}
	return ans;
}
//when m is prime
int modinv(int a, int m)  {return pow(a, m - 2, m);}
void start()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

const int N = 200005;
void solve()
{
	int n,k;cin>>n>>k;
	int h[n];
	int dp[N];

	fr(i,n) cin>>h[i];
	dp[0]=0;
	// dp[1]=abs(h[0]-h[1]);
	fre(i,1,n-1){
		int mn=INT_MAX;
		fre(j,1,k){
			if(i-j<0) break;
			int op=dp[i-j]+abs(h[i]-h[i-j]);
			mn=min(mn,op);
		}
		dp[i]=mn;
	}
	cout<<dp[n-1];


}


////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////


int32_t main()
{
	FIO;
	//start();
	solve();
// w(x)    {solve();}
#ifndef ONLINE_JUDGE
	cerr << "\nTime Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
}


Measured memory_bytes: 5184
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			String line = sc.nextLine();
			String answer = "";
			int length = line.length();
			for(int i = 0; i < length; i++){
				char ch = line.charAt(i);
				if(Character.isUpperCase(ch)){
					ch = Character.toLowerCase(ch);
					System.out.print(ch);
				}else if(Character.isLowerCase(ch)){
					ch = Character.toUpperCase(ch);
					System.out.print(ch);
				}else{
					System.out.print(ch);
				}
			}
			System.out.println();
		}
	}
}


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

using namespace std;

const int N = 100010;
int n, C, K;
int a[N];

int main() {
    scanf("%d %d %d", &n, &C, &K);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a, a + n);

    int l = 0;
    int ans = 0;
    while (l < n) {
        int r = l;
        while (r < n && a[r] - a[l] <= K && r - l + 1 <= C) r++;
        ans++;
        l = r;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 640