akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
 
template<class T> T gcd(T a, T b) {
    return b ? gcd(b, a%b) : a;
}

template<class T> T lcm(T a, T b) {
    return a*b / gcd(a, b);
}
 
int main(int argc, char** argv) {
    unsigned long long a, b;
    while(cin >> a >> b) {
        cout << gcd(a, b) << " " << lcm(a, b) << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
using System;

namespace ALDS1_5_B
{
    class Program
    {
        static long cnt = 0;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] S = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            // rightの初期値は配列の要素数
            MergeSort(S, 0, n);

            Console.WriteLine(cnt);
        }

        static void Merge(int[] A, int left, int mid, int right)
        {
            int n1 = mid - left;
            int n2 = right - mid;
            // 左右それぞれ一つ多く要素を作る
            int[] L = new int[n1 + 1];
            int[] R = new int[n2 + 1];
            // もとの配列を左右に分ける
            for (int i = 0; i < n1; i++)
            {
                L[i] = A[left + i];
            }
            for (int i = 0; i < n2; i++)
            {
                R[i] = A[mid + i];
            }

            // 無限みたいな
            L[n1] = int.MaxValue;
            R[n2] = int.MaxValue;

            int m = 0, j = 0;
            for (int k = left; k < right; k++)
            {
                if (L[m] <= R[j])
                {
                    A[k] = L[m];
                    m++;

                    cnt += j;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }


        static void MergeSort(int[] A, int left, int right)
        {
            if (left + 1 < right)
            {
                int mid = (left + right) / 2;
                MergeSort(A, left, mid);
                MergeSort(A, mid, right);
                Merge(A, left, mid, right);
            }
        }

    }
}



Measured memory_bytes: 36112
N = int(input())
A = list(map(int, input().split(' ')))
A = [0] + A + [0]

sum = 0
for i in range(N+1):
    sum += abs(A[i+1] - A[i])

for i in range(1, N+1):
    s = A[i] - A[i-1]
    t = A[i+1] - A[i]
    if s * t < 0:
        print(sum - 2 * min(abs(s), abs(t)))
    else:
        print(sum)

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

using namespace std;

using int64 = long long;

struct Item {
  int64 x, y, z;
};

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}
template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

constexpr int DEBUG = 0;

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

  int x_num, y_num, z_num;
  cin >> x_num >> y_num >> z_num;
  int n = x_num + y_num + z_num;
  vector<Item> items;
  for (int i = 0; i < n; i++) {
    int64 x, y, z;
    cin >> x >> y >> z;
    items.push_back(Item({x, y, z}));
  }
  sort(items.begin(), items.end(), [](Item item1, Item item2) {
    return (item1.x - item1.y) > (item2.x - item2.y);
  });
  
  if (DEBUG) {
    cout << "items:" << endl;
    for (auto item : items) {
      cout << item.x << " " << item.y << " " << item.z << endl;
    }
  }

  int64 sum1 = 0;
  priority_queue<int64> pq1;
  for (int i = 0; i < x_num; i++) {
    sum1 += items[i].x;
    pq1.push(items[i].z - items[i].x);
  }
  vector<int64> dp1(z_num + 1);
  dp1[0] = sum1;
  for (int i = x_num; i < x_num + z_num; i++) {
    sum1 += items[i].x;
    pq1.push(items[i].z - items[i].x);
    sum1 += pq1.top();
    pq1.pop();
    dp1[i - x_num + 1] = sum1;
  }

  int64 sum2 = 0;
  priority_queue<int64> pq2;
  for (int i = n - 1; i >= x_num + z_num; i--) {
    sum2 += items[i].y;
    pq2.push(items[i].z - items[i].y);
  }
  vector<int64> dp2(z_num + 1);
  dp2[0] = sum2;
  for (int i = x_num + z_num - 1; i >= x_num; i--) {
    sum2 += items[i].y;
    pq2.push(items[i].z - items[i].y);
    sum2 += pq2.top();
    pq2.pop();
    dp2[x_num + z_num - i] = sum2;
  }

  if (DEBUG) {
    for(int i = 0; i <= z_num; i++) {
      cout << "dp1[" << i << "]: " << dp1[i] << endl;
    }
    for(int i = 0; i <= z_num; i++) {
      cout << "dp2[" << i << "]: " << dp2[i] << endl;
    }
  }

  int64 ans = 0;
  for (int i = 0; i <= z_num; i++) {
    UpdateMax(ans, dp1[i] + dp2[z_num - i]);
  }
  cout << ans << endl;
}

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

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())


def calc(m, n):
    return True if n - m > k else False


set_list = [(a, b), (a, c), (a, d), (a, e), (b, c),
            (b, d), (b, e), (c, d), (c, e), (d, e)]

ans = 'Yay!'
for i in range(len(set_list)):
    m, n = set_list[i]
    if calc(m, n):
        ans = ':('
        break

print(ans)

Measured memory_bytes: 3064
import sys
NOT_ASSIGNED = -1

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

arr = [NOT_ASSIGNED for _ in range(N)]

for m in range(M):
    s, c = map(int, input().split())
    # 左からs桁目は配列のN-sに入る
    if arr[N-s] != NOT_ASSIGNED and arr[N-s] != c:
        print(-1)
        sys.exit()
    if N > 1 and s == 1 and c == 0:
        print(-1)
        sys.exit()
    arr[N-s] = c

for n in range(N):
    if arr[n] == NOT_ASSIGNED:
        arr[n] = 0

if arr[N-1] == 0 and N > 1:
    arr[N-1] = 1

ans = 0
for n in range(N):
    ans += arr[n] * pow(10, n)

print(ans)

Measured memory_bytes: 3064
while True:
    n = int(input())

    if(n == 0): break
    
    s = [int(x) for x in input().split(" ")]
    
    m = sum(s)/n
    
    d = 0
    for i in range(n):
        d +=(s[i] - m)**2

    S = d/n
    a = S**0.5
    
    print("{:.9}".format(a))


Measured memory_bytes: 5684
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define th third
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()
#define elif else if


int mod=1000000007;

signed main(){
  int n,m;
  cin>>n>>m;

  V<int> hakai(n+1,1);
  fo(i,m){
    int a;
    cin>>a;
    hakai[a]=0;
  }

  V<int> dp(n+1,0);
  dp[0]=1;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<min<int>(n+1,i+3); j++){
      if(hakai[j]){
        dp[j]+=dp[i];
        dp[j]%=mod;
      }

    }
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>

int main(void){
    
    char s[100001];
    scanf("%s",s);
    int l=strlen(s);
    int a[l];
    int c1 = 0, c2 = 0;

    int i;

    for(i = 0; i < l;i++){
        if(i%2==0){
            if(s[i]=='0')   c1++;
        }
        else{
            if(s[i]=='1')   c1++;
        }
    }

    for(i = 0; i < l;i++){
        if(i%2==0){
            if(s[i]=='1')   c2++;
        }
        else{
            if(s[i]=='0')   c2++;
        }
    }

    int ans=0;
    if(c1 <= c2){
        ans = c1;
    }
    else{
        ans = c2;
    }

    printf("%d",ans);

    return 0;

}

Measured memory_bytes: 256
N,C=map(int,input().split())

old=[[] for i in range(C)]

for i in range(N):
    s,t,c=map(int,input().split())
    old[c-1].append((s,t))
ch=[]
for li in old:
    li.sort()
    j=0
    while(j<len(li)):
        start=li[j][0]
        while(j<len(li)-1 and li[j][1]==li[j+1][0]):
            j+=1
        end=li[j][1]
        ch.append((((start-1)*2)+1,end*2))
        j+=1
    
        
imos=[0]*(2*10**5+10)
for s,t in ch:
    imos[s]+=1
    imos[t]-=1
for i in range(1,2*10**5+10):
    imos[i]=imos[i-1]+imos[i]
print(max(imos))

Measured memory_bytes: 32048
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		Arrays.sort(r);
		Arrays.sort(l);
		
		int min = l[m - 1];
		int max = r[0];
		int count = 0;

		for (int i = 1; i <= n; i++) {
			if (min <=i && i <= max) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 85448
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    string n;
    cin >> n;
    Yes((n[0]==n[1]&&n[1]==n[2])||(n[1]==n[2]&&n[2]==n[3]));
}

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

using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N);
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  vector<long long> dp((N + 1) * (W + 1));
  const int col = W + 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      if (j - w[i] >= 0) {
        dp[col * (i + 1) + j] =
            max(dp[col * (i + 1) + j], dp[col * i + j - w[i]] + v[i]);
      }
      dp[col * (i + 1) + j] = max(dp[col * (i + 1) + j], dp[col * i + j]);
    }
  }
  cout << dp[col * N + W] << endl;
  return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <vector>

using namespace std;

class NODE {
public:
	int id, p=-1, h=0, k;
	vector<int> c;
	NODE(int n) {
		this->id = n;
	}
};

int main() {
	int n, id, k, c;
	vector<NODE> U;
	cin >> n;
	for (int i = 0; i < n; i++) {
		NODE u(i);
		U.push_back(u);
	}

	for (int i = 0; i < n; i++) {
		cin >> id >> k;
		U[id].k = k;
		for (int j = 0; j < k; j++) {
			cin >> c;
			U[id].c.push_back(c);
			U[U[id].c[j]].p = id;
		}
	}

	for (int i = 0; i < n; i++) {
		int a = i;
		while (U[a].p != -1) {
			U[i].h++; a = U[a].p;
		}

		cout << "node " << U[i].id << ": parent = " << U[i].p << ", depth = " << U[i].h << ", ";

		if (U[i].p == -1) cout << "root, [";
		else if (U[i].k == 0) cout << "leaf, [";
		else cout << "internal node, [";

		for (int j = 0; j < U[i].k; j++) {
			cout << U[i].c[j];
			if (j != U[i].k - 1) cout << ", ";
		}
		cout << "]" << endl;
	}

	return 0;
}


Measured memory_bytes: 8004
# https://atcoder.jp/contests/abc057/tasks/abc057_b



N, M = gets.split.map(&:to_i)
as = Array.new(N)
bs = Array.new(N)
N.times do |i|
  as[i], bs[i] = gets.split.map(&:to_i)
end
cs = Array.new(M)
ds = Array.new(M)
M.times do |i|
  cs[i], ds[i] = gets.split.map(&:to_i)
end

ans = []

N.times do |i|
  d = 4 * (10 ** 8)
  checkpoint = 0
  M.times do |j|
    temp = (as[i] - cs[j]).abs + (bs[i] - ds[j]).abs
    if temp < d
      d = temp
      checkpoint = j + 1
    end
  end
  ans << checkpoint
end
puts ans


Measured memory_bytes: 3836
package main

import (
		"fmt"
)

func main() {
		var n int
		var s, t string
		fmt.Scan(&n, &s, &t)

		var r string

		for i := 0; i < n; i++ {
				r += string(s[i])
				r += string(t[i])
		}

		fmt.Println(r)
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題165

            ulong X = ulong.Parse(Console.ReadLine());

            int ans = 0;
            ulong kane = 100;
            while (kane < X)
            {
                //float y = (float)X;
                //y *= 1.01f;

                //X = (int)y;

                kane = kane + kane / 100;

                //Console.WriteLine(X);

                ans++;
            }

            Console.WriteLine(ans);


        }


    }
}


Measured memory_bytes: 27584
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <iostream>
#define SIZE 100005
#define INF 100000000000000000LL

using namespace std;
int main()
{

	int n;
	cin >> n;
	cout << n / 3 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>
#include<atcoder/all>

using ll=long long;

ll op(ll a, ll b) {
	return std::max(a, b);
}

ll e() {
	return -1;
}

ll target;

bool f(ll v) { return v < target; }

using namespace std;
int main()
{
	ll N, Q;
	cin >> N >> Q;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	atcoder::segtree<ll, op, e> st(A);

	for (int i = 0; i < Q; i++) {
		ll T;
		cin >> T;
		if (T == 2) {
			ll L, R;
			cin >> L >> R;
			L--;
			cout << st.prod(L, R) << endl;
		}
		else {
			ll X, V;
			cin >> X >> V;
			X--;
			if (T == 1) {
				st.set(X, V);
			}
			else {
				target = V;
				cout << st.max_right <f>(X)+1 << endl;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
long long int mod= 1000000007,modd=998244353;
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);  cout.tie(0);
   lli n,i,ans=0;
   cin>>n;
   for(i=1;i<=n-1;i++)
    ans+=(n-1)/i;
   cout<<ans<<"\n";
   return 0;
}//main


Measured memory_bytes: 3652
#include <iostream>
#include <cstring>

using namespace std;

#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,a) loop(i,0,a)

int rx[4],ry[4];
bool v[4][4];

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

int f(){
    int xx=-1,yy=-1;
    rep(i,16){
        int tx=i&3;
        int ty=i>>2;
        if(!v[ty][tx]){
            xx=tx,yy=ty;
            break;
        }
    }
    if(xx<0) return 1;

    v[yy][xx]=1;
    int ans=0;
    for(int i=0;i<4;i++){
        int nx=xx+rx[i],ny=yy+ry[i];
        if(in(nx,ny)&&!v[ny][nx]){
            v[ny][nx]=1;
            ans+=f();
            v[ny][nx]=0;
        }
    }
    v[yy][xx]=0;
    return ans;
}

int main(void){
    while(1){
        cin>>rx[0];
        if(rx[0]>=5) return 0;
        cin>>ry[0];
        loop(i,1,4) cin>>rx[i]>>ry[i];
        memset(v,0,sizeof(v));
        cout<<f()<<endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int x[30];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int l;
	cin>>l;
	int m=l;
	int cnt=0;
	int cnt2=0;
	while(m){
		if(m&1){
			x[cnt]=1;
			++cnt2;
		}
		++cnt;
		m>>=1;
	}
	cout<<20<<' '<<19+cnt-1+cnt2-1<<'\n';
	REP(i, 19){
		cout<<i+1<<' '<<i+2<<' '<<0<<'\n';
	}
	REP(i, cnt-1){
		cout<<i+1<<' '<<i+2<<' '<<(1<<i)<<'\n';
	}
	FORR(i, 0, cnt-1){
		if(x[i]){
			l-=(1<<i);
			cout<<i+1<<' '<<20<<' '<<l<<'\n';
		}
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	const int MaxAB = 10, Inf = 1000000;
	
	var tmp = ReadIntArray();
	int n = tmp[0], ma = tmp[1], mb = tmp[2];
	int[] a = new int[n];
	int[] b = new int[n];
	int[] c = new int[n];
	for (int i = 0; i < n; i++)
	{
	    tmp = ReadIntArray();
	    a[i] = tmp[0];
	    b[i] = tmp[1];
	    c[i] = tmp[2];
	}

	int[,,] dp = new int[n+1, n*MaxAB+1, n*MaxAB+1];
	for (int i = 0; i <= n; i++)
	    for (int j = 0; j <= n*MaxAB; j++)
		for (int k = 0; k <= n*MaxAB; k++)
		    dp[i,j,k] = Inf;

	dp[0,0,0] = 0;

	for (int i = 0; i < n; i++)
	{
	    for (int ca = 0; ca <= n*MaxAB; ca++)
	    {
		for (int cb = 0; cb <= n*MaxAB; cb++)
		{
		    if (dp[i,ca,cb] == Inf) continue;
		    dp[i+1,ca,cb] = Math.Min(dp[i+1,ca,cb], dp[i,ca,cb]);
		    dp[i+1,ca+a[i],cb+b[i]] =
			Math.Min(dp[i+1,ca+a[i],cb+b[i]], dp[i,ca,cb]+c[i]);
		}
	    }
	}

	int ans = Inf;
	for (int ca = 1; ca <= n*MaxAB; ca++)
	{
	    for (int cb = 1; cb <= n*MaxAB; cb++)
	    {
		if (ca*mb == cb*ma)
		{
		    ans = Math.Min(ans, dp[n,ca,cb]);
		}
	    }
	}

	if (ans == Inf) ans = -1;
	WriteLine(ans);
    }
}


Measured memory_bytes: 36832
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

ll dp[111][111][2];
int a[111];

ll powmod(ll n,ll k){
    ll ret=1;
    while(k>0){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

ll rec(int l,int r,int h,int flag){
    if(dp[l][r][flag]!=-1)return dp[l][r][flag];
    if(l+1==r){
        if(flag)return dp[l][r][flag]=powmod(2,a[l]-h);
        else return dp[l][r][flag]=0;
    }
    int mi=inf,ma=0;
    REP(i,l,r){
        mi=min(mi,a[i]);
        ma=max(ma,a[i]);
    }
    ll ret1=1;
    ll pos=l-1;
    REP(i,l,r){
        if(a[i]==mi){
            if(i-pos>1)ret1*=rec(pos+1,i,mi,1);
            ret1%=mod;
            pos=i;
        }
    }
    if(r-pos>1)ret1=ret1*rec(pos+1,r,mi,1)%mod;
    ret1=ret1;
    if(flag) return dp[l][r][flag]=ret1*powmod(2,mi-h)%mod;
    ll ret2=1;
    pos=l-1;
    REP(i,l,r){
        if(a[i]==mi){
            ret2=2*ret2%mod;
            if(i-pos>1)ret2*=(2*rec(pos+1,i,mi,1)+rec(pos+1,i,mi,0));
            ret2%=mod;
            pos=i;
        }
    }
    if(r-pos>1)ret2=ret2*(2*rec(pos+1,r,mi,1)+rec(pos+1,r,mi,0))%mod;
    ret2=(ret2-ret1*2+2*mod)%mod;
    return dp[l][r][flag]=ret2;
}
int main(){
   int n;
   cin>>n;
   rep(i,n)cin>>a[i];
   rep(i,n+1)rep(j,n+1)rep(k,2)dp[i][j][k]=-1;
   ll ans=rec(0,n,0,0)+rec(0,n,0,1);
   cout<<ans%mod<<endl;
   return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "Yes";
            for (int i = 0; i < sS.Length; i += 2) { if (sS.Substring(i, 1) == "L") { sOut = "No"; break; } }
            for (int i = 1; i < sS.Length; i += 2) { if (sS.Substring(i, 1) == "R") { sOut = "No"; break; } }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <stdio.h>

int d[15][15];
int N;
int ans;
int route[10];
int used[10];

void dfs(int depth,int pos){

	int i;

	if(depth==N){

		int flag=0;

		if(route[0]!=1){flag=1;}

		for(i=0;i<N-1;i++){
			if(flag==1){break;}
			if(d[route[i]][route[i+1]]==0){
				flag=1;
			}
		}
		if(flag==0){
			ans++;
		}
		return;
	}

	for(i=1;i<=N;i++){
		if(used[i]==0){
			used[i]=1;
			route[depth]=i;
			dfs(depth+1,i);
			used[i]=0;
		}
	}

}

int main(){


	int M;

	scanf("%d %d",&N,&M);

	int i;

	for(i=0;i<M;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		d[a][b]=1;
		d[b][a]=1;
	}

	dfs(0,1);

	printf("%d\n",ans);

	return 0;
}

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

int main() {
    int n, u, k, v;
    cin >> n;

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

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j != 0) cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
}



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

int main()
{
	int debt = 100000 ;
	int get ;

	cin >> get ;

	for( int i = 0 ; i < get ; i ++ )
	{
		debt *= 1.05 ;
		if( debt % 1000 != 0 )
		{
			debt = debt + 1000 - (debt%1000) ;
		}
	}

	cout << debt << endl ;
	return 0 ;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++){
        cin >> L.at(i);
    }
    sort(L.begin(), L.end());
    int cnt = 0;
    for(int i = 0; i < N - 2; i++){
        for(int j = i + 1; j < N - 1; j++){
            for(int k = j + 1; k < N; k++){
                if(!(L.at(i) == L.at(j) || L.at(j) == L.at(k) || L.at(i) == L.at(k)) && (L.at(i) + L.at(j) > L.at(k))){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3640
using System;

class Atcoder55
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);

        if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
            Console.WriteLine("Possible");
        else
            Console.WriteLine("Impossible");
    }
}

Measured memory_bytes: 11092
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from heapq import heapify, heappop, heappush
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations)

MAX_INT = 2**62-1
sys.setrecursionlimit(10**7)

input = sys.stdin.readline


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


def main():
    s = input().strip()
    q = int(input())
    queue = deque(s)
    is_reversed = 0

    for _ in range(q):
        t, *x = input().strip().split()
        # print(t, x, queue)
        if t == '1':
            is_reversed ^= 1
        else:
            where, c = x
            where = int(where) & 1
            if where ^ is_reversed:
                queue.appendleft(c)
            else:
                queue.append(c)
    if is_reversed:
        queue.reverse()

    print(''.join(queue))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9204
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n = int(sys.stdin.readline().rstrip())
    l = [None] * (n + 1); l[0], l[1] = 2, 1
    for i in range(1, n):
        l[i+1] = l[i] + l[i-1]
    print(l[n])

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include <stdio.h>
int main (){
int i,j,k=0,l,p=0;
scanf ("%d%d",&p,&l);
char s[1000][1000],t[1000][1000];
for (i=0;i<p;i++){
 scanf ("%s",s[i]);
}
for (i=0;i<p;i++){
  for (j=0;j<l;j++){
  if (s[i][j]=='.'){
  if (s[i-1][j-1]=='#'){k++;}
  if (s[i][j-1]=='#'){k++;}
  if (s[i+1][j-1]=='#'){k++;}
  if (s[i-1][j]=='#'){k++;}
  if (s[i+1][j]=='#'){k++;}
  if (s[i-1][j+1]=='#'){k++;}
  if (s[i][j+1]=='#'){k++;}
  if (s[i+1][j+1]=='#'){k++;}
  s[i][j]=k;
  k=0;
  printf ("%d",s[i][j]);
 }
 else
 {
 	printf ("#");
 }
  }
  printf ("\n");
}
return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i

rn = Math.sqrt(n).to_i + 1
arr = []
arr2 = []
(1..rn).each { |num|
    arr << num if n % num == 0
}

arr.each { |num|
    arr2 << n / num
}

m = arr.zip(arr2).map { |a1, a2|
    (a1 - 1) + (a2 - 1)
}.min

puts m

Measured memory_bytes: 14276
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int N;
    cin >> N;
    for(int i = 1; i < 10; i++){
        if(N <= 111*i){
            cout << 111*i << endl;
            break;
        }
    }
    return 0;
}


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define ll long long
#define oo INT_MAX

const int N = 20;
const int MASK = (1 << 16) + 5;
ll n , res;
ll b[N] , f[MASK];
ll a[N][N];
ll dp[N][MASK];
vector < int > g[N];

/// dp[i][mask] là số điểm cao nhất đạt được khi xài i cái lòng và cái các cái lòng từ 1 -> i có giá trị là mask
/// vì để tránh tình trạng lập lại vs cái lồng thứ i ta chỉ xét trạng thái mask mà i * (số bit 1 của mask) <= n.

int main()
{
    //freopen("U.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    REP(i , n)
        REP(j , n)
            cin >> a[i][j];
    REP(j , (1 << n))
    {
        int r = 0;
        REP(x , n)
            if((j >> x) & 1 == 1)
                b[++r] = x;
        g[r].pb(j);
        FOR(x , 1 , r)
            FOR(y , x + 1 , r)
                f[j] += a[b[x]][b[y]];
        dp[0][j] = f[j];
    }


    FOR(i , 1 , n - 1)
    {
        REP(j , (1 << n))
            dp[i][j] = dp[i - 1][j];
        REP(k , (n / (i + 1)))
        {
            REP(s , g[k + 1].size())
            {
                int x = g[k + 1][s];
                FOR(j , n - (n / (i + 1))  , n - 1)
                    REP(s1 , g[j + 1].size())
                    {
                        int y = g[j + 1][s1];
                        if(((y | x) ^ x) + x == y)
                            dp[i][y] = max(dp[i][y] , dp[i - 1][(y | x) ^ x] + f[x]);
                    }
            }
        }
    }
    REP(i , n)
        res = max(res , dp[i][(1 << n) - 1]);
    cout << res;
}


Measured memory_bytes: 11520
#include<stdio.h>
int main(void)
{
	int a,b,x[1001],i,j,S;
	scanf("%d %d",&a,&b);
	for(i=0;i<a;i++){
		scanf("%d",&x[i]);
	}
	for(i=1;i<=b;i++){
		for(j=0;j<a-1;j++){
			if(x[j]%i>x[j+1]%i){
				S=x[j];
				x[j]=x[j+1];
				x[j+1]=S;
			}
		}
	}
	for(i=0;i<a;i++){
		printf("%d\n",x[i]);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t  i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

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

  ll n,t;
  std::cin>>n>>t;

  std::vector<P> a(n);
  rep(i,0,n)std::cin>>a[i].first>>a[i].second;

  std::sort(all(a),[](P a,P b){
    return (long double)a.first/(1+a.second)>(long double)b.first/(1+b.second);
  });

  rep(i,0,n){
    a[i].first++;
    a[i].second+=a[i].first;
  }

  std::vector<ll> dp(31,MOD);

  dp[0]=0;

  rep(i,0,n){
    if(a[i].first==1)break;

    for(ll j=30;j>0;j--){
      chmin(dp[j],a[i].first*dp[j-1]+a[i].second);
    }
  }

  std::sort(all(a),[](P a,P b){return a.second<b.second;});

  std::vector<ll> sum;
  sum.emplace_back(0);

  rep(i,0,n){
    if(a[i].first==1){
      ll val=sum.back();
      sum.emplace_back(val+a[i].second);
    }
  }

  sum.emplace_back(MOD);

  ll ans=0;

  rep(i,0,31){
    if(dp[i]<=t)chmax(ans,i+std::upper_bound(all(sum),t-dp[i])-sum.begin()-1);
  }

  std::cout<<ans<<"\n";

  return 0;
}



Measured memory_bytes: 5620
fun main(args: Array<String>) {
    abc103b()
}

fun abc103b() {
    val s = readLine()!!
    val t = readLine()!!

    val answer = (0..s.length).any {
        val rotated = s.takeLast(it) + s.take(s.length - it)
        rotated == t
    }.let { if (it) "Yes" else "No" }

    println(answer)
}


Measured memory_bytes: 33648
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(a) reverse((c).begin(),(c).end())

typedef long long ll;
const ll INF = 1LL<<30;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1]; for (int i = 0; i < n + 1; i++) { a[i] = 1; }for (int i = 2; i < n + 1; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

int dp[500][500];
int nxdp[500][500];

signed main() {
	int n,Ma,Mb;
	cin >> n >> Ma >> Mb;
	pair<int,pair<int,int>> C[n];
	REP (i,n) {
		cin >> C[i].S.F >> C[i].S.S >> C[i].F;
	}
	REP (i,500) {REP (j,500) {dp[i][j] = INF;nxdp[i][j] = INF;}}
	sort(C,C+n);
	dp[0][0] = 0;
	REP (i,n) {
		int x = C[i].S.F,y = C[i].S.S;
		int cost = C[i].F;
		REP (j,410) {
			REP (k,410) {
				nxdp[j+x][k+y] = min(dp[j+x][k+y],dp[j][k] + cost);
			}
		}
		REP (j,410) {
			REP (k,410) {
				dp[j][k] = min(dp[j][k],nxdp[j][k]);
				nxdp[j][k] = INF;
			}
		}
	}
	int ans = INF;
	FOR (i,1,410) {
		FOR (j,1,410) {
			if (i * Mb == j * Ma && dp[i][j] != INF) {ans = min(ans,dp[i][j]);}
		}
	}
	if (ans == INF) cout << -1 << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>

using namespace std;

void PrimeNumSum(int& sum, unsigned int& num){
    unsigned int divisor = sqrt(num)+1;
    
    if(divisor == 2){
        sum++;
        return;
    }
    while(divisor>=2){
        if(num%divisor == 0){
            return;
        }
        divisor--;
    }
    
    sum++;
    
}

int main()
{
	int count;
    cin>>count;
    
    unsigned int* list = new unsigned int[count];
    
    for(int i = 0;i<count;i++){
        cin>>list[i];
    }
    
    int sum = 0;
    
    for(int i =0;i<count;i++){
        PrimeNumSum(sum, list[i]);
    }
    
    cout<<sum<<endl;
    
    delete[] list;
	return 0;
}

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

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

  if(a%2 != b%2)  cout << "IMPOSSIBLE" << endl;
  else  cout << (a+b)/2 << endl;
}

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


int main() {

   int x, a, b;
   cin >> x >> a >> b;
   int da = abs(x-a);
   int db = abs(x-b);

   if (da <db)
    cout << "A";
   else
    cout << "B";


    return 0;
}


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

int n;
int arr[100005];

bool checkSame(int k) {
    int lo = 0, hi = n, mid;
    int best = -1;
    while(lo<=hi) {
        mid = (lo+hi)/2;
        if (arr[mid]>=k) {
            hi = mid - 1;
            best = mid;
        } else {
            lo = mid + 1;
        }
    }
    if (best==n/2) return true;
    else return false;
}

int main() {
    //freopen("input.txt", "r", stdin);
    cin>>n;
    for (int i=0;i<n;i++) cin>>arr[i];
    sort(arr, arr+n);

    int cnt = 0;
    for (int i=0;i<=100000;i++) 
        if (checkSame(i)) cnt++;

    cout<<cnt;
}

Measured memory_bytes: 640
#include <cstdio>

using namespace std;

int main() {
    int n, f = 0, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        int x;
        
        scanf("%d", &x);
        
        if (x % 2 == 1) f = 1;
    }
    
    if (f == 1) {
        puts("first");
    } else {
        puts("second");
    }
    
    return 0;
}


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

int main(){
    int N;
    cin>>N;
    int ans=0;
    int ans_num=0;
    for(int i=1;i<=N;i++){
        int cnt=0;
        int a=i;
        while(a!=1){
            a /= 2;
            cnt++;
        }
        if(cnt>ans){
            ans = cnt;
            ans_num = i;
        }
    }
    if(ans_num==0)ans_num++;
    cout<<ans_num<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    score = []
    for i in range(N):
        a, b = map(int, input().split())
        score.append((a + b, a, b))

    takahashi, aoki = 0, 0
    for i, (t, a, b) in enumerate(sorted(score, reverse=True)):
        if i % 2 == 0:
            takahashi += a
        else:
            aoki += b
    print(takahashi - aoki)


if __name__ == '__main__':
    main()


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

typedef long long ll;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll n[3];
  n[0] = a; n[1] = b; n[2] = c;
  sort(n, n+3);

  ll ans=0;
  if ((a & 1) == 1 && (b & 1) == 1 && (c & 1) == 1) {
    int tmp=n[2]/2;
    ans = (n[2]-tmp)*n[0]*n[1] - tmp*n[0]*n[1];
  }

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


Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000000ll
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    string s;
    cin>>s;
    int ans=0;
    if(s=="RSR"){
        cout<<1<<endl;
        return 0;
    }

    rep(i,3){
        if(s[i]=='R'){
            ans++;
        }
    }

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

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    int x,y;cin>>x>>y;

    ll ans=0;
    if(x==1&&y==1){
        cout<<(400000+300000*2)<<endl;
        return 0;
    }

    if(x==1) ans+=300000;
    if(x==2) ans+=200000;
    if(x==3) ans+=100000;
    if(y==1) ans+=300000;
    if(y==2) ans+=200000;
    if(y==3) ans+=100000;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;

    string res = "2018" + S.substr(4, 6);

    cout << res << endl;
    return 0;
}


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

int main() {

  int N=0, C0=0, C1=0, C2=0, C3=0;
  string S;

  cin >> N;

  for(int i=0; i<N; i++) {

    cin >> S;

    if(S=="AC") {
      C0++;
    }
    
    if(S=="WA") {
    C1++;
    }
    
    if(S=="TLE") {
    C2++;
    }

    
    if(S=="RE") {
      C3++;
    }
    
  }

  cout << "AC x " << C0 << endl;
  cout << "WA x " << C1 << endl;
  cout << "TLE x " << C2 << endl;
  cout << "RE x " << C3 << endl;
  
}

Measured memory_bytes: 3628
N = int(input())

def dfs(s): # 文字列 s で始まる七五三数の個数
	if int(s) > N:
		return 0
	ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
	for c in '753':
		ret += dfs(s + c)
	return ret

print(dfs('0')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく


Measured memory_bytes: 2940
N, Y = map(int, input().split(' '))
count = 0
for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j
        result = 10000 * i + 5000 * j + 1000 * k
        if result == Y:
            print(i, j, k)
            count += 1
            break
    if count != 0:
        break
else:
    print('-1 -1 -1')            
        

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int numberOfItems;
    int numberOfDiscountTickets;

    cin >> numberOfItems;
    cin >> numberOfDiscountTickets;

    vector<double> prices(numberOfItems);
    for (int i = 0; i < numberOfItems;++i){
        cin >> prices[i];
    }
    make_heap(prices.begin(), prices.end());
    for (int i = 0; i < numberOfDiscountTickets;++i){
 //       make_heap(prices.begin(), prices.end());
        pop_heap(prices.begin(),prices.end());
        double& d = prices.back();
        d /= 2.0;
        push_heap(prices.begin(), prices.end());
        //        prices[0] /= 2.0;
    }
    long s = accumulate(prices.begin(), prices.end(), 0L, [](long acc, double v) {
        return acc + static_cast<long>(v);
    });
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long x, y;
  cin >> x >> y;
 
  long long z=y/x;
  
  long long num=1;
  while(z/2!=0){
    num++;
    z = z/2;
  }
  
  cout << num << endl;
  
  
}


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

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

    int m = max({a,b,c});
    m *= (int)pow(2,k) - 1;

    cout << a + b + c + m << endl;
    return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    deque<char> dq;
    for(int i = 0; i < s.size(); ++i) {
        dq.push_back(s[i]);
    }

    int Q;
    cin >> Q;
    bool flg = true;
    while(Q--) {
        int t;
        cin >> t;
        if(t == 1) {
            if(flg) flg = false;
            else flg = true;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if(flg) {
                if(f == 1) dq.push_front(c);
                else dq.push_back(c);
            } else {
                if(f == 1) dq.push_back(c);
                else dq.push_front(c);
            }
        }
    }

    if(flg) {
        while(!dq.empty()) {
            cout << char(dq.front());
            dq.pop_front();
        }
    } else {
        while(!dq.empty()) {
            cout << char(dq.back());
            dq.pop_back();
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 976
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define N 20
#define M (1<<15)+10
#define lowbit(x) (x&(-x))
using namespace std;
int f[M][N],g[M][N],h[M],a[N][N],bit[M],n,m,tot,ans;
void upd(int &x,int y)
{
	if(y>x) x=y;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y,d;scanf("%d%d%d",&x,&y,&d);
		tot+=d;
		a[x][y]=a[y][x]=d;
	}
	for(int i=1;i<=n;i++) bit[1<<(i-1)]=i;
	memset(f,-1,sizeof(f));
	memset(g,-1,sizeof(g));
	int ss=1<<n;
	for(int i=1;i<ss;i++)
	{
		int j=bit[lowbit(i)];
		h[i]=h[i-lowbit(i)];
		for(int k=1;k<=n;k++) if(j!=k && (i&(1<<(k-1)))) h[i]+=a[j][k];
	}
	f[1][1]=0;
	for(int i=0;i<ss;i++)
		for(int j=1;j<=n;j++)
		{
			upd(g[i][j],f[i][j]);
			if(f[i][j]!=-1)
			{
				int t=ss-1-i;
				for(int k=t;k;k=(k-1)&t)
					upd(g[i+k][j],f[i][j]+h[k+(1<<(j-1))]);	
			}
			if(g[i][j]!=-1)
			{
				for(int k=1;k<=n;k++)
				{
					if((i&(1<<(k-1))) || a[j][k]==0) continue;
					upd(f[i+(1<<(k-1))][k],g[i][j]+a[j][k]);
				}
			}
		}
	ans=max(f[ss-1][n],g[ss-1][n]);
	printf("%d\n",tot-ans);
	return 0;
}

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

float A, B, C, D, E, F;
string S, Sa, Sb, Sc;
long long int V[100000];
long long int X[100000];
typedef pair<double,int> Pi;
Pi N[100000] = {};
int main() {
	cin >> A >> B;
cout << A / B << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
    int num;
    scanf("%d",&num);
    int x[num];
    int i,j;
    int count=0;
  int temp=0;
    for(i=0;i<num;i++){
        scanf("%d",&x[i]);
    }
   for(i=0;i<num;i++){
        for(j=i;j<num;j++){
            if(x[i]>x[j]){
                temp=x[i];
                x[i]=x[j];
                x[j]=temp;
            }
        }
    }
  
  for(i=0;i<num;i++){
    if(x[i]>x[i-1]) count++;
  }
printf("%d",count);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define sq(a) (a)*(a)
typedef long long int ll;
typedef long double llf;
int main()
{
    ll a;
    llf b,b2;
    cin>>a>>b;
    b2=round(b*100);
    cout<<((a*b2)/100) <<endl;
    return 0;





}


Measured memory_bytes: 3820
route :: [Int] -> [Int] -> Int -> Int -> Int
route a1 a2 x n = sum $ b1 ++ b2
    where b1 = take x a1
          b2 = take (n - x + 1) $ reverse a2

main = do
    n <- readLn :: IO Int
    a1 <- map read . words <$> getLine :: IO [Int]
    a2 <- map read . words <$> getLine :: IO [Int]
    print $ maximum [ route a1 a2 x n | x <- [1..n]]

Measured memory_bytes: 1020