akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;

int B[100001] = {};

int main()
{
    int N, H;
    cin >> N >> H;

    int maxA = 0;
    for (int i = 0; i < N; ++i)
    {
        int a, b;
        cin >> a >> b;
        maxA = max(a, maxA);
        B[i] = b;
    }

    sort(B, B+N, greater<int>());

    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        if (B[i] < maxA) break;
        H -= B[i];
        ++ans;

        if (H <= 0)
        {
            cout << ans << endl;
            return 0;
        }
    }
    ans += H / maxA;
    if (H % maxA != 0) ++ans;
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>

using namespace std;


#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
int main() {
   /* map<int,pair<int,int>> mp;
    int n,m,problem;
    string s;
    cin >>n>>m;
    for(int i=0;i<m;i++){
        cin>>problem;
        cin >> s;
        if(s=="AC")mp[problem].first=1;
        else{
            if(mp[problem].first==0) mp[problem].second++;
        }
    }
    int ACs=0,WAs=0;
    for(auto i=mp.begin();i!=mp.end();i++){
        ACs+=i->second.first;
        WAs+=i->second.second;
    }
    cout << ACs <<" "<<WAs;*/


    int M, N; cin >> M >> N;
    int cnt[M]; bool found[M];
    int ans = 0;
    F0R(i, M) {
        cnt[i] = 0; found[i] = false;
    }
    int ans2 = 0;
    F0R(i, N) {
        int val; string S; cin >> val >> S; val--;
        if (S == "AC" && !found[val]) {
            found[val] = true; ans += cnt[val]; ans2++;
        } else {
            cnt[val]++;
        }
    }

    cout << ans2 << " " << ans << endl;

    return 0;



    return 0;

}


Measured memory_bytes: 3704
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
template <typename T> T max(T, T);
int gcd(int a, int b);

int main() {
    // source
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int ans=0;

    rep(i,n){
        if(i<k){
            ans+=x;
        }else{
            ans+=y;
        }
    }
    cout << ans << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T max(T a, T b) {

    if (a > b) {
        return a;
    } else {
        return b;
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}


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

int main(){
    string s, t;
    cin >> s >> t;
    int slen = s.length(), tlen = t.length();
    string res = "UNRESTORABLE";
    for(int i = 0; i <= slen-tlen; i++){
        string tmp = s;
        bool ok = true;
        for(int j = 0; j < tlen; j++){
            if(tmp[i+j] == '?' || tmp[i+j]==t[j])   tmp[i+j] = t[j];
            else{
                ok = false;
                break;
            }
        }
        if(!ok) continue;
        for(int j = 0; j < slen; j++)   if(tmp[j] == '?')   tmp[j] = 'a';
        if(res == "UNRESTORABLE" || tmp < res)  res = tmp;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b >= c) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MAX_N 20000
#define INF 0x3f3f3f3f
using namespace std;

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h,n;
    cin>>h>>n;
    int a[n];
    int b[n];
    for(int i =0; i<n; i++){
        cin>>a[i]>>b[i];
    }
    int dp[MAX_N+10];
    memset(dp, INF, sizeof(dp));
    dp[0] = 0;
    for(int i= 0;i<n;i++){
        for(int j = a[i]; j <= MAX_N; j++){
            dp[j] = min(dp[j], dp[ j-a[i]] + b[i] ); 
        }
    }
    int minc = INF;
    for(int i = h; i <= MAX_N; i++){
        minc = min(minc,dp[i]);
    }
    cout<< minc <<endl;
    return 0;
}


Measured memory_bytes: 384
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;
    let rec loop i count acc =
        if i = n then acc + count mod 2 else
            if a.(i) = a.(i - 1) then loop (i + 1) (count + 1) acc else
                loop (i + 1) 1 (acc + count mod 2)
    in
    loop 1 1 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 6668
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    s = [input() for _ in range(N)]
    a = 0
    b = 0
    c = 0#a&b
    ans = 0
    for i in range(N):
        if s[i][0] == 'B':
            if s[i][-1] == 'A':
                c += 1
            else:
                b += 1
        elif s[i][-1] == 'A':
            a += 1
        ans += s[i].count('AB')
      
    if a+b>0:
        print(ans + (c-1) + min(a+1,b+1))
    else:
        print(ans + max(0,c-1))
    # print(a,b,c)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

string s;
int main() {
    IOS
    cin >> s;
    for (int i = 1; i < (int) s.size(); ++i) {
        if (s[i] == s[i-1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;


    return 0;


}


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

int main()
{
	int a,b,c;
	cin >>a>>b>>c;

	if (b > c) {
		swap(b, c);
	}
	if (a>b){
		swap(a, b);
	}
	if (b > c) {
		swap(b, c);
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}

Measured memory_bytes: 3024
#include<stdio.h>
int main(void) {
	int n;
	int i,m,e,j;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<n;i++){
			scanf("%d%d%d",&m,&e,&j);
			if(m==100||e==100||j==100){
				printf("A\n");
			}else if(m+e>=180){
				printf("A\n");
			}else if(m+e+j>=240){
				printf("A\n");
			}else if(m+e+j>=210){
				printf("B\n");
			}else if(m+e+j>=150&&(m>=80||e>=80)){
				printf("B\n");
			}else{
				printf("C\n");
			}
		}
	}
	return 0;
}

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

using namespace std;

constexpr auto BASE = 1000000007;



class atcalc {

public:
	static int add(int a, int b)
	{
		return (int)(((long long)a + b) % BASE);
	}
	static int sub(int a, int b)
	{
		long long t = (long long)a - b;
		if (t < 0) {
			t += BASE;
		}
		return (int)(t % BASE);
	}
	static int times(int a, int b)
	{
		return (int)(((long long)a * b) % BASE);
	}
	static int div(int a, int b)
	{
		return (int)(((long long)a * atcalc::modinv(b, BASE)) % BASE);
	}

	static int comb(int a, int b)
	{
		if (a < b) { return 0; }
		if (b > a / 2) { b = a - b; }
		if (b == 0) { return 1; }


		int ans = 1;
		for (int i = 0; i < b; i++) {
			ans = atcalc::times(ans, a - i);
		}
		int tm = 1;
		for (int i = 0; i < b; i++) {
			tm = atcalc::times(tm, i + 1);
		}

		ans = atcalc::div(ans,tm);

		return ans;
	}

	static int modinv(int a, int m)
	{

		long long x = 0, y = 1, gcd = m;
		long long  px = 1, py = 0, pgcd = a;
		long long temp = 0;

		while (gcd > 0)
		{
			long long quotient = pgcd / gcd;

			temp = x;
			x = px - quotient * temp;
			px = temp;

			temp = y;
			y = py - quotient * temp;
			py = temp;

			temp = gcd;
			gcd = pgcd - quotient * temp;
			pgcd = temp;
		}

		while (px < 0) {
			px += BASE;
		}
		return (int)px;
	}
};



long long n, a, b;



int main()
{

	cin >> n;
	cin >> a;
	cin >> b;

	vector<int> r;
	long long ans = 2;
	r.push_back(ans);

	{
		int i = 1;
		int k = 1;
		int j = 0;
		{
			for (; i * 2 <= n; i *= 2) {
				ans = atcalc::times(ans, ans);
				r.push_back(ans);
				j++;
			}
			k = i;
			
			while(j>=0) {
				if (i + k <= n) {
					ans = atcalc::times(ans, r[j]);
					i += k;
				}
				else {
					k /= 2;
					j--;
				}
			}
		}
	}
	ans = atcalc::sub(ans,atcalc::comb(n,a));
	ans = atcalc::sub(ans, atcalc::comb(n, b));
	ans = atcalc::sub(ans, 1);

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var N = consoleReader.Int;
            var K = consoleReader.Int;
            return (N - 1 + K -2) / (K - 1);
        }


        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader
    {
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = textReader.ReadLine().Split();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.textReader.ReadLine().Split(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerable<T> Select<T>(Func<ConsoleReader, T> func) { for (int i = 0; i < count; i++) yield return func(cr); }
            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
typedef double D;

vector<int> hand(int n){
  vector<int> h(n+1,0);

  int m; cin >> m;
  for(int i=0;i<m;i++){
    int a; cin >> a; h[a]++;
  }
  
  for(int i=0;i<=n;i++) h[i] %= 2;

  return h;
}

D memo2[3][3][110]; //memo2[turn][joker][card]

//0: kotori, 1: umi
D rec2(int t, int j, int c){
  D &res = memo2[t][j][c];
  if(res >= 0) return res;
  
  if(c == 0){
    if(j == 1) return res = 0; //umi loses
    else return res = 1;       //umi wins
  }

  if(t == 0){ //kotori turn
    return res = rec2(1-t,j,c-1);
  }else{     //umi turn
    int total = c + (j==0);
    res = c * rec2(1-t,j,c-1);
    if(j==0) res += rec2(1-t,1,c);
    res /= total;

    return res;
  }
}

D memo3[3][3][110][110][110]; //memo3[turn][joker][hono][umi][koto]

//honoka: 0, umi: 1, kotori: 2
D rec3(int t, int j, vector<int> p){
  D &res = memo3[t][j][p[0]][p[1]][p[2]];
  if(res >= 0) return res;

  //only joker
  if(p[0]==0 && p[1]==0 && p[2]==0){
    if(j == 1) return res = 0; //umi loses
    else return res = 1;       //umi wins
  }

  int nt = (t+1)%3;
  //turn player has no card
  if(j!=t && p[(t+1)%3]==0 && p[(t+2)%3]==0){
    return res = rec3(nt, j, p); //skip turn
  }

  //two players remain
  for(int i=0;i<3;i++){
    if(j!=i && p[(i+1)%3]==0 && p[(i+2)%3]==0){
      if(i==1) return res = 1;                //umi wins
      else return res = rec2(t==1,j==1,p[i]); //umi remains
    }
  }

  //three players remain
  if(t==2){
    if(p[0]){ //umi has cards that kotori also has
      res = rec3(nt, j, {p[0]-1,p[1],p[2]});
    }else if(p[0]==0 && p[2]==0 && j==1){ //umi only has joker
      res = 1;
    }else{
      res = rec3(nt, j, {p[0],p[1]+1,p[2]-1});
    }
  }else{
    int total = p[t] + p[(t+1)%3] + (j==(t+2)%3);

    vector<int> np = p;
    np[t]--;
    np[(t+2)%3]++;
    res = p[t] * rec3(nt,j,np);
    
    np = p;
    np[(t+1)%3]--;
    res += p[(t+1)%3] * rec3(nt,j,np);

    if(j==(t+2)%3) res += rec3(nt,t,p);

    res /= total;
  }
  
  return res;
}

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

  vector<int> hono = hand(n), umi = hand(n), koto = hand(n);

  int joker = 0;
  if(hono[0] == 1) joker = 0;
  if( umi[0] == 1) joker = 1;
  if(koto[0] == 1) joker = 2;

  int h=0, u=0, k=0;
  for(int i=1;i<=n;i++){
    if(umi[i]  && koto[i]) h++;
    if(koto[i] && hono[i]) u++;
    if(hono[i] &&  umi[i]) k++;
  }

  for(int a=0;a<3;a++){
    for(int b=0;b<3;b++){
      for(int c=0;c<=n;c++){
	memo2[a][b][c] = -1;

	for(int d=0;d<=n;d++){
	  for(int e=0;e<=n;e++) memo3[a][b][c][d][e] = -1;
	}
      }
    }
  }

  cout << fixed << setprecision(10) << rec3(0, joker, {h,u,k}) << endl;
}

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

int main() {
  int n;
  cin >> n;
  int a[n];
  int result = 100000000;
  int temp;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    temp = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      temp++;
    }
    result = min(result, temp);
  }
  cout << result << endl;
  return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);
int ok[15];

int main(){
  string s;
  cin >> s;
  REP(i, s.length()) ok[i]=((s[i]=='A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T') ? 1 : 0);
  int res = 0;
  if(s.length()==1) { cout << ok[0] << endl; return 0; }
  REP(i, s.length()-1) { ok[i+1]=ok[i]*ok[i+1]+ok[i+1]; chmax(res, ok[i+1]); }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
# Problem C - Splitting Pile

# input
n = int(input())
a_list = list(map(int, input().split()))

# initialization
min_cost = 10**15
arai_score = sum(a_list)
snuke_score = 0

# 累積和による解
for i in range(len(a_list)-1):
    a = a_list[i]
    snuke_score += a
    arai_score = arai_score - a
    min_cost = min(min_cost, abs(snuke_score - arai_score))

# output
print(min_cost)


Measured memory_bytes: 24832
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
// #define first f
// #define second s
int main(){
    int i,j;
    long double n;
    cin>>n;
    long double ans=0;
    long double a,b;
    vector<pair<long double,long double>> vec;
    for(i=0;i<n;i++){
        cin>>a>>b;
        vec.push_back(make_pair(a,b));
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(i==j){
                continue;
            }
            ans+=sqrt((abs(vec[i].first-vec[j].first))*(abs(vec[i].first-vec[j].first))+(abs(vec[i].second-vec[j].second))*(abs(vec[i].second-vec[j].second)));
            
        }
    }
    ans=(ans)/n;;
    cout<<setprecision(12)<<ans<<endl;
    return 0;
}

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

N = int(input())
ls = {}
for i in range(N):
    s, p = input().split()
    if s not in ls:
        ls[s] = [(i+1, int(p))]
    else:
        ls[s].append((i+1, int(p)))

r = [(k,v) for k, v in ls.items()]
r.sort(key=(lambda x: x[0]))

for l in r:
    vals = l[1]
    vals.sort(key=(lambda x: x[1]), reverse=True)
    for v in vals:
        print(v[0])




Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

int div_up(int a, int b)
{
    return (a + b - 1) / b;
}

int main()
{
    int n, y, a, b, c;
    cin >> n >> y;

    if (y % 1000 == 0 && y >= n * 1000)
    {
        y /= 1000;

        int k = div_up(2 * (y - n), 9);

        if ((y - n) / 4 >= k && y / 5 >= k)
        {
            cout << y - n - 4 * k << " "
                 << 9 * k - 2 * (y - n) << " "
                 << y - 5 * k << endl;

            return 0;
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
import Data.Maybe
import Data.List

main = do
  s <- getLine
  t <- getLine
  putStrLn (maybe "UNRESTORABLE" id (key s t))

key s t = minimumSafe $ map (replace s t) $ mapMaybe (match t) ws
 where
   ws = zip [0..] (windows (length t) s)

minimumSafe xs
  | null xs = Nothing
  | otherwise = Just (minimum xs)

replace s t i = s1 ++ s2 ++ s3
  where
   sa = map (\c -> if c=='?' then 'a' else c) s
   (s1, s2, s3) = (take i sa, t, drop (i + length t) sa)

match t (i,w)
  | all (\(ct,cw) -> ct==cw || cw=='?') (zip t w) = Just i
  | otherwise = Nothing

windows k = takeWhile ((==k) . length) . map (take k) . tails

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
long long a[10005];
long long b[10005];
long long a1=0,a2=0,a3=0,a4=0,a5=0;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0; i<n; i++) {
		cin>>a[i];
		a1+=a[i];
	}
	for(int i=0; i<n; i++) {
		cin>>b[i];
		a2+=b[i];
	}
	if(a1>a2) {
		cout<<"No"<<endl;
		return 0;
	} else {
		for(int i=0; i<n; i++) {
			long long tp=a[i]-b[i];
			if(tp>0)a3+=tp;//a多的部分
			if(tp<0) {
				if(abs(tp)%2==0) {
					a4+=abs(tp);//b多的部分(偶数)
				} else {
					a4+=abs(tp)-1;
					a5++;
				}
			}//奇数
		}
		long long z=a3-a4/2;
		if((a4+a5-2*a3<0)||(a5!=0&&z>0))cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
from collections import Counter
MOD = pow(10,9)+7
N = int(input())
C = [int(input()) for i in range(N)]

DP = [1]*N
counter = Counter()
for i in range(N):
    c = C[i]
    if i==0:
        counter[c]+=1
    elif i==1:
        if c!=C[i-1]:
            counter[c]+=1
    else:
        DP[i] = DP[i-1]
        if c!=C[i-1]:
            DP[i]+=counter[c]
            counter[c]+=DP[i-1]
print(DP[N-1]%MOD)

Measured memory_bytes: 774092
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String[] s = new String[N];
        Map<String, Integer> map = new HashMap<>();
        
        //sに格納
        String a = "";
        String S = "";
        long ans = 0;
        for(int i = 0; i < N; i++) {
            a = sc.next();
            String[] sp = a.split("");
            Arrays.sort(sp);
            for(int j = 0; j < 10; j++) {
                S += sp[j];
            }
            if(map.containsKey(S)) {
                ans += map.get(S);
                map.put(S, map.get(S) + 1);
            }else {
                map.put(S, 1);
            }
            S = "";
        }
       System.out.println(ans);
    }
}

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

typedef long long LL;  
using namespace std;

#define fillchar(a, x) memset(a, x, sizeof(a))
#define MP make_pair
#define PB push_back
#define endl '\n'

const int M = 1000000007;

int main()
{
ios_base::sync_with_stdio(0); 
cout.precision(15);
cout.setf(ios::fixed);

string s;

cin>>s;

int n = s.size();
int i,ans = -1;
for(i=0;i+1<n;i++)
	if(s[i]==s[i+1])
		{ans = i;break;}


if(ans == -1)
	{for(i=0;i+2<n;i++)
		if(s[i]==s[i+2])
			{ans = i;break;}
	}
else
	{cout<<ans+1<<' '<<ans+2<<endl;return 0;}		

if(ans == -1)
	cout<<"-1 -1"<<endl;
else
	cout<<ans+1<<' '<<ans+3<<endl;

}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const int INF = 1e9;
const ll MAXN = 1e6;
int n,a,b,c;
vector<int> l;


int dfs(int i,int ta,int tb,int tc)
{
    if(i==n)
    {
        if(ta==0 ||tb==0 ||tc==0)return INF;
        return abs(a-ta)+abs(b-tb)+abs(c-tc);
    }

    int ret=dfs(i+1,ta,tb,tc);

    ret=min(ret,dfs(i+1,ta+l[i],tb,tc)+(ta?10:0));
    ret=min(ret,dfs(i+1,ta,tb+l[i],tc)+(tb?10:0));
    ret=min(ret,dfs(i+1,ta,tb,tc+l[i])+(tc?10:0));
    return ret;

}

int main()
{
    cin>>n>>a>>b>>c;
    l.resize(n);
    rep(i,n)
    {
        cin>>l[i];
    }
    cout<<dfs(0,0,0,0);
}

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

int main(){
    int n;
    cin >> n;
    vector<int> A(n),B(n);
    for(int i=0;i<n;i++){
        cin >> A.at(i);
    }
    for(int i=0;i<n;i++){
        cin >> B.at(i);
    }

    int sum;
    int max = 0;
    for(int i=0;i<n;i++){
        sum = 0;
        for(int j=0;j<=i;j++){
            sum += A.at(j);
        }
        for(int j=i;j<n;j++){
            sum += B.at(j);
        }
        if(max < sum)   max = sum;
    }
    cout << max << endl;
}


Measured memory_bytes: 256
S=input()

even=[]
odd=[]

for i in range(len(S)):
    if((i+1)%2==0):
        even.append(S[i])
    else:
        odd.append(S[i])

odd_flag=True
for o in odd:
    if(o=="R" or o=="U" or o=="D"):
        pass
    else:
        odd_flag=False

even_flag=True
for e in even:
    if(e=="L" or e=="U" or e=="D"):
        pass
    else:
        even_flag=False


if(odd_flag and even_flag):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<stdio.h>

int BSort(int t, int *S, int n){
    int high, mid, low;
    high = n;
    low = 0;
    while(low < high){
        mid = (high + low) / 2;
        if(S[mid] == t) return 1;
        else if(S[mid] < t) low = mid + 1;
        else high = mid;
    }
    return 0;
}
 
int main(){
    int i, j, cnt=0;
    int n, q;
    int S[100000];
    int key;
 
    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d", &S[i]);
    scanf("%d", &q);
    
    for(i=0;i<q;i++){
        scanf("%d", &key);
        cnt += BSort(key, S, n);
    }
    
    printf("%d\n", cnt);
 
    return 0;
}

Measured memory_bytes: 988
x1,y1,x2,y2 = gets.split("\s").map {|s|s.to_i}
x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)
x4 = x3 - (x2-x1)
y4 = y3 - (y2-y1)
puts "#{x3} #{y3} #{x4} #{y4}"

Measured memory_bytes: 1788
Class Program
    Shared Sub Main(args As String())
        Dim n As Integer = CInt(Console.ReadLine())
        Dim s As New List(Of String)
        For i = 0 To n - 1
            s.Add(Console.ReadLine())
        Next
        Console.WriteLine("AC x " & s.Where(Function(x) x = "AC").Count())
        Console.WriteLine("WA x " & s.Where(Function(x) x = "WA").Count())
        Console.WriteLine("TLE x " & s.Where(Function(x) x = "TLE").Count())
        Console.WriteLine("RE x " & s.Where(Function(x) x = "RE").Count())
    End Sub
End Class

Measured memory_bytes: 34372
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
    int a[4];
    for(int i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+3);
    cout<<a[0]+a[1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, C, ans, s, t, c;

int main()
{
    cin >> N >> C;
    vector<int> imos(100003);
    vector<pair<int, pair<int, int>>> ch;
    for (int i = 0; i < N; i++)
    {
        cin >> s >> t >> c;
        ch.push_back({c - 1, {s, t}});
    }
    sort(ch.begin(), ch.end());
    c = ch[0].first;
    tie(s, t) = ch[0].second;
    bool flag = false;
    for (int i = 1; i < N; i++)
    {
        if (ch[i].first == c && t == ch[i].second.first)
        {
            if (i == N - 1)
                flag = true;
            t = ch[i].second.second;
        }
        else
        {
            imos[s - 1]++, imos[t]--;
            c = ch[i].first;
            tie(s, t) = ch[i].second;
        }
    }
    if (true)
    {
        imos[s - 1]++, imos[t]--;
    }

    for (int i = 0; i < 100002; i++)
    {
        imos[i + 1] += imos[i];
        ans = max(ans, imos[i]);
    }

    cout << ans << endl;
}

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

int n;
int a[300000];
long long ans = 0;

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

    int Xor = 0;
    int Sum = 0;
    int r = 0;
    for (int l = 0; l < n; l++) {
        while (r < n && (Xor ^ a[r]) == Sum + a[r]) {
            Xor ^= a[r];
            Sum += a[r];
            r++;
        }
        ans += (r - l);
        Xor ^= a[l];
        Sum -= a[l];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>

constexpr int N = 200000;
int A[N];

int E(int x) {
    return x+1;
}

int main() {
    std::ios_base::sync_with_stdio(0);
    int n,k;
    std::cin >> n >> k;
    for (int i=0;i<n;++i) std::cin >> A[i];
    int max = 0;
    int sum = 0;
    for (int i=0;i<k;++i) sum += E(A[i]);
    max = std::max(sum, max);
    for (int i=0;i+k<n;++i) {
        sum -= E(A[i]);
        sum += E(A[i+k]);
        max = std::max(sum, max);
    }
    std::cout.precision(10);
    std::cout << std::fixed << double(max)/2 << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = [[] for _ in range(N)]

    def add_edge(self, s, t, w=1):
        self.E[s].append(t)


def solve(N: int, M: int, s: "List[int]", t: "List[int]"):
    c = Counter(s)
    g = Graph(N)
    for ss, tt in zip(s, t):
        g.add_edge(ss, tt)

    DP = [0]*N
    for i in range(N-2, -1, -1):
        DP[i] = sum(DP[t] for t in g.E[i])/c[i] + 1

    gm = DP[0]
    for i in range(N-2):
        if len(g.E[i]) == 1:
            continue
        dp = DP[:]
        for j in range(i, -1, -1):
            tot, m = 0, 0
            for t in g.E[j]:
                tot += dp[t]
                m = max(dp[t], m)
            if i == j:
                dp[j] = (tot-m)/(c[j]-1)
            else:
                dp[j] = tot/c[j]
            dp[j] += 1
        gm = min(dp[0], gm)
        # print(dp)
    print(gm)


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    t = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))-1
        t[i] = int(next(tokens))-1
    solve(N, M, s, t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 50268
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


//�ϐ�
ld A, B;






//�T�u�֐�
//����
void input()
{
	cin >> A >> B;
}


//�v�Z
void calc()
{
	constexpr ld pi= 3.141592653589793;
	cout << fixed;
	cout << setprecision(8) << (ld)4 * pi*B*B*B / 3 << endl;
}


//�o��
void output()
{

}


//�f�o�b�O
void debug()
{
	int N;
	cin>>N;
}


//���C���֐�
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}



Measured memory_bytes: 3280
n = int(input())
t,a = map(int, input().split())
dat = list(map(int, input().split()))
resind = -1
resval = 9999999999999999999999999
for i in range(n):
    x = t - dat[i] * 0.006
    diff = abs(x-a)
    if diff < resval:
        resval = diff
        resind = i
print(resind+1)


Measured memory_bytes: 9076
n = gets.to_i
a = gets.split(' ')
max = 10**18

if a.include? "0"
  puts "0"
  exit
end

sum = 1
n.times do |i|
  num = a[i].to_i
  sum *= num
  if sum > max
    puts "-1"
    exit
  end
end

puts sum

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

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

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int res = 0;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == s[i + 1]) res++;
    }
    res = min(res + 2 * k, n - 1);
    cout << res;

    return 0;
}

Measured memory_bytes: 512
from scipy.special import comb
n,p = map(int, input().split())
A = list(map(int, input().split()))
cnt = [0,0] #偶数,奇数
for a in A:
    if a%2==0: cnt[0] += 1
    else: cnt[1] += 1
      
ans = 0
if p==0: #偶数＋奇数を偶数個(0個含む)
    for i in range(0,cnt[1]+1,2):
        ans += comb(cnt[1],i,exact=True)
    ans *= 2**cnt[0]
else: #偶数＋奇数を奇数個
    for i in range(1,cnt[1]+1,2):
        ans += comb(cnt[1],i,exact=True)
    ans *= 2**cnt[0]
print(ans)

Measured memory_bytes: 42104
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
struct UnionFind{
    vector<int> d;
    UnionFind(int n) : d(n,-1) {}
    //根なら、-サイズを格納それ以外は、親を格納
    int find(int x){
        if(d[x] < 0) return x;
        return d[x] = find(d[x]); //経路縮約
    }
    bool unite(int x,int y){
        //二つ頂点を持ってくる
        x = find(x);
        y = find(y);
        if(x == y) return false;//根が一致するなら何もしない
        if(d[x] > d[y]) swap(x,y);
        //ex:d[x]=-5,d[y]=-2
        //小さい方が、大きい方に引っ付く
        d[x] += d[y];//この場合、yがxにくっつく
        d[y] = x;
        return true;
    }
    bool same(int x,int y) {return find(x) == find(y);}
    int size(int x) {return -d[find(x)];}
};
int main(){
    cout << fixed << setprecision(10);
    ll n,m;
    cin >> n >> m;
    vector<int> a(m),b(m);
    rep(i,m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    UnionFind uf(n);
    ll cur = n*(n-1)/2;
    vector<ll> res;
    rep(i,m){
        res.push_back(cur);

        int aa = a[m-1-i], bb = b[m-1-i];
        if(uf.same(aa,bb)) continue;
        ll sa = uf.size(aa), sb=uf.size(bb);
        cur -= sa*sb;
        uf.unite(aa,bb);
    }
    reverse(res.begin(),res.end());
    rep(i,res.size()) cout << res[i] << endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  map<string,int> mp;
  rep(i,n){
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for( auto p : mp ) mx = max(mx, p.second);
  for( auto p : mp ) {
    if(p.second == mx) cout << p.first << endl;
  }
  return 0;
}
  

Measured memory_bytes: 25216
n,m,q = map(int, input().split())
Q = [[]]*q
for i in range(q):
  Q[i] = list(map(int, input().split()))
 
#10H10 = 92378
mx = 0

import copy
import sys
sys.setrecursionlimit(10**6)

def count_d(A):
  global mx
  if len(A)<n:
    for i in range(A[-1],m+1):
      A_next = copy.deepcopy(A)
      A_next.append(i)
      count_d(A_next)
      
  if len(A)==n:
    res = 0
    for i in range(q):
      a, b, c, d = Q[i]
      if A[b-1] - A[a-1] == c:
        res += d
    if res>mx:
      mx = res
      
for i in range(1, m+1):
  count_d([i])
  
print(mx)

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N, M; cin >> N >> M;
  int a[N]; rep(i, N) cin >> a[i];
  vector<int> vs; set<int> st;
  for(int i=N-1; i>=max(0, N-M); i--) {
    if(!st.count(a[i])) {
      st.insert(a[i]);
      vs.push_back(a[i]);
    }
  }

  for(auto e: vs) cout << e << endl;
  return 0;
}

Measured memory_bytes: 5968
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    string S, T;
    cin >> S >> T;
 
    //Initialize ans with a temporal value.
    //This value should be large enough; otherwise you will get wrong answer
    //Make sure that the value will lead to the correct answer.
    int ans = T.size();
 
    //Brute force through all initial position in S
    for (int start = 0; start <= S.size() - T.size(); start++)
    {
        int diff = 0;
        for (int i = 0; i < T.size(); i++)
        {
            if (T[i] != S[start + i]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <stdio.h>

int gcd(int a, int b) {
    int r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main() {
    long long x = 0;

    int K;
    scanf("%d", &K);

    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= a; b++) {
            for (int c = 1; c <= b; c++) {
                if (a == b && b == c) {
                    x += a;
                } else if (a == b || b == c || c == a){
                    x += 3 * gcd(gcd(a, b), c);
                } else {
                    x += 6 * gcd(gcd(a, b), c);
                }
            }
        }
    }

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

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


int main() {
    int N;
    cin >> N;
    vector<int>cities(N+1);
    vector<int>yushas(N);
    for (int i=0; i < N + 1; i++) {
        cin >> cities.at(i);
    }

    for (int i=0; i < N; i++) {
        cin >> yushas.at(i);
    }

    int64_t sum = 0;
    int tmp = 0;
    for (int i=0; i < N + 1; i++) {
        int yusha = 0;
        if (i < N) {
            yusha = yushas[i];
        }

        int city = cities[i];
        sum += min(city, yusha + tmp);
        if (yusha > city - tmp) {
            tmp = yusha - max((city - tmp), 0);
        } else {
            tmp = 0;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1152
from collections import deque
import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

H,W=[int(i) for i in input().split()]
C=[input() for _ in range(H)]
C=[list(i) for i in C] 

ans = 10**9

visited_list = [[10**9]*W for _ in range(H)]
stack = deque([[0, 0, 0]])
visited_list[0][0] = 0

w_cnt=0
for c in C: w_cnt += c.count(".")

def dfs(town, visited_list, stack):
    global ans
    flag = 0
    while len(stack) > 0:
        h, w, cnt = stack.pop()
        if h == H-1 and w == W-1 and ans > cnt:
            ans = cnt
            flag = 1
            continue
        for j, k in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or new_w < 0 or new_w >= W:
                continue
            if  town[new_h][new_w] != "#" and visited_list[new_h][new_w] > cnt + 1:
                visited_list[new_h][new_w] = cnt + 1
                stack.append([new_h, new_w, cnt+1])
    if flag: 
        ans = w_cnt-(ans+1)
        return ans
    else: return -1

print(dfs(C, visited_list, stack))

Measured memory_bytes: 44252
package main

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

func main() {
	A := nextInt()
	B := nextInt()

	mod := B % A
	if mod == 0 {
		fmt.Println(A + B)
	} else {
		fmt.Println(B - A)
	}
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
s = gets.chomp
t = gets.chomp

diffs = []

s.length.times do |i|
    break if i + t.length > s.length
    diff = 0
    t.length.times do |j|
        diff += 1 if s[i+j] != t[j]
    end
    diffs << diff
end

puts diffs.min


Measured memory_bytes: 14304
#include<stdio.h>
int main()
{
  int a[1000], n, i, j, k, v;
  scanf("%d", &n);
  for(k = 0; k < n; k++)
    {
      scanf("%d",&a[k]);
    }
  for(k = 0; k < n-1; k++)
    {
      printf("%d ",a[k]);
    }
  printf("%d", a[n-1]);
  printf("\n");
  for(i = 1; i < n; i++)
    {
      v = a[i];
      j = i - 1;
      while (j >= 0 && a[j] > v)
	{
	  a[j+1] = a[j];
	  j--;
	  a[j+1] = v;
	}
      for(k = 0; k < n-1; k++)
	{
	  printf("%d ",a[k]);
	}
      printf("%d", a[n-1]);
      printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
 
int main(){
    string s;cin>>s;
    int si=s.size();
    vector<int> v(si,0);
    int a=0;
    int b=0;
    s+='R';
    rep(i,si){
        if(s[i]=='R'&&s[i+1]=='L'){
            a=i;
        }
        else if(s[i]=='L'&&s[i+1]=='R'){
            if((a+1-b)%2){
            v[a]=(i+1-b+1)/2;
            v[a+1]=(i+1-b)/2;
            }
            else {
            v[a]=(i+1-b)/2;
            v[a+1]=(i+1-b+1)/2;
            }
            b=i+1;
        }
    }
    rep(i,si){
        cout<<v[i]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 3828
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int A,B,C;

int main() {
	cin>>A>>B>>C;


	cout<<A*B/2<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

int main() {
    ll N=in();
    ll ans;
    ll i;
    for(i=1;i<=N;i++){
        if(i*(i+1)/2>N){
            break;
        }
    }
    ans=i;
    for(i=1;i<=ans;i++){
        if(ans*(ans+1)/2-N==i){
            continue;
        }
        else{
            cout<<i<<endl;
        }
    }
}

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

#define F                   first
#define S                   second
#define int                 long long int
#define pb                  push_back
#define mp                  make_pair
#define pii                 pair<int,int>
#define vi                  vector<int>
#define mii                 map<int,int>
#define pqb                 priority_queue<int>
#define pqs                 priority_queue<int,vi,greater<int> >
#define mod                 1000000007
#define endl                '\n'
#define rep(i,a,b)            for(int i=a;i<b;i++)

int knapSack(int si, int weight[], int value[], int capacity, int n, vector<vector<int> > &dp) {
    if (si == n) {
        return 0;
    }

    if (dp[si][capacity] != -1) {
        return dp[si][capacity];
    }

    int include = INT_MIN;
    if (weight[si] <= capacity) {
        include = value[si] + knapSack(si + 1, weight, value, capacity - weight[si], n, dp);
    }

    int exclude = knapSack(si + 1, weight, value, capacity, n, dp);

    int result = max(include, exclude);



    return  dp[si][capacity] = result;
}
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
    c_p_c();

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

    vector<vector<int> > dp(n + 1, vector<int> (maxw + 1, -1));
    int ans = knapSack(0, w, v, maxw, n, dp);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 83100
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll ans[555][555];
void dfs(ll num,ll le,ll ri,ll level){
  if(num==1){
    ans[le][ri]=level;
    return;
  }else if(num==0)return;
  // cout<<le<<" "<<le+num/2-1<<" "<<le+num/2<<" "<<ri<<endl;
  for(int i=le;i<le+num/2;i++){
    for(int j=le+num/2;j<=ri;j++){
      ans[i][j]=level;
      ans[j][i]=level;
    }
  }
  dfs(num/2,le,le+num/2-1,level+1);
  dfs(num/2+num%2,le+num/2,ri,level+1);
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  dfs(n,0,n-1,1);
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++)
      cout<<ans[i][j]<<" ";
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 2688
// Problem_A.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include <iostream>
using namespace std;

int main(void) {
	int A, B, ans;

	cin >> A >> B;
	ans = A + B;
	if (ans < 10)
		cout << ans << '\n';
	else
		cout << "error\n";

	return 0;
}


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

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int[] array = {scanner.nextInt(),scanner.nextInt(),scanner.nextInt()};
		Arrays.sort(array);
		
		System.out.println((array[0] + array[1]) == array[2]?"Yes":"No");
		scanner.close();
	}

}


Measured memory_bytes: 22868
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(a>=13){
			System.out.println(b);
		}
		else if(a>=6 && 12>=a)
		{ System.out.println(b/2);
		}
		else if(5>=a)
		{
			System.out.println(0);
		}
		sc.close();


	}

}

Measured memory_bytes: 21844
def longestRepeatedSubstring(str):

    n = len(str)
    LCSRe = [[0 for x in range(n + 1)]
             for y in range(n + 1)]

    res = ""
    res_length = 0

    index = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if (str[i - 1] == str[j - 1] and
                    LCSRe[i - 1][j - 1] < (j - i)):
                LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1

                if (LCSRe[i][j] > res_length):
                    res_length = LCSRe[i][j]
                    index = max(i, index)

            else:
                LCSRe[i][j] = 0


    if (res_length > 0):
        for i in range(index - res_length + 1,
                       index + 1):
            res = res + str[i - 1]

    return res


if __name__ == "__main__":
    a = int(input())
    s = input()

    print(len(longestRepeatedSubstring(s)))


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

int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;
  int counter = 0;
  for(int i=0; i<N ;++i){
    if(s[i]=='R') counter++;
  }
  int answer = 0;
  for(int i=0; i<counter ;++i){
    if(s[i]=='R') answer++;
  }
  cout << counter - answer << endl;
}

Measured memory_bytes: 3784
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int n;
	cin>>n;
    int a[105][105];
    for(int i=0;i<2;i++)
    {
    	for(int j=0;j<n;j++)
    	{
    		cin>>a[i][j];
		}
    }
    int sum[105][105];
    memset(sum,0,sizeof(sum));
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i==0 && j==0)
			{
				sum[i][j]=a[i][j];
			}
			else
			{
				sum[i][j]=max(sum[i][j-1]+a[i][j],sum[i-1][j]+a[i][j]);
			}
		}
	}
	cout<<sum[1][n-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

N = int(input())
S = input()

target = 'ABC'
count = 0
for i in range(N-2):
    if S[i:i+3] == target:
        count += 1

print(count)

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<ll> VL;

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

    int N;
    cin >> N;
    int H[N];
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
    }

    int ans = 0;
    int h = 0;
    for (int i = 0; i < N; ++i) {
        if (H[i] >= h) {
            ans++;
            h = max(h, H[i]);
        }
    }

    cout << ans << endl;
}

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

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		Integer[] arr = new Integer[5];
		for (int i = 0; i < 5; i++) {
			arr[i] = sc.nextInt();
		}

		Arrays.sort(arr, Collections.reverseOrder());

		for (int i = 0; i < 5; i++) {
			if (i != 0)
				System.out.print(" ");
			System.out.print(arr[i]);
		}
		System.out.println();
	}

}

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

int main() {
  int N,K;
  cin>>N>>K;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int count=0;
  for(int i=0;i<N;i++){
    if(vec.at(i)>=K){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3636