akhauriyash/Code-Regression huggingface dataset:
n = int(input())
table = []#リストをappendして長さの違う2重配列にする
for _ in range(n):
    a = int(input())
    tmp = []
    for _ in range(a):
        person,assessment = map(int,input().split())
        person -=  1
        tmp.append([person,assessment])
    table.append(tmp)

def check(i,n):
    
    for j in range(n):
        if i >> j & 1:
            for person,assessment in table[j]:
                if (i >> person)&1 !=  assessment:
                    return False
    
    return True

ans = 0
for i in range(2**n-1,-1,-1):
    if check(i,n):
        ans = max(ans,bin(i).count("1"))
        

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define lmax LLONG_MAX
#define lmin LLONG_MIN
#define imax INT_MAX
#define imin INT_MIN
#define f(i,a,b) for(long long i=a;i<b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define tc long long test;cin>>test;while(test--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define output(a,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define up upper_bound
#define lo lower_bound
#define endl "\n"
#define mem(a) memset(a,-1,sizeof(a))
#define ll long long
#define umap unordered_map


ll fact(ll n){
    ll p=1e9+7;
    ll ans=1;
    f(i,1,n+1){
        ans=ans*i;
        ans%=p;
    }

    return ans%p;
}
ll power(ll x,ll n){
    ll p=1e9+7;
    ll ans=1;
    f(i,0,n){
        ans=ans*x;
        ans%=p;
    }

    return ans%p;
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ll n;
    cin>>n;
    ll p=1e9+7;

    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    if(n==2){
        cout<<2<<endl;
        return 0;
    }

    // cout<<;
    ll ans = power(10,n);
    ans = (ans-(2*power(9,n))%p+p)%p;
    ans = ans+power(8,n);

    cout<<ans%p<<endl;

    return 0;
}

Measured memory_bytes: 3632
from sys import stdin
#import numpy as np

readline = stdin.readline

N, Q = map(int, readline().split()) 
C = list(map(int, readline().split())) 
S = [list(map(int, readline().split())) for _ in range(Q)] 
#print(S)
def main(N, Q, C, S):    
  # Binary Indexed Tree 
  # https://juppy.hatenablog.com/entry/2018/11/17/%E8%9F%BB%E6%9C%AC_python_Binary_Indexed_Tree_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0
  b = [0 for _ in range(N+1)]
  def BIT_query(idx): #idxまでの和(1からスタート)
    res_sum = 0
    while idx > 0:
      res_sum += b[idx]
      idx -= idx&(-idx) #一番下の位を減らす（例：13=1011 → 1010 → 1000） 
    return res_sum
  def BIT_update(idx,x): #idxをx増やした時
    while idx <= N:
      b[idx] += x
      idx += idx&(-idx) #一番下の位を繰り上げる（例：13=1011 → 1100 → 10000 ※N=16のとき） 
    return

  loc = [0 for _ in range(N)] #各種類の玉のうちの最右端の所在地
  S = [(S[i], i) for i in range(Q)] #クエリ
  S.sort(key = lambda s: s[0][1]) #区間の右端でソート
  #S = np.array(S, dtype = np.int64)
  #print(S)
  ans = [0 for _ in range(Q)]
  k = 0
  for j in range(N):
    if loc[C[j]-1] > 0: #玉の更新
      BIT_update(loc[C[j]-1], -1)
    loc[C[j]-1] = j+1
    BIT_update(j+1, 1)  
    
    if S[k][0][1] == j+1:
      t = BIT_query(j+1)
    while k < len(S) and S[k][0][1] == j+1: #クエリへの返答
      ans[S[k][1]] = t - BIT_query(S[k][0][0]-1)
      k += 1
    if k == len(S):
      break
  return ans

ans = main(N, Q, C, S)
print(*ans, sep='\n')

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

int n;
string s;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    if (s=="ARC") cout<<"ABC";
    else cout<<"ARC";
    
    
    
    return 0;
}

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

void outPut(int b, int a[4][3][10])
{
	for (int x = 0; x < 3; x++)
	{
		for (int y = 0; y < 10; y++)
		{
			cout << " " << a[b][x][y];
			if (y == 9) cout << endl;
		}
	}
}
void fence()
{
	cout << "####################" << endl;
}

int main()
{
	int p[4][3][10];
	int n, b, f, r, v;
	
	for (int x = 0; x < 4; x++)
	{
		for (int y = 0; y < 3; y++)
		{
			for (int z = 0; z < 10; z++)
			{
				p[x][y][z] = 0;
			}
		}
	}

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> b >> f >> r >> v;
		p[b - 1][f - 1][r - 1] += v;
	}

	outPut(0, p);
	fence();
	outPut(1, p);
	fence();
	outPut(2, p);
	fence();
	outPut(3, p);


}


Measured memory_bytes: 3092
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitsf(n) __builtin_popcount(n)
ll power(ll x, ll y); 

const ll MOD = 1000000007;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    quickio
    int n;
    cin >> n;
    ll arr[n + 1];
    repp(i, 1, n) cin >> arr[i];
    unordered_map<ll, ll> m, f;
    repp(i, 1, n) f[i - arr[i]]++;

    ll res = 0;
    repp(i, 1, n){
        ll x = i + arr[i];
        m[i - arr[i]]++;
        res += max(0ll, f[x] - m[x]);
    }

    cout << res;
}
 
ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}


Measured memory_bytes: 35708
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,dp[109][109];
string s[109];
bool bo[109][109];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>b;
	for(i=1; i<=a; i++){
		cin>>s[i];
		for(j=1; j<=b; j++){
			if(s[i][j-1]=='.') bo[i][j]=0; else bo[i][j]=1;
		}
	}
	for(i=0; i<=max(a,b)+1; i++){
		dp[i][b+1]=a*b+2;
		dp[a+1][i]=a*b+2;
	}
	dp[a+1][b]=0;dp[a][b+1]=0;
	for(i=a; i>=1; i--){
		for(j=b; j>=1; j--){
			if(bo[i][j]==0){
				dp[i][j]=min(dp[i+1][j],dp[i][j+1]);
			}else{
				if(bo[i][j+1]==0) dp[i][j]=dp[i][j+1]+1; else dp[i][j]=dp[i][j+1];
				if(bo[i+1][j]==0){
					dp[i][j]=min(dp[i][j],dp[i+1][j]+1);
				}else{
					dp[i][j]=min(dp[i][j],dp[i+1][j]);
				}
			}
		}
	}
	cout<<dp[1][1];
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int b=0;
  char a,c,d,e;
  cin>>a>>c>>d>>e;
  if(a=='+')b++;
  else b--;
  if(c=='+')b++;
  else b--;
  if(d=='+')b++;
  else b--;
  if(e=='+')b++;
  else b--;
  cout<<b;
}

Measured memory_bytes: 256
fn main() {
    let n: usize = read();
    let v: Vec<u32> = read_vec();

    let mut ans = 0;

    for i in 0..n {
        for j in 0..n {
            if i != j {
                ans += v[i] * v[j];
            }
        }
    }

    println!("{}", ans / 2);
}





//**********************************************************************************************************************************************//

// 標準入力から一行を読み取り、指定の型に変換する関数
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec2<T: std::str::FromStr>(n: u64) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

// 10進数での各桁の和
pub fn sum_dights(x: isize) -> isize {
    if x % 10 == 0 {
        return 0
    }
    let m = x % 10;
    m + sum_dights((x - m) / 10)
}


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

int main(){
   int a,b,c;
   vector<int> x(3);
   cin >> x[0] >> x[1] >> x[2];
   sort(x.begin(),x.end());
   reverse(x.begin(),x.end());
   cout << 10*x[0]+x[1]+x[2] << endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int N = sc.nextInt();
		int[] input = new int[N];
		for (int i = 0; i < input.length; i++) {
			input[i] = sc.nextInt();
		}
		int[] diff = new int[N];
		for (int i = 0; i < input.length - 1; i++) {
			diff[i] = input[i + 1] - input[i];
		}
		diff[N - 1] = K - input[N - 1] + input[0];
		Arrays.sort(diff);
		long res = 0;
		for (int i = 0; i < input.length - 1; i++) {
			res += diff[i];
		}
		System.out.println(res);

	}
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;

int main() {
    double a,b,x;
    cin>>a>>b>>x;
    cout << fixed << setprecision(15);
    if (2*x<a*a*b){
        double y=2.0*x/double(a*b);
        double low=0.0,high=90.0;
        int c=0;
        while (c<200){
            double mid=(low+high)/2.0;
            double theta=pi*mid/180.0;
            if (tan(theta)>double(b)/double(y)){
                high=mid;
            }
            else{
                low=mid;
            }
            c+=1;
        }
        cout<<(high+low)/2.0<<endl;  
        return 0;
    }

    else{
        double y=2.0*b-2.0*double(x)/double(a*a);
        double low=0.0,high=90.0;
        int c=0;
        while (c<200){
            double mid=(low+high)/2.0;
            double theta=(pi*mid)/double(180.0);
            if (tan(theta)>double(y)/double(a)){
                high=mid;
            }
            else{
                low=mid;
            }
            c+=1;
        }
        cout<<(high+low)/2.0<<endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include<set>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

const double EPS=1e-7; // EPS=1e-8 だと誤差で間違う
const double INF=1e77;
const double PI=acos(-1);

struct point{
	double x,y;
	point():x(0),y(0){}
	point(double x,double y):x(x),y(y){}
	point &operator+=(const point &a){ x+=a.x; y+=a.y; return *this; }
	point &operator-=(const point &a){ x-=a.x; y-=a.y; return *this; }
	point &operator/=(double c){ x/=c; y/=c; return *this; }
	point operator+(const point &a)const{ return point(x+a.x,y+a.y); }
	point operator-(const point &a)const{ return point(x-a.x,y-a.y); }
	bool operator< (const point &a)const{ return x+EPS<a.x || abs(x-a.x)<EPS && y+EPS<a.y; }
};

double cross(const point &a,const point &b){ return a.x*b.y-a.y*b.x; }

double abs(const point &a){ return sqrt(a.x*a.x+a.y*a.y); }

double arg(const point &a){ double t=atan2(a.y,a.x); return t<0?t+2*PI:t; }

point rot(const point &a,double theta){ return point(a.x*cos(theta)-a.y*sin(theta),a.x*sin(theta)+a.y*cos(theta)); }

typedef vector<point> polygon;

enum{CCW=1,CW=-1,ON=0};
int ccw(const point &a,const point &b,const point &c){
	double rdir=cross(b-a,c-a);
	if(rdir> EPS) return CCW;
	if(rdir<-EPS) return CW;
	return ON;
}

polygon convex_hull(vector<point> &P){
	int n=P.size();
	polygon CH;
	if(n<=1){
		CH.insert(CH.end(),P.begin(),P.end());
		return CH;
	}
	sort(P.begin(),P.end());

	rep(_,2){
		int m=0;
		vector<point> half(n);
		rep(i,n){
			half[m++]=P[i];
			while(m>=3 && ccw(half[m-3],half[m-2],half[m-1])==CW){
				half[m-2]=half[m-1];
				m--;
			}
		}
		CH.insert(CH.end(),half.begin(),half.begin()+m-1);
		reverse(P.begin(),P.end());
	}

	return CH;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		vector<point> P(n),Q(n);
		rep(i,n) scanf("%lf%lf",&P[i].x,&P[i].y);
		rep(i,n) scanf("%lf%lf",&Q[i].x,&Q[i].y);

		if(n==1){
			puts("0");
			continue;
		}

		polygon F=convex_hull(P);
		polygon G=convex_hull(Q);

		set<point> S(Q.begin(),Q.end());

		double ans=INF;
		rep(i,G.size()){
			point v=G[i]-F[0];
			double theta=arg(G[(i+1)%G.size()]-G[i])-arg(F[1]-F[0]);

			bool ok=true;
			rep(j,n){
				if(S.count(rot(P[j]-F[0],theta)+F[0]+v)==0){
					ok=false;
					break;
				}
			}
			if(ok){
				theta=abs(theta);
				while(theta>2*PI) theta-=2*PI;
				ans=min(ans,theta);
				ans=min(ans,2*PI-theta);
			}
		}
		printf("%.9f\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1296
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
   string s; cin >> s;
   string t;
   rep(i,s.size()){
       if(s[i] == '0')t += '0';
       if(s[i] == '1')t += '1';
       if(s[i] == 'B'){
           if(t.size() == 0)continue;
           else t.erase(t.size() - 1,1);
       }
   }
   print(t);
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs_visit(int);
void dfs();

int g_n, g_M[N][N];
int g_color[N], d[N], f[N], count;

int main(){
  int u,v,k,i,j;

  scanf("%d",&g_n);
  for(i = 0; i < g_n; i++){
    for(j = 0; j < g_n; j++){
      g_M[i][j] = 0;
    }
  }
  for(i = 0; i < g_n; i++){
    scanf("%d %d", &u, &k);
    u--;
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      v--;
      g_M[u][v] = 1;
    }
  }

  dfs();
  
  return 0;
}

void dfs_visit(int u){
  int v;
  g_color[u] = GRAY;
  d[u] = ++count;
  for(v = 0; v < g_n; v++){
    if(g_M[u][v] == 0) continue;
    if(g_color[v] == WHITE) dfs_visit(v);
  }
  g_color[u] = BLACK;
  f[u] = ++count;
}

void dfs(){
  int u;
  for(u = 0; u < g_n; u++) g_color[u] = WHITE;
  count = 0;

  for(u = 0; u < g_n; u++){
    if(g_color[u] == WHITE) dfs_visit(u);
  }
  for(u = 0; u < g_n; u++){
    printf("%d %d %d\n",u+1, d[u], f[u]);
  }
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int N, A, B;
  cin >> N >> A >> B;

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

    int num = i;
    while (num > 0) {
      sum += num % 10;
      num /= 10;
    }

    if (A <= sum && sum <= B) sums += i;
  }

  cout << sums << endl;

  return 0;
}


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

#pragma warning(disable : 4996)

using namespace std;

int n, a[100000]; long long s[200001];

long long sum(int l, int r)
{
	return s[r] - s[l];
}

int main()
{
	scanf("%d", &n);

	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	s[0] = 0; for (int i = 1; i <= 2 * n; i++) s[i] = s[i - 1] + a[(i - 1) % n];

	long long ret = 0, sums = s[n];

	for (int i = 0; i < n; i++)
	{
		int posr1 = lower_bound(s, s + 2 * n + 1, s[i] + sums / 3) - s;
		int posl1 = posr1 - 1;
		int posr2 = lower_bound(s, s + 2 * n + 1, s[i] + sums * 2 / 3) - s;
		int posl2 = posr1 - 1;

		ret = max(ret, min({ sum(i, posl1), sum(posl1, posl2), sum(posl2, i + n) }));
		ret = max(ret, min({ sum(i, posr1), sum(posr1, posl2), sum(posl2, i + n) }));
		ret = max(ret, min({ sum(i, posl1), sum(posl1, posr2), sum(posr2, i + n) }));
		ret = max(ret, min({ sum(i, posr1), sum(posr1, posr2), sum(posr2, i + n) }));
	}

	printf("%lld\n", ret);

	return 0;
}

Measured memory_bytes: 4652
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int ans = 1000 - (n%1000);
  if(ans==1000) ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3156
b = list(input())

for i in range(len(b)):
  if b[i] == "A":
    b[i] = "T"
  elif b[i] == "T":
    b[i] = "A"
  elif b[i] == "C":
    b[i] = "G"
  else:
    b[i] = "C"
    
print("".join(b))


Measured memory_bytes: 8984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int main(){
  int N, X;
  cin >> N >> X;
  int S[N];
  for(int i = 0; i < N; i++) cin >> S[i];
  sort(S, S+N);
  vector<vector<ll>> dp(N+1, vector<ll>(X+1, 0));
  for(int i = 1; i <= X; i++){
    dp[1][i] = i % S[0];
  }
  for(int i = 1; i < N; i++){
    for(int j = 1; j <= X; j++){
      dp[i+1][j] = (dp[i+1][j] + i*dp[i][j] + dp[i][j % S[i]]) % mod;
    }
  }
  cout << dp[N][X] << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

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

    ll N;
    cin >> N;

    Vl rs;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            rs.push_back(i);
            if (i * i != N) {
                rs.push_back(N / i);
            }
        }
    }

    ll ans = L_INF;
    for (const auto& r : rs) {
        ans = min(ans, (r - 1) + (N / r - 1));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double r = double.Parse(Console.ReadLine());
            double a, b;
            a =  r * r * Math.PI;
            b = 2 * r * Math.PI;

            Console.WriteLine("{0:f6} {1:f6}",a,b );
        }
    }
}

Measured memory_bytes: 5780
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int n, i, count1 = 0, count2;
  long *a;

  scanf("%d", &n);
  a = malloc(sizeof(long) * n);

  for (i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }

  while(1) {
    count2 = 0;
    for (i = 0; i < n; i++) {
      if (a[i] % 2 == 0) {
        count1++;
        a[i] = a[i] / 2;
      }else {
        count2++;
      }
    }
    if (count2 == n) {
      break;
    }
  }

  printf("%d\n", count1);

  return 0;
}

Measured memory_bytes: 256
l = input()
n = len(l)
dp = [[0]*2 for _ in range(n)]
mod = 10**9 + 7
dp[0] = [2,1]
for i in range(1,n):
  if l[i] == "1":
    dp[i][0] = dp[i-1][0]*2
    dp[i][1] = dp[i-1][0] + dp[i-1][1]*3
  else:
    dp[i][0] = dp[i-1][0]
    dp[i][1] = dp[i-1][1]*3
  dp[i][0] %= mod
  dp[i][1] %= mod
print(sum(dp[n-1])%mod)

Measured memory_bytes: 19700
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  string line[3];
  while(cin>>line[0]>>line[1]>>line[2]){
    REP(i,3){
      int a=0,b=0;
      FOR(j,1,line[i].size()){
        if(line[i][j]=='A') a++;
        else b++;
      }
      if(a-b>0) a++;
      else b++;
      cout<<a<<" "<<b<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e;
  string s,ss,sss;
  cin>>a>>b;
  c=b/10,d=b%10;
  ll ans=0;
  for(int i=11;i<=b;i++){
    if(i/10>=2&&i%10>=2&&(i/10)*(i%10)<=a){
      ans++;
      }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main(){
    string s;
    int x,y,i,j,r=0,cnt;
    cin>>s>>x>>y;
    queue<int>v,h;
    for(i=0;i<s.size()&&s[i]!='T';i++)r++;
    while(i<s.size()){
        for(cnt=0,i++;i<s.size()&&s[i]!='T';i++,cnt++);
        v.push(cnt);
        for(cnt=0,i++;i<s.size()&&s[i]!='T';i++,cnt++);
        h.push(cnt);
    }
    int vs=v.size(),hs=h.size();
    bool dpv[vs+1][16001]={},dph[hs+1][16001]={};
    dpv[0][8000]=true;
    for(i=0;i<vs;i++){
        cnt=v.front();v.pop();
        for(j=0;j<=16000;j++)if(dpv[i][j])dpv[i+1][j+cnt]=dpv[i+1][j-cnt]=true;
    }
    dph[0][8000+r]=true;
    for(i=0;i<hs;i++){
        cnt=h.front();h.pop();
        for(j=0;j<=16000;j++)if(dph[i][j])dph[i+1][j+cnt]=dph[i+1][j-cnt]=true;
    }
    cout<<(dph[hs][x+8000]&&dpv[vs][y+8000]?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 124288
#include<stdio.h>
#include<math.h>
int main(void)
{
  int a,b;
  scanf("%d%d",&a,&b);

  if(a == 1 && b == 2)
    printf("3");
  else if(a == 1 && b == 3)
    printf("2");

  else if(a == 3 && b == 2)
    printf("1");

  else if(a == 3 && b == 1)
    printf("2");

  else if(a == 2 && b == 3)
    printf("1");
  else if(a == 2 && b == 1)
    printf("3");
return 0;
}


Measured memory_bytes: 128
num = str(input())
a = num[0]
b = num[1]
c = num[2]
d = num[3]
plus = ["+", "+", "+"]
minus = ["-", "-", "-"]
for i in range(2**3):
    key = []
    for j in range(3):
        if ((i>>j) &1):
            key.append("+")
        else:
            key.append("-")
    ans = a + key[0] + b + key[1] + c + key[2] + d
    if eval(ans) == 7:
        print(ans + "=7")
        break


Measured memory_bytes: 9040
import * as fs from "fs";

function strArr2numArr(strArr: string[]): number[] {
    let numArr: number[] = [];
    strArr.map((item) => {
        numArr.push(+item);
    });
    return numArr;
}

function isTriangle(a: number, b: number, c: number): boolean {
    if (a + b <= c) return false;
    if (b + c <= a) return false;
    if (c + a <= b) return false;
    return true;
}

const MOD: number = 1e9 + 7;

const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");

let n: number = +input[0];
let L: number[] = strArr2numArr(input[1].split(" "));
L.sort();

let ans: number = 0;
for (let i = 0; i < n; i++) {
    for (let j = i + 1; j < n; j++) {
        for (let k = j + 1; k < n; k++) {
            if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) continue;
            if (isTriangle(L[i], L[j], L[k])) {
                ans++;
            }
        }
    }
}

console.log(ans);


Measured memory_bytes: 32432
#include <stdio.h>
int main(void){
    int i, ii, k, n, x, y, a[200001];
    long long int tmp;
    scanf("%d%d", &n, &k);
    for (i = 0; i < n; i++)
        scanf("%d", a + i);
    for (i = k; i < n; i++)
    {
        if (a[i] >a[i - k])
            printf("Yes\n");
        else
            printf("No\n");
    }
    
}


Measured memory_bytes: 2440
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  double sum = 0;
  for(int i=0; i<N; i++) {
    double x;
    string u;
    cin >> x >> u;
    if(u == "JPY")
      sum += x;
    else
      sum += 380000 * x;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
# F - Pond Skater

from collections import deque

H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1 -= 1
y1 -= 1
x2 -= 1
y2 -= 1
grid = []
for _ in range(H):
    grid.append(list(str(input())))

dist = [[-1] * W for _ in range(H)]
dist[x1][y1] = 0
q = deque()
q.append((x1, y1))

while q:
    (x, y) = q.popleft()
    if (x, y) == (x2, y2):
        break
    for vx, vy in ((0, 1), (1, 0), (0, -1), (-1, 0)):
        for k in range(1, K+1):
            nx = x + vx*k
            ny = y + vy*k
            if nx < 0 or nx >= H or ny < 0 or ny >= W or grid[nx][ny] == '@':
                break
            if dist[nx][ny] != -1 and dist[nx][ny] != dist[x][y] + 1:
                break
            if dist[nx][ny] == -1:
                dist[nx][ny] = dist[x][y] + 1
                q.append((nx, ny))

print(dist[x2][y2])

Measured memory_bytes: 43516
import bisect
 
a, b, q = map(int, input().split())
s = sorted([int(input()) for i in range(a)])
t = sorted([int(input()) for i in range(b)])

s = [-9e20] + s + [9e20]
t = [-9e20] + t + [9e20]
 
for i in range(q):
    x = int(input())
    p = bisect.bisect_left(s,x)
    m = bisect.bisect_left(t,x)
    
    ll = max(s[p], t[m]) - x
    lr = min(s[p] * 2 - t[m-1] - x, t[m] * 2 - s[p-1] - x)
    rl = min(s[p] - t[m-1] * 2 + x, t[m] - s[p-1] * 2 + x)
    rr = x - min(s[p-1], t[m-1])

    print(min(ll, lr, rl, rr))  

Measured memory_bytes: 13796
N, M, C = map(int, input().split())
lb = list(map(int, input().split()))
la = list()

for i in range(N):
    la.append(list(map(int, input().split())))

lailb = list()
ans = 0
for i in range(N):
    lailb = [la[i][k] * lb[k] for k in range(M)]
    #print(lailb)
    if sum(lailb) + C > 0:
        ans += 1
    
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main (void){
    int a,i;
    int max,min;
    long long int n,sum=0;
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&a);
        if(i==1){
            max=a;
            min=a;
        }
        if(a>max){
            max=a;
        }
        if(a<min){
            min=a;
        }
        sum+=a;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}
        
        

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>


using namespace std;

int main(){
  long N, K;
  map<long, long> count;
  vector<long> v;
  cin >> N >> K;
  for (int i=0;i<N;i++) {
    long a, b;
    cin >> a >> b;
    if (count.find(a) == count.end()) {
      count[a] = b;
    } else {
      count[a] += b;
    }
    v.push_back(a);
  }
  std::sort(v.begin(), v.end());
  long prev = -1;
  long idx = 0;
  for (auto it = v.begin();it != v.end();it++) {
    if (prev == *it) {
      continue;
    }
    idx += count[*it];
    if (K <= idx) {
      cout << *it << endl;
      break;
    }
    prev = *it;
  }
}


Measured memory_bytes: 4980
#include<iostream>
using namespace std;
int main(){
  int n,a;
  cin>>n;
  int min=1000000,max=-1000000;
  long long sum=0;
  for(int i=0;i<n;i++){
    cin>>a;
    
    if(min>a){
      min=a;
    }
    
    if(max<a){
      max=a;
    }
    
    sum=sum+a;
    
  }
  
  
  cout<<min<<" "<<max<<" "<<sum<<endl;
}



Measured memory_bytes: 3112
#include <iostream>
#include <vector>

using namespace std;

int n, s, d, m, poz;
string sol(205, '0');
string color;
vector<int> seq, another_seq;

string interrogate(vector<int> &seq) {

    string answer;

    cout << "? ";
    for(int i = 0; i < seq.size(); ++i)
            cout << seq[i] << " ";
    cout << endl;

    cin >> answer;
    return answer;

}

int main() {

    cin >> n;

    for(int i = 1; i <= n; ++i)
            seq.push_back(i);

    color = interrogate(seq);

    seq.clear();

    s = 1;
    d = n + 1;

    while(d - s > 1) {

        m = (s + d) / 2;

        for(int i = m; i < m + n; ++i)
                seq.push_back(i);

        if(interrogate(seq) == color)
                s = m;
        else
                d = m;

        seq.clear();

    }

    poz = s;

    sol[poz] = color[0];
    sol[poz + n] = ((int)'R' + 'B') - color[0];

    for(int i = poz + 1; i < poz + n; ++i)
            seq.push_back(i);

    for(int i = 1; i <= 2 * n; ++i)
            if(i < poz || i > poz + n) {

                seq.push_back(i);
                sol[i] = interrogate(seq)[0];
                seq.pop_back();

                another_seq.push_back(i);

            }

    seq = another_seq;

    for(int i = 1; i <= 2 * n; ++i)
            if(i > poz && i < poz + n) {

                seq.push_back(i);
                sol[i] = interrogate(seq)[0];
                seq.pop_back();

            }

    cout << "! " << string(sol.begin() + 1, sol.begin()+ 2 * n + 1) << endl;
}


Measured memory_bytes: 724
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <iomanip>
#define ll long long

using namespace std;

int main(void){
    ll n, k;
    cin >> n >> k;
    if(k%2!=0){
        ll count = 0;
        for(ll i = 1; i <= n; i++)
            if(i%k==0) count++;
        cout << count*count*count << endl;
    }
    else if(k%2==0){
        ll ca = 0, cb = 0;
        for(ll i = 1; i <= n; i++){
            if(i%k==0)
                ca++;
            if(i%k==(k/2))
                cb++;
        }
        cout << ca*ca*ca+cb*cb*cb << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		int N =nextInt();
		long K = nextLong();
		long[] a = nextLongs();

		ArrayList<Integer>list = new ArrayList<>();
		Arrays.sort(a);
		int idx=0;
		for(int i=1;i<a.length;i++){
			if(a[i]!=a[idx]){
				list.add(i-idx);
				idx=i;
			}
		}
		list.add(a.length-idx);

		Collections.sort(list);
		long size=list.size();
		long ans =0;
		for(int i=0;i<list.size();i++){
			if(size<=K){
				break;
			}
			ans+=list.get(i);
			size--;
		}


		System.out.println(ans);

	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

int main(){
	int n;
	while(cin >> n){
		int sum = 0;
		for(int a = 0; a < 10; a++){
			for(int b = 0; b < 10; b++){
				for(int c = 0; c < 10; c++){
					for(int d = 0; d < 10; d++){
						if(a+b+c+d == n){
							sum++;
						}
					}
				}
			}
		}
		cout << sum << endl;
	}	
return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,sc[10010],selected;
struct Set{
  int I,U,A,P;
};
bool comp(const Set& a, const Set& b){
  if(a.A!=b.A){
    return a.A>b.A;
  }else{
    return a.P<b.P;
  }
}
vector<Set> vec;
void el(int x){
  sc[vec[x].U]++;
  selected++;
  cout<<vec[x].I<<endl;
}
int main(){
  while(1){
    cin>>n;
    for(int i=0;i<n;i++)sc[i]=0;
    vec.clear();selected=0;
    if(n==0)break;
    for(int i=0;i<n;i++){
      Set t;
      cin>>t.I>>t.U>>t.A>>t.P;
      vec.push_back(t);
    }
    sort(vec.begin(),vec.end(),comp);
    for(int i=0;i<n&&selected<26;i++){
      if(selected<10){
	if(sc[vec[i].U]<3)el(i);
      }else if(selected<20){
	if(sc[vec[i].U]<2)el(i);
      }else{
	if(sc[vec[i].U]==0)el(i);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1232
n, h = gets.strip.split.map(&:to_i)
a = readlines.map {|line| line.strip.split.map(&:to_i) }.sort

categorized = a.group_by(&:first)

usual = categorized[categorized.keys.max].sort.first

tmp_h = h
result = 0
a.select {|e| e.last>usual.first }.map(&:last).sort.reverse.each do |thr|
  tmp_h -= thr
  result+=1
  if tmp_h<=0
    p result
    exit
  end
end

# 投げダメージだけだと倒せないので投げと振りで倒す
#a.delete(usual)
result = 0

throws = a.select {|e| e.last>usual.first }.map(&:last)
throws_dmg = throws.inject(0, :+)
h -= throws_dmg
result += throws.length

#if usual.last > usual.first
#  h -= usual.last
#  result += 1
#end

result += (h/usual.first.to_f).ceil

p result


Measured memory_bytes: 23664
#include <atcoder/dsu>
#include <cstdio>

using namespace std;
using namespace atcoder;

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    dsu d(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        scanf("%d %d %d", &t, &u, &v);
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                printf("1\n");
            } else {
                printf("0\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3504
/*  2019 6/23
    A Graph
*/

#include<iostream>
using namespace std;
static const int N = 100;

int main() {
    int M[N][N];
    int n, u, k, v;

    cin >> n;

    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        u--;  // 0 origin

        for (int j = 0; j < k; ++j) {
            cin >> v;
            v--;

            M[u][v] = 1;
        }
    }

    // output
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if ( j ) cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }

    return 0;

}




Measured memory_bytes: 3120
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(){
	
	char s;
	
	while(1){
		scanf("%c", &s);
		if(islower(s) != 0){
			s = toupper(s);
		}else if(isupper(s) != 0){
			s = tolower(s);
		}
		printf("%c", s);
		if(s == '\n')break;
	}
	
	return 0;
}

Measured memory_bytes: 3124
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

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

int main() {
    int n, k, l; cin >> n >> l >> k;
    UnionFind uf1(n), uf2(n);
    while (l--) {
        int p, q; cin >> p >> q; p--, q--;
        uf1.unionSet(p, q);
    }
    while (k--) {
        int r, s; cin >> r >> s; r--, s--;
        uf2.unionSet(r, s);
    }

    map<pair<int, int>, int> cnt;
    for (int i = 0; i < n; i++) {
        cnt[{uf1.root(i), uf2.root(i)}]++;
    }
    for (int i = 0; i < n; i++) {
        cout << cnt[{uf1.root(i), uf2.root(i)}] << " \n"[i == n - 1];
    }

    return 0;
}

Measured memory_bytes: 13568
import java.util.*;
import java.util.stream.*;

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

        var amax = (long) Math.pow( x+0.9, 0.2 );
        for(long a = 1; a <= amax; a++) {
            var b = longPow(x - a*a*a*a*a, 0.2);
            // System.out.println("# " + a + " " + (-b));
            if(a*a*a*a*a + b*b*b*b*b == x) {
                System.out.println(a + " " + (-b));
                System.exit(0);
            }
        }

        var bmax = (long) Math.pow( (x/5)+0.9, 0.25 );
        for(long b = 0; b <= bmax; b++) {
            var a = longPow(x + b*b*b*b*b, 0.2);
            // System.out.println("% " + a + " " + b);
            if(a*a*a*a*a - b*b*b*b*b == x) {
                System.out.println(a + " " + b);
                System.exit(0);
            }
        }
    }

    static long longPow(long x, double p) {
        assert x >= 0;
        return (long) Math.pow(x+0.9, p);
    }
}


Measured memory_bytes: 38944
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import sys
from collections import defaultdict


def solve(values, _nb, max_capacity):
    dp = {}
    dp[0] = 0
    for w, v in values:
        keys = sorted(dp.keys(), reverse=True)
        for vk in keys:
            if vk + v in dp:
                dp[vk + v] = min(dp[vk + v], dp[vk] + w)
            else:
                dp[vk + v] = dp[vk] + w
    result = 0
    for v, w in dp.items():
        if w <= max_capacity and v > result:
            result = v
    return result


def solve_better(values, _nb, max_capacity):
    dp = [0] * (max_capacity + 1)
    for w, v in values:
        # dp = dp[:w] + [max(dp[j], dp[j - w] + v) for j in range(w, max_capacity + 1)]
        dp[w:] = [max(dpj, dpjw + v) for dpj, dpjw in zip(dp[w:], dp[:-w])]
    return dp[max_capacity]


def solve_slow(values, nb, max_capacity):
    dp = [[0 for _ in range(max_capacity + 1)] for _ in range(nb + 1)]
    for i in range(1, nb + 1):
        w, v = values[i - 1]
        for j in range(1, max_capacity + 1):
            if w <= j:
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
            else:
                dp[i][j] = dp[i - 1][j]
    # print("\n".join(map(str, dp)))
    return dp[nb][max_capacity]


def do_job():
    "Do the work"
    # first line is number of test cases
    N, W = map(int, input().split())
    values = []
    for _ in range(N):
        values.append(list(map(int, input().split())))
    result = solve(values, N, W)
    print(result)


def print_output(testcase, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


Measured memory_bytes: 15776
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  // val a = new Array[Int](N)


  val N = in.next().toInt

  if(N == 1) {
    println("Yes")
    println(2)
    println("1 1")
    println("1 1")
  }
  else{
    var flag = false
    var s = -1
    breakable {
      for(i <- 2 to 1000) {
        if (N * 2 == i * (i+1)) {
          flag = true
          s = i
          break
        }
      }
    }

    if(flag) {
      val ans = Array.ofDim[Int](s+1, s)
      for(i <- 1 to s) {
        ans(0)(i-1) = i
      }

      var cnt = s + 1
      for(i <- 1 until s+1) {
        for (k <- 1 to i) {
          ans(i)(k-1) = ans(k-1)(i-1)
        }
        for (k <- i+1 to s) {
          ans(i)(k-1) = cnt
          cnt += 1
        }
      }


      pw.println("Yes")
      pw.println(s+1)
      for(i <- 0 until s+1) {
        pw.print(s)
        pw.print(" ")
        pw.println(ans(i).mkString(" "))
      }
      pw.flush()
    }
    else {
      println("No")
    }
  }
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 41960
s = input()[::-1]
i = 0
while True:
    if s[i:i+5] == "maerd":
        i += 5
    elif s[i:i+7] == "remaerd":
        i += 7
    elif s[i:i+5] == "esare":
        i += 5
    elif s[i:i+6] == "resare":
        i += 6
    else:
        print("NO")
        break
    if i == len(s):
        print("YES")
        break

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

int main(){
  string s;
  int c=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='(')c++;
    if(s[i]==')')c--;
    if(s[i]=='*')cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 3196
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define max 100000

int* sortMaxmin(int*, int);
int* sortMinmax(int*, int);
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
    int n, i, count=0;
    int d[max];
    
    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%d", &d[i]);
    }
    
    qsort(d, n, sizeof(int), compare_int);
    
    printf("%d", d[n/2]-d[n/2-1]);
    
    return 0;
}

int* sortMaxmin(int *a, int b)
{
    int i, j, tmp;
    for(i=0; i<b; i++){
        for (j=i+1; j<b; j++) {
            if(a[i]>a[j]){
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    return a;
}

int* sortMinmax(int *a, int b)
{
    int i, j, tmp;
    for(i=0; i<b; i++){
        for (j=i+1; j<b; j++) {
            if(a[i]<a[j]){
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    return a;
}



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

int main(){
    int q; cin >> q;
    set<int> a;
    rep(i ,q){
        int m , x;
        cin >> m >> x;
        switch (m)
        {
        case 0: 
            a.insert(x);
            cout << a.size() << endl; 
            break;
        case 1:
            /* decltype(a)::iterator */ auto itr = a.find(x);
            cout << (itr!=a.end() ? 1 : 0) << endl;
            break;
        }
    }
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define INF 1020304050

int main()
{
  int n;cin>>n;
  vector<vector<int>> a(n,vector<int>(n));
  int i,j,k,l;
  rep(i,n)
  {
    rep(j,n)
    {
      cin>>a[i][j];
    }
  }
  bool ok=true;
  rep(i,n)
  {
    rep(j,n)
    {
      rep(k,n)
      {
        if(a[i][j]>a[i][k]+a[k][j])
        {
          ok=false;
        }
      }
    }
  }
  if(!ok)cout<<-1<<endl;
  else
  {
    ll ans=0;
    rep(i,n)
    {
      rep(j,i)
      {
        bool add=true;;
        rep(k,n)
        {
          if(i==k||j==k)continue;
          if(a[i][j]==a[i][k]+a[k][j])
          {
            add=false;
          }
        }
        if(add)ans+=a[i][j];
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 640
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i, n) {
    cin >> vec[i];
  }
  int ans = 0;
  rep(i, n) {
    for (int j = i+1; j < n; j++) {
      ans += vec[i] * vec[j];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

cumsum = [a[0]]
for i in range(1, n):
    cumsum.append(cumsum[i-1] + a[i])

i, k = 0, 2
ans = 10**18
for j in range(1, n-2):
    while i < j:
        p = cumsum[i]
        q = cumsum[j] - cumsum[i]
        p_new = cumsum[i+1]
        q_new = cumsum[j] - cumsum[i+1]
        if abs(q_new - p_new) > abs(q - p):
            break
        else:
            i += 1

    while k < n-1:
        r = cumsum[k] - cumsum[j]
        s = cumsum[n-1] - cumsum[k]
        r_new = cumsum[k+1] - cumsum[j]
        s_new = cumsum[n-1] - cumsum[k+1]
        if abs(s_new - r_new) > abs(s - r):
            break
        else:
            k += 1

    pqrs = [p, q, r, s]
    ans = min(ans, abs(max(pqrs) - min(pqrs)))
    # print(i, j, k, ans, pqrs)
    
print(ans)


Measured memory_bytes: 25676
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
 
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int a, b;
    cin >> a >> b;
    int ans = 1;
    while(ans <= 1009) {
        int x = ans * 8 / 100;
        int y = ans * 10 / 100;
        if(x == a && y == b) {
            break;
        }
        ans++;
    }
    if(ans <= 1009) {
        cout << ans << endl;
    } 
    else cout << -1 << endl;
}


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

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

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

    double ans;
    ans = r * 2 * M_PI;

    // cout << ans << endl;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 3784
import math

def dis(n, x1, x2, d):
    dist = 0
    for i in range(n):
        dist += (abs(x1[i] - x2[i]))**d
    
    dist = pow(dist, 1/d)
    
    return dist

def chev(n, x1, x2):
    d = []
    for i in range(n):
        d.append(abs(x2[i]-x1[i]))
    
    return max(d)

n = int(input())
x1 = list(map(int, input().split()))
x2 = list(map(int, input().split()))

for i in range(1,4):
    print('%.5f'%dis(n,x1, x2, i))

print('%.5f'%chev(n, x1, x2))


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int div = 0, ans = 0;
  for (int i = 100;; i--) {
    if (A % i == 0 && B % i == 0) div++;
    if (div == K) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

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

    string S;
    cin >> S;
    
    char prev = S[0];
    for (int i = 1; i < S.length(); ++i) {
        if (prev == S[i]) {
            cout << "Bad" << endl;
            return 0;
        }
        prev = S[i];
    }

    cout << "Good" << endl;

    return 0;
}


Measured memory_bytes: 256