akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 1e5 + 2;


bool solve() {
	int i = 0, j = 0, k = 0, n = 0, m = 0;
	cin >> n;
	vi a(n + 1), sums(n + 4, 0);

	fr(i, 0, n+1)
	cin >> a[i];
	for(i = n; i >= 0; i--) {
		sums[i] = sums[i + 1] + a[i];
	}

	if(n == 0) {
		if(a[0] == 1) {
			cout << "1\n";
			return 1;
		} else
			return 0;
	}
	if(a[0] > 0) {
		return 0;
	}
	int x = 1, ans = 1;
	fr(i, 1, n+1) {
		if(sums[i] < x)
			return 0;

		if(sums[i] >= 2*x) {
			x = 2*x;
			ans += x;
		} else {
			x = sums[i];
			ans += x;
		}
		if(x < a[i]) return 0;
		x -= a[i];

	}
	cout << ans << el;
	return 1;
}

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
	// cin >> T;
	for(int tc = 1; tc <= T; tc++) {
		if(!solve()) cout << "-1\n";
	}
	return 0;
}

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

int main(){
	int n, k;
  	cin >> n >> k;
  	vector<int> a(3);
  	rep(i, 3) cin >> a[i];
  	string s;
  	cin >> s;
  
  	vector<int> ctoi(256);
  	ctoi['r'] = 2;
  	ctoi['c'] = 0;
  	ctoi['p'] = 1;
  
  	int ans = 0;
  	rep(i, k){
    	vector<int> x;
      	for(int j = i; j < n; j += k){
        	x.push_back(ctoi[s[j]]);
        }
      
      	vector<int> dp(2);
     	int pre = -1;
      	for(int nx : x){
        	vector<int> p(2);
          	swap(dp, p);
          	dp[0] = max(p[0], p[1]);
          	if(pre == nx){
            	dp[1] = p[0] + a[nx];
            } else {
            	dp[1] = max(p[0], p[1]) + a[nx];
            }
          	pre = nx;
        }
      	ans += max(dp[0], dp[1]);
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 1020
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, M;
int N2;
LL A[200011];

LL ans;
bool ok(int mid) {
    int len = mid * 2;

    LL le_ma = 0, ri_ma = 0;
    REP (i, mid) {
	LL tmp = A[i] + A[len-1-i];
	if (tmp >= M) return false;
	amax(le_ma, tmp);
    }
    REP (i, N-mid) {
	LL tmp = A[len+i] + A[N2-1-i] - M;
	if (tmp < 0) return true;
	amax(ri_ma, tmp);
    }

    amin(ans, max(le_ma, ri_ma));
    return false;
}

void MAIN() {
    scanf("%d%d", &N, &M);
    N2 = N+N;
    REP (i, N2) scanf("%lld", A+i);

    sort(A, A+N2);

    ans = 1LL<<60;
    int lo = 0, hi = N;
    while (hi - lo > 1) {
	int mid = (hi + lo) / 2;
	(ok(mid)? lo: hi) = mid;
    }
    ok(lo);
    ok(hi);
    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;



int main() {
    int n;
    scanf("%d", &n);
    vector<int> data(n, 0);
    rp(i, 0, n) {
        scanf("%d", &data.at(i));
    }
    vector<int> data_copy = data;
    sort(data_copy.begin(), data_copy.end());
    int smid = data_copy.at(n/2 - 1);
    int bmid = data_copy.at(n/2);
    rp(i, 0, n) {
        if(data.at(i) <= smid) {
            printf("%d\n", bmid);
        } else {
            printf("%d\n", smid);
        }
    }
    return 0;

} 

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

int main() {
  int n, tmp, min, index, count = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  // sort
  for (int i = 0; i < n - 1; ++i) {
    index = i;
    min = 101;
    for (int j = i; j < n; ++j) {
      if (a[j] < min) {
        min = a[j];
        index = j;
      }
    }
    // swap
    tmp = a[i];
    a[i] = min;
    a[index] = tmp;
    if (index != i) count++;
  }
  for (int i = 0; i < n; ++i) {
    cout << a[i] << ((i == n - 1) ? '\n' : ' ');
  }
  cout << count << '\n';
}



Measured memory_bytes: 3096
import itertools

n, m = map(int, input().split())

xyzs = []

for i in range(n):
    xyzs.append(tuple(map(int, input().split())))

result = 0

for signs in itertools.product((1, -1), repeat=3):
    signed_sum = lambda xyz: sum(sign * w for sign, w in zip(signs, xyz))
    cakes = sorted(xyzs, key=signed_sum, reverse=True)[:m]
    score = sum(signed_sum(xyz) for xyz in cakes)
    result = max(result, score)
    
print(result)

Measured memory_bytes: 49904
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

ll llabs(ll &a) { return (a < 0) ? (-a) : (a); }

// main -----------------------------------------------

int main() {
    ll n;
    cin >> n;
    vector<vector<ll>> abc(n, vector<ll>(3));
    REP(i, n){
        REP(j, 3){
            cin >> abc[i][j];
        }
    }

    vector<vector<ll>> dp(n+1, vector<ll>(3, 0));

    REP(i, n){
        REP(j, 3){
            REP(k, 3){
                if(j == k) continue;
                chmax(dp[i+1][j], dp[i][k] + abc[i][j]);
            }
        }
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
ll a[2010][2010];
void func(){
  for(int i=0;i<=2000;i++){
    a[i][0] = 1;
    a[i][i] = 1;
  }
  for(int i=2;i<=2000;i++){
    for(int j=1;j<i;j++){
      a[i][j] = (a[i-1][j-1] + a[i-1][j])%mod;
    }
  }
}

int main() {
  ll n,k;
  ll mul=1;
  cin >> n >> k;
  func();
  for(ll i=1;i<=k;i++){
    cout << a[n-k+1][i] * a[k-1][i-1] % mod << endl;
  }

} 

Measured memory_bytes: 30208
import java.util.Scanner;
public class Main{
	public static void main(String[] args) { 
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt(), ans=0;
			for(int i=1;i<600/n;i++){
				ans+=Math.pow(i*n, 2)*n;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 17200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n,in;
	cin >> n;
	vi x,y;
	rep(i, n) {
		cin >> in;
		x.push_back(in);
		y.push_back(in);
	}
	sort(all(x));
	int a=x[n/2-1], b=x[n/2];
	rep(i, n) {
		if (y[i] <= a)cout << b;
		else cout << a;
		cout << endl;
	}
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;
  cin>>n;
  vi b(n-1);
  rep(i,n-1) cin>>b[i];
  
  int ans=b[0]+b[n-2];
  rep(i,n-2){
    ans+=min(b[i],b[i+1]);
  }
  
  cout(ans);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
  for(;;) {
    auto solve = [](){
      int n, m;
      cin >> n >> m;
      if(n==0 && m==0) exit(0);
      bool maze[m][n][4];
      int di [] = {0,0,1,-1};
      int dj [] = {1,-1,0,0};
      for(int i = 0; i < m*2-1; i++) {
        if(i % 2) { // side walls
          for(int j = 0; j < n; j++) {
            int k;
            cin >> k;
            int ii = i/2;
            maze[ii][j][2]   = k==1;    // to down
            maze[ii+1][j][3] = k==1;    // to top
          }
        } else { // vert walls
          for(int j = 0; j < n - 1; j++) {
            int k;
            cin >> k;
            int ii = i/2;
            maze[ii][j][0]   = k==1;    // to right
            maze[ii][j+1][1] = k==1;    // to left
          }
        }
      }
      int que_body[n*m];
      int nextque_body[n*m];
      int *que = que_body;
      int *nextque = nextque_body;
      int sp = 0;
      int nextsp = 0;
      int cnt = 0;
      bool visited[n*m];
      for(int i = 0; i < n*m; i++) {
        visited[i] = 0;
      }
      que[sp++] = 0;
      visited[0] = true;
      while(sp > 0) {
        cnt++;
        for(int k = 0; k < sp; k++) {
          int q = que[k];
          if(q == m*n-1) return cnt;
          int i = q / n;
          int j = q % n;
          //cout << cnt << " visiting " << i << ","<<j << endl;
          for(int o = 0; o < 4; o++) {
            int i2 = i + di[o];
            int j2 = j + dj[o];
            if(i2 >= 0 && j2 >= 0 && i2 < m && j2 < n && !maze[i][j][o]) {
              int nq = i2 * n + j2;
              if(!visited[nq]) {
                visited[nq] = true;
                nextque[nextsp++] = nq;
                //cout << cnt << " pushing " << i2 << ","<<j2 << endl;
              }
            }
          }
        }
        sp = nextsp;
        int *p = que;
        que = nextque;
        nextque = p;
        nextsp = 0;
      }
      return 0;
    };
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 3024
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	string S;
	cin >> S;

	if (S.size() % 2 == 0) {
		int m = S.size() / 2;
		bool OK = 1;
		rep(i, m) {
			if (S[i] != S[i + m]) OK = 0;
		}
		if (OK) co("Yes");
		else co("No");
	}
	else co("No");

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>

bool solve(int i, int m, int n, int ary[]) {

  //現時点で作成した数がmと一致したらTRUEを返す．
  if (m == 0) {
    return true;
  }
  //iがnを超えた場合，aryを用いてmを作ることができないのでfalseを返す．
  else if (i >= n) {
    return false;
  }

  //どちらの条件も満たさなかった場合，今参照しているary[i]を用いる場合と用いない場合で再度関数を呼び出す．
  return solve(i + 1, m, n, ary) || solve(i + 1, m - ary[i], n, ary);
}

int main() {

  int i;

  int size_of_ary, size_of_aryM, m;
  int ary[25];

  std::cin >> size_of_ary;
  for (i = 0; i < size_of_ary; i++) {
    std::cin >> ary[i];
  }

  std::cin >> size_of_aryM;
  for (i = 0; i < size_of_aryM; i++) {

    std::cin >> m;

    if (solve(0, m, size_of_ary, ary)) {
      std::cout << "yes" << std::endl;
    } else {
      std::cout << "no" << std::endl;
    }
  }
}



Measured memory_bytes: 3088
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[1000001];int z[1500001],n,nxt[1000001],buc[1000011],rnxt[1000001];bool cut[1000001];
void zfunc(char *s,int n,int *z)
{
	z[1]=n;int l=0,r=0,pt;
	for(int i=2;i<=n;++i)
	{
		if(r<i){for(pt=i;pt<=n&&s[pt]==s[pt-i+1];++pt);--pt;z[i]=pt-i+1;if(z[i])l=i,r=pt;}
		else{int b=r-i+1,i_=i-l+1;if(z[i_]<b)z[i]=z[i_];else{for(pt=r+1;pt<=n&&s[pt]==s[pt-i+1];++pt);--pt;z[i]=pt-i+1;l=i;r=pt;}}
	}
}
void cal_next(int *z,int n,int *nxt)
{
	memset(buc,0x3f,sizeof(int)*(2*n+2));
	for(int i=n;i>=2;--i)buc[z[i]+i]=i;
	for(int i=2*n;i;--i)buc[i]=min(buc[i],buc[i+1]);
	for(int i=2;i<=n;++i)if(buc[i+1]<=i)nxt[i]=i-buc[i+1]+1;
}
int main()
{
	scanf("%s",s+1);n=strlen(s+1);int len=0;if(n==1){printf("1\n1\n");return 0;}zfunc(s,n,z);cal_next(z,n,nxt);
	len=n-nxt[n];if(!nxt[n]||n%len){printf("1\n1\n");return 0;}if(len==1){printf("%d\n%d\n",n,1);return 0;}
	printf("2\n");int ans=n-1;reverse(s+1,s+1+n);zfunc(s,n,z);cal_next(z,n,rnxt);
	for(int i=2;i<n;++i)if(nxt[i]&&!(i%(i-nxt[i])))cut[i]=true;
	for(int i=2;i<n;++i)if(rnxt[i]&&!(i%(i-rnxt[i])))cut[n-i]=true;
	for(int i=1;i<n;++i)ans-=cut[i];printf("%d\n",ans);return 0;
}

Measured memory_bytes: 16512
using System;
using System.Text.RegularExpressions;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            // かず
            int N = Convert.ToInt32(Console.ReadLine());

            string[] Code = new string[N];
            for (int i = 0; i < N; i++)
            {
                Code[i] = Console.ReadLine();
            }

            int C0 = 0, C1 = 0, C2 = 0, C3 = 0;

            for (int i = 0; i < N; i++)
            {
                if (Regex.IsMatch(Code[i], @"^(AC)"))
                {
                    C0++;
                }
                else if (Regex.IsMatch(Code[i], @"^(WA)"))
                {
                    C1++;
                }
                else if (Regex.IsMatch(Code[i], @"^(TLE)"))
                {
                    C2++;
                }
                else if (Regex.IsMatch(Code[i], @"^(RE)"))
                {
                    C3++;
                }
            }
            Console.WriteLine(String.Format("AC x {0}",C0));
            Console.WriteLine(String.Format("WA x {0}", C1));
            Console.WriteLine(String.Format("TLE x {0}", C2));
            Console.WriteLine(String.Format("RE x {0}", C3));
        }
    }
}


Measured memory_bytes: 51776
#include<stdio.h>

int main(void){

  int S,N,i;

  while(scanf("%d",&N),N){
    for(i=1,S=-N;i*i<N;i++)if(!(N%i))S+=i+N/i;

    if(S==N)printf("perfect number\n");
    else if(S<N)printf("deficient number\n");
    else if(S>N)printf("abundant number\n");
  }
  return 0;
}

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

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

    ll ac = 0, wa = 0, tle = 0, re = 0;
    for (int i=0; i<n; i++) {
        string s;
        cin >> s;
        if (s == "AC") {
            ac++;
        } else if (s == "WA") {
            wa++;
        } else if (s == "TLE") {
            tle++;
        } else {
            re++;
        }
    } 

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 3628
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] x = new int[4];
    int[] y = new int[4];
    for(int i =0;i<2;i++){
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }
    int disx = x[1] - x[0];
    int disy = y[1] - y[0];
    x[2] = x[1] - disy;
    y[2] = y[1] + disx;
    x[3] = x[2] - disx;
    y[3] = y[2] - disy;
    for(int i = 2;i<4;i++){
      System.out.println(x[i]);
      System.out.println(y[i]);
    }
  }
}


Measured memory_bytes: 35684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = (int)1e7 + 34;
const ld EPS = 1e-8;

ll getSum(ll x) {
    ll ans = 0;
    while (x > 0) {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

vector<ll> st10;

inline void add(vector<pair<ll, ld>> &a, ll x) {
    a.emplace_back(x, (0.0 + x) / (0.0 + getSum(x)));
}

void solve() {
    int n;
    cin >> n;

    st10 = {1};
    for (int i = 1; i < 20; i++) {
        st10.push_back(st10[i - 1] * 10);
    }

    vector<ll> res;
    vector<pair<ll, ld>> b;

    for (int len = 1; len <= 15; len++) {
        vector<pair<ll, ld>> a;
        add(a, st10[len] - 1);
        for (ll i = 1; i < 9; i++) add(a, i * st10[len - 1] + st10[len - 1] - 1);
        for (ll a1 = 1; a1 <= 9; a1++) {
            for (ll a2 = 0; a2 < 9; a2++) {
                if (len > 1) add(a, a1 * st10[len - 1] + a2 * st10[len - 2] + st10[len - 2] - 1);
            }
        }
        for (ll a1 = 1; a1 <= 9; a1++) {
            for (ll a2 = 0; a2 <= 9; a2++) {
                for (ll a3 = 0; a3 < 9; a3++) {
                    if (len > 2) add(a, a1 * st10[len - 1] + a2 * st10[len - 2] + a3 * st10[len - 3] + st10[len - 3] - 1);
                }
            }
        }
        sort(a.begin(), a.end());
        for (int i = 0; i < (int)a.size(); i++) b.push_back(a[i]);
    }

    ld mn = 1e18;
    for (int i = (int)b.size() - 1; i >= 0; i--) {
        if (b[i].second < mn + EPS) {
            mn = b[i].second;
            res.push_back(b[i].first);
        }
    }

    reverse(res.begin(), res.end());
    for (int i = 0; i < n; i++) {
        cout << res[i] << "\n";
    }
}

int main() {
#ifdef SERT
    freopen("a.in", "r", stdin);
    //solve();
    //solve();
#endif
    solve();
    return 0;
}

Measured memory_bytes: 856
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
using LLint = long long int;

const int mod = 1000000007;
int main(){
	int N,M;
	int S[6];
	string C[6];
	cin>>N>>M;
	for(int i=0;i<M;++i) cin>>S[i]>>C[i];
	
	for(int i=0;i<1000;++i)
	{
		bool check=true;
		string num = to_string(i);
		int ii = i;
		int digit = 1;
		while(1)
		{
			ii /=10;
			if(ii>0) ++digit;
			else break;
		}
		if(digit==N)
		{
			for(int j=0;j<M;++j)
			{
				if(num[S[j]-1]!=C[j][0])check=false;
			}
		}
		else check=false;
		if(check){
			cout<<i;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
 
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;
 
#define ll  long long
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)
 
#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)
 
#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount
#define die() return 0;
#define sz() size() 


 
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define MD          1000000007
#define M 			200011
#define LN             14
#define fftmod      998244353
#define EPS         (double)1e-10
 
long long  md=MD;
ll inf=1e18;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
 
inline ll exp(ll a,ll b){if(a==0&&b==0)return 1ll;if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=(r%md)*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
 
using cd=complex<double>;
const double PI=acos(-1);
 
inline ll rand(ll l,ll r){
    return l+rng()%(r-l+1);
}
map<pii,ll> m1,m2;
ll dp[2][10001];

int main(){
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
 
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p;string s1,s2;ll q;ll x,y;
    cin>>n>>s1;m=s1.size();
    dp[0][0]=1;

    for(i=1;i<=n;++i){
      ll s=0,o=1;
      if(i%2)swap(s,o);
      ll ans;
      for(j=0;j<=i;++j){
        ans=0;
        ans=ans+dp[o][max(0ll,j-1)]%md;if(ans>md)ans-=md;
        ans=ans+2*dp[o][j+1]%md;
        if(ans>md)ans-=md;
        dp[s][j]=ans;
      }

    }
    p=dp[n%2][m];
    cout<<p<<"\n";







}



Measured memory_bytes: 384
n = gets.to_i
s = gets.chomp

result = 0

max =
  if n > 52
    26
  else
    n/2
  end

(1..(n-1)).each do |z|
  x = s.slice(0, z)
  y = s.slice(z, n)

  if n-z < result
    break
  end

  x_h = {}
  x.each_char do |c|
    x_h[c] = true
  end

  y_h = {}
  y.each_char do |c|
    y_h[c] = true
  end

  keys = x_h.keys & y_h.keys
  cnt = keys.length
  if cnt > result
    result = cnt
  end

  if cnt >= max
    break
  end
end

puts result

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/24  Problem: ABC 119 D / Link: http://abc119.contest.atcoder.jp/tasks/abc119_d  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


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

	LL A, B, Q; cin >> A >> B >> Q;
	VL s(A), t(B);
	FOR(i, 0, A) {
		cin >> s[i];
	}
	FOR(i, 0, B) {
		cin >> t[i];
	}
	SORT(s);
	SORT(t);
	FOR(_, 0, Q) {
		LL x; cin >> x;

		LL ans = LINF;
		// x => s -> t
		{
			auto it = lower_bound(ALL(s), x) - s.begin();
			if (it != SZ(s)) {
				LL ret = abs(s[it] - x);
				auto it2 = lower_bound(ALL(t), s[it]) - t.begin();
				if (it2 != SZ(t))
					ans = min(ans, ret + abs(s[it] - t[it2]));
				if (it2 != 0) {
					it2--;
					ans = min(ans, ret + abs(s[it] - t[it2]));
				}
			}
			DD(de(ans));
			if (it != 0) {
				it--;
				LL ret = abs(s[it] - x);
				DD(de(ret));
				auto it2 = lower_bound(ALL(t), s[it]) - t.begin();
				if (it2 != SZ(t))
					ans = min(ans, ret + abs(s[it] - t[it2]));
				if (it2 != 0) {
					it2--;
					ans = min(ans, ret + abs(s[it] - t[it2]));
				}
			}
			DD(de(ans));
		}

		// x => t -> s 
		{
			auto it = lower_bound(ALL(t), x) - t.begin();
			if (it != SZ(t)) {
				LL ret = abs(t[it] - x);
				auto it2 = lower_bound(ALL(s), t[it]) - s.begin();
				if (it2 != SZ(s))
					ans = min(ans, ret + abs(t[it] - s[it2]));
				if (it2 != 0) {
					it2--;
					ans = min(ans, ret + abs(t[it] - s[it2]));
				}
			}
			if (it != 0) {
				it--;
				LL ret = abs(t[it] - x);
				auto it2 = lower_bound(ALL(s), t[it]) - s.begin();
				if (it2 != SZ(s))
					ans = min(ans, ret + abs(t[it] - s[it2]));
				if (it2 != 0) {
					it2--;
					ans = min(ans, ret + abs(t[it] - s[it2]));
				}
			}

		}

		cout << ans << "\n";
	}


	return 0;
}


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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
char s[NMAX],t[NMAX];
int main(int argc, char const *argv[])
{
	scanf("%s%s",s,t);
	int s_len = strlen(s) , t_len = strlen(t);
	int ans = 0;
	for(register int i = 0;i < s_len - t_len + 1;i++)
	{
		int ant = 0;	
		for(register int j = 0;j < t_len;j++)
			if(s[i+j] == t[j])
				ant++;
		ans = max(ans,ant);
	}
	printf("%d\n",t_len - ans);
	return 0;
}

Measured memory_bytes: 3824
//Serval vs Monster

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    double H, A;cin >> H >> A;
    cout << ceil(H/A) << endl;
    return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  mint ans = mint(2).pow(n);
  ans -= 1;
  ans -= choose(n,a);
  ans -= choose(n,b);
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

int dp[100010];

int main() {
  dp[0] = 0;
  for (int n = 1; n <= 100000; n++) {
    dp[n] = INF;
    int power = 1;
    while (power <= n) {
      dp[n] = min(dp[n], 1 + dp[n - power]);
      power *= 6;
    }
    power = 9;
    while (power <= n) {
      dp[n] = min(dp[n], 1 + dp[n - power]);
      power *= 9;
    }
  }
  int n;
  cin >> n;
  cout << dp[n] << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x, y;
		x = scan.nextInt();
		y = scan.nextInt();

		System.out.println(max(max(x + y,x - y),x * y));

		scan.close();

	}

	public static int max(int x,int y) {
		return x > y ? x : y;
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vi v(n);
    rep(i, n) cin >> v[i];

    map<int, int> f, s;

    for (int i = 0; i < n-1; i+=2) {
        f[v[i]]++;
        s[v[i+1]]++;
    }

    vector<pint> fv, sv;

    for (auto& e : f) {
        auto p = make_pair(e.second, e.first);
        fv.push_back(p);
    }
    sort(all(fv));
    reverse(all(fv));

    for (auto& e : s) {
        auto p = make_pair(e.second, e.first);
        sv.push_back(p);
    }
    sort(all(sv));
    reverse(all(sv));

    int res = 0;

    if (fv[0].second != sv[0].second) {
        res = n;
        res -= fv[0].first;
        res -= sv[0].first;
    }
    else {
        res = min(n - fv[0].first - sv[1].first, n - fv[1].first - sv[0].first);
    }

    cout << res << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define dbg(x)
#endif

#define X first
#define Y second

int main(){
    std::ios_base::sync_with_stdio(false);
    string str; cin >> str;
    int n = (int)str.size();
    for (int i = 1; i < n; i++){
        if (str[i] == str[i-1]){
            cout << i << ' ' << i + 1 << endl;
            return 0;
        }
    }
    for (int i = 2; i < n; i++){
        if (str[i] == str[i-2]){
            cout << i - 1 << ' ' << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << ' ' << -1 << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
int a[100000];



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  map<int, int> mp;
  // <this number's, how much>
  // <XXXXXXX, NNNNNNNN>
  for (int i = 0; i < n; i++) {
    ++(mp[a[i]]);
  }
  
  for (auto p: mp) {
    int x = p.first;
    int n = p.second;
    
    if (n < x) {
      ans += n;
    }
    else {
      ans += n - x;
    }
  }
  cout << ans << '\n';
}




Measured memory_bytes: 5120
#!/usr/bin/env python
#-*- coding:utf-8 -*-

def linearSearch(arr,key):
	arr.append(int(key))
	for idx,a in enumerate(arr):
		if a == key:
			if idx == (len(arr) - 1):
				return -1
			else :
				return 1
	
def main():
	Ns = int(raw_input())
	S  = map(int, raw_input().split())
	Nt = int(raw_input())
	T  = map(int, raw_input().split())

	sum_v = 0
	for key  in T:
		if linearSearch(S,key) > 0:
			sum_v += 1

	print sum_v

#def test():

if __name__ == '__main__':
	main()
	#test()

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

signed main(){
  const int MAX = 9;

  vector<int> con(MAX);
  int now = 4;
  int ans = 0;
  string s;

  cin>>s;

  con[now] = true;

  for(int i = 0; i < s.size(); i++){

    if(s[i] == 'R') {
      now++;
    } else {
      now--;
    }
    con[now] = !con[now];

    if(now == 0) {

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

      now = 4;

      con[now] = true;
    } else if(now == 8) {

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

      now = 4;

      ans++;

      con[now] = true;
    }
  }

  cout<<ans<<endl;

  return 0;
}



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


int main() {
    int n, m; cin >> n >> m;
    V<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int s = accumulate(ALL(a), 0);

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(a[i] * 4 * m >= s) cnt++;
        if(cnt == m){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;



    return 0;
}


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

int main()
{
  int k, s;
  cin >> k >> s;
  long long ans = 0;
  for (int i = 0; i <= k; i++) {
	for (int j = 0; j <= k; j++) {
	  int a = s - i - j;
	  if (a >= 0 && a <= k) {
		ans++;
	  }
	}
  }
  cout << ans << endl;
  return 0;
}



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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    rep(i, n) cin >> a[i + 1];
    int next = a[1];
    int ans = 0;
    rep(i, n)
    {
        ans++;
        if (next == 2)
        {
            cout << ans << endl;
            return 0;
        }
        next = a[next];
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 3752
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		var ans = new List<int>();
		while(true)
		{
			int N = GetInt();
			int X = GetInt();
			if(N == 0 && X == 0)
				break;

			ans.Add(solve(N, X));
		}
		WriteLine(string.Join("\n", ans));
	}

	private int solve(int N, int X)
	{
		int cnt = 0;
		for(int i = 1; i < N - 1; i++)
		{
			for(int j = i + 1; j < N; j++)
			{
				int rest = X - i - j;
				if(rest > j && rest <= N)
					cnt++;
			}
		}
		return cnt;
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}


Measured memory_bytes: 17960
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: u32,
        mut a: [u64; n],
    }

    let mut height = 0;
    let mut max_num = 0;
    for elem in a {
        max_num = std::cmp::max(elem, max_num);
        let tmp = max_num;
        height += tmp - elem;
    }

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

/*
fn max_index(array: &[u64]) -> usize {
    let mut i = 0;

    for (j, &elem) in array.iter().enumerate() {
        if elem > array[i] {
            i = j;
        }
    }

    i
}
*/


Measured memory_bytes: 5524
global num_lim
global tgt_sum

def dfs(cnt, num, sum):
  if cnt == num_lim:
    return sum == tgt_sum
  if num > 9:
    return 0
  return dfs(cnt + 1, num + 1, sum + num) + dfs(cnt, num + 1, sum)
    
while True:
  num_lim, tgt_sum = list(map(int, input().split()))
  if num_lim == 0 and tgt_sum == 0:
    break
  print(dfs(0, 0, 0))


Measured memory_bytes: 5600
import math

class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
    

def d(u, v):
    return math.sqrt((u.x - v.x) ** 2 + (u.y - v.y) ** 2)


a = [float(e) for e in input().split()]
u = Point(a[0], a[1])
v = Point(a[2], a[3])
print(d(u, v))



Measured memory_bytes: 5664
# ABC135C - City Savers
# greedy algorithm
def main():
    n = int(input())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    ans, a1 = 0, A[0]
    for a2, b in zip(A[1:], B):
        cnt1 = a1 if a1 < b else b
        cnt2 = a2 if a2 < b - cnt1 else b - cnt1
        ans += cnt1 + cnt2
        a1 = a2 - cnt2  # a2 becomes a1 in next turn
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 18624
#include<stdio.h>
#define MAX 101
#define INF 1<<30
#define WHITE 0
#define GRAY 1
#define BLACK 2

 int A[MAX][MAX],G[MAX],n,P[MAX];

 int prim(){
        int min,i,j,color[MAX],u,v;
        for(i=0;i<n;i++){color[i]=WHITE;}
        for(i=0;i<n;i++){G[i]=INF;}
        for(i=0;i<n;i++){P[i]=-1;}


        G[0]=0;

        while(1){
              min=INF;
              u=-1;
              for(i=0;i<n;i++){
                          if(min>G[i]&&color[i]!=BLACK){
                                             u=i;
                                             min=G[i];
                                             }
                          }
              if(u==-1)break;
              color[u]=BLACK;
              for(v=0;v<n;v++){
                          if(color[v]!=BLACK && A[u][v] != INF){
                                           if(G[v]>A[u][v]){
                                                     G[v]=A[u][v];
                                                     P[v]=u;
                                                     color[v]=GRAY;
                                                     }
                                           }
                         }
              }
        int sum=0;
        for(i=0;i<n;i++){
                   if(P[i]!=-1)sum+=A[i][P[i]];
                   }
        return sum;
        }


 int main(){
        int i,j,g;
        scanf("%d",&n);
        for(i=0;i<n;i++){
                   for(j=0;j<n;j++){
                               scanf("%d",&g);
                               A[i][j]=(g==-1)?INF:g;
                               }
                   }
        printf("%d\n",prim());
        return 0;
        }
        


Measured memory_bytes: 1988
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
int x,y,z;
struct node{
	int a,b,c;
	bool operator <(const node &t) const{
		return a-b>t.a-t.b;	
	}
}p[MAXN];
priority_queue<int> q;
ll lft[MAXN],tot,ans;
int main(){
	SF("%d%d%d",&x,&y,&z);
	int n=x+y+z;
	for(int i=1;i<=n;i++){
		SF("%d%d%d",&p[i].a,&p[i].b,&p[i].c);
		tot+=p[i].c;
	}
	sort(p+1,p+1+n);
	ll sum=0;
	for(int i=1;i<=x;i++){
		q.push(-p[i].a+p[i].c);
		sum+=p[i].a-p[i].c;
	}
	for(int i=x+1;i<=n-y;i++){
		lft[i-1]=sum;
		sum+=p[i].a-p[i].c;
		q.push(-p[i].a+p[i].c);
		sum+=q.top();
		q.pop();
	}
	lft[n-y]=sum;
	while(!q.empty())
		q.pop();
	sum=0;
	for(int i=n;i>n-y;i--){
		q.push(-p[i].b+p[i].c);
		sum+=p[i].b-p[i].c;
	}
	for(int i=n-y;i>=x;i--){
		ans=max(ans,lft[i]+sum+tot);
		sum+=p[i].b-p[i].c;
		q.push(-p[i].b+p[i].c);
		sum+=q.top();
		q.pop();
	}
	PF("%lld",ans);
}

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

typedef long long ll;
typedef vector <bool> v_bool;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}
ll N;
string S;
v_ll A;
int main(){
  cin >> S;
  N=S.length();
  A.assign(N+10,0);
  ll beg=-1,idx1=0,idx2=1,end=-1;
  for (ll i=0;i<=N-1;i++){

    if (S[i]=='R' && S[i+1]=='L'){
      idx1=i;idx2=i+1;
    }
    if ((i==N-1) || (S[i]=='L' && S[i+1]=='R' )){
      beg = end+1;
      end = i;
      //cout << beg << " " << idx1 << " " << idx2 << " " << end  << endl;
      if (idx1%2==beg%2){
        A[idx1]=(end-(beg-1)+1)/2;
        A[idx2]=(end-(beg)+1)/2;
      }else{
        A[idx1]=(end-(beg)+1)/2;
        A[idx2]=(end-(beg-1)+1)/2;
      }
    }
  }
  for (ll i=0;i<=N-1;i++){
    if (i>0) cout << " ";
    cout << A[i];
  }
  cout << endl;
}


Measured memory_bytes: 1472
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MAX_V 10000000
#define INF 100000000

int main(){
    int n; cin >> n;
    int a[n];
    vector<ll> dp(n, INF);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    dp[1] = abs(a[0] - a[1]);
    for(int i = 1; i < n; i++){
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    }
    cout << dp[n-1] << endl; 
}

Measured memory_bytes: 1408
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

vector<pair<int,int>> g[1024];

ll dp[2048][1024];

void solve(ll N, ll M, vector<ll> a, vector<ll> b, vector<ll> c) {
  REP(i,M) g[a[i] - 1].emplace_back(b[i] - 1, c[i]);
  REP(i,2048) REP(j,1024) dp[i][j] = -1e18;
  dp[0][0] = 0;
  REP(turn, 2010) {
    REP(i,N) {
      chmax(dp[turn + 1][i], dp[turn][i]);
      for (auto e: g[i]) {
        chmax(dp[turn + 1][e.first], dp[turn][i] + e.second);
      }
    }
  }
  if (dp[1005][N-1] == dp[2010][N-1]) { cout << dp[1005][N-1] << endl; }
  else cout << "inf" << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll M;
	ll N;
	scanf("%lld", &N);
	scanf("%lld", &M);
	vector<ll> c(M-1+1);
	vector<ll> a(M-1+1);
	vector<ll> b(M-1+1);
	for (int i = 0 ; i <= M-1 ; i++) {
	  scanf("%lld", &a[i]);
	  scanf("%lld", &b[i]);
	  scanf("%lld", &c[i]);
	}
	solve(N, M, a, b, c);
	return 0;
}


Measured memory_bytes: 16896
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string a, b; cin >> a >> b;
	int res = 1000000;
	for (int i = b.size() - 1; i < a.size(); i++)
	{
		int cnt = 0;
		for (int j = 0; j < b.size(); j++) cnt += a[j + i - b.size() + 1] != b[j];
		res = min(res, cnt);
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 3628