akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	map<long , bool> mp = {};

	rep(i,0,n){
		long a;
		cin >> a;
		
		if(mp[a] == true)
			mp[a] = false;
		else
			mp[a] = true;
	}
	
	int ans = 0;
	for(auto itr = mp.begin() ; itr != mp.end() ; ++itr ){
		if(itr->second)
			ans++;
	}
	
	P(ans);
	ret 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)



int main(){
    int n,res; cin >> n;
    if(n<105)res = 0;
    else if(n<135)res = 1;
    else if(n<165)res = 2;
    else if(n<189)res = 3;
    else if(n<195)res = 4;
    else res = 5;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int main()
{
	ll k;
	cin >> k;
	int n = 50;
	cout << n << endl;
	ll nok = k%n;
	for(int i=0; i<nok; ++i){
		cout << (n-1) - k + (n+1) * (k/n+1) << ' ';
	}
	for(int i=nok; i<n; ++i){
		cout << (n-1) - k + (n+1) * (k/n) << ' ';
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
bool vis[5];
char s[5];
int main() {
	scanf("%s",s);
	for(int i=0;i<=2;i++)
		vis[s[i]%3]=true;
	for(int i=0;i<=2;i++)
		if(vis[i]==false) {
			printf("No\n");
			return 0;
		}
	printf("Yes\n");
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  int i=1;
  int temp=0;
  while(temp<N){
    temp=temp+i;
    i++;
  }
  if(temp==N){
    for(int j=1;j<i-1;j++){
      cout<<j<<" ";
    }
    cout<<i-1<<endl;
    return 0;
  }
  
  for(int j=1;j<i-1;j++){
    if(j!=(temp-N)){
      cout<<j<<" ";
    }
  }
  cout<<i-1<<endl;
  return 0;

}

     
    
    
    

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

int main() {

int a,b,ab,x,y;

cin >> a >> b >> ab >> x >> y ;

int ans=0;
//まず、AかBのどちらかを満たすまで買う

ans=min(min(x,y)*(a+b),min(x,y)*2*ab);



//そこから、ABで買うかAorBで買うか決める
if(x>y)ans+=min((x-y)*a,(x-y)*2*ab);
else {ans+=min((y-x)*b,(y-x)*2*ab);}

cout <<ans <<endl;
return 0;

}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[input() for i in range(h)]
for i in range(h):
  l=""
  for j in range(w):
    if s[i][j]=="#":
      l+="#"
    else:
      l+=str(sum([t[max(0,j-1):min(w,j+2)].count("#") for t in s[max(0,i-1):min(h,i+2)]]))
  print(l)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}
 
 
int main() {
    int n,k,r,s,p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    map<char, int> mp;
    mp['r'] = r;
    mp['s'] = s;
    mp['p'] = p;
    mp['e'] = 0;
    int cnt = 0;
    string ss = t;
    rep(i, ss.size()) {
        if (t[i] == 'r') {
            ss[i] = 'p';
        }
        if (t[i] == 's') {
            ss[i] = 'r';
        }
        if (t[i] == 'p') {
            ss[i] = 's';
        }
    }
    rep(i, ss.size()) {
        if (ss[i] == ss[i-k] && i-k >= 0) {
            ss[i] = 'e';
        }
    }
    rep(i,ss.size()) {
        cnt += mp[ss[i]];
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 512
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

K, S = inm()


def solve():
    count = 0
    for x in range(K + 1):
        for y in range(K + 1):
            z = S - x - y
            if 0 <= z <= K:
                count += 1
    return count


print(solve())


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

int main() {
  long n,m;
  cin>>n>>m;
  if(n%m!=0){
    cout<<1<<endl;
  }
  else{
    cout<<0<<endl;
  }
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    int card_num[100001] = {};
    int cnt[M] = {};
    int possible_pair[M] = {};
    rep(i, N){
        int a; cin >> a;
        card_num[a]++;
        if(card_num[a] % 2 == 0) possible_pair[a%M]++;
        cnt[a%M]++;
    }
    int ans = 0;
    if(M % 2 == 0) ans += cnt[M/2]/2;
    ans += cnt[0]/2;
    int ulim = (M-1)/2;
    for(int i = 1; i <= ulim; i++){
        //iとM-iが組む
        int p = min(cnt[i], cnt[M-i]);
        ans += p;
        cnt[i] -= p; cnt[M-i] -= p;
        ans += min(cnt[i]/2, possible_pair[i]);
        ans += min(cnt[M-i]/2, possible_pair[M-i]);
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


// 常に貪欲に選択する

vector<vector<int>> s(400,vector<int>(27));
vector<int> c(27);
int D;

int cal_score(vector<int> t){
  int p(0);
  vector<int> l(27,0);
  for(int i(1);i<=D;i++){
    p += s[i][t[i]];
    l[t[i]] = i;
    for(int j(1);j<=26;j++){
      p -= c[j]*(i-l[j]);
    }
  }
  return p;
}

void input(){
  cin>>D;
  for(int i(1);i<27;i++){
    cin>>c[i];
  }
  for(int i(1);i<=D;i++){
    for(int j(1);j<=26;j++){
      cin>>s[i][j];
    }
  }
}

vector<int> cal_greedy(){
  vector<int> t(D+1);
  int nowp(0);
  vector<int> l(D,0);
  for(int i(1);i<=D;i++){
    int maxj(0),maxp(-1e9);
    for(int j(1);j<=26;j++){
      //i日目がj番目の場合
      int tmp(nowp);
      tmp += s[i][j];
      for(int k(1);k<=26;k++){ //ここ一度和を計算しておけば、何回も引くものを計算しなくても良い
        if(k == j) continue;
        tmp -= c[k]*(i - l[k]);
      }
      if(maxp < tmp) {
        maxj = j;
        maxp = tmp;
      }
    }
    t[i] = maxj;
    // 貪欲的にmaxj番目と決める
    nowp += s[i][maxj];
    l[maxj] = i;
    for(int j(1);j<=26;j++){
      nowp -= c[j]*(i - l[j]);
    }
  }
  return t;
}

int main(){
  clock_t start = clock(); 
  input();
  vector<int> t = cal_greedy();

  double time;
  int cnt(0);
  int nowp = cal_score(t);
  while(time < 1950){
    int d = max(rand()%(D+1),1);
    int q = max(rand()%27+1,1);
    int old = t[d];
    t[d] = q;
    int next_score = cal_score(t);
    if(nowp >= next_score){
      t[d] = old;
    }else{
      nowp = next_score;
    }
    cnt++;
    clock_t now = clock();
    time = static_cast<double>(now - start) / CLOCKS_PER_SEC * 1000.0;
    //cout << "point:" << max(1000000+nowp,0) << " " << "row_point:" << nowp << endl;
  }
  // cout << "ランダムに変更回数:" << cnt << endl;
  // printf("time %lf[ms]\n", time);

  for(int i(1);i<=D;i++){
    cout << t[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3724
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll a, b; cin >> a >> b;
    if(2*a <= b&&b <= 4*a){
        if(b%2 == 0){
        prt("Yes");
        }
        else{
            prt("No");
        }
    }else{
        prt("No");
    }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
map<long long,long long> mp;
int main()
{
	srand(time(0));
	long long w[30];
	for(int i=1;i<=26;i++) w[i]=w[i-1]+rand()%10000000007+998244353;
	int n;
	cin>>n;
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		string s;
		long long tot=0;
		cin>>s;
		for(int i=0;i<s.length();i++) tot+=w[s[i]-'a'+1]*(s[i]-'a'+1);
		ans+=mp[tot];
		mp[tot]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 6528
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val a = sc.next().toLong()
        pw.println(a + a * a + a * a * a)
    }
}


Measured memory_bytes: 36416
n = int(input())
m = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
dp = [10**6 for i in range(100001)]
for mi in m:
    dp[mi] = 1
for i in range(1,100001):
    for mi in m:
        if i+mi <= 100000:
            dp[i+mi] = min(dp[i+mi],dp[i]+1)
        else:
            break
print(dp[n])


Measured memory_bytes: 3912
n = int(input())
ll = [int(w) for w in input().split()]
ll.sort()

ans = 0
if n < 3:
    print(ans)
    exit()
for i in range(n):
    for j in range(i+1, n):
        if ll[i] == ll[j]:
            continue
        for k in range(j+1, n):
            if ll[j] == ll[k]:
                continue
            if ll[i]+ll[j] > ll[k]:
                ans += 1


print(ans)


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

using namespace std;

int a[200006];

int main()
{
    int n,v;
    long long j=0;
    cin>>n;
    for(int i=0;i<n;i++)
        {
        cin>>v;
        a[i]=v;
        }
    if(a[0]!=0)
        {
        cout<<-1;
        return 0;
        }
    for(int i=1;i<n;i++)
        {
        //////
        if (a[i]-a[i-1]==1)
            {
			j++;
            }
		//////
		else if(a[i]-a[i-1]<1)
            {
			j=j+a[i];
            }
        //////
        else if(a[i]-a[i-1]>1)
            {
            cout<<-1;
            return 0;
            }
        }
    cout<<j;
}


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

int main()
{
	long long len=0,n,a,b,x=0;
	scanf("%lld%lld%lld",&n,&a,&b);
	n--;scanf("%d",&x);
	while (n--)
	{
		long long y;
		scanf("%lld",&y);
		len+=min((y-x)*a,b);
		x=y;
	}
	printf("%lld\n",len);
	return 0;;
}

Measured memory_bytes: 256
def check_p(s):
    return s == s[::-1]

S = input().strip()
if len(S)%2 == 0:
    print('No')
else:
    if not check_p(S):
        print('No')
    elif not check_p(S[:(len(S) - 1)//2]):
        print('No')
    elif not check_p(S[((len(S) + 3)//2) - 1:]):
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll mod = 1000000007LL;

int main() {
	int N; cin >> N;
	vector<int> c;
	while (N--) {
		int ci; cin >> ci;
		if (c.size() == 0 || c[c.size() - 1] != ci)
			c.push_back(ci);
	}
	N = c.size();
	vector<ll> dp(N + 1, 0);
	map<int, ll> color_cnt;
	dp[0] = 1; color_cnt[c[0]] = 1;
	for (int i = 1; i <= N; ++i) {
		int ci = c[i - 1];
		dp[i] = color_cnt[ci];
		if (i < N) {
			int nx_c = c[i];
			color_cnt[nx_c] = (color_cnt[nx_c] + dp[i]) % mod;
		}
	}
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 15092
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
//#define bint int1024_t
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define F first
#define pll pair<ll,ll>
#define S second
#define pi 3.1415926536
#define mod int(1e9+7)
#define mp make_pair
//ios_base::sync_with_stdio(false);cin.tie(NULL);
#define testcases ll t; cin>>t; while(t--)

using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

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

    ll n,k,ans=0;
    cin>>n>>k;
    vect v(n);
    for(ll& i:v) cin>>i;

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

    cout<<accumulate(v.begin(),v.begin()+k,0);

    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  vector<pair<int,int>> X;
  rep0(i, N) {
    int x, l; cin >> x >> l;
    X.push_back(make_pair(x+l, x-l));
  }
  
  sort(all(X));
  int ans = 1;

  int M = X[0].first;
  rep1(i, N) {
    if(X[i].second >= M) {
      ans++;
      M = X[i].first;
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 2548
N, M, C = map(int, input().split())

B = list(map(int, input().split()))
num = 0

for _ in range(N):
    A = list(map(int, input().split()))
    r = 0
    for i in range(M):
        r += A[i] * B[i]
    r += C
    if r > 0:
        num += 1
print(num)

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

ll gcd(ll x,ll y) {
	ll r;
	if(x<y) swap(x,y);
	while(x%y!=0) {
		r=x;x=y;y=r%y;
	}
	return y;
}

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

	ll n,x;cin>>n>>x;
	cout<<3*(n-gcd(n,x))<<endl;

	return 0;
}


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

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

  int ans_a = 100 * A, ans_b = 0;
  for (int a = 0; 100 * a * A <= F; ++a) {
    for (int b = 0; 100 * (a * A + b * B) <= F; ++b) {
      for (int c = 0;
           c * C <= (a * A + b * B) * E && 100 * (a * A + b * B) + c * C <= F;
           ++c) {
        for (int d = 0; c * C + d * D <= (a * A + b * B) * E &&
                        100 * (a * A + b * B) + c * C + d * D <= F;
             ++d) {
          int ei = 100 * (a * A + b * B);
          int beet = (c * C) + (d * D);
          if (ans_b * (ei + beet) < beet * (ans_a + ans_b)) {
            ans_a = ei;
            ans_b = beet;
          }
        }
      }
    }
  }

  cout << ans_a + ans_b << " " << ans_b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	string S;
	cin >> S;
	ll a = 0, b = 0, c = 0;
	N = S.length();
	for (i = 0; i < N; i++) {
		if (S[i] == 'a') a++;
		else if (S[i] == 'b') b++;
		else c++;
	}
	if (N <= 2 && a < 2 && b < 2 && c < 2) cout << "YES";
	else if (a == 0 || b == 0 || c == 0) cout << "NO";
	else {
		ll P = max(a, max(b, c));
		ll Q = min(a, min(b, c));
		if (P > Q + 1) cout << "NO";
		else cout << "YES";
	}
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

string in;
int pos;
int p,q,r;

int formula(){
  if(isdigit(in[pos])){
    return in[pos++]-'0';
  }

  switch(in[pos]){
  case 'P':++pos; return p;
  case 'Q':++pos; return q;
  case 'R':++pos; return r;
  }

  if(in[pos]=='-'){
    ++pos;
    return 2-formula();
  }
  ++pos;
  int a=formula();
  char cc=in[pos++];
  int b=formula();
  pos++;
  if(cc=='+'){
    if(a==2 || b==2)return 2;
    if(!a && !b)return 0;
    return 1;
  }
  if(!a || !b)return 0;
  if(a==2 && b==2)return 2;
  return 1;
}


main(){
  while(cin>>in){
    if(in==".")break;
    int ans=0;
    for(p=0;p<3;p++)for(q=0;q<3;q++)for(r=0;r<3;r++){
      pos=0;
      if(formula()==2)++ans;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if(a<b){
		cout << "a < b" << endl;
	}
	else if(a==b){
		cout << "a == b" << endl;
	}
	else {
		cout << "a > b" << endl;
	}
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll x;
	cin>>x;
	map<ll,ll> map;
	map[0]=0;
	for(ll i=1;;i++){
		ll y=pow(i,5);
		if(y>1e18){
			break;
		}
		map[y]=i;
		map[-y]=-i;
	}
	
	std::map<ll,ll> ::iterator it,it2;
	for(ll i=-3981;;i++){
		ll y=pow(i,5);
		ll z=y-x;
		it=map.find(y);
		it2=map.find(z);
		if(it!=map.end()&&it2!=map.end()){
			ll a=map[y];
			ll b=map[z];
			
			ll p1=pow(a,5)-pow(b,5);
			if(p1==x)
				cout<<a<<" "<<b<<endl;
			else
				cout<<b<<" "<<a<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 4644
#include <bits/stdc++.h>
#define ll long long
#define MAX 500005
using namespace std;

template<typename T>
void read(T &n){
    n = 0;
    T f = 1;
    char c = getchar();
    while(!isdigit(c) && c != '-') c = getchar();
    if(c == '-') f = -1, c = getchar();
    while(isdigit(c)) n = n*10+c-'0', c = getchar();
    n *= f;
}
template<typename T>
void write(T n){
    if(n < 0) putchar('-'), n = -n;
    if(n > 9) write(n/10);
    putchar(n%10+'0');
}

int n, m;

int main()
{
    cin >> n >> m;
    cout << n*(n-1)/2+m*(m-1)/2 << endl;

    return 0;
}

Measured memory_bytes: 256
cards = {
        'S': [0 for _ in range(13)],
        'H': [0 for _ in range(13)],
        'C': [0 for _ in range(13)],
        'D': [0 for _ in range(13)],
}
n = int(input())
for _ in range(n):
    (s, r) = input().split()
    cards[s][int(r) - 1] = 1
 
for s in ('S', 'H', 'C', 'D'):
    for r in range(13):
        if cards[s][r] == 0:
            print(s, r + 1)

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

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL);


#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
typedef long long int llint;

int main() {
    fast_io
    int n;
    cin >> n;
    n = n%10;
    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon\n";
    if(n == 0 || n==1 || n == 6 || n == 8) cout << "pon\n";
    if(n == 3) cout << "bon\n";

}


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

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

using namespace std;

int main(){
	fastio
	int n;
	cin >> n;
	int arr[n];
	for(auto &x : arr) cin >> x;
	ll sum = 0;
	for(int x : arr) sum ^= x;
	for(int x : arr) cout << (sum^x) << " ";
}	

Measured memory_bytes: 4380
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a="maerd"
b="remaerd"
c="esare"
d="resare"
s="".join(list(reversed(SI())))
n=len(s)
ind=0
while ind<n:
    #print(ind)
    if s[ind:ind+5]==a or s[ind:ind+5]==c:
        ind+=5
    elif s[ind:ind+6]==d:
        ind+=6
    elif s[ind:ind+7]==b:
        ind+=7
    else:
        print("NO")
        sys.exit()
    #print(ind)
if ind==n:
    print("YES")

Measured memory_bytes: 4336
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int p;
			int[][] map = new int[n][31];
			for(int i=0;i<n;i++){
				p = sc.nextInt();
				for(int j=0;j<p;j++) map[i][sc.nextInt()]++;
			}
			
			boolean flag = false;
			boolean check = true;
			int[] temp = new int[n];
			int[][] list = new int[n][n];
			ArrayDeque<Integer> que = new ArrayDeque<Integer>();
			for(int i=1;i<=30;i++){
				for(int j=0;j<n;j++){
					if(map[j][i]>0){
						que.offer(j);
						list[j][j]++;
						for(int k=0;k<n;k++) temp[k] += list[j][k];
					}
				}
				while(que.size()!=0){
					p = que.poll();
					list[p] = temp.clone();
				}
				
				check = false;
				for(int j=0;j<n;j++){
					if(temp[j]==0){
						check = true;
						break;
					}
				}
				
				if(check==false){
					System.out.println(i);
					break;
				}
				
				Arrays.fill(temp, 0);
			}
			if(check==true) System.out.println(-1);
		}	
	}	
}

Measured memory_bytes: 83660
#include <stdio.h>
#include <string.h>


int main() {

  char key[] = {'y','h','n','u','j','m','i','k','o','p','l','\0'};
  char str[33];
  int hand,cha,i,j;




  while(1) {

  scanf("%s",str);

  if(str[0] == '#') break;


  for(i=0;i<strlen(key); i++) {

    if(key[i] == str[0]) break;

  }

  //rgiht:0 left:1
  if(strlen(key) == i) hand = 1;
  else hand = 0;

  //printf("hand = %d\n",hand);

  cha = 0;
  for(i=1;i<strlen(str);i++) {
    
    for(j=0;j<strlen(key);j++) {
      
      if(hand ==  0 && str[i] == key[j]){
	break;
      } else if(hand ==  1 && str[i] == key[j]){
	hand = 0;
	cha++;
	break;
      }
    }
    if(hand == 0 && strlen(key) == j) {
      cha++;
      hand = 1;
    }

  }
    
  
  printf("%d\n",cha);

  }



  return 0;

}

Measured memory_bytes: 540
import java.io.*;

class Main{ 
public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[ ] str_div = br.readLine().split(" ");
        int x = Integer.parseInt(str_div[0]);
        int y = Integer.parseInt(str_div[1]);
        int z = Integer.parseInt(str_div[2]);
        if(x < y && y< z )
        System.out.println("Yes");
        else
        System.out.println("No");
 }
}
     

Measured memory_bytes: 17084
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(10);
	ll n;
	cin>>n;
	set<string> s;
	for(int a=0;a<n;a++)
	{
		string ss;
		cin>>ss;
		s.insert(ss);
	}
	cout<<s.size();
	return 0;
}

Measured memory_bytes: 19120
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;

int main () {

    int A,B;
    cin >> A >> B;

    for (int i = 1; i <= 3; i++) {
        if ((A * B * i) % 2 == 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

int n;
string s;


int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n >> s;

  int wc = 0;
  forn (i,n) {
    if (s[i] == '.') wc++;
  }

  int res = wc;

  int wb = 0;
  forn (i,n) {
    if (s[i] == '.') wc--;
    else wb++;

    chmin(res, wc+wb);
  }

  cout << res << "\n";


  return 0;
}


Measured memory_bytes: 640
S = list(input())

s = set(S)

ans = 1000
for w in s:
    old = S.copy()
    cnt = 0
    while True:
        if len(set(old)) == 1:
            ans = min(ans, cnt)
            break
        new = []
        cnt += 1
        for i in range(len(old) - 1):
            if old[i] == w or old[i + 1] == w:
                new.append(w)
            else:
                new.append(old[i])

        old = new.copy()

print(ans)


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

LL A, B, C, D;
map<LL, LL> memo;
LL solve(LL N) {
    if (N == 0) return 0;
    if (N == 1) return D;
    if (memo.count(N)) return memo[N];
    LL l2 = (N/2)*2;
    LL r2 = ((N+1)/2)*2;
    LL l3 = (N/3)*3;
    LL r3 = ((N+2)/3)*3;
    LL l5 = (N/5)*5;
    LL r5 = ((N+4)/5)*5;

    LL res = 1e18;
    if (N < res/D) res = N*D;
    res = min(res, llabs(l2-N)*D + A + solve(l2/2));
    res = min(res, llabs(r2-N)*D + A + solve(r2/2));

    res = min(res, llabs(l3-N)*D + B + solve(l3/3));
    res = min(res, llabs(r3-N)*D + B + solve(r3/3));

    res = min(res, llabs(l5-N)*D + C + solve(l5/5));
    res = min(res, llabs(r5-N)*D + C + solve(r5/5));

    memo[N] = res;

    return res;
}

int main() {
    int T;
    cin >> T;
    for (int t = 0; t < T; t++) {
        memo.clear();
        LL N;
        cin >> N;
        cin >> A >> B >> C >> D;
        cout << solve(N) << "\n";
    }
}


Measured memory_bytes: 4440
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  const int nmax = 100; 
  int d[nmax];
  int cmp = 0;

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

  int cnt[nmax];
  
  for(int i = 0; i < cmp; i++) cnt[i] = 0;
  
  for(int i = 0; i < n; i++) cnt[d[i] - 1]++;
  
  int sum = 0;
  
  for(int i = 0; i < cmp; i++) 
    if(cnt[i] > 0) sum++;
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

vint G[100010];

struct UnionFind{
    vint v;
    UnionFind(int n){ v.assign(n,-1); }
    int  find(int x){ return v[x]<0? x:v[x]=find(v[x]); }
    void unite(int x,int y){
        x=find(x),y=find(y); if(x==y) return;
        if(v[x]>v[y]) swap(x,y); v[x]+=v[y],v[y]=x;
    }
    int  size(int x){ return -v[find(x)]; }
    bool same(int x,int y){ return find(x)==find(y); }
    bool root(int x){ return v[x]<0; }
};

signed main()
{   
    int N,M; cin>>N>>M;
    vint a(M),b(M);
    REP(i,M){
        cin>>a[i]>>b[i];
        a[i]--; b[i]--;
    }

    vint ans(M+1);
    ans[M-1]=N*(N-1)/2;

    UnionFind tree(N);
    for(int i=M-2;i>=0;i--){
        if(tree.same(a[i+1],b[i+1])){
            ans[i]=ans[i+1];
        }
        else{
            ans[i]=ans[i+1]-tree.size(a[i+1])*tree.size(b[i+1]);
            tree.unite(a[i+1],b[i+1]);
        }
    }
    REP(i,M) cout<<ans[i]<<endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  // ここにプログラムを追記
  int count = 0;
  
  bool hantei = true; 
  
  while( hantei ) {
  
  for (int i = 0; i < N; i++) {
    if ( A.at(i) % 2 != 0 )
      hantei = false;
  }
  
  for (int i = 0; i < N; i++) {
    A.at(i) /= 2;
  }
    if ( hantei ) count++;
  }
  
  cout << count << endl;
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef vector<int> vi;
typedef long long LL;
template<typename T>
inline void read(T &x){
	int ch = getchar(); x = 0;
	bool f = false;
	while((ch < '0' || ch > '9') && ch != '-') ch = getchar();
	if(ch == '-'){f = true; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
	if(f) x = -x;	
}
int n, k;
vi a[6], A;
inline vi inv(const vi &p){
	vi q(n);
	for(Rint i = 0;i < n;++ i) q[p[i]] = i;
	return q;
}
inline vi mul(const vi &p, const vi &q){
	vi r(n);
	for(Rint i = 0;i < n;++ i) r[i] = p[q[i]];
	return r;
}
inline vi ksm(vi a, int b){
	vi res(n);
	for(Rint i = 0;i < n;++ i) res[i] = i;
	while(b){
		if(b & 1) res = mul(res, a);
		a = mul(a, a); b >>= 1;
	}
	return res;
}
int main(){
	read(n); read(k); -- k;
	a[0].resize(n); for(Rint i = 0;i < n;++ i) read(a[0][i]), -- a[0][i];
	a[1].resize(n); for(Rint i = 0;i < n;++ i) read(a[1][i]), -- a[1][i];
	for(Rint i = 2;i < 6;++ i) a[i] = mul(a[i - 1], inv(a[i - 2]));
	if(k < 6){for(Rint i = 0;i < n;++ i) printf("%d ", a[k][i] + 1); return 0;}
	A = ksm(mul(mul(a[1], inv(a[0])), mul(inv(a[1]), a[0])), k / 6);
	A = mul(mul(A, a[k % 6]), inv(A));
	for(Rint i = 0;i < n;++ i) printf("%d ", A[i] + 1); 
}

Measured memory_bytes: 5872
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define PI 3.14159265359
static const int INF = 1e9+7;
typedef long long ll;
using namespace std;
int main()
{

    string s;
    cin>>s;
    string ans;
    int n=s.length();
    rep(i,s.size())
    {
        if(s[i] == 'B' && ans.size()>0) ans.erase(ans.end()-1,ans.end());
        else if(s[i] != 'B') ans += s[i];
    }

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


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

int main()
{
	int N, M;
	std::unordered_multimap<int, int> XY;

	std::cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int x, y, z;
		std::cin >> x >> y >> z;
		--x;
		--y;
		XY.insert({x, y});
		XY.insert({y, x});
	}

	std::unordered_set<int> rest;
	for (int i = 0; i < N; ++i) {
		rest.insert(i);
	}

	int result = 0;
	while (!rest.empty()) {
		++result;
		std::stack<int> q;
		q.push(*rest.begin());
		rest.erase(rest.begin());
		while (!q.empty()) {
			int n = q.top();
			q.pop();
			auto er = XY.equal_range(n);
			for (auto it = er.first; it != er.second; ++it) {
				if (rest.find(it->second) != rest.end()) {
					q.push(it->second);
					rest.erase(it->second);
				}
			}
		}
	}

	std::cout << result << "\n";
}


Measured memory_bytes: 13000
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		String ans = "NA";
		int first = N / 100;
		int second = N % 100;
		if (isMM(first) && isMM(second)) {
			ans = "AMBIGUOUS";
		} else if (isMM(first)) {
			ans = "MMYY";
		} else if (isMM(second)) {
			ans = "YYMM";
		}

		System.out.println(ans);





		reader.close();

	}
	static boolean isMM(int num) {
		return num >= 1 && num <= 12;
	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <algorithm>

using namespace std;

int main() {
	string S;
	cin >> S;
	if (S.substr(0, 4) == "YAKI") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int x=s.size();
  int a,b;
  
  for(int i=0;i<x;i++){
    if(s[i]=='A'){
      a=i;
      break;
    }
  }
  for(int i=x-1;i>=0;i--){
    if(s[i]=='Z'){
      b=i;
      break;
    }
  }
  
  cout << b-a+1 << endl;

}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<bitset>
#include<map>
#include<vector>
#include<set>
#define ll long long
#define db double
#define si short int
#define mem(a) memset(a,0,sizeof(a))
#define maxn 105
#define maxm
#define inf 0x7fffffff
#define mod
#define eps
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
ll read(){
	ll a=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){a=a*10+c-'0';c=getchar();}
	return a*f;
}
char s[maxn];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%s",s+1);
	ll ans=0,n=strlen(s+1);
	for(int i=1;i<n-i+1;i++){
		if(s[i]!=s[n-i+1])ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main()
{
    boost;
    ll n,i,j,x;
    cin>>n;
    string s,t;
    cin>>s>>t;
    for(i=0;i<n;i++) cout<<s[i]<<t[i];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+10;
int pre[maxn],sizes[maxn];
int m,n;
void inint()
{
    for(int i=1;i<=n;i++)
    {
        pre[i]=i;
        sizes[i]=1;
    }
}
int finds(int x)
{
    if(x==pre[x])
    {
        return x;
    }
  else
    return pre[x]=finds(pre[x]);
}
bool same(int a,int b)
{
  return finds(a)==finds(b);

}
void unint(int a,int b)
{
       int x=finds(a);
       int y=finds(b);
       if(x==y)
        return ;
       if(sizes[x]<sizes[y])
       {
           pre[x]=y;
           sizes[y]+=sizes[x];
       }
       else
       {
           pre[y]=x;
           sizes[x]+=sizes[y];
       }
}
int main()
{
     scanf("%d%d",&n,&m);
     vector<int>a(m),b(m);
     inint();
     vector<ll>ans(m);
     for(int i=0;i<m;i++)
    scanf("%d%d",&a[i],&b[i]);
    ans[m-1]=(long long)n*(n-1)/2;
    for(int i=m-1;i>=1;i--)
    {
        ans[i-1]=ans[i];
        if(!same(a[i],b[i]))
        {
            ans[i-1]-=(ll)sizes[finds(a[i])]*sizes[finds(b[i])];
            unint(a[i],b[i]);
        }
    }
    for(int i=0;i<m;i++)
     printf("%lld\n",ans[i]);

    return 0;
}


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

int main() 
{
    int n,c=0;
    cin>>n;
    map<int,int>mp;
    for(int i=1;i<n;i++)
        mp[i]=1;
    for(auto it=mp.begin();it!=mp.end();it++)
    { 
        int x=it->first;
         int y=n-x;
          if(mp[x]!=0)
           {  mp[x]=0;
                if(mp.find(y)!=mp.end()&&mp[y]!=0)
                  c++;
               
           }
           mp[y]=0;
            
    }
    cout<<c;
      
      
    
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, 0, n) cin >> s[i];
    sort(all(s));
    string ans = "";
    rep(i, 0, n) ans += s[i];
    cout << ans << endl;
}

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

typedef long double ld;									// XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
#define mem(a,x) memset(a,x,sizeof(a))
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9+7;
const int inf = 1e18;
const int maxn = 2e5+5;

void solve(){
	int n; cin>>n;
	n = n^1;
	cout<<n;
}
signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //io();
    //cout<<setprecision(16);
    int tc=1; //cin>>tc; 
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define MP make_pair
#define PB push_back
#define LL long long
#define pii pair<int,int>

#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
//const int inf = 0x7fffffff; //beware overflow
//const LL INF = 0x7fffffffffffffff; //beware overflow
#define mem(x, y) memset(x, (y), sizeof(x) );
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
inline LL getint(){
   LL _x=0,_tmp=1; char _tc=getchar();
   while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
   if( _tc == '-' ) _tc=getchar() , _tmp = -1;
   while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
   return _x*_tmp;
}
#define maxn
int cnt[1005];
const int mod = 1e9+7;
void fac(int n) {
    for(int i=2;i*i<=n;i++) {
        while( n && (n%i==0) ) {
            n /=i;
            cnt[i]++;
        }
    }
    cnt[n]++;
}
int main() {
    int n;cin>>n;
    for(int i=2;i<=n;i++) fac(i);
    LL ans=1;
    for(int i=2;i<=1000;i++)
        ans = ans*(cnt[i]+1)%mod;
    cout << ans << endl;

}


Measured memory_bytes: 256
INF = -1 * 10 ** 1000
n = gets.to_i
nums = gets.split.map(&:to_i)
length = nums.length
# dp[i 個目の num まで][前の数字を選んだか][ぴったり採用 - 1, ぴったり採用, ぴったり採用 + 1]の最大値
dp = (length + 1).times.map { 2.times.map { Array.new(3, INF) } }
# 初期化
# dp[0 個目の num まで][前の数字を選んだか][ぴったり採用]の最大値は 0
dp[0][0][1] = 0

# 桁数分ループする（i は遷移元の桁）
length.times do |i|
  dp_current = dp[i]
  # 最適化のため、事前に 1 行分だけ参照渡しをする
  # dp_next と dp[i + 1] の object_id は同じ
  dp_next = dp[i + 1]
  2.times do |selected|
    dp_current_selected = dp_current[selected]
    3.times do |count|
      current_sum = dp_current_selected[count]
      next if current_sum == INF
      count += 1 if i.odd?
      2.times do |next_selected|
        tmp_count = count
        next if selected == 1 && next_selected == 1
        if next_selected == 1
          current_sum += nums[i]
          tmp_count -= 1
        end
        next if tmp_count > 2 || tmp_count < 0
        dp_next_next_selected = dp_next[next_selected]
        dp_next_next_selected[tmp_count] = current_sum if dp_next_next_selected[tmp_count] < current_sum
      end
    end
  end
end

puts [dp[n][0][1], dp[n][1][1]].max


Measured memory_bytes: 58008
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

const static string table[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

static string S;

void solve(void) {
  FOR0(i, 7) {
    if (S == table[i]) {
      cout << (7 - i) << endl;
    }
  }
}

int main(void) {
  cin >> S;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int selection_sort(int n, int *a)
{
    int i, j, minj, x;
int ans = 0;
 
    for (i = 0; i < n; i++) {
        minj = i;
        for (j = i; j < n; j++) {
            if (a[j] < a[minj]) minj = j;
        }
        if (i != minj) {
            x = a[i], a[i] = a[minj], a[minj] = x;
ans++;
        }
    }
return ans;
}
 
//#define getchar_unlocked()  getchar()
int in()
{
    int n = 0, c = getchar_unlocked();
    do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
    return n;
}
 
int a[102];
 
int main()
{
    int N, i, k;
 
    N = in();
    for (i = 0; i < N; i++) a[i] = in();
    k = selection_sort(N, a);
    printf("%d", a[0]);
    for (i = 1; i < N; i++) printf(" %d", a[i]);
    putchar('\n');
    printf("%d\n", k);
    return 0;
}


Measured memory_bytes: 2088
#include <iostream>
#include <stdio.h>
using namespace std;

long long getgcd(long long x,long long y){
    long long r=x%y;
    while(r!=0){
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}
int main(){
    int N;
    long long K;
    long long gcd;
    scanf("%d %lld",&N,&K);
    long long input[N];
    long long int inp;
    long long max=0;
    for(int i=0;i<N;i++){
        scanf("%lld",&input[i]);
        if(input[i]>max){
            max=input[i];
        }
    }    
    if(max<K){
        printf("IMPOSSIBLE\n");
        return 0;
    }
    gcd=input[0];
    for(int i=1;i<N;i++){
        gcd=getgcd(gcd,input[i]);
        if(K%gcd==0){
            printf("POSSIBLE\n");
            return 0;
        }
    }
    if(K%gcd==0){
        printf("POSSIBLE\n");
        return 0;
    }
    printf("IMPOSSIBLE\n");
       
    return 0;
    
}

Measured memory_bytes: 1024
// Aizu Vol0 0014: Integral
// 2017.7.28

#include <stdio.h>

#define MAX 600

int main()
{
	int s, d, x;
	
	while (scanf("%d", &d) == 1) {
		s = 0, x = d;
		while (x < MAX) {
			s += d * x*x;
			x += d;
		}
		printf("%d\n", s);
	}
	return 0;
}

Measured memory_bytes: 596