akhauriyash/Code-Regression huggingface dataset:
"""

https://atcoder.jp/contests/code-festival-2016-qualc/tasks/codefestival_2016_qualC_e

ページの合計に与える寄与を考えればよい
ある位置iにある数字の与える寄与は
(自分より右にある数字の数)! * 自分より右にあるより小さい数字の数

元からおかれている数字同士に関しての寄与はBITで終わり
元からおかれている数字 & 自由な数字の寄与は
順列の総数 * 自由な数字の中で自分より小さいものの数 * 右にある空欄の数 / 全ての空欄の数 * fac[N-1-i]
順列の総数 * 自由な数字の中で自分より大きいものの数 * 左にある空欄の数 / 全ての空欄の数 * fac[N-1-i]
で求まる

自由同士は、半分になるはずなので
fac[N-1-i] * 右にある0の数 // 2
それより左にあるfacの平均を出す？→avrage
順列の総数 * 自由な数字の中で自分より大きいものの数 * 左にある空欄の数 / 全ての空欄の数 * average

"""

mod = 10**9+7
#逆元
def inverse(a,mod): #aのmodを法にした逆元を返す
    return pow(a,mod-2,mod)

#modのn!と、n!の逆元を格納したリストを返す(拾いもの)
#factorialsには[1, 1!%mod , 2!%mod , 6!%mod… , n!%mod] が入っている
#invsには↑の逆元が入っている

def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs

def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)
    return fac[n] * inv[n-r] * inv[r] % mod

def bitadd(a,w,bit): #aにwを加える(1-origin)
 
    x = a
    while x <= (len(bit)-1):
        bit[x] += w
        x += x & (-1 * x)
 
def bitsum(a,bit): #ind 1～aまでの和を求める
 
    ret = 0
    x = a
    while x > 0:
        ret += bit[x]
        x -= x & (-1 * x)
    return ret

import sys
from sys import stdin
N = int(stdin.readline())
a = list(map(int,stdin.readline().split()))

BIT = [0] * (N+1)

fac,inv = modfac(N+10,mod)
zeronum = 0
 
ans1 = 0
RZ = [0] * N
app = [False] * (N+1)
app[0] = True

for i in range(N-1,-1,-1):

    if a[i] != 0:
        ans1 += fac[N-1-i] * ( bitsum(a[i],BIT) )
        ans1 %= mod
        bitadd(a[i],1,BIT)
        app[a[i]] = True
    else:
        zeronum += 1
    RZ[i] = zeronum

mEX = [0] * (N+1) #数字x以下の数がいくつあるか
for i in range(1,N+1):
    if app[i] == False:
        mEX[i] = mEX[i-1] + 1
    else:
        mEX[i] = mEX[i-1]

ans1 *= fac[zeronum]

ans2 = 0
ans3 = 0
tmpinv = inverse(zeronum,mod)
tmpsum = 0
for i in range(N):
    if a[i] != 0:
        ans2 += fac[zeronum] * mEX[a[i]] * RZ[i] * tmpinv * fac[N-1-i]
        ans2 += fac[zeronum] * (zeronum-mEX[a[i]]) * tmpinv * tmpsum
        ans2 %= mod
    else:
        ans3 += fac[N-1-i] * fac[zeronum] * (RZ[i]-1) * inverse(2,mod)
        tmpsum += fac[N-1-i]

print (ans1 , ans2 , ans3 , fac[zeronum],file=sys.stderr)
print ((ans1 + ans2 + ans3 + fac[zeronum]) % mod)



Measured memory_bytes: 166576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int X;
    cin >> X;
    if(X==7 || X==5 || X==3) cout << "YES" << endl;
    else cout << "NO" << endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define F false

using namespace std;

int main(void) {
	int num, i, ok = true;
	cin >> num;
	vector<int> d(num), a;
	map<int, int> mp;
	for (i = 0; i < num; i++)
		scanf("%d", &d[i]);
	sort(d.begin(), d.end());
	a.push_back(d[0]);
	mp[d[0]]++;
	for (i = 1; i < num; i++) {
		if (d[i - 1] != d[i])
			a.push_back(d[i]);
		mp[d[i]]++;
	}
	switch (a.size()) {
	case 1:
		if ((a[0] ^ a[0]) != a[0])
			ok = F;
		break;
	case 2:
		if (a[0] == 0) {
			if (mp[a[0]] * 2 != mp[a[1]])
				ok = F;
		}
		else if (a[1] == 0) {
			if (mp[a[1]] * 2 != mp[a[0]])
				ok = F;
		}
		else
			ok = F;
		break;
	case 3:
		if ((a[0] ^ a[1]) != a[2])
			ok = F;
		for (i = 0; i < 2; i++) {
			if (mp[a[i]] != mp[a[i + 1]])
				ok = F;
		}
		break;
	default:
		ok = F;
		break;
	}
	if (ok)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int[][] a = new int[n][2];
        for (int i = 0; i < n; i++) {
            a[i][0] = sc.nextInt();
            a[i][1] = sc.nextInt();
        }
        Arrays.sort(a, (x, y) -> x[0] - y[0]);
        long sum = 0;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i][1];
            if(sum >= k){
                ans = a[i][0];
                break;
            }
        }

        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 93032
package main

import (
	"fmt"
	"regexp"
)

func main() {
	var S string
	fmt.Scan(&S)

	r := regexp.MustCompile(`^A[a-z][a-z]*C[a-z]*[a-z]$`)
	if r.MatchString(S) {
		fmt.Println("AC")
	} else {
		fmt.Println("WA")
	}
}


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

using namespace std;
using ll = long long;

int const N = 200 * 1000 + 16;

int n;
int a[N];

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

  cin >> n;
  ll sum = 0;
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }

  ll d = 9e18;
  ll s = 0;
  for(int i = 0; i + 1 < n; ++i) {
    sum -= a[i];
    s += a[i];
    d = min(d, abs(s-sum));
  }

  cout << d << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>

int main()
{
	bool base[4];
	int out;
	int n;
	int score;
	std::string event;

	std::cin>>n;
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<4;i++)base[i]=0;
		out=0;
		score=0;
		while(out<3)
		{
			std::cin>>event;
			if(event=="HIT")
			{
				for(int i=2;i>=0;i--)
				{
					base[i+1]=base[i];
				}
				base[0]=true;
				if(base[3]==true)
				{
					score++;
					base[3]=false;
				}
			}
			else if(event=="HOMERUN")
			{
				for(int i=2;i>=0;i--)
				{
					if(base[i])
					{
						score++;
						base[i]=false;
					}
				}
				score++;
			}
			else if(event=="OUT")
			{
				out++;
			}
		}
		std::cout<<score<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <complex>
#include <vector>
using namespace std;

typedef complex<double> P;

#define INF 999999999
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)

//??????
double dot(P a, P b){
  return (a.real() * b.real() + a.imag() * b.imag());
}

//??????
double cross(P a,P b){
  return (a.real() * b.imag() - a.imag() * b.real());
}

//??????ab??¨???c????????¢
double distance_ls_p(P a, P b, P c) {
  if ( dot(b-a, c-a) < EPS ) return abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

//??????ab?????????c????????????
int is_point_on_line(P a, P b, P c) {
  return EQ( cross(b-a, c-a), 0.0 ) &&
         (dot(b-a, c-a) > -EPS) &&
         (dot(a-b, c-b) > -EPS);
}

//p????§????????????????????±???????
P move(P p,double v){
  P b = -p / abs(-p); //-p ?????????????????????
  return p + b * v;
}

int main(void){
  int n;
  double R;

  while(cin>>R>>n && (R||n)){
    int ans = 0;
    vector<P> p(n);
    vector<double> r(n),v(n);

    for(int i=0;i<n;i++){
      cin>>p[i].real()>>p[i].imag()>>r[i]>>v[i];
    }

    while(p.size() != 0){
      int minIdx = -1;
      double minDist = INF;

      for(int i=0;i<p.size();i++){
        //?????????????????????????????´?????????????????????
        if(abs(p[i]) < R + EPS){
          ans++;
          p.erase(p.begin()+i);
          r.erase(r.begin()+i);
          v.erase(v.begin()+i);
          i--;
          continue;
        }

        P aft = move(p[i],v[i]);
        double dist = abs(aft);

        //(0,0)???????????????????????????,??????R??????????????????????????????
        if(is_point_on_line(p[i],aft,P(0,0)) || dist < R + EPS){
          ans++;
          p.erase(p.begin()+i);
          r.erase(r.begin()+i);
          v.erase(v.begin()+i);
          i--;
          continue;
        }

        p[i] = aft;
        if(minDist > dist){
          minIdx = i;
          minDist = dist;
        }
      }

      if(minIdx == -1) break;

      P pp = p[minIdx];
      for(int i=0;i<p.size();i++){
        P b = pp / abs(pp); //pp?????????????????????
        P o = b * R + b * EPS;
        //????????????R??¢????????´???????§??????¨??????,pp????????????????????????????????¨ p[i] ????????¢??? r[i] ??\??????????????????
        if(distance_ls_p(o,b*10000000.0,p[i]) < r[i] + EPS){
          p.erase(p.begin()+i);
          r.erase(r.begin()+i);
          v.erase(v.begin()+i);
          i--;
        }
      }
    }

    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
int main(){
  ll i, j;
  ll a,b;
  cin >> a >> b;
  cout << (a - 1) * (b - 1) << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	int x;
	cin >> x;
	int ans=1;
	for(int i=2; i*i<=x; i++){
		int pow=i;
		while(pow*i<=x)
			pow*=i;
		ans=max(ans, pow);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
for i in range(100):
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    #print(h*w)
    #print(h)
    #print(w)
    for j in range(1,h+1):
        if j%2!=0:
            for k in range(1,w+1):
                if k%2!=0:
                    print('#',end='')
                elif k%2==0:
                    print('.',end='')
        elif j%2==0:
            for l in range(1,w+1):
                if l%2!=0:
                    print('.',end='')
                elif l%2==0:
                    print('#',end='')
        print('')
    print('')


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    ll n, a, b;
    cin >> n >> a >> b;

    if(b-a < 0 || a > b || (n == 1 && a != b)){
        cout << 0 << endl;
    }else{
        ll ans = (b-a) * (n-2) + 1;
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int x[26];string s;
int main(){
	cin>>s;
	rep(i,s.size()) x[s[i]-'a']++;
	ll ans = 1LL*(s.size())*(s.size()-1)/2LL;
	rep(i,26) ans-=1LL*x[i]*(x[i]-1)/2LL;
	cout<<ans+1<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <unordered_map>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main()
{
    ll N, K;
    scanf("%lld %lld", &N, &K);
    vector<ll> p(N);
    for (ll i = 0; i < N; i++)
    {
        scanf("%lld", &p[i]);
    }

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

    ll ans = 0;
    for (ll i = 0; i < K; i++)
    {
        ans += p[i];
    }

    printf("%lld\n", ans);
}


Measured memory_bytes: 3788
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int l=sc.nextInt();
		int a[][] = new int[n][m];
		int b[][] = new int[m][l];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				a[i][j]=sc.nextInt();
			}
		}
		for(int i=0;i<m;i++){
			for(int j=0;j<l;j++){
				b[i][j]=sc.nextInt();
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<l;j++){
				double sum=0;
				for(int k=0;k<m;k++){
					sum+=a[i][k]*b[k][j];
				}
				System.out.printf("%.0f",sum);
				if(j!=l-1){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 67004
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
int main(){
    int N;
    cin >> N;
    vector <string> W(N);
    for(int i = 0; i < N; i++){
        cin >> W[i];
    }
    map<string , int> shiritori;
    bool s = true;
    shiritori[W[0]];
    for(int i = 1; i < N; i++){
        if(!(shiritori.count(W[i]))){
            shiritori[W[i]]++;
            string a = W[i - 1];
            string b = W[i];
            if(!(a[a.size() - 1] == b[0])){
                s = false;
            }
        }
        else{
            s = false;
        }
    }
    if(s){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3644
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut s = vec![];
    for i in 0..n {
        s.push(read::<String>());
    }
    let m = read::<usize>();
    let mut t = vec![];
    for i in 0..m {
        t.push(read::<String>());
    }

    let mut t_count = HashMap::new();
    for word in t {
        *t_count.entry(word).or_insert(0) += 1;
    }
    let mut s_count = HashMap::new();
    for word in s {
        *s_count.entry(word).or_insert(0) += 1;
    }

    debug!(t_count);
    debug!(s_count);
    let mut ans = 0;
    for (k, v) in s_count {
        ans = max(ans, v - *t_count.entry(k).or_insert(0));
    }
    println!("{}", ans);
}

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()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main(){
	int a,b;
	cin >> a >> b;
	if(a > 0 && b > 0){
		cout << "Positive" << endl;
		return 0;
	}
	if(a <= 0 && b >= 0){
		cout <<  "Zero" << endl;
		return 0;
	}
	if(a < 0 && b < 0){
		if(-(a + b) & 1) cout << "Positive" << endl;
		else cout << "Negative" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+7;
const ll INF=2e9;//INF*INF< INT64_MAX
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long int ll;
ll su(ll m){
	ll ans=0;
	while(m){
		ans+=m%10;
		m/=10;
	}
	return ans;
}

int main(){
	ll n,ans=1e9;
	cin>>n;
	for(ll i=1;i<n;i++){
		ans=min(ans,su(i)+su(n-i));
	}
	cout<<ans<<"\n";
	
	return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  for ( int k=1; k<=100; k++ ) {
    if ( a*k%b==c ) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0; 
}

Measured memory_bytes: 3652
def main():
    N, K = map(int, input().split())
    if K % 2 == 1:
        print((N//K)**3)
    else:
        e = N//K
        o = ((N//(K//2))+1)//2
        print(e**3 + o**3)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "

const int N = 1e5+1;
ll n, a[N], delta[N];
bool solve()
{
  ll sum = 0;
  for (int i = 0; i < n; ++i)
    scanf("%lld", a+i), sum += a[i];
  ll subsum = n * (n + 1) / 2;
  if (sum % subsum) return false;
  ll t = sum / subsum;
  for (int i = 0; i < n; ++i)
    {
      ll delta = a[i] - a[(i+n-1)%n];
      ll x = t - delta;
      if (x < 0 || x % n) return false;
    }
  return true;
}
int main()
{
  while (~scanf("%lld", &n)) puts(solve()?"YES":"NO");
}


Measured memory_bytes: 1024
using System;

class tino
{
    public static void Main()
    {
        string times = Console.ReadLine();
        int time = int.Parse(times);
        int hour, minute, second;
        hour = time / 3600;
        minute = time % 3600 / 60;
        second = time % 3600 % 60;
        Console.WriteLine(hour + ":" + minute + ":" + second);
    }
}

  


Measured memory_bytes: 9108
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false);
#define rmod(x, y) ((((x)%(y))+(y))%(y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){
	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

const int maxn = 3e5+5;
const ll mod = 1e9+7;

ll mul(ll a, ll b){return a*b %mod;}
ll sub(ll a, ll b){return (((a-b)%mod)+mod)%mod;}
int n, h, w;
ll f[maxn];
ll ways[maxn];
pair<int, int> pts[maxn];
ll fpow(ll a, ll b){
	ll res = 1;
	while(b>0){
		if(b&1) res = res*a %mod;
		a = a*a %mod;
		b>>=1;
	}
	return res;
}

ll inv(int n){return fpow(n, mod-2);}
ll comb(int n, int k){
	if (k == 0 or n == k) return 1;
	return mul(f[n], inv(mul(f[k], f[n-k])));
}

bool contains(pair<int,int> &cur, pair<int, int> &prev){
	return (prev.first<=cur.first && prev.second<=cur.second);
}

int main(){
	f[0] = f[1] = 1;
	for(ll i = 2; i<maxn; i++) f[i] = mul(f[i-1], i);
	scanf("%d %d %d", &h, &w, &n);
	for(int i = 0; i<n; i++) scanf("%d %d", &pts[i].first, &pts[i].second);
	pts[n] = {h, w};
	sort(pts, pts+n);
	pair<int, int> cur, prev;
	for(int i = 0; i<=n; i++){
		cur = pts[i];
		ways[i] = comb(cur.first+cur.second-2, cur.first-1);
		for(int j = 0; j<=n; j++) if (i != j){
			prev = pts[j];
			if (contains(cur, prev)){
				int nh = cur.first-prev.first;
				int nw = cur.second-prev.second;
				ways[i] = sub(ways[i], mul(ways[j], comb(nh+nw, nh)));
			}
		} 
	}
	printf("%lld\n", ways[n]);
	return 0;
}


Measured memory_bytes: 5248
// https://atcoder.jp/contests/abc147/tasks/abc147_c
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, ans = 0;
    cin >> N;
    vector<vector<int>> t(N), f(N);
    REP(i, N) {
        int A;
        cin >> A;
        REP(j, A) {
            int x, y;
            cin >> x >> y;
            if (y == 1) {
                t[i].emplace_back(x - 1);
            } else {
                f[i].emplace_back(x - 1);
            }
        }
    }
    REP(i, (1LL) << N) {
        // 矛盾したらダメ
        bool flag = true;
        REP(j, N) {
            if (i & (1LL << j)) {
                // trueリスト
                for (auto &x : t[j]) {
                    if (!(i & (1LL << x))) {
                        flag = false;
                        break;
                    }
                }
                // falseリスト
                for (auto &x : f[j]) {
                    if ((i & (1LL << x))) {
                        flag = false;
                        break;
                    }
                }
            }
        }
        if (flag) {
            ans = max(ans, __builtin_popcount(i));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	int H=sc.nextInt();
    	int W=sc.nextInt();

    	int counter=0;
    	for(int i=0;i<H;i++) {
    		String buf=sc.next();
    		counter+=countsharp(buf);
    	}

    	if(counter==H+W-1) {
    		System.out.println("Possible");
    	}else {
    		System.out.println("Impossible");
    	}

    }


    public static int countsharp(String str) {

    	int counter=0;
    	for(int i=0;i<str.length();i++) {
    		if(str.substring(i,i+1).equals("#")) {
    			counter++;
    		}
    	}

    	return counter;

    }
}



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

int main(){
  int K;
  cin >> K;
  int sum=0;
  for(int i=0;i<K;i++){
    for(int j=0;j<K;j++){
      for(int k=0;k<K;k++){
        sum+=__gcd(__gcd(i+1,j+1),k+1);
      }
    }
  }
  cout << sum << endl;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int x;
    cin >> x;
    if (x == 7 || x == 5 || x == 3)YES;
    else NO;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define NUMMAX 1000001

int main(){

	int prime[NUMMAX]={0};
	int a,d,n,cnt;

	prime[0]=1,prime[1]=1;

	for(int i=0;i<NUMMAX;i++){
		if(prime[i]==0){
			for(int j=i*2;j<NUMMAX;j+=i){
				prime[j]=1;
			}
		}
	}

	while(1){

		cin>>a>>d>>n;
		if(a==0&&d==0&&n==0) break;

		for(int i=a,cnt=0;;i+=d){
			if(prime[i]==0) cnt++;
			if(cnt==n){
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 5072
while data = gets
	data2 = data.to_i
	count = 0
	for i in 0 ...10 
		for j in 0 ...10 
			for k in 0 ...10 
				for l in 0 ...10 
					if (i+j+k+l) == data2 
						count += 1
					end
				end
			end
		end
	end
	p count
end

Measured memory_bytes: 6108
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	n := scanInt()
	answer := f(n)
	fmt.Println(answer)
}

func debug(a ...interface{}) {
	fmt.Println(a...)
}

func f(n int) int {
	return n + n*n + n*n*n
}


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

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for(int i=n-1;i>=0;i--)
    {
        cout << a[i];
        if(i!=0) cout << " ";
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <sstream>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  long long count = 0;
  for(int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if(a % 2 == 0) {
      long long tmp = a;
      while(tmp % 2 == 0) {
        tmp /= 2;
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define DEBUG_VARIABLE(variable) cout << #variable << ":" << variable << endl

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
#define INF (1 << 9)
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

void printArray(int *array, int);
void printVector(Vector &v);
void printDimention(DVector &dv);

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    int a[n];
    int num[n];
    memset(num, 0, sizeof(num));
    
    ll cnt = 0, rem;
    rep(i, n){
        cin >> a[i];
        if(a[i] <= n){
            num[a[i] - 1]++;
        }else{
            cnt++;
        }
    }
    
    rep(i, n){
        rem = 0;
        if(num[i] > i + 1){
            rem = num[i] - (i + 1);
        }else if(0 < num[i] && num[i] < i + 1){
            rem = num[i] - 0;
        }
        cnt += rem;
    }
    cout << cnt << endl;
}

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

//Vectorの表示
void printVector(Vector &v){
    rep(i, (int)v.size()){
        if(i)   cout << " ";
        cout << v[i];
    }
    cout << endl;
}

//二次元配列の表示
void printDimention(DVector &dv){
    rep(i, (int)dv.size()){
        rep(j, (int)dv[i].size()){
            if(j)   cout << " ";
            cout << dv[i][j];
        }
        cout << endl;
    }
}

//numの中に何個2がかかってるか
int factor2(int num){
    int cnt = 0;
    while(num % 2 == 0){
        num /= 2;
        cnt++;
    }
    return cnt;
}

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

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String a = sc.next();
        char[] S = a.toCharArray();
        int[] s = new int[N];
        int[] s1=new int[N];
        Arrays.fill(s, 0);
        Arrays.fill(s1,0);
        for (int i = 1; i < N; i++) {
            if (S[i - 1] == 'E') {
                s[i] = s[i - 1] + 1;
            }else{
                s[i]=s[i-1];
            }
        }
        for (int i = N - 2; i >= 0; i--) {
            if (S[i + 1] == 'W') {
                s1[i] = s1[i + 1] + 1;
            }else{
                s1[i]=s1[i+1];
            }
        }
        int ans = 0;
        for (int i = 0; i < N; i++) {
            ans = Math.max(s[i]+s1[i], ans);
        }
        System.out.println(N-ans-1);
    }
}


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

int main(void)
{
    char a,b;
    cin >> a >> b;
    if(a == 'H')
    {
        if(b == 'H')
        {
            cout << "H";
        }
        else
        {
            cout << "D";
        }
    }
    else
    {
        if(b == 'H')
        {
            cout << "D";
        }
        else
        {
            cout << "H";
        }
    }
    return 0;
}


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


int main(){
  string s;
  cin >> s;
  int cnt = 0;
  if(s[0] == 'R'){
    cnt++;
    if(s[1] == 'R'){
      cnt++;
      if(s[2] == 'R'){
        cnt++;
      }
    }
  }
  else if(s[1] == 'R'){
    cnt++;
    if(s[2] == 'R'){
        cnt++;
    }
  }
  else if(s[2] == 'R'){
    cnt++;
  }
  cout << cnt << endl;
}  

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

long long arr[100010];
int main()
{
    long long n;
    scanf("%lld", &n);
    for(long long i = 1;i <= n;++i)
        scanf("%lld", &arr[i]);
    long long ans = 0;
    long long cur = 1;
    for(long long i = 1;i <= n;++i)
    {
        if(arr[i] > cur)
        {
            if(arr[i] == cur)
                ++cur;
            else
            {
                if(arr[i] % cur == 0)
                    ans += arr[i] / cur - 1;
                else
                    ans += arr[i] / cur;
                arr[i] = 1;
            }
        }
        cur = max(cur, arr[i] + 1);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

inline int mul( int x , int y ){
	return 1LL * x * y % mod;
}

inline void upd( int & x , int y ){
	x += y;
	if( x >= mod )
		x -= mod;
}

int get( int x ){
	return ( x % mod + mod )%mod;
}

int N , X[maxn] , Y[maxn] , M;

int main( int argc , char * argv[] ){
	N = read() , M = read();
	for(int i = 1 ; i <= N ; ++ i)
		X[i] = read();
	for(int i = 1 ; i <= M ; ++ i)
		Y[i] = read();
	sort( X + 1 , X + N + 1 );
	sort( Y + 1 , Y + M + 1 );
	int sumx = 0 , sumy = 0;
	long long pre = 0;
	for(int i = 1 ; i <= N ; ++ i){
		long long z = 1LL * (i - 1) * X[i] - pre;
		upd( sumx , z % mod );
		pre += X[i];
	}
	pre = 0;
	for(int i = 1 ; i <= M ; ++ i){
		long long z = 1LL * (i - 1) * Y[i] - pre;
		upd( sumy , z % mod );
		pre += Y[i];
	}
	cout << mul( sumx , sumy ) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    // Here your code !
    char S[27];
    int i,j,ans=0,c=0;
    
    scanf("%s",S);
    //文字列の長さ
    for(i=0; S[i] != '\0'; i++){
        c++;
    }
    for(i=0; i<c; i++){
        for(j=i+1; j<c; j++){
            if(S[i] == S[j])
            ans = 1;
        }
    }
    if(ans == 1){
        printf("no\n");
    }else{
        printf("yes\n");
    }
    return 0;
}

Measured memory_bytes: 128
N = int(input())
train = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N-1):
    t = train[i][0] + train[i][1]
    for j in range(i+1, N-1):
        if train[j][1] >= t:
            t = train[j][1] + train[j][0]
        elif t % train[j][2] == 0:
            t += train[j][0]
        else:
            #print(t+train[j][2]-t%train[j][2])
            t = t+train[j][2]-t%train[j][2]
            t += train[j][0]
    print(t)
print(0)


Measured memory_bytes: 3188
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
x = list(map(int, input().split()))
M = 10**9+7
p = 1
invs = [None]
v = 1
for i in range(2, n+1):
    invs.append(v)
    v += pow(i, M-2, M)
    v %= M
for i in range(1, n):
    p *= i
    p %= M
ans = 0
for i in range(n-1):
    ans += (x[i+1]-x[i]) * invs[i+1]
    ans %= M
ans *= p
print(ans%M)

Measured memory_bytes: 90944
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

const int INF = 1e9;
const int MOD = 1e9+7;

int gb[4200][4200];

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

  int n, k;
  cin >> n >> k;
  int dk = 2 * k;
  vi x(n), y(n), c(n);
  REP(i, n) {
    char ca;
    cin >> x[i] >> y[i] >> ca;
    int xx = x[i] % dk;
    int yy = y[i] % dk;
    if(ca != 'B') {
      yy = (yy + k) % dk;
    }
    gb[xx][yy] += 1;
    gb[xx+dk][yy] += 1;
    gb[xx][yy+dk] += 1;
    gb[xx+dk][yy+dk] += 1;
  }

  REP(i, 2*dk+1){
    REP(j, 2*dk+1){
      gb[i+1][j+1] += gb[i+1][j] + gb[i][j+1] - gb[i][j];
    }
  }

  /*
  REP(i, 2*dk+1) {
    REP(j, 2*dk+1) {
      cout << gb[i][j] << " ";
    }cout << endl;
  }cout << endl << endl;
  */

  int ans = 0;
  REP(i, dk) {
    REP(j, dk){
      int res = 0;
      res += gb[i+k][j+k] - gb[i+k][j] - gb[i][j+k] + gb[i][j];
      res += gb[i+dk][j+dk] - gb[i+dk][j+k] - gb[i+k][j+dk] + gb[i+k][j+k];
      //cout << "i : " << i << "j : " << j << endl;
      //cout << res << endl << endl;
      ans = max(ans, res);
    }
  }

  cout << ans << endl;
}

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

int main()
{
    int a, b; cin >> a >> b;
    if (a == b)
    {
        cout << "Draw";
        return 0;
    }

    if (a == 1)
    {
        cout << "Alice";
        return 0;
    }
    if (b == 1)
    {
        cout << "Bob";
        return 0;
    }
    if (a > b)
        cout << "Alice";
    else if (a < b)
        cout << "Bob";
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main(){
  long long int n,m,num=0;
  long long int money=0;
  cin >> n >> m;
  multimap<long long int,long long int> v;
  
  for(int i=0;i<n;i++){
    long long int a,b;
    cin >> a >> b;
    v.emplace(a,b); 
  }
  
  
  while(num<m){
    long long int x,y;
    x = v.begin()->first;
    y = v.begin()->second;
    if((m-num)>y){
      money += x*y;
      num += y;
    }else{
      money += x*(m-num);
      num += (m-num);
    }
    v.erase(begin(v));
  }
  
  cout << money << endl;
  
  return 0;
}

Measured memory_bytes: 6528
// created_by  Rishi_Mohan

#include<bits/stdc++.h>

#define    ll            long long int
#define    db1(x)       cout<<#x<<"="<<x<<'\n'
#define    db2(x,y)     cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define    db3(x,y,z)   cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

using namespace std;
const long long  ma = 1e18;
const long long tr = 1e9;
void solve()
{
   int n;
   cin >> n;
   vector<ll> v(n);
   //ll sum = 0 , sum1 = 0;
   int c = 0;
  // bool ok = 0;
    for(int i=0;i<n;i++)
    {
        cin >> v[i];

        if(v[i]==0) c+=1;
    }

   // if(sum>2 || ok==1) cout << "-1" << endl;
    if(c==1) cout << "0" << endl;
    else
    {
      ll ans = 1;
      // ll a_max = 0;
      // bool ok2 = 0;
      for(int i=0;i<n;i++)
      {
         ans = ans * v[i];

         //if(ans >a_max)  a_max = ans;
         //else {ok2 = 1; break;}
        // db1(ans);
        // if(ans > ma) {ok =1; break;}
      }
      if(ans > ma ||ans<0|| (ans==0 && c==0) ) cout << "-1" << endl;

      else cout <<  ans << endl;
    }

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}


Measured memory_bytes: 3980
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

//using namespace __gnu_pbds;

using namespace std;

#define ll  long long

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef unordered_map<int,int> um;
typedef unordered_set<int> us;
typedef priority_queue<int> pq;
typedef deque<int> dq;
typedef queue<int> q;
typedef stack<int> st;

#define f first
#define s second
#define pb push_back
#define mp make_pair

#define rep(i,a,b) for (auto i = a; i < b; i++)
//#define bitset<n> b<n>

/* typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set; */

//indexed_set s;
	//s.insert(2);
	//s.insert(3);
	//s.insert(7);
	//s.insert(9);

	//auto x = s.find_by_order(2);
	//s.order_of_key(7)
	
	//c_p_c();

	//__builtin_clz(x): the number of zeros at the beginning of the number
   // __builtin_ctz(x): the number of zeros at the end of the number
   // __builtin_popcount(x): the number of ones in the number
   // __builtin_parity(x): the parity (even or odd) of the number of ones

void c_p_c()
{
	
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int main(){

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	
	ll n,k;
	cin>>n>>k;

	std::vector<ll> v(n);

	rep(i,0,n){
		cin>>v[i];
	}

	std::vector<ll> res(n);

	res[0] = 0;
	res[1] = abs(v[1]-v[0]);

		rep(i,2,n){
			res[i] = 1e18;
			rep(j,1,k+1){
				if(i-j>=0)
				res[i] = min((res[i-j]+abs(v[i]-v[i-j])),res[i]);
			}
		}
	

	cout<<res[n-1];
	//ll t;
	//cin>>t;
	//while(t--){

	//}

	return 0;
	}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    ll a[n+1];
    ll ans1 = 0;
    ll ans2 = 0;
    int count1 = 0;
    int count2 = 0;
    int tail1 = -1;
    int tail2 = -1;
    int head1 = 1001001001;
    int head2 = 1001001001;
    srep(i,1,n+1){
        cin >> a[i];
        if(0<a[i]){
            if(i%2==1){
                ans1 += a[i];
                count1++;
                tail1 = i;
                if(i<head1)head1 = i;
            }else{
                ans2 += a[i];
                count2++;
                tail2 = i;
                if(i<head2)head2 = i;
            }
        }
    }
    if(max(ans1,ans2)==0){
        int ma = -1001001001;
        int x = -1;
        srep(i,1,n+1){
            if(ma<a[i]){
                ma = a[i];
                x = i;
            }
        }
        cout << ma << endl;
        cout << n-1 << endl;
        int ite = n;
        rep(i,x-1){
            cout << '1' << endl;
            ite--;
        }
        rep(i,n-x){
            cout << ite << endl;
            ite--;
        }
        return 0;
    }

    if(ans2 <= ans1){
        cout << ans1 << endl;
        cout << n-1 -(tail1-head1)/2 << endl;
        int ite = n;
        while(tail1<ite){
            cout << ite << endl;
            ite--;
        }
        while(true){
            if(ite==head1)break;
            if(0 < a[ite-2]){
                cout << ite-1 << endl;
                ite -= 2;
            }else{
                cout << ite-2 << endl;
                ite -= 2;
            }
        }
        srep(i,1,ite){
            cout << '1' << endl;
        }
    }else{
        cout << ans2 << endl;
        cout << n-1 - (tail2-head2)/2 << endl;
        int ite = n;
        while(tail2<ite){
            cout << ite << endl;
            ite--;
        }
        while(true){
            if(ite==head2)break;
            if(0 < a[ite-2]){
                cout << ite-1 << endl;
                ite -= 2;
            }else{
                cout << ite-2 << endl;
                ite -= 2;
            }
        }
        srep(i,1,ite){
            cout << '1' << endl;
        }
    }

    return 0;
}
 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    char s[300005];
    while(~scanf("%d",&n))
    {
        int min=0;
        scanf("%s",s);
        for(int i=1;i<n;i++)
        {
            if(s[i]=='E')
                min++;
        }
        int a=min;
        for(int i=1;i<n;i++)
        {
            if(s[i]=='E'&&s[i-1]=='E')
                a--;
            if(s[i]=='W'&&s[i-1]=='W')
                a++;
            if(a<min)
                min=a;
        }
        printf("%d\n",min);
    }
    return 0;
}

Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <chrono>

using namespace std;

class

BQualificationSimulator {
public:

    void solve(std::istream &in, std::ostream &out) {

        int N, A, B;
        string S;

        in >> N >> A >> B;
        in >> S;

        int domestic = 0;
        int international = 0;
        for (auto c : S) {
            if (c == 'a') {
                if (domestic + international < A + B) {
                    domestic++;
                    out << "Yes" << endl;
                } else {
                    out << "No" << endl;
                }
            }

            if (c == 'b') {
                if (domestic + international < A + B && international < B) {
                    international++;
                    out << "Yes" << endl;
                } else {
                    out << "No" << endl;
                }
            }

            if (c == 'c') {
                out << "No" << endl;
            }
        }
    }

};


int main() {
    BQualificationSimulator solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 896
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int k,x;
    cin >> k >> x;
    if(500*k>=x){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int N = 3;
  int C[3][3];
  bool check = true;
  for (int i = 0; i < N; i++)
  {
    int storage;
    for (int j = 0; j < N; j++)
    {

      cin>>C[i][j];
      if(j==0)storage = C[i][0];
      C[i][j] = C[i][j] - storage;
    }

    for (int j = 0; j < N; j++)
    {
      if(C[0][j] != C[i][j]) check = false;
    }
    
  }
  cout<<(check?"Yes":"No")<<endl;

  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


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

int main() {

    int N;
    cin >> N;

    vl A(N);
    rep(i, N) cin >> A[i];

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

    ll ans = 0;
    int itr = N-1;
    FOR(i, 1, N) {
        if (i == 1) {
            ans += A[itr];
            itr--;
            continue;
        }
        ans += A[itr];
        i++;
        if (i < N) {
            ans += A[itr];
        }
        itr--;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4836
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        boolean ans = true;
        for (int i = 0; i < s.length; i++) {
            if(i % 2 == 0){
                if(s[i] == 'L'){
                    ans = false;
                    break;
                }
            }else{
                if(s[i] == 'R'){
                    ans = false;
                    break;
                }
            }
        }
        System.out.println(ans ? "Yes" : "No");
        sc.close();

    }

}


Measured memory_bytes: 23508
a = [int(i) for i in input().split()]
count5 = 0
count7 = 0
for i in a:
    if i==5:
        count5 += 1
    if i==7:
        count7 += 1
if count5==2 and count7==1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int A = 0;
		int n = b - a;
		for(int i = 1; i < n; i++) {
			A += i;
		}
		System.out.println(A - a);
		sc.close();
	}
}


Measured memory_bytes: 21844
while True:
    c = [int(x) for x in input().split()]
    if c[0] == 0:
        break
    L = []
    for i in c:
        if i > 10:
            L.append(10)
        else:
            L.append(i)

    p = []
    for  i in range(L.count(1)+1):
        t = sum(L) + 10 *i
        if t > 21:
            t =0
        p.append(t)

    print(max(p))



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

int main(){
    int n;
    scanf("%d",&n);
    int b[n-1];
    
    for(int i=0;i<n-1;i++) scanf("%d",&b[i]);
    int ans=b[0];
    //if(b[1]>=b[0]) ans+=b[0]+b[0];
    //else ans+=b[0]+b[1];
    for(int i=0;i<n-1;i++){
        if(i==n-2) ans+=b[n-2];
        else if(b[i+1]>=b[i]) ans+=b[i];
        else ans+=b[i+1];
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256