akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int n, m, x; cin >> n >> m >> x;
    vei A(m);
    int costn = 0;
    int cost0 = 0;
    rep(i,m) {
        cin >> A[i];
        if (x < A[i] and A[i] < n) costn++;
        if (0 < A[i] and A[i] < x) cost0++;
    }
    cout << min(costn,cost0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    string s;
    cin>>n>>s;
    int r=n-1,ans=0;
    for(int l=0;l<n;++l){
        if(s[l]=='R')continue;
        while(s[r]=='W'&&l<r)--r;
        swap(s[l],s[r]);
        if(l>=r)break;
        ++ans;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3748
s = input()
size = len(s)
d = ('A','C','G','T')
ans = 0
for i in range(size):
    for j in range(i+1, size+1):
        for k in s[i:j]:
            if k not in d:
                break
        else: ans = max(ans, j-i)

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define ALL(v) v.begin(), v.end()
#define MAX_N 100001
#define rep(i, a, b) for(ll i=a; i<b; i++)
#define rer(i, a, b) for(ll i=a-1; i>=b; i--)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n;
string s;
string a = "dream", b = "dreamer", c = "erase", d = "eraser";
signed main(){
    cin >> s;
    reverse(ALL(s));
    reverse(ALL(a));
    reverse(ALL(b));
    reverse(ALL(c));
    reverse(ALL(d));
    int i = 0, n = s.size();
    while(i < n){
        if(s.substr(i, a.size()) == a) i += a.size();
        else if(s.substr(i, b.size()) == b) i += b.size();
        else if(s.substr(i, c.size()) == c) i += c.size();
        else if(s.substr(i, d.size()) == d) i += d.size();
        else break;
    }
    if(i == n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
#define MAXR 1000

int dp[1010][1010];
int doll[1010][1010];

int main()
{
    int n,m;
    while(cin >>n)
    {
        if(n==0)break;
        memset(dp,0,sizeof(dp));
        memset(doll,0,sizeof(doll));
        int h,r;
        for(int i=0;i<n;i++)
        {
            cin>>h>>r;
            doll[h][r]=1;
        }
        cin >> m;
        for(int i=0;i<m;i++)
        {
            cin>>h>>r;
            doll[h][r]=1;
        }

        for(int i=1;i<MAXR;i++)
        {
            for(int j=1;j<MAXR;j++)
            {
                int temp;
                if(doll[i][j]==1)
                {
                    temp = max(dp[i-1][j],dp[i][j-1]);
                    dp[i][j] = max(1+dp[i-1][j-1],temp);
                }
                else
                    dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
        cout << dp[999][999] << endl;
    }
    return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,a[N],dp[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]),dp[a[i]]=dp[a[i]-1]+1;
    int ans=0;
    for(int i=1;i<=n;i++)
        ans=max(ans,dp[i]);
    printf("%d\n",n-ans);
}


Measured memory_bytes: 1792
package main

import (
  "fmt"
)

func main() {

  var n, l int
  fmt.Scan(&n, &l)
  
  var apples [] int
  var taste int
  taste = l
  for i:=1; i<=n; i++ {
    apples = append(apples, taste)
    taste += 1
  }
  
  var ntotal int
  for _, v := range(apples) {
    ntotal += v
  }
  
  if l > 0 {
    fmt.Println(ntotal - l) 
  } else {
    if (n + l) > 0 {
      fmt.Println(ntotal) 
    } else {            
      fmt.Println(ntotal - (n + l - 1)) 
    }
  }
}

Measured memory_bytes: 512
function Main(input) {	
  	if(parseInt(input) === 0 ){
      console.log(1)
    }else{
      console.log(0)
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29688
#include <bits/stdc++.h>
#define inf 1e15
using namespace std;
typedef long long ll;

int main(){
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A+2), t(B+2);
    for(int i=1; i<=A; i++) cin >> s[i];
    for(int i=1; i<=B; i++) cin >> t[i];
    s[0] = -inf;  s[A+1] = inf;
    t[0] = -inf;  t[B+1] = inf;

    while(Q>0){
        ll x; cin >> x;
        ll sr, sl, tr, tl;
        int is = lower_bound(s.begin(), s.end(), x) - s.begin();
        int it = lower_bound(t.begin(), t.end(), x) - t.begin();
        sr = s[is];  sl = s[is-1];
        tr = t[it];  tl = t[it-1];

        ll ans = 1e18;
        ans = max(sr-x, tr-x);
        ans = min(ans, max(x-sl, x-tl));
        ans = min(ans, 2*(x-sl) + tr-x);
        ans = min(ans, 2*(x-tl) + sr-x);
        ans = min(ans, 2*(sr-x) + x-tl);
        ans = min(ans, 2*(tr-x) + x-sl);
        cout << ans << endl;

        Q--;
    }
}


Measured memory_bytes: 2944
import java.util.*;

public class Main {
  public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int a = sc.nextInt();
    	int b = sc.nextInt();
    	int c = sc.nextInt();
    	int d = sc.nextInt();
    if(a + b > c + d) {
      System.out.println("Left");
    } else if(a + b == c + d) {
      System.out.println("Balanced");
    } else {
      System.out.println("Right");
    }
  }
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
int N;

unordered_set <string> S;

int main(){
	fast;
	
  cin>>N;
  FOR(i,0,N-1){
	string str;
    cin>>str;
    S.insert(str);
  }
  
  cout<<S.size();
	
}



Measured memory_bytes: 17728
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  string s[n];
  for(int i=0;i<n;i++){
    cin >> s[i] >> a[i];
  }
  int tmp;
  string tmp2;
  int c[n];
  for(int i=0;i<n;i++)c[i]=i+1;
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      if(s[i]>s[j]){
        tmp=a[i];
        a[i]=a[j];
        a[j]=tmp;
        tmp2=s[i];
        s[i]=s[j];
        s[j]=tmp2;
        tmp=c[j];
        c[j]=c[i];
        c[i]=tmp;
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      if(a[i]<a[j]&&s[i]==s[j]){
        tmp=a[i];
        a[i]=a[j];
        a[j]=tmp;
        tmp=c[i];
        c[i]=c[j];
        c[j]=tmp;
      }
    }
  }
  for(int i=0;i<n;i++)cout << c[i] << endl;
}


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

int main() {
  int N, l, r;
  int c = 0;
  
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> l >> r;
    for(int j=l-1;j<r;j++){
    c++;
    }      
  }
  
  cout << c << endl;
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), C(N-1);
    for (auto& e : A)
        cin >> e;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        sum += tmp;
    }
    for (auto& e : C)
        cin >> e;

    for (int i = 0; i < N - 1; i++) {
        if (A[i] == A[i + 1] - 1)
            sum += C[A[i] - 1];
    }

    cout << sum << endl;
}

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

int main() {
int N,a,sum=0;
  cin>>N;
  a=N;
  for(int i=0;i<10;i++){
    sum+=N%10;
    N=N/10;
  }
  if(a%sum==0){
  cout<<"Yes"<<endl;
}
  else if(a%sum!=0){
    cout<<"No"<<endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n, m;
    cin >> n >> m;
    vector <int> a(m);
    for (int i = 0; i < m; ++i) cin >> a[i];
    if (m == 1) {
        if (n == 1) {
            cout << "1\n1\n1";
            return 0;
        } else {
            cout << a[0] << '\n';
            cout << 2 << '\n' << a[0] - 1 << ' ' << 1 << '\n';
            return 0;
        }
    }
    int cnt = 0;
    for (int i = 0; i < m; ++i) if (a[i] % 2 == 1) ++cnt;
    if (cnt > 2) {
        cout << "Impossible\n";
        return 0;
    }
    for (int i = 1; i < m; ++i) {
        if (a[i] % 2 == 1) {
            if (a[0] % 2 == 0) swap(a[0], a[i]);
            else swap(a[i], a.back());
        }
    }
    for (int i = 0; i < m; ++i) cout << a[i] << ' ';
    cout << '\n';
    cout << (a[0] == 1 ? m - 1 : m) << '\n';
    if (a[0] > 1) cout << a[0] - 1 << ' ';
    for (int i = 1; i + 1 < m; ++i) {
        cout << a[i] << ' ';
    }
    if (m > 1) cout << a[m - 1] + 1 << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
double dp[305][305][305];
double solve(int x, int y, int z){
    if(x==0 && y==0 && z==0) return 0;
    if(x<0 || y<0 || z<0) return 0;
    if(dp[x][y][z]>0) return dp[x][y][z];
    int tot = x+y+z;
    return dp[x][y][z] = (n*1.0+x*solve(x-1,y,z)+y*solve(x+1,y-1,z)+z*solve(x,y+1,z-1))/tot;

}
int main(){
cin >> n;
int one=0,two=0,three=0;
for(int i=0; i<n; i++){
int x;
cin >> x ;
if(x==1) one++;
else if(x==2) two++;
else three++;
}
memset(dp, -1, sizeof dp);
cout << fixed << setprecision(10) << solve(one,two,three) << endl;


return 0;
}


Measured memory_bytes: 225464
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
string t;
int main(void)
{
	int ans=0;

	vi n(3);

	rep(i, 3) cin>>n[i];

	sort(all(n));

	rep(i, 2){
		ans+=(n[2]-n[i])/2;
		n[i]+=((n[2]-n[i])/2)*2;
	}

	if(n[0]==n[1]&&n[1]==n[2]){
		cout<<ans<<endl;
	}else if(n[0]!=n[2]&&n[1]==n[2]){
		cout<<ans+2<<endl;
	}else if(n[1]!=n[2]&&n[0]==n[2]){
		cout<<ans+2<<endl;
	}else{
		cout<<ans+1<<endl;
	}
}

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

long long f (int v, int i, int j) {
	return ((long long) v) * ((long long) abs(i - j));
}

signed main () {
	int n;
	cin >> n;
	vector < int > a(n);
	for (int &x: a) 
		cin >> x;
	vector < pair < int, int > > b(n);
	for (int i = 0; i < n; ++i)
		b[i] = make_pair(a[i], i);
	sort(b.rbegin(), b.rend());
	long long dp[n][n];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j)
			dp[i][j] = -1e18;
	}
	for (int l = n - 1; l >= 0; --l) {
		for (int r = l; r < n; ++r) {
			int to_eat = l + (n - 1 - r);
			if (l == r)
				dp[l][r] = f(b[to_eat].first, b[to_eat].second, l);
			else 
				dp[l][r] = max(dp[l][r - 1] + f(b[to_eat].first, b[to_eat].second, r), dp[l + 1][r] + f(b[to_eat].first, b[to_eat].second, l));
		}
	}
	cout << dp[0][n - 1] << '\n';
}


Measured memory_bytes: 34884
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  auto cost = [&] (string a) {
    int s = 0;
    for (int i = 0; i < (int) a.size(); i++) {
      int j = i;
      while (j < (int) a.size() && a[j] == a[i]) j++;
      s += (j - i) / 2;
      i = j - 1;
    }
    return s;
  };
  int k;
  cin >> k;
  bool same = true;
  for (auto c : s) {
    if (c != s[0]) same = false;
  }
  if (same) {
    cout << s.size() * (ll) k / 2 << '\n';
    return 0;
  }
  vector <int> a;
  string cur = "";
  for (int i = 0; i < 10; i++) {
    cur += s;
    a.push_back(cost(cur));
  }
  k--;
  if (k < (int) a.size()) {
    cout << a[k] << '\n';
  } else {
    cout << a.back() + (k - ((int) a.size() - 1)) * (ll) (a.back() - a[(int) a.size() - 2]) << '\n';
  }
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>

int main(void) {
  int N;
  scanf("%d", &N);
  int64_t A[100000];
  int64_t SUM = 0;
  for(int i = 0; i < N; i++) {
    scanf("%ld", &A[i]);
    SUM += A[i];
  }

  int64_t B[100000];
  B[N-1] = SUM;
  for(int i = 0; i < N-2; i+=2) {
    B[N-1] -= 2 * A[i];
  }  

  for(int j = N-2; j >= 0; j--) {
    int64_t b = A[j] - (B[j+1] / 2);
    B[j] = b * 2;
  }
  for(int i = 0; i < N; i++) {
    printf("%ld ", B[i]);
  }
  printf("\n");
  
  return 0;
}


Measured memory_bytes: 2816
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let N = read int
    let AS = reada int64

    let dp = Array2D.create (N + 1) 2 0L
    dp.[0,1] <- -1000000007L
    for i in [1 .. N] do
        let ai = AS.[i-1]
        dp.[i,0] <- max
            (dp.[i-1,0] + ai)
            (dp.[i-1,1] - ai)
        dp.[i,1] <- max
            (dp.[i-1,0] - ai)
            (dp.[i-1,1] + ai)

    printfn "%i" dp.[N,0]
    0

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    int a, b;
    cin >> a >> b;

    if(a + b < 10)
        cout << a + b << endl;
    else
        cout << "error" << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	map<char, int> mp;
	rep(i,4){
		++mp[s[i]];
	}
	if(mp.size() == 2 && mp[s[0]] == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define mp make_pair
#define db long double
#define up upper_bound
#define lb lower_bound
#define pll pair<ll,ll>
#define vll vector<ll>
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define sz(x) (int)x.size()
#define endl '\n'
#define int long long
#define mod 1000000007
#define MAX 100005
using namespace std;
vll g[MAX];

void dfs(ll cur,vll &d,vll &v,ll dis){
    d[cur] = dis;
    ll len = sz(g[cur]);
    v[cur]=1;
    rep(i,0,len){
    	ll no = g[cur][i];
    	if(!v[no]) dfs(no,d,v,dis+1);
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
 
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
 
    
    ll n;
    cin >> n;
    ll u,v;
    cin >> u >> v;
    rep(i,0,n-1){
    	ll a,b;
    	cin >> a >> b;
    	g[a].pb(b);
    	g[b].pb(a);
    }
    vll d1(n+5,0),d2(n+5,0);
    vll v1(n+5,0),v2(n+5,0);
    dfs(u,d1,v1,0);
    dfs(v,d2,v2,0);
    vector<pll> k;
    rep(i,1,n+1){
    	k.pb({d2[i],i});
    }
    sort(all(k),greater<>());
    rep(i,0,sz(k)){
    	if(d1[k[i].se] < k[i].fi){
    		cout << k[i].fi - 1;
    		return 0;
    	}
    }
    return 0;
 
}

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

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

    for(int i = 0; i < S.size(); ++i){
        if((i+1) & 1){
            if(!(S[i] == 'R' || S[i] == 'U' || S[i] == 'D')){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(!(S[i] == 'L' || S[i] == 'U' || S[i] == 'D')){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define cases long long int t;cin>>t;while(t--)
#define fio ios::sync_with_stdio(false); cin.tie(0)
#define ALL(v) (v).begin(), (v).end() 
#define twod(n,m) vector<vector<int> > arr( n , vector<int> (m, 0))
#define prs(s,n) for(ll i=0;i<n;i++)cout<<s[i];
#define pra(arr,n) for(ll i=0;i<n;i++)cout<<arr[i]<<" ";
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl;
using namespace std;
int main() 
{
	fio;
    ll n,k;
    cin>>n>>k;
    vector<ll> arr(n);
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    sort(arr.begin(),arr.end());
    ll sum = 0;
    for(ll i=0;i<k;i++)
        sum += arr[i];
    cout<<sum;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s, t;
  vector<int> a(26), b(26), A(26), B(26);
  cin >> s >> t;
  int cnt = 1;
  A.resize(s.length());
  B.resize(t.length());
  for (int i = 0; i < s.length(); i++){
    int tt = s[i] - 'a';
    if (a[tt] == 0){
      a[tt] = cnt++;
    }
    A[i] = a[tt];
  }
  cnt = 1;
  for (int i = 0; i < t.length(); i++){
    int tt = t[i] - 'a';
    if (b[tt] == 0){
      b[tt] = cnt++;
    }
    B[i] = b[tt];
  }
  for (int i = 0; i < s.length(); i++){
    if (A[i] != B[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 2312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

void DFS(int p, int cur, vector<vector<pair<int, ll>>> &V, vector<ll> &D, ll sum){
  D[cur] = sum;
  rep(i, 0, V[cur].size()){
    if(V[cur][i].first == p) continue;
    DFS(cur, V[cur][i].first, V, D, sum + V[cur][i].second);
  }
}

void Main() {
  const int N = 10;
  int H, W; cin >> H >> W;
  vector<vector<int>> c(N, vector<int>(N));
  rep(i, 0, N){
    rep(j, 0, N){
      cin >> c[i][j];
    }
  }
  rep(k, 0, N){
    rep(i, 0, N){
      rep(j, 0, N){
        chmin(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  int res = 0;
  rep(i, 0, H){
    rep(j, 0, W){
      int A; cin >> A;
      if(A == -1) continue;
      res += c[A][1];
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 8064
N = int(input())
length = [int(i) for i in input().split()]
pos = []
s1 = sum(length)
s2 = 0

for a in range(len(length)):
    pos.append(max(s1,s2) - min(s1,s2))
    s1 -= length[a]
    s2 += length[a]
    # print("pos " + str(a)+":",sum(length[:a]), sum(length[a:]))
# print(pos)

print(min(pos))

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

#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;

void solve()
{
	int n;
	cin >> n;
	string s;
	int ac= 0, wa= 0, tle= 0, re = 0;
	while (n--)
	{
		cin >> s;
		if (s == "AC")
			ac++;
		else if (s == "WA")
			wa++;
		else if (s == "TLE")
			tle++;
		else if (s == "RE")
			re++;
	}
	cout << "AC x " << ac << "\n";
	cout << "WA x " << wa << "\n";
	cout << "TLE x " << tle << "\n";
	cout << "RE x " << re << "\n";
}


int main()
{

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

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

	int t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}




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

#define MOD 1000000007
template<typename ty1,typename ty2>
inline int add(ty1 x, ty2 y) {
	if(y>=MOD)y%=MOD;
	if(x>=MOD)x%=MOD;
    x += y; return x < MOD ? x : x - MOD;
}
template<typename ty1,typename ty2>
inline void addto(ty1 &x, ty2 y) {
		  if(y>=MOD)y%=MOD;
		  if(x>=MOD)x%=MOD;
	      x += y; if (x >= MOD) x -= MOD;
}
template<typename ty1,typename ty2>
inline int sub(ty1 x, ty2 y) {
		if(y>=MOD)y%=MOD;
		 if(x>=MOD)x%=MOD;
        x -= y; return x < 0 ? x + MOD : x;
}
template<typename ty1,typename ty2>
inline void subto(ty1 &x, ty2 y) {
	if(y>=MOD)y%=MOD;
	if(x>=MOD)x%=MOD;
    x -= y; if (x < 0) x += MOD;
}
template<typename ty1,typename ty2>
inline int mul(ty1 x, ty2 y) {
        if(y>=MOD)y%=MOD;
		if(x>=MOD)x%=MOD;
        return 1ll * x * y % MOD;
}
template<typename ty1,typename ty2>
void multo(ty1 &x, ty2 y) {
        if(y>=MOD)y%=MOD;
		if(x>=MOD)x%=MOD;
        x=1ll * x * y % MOD;
}

#define MAX 100002

int n;
int h;
int w;

struct UF{
	vector<int> belong;
	vector<int> size;
	vector<int> ed;
	void resize(int n){
		belong.assign(n + 1, -1);
		size.assign(n + 1, 1);
		ed.assign(n+1,0);
	}
	inline int root(int b){
		if (belong[b] == -1){
			return b;
		}
		belong[b] = root(belong[b]);
		return belong[b];
	}
	void merge(int a, int b){
		a = root(a);
		b = root(b);
		if (a == b)return;
		belong[a] = b;
		size[b] += size[a];
		ed[b]+=ed[a];
	}
};

vector<pair<int,pair<int,int> > > v;

int main(){
	cin>>n>>h>>w;
	for(int i=0;i<n;i++){
		int r,c,a;
		scanf("%d%d%d",&r,&c,&a);
		r--;
		c--;
		c+=h;
		v.push_back(make_pair(a,make_pair(r,c)));
	}
	UF uf;
	uf.resize(h+w);
	
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	long long int ans=0;
	for(int i=0;i<v.size();i++){
		int a=v[i].second.first;
		int b=v[i].second.second;
		if(uf.root(a)!=uf.root(b)){
			int sz=uf.size[uf.root(a)]+uf.size[uf.root(b)];
			int eg=uf.ed[uf.root(a)]+uf.ed[uf.root(b)];
			eg++;
			if(sz>=eg){
				uf.merge(a,b);
				uf.ed[uf.root(a)]++;
				ans+=v[i].first;
			}
			continue;
		}
		int sz=uf.size[uf.root(a)];
		int eg=uf.ed[uf.root(a)];
		if(sz>=eg+1){
			uf.ed[uf.root(a)]++;
			ans+=v[i].first;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define endl "\n" 
using namespace std;
#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    cin.sync_with_stdio(0); cin.tie(0); 
    string s;
    cin>>s;
    if(s.size()<5){
        cout<<"No"<<endl;
        return 0;
    }
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
        return 0;
    } 
    cout<<"No"<<endl;
}


Measured memory_bytes: 3592
n,y = map(int,input().split())
 
y /= 1000
 
y10 = 0
y5 = 0
y1 = 0
 
i = 0
#i,j,k = 10000,5000,1000
while 1:
    y1 = i
    y5 = (10*n-y-9*y1)//5
    y10 = n-y5-y1
    if (10*n-y-9*y1)%5 == 0 and y10>=0 and y5>=0 and y1>=0:
        print(int(y10),int(y5),int(y1))
        break
    i += 1
    if i>n:
        print(-1,-1,-1)
        break

Measured memory_bytes: 3064
use proconio::input;

fn main() {
    input! {
        k: i64,
        a: i64,
        b: i64,
    }

    let mut ans = false;
    for i in 0..1000 {
        if a <= i * k && i * k <= b {
            ans = true;
        }
    }

    if ans {
        println!("OK");
    } else {
        println!("NG");
    }
}


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

map<string, int> mp;

int main() {
    int n;
    cin >> n;
    while(n--) {
        string s;
        cin >> s;
        ++mp[s];
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"];
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
 
using namespace std;
 
string s;
int dt[100010];
 
bool f(int x)
{
    if( x == s.size() ) return true;
    bool ret = false;
    if( x+5 <= s.size() )
    {
        if( s.substr(x, 5) == "dream" or s.substr(x, 5) == "erase" )
            ret |= f(x+5);
    }
    if( x+6 <= s.size() )
    {
        if( s.substr(x, 6) == "eraser" )
            ret |= f(x+6);
    }
    if( x+7 <= s.size() )
    {
        if( s.substr(x, 7) == "dreamer" )
            ret |= f(x+7);
    }
    return  ret;
}
 
int main()
{
    cin>>s;
    cout<<(f(0)?"YES":"NO")<<endl;
}

Measured memory_bytes: 2432
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ll n;
    cin>>n;
    lvec a(n);
    rep(i,n) cin>>a[i];
    ll sum=0;
    sum+=abs(a[0])+abs(a[n-1]);
    for(int i=0;i<n-1;i++) sum+=abs(a[i]-a[i+1]);
    lvec b(n),c(n);
    b[0]=abs(a[0])+abs(a[0]-a[1]);
    b[n-1]=abs(a[n-1])+abs(a[n-1]-a[n-2]);
    for(int i=1;i<n-1;i++) b[i]=abs(a[i]-a[i+1])+abs(a[i]-a[i-1]);
    c[0]=sum-b[0]+abs(a[1]);
    c[n-1]=sum-b[n-1]+abs(a[n-2]);
    for(int i=1;i<n-1;i++) c[i]=sum-b[i]+abs(a[i-1]-a[i+1]);
    rep(i,n) cout<<c[i]<<endl;
}

Measured memory_bytes: 3584
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(N),
    X is N * (N + 1) div 2,
    writeln(X).


Measured memory_bytes: 8124
#![allow(unused_imports, non_snake_case)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

#[fastout]
fn main() {
    input!{
        N:usize,
        A:[usize; N]
    }
    let mut ans = 0;
    let mut cur = 0;
    for &x in &A {
        if cur < x {
            cur = x;
        } else {
            ans += cur - x;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5680
////   SHAKALAKA BOOM BOOM ////

#include<bits/stdc++.h>

#define ll           long long
#define vi           vector<ll>
#define pb           push_back
#define all(a)       (a).begin(),(a).end()
#define F            first
#define S            second
#define sz(x)        (int)x.size()
#define hell         1000000007
#define endl         '\n'
#define fl(z,a,b)    for(ll z=a;z<b;z++)
#define ifl(i,a,b)   for(ll i=a;i<=b;i++)
#define dfl(i,a,b)   for(ll i=a;i>=b;i--)
#define speed        ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define debug1(x)    cerr << "at line " << __LINE__ << ": " << #x << " = " << (x) << endl
#define debug2(x)    cerr << #x << " = " << (x) << endl
using namespace std;
//=====================
//const int N=1e6;





void solve()
{
       ll n; cin>>n;
       vi a(n),b(n),c(n);
       fl(i,0,n)
       {
           cin>>a[i]>>b[i]>>c[i];
       }
       ll ans = INT_MIN;
       ll dp[n][3];

       dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];

       fl(i,1,n)
       {
           dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
           dp[i][1] = b[i] + max(dp[i-1][2],dp[i-1][0]);
           dp[i][2] = c[i] + max(dp[i-1][1],dp[i-1][0]);
       }


       cout<< max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << endl;
}



int main()
{
    ll TESTS=1;
    speed;
  //  cin>>TESTS;
    while(TESTS--) solve();
    return 0;
}


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  if(s[0] == 'S'){
    cout << "Cloudy\n";
  }else if(s[0] == 'C'){
    cout << "Rainy\n";
  }else{
    cout << "Sunny\n";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <bitset>
#include <list>
#include <cmath>
using namespace std;

int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	long long blue = n / (a + b) * a;
	if (n % (a + b) < a) {
		blue += n % (a + b);
	} else {
		blue += a;
	}
	cout << blue << endl;

	return 0;
}

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

class UnionFind {
public:
    vector<int> uni;
    UnionFind(int s);
    int root(int a);
    bool connect(int a, int b);
    bool isConnect(int a, int b);
    int size(int a);
};

inline UnionFind::UnionFind(int s) : uni(s, -1) {}

inline int UnionFind::root(int a) {
    if(uni[a] < 0) return a;
    else return uni[a] = root(uni[a]);
}

inline bool UnionFind::connect(int a, int b) {
    a = root(a);
    b = root(b);
    if(a == b) return false;
    if(uni[a] > uni[b]) swap(a, b);
    uni[a] = uni[a] + uni[b];
    uni[b] = a;
    return true;
}

inline bool UnionFind::isConnect(int a, int b) {
    return root(a) == root(b);
}

inline int UnionFind::size(int a) {
    return -uni[root(a)];
}

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf(N);
    vector<set<int>> friends(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.connect(a, b);
        friends[a].insert(b);
        friends[b].insert(a);
    }
    rep(i, K) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        if(uf.isConnect(c, d) && friends[c].count(d) == 0) {
            friends[c].insert(d);
            friends[d].insert(c);
        }
    }
    rep(i, N) cout << uf.size(i) - 1 - friends[i].size() << " ";
    cout << '\n';
    return 0;
}


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

int main()
{
	int n,l,ans;
	scanf("%d%d",&n,&l);
	ans=(n-1+l+l)*n/2;
	if(l<=0&&n+l-1>=0)
	{
		printf("%d",ans);
	}
	else if(n+l-1<0)
	{
		printf("%d",ans-(n+l-1));
	}
	else
	{
		printf("%d",ans-l);
	}
	return 0;
} 

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    vector<ll> kaisu(n,0);
    for(ll i=0;i<n;i++) cin>>a[i];

    ll p = 0;
    kaisu[0] = 1;
    ll r = 0;
    while(kaisu[p] < 2){
        p = a[p] - 1;
        kaisu[p]++;
        r++;
        if(r == k){
            cout<<p + 1<<endl;
            return 0;
        }
    }
    ll T = 0;
    vector<ll> c;
    while(kaisu[p] < 3){
        c.push_back(p);
        p = a[p] - 1;
        kaisu[p]++;
        T++;
    }
    for(int i=0;i<n;i++){
        if(kaisu[i] == 1){
            k -= r;
            break;
        }
    }
    ll ans = k % T;
    cout<<c[ans] + 1<<endl;
    //for(int i=0;i<c.size();i++) cout<<c[i]+1<<endl;
}

Measured memory_bytes: 7380
import sys
import math
import copy
import random
import itertools
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 21
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve(n=None, s1=None, s2=None):
    r, c, k = getList()
    value = [[0] * (c + 1) for i in range(r)]

    for i in range(k):
        cr, cc, cv = getZList()
        cv += 1
        value[cr][cc + 1] = cv

    dp = [[[0] * (c + 1) for i in range(r)] for j in range(4)]
    # print(value)
    # print("")
    for y in range(r):
        for x in range(1, c+1):
            curv = value[y][x]
            if y > 0:
                dp[0][y][x] = max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                )
                dp[1][y][x] = max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                )
            if curv == 0:
                for z in range(4):
                    dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1])

            else:
                dp[0][y][x] = max(dp[0][y][x], dp[0][y][x-1])
                dp[1][y][x] = max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv)
                dp[2][y][x] = max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv)
                dp[3][y][x] = max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv)

    # for dd in dp:
    #     print(dd)

    ans = 0
    for z in range(4):
        for y in range(r):
            for x in range(1, c+1):
                ans = max(ans, dp[z][y][x])

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()
    return


if __name__ == "__main__":
    # main()
    solve()



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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define sz(obj) ((int)(obj).size())
#define pf push_front
#define pb push_back

int main()
{
  int n, m;

  while(cin >> n >> m, n + m){
    bool used[510];
    memset(used, 0, sizeof(used));
    used[1] = true;
    vector<int> f[n + 1];
    int ans = 0;

    REP(i, m){
      int a, b;
      cin >> a >> b;
      if(a == 1){
        ans++;
        used[b] = true;
      }
      f[a].pb(b);
      f[b].pb(a);
    }
    REP(i, f[1].size()){
      REP(j, sz(f[f[1][i]])){
        if(!used[f[f[1][i]][j]]){
        ans++;
        used[f[f[1][i]][j]]=true;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

const string YES = "Yes";
const string NO = "No";

void solve(vector<vector<int>> A, int N, vector<int> b) {
  rep(i, 3) {
    rep(j, 3) {
      if (count(b.cbegin(), b.cend(), A[i][j]))
	A[i][j] = 0;
    }
  }

  bool succeeded = false;
  rep(i, 3) {
    if (accumulate(A[i].cbegin(), A[i].cend(), 0) == 0)
      succeeded = true;
    if ((A[0][i] + A[1][i] + A[2][i]) == 0)
      succeeded = true;
  }
  if ((A[0][0] + A[1][1] + A[2][2]) == 0)
    succeeded = true;
  if ((A[0][2] + A[1][1] + A[2][0]) == 0)
    succeeded = true;

  cout << (succeeded ? YES : NO) << endl;
}

int main(){
  // int 3E4
  // long 2E9
  // long long 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> A(3, vector<int>(3));
  for(int i = 0 ; i < 3 ; i++){
    for(int j = 0 ; j < 3 ; j++){
      cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  vector<int> b(N);
  for(int i = 0 ; i < N ; i++){
    cin >> b[i];
  }
  solve(move(A), N, move(b));
  return 0;
}


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

//#include <unordered_map>

//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define dd(n) cout<<fixed<<setprecision(n)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define repir(i,a,b) for(int i=(a)-1, i##_first=(b); i>=i##_first; --i)
#define repr(i,n) repir(i,n,0)
#define repir_(i,a,b) for(int i=(a), i##_first=(b); i>=i##_first; --i)
#define repr_(i,n) repir_(i,n,0)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
//template<typename T> T vpop(vector<T> *v) {
//	T res = v->back();
//	v->pop_back();
//	return res;
//}
//char vpop(string *v) {
//	char res = v->back();
//	v->pop_back();
//	return res;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define pi 3.14159265358979
#define co(x) cout<<x<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

//#define lint long long
typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<lint> lvec;
typedef vector<vector<int>> ivvec;
typedef pair<int, int> P;

const int
dx8[8] ={ 0,1,1,1,0,-1,-1,-1 },
dy8[8] ={ 1,1,0,-1,-1,-1,0,1 },
dx4[4] ={ 0,1,0,-1 },
dy4[4] ={ 1,0,-1,0 };

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

int main(){
	setc;

	lint a,b,c;cin>>a>>b;
	Yes(a%2&&b%2);
	gc();
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005;

int n;

struct aa
{
	int v,id;
}a[N];
bool cmp(const aa &x,const aa &y) {return x.v<y.v;}


int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i].v),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	
	int mid=1;
	while (a[mid+1].v*2<=a[n].v) mid++;
	if (mid==n-1||abs(a[mid].v*2-a[n].v)<abs(a[mid+1].v*2-a[n].v)) 
		printf("%d %d\n",a[n].v,a[mid].v);
	else printf("%d %d\n",a[n].v,a[mid+1].v);
	
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
int main() {
	string s;
	cin >> s;
	int n;
	n = s.size();
	string a, b;
	int count = 0,flag = 0;
	if (s.size() % 2 == 1) {
		a = s.substr(0, s.size() / 2);
		b = s.substr(s.size() / 2+1, s.size() / 2);
	}
	else {
		a = s.substr(0, s.size() / 2);
		b = s.substr(s.size() / 2 , s.size() / 2);
	}
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == b[a.size()-1 - i]) {
			flag++;
		}	
	}
	
	if (flag != a.size()) {
		cout << "No" << endl;
		return 0;
	}
	
	flag = 0;
	string x;
	x = s.substr(0, (s.size() - 1) / 2);
	
		if (x.size() % 2 == 1) {
			a = x.substr(0, x.size() / 2);
			b = x.substr(x.size() / 2 + 1, x.size() / 2);
		}
		else {
			a = x.substr(0, x.size() / 2);
			b = x.substr(x.size() / 2, x.size() / 2);
		}
		for (int i = 0; i < a.size(); i++) {
			if (a[i] == b[a.size()-1 - i]) {
				flag++;
			}
		}
		
		if (flag != a.size()) {
			cout << "No" << endl;
			return 0;
		}
		flag = 0;
	
	string y;
	y = s.substr((s.size() + 3) / 2-1, s.size() - (s.size() + 3) / 2 + 1);
	
	
		if (y.size() % 2 == 1) {
			a = y.substr(0, y.size() / 2);
			b = y.substr(y.size() / 2 + 1, y.size() / 2);
		}
		else {
			a = y.substr(0, y.size() / 2);
			b = y.substr(y.size() / 2, y.size() / 2);
		}
		for (int i = 0; i < a.size(); i++) {
			if (a[i] == b[a.size()-1 - i]) {
				flag++;
			}
		}
		
		if (flag != a.size()) {
			cout << "No" << endl;
			return 0;
		}
		
		cout << "Yes" << endl;
	
	return 0;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> nList = new ArrayList<Integer>();
		for (int i=0; i<N; i++) {
			nList.add(sc.nextInt());
		}

		int processingCount = divisionAllEven(nList, 0);

		System.out.println(processingCount);

	}
	private static int divisionAllEven(List<Integer> nList, int processingCount) {

		for (int i=0; i<nList.size(); i++) {
			Integer Ai = nList.get(i);
			if (Ai%2 == 0) {
				nList.set(i, (Ai/2));
			}
			else {
				return processingCount;
			}
		}
		processingCount++;
		return divisionAllEven(nList, processingCount);
	}

}

Measured memory_bytes: 23124