akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
	int K, S;
	cin >> K >> S;
	int cnt = 0;
	for(int x = 0; x <= K; x++){
		for(int y = 0; y <= K; y++){
			int z = S - x - y;
			if(z >= 0 && z <= K) cnt++;
		}
	}
	cout << cnt << endl;
}

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

struct edge {
	int from, to;
	edge(int f, int t) : from(f), to(t) {}
};

using edges = vector<edge>;
using graph = vector<edges>;

void add_edge(graph& G, int f, int t) {
	G[f].emplace_back(f, t);
	G[t].emplace_back(t, f);
}

vector<int> articulation_point(const graph& g) {
	int n = g.size(), idx = 0;
	vector<int> low(n), ord(n), art;
	function<void(int)> dfs = [&](int v) {
		low[v] = ord[v] = ++idx;
		for (auto& e : g[v]) {
			int w = e.to;
			if (ord[w] == 0) {
				dfs(w);
				low[v] = min(low[v], low[w]);
				if ((ord[v] == 1 && ord[w] != 2) || (ord[v] != 1 && low[w] >= ord[v]))
					art.push_back(v);
			}
			else
				low[v] = min(low[v], ord[w]);
		}
	};
	for (int u = 0; u < n; ++u) {
		if (ord[u] == 0) {
			idx = 0;
			dfs(u);
		}
	}
	sort(art.begin(), art.end());
	art.erase(unique(art.begin(), art.end()), art.end());
	return art;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int V, E;
	cin >> V >> E;
	graph G(V);
	for (int i = 0, s, t; i < E; i++) {
		cin >> s >> t;
		add_edge(G, s, t);
	}
	auto ap = articulation_point(G);
	for (auto v : ap) {
		printf("%d\n", v);
	}
	return 0;
}

Measured memory_bytes: 4872
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
ll func(ll x) {
    if (x%4 == 0) {
        return x;
    }
    else if (x%4 == 1) {
        return (x-1)^x;
    }
    else if (x%4 == 2) {
        return (x-2)^(x-1)^x;
    }
    else
    {
        return 0;
    }
}

int main(){
    
    ll a,b;
    cin >> a >> b;
    if (a==0) {
        ll ans = func(b);
        cout << ans << endl;
    }
    else
    {
        ll ans = func(a-1) ^ func(b);
        // cout << "func(a-1)=" << a << endl; 
        // cout << "func(b)=" << b << endl; 
        cout << ans << endl;
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
    int n;
    cin >> n;
    if(n % 1000 == 0){
        cout << 0 << endl;
    }else{
        cout << 1000 - n % 1000 << endl;
    }
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define ll long long int
#define all(x) x.begin(), x.end()
#define pb push_back
#define se second
#define fi first
using namespace std;
typedef pair<ll,ll> pll;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("input.in","r",stdin); 
    //freopen("output.out","w",stdout);
    int n; cin>>n;
    map<ll,int> count;
    for(int i=0;i<n;i++){
        ll val; cin>>val;
        count[val]++;
    } 
    bool ok=true;
    int m; cin>>m;
    for(int i=0;i<m;i++){
        ll val; cin>>val;
        if(!count[val]) ok=false;
        else{
            count[val]--;
        }
    }
    if(ok) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 12800
//繝・Φ繝励Ξ
#include <bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(),(v).end()

using namespace std;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
//
int a[100010];
int d[100010];
signed main (){
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   int N;
   cin >> N;
   int ans = 0;
   fill(a,a+N,0);
   REP(i,N)
   {
      cin >> a[i];
      if(a[i] > N) ans ++;
      else d[a[i]] ++;
   }
   FOR(i,1,N)
   {
      if(d[i]-i >0) ans += d[i] - i;
      if(d[i]-i < 0) ans += d[i];
   }
   cout << ans << endl;
}

//驛ｨ蛻・・譛蟆丞､
//譖ｴ譁ｰ縺励↑縺・ｴ蜷遺・邏ｯ遨阪ｏ
//莠梧ｬ｡蜈・↓縺励◆縺・・縺・ｂ縺呎ｳ・
//荳邂・園繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Segment Tree(縺溘□縺怜叙蠕涌(logN))
//遽・峇繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Lazy Segment Tree


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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

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

int main() {
  cout << setprecision(18);
  u32 K, A, B;
  cin >> K >> A >> B;
  u32 res = 0;
  while (res < A) {
    res += K;
  }
  if (res <= B)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;

  return 0;
}


Measured memory_bytes: 3652
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

void swap(int a,int b) {
	int tmp = a;
	a = b;
	b = tmp;
}

int main(void) {
	int k;
	cin >> k;

	int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	
	cout << a[k-1] << endl;
	

	return 0;
}

Measured memory_bytes: 3616
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
#------------------------------------------------------#
X, Y, Z = ri_()
print((X - Z) // (Y + Z))

Measured memory_bytes: 63084
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

ll calc(ll k,ll d) {
  return k*(k+1)/2*d;
}

const ll n=26;
ll c[n],q[444];
ll a[444][n];
set<ll> s[n];

ll solve(ll x,ll y) {
  ll ans=0;
  {
    ans-=a[x][q[x]];
    iter(s[q[x]]) it2=s[q[x]].lower_bound(x);
    iter(s[q[x]]) it1=it2,it3=it2;it1--,it3++;
    ans+=calc(*it2-*it1-1,c[q[x]]);
    ans+=calc(*it3-*it2-1,c[q[x]]);
    ans-=calc(*it3-*it1-1,c[q[x]]);
    s[q[x]].erase(it2);
  }
  {
    q[x]=y;
    s[q[x]].in(x);
    ans+=a[x][q[x]];
    iter(s[q[x]]) it2=s[q[x]].lower_bound(x);
    iter(s[q[x]]) it1=it2,it3=it2;it1--,it3++;
    ans-=calc(*it2-*it1-1,c[q[x]]);
    ans-=calc(*it3-*it2-1,c[q[x]]);
    ans+=calc(*it3-*it1-1,c[q[x]]);
  }
  return ans;
}

         
void Main() {
  srand((unsigned)time(NULL));
  int T;
  R T;
  rep(i,n) R c[i];
  rep(i,T)rep(j,n) R a[i][j];
  rep(i,n) s[i].in(-1),s[i].in(T);
  ll ans[T];
  mem(ans);
  rep(k,T) {
    ll x=rand()%n;
    q[k]=x;
    s[x].in(k);
    ans[k]=x;
  }
  clock_t t2=clock();
  for(int tt=0;;tt++) {
    ll e[2][3],sum=0;
    rep(i,2) {
      ll x=rand()%T,y=rand()%n;
      e[i][0]=q[x],e[i][1]=x,e[i][2]=y;
      sum+=solve(x,y);
    }
    if(sum<0) {
      rrep(i,2) {
        int x=e[i][1];
        s[q[x]].erase(x);
        q[x]=e[i][0];
        s[q[x]].in(x);
      }
    } else {
      rep(i,2) ans[e[i][1]]=e[i][2];
    }
    clock_t t3=clock();
    double t4=(double)(t3-t2)/CLOCKS_PER_SEC;
    if(tt>=2&&(double)t3/CLOCKS_PER_SEC+t4*2>1.900) break;
    t2=t3;
  }
  rep(i,T) pr(ans[i]+1);
}

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


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <atcoder/all>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
using namespace atcoder;

signed main(){
	fastio
	int n,q;
	cin >> n >> q;
	fenwick_tree<int> t(n);
	for(int i = 0,tmp;i < n;i++){
		cin >> tmp;
		t.add(i,tmp);
	}
	while(q--){
		int a,b,c;
		cin >> a >> b >> c;
		if(a==0) t.add(b,c);
		else cout << t.sum(b,c) << "\n";
	}
}

Measured memory_bytes: 8260
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    input! {
        n:usize,
        mut red:[(usize,usize);n],
        mut blue:[(usize,usize);n],
    }

    red.sort();
    red.reverse();

    let mut used = vec![false; n];
    let mut ans = 0;

    for (a, b) in red {
        let mut now_j = U_INF;
        let mut now = U_INF;
        for i in 0..n {
            if used[i] {
                continue;
            }

            let (c, d) = blue[i];
            if a < c && b < d {
                if now_j > d {
                    now_j = d;
                    now = i;
                }
            }
        }

        if now == U_INF {
            continue;
        } else {
            used[now] = true;
            ans += 1;
        }
    }
    
    println!("{}", ans);
}


Measured memory_bytes: 2192
#include<iostream>

int main()
{
    int N=0;
    int joyo,otsuri=0;

    std::cin >> N;

    joyo=N%1000;

    if(0 != joyo)
    {
        otsuri=1000-joyo;
    }
    else
    {
        otsuri=0;
    }
    std::cout << otsuri;

    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;
import java.util.Vector;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		Vector<Integer> vec = new Vector<Integer>();

		for(int i = 1; i <= Math.min(a, b); i++){
			if(a%i == 0 && b%i == 0){
				vec.add(i);
			}
		}

		System.out.println(vec.get(vec.size() - k));
	}

}


Measured memory_bytes: 21844
#include <stdio.h>

int main(void){

  char s[101];
  scanf("%s", s);

  int flag = 1;
  for (int i = 0; i < 101; i++) {
    if (s[i] < 'A' || s[i] > 'Z') {
      break;
    }
    if (i%2 == 0) {
      if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
        flag = 0;
        break;
      }
    } else {
      if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
        flag = 0;
        break;
      }
    }
  }

  if (flag == 1) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }
const int INF = 1000000000;

struct UnionFind
{
    vi par;
    vi sizes;

    UnionFind(int n) : par(n), sizes(n,1){
        rep(i,0,n) par[i] = i;
    }

    int find(int x){
        if(x==par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return;
        if(sizes[x]<sizes[y]) swap(x,y);
        par[y] = x;
        sizes[x]+=sizes[y];
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){
        return sizes[find(x)];
    }

};

int main() {
    ll N,M; cin>>N>>M;
    ll a[M],b[M];
    rep(i,0,M){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
    } 
    UnionFind uf(N);
    ll rec=N*(N-1)/2;
    ll ans[M+1];
    ans[0]=rec;
    for(int i=M-1;i>=0;i--){
        if(uf.same(a[i],b[i])) ans[M-i]=rec;
        else{
            rec-=uf.size(a[i])*uf.size(b[i]);
            ans[M-i]=rec;
            uf.unite(a[i],b[i]);
        }
    }
    reverse(ans,ans+M+1);
    rep(i,1,M+1) cout<<ans[i]<<endl;
}

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

bool is_prime[1000001];
int prime_sum[1000001];
int main() {
	memset(is_prime, 1, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	int p = 0, cnt = 0;
	for (int i = 2; i <= 1000000; i++) {
		if (is_prime[i]) {
			cnt += i;
			prime_sum[++p] = cnt;
			for (int j = i * 2; j <= 1000000; j += i)is_prime[j] = false;
		}
	}
	int n;
	while (scanf("%d", &n), n)printf("%d\n", prime_sum[n]);
	return 0;
}



Measured memory_bytes: 4496
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int h,w,n;
  cin>>h>>w>>n;
  Int sr,sc;
  cin>>sr>>sc;
  string s,t;
  cin>>s>>t;
  auto NG=[](){cout<<"NO"<<endl;exit(0);};
  
  {
    Int l=1,r=h;
    for(Int i=n-1;i>=0;i--){
      if(t[i]=='D') l--;
      if(t[i]=='U') r++;
      if(l<=1) l=1;
      if(r>=h) r=h;
      
      if(s[i]=='D') r--;
      if(s[i]=='U') l++;

      if(r<l) NG();
    }
    if(sr<l||r<sr) NG();
  }
  
  {
    Int l=1,r=w;
    for(Int i=n-1;i>=0;i--){
      if(t[i]=='R') l--;
      if(t[i]=='L') r++;
      if(l<=1) l=1;
      if(r>=w) r=w;
      
      if(s[i]=='R') r--;
      if(s[i]=='L') l++;

      if(r<l) NG();
    }
    if(sc<l||r<sc) NG();
  }
  cout<<"YES"<<endl;
  return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;

    int k = 0;
    if(a >= b){
        k = a - b;
    }else{
        k = b - a;
    }

    if(k % 2 == 0){
        if(a >= b){
            cout << a - (k / 2) << endl;
        }else{
            cout << b - (k / 2) << endl;
        }
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

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

int main(){
    int N;
    cin >> N;
    vector<string> s(N);
    vector<int> t(N);
    string X;
    int ans = 0;
    
    for (size_t i = 0; i < N; i++)
    {
        cin >> s.at(i);
        cin >> t.at(i);
    }
    
    cin >> X;

    

    for (size_t i = 0; i < N; i++)
    {
        
        if(s.at(i) == X){
            for (size_t j = i+1; j < N; j++)
            {
                ans += t.at(j);
                
            }
            
        }
    }

    cout << ans;
    
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int N;
    cin >> N;
    vector<ll> H(N);
    rep(i,N) cin >> H[i];
    
    ll key = H[0] - 1;
    for(int i = 1;i < N;i++)
    {
        if(H[i] == key)continue;
        else if(H[i] > key) H[i]--;
        else
        {
            cout << "No" << endl;
            return 0;
        }
        key = H[i];
    }
    cout << "Yes" << endl;


}


Measured memory_bytes: 1152
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
     
class Main{
    public static void main(String arg[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine();
        String A = sc.nextLine();
        Integer[] a = new Integer[N]; 

        sc.close();

        for(int i = 0; i < N; i++) {
            String[] s = A.split(" ");
            a[i] = Integer.parseInt(s[i]);
        }
        
        System.out.println(calc(a));    
    }
    
    public static int calc(Integer[] a) {
        int Alice = 0;
        int Bob = 0;
        
        Arrays.sort(a, Comparator.reverseOrder());

        for(int i = 0; i < a.length; i++){
            if(i % 2 == 0){
                Alice += a[i];
            }else{
                Bob += a[i];
            }
        }
		return Alice - Bob;
    }
}

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

int N;
string S;

int main() {
  cin >> N >> S;
  
  int slime_num = 1;
  int slime_color = S[0];
  
  for (int i = 1; i < N; i++) {
    if (slime_color == S[i]) continue;
    
    slime_num += 1;
    slime_color = S[i];
  }
  
  cout << slime_num << endl;
  
  return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>

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

using namespace std;

typedef long long ll;

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  int n; cin >> n;
  vector<int> a(n, 0);
  
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());

  ll ans = 0;

  if (n & 1) {
    ll t = 0, s = 0;
    rep(i, n) {
      if ( i < n/2 ) {
        s -= 2 * a[i];
      } else {
        s += 2 * a[i];
      }
      if ( i <= n/2 ) {
        t -= 2 * a[i];
      } else {
        t += 2 * a[i];
      }
    }
    s -= (a[n/2] + a[n/2+1]);
    t += (a[n/2] + a[n/2-1]);
    ans = max(s, t);
  } else {
    rep(i, n) {
      if (i < n/2) {
        ans -= 2 * a[i];
      } else {
        ans += 2 * a[i];
      }
    }
    ans += ( a[n/2-1]-a[n/2] );
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
using System.Linq;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int[] G() => ReadLine().Split().Select(int.Parse).ToArray();
	public K()
	{
		var I = G();
		WriteLine(Abs(I[0] - I[1]) < Abs(I[0] - I[2]) ? "A" : "B");
	}
}


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

const int N = 100054;

int S, T;
char s[N], t[N];
int sa[N], ta[N];

int main() {
	int i, j, k, l, q;
	scanf("%s%s%d", s, t, &q), S = strlen(s), T = strlen(t);
	for (i = 0; i < S; ++i) sa[i + 1] = sa[i] + --s[i] % 3;
	for (i = 0; i < S; ++i) ta[i + 1] = ta[i] + --t[i] % 3;
	for (; q; --q)
		scanf("%d%d%d%d", &i, &j, &k, &l),
		puts((sa[j] - sa[--i] - ta[l] + ta[--k]) % 3 ? "NO" : "YES");
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    rep2(i, N, 1000) {
        string temp = to_string(i);
        sort(temp.begin(), temp.end());
        if(temp.front() == temp.back()) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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 main(){
    int i,j;
    int n;
    vector<int> v={500,100,50,10,5,1};
    while(1){
        cin>>n;
        if(n==0) break; 
        int cnt=0;
        n=1000-n;
        for(i=0;i<6;i++){
            while(n>=v[i]){
                n-=v[i];
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }

}


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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (c>=a&&c<=b) {
		cout << "Yes" << "\n";
		return 0;
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
s = input()
t = input()

def checker(s,t):
    alphabets = [None] * 26
    for i,j in zip(s,t):
        order_number = ord(i) - ord("a")
        if alphabets[order_number] == None:
            alphabets[order_number] = j
        else:
            if alphabets[order_number] != j:
                return False
    return True

if checker(s,t) and checker(t,s):
    print("Yes")
else:
    print("No")

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

int a, b, c;
int main() {
	cin >> a >> b >> c;
	if(a==b && b==c) puts("No");
	else if(a==b || b==c || c==a) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)

#define DEB(X) if(mode==1)cout<< #X <<": "<<X<<" ";
#define DEB2(X) if(mode==1)cout<< #X <<": "<<" ";
#define ARDEB(i,X) if(mode==1)cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define FORDEB(n,X) if(mode==1)for(int i=0;i<(n);i++)ARDEB(i,X)
#define END if(mode==1)cout<<endl;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};

const int INF=100000000;
int mode=1;

#define MAX_V 51 
ll C[MAX_V][MAX_V];
ll d[MAX_V];
int cost[MAX_V][MAX_V];
bool used[MAX_V];
int X[MAX_V],Y[MAX_V];
int Ans,V,M;

void Dijkstra(int s,int x,int y){
	std::fill(d,d+V,INF);
	std::fill(used,used+V,false);
	d[s]=0;
	while(1){
		int v=-1;
		for(int u=0;u<V;u++){
			if(used[u]!=true && (v==-1 || d[u]<d[v])){
				v=u;
			}
		}
		if(v==-1)break;
		used[v]=true;
		for(int u=0;u<V;u++){
			d[u] = std::min(d[u], d[v]+((v==x&&u==y)||(v==y&&u==x)?INF:C[v][u]));
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin>>V>>M;
	for(int i=0;i<51;i++){
		for(int j=0;j<51;j++){
			C[i][j]=INF;
		}
	}
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		C[a-1][b-1]=1,C[b-1][a-1]=1;
		X[i]=a-1,Y[i]=b-1;
	}
	for(int i=0;i<min(50,V*(V-1)*2);i++){
		Dijkstra(0,X[i],Y[i]);
		for(int j=0;j<V;j++){
			if(d[j]==INF){
				Ans++;
				break;
			}
		}
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <numeric>
#include <cstdint>
#include <cmath>
using namespace std;
using i64 = int64_t;
void solve() {
	int a, b;
	cin >> a >> b;
	if (a < 1 || a > 9 || b < 1 || b > 9) {
		cout << -1 << endl;
	}
	else {
		cout << a * b << endl;
	}
}

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


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

int main()
{
  int N,K;
  cin>>N>>K;
  int ans=0;
  for(int i=0;i<30;i++){
    ans+=1;
    N/=K;
    if(N==0) break;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B;
    cin >> A >> B;
    cout <<  max(max(A+B, A-B), A*B) << endl;
    return 0;
}


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

int a[110],c[110];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i),c[a[i]]++;
	sort(a+1,a+n+1,greater<int>());
	int mid=(a[1]+1)/2,gg=(a[1]&1)+1;
	if(a[n]<mid||c[mid]!=gg) return puts("Impossible"),0;
	for(int i=a[1];i>mid;i--) if(c[i]<2) return puts("Impossible"),0;
	puts("Possible");
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;


int main() {
	make(n);
	int m = (n * (n-1))/2 - (n/2);
	printf("%d\n", m);
	int kij = n + (n+1)%2;
	FOR(i,1,n+1) {
		FOR(j,i+1,n+1) {
			if (i + j != kij) {
				printf("%d %d\n", i, j);
			}
		}
	}

}






Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		/*
		Scanner stdIn = new Scanner(System.in);
		int W = stdIn.nextInt();
		int H = stdIn.nextInt();
		int N = stdIn.nextInt();
		boolean[][] P = new boolean[W][H];
		
		for(int i = 0; i < N; i++) {
			int x = stdIn.nextInt();
			int y = stdIn.nextInt();
			int a = stdIn.nextInt();
			if(a == 1) {
				for(int j = 0; j < x; j++) {
					Arrays.fill(P[j], true);
				}
			}
			else if(a == 2) {
				for(int j = x; j < W; j++) {
					Arrays.fill(P[j], true);
				}
			}
			else if(a == 3) {
				for(int j = 0; j < y; j++) {
					for(int k = 0; k < W; k++) {
						P[k][j] = true;
					}
				}
			}
			else if(a == 4) {
				for(int j = y; j < H; j++) {
					for(int k = 0; k < W; k++) {
						P[k][j] = true;
					}
				}
			}
		}
		
		int ans = 0;
		for(int i = 0; i < W; i++) {
			for(int j = 0; j < H; j++) {
				if(!P[i][j]) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		*/
		
		Scanner stdIn = new Scanner(System.in);
		int W = stdIn.nextInt();
		int H = stdIn.nextInt();
		int N = stdIn.nextInt();
		int x0 = 0;
		int y0 = 0;
		
		for(int i = 0; i < N; i++) {
			int x = stdIn.nextInt();
			int y = stdIn.nextInt();
			int a = stdIn.nextInt();
			if(a == 1) {
				if(x > x0 && x < W) {
					x0 = x;
				}
				else if(x >= W) {
					System.out.println(0);
					System.exit(0);
				}
			}
			else if(a == 2) {
				if(x < W && x > x0) {
					W = x;
				}
				else if(x <= x0) {
					System.out.println(0);
					System.exit(0);
				}
			}
			else if(a == 3) {
				if(y > y0 && y < H) {
					y0 = y;
				}
				else if(y >= H) {
					System.out.println(0);
					System.exit(0);
				}
			}
			else if(a == 4) {
				if(y < H) {
					H = y;
				}
				else if(y <= y0) {
					System.out.println(0);
					System.exit(0);
				}
			}
		}
		
		System.out.println((W-x0)*(H-y0));

	}

}

Measured memory_bytes: 22100
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
//const long long mod = 1000000007;
//const long long mod = 998244353;


int main() {
	int a;
	scanf("%d", &a);
	char s[11];
	scanf("%s", s);
	printf(a >= 3200 ? s : "red");
	return 0;
}

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

using namespace std;

int main(){
    string dance;
    int flag=0;
    cin >> dance;
    for(int i=0; i < dance.length(); i++)
    {
      if(dance[i] == 'R' or dance[i] == 'U' or dance[i] == 'L' or dance[i] == 'D')
        {
            if(i % 2 == 1 and (dance[i] ==  'U' or dance[i] == 'L' or dance[i] == 'D'))
             {
               continue;
             }
            else if(i % 2 == 0 and (dance[i] ==  'U' or dance[i] == 'R' or dance[i] == 'D') )
            {
              continue;
            }
            else
            {
                flag=1;
                break;
            }
        }
    }


   if(flag == 0)
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }

    return 0;
}


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

constexpr int MAX_SIZE = 100;
int w, h;
int field[MAX_SIZE][MAX_SIZE];
int is_outside[MAX_SIZE][MAX_SIZE];
bool visited[MAX_SIZE][MAX_SIZE];

constexpr int dx[2][6] = {{1, 1, 1, 0, -1, 0}, // even
						  {0, 1, 0, -1, -1, -1}}; // odd
constexpr int dy[6] = {-1, 0, 1, 1, 0, -1};

inline bool out(int x, int y) {
	return x < 0 || y < 0 || x >= w || y >= h;
}

void dfs(int x, int y) {
	is_outside[y][x] = 1;

	const bool is_odd = (y & 1);
	for(int i = 0; i < 6; ++i) {
		const int nx = x + dx[is_odd][i];
		const int ny = y + dy[i];

		if(out(nx, ny) || is_outside[ny][nx] != -1) continue;
		dfs(nx, ny);
	}
}

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

	cin >> w >> h;

	memset(is_outside, -1, sizeof(is_outside));
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			cin >> field[i][j];
			if(field[i][j]) is_outside[i][j] = 0;
		}
	}

	for(int i = 0; i < h; ++i) {
		if(field[i][0] == 0) dfs(0, i);
		if(field[i][w - 1] == 0) dfs(w - 1, i);
	}

	for(int i = 0; i < w; ++i) {
		if(field[0][i] == 0) dfs(i, 0);
		if(field[h - 1][i] == 0) dfs(i, h - 1);
	}

	int ans = 0;
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if(field[i][j] == 0) continue;

			const bool is_odd = (i & 1);
			for(int k = 0; k < 6; ++k) {
				const int nx = j + dx[is_odd][k];
				const int ny = i + dy[k];

				if(out(nx, ny) || is_outside[ny][nx] == 1) ++ans;
			}
		}
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1552
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> C;

	for (auto i = 0; i < H; ++i)
	{
		string temp;
		cin >> temp;
		C.push_back(temp);
		C.push_back(temp);
	}

	for (auto i = 0; i < C.size(); ++i)
	{
		cout << C[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
int main() {
  int l,n=0,i;
  char s[1001];
  scanf("%s",s);
  l=strlen(s);
  while (n!=15&&i<l) {
    if (n%2==0&&s[i]=='E') {
      n+=1;
    } else if ((n/2)%2==0&&s[i]=='N') {
      n+=2;
    } else if ((n/4)%2==0&&s[i]=='S') {
      n+=4;
    } else if ((n/8)%2==0&&s[i]=='W') {
      n+=8;
    }
    i++;
  }
  if (n==6||n==9||n==15) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int> d(N);
    for(int i=0; i<N; i++) cin>>d[i];
    sort(d.begin(),d.end());
    int ans =1;
    for(int i=0; i<N-1; i++){
        if(d[i]<d[i+1]){
            ans++; 
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#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 <fstream>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

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

    ll a, b, k;
    cin >> a >> b >> k;
    if(k <= a){
        cout << a - k << " " << b << endl;
        return 0;
    }
    k -= a;
    a = 0;
    b = max(0ll, b - k);

    cout << a << " " << b << endl;
}

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

int LCS() {
  string a, b;
  cin >> a >> b;
  int dp[1001][1001] = {{0}};
  for (int i = 0; i < a.size(); i++)
  {
    for (int j = 0; j < b.size(); j++)
    {
      if (a[i] == b[j]) {
        dp[i+1][j+1] = max(dp[i][j]+1, max(dp[i+1][j], dp[i][j+1]));
      }
      else {
        dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
      }
    }
  }
  return dp[a.size()][b.size()];
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int ans = LCS();
    cout << ans << endl;
  }
  
}


Measured memory_bytes: 7132
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//ll tt;	cin>>tt;	while(tt--)
	{
		ll n,k,i,min_sum,max_sum,ways;
		cin>>n>>k;	

		ways=0;
		for(i=k;i<=n+1;i++)
		{
			ways+=(((n+n-i+1)*i)-(i*(i-1)))/2;
			ways++;
			ways%=1000000007;
		}

 		cout<<ways;
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 3792
from itertools import product

C1 = [int(x) for x in input().split()]
C2 = [int(x) for x in input().split()]
C3 = [int(x) for x in input().split()]
R1 = [c[0] for c in [C1,C2,C3]]
R2 = [c[1] for c in [C1,C2,C3]]
R3 = [c[2] for c in [C1,C2,C3]]

def check(C1, C2):
    r = 1 == len(set([C1[0] - C2[0], C1[1] - C2[1], C1[2] - C2[2]]))
    return r

if all(check(c1, c2) for c1, c2, in product([C1,C2,C3], [C1,C2,C3])) and \
        all(check(c1, c2) for c1, c2 in product([R1,R2,R3], [R1,R2,R3])):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using pii = pair<int, int>;
using ll = long long int;
using ld = long double;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
// ll mod(long long val) {
//     long long res = val % MOD;
//     if (res < 0) res += MOD;
//     return res;
// }
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }

int w, h;
vector<vector<int>> c;

bool dfs(int i, int j) {
    if (c[i][j] == 0) return false;
    c[i][j] = 0;
    if (i - 1 >= 0) dfs(i - 1, j);
    if (i + 1 < h) dfs(i + 1, j);
    if (j - 1 >= 0) dfs(i, j - 1);
    if (j + 1 < w) dfs(i, j + 1);
    if (i - 1 >= 0 && j - 1 >= 0) dfs(i - 1, j - 1);
    if (i - 1 >= 0 && j + 1 < w) dfs(i - 1, j + 1);
    if (i + 1 < h && j + 1 < w) dfs(i + 1, j + 1);
    if (i + 1 < h && j - 1 >= 0) dfs(i + 1, j - 1);
    return true;
}

bool solve() {
    cin >> w >> h;
    if (w == 0 && h == 0) return false;
    c = vector<vector<int>>(h, vector<int>(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> c[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            ans += dfs(i, j);
        }
    }
    cout << ans << endl;
    return true;
}

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



Measured memory_bytes: 3332
import sys
K,A,B=[int(i) for i in input().split(" ")]


if A>=K+1:
    print(K+1)


elif B>A+2:
    K-=(A-1)
    biscuit=A
    biscuit+=(B-A)*(int(K/2))
    if K%2==1:
        biscuit+=1
    print(biscuit)

else:
    print(K+1)


Measured memory_bytes: 3060
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll x,tmp,len;
  bool can=false;
  cin >> x;
  len = x/100;
  if(x<100){
    cout <<"0\n";
    return 0;
  }else if(x>=100*20){
    cout <<"1\n";
  }else{
    tmp = x%100;
    if(tmp<=len*5){
      cout <<"1\n";
    }else{
      cout <<"0\n";
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
using namespace std;


int main(){
    int n;
    cin >> n;
    int a[n], max_a=1, second_a=1;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        if (a[i] >= max_a){
            second_a = max_a;
            max_a = a[i];
        }
        else {
            second_a = max(second_a, a[i]);
        }
    }
    for (int i = 0; i < n; i++){
        if (a[i] == max_a){
            cout << second_a << endl;
        }
        else{
            cout << max_a << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
using namespace std;
int r,n;
int a[50];
main()
{
	while(cin>>r>>n,r)
	{
		for(int i=0;i<=40;i++)a[i]=0;
		for(int i=0;i<n;i++)
		{
			int l,r,h;cin>>l>>r>>h;
			l+=20;r+=20;
			for(int j=l;j<r;j++)a[j]=max(a[j],h);
		}
		double l=0,f=1e2;
		for(int i=0;i<100;i++)
		{
			double m=(l+f)/2;
			bool flag=1;
			for(int j=20;j>20-r;j--)
			{
				double h=sqrt(r*r-(20-j)*(20-j))+m-r;
				if(a[j-1]<h)
				{
					flag=0;
					break;
				}
			}
			for(int j=20;j<20+r;j++)
			{
				double h=sqrt(r*r-(j-20)*(j-20))+m-r;
				if(a[j]<h)
				{
					flag=0;
					break;
				}
			}
			if(flag)l=m;
			else f=m;
		}
		cout<<fixed<<setprecision(9)<<l<<endl;
	}
}



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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double

// AtCoder Grand Contest 015
// A - A+...+B Problem
int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  if (a > b) {
    cout << 0 << endl;
    return 0;
  }
  else if (n <= 1) {
    if (a == b) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }
  cout << ((n-2) * (b-a) + 1) << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    while(true){
        int d,w,h,n,r[10000],a=0,b=0;
        float c=0;
        cin>>d>>w>>h;
        if(d+w+h==0)break;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>r[i];
        }
        a=d;
        if(a>w){
            swap(a,w);
        }
        b=w;
        if(w>h){
            b=h;
        }
        c=a*a+b*b;
        c=sqrt(c);
        for(int i=0;i<n;i++){
            if(2*r[i]>c)cout<<"OK"<<endl;
            else{
                cout<<"NA"<<endl;
            }
        }
    }
}

Measured memory_bytes: 3020
#include<iostream>
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>
#include<math.h>
#include"boost/algorithm/string.hpp"

using namespace std;


int main(){
	//Q2

	int n;
	
	double pay;
	string type;

	long jpy = 0;
	double btc = 0;
	long btc2jpy = 380000;
	cin >> n;

	for (int i = 0; i < n; ++i){
		cin >> pay >> type;
		if (type == "JPY"){
			jpy += (long)pay;
		}
		else{
			btc += pay;
		}
	}

	cout << ((double)jpy + btc * btc2jpy) << endl;

	return 0;

	/*
	Q1

	int a, b = 0;
	string day;
	cin >> day;
	//2019/mm/dd

	if (day[5] == '0' && day[6] < '5'){
		cout << "Heisei" << endl;
	}
	else{
		cout << "TBD" << endl;
	}


	return 0;

	/*Q2*/

	/*Q3*/

		/*Q4*/

		//return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

inline vector<P> countVec(vector<int> vec) {
	vector<P> ans;
	sort(vec.begin(), vec.end());
	vec.push_back(0);
	int cnt = 0;
	rep(i, vec.size() - 1) {
		cnt++;
		if (vec.at(i) != vec.at(i + 1)) {
			ans.push_back(P(cnt, vec.at(i)));
			cnt = 0;
		}
	}
	return ans;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<P> p = countVec(a);
	int ans = 0;
	rep(i, p.size()) {
		if (p[i].first % 2 == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	int sum = 0;
	int pos = N;
	while (pos > 0) {
		sum += pos % 10;
		pos /= 10;
	}

	if (N % sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define Forn(i, a) for(int i=1; i<=a; i++)
#define read(x) ((scanf("%s", &_), (x) = _))
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
#define HASH 1543 

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{ 
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0; 
	}
    do 
	{ 
		x=(x<<3)+(x<<1)+(c^48); 
	} 
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int gcd(int a, int b){if(a>b) swap(a, b); return a==0?b:gcd(b%a, a);}
inline int lcm(int a, int b){return a*b/gcd(a, b);}

int N, M, dist[200010], a, b, c;
vector<pi> e[200010], em;
bool vis[200010];
unordered_set<int> inr[200010], m;

int main()
{
	while(~scanf("%d %d",&N,&M))
	{
		memset(vis, false, sizeof(vis));
		memset(dist, 63, sizeof(dist));
		Forn(i, 200000)
			e[i]=em, inr[i]=m;
		while(M--)
		{
			a=in(), b=in(), c=in();
			e[a].eb(mp(b, c));
			e[b].eb(mp(a, c));
		}
		priority_queue<pi> q;
		dist[1]=0;
		vis[1]=true;
		q.push(mp(0, 1));
		while(!q.empty())
		{
			int st=q.top().s, cost=-q.top().f;
			q.pop();
			vis[st]=true;
			if(cost>dist[st])
				continue;
			foreach(it, e[st])
			{
				int ed=it->f, c=it->s, d=dist[st]+(!inr[st].count(c));
				if(vis[ed]||dist[ed]<d)
					continue;
				if(dist[ed]>d)
				{
					dist[ed]=d;
					q.push(mp(-d, ed));
					inr[ed].clear();
				}
				inr[ed].insert(c);
			}
		}
		if(dist[N]>INF)
			puts("-1");
		else
			printf("%d\n", dist[N]);
	}
	return 0;
}


Measured memory_bytes: 33268
N=int(input())
L=list(map(int,input().split()))
S=sorted(L)
D={}
c=1
t=0
for i in range(N-1):
  if S[i]==S[i+1]:
    c+=1
  else:
    D[S[i]]=c
    c=1
D[S[N-1]]=c

for i in D.values():
   t+=i*(i-1)//2 
for i in range(N):
  print(t-(D[L[i]]-1))

Measured memory_bytes: 26140
import java.util.Scanner;
import scala.collection.immutable.Set;

object Main{
  def main(args: Array[String]){
    val sc = new Scanner(System.in);
    val n = sc.nextInt;
    sc.nextLine;
    val s: String = sc.nextLine;

    println((for(i <- 1 to s.length-1) yield {
      s.splitAt(i) match{
        case (f,s) => {
          (f.toCharArray.toSet & s.toCharArray.toSet).size;
        }
      }
    }).max);
  }
}


Measured memory_bytes: 27060