akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define se second
#define fi first
#define pb push_back
#define cn cout<<"\n"
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repr(i,a,b) for(int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

#define _ ios::sync_with_stdio(0); cin.tie(0);

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>
#define flush fflush(stdout)

const int INF = 1e8;
const ll MOD = 1e9 + 7;
const int MAX = 1e5;

using namespace std;


int main(){
	_

	int t = 1;

	// cin>>t;

	int n, m;
	ll a, b, mini = 1e6, maxi = -1;
	rep(nc, 0, t){
		cin>>n>>m;

		vi a(n);
		vii b(m, ii());
		rep(i, 0, n)
			cin>>a[i];
		rep(i, 0, m)
			cin>>b[i].se>>b[i].fi;

		sort(all(a));

		sort(allr(b));

		int i = 0, j = 0; 
		while(i < n && j < m){
			while(i < n && j < m && b[j].se > 0 && b[j].fi > a[i]){
				a[i] = b[j].fi;
				b[j].se--;
				i++;
			}
			j++;
		}

		ll sum = 0;
		rep(i, 0, n)
			sum += a[i];

		cout<<sum<<"\n";
	}

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 1e5 + 10;
int ac[N], wa[N];

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n, m; cin >> n >> m;

  while (m--) {
    int p; cin >> p;
    string s; cin >> s;
    if (s == "AC") {
      ac[p] = 1;
    } else {
      if (!ac[p]) wa[p]++;
    }
  }

  int acc = 0, wac = 0;
  for (int i = 0; i < N; i++) {
    if (ac[i]) {
      acc++;
      wac += wa[i];
    }
  }

  cout << acc << ' ' << wac << endl;

  return 0;
 }


Measured memory_bytes: 1024
//Bismillahir Rahmanir Rahim
//In the name of Allah
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long  int
int i,j;

main()
{

 int n;
 cin>>n;
 int a[n+1]={0};
 int m;
 cin>>m;
 for(i=1;i<=n;i++) a[i]=0;
 while(m--)
 {
     int p;
     cin>>p;
     while(p--)
     {
         int f;
         cin>>f;
         a[f]=1;
     }
 }
 int c=0;
 for(i=1;i<=n;i++)
 {
     if(a[i]==0) c++;
 }
 cout<<c<<endl;
}



Measured memory_bytes: 3584
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;

using namespace std;

int main(){
  string S;
  cin >> S;
  if(S[0]==S[1] && S[1] == S[2] && S[2]==S[3]) cout << "No" << endl;
  else if(S[0]==S[1] && S[2]==S[3]) cout << "Yes" << endl;
  else if(S[0]==S[2] && S[1]==S[3]) cout << "Yes" << endl;
  else if(S[0]==S[3] && S[1]==S[2]) cout << "Yes" << endl;
  else cout << "No" << endl;  
}


Measured memory_bytes: 256
#define T 444
D[T][T],i,j,x,y,a,b,c,r=9999;main(k){for(i=-1;++i<T;)for(j=-1;++j<T;)D[i][j]=r;scanf("%*d%d%d",&x,&y);for(D[0][0]=0;~scanf("%d%d%d",&a,&b,&c);)for(i=T;i-->a;)for(j=T;j-->b;){k=D[i-a][j-b]+c;if(D[i][j]>k)D[i][j]=k;}for(i=x,j=y;i<T&&j<T;i+=x,j+=y){if(D[i][j]<r)r=D[i][j];}printf(r>=9999?"-1\n":"%u\n",r);}

Measured memory_bytes: 896
#include<stdio.h>

int main(){
    int H1, H2, M1, M2, K;

    scanf("%d", &H1);
    scanf("%d", &M1);
    scanf("%d", &H2);
    scanf("%d", &M2);
    scanf("%d", &K);

    printf("%d", (H2 - H1) * 60 + (M2 - M1) - K);

    return 0;
}

Measured memory_bytes: 2136
from collections import deque
N, D, A = list(map(int, input().split()))
pair_xh = [[-1, -1] for _ in range(N)] # 1回ずつしか使わないけどソートするから必要
for i in range(N):
    pair_xh[i][0], pair_xh[i][1] = list(map(int, input().split()))
pair_xh.sort(key = lambda x: x[0]) #座標でソート

q_lim_d = deque() # 累積和に含まれる攻撃範囲とダメージを保存する場所
total = 0 # 喰らいダメージの累積和
count = 0 # 攻撃回数
for i in range(N):
    x = pair_xh[i][0]
    h = pair_xh[i][1]
    
    while len(q_lim_d) and q_lim_d[-1][0] < x: # 範囲外になったら喰らわないから累積和から外す
        total -= q_lim_d[-1][1]
        q_lim_d.pop()
    h -= total
    if h > 0: # 見てる敵の体力が0になる攻撃回数を求めその分を累積和に足す
        times = (h + A - 1) // A # 0にするのに必要な回数(切り上げ)
        count += times
        damage = A * times
        total += damage
        q_lim_d.appendleft([x + 2 * D, damage])
print(count)

Measured memory_bytes: 53928
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==5&&b==5&&c==7)cout<<"YES"<<endl;
    else if(a==5&&b==7&&c==5)cout<<"YES"<<endl;
    else if(a==7&&b==5&&c==5)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a+b+c-max({a,b,c})<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
#define ll long long
#define inf int(1e9+7)
#define pb push_back
#define mp make_pair
string s;
int n,m;
bool was[26];
bool dfs(int i)
{
	if(i==n)
	{
		for(int i=0;i<26;i++)
			if(!was[i])
			{
				s+=char(i+'a');
				return 1;
			}
		return 0;
	}
	was[s[i]-'a']=1;
	if(dfs(i+1))
		return 1;
	for(int j=s[i]-'a'+1;j<26;j++)
		if(!was[j])
		{
			s.erase(i,s.size()-i);
			s+=char(j+'a');
			return 1;
		}
	was[s[i]-'a']=0;
	return 0;
}
int main()
{
	cin>>s;
	n=s.size();
	if(!dfs(0))
		puts("-1");
	else
		cout<<s;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	const int MAX_V = 1000000;
	int prime[MAX_V+1],sum[MAX_V];
	int i,k,n,ans;
	for(i=2;i<=MAX_V;i++){
		prime[i] = 1;
		sum[i] = 0;
	}
	for(i=2;i*i<=MAX_V;i++){
		if(prime[i]==1){
    	for(k=2*i;k<=MAX_V;k+=i){
				prime[k] = 0;
			}
		}
	}
  for(i=2;i<=MAX_V;i++){
		sum[i+1]=sum[i]+prime[i];
  }
  while(scanf("%d",&n) != EOF){
    ans = sum[n+1];
    printf("%d\n",ans);
  }
  return 0;
}

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

#define vi vector<int>
#define pb push_back

typedef long long ll;
using namespace std;


int main(){
    int m,nmn,nmx;
    while(cin >> m >> nmn >> nmx,m) {
        int gmx = 0,mxn = 0;
        vi p;
        rep(i,m){
            int tmp;
            cin >> tmp;
            p.pb(tmp);
        }
        sort(p.begin(),p.end());
        REP(n,nmn,nmx + 1){
            if(gmx <= (abs(p[m - n] - p[m - n - 1]))) {
                gmx = abs(p[m - n ] - p[m - n - 1]);
                mxn = n;
            }
        }
        cout << mxn << endl;
    }
    return 0;
}



Measured memory_bytes: 3156
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

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

int main(void) {
    map<Int,Int> A;
    Int n,m;
    cin>>n>>m;

    for(int i = 0;i < n;i++) {
        Int a;
        cin>>a;

        A[a]++;
    }

    for(int i = 0;i < m;i++) {
        Int b,c;
        cin>>b>>c;
        A[c] += b;
    }
    Int sum = 0;
    for(auto it = A.rbegin();it != A.rend();it++) {
        //cout<<it->first<<" "<<it->second<<endl;
        if(it->second <= n) {
            sum += (it->first)*(it->second);
            n -= it->second;
        }
        else {
            sum += (it->first)*(n);
            break;
        }
        if(n == 0)
            break;
    }

    cout<<sum<<endl;

    return 0;
}




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

int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a+c==b)
    {
        printf("Yes");
    }
    else if (a-c==b)
    {
        printf("Yes");
    }
    else if (c-a==b)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val in = readLine.split(" ").map(_.toInt)
    val N = in(0)
    val A = in(1)
    val B = in(2)

    var count = 0
    for(i <- 1 to N){
      val deg = i.toString.length - 1
      val array = (0 to deg).map{idx => i.toString.charAt(idx).toString.toInt}.toArray
      if (A <= array.sum & array.sum <= B) count += i
    }

    print(count)

  }
}

Measured memory_bytes: 37196
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] l = new int[n];
		for(int i = 0; i < n; i++){
		    l[i] = sc.nextInt();
		}

		// 計算
	    int result = 0;
	    Arrays.sort(l);
	    for(int i = 0; i < n; i++){
		    for(int j = i + 1; j < n; j++){
		        int k = j + 1;
		        while(k < n && l[k] - l[j] < l[i]) k++;
		        result += k - (j + 1);
		    }
		}

		// 出力
		System.out.println(result);
        
	}
}


Measured memory_bytes: 26212
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,M = map(int,readline().split())
WA_cnt = [0]*(N+1)
WA_use = [0]*(N+1)
A = []
cnt = 0
for _ in range(M):
    p,S = readline().decode().split()
    p = int(p)
    if S == 'AC' and WA_use[p] == 0:
        A.append(p) 
        cnt += WA_cnt[p]
        WA_use[p] = 1
    else:
        WA_cnt[p] += 1
        
print(len(set(A)),cnt)

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

int main(){
   int n; cin >> n;
   vector<int> S(n); rep(i,n) cin >> S[i];
   int q; cin >> q;
   vector<int> T(q); rep(i,q) cin >> T[i];

   int ans = 0;
   rep(i,q){
       int Q = T[i];
       int right = n;
       int left = -1;
       int mid = (right + left) / 2;
       while(right-left >1){
           if(Q == S[mid]) {
               ans++;
               break;
           }else if(Q > S[mid]) left = mid;
           else right = mid;
           mid = (right + left) / 2;
       }
   }
   cout << ans << endl;
}


Measured memory_bytes: 3360
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int X, Y;
		cin >> X >> Y;

		string ans = "No";
		for( int i = 0; i <= X; ++i ) {
			int a = 2*i;
			int b = 4*(X-i);
			if( a+b == Y ) {
				ans = "Yes";
			}
		}
		cout << ans << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3628
N = int(input())
def LI():
  return [int(s) for s in input().split()]

p = LI()

count = 0
  
for i in range(1,N-1):
  if p[i] < p[i+1] and p[i] > p[i-1]:
      count += 1  
  elif p[i] > p[i+1] and p[i] < p[i-1]:
      count += 1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <time.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 2147483647

int main() {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	double ans = 0; 
	vector<double> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	if (n == 2) {
		printf("%.5f\n", (a[0] + a[1]) / 2); 
	}
	else {
		sort(a.begin(), a.end()); 
		ans += (a[0] + a[1]) / 2; 
		for (int i = 2; i < n; i++) {
			ans = ((ans + a[i]) / 2); 
		}
		printf("%.5f\n", ans);
	}

	return 0;
}


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

int main() {
  	int n; cin>>n;
  	priority_queue<long double, vector<long double>, greater<long double>> pq;
  	for (int i = 0; i < n; i++) {
      int x; cin>>x;
      pq.push(x);
    }
  	while (pq.size() > 1) {
      	long double a = pq.top(); pq.pop();
      	long double b = pq.top(); pq.pop();
      	pq.push((a+b)/2);
    }
  	cout << setprecision(30) << pq.top() << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define pb push_back
#define F first
#define S second
#define M (ll)(1e9+7)
#define mp make_pair
  
using namespace std; 
typedef long long ll;
bool isPrime(int a)
{
    if(a<2)
    return false;
    for(int i=2;i*i<=a;i++)
    if(a%i==0)
    return false;
    return true;
}
void solve()
{
    int n,k;ll r,s,p,ans=0;string t;
    cin>>n>>k>>r>>s>>p>>t;
    for(int i=0;i<k;i++)
    {
        string te="";
        for(int j=i;j<n;j+=k)
        te.pb(t[j]);
        te.pb('*');
        //cout<<te<<endl;
        char ch=te[0];ll c=1;
        for(int j=1;j<te.size();j++)
        {
            if(te[j]==ch)
            c++;
            else
            {
                ll v=c/2+(c%2);
                //cout<<v<<" "<<ch<<endl;
                if(ch=='r')
                ans+=v*p;
                else if(ch=='s')
                ans+=v*r;
                else
                ans+=v*s;
                c=1;
                ch=te[j];
            }
        }
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int h, w, c[50];
char f[10005];
vector<char> b;
bool fg = 0;
int main(){
	scanf("%i%i", &h, &w);
	for(int i=0;i<h;i++){
		scanf("%s", f+(i*w));
	}
	sort(f, f+(h*w));
	char l = f[0];
	for(int i=0;i<h*w;i++){
		if(f[i] == l) c[l-'a']++;
		else {
			if(c[l-'a'] % 4 != 0) {
				c[l-'a'] %= 4;
				b.push_back(l);
			}
			l = f[i];
			c[l-'a']++;
		}
	}
	if(c[l-'a'] % 4 != 0){
		c[l-'a'] %= 4;
		b.push_back(l);
	}
	int bx = (h % 2) + (w % 2), gtx = 0;
	for(int i=0;i<b.size();i++){
		if(h == w && w == 2) {printf("No\n"); return 0;}
		if(c[b[i] - 'a'] % 2 == 1) {
			if(fg) {printf("No\n"); return 0;}
			fg = true;
		} else {
			gtx++;
		}
	}
	int gbx = 0;
	if(w % 2) gbx += (h/2);
	if(h % 2) gbx += (w/2);
	if(gtx <= gbx) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    //
    ll n,i,j,c,a[200005];
    while(cin>>n)
    {

        c=0;
        for(i=1; i<=n; i++)
            cin>>a[i];


            for(i=1; i<=n; i++)
            {
                if(a[a[i]]==i)

                {
                    c++;

                }


            }

            cout<<c/2<<endl;

        }
        return 0;

    }


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;

int main(void) {
	ll n;
	cin >> n;
	if (n == 2) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	for (ll m = 1;m + 1 <= sqrt(n);m++) {
		if ( n == (m + 1)*(n % m))ans += m;
		if ((n % (m + 1) == 0) && n == (n / (m + 1))*(n % (n / (m + 1)-1)))ans += n / (m + 1) - 1;
	}
	cout << ans + (n - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int k = sc.nextInt();
	if(k == 1) {
	    System.out.println(0);
	}else {
	System.out.println(n-k);
	}
    }
}


Measured memory_bytes: 23124
n, k = [ int(v) for v in input().split() ]
coordinate_list = sorted([ int(v) for v in input().split() ]) 

def fire(a,b):
    if a * b >= 0:
        r = max(abs(a),abs(b))
    else:
        r = abs(a) + abs(b) + min(abs(a),abs(b))
    return r

ans = 10**14
for i in range(n-k+1):
    ans = min(fire(coordinate_list[i],coordinate_list[i+k-1]),ans)
print(ans)

Measured memory_bytes: 62576
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,m;
    cin>>n>>m;
    ve <ll> arr(n);
    ll sum=0;
    rep (i,0,n)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    ll val=sum/(4*m);
    if (sum%(4*m)!=0)
    {
        val++;
    }
    ll cnt=0;
    rep (i,0,n)
    {
        if (arr[i]>=val)
        {
            cnt++;
        }
    }
    if (cnt>=m)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;

int top,S[1000];

void push(int x){
	S[++top] = x;
}

int pop(){
	top--;
	return S[top+1];
}

int main(){
	int a,b;
	top = 0;
	char s[1000];
	while( scanf("%s" , s) != EOF){
		if(s[0] == '+'){
			a = pop();
			b = pop();
			push(a + b);
		}else if(s[0] == '-'){
			b = pop();
			a = pop();
			push(a - b);
		}else if(s[0] == '*'){
			a = pop();
			b = pop();
			push(a * b);
		}else{
			push(atoi(s));
		}
	}

	cout << pop() << endl;

	return 0;
}


Measured memory_bytes: 3268
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		//Scanner reader=new Scanner(System.in);
		String s;
		while((s=reader.readLine())!=null){
			int in=Integer.parseInt(s);
		//int in;
		//while((in=reader.nextInt())!=EOF){
			int co=0;
			for(int i=0;i<10;i++)
				for(int j=0;j<10;j++)
					for(int k=0;k<10;k++)
						if(in-i-j-k>=0&&in-i-j-k<10)co++;
			System.out.println(co);
		}

	}
}

Measured memory_bytes: 18272
import java.util.Scanner;

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

		int a = sc.nextInt();
		String s = sc.next();

		if (a >= 3200) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}
		sc.close();
	}
}

Measured memory_bytes: 27068
#include <stdio.h>
int z[9999],r[9999];
int f(int a,int b){
	printf("? %d %d\n",a,b);
	fflush(stdout);
	char c[2];
	scanf("%s",c);
	return *c=='Y';
}
int main(){
	int a,b,c=0,h,i=0;
	scanf("%d%d",&a,&b);
	if(a<=b){puts("Impossible");return 0;}
	for(a+=b;i<a;i++)if(!c||f(i,z[c-1]))z[c++]=i;else c--;
	for(h=*z,i=a;~--i;)r[i]=f(h,i);
	for(printf("! "),i=0;i<a;)printf("%d",r[i++]);
	puts("");
}

Measured memory_bytes: 724
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>
#include <set>

#include <stdio.h>
#include <string.h>

using namespace std;

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

typedef pair<int, int> P;

// 素集合データ構造
struct UnionFind
{
	// par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
	vector<int> par;
	// sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
	vector<int> sizes;

	UnionFind(int n) : par(n), sizes(n, 1) {
		// 最初は全てのデータiがグループiに存在するものとして初期化
		rep(i, n) par[i] = i;
	}

	// データxが属する木の根を得る
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		// sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};

// 頂点a, bをつなぐコストcostの（無向）辺
struct Edge
{
	int a, b, cost;

	// コストの大小で順序定義
	bool operator<(const Edge& o) const {
		return cost < o.cost;
	}
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
	int n;  // 頂点数
	vector<Edge> es;  // 辺集合

					  // クラスカル法で無向最小全域木のコストの和を計算する
					  // グラフが非連結のときは最小全域森のコストの和となる
	int kruskal() {
		// コストが小さい順にソート
		sort(es.begin(), es.end());

		UnionFind uf(n);
		int min_cost = 0;

		rep(ei, es.size()) {
			Edge e = es[ei];
			if (!uf.same(e.a, e.b)) {
				// 辺を追加しても閉路ができないなら、その辺を採用する
				min_cost += e.cost;
				uf.unite(e.a, e.b);
			}
		}

		return min_cost;
	}
};


int main(int argc, char* argv[])
{
	int N;
	cin >> N;
	P x[N], y[N];
	for (int i = 0; i < N; i++) {
		cin >> x[i].first >> y[i].first;
		x[i].second = y[i].second = i;
	}

	// 最小全域木を求めるのに辺が多すぎるので、必要な辺だけを残す
	sort(x, x + N), sort(y, y + N);

	Graph g;
	g.n = N;
	Edge e;
	for (int i = 0; i < N - 1; i++) {
		e.a = x[i].second, e.b = x[i + 1].second, e.cost = x[i + 1].first - x[i].first;
		g.es.push_back(e);
		e.a = y[i].second, e.b = y[i + 1].second, e.cost = y[i + 1].first - y[i].first;
		g.es.push_back(e);
	}

	cout << g.kruskal() << endl;

	return 0;
}


Measured memory_bytes: 6516
#include<bits/stdc++.h>
using namespace std ;
int main ()
{
    int n,i,AC=0,TLE=0,RE=0,WA=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s=="AC")
            AC++;
        else if(s=="WA")
            WA++;
        else if(s=="TLE")
            TLE++;
        else if(s=="RE")
            RE++;
    }
    cout<<"AC"<<" x "<<AC<<endl;
    cout<<"WA"<<" x "<<WA<<endl;
    cout<<"TLE"<<" x "<<TLE<<endl;;
    cout<<"RE"<<" x "<<RE;
}


Measured memory_bytes: 3640
import numpy as np

class Calculator:
    def __init__(self, arr):
        self.arr = arr

    def get_result(self):
        return (self.arr[0] - 1) * (self.arr[1] - 1)

def main():
    A, B, = map(int, input().split())
    arr = np.array([A, B], dtype=int)
    calc = Calculator(arr)
    print(calc.get_result())

if __name__ == "__main__":
    main()



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

int main()
{
	long long int N, K, ans=0;
	cin>>N>>K;
	vector<long long int> v(N);
	for(int i=0; i<N; i++) cin>>v[i];
	
	sort(v.begin(), v.end());
	
	for(int i=0; i<N-K; i++)
		ans+=v[i];
	
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int X = sc.nextInt();//気温
		//判定
		if(X>=30) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}


	}

}


Measured memory_bytes: 35736
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;
using static System.Math;
using System.Numerics;

class Program
{
    static void Main(string[] args)
    {
        label:
        var sp = ReadLine().Split();
        int n = Parse(sp[0]);
        int m = Parse(sp[1]);
        int max = m / n;
        WriteLine(Yakusuu(m).Where(i => i <= max).Max());
        //goto label;
    }

    static List<int> Yakusuu(int num)
    {
        if (num == 1) return new List<int>() { 1 };
        int sq = (int)Ceiling(Sqrt(num));
        int sqsq = (int)Ceiling(Sqrt(sq));
        var gousei = new bool[sq + 1];
        for(int i = 2; i <= sqsq; ++i)
        {
            if (gousei[i]) continue;
            for(int j = i * 2; j < gousei.Length; j += i)
            {
                gousei[j] = true;
            }
        }
        var insuu = new List<List<int>>();
        for(int i = 2; i < gousei.Length; ++i)
        {
            if (!gousei[i])
            {
                if (num % i == 0)
                {
                    var list = new List<int>() { 1, i };
                    insuu.Add(list);
                    int j = i * i;
                    for(; num % j == 0; j *= i)
                    {
                        list.Add(j);
                    }
                    num /= (j / i);
                }
                if (num < i) break;
            }
        }
        if (1 < num)
        {
            insuu.Add(new List<int>() { 1, num });
        }
        var result = Get(insuu, 0).ToList();
        return result;
    }
    static IEnumerable<int> Get(List<List<int>> lislis, int i)
    {
        foreach (int n in lislis[i])
        {
            if (i == lislis.Count - 1)
            {
                yield return n;
            }
            else
            {
                foreach (var next in Get(lislis, i + 1))
                {
                    yield return n * next;
                }
            }
        }
    }
}


Measured memory_bytes: 13396
N = int(input())
A = list(map(int, input().split()))

x = []
y = []
P = sorted((a for a in A if a >= 0), reverse=True)
Q = sorted(a for a in A if a < 0)
if not Q:
    M = sum(P[:-2]) + (P[-2] - P[-1])
    for _ in range(N - 2):
        X = P.pop()
        Y = P.pop()
        x.append(X)
        y.append(Y)
        P.append(X - Y)
    Y = P.pop()
    X = P.pop()
    x.append(X)
    y.append(Y)
elif not P:
    M = -sum(Q[:-2]) - (Q[-2] - Q[-1])
    for _ in range(N - 1):
        X = Q.pop()
        Y = Q.pop()
        x.append(X)
        y.append(Y)
        Q.append(X - Y)
else:
    M = sum(abs(a) for a in A)
    for _ in range(N - 1):
        if len(P) == 1:
            X = P.pop()
            Y = Q.pop()
            x.append(X)
            y.append(Y)
            P.append(X - Y)
        else:
            X = Q.pop()
            Y = P.pop()
            x.append(X)
            y.append(Y)
            Q.append(X - Y)

print(M)
for X, Y in zip(x, y):
    print('{} {}'.format(X, Y))


Measured memory_bytes: 68620
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

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

int main(){
    ll n,k;cin>>n>>k;
    vector<pair<ll,ll>> p;
    rep(i,0,n){
        ll a,b;cin>>a>>b;
        p.pb(mp(a,b));
    }
    sort(all(p));
    ll t = 0;
    rep(i,0,n){
        t += p[i].se;
        if(t >= k){
            cout << p[i].fi << ednl;
            return 0;
        }
    }
}


Measured memory_bytes: 2420
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	char s[2];
	cin>>s[0]>>s[1]>>s[2];
	bool a=false;
	bool b=false;
	bool c=false;
	for(int i=0;i<3;i++){
		if(s[i]=='a')a=true;
		if(s[i]=='b')b=true;
		if(s[i]=='c')c=true;
	}
	if(a==true&&b==true&&c==true){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
import math
a, b = map(int, input().split())
for yen in range(1, 10000):
    ap = math.floor(yen*0.08)
    bp = math.floor(yen*0.10)
    #print(yen, ap, bp)
    if ap == a and bp == b:
        print(yen)
        exit()
print(-1)

Measured memory_bytes: 3060
#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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C;
    cin >> A >> B >> C;
    if (A <= C && C <= B)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a = scan.nextInt();
		
		while (n-500 > 0) {
			n = n-500;
		}
		if (n<500 && a<n) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}


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

int a,b,c,Left,Right;

signed main()
{
	cin>>a>>b>>c;
	Right=c-b-a;
	Left=2.00*sqrt(a*b);
	
	if (Left<Right)  cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void push(int);
int pop();
int top;
int S[200];
int main(){
    int a,b;
    top=0;
    char s[8];
    while(scanf("%s",s)!=EOF){
        if(s[0]=='+'){
            a=pop();
            b=pop();
            push(a+b);
        }else if(s[0]=='-'){
            a=pop();
            b=pop();
            push(b-a);
        }else if(s[0]=='*'){
            a=pop();
            b=pop();
            push(a*b);
        }else{
            push(atoi(s));
        }
    }
    
    printf("%d\n",pop());
    return 0;
}

void push(int a){
    top++;
    S[top]=a;
}

int pop(){
    top--;
    return S[top+1];
}

Measured memory_bytes: 548
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn minecount(board:&Vec<Vec<char>>,x:usize,y:usize)->u32{
    use std::cmp;
    let sx = if x == 0 { 0 } else { x -1 };
    let sy = if y == 0 { 0 } else { y -1 };
    let ex = cmp::min(x+2,board.len());
    let ey = cmp::min(y+2,board[x].len());
    let mut count = 0;
    for cx in sx..ex{
        for cy in sy..ey{
            if board[cx][cy] == '#' {
                count += 1;
            }
        }
    }
    return count;
}

fn main() {
input!{
    h: usize,
    w: usize,
    board: [chars; h]
}
let mut y = 0;
while y != board.len() {
    let mut x = 0;
    while x != board[y].len() {
        if board[y][x] == '.' {
            let count = minecount(&board,y,x);
            let count = std::char::from_digit(count as u32, 10).unwrap();
            print!("{}", count); 
        }else{
            print!("{}", board[y][x]); 
        }
        x += 1;
    }
    println!(""); 
    y += 1;
}
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int s = a*b;
		int l = 2*a+2*b;
		
		System.out.println(s+" "+l);
	}
}



Measured memory_bytes: 26144
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
const int INF = 1e9;
const int MXN = 3e3 + 5;
const int MXV = 0;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i < (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i > (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);
double dp[MXN][MXN];

int main()
{
    IOS;
    int n;
    cin >> n;
    dp[0][0] = 1;
    FOR(i, 1, n + 1)
    {
        double x;
        cin >> x;
        FOR(j, 0, n + 1)
        {
            dp[i][j] += (1 - x) * dp[i - 1][j];
            if (j)
            {
                dp[i][j] += x * dp[i - 1][j - 1];
            }
        }
    }
    double ans = 0;
    FORD(i, n, n / 2) { ans += dp[n][i]; }
    cout << fixed << setprecision(10) << ans << '\n';
}


Measured memory_bytes: 74172
#include<stdio.h>
int main()
{
	int k[10000],j=0,n[10000],sw[10000],count[10000],i;
	scanf("%d",&n[j]);
	while(n[j]!=0){
		sw[j]=0;
		for(i=0;i<n[j];i++){
			scanf("%d",&k[i]);
		}
		count[j]=0;
		for(i=0;i<n[j];i++){
			if(k[i]>0){
				count[j]++;
				if(k[i]>=2)
					sw[j]++;
			}
		}
		j++;
		scanf("%d",&n[j]);
	}
	for(i=0;i<j;i++){
		if(sw[i]>0)
			printf("%d\n",count[i]+1);
		else
			printf("NA\n");
	}
	return 0;
}

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


int main() {
    ll n;
    cin >> n;
    ll prod = 1;
    bool over = false;
    bool zero = false;
    rep(i, n) {
        ll a;
        cin >> a;
        prod *= a;
        //cout << a << " " << prod << endl;
        if (a==0) zero = true;
        if (prod>1000000000000000000LL) over = true;
        if (prod<a) over=true;
    }
    if (zero) prod = 0;
    else if (over) prod = -1;
    cout << prod << endl;
}


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

int main(int argc, char *argv[]){
	int n;
	cin >> n;
	char c; 
	for(int i=0;i<n;++i){
		cin >> c;
		if( c=='Y') {
			cout << "Four" << endl; return 0;
		} 
	}
	cout << "Three" << endl;
}

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

int     main() {
	int N;
	cin >>N;
	int MI=1000000000;
	int MA=1;
	int M;
	for (int i=0; i<N; i++) {
		cin >>M;
		MA = max(MA, M);
		MI = min(MI, M);
	}
	cout <<MA-MI <<endl;
	return 0;
};


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

int main(void) {
    string s;
    int64_t ABCD[4];
    string op[3];
    int64_t chk;

    cin >> s;
    for(int i=0;i<4;i++) {
        ABCD[i] = s[i]-'0';
    }

    
    for(int i=0;i<8;i++) {
        chk = 0;
        if(i & 4) {
            op[0] = '+';   
            chk = ABCD[0] + ABCD[1];
        } else {
            op[0] = '-';   
            chk = ABCD[0] - ABCD[1];
        }
        if(i & 2) {
            op[1] = '+';   
            chk = chk + ABCD[2];
        } else {
            op[1] = '-';   
            chk = chk - ABCD[2];
        }
        if(i & 1) {
            op[2] = '+';   
            chk = chk + ABCD[3];
        } else {
            op[2] = '-';   
            chk = chk - ABCD[3];
        }

        if(chk == 7) {
            for(int i=0;i<3;i++) {
                cout << ABCD[i] << op[i];
            }
            cout << ABCD[3] << "=7\n";
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif


typedef long long lint;

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

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



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

	string s, t; cin >> s >> t;
	if (s == t)co("H");
	else co("D");
	gc();
}

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

struct UnionFind {
    // child: parent id >= 0
    //  root: -size < 0
    vector< int > d;
    UnionFind(int n = 0) : d(n, -1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};

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

    UnionFind R(N + 1);
    UnionFind G(N + 1);
    UnionFind B(N + 1);
    rep(i, N) {
        char s = S[i];
        if (s == 'R') {
            R.unite(0, i + 1);
        } else if (s == 'G') {
            G.unite(0, i + 1);
        } else {
            B.unite(0, i + 1);
        }
    }

    ll ans = (ll)(R.size(0) - 1) * (ll)(G.size(0) - 1) * (ll)(B.size(0) - 1);
    for (int i = 1; i <= N; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            int k = j + j - i;
            if (k > N) continue;
            bool r = R.same(i, j) || R.same(j, k) || R.same(i, k);
            bool g = G.same(i, j) || G.same(j, k) || G.same(i, k);
            bool b = B.same(i, j) || B.same(j, k) || B.same(i, k);
            if (!r && !g && !b) {
                --ans;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3664
# AOJ 1589 Unhappy Class
# Python3 2018.7.13 bal4u

N, M, L = map(int, input().split())
tbl = [[] for i in range(45)]
for i in range(M):
	d, a, k, t = map(int, input().split())
	tbl[d*N+a-1].append((k, t))
dp = [[0 for i in range(45)] for j in range(45)]
for da in range(5*N):
	for i in range(L+1):
		if i < L:
			for k, t in tbl[da]:
				dp[da+k][i+1] = max(dp[da+k][i+1], dp[da][i]+t)				 
		dp[da+1][i] = max(dp[da+1][i], dp[da][i])
print(dp[5*N][L])



Measured memory_bytes: 5608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

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

		int[] height = new int[n];

		for(int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		}

		for(int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(Math.abs(height[a - 1]) >= Math.abs(height[b - 1]) && height[b - 1] > 0) {
				height[b - 1] *= -1;
			}
			if(Math.abs(height[a - 1]) <= Math.abs(height[b - 1]) && height[a - 1] > 0) {
				height[a - 1] *= -1;
			}
		}

		int ans = 0;

		for(int i = 0; i < n; i++) {
			if(height[i] > 0) {
				ans++;
			}
		}

		System.out.println(ans);

		sc.close();

	}

}


Measured memory_bytes: 60116
N,W=[int(x) for x in input().split()]
w=[-1 for _ in range(N)]
v=[-1 for _ in range(N)]
for i in range(N):
	w[i],v[i]=[int(x) for x in input().split()]
#Constraints N<=100 W<=10^9 w[i]<=10^9 and v[i]<=10^3
#dp[w] used to store maximum value at weight<=w
#dp[v] used to store minimum weight at value==v
dp=[1000000002 for _ in range(100001)]
dp[0]=0
for i in range(N):
	for v_ in range(100000,v[i]-1,-1):
		#print(v_-v[i])
		dp[v_]=min(dp[v_],dp[v_-v[i]]+w[i])
for v_ in range(100000,-1,-1):
	if dp[v_]<=W: print(v_); break

Measured memory_bytes: 74668
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

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; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int sum = 700;
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s.at(i) == 'o') sum += 100;
	}
	cout << sum << endl;
}


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


using namespace std;




int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> switch_;
    vector<int> p;
    vector<vector<int>> condition;

    for(int i=0; i<pow(2, N); i++){
        switch_.push_back(i);
    }

    for(int i=0; i<M; i++){
        int k;
        cin >>k;
        vector<int> tmp;
        for(int j=0; j<k; j++){
            int tmp_val;
            cin >> tmp_val;
            tmp.push_back(tmp_val);
        }
        condition.push_back(tmp);

    }

    for(int i=0; i<M; i++){
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }

    for(int i=0; i<M; i++) {
        vector<int> cond = condition[i];
        vector<int> tmp;

        for(int j=0; j<switch_.size(); j++){
            int count = 0;
            for(auto& c: cond){
                if (switch_[j] & (1<<(c-1))){
                    count++;
                }
            }
            if(count%2 == p[i]) {
                tmp.push_back(switch_[j]);
            }
        }
        switch_ = tmp;
        if(switch_.size()==0)
            break;
    }

    cout<<switch_.size()<<endl;

    return 0;
}

Measured memory_bytes: 256
//AOJ 0000
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define MAX_A 104
#define MAX_B 104

int a,  i, dp[MAX_A][MAX_B], max, j, b;

int sort(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(){
  /*while(1){
    scanf("%d %d", &a, &b);
    if(a == 0 && b == 0) break;
    memset(dp, -1, sizeof(dp));
    for(i = 0; i < a + 2; i++){
      dp[i][0] = 0;
      dp[i][1] = 1;
    }
    for(i = 0; i < b + 2; i++){
      dp[0][i] = 0;
      dp[1][i] = 1;
    }
    dp[1][1] = 1;
    for(i = 2; i <= a; i++){
      for(j = 2; j <= b; j++){
	dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
	if(i > 2 && j > 2) dp[i][j] -= 2;
	else if(i > 2 || j > 2) dp[i][j]--;
	}
    }
    printf("%d\n", dp[a][b] % 100000);
  }
  */
  for(i = 1; i <= 9; i++)
    for(j = 1; j <= 9; j++)
      printf("%dx%d=%d\n", i, j, i * j);
  return 0;
}

Measured memory_bytes: 928