akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
    cin>>a;
    int l=a.size();
    for(int i=1;i<l;i++)
    {
        if(a[i]==a[i-1])
        {
            cout<<i<<" "<<i+1<<endl;
            return 0;
        }
    }
    for(int i=2;i<l;i++)
    {
        if(a[i]==a[i-2])
        {
            cout<<i-1<<" "<<i+1<<endl;
            return 0;
        }
    }
    cout<<-1<<" "<<-1<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n ;
    cin >> n ;
    
    ll a[n][3];
    for(ll i = 0; i < n ; i++)
    {
        for(ll j = 0 ; j < 3 ; j++)
        {
            cin >> a[i][j];
           // cout << a[i][j] << " ";
        }
    }
    ll dp[n][3];
    dp[0][0] = a[0][0] , dp[0][1] = a[0][1] , dp[0][2] = a[0][2] ;
    for(ll i = 1 ; i < n ; i++)
    {
        for(ll j= 0 ; j < 3 ; j++)
        {
            if(j == 0)
            {
                dp[i][j] = max(dp[i-1][1]+a[i][j] , dp[i-1][2]+a[i][j]);
            }
            else if(j == 1)
            {
                dp[i][j] = max(dp[i-1][0]+a[i][j] , dp[i-1][2]+a[i][j]);
            }
            else
            {
                dp[i][j] = max(dp[i-1][0]+a[i][j] , dp[i-1][1]+a[i][j]);
            }
        }
    }

    cout << max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2]));
    
    


    



}


Measured memory_bytes: 4864
#include<stdio.h>
int main(){
  int i,a,b,sum,max,min;
  while(1)
    {
      sum=0;
	  max=-10000;
	  min=10000;
      scanf("%d",&a);
      if(a==0)break;
      for(i=1;i<=a;i++)
	{
	  scanf("%d",&b);
	  if(b>max)
	    {
	      max=b;
	    }
	  if(b<min)
	    {
	      min=b;
	    }
	  sum+=b;
	}
      printf("%d\n",(sum-max-min)/(a-2));
    }
  return 0;
}

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

Measured memory_bytes: 1168
from collections import Counter
 
N = int(input())
S = [input() for _ in range(N)]

# 方針：各文字列の出現回数を数え、出現回数が最大なる文字列を昇順に出力する
# Counter(リスト) は辞書型のサブクラスであり、キーに要素・値に出現回数という形式
# Counter(リスト).most_common() は(要素, 出現回数)というタプルを出現回数順に並べたリスト
S = Counter(S).most_common()
max_count = S[0][1] # 最大の出現回数
# 最大の出現回数を取る文字列を出力する
l = [s[0] for s in S if s[1] == max_count]

# 昇順にソートして出力
for i in sorted(l):
  print(i)

Measured memory_bytes: 49552
# INPUT
r, c = map(int, input().split())

matrix = [[0 for i in range(c + 1)] for j in range(r + 1)]

for j in range(r):

    for cnt, element in enumerate(list(map(int, input().split()))):
        matrix[j][cnt] = element


# CALC
for i in range(c):
    
    sum_cow = 0
    
    for j in range(r):

        sum_cow += matrix[j][i]

    matrix[r][i] = sum_cow


for j in range(r + 1):

    matrix[j][c] = sum(matrix[j])


# OUTPUT
for j in range(0, r + 1):
    print(f"{matrix[j][0]}", end="")
    
    for i in range(1, c + 1):
        print(f" {matrix[j][i]}", end="")

    print()



Measured memory_bytes: 6224
n = int(input())
p = 10**9 + 7
m = [2]
for i in range(n+1):
    for j in range(2, i):
        if i % j == 0:
            break
        if j == i-1:
            m.append(i)

a = [0]*len(m)

for i in range(1, n+1):
    for j in range(len(m)):
        while i % m[j] == 0:
            a[j] += 1
            i //= m[j]
ans = 1
for i in a:
    ans *= (i+1) % p
print(ans%p)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
using namespace std;

ll a, b;
string s;

inline void work(){
	cin >> s;
	REP(i, 0, s.size() - 1){
		if (s[i] == 'A') a++;
		else b++;
	}
	if (a && b) puts("Yes");
	else puts("No");
}

int main(){
	work();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = ll(1e18) + 1;

int main() {
    cout << fixed << setprecision(10);
    
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    ll lx = -INF, rx = INF;
    while(lx+1 < rx) {
        ll cx = (lx + rx) / 2;
        // cx未満になる数がいくつあるか数える
        ll tot = 0;
        rep(i, N) {
            if (A[i] < 0) {
                // A[i]が0未満のとき、右側とのペアがより小さい
                int l = -1, r = N;
                while(l+1 < r) {
                    int c = (l+r)/2;
                    if (A[c] * A[i] < cx) {
                        r = c;
                    } else {
                        l = c;
                    }
                }
                tot += N-r;
            } else {
                // A[i]が0以上のとき、左側とのペアがより小さい
                int l = -1, r = N;
                while(l+1 < r) {
                    int c = (l+r)/2;
                    if (A[c] * A[i] < cx) {
                        l = c;
                    } else {
                        r = c;
                    }
                }
                tot += r;
            }
            if (A[i]*A[i] < cx) {
                tot -= 1;
            }
        }
        tot /= 2;
        if (tot < K) {
            lx = cx;
        } else {
            rx = cx;
        }
    }
    cout << lx << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)

signed main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    int cnt = 0;
    int inc = 0;
    int dcr = 0;

    rep(i, n-1){
        int diff = a[i+1] - a[i];
        if(diff < 0){
            if(inc){
                cnt++;
                dcr = 0;
                inc = 0;
                continue;
            }
            inc = 0;
            dcr++;
            /* cout << "dcr "; */
        }else if(diff > 0){
            if(dcr){
                cnt++;
                inc = 0;
                dcr = 0;
                continue;
            }
            dcr = 0;
            inc++;
            /* cout << "inc "; */
        }else{
            if(dcr > 1) dcr++;
            if(inc > 1) inc++;
        }
    }
    /* cout << endl; */

    cout << cnt+1 << endl;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*b,c*d)<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 100
#define LARGE 10000

typedef struct edge{
	int cost;
	int u;
	int v;
}edge;


int n;
int a[MAX][MAX];
edge E[LARGE];


/*qsort用*/
int cmp(const void *p,const void *q){
	return ((edge*)p)->cost - ((edge*)q)->cost;
}


int find(int u,int b[]){
	if(b[u]==u){
		return u;
	}else {
		return b[u]=find(b[u],b);
	}
}

void merge(int u,int v,int b[]){
	if(b[u] < b[v]){
		if(v!=b[v])
			merge(u,b[b[v]],b);
		b[v]=b[u];
	}
	else {
		if(u!=b[u])
			merge(v,b[b[u]],b);
		b[u]=b[v];
	}
	return;
}



int main(){
	int i,j;
	int num=0;
	int ans=0;
	int b[MAX];/*親の配列*/
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)b[i]=i;
	
	
	/*隣接行列の読み込み*/
	for(i=0;i<n;i++){
	
		for(j=0;j<n;j++){
			scanf("%d",&a[i][j]);
			if(a[i][j]!=-1 && j>=i+1){
				E[num].cost=a[i][j];
				E[num].u=i;
				E[num++].v=j;
			}
		}
		
	}
	
	/*edgeのソート*/
	qsort(E,num,sizeof(edge),cmp);
	
	for(i=0;i<num;i++){
		if(find(E[i].u,b) != find(E[i].v,b)){
			merge(E[i].u,E[i].v,b);
			ans+=E[i].cost;
		}
	}
	
	printf("%d\n",ans);
	
	return 0;
	
}


Measured memory_bytes: 2104
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int h = in.nextInt();
            out.println((a + b) * h / 2);
        }

    }
}



Measured memory_bytes: 22356
def main():
    _ = input()
    A = list(map(int, input().split()))
    cnt = 1 
    mi = min(A)
    if mi == 0:
        print(0)
    else:
        for a in A:
            cnt *= a 
            if cnt > 1e18 and mi > 0:
                print(-1)
                break
        else:
            if cnt < 0:
                print(-1)
            else:
                print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 84672
n = int(input())
p = list(map(int,input().split()))
ans = 0

flag = False
for i in range(n):
    if flag:
        flag = False
        continue
    if p[i] == i+1:
        if i < n-1 and p[i+1] == i+2:
            flag = True
        ans += 1

print(ans)


Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007LL;
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;

ll n, k;

ll cache[2050][2050];
ll combi(ll a, ll b) {
	if(a < b) return 0;
	if(a == b || b == 0) return 1;

	ll& ret = cache[a][b];
	if(ret != -1) return ret;

	return ret = (combi(a-1,b-1) + combi(a-1,b))%MOD;
}

int main(void) {
	ios_base::sync_with_stdio(false); 
	cin.tie(0); 
	cout.tie(0);
	//freopen("in.txt", "r", stdin);
	rep(i,0,2050) rep(j,0,2050) {
		cache[i][j] = -1;
	}
	cin >> n >> k;
	for(ll a = 1; a <= k; ++a) {
		cout << (combi(n-k+1, a) * combi(k-1, a-1))%MOD << endl;
	}
	return 0;
}


Measured memory_bytes: 33152
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	S := readBytes()
	var ans int = math.MaxInt32
	for _, c := range []int{0, 1} {
		var count int
		for i := range S {
			if int(S[i]-'0') != c {
				count++
			}
			c = 1 - c
		}
		ans = min(ans, count)
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>

#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;


int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (auto &v : a) cin >> v;
    
    ll minVal = n;
    ll minPos = 0;
    for (auto i = 0; i < n; i++) {
        if (a[i] < minVal) {
            minVal = a[i];
            minPos = i;
        }
    }
    
    ll count = 0;
//    if (minPos < k || minPos >= (n - k)) {
        count = ceil(double(n - 1) / (k - 1));
//    } else {
//      count  = ceil(double(minPos) / (k - 1)) + ceil(double(n - minPos - 1) / (k - 1));
//    }
    
                    
    cout << count << endl;
    
    return 0;
}



Measured memory_bytes: 1024
N,P = map(int,input().split())
max_a = int(P**(1/N))+1
ans = 1
if N == 1:
  print(P)
else:
  for i in range(2,max_a):
    while (P%(i**N) == 0):
      ans = ans*i
      P = P//i**N

  print(ans)

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

int main(){
    int k,z=0,no=0;
    vector<int>a(5);
    
    for(int i=0;i<5;i++){
        cin>>a.at(i);
    }
    cin>>k;
    z=a.at(4)-a.at(0);
    if(z>k)no=1;
    if(no==1){
        cout<<":("<<endl;
    }else{
        cout<<"Yay!"<<endl;
    }

}



Measured memory_bytes: 256
#include<stdio.h>
using namespace std;

int main(){
	int h, w;
	int i,j;
	while(1){
		scanf("%d %d", &h, &w);
		if(!h && !w)break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(i==0 || i==h-1 || j==0 || j==w-1){
					putchar('#');
				}else{
					putchar('.');
				}
			}
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1000
#include <stdio.h>
int main(){
	int a;
	scanf("%d", &a);
	for(int i = 1; i < 10; ++i){
		if(a%i == 0 && a/i < 10){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mm 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define siz(x) (int)x.size()

#define show(x) cout<<#x<<" "<<x<<'\n'
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define oset tree<int , null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

int main()
{
    iosbase;
    int n,k,i;
    cin>>n>>k;
    
    vector<ll> h(n+1),ans(n+1,INT_MAX);

    for(i=1;i<=n;i++) cin>>h[i];
    ans[1]=0;
    for(i=2;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j>=1)
            {
                ans[i]=min(ans[i],ans[i-j]+abs(h[i]-h[i-j]));
            }
            else break;
        }
    }
    cout<<ans[n]<<'\n';
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;

int main()
{
  string s,ans="First";
  cin>>s;
  if((s.length()%2==0) != (s[0]==s[s.length()-1])){
    ans="Second";
  } 
  cout<< ans <<endl;
}


Measured memory_bytes: 512
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let _n = get!(usize);
    let mut x = 0;
    let mut y = 0;
    let mut z = 0;
    for a in get!(String).split_whitespace().map(|i| i.parse::<i32>().unwrap()) {
        match a {
            _ if a%4 == 0 => x += 1,
            _ if a%2 == 0 => y += 1,
            _ => z += 1,
        }
    }
    if y > 0 {
        z += 1;
    }
    println!("{}", if x >= z-1 { "Yes" } else { "No" });
}

Measured memory_bytes: 6396
#include<iostream>

using namespace std;

int main(void)
{
        int n;
        cin >> n;
        int a[n];

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

        int count = 0;
        bool flag = false;

        while(true)
        {
                for(int i=1;i<=n;i++)
                {
                        if(a[i-1]%2==1)
                        {
                                flag = true;
                                break;
                        }
                        a[i-1]=a[i-1]/2;
                }
                if(flag==true)
                        break;
                count++;
        }

        cout << count << endl;

}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
lis = [0]*(n)
lis[1] = abs(h[1]-h[0])
for i in range(2,n):
  lis[i] = min(lis[i-1]+abs(h[i]-h[i-1]),lis[i-2]+abs(h[i-2]-h[i]))
print(lis[n-1])

Measured memory_bytes: 13928
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
a.append(0)
F = [([0]*w) for _ in range(h)]
count = a[0]
x = 1
for j in range(h):
    for i_ in range(w):
        i = ((-1)**j)*i_ + (w-1 if j%2 else 0)
        F[j][i] = x
        count -= 1
        if count == 0:
            count = a[x]
            x += 1
for l in F:
    print(" ".join(list(map(str, l))))


Measured memory_bytes: 3564
n = int(input())
a = list(map(int,input().split()))
mydic ={}
for i in range(n):
	mydic[a[i]] = i+1
sortedDict = sorted(mydic.items())
s =[]
for j in range(n):
    s.append(str(sortedDict[j][1]))
print(" ".join(s))

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

int main(){
	string s;
	cin >> s;
	vector<int> a(4);
	rep(i, 4) a.at(i) = s.at(i) - '0';

	for(int x = 0; x < 8; x++){
		int sum = a.at(0);
		string formula;
		formula += s.at(0);

		for(int i = 0; i < 3; i++){
			if(x & (1<<i)){
				sum += a.at(i+1);
				formula += '+';
				formula += s.at(i+1);
			}else{
				sum -= a.at(i+1);
				formula += '-';
				formula += s.at(i+1);
			}
		}
		if(sum == 7){
			cout << formula << "=7" << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int b,c,e;
int main() {
    int n1,n2;
    cin>>n1;
    vector<int> a(n1);
    for(int i=0;i<n1;i++){
        cin>>a[i];
    }
    cin>>n2;
    vector<int> b(n2);
    for(int i=0;i<n2;i++){
        cin>>b[i];
    }
    cout<< (a<b) <<endl;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int MOD=1e9+7;
ll a[N];
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    ll n,m,x;
    cin>>n>>m>>x;
    ll ans1=0,ans2=0;
    for(ll i=1;i<=m;i++){
        int t;cin >> t;
        a[t]=1;
    }
    for(ll i=x;i<=n;i++)
        if(a[i])    ans1++;
    for(ll i=x;i>=1;--i)
        if(a[i])    ans2++;
    cout << min(ans1,ans2)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int cards[4][13] = {}, all, num, x, y;
	char suit, kindsuit[] = {'S', 'H', 'C', 'D'};
	scanf("%d", &all);
	for (x = 0; x < all + 1; x++) {
		scanf("%c %d%*c", &suit, &num);
		switch (suit) {
		case 'S' :
			cards[0][num - 1] = 1;
			break;
		case 'H' :
			cards[1][num - 1] = 1;
			break;
		case 'C' :
			cards[2][num - 1] = 1;
			break;
		case 'D' :
			cards[3][num - 1] = 1;
			break;
		}
	}
	for (x = 0; x < 4; x++) {
		for (y = 0; y < 13; y++) {
			if (cards[x][y] == 0) {
				printf("%c %d\n", kindsuit[x], y + 1);
			}
		}
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(3e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    REP(i,n){
        cin >> a[i];
    }
    REP(i,n){
        cin >> b[i];
    }
    ll x=0,y=0;
    REP(i,n){
        if(a[i]<b[i])x += (b[i]-a[i])/2;
        else y += a[i]-b[i];
    }
    if(x>=y)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const int MAXK = 1000;

int c[2*MAXK+1][2*MAXK+1];
int sum[2*MAXK+1][2*MAXK+1];

int query(int x1, int y1, int x2, int y2){
  if(x1 > x2 || y1 > y2) return 0;
  // return sum of x1 <= x <= x2 && y1 <= y <= y2
  return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N, K; cin >> N >> K;
  for(int i=0;i<N;i++){
    int x, y;
    char color;
    cin >> x >> y >> color;
    if(color == 'B'){
      c[x %(2*K) + 1][y %(2*K) + 1]++;
    }else{
      c[x %(2*K) + 1][(y + K) %(2*K) + 1]++;
    }
  }

  for(int i=1;i<=2*K;i++){
    for(int j=1;j<=2*K;j++){
      sum[i][j] = c[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
      // cout << sum[i][j] << " ";
    }
    // cout << endl;
  }

  int maxnum = 0;
  for(int x=1;x<=K+1;x++){
    for(int y=1;y<=K+1;y++){
      // count num in five black squares
      int num = query(1, 1, x-1, y-1) + query(1, y+K, x-1, 2*K)
      + query(x, y, x+K-1, y+K-1) + query(x+K, 1, 2*K, y-1) + query(x+K, y+K, 2*K, 2*K);
      maxnum = max(max(num, N-num), maxnum);
    }
  }
  cout << maxnum << endl;
}

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

int fact(int x){
        if(x==0) return 1;
        return x*fact(x-1);
}
int hoge(int a,int t){
        return (a-1)*fact(t-1);
}
int main(){
        int N;
        cin >> N;
        int P[N-1],Q[N-1];
        for(int i=0;i<N;i++)cin >> P[i];
        for(int i=0;i<N;i++)cin >> Q[i];

        int num_p=0;
        int num_q=0;
        for(int t=0;t<N;t++){
                int count_p=1;
                int count_q=1;
                for(int i=t+1;i<N;i++){
                        if(P[i]<P[t]) count_p++;
                        if(Q[i]<Q[t]) count_q++;
                }
                num_p+=hoge(count_p,N-t);
                num_q+=hoge(count_q,N-t);
        }
        cout <<abs(num_p-num_q);

        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
#define pi 3.1415926535
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int x;
    cin>>x;
    float result=45;
    bool flag=false;
    if(2*x<=a*a*b)
        flag=false;//没有半满
    else if(2*x>a*a*b)
        flag=true;//半满

    if(!flag)
    {
        float c=a*b*b;c/=(2*x);
        printf("%.10f",atan(c)/pi*180);
    }
    else
    {
        float c=a*a*b-x;c/=a;c*=2;c/=a;c/=a;
        printf("%.10f",atan((c))/pi*180);
    }
}


Measured memory_bytes: 632
import java.util.*;

public class Main {
    public static final long INF = Long.MAX_VALUE >> 2;
    public static final int SIZE = 110000;
    public static long[][] dp = new long[SIZE][3]; //制約に応じてテーブル規模を調節する
    //dp[DAY][DID] -> DAY日目までの幸福度の総和の最大値と、前日にした行動(DID)
    public static long[][] happiness = new long[SIZE][3];//制約に応じてテーブル規模を調節する
    //happiness[DAY][VALUE] -> DAY日目の幸福度(VALUE)
    public static void main(String[] args) throws Exception {
       for(int i=0;i<SIZE;++i){
           for(int j=0;j<3;j++){
                dp[i][j] = 0;   
           }
       }
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
       for(int i=0;i<N;i++){
           for(int j=0;j<3;j++){
               happiness[i][j] = sc.nextInt();
           }
       }
       for(int i=1;i<=N;i++){
               for(int j=0;j<3;j++){
                   for(int k=0;k<3;k++){
                       if(j == k) continue;
                       dp[i][k] = Math.max(dp[i][k],dp[i-1][j] + happiness[i-1][k]);
                   }
               }
           }
        long res = 0;
        for(int j=0;j<3;j++)res = Math.max(res,dp[N][j]);
        System.out.println(res);
       }
    }

Measured memory_bytes: 104900
#include<iostream>
#include<math.h>
using namespace std;

int main(){
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
	
	long long int  n,k;
	cin>>n>>k;
	long long int x = n%k;
	if(abs(x-k) < x ){
		cout<<abs(x - k)<<endl;
	}else{
		cout<<x<<endl;
	}
}

Measured memory_bytes: 3648
A, B, C, D = gets.split('').map(&:to_i)

ops = [1,-1].repeated_permutation(3)

ans = Array.new
ops.each do |op|
  if A+op[0]*B+op[1]*C+op[2]*D == 7
    3.times do |k|
      ans[k] = op[k]==1 ? '+' : '-'
    end
  end
end

puts A.to_s + ans[0] + B.to_s + ans[1] + C.to_s + ans[2] + D.to_s + '=7'

Measured memory_bytes: 1788
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！

s = input()
if s[-1] == "s":
    print(s+"es")
else:
    print(s+"s")

Measured memory_bytes: 9920
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
bool byme(pair<int,int> a,pair<int,int> b)
{
    return a.ss<b.ss;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
pair<int,int> arr[n];
for(int i=0;i<n;i++)
{
    int x,d;
    cin>>x>>d;
    arr[i].ff=x-d;
    arr[i].ss=x+d;
}
sort(arr,arr+n,byme);
int ans=0;
int inf=-pow(10,15);
int prev=inf;
for(int i=0;i<n;i++)
{
    if(arr[i].ff>=prev)
    {
        prev=arr[i].ss;
      ans++;
    }
}

cout<<ans<<endl;













    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

bool judge(int n){
  string s = to_string(n);
  rep(i,s.size()/2) if(s[i] != s[s.size()-i-1]) return false;
  return true;
}

main(){
  int a, b; cin >> a >> b;
  int ans = 0;
  FOR(i,a,b+1) if(judge(i)) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
input_str = input()
A = int(input_str[0])
B = int(input_str[1])
C = int(input_str[2])
D = int(input_str[3])

list = []
list.append(A + B + C + D)
list.append(A + B + C - D)
list.append(A + B - C + D)
list.append(A + B - C - D)
list.append(A - B + C + D)
list.append(A - B + C - D)
list.append(A - B - C + D)
list.append(A - B - C - D)

num = list.index(7)

if num <= 3:
    op1 = '+'
else:
    op1 = '-'

if num == 0 or num == 1 or num == 4 or num == 5:
    op2 = '+'
else:
    op2 = '-'

if num % 2 == 0:
    op3 = '+'
else:
    op3 = '-'

print('{}{}{}{}{}{}{}=7'.format(A,op1,B,op2,C,op3,D))

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		long[] A=new long[N];
		for(int i=0; i<N; i++) {
			A[i]=sc.nextLong();
		}
		Arrays.sort(A);
		for(int i=0; i<N/2; i++) {
			if(A[i*2]+A[i*2+1]<0) {
				A[i*2]*=-1;
				A[i*2+1]*=-1;
			}
		}
		long ans=0;
		for(int i=0; i<N; i++) {
			ans+=A[i];
		}
		pl(ans);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}


Measured memory_bytes: 43988
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef pair<int, int> pi;
#define SQ(a) (a) * (a)
#define deb(x) cout << #x << " = " << x << '\n'
#define deb2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
 
int dp[100002][3];

int solve(int a[][3],int curr,int choice){
	if(curr==0){
		return 0;
	}
	if(dp[curr][choice]!=-1) return dp[curr][choice];
	if(choice==0){
		return dp[curr][choice]=max(a[curr][1]+solve(a,curr-1,1),a[curr][2]+solve(a,curr-1,2));
	}
	if(choice==1){
		return dp[curr][choice]=max(a[curr][0]+solve(a,curr-1,0),a[curr][2]+solve(a,curr-1,2));
	}
	else{
		return dp[curr][choice]=max(a[curr][0]+solve(a,curr-1,0),a[curr][1]+solve(a,curr-1,1));
	}
}
 
int main(int argc, char const *argv[])
{
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp,-1,sizeof dp);
    int n;
    cin>>n;
    int a[n+1][3];
    for(int i=1;i<=n;i++){
    	cin>>a[i][0]>>a[i][1]>>a[i][2];

    }
    int ans = max(a[n][0]+solve(a,n-1,0),max(a[n][1]+solve(a,n-1,1),a[n][2]+solve(a,n-1,2)));
    cout<<ans;

    return 0;
}

Measured memory_bytes: 12168
S = input()
s1 = int(S[:2])
s2 = int(S[2:])
def is_MM(s):
    return 1 <= s <= 12

if is_MM(s1) and is_MM(s2):
    print('AMBIGUOUS')
elif is_MM(s1):
    print('MMYY')
elif is_MM(s2):
    print('YYMM')
else:
    print('NA')    


Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
int main(void)
  {
	int n,i,d,scoret=0,scoreh=0;
	char cardt[101],cardh[101];
	scanf("%d",&n);
	for(i=0;i<n;i++)
  {
	scanf("%s %s",cardt,cardh);
	d=strcmp(cardt,cardh);
	if(d==0){scoret++;scoreh++;}
	else if(d>0){scoret+=3;}
	else{scoreh+=3;}
  }
	printf("%d %d\n",scoret,scoreh);

	return 0;
  }

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
int a[4001][3],b[4001][3],c[4001];
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	long long ans=0;
	a[0][0]=a[0][1]=a[0][2]=0;
	b[n-1][0]=b[n-1][1]=b[n-1][2]=0;
	for(int i=0;i<s.size();i++)
	{
		a[i][0]=a[i-1][0];
		a[i][1]=a[i-1][1];
		a[i][2]=a[i-1][2];
		if(s[i]=='R')
			a[i][0]++;
		if(s[i]=='G')
			a[i][1]++;
		if(s[i]=='B')
			a[i][2]++;
	}
	for(int i=s.size()-1;i>=0;i--)
	{
		b[i][0]=b[i+1][0];
		b[i][1]=b[i+1][1];
		b[i][2]=b[i+1][2];
		if(s[i]=='R')
			b[i][0]++;
		if(s[i]=='G')
			b[i][1]++;
		if(s[i]=='B')
			b[i][2]++;
	}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='R')
		{
			for(int j=1;j<=min(i,n-i-1);j++)
			{
				if((s[i+j]=='B'&&s[i-j]=='G')||(s[i+j]=='G'&&s[i-j]=='B'))
					c[i]++;
			}
		}
		if(s[i]=='G')
		{
			for(int j=1;j<=min(i,n-i-1);j++)
			{
				if((s[i+j]=='B'&&s[i-j]=='R')||(s[i+j]=='R'&&s[i-j]=='B'))
					c[i]++;
			}
		}	
		if(s[i]=='B')
		{
			for(int j=1;j<=min(i,n-i-1);j++)
			{
				if((s[i+j]=='R'&&s[i-j]=='G')||(s[i+j]=='G'&&s[i-j]=='R'))
					c[i]++;
			}
		}
	}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='G')
		{
			ans+=a[i][0]*b[i][2];
			ans+=a[i][2]*b[i][0];
		}
		if(s[i]=='R')
		{
			ans+=a[i][1]*b[i][2];
			ans+=a[i][2]*b[i][1];
		}
		if(s[i]=='B')
		{
			ans+=a[i][0]*b[i][1];
			ans+=a[i][1]*b[i][0];
		}
		ans-=c[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
int ans, rmd, idx = 1, rmds[2019] = { 1 };
string s;
int main()
{
	cin >> s;
	reverse(s.begin(), s.end());
	for (auto i : s)
	{
		rmd = (idx * (i - '0') + rmd) % 2019;
		rmds[rmd]++;
		idx = idx * 10 % 2019;
	}
	for (auto i : rmds)
	{
		ans += i * (i - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3672
#include <stdio.h>

int main(void) {
	int ab, bc, ca;
	int ans = 0;
	if (scanf("%d%d%d", &ab, &bc, &ca) != 3) return 1;
	if (ab*ab+bc*bc==ca*ca) {
		ans = ab * bc;
	} else if (ab*ab+ca*ca==bc*bc) {
		ans = ab * ca;
	} else if (bc*bc+ca*ca==ab*ab) {
		ans = bc * ca;
	} else {
		puts("error");
		return 0;
	}
	if(ans % 2 != 0) {
		puts("not integer");
	} else {
		printf("%d\n", ans / 2);
	}
	return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
        bool list[100001];
        for(int i = 2; i*i <= 100000; i++){
                for(int j = 2; !list[i] && i*j <= 100000; j++){
                        list[i*j] = true;
                }   
        }   
        int n;
        while(cin >> n){ 
                int min = n;
                while(list[--min]);
                int max = n;
                while(list[++max]);
                cout << min << " " << max << endl;
        }   
}

Measured memory_bytes: 0
H, W = map(int, input().split())

S = [[] for _ in range(H)]
for i in range(H):
    S[i] = input()

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "." and i - 1 < 0:
            D[i][j] = 1
        elif S[i][j] == "." and i - 1 >= 0:
            D[i][j] = D[i-1][j] + 1
        if S[i][j] == "." and j - 1 < 0:
            L[i][j] = 1
        elif S[i][j] == "." and j - 1 >= 0:
            L[i][j] = L[i][j-1] + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        if S[i][j] == "." and i + 1 >= H:
            U[i][j] = 1
        elif S[i][j] == "." and i + 1 < H:
            U[i][j] = U[i+1][j] + 1
        if S[i][j] == "." and j + 1 >= W:
            R[i][j] = 1
        elif S[i][j] == "." and j + 1 < W:
            R[i][j] = R[i][j+1] + 1

ans = 0

for i in range(H):
    for j in range(W):
        ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)

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

int main(){
    int n, b, f, r, v;
    int buildings[4][3][10];

    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                buildings[i][j][k] = 0;
            }
        }
    }

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

    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                cout << " " << buildings[i][j][k];
            }
            cout << endl;
        }
        if(i!=3){
            cout << "####################" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;
int main(){
	string s;
	std::cin >> s;
	std::vector<int> pos,pos1;
	
	int le=s.size();
	rep(i,le-1){
		if(s[i]=='R'&&s[i+1]=='L')pos.push_back(i);
		if(s[i]=='L'&&s[i+1]=='R')pos1.push_back(i);
		
	}
	pos1.push_back(le-1);
	std::vector<int> to(le,0);
	int j=0;
	for (int i = 0; i < le; i++) {
		/* code */
		
		if(pos1[j]<i)j++;
		if(abs(i-pos[j])%2==0)to[pos[j]]++;
		else to[pos[j]+1]++;
	}
	rep(i,le)std::cout << to[i] << ' ';
	std::cout << std::endl;
}

Measured memory_bytes: 1532
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "MyDisjointset.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
typedef pair<int, int> P; typedef long long int ll;
const int INF = 10000000;
int n, e;
int d[15][15], dp[1 << 15][15];
int rec(int s, int v) {
	if (s == (1 << n) - 1 && v == 0) return dp[s][v] = 0;
	else if (dp[s][v] != -1) return dp[s][v];
	else {
		int res = INF;
		for (int i = 0; i < n; i++) {
			if (!(s >> i & 1)) res = min(res, d[v][i] + rec(s | 1 << i, i));
		}
		return dp[s][v] = res;
	}
}
int main() {
	cin >> n >> e;
	fill(d[0], d[15], INF);
	fill(dp[0], dp[1 << 15], -1);
	for (int i = 0; i < e; i++) {
		int s, t, dis; cin >> s >> t >> dis;
		d[s][t] = dis;
	}
	if (rec(0, 0) >= 10000000) cout << -1 << endl;
	else cout << rec(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 5012
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define mod 1000000007
ll power(ll x,ll a)
{
	if(a==0)
	{
		return 1;
	}
	return x*(x,a-1);
}
ll factorial(ll a)
{
	if(a==1)return 1;
	return a*factorial(a-1);
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,r;
    cin>>s>>r;
    int m,n;
    m=s.size();
    n=r.size();
    string p="";
    int i,j;
    int dp[m+1][n+1];
    for(i=0;i<=m;i++)
    {
        for(j=0;j<=n;j++)
        {
            if(i==0||j==0)
            {
                dp[i][j]=0;
            }
            else
            {
                if(s[i-1]==r[j-1])
                {
                    dp[i][j]=dp[i-1][j-1]+1;
                    //p+=s[i-1];
                    //cout<<"i="<<i<<" j="<<j<<" p="<<p<<endl;
                }
                else
                {
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
    }
    i=m;j=n;
    while(i>0&&j>0)
    {
        if(s[i-1]==r[j-1])
        {
            p=s[i-1]+p;
            i--;
            j--;
        }
        else if(dp[i][j-1]>dp[i-1][j])
        {
            j--;
        }
        else
        {
            i--;
        }
        
    }
    cout<<p<<endl;
    return 0;
}

Measured memory_bytes: 35456
import math
A, B, H, M = map(int, input().split())

minute = H*60+M
h_n = (6*minute)%360
m_n = (0.5*minute)%360


if h_n > m_n:
    r = h_n - m_n
    Cos = math.cos(math.radians(r))
    a = math.sqrt(A**2 + B**2 - 2*A*B*Cos)
else:
    r = m_n - h_n
    Cos = math.cos(math.radians(r))
    a = math.sqrt(A**2 + B**2 - 2*A*B*Cos)

print(a)

Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repbtw(i, a, b) for (int i = a; i <= (int)(b); i++)
#define all(v) v.begin(), v.end()
#define pr(x) cout << x << endl


int main()
{
    int n, m;
    cin >> n >> m;
    
    vector<int> h(n);
    rep(i, n) cin >> h.at(i);

    vector<bool> good(n, true);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        if(h.at(a-1) == h.at(b-1)){
            good.at(a-1) = false;
            good.at(b-1) = false;
        }else if(h.at(a-1) > h.at(b-1)){
            good.at(b-1) = false;
        }else{
            good.at(a-1) = false;
        }
    }

    int cnt = 0;
    rep(i, n){
        if(good.at(i)) cnt++;
    }

    pr(cnt);
    return 0;
}



Measured memory_bytes: 3784
s = str(input())
l = len(s)
ans = 0
x = 2**(l-1)
dg = [[] for i in range(x)]
for i in range(x):
    b = 0#各桁の値
    d = 0#一つの値にするやつ
    tmp = 0 #数式計算用

    for j in range(l):
        b = int(s[j])
        d = d*10 +b
        if i>>j&1 :
            tmp += d
            dg[i].append(d)
            d = 0
    tmp += d
    ans += tmp
    dg[i].append(d)
# for i in range(x):
#     print(dg[i])
print(ans)



Measured memory_bytes: 3064
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;


int main() {
	stack<char> st;
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt_front, cnt_back;
	cnt_front = cnt_back = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '(') {
			st.push(s[i]);
		}
		else {
			if (st.empty()) {
				cnt_front++;
			}
			else {
				st.pop();
			}
		}
	}
	while (!st.empty()) {
		st.pop();
		cnt_back++;
	}
	REP(i, 1, cnt_front) {
		cout << '(';
	}
	cout << s;
	REP(i, 1, cnt_back) {
		cout << ')';
	}
	cout << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
def warshal_floyd(d, n):
  for k in range(n):
    for i in range(n):
      for j in range(n):
        d[i][j] = min(d[i][j], d[i][k]+d[k][j])
        
  return d

h, w = map(int, input().split())
m = [str(input()) for _ in range(h)]
d = [[float('inf') for i in range(h*w)] for j in range(h*w)]
for i in range(h*w):
  d[i][i] = 0
  
for i in range(h*w):
  for j in range(h*w):
    py, px = i//w, i%w
    qy, qx = j//w, j%w
    if (px == qx and abs(py-qy) == 1) or (py == qy and abs(px-qx) == 1):
      pm = m[py][px]
      qm = m[qy][qx]
      if qm in ['.'] and pm in ['.']:
        d[i][j] = 1
        
#print(d)
d = warshal_floyd(d, h*w)
#print(d)

ans = 0
for i in range(h*w):
  for j in range(h*w):
    if d[i][j] != float('inf'):
      ans = max(ans, d[i][j])
print(ans)

Measured memory_bytes: 137436
n, m, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

a_i = [0]
b_i = [0]

a_cnt = 0
a.size.times do |i|
  a_i << a_cnt + a[i]
  a_cnt += a[i]
end

b_cnt = 0
b.size.times do |i|
  b_i << b_cnt + b[i]
  b_cnt += b[i]
end

i = 0
j = b.size
max = 0

while i < a_i.size && j >= 0
  if a_i[i] + b_i[j] <= k
    max = i + j if max < i + j
    i += 1
  else
    j -= 1
  end
end

p max

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll X; cin >> X;
    ll ans;
    if (400 <= X && X <= 599){ans = 8;}
    else if (600 <= X && X <= 799){ans = 7;}
    else if (800 <= X && X <= 999){ans = 6;}
    else if (1000 <= X && X <= 1199){ans = 5;}
    else if (1200 <= X && X <= 1399){ans = 4;}
    else if (1400 <= X && X <= 1599){ans = 3;}
    else if (1600 <= X && X <= 1799){ans = 2;}
    else if (1800 <= X && X <= 1999){ans = 1;}
    cout << ans << endl;
}

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


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

signed main(){
   int N,M; cin>>N>>M;
   int sum=0;
   for(int i=0;i<M;i++){
       int a; cin>>a;
       sum+=a;
   }
   cout<<(N>=sum ? N-sum : -1)<<endl;
}

Measured memory_bytes: 3644
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int indx = 0 ;
	int x = 0 , N ;
	scanf("%d \n",&N);
	char s[100];
	scanf("%s",s);
	for(int j = 0 ; j<=N ; j++)
	{
		if(s[j]=='I')
		x++;
		else if(s[j]=='D')
		x--;
		if(x>indx)
		indx = x ;	
	}
	cout<<indx;
}

Measured memory_bytes: 256