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

#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
// vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

typedef pair<ll,ll> P;
#define MAX_V 201
struct edge { ll to, cost; };
vector<edge> g[MAX_V];
ll d[MAX_V];

void dijkstra(int s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + MAX_V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < g[v].size(); i++) {
			edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}


ll N; // 頂点数
ll color[MAX_V]; // 頂点iの色(1 or -1)
vector<ll> G[MAX_V]; // グラフ 
// 頂点を1と-1で塗っていく 
bool dfs(int v, int c) {
	color[v] = c; // 頂点vをcで塗る
	for (int i = 0; i < G[v].size(); i++) {
		// 隣接している頂点が同じ色ならfalse
		if (color[G[v][i]] == c) return false;
		// 隣接している頂点がまだ塗られていないなら-cで塗る
		if (color[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false;
	}
	// すべての頂点を塗れたらtrue 
	return true;
}

void solve(long long N, vector<string> S){
	// グラフ初期設定
	rep(i, N) {
		rep(j, N) {
			if (S[i][j] == '1') G[i].push_back(j);
		}
	}
	for (int i = 0; i < N; i++) {
		if (color[i] == 0) {
		// まだ頂点iが塗られていなければ1で塗る 
			if (!dfs(i, 1)) {
				printf("-1\n");
				return;
			}
		}
	}

	// グラフ初期設定
	rep(i, N) {
		rep(j, N) {
			if (S[i][j] == '1') {
				edge e1 = {j,1};
				g[i].push_back(e1);
			}
		}
	}

	ll res = 0;
	rep(i, N) {
		dijkstra(i);
		rep(j, N) {
			res = max(res, d[j]);
		}
	}
	cout << res+1 << endl;
}

int main(){	
	scanf("%lld",&N);
	vector<string> S(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		cin >> S[i];
	}
	solve(N, S);
	return 0;
}



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

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

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

//constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

void solve(int n) {
	vi v(n, 0);
	vi dist(n + 1, INF);
	vector<vector<bool>> dp(n + 1, vector<bool>(n, false));
	rep(i, n) {
		cin >> v[i];
	}
	for (int l = 2; l <= n; l += 2) {
		for (int i = 0; i + l <= n; i++) {
			bool b = false;
			if (l != 2) {
				for (int j = 2; j<l; j += 2) {
					if (dp[j][i] && dp[l - j][i + j])
						b = true;
				}
			}
			int dif = abs(v[i] - v[i + l - 1]);
			if (dif <= 1&&(l==2?1:dp[l-2][i+1]))b = true;
			if (b)dp[l][i] = true;
			//cout << l << " " << i << " " << dp[l][i] << endl;
		}
	}
	int pos = 0;
	deque<pii> q;
	q.push_back({ 0,0 });
	while (!q.empty()) {
		pii p = q.front(); q.pop_front();
		if (p.sc < dist[p.fs]) {
			dist[p.fs] = p.sc;
			if (p.fs == n) {
				cout << n - p.sc << endl;
				return;
			}
			for (int i = 2; i < n + 1; i += 2) {
				if (dp[i][p.fs]) {
					q.push_front({ p.fs + i,p.sc });
				}
			}
			q.push_back({ p.fs + 1 ,p.sc + 1 });
		}
	}

}

int main(void) {
	int ans = 0;
	string s;
	cin >> s;
	rep(i, 4) {
		if (s[i] == '+')ans++;
	}
	cout << -4 + (ans * 2) << endl;
}



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

int resolve(int schedule[], int n, int f[][5][2], int p[][11], int index);

int main() {
  int n;
  cin >> n;
  int f[n][5][2];
  int p[n][11];
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        cin >> f[i][j][k];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  
  int schedule[10];
  int max;
  max = resolve(schedule, n, f, p, 0);

  cout << max << endl;
}

int resolve(int schedule[], int n, int f[][5][2], int p[][11], int index) {  
  if (index == 10) {
    int o_c = 0;
    for (int i = 0; i < 10; i++) {
      o_c += schedule[i];
    }
    if (o_c == 0) {
      return -10e7 * n;
    }
    
    int rev = 0;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if (schedule[j] == 1 && f[i][j / 2][j % 2] == 1) {
          cnt++;
        }
      }
      rev += p[i][cnt];
    }
    return rev;
  }
  
  int rev0, rev1; 
  schedule[index] = 0;
  rev0 = resolve(schedule, n, f, p, index + 1);
  
  schedule[index] = 1;
  rev1 = resolve(schedule, n, f, p, index + 1);
      
  return (rev0 > rev1) ? rev0 : rev1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define lli            long li
#define ull            unsigned lli
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vlli           vector<lli>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;i++)               
#define forr(i,s,n)    for(auto i=s;i>=n;i--) 
const lli MOD = 1e9+7;
const lli mx = 1e7; 

void solve()
{
    int n,k;
    cin>>n>>k;
    vi a(n);
    forn(i,0,n)
        cin>>a[i];
    sort(a.begin(),a.end());
    int sum=0;
    forn(i,0,k)
    sum+=a[i];
    cout<<sum<<endl;
}


int32_t main()
{
    ioS
    // int t;
    // cin>>t;
    // while(t--)
        solve();
}

Measured memory_bytes: 3620
n = int(input())
a = list(map(int,input().split()))
res = 0
i = 0
if n%2:
    a.append(a[n-1]+1)
#print(a)

while i < n-1:
    if a[i] == a[i+1]:
        res += 1
        i+=1
    i+=1
print(res)

Measured memory_bytes: 9064
#include<stdio.h>
#include<stdlib.h>

int main(){
  int a, b, DigitOfNumber[200], j=0;
  while(scanf("%d%d", &a, &b) != EOF){
    DigitOfNumber[j] = returnDigitOfNumber(a+b);
    j+=1;
  }
  int i;
  for(i=0; i<j; i++){
    printf("%d\n", DigitOfNumber[i]);
  }
  return 0;
}

int returnDigitOfNumber(int number){
  int digit = 1, break_num = 10;
  while(number / break_num != 0){
    break_num *= 10;
    digit+=1;
  }
  return digit;
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;
constexpr int tenfive = 100000;

int main() {
	int a, b, c;
	cin >> a>>b>>c;
	cout << ((a + b + c) > 21 ? "bust":"win") << endl;
	return 0;
}


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

int main() {
  int K;
  cin>>K;
  int Z=0;
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      for(int l=1;l<=K;l++){
        Z+=gcd(i,gcd(j,l));
      }
    }
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9+7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

//拡張拡張Euclidの互除法による(階乗)逆元の求め方
//O(N)
void stairs(long long N, vector<long long>& st, long long mod = 1e9 + 7) {
	st.resize(N + 1, 1);
	for (long long n = 2; n <= N; n++) {
		st[n] = (st[n - 1] * n) % mod;
	}
}

void modinvs(long long N, vector<long long>& inv, vector<long long>& sinv, long long mod = 1e9 + 7) {
	inv.resize(N + 1);
	sinv.resize(N + 1);
	inv[1] = 1;
	sinv[0] = 1;
	sinv[1] = 1;
	for (int n = 2; n <= N; n++) {
		inv[n] = mod - (inv[mod % n] * (mod / n)) % mod;
		sinv[n] = (sinv[n - 1] * inv[n]) % mod;
	}
}

long long Comb(long long n, long long k, vector<long long>& st, vector<long long>& sinv, long long mod = 1e9 + 7) {
	long long ans = st[n];
	ans = (ans * sinv[n - k]) % mod;
	ans = (ans * sinv[k]) % mod;
	return ans;
}

ll N, M, K;
vector<ll> stair, inv, sinv;

int main() {
	cin >> N >> M >> K;
	stairs(M*N, stair);
	modinvs(max(M * N,(ll)6), inv, sinv);
	ll temp1 = ((N - 1) * N * M) % MOD;
	temp1 = (temp1 * M) % MOD;
	temp1 = (temp1 * (N + 1)) % MOD;
	temp1 = (temp1 * inv[6]) % MOD;
	ll temp2 = ((M - 1) * M * N) % MOD;
	temp2 = (temp2 * N) % MOD;
	temp2 = (temp2 * (M + 1)) % MOD;
	temp2 = (temp2 * inv[6]) % MOD;
	ll ans = (temp1 + temp2) % MOD;
	ans = (ans * Comb(N * M - 2, K - 2, stair, sinv))%MOD;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
    string str;
    bool isYes = true;
    cin >> str;

    for(int i = 0; i < str.size(); i++){
        for(int j = i + 1; j < str.size(); j++){
            if(str[i] == str[j]){
                isYes = false;
                break;
            }
        }
    }
    if(isYes)
        cout << "yes";
    else
        cout << "no";

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define REP3(i,x,n) for(int i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    ll N,i=0,x,minimum_HP=INF,sum = 0;
    vector<ll> X;
    for(cin>>N;i<N;i++){cin >>x; X.push_back(x);}
    sort(ALL(X));
    REP2(i,0,101){
        sum = 0;
        REP(j,N){
            sum += (i-X[j])*(i-X[j]);
        }
        minimum_HP =min(minimum_HP,sum);
    }
    cout << minimum_HP << endl; 
    return 0;
}

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

int main() {
    //
    long long a, b, x;
    cin >> a >> b >> x;

    if (x == 1) {
        cout << b - a + 1 << endl;
        return 0;
    }
/*
    long long cnt = 0;
    long long tmp = 0;
    for (long long i = a; i <= b; i++) {
        if (i % x == 0) break;
        tmp++;
    }
    */
    //cout << a/x << endl;
    //b = b - a - tmp;
    if(a % x == 0)cout << (b / x+1) - (a / x) << endl;
    else cout << (b / x) - (a / x) << endl;
    //
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

lld gcd(lld x,lld y)
{
	if (y==0)
	{
		return x;
	}
	return gcd(y,x%y);
}

int main()
{
	lld n,x;
	cin >> n>>x;
	cout << 3*(n-gcd(n,x)) << endl;

	return 0;
}

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

int main(){
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n), f(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.begin(), f.end(), greater<ll>());

  auto ok = [&](ll m) {
    ll cnt = 0;
    rep(i,n) {
      cnt += max(0LL, a[i] - m / f[i]);
    }
    return cnt <= k;
  };
  ll l = -1, r = 1e18;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    if (ok(m)) r = m;
    else l = m;
  }
  cout << r << endl;
  return 0;
} 

Measured memory_bytes: 3456
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// main function
int main()
{
	ll ans = 0;
	ll N = 0;

	cin >> N;
	vector < ll > a(N);

	Rep(i, N) {
		cin >> a[i];
	}

	Rep(i, N) {
		ll cnt = 0;
		bool isOK = false;
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			cnt++;
			isOK = true;
		}
		if (isOK) ans += cnt;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1001001001;
vector<int> to[100005];

int main()
{
	int n, m;
	cin >> n >> m;
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a); //to[0] 1; to[1] 0,2,3;�@to[2] 1,3; to[3] 1,2;
	}
	vector<int> q;
	vector<int> dist(n, INF);//dist{INF,INF,...,INF}
	vector<int>pre(n, -1);//pre{-1,-1,...,-1}
	dist[0] = 0;//dist{0,INF,...}
	q.push_back(0); //q {0}
	while (!q.empty())//when q is not empty 
	{
		int v = q.front();	
		q.erase(q.begin());//v=0 //v=1 //v=2,3 as well as v=0,1
		for (int u : to[v])//u=1�@//u=0,2,3
		//every u which is contained in to[v]
		{
			if (dist[u] != INF) continue; //execute if dist[u] is not renewed
			dist[u] = dist[v] + 1;//dist{0,1,INF,...}�@//dist{0,1,2,2}
			pre[u] = v;// pre{-1,0,...}//pre{-1,0,1,1}
			q.push_back(u);//q{1}//q{2,3}
		}
	}
	auto result = find(dist.begin(), dist.end(), INF);
	if (result == dist.end()) {
		cout << "Yes" << endl;
		rep(i, n)
		{
			if (i == 0)continue;
			int ans = pre[i];
			++ans;
			cout << ans << endl;
		}
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 10908
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,W;
    cin >> n >> W;

    vector<ll> w(n),v(n);
    for(int i  =0; i< n; ++i)
    {
        cin >> w[i] >> v[i];
    }
    vector<ll> dp(W+1);

    ll sol = 0;

    for(int item = 0; item < n; ++item)
    {
        for(int weight = W; weight >= 1; weight--)
        {
            if(weight-w[item] >= 0)
                dp[weight] = max(dp[weight], v[item] + dp[weight-w[item]]);
            sol = max(sol,dp[weight]);
        }   
    }
    cout << sol << '\n';



    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll chan(ll x){if(x%2)return ((x+1)/2%2); else return x|((x+1)/2%2);}
int main(){ll A,B; cin>>A>>B; --A; cout<<(chan(A) xor chan(B))<<"\n";}


Measured memory_bytes: 384
from collections import defaultdict
import heapq
T=int(input())
for testcase in range(T):
    N,A,B,C,D=map(int,input().split())
    dist=defaultdict(lambda:10**23)
    dist[N]=0
    q=[]
    heapq.heappush(q,(0,N,0))
    while(len(q)!=0):
        nowdist,num,onestreak=heapq.heappop(q)
        if dist[num]<nowdist:
            continue
        if dist[0]>dist[num]+num*D:
            dist[0]=dist[num]+num*D
            heapq.heappush(q,(dist[0],0,num*D))
        if num%2==0 and (dist[num//2]>dist[num]+A):
            dist[num//2]=dist[num]+A
            heapq.heappush(q,(dist[num//2],num//2,0))
        if num%3==0 and (dist[num//3]>dist[num]+B):
            dist[num//3]=dist[num]+B
            heapq.heappush(q,(dist[num//3],num//3,0))
        if num%5==0 and (dist[num//5]>dist[num]+C):
            dist[num//5]=dist[num]+C
            heapq.heappush(q,(dist[num//5],num//5,0))
        if onestreak<5 and (dist[num+1]>dist[num]+D):
            dist[num+1]=dist[num]+D
            heapq.heappush(q,(dist[num+1],num+1,onestreak+1))
        if onestreak<5 and num>=1 and (dist[num-1]>dist[num]+D):
            dist[num-1]=dist[num]+D
            heapq.heappush(q,(dist[num-1],num-1,onestreak+1))
    print(dist[0])

    
        
        

Measured memory_bytes: 20144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

vvi c(3,vi(3));
rep(i,3) rep(j,3) cin >> c[i][j];

vi a(3),b(3);
a[0] = 0;
rep(i,3) b[i] = c[0][i];
a[1] = c[1][0] - b[0];
a[2] = c[2][0] - b[0];


rep(i,3)rep(j,3){
    if(c[i][j] != a[i] + b[j]){
        cout << "No" << endl;
        return 0;
    }
}

cout << "Yes" << endl;


return 0;
}

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

using namespace std;

bool dfs(int n, int sum, vector<int>& a, const int m)
{
    if(sum==m)return true;
    if(n>a.size()-1)return false;
    bool ret=false;
    if(ret==false)ret|=dfs(n+1, sum+a[n], a, m);
    if(ret==false)ret|=dfs(n+1, sum, a, m);
    return ret;
}

int main()
{
    int n;cin>>n;
    vector<int> a(n);for(int i = 0; i < n; i++)cin>>a[i];
    int q;cin>>q;
    for(int i = 0; i < q; i++){int mi;cin>>mi;
    cout<<(dfs(0, 0, a, mi)?"yes":"no")<<endl;}
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
 /* #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
//ll  t;cin>>t;while(t--)
{
  int a,b,c;
  cin>>a>>b>>c;
  if(b-a==c-b)
  {
    YES
  }
  else
  {
    NO
  }

 

}
return 0;
}


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

using namespace std;


int main(){
    int N,K;
    cin>> N >> K;
    int A[N+1];
    int dp[K+1];

    for(int i = 1; i <= N; i++){
        cin>>A[i];
    }

    dp[0] = 0;
    for(int i = 1; i <= K; i++){
        dp[i] = 0;
        for(int j = 1; j <= N; j++){
            if(A[j] <= i && dp[i-A[j]] == 0){
                dp[i] = 1;
            }
            else if(A[j] > i){
                break;
            }
        }
    }

//    for(int i = 1; i <= K; i++){
//        cout<<dp[i]<<" "<<endl;
//    }

    if(dp[K] == 1){
        cout<<"First";
    }
    else{
        cout<<"Second";
    }

    return 0;
}


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

int main(){
    int x, y, z;
    cin >> x >> y >> z;

    int tmp = x;
    x = y;
    y = tmp;

    tmp = x;
    x = z;
    z = tmp;

    cout << x << " " << y << " " << z << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    
    S = "#" + S + "#";

    auto can_reach = [&](int start, int end) {
        for (int i = start; i + 1 <= end; i++) {
            if (S[i] == '#' && S[i + 1] == '#') return false;
        }
        return true;
    };

    if (!can_reach(A, C) || !can_reach(B, D)) {
        cout << "No" << endl;
        return 0;
    }

    if (C > D) {
        bool snuke_can_over = false;
        for (int i = B; i <= D; i++) {
            if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
                snuke_can_over = true;
            }
        }
        if (!snuke_can_over) {
            cout << "No" << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 3852
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if (V-W) == 0:
    print("NO")
else:
    if (V-W) > 0:
        if T >= (abs(B-A)/(V-W)):
            print("YES")
        else:
            print("NO")
    else:
        
        print("NO")

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;

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

int bubble_sort(vector<int> &A) {
  int count = 0;
  auto flag = true;
  for (int i = 0; flag; ++i) {
    flag = false;
    for (int j = A.size() - 1; j >= 1; --j) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        flag = true;
        count++;
      }
    }
  }
  return count;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  auto count = bubble_sort(A);
  REP(i, N) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl << count << endl;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
int arr[10001];
using namespace std;
int main() {
    int n, p1, p2, cal, ans;
    std::scanf("%d", &n);
    scanf("%d %d", &p1, &p2);
    scanf("%d", &cal);
    for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
    sort(arr, arr+n, greater<int>());
    ans = cal / p1;
    for (int i = 0; i < n; i++) {
        ans = max(ans, (cal + arr[i]) / (p1+p2));
        cal+=arr[i], p1+=p2;
    }
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 3264
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;

int n;
int a[MaxN];

inline bool solve()
{
	int l = *min_element(a, a + n);
	int r = *max_element(a, a + n);
	if (l + 1 < r)
		return false;

	if (l == r && r == n - 1)
		return true;

	int nL = count(a, a + n, r - 1);
	int nR = n - nL;
	return nL + (nR / 2) >= r && nL + (nR > 0) <= r;
}

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

	puts(solve() ? "Yes" : "No");

	return 0;
}

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

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var s = Console.ReadLine();
            if (s == ".") break;
            var st = new Stack<int>();
            for (int i = 0; i < s.Length; i++)
                if (s[i] == '(') st.Push(1);
                else if (s[i] == '[') st.Push(2);
                else if ((s[i] == ')' | s[i] == ']') && st.Count() == 0) { Console.WriteLine("no"); goto next; }
                else if (s[i] == ')' && st.Count() > 0 && st.Pop() != 1) { Console.WriteLine("no"); goto next; }
                else if (s[i] == ']' && st.Count() > 0 && st.Pop() != 2) { Console.WriteLine("no"); goto next; }
            Console.WriteLine(st.Count() == 0 ? "yes":"no");
            next:;
        }
    }
}






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

#define MOD 1000000007
#define MAX 100005
#define ll long long
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define ss(x) scanf("%s",x)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vpii vector<pii >
#define vll vector<ll>
#define clr(x) memset(x,0,sizeof(x))

#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

ll x[1005],y[1005],r[1005];

vector<pair<int,double> > adj[1005];
bool visited[1005];

#define node pair<double,int>

double dijkstra(int x,int y){
	clr(visited);
	
	priority_queue<node,vector<node >,greater<node > > P;
	P.push(mp(0,x));
	
	// Take care to write visited thing there only !!
	while(!P.empty()){
		node top=P.top();
		P.pop();
		
		if(visited[top.SS]) continue;
		visited[top.SS]=true;
		
		if(top.SS==y) return top.FF;
		
		for(int i=0;i<adj[top.SS].size();i++){
			if(visited[adj[top.SS][i].FF]) continue;
			P.push(mp(adj[top.SS][i].SS+top.FF,adj[top.SS][i].FF));
		}
	}
}

double pointD(pair<double,double> a,pair<double,double> b){
	return sqrt((a.FF-b.FF)*(a.FF-b.FF)+(a.SS-b.SS)*(a.SS-b.SS));
}

double pt_cir(pair<double,double> a,int ind){
	double d1=pointD(a,mp(x[ind],y[ind]));
	if(d1<=r[ind]) return 0;
	return d1-r[ind];
}

double circ(int i,int j){
	double d1=pointD(mp(x[i],y[i]),mp(x[j],y[j]));
	if(d1<=r[i]+r[j]) return 0;
	return d1-(r[i]+r[j]);
}

int main(){
	ll xs,ys,xt,yt;
	slld(xs);slld(ys);slld(xt);slld(yt);
	int n;sd(n);
	for(int i=1;i<=n;i++){
		slld(x[i]);slld(y[i]);slld(r[i]);
	}
	pair<double,double> st=mp(xs,ys),en=mp(xt,yt);
	
	double d1=pointD(st,en);
	adj[0].pb(mp(n+1,d1));
	adj[n+1].pb(mp(0,d1));
	
	for(int i=1;i<=n;i++){
		d1=pt_cir(st,i);
		adj[0].pb(mp(i,d1));
		adj[i].pb(mp(0,d1));
		
		d1=pt_cir(en,i);
		adj[n+1].pb(mp(i,d1));
		adj[i].pb(mp(n+1,d1));
	}
	
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			d1=circ(i,j);
			adj[i].pb(mp(j,d1));
			adj[j].pb(mp(i,d1));
		}
	}
	
	double ans=dijkstra(0,n+1);
	printf("%.11lf\n",ans);
}

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

int main() {
  vector<int> a(101);
  int b = 0, c;
  for (cin >> c; cin >> c; a.at(c)++);
  for (c = 101; c--;) if (a.at(c)) b++;
  cout << b;
}

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

using namespace std;

int main(){
    int n, k;
    int x[100300] = {0};

    cin >> n >> k;    
    for(int a = 0; a < n; a++){
        cin >> x[a + 1];
    }

    int ans = 1;
    n -= k;

    while(n > 0){
        n -= k - 1;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
  int H,W,i,j,n,m,sum=0,a,b;
  scanf("%d %d",&H,&W);
  int A[H][W],dis[H][W];
  for(i=0;i<H;i++)
    for(j=0;j<W;j++)
      scanf("%d",&A[i][j]);
  for(i=0;i<H;i++)
  {
    for(j=0;j<W;j++)
    {
      for(n=0;n<H;n++)
      {
        for(m=0;m<W;m++)
          {
            a=abs(i-n); b=abs(j-m);
            if(a<b) sum+=a*A[n][m];
            else sum+=b*A[n][m];
          }
        }
        dis[i][j]=sum;
        sum=0;
      }
    }
    int min=dis[0][0];
    for(i=0;i<H;i++)
    {
      for(j=0;j<W;j++)
        if(min>dis[i][j]) min=dis[i][j];
    }
    printf("%d\n",min);
  return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
string s;
map<string,int>f;
map<string,int>g;
int g_search(string s);
int f_search(string s);
int main()
{
    cin>>s;
    f[""]=1;
    cout<<f_search(s)<<endl;
    return 0;
}
int f_search(string s)
{
    if(f.find(s)!=f.end())
    return f[s];
    for(int i=1;i<=s.size();++i)
    f[s]=(f[s]+1ll*f_search(s.substr(0,s.size()-i))*g_search(s.substr(s.size()-i,i))%mod)%mod;
    return f[s];
}
int g_search(string s)
{
    if(g.find(s)!=g.end())
    return g[s];
    if(s.size()==1)
    return g[s]=s[0]-'0'+1;
    int i=1,j;
    while(i<s.size())
    {
        if(s.size()%i==0)
        {
            string t;
            j=0;
            while(j<i)
            {
                int r=1;
                for(int k=0;k<s.size()/i;++k)
                if(s[i*k+j]=='0')
                r=0;
                t=t+(char)(r+'0');
                j=j+1;
            }
            g[s]=(g[s]+f_search(t))%mod;
        }
        i=i+1;
    }
    return g[s];
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n,m,c,b[20],a[20],x,ans=0;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> m >> c;
	rep(m) cin >> b[i];
	rep(n){
		rep1(j,m) cin >> a[j];
		x=0;
		rep1(j,m) x+=a[j]*b[j];
		x+=c;
		ans+=x>0; 
	}
	print1(ans);
	return 0;
}


Measured memory_bytes: 256
n = int(input())
res = 0
if n < 10:
    res = n
elif 10 <= n < 100:
    res = 9
elif 100 <= n < 1000:
    res = 9 + (n - 99)
elif 1000 <= n < 10000:
    res = 9 + 900
elif 10000 <= n < 100000:
    res = 9 + 900 + (n - 9999)
elif n == 100000:
    res = 9 + 900 + 90000
print(res)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

#define N 4
#define N2 16
#define LIMIT 45

const int dx[4] { -1, 0, 1, 0 };
const int dy[4] { 0, -1, 0, 1 };
const char dir[4] { 'u', 'l', 'd', 'r' };

int MDT[N2][N2];
struct Puzzle {
	int f[N2], space, MD;
};

int getAllMd(Puzzle p) {
	int sum = 0;
	for (int i = 0; i < N2; ++i) {
		if (p.f[i] == N2)
			continue;
		sum += MDT[i][p.f[i] - 1];
	}
	return sum;
}
int limit;
int path[LIMIT];
Puzzle state;
bool dfs(int depth, int prevR) {
	if (state.MD == 0)
		return true;
	if (depth + state.MD > limit)
		return false;

	int sx = state.space / N;
	int sy = state.space % N;
	Puzzle tmp;
	for (int r = 0; r < 4; ++r) {
		if (max(r, prevR) - min(r, prevR) == 2)
			continue;
		int tx = sx + dx[r];
		int ty = sy + dy[r];
		if (tx < 0 || ty < 0 || tx >= N || ty >= N)
			continue;
		tmp = state;
		state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
		state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
		swap(state.f[tx * N + ty], state.f[sx * N + sy]);
		state.space = tx * N + ty;
		if (dfs(depth + 1, r)) {
			path[depth] = r;
			return true;
		}
		state = tmp;
	}
	return false;
}
string deepening(Puzzle p) {
	int md = getAllMd(p);
	p.MD = md;
	state = p;
	for (limit = md; limit <= LIMIT; ++limit) {
		if (dfs(0, -100)) {
			string ans;
			for (int i = 0; i < limit; ++i) {
				ans += dir[path[i]];
			}
			return ans;
		}
	}
	return "";
}

int main() {
	for (int i = 0; i < N2; ++i) {
		for (int j = 0; j < N2; ++j) {
			MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
		}
	}
	Puzzle p;
	for (int i = 0; i < N2; ++i) {
		scanf("%d", &p.f[i]);
		if (p.f[i] == 0) {
			p.f[i] = N2;
			p.space = i;
		}
	}
	string ans = deepening(p);
	cout << ans.size() << endl;

	return 0;
}

Measured memory_bytes: 3280
N, WI = map(int, input().split())
V = [0] * N
W = [0] * N
for i in range(N):
    v, w = map(int, input().split())
    V[i] = v
    W[i] = w

dp = [[0] * 10100 for _ in range(N+1)]

for i in range(1,1+N):
    for j in range(10100):
        if j-W[i-1] >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i][j-W[i-1]]+V[i-1])
        else:
            dp[i][j] = dp[i-1][j]
    
print(dp[N][WI])



Measured memory_bytes: 16352
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

int n, m;
vector<int> graph[10];
ll ans = 0;

void dfs(int from = 0, int state = 1){
    if(state == ((1 << n) - 1)){
        ++ans;
        return;
    }
    for(int to : graph[from]){
        if((state >> to) & 1)   continue;
        dfs(to, state | (1 << to));
    }
    return;
}

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

    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs();
    cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = dict()
for x in a:
    d[x] = d.get(x, 0) + 1
d2L = [(k, v) for k, v in d.items()]
d2L = sorted(d2L, key = lambda x: x[1])

ans = 0
i = 0
while len(d2L) - k - i > 0:
    ans += d2L[i][1]
    i += 1
print(ans)

Measured memory_bytes: 40628
N = int(input())

dp = [[0]*10 for _ in range(10)]

for n in range(1,N+1):
    s = str(n)
    dp[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += dp[i][j] * dp[j][i]
print(ans)

Measured memory_bytes: 9200
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
 
int n,dp[100005],a[100005]; 
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for (int i=2;i<=n;i++){
		dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
		if (i > 2)
		dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 896
function Main(input) {
  var array = input.split("\n");
  var N = array[0] - 0;
  var stone = array[1];
  var count = 0;
  var j = N;
  for (var i = 0; i < N; i++) {
    if (stone[i] === 'W') {
      for (; j > i;) {
        j--;
        if (stone[j] === 'R') {
          count++;
          break;
        }
      }
    }
  }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 32520
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<queue>

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

using namespace std;

int n,m;

struct edge {
public:
	int to,cost,time;
	edge(int b,int cost,int time) {
		this->to = b;
		this->cost = cost;
		this->time = time;
	}
};

typedef pair<int,int> P;

vector<edge> G[3007];

int dijk(int s,int t,int mode) {
	
	priority_queue<P, vector<P> ,greater<P> > que;
	int d[3007];rep(i,3007) d[i]=1000000;
	d[s]=0;
	que.push(P(0,s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.second;
		if(v==t) break;
		if(d[v] < p.first) continue;

		rep(i,G[v].size()) {
			edge e = G[v][i];
			int cost = mode==0?e.cost:e.time;

			if(d[e.to] > d[v] + cost) {
				d[e.to] = d[v] + cost;
				que.push(P(d[e.to],e.to));
			}

		}
	}
	return d[t];
}

void solve() {
	rep(i,n) {
		int a,b,cost,time;
		cin>>a>>b>>cost>>time;
		G[a].push_back(edge(b,cost,time));
		G[b].push_back(edge(a,cost,time));
	}

	int k;
	cin>>k;
	rep(i,k) {
		int s,t,mode;
		cin>>s>>t>>mode;
		cout<<dijk(s,t,mode)<<endl;
	}

	rep(i,3007) G[i].clear();
}

int main() {
	while (cin>>n>>m)
	{
		if(n+m==0) return 0;
		solve();
	}
	return 0;
}

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

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

  int N;
  int a[110];
  cin >> N;
  REP(i, N) cin >> a[i];

  sort(a, a + N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  REP(i, N) {
    if(i % 2 == 0) {
      Alice += a[i];
    } else {
      Bob += a[i];
    }
  }

  cout << Alice - Bob << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n,c,k;
  cin>>n>>c>>k;
  vi t(n);
  rep(i,n)cin>>t[i];
  sort(all(t));
  vi num(n);
  num[0]=1;
  i=0;
  while(i<t.size()-1){
    if(t[i+1]-t[i]<=k&&num[i]<c){
      num[i]++;
      t.erase(t.begin()+i+1);
    }else{
      i++;
      num[i]=1;
    }
  }
  cout<<t.size()<<endl;
}

Measured memory_bytes: 1024
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll h,w;
  cin>>h>>w;
  ll cnt=0;
  vector<vector<char>> v(h,vector<char>(w));
  rep(i,h) rep(j,w) cin>>v[i][j];
  rep(i,h) rep(j,w) if(v[i][j]=='#') cnt++;
  if(cnt==h+w-1) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 256
from itertools import groupby

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

odd=[v[i] for i in range(0,n) if i%2==1]
even=[v[i] for i in range(0,n) if i%2==0]
odd.sort()
even.sort()
odd=groupby(odd)
even=groupby(even)
odd=[[len(list(group)),key] for key,group in odd]
even=[[len(list(group)),key] for key,group in even]
odd.append([0,0])
even.append([0,0])
odd.sort(reverse=True)
even.sort(reverse=True)
if odd[0][1]!=even[0][1]:
    print(n-odd[0][0]-even[0][0])
else:
    print(min(n-odd[0][0]-even[1][0],n-odd[1][0]-even[0][0]))


Measured memory_bytes: 62188
#include <iostream>
using namespace std;
#define MAX 100
#define INFTY 10000001
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define DEFLT 0 // 初期値

int M[MAX][MAX], d[MAX];

void dijkstra(int n){
  int mincost, u, color[n], p[n];
  for(int i=0; i<n; i++){
    color[i] = WHITE;
    d[i] = INFTY;
  }

  d[DEFLT] = 0;
  p[DEFLT] = -1;

  while(true){
    mincost = INFTY;
    for(int i=0; i<n; i++){
      if(color[i] != BLACK && d[i] < mincost){
        mincost = d[i];
        u = i;
      }
    }

    if(mincost == INFTY) break;

    color[u] = BLACK;

    for(int v=0; v<n; v++){
      if(color[v] != BLACK && M[u][v] < INFTY){
        if(d[u] + M[u][v] < d[v]){
          d[v] = d[u] + M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
}

int main(void){
  int n, u, k, v, c;
  cin >> n;

  for(u=0; u<MAX; u++){
    for(v=0; v<MAX; v++){
      M[u][v] = INFTY;
    }
  }

  for(int i=0; i<n; i++){
    cin >> u >> k;
    for(int j=0; j<k; j++){
      cin >> v >> c;
      M[u][v] = c;
    }
  }

  dijkstra(n);

  for(int i=0; i<n; i++){
    cout << i << " " << d[i] << endl;;
  }
  return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
 
#define INF 1234567890LL
#define ll long long

int N, M, K;
string s[7];
bool vis[7][7];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> M >> K;
	for(int i=0; i<N; i++)
		cin >> s[i];
	int res = 0;
	for(int i=0; i<(1<<N); i++)
		for(int j=0; j<(1<<M); j++)
		{
			memset(vis, 0, sizeof(vis));
			for(int k=0; k<N; k++)
				if (i&(1<<k))
					for(int x=0; x<M; x++)
						vis[k][x] = true;
			for(int k=0; k<M; k++)
				if (j&(1<<k))
					for(int y=0; y<N; y++)
						vis[y][k] = true;

			int cnt = 0;
			for(int y=0; y<N; y++)
				for(int x=0; x<M; x++)
					if (!vis[y][x] && s[y][x]=='#')
						cnt++;
			if (cnt == K)
				res++;
		}
	cout << res;
	return 0;
}

Measured memory_bytes: 3632
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        s: String
    }
    let red = s.chars().filter(|&c| c == 'R').count();
    let blue = s.chars().filter(|&c| c == 'B').count();
    let result = if red > blue { "Yes" } else { "No" };
    println!("{}", result);
}


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

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

    int64_t counter[5] = { 0 };
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        counter[0] += s[0] == 'M';
        counter[1] += s[0] == 'A';
        counter[2] += s[0] == 'R';
        counter[3] += s[0] == 'C';
        counter[4] += s[0] == 'H';
    }

    int a[] = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 };
    int b[] = { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 };
    int c[] = { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 };

    int64_t ans = 0;
    for (int i = 0; i < 10; ++i) {
        ans += counter[a[i]] * counter[b[i]] * counter[c[i]];
    }

    cout << ans << endl;
}



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

int main(){
    string s;
    cin>>s;
    int n=s.size();
    long long ans =0;
    for(int i=0;i<1<<(n-1);i++){
        long long num = s[0] - '0';
        for(int j=0;j<n-1;j++){
            if(i&1<<j){
                ans+=num;
                num=0;
            }
            num=num*10+s[j+1]-'0';
        }
        ans+=num;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

/**
 * 【問題概要】
 *
 * 0 と 1 のみから成る 3 桁の番号 s が与えられます。1 が何個含まれるかを求めてください。
 *
 * @author tsuch
 *
 */
public class Main {

	private static Scanner sc = new Scanner(System.in);

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

	private void solve() {
		try {
			String s = sc.next();
			String[] ar = s.split("");
			long count = Arrays.stream(ar).filter(f -> f.equals("1")).count();
			System.out.println(count);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 27348