akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cmath>
#include<utility>
#include<algorithm>
#include<map>
using namespace std;
typedef long long int ll;
int main(void) {
	std::string str;
	cin >> str;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == ',')cout << " ";
		else cout << str[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
v = list(map(int,input().split()))

out=0
ki,gu=[], []
for i in range(n):
    if i%2==0:
        ki.append(v[i])
    else:
        gu.append(v[i])
# print('ki,gu:',ki,gu)

if len(set(v)) ==1:  #1種類
    out=len(v)//2

else:
    kiC, guC = collections.Counter(ki), collections.Counter(gu)
    kiI, guI = list(kiC.keys()), list(guC.keys())
    kiV, guV = list(kiC.values()), list(guC.values())
    if max(kiC, key=kiC.get) == max(guC, key=guC.get):
        kiV, guV = sorted(kiV), sorted(guV)
        out = min(len(ki) - kiV[-1] +  len(gu) - guV[-2], len(ki) - kiV[-2] + len(gu) - guV[-1] )
    # print(kiC,kiV, guC,guV
    else:
        out+=len(ki) - max(kiV)
        out+=len(gu) - max(guV)

print(out)


Measured memory_bytes: 111772
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define nmax_def 110
using namespace std;
typedef long long ll;


int main() {
	int i, j;
	int N;
	cin >> N;
	cout << ((N - 2) * 180) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#include <math.h> /* M_PI */
vector<ll> store;
vector<ll> bottle(5);
ll n;
ll dp(int u) //
{
    ll res = 0;
    if (u == 0)
    {
        res = (n - 1) / store[0] + 1;
        return res;
    }
    if (store[u] >= bottle[u - 1])
    {
        res += dp(u - 1) + 1;
    }
    else
    {
        res += u + (n - 1) / bottle[u] + 1;
    }
    return res;
}
int main()
{
    cin >> n;
    store.resize(5);
    ll min1 = 1000000000000008;
    rep(i, 5)
    {
        cin >> store[i];
        min1 = min(min1, store[i]);
        bottle[i] = min1;
    }

    ll count = 0;
    cout << dp(4); //4を履けるのにどれぐらい時間かかりますか。
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int r, c, a[1000][1000];
     
    cin >> r >> c;
    for(int i = 1; i <= r; i++){
        for(int j = 1; j <= c; j++){
            cin >> a[i][j];
            a[i][c+1] += a[i][j];
        }
    }
    for(int j = 1; j <= c+1; j++){
        for(int i = 1; i <= r; i++){
            a[r+1][j] += a[i][j];
        }
    }
     
    for(int i = 1; i <= r+1; i++){
        for(int j = 1; j <= c+1; j++){
            if(j == 1)  cout << a[i][j];
            else    cout << " " << a[i][j];
        }
        cout << endl;
    }
     
    return 0;
}


Measured memory_bytes: 3480
#include <bits/stdc++.h>
#define endl '\n'
#define pi 3.1415926535897932384626433832
#define ll long long
using namespace std;
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / __gcd(a, b); }
bool isPrime(int n) {if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;}

void lok(){

}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    int sum=0;
    while(a>=b){
        b*=2;
        sum++;
    }
    while(b>=c){
        c*=2;
        sum++;
    }
    if(sum>k){
        cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3648
n,m,q=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(q)]
ans=0

import itertools


for con in itertools.combinations_with_replacement(range(1,m+1),n):
    tmpAns = 0
    for lst in arr:
        if con[lst[1]-1] - con[lst[0]-1] == lst[2]:
            tmpAns += lst[3]
    ans = max(ans, tmpAns)

print(ans)

Measured memory_bytes: 9168
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
    int d,i,j,k;
    cin >>d;
    double a[1000]={},b[1000]={};
    for(i=0;i<d;i++) cin >>a[i];
    for(i=0;i<d;i++) cin >>b[i];
    double a1=0,a2=0,a3=0,ao=0;
    for(i=0;i<d;i++){
        a1+=fabs(a[i]-b[i]);
        a2+=fabs((a[i]-b[i])*(a[i]-b[i]));
        a3+=fabs((a[i]-b[i])*(a[i]-b[i])*(a[i]-b[i]));
        ao=max(ao,fabs(a[i]-b[i]));
    }
    printf("%.5f\n",a1);
    printf("%.5f\n",sqrt(a2));
    printf("%.5f\n",cbrt(a3));
    printf("%.5f\n",ao);
    return 0;
}


Measured memory_bytes: 3388
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N, X, T;
	cin >> N >> X >> T;
	int ans = (N / X) * T;
	if(N % X > 0){
		ans += T;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int W, H, N;
    cin >> W >> H >> N;
    vector<int> x(N);
    vector<int> y(N);
    vector<int> a(N);
    // a
    // 1 のときはx<xiが黒く
    // 2 のときはx>xiが黒く
    // 3 のときはy<yiが黒く
    // 4 のときはy>yiが黒く
    int left = 0;
    int right = W;
    int down = 0;
    int up = H;
    REP(i, N) {

        cin >> x[i] >> y[i] >> a[i];
        if(a[i] == 1) {
            left = max(x[i], left);
        }
        if(a[i] == 2) {
            right = min(x[i], right);
        }
        if(a[i] == 3) {
            down = max(down, y[i]);
        }
        if(a[i] == 4) {
            up = min(up, y[i]);
        }
    }
    if(right <= left) {
        cout << 0 << endl;
        return 0;
    }
    if(up <= down) {
        cout << 0 << endl;
        return 0;
    }
    cout << max((right - left) * (up - down), 0) << endl;
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int a, b, c; cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n,x[2020],m,a[2020],i,j=0,k=0,g=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&x[i]);
	}
	scanf("%d",&m);
	for(j=1;j<=m;j++){
		scanf("%d",&a[j]);
	}
	for(j=1;j<=m;j++){
		g=0;
		k=a[j];
		for(i=1;i<=n;i++){
			if(x[k]+1==x[i]){
				g++;
			}
		}
		if(g==0){
			x[k]=x[k]+1;
			if(x[k]>2019){
				x[k]=x[k]-1;
			}
		}
	}
	for(i=1;i<=n;i++){
	printf("%d\n",x[i]);
	}
		return 0;
}



Measured memory_bytes: 2024
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
 
int main() {
	cin >> a >> b >> c >> d;

	long long op1 = (long long) a * c;
	long long op2 = (long long) b * d;
	long long op3 = (long long) a * d;
	long long op4 = (long long) b * c;

	cout << max({op1, op2, op3, op4}) << '\n';

	return 0;
}


Measured memory_bytes: 3632
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan =new Scanner(System.in);
    		
    		String s=scan.next();
    		if (s.contains("a")&&s.contains("b")&&s.contains("c")) {
    			System.out.print("Yes");
    		}else {
    			System.out.print("No");
    		}
    		

;
    		
     
    }
    }
// end 
    

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

int main()
{
  string s;
  cin>>s;
  int a=-1,z=-1;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A' && a==-1){
      a=i;
    }
    if(s[s.size()-1-i]=='Z' && z==-1){
      z=(s.size()-i);
    }
  }
  cout<<z-a;
}

Measured memory_bytes: 640
// 2018/12/17 Tazoe

#include <iostream>
using namespace std;

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

	int X = ((N-1)/A+1)*B;
	int Y = ((N-1)/C+1)*D;

	if(X<=Y){
		cout << X << endl;
	}
	else{
		cout << Y << endl;
	}

	return 0;
}



Measured memory_bytes: 3124
import java.util.Scanner;

class Main {
    private static long maxKnapsack(int[] ws, long[] vs, int idx, int total, long[][] dp) {
        if (total <= 0 || idx == ws.length) return 0;

        if (dp[idx][total] != 0) {
            return dp[idx][total];
        }
        long loot1 = 0;
        if (ws[idx] <= total)
            loot1 = vs[idx] + maxKnapsack(ws, vs, idx + 1, total - ws[idx], dp);

        dp[idx][total] = Math.max(loot1, maxKnapsack(ws, vs, idx + 1, total, dp));
        return dp[idx][total];
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), w = sc.nextInt();
        int[] ws = new int[n];
        long[] vs = new long[n];

        long[][] dp = new long[n][w + 1];
        for (int i = 0; i < n; i++) {
            ws[i] = sc.nextInt();
            vs[i] = sc.nextInt();
        }
        System.out.println(maxKnapsack(ws, vs, 0, w, dp));
    }
}



Measured memory_bytes: 126548
n = gets.to_i
a = gets.split.map(&:to_i)

puts a.join(" ")

for i in 1..(n-1)
  v = a[i]
  j = i - 1
  while j >= 0 && a[j] > v
    a[j + 1] = a[j]
    j -= 1
  end
  a[j + 1] = v
  puts a.join(" ")
end

Measured memory_bytes: 6108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read() {
    ll x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=x*10+ch-'0';
    return x*f;
}
inline void chkmin( int &a,int b ) { if(a>b) a=b; }
inline void chkmax( int &a,int b ) { if(a<b) a=b; }
#define _ read()
int n,flag,a[105],b[105];
int main() {
	n=_;
	for( int i=1;i<=n;i++ ) a[i]=_;
	for( int i=1;i<=n;i++ ) {
		if(a[i]>i) flag=1;
		if(!b[a[i]]) b[a[i]]=a[i];
		else {
			for( int j=i-1;j>=a[i];j-- ) b[j+1]=b[j];
			b[a[i]]=a[i];
		}
	}
	if(flag) puts("-1");
	else for( int i=1;i<=n;i++ )cout<<b[i]<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>

using namespace std;

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

	char s[101], t[101];
	cin >> s >> t;

	int cnt = N;
	bool end = false;
	while (0 < cnt) {
		if (strcmp(s, t) == 0) {
			break;
		}
		for (int i = 0; i < cnt - 1; i++) {
			s[i] = s[i + 1];
		}
		cnt--;
		s[cnt] = t[cnt] = '\0';
	}
	cout << 2 * N - cnt << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,i,s=0;
cin>>a;
while(a>=500){
	a-=500;
	s+=1000; 
}
while(a>=5){
	a-=5;
	s+=5;
}
cout<<s;
return 0;
}

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



int main() {

	string s;
	cin >> s;

	string t;

	for (int i = 0; i < s.size(); i += 2) {
		t.push_back(s.at(i));
	}

	cout << t << endl;

	return 0;
}




Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	char c;int res=0,flag=1;
	for(;!isdigit(c);c=getchar())if(c=='-')flag=-1;
	for(;isdigit(c);c=getchar())res=res*10+c-'0';
	return res*flag;
}
set<int>s;
int n,a;
int main()
{
	n=read();
	while(n--)
	{
		a=read();
		if(s.find(a)!=s.end())
		{
			s.erase(a);
		}
		else
		{
			s.insert(a);
		}
	}
	printf("%d\n",s.size());
	return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  int64_t a=0;
  for(int i=0;i<(1<<(s.size()-1));i++){
    vector<bool> b(s.size()-1);
    int n=i;
    for(int d=0;d<s.size()-1;d++){
      b.at(d)=n%2;
      n/=2;
    }
    int64_t x=(int)(s.at(0)-'0');
    int64_t p=1;
    for(int d=1;d<s.size();d++){
      p=(b.at(d-1)?1:p*10);
      x+=(int64_t)(s.at(d)-'0')*p;
    }
    a+=x;
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
T, S, E, W, N, B = range(6)

class Dice:

    def __init__(self):
        self.state = list(range(6))

    def __eq__(self, dice):
        return self.state == dice.state

    def __gt__(self, dice):
        return self.state > dice.state

    def copy(self):
        dice = Dice()
        dice.state = [x for x in self.state]
        return dice

    def _turn(self, turn):
        k = self.state[turn[-1]]
        for i in range(4):
            self.state[turn[i]], k = k, self.state[turn[i]]

    def go_south(self):
        turn = [T, S, B, N]
        self._turn(turn)

    def go_north(self):
        turn = [N, B, S, T]
        self._turn(turn)

    def go_east(self):
        turn = [T, E, B, W]
        self._turn(turn)

    def go_west(self):
        turn = [T, W, B, E]
        self._turn(turn)

    def north(self):
        return self.state[N]

    def south(self):
        return self.state[S]

    def east(self):
        return self.state[E]

    def west(self):
        return self.state[W]

    def bottom(self):
        return self.state[B]

    def top(self):
        return self.state[T]

    def goto(self, n):
        func = [self.go_west, self.go_north, self.go_east, self.go_south]
        func[n]()

    def show(self):
        d = list("TSEWNB")
        for x, s in zip(d, self.state):
            print(x + " : {}".format(s))


import heapq

INF = 10**9
if __name__ == "__main__":
    dx = [-1, 0, 1, 0]
    dy = [0, -1, 0, 1]
    while True:
        dp = [[[[INF for _ in range(6)] for i in range(6)] for j in range(10)] for k in range(10)]
        h, w = map(int, input().split())
        if h == 0:
            break

        cost = [list(map(int, input().split())) for _ in range(h)]
        sy, sx = map(int, input().split())
        gy, gx = map(int, input().split())
        q = []
        dice = Dice()
        heapq.heappush(q, [0, sx, sy, dice])
        dp[sy][sx][dice.bottom()][dice.east()]

        ans = INF+1
        while q:
            c, x, y, dice = heapq.heappop(q)
            if x == gx and y == gy:
                ans = min(ans, c)
                continue
            if c >= ans:
                continue
            else:
                for i in range(4):
                    ddx, ddy = dx[i], dy[i]
                    if x + ddx >= w or x + ddx < 0 or y + ddy >= h or y + ddy < 0:
                        continue
                    else:
                        d = dice.copy()
                        d.goto(i)

                        new_cost = c + (d.bottom()+1)*cost[y+ddy][x+ddx]
                        if dp[y+ddy][x+ddx][d.bottom()][d.east()] > new_cost:
                            dp[y+ddy][x+ddx][d.bottom()][d.east()] = new_cost
                            heapq.heappush(q, [new_cost, x+ddx, y+ddy, d])
        print(ans)



Measured memory_bytes: 5948
#include <iostream>

using namespace std;

const int money[] = {0, 6000, 4000, 3000, 2000};

int main()
{
    int t, n;

    for (int i = 0; i < 4; i++) {
        cin >> t >> n;
        cout << money[t] * n << endl;
    }

    return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int N;
	cin >> N;
	vec(A);
	vecl(B);
	fx(N+1) {
		vecp(A);
	}

	if (A[0]!=0) {
		if (N!=0||A[0]!=1) {
			ce(-1);
			return 0;
		}

	}

	B.push_back(1);
	fx(N-1) {

		if (B[x]>=((double)LLONG_MAX+A[x+1])/2) {
			pb(B, LLONG_MAX);
		}
		else {
			pb(B, B[x] * 2 - A[x + 1]);
		}


		if (B[x+1]<0) {
			ce(-1);
			return 0;
		}
	}
	ll ans = A[N];
	ll sum = A[N];

	for (int i = N-1; i >= 0;i--) {

		if ((sum +1)/ 2 > B[i] ) {
			ce(-1);
			return 0;
		}
		sum = min(B[i], sum);
		sum += A[i];
		ans += sum;
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 4684
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, m;
  cin >> n >> m;
  ll a = 0;
  string s = "kogakubu10gokan";
  bool flag = true;
  rep(i, n) {
    cin >> a;
    if (a > m) {
      cout << s << endl;
      flag = false;
      break;
    } else {
      cin >> s;
    }
  }
  if (flag) {
    cout << s << endl;
  }
}


Measured memory_bytes: 3216
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
ans = 0
a_2_list = a_list * 2
sorted_a = sorted(a_list, reverse=True)

for i in range(n):
  for j in range(i+1, n):
    if a_list[i] > a_list[j]:
      ans += k

for i in range(n):
  indexes = [j for j, x in enumerate(sorted_a) if x == a_list[i]]
  ans += (n-indexes[-1]-1) * k*(k-1)//2%(10**9+7)

print(ans%(10**9+7))

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>

using namespace std;

struct Item {
    friend istream& operator>>(istream& inp, Item& item)
    {
        return inp >> item.w >> item.v;
    }
    int w, v;
};

template<typename T>
struct Matrix {
    Matrix(int rows, int columns) : _rows(rows), _columns(columns), a(rows * columns) {}
    T* operator[](int row) { return row * _columns + a.data(); }
    int _rows, _columns;
    vector<T> a;
};

int main()
{
    int n, maxw;
    cin >> n >> maxw;
    int maxv = n * 1e3;
    vector<Item> items(n);
    for (auto& item : items) cin >> item;
    Matrix<long long> dp(n, maxv + 1);
    int res = 0;

    auto f = [&](int i, int j) -> long long {
        if (j == 0) return 0;
        if (i < 0 || j < 0) return numeric_limits<int>::max();
        return dp[i][j];
    };

    for (int i = 0; i < n; ++i) {
        int w = items[i].w, v = items[i].v;
        for (int j = 0; j <= maxv; ++j) {
            dp[i][j] = min(f(i - 1, j), (f(i - 1, j - v)) + w);

            if (dp[i][j] <= maxw)
                res = max(res, j);
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 78336
a=gets.strip.split.map(&:to_i)
n=[]
n << (a[0]-a[1]).abs+(a[1]-a[2]).abs
n << (a[0]-a[2]).abs+(a[2]-a[1]).abs
n << (a[1]-a[0]).abs+(a[0]-a[2]).abs
n << (a[1]-a[2]).abs+(a[2]-a[0]).abs
n << (a[2]-a[0]).abs+(a[0]-a[1]).abs
n << (a[2]-a[1]).abs+(a[1]-a[0]).abs
puts n.min

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define int long long

int N, M;

signed main()
{
    cin >> N >> M;
    int ans = 1;
    while(N * 2 <= M){
        N *= 2;
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
T = list(map(int, input().split()))
M = int(input())
for i in range(M):
    P, X = map(int, input().split())
    ans = 0
    for j in range(N):
        if j == P-1:
            ans += X
        else:
            ans += T[j]
    print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>

typedef long long int lli;
lli num[60][8000];

int main(void) {
    int n,a;
    scanf("%d%d",&n,&a);

    num[0][0] = 1;

    for(int i=0; i<n; i++) {
        lli x;
        scanf("%lld",&x);
        for(int c=55; c>=0; c--)
            for(int s=0; s<3000; s++)
                num[c+1][s+x] += num[c][s];
    }

    lli res=0;
    for(int c=1; c<55; c++)
        res += num[c][c*a];
    printf("%lld\n",res);

}

Measured memory_bytes: 1664
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 = b / a;
        if(c < d) System.out.println(c);
		else System.out.println(d);
	}
}

Measured memory_bytes: 21972
n = int(input())
list_A = list(map(int, input().split()))
ans = 0
a = 0
while True:
    cnt = 0
    for i in range(len(list_A)):
        if list_A[i] % 2 == 0:
            list_A[i] //= 2
            cnt += 1
    if cnt == len(list_A):
        ans += 1
    else:
        break

print(ans)

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

int main(){
  int N;
  cin >> N;
  long long A;
  long long m=1000000000;
  long long c=0;
  long long s=0;
  for (int i;i<N;i++){
    cin >> A;
    m=min(abs(A),m);
    c=A<0?1-c:c;
    s+=abs(A);
  }
  cout << (c==1?s-m*2:s) << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n,l;cin >> n >> l;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  sort(s.begin(),s.end());
  cout << accumulate(s.begin(),s.end(),string()) << endl;
}


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

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

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);

  ll now = 1;
  ll t = 1000000000000000000LL;
  Bint total = 1;
  rep(i, n) {
    cin >> a[i];

  }
  sort(a.begin(), a.end());
  rep(i, n) {
    total *= a[i];
    if (total > t) {
      cout << -1 << endl;
      return 0;
    }
  }

  if (total > t) {
    cout << -1 << endl;
  } else {
    cout << total << endl;
  }


}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll x, y;
    cin >> x >> y;

    ll t = 100000, a = max(0LL, 4 - x), b = max(0LL, 4 - y);
    ll res = t * (a + b);
    if (x == 1 && y == 1) res += 4 * t;
    cout << res << endl;
    return 0;
}

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

using namespace std;

const int maxn = 2005;

int n;
string s;
vector<int> g[maxn];

int count[maxn];
int low[maxn], high[maxn];

void dfs_solve(int v, int p) {
  count[v] = (s[v] == '1');

  if(p != -1 && g[v].size() == 1) {
    low[v] = high[v] = 0;
    return;
  }

  vector<int> ts;

  int least = 0, odd = 0;

  high[v] = 0;
  for(int s : g[v]) if(s != p) {
    dfs_solve(s, v);
    count[v] += count[s];
    int a = low[s] + count[s], b = high[s] + count[s];
    high[v] += b;
    least = max(least, a);
    odd ^= (a & 1);
    ts.push_back(b);
  }


  sort(ts.begin(), ts.end());

  if(ts.size() == 1) {
    low[v] = least;
    return;
  }

  low[v] = 1e9;

  int leastcost = 0;
  for(int x : ts) {
    int y = min(x, least);
    if(x > least && x % 2 != least % 2) y--;
    leastcost += y;
  }



  int sum_smaller = 0, countodd = 0, counteven = 0;
  for(int x : ts) {
    if(x % 2 == 0) ++counteven;
    else ++countodd;
  }


  if(least * 2 <= leastcost) low[v] = min(low[v], odd);
  else low[v] = min(low[v], least * 2 - leastcost);

  for(int i = 0; i < ts.size(); ++i) {
    sum_smaller += ts[i];
    if(ts[i] % 2) --countodd;
    else --counteven;
    if(ts[i] < least || (i + 1 < ts.size() && ts[i + 1] == ts[i])) continue;

    int sum = sum_smaller + (ts[i] - 1) * (countodd + counteven);
    if(ts[i] % 2) sum += countodd;
    else sum += counteven;

    if(ts[i] * 2 <= sum) low[v] = min(low[v], odd);
    else low[v] = min(low[v], ts[i] * 2 - sum);
  }


  if(low[v] % 2 != high[v] % 2) {
    cout << v << endl;
  }

//  assert(low[v] % 2 == high[v] % 2);
//  assert(low[v] <= high[v]);
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);

  cin >> n >> s;
  for(int i = 0; i + 1 < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[--u].emplace_back(--v);
    g[v].emplace_back(u);
  }

  int ans = 1e9 + 7;
  for(int root = 0; root < n; ++root) {
    dfs_solve(root, -1);

    if(low[root] == 0) {

      ans = min(ans, high[root] / 2);
    }
  }

  cout << (ans > 1e9 ? -1 : ans) << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fastin ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
int n,a[3010],ans;
int main(){
	cin>>n;
	rep(i,1,n){
		cin>>a[i];
		ans+=(a[i]-1);
	}
	printf("%d\n",ans); 
	return 0;
}


Measured memory_bytes: 3732
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        mut aa: [usize; n]
    };
    aa.sort();
    let max = aa[n - 1];
    let mut dp = vec![true; max + 1];
    let mut dup = 0;
    let mut i = 0;
    while i < aa.len() {
        let a = aa[i];
        if !dp[a] {
            i += 1;
            continue;
        }
        if i > 0 {
            let left = i - 1;
            if aa[left] == aa[i] {
                while aa[left] == aa[i] {
                    i += 1;
                    if i >= aa.len() {
                        break;
                    }
                }
                dup += i - left;
                continue;
            }
        }
        let mut na = 2 * a;
        while na <= max {
            dp[na] = false;
            na += a;
        }
        i += 1;
    }
    // dbg!(aa.iter().filter(|&&a| dp[a]).collect::<Vec<_>>());
    println!(
        "{}",
        aa.iter().filter(|&&a| dp[a]).collect::<Vec<_>>().len() - dup
    )
}


Measured memory_bytes: 8180
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int cnt=0;
  while(cin>>str){
    int flag=1;
    for(int i=0;i<str.size()/2;i++){
      if(str[i]!=str[str.size()-i-1]){
	flag=0;
	break;
      }
    }
    if(flag)
      cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 2988
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
ll dp[111][111][5555];
int main() {
    int n,a;
    cin>>n>>a;
    vector<int> x(n);
    rep(i,n){
        cin>>x[i];
    }
    dp[0][0][0]=1;
//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//         for(int k=0;k<=5000;k++){
//             dp[i+1][j][k]+=dp[i][j][k];
//             if(k>=x[i]){
//                 dp[i+1][j+1][k]+=dp[i][j][k-x[i]];
//             }
//         }
//        }
//    }
sort(x.begin(),x.end());
ll c=max(x[n-1],a);

    for(int i=0;i<n;i++){
        for(int j=0;j<i+1;j++){
            for(int k=0;k<=c*50;k++){
                dp[i+1][j][k]+=dp[i][j][k];
                if(k>=x[i]){
                    dp[i+1][j+1][k]+=dp[i][j][k-x[i]];
                }
            }
        }
    }




    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 157952
#include <bits/stdc++.h>
using namespace std;
int mismatch(string a, string b){
    int res = 0;
    for(int i = 0; i < a.length(); i++){
        if(a[i] != b[i]) res++;
    }
    return res;
}
int main(){
    string a,b;
    cin >> a >> b;
    int i = 0;
    int res = 10000;
    while(i < a.length()){
        string tmp = a.substr(i,b.length());
        if(tmp.length() < b.length()) break;
        res = min(res,mismatch(tmp,b));
        i++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3572
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	o := map[int]int{}
	n := func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }()
	for i := 0; i < n; i++ {
		o[func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }()]++
	}
	fmt.Println(len(o))
}

Measured memory_bytes: 640
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int mod = 1e9 + 7;

int calculate(vector<int> & a, int k) { 
    int n = a.size();
    int prod = 1; 
    
    if(a[n - 1] == 0 && (k & 1)) 
        return 0; 
  
    if(a[n - 1] <= 0 && (k & 1)) { 
        for(int i = n - 1; i >= n - k; i--) 
            prod = (prod * (a[i] % mod + mod)) % mod; 
        return prod; 
    } 

    int i = 0, j = n - 1; 
  
    if (k & 1) { 
        prod = (prod * (a[j] % mod + mod) % mod); 
        j--; 
        k--; 
    } 

    k >>= 1; 
    while(k--) { 
        int left = a[i] * a[i + 1]; 
        int right = a[j] * a[j - 1]; 
  
        if (left > right) { 
            prod = (prod * (left % mod + mod)) % mod; 
            i += 2; 
        } 
        else { 
            prod = (prod * (right % mod + mod)) % mod; 
            j -= 2; 
        } 
    } 
  
    return prod; 
} 

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        for(auto && x : a)
            cin >> x;

        sort(a.begin(), a.end());

        int ans = calculate(a, k);
        cout << ans << '\n';

        
    }
    
    return 0;
}



Measured memory_bytes: 4788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
const int N = 2002;
ll dp[N][N][2];
int main()
{
       ll s;
       cin>>s;
       memset(dp,0,sizeof dp);
       //fri(i,0,N)dp[i][0][0] = 1;
       fri(i,3,s+1){
              dp[i][1][0] = 1;
       }
       fri(j,2,s+1){
              fri(i,1,s+1){
                     dp[i][j-1][1] = dp[i][j-1][0]+dp[i-1][j-1][1];
                     dp[i][j-1][1] %= mod;
              }
              fri(i,3,s+1){
                     dp[i][j][0] = dp[i-3][j-1][1];
              }
       }
       //cout<<dp[s][3][0]<<endl;
       ll ans = 0;
       fri(j,1,s+1){
              ans += dp[s][j][0];
              ans %= mod;
       }
       cout<<ans<<endl;
}


Measured memory_bytes: 66212
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll mod=1000000007ll;

const ll hmax=1000000000;
const ll wmax=1000000000;

unordered_map<string,ll> mp;

int main(){
    ll h,w,n,a,b;
    cin>>h>>w>>n;
    string s;
    for(ll i=0;i<n;i++){
        cin>>a>>b;
        for(ll j=-1;j<=1;j++){
            for(ll k=-1;k<=1;k++){
                if(2<=a+j&&a+j<=h-1&&2<=b+k&&b+k<=w-1){
                    s=to_string(a+j)+" "+to_string(b+k);
                    mp[s]++;
                }
            }
        }
    }
    ll ct[10],tmp;
    ll su=0;
    for(ll i=1;i<=9;i++){
        tmp=0;
        for(auto itr = mp.begin(); itr != mp.end(); ++itr){
            //cout<<itr->first<<","<<mp[itr->first]<<endl;
            if(itr->second==i){
                tmp++;
            }
        }
        su+=tmp;
        ct[i]=tmp;
    }
    ct[0]=(h-2)*(w-2)-su;

    for(ll i=0;i<10;i++){
        cout<<ct[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 121104
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int K = sc.nextInt();
	long ans = K;
	for(int i = 1; i<N;i++) {
	    ans*=(K-1);
	}
	System.out.println(ans);
    }
}

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

int main(void){
    char n[200001];
    scanf("%s", n);
    
    int amari=0;
    
    int ni=0;
    while(n[ni]!='\0'){
        amari+='0'-n[ni];
        //printf("%d %c\n",ni,n[ni]);
        amari%=9;
        ni++;
    }
    
    
    if(amari==0){
    printf("Yes");
    }else{
    printf("No");
    }
}


Measured memory_bytes: 1868
#include <stdio.h>

#define abs(a) ((a > 0) ? (a) : (-(a)))

int main () {
    int N;
    int L;
    scanf("%d", &N);
    scanf("%d", &L);
    int sum = N * (L - 1) + ((N + 1) * N) / 2;
    //printf("sum: %d\n", sum);
    int min_abs = 1000000000;
    int min = 0;
    for (int i = 1; i <= N; i++) {
        if (abs(L + i - 1) < min_abs) {
            min_abs = abs(L + i - 1);
            min = L + i - 1;
            //printf("min_abs: %d\n", min_abs);
        }
    }

    printf("%d\n", sum - min);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

// fatorial.cpp depend on this.
#ifndef MOD_INT
#define MOD_INT
template<int mod>
struct ModInt{
	private:
		int x;

	public:
		ModInt() : x(0){}
		ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}
	
		ModInt &operator+=(const ModInt &p){
			if((x += p.x) >= mod) x -= mod;
			return *this;
		}
		ModInt &operator-=(const ModInt &p){
			if((x += mod - p.x) >= mod) x -= mod;
			return *this;
		}
		ModInt &operator*=(const ModInt &p){
			x = (int) (1LL * x * p.x % mod);
			return *this;
		}
		ModInt &operator/=(const ModInt &p){
			*this *= p.inverse();
			return *this;
		}
	
		ModInt operator-() const {return ModInt(-x);}
		ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}
		ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}
		ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}
		ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}
		bool operator==(const ModInt &p) const {return x == p.x;}
		bool operator!=(const ModInt &p) const {return x != p.x;}
		bool operator<(const ModInt &p) const {return x < p.x;}
	
		template<typename T>
		operator T() const {return (T)x;}
	
		ModInt inverse() const {
			int a = x, b = mod, u = 1, v = 0, t;
			while(b > 0) {
				t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return ModInt(u);
		}
	
		ModInt pow(int64_t n) const {
			ModInt ret(1), mul(x);
			while(n > 0) {
				if(n & 1) ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}
	
		friend ostream &operator<<(ostream &os, const ModInt &p){
			return os << p.x;
		}
	
		friend istream &operator>>(istream &is, ModInt &a){
			int64_t t;
			is >> t;
			a = ModInt< mod >(t);
			return (is);
		}
	
		static int get_mod(){return mod;}
};

using mint = ModInt<MOD>;
#endif


int main(void){
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for(int i = 0; i < N; i++) cin >> A[i];

	mint res = 0;
	for(int i = 0; i < N; i++){
		for(int j = i + 1; j < N; j++){
			if(A[i] > A[j]) res += K;
		}

		mint num = 0;
		for(int j = 0; j < N; j++){
			if(A[i] > A[j]) num += 1;
		}

		mint mK = (ll) (K) * (K-1) / 2;
		res += (num * mK);
	}

	cout << res << '\n';

	return 0;
}

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

#define rep(i,n) for(int i = 0; i<n;i++)
using namespace std;
int main(){
	
	int n;
	int list;
	while(cin >> n >> list,n+list)
	{
	//cout << n << list << endl;
	typedef pair<int, int>F;
	vector<F> v(100001);
	vector<int>x(n+1,0);
	bool array[100001];
	bool dcheck[100001];
	int answer = 0;
	rep(i,n+1)
		array[i] = false;
	rep(i,n+1)
		dcheck[i] = true;
	rep(i,list)
		cin >> v[i].first >> v[i].second;
	rep(i,list)
		{
			if(v[i].first == 1)
			{
				array[v[i].second] = true;
				//cout << v[i].second << endl;
				answer++;
			}
		}
	//cout << "------v[i].second-------- " << endl;
	rep(i,list)
		{
			if((array[v[i].first ]== true&&v[i].first != 1&& array[v[i].second ]== false&&dcheck[v[i].second] == true) || (array[v[i].second] == true&&array[v[i].first] == false && v[i].first != 1 && dcheck[v[i].first] == true))
				{
				answer++;
				//cout <<v[i].first << " and "<< v[i].second << endl;
				if(array[v[i].first])
					dcheck[v[i].second] =false;
				else 
					dcheck[v[i].first] = false; 
		}
	}
	cout << answer << endl;
	//cout <<"x is"; rep(i,n) cout << " " << x[i];
	//cout <<"v is"; rep(i,n) cout << " " << 
	}
    return 0;
}

Measured memory_bytes: 1984
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;
  ll ans = 0;
  REP(i, S.length() - 1) {
    if (S[i] != S[i + 1]) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;

class Program
{
    public static void Main(string[] args)
    {
        Program pg = new Program();
        pg.Exe();
    }

    public void Exe()
    {
        int[] i_ary = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int num = i_ary[0];
        int buy = i_ary[1];

        List<int> item_list = new List<int>(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse));
        item_list.Sort((a, b) => a - b);

        int sum = 0;
        for(int i = 0; i < buy; i++)
        {
            sum += item_list[i];
        }

        Console.WriteLine(sum);
    }
}



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

#define MAX_N 500000
string A, B;
int n, c, d, e, sum;
int a[MAX_N], b[MAX_N], ab[MAX_N];
char f[MAX_N];

int main() {
	cin >> n;
	cin >> A >> B;
	d = max(A.size(), B.size()) + 1;
	for (int i = 0; i < A.size(); i++)
	{
		if (A[i] == '1') { c = 1; }
		if (A[i] == '0') { c = 0; }
		a[A.size() - 1 - i] = c;
	}
	for (int i = 0; i < B.size(); i++)
	{
		if (B[i] == '1') { c = 1; }
		if (B[i] == '0') { c = 0; }
		b[B.size() - 1 - i] = c;
	}
	for (int i = 0; i < d; i++)
	{
		ab[i] += a[i] + b[i];
		if (ab[i] >= 2) {
			ab[i] -= 2; ab[i + 1]++;
		}
	}
	for (int i = 0; i < n; i++)
	{
		cin >> f[i];
		if (f[i] == 'A') {
			cin >> e;
			if (a[e] == 1)
			{
				a[e] = 0;
				ab[e]--;
				if (ab[e] < 0)
				{
					while (e < d)
					{
						ab[e + 1]--;
						ab[e] += 2;
						if (ab[e + 1] == 0) { break; }
						e++;
					}
				}
			}
			else
			{
				a[e] = 1;
				ab[e]++;
				if (ab[e] >= 2)
				{
					while (e < d)
					{
						ab[e + 1]++;
						ab[e] -= 2;
						if (ab[e + 1] == 1) { break; }
						e++;
					}
				}
			}
		}
		if (f[i] == 'B')
		{
			cin >> e;
			if (b[e] == 1)
			{
				b[e] = 0;
				ab[e]--;
				if (ab[e] < 0)
				{
					while (e < d)
					{
						ab[e + 1]--;
						ab[e] += 2;
						if (ab[e + 1] == 0) { break; }
						e++;
					}
				}
			}
			else
			{
				b[e] = 1;
				ab[e]++;
				if (ab[e] >= 2)
				{
					while (e < d)
					{
						ab[e + 1]++;
						ab[e] -= 2;
						if (ab[e + 1] == 1) { break; }
						e++;
					}
				}
			}
		}
		if (f[i] == 'Q') {
			if (i >= 1) {
				if (f[i - 1] == 'Q') {
					cout << sum << endl; goto H;
				}
			}
			sum = 0;
			for (int j = d; j >= 0; j--)
			{
				if (a[j] != ab[j])
				{
					sum += j;
					break;
				}
				if (a[j] == 1) {
					sum++;
				}
			}
			cout << sum << endl;
		H:;
		}
	}
	return 0;
}

Measured memory_bytes: 7396
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

ll X,K,D;
int main() {
  cin >> X>> K >>D;
  ll move = abs(X/D);
  chmin(move, K);
  K -= move;
  if (K == 0) {
    ll ans = abs(X) - D*move;
    printf("%lld\n", ans);
    return 0;
  }
  ll now = abs(X) - D*move;
  if (K&1)  {
    now = abs(now - D);
  }
  printf("%lld\n", now);
  return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n;cin>>n;
  vector<vector<pair<int,int>> > a(n);
  rep(i,n){
    int tmp;cin>>tmp;
    rep(j,tmp){
      int f,s;cin>>f>>s;
      a[i].pb(mp(f,s));
    }
  }
  int ans = 0;
  rep(bit,1<<n){
    bitset<15> bs(bit);
    vector<int> b(n,-1);
    int cnt = 0;
    rep(i,n){
      if(bs[i]){
        cnt++;
        b[i] = 1;
      }
    }
    bool ok = true;
    rep(i,n){
      if(!bs[i])continue;
      rep(j,a[i].size()){
        if(bs[a[i][j].fi-1] != a[i][j].se){
          ok = false;
          break;
        }
      }
    }

    if(ok){
      chmax(ans,cnt);
      // test(bs);
    }
  }
  print(ans);
  return 0;
}



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

using namespace std;

int main(int argc, char const* argv[])
{
	string input_string;
	string answer;

	while( cin >> input_string ){
		answer.clear();
		for( unsigned int i = 0;i < input_string.size();i++ ){
			if( input_string[i] != '@' ) answer.append( 1, input_string[i] );
			else {
				answer.append( input_string[i + 1] - '0', input_string[i + 2] );
				i += 2;
			}
		}
		cout << answer << endl;
	}
	return 0;
}

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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	int n; cin >> n;
	ll t[105];
	rep(i, 0, n) cin >> t[i];
	ll ans = t[0];
	rep(i, 1, n){
		ans = LCM(ans, t[i]);

	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632