akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/


template<typename T> ostream& operator<<(ostream& os,const set<T> st){
    os << "[";
    for(T v : st) os << v << ",";
    os << "]" << endl;
}

int main(){
    int N;
    while(cin>>N){
        if(N==0) break;
//        cerr << "----------" << endl;

        set<int> p[128];

        for(int i=0;i<N;i++){
            int m;cin>>m;
//            debug(m);
            rep(j,m){
                int t;cin>>t;t--;
                p[i].insert(t);
            }
        }

        int k;cin>>k;
        vector<int> l(k);
        rep(i,k){
            cin >> l[i];
            l[i]--;
        }
        sort(all(l));

        vector<int> d;
        for(int i=0;i<N;i++){
            bool f=true;
            for(int j=0;j<k;j++){
                if(!p[i].count(l[j])){
                    f=false;
                    break;
                }
            }
            if(f) d.pb(i);
        }
//        debug(d);
        if(d.size()==1){
            cout << d[0]+1 << endl;
        }else{
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 3572
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        x1,y1=xy[i]
        x2,y2=xy[j]
        ans+=((x1-x2)**2+(y1-y2)**2)**(1/2)
ans/=n/2
print(ans)

Measured memory_bytes: 9380
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();

        boolean[] na = new boolean[N + 1];
        for (int i = 0; i < K; i++) {
            int d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                na[sc.nextInt()] = true;
            }
        }
        int count = 0;
        for (int i = 1; i <= N; i++) {
            count += !na[i] ? 1 : 0;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 46284
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	vector<int> v(3);
	REP(i, 3) cin >> v[i];

	sort(ALL(v));

	cout << v[0] + v[1] + v[2] * 10 << endl;

	
}


Measured memory_bytes: 256
A1,A2,A3 = map(int,input().split())
 
x = abs(A1 - A2)
y = abs(A2 - A3)
z = abs(A3 - A1)
 
if x + y <= y + z and x + y <= z + x:
	print(x + y )
elif y + z <= x + y and  y + z <= z + x:
	print(y + z )
else:
	print(z + x)

Measured memory_bytes: 3064
X = int(input())
if 1800 <= X <= 1999:
    print(1)
elif 1600 <= X <= 1799:
    print(2)
elif 1400 <= X <= 1599:
    print(3)
elif 1200 <= X <= 1399:
    print(4)
elif 1000 <= X <= 1199:
    print(5)
elif 800 <= X <= 999:
    print(6)
elif 600 <= X <= 799:
    print(7)
else:
    print(8)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    int n;
    cin >> n;
    int a[n+10];
    int count=0;
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        if(a[a[i]-1]==i+1) count++;
    }
    cout << count/2 << endl;
}

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


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e5 + 5

signed main() {
	int N, A, B;
	string s;
	cin >> N >> A >> B;
	cin >> s;
	int sum_cnt = 0;
	int soto_cnt = 0;
	rep(i, s.size()) {
		if (s[i] == 'a') {
			if (sum_cnt < A + B) {
				cout << "Yes" << endl;
				sum_cnt++;
			}
			else cout << "No" << endl;
		}
		else if (s[i] == 'b') {
			if (sum_cnt < A + B && soto_cnt < B) {
				cout << "Yes" << endl;
				sum_cnt++;
				soto_cnt++;
			}
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}
	return 0;
}

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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N+1);
  vector<ll> B(N);
  rep(i, N+1) cin >> A[i];
  rep(i, N) cin >> B[i];
  ll ans = 0;
  rep(i, N) {
    if (B[i] < A[i]) {
      ans += B[i];
    }
    else if (A[i] <= B[i] && B[i] < A[i] + A[i+1]) {
      ans += B[i];
      A[i+1] = A[i] + A[i+1] - B[i];
    }
    else if (B[i] >= A[i] + A[i+1]) {
      ans += A[i] + A[i+1];
      A[i+1] = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
char s[500005];
int main(void){
	string S; cin>>S;
	for(int i=200001;i<S.size()+200001;i++){
		s[i]=S[i-200001];
	}
	int q; cin>>q;
	int a,b; char c;
	int top=200001,last=200001+S.size()-1;
	bool x=true;
	for(int i=0;i<q;i++){
		cin>>a;
		if(a==1){
			if(x==true){
				x=false;
			}else{
				x=true;
			}
		}else{
			cin>>b>>c;
			if(b==1){
				if(x){
					top--;
					s[top]=c;
				}else{
					last++;
					s[last]=c;
				}
			}else{
				if(x){
					last++;
					s[last]=c;
				}else{
					top--;
					s[top]=c;
				}
			}
		}
	}
	if(x){
		for(int i=top;i<=last;i++){
			cout<<s[i];
		}
	}else{
		for(int i=last;i>=top;i--){
			cout<<s[i];
		}
	}
	cout<<endl;
	
	
}


Measured memory_bytes: 1024
def main():
    n = str(input())
    w = int(n[-1])
    if w in [2, 4, 5, 7, 9]:
        print('hon')
    elif w in [0, 1, 6, 8]:
        print('pon')
    elif w in [3]:
        print('bon')


def input_list():
    return list(map(int, input().split()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61708
#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rg register
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
template<class T> il T Max(T a,T b){return a>b?a:b;}
template<class T> il T Min(T a,T b){return a<b?a:b;}
long long n,ans;
int main(){
	scanf("%lld",&n),ans=1e18;
	for(rg int i=1;1ll*i*i<=n;++i) if(!(n%i)){
		ans=Min(ans,i+n/(long long)i-2ll);
	}
	printf("%lld\n",ans);
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 384
from collections import defaultdict


def main():
    N, X, Y = list(map(int, input().split(' ')))
    # d(i, j) is the minimum of ...
    # * j - i                 (not use the edge X-Y)
    # * |i - X| + 1 + |j - Y| (use the edge X-Y)
    counter = defaultdict(int)
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            k = min([j - i, abs(i - X) + 1 + abs(j - Y)])
            counter[k] += 1
    for k in range(1, N):
        print(counter[k])


if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()
ans = 0

def point(a):
    if (a == "r"):
        return p
    elif (a == "s"):
        return r
    else:
        return s

for i in range(k):
    j = 0
    while j <= ((n-i-1)//k -1):        
        if (t[i+k*j]==t[i+k*(j+1)]):
            ans += point(t[i+k*j])
            j += 2
        else:
            ans += point(t[i+k*j])
            j += 1
    if j == (n-i-1)//k:
        ans += point(t[i+k*j])
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
const int MD=1e9+7;
int f[N];
int quick_pow(int x,int y) {
    int ans=1;
    while(y) {
        if(y&1) ans=1LL*ans*x%MD;
        y>>=1;
        x=1LL*x*x%MD;
    }
    return ans;
}
void add(int &x,int y) {
    x+=y;
    if(x>=MD) x-=MD;
    if(x<0) x+=MD;
}
int main() {
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=k;i>=1;i--) {
        f[i]=quick_pow(k/i,n);
        for(int j=2*i;j<=k;j+=i) {
            add(f[i],-f[j]);
        }
    }
    int ans=0;
    for(int i=1;i<=k;i++) {
        add(ans,1LL*f[i]*i%MD);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 4084
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var input string
	var step string
	step = "No"
	input = nextLine()
	cols := strings.Split(input, "")
OUT:
	for index, char := range cols {
		if index%2 == 0 {
			switch char {
			case "R", "U", "D":
				step = "Yes"
			default:
				step = "No"
				break OUT
			}
		} else {
			switch char {
			case "L", "U", "D":
				step = "Yes"
			default:
				step = "No"
				break OUT
			}
		}
	}
	fmt.Println(step)
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
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);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i];}cerr << endl;}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    double t, a;
    cin >> t >> a;
    double array[n];
    rep(i, n){
        double h;
        cin >> h;
        array[i] = abs(t-h*0.006-a);
    }

    auto minitr = min_element(array, array+n);

    cout << minitr-array+1 << endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int checkmark(char c);

int main() {
	char mark[] = "SHCD";
	bool card[4][13] = { 0 };

	int n;
	scanf("%d", &n);
	fflush(stdin);

	int i, j;
	int num,mkn;
	char mk='\n';
	for (i = 0; i < n; i++) {
		do { scanf("%c", &mk); }
		while (mk == '\n');

		scanf("%d", &num);
		mkn = checkmark(mk);

		card[mkn][num - 1] = 1;
	
	}


	for (i = 0; i < 4; i++) for (j = 0; j < 13; j++) {
		if(!card[i][j]) printf("%c %d\n", mark[i], j + 1);
	}

	return 0;
}

int checkmark(char c) {
	int m;
	char mark[] = "SHCD";
	for (m = 0; m < 4; m++) {
		if (mark[m] == c) return m;
	}
	return -1;
}



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

int main(){
  int n;
  cin >> n;
  double tmp,sum = 0;
  for(int i=0;i<n;i++){
    cin >> tmp;
    sum += 1/tmp;
  }
  printf("%.12f\n",1/sum);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define FR(i,a,b) for(int i = (a);i<(b);i++)
#define RF(i,a,b) for(int i = (a);i>(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 1005
#define M 51
#define INF 100000000000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
inline int Max(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^b;
}
inline int Min(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^a;
}

ll dp[N][N];
ll fac[N][N];
ll invf[N][N];

ll rev(ll n) {
	ll ret = 1;
	ll exponent = MOD - 2;
	for (ll i = exponent; i; i >>= 1, n = n * n % MOD) {
		if (i & 1) {
			ret = ret * n % MOD;
		}
	}
	return ret;
}

void get_factorial_inverse(int n, int p) {
	fac[0][1] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i][1] = i * fac[i - 1][1] % p;
		for(int j = 2;j<=n;j++){
            fac[i][j] = fac[i][j-1]*fac[i][1]%p;
		}
	}
	invf[n][1] = rev(fac[n][1]);
	for (int i = n-1; i >= 0; --i) {
		invf[i][1] = invf[i + 1][1] * (i + 1) % p;
		for(int j = 2;j<=n;j++){
            invf[i][j] = invf[i][j-1]*invf[i][1]%p;
		}
	}
}

ll C(ll a,ll b)
{
    return fac[a][1]*rev(fac[b][1])%MOD*rev(fac[a-b][1])%MOD;
}
int main()
{
    int n,a,b,c,d;

    while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&d)!=EOF)
    {
        get_factorial_inverse(n,MOD);

        dp[a-1][0] = 1;
        FOR(i,1,n)dp[a-1][i] = 0;
        FOR(i,a,b)
        {
            FOR(j,0,n)
            {
                dp[i][j] = dp[i-1][j];
                int num = c;
                while(j-num*i>=0&&num<=d)
                {
                    int pre = j-num*i;
                    dp[i][j] = (dp[i][j]+dp[i-1][j-num*i]*C(n-j+num*i,num*i)%MOD*fac[num*i][1]%MOD*rev(fac[i][num]*fac[num][1]%MOD)%MOD)%MOD;
                    num++;
                }
            }
        }
        printf("%I64d\n",dp[b][n]);
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

bool bsearch(vec A, ll X, ll M)
{
    ll N = SZ(A);
    ll cnt = 0, pos;
    REP(i,0,N) {
        pos = lower_bound(ALL(A), X - A[i]) - A.begin();
        cnt += N - pos;
    }
    return cnt < M;
}


int main()
{
    ll N, M;
    cin >> N >> M;
    vec A(N);
    REP(i,0,N) cin >> A[i];
    
    ASC(A);
    
    ll ng = -1, ok = A[N-1] * 2 + 1, mid;
    while(abs(ok - ng) > 1) {
        mid = (ok + ng) / 2;
        if(bsearch(A, mid, M)) ok = mid;
        else ng = mid;
    }

    vec csum(N+1, 0);
    ll pos, cnt, sum = 0;
    REP(i,0,N) csum[i+1] = csum[i] + A[i];
    REP(i,0,N) {
        pos = upper_bound(ALL(A), ng - A[i]) - A.begin();
        cnt = N - pos;
        sum += cnt * A[i] + (csum[N] - csum[pos]);
        M -= cnt;
    }
    sum += M * ng;

    PR(sum);

    return 0;
}

/*

A_1 + A_1, ..., A_x + A_y, ..., A_n + A_n

(A_x + A_y) + ... + (A_x + A_n)
= A_x * C + (A_y + ... + A_n)

*/

Measured memory_bytes: 4828
# -*- coding: utf-8 -*-
n = int(input())

for k in range(1,n+1):
    s = k*(k+1)//2
    if s==n:
        res = set(range(1,k+1))
        break
    if s>=n and (s-n)<=k:
        res = set(range(1,k+1))
        res.remove(s-n)
        break

for r in res:
    print(r)


Measured memory_bytes: 3660
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  ll x,y;cin>>x>>y;
  ll a,b,c,d;
  ll ans;
  if(abs(x)>=abs(y) &&x>0 && y>0)ans=abs(abs(x)-abs(y))+2;
  if(abs(x)<=abs(y) &&x>0 && y>0)ans=abs(abs(x)-abs(y));
  if(abs(x)>=abs(y) &&x<0 && y<0)ans=abs(abs(x)-abs(y));
  if(abs(x)<=abs(y) &&x<0 && y<0)ans=abs(abs(x)-abs(y))+2;
  if(abs(x)>=abs(y) &&x>0 && y<0)ans=abs(abs(x)-abs(y))+1;
  if(abs(x)<=abs(y) &&x>0 && y<0)ans=abs(abs(x)-abs(y))+1;
  if(abs(x)>=abs(y) &&x<0 && y>0)ans=abs(abs(x)-abs(y))+1;
  if(abs(x)<=abs(y) &&x<0 && y>0)ans=abs(abs(x)-abs(y))+1;
  if(x==0&&y>0)ans=y;
  if(x==0&&y<0)ans=abs(y)+1;
  if(y==0&&x<0)ans=abs(x);
  if(y==0&&x>0)ans=abs(x)+1;
  if(x==0 && y==0)ans=0;
  cout<<ans<<endl;
}
  
  

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

int main() {
    int n;
    cin >> n;

    int sum = 0;
    vector<int> a;
    for (int i = 1; i <= n; i++) {
        if (sum > n) break;
        a.push_back(i);
        sum += i;
    }

    if (sum == n) {
        for (auto c : a) cout << c << endl;
        return 0;
    }

    for (int i = 1; i <= n; i++) {
        if (sum - i == n) {
            a.erase(a.begin() + i - 1);
        }
    }

    for (auto c : a) cout << c << endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(){
    int h, w;
    int i, j;

    while(1){
        scanf("%d %d",&h, &w);
        if(h == 0 && w == 0) break;

        for(i = 0; i < h; i++){
            for(j = 0; j < w; j++){
                if(i == 0 || j == 0 || i == h-1 || j == w-1){
                    printf("#");
                }
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2088
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    E=[[] for _ in range(n)]
    idx={}
    for i in range(n-1):
        a,b=map(int,input().split())
        a-=1; b-=1
        E[a].append(b)
        E[b].append(a)
        idx[(a,b)]=i
        idx[(b,a)]=i

    k=max(len(E[i]) for i in range(n))
    # dfs
    ans=[None]*(n-1)
    Q=[(0,-1)]
    while(Q):
        v,p=Q.pop()
        # 根のとき -> 辺を張る
        if(p==-1):
            col=1
            for nv in E[v]:
                ans[idx[(v,nv)]]=col
                col+=1
                Q.append((nv,v))
        # そうでないとき -> 親の色は除外
        else:
            col=1
            for nv in E[v]:
                if(nv==p): continue
                col+=(col==ans[idx[(v,p)]]) # 親の色になってしまったら足す
                ans[idx[(v,nv)]]=col
                col+=1
                Q.append((nv,v))

    print(k)
    print(*ans,sep='\n')
resolve()

Measured memory_bytes: 91040
// Problem : Divide them all
// Contest : CodeChef - Code Invicta
// URL : https://www.codechef.com/GHC32020/problems/MOON
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
 
 
 
 
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
 
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define mod 998244353
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}


int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<vec> g(n);
    fo(i,n-1){
        g[i].pb(i + 1);
        g[i + 1].pb(i);
    }
    g[x].pb(y);
    g[y].pb(x);
    vec ans(n + 1, 0);
    fo(i,n){
        vec vis(n, 0);
        vec dis(n, 0);
        queue<int> q;
        q.push(i);
        vis[i] = 1;
        while(!q.empty()){
            int p=q.front();
            q.pop();
            for(auto it:g[p]){
                if(vis[it]==0){
                    vis[it]=1;
                    dis[it] = dis[p] + 1;
                    q.push(it);
                }
            }
            
        }
        //deb1a(dis);
        fo(i,n){
            ans[dis[i]]++;
        }
    }
    foo(i, 1, n)
            cout
        << ans[i] / 2 << endl;
    
} 

Measured memory_bytes: 384
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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


use std::collections::HashSet;

fn main() {
    input! {
        s: i32,
    }
    
    let mut set = HashSet::new();
    
    let mut a = s;
    for m in 1..1000000 {
        if (!set.insert(a)) {
            println!{"{}", m};
            break;
        }
                
        a = match a % 2 {
            0 => a / 2,
            _ => 3 * a + 1,
        };
    }
}

Measured memory_bytes: 4352
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


template<typename T, typename U>
void fill_all(T& v, const U& p) {
	v = p;
}
template<typename T, size_t N, typename U>
void fill_all(T(& v)[N], const U& p) {
	for (auto& i : v) { fill_all(i, p); }
}

int32_t N;
std::string S;
int32_t in_sum;
int64_t in_multi;
int64_t func3(int32_t i, int32_t sum, int64_t multi, int over)
{
	if (i == N) {
		if (sum > 0) {
			return 1;
		}
		if (sum == 0 && multi < in_multi) {
			return 1;
		}
		if (sum == 0 && multi == in_multi && over==1) {
			return 1;
		}
		return 0;
	}
	static std::unordered_map<int64_t, int64_t> dp[14][9 * 14 + 1][3];

	if (dp[i][sum][over].count(multi) > 0) {
		return dp[i][sum][over][multi];
	}
	auto& memo = dp[i][sum][over][multi];
	for (int32_t x = 0; x <= std::min(sum, 9); x++)
	{
		int next_over = over;
		if (next_over == 0) {
			if (x < S[i]) {
				next_over = 1;
			}
			else if(x==S[i]){
				next_over = 0;
			}
			else {
				next_over = 2;
			}
		}
		memo += func3(i + 1, sum - x, multi*(x + 1), next_over);
	}
	return memo;
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> S; N = S.size();
	for (auto& i : S) {
		i -= '0';
	}
	in_sum = 0;
	in_multi = 1;
	for (auto& i : S) {
		in_sum += i;
		in_multi *= (i+1);
	}

	out << func3(0, in_sum, 1, 0) << endl;

	return 0;
}
#endif



Measured memory_bytes: 29860
#include<bits/stdc++.h>
#define rep(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define drep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define MAGICLINE ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define se second
#define fs first
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, int> PLI;
typedef priority_queue<int> PQI;
typedef priority_queue<LL> PQL;
typedef priority_queue<PLI,
                       vector<PLI>,
                       greater<PLI> > dijQ;

const int MN = 3002;
double T[MN][MN];
vector<double> inp;

void prefill(int n){
  T[0][0] = 1;
  rep(i, 1, n+1) T[i][0] = T[i-1][0]*(1.0 - inp[i]);
}

int main(){
  MAGICLINE;
  int n; scanf("%d", &n);
  inp.pb(0);
  rep(i, 0, n){
    double a; scanf("%lf", &a);
    inp.pb(a);
  }
  prefill(n);
  rep(i, 1, n+1)
    rep(j, 1, i+1)
      T[i][j] = T[i-1][j]*(1 - inp[i]) + T[i-1][j-1]*inp[i];

  double ans = 0;
  rep(i, (n+1)/2, n+1) ans += T[n][i];
  printf("%.9lf\n", ans);
  return 0;
}


Measured memory_bytes: 68992
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

int main(){
	string w, t;
	cin >> w;
	for(int i=0; i<w.length(); i++){
		if(w[i]>='A'&&w[i]<='Z'){
			w[i] -= 'A'-'a';
		}
	}
	int ans = 0;
	for(;;){
		cin >> t;
		if(t=="END_OF_TEXT") break;
		for(int i=0; i<w.length(); i++){
			if(t[i]>='A'&&t[i]<='Z'){
				t[i] -= 'A'-'a';
			}
		}
		if(w==t) ans++;

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

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

// definitions
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define pb push_back
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256

using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dq;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;


// standard functions
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 


ll modexp(ll x, ll ex, ll modp) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x)%modp;
        ex >>= 1ll;
        x = (x * x)%modp;
    }
    return ans;
} 
 
ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}

ll binarySearch(ll arr[], ll l, ll r, ll x) 
{ 
    while (l <= r) 
    { 
        ll m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    }
    return -1; 
}

const ll MAXSIEVE=(1e3);
ll spf[MAXSIEVE];
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXSIEVE; i++) 
        spf[i] = i; 

    for (ll i=4; i<MAXSIEVE; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<MAXSIEVE; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXSIEVE; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}

// code beigns in main
int main()
{
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
        ld r;
        cin >> r;

        ld area=M_PI*r*2;
        cout << area << endl;
    }
}



Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 998244353;
const int N = 2e5 + 50;
char sh[N];


int main() {
	cin>>sh;
  int len = strlen(sh);
  if(len % 2) {
  	cout<<"No"<<endl;
  }else {
  	int flag = 1;
    for(int i=0;i<len;i+=2) {
    	if(sh[i] != 'h' || sh[i+1] != 'i') {
        	flag = 0;
          break;
        }
    }
    printf("%s\n", flag?"Yes":"No");
  }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void show(int n,int a[])
{
    for(int i=0;i<n;i++)
    {
        if(i>0)cout<<" "<<a[i];
        else cout<<a[i];
    }
    cout<<endl;
}

int bubble(int n,int a[])
{
    int sw=0;
    bool flag=1;
    for(int i=0;flag;i++)
    {
        flag=0;
        for(int j=n-1;j>=i+1;j--)
        {
            if(a[j]<a[j-1])
            {
                swap(a[j],a[j-1]);
                sw +=1;
                flag = 1;
            }
        }
    }
    show(n,a);
    return sw;
}


int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int sw = bubble(n,a);
    cout<<sw<<endl;
    return 0;
}


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

//for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//abbreviati
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//constant
const int INF = 1<<30;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet**************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin
************************************************/

//adjacency list
vector<int> to[100005];

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n; cin >> n;
    vector<ll> h(100006);
    rep(i,0,n) cin >> h[i];
    vector<ll> dp(100006,INFL);
    //vector<ll> cost(1000006);
    // rep(i,1,n){
    //     if(i==1) cost[i]=abs(h[i]-h[i-1]);
    //     else if(cost[i-1]+abs(h[i]-h[i-1])>cost[i-2]+abs(h[i]-h[i-2])){
    //         cost[i]=cost[i-2]+abs(h[i]-h[i-2]);
    //     }else{
    //         cost[i]=cost[i-1]+abs(h[i]-h[i-1]);
    //     }
    // }
    dp[0]=0;
    rep(i,1,n){
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1){
            chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
        }
    }


    cout << dp[n-1] ENDL;



    
    return 0;
}

Measured memory_bytes: 7160
import math

X = int(input())

flag = 1
while True:
  i = 2
  flag = 1
  while i * i <=  X:
    if X % i == 0:
      flag = 0
      break
    i += 1
  
  if flag == 1:
    print(X)
    break
    
  X += 1

Measured memory_bytes: 2940
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
auto no = [](){cout << "NO"; exit(0);};
auto read = [](){int x; cin >> x; return x;};
#define maxn 4800
const LL mod = 998244353;
LL f[maxn][maxn];
LL b[maxn], s[maxn];
char S[maxn]; 
int main(){
	ios::sync_with_stdio(false);
	cin >> (S + 1);
	int N = strlen(S + 1);
	for(int i = 1; i <= N; i += 1){
		b[i] = S[i] - '0';
		s[i] = s[i - 1] + b[i]; 
	}
	f[0][0] = 1;
	for(int i = 1; i <= 2 * N; i += 1)
		for(int j = 0; j <= 2 * N; j += 1) if(j <= s[min(i, N)] and i - j <= 2 * min(i, N) - s[min(i, N)])
			f[i][j] = ((j ? f[i - 1][j - 1] : 0) + f[i - 1][j]) % mod;
	cout << f[2 * N][s[N]];
}

Measured memory_bytes: 150016
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n; cin >> n;
    int d[n + 1];
    for (int i = 0; i < n; i++) cin >> d[i];
    int ans = 1;
    sort(d, d + n);
    for (int i = 0; i < n - 1; i++) {
        if (d[i] != d[i + 1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,-1,sizeof(i));
#define pb push_back

int main(){
    int n, m;
    cin >> n >> m;
    vector<int>sw[15];
    f1(m){
        int k;
        cin >> k;
        while(k--){
            int add;
            cin >> add;
            sw[i].pb(add);
        }
    }
    int in[15]={},ans = 0;
    f1(m)cin >> in[i];
    for(int k=0;k<(1<<n);k++){
        int c[15];
        f1(m){
            c[i] = in[i];
        }
        f1(m){
            for(auto z:sw[i]){
                if(k&(1<<(z-1))){
                    c[i] ^= 1;
                }
            }
        }
        int f = 0;
        //cout << endl;
        f1(m){
            f|=c[i];
        }
        if(!f){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

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

Measured memory_bytes: 3624
#pragma GCC optimize "O3"

#define F first
#define S second

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main() {
  LL n, m; scanf("%lld %lld", &n, &m);
  LL x = n * 100 + m * 1800;
  printf("%lld\n", x * (1<<m));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int main(){
    int N;
    cin >> N;
    LL v[5]={};
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        if(s[0]=='M') v[0]++;
        if(s[0]=='A') v[1]++;
        if(s[0]=='R') v[2]++;
        if(s[0]=='C') v[3]++;
        if(s[0]=='H') v[4]++;
    }
    LL ans=0;
    for(int i=0;i<(1<<5);i++){
        vector<int> l;
        for(int j=0;j<5;j++){
            if(i>>j&1) l.push_back(j);
        }
        if(l.size()!=3) continue;
        ans+=v[l[0]]*v[l[1]]*v[l[2]];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
	int n, i, t, sc[1000];
	double a, v;
	while (1) {
		scanf("%d", &n);
		if (n == 0) break;
		t = 0;
		for (i = 0; i < n; i++) {
			scanf("%d", sc + i);
			t += sc[i];
		}
		a = (double)t / (double)n;
		v = 0;
		for (i = 0; i < n; i++) {
			v += ((double)sc[i] - a) * ((double)sc[i] - a);
		}
		printf("%lf\n", sqrt(v / (double)n));
	}
	return 0;
}

Measured memory_bytes: 636
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		int[] n = new int[5];
		int res = 0;

		//System.out.printf("%d %d %d\n", N, A, B);

		for(int i = 1; i <= N; i++){
			int temp = i;
			int sum = 0;

			n[0] = temp / 10000;
			temp %= 10000;
			n[1] = temp / 1000;
			temp %= 1000;
			n[2] = temp / 100;
			temp %= 100;
			n[3] = temp / 10;
			temp %= 10;
			n[4] = temp;

			for(int j = 0; j < 5; j++) sum += n[j];
			if(sum >= A && sum <= B) res += i;
		}

		System.out.println(res);
	}
}


Measured memory_bytes: 22740
#include <iostream>

using namespace std;

void replace(string &s, const string &from, const string &to)
{
    string::size_type pos = 0;

    while (pos = s.find(from, pos), pos != string::npos) {
        s.replace(pos, from.length(), to);
        pos += to.length();
    }
}

void char_replace(string &s, const char &from, const char &to)
{
    for (int i = 0; i < s.size(); i++)
        if (s[i] == from)
            s[i] = to;
}

string check(string &s)
{
    while (s.size() > 1) {
        replace(s, "-0", "2"), replace(s, "-1", "1"), replace(s, "-2", "0");
        replace(s, "(0*0)", "0"), replace(s, "(0*1)", "0"), replace(s, "(0*2)", "0");
        replace(s, "(1*0)", "0"), replace(s, "(1*1)", "1"), replace(s, "(1*2)", "1");
        replace(s, "(2*0)", "0"), replace(s, "(2*1)", "1"), replace(s, "(2*2)", "2");
        replace(s, "(0+0)", "0"), replace(s, "(0+1)", "1"), replace(s, "(0+2)", "2");
        replace(s, "(1+0)", "1"), replace(s, "(1+1)", "1"), replace(s, "(1+2)", "2");
        replace(s, "(2+0)", "2"), replace(s, "(2+1)", "2"), replace(s, "(2+2)", "2");
    }

    return s;
}

int main()
{
    string s;

    while (cin >> s, s != ".") {
        int cnt = 0;

        for (char p = '0'; p <= '2'; p++)  
            for (char q = '0'; q <= '2'; q++)
                for (char r = '0'; r <= '2'; r++) {
                    string re = s;

                    char_replace(re, 'P', p);
                    char_replace(re, 'Q', q);
                    char_replace(re, 'R', r);
                    
                    if (check(re) == "2")
                        cnt++;
                }
                    
        cout << cnt << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

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

int main()
{
  int x, y, xx, yy;
  ci >> x >> y >> xx >> yy;

  int xxx, yyy, xxxx, yyyy;

  xxx = xx + abs(yy - y) * (y < yy ? -1 : 1);
  yyy = yy + abs(xx - x) * (x > xx ? -1 : 1);
  xxxx = xxx + abs(yyy - yy) * (yy < yyy ? -1 : 1);
  yyyy = yyy + abs(xxx - xx) * (xx > xxx ? -1 : 1);

  co << xxx << ' ' << yyy << ' ' << xxxx << ' ' << yyyy << en;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#pragma GCC Optimize("Ofast")
using namespace std;
#define ll long long
ll vis[100];

ll solve(ll val, ll n, bool flag)
{
    if(n <= val)
    {
        return val;
    }
    
    ll ans=INT_MAX;
    if(flag)
    {
        for(ll i=1;i<=9;i++)
        {
            if(vis[i]==0)
            {
                ans = min(ans,solve(val*10+i,n,false));
            }
        }
    }
    else{
    for(ll i=0;i<=9;i++){
        if(vis[i]==0)
        {
            ans = min(ans,solve((val*10)+i,n,flag));
        }
    }
        
    }
    return ans;
}



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    memset(vis,0,sizeof(vis));
    ll a,b,c;cin>>a>>b>>c;
    ll count1,count2;
    count2=count1=0;
    if(a==5)
        count1++;
    if(b==5)
        count1++;
    if(c==5)
        count1++;
        
    if(a==7)
        count2++;
    if(b==7)
        count2++;
    if(c==7)
        count2++;
        
    if(count2==1 && count1==2)
        cout<<"YES\n";
    else
        cout<<"NO\n";
        
    
    
    
    
   return 0;
}

Measured memory_bytes: 256
N, M = gets.split(' ').map(&:to_i)
light = []
M.times do
  switches = gets.split(' ').map(&:to_i)
  light.push(switches[1..N])
end
on = gets.split(' ').map(&:to_i)

cnt = 0
[0, 1].repeated_permutation(N).each do |ss|
  allon = true
  M.times do |i|
    if light[i].select{|j| ss[j - 1] == 1}.size % 2 != on[i]
      allon = false
    end
  end
  cnt += 1 if allon
end

puts cnt

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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int n;
  cin >> n;

  vector<int> ans(n + 1);

  const auto f = [](int x, int y, int z) {
    return (x + y + z) * (x + y + z) - x * y - y * z - z * x;
  };

  for (int i = 1; i < n / 3; i++) {
    for (int j = 1; j < n / 3; j++) {
      for (int k = 1; k < n / 3; k++) {
        const int a = f(i, j, k);
        if (a <= n)
          ++ans[a];
        else
          break;
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int fact(int n){
	if(n==1)return 1;
	if(n==2)return 3;
	if(n==3)return 6;
}

int f(int x){
	int cnt=0;
	for(int i=1;i*i<=x;i++){
		for(int j=1;j*j<=x;j++){
			int l=1,r=100,ans=-1;
			while(l<=r){
				int k=(l+r)/2;
				if(i*i+j*j+k*k+i*j+k*j+i*k==x)ans=k;
				if(i*i+j*j+k*k+i*j+k*j+i*k<x)l=k+1;
				else r=k-1;
			}
			if(ans!=-1){
				//cout<<x<<' '<<i<<' '<<j<<' '<<ans<<'\n';
				cnt++;
			}
		}
	}
	return cnt;
}

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cout<<f(i)<<'\n';
	}
}


Measured memory_bytes: 3520
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#define MN 40002
#define MM 5000001
#define ll long long
#define ld long double
#define inf 0x7fffffff
#define clz 1000000007
#define ers(arr,val) memset(arr,val,sizeof(arr));
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repd(i,b,a) for(int i=(b);i>=(a);i--)
#define repe(i,u) for(int i=h[u];i;i=e[i].nx)
using namespace std;
int n,m,X,Y;
int x[100001],y[100001];
int main(){
	scanf("%d%d%d%d",&n,&m,&X,&Y);
	rep(i,1,n) scanf("%d",&x[i]);
	rep(i,1,m) scanf("%d",&y[i]);
	sort(x+1,x+n+1); sort(y+1,y+m+1);
	if(x[n]<y[1]){
		if(X<y[1]&&y[1]<=Y) puts("No War");
		else puts("War");
	}else puts("War");
	return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int> a(n + 1);
	int s = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		s += a[i];
	}
	int m; cin >> m;
	while (m--) {
		int i, t; cin >> i >> t;
		cout << s + t - a[i] << '\n';
	}
}

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

using namespace std;
int a[200];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    int ans=0;
    for(int i=2;i<n;i++){
        if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]>a[i+1]&&a[i]<a[i-1])) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;



int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);

	string n;
	cin >> n;

	int sum = 0;
	for(char c : n) {
		sum += (c - '0');
	}

	if(sum % 9 == 0) {
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define int long long
const int MOD = 1e9 + 7;
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 45, maxxyz = 17, maxmask = (1ll << 16), reqbits = 16;

int n, xyz[3], dp[maxn][maxmask];

int check(int mask)
{
    int step = 2, cur = 0, sum = 0;
    while(mask > 0)
    {
        assert(step >= 0);
        ++cur;
        if(mask & 1)
        {
            sum += cur;
            cur = 0;
            if(sum > xyz[step])
                return 1;
            if(sum == xyz[step])
            {
                if(!step)
                    return 0;
                sum = 0;
                step--;
            }
        }
        mask /= 2;
    }
    return 1;
}

void printbits(int x)
{
    if(x > 1)
        printbits(x / 2);
    cout << (x & 1);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < 3; i++)
        cin >> xyz[i];
    int allon = (1ll << (reqbits + 1)) - 1;
    for(int i = 0; i < 10; i++)
        dp[1][1ll << i] = 1;
    for(int i = 1; i < n; i++)
        for(int j = 0; j < (1ll << reqbits); j++)
            if(dp[i][j])
                for(int k = 0; k < 10; k++)
                {
                    int newmask = ((j << 1) | 1);
                    newmask <<= k;
                    newmask &= allon;
                    if(check(newmask))
                    {
                        if(newmask & (1ll << reqbits))
                            newmask ^= (1ll << reqbits);
                        dp[i + 1][newmask] += dp[i][j];
                        dp[i + 1][newmask] %= MOD;
                    }
                }
    int sub = 0;
    for(int j = 0; j < maxmask; j++)
    {
        sub += dp[n][j];
        sub %= MOD;
    }
    int all = 1;
    for(int i = 0; i < n; i++)
    {
        all *= 10;
        all %= MOD;
    }
    assert(all >= 0 && sub >= 0);
    cout << (all - sub + MOD) % MOD << "\n";
    // for(int j = 0; j < maxmask; j++)
    //     if(dp[n][j] > 0 && __builtin_popcountll(j) > n)
    //         assert(false);
    return 0;
}

Measured memory_bytes: 22584
#include <bits/stdc++.h>
using namespace std;
 
 
#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;
 
ll mod = 1e9 + 7ll;
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; }
const ll inf = 1ll << 60;

int n, m, p;
vector<vector<pair<int, int>>> rpass(3000);
vector<vector<int>> pass(3000);
vector<int> cango(3000);
vector<int> cancome(3000);
vector<int> s;
vector<vector<int>> opt(3000, vector<int>(3000, -1000000000));
int main(){
    string s;
    cin >> s;
    if(s.size()%2){
        cout << "No" << endl;
        return 0;
    } else {
        rp(i, 0, s.size()/2){
            if(s.at(i*2) != 'h' or s.at(i*2+1) != 'i'){
                cout << "No" << endl;
                return 0;
            } else {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
}




Measured memory_bytes: 35712