akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

#define N 2001
#define M 924844033LL

long long f[2][N << 1][N], p[N], r;
int a[N << 1], n, k;

int main()
{
    scanf("%d%d", &n, &k);
    f[0][1][0] = 1;

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

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

    for (int i = 2; i <= n << 1; i++)
    {
        for (int j = 0; j <= i >> 1; j++)
        {
            f[0][i][j] = (f[0][i - 1][j] + f[1][i - 1][j]) % M;
            if (j && a[i] - a[i - 1] == k)
                f[1][i][j] = f[0][i - 1][j - 1];
        }
    }

    for (int i = 0; i <= n; i++)
    {
        long long g = (f[0][n << 1][i] + f[1][n << 1][i]) * p[n - i] % M;
        r = (r + ((i & 1) ? M - g : g)) % M;
    }

    printf("%lld\n", r);
    return 0;
}


Measured memory_bytes: 123776
N,M = map(int,input().split())
A = [input().strip() for _ in range(N)]
B = [input().strip() for _ in range(M)]
ind = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        flag = 0
        for k in range(M):
            for l in range(M):
                if B[k][l]!=A[i+k][j+l]:
                    flag = 1
                    break
            if flag==1:break
        if flag==0:
            ind = 1
            break
    if ind==1:break
if ind==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63868
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll MOD=1e9+7;
ll dp[3];
ll ans=1;
//modulo arithmetic
inline ll add(ll a, ll b)
{
	ll res = a + b;
	if(res >= MOD)
		return res - MOD;
	return res;
}

inline ll mult(ll a, ll b)
{
	ll  res = a;
	res *= b;
	if(res >= MOD)
		return res % MOD;
	return res;
}

inline ll sub(ll a, ll b)
{
	return (a%MOD-b%MOD+MOD)%MOD;
}


int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll n;
 	cin>>n;		
 	ll a[n];
 	memset(dp,0,sizeof(dp));
 	for(ll i=0;i<n;i++)
 	{
 		cin>>a[i];		
 		ll pos=0;
 		for(ll j=0;j<3;j++)
 		{
 			if(dp[j]==a[i])
 			{
 				pos++;
 			}
 		}
 		for(ll j=0;j<3;j++)
 		{
 			if(dp[j]==a[i])
 			{
 				dp[j]++;
 				break;
 			}
 		}			
 		ans=mult(ans,pos);
 	}
 	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
n,x,y=map(int,input().split())
x-=1;y-=1
l=[[10**4 for g in range(n)] for i in range(n)]
fl=[0 for i in range(n-1)]
for i in range(n):
    for j in range(i+1,n):
        fl[min(abs(j-i),abs(j-x)+1+abs(y-i),abs(i-x)+1+abs(y-j))]+=1
print(*fl[1:],sep="\n")
print(fl[0])

Measured memory_bytes: 37492
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
	
		Scanner stdIn = new Scanner(System.in);
		
		byte n = stdIn.nextByte();
		byte k = stdIn.nextByte();
		
		if (n % k == 0) {
			System.out.println(0);
			return;
		}
		if (n % k == 1) {
			System.out.println(1);
			return;
		}
		else {
			System.out.println(1);
			return;
		}
	
	}
		
}

Measured memory_bytes: 23636
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < ll , ll >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 
const ll inf=1e18+1e17;
const ll moda =29;
const ll modb =34483;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
/*ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}*/
const ll N =2e5+5;
void solve(){
	int x, y, z;
	cin>>x>>y>> z;
	z=z*y;
	if ( x<=z)
		cout<<"Yes\n";
	else
		cout<<"No\n";

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

	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	
	ll t=1;
	//cin>>t;
	for ( ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
    	solve();
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vl x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];
    vl p(n);
    iota(all(p),0);
    ll q=1;
    rep(i,n)q*=(i+1);
    double ans=0;
    do{
        double val=0;
        rep(i,n-1){
            val+=hypot(x[p[i+1]]-x[p[i]],y[p[i+1]]-y[p[i]]);
            // puta(x[p[i+1]]-x[p[i]],y[p[i+1]]-y[p[i]]);
        }
        ans+=val;
    }while(next_permutation(all(p)));
    fcout(10)<<ans/q<<endl;
    return 0;
}

Measured memory_bytes: 256
let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m

module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let sort_count cmp xs =
  let rec rev_merge_count xs lxs ys invs acc k =
    match xs, ys with
    | _, [] -> k invs (List.rev_append xs acc)
    | [], _ -> k invs (List.rev_append ys acc)
    | x :: xs', y :: ys' ->
        if cmp x y <= 0
        then rev_merge_count xs' (lxs - 1) ys invs (x :: acc) k
        else rev_merge_count xs lxs ys' (lxs + invs) (y :: acc) k in
  let rec rev_merge_count_rev xs ys lys invs acc k =
    match xs, ys with
    | _, [] -> k invs (List.rev_append xs acc)
    | [], _ -> k invs (List.rev_append ys acc)
    | x :: xs', y :: ys' ->
        if cmp x y > 0
        then rev_merge_count_rev xs' ys lys (lys + invs) (x :: acc) k
        else rev_merge_count_rev xs ys' (lys - 1) invs (y :: acc) k in
  let rec sort_count invs n xs k =
    match n, xs with
    | 0, _ -> k xs invs []
    | 1, x :: xs -> k xs invs [x]
    | _, _ ->
        sort_count_rev invs ((n + 1) lsr 1) xs @@ fun xs invs ys ->
          sort_count_rev invs (n lsr 1) xs @@ fun xs invs zs ->
            rev_merge_count_rev ys zs (n lsr 1) invs [] @@ k xs
  and sort_count_rev invs n xs k =
    match n, xs with
    | 0, _ -> k xs invs []
    | 1, x :: xs -> k xs invs [x]
    | _, _ ->
        sort_count invs (n lsr 1) xs @@ fun xs invs ys ->
          sort_count invs ((n + 1) lsr 1) xs @@ fun xs invs zs ->
            rev_merge_count ys (n lsr 1) zs invs [] @@ k xs in
  sort_count 0 (List.length xs) xs @@ fun _ invs zs -> invs, zs

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  Printf.printf "%d\n" @@
  ( +^ ) (k *^ fst (sort_count compare (Array.to_list as_))) @@
  ( *^ ) (k * (k - 1) / 2 mod m) @@
  fst @@
  IntMap.fold (fun _ n (acc, sum) -> (acc + n * sum, sum + n))
    (Array.fold_left (fun m a ->
      IntMap.add a (1 +
        try IntMap.find a m
        with Not_found -> 0) m) IntMap.empty as_) (0, 0)


Measured memory_bytes: 4608
using Yorukatsu055.Questions;
using Yorukatsu055.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu055.Questions
{
    /// <summary>
    /// https://atcoder.jp/contests/arc067/tasks/arc067_b
    /// </summary>
    public class QuestionD : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nab = inputStream.ReadIntArray();
            var townsCount = nab[0];
            long walk = nab[1];
            long teleport = nab[2];

            var x = inputStream.ReadIntArray();
            long totalExhaust = 0;

            for (int i = 0; i + 1 < x.Length; i++)
            {
                var distance = x[i + 1] - x[i];
                totalExhaust += Math.Min(walk * distance, teleport);
            }

            yield return totalExhaust;
        }
    }
}


namespace Yorukatsu055
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionD();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu055.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu055.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 21728
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,j,a,b,c,d,r,k,f;
    cin>>n;
    vector<ll>v1[n+1],v2[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>r;
        for(j=1;j<=r;j++)
        {
            cin>>a>>b;
            if(b==1)v1[i].pb(a);
            else
                v2[i].pb(a);
        }
    }
    c=0;
    for(i=1;i<(1<<n);i++)
    {
        f=0,r=0;
        for(j=0;j<n;j++)
        {
            if((i&(1<<j)))
            {
                r++;
                for(k=0;k<v1[j+1].size();k++)
                {
                    if((i&(1<<(v1[j+1][k]-1)))==0)
                    {
                        f=1;
                        break;
                    }
                }
                 for(k=0;k<v2[j+1].size();k++)
                {
                    if((i&(1<<(v2[j+1][k]-1)))!=0)
                    {
                        f=1;
                        break;
                    }
                }
                if(f==1)break;
            }
        }
        if(f==0)c=max(c,r);
    }
    cout<<c<<endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 1005
#define M 8000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define mk make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

int i,j,m,n,p,k,a[N][N];

int main()
{
		scanf("%d%d",&n,&m);
		scanf("%d",&k); int x=1,y=1,f=1;
		for (i=1;i<=k;++i)
		{
				scanf("%d",&p);
				for (;p--;)
				{
						a[x][y]=i;
						y+=f;
						if (y>m||y<1) 
						{
								++x;
								if (f==1) y=m; else y=1;
								f*=-1;
						}
				}
		}
		for (i=1;i<=n;++i)
		{
				for (j=1;j<=m;++j) printf("%d ",a[i][j]);
				puts("");
		}
}


Measured memory_bytes: 640
n = int(input())
b = list(map(int,input().split()))
a = list(map(int,input().split()))
lock = [0]*n

ans = 0
top = []
for i in range(n):
  if a[i] < b[i]:
    print(-1)
    exit()
  if a[i] == b[i]:
    lock[i] = 1
    continue
  if a[i-1]+a[(i+1)%n]<a[i]:
    top.append(i)
while True:
  while top:
    x = top.pop()
    ne = a[x-1]+a[(x+1)%n]
    if (a[x]-b[x])%ne == 0:
      ans += (a[x]-b[x])//ne
      lock[x] = 1
      a[x] = b[x]
    else:
      ans += a[x]//ne
      a[x] %= ne
    for i in (x+1,x-1):
      if a[i-1]+a[(i+1)%n]<a[i%n]:
        top.append(i%n)
  if lock.count(1) == n:
    print(ans)
    exit()
  elif not top:
    print(-1)
    exit()

Measured memory_bytes: 119032
s = input()
K = int(input())

kouho = [s]# for x in range(K)]

for atama in range(len(s)):
    for offset in range(K):
        tes = s[atama:atama+offset+1]
        if tes in kouho:
            continue
        kouho.append(tes)
        kouho = sorted(kouho)
        if len(kouho) > K:
            kouho.pop()

print(kouho[K-1])


Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std;  
long INF=1000000000000000;
int main() {
    long a,b;
    cin>>a>>b;
    long Monu=b-a;
    long ans=0-b;
    for(int i=1;i<=b-a;i++) ans+=i;
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  	int x;
    cin >> x;

  	if(100<=x and x<=105){
      cout << 1 << endl;
      return 0;
    }
  
    for(;;) {
      if (x<=99) {
      cout << 0 << endl;
      return 0;
      }
      int y = x % 100;
      if(y<=5 and x>=100) {
        //printf("%d %d\n",x,y);
      cout << 1 << endl;
      return 0;
      }
      x -= 105;
    }
}


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

int main()
{
    ll a, b, k;
    cin >> a >> b >> k;

    cout << max(a - k, (ll)0) << " " << max(b - max(k - a, (ll)0), (ll)0) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n, r, p, c;
        int[] card = new int[50];
        int[] tmp = new int[50];
        while(true){
            n = sc.nextInt();
            r = sc.nextInt();
            if(n == 0 && r == 0) break;
            for(int i=0;i<n;i++){
                card[i] = n-i;
            }
            for(int i=0;i<r;i++){
                p = sc.nextInt();
                c = sc.nextInt();
                for(int j=0;j<c;j++){
                    tmp[j] = card[p-1+j];
                }
                for(int j=0;j<p-1;j++){
                    card[p-2-j+c] = card[p-2-j];
                }
                for(int j=0;j<c;j++){
                    card[j] = tmp[j];
                }
            }
            System.out.println(card[0]);
        }
    }
}


Measured memory_bytes: 37940
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    vector<int> v(110, 0);
    REP (i, A, B) v[i]++;
    REP (i, C, D) v[i]++;
    int cnt = 0;
    REP (i, 0, v.size()) cnt += (v[i] == 2);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n,d,x;
    cin>>n;
    cin>>d>>x;
    int a[n];
    for(int i=0;i<n;i++)    cin>>a[i];
    int tot=0;
    for(int i=0;i<n;i++){
        int cnt=0,j=0;
        while(1 + j*a[i] <= d){
            cnt++;
            j++;
        }
        tot += cnt;
    }
    cout<<tot+x<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstdio>
using ll = long long;
using namespace std;

int T[210];
int A[210], B[210], C[210];
int dp[210][210];
int main(void)
{
    int D, N; //Dは服の計画を立てる日数 Nは服の種類の数
    cin >> D >> N;

    for (int i = 0; i < D; ++i)
        cin >> T[i];

    for (int i = 0; i < N; ++i)
        cin >> A[i] >> B[i] >> C[i]; //A度以上B度以下 おしゃれ度C

    for (int i = 0; i < 210; ++i)
        for (int j = 0; j < 210; ++j)
            dp[i][j] = -1;
    //先に温度を考慮して分類しておく
    for (int i = 0; i < N; ++i)
    {
        if (T[0] >= A[i] && T[0] <= B[i])
            dp[0][i] = 0;
    }

    for (int i = 1; i < D; ++i)
    {
        for (int j = 0; j < N; ++j)
        { //服の番号
            for (int k = 0; k < N; ++k)
            {
                if (A[k] <= T[i] && B[k] >= T[i] && dp[i - 1][j] != -1)
                {
                    dp[i][k] = max(dp[i][k], dp[i - 1][j] + abs(C[j] - C[k]));
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < N; ++i)
        ans = max(ans, dp[D - 1][i]);

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


Measured memory_bytes: 3256
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}

int main() {
  int n; cin >> n;
  vector<vector<P>> v(n, vector<P>(0));
  vector<int> u(n);
  rep(i, n){
    int a; cin >> a;
    u[i] = a;
    v[i].resize(a);
    rep(j, a){
      int x, y; cin >> x >> y;
      --x;
      v[i][j] = make_pair(x, y);
    }
  }

  int ans = 0;
  rep(s, 1<<n){
    bool flag = true;
    rep(i, n){
      if((s>>i)&1){
        rep(j, u[i]){
          if(((s>>(v[i][j].first))&1) != v[i][j].second){
            flag = false;
          }
        }
      }
    }
    if(flag) chmax(ans, __builtin_popcount(s));
  }

  cout << ans << endl;
}


Measured memory_bytes: 3580
#include "bits/stdc++.h"
using namespace std;

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int n;
LL a[200000];
LL b[200000];

int main(){
  cin>>n;
  LL lb=UINT_MAX,ub=-UINT_MAX;
  REP(i,n){
    cin>>a[i];
    b[i]=a[i]-i;
    if(b[i] < lb) lb = b[i];
    if(b[i] > ub) ub = b[i];
  }
  LL standard = b[0],del = (ub-lb)/2;
  int up_num,eq_num,down_num;
  while(1){
    up_num=0;
    eq_num=0;
    down_num=0;
    REP(i,n){
      if(b[i] > standard)up_num++;
      if(b[i] == standard)eq_num++;
      if(b[i] < standard)down_num++;
    }
    if(up_num > eq_num + down_num)
      standard += del;
    else if(down_num > eq_num + up_num)
      standard -= del;
    else
      break;
    del = max(del/2,(LL)1);
  }
  LL m = UINT_MAX;
  int max_ind;
  REP(i,n){
    if(abs(b[i]-standard) < m){
      m = abs(b[i]-standard);
      max_ind = i;
    }
  }
  LL ret=0;
  LL b_val = a[max_ind]-max_ind;
  REP(i,n){
    ret+=abs(a[i]-b_val-i);
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

void Primefactorization(int n, vi &fac) {
	for (int i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			fac[i]++;
			n = n / i;
		}
	}
	if (n != 1) fac[n]++;
	return;
}

int Power(int m, int n){
	lli ans = 1;
	while(n != 1) {
		if (n % 2 != 0) {
			ans = ans * m;
			n--;
		}
		m = m * m;
		n /= 2;
	}

	return ans * m;
}
int main() {
	int n; cin >> n;

	vi a(1000,0);
	for (int i = 0; i < n; i++) {
		int num; cin >> num;

		vi fac(1000,0);
		Primefactorization(num,fac);
		for (int j = 0; j < fac.size(); j++) {
			if (a[j] < fac[j]) {
				a[j] = fac[j];
			}
		}
		fac.clear();
	}

	lli ans = 1;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] != 0) {
			ans *= Power(i,a[i]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3112
fn read1<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 readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let mut s = read1::<String>().chars().collect::<Vec<char>>();
    s.pop();
    s.pop();
    loop {
        let h = s.len() / 2;
        let mut flg = true;
        for i in 0..h {
            if s[i] != s[i+h] {
                flg = false;
                break;
            }
        }
        if flg {
            break;
        } else {
            s.pop();
            s.pop();
        }
    }
    
    
    println!("{}", s.len());
}

Measured memory_bytes: 4352
s= str(input())
t = str(input())
s = list(s)
t = list(t)
a=0
for i in range(len(s)):
    if s[i]==t[i]:
        a = a+1
if a == len(s):
    if len(t)-len(s)==1:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 9072
n = int(input())
li = list()

for i in range(n):
    li.append(list(map(int, input().split())))

dp = [[0]*3 for i in range(n+1)]
for i in range(3):
    dp[0][i] = 0



for i in range(n):
    for j in range(3):
        #dp[i+1][j]を更新する
        maxValue = 0
        for k in range(3):
            if k== j:
                continue
            maxValue = max(maxValue, dp[i][k])
            
        
        dp[i+1][j] = maxValue + li[i][j]
        
print(max(dp[n][0],dp[n][1], dp[n][2]))

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

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int k = Integer.parseInt(br.readLine());
        if(k < 10)
            System.out.println(k);
        else {
            Sol sol = new Sol(k);
            sol.preComp();
        }
    }
}

class Sol {
    long[][] pre;
    int k, l;
    Stack<Integer> res;
    
    Sol(int k){
        this.k = k;
        this.l = 12;
        pre = new long[l][11];
        res = new Stack<>();
    }
    
    void preComp(){
       // base
       for(int dig = 0; dig < 10; ++dig){
           pre[1][dig] = 1;
       }
       pre[1][10] = 9;
       
       int stLen = 0;
       long globSum = 9;
       boolean esc = false;
       
       // rest
       for(int len = 2; len < l; ++len){
           for(int dig = 0; dig < 10; ++dig){
               for(int st = -1; st < 2; ++st){
                    int newDig= dig+st;
                    if(newDig < 0 || newDig > 9)
                        continue;
                    pre[len][dig] += pre[len-1][newDig]; 
               }
               long val = pre[len][dig];
               if(dig != 0){
                   globSum += val;
                   if(globSum >= k){
                       k -= (globSum-val);
                       stLen = len-1;
                       res.add(dig);
                       esc = true;
                       break;
                   }
               }
           }
           if(esc)
                break;
       }
        search(stLen,res.peek());
        StringBuilder sb = new StringBuilder();
        for(int el : res)
            sb.append(el);
        System.out.println(sb);
    }
    
    void search(int len, int currDig){
        if(len==0)
            return;
        
        if(k == 1 && currDig == 1){
            while(len-->0)
                res.add(0);
            return;
        }
        long tSum = 0;
        for(int st = -1; st < 2; ++st){
            int newDig = currDig+st;
            if(newDig < 0 || newDig > 9)
                continue;
            tSum += pre[len][newDig];
            if(tSum >= k){
                res.add(newDig);
                k -= (tSum - pre[len][newDig]);
                search(len-1, newDig);
                break;
            }
        }
    }
}

Measured memory_bytes: 21076
import java.util.*;

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

		String s = sc.next();
		char c[] = s.toCharArray();
		
		for(int i=0;i<4;i++) {
			num[i] = c[i]-'0';
		}
		
		calc(0,num[0],String.valueOf(num[0]));
		System.out.println(str + "=7");
	}
	
	static void calc(int p, int tmp_sum, String tmp_str) {
		if(p==3) {
			if(tmp_sum==7) {
				str = tmp_str;
			}	
			return;
		}
		
		if(p<3) {
			calc(p+1,tmp_sum+num[p+1],tmp_str+"+"+num[p+1]);
			calc(p+1,tmp_sum-num[p+1],tmp_str+"-"+num[p+1]);
		}
			
	}
}


Measured memory_bytes: 21844
H, W, N = map(int,input().split())
sr, sc = map(int,input().split())
S = input()
T = input()

cant = False
leftsafe, rightsafe, upsafe, downsafe = 1, W, 1, H

for i in reversed(range(N)):
    if i != N-1: #最後だけはT[i]を無視
        if T[i] == "R" and leftsafe > 1:
            leftsafe -= 1
        elif T[i] == "L" and rightsafe < W:
            rightsafe += 1
        elif T[i] == "D" and upsafe > 1:
            upsafe -= 1
        elif T[i] == "U" and downsafe < H:
            downsafe += 1
    
    if S[i] == "L":
        leftsafe += 1
    elif S[i] == "R":
        rightsafe -= 1
    elif S[i] == "U":
        upsafe += 1
    elif S[i] == "D":
        downsafe -= 1
    
    if leftsafe > rightsafe or upsafe > downsafe:
        cant = True
        break
    
if leftsafe > sc or rightsafe < sc or upsafe > sr or downsafe < sr:
    cant = True
    
if cant:
    print("NO")
else:
    print("YES")















Measured memory_bytes: 3888
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
	ll A, B, X;
	cin >> X;
	for (ll i = -1000;i < 1000;i++) {
		for (ll j = -1000;j < 1000;j++) {
			if (i * i * i * i * i - j * j * j * j * j == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3592
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    int N; cin >> N;
    vector<long double> x(N), y(N);

    rep(i, N) {
        cin >> x[i] >> y[i];
    }

    double ans=0;

    cout << fixed << setprecision(10);

    rep(i, N - 1) {
        for (int j = i + 1; j < N; ++j) {
            ans += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        }
    }

    cout << ans*2/N  << endl;

}

Measured memory_bytes: 768
#include <cstdio>
#include <cstdlib>
int main()
{
	int a[205];
	int n, l;
	int ans = 0, min = 100000;
	scanf("%d%d", &n, &l);
	for (int i = 1; i <= n; i++) {
		ans += l + i - 1;
		if (abs(l + i - 1) < abs(min))
			min = l + i - 1;
 	}
	ans -= min;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>
#include <unordered_map>
#include <tuple>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n,q; cin >> n >> q;
    vector<pair<int, pair<int,int>>> w(n);
    rep(i,n){
        ll s,t,x;
        cin >> s >> t >> x;
        w[i] = mp(x, mp(s-x,t-x));
    }
    sort(all(w));
    vector<ll> ans(q);
    rep(i,q) ans[i] = -1;
    set<pair<ll, int>> s;
    rep(i,q){
            ll t; cin >> t;
            s.insert(mp(t, i));
    }
    rep(i,n){
        ll st = w[i].second.first, t = w[i].second.second, x = w[i].first;
        auto it = s.lower_bound(mp(st,-1)); 
        while(s.size() && it != s.end() && (*it).first < t){
            ans[(*it).second] = x;
            s.erase(it++);
          
        }
    }
    rep(i,q) printf("%lld\n", ans[i]);
    return 0;
}

Measured memory_bytes: 18304
from sys import stdin
input = stdin.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    BC = [list(map(int, input().split())) for _ in range(Q)]

    d = dict()

    # dictに格納 O(1)
    for a in A:
        try:
            d[a] += 1
        except KeyError:
            d[a] = 1
    
    ans = 100000000000000000000000000
    ans = 0

    # 一旦ans出す
    for dat in d.items():
        ans += dat[0]*dat[1]

    # B,Cの操作
    # for bc in BC:
    #     try:
    #         d[bc[1]] += d[bc[0]]
    #     except KeyError:
    #         try:
    #             d[bc[1]] = d[bc[0]]
    #         except KeyError:
    #             d[bc[0]] = 0
    #             d[bc[1]] = 0
    #     finally:
    #     # 増減分だけ変更
    #         ans += bc[1]*d[bc[0]] - bc[0]*d[bc[0]]
    #         d[bc[0]] = 0
    #     print(ans)

    # B,Cの操作
    for bc in BC:
        if bc[0] in d:
            if bc[1] in d:
                d[bc[1]] += d[bc[0]]
                ans += bc[1]*d[bc[0]] - bc[0]*d[bc[0]]
                d[bc[0]] = 0
            else:
                d[bc[1]] = d[bc[0]]
                ans += bc[1]*d[bc[0]] - bc[0]*d[bc[0]]
                d[bc[0]] = 0
        else:
            pass
        print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 98036
#include <cstdio>

int A,B,T;

int main() {
	char c;
	for (;;) {
		c = getc(stdin);
		if (c == '\n' || c == EOF) break;
		T += (A < B ? 1:0) + (c == 'g' ? 0:-1);
		if (A < B) A++;
		else B++;
	}
	printf("%d\n", T);
}

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

int main() {
  int k,a,b;
  cin >>k>>a>>b;
  bool awse = false;
  for(int i=0;i < b-a+1;i++){
    if((a+i)%k == 0){
      awse = true;
    }
  }
  if(awse) cout << "OK" << endl;
  else cout << "NG" << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int x, a, b;
  cin >> x >> a >> b;
  int m = x-a;
  cout << m%b << endl;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
using namespace std;
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;

int n,m;
bool vis[10005];
vector<int>v,G[10005];

void dfs(int u) {
	vis[u]=1;
	for (auto p:G[u]) {
		if (!vis[p]) dfs(p);
	}
	v.pb(u);
}

int main() {
	cin>>n>>m;
	for (int i=0;i<m;i++) {
		int s,t; cin>>s>>t;
		G[s].pb(t);
	}
	for (int i=0;i<n;i++) if (!vis[i]) dfs(i);
	for (int i=v.size()-1;i>=0;i--) cout<<v[i]<<'\n';
}


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

int n =sc.nextInt();
int a[]=new int[n];
int ans[]=new int[200000];
for(int i=1;i<n;i++)
a[i]=sc.nextInt();
for(int i=1;i<n;i++)
ans[a[i]]++;
for(int i=1;i<n;i++)
System.out.println(ans[i]);
System.out.println(0);



}
}

Measured memory_bytes: 57660
#include<stdio.h>
#define ll long long
ll f(ll b){
    if(b % 4 == 0) return b;
    if(b % 4 == 1) return 1;
    if(b % 4 == 2) return b + 1;
    return 0;
}
int main(){
    ll a, b;
    scanf("%lld%lld",&a,&b);
    ll ans = f(a - 1) ^ f(b);
    if(a != b)
        printf("%lld\n",ans);
    else 
        printf("%lld\n",f(b));
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
        int cntdig1 = 0;
      int cntdig3=0;
      int cntdig5=0;
      if(a<10){
        cntdig1 += a;
      }else if(a>=10){
        cntdig1=9;
      }
      
      if(10<=a && a<1000){
       cntdig3 += a-99; 
      }else if(a>=1000){
      cntdig3=900;
      }
      
      if(1000<=a && a <100000){
        cntdig5 += a-9999;
      }else if (a>=100000){
        cntdig5=90000;
      }
      if(cntdig1<0){
        cntdig1=0;
      }
      if(cntdig3<0){
        cntdig3=0;
      }
      if(cntdig5<0){
        cntdig5=0;
      }
      int cnt =cntdig1+cntdig3+cntdig5;
		// 出力
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

const ll M = 4e18;

ll n, m, mn = M;
vector<ll> ve[1005];
vector<ll> ans;
vector<ll> now;
ll vv[1005];

void dfs(ll p)
{
    if(now.size() != 0 && p == now[0])
    {
        if(mn > now.size())
        {
            mn = now.size();
            ans = now;
        }
        return;
    }
    else if(vv[p]) return;
    if(now.size() > mn) return;
    vv[p] = true;
    now.push_back(p);
    for(ll i = 0; i < ve[p].size(); i++)
    {
        dfs(ve[p][i]);
    }
//    vv[p] = false;
    now.pop_back();
}

int main()
{
    scanf("%lld%lld", &n, &m);
    for(ll i = 0; i < m; i++)
    {
        ll u, v;
        scanf("%lld%lld", &u, &v);
        ve[u].push_back(v);
    }
    for(ll i = 1; i <= n; i++)
    {
        for(ll i = 1; i <= n; i++) vv[i] = false;
        dfs(i);
    }
    if(mn == M) printf("-1\n");
    else
    {
        printf("%lld\n", mn);
        for(ll i = 0; i < ans.size(); i++)
        {
            printf("%lld\n", ans[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 384
//????°???±????\??????????
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define MAX_V 100000

vector<int> G[MAX_V];
vector<int> depth,vs;
int id[MAX_V]={};

template<class T>
class segtree{
private:
    vector<T> dat;
    int _size;
    T _init;
    
public:
    segtree(int __size=0 , T init=numeric_limits<T>::max() ):_size(__size) , _init(init) , dat(4*__size,init){
        if(__size==0)return ;
        int x=1;
        while(x<_size)x*=2;
        _size = x;
    }
    
    int size(){
        return _size;
    }
    
    void update(int m,T x){
        int i = m+_size;
        dat[i] = x;
        while(i!=1){
            dat[i/2] = min(dat[i],dat[i^1]);
            i/=2;
        }
    }
    
    // call find(s,t)
    T find(int s,int t,int num=1,int a=0,int b=-1){
        if(b==-1)b=_size-1; //I couldn't "int b=_size".
        if(b<s||t<a)return _init;
        if(s<=a&&b<=t)return dat[num];
        return min( find(s,t,num*2,a,(a+b)/2) , find(s,t,num*2+1,(a+b)/2+1,b) );
    }
};


void dfs(int d,int num){
    depth.pb(d);
    vs.pb(num);
    rep(i,G[num].size()){
        dfs(d+1,G[num][i]);
        depth.pb(d);
        vs.pb(num);
    }
    return ;
}


void init(){
    dfs(1,0);
    rep(i,vs.size()){
        if(id[ vs[i] ]==0)id[ vs[i] ]=i;
    }
}


int main(){
    int n;
    cin>>n;
    rep(i,n){
        int k;
        cin>>k;
        rep(j,k){
            int b;
            cin>>b;
            G[i].pb(b);
        }
    }
    init();                                                         // aranging depth[] , vs[] and id[]
    segtree<pii> st(depth.size(),pii((1ULL<<31)-1,(1ULL<<31)-1));         // the number of elements is depth.size()
    rep(i,depth.size()){                                            //initialize
        st.update(i,pii(depth[i],vs[i]));
    }
    int a,b;
    int q;
    cin>>q;
    rep(i,q){
        cin>>a>>b;
        cout<<st.find(min(id[a],id[b]),max(id[a],id[b])).second<<endl;  // is equal to LCA(a,b)
    }
}

Measured memory_bytes: 19604
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;

void convert(string& S){
    int N,i,start,Slength,Count;
    while (i!=S.length()){
        Count = 0;
        for (i=0;i<S.length() ;i++){
            if (Count ==0 ){
                start = i;
            }
            if (S[i] == '('){
                Count += 1;
            }else{
                Count += -1;
            }

            if (Count < 0){
                break;
            }
        }
        if (Count < 0){
            S.insert(S.begin(),'(');
        }
    }

    Count = 0;
    for (i=0;i<S.length() ;i++){
        if (S[i] == '('){
            Count += 1;
        }else{
            Count += -1;
        }
    }

    for (i= 0; i< Count ; i++){
        S.insert(S.end(),')');
    }

}

int main()
{
    // 整数の入力
    int N,i,start,Slength,Count;
    string S;
    cin >> N;
    cin >> S;
    convert(S);
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList <Integer> list = new ArrayList<>();
        int count = 1;
        int ans = 0;
        
        for(int i=0; i<N; i++){
            int tmp = sc.nextInt();
            if(tmp == count){
                ans++;
                count++;
            }
            list.add(tmp);
        }
        
        if(ans == 0){
            System.out.println("-1");
        }else{
        System.out.println(N-ans);
        }
   }
}


Measured memory_bytes: 66100
N,K=map(int,input().split())
S=str(input())



happiness=N
for i in range(N):
    if i==0:
        if S[0]=='L':
            happiness-=1
            continue
    if i==N-1:
        if S[N-1]=='R':
            happiness-=1
            continue
    if S[i]=='R':
        if S[i+1]=='L':
            happiness-=1
    else:
        if S[i-1]=='R':
            happiness-=1

print(min(happiness+2*K,N-1))

Measured memory_bytes: 3316
n,*l=map(int,open(0).read().split())
e=[1]
for i in range(n):
  e+=[(e[-1]-l[i])*2]
a=t=0
for i in range(n,-1,-1):
  if l[i]>e[i]:
    print(-1)
    break
  t=min(l[i]+t,e[i])
  a+=t
else:
  print(a)

Measured memory_bytes: 674384
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
vector <vector<int> > A;
int magic(int n){
	int c=1,x=n/2,y=x+1;
	while (c<=n*n){
		if (A[y][x]==0){
			A[y][x]=c++;
			x++;
		}
		else x+=n-1;
		y+=n+1;
		x%=n;
		y%=n;
	}
	return 0;
}
int main(){
	int n,i,j;
	while(cin>>n,n!=0){
		A.resize(n);
		for(i=0;i<n;i++)A[i].resize(n,0);
		magic(n);
		for(i=0;i<n;i++){
			for(j=0;j<n;j++)printf("%4d",A[i][j]);
			cout<<endl;
		}
		A.clear();
	}
}

Measured memory_bytes: 1228
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
int main(){
    int n,x=0,mx=0;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; i++){
       if(s.at(i)=='I') x++;
       else x--;
       if(x>mx) mx=x;
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;


class P
{
    static void Main()
    {
        int[] tx = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine((double)tx[0] / (double)tx[1]);
        Console.ReadLine();
    }
}


Measured memory_bytes: 13268