akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

typedef long long LL;
const int N = 1010;
int n;
LL a[N];
int vis[N];
int step[N], cnt;

void del(int x) {
	int i;
	step[++cnt] = x;
	if(x == n) {--n; return;}
	if(x == 1) {
		rep(i, 1, n-1) a[i] = a[i+1], vis[i] = vis[i+1];
		--n;
		return;
	}
	a[x-1] += a[x+1];
	rep(i, x, n-2) a[i] = a[i+2], vis[i] = vis[i+2];
	n -= 2;
	
}

int main() {
	int i, t, tag; LL sum1 = 0, sum2 = 0;
	bool spe = 1;
	scanf("%d", &n);
	rep(i, 1, n) {
		scanf("%lld", &a[i]);
		if(a[i] >= 0ll) spe = 0;
	}
	
	if(spe) {
		t = 1;
		rep(i, 1, n) if(a[i] > a[t]) t = i;
		vis[t] = 1; tag = 1;
	} else {
		for(i = 1; i <= n; i += 2)
		if(a[i] >= 0) {sum1 += a[i]; vis[i] = 1;}
		for(i = 2; i <= n; i += 2)
		if(a[i] >= 0) {sum2 += a[i]; vis[i] = 2;}
		if(sum1 > sum2) tag = 1; else tag = 2;
	}
//	printf("%d %d\n", mxl, mxr);
	
	while(vis[1] != tag) del(1);
	while(vis[n] != tag) del(n);
	while(n > 1) {
		if(vis[3] == tag) del(2); else del(3);
	}
	printf("%lld\n", a[1]);
	printf("%d\n", cnt);
	rep(i, 1, cnt) printf("%d\n", step[i]);
	return 0;
}

Measured memory_bytes: 128
import sys

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def Base(X, n):
    if (int(X/n)):
        return Base(int(X/n), n)+str(X%n)
    return str(X%n)

def main():
    N = ii()
    m = 10**100
    for i in range(N+1):
        a = sum(map(int, Base(i, 6)))
        b = sum(map(int, Base(N-i, 9)))
        m = min(m, a+b)
    print(m)

if __name__ == '__main__':
    main()


Measured memory_bytes: 80704
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            checked
            {
                string s = Console.ReadLine();

                int Rc = 0;
                int Lc = 0;

                bool isR = true;
                for (int i = 0; i < s.Length; i++)
                {
                    if (isR)
                    {
                        if ( s[i] == 'R')
                        {
                            Rc++;
                        }
                        else
                        {
                            Lc++;
                            isR = false;
                        }
                    }
                    else
                    {
                        if ( s[i] == 'L')
                        {
                            Lc++;
                        }
                        else
                        {
                            CountAndPrint(Rc, Lc);
                            Rc = 1;
                            Lc = 0;
                            isR = true;
                        }
                    }
                }

                CountAndPrint(Rc, Lc);

                Console.WriteLine();
            }
        }

        static void CountAndPrint(int Rc,int Lc)
        {
            for (int i = 0; i < Rc - 1; i++)
            {
                Console.Write("0 ");
            }
            Console.Write("{0} {1} ",
                (Rc + 1) / 2 + Lc / 2,
                Rc / 2 + (Lc + 1) / 2);
            for (int i = 0; i < Lc - 1; i++)
            {
                Console.Write("0 ");
            }
        }
    }
}


Measured memory_bytes: 15580
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();

        PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        for(int i = 0;i < n;i++){
            queue.add(sc.nextInt());
        }

        for(int i = 0;i < m;i++){
            int price = queue.poll();
            queue.add(price/2);
        }

        long sum = 0;
        while(!queue.isEmpty()){
            sum += queue.poll();
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 59404
package main

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

func main() {
	N := nextInt()
	M := nextInt()

	graph := make([][]int, N)

	for i := 0; i < M; i++ {
		a := nextInt() - 1
		b := nextInt() - 1
		graph[a] = append(graph[a], b)
		graph[b] = append(graph[b], a)
	}

	// 幅優先探索で。
	shortests := make([]pair, N)
	for i := 0; i < N; i++ {
		shortests[i] = pair{-1, N + 10}
	}
	shortests[0].size = 0

	done := make([]bool, N)
	queue := make([]int, 0, N)
	queue = append(queue, 0)

	for len(queue) > 0 {
		p := queue[0]
		queue = queue[1:]

		if done[p] {
			continue
		}
		done[p] = true

		for i := 0; i < len(graph[p]); i++ {
			n := graph[p][i]
			queue = append(queue, n)

			s := shortests[p].size + 1
			if shortests[n].size > s {
				shortests[n].node = p
				shortests[n].size = s
			}
		}
	}

	fmt.Println("Yes")
	for i := 1; i < N; i++ {
		fmt.Println(shortests[i].node + 1)
	}
}

type pair struct {
	node int
	size int
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 30672
N, Q = map(int, input().split())
d = {'L': -1, 'R': 1}
s = input()
v = []
for i in range(Q):
    a, b = input().split()
    v.append((a, d[b]))


def checkL(x, s):
    for a, b in v:
        if a == s[x]:
            x += b
        if x < 0:
            return True
        if x >= len(s):
            return False


def checkR(x, s):
    for a, b in v:
        if a == s[x]:
            x += b
        if x >= len(s):
            return True
        if x < 0:
            return False


left = -1
l, r = -1, N
while r - l > 1:
    mid = (r + l) // 2
    if checkL(mid, s):
        l = mid
    else:
        r = mid

left = l


right = N
l, r = -1, N
while r - l > 1:
    mid = (r + l) // 2
    if checkR(mid, s):
        r = mid
    else:
        l = mid

right = r

print(max(0, right - left - 1))

Measured memory_bytes: 17840
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
const int INF = 1001001001;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define re0 return 0
#include<string.h>
int npr(int n , int r){//nPr
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}
int gcd(int a, int b) {//最大公約数
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {//最小公倍数
    return a * b / gcd(a, b);
}
int digsum(int n) {//桁和
    int res = 0;
    while(n > 0) {
        //res += n%10;
        //　↑をres++;にすれば桁数
         res++;
        n /= 10;
    }
    return res;
}
bool isPrime(int x){//素数判定
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
/*bit全探索
for (int bit = 0; bit < (1<<N); ++bit) {
}
if (bit & (1 << i)) {
}
*/


signed main(){
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int ans = 0;
    rep(i,n){
        if(s[i]!=t[i]){
            ans++;
        }
    }

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


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

using namespace std;

int n;
vector<vector<int>> g; 
int timeT = 0;
vector<int> d, f;
 
void dfs(int node){
    timeT++;

    if(d[node] == 0){
        d[node] = timeT;
    }

    for(auto next : g[node]){
        if(d[next] == 0){
            dfs(next);
        }
    }
    
    timeT++;
    if(f[node] == 0){
        f[node] = timeT;
    }
    return;
}
    
int main(){
    
    time(NULL);
    cin >> n;

    d.assign(n + 1, 0);
    f.assign(n + 1, 0);

    g.assign(n + 1, vector<int>());

    for(int i = 0; i < n; i++)
    {
        int nod, numOut;
        cin  >> nod >> numOut;
        for(int j = 0; j < numOut; j++)
        {
            int temp;
            cin >> temp;
            g[nod].push_back(temp);
        }
    }
    
    for(int i = 1; i <= n; i++)
    {
        if(d[i] == 0){
            dfs(i);
        }
    }

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

    return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << a*b/2;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m],d=0,k;
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        d=d+a[i];
    }
    k=n-d;
    if(k<0)
        k=-1;
    cout<<k;
}


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

int key[10];

// プロトタイプ宣言
void Reset(void);
char Output(int);
// ここまで

int main(){
	Reset();

	int n;	cin>>n;
	for(int i=0;i<n;i++){
		string ans="";
		string s;
		cin>>s;
		for(int j=0;j<s.length();j++){
			int num=s[j]-'0';
			//printf("<%d>\n",num);

			if(num==0){
				for(int k=1;k<=9;k++){
					if(key[k]<0)continue;
					else ans+=Output(k);
				}
				Reset();
			}else{
				key[num]++;
			}
		}

		cout<<ans<<endl;
	}


	return 0;
}



void Reset(void){ for(int i=0;i<10;i++) key[i]=-1; }
char Output(int num){
	char word[10][5]={
		{'A','B','C','D','E'},// 使わない
		{'.',',','!','?',' '},
		{'a','b','c','F','G'},
		{'d','e','f','H','I'},
		{'g','h','i','J','K'},
		{'j','k','l','L','M'},
		{'m','n','o','N','O'},
		{'p','q','r','s','P'},
		{'t','u','v','Q','R'},
		{'w','x','y','z','S'}};

	int tmp=key[num];
	switch(num){
		case 1:
			tmp%=5;
			break;
		case 7:
		case 9:
			tmp%=4;
			break;
		default:
			tmp%=3;
			break;
	}

	return word[num][tmp];
}



Measured memory_bytes: 3172
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    class City
    {
        public int prefecture;
        public int year;
        public int order;

        public override string ToString()
            => $"{prefecture.ToString().PadLeft(6, '0')}{order.ToString().PadLeft(6, '0')}";
    }
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt32();
            var N = line[0];
            var M = line[1];
            var cities = consoleReader.RepeatSplitInt32(M).Select(py => new City { prefecture = py[0], year = py[1] }).ToArray();

            foreach (var preGroup in cities.GroupBy(c => c.prefecture))
            {
                preGroup.OrderBy(c => c.year).Select((c, i) => c.order = i + 1).ToList();
            }

            return MultiLine(cities);
        }

        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int32() => int.Parse(String()); public long Int64() => long.Parse(String()); public ulong UInt64() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray(); public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt32(int count) { for (int i = 0; i < count; i++) yield return Int32(); } public IEnumerable<long> RepeatInt64(int count) { for (int i = 0; i < count; i++) yield return Int64(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt32(int count) { for (int i = 0; i < count; i++) yield return SplitInt32(); } }
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(min(abs(a-b),abs(a-c))+abs(b-c),abs(a-b)+abs(a-c)) << endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> D(N);
  for(int i = 0; i < N; ++i) cin >> D[i];
  long long ans = 0;
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < i; ++j){
      ans += D[i]*D[j];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(auto &i:a) cin>>i;
	cin>>m;
	vvl dp(2,vl(m+1));
	dp[0][m]++;
	for(int i=0;i<n;i++){
		for(int j=a[i];j<=m;j++) for(int k=0;k<2;k++) {
			(dp[k^1][j-a[i]]+=dp[k][j])%=mod;
		}
//		for(int j=0;j<=m;j++) cout<<dp[0][j]<<' '<<dp[1][j]<<endl;
//		cout<<endl;
	}
	ll res=0;
	for(int i=1;i<=m;i++){
		ll tmp=1;
		for(int j=0;j<n;j++) (tmp*=i)%=mod;
		for(int j=0;j<2;j++){
			ll t=dp[j][i]*tmp%mod;
			if(j==0) (res+=t)%=mod;
			else res=(res-t+mod)%mod;
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 4932
N,M = map(int,input().split())
COST = []
B = []
C = []
C_bit = []
INF = 10**18
dp = [INF]*(1<<N)
dp[0] = 0

for _ in range(M):
  a,b = map(int,input().split())
  C.append(list(map(int,input().split())))
  COST.append(a)
  B.append(b)

for i in range(M):
  bit = ['0']*N
  for j in range(B[i]):
    bit[C[i][j]-1] = '1'
  bit_int = int(''.join(bit),2)
  C_bit.append(bit_int)

for cost,c in zip(COST,C_bit):
  for i in range(1<<N):
    j = i|c
    d = dp[i]+cost
    if dp[j] > d:
      dp[j] = d

if dp[-1] == INF:
  print(-1)
else:
  print(dp[-1])

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;

int main(){
  
  ll n,p;
  
  cin>>n>>p;

  if(n==1){
    cout<<p<<endl;
    return 0;
  }
  
  ll ans=1;
  
  for(ll i=2;i*i<=p;i++){
    if(p%i)continue;
    ll cnt=0;
    while(p%i==0){
	 cnt++;
	 p/=i;
    }
    ans*=pow(i,cnt/n);
  }

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


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  ll a[300010];
  rep(i, 3 * n) cin >> a[i];
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);
  ll sum = 0;
  for (int i = 1, cnt = 0; cnt < n; i += 2, cnt++)
    sum += a[i];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 2560
N, M = map(int,input().split())
n = []
for i in range(N):
    A = [int(x) for x in input().split()]
    for j in range(1,len(A)):
        n.append(A[j])

B = list(set(n))
ans = sum(n.count(x) >= N for x in B)
print(ans)

Measured memory_bytes: 3060
import java.util.*
import kotlin.math.acos
import kotlin.math.cos
import kotlin.math.round
import kotlin.math.sin

fun main(args: Array<String>) {
    val a = ArrayDeque<Char>()
    val b = ArrayDeque<Char>()
    val c = ArrayDeque<Char>()

    a.addAll(readString().map { it })
    b.addAll(readString().map { it })
    c.addAll(readString().map { it })

    var turn = a.first
    while (true) {
        when (turn) {
            'a' -> {
                if (a.isEmpty()) {
                    println("A")
                    return
                }
                turn = a.removeFirst()
            }
            'b' -> {
                if (b.isEmpty()) {
                    println("B")
                    return
                }
                turn = b.removeFirst()
            }
            'c' -> {
                if (c.isEmpty()) {
                    println("C")
                    return
                }
                turn = c.removeFirst()
            }
        }
    }
}

// read
fun readString() = readLine()!!

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

int n,a[114514],b[114514];
signed main(){
	cin>>n;
	int ans=0;
	rep(i,n){
		cin>>a[i]>>b[i];
	}
	for(int i=n-1;i>=0;i--){
		if((a[i]+ans)%b[i]){
			ans+=b[i]-(a[i]+ans)%b[i];
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
from numpy import int_

mod = 10 ** 9 + 7

N, K = map(int, input().split())

M = int(N ** 0.5)
T = [N // i - N // (i + 1) for i in range(1, M + 1)]
dp = int_([1] * (N - sum(T)) + T[::-1])

A = dp[:]
for _ in range(K - 1):
    dp = A * dp.cumsum()[::-1] % mod

print(sum(dp) % mod)

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

int b[100][100];
int vis[100][100];

int w, h;
bool in(int x, int y) {
	return 0 <= x && x < w && 0 <= y && y < h;
}


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

	while(cin >> w >> h, w + h) {
		int xs, ys, xg, yg, n;
		cin >> xs >> ys >> xg >> yg >> n;
		xs--, ys--, xg--, yg--;

		memset(b, 0, sizeof b);
		for(int i = 0; i < n; i++) {
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			x--, y--;
			int H = 2, W = 4;
			if(d == 1) swap(H, W);
			for(int dx = 0; dx < W; dx++) {
				for(int dy = 0; dy < H; dy++) {
					b[y + dy][x + dx] = c;
				}
			}
		}

		if(b[ys][xs] == 0 || b[ys][xs] != b[yg][xg]) {
			cout << "NG" << endl;
			continue;
		}

		typedef pair<int, int> P;
		queue<P> q;
		q.push({ xs, ys });
		memset(vis, 0, sizeof vis);
		vis[ys][xs] = 1;
		while(q.size()) {
			int x = q.front().first, y = q.front().second;
			q.pop();
			int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
			for(int k = 0; k < 4; k++) {
				int nx = x + dx[k], ny = y + dy[k];
				if(in(nx, ny) && b[y][x] == b[ny][nx] && vis[ny][nx] == 0) {
					vis[ny][nx] = 1;
					q.push({ nx, ny });
				}
			}
		}
		if(vis[yg][xg]) {
			cout << "OK" << endl;
		}
		else {
			cout << "NG" << endl;
		}
	}
}

Measured memory_bytes: 3216
<?php
    $s = explode(' ', trim(fgets(STDIN)));
    $n = (int)$s[0];
    $m = (int)$s[1];
 
    $arr = explode(' ', trim(fgets(STDIN)));
 
    // 総得点
    $sum_point = 0;
    for ($i=0; $i < (int)$n ; $i++) { 
        $sum_point += (int)$arr[$i];
    }
    // echo $sum_point . PHP_EOL;

    // 総得票数の 1/4M 以上の数
    $ct = 0;
    for ($i=0; $i < (int)$n ; $i++) {
        // echo $arr[$i] . PHP_EOL; 
        if ((int)$arr[$i] >= ((int)$sum_point / (4 * (int)$m))) {
            $ct = (int)$ct + 1;
            // echo 'PLUS' . PHP_EOL;
        }
    }
    
    // echo 'result' . PHP_EOL;
    // echo $m . PHP_EOL;
    // echo $ct . PHP_EOL;

    if ((int)$m <= (int)$ct) {
        echo 'Yes';
    } else {
        echo 'No';
    }
?>

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

bool is_clear(vector<vector<bool>> a) {
    if (a[0][0] == true && a[0][1] == true && a[0][2] == true) return true;
    else if (a[1][0] == true && a[1][1] == true && a[1][2] == true) return true;
    else if (a[2][0] == true && a[2][1] == true && a[2][2] == true) return true;
    else if (a[0][0] == true && a[1][0] == true && a[2][0] == true) return true;
    else if (a[0][1] == true && a[1][1] == true && a[2][1] == true) return true;
    else if (a[0][2] == true && a[1][2] == true && a[2][2] == true) return true;
    else if (a[0][0] == true && a[1][1] == true && a[2][2] == true) return true;
    else if (a[0][2] == true && a[1][1] == true && a[2][0] == true) return true;
    else return false;
}

int main() {
    vector<vector<int>> bingo(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> bingo[i][j];
        }
    }
    int n;
    cin >> n;
    vector<vector<bool>> is_bingo(3, vector<bool>(3));
    bool bingoo = false;
    for (int k = 0; k < n; k++) {
        int b;
        cin >> b;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (bingo[i][j] == b) is_bingo[i][j] = true;
                if (is_clear(is_bingo)) {
                    bingoo = true;
                }
            }
        }
    }
    if (bingoo) cout << "Yes" << endl;
    else cout << "No" << endl; 
}

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

int main() {
    int R,G,B,N;
    cin >> R >> G >> B >> N;
    int ans=0;
    for(int i=0;i<=3000;i++){
        for(int j=0;j<=3000;j++){
            int v=R*i+G*j;
            if(N>=v&&(N-v)%B==0){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

int main(void){
    int x;
    scanf("%d", &x);
    int s[1000] = {0};
    s[0] += 1;
    for(int i = 2; i < 32; i++){
        for(int j = 2; pow(i, j) <= 1000; j++){
            s[(int) pow(i, j)-1] += 1;
        }
    }
    
    int ans = 1;
    for(int i = x; i>= 0; i--){
        if(s[i - 1] > 0){
            ans = i; 
            break;
        }
    }
    printf("%d\n", ans);
    
    return 0; 
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#define N 200005
 
int n;
long long a[N];
 
inline long long cnt(long long x) {
    long long ans = 0;
    for (int i = 0; i < n; ++i)
        if (!a[i]) ans += x >= 0 ? n - i - 1 : 0;
        else if (a[i] < 0) ans += std::min(n - i - 1, (int)(a + n - std::lower_bound(a, a + n, (long long)std::ceil((long double)x / a[i]))));
        else if (a[i] > 0) ans += std::max(0, (int)(std::upper_bound(a, a + n, (long long)std::floor((long double)x / a[i])) - a - i - 1));
    return ans;
}
 
int main() {
    long long k;
    scanf("%d%lld", &n, &k);
    for (int i = 0; i < n; ++i) scanf("%lld", a + i);
    std::sort(a, a + n);
    long long l = -1e18, r = 1e18;
    while (l < r) {
        long long mid = l + r >> 1;
        if (cnt(mid) < k) l = mid + 1;
        else r = mid;
    }
    printf("%lld\n", l);
    return 0;
}


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

int main() {
	int n,m,c;
	cin>>n>>m>>c;
	vector<int> bs(m);
	for(int i = 0; i < m; i++) {
		cin >> bs[i];
	}
	int count = 0;
	for(int i = 0; i < n; i++) {
		int ans = 0;
		for(int j = 0; j < m; j++) {
			int a;
			cin >> a;
			ans += a*bs[j];
		}
		ans += c;

		count += (ans>0)?1:0;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[100100],s1[100100];
int m;
bool mark;
int main(){
	cin>>a;
	m=strlen(a);
	for(int i=0;i<m;i++)
		s1[i]=a[i];
	for(int i=0;i<m;i++){
		if(a[i]=='b')
		a[i]='d';
		else if(a[i]=='d')
		a[i]='b';
		else if(a[i]=='p')
		a[i]='q';
		else if(a[i]=='q')
		a[i]='p';
	}/*
	for(int i=0;i<m;i++)
		cout<<s1[i];
	cout<<endl;
	for(int i=m-1;i>=0;i--)
		cout<<a[i];
	cout<<endl;*/
	mark=1;
	for(int i=0;i<m;i++){
		if(a[i]!=s1[m-i-1])
			mark=0;
	}
	if(mark==0)
	cout<<"No";
	else
	cout<<"Yes";
	return 0;
} 

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

int main(){
    int i, n, taro = 0, hanako = 0;
    string st, sh;
    cin >> n;
    for (i = 0; i < n; i++){
        cin >> st >> sh;
        if (st > sh){
            taro+=3;
        } else if (st == sh){
            taro++;
            hanako++;
        } else {
            hanako+=3;
        }
    }
    cout << taro << " " << hanako << endl;
    return 0;
}


Measured memory_bytes: 3192
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{a:f64,b:f64};

    println!("{}", ((a+b)/2.0).ceil() as i32);

}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

int main(){
	int N; cin >> N;
	vector<int> A;

	A.resize(N);
	for(int i = 0; i < N; ++i) cin >> A[i];

	long absmin = 1000000000;
	long sum = 0;
	long minus = 0, zero = 0;
	for(int i = 0; i < N; ++i){
		sum += abs(A[i]);

		if(absmin > abs(A[i])) absmin = abs(A[i]);
		if(A[i] < 0) minus++;
		if(A[i] == 0) zero = 1;
	}

	if(zero == 1) cout << sum << endl;
	else if(minus % 2 == 0) cout << sum << endl;
	else if(minus % 2 == 1) cout << sum - absmin * 2 << endl;

	return 0;
}


Measured memory_bytes: 640
import bisect
N, M, V, P = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
eps = 0.1
def func(k):
    # print("tsrget:"+str(k))
    used = 0
    tmp = a[:k]+a[k+1:]
    val = a[k]+M
    x1 = N-1-bisect.bisect(tmp, val+eps)
    x2 = bisect.bisect(tmp, val-eps)
    x3 = N-(x1+x2+1)
    # print(tmp,val,x1,x2,x3)
    if x1 >= P:
        return False
    v = V - (x1+1)
    p = P - (x1+1)
    used += x1+1
    if v <= 0:
        return True
    # x2+x3問からあとp問はa[k]+Mを超えてもよい
    # x3が十分ある
    if x3 >= p > 0:
        x3 -= p
        v -= p
        used += p
        p = 0
    if p>0:
        p -= x3
        v -= x3
        used += x3
    if x2 >= p > 0:
        x2 -= p
        v -= p
        used += p
        p = 0
    if p>0:
        p -= x2
        v -= x2
        used += x2
    if v <= 0:
        return True
    # x2問からあとp問はa[k]+Mを超えてもよい
    tmp2 = tmp[:N-used]
    rest = sum([min(M,val-val2) for val2 in tmp2])
    # print(tmp2,N,x1,x3,p,v, rest)
    if rest >= M*v:
        return True
    return False

ok = N-1  # exist
ng = -1  # not exist
while abs(ok - ng) > 1:
    cnt = (ok + ng) // 2
    t = func(cnt)
    # print(t)
    if t:
        ok = cnt
    else:
        ng = cnt
print(N-ok)

Measured memory_bytes: 14964
<?php

while ($stdin = fgets(STDIN)) {
    $line[] = trim($stdin);
}
foreach ($line as $key => $value) {
    $data[] = explode(' ', $value);
}

foreach ($data as &$line) {
    $line = array_map(function($val) { return (int)$val; }, $line);
}

$N = $data[0][0];
$K = $data[0][1];
$A = $data[1];

$seen = array_pad([], $N, null);

$i = 0;
$currentKey = 0;
while (true) {
    $seen[$currentKey] = $i;
    $i++;
    $nextKey = $A[$currentKey] - 1;

    if (!is_null($seen[$nextKey])) {
        $findTurn = $i;
        $freq = $i - $seen[$nextKey];
//var_dump($nextKey.'にて');
//
//var_dump($findTurn);
//var_dump($freq);

        if ($K >= $findTurn) {
            $overhead = $findTurn - $freq;
            $newSeen = [];
            foreach ($seen as $seenkey => $seenval) {
                if (is_null($seenval) || $seenval < $overhead) {
                    $newSeen[$seenkey] = null;
                } else {
                    $newSeen[$seenkey] = $seenval % $freq;
                }
            }
            $amari = $K % $freq;
            $kkkey = array_search($amari, $newSeen, true);
//var_dump($newSeen);
//            var_dump('あまりは'.$amari);
//            var_dump('kkkey'.$kkkey);
            $ans = $kkkey + 1;
        } else {
            $kkkey = array_search($K, $seen, true);
            $ans = $kkkey + 1;
        }
        break;

    } else {
        $currentKey = $nextKey;
    }

}

printf('%d', $ans);



Measured memory_bytes: 44400
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int main()
{
 
  int a, b, c, d, e, X, Y;
  //  double  c;
  int  A[100001]={};
//  int  B[100003]={};
  int  L[1003]={};

  int  flag[103]={};

//  long long  a, b, c, d, X, Y;
char s[100001]={};
  long long JPY;
  double BTC;
char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
//  int flag=0;
  double tmp=0;
//  int min=1000000;
  long long min=100000001;
  int len=0;
  int cnt=0;
  int cnt0=0;
  int cnt1=0;
  int num=0;
//  double ans=0.0;
  int ans=0.0;
  int max=0;
  int sum=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%s", &s);
//  printf("%s\n",s);
  len= strlen(s);
//  printf("len%d\n",len);

  for(i=0;i<len;i++){
//           printf("%d cnt%d\n",i, cnt);
    if(s[i]=='0'){
      cnt0++;
    } else {
      cnt1++;
    }
  }
// printf("cnt0%d cnt1%d\n",cnt0, cnt1);

  if(cnt0<cnt1) printf("%d\n",cnt0*2);
  else  printf("%d\n",cnt1*2);
//  printf("%d\n",A[cnt-c]);

  //    if(max < cnt - max)  printf("Yes\n");
//    else  
  
return 0;
}


Measured memory_bytes: 256
from math import ceil
from collections import defaultdict

h, w = map(int, input().split())
s = [input() for _ in range(h)]

n = h * w
INF = 100 * 100

dp = defaultdict(lambda: INF)
if s[0][0] == "#":
    dp[(1, 1, 1)] = 1
else:
    dp[(1, 1, 0)] = 0

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i-1][j-1] == "#":
            dp[(i, j, 1)] = min(dp[(i, j, 1)], dp[(i-1, j, 0)] + 1, dp[(i-1, j, 1)], dp[(i, j-1, 0)] + 1, dp[(i, j-1, 1)])
        else:
            dp[(i, j, 0)] = min(dp[(i, j, 0)], dp[(i-1, j, 0)], dp[(i-1, j, 1)] + 1, dp[(i, j-1, 0)], dp[(i, j-1, 1)] + 1)

idx = 1 if s[h-1][w-1] == "#" else 0
ans = dp[(h, w, idx)]
ans = ceil(ans / 2)
print(ans)


Measured memory_bytes: 48748
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

A, B, C, K = map(int, input().split())

if abs(A - B) > int(1e18):
    print('Unfair')
elif K % 2 == 0:
    print(A-B)
else:
    print(B-A)


Measured memory_bytes: 3060
S = input()
all_sum = 0
for pattern in range(1 << (len(S)-1)):
  this_sum = 0
  cut = 0
  for i in range(1,len(S)):
    if pattern & 1 << i-1:
      this_sum += int(S[cut:i])
      cut = i

  this_sum += int(S[cut:])
  all_sum += this_sum

print(all_sum)

Measured memory_bytes: 39280
S = input()
S1 = int(S[0:2])
S2 = int(S[2:4])


if 0 < S1 < 13 and 0 < S2 < 13:
    print('AMBIGUOUS')
if (S1 >= 13 or S1 == 0) and (S2 >= 13 or S2 == 0):
    print('NA')
if 0 < S1 < 13 and (S2 >= 13 or S2 == 0):
    print('MMYY')
if (S1 >= 13 or S1 == 0) and 0 < S2 < 13:
    print('YYMM')


Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#include <numeric>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int H, W, M; cin >> H >> W >> M;
	vector<int>BH(H + 1, 0), BW(W + 1, 0);
	map<P, int>b;
	rep(i, M) {
		int h, w; cin >> h >> w;
		BH[h]++; BW[w]++;
		P a = make_pair(h, w);
		b[a]++;
	}
	int maxh = max_element(BH.begin(), BH.end()) - BH.begin();
	int maxw = max_element(BW.begin(), BW.end()) - BW.begin();
	vector<int> bh, bw;
	REP(i, H) {
		if (BH[maxh] == BH[i]) {
			bh.push_back(i);
		}
	}
	REP(i, W) {
		if (BW[maxw] == BW[i]) {
			bw.push_back(i);
		}
	}
	for (int& e : bh) {
		for (int& el : bw) {
			if (b[make_pair(e, el)] == 0) {
				cout << BH[maxh] + BW[maxw] << endl;
				return 0;
			}
		}
	}


	cout << BH[maxh] + BW[maxw] - b[make_pair(maxh, maxw)] << endl;
}



Measured memory_bytes: 28532
s = input()
n = int(s)

nodes = []

for i in range(n):
    p = input()
    q = int(p)
    nodes.append(q)

answer = -1
m = []

x = nodes[0]
m.append(x)
for i in range(n-1):
    w = nodes[x-1]
    m.append(w)
    x = w

for i in range(len(m)):
    if m[i] == 2:
        answer = i + 1
        break

print(answer)


Measured memory_bytes: 13860
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        long ans = 0;
        for(int i = 1; i < n; i++){
            ans += i;
        }
        System.out.println(ans);
    }
}

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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    for(int i = 0; i < N - 1; i++){
        if(S[i] != S[i + 1]) ans++;
    }
    ans++;
    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);


        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();

            if (w == 0 && h == 0) break;
            if(w==1&&h==1) System.out.println("#");
            else {
                for (int i = 0; i < h; i++) {
                    for (int j = 0; j < w; j++) {
                        if (i % 2 != 0) {
                            if(j%2!=0)System.out.printf("#");
                            else System.out.printf(".");
                        }
                        else {
                            if(j%2!=0)System.out.printf(".");
                            else System.out.printf("#");

                        }
                    }
                    System.out.printf("\n");
                }
            }
                System.out.printf("\n");

        }
    }
}


Measured memory_bytes: 58332
def main():
    from sys import stdin
    from collections import deque
    n,m = map(int,stdin.readline().rstrip().split())       
    AB=[]
    for _ in range(m):
        AB.append(list(map(int,stdin.readline().rstrip().split())))
    
    G = [[] for _ in range(n+1)]
    for a,b in AB:
        G[a].append(b)
        G[b].append(a)

    visit = [False]*(n+1)
    visit[0]=True
    path = [-1]*(n+1)

    dq = deque([1])

    while len(dq)>0:
        edge = dq.popleft()

        for i in G[edge]:
            if not visit[i]:
                visit[i] = True
                path[i] = edge
                dq.append(i)
        
    print("Yes")
    for i in path[2:]:
        print(i)
main()

Measured memory_bytes: 59504
# -*- coding: utf-8 -*-


def selection_sort(n, a):
    cnt = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if a[j] < a[minj]:
                minj = j
        if i != minj:
            tmp = a[minj]
            a[minj] = a[i]
            a[i] = tmp
            cnt += 1
    return a, cnt


if __name__ == '__main__':
    n = int(input())
    a = [int(n) for n in input().split()]
    ans, cnt = selection_sort(n, a)
    print(' '.join(map(str, ans)))
    print(cnt)

Measured memory_bytes: 7684
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000

int main(){
  int n;
  cin >> n;
  int v;
  vector<pair<int, int> > odd(MAX + 1); // cnt, num
  vector<pair<int, int> > even(MAX + 1); // cnt, num
  // init
  for ( int i = 0; i <= MAX; i++)odd[i] = even[i] = make_pair(0, i);

  for ( int i = 1; i <= n; i++){
    cin >> v;
    if ( i % 2 == 1){
        odd[v].first ++;
    } else {
        even[v].first ++;
    }
  }

  sort(odd.begin(), odd.end());
  sort(even.begin(), even.end());
  if( odd[MAX].second != even[MAX].second){
    cout << n - odd[MAX].first - even[MAX].first << endl;
  } else {
    cout << n - max(odd[MAX].first + even[MAX-1].first, odd[MAX-1].first + even[MAX].first)  << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
def main():
    N, T = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    AB.sort()

    ans = 0
    dp1 = [[0]*(T+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(T):
            t = j - AB[i][0]
            if 0 <= t:
                dp1[i+1][j] = max(dp1[i][j], dp1[i][t] + AB[i][1])
            else:
                dp1[i+1][j] = dp1[i][j]
        ans = max(ans, dp1[i][T-1] + AB[i][1])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 145672
#include <bits/stdc++.h>
#include  <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
#define endl '\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> index_set;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using ii = pair<int,int>;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define mod 1000000007
int get(string s) 
{
    int count = 0;  
    int ans = 0;  
    for (int i = 0; i < sz(s); i++) 
    {  
        if (s[i] == 'S') 
            count = 0;  
        else
        { 
            count++; 
            ans = max(ans, count); 
        } 
    } 
    return ans; 
} 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	string s;
	cin >> s;
	cout << get(s) <<endl;
 return 0;
}


Measured memory_bytes: 3564
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int p[202020];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int n;
  cin >> n;
  for(int i=2;i<=n;i++){
    int x;
    cin >> x;
    p[x]++;
  }
  for(int i=1;i<=n;i++){
    cout << p[i] << endl;
  }

return 0;
}
///....


Measured memory_bytes: 5224
#include <cstdio>
typedef long long ll; 
ll dp[305][305], C[305][305], pre[305][305]; 
int main()
{
	// freopen("AGC024-E.in", "r", stdin); 
	int n, lim, mod; 
	scanf("%d%d%d", &n, &lim, &mod);
	for (int i = 0; i <= n; i++)
	{
		C[i][0] = 1; 
		for (int j = 1; j <= i; j++)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; 
	}
	for (int i = 0; i <= lim; i++)
	{
		dp[1][i] = 1; 
		pre[1][i] = lim - i + 1; 
	}
	for (int i = 2; i <= n + 1; i++)
	{
		for (int j = lim; j >= 0; j--)
		{
			for (int k = 1; k < i; k++)
				(dp[i][j] += C[i - 2][k - 1] * dp[i - k][j] % mod * pre[k][j + 1]) %= mod; 
			pre[i][j] = (pre[i][j + 1] + dp[i][j]) % mod; 
		}
	}
	printf("%lld\n", dp[n + 1][0]);
	return 0; 
}


Measured memory_bytes: 2304
#include<iostream>
#include<math.h>

using namespace std;
typedef long long ll;

int main(){
    ll A, B, x;
    cin >> x;
    for(int i = -120;i <= 120;i++){
        for(int j = -120;j <= 120;j++){
            if(pow(i, 5) - pow(j, 5) == x){
                cout << i << " " << j;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4056
# -*- coding: utf-8 -*-

A = input()
B = input()
C = input()

a_list = list(A)
b_list = list(B)
c_list = list(C)


def kill_first_char_from_list(kill_list):
    if(kill_list == a_list):
        result = a_list[0]
        del kill_list[0]
        return result
    elif(kill_list == b_list):
        result = b_list[0]
        del kill_list[0]
        return result
    elif(kill_list == c_list):
        result = c_list[0]
        del kill_list[0]
        return result

next_char = ""

for i in range(len(a_list) + len(b_list) + len(c_list)):
    if(i == 0):
        next_char = a_list[0]

    if(next_char == "a"):
        if (len(a_list) == 0):
            next_char = "A"
            break
        else:
            next_char = kill_first_char_from_list(a_list)
    elif(next_char == "b"):
        if(len(b_list) == 0):
            next_char = "B"
            break
        else:
            next_char = kill_first_char_from_list(b_list)
    elif(next_char == "c"):
        if (len(c_list) == 0):
            next_char = "C"
            break
        else:
            next_char = kill_first_char_from_list(c_list)


print(next_char)

Measured memory_bytes: 3064
n, m = map(int, input().split())

s = [0 for _ in range(n)]
t = [0 for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    if a > b:
        temp = a
        b = a
        a = temp

    if a == 1:
        s[b-1] = 1
    if b == n:
        t[a-1] = 1

for i in range(n):
    if s[i] * t[i] == 1:
        print('POSSIBLE')
        exit()

print('IMPOSSIBLE')

Measured memory_bytes: 6320
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
using vs= vector<string>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int a,b,ans=-1;
  cin >> a >> b;

  rep(i,1,10000){
    if(a==i*8/100 && b==i*10/100){
      ans=i;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#E
import sys
input=sys.stdin.readline

N=int(input())
A=[0 for i in range(N)]
B=[0 for i in range(N)]

for i in range(N):
    A[i],B[i]=map(int,input().split())
    
A_sort=sorted(A)
B_sort=sorted(B)

if N%2==0:
    f=(A_sort[int(N/2)]+A_sort[int(N/2)-1])/2
    t=(B_sort[int(N/2)]+B_sort[int(N/2)-1])/2
    ans=int((t-f)*2+1)
else:
    f=A_sort[int((N-1)/2)]
    t=B_sort[int((N-1)/2)]
    ans=int((t-f)+1)
    
print(ans)

Measured memory_bytes: 94164
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    a = 26
    ans = []
    for i in range(100000):
        c = N % a
        if c == 0:
            c = 26
            N -= 1
        N //= a
        ans.append(chr(ord('a')+c-1))
        if N == 0:
            break
    return ''.join(reversed(ans))


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10400