akhauriyash/Code-Regression huggingface dataset:
/*  ex9_1
    Graku   */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100

typedef struct stack {
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

void initialize_stack(stack *stk);
char pop(stack *stk);
void push(stack *stk, char c);
void print_stack(stack *stk);

int main(void) {
    stack stk;
    initialize_stack(&stk);

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

    for (int i = 0; i < (int)strlen(s); ++i) {
        if (s[i] == 'B') { //delete a element
            if (stk.count > 0) { //stk has elements
                pop(&stk);
            }
        }
        else {
            push(&stk, s[i]); //add a element to stk
        }
    }

    print_stack(&stk);

    return 0;
}

void initialize_stack(stack *stk) {
    stk->size = SIZE;
    stk->count = 0;
    stk->top = stk->data; //stk.data[0] is always empty
}

char pop(stack *stk) {
    char del;
    if (stk->count <= 0) { //stk has no elements
        printf("Error: stack underflow.\n");
        exit(1);
    }
    del = *(stk->top);
    if (stk->count > 1) {
        stk->top--;
    }
    stk->count--;
    return del;
}

void push(stack *stk, char c) {
    if (stk->count >= stk->size) { //stk has biggest elements it can have
        printf("Error: stack overflow.\n");
        exit(1);
    }
    if (stk->count >= 1) {
        stk->top++;
    }
    *(stk->top) = c;
    stk->count++;
}

void print_stack(stack *stk) {
    char *p = stk->data;
    for (int i = 0; i < stk->count; ++i) {
        printf("%c", p[i]);
    }
    printf("\n");
}

Measured memory_bytes: 1608
from operator import itemgetter
import sys
input = sys.stdin.readline

n = int(input())
time = []
flag = True
now = 0

for i in range(n):
    a, b = map(int, input().split())
    time.append([a, b])

time = sorted(time, key = lambda x: x[1])

for i in range(n):
    now += time[i][0]
    if now <= time[i][1]:
        pass
    else:
        flag = False

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 39640
n, a, b = map(int, input().split())
st = str(input())
bor = a + b

ans = []

pa = 1
fore = 1

for i in st:
    if i == 'a':
        if pa <= bor:
            print('Yes')
            pa += 1
        else:
            print('No')
    elif i == 'b':
        if pa <= bor:
            if fore <= b:
                print('Yes')
                pa += 1
                fore +=1
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')



Measured memory_bytes: 4016
n, a, b, c, d = map(int, input().split())
s = input()
if c < d:
    flg = False
    for i in range(a - 1, c):
        if s[i] == "#":
            if flg:
                print("No")
                exit()
            flg = True
        else:
            flg = False
    for i in range(b - 1, d):
        if s[i] == "#":
            if flg:
                print("No")
                exit()
            flg = True
        else:
            flg = False
    print("Yes")

else:
    flg = False
    for i in range(a - 1, c):
        if s[i] == "#":
            if flg:
                print("No")
                exit()
            flg = True
        else:
            flg = False
    flg = 0
    for i in range(b - 2, d + 1):
        if s[i] == ".":
            if flg == 2:
                print("Yes")
                exit()
            flg += 1
        else:
            flg = 0
    print("No")


Measured memory_bytes: 3572
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

class Main {

  public static void main(String[] args) {
    final FastScanner scanner = new FastScanner();
    final PrintWriter writer = new PrintWriter(System.out);
    final long a = scanner.nextLong();
    final long b = scanner.nextLong();
    final long k = scanner.nextLong();
    final String result;
    if (a + b > k) {
      if (a >= k) {
        result = a - k + " " + b;
      } else {
        result = "0 " + (b - (k - a));
      }
    } else {
      result = "0 0";
    }
    writer.println(result);
    writer.flush();
    writer.close();
  }

  // FastScanner --
  static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    public FastScanner() {
    }

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = in.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte())
        return buffer[ptr++];
      else
        return -1;
    }

    private boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr]))
        ptr++;
      return hasNextByte();
    }

    public String next() {
      if (!hasNext())
        throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext())
        throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
        throw new NumberFormatException();
      return (int) nl;
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }
}

Measured memory_bytes: 22868
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int mod_pow(int a,int n,int m) {
    int ret=1;
    while(n) {
        if(n&1) {
            ret*=a;
            ret%=m;
        }
        a*=a;
        a%=m;
        n>>=1;
    }

    return ret;
}

int N,M,A,B,C,T;
int S[60];

int get_S(int i) {
    if(i<0||N<=i) return 0;
    return S[i];
}

vector<vector<int> > mul(vector<vector<int> > &A, vector<vector<int> > &B) {
    vector<vector<int> > C(A.size(),vector<int>(B[0].size()));
    
    rep(i,A.size()) rep(k,B.size()) rep(j,B[k].size()) {
        C[i][j]=(C[i][j]+A[i][k]*B[k][j])%M;
    }

    return C;
}
vector<vector<int> > mod_pow(vector<vector<int> > mat,int n,int m) {
    vector<vector<int> > ret(mat.size(),vector<int>(mat.size()));
    rep(i,ret.size()) ret[i][i]=1;
    while(n) {
        if(n&1) ret=mul(ret,mat);
        mat=mul(mat,mat);
        n>>=1;
    }

    return ret;
}

void solve() {
    vector<vector<int> > mat(N,vector<int>(N));
    rep(i,N) {
        int a=i-1;
        int b=i;
        int c=i+1;
        if(a>=0) mat[i][a]=A;
        mat[i][b]=B;
        if(c<N) mat[i][c]=C;
    }
    mat=mod_pow(mat,T,M);

    rep(i,N) {
        int ans=0;
        rep(j,N) {
            ans+=mat[i][j]*get_S(j);
            ans%=M;
        }
        cout<<ans;;
        if(i==N-1) cout<<endl;
        else cout<<" ";
    }

}

int main() {
    while(cin>>N>>M>>A>>B>>C>>T) {
        if(N==0) break;
        rep(i,60) S[i]=0;
        rep(i,N) cin>>S[i];
        solve();
    }
    return 0;
}

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

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

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)			// repeat reverse

#endif

namespace AGC008B
{
	void Run(void)
	{
		ll n, k; cin >> n >> k;
		vector<ll> a(n);
		rep(i, 0, n)
			cin >> a[i];

		ll l = 0;
		ll r = k - 1;
		vector<ll> ans_w(1);
		rep(i, 0, n)
			ans_w[0] += (0 < a[i] && k <= i) ? a[i] : 0;
		while (1)
		{	// 白く塗ったKマスをスライドさせて累積
			l++; r++;
			if (r == n)
				break;

			ans_w.push_back(ans_w.back());
			ans_w.back() += (0 < a[l - 1]) ? a[l - 1] : 0;
			ans_w.back() += (0 < a[r]) ? -a[r] : 0;
		}

		l = 0;
		r = k - 1;
		vector<ll> ans_b(1);
		rep(i, 0, n)
			ans_b[0] += (i < k) ? a[i] : (k <= i && 0 < a[i]) ? a[i] : 0;
		while (1)
		{	// 黒く塗ったKマスをスライドさせて累積
			l++; r++;
			if (r == n)
				break;

			ans_b.push_back(ans_b.back());
			ans_b.back() += (0 < a[l - 1]) ? 0 : -a[l - 1];
			ans_b.back() += (0 < a[r]) ? 0 : a[r];
		}

		cout << max(*max_element(all(ans_w)), *max_element(all(ans_b)));
	}
};

int main(void)
{
	AGC008B::Run();
	return 0;
}


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

const int N=1e6+6;
vb ex(N);
vi no(N,0),freq(N);

int main()
{
    int n;
    cin>>n;
    vi a(n);
    for(int i=0;i<n;i++) cin>>a[i],ex[a[i]]=true,freq[a[i]]++;
    sort(a.begin(),a.end());

    int mx=a[n-1];
    for(int i=0;i<n-1;i++)
    {
        if(freq[a[i]]>1) no[a[i]]++;
        for(int j=2*a[i];j<=mx;j+=a[i])
        {
            no[j]++;
        }
    }
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(no[a[i]]==0) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 11944
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>
#include <cassert>
#pragma region ACL
//#include <atcoder/fenwicktree>
//#include <atcoder/math>
//#include <atcoder/string>
#pragma endregion

using namespace std;
//using namespace atcoder;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<int> a(n); rep(i, n)cin >> a[i];
	sort(all(a));
	vector<bool> used(1001001);
	int res = 0;
	rep(i, n)
	{
		if (used[a[i]])continue;
		if (i + 1 < n && a[i] != a[i + 1])++res;
		else if (i == n - 1)++res;
		for (int j = a[i]; j <= 1000000; j += a[i])used[j] = true;
	}
	cout << res << endl;
}

Measured memory_bytes: 3988
import java.util.Scanner;
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();
        for(int i=0;i<10;i++){
            c=a*c-b;
            System.out.println(c);
        }
    }
    
}


Measured memory_bytes: 21204
N, M = map(lambda x: int(x), input().split())
mask_list = []
for i in range(M):
    ks = list(map(lambda x: int(x), input().split()))
    k, s = ks[0], ks[1:]
    mask = 0
    for j in s:
        mask += (1 << (j - 1))
    mask_list.append(mask)
p_list = list(map(lambda x: int(x), input().split()))

count = 0
for i in range(2 ** N):
    tmp = 1
    for j in range(M):
        def count_bit(val):
            result = 0
            while val > 0:
                result += val & 1
                val = val >> 1
            return result
        if count_bit(i & mask_list[j]) % 2 != p_list[j]:
            tmp = 0
            break
    count += tmp
print(count)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll r, c, n;
    cin >> r >> c >> n;
    vl clockwise;
    vector<pll> up, right, down, left;
    vi cnt(n, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 2; ++j) {
            ll x1, y1;
            cin >> x1 >> y1;
            if (y1 == 0 && x1 != 0) {
                up.emplace_back(x1, i);
                cnt[i]++;
            } else if (x1 == r && y1 != 0) {
                right.emplace_back(y1, i);
                cnt[i]++;
            } else if (y1 == c && x1 != r) {
                down.emplace_back(r - x1, i);
                cnt[i]++;
            } else if (x1 == 0 && y1 != c) {
                left.emplace_back(c - y1, i);
                cnt[i]++;
            }
        }
    }
    sort(up.begin(), up.end());
    sort(right.begin(), right.end());
    sort(down.begin(), down.end());
    sort(left.begin(), left.end());
    for (auto &x : up)
        if (cnt[x.second] == 2)
            clockwise.push_back(x.second);
    for (auto &x : right)
        if (cnt[x.second] == 2)
            clockwise.push_back(x.second);
    for (auto &x : down)
        if (cnt[x.second] == 2)
            clockwise.push_back(x.second);
    for (auto &x : left)
        if (cnt[x.second] == 2)
            clockwise.push_back(x.second);
    set<ll> used;
    stack<ll> st;
    for (auto &x : clockwise) {
        if (used.count(x) == 1) {
            if (st.top() != x) {
                cout << "NO"
                     << "\n";
                return 0;
            }
            st.pop();
        } else {
            used.insert(x);
            st.push(x);
        }
    }
    cout << "YES"
         << "\n";
    return 0;
}

Measured memory_bytes: 10152
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

const int big = 100000000;
int main(){
  while(1){
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    vector<int> c(m);
    vector<int> x(n);
    rep(i, m) cin >> c[i];
    rep(i, n) cin >> x[i];
    vector<vector<int>> dp(n+1, vector<int>(256, big));
    dp[0][128] = 0;
    int y;
    rep(i, n)rep(j, 256)rep(k, m){
      y = j + c[k];
      if (y < 0) y = 0;
      if (y > 255) y = 255;
      dp[i+1][y] = min(dp[i+1][y], dp[i][j] + (y - x[i]) * (y - x[i]));
    }
    int ans = big;
    rep(i, 256) if(ans > dp[n][i]) ans = dp[n][i];
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 23676
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(ll i = 0;i < n;i++)
#define FOR(i,a,b) for(ll i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

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;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

struct edge { ll to, cost; };

int main() {
	IOS;
	ll n;
	cin >> n;
	ll a = 1, b = 1;
	REP(i, n) {
		ll x, y;
		cin >> x >> y;
		ll t1 = a / x;
		if (a % x != 0)t1++;
		ll t2 = b / y;
		if (b % y != 0)t2++;
		ll m = max(t1, t2);
		a = m * x, b = m * y;
	}
	dump(a + b);
}




Measured memory_bytes: 256
N, A, B, K = map(int, input().split())
MOD = 998244353

fact = [1]*(N+1)
rev = [1]*(N+1)
for i in range(1, N+1):
    fact[i] = fact[i-1]*i % MOD
    rev[i] = pow(fact[i], MOD-2, MOD)

ans = 0
for a in range(N+1):
    if (K - a*A) >= 0 and (K - a*A) % B == 0:
        b = (K - a*A) // B
        if not 0 <= b <= N:
            continue
        ans += rev[a]*rev[N-a] * rev[b]*rev[N-b]
        ans %= MOD
ans *= fact[N]*fact[N]
ans %= MOD
print(ans)

Measured memory_bytes: 28764
n,m,k=map(int,input().split())
 
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * (g2[r] * g2[n-r]) % mod)%mod
 
mod = 998244353
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
 
for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
 
ans = 0
for i in range(k+1):
    ans += (m * pow(m-1,n-1-i,mod) * cmb(n-1,i,mod)) % mod
print(ans%mod)

Measured memory_bytes: 32928
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(scanf("%d %d",&n,&m),n){
		vvi in(n,vi(n));
		vvi pic(m,vi(m));
		rep(i,n)rep(j,n)scanf("%d",&in[i][j]);
		rep(i,m)rep(j,m)scanf("%d",&pic[i][j]);
		pii out(inf,inf);
		int N=n-m+1,M=n-m+1;
		rep(e,4){
			rep(i,n-m+1)rep(j,n-m+1){
				if(i>N&&j>M)goto end;
				pii t(inf,inf);
				rep(k,m)rep(l,m)
					if(pic[k][l]!=-1){
						if(in[i+k][j+l]!=pic[k][l])goto en;
						t=min(t,pii(i+k,j+l));
					}
				out=min(out,t);
				N=out.first;
				M=out.second;
				goto end;
				en:;
			}
			end:;
			vvi tmp=pic;
			rep(i,m)rep(j,m)pic[i][j]=tmp[j][m-i-1];
		}
		if(out.first==inf)cout<<"NA"<<endl;
		else cout<<out.second+1<<" "<<out.first+1<<endl;
	}
}

Measured memory_bytes: 1296
#include<stdio.h>
#include<limits.h>

typedef struct{
	char suit;
	int value;
}Card;

int partition(Card *,int,int);
void merge(Card *,int,int,int);
void mergeSort(Card *,int,int,int);
void quickSort(Card *,int,int,int);

Card L[50002],R[50002];

int main(){
	int n,i,v;
	Card A[100000],B[100000];
	char S;
	int hantei=1;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf(" %c",&S);
		scanf("%d",&v);
		A[i].suit=B[i].suit=S;
		A[i].value=B[i].value=v;
	}
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);
	for(i=0;i<n;i++){
		if(A[i].suit!=B[i].suit)hantei=0;
	}
	if(hantei==1)printf("Stable\n");
	else printf("Not stable\n");
	for(i=0;i<n;i++){
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}

int partition(Card *A,int p,int r){
  int i,j;
  Card x,a;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
  a=A[i+1];
  A[i+1]=A[r];
  A[r]=a;
  return i+1;
}

void merge(Card *A,int left,int mid,int right){
	int i,j,k;
	int n1 = mid-left;
	int n2 =right-mid;
	for(i=0;i<n1;i++) L[i]=A[left+i];
	for(i=0;i<n2;i++) R[i]=A[mid+i];
	L[n1].value=R[n2].value=INT_MAX;
	i=0;
	j=0;
	for(k=left;k<right;k++){
		if(L[i].value<=R[j].value){
			A[k]=L[i++];
		}
		else{
			A[k]=R[j++];
		}
	}
}

void mergeSort(Card *A,int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,left,mid,right);
  }
}

void quickSort(Card *A,int n,int p,int r){
	int q;
	if(p<r){
		q=partition(A,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}



Measured memory_bytes: 4080
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 998244353
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int fa[maxn];
int u[maxn],v[maxn];
ll n,m,q;
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
int main()
{
	n=read(); m=read(); q=read();
	if(m==n-1){
		for(int i=1;i<=q;i++){
			int x=read(),y=read(),z=read();
			if(z){
				puts("No"); return 0;
			}
		}
		puts("Yes"); return 0;
	}
	for(int i=0;i<n;i++)
		fa[i]=i;
	int cnt=n,tot=0;
	for(int i=1;i<=q;i++){
		int x=read(),y=read(),z=read();
		if(!z){
			int fx=find(x),fy=find(y);
			if(fx!=fy)--cnt,fa[fx]=fy;
		}
		else u[++tot]=x,v[tot]=y;
	}
	for(int i=1;i<=tot;i++)
		if(find(u[i])==find(v[i])){
			puts("No"); return 0;
		}
	if(m<=n-cnt+(ll)cnt*(cnt-1)/2)puts("Yes");
	else puts("No");
	return 0;
}

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

int main() {
  int n, c;
  std::cin >> n >> c;
  std::vector<std::vector<uint16_t>> d(c, std::vector<uint16_t>(c));

  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      std::cin >> d[i][j];
    }
  }

  std::vector<int> c_g[3];
  c_g[0] = std::vector<int>(c, 0);
  c_g[1] = std::vector<int>(c, 0);
  c_g[2] = std::vector<int>(c, 0);

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int tmp;
      std::cin >> tmp;
      c_g[(i + j) % 3][tmp - 1]++;
    }
  }

  uint64_t cost = 250000000;

  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      for (int k = 0; k < c; k++) {
        if (i == j || j == k || k == i) {
          continue;
        } else {
          uint64_t cost_now = 0;
          for (int l = 0; l < c; l++) {
            cost_now += d[l][i] * c_g[0][l];
          }
          for (int l = 0; l < c; l++) {
            cost_now += d[l][j] * c_g[1][l];
          }
          for (int l = 0; l < c; l++) {
            cost_now += d[l][k] * c_g[2][l];
          }
          cost = std::min(cost, cost_now);
        }
      }
    }
  }

  std::cout << cost << std::endl;
  return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val nums     = scala.io.StdIn.readLine.split("")
    val like_num = 753
    var min_diff = 1000000
    for(i <- 0 until nums.length - 2) {
      val num = (nums(i) + nums(i + 1) + nums(i + 2)).toInt
      val diff = Math.abs(like_num - num)
      if( min_diff > diff) {
        min_diff = diff
      }
    }
    println(min_diff)
  }
}

Measured memory_bytes: 25416
#include<iostream>
#include<cstdlib>
#include <cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_map>
#include <bits/stdc++.h>
using namespace std;

int main()
{      
    int N;
    cin >> N;
    
    string s;
    
    unordered_map<string, long> hash;
    for(int i=0; i<N; i++){
        cin >> s;
        if(!hash[s]){
            hash[s] = 1;
        }else{
            hash[s] += 1;
        }
    }
    cout << "AC x " << hash["AC"] << endl;
    cout << "WA x " << hash["WA"] << endl;
    cout << "TLE x " << hash["TLE"] << endl;
    cout << "RE x " << hash["RE"] << endl;
    
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  bool A = true;
  for (int i = 0; i < N - 2; i++) {
    if (a.at(i) == b.at(i) && a.at(i + 1) == b.at(i + 1) && a.at(i + 2) == b.at(i + 2)) {
      A = false;
      cout << "Yes" << endl;
      break;
    }
  }
  if (A) {
    cout << "No" << endl;
  }
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

int digitsum(int n){
    int s = 0;
    while (n > 0){
        s += n % 10;
        n /= 10;
    }
    return s;
}

signed main() {

    int n, a, b;
    cin>>n>>a>>b;
    
    int ans=0;
    for(int i=1; i<=n; i++){
        int d = digitsum(i);
        if(a<=d && d<=b) ans+=i;
    }
    cout <<ans <<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();
	vector<int> a(n);
	trav(i,a)i=in();
	vector<int> rg(n);
	vector<int> lg(n);
	rg[n-1]=a[n-1];lg[0]=a[0];
	if(n==1){cout<<a[0];return 0;}
	if(n==2){cout<<max(a[0],a[1]);return 0;}
	int g=a[0];
	for(int i=1;i<n;i++)
	{
		g=__gcd(g,a[i]);
		lg[i]=g;
	}
	g=a[n-1];
	for(int i=n-2;i>=0;i--)
	{
		g=__gcd(g,a[i]);
		rg[i]=g;
	}
	int mx=max(lg[n-2],rg[1]);
	for(int i=1;i<n-1;i++)
	{
		mx=max(mx,__gcd(lg[i-1],rg[i+1]));
	}
	cout<<mx;
	
	
}

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

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

using namespace std;

void solve(){
	int n;
	cin >> n;
	int arr[n], arr2[n], cnt1[n+1] = {}, cnt2[n+1] = {};
	for(auto &x : arr){
		cin >> x;	
		cnt1[x]++;
	}
	for(auto &x : arr2){
		cin >> x;
		cnt2[x]++;
	}
	for(int i = 0;i <= n;i++){
		if(cnt1[i]+cnt2[i]>n){
			cout << "No\n";
			return;
		}
	}
	reverse(arr2,arr2+n);
	int l = 1e18, r = -1;
	for(int i = 0; i < n;i++){
		if(arr[i]==arr2[i]){
			l = min(l,i);
			r = i;
		}
	}
	for(int i = l; i <= r;i++){
		swap(arr2[i],arr2[(i+n/2)%n]);
	}
	cout << "Yes\n";
	for(auto x : arr2) cout << x << " ";
}

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

Measured memory_bytes: 9892
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,T,t[200001];
	cin>>n>>T;
	for(int i=0;i<n;i++)
		cin>>t[i];
	t[n]=2e9;
	int ans=0;
	for(int i=0;i<n;i++)
		ans+=min(t[i+1]-t[i],T);
	cout<<ans<<endl;
}


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

using namespace std;

int main()
{
    int N, a, min = 0, count = 0, b;
    cin >> N;
    vector<int> v;
    vector<bool> color;

    for (int i = 0; i < N; i++)
    {
        cin >> a;
        v.push_back(a);
    }

    for (int i = 0; i <= 7; i++)
    {
        color.push_back(false);
    }

    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] >= 1 && v[i] <= 399)
        {
            color[0] = true;
            continue;
        }

        if (v[i] >= 400 && v[i] <= 799)
        {
            color[1] = true;
            continue;
        }

        if (v[i] >= 800 && v[i] <= 1199)
        {
            color[2] = true;
            continue;
        }

        if (v[i] >= 1200 && v[i] <= 1599)
        {
            color[3] = true;
            continue;
        }

        if (v[i] >= 1600 && v[i] <= 1999)
        {
            color[4] = true;
            continue;
        }

        if (v[i] >= 2000 && v[i] <= 2399)
        {
            color[5] = true;
            continue;
        }

        if (v[i] >= 2400 && v[i] <= 2799)
        {
            color[6] = true;
            continue;
        }

        if (v[i] >= 2800 && v[i] <= 3199)
        {
            color[7] = true;
            continue;
        }

        if (v[i] >= 3200)
        {
            min++;
            count++;
        }
    }

    for (int i = 0; i < color.size(); i++)
    {
        if (color[i])
        {
            count++;
        }
    }

    b = count - min;
    if (b == 0)
    {
        b = 1;
    }

    cout << b << " " << count;
}

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

using namespace std;

int main(){
  int N,K;
  string S;

  cin >> N;
  cin >> S;
  cin >> K;

  char t = S[K-1];
  
    for(int i=0;i<N;i++){
        if(S[i] != t){
            S[i] = '*';
        }
    }
  cout << S << endl;
}



Measured memory_bytes: 256
a,b,c = gets.chomp.split(' ').map{|n| n.to_i}

arr = [a,b,c]
arr.sort!
up = arr[2] - arr[1]
dow = arr[2] - arr[0]
count = 0
if (dow + up).odd?
  arr[1] += 1
  arr[2] += 1
  count += 1
end

while arr[1] != arr[2] do
  arr[1]+=1
  arr[0]+=1
  count+=1
end

while arr[0] != arr[2] do
  arr[0] += 2
  count+=1
end

puts count


Measured memory_bytes: 1788
R, G, B, N = map(int, input().split())

def f(a, b):
    sho, amari = int(a/b), a%b
    return sho, amari


def ans(l, m, s):
    cnt = 0

    R_s, R_a = f(N, l)

    for i in range(R_s + 1):
        x = R_a + i * l # R を i 個使う
        G_s, G_a = f(x, m)
        for j in range(G_s + 1):
            y = G_a + j * m # G を j 個使う
            if y % s == 0:
                cnt += 1
    return cnt

li = [R, G, B]
li.sort(reverse=True)

cnt = ans(li[0], li[1], li[2])

print(cnt)





Measured memory_bytes: 3064
from collections import Counter

class Eratosthenes():  # エラトステネスの篩
    def __init__(self, N):  # 素数リスト生成 O(n*log(log n))
        self.fact = [i for i in range(N + 1)]
        for i in range(2, int(N ** 0.5) + 1):
            if self.fact[i] < i:
                continue
            for j in range(i ** 2, N + 1, i):
                self.fact[j] = i
        self.prime = [i for i in range(2, N + 1) if i == self.fact[i]]

    def factor(self, NUM):  # 高速素因数分解 O(log num)
        PRIME = []
        while NUM > 1:
            PRIME.append(self.fact[NUM])
            NUM //= self.fact[NUM]
        return Counter(PRIME)

n = int(input())

era = Eratosthenes(n)
ans = 0
for i in range(1, n):
    tmp = 1
    for num in era.factor(i).values():
        tmp *= num + 1
    ans += tmp
print(ans)


Measured memory_bytes: 149048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,i;
	cin>>n>>i;
	cout<<n-i+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  double r; cin >> r;
  printf("%.3f",2*r*3.141592);
  return 0;
}


Measured memory_bytes: 3780
S = input()
N = len(S)

ls = []
n = 0
c = ['R','L']
cn = 0
for s in S[1:]:
	n = n + 1
	if not s == c[cn]:
		cn = (cn + 1) % 2
		ls.append(n)
		n = 0
ls.append(n+1)

pt = len(ls)//2

ans = [0] * N
pos = 0
for i in range(pt):
	rn = ls[2*i]
	ln = ls[2*i+1]
	pos += rn
	m = (rn+ln)//2
	if (ln + rn) % 2 == 0:
		ans[pos-1] = m
		ans[pos] = m
	else:
		if rn % 2 == 0:
			ans[pos-1] = m
			ans[pos] = m+1
		else:
			ans[pos-1] = m+1
			ans[pos] = m
	pos += ln

print(str(ans).replace(',','')[1:-1])













Measured memory_bytes: 5384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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(int argc, char const *argv[]) {
  int n,r;
  cin >> n >> r;
  if(n>=10) cout << r << endl;
  else{
    cout << r+100*(10-n) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
A,V=input().split()
B,W=input().split()
T=int(input())
A=int(A)
V=int(V)
B=int(B)
W=int(W)
distance=abs(A-B)
speed=abs(V-W)
if V<=W:
    print("NO")
if V>W:
    a=T*speed
    if a>=distance:
        print("YES")
    if a<distance:
        print("NO")

Measured memory_bytes: 9200
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> v;
    for (int i = 1; i <= min(a, b); ++i) {
        if(a%i == 0 && b%i == 0) v.emplace_back(i);
    }
    reverse(v.begin(), v.end());
    cout << v[k-1] << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ar[n+1];
    for(int i=0;i<n;i++)cin>>ar[i];
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if((ar[i]+ar[j]>ar[k])&&(ar[i]+ar[k]>ar[j])&&(ar[j]+ar[k]>ar[i]) && (ar[i]!=ar[j])&&(ar[j]!=ar[k])&&(ar[i]!=ar[k])){
                       //cout<<ar[i]<<" "<<ar[j]<<" "<<ar[k]<<endl;
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;
}



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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(long long i=0;i<n;i++)
#define rev(i,n) for(long long i=n;i>=0;i--)
#define rep_a(i,a,n) for(long long i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r" , stdin);
	//freopen("output.txt", "w" , stdout);
	#endif
	
	ll k,curr;
  	cin >> k;
  	queue<ll> q;
  
  	for(ll i=1;i<=9;i++){
    	q.push(i);
   	}
  
  	while(k--){
    	curr=q.front();
      	q.pop();
      
      	if(curr%10!=0)
          q.push(curr*10 + curr%10-1);
      
      	q.push(curr*10 + curr%10);
      
      	if(curr%10!=9)
          q.push(curr*10 + curr%10+1);
    }
  
  	cout << curr << endl;
	
}


Measured memory_bytes: 1792
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();

    int[] votes = new int[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
      int vote = sc.nextInt();
      votes[i] = vote;
      sum += vote;
    }
    int count = 0;
    for (int vote : votes) {
      BigDecimal a = new BigDecimal(vote);
      BigDecimal b = 
          new BigDecimal(sum).divide(new BigDecimal(4).multiply(new BigDecimal(m)), 3, RoundingMode.DOWN);
      if (a.compareTo(b) >= 0) {
        count++;
      }
    }
    if (count >= m) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(1000000)

def DFS(i):
    if done[i]:
        ans[-1]+=1
        done[i]=False
        for g in G[i]:
            if done[g]:
                DFS(g)
    else:
        return p

N,M=map(int,input().split())
G=[[] for _ in range(N)]
done=[True for _ in range(N)]

for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)
ans=[]
for j in range(N):
    ans.append(0)
    if done[j]:
        DFS(j)
print(max(ans))


Measured memory_bytes: 210936
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

ll dp[200005][3][2];

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
  }
  rep(i, 200005){
    rep(j, 3){
      rep(k, 2){
        dp[i][j][k]=-INFll;
      }
    }
  }
  dp[0][1][0]=0;
  repo(i, n){
    rep(j, 3){
      rep(k, 2){
        if((i-1)/2-1+j>=i/2-1 &&(i-1)/2-1+j<=(i+1)/2){
          dp[i][(i-1)/2-1+j-(i/2-1)][0]=max(dp[i][(i-1)/2-1+j-(i/2-1)][0], dp[i-1][j][k]);
        }
        if((i-1)/2-1+j+1>=i/2-1 &&(i-1)/2-1+j+1<=(i+1)/2 && k==0){
          dp[i][(i-1)/2-1+j+1-(i/2-1)][1]=max(dp[i][(i-1)/2-1+j+1-(i/2-1)][1], dp[i-1][j][k]+a[i-1]);
        }
      }
    }
  }
  ll ans=max(dp[n][1][0], dp[n][1][1]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13556
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>


#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

typedef long long int ll;


int main(){

    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }

    ll left = 0,right = 1;
    ll bit_now = a[0];
    ll count_now = a[0];
    ll ans = 1;
    //cout << ans << endl;
    while(right < n){
        //cout << right << endl;
        if((bit_now ^ a[right]) == count_now + a[right] || left >= right  ){
            //cout << "a" << endl;
            ans += (right-left+1);
            bit_now = bit_now ^ a[right];
            count_now += a[right];
            right++;
        }else{
            //cout << "b" << endl;
            bit_now = bit_now ^ a[left];
            count_now = count_now - a[left];
            left++;
        }
        //cout << left << " " << right << " " << ans << endl;
    }
    cout << ans << endl;


    return 0;
}

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

typedef const int& cint;

const int MAXN = 2010;

struct Edge{
	int nxt, to;
	
	Edge(){}
	
	Edge(cint nxt_, cint to_){nxt = nxt_, to = to_;}
}ed[MAXN << 1];
int head[MAXN], tot;
int eg[2][MAXN];
bool vis[MAXN]; int dep[MAXN], cnt[MAXN];

inline void chkmin(int& a, int b){if (b < a) a = b;}

inline void add(cint u, cint v){
	ed[++tot] = Edge(head[u], v), head[u] = tot;
	ed[++tot] = Edge(head[v], u), head[v] = tot;
}

void dfs(int u){
	vis[u] = 1, ++cnt[dep[u]];
	int tmp, v;
	for (tmp = head[u], v = ed[tmp].to; tmp; tmp = ed[tmp].nxt, v = ed[tmp].to)
		if (!vis[v])
			dep[v] = dep[u] + 1, dfs(v);
}

int main(){
	int N, K;
	scanf("%d %d", &N, &K);
	for (int i = 1; i < N; ++i)
		scanf("%d %d", &eg[0][i], &eg[1][i]), add(eg[0][i], eg[1][i]);
	int ans = N;
	if (K & 1){
		for (int i = 1, sum; i < N; ++i){
			memset(vis, 0, sizeof vis);
			memset(cnt, 0, sizeof cnt);
			dep[eg[0][i]] = dep[eg[1][i]] = 0;
			vis[eg[0][i]] = vis[eg[1][i]] = 1;
			dfs(eg[0][i]), dfs(eg[1][i]);
			sum = 0;
			for (int i = K / 2; i >= 0; --i)
				sum += cnt[i];
			chkmin(ans, N - sum);
		}
	}
	else {
		for (int i = 1, sum; i <= N; ++i){
			memset(vis, 0, sizeof vis);
			memset(cnt, 0, sizeof cnt);
			vis[i] = 1, dep[i] = 0, dfs(i);
			sum = 0;
			for (int i = K / 2; i >= 0; --i)
				sum += cnt[i];
			chkmin(ans, N - sum);
		}
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<long> a;
long n,m,i,s,mx,b,l,r,md,k;
int main() {
    cin >> n >> m >> k;
    a.resize(n);
    cin >> a[0];
    mx = 0;
    if(a[0] <= k) mx = 1;
    for(i = 1; i < n; i++) {
        cin >> a[i];
        a[i] += a[i-1];
        if(a[i] <= k) mx = i+1;
    }
    s = 0;
    for(i = 0; i < m; i++) {
        cin >> b;
        s += b;
        if(s > k) break;
        mx = max(mx,i+1);
        l = 0;
        r = n;
        while(r-l > 1) {
            md = (l + r) >> 1;
            if(a[md] > k-s) r = md;
            else l = md;
        }
        if(a[l]+s <= k) {
            mx = max(mx,i+1+l+1);
        }
    }
    cout << mx;
    return 0;
}

Measured memory_bytes: 4752
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,d,water,x,y,ans;
	cin>>a>>b>>c>>d>>water;
	x=water*a;
	y=b;
	if(c<water)y+=(water-c)*d;
	ans=min(x,y);
	cout<<ans<<endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
    const int CMAX = 13; 
    int n;
    int s[CMAX];
    int h[CMAX];
    int c[CMAX];
    int d[CMAX];
    char cd;
    int  num;

    memset(s, 0, sizeof(s));
    memset(h, 0, sizeof(s));
    memset(c, 0, sizeof(s));
    memset(d, 0, sizeof(s));

    cin >> n;

    if (n > 0 && n <= 52) {
        for (int i = 0; i < n; i++) {
            cin >> cd >> num;
            if (num >= 1 && num <= 13) {
                switch (cd) {
                case 'S': s[num-1] = 1; break;
                case 'H': h[num-1] = 1; break;
                case 'C': c[num-1] = 1; break;
                case 'D': d[num-1] = 1; break;
                default: break;
                }
            }
        }
    }

    int i;

    for (i = 0; i < CMAX; i++) {
        if (s[i] == 0) {
            cout << "S " << i+1 << endl;
        }    
    }

    for (i = 0; i < CMAX; i++) {
        if (h[i] == 0) {
            cout << "H " << i+1 << endl;
        }    
    }

    for (i = 0; i < CMAX; i++) {
        if (c[i] == 0) {
            cout << "C " << i+1 << endl;
        }    
    }

    for (i = 0; i < CMAX; i++) {
        if (d[i] == 0) {
            cout << "D " << i+1 << endl;
        }    
    }

   return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

ll modnum = 1000000007;

//繰り返し二乗法
ll RepeatSquaring(ll N, ll P, ll M) {
  if (P == 0) return 1;
  if (P == 1) return N % M;
  if (P % 2 == 1) return (N * RepeatSquaring(N, P-1, M)) % M;
  ll t = RepeatSquaring(N, P/2, M);
  return (t * t) % M;
}

int main() {
  ll n, k;
  cin >> n >> k;

  ll ans = 0;
  vector<ll> C(n), H(n);
  C[0] = 1, H[0] = 1;
  
  for(ll i = 0; i < n-1; i++) {
    C[i+1] = (C[i] * (n-i)) % modnum;
    C[i+1] = (C[i+1] * RepeatSquaring(i+1, modnum-2, modnum)) % modnum;
  }

  for(ll i = 0; i < n-1; i++) {
    H[i+1] = (H[i] * (n-i-1)) % modnum;
    H[i+1] = (H[i+1] * RepeatSquaring(i+1, modnum-2, modnum)) % modnum;
  }

  for(ll i = 0; i <= min(k, n-1); i++) {
    ans = (ans + (C[i] * H[n-1-i]) % modnum) % modnum;
  }

  while(ans < 0) {
    ans = ans + modnum;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3328