akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

int n,q;
Ki G(n);
vector<int> cnt(n);
vector<bool> seen(n);

void dfs(int now){
    seen[now]=true;
    for(auto &next:G[now]){
        if(seen[next]) continue;
        cnt[next]+=cnt[now];
        dfs(next);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n=10;
    vector<int> dist[n];
    rep(i,n) dist[i].assign(n,INF);
    
    rep(i,n) dist[i][i] = 0;
    int h,w;
    cin>>h>>w;
    rep(i,10){
        rep(j,10){
            int x;
            cin>>x;
            dist[i][j]=x;
        }
    }
    
    rep(k,n){
        rep(i,n){
            rep(j,n){
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }
    ll ans=0;
    rep(i,h){
        rep(j,w){
            int f;
            cin>>f;
            if(f==-1||f==1) continue;
            ans+=dist[f][1];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int n, x, y; cin >> n >> x >> y;
	--x; --y;
	vector<int> ans(n);
	rep (sv, n) {
		vector<int> dist(n, INF);
		queue<int> q;
		auto push = [&](int v, int d) {
			if (dist[v] != INF) return;
			dist[v] = d;
			q.push(v);
		};
		push(sv, 0);
		while(!q.empty()) {
			int v = q.front(); q.pop();
			int d = dist[v];
			if (v - 1 >= 0) push(v - 1, d + 1);
			if (v + 1 < n) push(v + 1, d + 1);
			if (v == x) push(y, d + 1);
			if (v == y) push(x, d + 1);
		}
		rep (i, n) ans[dist[i]]++;
	}
	rep (i, n) ans[i] /= 2;
	for (int i = 1; i <= (n - 1); ++i) {
		cout << ans[i] << endl;
	}
	return;
}

int main() {
	solve();
  return 0;
}

Measured memory_bytes: 256
//14:07:00 

#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int x,a,b; cin>>x>>a>>b;
	if(a>=b) cout<<"delicious\n";
	else if(b-a>x) cout<<"dangerous\n";
	else cout<<"safe\n";
	return 0;
}











Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iomanip>

int main(){
  long long int N, M, tmp1, tmp2;
  scanf("%lld%lld", &N, &M);
  
  std::vector<std::vector<long long int> > G(N);
  for(long long int i = 0; i < M; i++){
    scanf("%lld%lld", &tmp1, &tmp2);
    G[tmp1-1].push_back(tmp2-1);
  }
  /*
  for(long long int i = 0; i < N; i++){
    std::cerr << i << " to ";
    for(long long int j = 0; j < G[i].size(); j++){
      std::cerr << G[i][j] << " ";
    }std::cerr << std::endl;
  }*/
  
  double E, tmpd1, tmpd2;
  
  // calculate the expectation value with no operation
  std::vector<double> exp_list(N);
  for(long long int i = 0; i < N; i++){
    exp_list[i] = 0.0;
  }
  for(long long int i = N-2; i >= 0; i--){
    tmp1 = G[i].size();
    for(long long int j = 0; j < tmp1; j++){
      exp_list[i] += exp_list[G[i][j]]/(tmp1*1.0);
    }
    exp_list[i] += 1.0;
  }
  E = exp_list[0];
  
  // operation on a edge starting from s-th vertex
  for(long long int s = 0; s < N-1; s++){
    // if it is impossible to remove a edge starting from i-th vertex
    if(G[s].size() <= 1){
      continue;
    }
    // initialize exp_list
    for(long long int i = 0; i < N; i++){
      exp_list[i] = 0.0;
    }
    for(long long int i = N-2; i >= 0; i--){
      // if there is no operation
      if(i != s){
        tmp1 = G[i].size();
        for(long long int j = 0; j < tmp1; j++){
          exp_list[i] += exp_list[G[i][j]]/(tmp1*1.0);
        }
        exp_list[i] += 1.0;
      }
      // if there is operation
      else{// if(i == s)
        // determine the edge to operate: remove the edge to the vertex biggest expectation value
        tmp1 = G[i].size();
        tmpd1 = exp_list[G[i][0]];
        tmp2 = 0;
        for(long long int j = 0; j < tmp1; j++){
          if(exp_list[G[i][j]] > tmpd1){
            tmpd1 = exp_list[G[i][j]];
            tmp2 = j;
          }
        }
        // determine expectation value of the point
        for(long long int j = 0; j < tmp1; j++){
          if(j != tmp2){
            exp_list[i] += exp_list[G[i][j]]/((tmp1-1)*1.0);
          }
        }
        exp_list[i] += 1.0;
      }
    }
    // update E
    if(E > exp_list[0]){
      E = exp_list[0];
    }
  }
  
  std::cerr << "Answer:" << std::endl;
  std::cout << std::setprecision(18) << E << std::endl;
  
  return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))

using namespace std;

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

    bool is_rise = false;
    vector<int> wave (0); //kabuka,is_kau
    for(int i = 1;i < n;i++){
        if(!is_rise){
            //fall
            if(a[i-1] < a[i]){
                //ifrise
                wave.push_back(a[i-1]);
                is_rise = true;
                /* cout << i << endl; */
            }
        } else {
            if(a[i-1] > a[i]){
                //ifrise
                wave.push_back(a[i-1]);
                is_rise = false;
                /* cout << i << endl; */
            }
        }
    }

    if(wave.empty()){
        cout << 1000;
        return 0;
    }

    if(wave.back() < a[n-1] || is_rise == true){
        wave.push_back(a[n-1]);
    }

    /* for(auto i : wave){
        cout << i.first << " " << i.second << endl;
    } */
    ll money = 1000;
    for(int i = 0;i <= wave.size()-2;i++){
        if(i % 2 == 0){
            assign_max(money, (money % wave[i]) + ((money / wave[i]) * wave[i+1]));
        }
    }

    cout << money << endl;
    
    return 0;
}

Measured memory_bytes: 3200
import collections
class KMP():
    def __init__(self, pattern):
        self.pattern = pattern
        self.n = len(pattern)
        self.create_k_table()
    
    def create_k_table(self):
        ktable = [-1]*(self.n+1)
        j = -1
        for i in range(self.n):
            while j >= 0 and self.pattern[i] != self.pattern[j]:
                j = ktable[j]
            j += 1
            if i+1 < self.n and self.pattern[i+1] == self.pattern[j]:
                ktable[i+1] = ktable[j]
            else:
                ktable[i+1] = j
        self.ktable = ktable

    def match(self,s):
        n = len(s)
        j = 0
        ret = [0]*n
        for i in range(n):
            while j >= 0 and (j == self.n or s[i] != self.pattern[j]):
                j = self.ktable[j]
            j += 1
            if j == self.n:
                ret[(i-self.n+1)%n] = 1 
        return ret

def main():
    s = input()
    t = input()
    n = len(s)
    m = len(t)
    k = 1 - (-(m-1)//n)
    si = s*k
    a = KMP(t)
    b = a.match(si)
    edges = [[] for i in range(n)]
    indegree = [0] * n
    for i in range(n):
        k = (i+m)%n
        if b[i]:
            edges[i].append(k)
            indegree[k] += 1
    
    def topSort():
        q = collections.deque([i for i in range(n) if indegree[i] == 0])
        while q:
            cur = q.popleft()
            res.append(cur)
            for nei in edges[cur]:
                indegree[nei] -= 1
                if indegree[nei] == 0:
                    q.append(nei)
        return len(res) == n
    
    res = []
    dp = [0] * n
    flag = topSort()
    if flag:
        for k in range(n):
            i = res[k]
            for j in edges[i]:
                dp[j] = max(dp[j], dp[i] + 1)
        ans = max(dp)
    else:
        ans = -1
    return ans
     

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 135184
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String s = sc.next();

    char[] ch = s.toCharArray();
    int red = 0;
    int blue = 0;

    for(int i = 0; i < ch.length; i++) {
    	if(ch[i] == 'R') {
    		red++;
    	}else {
    		blue++;
    	}
    }

    if(red > blue) {
    	System.out.println("Yes");
    }else {
    	System.out.println("No");
    }

  }
}


Measured memory_bytes: 22608
#include <stdio.h>
int min(int, int);

int main(void){
    int h, w, c[10][10], a[200][200];
    int i, j, k, s=0;
    
    scanf("%d %d", &h, &w);
    for(i = 0; i < 10; i++){
        for(j = 0; j < 10; j++){
            scanf("%d", &c[i][j]);
        }
    }
    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            scanf("%d", &a[i][j]);
        }
    }

    for(i = 0; i < 10; i++){
        for(j = 0; j < 10; j++){
            for(k = 0; k < 10; k++){
                c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
            }
        }
    }

    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            if(a[i][j]>=0 && a[i][j]!=1){
                s += c[a[i][j]][1];
            }
        }
    }
    printf("%d\n", s); 
    
    return 0;
}

int min(int x, int y){
    if(x < y) return x;
    else return y;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

    int sum=0;
    for(int a=A ; a<B ; a++){
        if(a>=C && a<D)sum++;
    }
    cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  int a,b;
  cin >> a >> b;
  if(a < b){
    for(int i=0; i<b; i++) cout << a;
    cout << endl;
  } else if(a > b){
    for(int i=0; i<a; i++) cout << b;
    cout << endl;
  } else {
    for(int i=0; i<a; i++) cout << b; 
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N,K = gets.split.map(&:to_i)
has = Array.new(N, false)

K.times {
  gets
  a = gets.split.map(&:to_i)
  a.each { |_a|
    has[_a-1] = true
  }
}

cnt = 0
#p has
has.each { |v|
  if v == false
    cnt += 1
  end
}

puts cnt


Measured memory_bytes: 14388
#include<bits/stdc++.h>
using namespace std;
int main(){
  int X, Y;
  cin >> X >> Y;
  bool seigo = false;
  for(int i = 0; i < X + 1; i++){
    if(2*i+4*(X-i) == Y){
      seigo = true;
      break;
    }
  }
  if(seigo == true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s;
    cin>>t;
    int i,cnt;
    if(s.length()>=1&&s.length()<=10&&(t.length()==s.length()+1))
    {
        cnt=0;
        for(i=0;i<s.length();i++)
        {
            if(t[i]==s[i])
                cnt++;
        }
        if(cnt==s.length())
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int c=1,ans=0;
    while(c<b){
        c+=(a-1);
        ans++;
    }
    cout << ans;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
int N, K;
	cin >> N >> K;
	int ans = 0;
	fx(N) {
		int h;
		cin >> h;
		if (h>=K) {
			ans ++ ;
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int count = 0;

		for (int i = 1; i <= n; i++) {
			if (Integer.toString(i).length() % 2 == 1) {
				count++;
			}
		}
		System.out.println(count);

	}
}

Measured memory_bytes: 28116
//In The Name of Allah
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template < class T > using Tree = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;

typedef long long            ll;
typedef long double          ld;
typedef string               str;
typedef pair < ll , ll >     pll;

#define X               first
#define Y               second
#define pb              push_back
#define all(x)          (x).begin(), (x).end()
#define SZ(x)           (ll)(x.size())
#define sep             ' '
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define dbl_io(x)       cout << fixed << setprecision(x);

const int N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 10;

int main(){
    fast_io
    //dbl_io(10);
    ll n, m;
    cin >> n >> m;
    ll ans = (m * 1900LL + (n - m) * 100LL) << m;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef pair<int,pair<int,int> > piii;


int main(){
	int n,m,a;
	while(1){
		cin>>n>>m>>a;
		if(!n&&!m&&!a)break;
		piii w[m];
		rep(i,m)cin>>w[i].first>>w[i].second.first>>w[i].second.second;
		sort(w,w+m);
		reverse(w,w+m);
		rep(i,m){
			if(w[i].second.first==a){
				a=w[i].second.second;
			}else if(w[i].second.second==a){
				a=w[i].second.first;
			}
		}
		cout<<a<<endl;
	}
	return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(m);
  for(int i=0;i<m;i++) cin >> a.at(i);

  int sum=0;
  for(int i=0;i<m;i++) sum+=a.at(i);

  if(sum>n) cout << "-1" << endl;
  else{
    int res=n-sum;
    cout << res << endl;
  }
  
  return 0; 
}


Measured memory_bytes: 3640
//#pragma GCC optimize(3)
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=0;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int n,maxc;
vector<pair<int,int> >seq;
vector<int> g[100010];
map<pair<int,int>,int> mpp;
void dfs(int v,int p,int c){
	int siz=g[v].size();
	int col=1;
	rep(i,siz){
		if(g[v][i]==p)continue;
		if(col==c)col++;
		pair<int,int> pa,pb;
		pa.first=v;pa.second=g[v][i];
		pb.first=v;pb.second=g[v][i];
		mpp[pa]=col;mpp[pb]=col;
		dfs(g[v][i],v,col);
		maxc=max(maxc,col);
		col++;
	}
}
int main(int argc,char** argv){
	/*
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);*/
	//freopen("input.txt","r",stdin);
	scanf("%d",&n);
	rep(i,n-1){
		int a,b;
		scanf("%d %d",&a,&b);
		g[a].pb(b);
		g[b].pb(a);
		seq.pb(mp(a,b));
	}
	dfs(1,-1,-1);
	printf("%d\n",maxc);
	rep(i,n-1){
		printf("%d\n",mpp[seq[i]]);
	}
	return 0;
}


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

int main(int argc, char const *argv[]) {
    int x, y, r;
    cin >> x >> y;
    while (x % y != 0) {
        r = x % y;
        x = y;
        y = r;
    }

    cout << y << endl;
    return 0;
}



Measured memory_bytes: 3108
#include <stdio.h>

int main()
{
  char c1[4], c2[4];
  scanf("%s", c1);
  scanf("%s", c2);
  if (c1[0]==c2[2] && c1[1]==c2[1] && c1[2]==c2[0]){
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128
S = input()
if len(S) % 2 == 0:
    N1 = "01" * (len(S)//2)
    N2 = "10" * (len(S)//2)
else:
    N1 = "01" * (len(S)//2) + "0"
    N2 = "10" * (len(S)//2) + "1"
n1 = 0
n2 = 0 
for i in range(len(S)):
    if S[i] != N1[i]:
        n1 = n1+1
    elif S[i] != N2[i]:
        n2 = n2+1
print(min(n1, n2))

Measured memory_bytes: 3316
#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()

const int MOD = 1000000007;
const int INF = 1 << 30;

lint log_mul(lint base, lint bit) {
    lint res = 0;

    while (bit) {
        if (bit & 1) res = (res + base) % MOD;
        base = (base + base) % MOD;
        bit >>= 1;
    }

    return res;
}

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

    unordered_map<lint, lint> m;

    for (int i = 2; i <= n; i++) {
        int t = i;
        int j = 2;
        while (j * j <= t) {
            if (t % j == 0) {
                m[j]++;
                t /= j;
            }
            else {
                j++;
            }
        }
        if (t > 1) m[t]++;
    }

    lint res = 1;

    for (auto&& p : m) {
        res = log_mul(res, p.second+1);
        res %= MOD;
    }

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


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func Solve(s string, k int) string {
	c := s[k-1]
	result := make([]byte, len(s))
	copy(result, s)
	for i := 0; i < len(s); i++ {
		if s[i] != c {
			result[i] = '*'
		}
	}
	return string(result)
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var s string
	fmt.Scanf("%s", &s)
	var k int
	fmt.Scanf("%d", &k)
	result := Solve(s, k)
	fmt.Println(result)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_backpostdoctoral
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;
 
template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
 
const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  	
  	int h1, m1, h2, m2;
  	cin >> h1 >> m1 >> h2 >> m2;
  	int a1 = h1 * 60 + m1;
  	int a2 = h2 * 60 + m2;
  	int k;
  	cin >> k;
  	cout << max(0, a2 - a1 - k) << endl;
	
  	
  	
    cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 3804
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
string s;
int main(){
fcin;
    cin >> s;
    if(s == "SUN") cout << 7 << "\n";
    if(s == "SAT") cout << 1 << "\n";
    if(s == "MON") cout << 6 << "\n";
    if(s == "TUE") cout << 5 << "\n";
    if(s == "WED") cout << 4 << "\n";
    if(s == "THU") cout << 3 << "\n";
    if(s == "FRI") cout << 2 << "\n";
    


}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	if(n%m==0)
	{
		cout<<0<<endl;
		return 0;
	}
	if(n%m!=0||n<m)
	{
		cout<<1<<endl;
		return 0;
	}
 } 

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

int main() {
    string s;
    cin >> s;
    long long int sum = 0;
    for (int bit = 0; bit < (1 << (s.size() - 1)); bit++) {
        int last_ind = 0;
        for (int i = 0; i < s.size() - 1; i++) {
            if (bit & (1 << s.size() - 2 - i)) {
                sum += stoll(s.substr(last_ind, i + 1 - last_ind));
                last_ind = i + 1;
            }
        }
        sum += stoll(s.substr(last_ind));
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3628
import sys
import itertools

N,M,R=map(int, raw_input().split())

d=[  [ float("inf") for j in range(N+1) ]  for i in range(N+1) ]

r=map(int, sys.stdin.readline().split())

for _ in range(M):
	a,b,c=map(int, sys.stdin.readline().split())
	d[a][b]=c
	d[b][a]=c


for _ in range(3):
	for i in range(1,N+1):
		for j in range(1,N+1):
			for k in range(1,N+1):
				d[i][j]=min(d[i][j], d[i][k]+d[k][j])


C=list(itertools.permutations(r))


ans=float("inf")
for x in C:
	tmp_ans=0
	for i in range(R-1):
		fro=x[i]
		to=x[i+1]
		tmp_ans+=d[fro][to]
	ans=min(ans, tmp_ans)

print ans
		

Measured memory_bytes: 38812
#include<iostream>
#include<stdio.h>
#include<iomanip>
using namespace std;
int main()
{
    double a,b,c,d,e,f,x,y;
    while(cin>>a>>b>>c>>d>>e>>f)
    {

    cout<<setprecision(3)<<fixed;
    x=((-b*f)+(c*e))/(a*e-b*d);
    y=(-c*d+a*f)/(a*e-b*d);
    if(x==0)x=0;
    if(y==0)y=0;
    cout<<x<<" "<<y<<endl;
    }



    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long x = scan.nextLong();
		long count = 0;

		count = b/x - a/x;

		if(a%x==0) {
			count++;
		}

		//if(a==b && a%x)
		//}

		/*
		count = (b-a)/x;


		if(a==0) {
			count = count +1;
		}

		if(a>=x) {
			count = count + 1;
		}



		if(a==b && a%x!=0) {
			count =0;
		}else if(a==b && a%x==0) {
			count =1;
		}

		//System.out.println((b-a)%x);

		 */
		System.out.println(count);
	}

}


Measured memory_bytes: 23764
#include <iostream>  
#include <cstdio>  
#include <algorithm>  
#include <set>  
#include <string>  
#include <cstring>  
#include <cmath>  
#include <map>  
#define N 505  
using namespace std;  
typedef long long ll;  
int c[505]; //到一个车站的花费时间  
int s[505]; //一个车站出发的等待时间  
int f[505];  //一个车站每f秒出发一个车  
int main()  
{  
    int x;  
    scanf("%d",&x);  
    for(int i=1;i<=x;i++)  
        scanf("%d%d%d",&c[i],&s[i],&f[i]);  
    for(int i=1;i<=x;i++){  
        int ans=0;  
        for(int j=i;j<x;j++){  
            if(ans<s[j])   //小于等待时间重新赋值  
                ans=s[j];  
            if(ans%f[j]!=0)    //是否处于间隔时间  
                ans=ans+f[j]-ans%f[j];  
            ans+=c[j];  
        }  
        printf("%d\n",ans);  
    }  
}  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=250020;
const ll MOD1=1000000007;
const ll MOD2=1000000009;
const ll p=250007;
ll N,lux1[2*MAX],lux2[2*MAX],ptarr[MAX],ans;
char S[MAX];
map<pll,ll> cum;
ll power(ll x,ll y,ll m){
    if(y==0) return 1;
    ll t=power(x,y/2,m);
    if(y%2) return t*t%m*x%m;
    return t*t%m;
}
void dc(ll idx,ll mul,ll *pt,ll* val1,ll* val2){
    switch(S[idx]){
    case '<':
        *pt-=1; break;
    case '>':
        *pt+=1; break;
    case '+':
        *val1+=mul*lux1[*pt];
        *val2+=mul*lux2[*pt];
        break;
    case '-':
        *val1-=mul*lux1[*pt];
        *val2-=mul*lux2[*pt];
        break;
    }
    *val1+=MOD1,*val1%=MOD1;
    *val2+=MOD2,*val2%=MOD2;
}
int main(){
    scanf(" %lld %s",&N,S);
    lux1[N]=1,lux2[N]=1;
    int inv_p1=power(p,MOD1-2,MOD1),inv_p2=power(p,MOD2-2,MOD2);
    for(ll i=N;i<=2*N-1;i++) {
        lux1[i+1]=lux1[i]*p%MOD1;
        lux2[i+1]=lux2[i]*p%MOD2;
    }
    for(ll i=N;i>=1;i--) {
        lux1[i-1]=lux1[i]*inv_p1%MOD1;
        lux2[i-1]=lux2[i]*inv_p2%MOD2;
    }
    ll pt1=N,pt2=N;
    pll val1(0,0),val2(0,0),val3(0,0);
    for(ll i=0;i<N;i++) dc(i,1,&pt2,&val2.first,&val2.second);
    pt2=N; val3=val2;
    for(ll i=0;i<N;i++){
        ll t1,t2;
        t1=((val3.first-val3.first*lux1[pt1]-val1.first)%MOD1+MOD1)%MOD1;
        t2=((val3.second-val3.second*lux2[pt1]-val1.second)%MOD2+MOD2)%MOD2;
        cum[make_pair(t1,t2)]++;
        dc(i,-1,&pt2,&val2.first,&val2.second);
        //printf("val2: %lld %lld %lld\n",pt2,t1,t2);
        //printf("val1: %lld %lld %lld\n",pt1,val1.first,val1.second);
        ans+=cum[val2];
        dc(i,1,&pt1,&val1.first,&val1.second);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 39680
x = int(input())

n = (x//11)
i = 0
now = n*11
while(1):
  i += 1
  if x%11 == 0:
    print(2*n)
    break
  if i%2 == 1:
    now += 6
    if now >= x:
      print(2*n + 1)
      break
  else:
    now += 5
    if now >= x:
      print(2*n + 2)
      break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define V vector<int>
#define VLL vector<long long>
#define VV vector<vector<int>>
#define be(x) begin(x),end(x)
#define For(a) for(int i=0;i<a;i++)
#define Forin(a,b) for(int j=a;j<b;j++)
#define len(a) a.size()
#define pb push_back 
#define mp make_pair
#define Um unordered_map
#define S unordered_set
#define mod 1000000007
using namespace std;
ll findProductSum(ll A[], ll n)
{
	ll sum = 0,result=0;
	for (ll i = 0; i < n; i++)
	sum = sum + A[i];
	for(int i=0;i<n;i++)
	{
	    sum-=A[i];
	    result+=((A[i]%mod)*(sum%mod))%mod;
	}
	return result%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie();
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
    #endif 
	ll n;
	cin>>n;
	ll a[n];
	For(n) cin>>a[i];
    cout<<findProductSum(a,n)<<"\n";

}


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

int main() {
    // your code goes here
    ll h,n,i,a[100005],sum=0;
    cin >> h >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
        sum+=a[i];
    }
    if(sum>=h) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

const int N = 3005, mod = 998244353;

int n, m, dp[N][N];
int yo(int i, int j) {
	if (i < n || j < m) return 0;
	if (i == n && j == m) return 1;
	int &ret = dp[i][j];
	if (ret != -1) return ret;
	long long ans = 1LL * yo(i - 1, j) * j + 1LL * yo(i, j - 1) * i;
	ans -= 1LL * yo(i - 1, j - 1) * (i - 1) * (j - 1);
	ans %= mod;
	ans = (ans + mod) % mod;
	return ret = ans;
}
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int p, q; cin >> n >> m >> p >> q;
	memset(dp, -1, sizeof dp);
	cout << yo(p, q) << '\n';
    return 0;
}

Measured memory_bytes: 39368
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
#define MOD (1000000007ll)
#define l_ength size

bool flag = true;

int main(void){
	ll n,a,b,x,y,m,p,q,r,i,j;
	vector<ll> v;
	cin >> n >> a >> b;
	if(a == 1ll){
		if(b == n){
			for(i=n; i>0ll; --i){
				cout << i << ((i)?" ":"");
			}
			cout << endl;
		}else{
			cout << -1 << endl;
		}
		return 0;
	}
	x = a*b;
	y = a+b-1ll;
	if(x < n || y > n){
		cout << "-1" << endl;
		return 0;
	}
	x = n-b;
	y = a-1ll;
	p = x/y;
	q = x%y;
	r = y-q;
	x = 0ll;
	for(i=1ll; i<=r; ++i){
		for(j=0; j<p; ++j){
			v.push_back(p*i-j);
			x = max(x,p*i-j);
		}
	}
	++p;
	for(i=1ll; i<=q; ++i){
		for(j=0; j<p; ++j){
			v.push_back(x+p*i-j);
		}
	}
	for(i=0ll; i<b; ++i){
		v.push_back(n-i);
	}
	for(i=0; i<n; ++i){
		cout << ((i)?" ":"") << v[i];
	}
	cout << endl;
	return 0;
}


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

#define ll long long int
#define vi vector<int> 
ll prime(int i){

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




int main() {
  long long int a,b;
  cin >> a >>b;
  cout << (a*b)/__gcd(a,b);
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rev(a) reverse(all(a)
bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
   
int main() {
    long double a,b,x,temp,temp1;
    cin >> a >> b >> x;
    temp=(b*b*a)/(2*x);
    temp1=(2*b/a)-(2*x)/(a*a*a);
    //cout << temp << endl;
    if(x>(b*a*a/2)) temp=temp1;
    else temp=temp;
    long double ans=atan(temp);
    ans=ans*180/M_PI;
    cout << fixed << setprecision(10) << ans <<endl; 
   
	return 0;
}

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

/* define*/
#define Yes(X) puts ( X ? "Yes" : "No")
#define YES(X) puts ( X ? "YES" : "NO")
#define FOR(i, a, b) for ( i = a, i < b ; i++)
#define REP(i, n) for ( i = 0; i < n ; i++)
#define DER(i, n) for ( i = 0; n ; i--)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1e9 + 7;

/* alias */
typedef long long ll;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}

//* main */
int i, j, k;

int main() {
	int n, t, a[10000], r;
	scanf("%d%d", &n, &t);
	REP(i, t)scanf("%d", &a[i]);
	qsort(a, t, sizeof(int), cmp2);
	r = 2 * a[0] - n - 1;
	printf("%d", max(0, r));
	return 0;
}

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

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        
        if(a<b){
            System.out.println("a < b");
        } else if(a>b){
            System.out.println("a > b");
        } else {
            System.out.println("a == b");
        }
    }
    
}



Measured memory_bytes: 26148
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int bseh(int val, V<int> &v, int n) {
    int l = -1, r = n;
    while(r-l > 1) {
        int mid = (l+r) / 2;
        if(v[mid] >= val) {
            r = mid;
        } else {
            l = mid; 
        }
    }
    return r;
}

int main(){
    INIT;
    int n;
    V<int> v;
    cin >> n;
    v.resize(n);
    REP(i,n) { cin >> v[i]; }
    std::sort(ALL(v));
    LL ans = 0;
    FOR(k,1,100001) {
        int idx = bseh(k,v,n);
        if((n/2) == idx) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 640
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cfloat>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}

inline void solve(void){
  int n;in(n);
  vector<int> a(n);
  rep(i,n)in(a[i]);
  double ave=(double)accumulate(all(a),0)/n;
  double diff=DBL_MAX;
  int id=n-1;
  dw(i,n-1,0){
    if(abs(ave-a[i])<=diff){
      id=i;
      diff=abs(ave-a[i]);
    }
  }
  out(id);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
import heapq

INF = 10**9

def solve():
  # n から 1への最短距離をもとめる
  H,W = map(int, input().split())
  graph = [list(map(int, input().split())) for _ in range(10)]
  search_table = [[i != 1 and i != j for i in range(10)] for j in range(10)]
  min_distance_n_to_1 = [INF]*10
  min_distance_n_to_1[1] = 0
  
  # 1から逆にたどっていく
  queue = [(min_distance_n_to_1[v], v) for v in range(10)]
  heapq.heapify(queue)

  while queue:
    _, dom = heapq.heappop(queue)
    # print(dom, min_distance_n_to_1)
    for i in range(10):
      # if not search_table[dom][i]: continue
      # search_table[dom][i] = False
      
      if min_distance_n_to_1[i] > min_distance_n_to_1[dom] + graph[i][dom]:
        min_distance_n_to_1[i] = min_distance_n_to_1[dom] + graph[i][dom]
        heapq.heappush(queue, (min_distance_n_to_1[i], i))

  # print(min_distance_n_to_1)
  ret = sum(sum(min_distance_n_to_1[int(Aij)] if int(Aij) != -1 else 0 for Aij in input().split()) for _ in range(H))
  print(ret)
  
solve()

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


int main(){
    Int N, M, K;
    cin >> N >> M >> K;
    vector<Int> A(N), B(M);
    rep(i,N) cin >> A[i];
    rep(j,M) cin >> B[j];

    Int now = 0, time = 0, ans;
    rep(i,N) {
        if (time + A[i] > K) {
            break;
        }
        time += A[i];
        now++;
    }
    Int nowN = now, maxN = now;
    rep(j,M) {
        if (time + B[j] > K) break;
        time += B[j];
        now++;
    }
    Int nowM = now - nowN;
    ans = now;
    for (int i = maxN; i>0; i--) {
        time -= A[i-1];
        now--;
        for (int j = nowM; j<M; j++) {
            if (time + B[j] > K) break;
            time += B[j];
            now++;
            nowM++;
        }
        ans = max(ans, now);
    }

    cout << ans << endl;
}

Measured memory_bytes: 6420
import Data.List.Split (splitOn)
import Data.List (transpose, genericLength)

mean :: (Fractional a, Real b) => [b] -> a
mean l = (sum . map realToFrac) l / (genericLength l)

totalSalesAmount :: Integral a => [[a]] -> a
totalSalesAmount = sum . (map product)

salesQuantityAvergage :: Integral a => [[a]] -> a
salesQuantityAvergage l = truncate $ (+) 0.5 $ mean $ flip (!!) 1 $ transpose l

main :: IO ()
main = putStr . unlines . map show . (\l -> [totalSalesAmount l, salesQuantityAvergage l]) .
    map (map read) . map (splitOn ",") . lines =<< getContents

Measured memory_bytes: 3752
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
		
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final long X = sc.nextLong();
			
			final long X_500 = X / 500;
			final long X_5 = (X - X_500 * 500) / 5;
			
			System.out.println(X_500 * 1000 + X_5 * 5);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int kuji[1005][105];

int main()
{
//	cut here before submit 
//	freopen ("testcase.ACM", "r", stdin );
	int n, m, a;
	while (scanf ("%d %d %d", &n, &m, &a ), n, m, a ){
		memset (kuji, 0, sizeof (kuji ) );
//		rep (i, m ){
		for (int i = 1; i <= m; i++ ){
			int h, p, q;
			scanf ("%d %d %d ", &h, &p, &q );
			kuji[1000-h][p] = i; kuji[1000-h][q] = i;
		} // end rep
		int curr = a;
		for (int i = 0; i < 1005; i++ ){
			if (kuji[i][curr] ){
				if (kuji[i][curr] == kuji[i][curr-1] ) curr--;
				else curr++;
			} // end if
		} // end for
		printf ("%d\n", curr );
/*
		// for debug
		rep (i, 10 ){
			rep (j, n+1 ){
				cout << kuji[i][j];
			} // end rep
			cout << endl;
		} // end rep
		cout << endl;
*/
//		cout << curr << endl;
	} // end while

	return 0;
}

Measured memory_bytes: 1612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {
	
	vi a(5);
	rep(i, 5)cin >> a[i];
	rep(i, 5)if (a[i] == 0)cout << i + 1 << endl;

}

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

using namespace std;

int main()
{
    int k,n;
    cin >> n;
    k = n; 
    int sn = 0;

    while(k){
        sn += (k%10);
        k /= 10;
    } 
    
    if(n%sn==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256