akhauriyash/Code-Regression huggingface dataset:
import math

def is_prime(x):
    if x < 2:
        return False
    else:
        t = int(math.sqrt(x)) + 1
        for n in range(2, t):
            if x % n == 0:
               return False
        return True


n = int(input())

cnt = 0
ans = []
for num in range(2, 55555):
    if is_prime(num) and num % 5 == 1:
        cnt += 1
        ans.append(num)

    if cnt == n:
        break

print(*ans)


Measured memory_bytes: 3060
import sys
def input(): return sys.stdin.readline().strip()

s  = lambda: input()

S = s()
N = len(S)

C = [1] * N
r = 0
l = 0
l_c = -1

i = -1
while i < N-1: 
  i += 1
  if S[i] == "R":
    if S[i:i+2] == "RL":
      continue
    if S[i:i+3] == "RRL":
      C[i+2] += C[i]
      C[i] = 0
    if S[i:i+4] == "RRRL":
      C[i+2] += C[i]
      C[i] = 0
    if S[i:i+4] == "RRRR":
      C[i+4] += C[i]
      C[i] = 0

i += 1
while i > 0:
  i -= 1
  if S[i] == "L":
    if S[i-1:i+1] == "RL":
      continue
    if S[i-2:i+1] == "RLL":
      C[i-2] += C[i]
      C[i] = 0
    if S[i-3:i+1] == "RLLL":
      C[i-2] += C[i]
      C[i] = 0
    if S[i-3:i+1] == "LLLL":
      C[i-4] += C[i]
      C[i] = 0

print(' '.join(list(map(str,C))))

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

int main() {
	string s;
	cin >> s;
	int l = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'x') l++;
	}
	cout << (l < 8 ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;
int main(){
    ios;
	string n; cin >> n;
	ll ans = 0;
    for(ll i = 0; i < (int) n.size(); ++i){
		string s = "";
		s += n[i];
        int x = stoi(s);
        ans += x;
    }
	if(ans % 9 == 0) cout << "Yes";
	else cout << "No";
    return 0;
}


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

int main(){
  int N, A[2][100], sum, nextsum, maxsum;
  
  cin >> N;
  for(int i=0; i<2; ++i)
    for(int j=0; j<N; ++j)
      cin >> A[i][j];
  
  sum = A[0][0];
  for(int i=0; i<N; ++i)
    sum = sum + A[1][i];
  maxsum = sum;
  for(int i=1; i<N; ++i) {
    nextsum = sum - A[1][i-1] + A[0][i];
    if(nextsum > maxsum) maxsum = nextsum;
    sum = nextsum;
  }
  
  cout << maxsum << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#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(int 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 vector<string> vs;
typedef pair<int,int> pii;

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


int main(void) {
    int i,j;
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    int cnt = 0;
    rep(i,n){
        if(s[i] == 'W'){
            ans += cnt;
        }else{
            cnt++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define repq(i,a,n) for(int i=a; i<=n; i++)
long long dp[110][20][1010];
int main() {
    int n, s;
    memset(dp, 0, sizeof(dp)); dp[0][0][0] = 1;
    repq(i,1,100) repq(j,0,15) repq(k,0,1000) {
        dp[i][j][k] = dp[i-1][j][k];
        if(k - i < 0) continue;
        if(j != 0) dp[i][j][k] += dp[i-1][j-1][k-i];
    }
    while(std::cin >> n >> s, n || s)
        std::cout << dp[100][n][s] + dp[100][n-1][s] << std::endl;
    return 0;
}

Measured memory_bytes: 20440
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int[] count = new int[101];
		int max,value;
		while(sc.hasNext()){
			value = sc.nextInt();
			count[value]++;
		}
		max = count[0];
		for(int i=0;i<100;i++){
			if(max < count[i]) max = count[i];
		}
		for(int i=0;i<100;i++){
			if(max == count[i]) System.out.println(i);
		}
	}
}

Measured memory_bytes: 18112
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(double x){
  printf("%.15f",x);
}
template<class T> inline T pow2_L(T a){
  return a*a;
}
int N;
int X[8];
int Y[8];
int main(){
  int i;
  double s = 0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(X[Lj4PdHRW]);
      rd(Y[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    int j;
    for(j=(i+1);j<(N);j++){
      s += sqrt(pow2_L((X[i]-X[j]))+pow2_L((Y[i]-Y[j])));
    }
  }
  wt_L(2*s/N);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int N, X[8], Y[8];
// {
//   double s = 0;
//   rd(N,(X,Y)(N));
//   rep(i,N) rep(j,i+1,N) s += sqrt( (X[i]-X[j])**2 + (Y[i]-Y[j])**2 );
//   wt(2*s/N);
// }


Measured memory_bytes: 256
n, k = [int(z) for z in input().strip().split()]
p = [int(z) - 1 for z in input().strip().split()]
c = [int(z) for z in input().strip().split()]
 
visited = [False for _ in range(n)]
cycle = []
for start in range(n):
    if visited[start]:
        continue
    now = start
    route = []
    while not visited[now]:
        visited[now] = True
        route.append(now)
        now = p[now]
    cycle.append(route)
 
min_c = min(c)
max_value = min_c
for route in cycle:
    full_value = sum([c[i] for i in route])
    double_route = route + route
    v = [c[i] for i in double_route]
    max_sum_step = []
    for step in range(1, len(route)):
        s = sum(v[:step])
        max_sum = max(s, min_c)
        for idx in range(step, step + len(route) - 1):
            s += v[idx]
            if idx >= step:
                s -= v[idx - step]
            max_sum = max(s, max_sum)
        max_sum_step.append(max_sum)
    addition = k % len(route)
    if full_value > 0:
        addition_value = 0 if addition == 0 else max(max_sum_step[:addition])
        value1 = int(k / len(route)) * full_value + addition_value
        value2 = (int(k / len(route)) - 1) * full_value + max(max_sum_step)
        value = max(value1, value2)
    else:
        value = max(max_sum_step[:min(k, len(max_sum_step))])
    max_value = max(max_value, value)
print(max_value)

Measured memory_bytes: 75208
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  string s0,s1,stmp,c;
  cin >> s1;

  
  int q;
  cin >> q;
  
  int t,f;
  for(int i=0;i<q;i++){
    cin >> t;
    if(t==1){
      stmp=s0;
      s0=s1;
      s1=stmp;
    }else{
      cin >> f;
      cin >> stmp;
      if(f==1){
	s0+=stmp;
      }else{
	s1+=stmp;
      }
    }
  }


  reverse(s0.begin(),s0.end());
  cout << s0 << s1 << endl;
  
  
  return 0;
}


Measured memory_bytes: 964
N = int(input())
L = list(map(int, input().split()))
odd = 0
div2 = 0
div4 = 0
for l in L:
    if l % 2 != 0:
        odd += 1
    elif l % 4 == 0:
        div4 += 1
    else:
        div2 += 1

if N == 2:
    if odd == 2 or (odd == 1 and div2 == 1):
        print("No")
    else:
        print("Yes")
    exit()

if N == 3:
    if div4 >= 1:
        print("Yes")
    else:
        if odd == 0:
            print("Yes")
        else:
            print("No")
    exit()

if odd <= div4:
    print("Yes")
else:
    if div2 == 0 and odd - div4 == 1:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1LL << 60;

ll h[100010];

ll dp[100010];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) cin >> h[i];

    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    dp[0] = 0;

    
    for (int i = 1; i < N; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>

#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include <cmath>
#include <algorithm>

#include <fstream>

using namespace std;

#define M_PI 3.14159265358979323846264338327950288

int main()
{
  srand(179179);

  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  cout.setf(ios_base::fixed);
  cout.precision(28);

  long long a, b, c;
  cin >> a >> b >> c;
  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
    cout << "0\n";
  } else {
    cout << min(a * b, min(b * c, a * c)) << endl;
  }
  return 0;
}

Measured memory_bytes: 384
from itertools import product
n, m, x = list(map(int, input().split()))
cl = [0] * n
al = [[]*m for _ in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    cl[i] = tmp[0]
    al[i] = tmp[1:]


def dfs(status, book):
    for i in range(m):
        status[i] += book[i]
    return status


ans = 10**10
for bit in product([0, 1], repeat=n):
    # print(bit)
    status = [0]*m
    money = 0
    for i, b in enumerate(list(bit)):
        if b == 1:
            for k in range(m):
                status[k] += al[i][k]
            money += cl[i]
    flag = True
    for i in range(m):
        if status[i] >= x:
            continue
        else:
            flag = False
    if flag:
        ans = min(ans, money)
if ans == 10**10:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 74288
#include <bits/stdc++.h>
using namespace std;
using namespace std;
 
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair


int main() 

{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll r;
    cin>>r;
    double ans= 2* M_PI*r;
    std::cout << std::setprecision(5) << ans << '\n';

}

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

// vector<bool> IsPrime;
bool f [100001];
int c[100001];

/*
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;
    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j)
                IsPrime[i*j] = false;
        }
    }
}
*/

int main(){
    int Q;
    cin >> Q;
    int l[100000], r[100000];
    for(int i=0;i<Q;i++)
        cin >> l[i] >> r[i];
    
    // sieve(100000);
    for(int i=2;i<=100000;i++){
        if(!f[i]){
            // iの倍数
            for(int j=i+i;j<=100000;j+=i)
                f[j] = true;    // iの倍数である
        }
    }
    for(int i=3;i<=100000;i+=2){
        if(!f[i] && !f[(i+1)/2])
            c[i]++;
    } 
    for(int i=3;i<=100000;i++)
        c[i] += c[i-1];

    for(int i=0;i<Q;i++)
        cout << c[r[i]] - c[l[i]-1] << endl;
    return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  int res=0;
  int prev=-1;
  int cur=0;
  for(int i=0;i<n;i++){
    int t;
    cin>>t;
    if(prev>=t){
      cur++;
    }else{
      cur=0;
    }
    res=max(cur,res);
    prev=t;
  }
  cout<<res<<endl;

  return 0;
}


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

using namespace std;

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

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


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

//a=97,z=122

Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;
ll INF=100000000000001;
vector<ll> value; // ノードの値を持つ配列
ll N;             // 葉の数
 
void update(ll i, ll x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1],
                       value[i * 2 + 2]); // 左右の子の min を計算しなおす
    }
}
 
ll query(ll a, ll b, ll k, ll l, ll r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                         // に完全に含まれる
    else {
        ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return min(c1, c2); // 左右の子の値の min を取る
    }
}
signed main(){
    llin(h);
    llin(n);
    vllin(a,n);
    FOR(i,0,n-1){
        h-=a[i];
    }
    Yn(h<=0)
}

Measured memory_bytes: 1024
#include <stdio.h>

int main() {
	long long int n,i,j,y;
	scanf("%lld", &n);
	long long x = n-1;

	for (i = 2; i*i<=n; i++){
		if (n % i == 0){
			j = n / i;
			y = (i-1) + (j-1);
			if (y < x){
				x = y;
			}
		}
	}
	printf("%lld\n", x);

}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <stack>
using namespace std;

typedef long long ll;

ll dp[101][101];

int cp=-1;
int idx;
char result=0;


// ツ嘉ーツ静債つオツづ按つェツづァツカツウツδ督トツつオツづつ「ツつュ
void dfs(string str){
	string res;
	ll pos=0;
	ll resCnt=0;
	while(1){
		ll initPos=pos;
		if(pos>=str.size())
			break;
		if(str[pos]>='0'&&str[pos]<='9'){
			for(ll i=pos+1; ; i++){
				if(!(str[i]>='0'&&str[i]<='9')){
					pos=i;
					break;
				}
			}
			ll cnt=atoi(str.substr(initPos,pos-initPos).c_str());
			if(str[pos]=='('){
				stack<ll> s;
				s.push(0);
				ll start=pos;
				while(1){
					pos++;
					if(str[pos]=='(')
						s.push(0);
					else if(str[pos]==')')
						s.pop();
					if(s.size()==0)
						break;
				}
				string subs=str.substr(start+1,pos-start-1);
				for(int i = 0; i < cnt; i++){
					dfs(subs);
					if(result!=0){
						return;
					}
				}
				//resCnt+=an*cnt;
				pos++;
			}
			else{
				for(int i = 0;i < cnt; i++){
					cp++;
					if(cp==idx){
						result=str[pos];
						return;
					}
				}
				resCnt+=cnt;
				pos++;
			}
		}
		else{
			for(ll i = initPos; ; i++){
				if(i>=str.size()){
					pos=i+1;
					break;
				}
				else if(!(str[i]>='A'&&str[i]<='Z')){
					pos=i;
					break;
				}
				else{
					cp++;
					if(cp==idx){
						result=str[i];
						return;
					}
				}
			}
			//return pos-1;
		}
	}
}


	
int main(){

	string str;

	while(cin>>str>>idx&&!(str=="0"&&idx==0)){
		cp=-1;
		//char r=rec(str,idx);
		result=0;
		dfs(str);
		if(result==0){
			cout<<0<<endl;
		}
		else{
			cout<<result<<endl;
		}
	}

	return 0;
}

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

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

  cin >> A>>B >>C >>D;
  if (A+B>C+D){
   cout << "Left"<< endl;  
  }
  else if(A+B<C+D){
  cout << "Right" << endl;
  }
  else{
  cout<< "Balanced"<<endl;
  }
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,K = map(int, readline().split())
    A = [int(i) - 1 for i in readline().split()]

    p = 0
    route = []
    seen = set()
    while True:
        route.append(p)
        seen.add(p)
        p = A[p]
        if p in seen:
            break
    
    loop_start = route.index(p)
    loop_len = len(route) - loop_start

    if K <= loop_start:
        ans = route[K] + 1
    else:
        r = (K - loop_start) % loop_len
        ans = route[loop_start + r] + 1
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 32416
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = numeric_limits<long long>::max();

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

    queue<ll> q;
    REP(i, 1, 10) q.push(i);

    ll tmp;
    REP(i, 0, K){
        tmp = q.front();
        q.pop();
        if (tmp % 10 != 0) q.push(10 * tmp + tmp % 10 - 1);
        q.push(10 * tmp + tmp % 10);
        if (tmp % 10 != 9) q.push(10 * tmp + tmp % 10 + 1);
    }
    cout << tmp << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MIN INT_MIN
#define MAX INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define E "\n"
#define frep(i,j,k,inc) for(int i=j;i<k;i+=inc)
#define rrep(i,j,k,dec) for(int i=j;i>k;i-=dec)
#define arep(elm,obj) for(auto elm:obj)
#define all(x) x.begin(),x.end()
#define revT greater<int>()
#define SMAX 1000000
#define EMAX 101

typedef uint64_t usf;
typedef int64_t isf;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int>pii;
const ll mod=1000000007;
void solve();
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
//    int t;cin>>t;while(t--)
    {solve();}return 0; }

int mima(vi vec,int f){int mi=vec[0],ma=vec[0];frep(i,1,vec.size(),1){mi=min(mi,vec[i]);ma=max(ma,vec[i]);}if(f){return ma;}else{return mi;}}
template <class T>
T gcd(T a,T b){return __gcd(a,b);}
template <class T>
T lcm(T a,T b){return (a*b)/gcd(a,b);}
template <class T>
T miller(T d,T n,T a){T x=mpow(a,d,n);if(x==1 || x==n-1){return true;}while(d!=n-1){x=(x*x)%n;d*=2;if(x==1){return false;}if(x==n-1){return true;}}return false;}
template <class T>
T isprime(T n){if(n<=1 || n==4){return false;}if(n<=3){return true;}T d=n-1;while(d%2==0){d/=2;}T arr109[3]={2,7,61};T arr264[12]={2,3,5,7,11,13,17,19,23,29,31,37};for(auto x:arr109){if(!miller(d,n,x)){return false;}}return true;}
bool earr[EMAX+1];void eseive() {memset(earr, 1, sizeof(earr));earr[0] = 0;earr[1] = 0;frep(i, 2, sqrt(EMAX) + 1, 1) {frep(j, i * i, EMAX + 1, i) {earr[j] = 0;}}frep(i, 0, EMAX + 1, 1) {if (earr[i]) {cout << i << E;}}}
int spf[SMAX]={0};
void pseive(){spf[1]=1;frep(i,2,SMAX,1){spf[i]=i;}frep(i,4,SMAX,2){spf[i]=2;}for(int i=3;i*i<SMAX;i++){if(spf[i]==i){for(int j=i*i;j<SMAX;j+=i){if(spf[j]==j){spf[j]=i;}}}}}
vi fastfactor(int n){vi ret;while(n!=1){ret.PB(spf[n]);n/=spf[n];}return ret;}
template <class T>
T minv1(T a,T m){T temp=m,q,t,u=0,v=1;if(m==1){return 0;}while(a>1){q=a/m;t=m;m=a%m;a=t;t=u;u=v-q*u;v=t;}if(v<0){v+=temp;}return v;}
template <class T>
T mmul(T a,T b,T m){T res=0;a%=m;while(b){if(b&1){res=(res+a)%m;}a=(2*a)%m;b>>=1;}return res%m;}
template <class T>
T mpow(T a,T n,T m){T res=1;a%=m;if(!a){return 0;}while(n){if(n&1){res=mmul(res,a,m);}n=n>>1;a=mmul(a,a,m);}return res;}
template <class T>
T minv2(T a, T m){return mpow(a,m-2,m);}

void solve(){ 
	usf n;
	cin>>n;
	usf ans=0;
	for(usf i=0;i<n;i++){ans+=((i+1)*(n-i));}
	frep(i,0,n-1,1){
		usf a,b;
		cin>>a>>b;
		a--;b--;
		if(a>b){swap(a,b);}
		ans-=(a+1)*(n-b);	
	}
	cout<<ans<<E;
}

Measured memory_bytes: 3644
s=input()
n=len(s)
f=1
for i in range((n-1)//2):
    if s[i]!=s[n-i-1]:
        f=-1
        break
if f==1:
    for i in range((n-1)//4):
        if s[i]!=s[(n-3-2*i)//2]:
            f=-1
            break
    
if f==1 and n!=3:
    for i in range((n+1)//2,(3*n+3)//4):
            if s[i]!=s[n-i-1]:
                f=-1
                break

if f==1:
    print('Yes')
else:
    print('No')
    


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

vector<vector<int>> to;
int N; 
vector<pair<int,int>> Edges;
vector<bool> visited;
map<pair<int,int>,int> ans;
int S = 0; vector<int> color;

void dfs(int v, int p){
  // vが現在の頂点、pが親
  visited[v] = true;
  S = max(S,(int)to[v].size());
  
  int paint = 1;
  
  for(auto ne : to[v]){
    if(visited[ne]){ continue;}
    // vとneの間をどう塗るか
    
    if( paint == color[v] && v != -1){ paint++;}
    
    color[ne] = ans[{v,ne}] = ans[{ne,v}] = paint++;
    
    dfs(ne,v);
    
  }
  
}
    

int main(){ 
  cin >> N; 
  
  to.resize(N);
  visited = vector<bool> (N,false);
  color = vector<int> (N,0);
  
  for(int i = 1; i < N; i++){
    int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b); to[b].push_back(a);
    Edges.push_back({a,b}); 
  }
  
  dfs(0,-1); //頂点０を根として順次色をつけていく.親がいないので-1
  
  cout << S << endl;
  
  for(auto ne : Edges){ cout << ans[ne] << endl;}
  
  return 0;
}

Measured memory_bytes: 20600
from collections import defaultdict
n = int(input())
dic = defaultdict(lambda: 0)
for _ in range(n):
    com = input().split(' ')
    if com[0]=='insert':
        dic[com[1]] = 1
    else:
        if com[1] in dic:
            print('yes')
        else:
            print('no')

Measured memory_bytes: 37492
#include<iostream>
#include<map>
#include<set>
using namespace std;
map<int,int> a;
multiset<int> b;
int n,k,v[300000];
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
		a[v[i]]++;
	}
	for(auto i:a)b.insert(i.second);
	int j=0,ans=0;
	auto i=b.rbegin();
	for(;j<k&&i!=b.rend();j++,i++)ans+=*i;
	cout<<n-ans<<endl;
}


Measured memory_bytes: 19840
#include<stdio.h>

int main(){
  int r;
  
  scanf("%d", &r);
  
  if(r < 1200){
    printf("ABC\n");
  } else if(r < 2800){
    printf("ARC\n");
  } else {
    printf("AGC\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;


int main(void) {
  double x, h;
  while(cin >> x >> h){
    if( x == 0 ) break;
    double s = x * x;

    s += 2 * x * sqrt( h * h + x * x / 4 );

    printf("%.10lf\n", s);
  }

  return 0;
}

// EOF

Measured memory_bytes: 3068
#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SQR(x) (x) * (x)
#define itn int

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
#define MAX_V 300
int shortest_path[MAX_V][MAX_V]; //shortest_path[i][j] = cost(i→j) or INF
int V;                           //num of nodes
void warshall_floyd() {
  for (int k = 0; k < V; k++) {
    shortest_path[k][k] = 0;
  }
  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        shortest_path[i][j] = min(shortest_path[i][j], shortest_path[i][k] + shortest_path[k][j]);
      }
    }
  }
};
signed main() {
  int E;
  cin >> V >> E;
  FILL(shortest_path, INF);
  int s, t, d;
  REP(_, E) {
    cin >> s >> t >> d;
    shortest_path[s][t] = d;
  }
  warshall_floyd();
  REP(i, V) {
    if (shortest_path[i][i] < 0) {
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  }
  REP(i, V) {
    REP(j, V) {
      if (shortest_path[i][j] >= INF - (int)(1e12)) {
        cout << "INF";
      } else {
        cout << shortest_path[i][j];
      }
      cout << (j != V - 1 ? " " : "");
    }
    cout << endl;
  }
}



Measured memory_bytes: 3796
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(N)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """

    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, left, right):
        """
        [left, right)のsegfuncしたものを得る
        left: index(0-index)
        right: index(0-index)
        """
        res = self.ide_ele
        left += self.num
        right += self.num
        while left < right:
            if left & 1:
                res = self.segfunc(res, self.tree[left])
                left += 1
            if right & 1:
                res = self.segfunc(res, self.tree[right - 1])
            left >>= 1
            right >>= 1
        return res


def resolve():
    n, q = map(int, input().split())
    A = list(map(int, input().split()))
    seg = SegTree(A, lambda x, y: max(x, y), -f_inf)

    for _ in range(q):
        t, *query = map(int, input().split())
        if t == 1:
            x, v = query
            seg.update(x - 1, v)
        elif t == 2:
            l, r = query
            print(seg.query(l - 1, r))
        else:
            x, v = query
            ok, ng = n + 1, x - 1
            while abs(ng - ok) > 1:
                middle = (ok + ng) // 2
                if seg.query(x - 1, middle) >= v:
                    ok = middle
                else:
                    ng = middle
            print(ok)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 100240
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int N;
int l[1000];

int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);
  cin >> N;
  rep(i, N) cin >> l[i];

  sort(l, l+N);
  reverse(l, l+N);

  int sum = 0;
  for (int i = 1; i < N; ++i) sum += l[i];

  if (sum > l[0]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int pr[100005];
int main() {
	long long num;
	for (int i = 0; i <= 100003;i++) {
		pr[i] = 1;
	}
	for (int i = 2; i <= 100003;i++) {
		if(pr[i]==1)
		for (int j = i*2; j <= 100003; j += i) {
			pr[j] = 0;
		}
	}
	cin >> num;
	while (true) {
		if (pr[num] == 1) {
			cout << num;
			break;
		}
		else
			num++;
}
	return 0;
}

Measured memory_bytes: 640
n,k=map(int,input().split())
s=list(input())
if s[k-1]=="A":
    s[k-1]="a"
if s[k-1]=="B":
    s[k-1]="b"
if s[k-1]=="C":
    s[k-1]="c"
print("".join(s))

Measured memory_bytes: 3060
#include <stdio.h>

int n, A[20];

int solve(int i, int m) {
    int res;
    
    if (m == 0) {
        return 1;
    }
    
    if (i >= n) {
        return 0;
    }
    
    res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    
    return res;
}

int main() {
    int q, m;
    int i;
    
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);

    for (i = 0; i < q; i++) {
        scanf("%d", &m);
        
        if (solve(0, m)) {
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }
    
    return 0;
}



Measured memory_bytes: 1932
#include <iostream>
using namespace std;
int main(void){
    // Your code here!

int W , H , x , y , r   ;

  cin >> W;
  cin >> H;
  cin >> x;
  cin >> y;
  cin >> r;




if( (x-r ) >= 0 && (x+r) <= W && (y-r) >= 0 && (y+r) <= H){
    cout << "Yes" ;
    
    
}else
  cout << "No" ;
  
cout << endl;
}




Measured memory_bytes: 3104
/*pata hai na?*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

//#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     makep        make_pair
#define     maket        make_tuple
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

#define REPinit(i,a,n) for(int i=(a); i<(n); i++)

const ld pi=acos(-1);
//const int inf=1e18,M=1e9+7;
const int N=2e4+5;

set<int> st[26];

int type[N],idx[N],l[N],r[N];
char c[N];

void solve()
{
    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;

    REPinit(i, 0, Q) {
        cin >> type[i];
        if (type[i] == 1) {
            cin >> idx[i] >> c[i];
        }
        else {
            cin >> l[i] >> r[i];
        }
    }

    string initial = S;
    REPinit(i, 0, 26) {
        st[i].clear();
        st[i].insert(N);
    }

    REPinit(i, 0, N) {
        st[(int)(S[i] - 'a')].insert(i);
    }

    REPinit(i, 0, Q) {
        if (type[i] == 1) {
            st[(int)(S[idx[i] - 1] - 'a')].erase(idx[i] - 1);
            S[idx[i] - 1] = c[i];
            st[(int)(S[idx[i] - 1] - 'a')].insert(idx[i] - 1);
        }
        else {
            int ANS = 0;
            REPinit(j, 0, 26) {
                auto itr = st[j].lower_bound(l[i] - 1);
                if (*itr <= r[i] - 1) ANS++;
            }
            cout << ANS << '\n';
        }
    }
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 25116
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
//ll t;
//cin>>t;
//while(t--)

 ll n,i,j,k=0;

cin>>n;
for(i=1;i<10;i++)
{
  for(j=1;j<10;j++)
  {
      if(i*j==n)
       {k=1;
      break;}
  }
}
if(k==1)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;
return 0;
}


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

using namespace std;

int main()
{
	int n,c,k;
	cin >> n >> c >> k;
	int t[100005];
	for(int i=1;i<=n;i++)
		cin >> t[i-1];
	
	sort(t,t+n);

	int ans=1;
	int tmp=t[0];
	int count=1;
	for(int i=2;i<=n;i++)
	{
		
		if(tmp+k<t[i-1] or count==c)
		{
			ans++;
			tmp=t[i-1];
			count=1;
		}
		else	count++;
	}

	cout << ans << endl;

}




Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define rep(i,l,r)  for(int i=l;i<=r;i++)
#define pre(i,r,l)  for(int i=r;i>=l;i--)
#define pii pair<int,int>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int maxn = 1000005;
inline int read(){
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
ll flag[maxn];
int main() {
  int n; cin >> n;
  vector<ll> v(n+1);
  ll sum = 0;
  rep(i, 1, n) cin >> v[i], sum += v[i], flag[v[i]]++;
  int q = read();
  while(q--) {
    int a = read(), b = read();
    sum -= a*flag[a];
    sum += b*flag[a];
    flag[b] += flag[a];
    flag[a] = 0;
    cout << sum << endl;
  }
}


Measured memory_bytes: 4768
function main(input) {
    let lines = input.split("\n");
    let c = lines[1].split('');

    let cl = 0;
    let cr = c.length -1;
    let cnt = 0;
    while(true){
        cl = c.indexOf("W", cl);
        cr = c.lastIndexOf("R", cr);

        if(cl >= cr || cl === -1 || cr === -1){
            break;
        }

        let b = c[cl];
        c[cl] = c[cr];
        c[cr] = b;
        
        cnt++;
        cl++;
        cr--;
    }
    //console.log(c.join(""));

    return cnt;
}

//******************************
exports.main = main;

function Main(input) {
    console.log(main(input.trim()));
}

if (process.argv[2] !== "test") {
    Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}

Measured memory_bytes: 35312
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	alice, bob := 0, 0
	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	for i, v := range A {
		if i%2 == 0 {
			alice += v
		} else {
			bob += v
		}
	}

	fmt.Fprintln(wtr, alice-bob)
	wtr.Flush()
}


Measured memory_bytes: 640
N, M = map(int, input().split())
E = [set() for i in range(N+1)]
for i in range(M):
    A, B = map(int, input().split())
    E[A].add(B)
    E[B].add(A)
Closed = set()
n = 1
Ans = []
while True:
    Ans.append(n)
    Closed.add(n)
    for e in E[n]:
        if e not in Closed:
            n = e
            break
    else:
        break
n = 1
Ans.reverse()
del Ans[-1]
while True:
    Ans.append(n)
    Closed.add(n)
    for e in E[n]:
        if e not in Closed:
            n = e
            break
    else:
        break

print(len(Ans))
print(*Ans)


Measured memory_bytes: 37256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int c[51][51];
bool used[51][51];
const int dx[]={-1,-1,-1,0,0,1,1,1},dy[]={1,0,-1,1,-1,1,0,-1};
int main(){
    int w,h;
    while(cin>>w>>h,w|h){
        int cnt=0;
        memset(used,0,sizeof(used));
        rep(i,h)rep(j,w) cin>>c[i][j];
        rep(i,h)rep(j,w)if(!used[i][j]&&c[i][j]==1){
            ++cnt;
        queue<pair<pint,int> > q;
        q.push({{j,i},0});
        used[i][j]=true;
        while(!q.empty()){
            pair<pint,int> pi=q.front();q.pop();
            rep(k,8){
                int tx=pi.first.first+dx[k],ty=pi.first.second+dy[k];
                if(tx>=0&&ty>=0&&tx<w&&ty<h&&c[ty][tx]==1&&!used[ty][tx]){
                    q.push({{tx,ty},pi.second+1});
                    used[ty][tx]=true;
                }
            }
        }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a[100100];

int main() {
	li n,t;
	cin>>n>>t;
	li current_min = INF;
	li diff_max=0;
	li diff_cnt=0;
	rin{
		cin>>a[i];
		current_min = min(current_min,a[i]);
		if(current_min==INF)continue;
		if(diff_max<a[i]-current_min){
			diff_cnt=1;
			diff_max=a[i]-current_min;
		}else if(diff_max==a[i]-current_min){
			diff_cnt++;
		}
	}
	cout<<diff_cnt<<endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    int N, M;
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define vvi vector<vi>
#define endl "\n"
int vis[100005]={0};
using namespace std;
void solve1();
void solve()
{
    int t;cin>>t;
    while(t--)
    {
        solve1();
    }
}
signed main()
{
    solve1();
}
void solve1()
{
    int n;cin>>n;
    int arr[n];int ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];ans+=arr[i];vis[arr[i]]++;
    }
    int q,x,y;cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>x>>y;
        ans+=((y-x)*vis[x]);vis[y]+=vis[x];vis[x]=0;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 5148
n = int(input())
s = []
for i in range(n):
    s.append(int(input()))
maxs = sum(s)
s.sort()
k = []
for i in range(n):
    k.append(s[i] % 10)
if (maxs % 10) != 0:
    print(maxs)
elif k == [0]*n:
    print(0)
else:
    for i in range(n):
        if k[i] != 0:
            l = i
            break
    print(maxs - s[l])

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

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

const ll INF = 1LL << 60;

struct Edge{
  int to;
  ll weight;
  Edge(int t, ll w) : to(t),weight(w){}
};
using Graph = vector<vector<Edge>>;
typedef pair<ll, int> P;  // first: 最短距離, second: 頂点番号

Graph G;
vector<ll> d;

void dijkstra(int s) {
    fill(all(d), INF);
    d[s] = 0;  // 始点sへの最短距離は0

    priority_queue<P, vector<P>, greater<P>> pq;  // 距離が小さい順に取り出せるようgreater<P>を指定
    pq.push(P(0, s));
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;  // 更新した頂点の中で距離が最小の頂点v
        if (d[v] < p.first) {
            continue;
        }
        for (auto e : G[v]) {  // 頂点vから出る辺eを走査
            if (d[e.to] > d[v] + e.weight) {
                d[e.to] = d[v] + e.weight;
                pq.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
  int n, m; cin >> n >> m;
  G.resize(n);
  rep(i, m){
    int l,r; ll c; cin >> l >> r >> c;
    l--; r--;
    G[l].pb(Edge(r, c));
  }

  rep(i, n-1) G[i+1].pb(Edge(i, 0));

  d.resize(n);
  dijkstra(0);
  ll ans;
  if(d[n-1] == INF) ans = -1;
  else ans = d[n-1];
  std::cout << ans << '\n';
}


Measured memory_bytes: 9340
#include <bits/stdc++.h>
#define R cin>>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int N;
    R N;
    vector<int> v(N);
    rep(i, N) scanf("%d", &v[i]);
    vector<int> s = v;
    sort(all(v));
    float m;
    m = (v[N/2]+v[N/2-1])/2;
    rep(i, N) {
        if (s[i] <= m) {
            printf("%d\n", v[N/2]);
        } else {
            printf("%d\n", v[N/2-1]);
        }
    }
    return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x = scan.nextInt();
		int[] a = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			sum += a[i];
			if (a[i] < a[0]) {
				a[0] = a[i];
			}
		}
		int b = x - sum;
		System.out.println(b / a[0] + n);
	}
}


Measured memory_bytes: 21844