akhauriyash/Code-Regression huggingface dataset:
N, M = map(int,input().split())
par = [i for i in range(N+1)]
size = [1 for _ in range(N+1)]

def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y
    size[y] += size[x]
    size[x] = 0

for i in range(M):
    x, y, z= map(int,input().split())
    unite(x,y)

Ans = 0
for j in size[1:]:
    if j != 0:
        Ans += 1
print(Ans)


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
	ll n,ans;

	cin >> n;
	ans = 100000000000000;
	bool a = false;

	FOR(i,2,1000001) {
		if(n%i == 0) {
			ll mi = i + (n/i);
			if(ans > mi) {
				ans = mi;
			}
		}
	}
	if(ans < n) {
		cout << ans-2 << endl;
	} else {
		cout << n-1 << endl;
	}


}



Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

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

	int A, B;
	cin >> A >> B;
  
    string U;
  	cin >> U;

	if (U == S) {
		A--;
		cout << A << " " << B << endl;
	}

	if (U == T) {
		B--;
		cout << A << " " << B << endl;
	}



}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<cstdlib>
using namespace std;

int h,w;
char c[30][30];

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


int dijkstra(int y, int x){
    int dist[30][30];
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            dist[i][j]=-1;
        }
    }
    dist[y][x]=0;
    queue<pair<int,int>> que;
    que.push(pair<int,int>(y,x));
    while (!que.empty())
    {
        pair<int,int> cur=que.front();
        que.pop();
        for(int i=0;i<4;++i){
            int ny=cur.first+dy[i];
            int nx=cur.second+dx[i];
            if(0<=ny&&ny<h&&0<=nx&&nx<w&&c[ny][nx]=='.'&&dist[ny][nx]==-1){
                que.push(pair<int,int>(ny,nx));
                dist[ny][nx]=dist[cur.first][cur.second]+1;
            }
        }
    }
    
    int res=0;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            res=max(res,dist[i][j]);
        }
    }

    return res;
}

void solve(){
    int res=0;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(c[i][j]=='#') continue;
            res=max(dijkstra(i,j),res);
        }
    }
    cout<<res<<endl;
}    

int main(){
    cin>>h>>w;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cin>>c[i][j];
        }
    }
    solve();
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <map>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
    std::cout << 0;
  else
    std::cout << std::min(1LL * a * b, std::min(1LL * a * c, 1LL * b * c));
  return 0;
}


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

int main(){
    int n,count_median; 
    double a_median, b_median;
    cin >> n;
    int a[n], b[n];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }

    sort(a, a+n);
    sort(b, b+n);
    if(n % 2 == 0){
        a_median = (a[n/2 - 1] + a[n/2])/2.0;
        b_median = (b[n/2 - 1] + b[n/2])/2.0;
        count_median = (int)((b_median - a_median)*2) + 1;

    }else{
        a_median = a[(n-1)/2];
        b_median = b[(n-1)/2];
        count_median = (b_median - a_median) + 1;
    }
    cout << count_median << endl;

    return 0;

    /*
    2
    1 2
    2 3

    3
    100 100
    10 10000
    1 1000000000
    */
}

Measured memory_bytes: 4740
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
	int key;
	struct node *prev,*next;
};
typedef struct node node;
node *nil;
void init();
void insert(int key);
void deletef(int key);
void deleteFirst();
void deleteLast();
void printKey();
node *listSearch(int key);
int main(){
	int n,i,j=0,key;
	char a[15];
	scanf("%d",&n);
	init();
	for(i=0;i<n;i++){
		scanf("%s",a);
		if(strlen(a)==6){
			scanf("%d",&key);
			if(a[0]=='i'){
				insert(key);
			}
			else{
				deletef(key);
			}
		}
		else if(a[6]=='F'){
			deleteFirst();
		}
		else if(a[6]=='L'){
			deleteLast();
		}
	}
	printKey();
	return 0;
} 
void init(){
    nil=(node *)malloc(sizeof(node));
    nil->next=nil;
    nil->prev=nil;
}
void insert(int key){
	node *x=(node *)malloc(sizeof(node));
	x->key=key;
	x->next=nil->next;
	nil->next->prev=x;
	x->prev=nil;
	nil->next=x;
}
void deletef(int key){
	node *x=listSearch(key);
	if(x==nil)return;
	x->prev->next=x->next;
	x->next->prev=x->prev;
	free(x);
}
void deleteFirst(){
	node *x=nil->next;
	x->prev->next=x->next;
	x->next->prev=x->prev;
	free(x);
}
void deleteLast(){
	node *x=nil->prev;
	x->prev->next=x->next;
	x->next->prev=x->prev;
	free(x);
}
node *listSearch(int key){
	node *current=nil->next;
	while(current->key!=key&&current!=nil){
		current=current->next;
	}
	return current;
}
void printKey(){
	node *current=nil->next;
	int t=0;
	while(current!=nil){
		if(t>0)
		printf(" ");
		printf("%d",current->key);
		current=current->next;
		t++;
	}
	printf("\n");
}



Measured memory_bytes: 33112
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	int i;
	for(i=0;i<n;i++)
		cin>>a[i];
	map<int,int> mp;
	for(i=0;i<n;i++)
		mp[a[i]]++;
	int ans = INT_MIN;
	for(i=0;i<n;i++)
		ans = max(ans,mp[a[i]]+mp[a[i]-1]+mp[a[i]+1]);
	cout<<ans;
}

Measured memory_bytes: 5120
package main

import "fmt"

func main() {
  var n, k int
  fmt.Scanf("%d %d", &n, &k)
  
  a := make([]int, n)
  
  for i:=0; i<k; i++ {
    var d int
    fmt.Scan(&d)
    for j:=0; j<d; j++ {
      var s int
      fmt.Scan(&s)
      a[s-1]+=1
    }
  }
  
  var r int
  for i:=0; i<n; i++ {
    if a[i] == 0 {
      r+=1
    }
  }
  
  fmt.Println(r)
}

Measured memory_bytes: 2496
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];

    ll tate = 0;
    rep(i, n - 1) {
        ll now = x[i + 1] - x[i];
        (now *= (ll)(i + 1)) %= MOD;
        (now *= (ll)(n - i - 1)) %= MOD;
        (tate += now) %= MOD;
    }

    ll yoko = 0;
    rep(i, m - 1) {
        ll now = y[i + 1] - y[i];
        (now *= (ll)(i + 1)) %= MOD;
        (now *= (ll)(m - i - 1)) %= MOD;
        (yoko += now) %= MOD;
    }

    cout << tate * yoko % MOD << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	int a = 0;
	int b = 0;
	int c = 0;
	int d = 0;

	if (scanf("%d%d%d%d", &a, &b, &c, &d) == 4) {
		if ((0 <= a && a <= 100) && (0 <= b && b <= 100) && (a < b)
			&& (0 <= c && c <= 100) && (0 <= d && d <= 100) && (c < d)
			) {
			int sum = 0;

			if (a <= c) {
				if (c <= b) {
					if (b <= d) {
						sum = b - c;
					} else {
						sum = d - c;
					}
				}
			} else {
				if (a <= d) {
					if (d <= b) {
						sum = d - a;
					} else {
						sum = b - a;
					}
				}
			}
			printf("%d\n", sum);
		}
	}

	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {

    ll N;
    cin >> N;
    REP(i, N + 1) {
        ll X = i * 1.08;
        if (X == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N; cin >> N;
	long long num = 100;
	for (int i = 0; i < 4000; i++) {
		if (num >= N) {
			cout << i << endl;
			return 0;
		}
		num *= 1.01;
	}
}

Measured memory_bytes: 3636
N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
frag = [1] + [0]*N
def func(ide):
    global Q
    for i in E[ide]:
        i = int(i) - 1
        if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
        
    

while Q:top = Q[0];func(top);del Q[0]

for i in range(N):print(i + 1 ,int(L[i]))



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

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

  if((a=='H' && b=='H') || (a=='D' && b== 'D')){
    cout << 'H' << endl;
  }else{
    cout << 'D' << endl;
  }

}



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

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

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, C, K; cin >> N >> C >> K;
  int T[N]; rep(i,N) cin >> T[i]; sort(T,T+N);

  int result = 0, pos = 0;
  while (pos<N) {
    auto r = upper_bound(T,T+N,T[pos]+K) - T;
    pos = r-pos>=C ? pos+C : r;
    result++;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    vector<int> a(n+1),b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) {
        if(a[i] >= b[i]) ans += b[i];
        else {
            ans += min(b[i],a[i]+a[i+1]);
            a[i+1] = max(0,a[i+1]+a[i]-b[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main() {
	long long S, c;
	cin >> S >> c;
	long long set = 0;

	if (S - c / 2 <= 0) {
		set = S + (c - S * 2) / 4;
	}
	else {
		set = floor(c / 2);
	}

	cout << set << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    int a, b;
    cin >> a >> b;

    if (a - 2 * b < 0) {
        cout << 0 << "\n";
    } else {
        cout << a - 2 * b << "\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#define INF 1e+9
using namespace std;

int main(){
	int n,p;
	map<int,int> num;
	int cost[101][101];
	cin >> n;
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= n;j++) cost[i][j] = INF;
		cost[i][i] = 0;
	}
	for(int i = 0;i < n;i++){
		int r,k;
		cin >> r >> k;
		for(int j = 0;j < k;j++){
			int t;
			cin >> t;
			cost[r][t] = 1;
		}
	}
	for(int k = 0;k <= n;k++){
		for(int i = 0;i <= n;i++){
			for(int j = 0;j <= n;j++) cost[i][j] = min(cost[i][j],cost[i][k] + cost[k][j]);
		}
	}
	cin >> p;
	for(int i = 0;i < p;i++){
		int s,d,v;
		cin >> s >> d >> v;
		if(cost[s][d] >= v) cout << "NA" << endl;
		else cout << cost[s][d] + 1 << endl;
	}
	return 0;
}

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

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

void solve(long long X){
  cout << ((X >= 30) ? YES : NO) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
  scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int x,a; cin >> x >> a;
    cout << ((x<a) ? 0: 10) << endl; return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <vector>

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

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& v) {
    os << "(" << v.first << ", " << v.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    for (int i = 0; i < v.size(); i++) {
        if (i) os << ", ";
        os << v[i];
    }
    os << "}";
    return os;
}

int main()
{
    ll mod = TEN(9) + 7;
    int n;
    cin >> n;
    vector<ll> a(n, 0);
    ll a_max = 0;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a_max = max(a_max, a[i]);
    }

    ll y = 1; int log_a_max = 0;
    while (y < a_max) {
        y *= 2;
        log_a_max++;
    }

    vector<vector<bool>> p(n, vector<bool>(log_a_max, 0));
    vector<int> s(log_a_max, 0);
    for (int i = 0; i < n; i++) {
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < log_a_max; j++) {
            s[j] += (a[i] >> j) & 1;
        }
    }

    ll sum = 0;
    ll x = 1;
    for (int j = 0; j < log_a_max; j++) {
        for (int i = 0; i < n; i++) {
            if (a[i] >> j & 1) {
                sum += x * (n - s[j]);
            } else {
                sum += x * s[j];
            }
            sum %= mod;
        }
        x *= 2;
        x %= mod;
    }
    cout << sum * ((mod + 1) / 2) % mod << endl;
    return 0;
}


Measured memory_bytes: 26732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int D = sc.nextInt();
		if (D == 25) System.out.println("Christmas");
		else if (D == 24) System.out.println("Christmas Eve");
		else if (D == 23) System.out.println("Christmas Eve Eve");
		else if (D == 22) System.out.println("Christmas Eve Eve Eve");
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main() {
	long n,m,i,j,p;
	p=pow(10,9)+7;
	cin>>n>>m;
	char a[n][m];
	long t[n][m];
	for(i=0;i<n;i++)
	{
	    for(j=0;j<m;j++)
	    {
	        cin>>a[i][j];
	    }
	}
	for(i=0;i<n;i++)
	{
	    for(j=0;j<m;j++)
	    {
	        if(i==0&&j==0)
	        {
	            if(a[i][j]=='#')
	            t[i][j]=0;
	            else
	            t[i][j]=1;
	        }
	        else if(i==0)
	        {
	            if(a[i][j]=='#')
	            t[i][j]=0;
	            else
	            t[i][j]=t[i][j-1];
	        }
	        else if(j==0)
	        {
	            if(a[i][j]=='#')
	            t[i][j]=0;
	            else
	            t[i][j]=t[i-1][j];
	        }
	        else 
	        {
	            if(a[i][j]=='#')
	            t[i][j]=0;
	            else
	            t[i][j]=(t[i-1][j]+t[i][j-1])%p;
	        }
	    }
	}
	cout<<t[n-1][m-1]<<endl;
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> data;
  vector<bool> t(w,false);
  rep(i,h){
    string s; cin >> s;
    bool flag=false;
    rep(j,w){
      if(s[j]=='.'){
      } else {
        flag = true;
        t[j] = true;
      }      
    }
    if(flag){data.emplace_back(s);}
  }
  
  rep(i,data.size()){
    rep(j,w)if(t[j]){cout<<data[i][j];}
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
idx = 0
a =  a.sort

double_tmp_sum = 0

0.upto(n-2) do |i|
  double_tmp_sum += 2 * a[i]

  idx = i + 1 if double_tmp_sum < a[i+1]
end

puts n - idx



Measured memory_bytes: 11256
#include <iostream>
using namespace std;
bool check(int a,bool ok[]){
    while(a>0){
        if(!ok[a%10]) return false;
        a/=10;
    }
    return true;
}
int main(){
    int n,k;
    cin >> n >> k;
    bool ok[10];
    fill_n(ok,10,true);
    int x;
    for(int i = 0;i<k;i++){
        cin >> x;
        ok[x] = false;
    }
    for(int i = n;true;i++){
        if(check(i,ok)){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
n = gets.to_i
list = []

n.times do 
  command, key = gets.split()
  if command == "insert"
    list.unshift(key)
  elsif command == "delete"
    next if list.index(key) == nil
    list.delete_at(list.index(key))
  elsif command == "deleteFirst"
    list.shift()
  else 
    list.delete_at(list.size - 1)
  end
end

puts list.join(" ")


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


int main() {
  int x,ans,a,i;
  cin >> x;
  a=(x-400)/200;
  ans=8-a;
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;
typedef pair<int,int> P;

int main()
{

    lint A,B,C,D;
    cin >> A >> B >> C >> D;

    lint ac,bc,ad,bd,acd,bcd;

    ac = (A-1)/C;
    bc = B/C;
    ad = (A-1)/D;
    bd = B/D;

    lint a, b, r, x, tmp;
    a = C;
    b = D;

    x = a * b;

    /* 自然数 a > b を確認・入替 */
    if(a<b){
      tmp = a;
      a = b;
      b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while(r!=0){
      a = b;
      b = r;
      r = a % b;
    }




    acd = (A-1)/(x/b);
    bcd = B/(x/b);

    //cout << ac << " " << bc << " " <<  ad << " " << bd << " " <<  acd << " " << bcd << endl;


    lint ans;
    ans = B - A + 1;
    ans -= (bc-ac) + (bd-ad) - (bcd-acd);

    cout << ans << endl;



}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int out = X;
		out -= A;
		out = out - B * (out / B);
		System.out.println(out);
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
long long a[200013],n,ans,j,h;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		for(j;j<n;j++)
		{
			if((h|a[j])!=h+a[j])break;else h=h+a[j],
			ans=ans+j-i+1;
		}
		h-=a[i];
	}
	cout<<ans;
}

Measured memory_bytes: 1920
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    E=[None]*n
    for i in range(n):
        a=int(input())
        XY=[tuple(map(int,input().split())) for _ in range(a)]
        E[i]=XY

    N=2**n
    ans=0
    for S in range(N):
        flag=True
        for i in range(n):
            if((S>>i)&1)==0: continue # 正直者のみを見る
            for x,y in E[i]:
                x-=1
                if((S>>x)&1)!=y:
                    flag=False
        if(flag):
            ans=max(ans,bin(S).count('1'))
    print(ans)
resolve()

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

using ll = long long;

int main(){

  int N,M,K;
  cin >> N >> M >> K;

  vector<int> a(N);
  vector<int> b(M);
  for(int i=0;i<N;i++) cin >> a[i];
  for(int i=0;i<M;i++) cin >> b[i];

  ll sum=0;
  for(int i=0;i<M;i++){
    sum+=b[i];
  }

  int ans=0;
  int j=M;
  for(int i=0;i<=N;i++){
    while(j>0 && sum>K){
      j--;
      sum-=b[j];
    }
    if(sum>K) break;
    ans=max(ans,i+j);
    if(i==N)break;
    sum+=a[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    int n;cin>>n;
    ves s(n);
    int ac=0,wa=0,tle=0,re=0;
    rep(i,n) {cin>>s[i];
        if(s[i]=="AC") ac++;
        else if(s[i]=="WA") wa++;
        else if(s[i]=="TLE") tle++;
        else if(s[i]=="RE") re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

struct pos{
  int x;
  int y;
  int d;
};

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<bool>> a(h,vector<bool>(w));
  char c;
  int sx,sy;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c;
      if(c=='#'){
        a[i][j]=1;
      }else if(c=='.'){
        a[i][j]=0;
      }else{
        a[i][j]=0;
        sx=j,sy=i;
      }
    }
  }
  vector<int> houkou={0,1,0,-1,0};
  vector<vector<bool>> arrived(h,vector<bool>(w,0));
  arrived[sy][sx]=0;
  queue<struct pos> bfs,bfs2;
  bfs.push({sx,sy,0});
  int nx,ny;
  struct pos now;
  int ans=100000;
  while(!bfs.empty()){
    now=bfs.front();
    bfs.pop();
    for(int i=0;i<4;i++){
      nx=now.x+houkou[i];
      ny=now.y+houkou[i+1];
      if(now.d==k){
        if(0<=nx&&nx<w&&0<=ny&&ny<h){
          if(nx==0||nx==w-1||ny==0||ny==h-1){
            ans=min(ans,2);
            continue;
          }
          if(!arrived[ny][nx]){
            arrived[ny][nx]=1;
            bfs2.push({nx,ny,k+1});
          }
        }
      }else{
        if(0<=nx&&nx<w&&0<=ny&&ny<h){
          if(nx==0||nx==w-1||ny==0||ny==h-1){
            ans=min(ans,(a[ny][nx]?2:1));
            continue;
          }
          if(!arrived[ny][nx]){
            arrived[ny][nx]=1;
            if(a[ny][nx]){
              bfs2.push({nx,ny,k+1});
            }else{
              bfs.push({nx,ny,now.d+1});
            }
          }
        }
      }
    }
  }
  while(!bfs2.empty()){
    now=bfs2.front();
    bfs2.pop();
    for(int i=0;i<4;i++){
      nx=now.x+houkou[i];
      ny=now.y+houkou[i+1];
      if(0<=nx&&nx<w&&0<=ny&&ny<h){
        if(nx==0||nx==w-1||ny==0||ny==h-1){
          ans=min(ans,(now.d+k)/k);
          continue;
        }
        if(!arrived[ny][nx]){
          arrived[ny][nx]=1;
          bfs2.push({nx,ny,now.d+1});
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2176
n=int(input())
s=[]
t=[]
for i in range(n):
    a,b=map(str,input().split())

    s.append(a)
    t.append(int(b))

x=str(input())
count=0
for i in range(n):
    if s[i]==x:
        count=i
        break
ans=0
count+=1

for i in range(count,n):
    ans+=t[i]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    int n, maxnum = 0, m = 0;
    cin >> n;
    string t;
    vector<string> s(n), ans;
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    for(int i = 0; i < n; ) {
        t = s[i];
        while(i < n && s[i] == t) {i++; m++;}
        if(m == maxnum) ans.push_back(t);
        if(m > maxnum) {
            maxnum = m;
            ans.clear();
            ans.shrink_to_fit();
            ans.push_back(t);
        }
        m = 0;
    }
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 15988
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (auto&& x : a) cin >> x;
	deque<int> d;
	for (int i = 0; i < n; i++) {
		int p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
		if (p == 0) d.push_front(a[i]);
		else d[p - 1] = a[i];		
	}
	cout << d.size() << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
     
    int main(){
        long long  a;
        long long  b;
        long long  n;
     
        scanf("%lld %lld %lld",&n,&a,&b);
        long long k=n/(a+b); //ciclosCompletos
        long long   mod=n%(a+b); //sobra
        long long nbas,res;
     

            
        if(mod<a)
            nbas = mod;
        else
            nbas = a;
     
        res = k*a + nbas;
     
        printf("%lld",res);
     
     
     
        return 0;
     
    }

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

#define ll long long

ll x, y;
ll a, b;

int main(){
	scanf("%lld%lld", &x, &y);
	while(!(x < 2 && y < 2)){
		y += x / 2;
		a += x / 2;
		x %= 2;
		std::swap(x, y);
		std::swap(a, b);
	}
	printf(a == b ? "Brown\n" : "Alice\n");
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
a = gets.split.map(&:to_i)
d = [0]

a.each_with_index do |aa, i|
  d << d[i] + aa
end

ans = (d[N] - d[1] * 2).abs
2.upto(N - 1) do |i|
  t = (d[N] - d[i] * 2).abs
  ans = t if t < ans
end
p ans


Measured memory_bytes: 18948
/*.....Bismillahir Rahmanir Rahim.....*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld long double
#define   pb push_back
#define  sz(x)  (int)x.size()
#define  ff first
#define  ss second
#define  pii  pair<int,int>
using namespace std;

int  gcd(int a,int b) {
	return  (b==0)? a: gcd(b,a%b);
}
bool palindrome(string s){
	int l=s.size()-1;
	for (int i=0,j=l;i<j;i++,j--){
		if (s[i]!= s[j]) return false;
	}
	return true;
}

inline void solve(){ 
	int  n; string s;
	cin >> s;
	n=s.size();
	bool ok=false;
	if ((n&1) && (palindrome(s))){
		while(1){
			if (palindrome(s.substr(0,(n-1)/2)))
				ok= true;
			if (!palindrome(s.substr(((n+3)/2)-1,(n-1)/2)))
				ok=false;
			break;
		}
	}
	if (ok) cout  << "Yes" ;
	else cout << "No";
}

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


Measured memory_bytes: 256
// AOJ ALDS1_6_C Quick Sort
// 2018.5.1 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char buf[20];
void mypr(int n)
{
	int i;
	if (!n) { pc('0'); return; }
	i = 0; while (n) buf[i++] = n%10 + '0', n/=10;
	while (i--) pc(buf[i]); 
}

typedef struct { char c; int a; int id; } DATA;

int partition(DATA *a, int lo, int hi)
{
	int i, j;
	int key;
	DATA t;
	
	key = a[hi].a, i = lo-1;
	for (j = lo; j < hi; j++) {
		if (a[j].a <= key) i++, t = a[i], a[i] = a[j], a[j] = t;
	}
	t = a[++i], a[i] = a[hi], a[hi] = t;
	return i;
}

void quick_sort(DATA *a, int lo, int hi)
{
	int mi;

	if (lo < hi) {
		mi = partition(a, lo, hi);
		quick_sort(a, lo, mi-1);
		quick_sort(a, mi+1, hi);
	}
}

DATA a[100002];

int main()
{
	int N, i, f;

	N = in();
	for (i = 0; i < N; i++) {
		a[i].c = gc(), gc();
		a[i].a = in(), a[i].id = i;
	}
	quick_sort(a, 0, N-1);
	f = 0; for (i = 1; i < N; i++) {
		if (a[i-1].a == a[i].a && a[i-1].id > a[i].id) { f = 1; break; }
	}
	puts(f? "Not stable": "Stable");
	for (i = 0; i < N; i++) {
		pc(a[i].c), pc(' '), mypr(a[i].a), pc('\n');
	}
	return 0;
}




Measured memory_bytes: 2716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

const ll MOD=1e9+7;

ll ad(ll x,ll y=0){
  return (x+y)%MOD;
}

ll mlt(ll x,ll y=1){
  return (x*y)%MOD;
}

int main(){
  ll n,t[100010],a[100010],m[100010]={},M[100010]={},ans=1;
  cin>>n;
  Fr(i,n) cin>>t[i];
  fr(i,n) cin>>a[i];
  t[0]=0;a[n]=0;
  Fr(i,n){
    M[i]=t[i];
    if(t[i]!=t[i-1]) m[i]=t[i];
    else m[i]=1;
  }
  iFr(i,n){
    M[i]=min(M[i],a[i-1]);
    if(a[i]!=a[i-1]) m[i]=max(m[i],a[i-1]);
  }
  Fr(i,n) ans=mlt(ans,max(0ll,M[i]-m[i]+1));
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long ll;
ll mod=1000000007;
ll BIG=1e15;

ll d[201][201];

int main(){
    int N,M,R; cin>>N>>M>>R;
    for(int i=0;i<201;i++){
        for(int j=0;j<201;j++) if(i!=j) d[i][j]=BIG;
    }
    vector<int> v(R);
    for(int i=0;i<R;i++) cin>>v.at(i);
sort(v.begin(),v.end());
    for(int i=0;i<M;i++){
        int A,B; cin>>A>>B;
        ll C; cin>>C;
        d[A][B]=C;
        d[B][A]=C;
    }
    for(int k=1;k<201;k++){
        for(int i=1;i<201;i++){
            for(int j=1;j<201;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    ll ans=BIG;
    do{
        ll kari=0;
        for(int i=0;i<R-1;i++) kari+=d[v.at(i)][v.at(i+1)];
        ans=min(kari,ans);
    }while(next_permutation(v.begin(),v.end()));
    cout<<ans<<endl;

}

Measured memory_bytes: 512
s = str(input())
mod = 10**9 + 7
n = len(s)

if s[0] == "?":
  ans = [1,1,1,1,1,1,1,1,1,1,0,0,0]
else:
  ans = [0,0,0,0,0,0,0,0,0,0,0,0,0]
  ans[int(s[0])] = 1


for i in s[1:]:
  dp = [0]*13
  for j in range(13):
    dp[j*10%13] = ans[j] % mod
  dp += dp
  if i == "?":
    for j in range(13):
      ans[j] = sum(dp[j+4:j+14])
  else:
    for j in range(13):
      ans[j] = dp[j+13-int(i)]
print(ans[5]%mod)

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

int main(){
  int n;

  while(true){
    cin >> n;
    if(n == 0) break;

    int w[n], c[n];

    for(int i = 0; i < n; i++){
      cin >> w[i] >> c[i];
    }

    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
        if(c[i] < c[j]) continue;
        swap(w[i], w[j]);
        swap(c[i], c[j]);
      }
    }

    int sum = 0;
    bool yesFlg = true;

    for(int i = 0; i < n; i++){
      sum += w[i];
      if(sum > c[i]){
        yesFlg = false;
        break;
      }
    }
    cout << (yesFlg ? "Yes" : "No") << endl;
  }
}

Measured memory_bytes: 1152
from math import floor, ceil
def Sum1to(n):
    return int((n + 1) * n / 2)
N = int(input())
finN = floor(N/15)
base = finN * 60 + 120 * Sum1to(finN - 1)
addn = sum([i for i in range(15*finN+1,N+1) if i % 3 != 0 and i % 5 != 0])
print(base + addn)

Measured memory_bytes: 9188
while True:
    n,a,b=map(int,raw_input().split())
    if n==a==b==0:break
    L=[True]*(n+1)
    for i in range(a):
        x=b*i
        if x>n:break
        while x<=n:
            L[x]=False
            x+=a
    print L.count(True)

Measured memory_bytes: 12300
#include<stdio.h>

long long int dp[87];
int main()
{
	int n;
	scanf("%d",&n);
	dp[0] = 2;
	dp[1] = 1;
	for (int i = 2; i <= n; i++)
	{
		dp[i] = dp[i-1] + dp[i-2];
	}
	printf("%lld",dp[n]);
	return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
E1 = [[] for _ in range(N)]
E2 = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E1[a-1].append((b-1, -c))
    E2[b-1].append((a-1, -c))

def bellman_ford(n, E, s=0):
    D = [1<<100] * n
    D[s] = 0
    f = 1
    k = 0
    while f:
        f = 0
        for i in range(n):
            for j, c in E[i]:
                if D[i] < 1<<100 and D[j] > D[i] + c:
                    D[j] = D[i] + c
                    f = 1
                    if k == N-1 and j == N-1: return (1, [])
        k += 1
        if k == N: return (0, D)
    return (0, D)

b, d = bellman_ford(N, E1)
if b:
    print("inf")
else:
    print(-d[-1])


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

int h, w, k;
int ans = 0;
char c[6][6];

void judge(int mask)
{
    int black = 0;
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            if((mask & (1 << i)) && (mask & (1 << (h+j))) && c[i][j] == '#')
            {
                black++;
            }
        }
    }
    if(black == k) ans++;
    return;
}

int main() {
    string s;
    cin >> h >> w >> k;
    for(int i=0; i<h; i++)
    {
        cin >> s;
        for(int j=0; j<w; j++)
        {
            c[i][j] = s[j];
        }
    }
    for(int i=0; i<pow(2,(h+w)); i++)
    {
        judge(i);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4024
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a, b, answer = 0;
		String operator;

		while (true) {
			a = scanner.nextInt();
			operator = scanner.next();
			b = scanner.nextInt();

			if (operator.equals("+"))
				answer = a + b;
			else if (operator.equals("-"))
				answer = a - b;
			else if (operator.equals("*"))
				answer = a * b;
			else if (operator.equals("/"))
				answer = a / b;
			else if (operator.equals("?"))
				break;

			System.out.println((int) answer);
		}
	}
}

Measured memory_bytes: 26272
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int N, i = 1;
	cin >> N;
	while(i * i <= N) i++;
	cout << (i - 1) * (i - 1) << endl;
}

Measured memory_bytes: 256
/*
Problem : https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_f
Algorithm : dp
Status : AC
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;

const int MAXN = 2005;
const int MOD = 998244353;

int n,pre[MAXN * 2],dp[MAXN * 2][MAXN * 2];
char s[MAXN];

int main(){
    scanf("%s",s + 1);
	n = strlen(s + 1);
    for(int i = 1;i <= n;i++) 
	    pre[i] = pre[i - 1] + (s[i] - '0');
    for(int i = n + 1;i <= n * 2;i++)
	    pre[i] = pre[i - 1];
    dp[0][0] = 1;
    for(int i = 1;i <= n * 2;i++){
    	int l = max(pre[i] - i,0);
    	int r = min(pre[i],i);
        for(int j = l;j <= r;j++) {
            if(j != 0) 
			    dp[i][j] = dp[i - 1][j - 1];
            if(i > j)
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
        }
    }
    printf("%d\n",dp[n * 2][pre[n]]);
}


Measured memory_bytes: 61440
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef gp_hash_table < int, int > fast;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test();

int main() {
    fast_io();
    cout << fixed << setprecision(15);
    test();
    return 0;
}

void test() {
    int a, b;
    cin >> a >> b;
    if ((a + b) & 1) {
        cout << "IMPOSSIBLE\n";
    } else {
        cout << abs(a + b) / 2 << "\n";
    }
}


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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))
#define Ssort(v) sort((v).begin(),(v).end(),[](auto &left,auto &right){return left.second<right.second;})

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin>>s;
    ll n=Size(s);
    ll res=nCr(n,2)+1;
    vl A(26,0);
    rep(i,n)A[s[i]-'a']++;
    rep(i,26)res-=nCr(A[i],2);
    cout<<res<<endl;
}

Measured memory_bytes: 3788
from collections import defaultdict as dd
from sys import exit
import math
n, m = map(int, input().split())
dic = dd(int)

#M=1
if m == 1:
    print(1)
    exit()

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(2, math.ceil(m**0.5) + 3):
    while m % i == 0:
        m //= i
        dic[i] += 1
if m != 1:
    dic[m] = 1
#print(dic)

ans = 1
mod = 10**9 + 7
for count in dic.values():
    ans *= combinations_count(count + n - 1, n-1) % mod

print(ans % mod)

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

const int MAXN = 1e5 + 10;

long long dp[MAXN];

int main(){	
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	memset(dp,0,sizeof dp);
	int n,w;
	cin >> n >> w;
	for(int i = 1; i <= n; i++){
		int wi,vi;
		cin >> wi >> vi;
		for(int x = w; x >= 1; x--){
				if(x >= wi) dp[x] = max(dp[x], dp[x-wi] + vi); 
		}
	}
	long long M = 0;
	for(int i = 1; i <= w; i++){
		M = max(M, dp[i]);
	}
	cout << M << endl;
	return 0;
}


Measured memory_bytes: 4448
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define qwq(x) cerr<<"# "<<#x<<" = "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned long long u64;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int S=(1<<26)+5,N=105,mod=998244353;
int f[S],g[N][N],h[N],a[N],n;
unordered_map<u64,int> F;
char s[N];

int fix(int x){
	return x>=mod?x-mod:x;
}

int solve(u64 s,int n){
	if(n<=1)return (s&1)+1;
	if(n<=25&&f[s|(1<<n)])return f[s|(1<<n)];
	if(n>25&&F.count(s|(1ll<<n)))return F[s|(1ll<<n)];	
	int res=solve(s>>1,n-1);
	if(s&1)res=fix(res+res);
	int suf[n+1];
	fill(suf,suf+n+1,-1);
	rep(len,1,n/2){
		u64 st=(1ll<<len)-1,las=-1; int ans=0;
		for(int p=0,k=1;p+len<=n;p+=len,k++){
			st&=s>>p;
			if(k>=2){
				if(st!=las)ans=solve(st,len);
				if(suf[p+len]==-1)
					suf[p+len]=solve(s>>(p+len),n-p-len);
				las=st,res=(res+(ll)ans*suf[p+len])%mod;
			}
		}
	}
	if(n<=25)f[s|(1<<n)]=res;
	else F[s|(1ll<<n)]=res;
	return res;
}

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	rep(i,1,n)a[i]=s[i]-'0',g[i][i]=a[i]+1;
	rep(len,1,n/2)
		rep(l,1,n-2*len+1){
			u64 full=(1ll<<len)-1,st=(1ll<<len)-1,las=-1; int ans=0;
			for(int p=l,k=1;p+len<=n+1;p+=len,k++){
				REP(i,len)st&=full-(1ll<<i)+((1ll*a[p+i])<<i);
				if(k>=2){
					if(st!=las)ans=solve(st,len);
					las=st,g[l][p+len-1]=fix(g[l][p+len-1]+ans);
				}
			}
		}
	h[0]=1;
	rep(i,1,n)rep(j,0,i-1)
		h[i]=(h[i]+(ll)h[j]*g[j+1][i])%mod;
	cout<<h[n]<<endl;
	return 0;
}

Measured memory_bytes: 262656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int coin = sc.nextInt();
		int m = (n % 500);
		
		if (coin >= m) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 21332
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int N,K;

struct Combination{
    int MAX_N;
    int MOD;
    int *fac, *finv, *inv;
    Combination(int max_n,int MOD): MAX_N(max_n+1),MOD(MOD){ //make table
        fac = new int[MAX_N];finv = new int[MAX_N];inv = new int[MAX_N];
        fac[0]=fac[1]=1;
        finv[0]=finv[1]=1;
        inv[1]=1;
        for (int i = 2; i < MAX_N; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    int COM(int n,int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    void free_COM(){
        delete[] fac;
        delete[] finv;
        delete[] inv;
    }
    
};

signed main(){
    scanf("%lld %lld",&N,&K);
    Combination CMB(N,mod);
    int ans=0;
    rep(i,min(K+1,N)){//0の部屋はK個またはN-1個まで
        ans+=(CMB.COM(N,i)*CMB.COM(N-1,i))%mod;
        ans%=mod;
    }
    printf("%lld\n",ans);
    CMB.free_COM();
    return 0;
}

Measured memory_bytes: 7520