akhauriyash/Code-Regression huggingface dataset:
// Java program For handling Input/Output 
import java.io.*; 
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main 
{ 
    Scanner sc;
    //actual logic
    void solve(){
        int n = ni();
        ns();
        String s[] = new String[n];
        int t[] = new int[n];
        for(int i = 0;i < n;i++)
        {
            s[i] = sc.next();
            t[i] = ni();
            ns();
        }
        String x = ns();
        int ans = 0;
        int f = 0;
        for(int i = 0;i < n;i++)
        {
            if(f == 1)
                ans += t[i];
            if(s[i].equals(x))
                f = 1;
        }
        System.out.println(ans);

    }
    
    //constructor
    Main(){
        try{  
            sc = new Scanner(System.in);
        }catch(Exception e){
            System.out.println(e);
        }
    }


    //main metohd
    public static void main(String[] args)
    { 
       new Main().solve();
   }
    //Utility methods
        //input an integer from scanner
   int ni()
   {
    int a = sc.nextInt();
    return a;
    }
            //input a long from scanner
    long nl()
    {
        return sc.nextLong();
    }
            //input a float from scanner
    float nf(){
        float a = sc.nextFloat();
        return a;
    }
            //input a double from scanner
    double nd(){
        double a = sc.nextDouble();
        return a;
    }
    //input a sentence from scanner
    String ns(){
        return sc.nextLine();
    }
    //input an intger array
    void ia(int a[]){
        for(int i = 0;i < a.length;i++)
            a[i] = sc.nextInt();
    }
            //
    void la(long a[]){
        for(int i = 0;i < a.length;i++)
            a[i] = sc.nextLong();
    }
            //input a float array
    void fa(float a[]){
        for(int i = 0;i < a.length;i++)
            a[i] = sc.nextFloat();
    }
            //input a double array
    void da(double a[]){
        for(int i = 0;i < a.length;i++)
            a[i] = sc.nextDouble();
    }
    //input two dimensional integer array
    void ida(int a[][], int n, int m)
    {
        for(int i = 0;i < n;i++)
        {
            for(int j = 0;j < m;j++)
            {
                a[i][j] = ni();
            }
        }
    }
            //input two dimentional long array
    void lda(long a[][], int n, int m)
    {
        for(int i = 0;i < n;i++)
        {
            for(int j = 0;j < m;j++)
            {
                a[i][j] = nl();
            }
        }
    }
    //input two dimensional double array
    void dda(double a[][], int n, int m)
    {
        for(int i = 0;i < n;i++)
        {
            for(int j = 0;j < m;j++)
            {
                a[i][j] = nd();
            }
        }
    }
    //convert string to integer
    int stoi(String s){
        return Integer.parseInt(s);
    }
    //convert string to double
    double stod(String s){
        return Double.parseDouble(s);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
const int inf = 1 << 28;

template<typename T> void chmin(T &t, T f){if(t > f)t = f;}

int n, m, c, s, g;
vector<vector<vector<int> > > dist, cost;

void init(){
    dist.assign(c, vector<vector<int> >(n, vector<int>(n, inf)));
    cost.assign(c, vector<vector<int> >(n, vector<int>(n, inf)));
    rep(i, c)rep(j, n)dist[i][j][j] = cost[i][j][j] = 0;
}

void doWF(){
    rep(r, c)rep(k, n)rep(i, n)rep(j, n){
        chmin(dist[r][i][j], dist[r][i][k] + dist[r][k][j]);
    }
}

void calc(int k, vector<int> q, vector<int> r){
    vector<int> f(r.size());
    rep(i, (int)q.size())f[i+1] = f[i] + (q[i] - (i? q[i-1]: 0)) * r[i];
    q.insert(q.begin(), 0);
    rep(i, n)rep(j, i){
        if(dist[k][i][j] == inf)continue;
        int p = upper_bound(all(q), dist[k][i][j]) - q.begin();
        cost[k][i][j] = cost[k][j][i] = f[p-1] + (dist[k][i][j] - q[p-1]) * r[p-1];
    }
}

int solve(){
    vector<int> mem(n, inf);
    mem[s] = 0;
    priority_queue<pair<int, int> > q;
    for(q.emplace(0, s); !q.empty();){
        int cc = q.top().first, v = q.top().second; q.pop();
        if(v == g)return -cc;
        rep(r, c)rep(u, n){
            if(dist[r][v][u] == inf)continue;
            int nc = cost[r][v][u] - cc;
            if(mem[u] <= nc)continue;
            q.emplace(-(mem[u] = nc), u);
        }
    }
    return -1;
}

int main(){
    while(cin >> n >> m >> c >> s >> g, n|m|c|s|g){
        s--; g--;
        init();
        while(m--){
            int x, y, d, k;
            cin >> x >> y >> d >> k;
            x--; y--; k--;
            chmin(dist[k][x][y], d);
            dist[k][y][x] = dist[k][x][y];
        }
        doWF();
        vector<int> p(c);
        rep(i, c)cin >> p[i];
        rep(i, c){
            vector<int> q(p[i]-1), r(p[i]);
            for(auto& x: q)cin >> x;
            for(auto& x: r)cin >> x;
            calc(i, q, r);
        }
        cout << solve() << '\n';
    }
    return 0;
}

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

int N,M,K;
long long L,R,A[20001],dp[20001];

int main(){
  scanf("%d %d %d",&N,&M,&K);
  for(int i=1;i<=N;i++){
    scanf("%lld",&A[i]);
    dp[i]=(1LL<<60);
    L=R=A[i];
    for(int j=1;j<=M&&i-j>=0;j++){
      dp[i]=min(dp[i],dp[i-j]+(R-L)*j+K);
      L=min(L,A[i-j]);R=max(R,A[i-j]);
    }
  }
  printf("%lld\n",dp[N]);
  return 0;
}

Measured memory_bytes: 1500
#include <iostream>

using namespace std;

int main()
{
    cin.tie(NULL);
    int a,b;
    int sum=0;
    cin>>a>>b;
    for(int i=0;i<b;i++)
    {
        int x;
        cin>>x;
        if(sum<1e9)
        sum+=x;
    }
    if(sum>=a)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)

#define DumpArray(cont,from,to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

using namespace std;
typedef long long ll;
typedef long double ld;
int A,B;
int main() {
    cin >> A>> B;
    cout << max(A+B,max(A-B,A*B))<< endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    vector<int> A(N);
    int sum=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    
    int cnt=0;
    
    for(int i=0;i<N;i++){
        if(A[i]*4*M>=sum) cnt++;
    }
    
    if(cnt>=M) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll; 
const ll MOD = 1000000007;

int main()  
{ 
	FAST_INP;
	int n;
	double d;
	cin >> n >> d;
	int ans=0;
	for (int i=0; i<n; i++) {
		long double x, y;
		cin >> x >> y;
		long double r=sqrt(x*x+y*y);
			if (r<=d) ans++;
	}
	cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair

int main(){
  int n; cin >> n;
  vector<pii> red(n), blue(n);
  rep(i, n){
    int a, b; cin >> a >> b;
    red[i] = mp(a, b);
  }
  rep(i, n){
    int c, d; cin >> c >> d;
    blue[i] = mp(c, d);
  }
  sort(all(red));
  sort(all(blue));

  int cnt = 0;
  rep(i, n){
    int c = blue[i].fi;
    int d = blue[i].se;
    int mj = -1;
    int mb = 0;
    rep(j, red.size()){
      int a = red[j].fi;
      int b = red[j].se;
      if(a<c && b<d){
        if(b >= mb){
          mb = b;
          mj = j; 
        }
      }
    }
    if(mj >= 0){
      red.erase(red.begin() + mj);
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int w[10],k[10],x=0,y=0,z,za=0,wa=0,n,s;
	for(z=0;z<10;z++){
		scanf("%d",&w[z]);
	}
	for(s=0;s<3;s++){
		for(z=0;z<10;z++){
			if(za < w[z]){
				za = w[z];
				n = z;
			}
		}
		x += za;
		w[n] = 0;
		za = 0;
		n = 0;
	}
	for(z=0;z<10;z++){
		scanf("%d",&k[z]);
	}
	for(s=0;s<3;s++){
		for(z=0;z<10;z++){
			if(wa < k[z]){
				wa = k[z];
				n = z;
			}
		}
		y += wa;
		k[n] = 0;
		wa = 0;
		n = 0;
	}
	printf("%d %d\n",x,y);
	return 0;
}

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

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    vec<int> h(N);
    rep(i, N) cin >> h[i];
    sort(all(h),greater<int>());

    function<bool(int)> isOK = [&](int test_num) {
        int C = A-B;
        int BASE = B*test_num;
        int Count = test_num;
        rep(i,N){
            if(h[i] <= BASE) continue;
            Count-=(h[i]-BASE+C-1)/C;
            if(Count < 0) return false;
        }
        return true;
    };

    function<int()> nibutan = [&]() {
        int ng = 0;
        int ok = (h[0]/B)+1;

        /* ok と ng のどちらが大きいかわからないことを考慮 */
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;

            if (isOK(mid)) ok = mid;
            else
                ng = mid;
        }
        return ok;
    };

    cout << nibutan() << endl;

}


Measured memory_bytes: 3796
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const int N=200005;

ll n,k;
ll a[N];

bool check(ll x)
{
    ll cnt=0;
    for(int i=1;i<=n;i++)
    {
        cnt+=(a[i]+x-1)/x-1;
        if(cnt>k)return false;
    }
    return true;
}

int main()
{
    scanf("%lld %lld",&n,&k);
    ll l=1,r=1,mid;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",a+i);
        r=max(r,a[i]);
    }
    while(l<r)
    {
        mid=l+r>>1;
        if(check(mid))r=mid;
        else    l=mid+1;
    }
    printf("%lld\n",r);
    return 0;
}

Measured memory_bytes: 5276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // 現在と目指すレートの入れ物を用意
  int a, b;
  // a >= 0 で b >= 4500 (整数)で受け取る
  cin >> a >> b;
  cout << b * 2 - a << endl;
}

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

int rain(string x){
    int score = 0;
    int max_score = 0;
    for (int i = 0; i < 3; i++){
        if (x[i] == 'R'){
            score += 1;
        }
        else {
            score = 0;
        }
        if (max_score < score){
            max_score = score;
        }
    }
    return max_score;
}
int main(){
    string y;
    cin >> y;
    int p = rain(y);
    cout << p << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    long long a, b;
    cin >> a >> b;
    long long ave = (a + b) / 2;
    if (abs(a - ave) == abs(b - ave))
    {
        cout << ave << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
  int n,d,x;
  cin >> n >> d >> x;
  REP(i,n) {
    int a;
    cin >> a;
    int day = 1;
    while (day <= d) {
      x++;
      day += a;
    }
  }
  cout << x << endl;
}

int main(int argc, char *argv[]){

  // /* Regular */
  // int case_num = 1;
  // if (argc > 1 && stoi(argv[1])) cin >> case_num;
  // REP(case_no, case_num) {
  //   cerr << endl << "case " << case_no + 1 << endl;
  //   solve();
  // }
  
  /* AOJ */
  solve();
  return 0;
}

Measured memory_bytes: 256
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n,k,m;

int f(int n){
	if(n==1)return 0;
	return (k+f(n-1))%n;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>n>>k>>m && n){
		cout<<(f(n-1)+m)%n+1<<endl;
	}
}

Measured memory_bytes: 1348
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    std::string S;
    std::cin >> S;

    int64_t K;
    std::cin >> K;

    for (int64_t i = 0; i < std::min(S.size(), (size_t)K); ++i) {
        if (S[i] != '1') {
            std::cout << S[i] << std::endl;
            return 0;
        }
    }

    std::cout << '1' << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int puttable(vector<string>& t, bool mami, int i, int j) {
  if (t[i][j] != '.') return 0;
  int puttable_num = 0;
  for(int di=-1;di<=1;++di)
    for(int dj=-1;dj<=1;++dj){
      if(di==dj&&di==0)continue;
      for(int k=1;k<8;++k){
        int pi=i+di*k;
        int pj=j+dj*k;
        if(pi<0||pj<0||pi>=8||pj>=8)break;
        if(t[pi][pj]=='.')break;
        if((t[pi][pj] == 'o') == mami){
          puttable_num += k-1;
          break;
        }
      }
    }
  return puttable_num;
}

void put_i(vector<string>& t, bool mami, int i, int j) {
  t[i][j] = (mami?'o':'x');
  for(int di=-1;di<=1;++di)
    for(int dj=-1;dj<=1;++dj){
      if(di==dj&&di==0)continue;
      for(int k=1;k<8;++k){
        int pi=i+di*k;
        int pj=j+dj*k;
        if(pi<0||pj<0||pi>=8||pj>=8)break;
        if(t[pi][pj]=='.')break;
        if((t[pi][pj] == 'o') == mami){
          for(int l=1;l<k;++l){
            int li=i+di*l;
            int lj=j+dj*l;
            t[li][lj]=(mami?'o':'x');
          }
          break;
        }
      }
    }
}

void put(vector<string>& t, bool mami) {
  int num=0,pi=0,pj=0;
  if(mami){
    REP(i,8)REP(j,8){
      int n=puttable(t,mami,i,j);
      if(n > num){
        num=n;
        pi=i;pj=j;
      }
    }
  }else{
    REP(i,8)REP(j,8){
      int n=puttable(t,mami,7-i,7-j);
      if(n > num){
        num=n;
        pi=7-i;pj=7-j;
      }
    }
  }
  put_i(t,mami,pi,pj);
}

bool puttable_all(vector<string>& t, bool mami) {
  REP(i,8)REP(j,8)
    if(puttable(t,mami,i,j) > 0) return true;
  return false;
}

int main() {
  vector<string> t(8);
  REP(i,8) cin>>t[i];
  bool passed = false;
  bool mami = true;
  while(1){
    if(!puttable_all(t,mami)){
      if(passed) break;
      passed = true;
      mami = !mami;
      continue;
    }
    passed = false;
    put(t,mami);
    mami = !mami;
  }
  for(auto& s:t) cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 1184
#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 i, N, judge=0;
  
  cin >> N;
  
  rep(i,9){
    if(N%(i+1)==0 && N/(i+1) < 10) {
      judge=1;
      break;
    }
  }
  
  if(judge) cout << "Yes";
  else cout << "No";
}






Measured memory_bytes: 3644
//
//  main.c
//  ITP1_10_D
//
//  Created by k16031kk on 2018/05/29.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int n;
    scanf("%d", &n);
    double x[n], y[n];
    for(int i=0; i<n; i++) {
        scanf("%lf", &x[i]);
    }
    for(int i=0; i<n; i++) {
        scanf("%lf", &y[i]);
    }
    double p1=0.0, p2=0.0, p3=0.0, p8=0.0;
    for(int i=0; i<n; i++) {
        p1+=fabs(x[i]-y[i]);
        p2+=pow(fabs(x[i]-y[i]),2);
        p3+=pow(fabs(x[i]-y[i]),3);
        if(p8<fabs(x[i]-y[i])) p8=fabs(x[i]-y[i]);
    }
    p2=sqrt(p2);
    p3=cbrt(p3);
    printf("%lf\n", p1);
    printf("%lf\n", p2);
    printf("%lf\n", p3);
    printf("%lf\n", p8);
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
const int maxN = 1e4 + 10;
using namespace std;

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

    int32_t n;
    cin >> n;

    if(n % 1000 == 0)
    {
        cout << 0;
        return 0;
    }

    cout << (n / 1000 + 1) * 1000 - n;
}


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

int main(){
  long long x,y;
  scanf("%lld%lld",&x,&y);
  long long ans=0;
  while(y>=x){
    x=x*2;
    ans++;
  }
  printf("%lld\n",ans);
  return 0;
}
  
  

Measured memory_bytes: 128
# include <bits/stdc++.h>
  using namespace std;
# define res(a,b,c) for (int64 a=b ; a<c ; a++)
# define ress(a,b)  for (auto a = b.begin() ; a!=b.end() ; a++) 
# define all(con) con.begin() , con.end()
# define INF (int)1e9  
# define MOD 1000000007
# define pb push_back   
# define mp make_pair
# define f first
# define s second   
# define MAX numeric_limits<int>::max() 
# define MIN numeric_limits<int64>::min()
# define mymin -1000000000000000001
# define mymax 1000000000000000001
# define watch(x) cout<<(#x)<<" is "<<(x)<<endl
# define in(x) cin>>(x)
# define inn(x,y) cin>>(x)>>(y)  
# define out(x) cout<<(x)<<"\n"  
# define outt(x,y) cout<<(x)<<" "<<(y)<<"\n"  
typedef long long int int64;
typedef unsigned long long int uint64;
typedef vector<int64> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int64,int64> pi; 
bool doubleSame(double a, double b)
{ const double eps = 1e-15; return ( abs(a-b)<= eps*abs(a) ); }

int main()
{
	int64 n,k;
	cin>>n>>k;

	vector<int64> h(n);
	for(int64 i = 0 ; i<n ; i++)
		cin>>h[i];

	vector<int64> ans(n);
	ans[0] = 0;
	ans[1] = abs(h[1]-h[0]);

	for(int64 i = 2 ; i<n ; i++)
	{
		ans[i] = abs(h[i]-h[i-1])+ans[i-1];
		for(int64 j = 2 ; j<=i && j<=k ; j++)
			ans[i] = min(ans[i],abs(h[i]-h[i-j])+ans[i-j]);	
	}
	cout<<ans[n-1];
}

Measured memory_bytes: 1792
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var n = parseInt(input[0], 10);
    var f = new Array(n);
    for (var i = 0; i < n; i++) {
        f[i] = new Array(10);
        var args = input[1 + i].split(' ');
        for (var j = 0; j < 10; j++) {
            f[i][j] = parseInt(args[j], 10);
        }
    }
    var p = new Array(n);
    for (var i = 0; i < n; i++) {
        p[i] = new Array(11);
        var args = input[1 + n + i].split(' ');
        for (var j = 0; j < 11; j++) {
            p[i][j] = parseInt(args[j], 10);
        }
    }

    var ret = Number.MIN_SAFE_INTEGER;
    for (var i = 1; i < 1024; i++) {
        var cc = 0;
        for (var j = 0; j < n; j++) {
            var c = 0;
            for (var k = 0; k < 10; k++) {
                if ((i >> k & 1) == 1 && f[j][k] > 0) {
                    c++;
                }
            }
            cc += p[j][c];
        }
        if (ret < cc) {
            ret = cc;
        }
    }

    console.log(ret);

    return 0;
}


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

int main() {
  int n, k, q, t;
  cin >> n >> k >> q;
  vector<int> a(n);
  for(int i = 0; i < q; i++) {
    cin >> t;
    a.at(t - 1)++;
  }
  for(int i = 0; i < n; i++) {
    if(q - a.at(i) < k)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#include <cstdio>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main()
{
   int i,j,k,l;
   long double x;
   long double h;
   while(1) {
      cin >> x >> h;
      if (x == 0 && h == 0) break;
      printf("%llf\n", x*x + 2 *x * sqrtl(x/2*x/2+h*h));
   }
   
   return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,k,l,ii,jj;
ll n,m,a,b,c;
ll x,y,ans=0;

int main(){
	cin>>a>>b>>c>>k;
	if(k%2==1){
		p(b-a);
	}else{
		p(a-b);
	}
	return 0;
}

Measured memory_bytes: 5500
n = int(input())
p_list = list(map(int,input().split()))
count = 0
for i in range(1,len(p_list)-1):
    tmp_list = [p_list[i-1], p_list[i],p_list[i+1]]
    tmp_list.sort()
    if tmp_list[1] == p_list[i]:
        count += 1
print(count)

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

struct node{
    unsigned int key;
    struct node *next;
    struct node *prev;
};

typedef struct node *NodePointer;

NodePointer nil;

NodePointer listSerch(int key){
    NodePointer t=nil->next;
    while(t!=nil){
        if(t->key==key){
            return t;
        }
        t=t->next;
    }
    return nil;
}

void init(){
    nil=new node;
    nil->next=nil;
    nil->prev=nil;
}
void printList(){
    NodePointer cur=nil->next;
    int isf=1;
    while(1){
        if(cur==nil)break;
        if(isf==0)printf(" ");
        printf("%d",cur->key);
        cur=cur->next;
        isf=0;
    }
    printf("\n");
}

void deleteNode(NodePointer t){
    if(t==nil)return;
    NodePointer temp1=t->next,temp2=t->prev;
    temp1->prev=temp2;
    temp2->next=temp1;
    delete t;
}

void deleteFirst(){
    NodePointer t=nil->next;
    if(t==nil)return;
    deleteNode(t);
}

void deleteLast(){
    NodePointer t=nil->prev;
    if(t==nil)return;
    deleteNode(t);
}

void deletekey(int key){
    NodePointer t=listSerch(key);
    if(t==nil)return;
    deleteNode(t);
}

void insert(int key){
    NodePointer x=new node;
    x->key=key;
    NodePointer temp1=nil->next,temp2=nil;
    x->prev=temp2;
    x->next=temp1;
    temp1->prev=x;
    temp2->next=x;
}

int main(){
    int key,n;
    int size =0;
    char com[20];
    int np=0,nd=0;
    scanf("%d",&n);
    init();
    rep(i,n){
        scanf("%s",com);
        if(com[0]=='i'){cin>>key;insert(key);np++;size++;}
        else if(com[0]='d'){
            if(strlen(com)>6){
                if(com[6]=='F')deleteFirst();
                else if(com[6]=='L')deleteLast();
            }else{
                cin>>key;
                deletekey(key);nd++;
            }
            size--;
        }
    }
    printList();
    return 0;
}


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

using namespace std;

long long A[51], P[51];

long long count(int n, long long x) {
  if (n == 0) return x > 0 ? 1 : 0;
  if (x <= 1) return 0;
  if (x >= A[n]) return P[n];
  if (x <= 1 + A[n - 1]) return count(n - 1, x - 1);
  return 1 + P[n - 1] + count(n - 1, x - A[n - 1] - 2);
}

int main() {
  int N;
  long long X;
  cin >> N >> X;
  A[0] = P[0] = 1;
  for (int i = 1; i <= 50; i++) {
    A[i] = A[i - 1] * 2 + 3;
    P[i] = P[i - 1] * 2 + 1;
  }
  cout << count(N, X) << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
#input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

from collections import deque

def main():
	h,w,k=MI()
	x1,y1,x2,y2=MI()
	G=["@"]*(w+2)
	for _ in range(h):
		G.append("@")
		G+=(list(map(str,input().rstrip())))
		G.append("@")
	G+=["@"]*(w+2)
	#print(G)


	G[x1*(w+2)+y1]=0
	#print(G)

	Q=deque()
	Q.append((x1*(w+2)+y1,0))

	while Q:
		#print(Q)
		now,d=Q.popleft()
		#print(Q)
		for m in [1,-1,w+2,-w-2]:
			for i in range(1,k+1):
				if G[now+m*i]==d or G[now+m*i]=="@":
					break
				elif G[now+m*i]==".":
					G[now+m*i]=d+1
					Q.append([now+m*i,d+1])
				elif G[now+m*i]==d+1:
					continue
				else:
					break

		#print(Q)
	#print(G)

	if G[x2*(w+2)+y2]==".":
		print(-1)
	else:
		print(G[x2*(w+2)+y2])


if __name__ == "__main__":
	main()


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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vll>;
df data(n, vll(m));
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/range/algorithm.hpp> // boost::sort(arr)
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
using boost::algorithm::join; // string s = join(arr, "");
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");

int main() {
  string s;
  getline(cin, s);
  replace_all(s, ",", " ");
  cout << s << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int MOD = 1000000;
	
	int[][] es = {
			{0, 1, 2, 3},
			{0, 1, 2},
			{0, 1, 2, 4},
			{2, 3},
			{0, 4}
			};
	//	|.., .|., ..|, |_||, ||_|
	int len = 5;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(), w=sc.nextInt();
		if( w == 1 ) {
			int ret = 1;
			for(int i=0;i<h;i++) ret = ret * 2 % MOD;
			System.out.println(ret);
			return;
		}
		int[][] cnt = new int[2][len]; cnt[0][0] = 1;
		int p = 1;
		for(int i=0;i<=h;i++) {
			fill(cnt[p], 0);
			for(int j=0;j<len;j++) for(int k=0;k<es[j].length;k++) {
				cnt[p][es[j][k]] = (cnt[p][es[j][k]] + cnt[1-p][j]) % MOD;
			}
//			debug(cnt[p]);
			p = 1-p;
		}
//		int ans = ( cnt[1-p][2] + cnt[1-p][3] ) % MOD;
		System.out.println(cnt[1-p][2]);
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 17360
import java.util.Scanner;

public class Main{
    public static void main(String[]args){

        try(Scanner sc = new Scanner(System.in)){
            int w =sc.nextInt();
            int n =sc.nextInt();
            int[] values =new int[w];
            for(int i=0;i<values.length;i++){
                values[i]=i+1;
            }
            for(int i=0;i<n;i++){
                String str=sc.next();
                String[] ab = str.split(",");
                int a=Integer.parseInt(ab[0])-1;
                int b=Integer.parseInt(ab[1])-1;
                int c=0;
                c = values[a];
                values[a]=values[b];
                values[b]=c;
            }
        for(int i=0;i<values.length;i++){
            System.out.println(values[i]);
        }
        }
    }
}


Measured memory_bytes: 26032
n = gets.to_i
s = gets.to_s.chomp

case n.odd?
when true then
    puts "No"
else
    a = s.slice(0,n/2)
    t = s.slice(n/2,n-1)
    if a == t
        puts "Yes"
    else
        puts "No"
    end
end



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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

ll a[3] = {3,5,7};
set<ll> S;
ll n;
void dfs(ll v,int bit) {
  if( __builtin_popcount(bit) == 3 ) {
    S.insert(v);
  }

  rep(i,3) {
    ll w = v * 10LL + a[i];
    if( w <= n ) {
      dfs(w,bit|(1<<i));
    }
  }
}

int main() {
  cin >> n;
  dfs(7,(1<<2));
  dfs(5,(1<<1));
  dfs(3,(1<<0));
  cout << S.size() << endl;
  compute();
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);cout.tie(NULL);
        unsigned long long int n,d,x,y,ans=0;
        cin>>n>>d;
        while(n--){
                cin>>x>>y;
                if(x*x+y*y<=d*d){
                        ans++;
                }
        }
        cout<<ans;
        return 0;
}
/*

        creation time:  13.09.2020 09:23:27

*/                      



Measured memory_bytes: 3600
N=input()
T,A=map(int,input().split())
L=list(map(int,input().split()))
M=[]
#print(L)
for i in range(1,1+int(N)) :
    M.append(abs(T-(L[i-1]*0.006)-A))
print( M.index(min(M))+1)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	 static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
	
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		int l = s.nextInt();
		int r = s.nextInt();
		int d = s.nextInt();
		int c=0;
		for(int i=l;i<=r;i++) {
			if(i%d==0)c++;
		}
		System.out.println(c);
		
	}
}

Measured memory_bytes: 32764
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cmath>
#include <stack>
typedef long long ll;
#define INF 0x3f3f3f3f

using namespace std;
int gcd(int a, int b)
{
	return b == 0? a : gcd(b, a % b);
}
int x[100000 + 10];

int main(int argc, char *argv[]) {
	int n, X;
	cin >> n >> X;
	int ans;
	if(n == 1) {
		cin >> x[0];
		cout << abs(x[0] - X);
	} else {
		for(int i = 0; i < n; i++)
		{
			cin >> x[i];
		}
		ans = gcd(abs(x[0] - X), abs(x[1] - X));
		for(int i = 2; i < n; i++)
		{
			ans = gcd(ans, abs(x[i] - X));
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int n,lmoney=100000;
	int i;

	scanf("%d",&n);

	for(i = 0;i < n;i++){
		lmoney+=lmoney*(0.05);
		if(lmoney%1000>0){
			lmoney += 1000 - (lmoney%1000);
		}
	}

	printf("%d\n",lmoney);
	
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int dp[11][21][200];

signed main(){
    int n ,k, s;
    while(1){
        cin >> n >> k >> s;
        if(n + k + s == 0) break;
        rep(i, 0, 11) rep(j, 0, 21) rep(l, 0, 200){
            dp[i][j][l] = 0;
        }
        dp[0][0][0] = 1;
        rep(i, 0, k){
            rep(j, 0, n + 1){
                rep(l, 0, 160){
                    rep(m, j + 1, n + 1){
                        if(l + m > 155) continue;
                        dp[i + 1][m][l + m] += dp[i][j][l];
                    }
                }
            }
        }
        int ans = 0;
        rep(i, 0, n + 1){
            ans += dp[k][i][s];
        }
        cout << ans << endl;
    }
}

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

int main(){
    int n;
    cin >> n;
    long long ans = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        ans += a-1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

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

    ll a, b, c;
    cin >> a >> b >> c;
    bool x = (a * b * 4LL < (c - a - b) * (c - a - b));
    if (c <= a + b) x = false;
    if (x) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll  INFL = 1e18;


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    long double a, b, c; cin >> a >> b >> c;
    if(2*sqrtl(a*b) < c-(a+b)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define INF (1<<28)
typedef long long Int;

int N, M, W, T;
string S[8];
int V[8], P[8];
int L[8], X[8], Y[8], id[8][8], pf[8][8];

int wdp[1<<8][8], wt[1<<8];
Int wp[1<<8], p[8];

Int knapsack(int m, int n, int *w, Int *v) {
    static Int dp[20000];
    memset(dp, 0, sizeof(dp));
    rep(k, n) rep(i, m-w[k]+1) dp[i+w[k]] = max(dp[i+w[k]], dp[i]+v[k]);
    return *max_element(dp, dp+m+1);
}


int main() {
    cin >> N >> M >> W >> T;
    rep(i, M) cin >> S[i] >> V[i] >> P[i];
    rep(i, N) {
        cin >> L[i] >> X[i] >> Y[i];
        rep(j, L[i]) {
            string r;
            int q;
            cin >> r >> q;
            id[i][j] = find(S, S+M, r)-S;
            pf[i][j] = P[id[i][j]]-q;
        }
    }
    rep(i, 1<<8) rep(j, 8) wdp[i][j] = INF;
    rep(i, N) wdp[1<<i][i] = abs(X[i])+abs(Y[i]);
    const int nn = 1<<N;
    rep(i, nn) rep(j, N) rep(k, N) {
        wdp[i|(1<<k)][k] = min(wdp[i|(1<<k)][k],
                wdp[i][j]+abs(X[j]-X[k])+abs(Y[j]-Y[k]));
    }
    rep(k, nn) {
        wt[k] = INF;
        rep(i, N) wt[k] = min(wt[k], wdp[k][i]+abs(X[i])+abs(Y[i]));
        rep(i, M) p[i] = 0;
        rep(i, N) if(k&(1<<i)) {
            rep(j, L[i]) p[id[i][j]] = max(p[id[i][j]], (Int)pf[i][j]);
        }
        wp[k] = knapsack(W, M, V, p);
    }
    cout << knapsack(T, nn, wt, wp) << endl;
    return 0;
}

Measured memory_bytes: 0
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        Set<String> set = new HashSet<>();

        for(int i = 0;i <= 999;i++) {
            char[] tmp = new char[3];
            for(int j = 0;j < 3;j++) {
                tmp[2 - j] = (char) (((i / Math.pow(10, j)) % 10) + '0');
            }

            boolean isExist1 = false;
            boolean isExist2 = false;
            boolean isExist3 = false;
            for(int j = 0;j < s.length;j++) {
                if(!isExist1 && s[j] == tmp[2]) isExist1 = true;
                else if(!isExist2 && isExist1 && s[j] == tmp[1]) isExist2 = true;
                else if(!isExist3 && isExist2 && s[j] == tmp[0]) {
                    isExist3 = true;
                    break;
                }
            }

            if(isExist1 && isExist2 && isExist3) set.add(String.valueOf(tmp));
        }

        System.out.println(set.size());
    }
}


Measured memory_bytes: 23636
from bisect import bisect_left
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort()
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        count += bisect_left(l_list,l_list[i]+l_list[j]) - j - 1

print(count)


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

int main(){
	int i,j,iDate[10],hight[10];
	for(i=0;i<=9;++i){
		cin >> iDate[i];
		hight[i]=0;
	}
	for(i=0;i<=9;++i){
		for(j=0;j<=3;++j){
			if (iDate[i]>hight[j]){
				hight[j+2]=hight[j+1];
				hight[j+1]=hight[j];
				hight[j]=iDate[i];
				break;
			}
		}
	}
	for(i=0;i<=2;++i){
		cout << hight[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << "  = " << x << endl
typedef long long int ll;
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

#define dbg2(x, y)                                                       \
    {                                                                    \
        cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; \
    }
#define fo(i, n) for (int i = 0; i < n; i++)
#define fok(i, k, n) for (int i = k; i < n; i++)
#define foA(i, A) for (auto i : A)
const int mxN=22;
const int modd=1e9+7;
int n, total;
int dp[(1<<mxN)];

vector<vector<int>>adj(mxN);

// Think about redundant states in dp esp. in storage

int rfun(int ind, int msk){
    //deb(msk);
    //bitset<7>b(msk);cout<<b<<endl;
    if(msk==total and ind==n)return 1;
    if(ind>=n)return 0;
    if(dp[msk]!=-1)return dp[msk];
    int an=0;
    for(int i:adj[ind]){//dbg2(ind, i);
        if(msk&(1<<i))continue;
        an = (an+rfun(ind+1, msk^(1<<i)))%modd;
    }
    return dp[msk]= an;
}

int main(){
    cin>>n;
    total=(1<<n)-1;
    memset(dp, -1, sizeof dp);
    fo(i, n){
        fo(j, n){
            int x;cin>>x;
            if(x)adj[i].push_back(j);
        }
    }
    int ans=rfun(0, 0);
    cout<<ans;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count = 0;
  
  for(int i = 0; i < n; i++) {
    if(s[i] == 'A') {
      if(s[i + 1] == 'B' && s[i + 2] == 'C') {
        count++;
      }
    }
  }
  cout << count << endl;
}
  

Measured memory_bytes: 256
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(1, N):
    A[i] += A[i - 1]
dic = defaultdict(int)
num = 0
dic[0] = 1
for i in A:
    num += dic[i % M]
    dic[i % M] += 1

print(num)

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

using namespace std;

typedef pair<int,int> pi;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int T1 = H1*60 + M1, T2 = H2*60 + M2;
	cout << max(0,T2-T1-K) << '\n';
}

Measured memory_bytes: 3636
/*
  AtCoder Beginner Contest 079
  A - Good Integer

  方針
    各桁を順番に見ていく。

  実装
    10進法の場合、10で割って余る数が一番下の桁の数になる。
*/

#include<iostream>
using namespace std;

int N;

int main() {
  scanf("%d", &N);

  int buf = -1;
  int maxcnt = 0;
  int cnt = 0;
  while (N) {
    if (buf == N % 10) cnt++;
    else {
      buf = N % 10;
      cnt = 1;
    }
    maxcnt = max(maxcnt, cnt);
    N /= 10;
  }

  if (maxcnt >= 3) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

s = sum(a)
half = s / 2

cum = 0
for v in a:
    if abs(half - cum) < abs(half - (cum + v)):
        break
    cum += v
print(abs((s - cum) - cum))


Measured memory_bytes: 105132
N=int(input())
A=list(map(int, input().split()))
suc = []
point = A[0]
count = 1
for i in range(1,N):
    if A[i] == point:
        count += 1
    else:
        suc.append(count)
        count = 1
        point = A[i]
suc.append(count)
ans=0
for x in suc:
    ans += x//2
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    string t;
    cin >> t;
    for (int i = 0; i < t.size(); i++) {
        if (t[i] == '?') {
            t[i] = 'D';
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 3720
n, w = map(int, raw_input().split())
dp = [0] * (w+1)
for _ in range(n):
    v, tw = map(int, raw_input().split())
    dp[tw] = v
    for i in range(w+1):
        if dp[i] != 0 and i+tw <= w:
            dp[i+tw] = max(dp[i+tw], dp[i] + v)
print max(dp)      

Measured memory_bytes: 6768
#include <bits/stdc++.h>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(ll i = 0; i<n; i++)
#define rep_s(i, start, n) for(ll i= start;  i<n; i++)
#define rep_down(i, n) for(ll i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(ll i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()
#define print(ans) cout << ans << endl;
#define MOD 1000000007
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
 
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;
 
}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];
 
void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}
 
ll keta_num(ll num){
  ll total = 0;
  while(num){
    num /= 10;
    total++;
  }
}
 
 
ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}
 
bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}
 
ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
 
ll fibonacchi(ll num){
  ll f0 = 0, f1 = 1, f2;
  ll count = 0;
  while(count<num){
    f2 = f0+f1;
    f0 = f1;
    f1 = f2;
    count++;
  }
  return f2;
}
 
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
 
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
 
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
 
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
 
int main(void){
  ll N, M, A, B, C, D, E, F, G, K,L, W, H, P, Q, R, V, X, Y;
  string S, T;
  cin >> S >> T;
  ll count = 0;
  rep(i, S.length()) if (S[i] != T[i]) count++;
  cout <<count<< endl;
 
}

Measured memory_bytes: 3976