akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

#define N 10

int h,w;
int a[200][200];
int c[N][N];
int copt[N];

void dijkstra(){
  int s; //始点
  int f[N]={0}; //訪問フラグ
  int tmp;

  for (int i=0; i<N; i++) copt[i] = 1000;
  s = 1;
  copt[s] = 0;

  for(int i=0; i<N; i++){
    f[s] = 1;

    for(int j=0; j<N; j++){
      if(c[j][s]<=0) continue;
      if(copt[j] > copt[s]+c[j][s]) copt[j] = copt[s]+c[j][s];
    }

    tmp = 1000;
    for(int j=0; j<N; j++){
      if(f[j] == 1) continue;
      if(copt[j] < tmp){
        tmp = copt[j];
        s = j;
      }
    }
  }
  return;
}


int main(){
  int total = 0;

  cin >> h >> w;

  for (int i=0; i<10; i++){
    for (int j=0; j<10; j++){
      cin >> c[i][j];
    }
  }

  for (int i=0; i<h; i++){
    for (int j=0; j<w; j++){
      cin >> a[i][j];
    }
  }

  dijkstra();

  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(a[i][j] == 1 || a[i][j] == -1) continue;
      total += copt[a[i][j]];
    }
  }

  cout << total << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
long long sq(long long x){
    return x*x;
}
int main()
{
    long long n,k,i,j,sum,m;
    cin>>n>>k;
    long long x[n];
    sum=0;
    for(i=0;i<n;i++){
        cin>>x[i];
        sum+=(2*min((long long)(sqrt(sq(x[i]))),(long long)(sqrt(sq(x[i]-k)))));
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
 
int main(){
int n,a,i,b;
std::cin>>n;
 for(i=0,a=100000;i<n;++i){
      a=a+a/20;
        if(a%1000!=0){
        b=a%1000;
        a=a+1000-b;
        }
          }
        std::cout<<a<<std::endl;
        return 0;
        }

Measured memory_bytes: 1160
X , N = map(int, input().split())
if N == 0:
    print(X)
else:
    P = sorted(map(int,input().split()))

    if P.count(X)== 0:
        print(X)
    else:
        hi = 0
        lo = 0
        i = 1
        j = 1
        while lo == 0:
            a = X-i
            if P.count(a)==0:
                lo += 1
            else:
                i += 1
                
            
        while hi == 0:
            a =X+j 
            if P.count(a)==0:
                hi += 1
            else:
                j += 1 
                
            
        if i > j:
            print(X+j)
        elif i<j:
            print(X-i)
        else:
            print(X-i)

Measured memory_bytes: 9220
#include <cstdio>
#include <algorithm>
using namespace std;
int n,a,maxi=0,mini=2e9;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		maxi=max(maxi,a);
		mini=min(mini,a);
	}
	printf("%d",maxi-mini);
	return 0;
}

Measured memory_bytes: 128
#include <queue>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=1e5+5;
int n,rt,du[N],del[N];
vector <int> G[N];
queue <int> q;
char str[N];

inline void addedge(int u=0,int v=0) {
	scanf("%d%d",&u,&v),G[u].push_back(v),G[v].push_back(u),du[u]++,du[v]++;
}
inline void topsort() {
	for(int i=1;i<=n;++i)
		if(str[i]=='B'&&du[i]==1) q.push(i);
	while(!q.empty()) {
		int u=q.front();q.pop(),del[u]=true;
		for(auto v:G[u]) {
			if(du[v]) --du[v];
			if(du[v]==1&&str[v]=='B'&&!del[v]) q.push(v);
		}
	}
}

int tot,sum,ans,dp[N];
inline bool val(int u) {return (str[u]=='W')^(du[u]&1);}
void dfs(int u,int fa) {
	++tot,sum+=val(u),dp[u]=val(u)*(-2);
	for(auto v:G[u]) if(v!=fa&&!del[v])
		dfs(v,u),ans=min(ans,dp[u]+dp[v]),dp[u]=min(dp[u],dp[v]+val(u)*(-2));
}

int main() {
	scanf("%d",&n);
	for(int i=2;i<=n;++i) addedge();
	scanf("%s",str+1);
	topsort();
	for(int i=1;i<=n;++i) if(!del[i]) rt=i;
	dfs(rt,0);
	printf("%d\n",(tot-1)*2+sum+ans);
	return 0;
}

Measured memory_bytes: 12544
#include<iostream> 
#include<cstdio>
#include<cstdlib>

using namespace std;

double a[100005];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int t;
		cin>>t;
		a[i]=(double)(1.0/t);
	}
	double sum=0.0;
	for(int i=1;i<=n;i++)
	{
		sum+=a[i];
	}
	cout<<(double)(1.0/sum);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = [str(sorted(str(input()))) for _ in range(n)]

d = {}

for i in range(n):
  s = l[i]
  # print(s)
  if s in d:
    d[s] += 1
  else:
    d[s] = 1

ans = 0
for x in d.values():
  ans += x*(x-1)/2
print(int(ans))




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

bool solve(int k, int a, int b){
	for (int i = a; i <=b; i++)
		if (i % k == 0)
			return true;
	return false;
}

int main(){
	int k, a, b;
	cin >> k;
	cin >> a >> b;
	cout << (solve(k,a,b) ? "OK" : "NG");
}


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

int main(){
    int A, B, C, K;
    int count = 0;

    cin >> A >> B >> C >> K;
    while (A >= B){
        B *= 2;
        count++;
    }
    while (B >= C){
        C *= 2;
        count++;
    }
    if(count <= K){
        cout << "Yes" << endl;
    }

    else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        200001
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--) 
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define MAXN		200001
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree1_order_statistics_node_update> 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s1;
	string s2;
	cin >> s1;
	cin >> s2;
	ll int ans=0;
	rep(i,0,3)
	{
		if (s1[i]==s2[i])ans++;
	}
	cout << ans << endl;
}

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

int main(){
  int n,F[50];
  cin >> n;
  F[0] = F[1] = 1;
  for(int i=2;i<=n;i++){
    F[i] = F[i-1] + F[i-2];
  }
  cout << F[n] << endl;

  return 0;
}



Measured memory_bytes: 3128
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var a=sc.Ia;
		for(int i = 0;i<a.Length;i++) {
			if(a[i]==0){
				Console.WriteLine("{0}",i+1);
				return;
			}
		}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27408
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int a, b; cin >> a >> b;
    rep(i, b){
        if(i*a-(i-1)>=b){
            out(i);
            break;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int n;
    cin >> n;
    vi v(n);
    rep(i,n){
        cin >> v[i];
    }
    sort(all(v));
    double ans = v[0];
    rep1(i,n){
        ans += v[i];
        ans /= 2;
    }
    printf("%.5f\n",ans);
    return 0;
}

Measured memory_bytes: 256
from sys import stdin


def is_kaibun(kaibun):
    # print(len(kaibun)/2)
    for i in range(len(kaibun)//2):
        # print(kaibun[i],kaibun[-1-i])
        if kaibun[i] != kaibun[-1-i]:
            return False
    return True


# N, A, B = [int(x) for x in stdin.readline().rstrip().split()]
# A,B = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip().split()[0]
# print(S)
s1 = S[0:(len(S)-1)//2]
s2 = S[(len(S)+1)//2:len(S)]
# print(s1)
# print(s2)
if is_kaibun(S) is True:
    if is_kaibun(s1) is True:
        if is_kaibun(s2) is True:
            print("Yes")
            exit(0)
print("No")

Measured memory_bytes: 3064
main :: IO ()
main = do
    str <- getLine
    print $ solve $ reverse str

solve :: String -> Int
solve "" = 0
solve (c:ss) | isOk ss = length ss
             | otherwise = solve ss
    where
        isOk s = let n = length s
                     (a,b) = splitAt (n`div`2) s
                  in even n && a == b

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 1;
  
  for (int i = 0; i < N; i++) {
    int a1 = ans * 2;
    int a2 = ans + K;
    if (a1 > a2) ans += K;
    else ans *= 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = int_fast64_t;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,y;
    cin >> n >> y;
    REP(i,0,n+1) REP(j,0,n+1-i) {
        int k = n - i - j;
        if (i * 10000 + j * 5000 + k * 1000 == y) {
            cout << i << " " << j << " " << k << endl;
            return;
        }
    }
    cout << "-1 -1 -1" << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define reset(N) memset(N,0,sizeof(N))
#define clear(N) while(N.size()>0) N.pop()
#define f(a,v,b) for(int a=v;a<b;a++)
#define cb(N) __builtin_popcount(N)
#define cbl(N) __builtin_popcountl(N)
#define cbll(N) __builtin_popcountll(N)
using namespace std;
int n,k;
int h[100001];
int dp[100001];
void solve(){
	cin>>n>>k;
	f(i,0,n){
		cin>>h[i];
	}
	f(i,1,n){
		int mi=2e9;
		for(int j=1;j<=k;j++){
			if(i-j<0) break;
			mi=min(dp[i-j]+abs(h[i]-h[i-j]),mi);
		}
		dp[i]=mi;
	}
	cout<<dp[n-1]<<'\n';
}
int main(){
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nk = Input.ar;
        var ar = Input.ar;
        var sum = new long[nk[0] + 1];
        for (var i = 1; i <= nk[0]; i++)
            sum[i] += sum[i - 1] + ar[i - 1];
        var list = new List<long>();
        for (var i = 1; i <= nk[0]; i++)
            for (var j = 1; j <= i; j++)
                list.Add(sum[i] - sum[j - 1]);
        var res = 0L;
        for(var i=40;i>0;i--)
        {
            var ct = 0;
            for(var j=0;j<list.Count;j++)
            {
                var calc = res + (1L << i - 1);
                if ((calc & list[j]) == calc)
                    ct++;
            }
            if (ct >= nk[1]) res += (1L << i - 1);
        }
        WriteLine(res);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 21088
n = int(input())
h = list(map(int, input().split()))

dp2 = 0
dp1 = abs(h[0] - h[1])
if n == 2:
    print(dp1)
else:
    dp0 = 0
    for i in range(2, n):
        dp0 = min(
        dp2 + abs(h[i] - h[i - 2]),
        dp1 + abs(h[i] - h[i - 1]))
        dp2, dp1 = dp1, dp0
    print(dp0)


Measured memory_bytes: 13928
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 31 14:30:45 2018

@author: Yamazaki Kenichi
"""

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

limit = int(pow(P,1/N)//1)

if N == 1:
    ans = P
elif limit == 1:
    ans = 1
else:
    ans = 1
    for i in range(2,limit+2):
        if P % pow(i,N) == 0:
            ans = i
            
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <list>
#include <queue>
#include <string.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std; 
typedef long long ll; 

vector< pair<ll,ll> > rg; 
void pop(int nbit,ll l,ll h){
    rg.push_back(make_pair(l,h)); 
    if(l<=-1000000000 && h>=1000000000) return; 
    ll num=((ll)1<<nbit);
    if(nbit%2==0)
        num*=-2;
    else 
        num*=2;
    if(num<0){
        pop(nbit+1,l+num,h);
    }
    else{
        pop(nbit+1,l,h+num);
    }
    
}

int main(){    
    ll n;
    cin>>n; 
    pop(0,0,1);
    int i=0;
    while(1){
        if(rg[i].first<=n && rg[i].second>=n) break;
        i++; 
    }
    for(i;i>=0;i--){
        if(n==0) { cout<<0; }
        else if(i==0) { cout<<1; }
        else{
            if(rg[i-1].first<=n && rg[i-1].second>=n){
                cout<<0; 
            }
            else {
                cout<<1; 
                ll num=(ll)1<<i;
                if(i%2==1) num=-num;
                n-=num; 
            }
        }
    }
}


Measured memory_bytes: 256
n=int(input())
s=[[j for j in input().split()] for i in range(n)]
for i in range(n):
    s[i][1]=int(s[i][1])
    s[i].append(i)
s.sort(reverse=True,key=lambda x: x[1])
s.sort(key=lambda x: x[0])
for i in range(n):
    print(s[i][2]+1)

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int max_v = 0;
  int x = 0;
  for (int i = 0; i < N; ++i) {
    char c = S[i];
    if (c == 'I') {
      ++x;
    } else {
      --x;
    }
    max_v = max(max_v, x);
  }
  cout << max_v << endl;
}

Measured memory_bytes: 256
str = input()

str = str[::-1]

str_list = ["dream","dreamer","erase","eraser"]

for i in range(4):
    str_list[i] = str_list[i][::-1]

result = "YES"

while len(str) >= 5:
    if str[:5] == str_list[0]:
        str = str[5:]
    elif str[:7] == str_list[1]:
        str = str[7:]
    elif str[:5] == str_list[2]:
        str = str[5:]
    elif str[:6] == str_list[3]:
        str = str[6:]
    else:
        result = "NO"
        break

if len(str) != 0:
    result = "NO"

print(result)


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<functional>
#include<fstream>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
#define f first
#define s second

int main(){
  int n,m;

  while(cin>>n>>m){
    vector<pair<int,pair<int,string> > > jp(n);
    REP(i,n){
      int a,b;
      string s;
      cin>>s>>a>>b;
      jp[i].f = b - a + 1;
      jp[i].s.f = a;
      jp[i].s.s = s;
    }

    sort(jp.begin(), jp.end());

    REP(i,m){
      int ans = -1;
      int q;
      cin>>q;
      REP(j,n){
        if(jp[j].f <= q && jp[j].f+jp[j].s.f > q){
          ans = j;
          break;
        }
      }
      if(ans == -1) cout << "Unknown" << endl;
      else cout << jp[ans].s.s << " " << q - jp[ans].f + 1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 976
AB = list(map(int, input().split()))
A = AB[0]
B = AB[1]
ans = 0

B_list = [B*10 + i for i in range(10)]

for i in B_list:
  if int((i) * 0.08) == A:
    ans = i
    break

if ans == 0:
  ans = -1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
int n,m;
int p[114514];
vector<P> dis[114514];
bool reached[114514]={};
bool ans=true;
void solve(int s){
    reached[s]=true;
    for(int i=0;i<dis[s].size();i++){
        P l=dis[s][i];
        if(reached[l.first]){
            if(p[l.first]-p[s]!=l.second)ans=false;
        }else{
            p[l.first]=p[s]+l.second;
            solve(l.first);
        }
    }
    return;
}
signed main(){
    cin>>n>>m;
    for(int i=0;i<114514;i++)p[i]=INF;
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        dis[a-1].push_back(P(b-1,c));
        dis[b-1].push_back(P(a-1,-c));
    }
    for(int i=0;i<n;i++){
        if(!reached[i]){
            p[i]=0;
            solve(i);
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 17024
n = int(input())

memo = [{} for i in range(n+1)]

def ok(last4):
  for i in range(4):
    t = list(last4)
    if i >= 1:
      t[i-1], t[i] = t[i], t[i-1]
    if ''.join(t).count('AGC') >= 1:
      return False
  return True

def dfs(cur, last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur == n:
    return 1
  ret = 0
  for c in 'AGCT':
    if ok(last3 + c):
      ret = (ret + dfs(cur+1, last3[1:] + c)) % 1000000007
  memo[cur][last3] = ret
  return ret

print(dfs(0, 'TTT'))

Measured memory_bytes: 3888
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool isPrime(int n){
    if(n==2)return true;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return true;
}


int main() {
    vector<ll> p;
    
    int c=0;
    for(int i=2;c<=10000;i++){
        if(isPrime(i)){
            p.pb(i);
            c++;
        }
    }
    for(int i=1;i<p.size();i++){
        p[i]=p[i]+p[i-1];
    }
    
    int n;
    while(cin>>n){
        if(n==0)break;
        cout<<p[n-1]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1336
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main(){
	int m, f, r;
	for(;;){
		cin >> m >> f >> r;
		if(m == -1 && f == -1 && r == -1) break;
		else if(m == -1 || f == -1){
			cout << "F" << endl;
		}
		else if(m + f >= 80){
			cout << "A" << endl;
		}
		else if(65 <= m + f && m + f < 80){
			cout << "B" << endl;
		}
		else if(50 <= m + f && m + f < 65){
			cout << "C" << endl;
		}
		else if(30 <= m + f && m + f < 50){
			if(r >= 50) cout << "C" << endl;
			else cout << "D" << endl;
		}
		else if(m + f < 30){
			cout << "F" << endl;
		}

	}

}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007

using graph = vector<vector<ll>>;

int main(){
    int n;
    cin >> n;
    ll l[n];
    rep(i,n){
        ll temp;
        cin >> temp;
        l[i]= temp;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1;j < n; j++){
            for(int k = j+1; k < n; k++){
                if(l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i] && l[i] != l[j] && l[i] != l[k] && l[j] != l[k]){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    for(int i = 0;;i++){
        double memo = sqrt(n - i);
        int memo2 = sqrt(n - i);
        if(memo - memo2 == 0){
            cout << n - i << endl;
            break;
        }
    }
}

Measured memory_bytes: 3612
n = gets.chomp.to_i
s = gets.chomp

stack = []
if (s[0] == '#') 
    stack.push(0)
end

tar = s[0]
cnt = 0
min = 0

for i in 1..n do
    if (s[i-1]==tar)
        cnt += 1
    else
        if (tar == ".") 
            min += cnt
        end
        tar = s[i-1]
        stack.push(cnt)
        cnt = 1
    end
end

stack.push(cnt)
if (s[n-1] == '.')
    stack.push(0)
    min += cnt
end
min -= stack[0]

# p stack
# p min
now = min
1.step(stack.size-3,2) do |i|
    now += stack[i]
    now -= stack[i+1]
    # p now
    if (min > now)
        min = now
    end
end

p min

Measured memory_bytes: 3832
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	f := make([]bool, 26)
	for _, c := range s {
		f[c-97] = true
	}
	for i, e := range f {
		if !e {
			fmt.Println(string(i + 97))
			return
		}
	}
	fmt.Println("None")
	return
}


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int x;
	int ans = 1;
	cin >> x;
	int reminder = x%100;
	int max_yen = x/100;
	for(int i= 5; i > 0; i--){
		if(reminder / i > max_yen){
			ans = 0;
			break;
		}
		max_yen -= reminder /i;
		reminder -= (int)(reminder / i)*i;
	}
	cout << ans;

}


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

using namespace std;

int n,res;

string s;

vector<string> str[26][27];

bool flag;

int main() {

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> s;

		flag = false;

		if (s.size() > 1) {
			for (auto&& x : str[s[0] - 'a'][s[1] - 'a']) {
				if (x == s) {
					flag = true;
					break;
				}
			}
			if (flag == false)str[s[0] - 'a'][s[1] - 'a'].push_back(s);
		}

		else {
			for (auto&& x : str[s[0] - 'a'][26]) {
				if (x == s) {
					flag = true;
					break;
				}
			}
			if (flag == false)str[s[0] - 'a'][26].push_back(s);
		}
	}

	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < 27; j++) {
			res += str[i][j].size();
		}
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 11576
# https://atcoder.jp/contests/keyence2019/tasks/keyence2019_c

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = int(input())
    A = []
    B = []
    for _ in range(n):
        a, b = input_int_list()
        A.append(a)
        B.append(b)

    cnt = 0
    for a, b in zip(A[::-1], B[::-1]):
        a += cnt
        cnt += (-a) % b
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 83424
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
void insert(int);
void _delete(int);
void deleteFirst(void);
void deleteLast(void);
#define N 2000020
clock_t start, finish;
struct list
{
	int li;
	list *pl, *pl2;
};
int cou = 0, now = 0;
list L[N], first, last;
int main(void)
{
	int n, x;
	char c[12];
	list *f;
	first.li = -1;
	first.pl = &last;
	last.li = -1;
	last.pl2 = &first;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", c);		
		if (c[0] == 'i') {
			scanf("%d", &x);
			insert(x);
		}
		else if (c[0] == 'd' && c[6] == '\0') {
			scanf("%d", &x);
			_delete(x);
		}
		else if(c[0] == 'd' && c[6] == 'F') { deleteFirst(); }
		else if(c[0] == 'd' && c[6] == 'L') { deleteLast(); }
		f = first.pl;
	}
	for (int i = 0; ; i++) {
		printf("%d", f->li);
		if (last.pl2 == f) break;
		f = f->pl;
		printf(" ");
	}
	printf("\n");
}
void insert(int a)
{
	L[cou].li = a;
	L[cou].pl2 = &first;
	L[cou].pl = first.pl;;
	first.pl->pl2 = &L[cou];
	first.pl = &L[cou];
	cou++; now++;
}
void _delete(int a)
{
	list *f, *fb, *fa;
	f = first.pl;
	if (now >= 1) {
		for (int i = 0; ; i++) {
			if (a == f->li) {
				fa = f->pl; fb = f->pl2;
				fb->pl = fa;
				fa->pl2 = fb;
				now--;
				break;
			}
			if (last.pl2 == f) break;
			f = f->pl;
		}
	}
}
void deleteFirst(void)
{
	if (now >= 1) {
		list *fa;
		fa = first.pl;
		fa->pl->pl2 = &first;
		first.pl = fa->pl;
		now--;
	}
}
void deleteLast(void)
{
	if (now >= 1) {
		list *fb;
		fb = last.pl2;
		fb->pl2->pl = &last;
		last.pl2 = fb->pl2;
		now--;
	}
}

Measured memory_bytes: 28892
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int lookUp(string& s, string obj) {
	int result = 0;
	int pos = s.find(obj);
	int objLen = obj.length();
	if (obj.empty()) {
		return 0;
	}
	while ((pos = s.find(obj, pos)) != string::npos) {
		result++;
		pos += objLen;
	}
	return result;
}

int main() {
	int n;
	cin >> n;
	int a = 0, b = 0, ab = 0;
	int ans = 0;
	rep(i, n) {
		string s;
		cin >> s;
		int l = s.size();
		if (s.at(0) == 'B' && s.at(l - 1) == 'A') {
			ab++;
		}
		else if (s.at(0) == 'B') {
			b++;
		}
		else if (s.at(l - 1) == 'A') {
			a++;
		}
		ans += lookUp(s, "AB");
	}
	if (ab > 0) {
		ans += ab - 1;
		if (a > 0) {
			ans++;
			a--;
		}
		if (b > 0) {
			ans++;
			b--;
		}
	}
	ans += min(a, b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(i=a;i<b;i++)
#define per(i,b,a) for(i=b;i>=a;i--)
#define For(i,a,b) for(i=a;i<=b;i++)
#define Forenska(it,c) for(register __typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
using namespace std;
int i,j;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
	int x=0;
	char ch=' ';
	bool flag=false;
	while(!isdigit(ch))
	{
		if(ch=='-')flag=true;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return flag?-x:x;
}

int main()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    str='~'+str;
    vec L;
    L.resize(n+1);
    For(i,1,n)
    {
    	if(str[i]=='1')L[i]=L[i-1];
    	else L[i]=i;
	}
	vec dp;
	dp.resize(n+1);
	For(i,1,n)
	{
		dp[i]=dp[i-1];
		if(str[i]=='1')
		{
			if(str[i-1]=='0' && str[i-2]=='1')
			{
				dp[i]=max(dp[i],dp[L[i-2]]+(i-2)-L[i-2]);
				dp[i]=max(dp[i],dp[L[i-2]+1]+(i-2)-L[i-2]-1);
			}
			else if(L[i]>1 && str[L[i]-1]=='1')
			{
				dp[i]=max(dp[i],dp[L[i]-2]+i-L[i]);
			}
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}



Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[2] == s[3])cout << "Yes";
    else cout << "No";
    cout << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n;
   cin >> n;
   vector<int> l(n);
   rep(i, 0, n) cin >> l[i];
   int ans = 0;
   rep(i, 0, n) rep(j, i + 1, n) rep(k, j + 1, n) {
      if (l[i] == l[j] || l[j] == l[k] || l[i] == l[k]) continue;
      ll mx = max({l[i], l[j], l[k]});
      ll l2 = (ll)l[i] + l[j] + l[k] - mx;
      if (mx < l2) ans++;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
//#include <algorithm>
#include<set>
#include <limits>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
int main(void){
  ll n;cin>>n;
  string s[2];
  cin>>s[0]>>s[1];
  ll ans=1;
  ll now=0;
  int pre=-1;
  int ppre=-1;
  s[0]+='@';
  s[1]+='y';
  while(now<s[0].size()-1){
    //cout << ans << endl;
    if(s[0][now]==s[0][now+1] && s[1][now]==s[1][now+1] ){
      if(pre==0){
        ans*=3;
      }else if(pre==1){
        ans*=2;
      }else{
        ans*=6;
      }
      ans%=d9_7;
      ppre=pre;
      now+=2;
      pre=0;
    }else if(s[0][now]==s[1][now]){
      if(pre==0){
        ans=ans;
      }else if(pre==1){
        ans*=2;
      }else{
        //cout << "y";
        ans*=3;
      }
      ans%=d9_7;
      ppre=pre;
      now++;
      pre=1;
    }
  }
  cout << ans%d9_7;
	return 0;
}

Measured memory_bytes: 256
n= int(input())
h= list(map(int, input().split()))
x=max(h)
ans=0
count=0
for i in range(10009):
    count=0
    if max(h)==0:
        break
    ans+=1
    for j in range(n):
        if h[j]==0 and count==0:
            continue
        elif h[j]>0:
            count=1
            h[j]-=1
        else:
            break



print(ans)

Measured memory_bytes: 41324
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int main(void){
	int a=nextint();
	int b=nextint();
	printf("%d\n", a*b);
}


Measured memory_bytes: 1564
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

#define P 1000000007
#define N_MAX 10000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
int main(int argc, char const *argv[]) {
  init();
  ll n, k;scanf("%lld %lld", &n, &k);
  vll a(k);re(i, k) scanf("%lld", &a[i]);
  vvl dp = VV(k+1, n+1, 0, ll);
  dp[0][0] = 1;
  ll ans = fac[n];

  for(int i=1;i<=k;i++){
    for(int j=0;j<=n;j++){
      for(int d=0;d<=j;d++){
        ll prev = dp[i-1][j-d];
        ll x = pp(comb(n-d, a[i-1]-d), finv[d]);
        dp[i][j] = (dp[i][j] + pp(prev, x))%P;
      }
    }
  }
  std::cout << pp(ans, dp[k][n]) << '\n';
  return 0;
}


Measured memory_bytes: 234752
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long e,f,g,h;
  e=a*c;
  f=a*d;
  g=b*c;
  h=b*d;
  cout<<max({e,f,g,h})<<endl;
  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
typedef struct{
  int num;
  char mk; 
} C;

int isStable(C in[],C out[]);
int n;

int main()
{
  int i,j,minj;
  C N[36],M[36],temp;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&N[i].mk,&N[i].num);
    M[i]=N[i];
  }

  //BubbleSort
  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(N[j].num<N[j-1].num){
	temp=N[j];
	N[j]=N[j-1];
	N[j-1]=temp; 
      }
    }
  }
  for(i=0;i<n-1;i++) printf("%c%d ",N[i].mk,N[i].num);
  printf("%c%d\n",N[n-1].mk,N[n-1].num);

  if(isStable(M,N)) printf("Stable\n");
  else printf("Not stable\n");

  for(i=0;i<n;i++) N[i]=M[i];

  //SelectionSort
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(N[j].num<N[minj].num) minj=j;
    }
    temp=N[i];
    N[i]=N[minj];
    N[minj]=temp;
  } 
  for(i=0;i<n-1;i++) printf("%c%d ",N[i].mk,N[i].num);
  printf("%c%d\n",N[n-1].mk,N[n-1].num);
  
  if(isStable(M,N)) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}

int isStable(C in[],C out[]){
  int i,j,a,b;

  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(a=0;a<n;a++){
	for(b=a+1;b<n;b++){
	  if(in[i].num==in[j].num && in[i].mk==out[b].mk && in[j].mk==out[a].mk){
	    if(in[i].num==out[b].num && in[j].num==out[a].num) return 0;
	  }
	}
      }
    }
  }
  return 1;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ret = 800 * n;
    ret -= 200 * (n / 15);
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int A,B,C,K,cnt;
int main(){
	scanf("%d%d%d%d",&A,&B,&C,&K);
	while(A>=B)B*=2,cnt++;
	while(B>=C)C*=2,cnt++;
	puts(cnt<=K?"Yes":"No");
	return 0;
}


Measured memory_bytes: 3160
#include <iostream>
using namespace std;
char c[100004];
int a[100004];
int po,pe;
int main(){
	cin>>c;
	int mode=0,odd=0,even=0;
	for(int i=0;c[i];i++){
		if(mode==0){
			if(c[i]=='R'){
				if(i%2==0)even++;else odd++;
			}else{
				po=i;pe=i-1;
				if(po%2==0)po=i-1,pe=i;
				mode=1;
				if(i%2==0)even++;else odd++;
			}
		}else{
			if(c[i]=='R'){
				a[pe]=even;a[po]=odd;
				mode=even=odd=0;
				if(i%2==0)even++;else odd++;
			}else{
				if(i%2==0)even++;else odd++;
			}
		}
	}
	a[pe]=even;a[po]=odd;
	for(int i=0;c[i];i++){
		cout<<a[i]<<" ";
	}
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define    fios ios_base::sync_with_stdio(false); cin.tie(0);
#define    sf(x) scanf("%d",&x)
#define    sfl(x) scanf("%lld",&x)
#define    pf(x) printf("%d\n",x)
#define    pfl(x) printf("%lld\n",x)
#define    ll long long
#define    nl "\n"
#define    PB(x) push_back(x)
#define    For(i,n) for(int i=0; i<n; i++)
#define    PI acos(-1)
using namespace std;


int b[1000005];

int main()
{
    int n,x;

    cin>>n;

    int a[n];

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

        b[a[i]]++;

    }

    if(b[1]==1)
    {
        cout<<1<<nl;
        return 0;
    }

    if(b[1]>1)
    {
        cout<<0<<nl;
        return 0;
    }

    ll ans=0;
    for(int i=0; i<n; i++)
    {
        bool fl=0;
        for(int j=2; j*j<=a[i]; j++)
        {

             if(a[i]%j==0 )
             {
                // isPrime=1;

                 if(b[a[i]/j]>=1 || b[j]>=1)
                 {
                      fl=1;
                      break;
                 }
             }

        }

        if(fl==0 && b[a[i]]<2)
            ans++;

    }

    cout<<ans<<nl;


    return 0;
}


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



int main()
{
  int a,b,k;
  cin >> a >> b >> k;
  int cnt = 0, tmp=min(a,b);
  while(1)
  {
    if(a%tmp==0 && b%tmp==0){
      cnt++; // tmp is a cnt-th common divisor
      if(cnt==k) break;
    }
    tmp--;
  }
  cout << tmp << endl;
}

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

int mod = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<vector<bool>> bit_a(n, vector<bool>(60, 0));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 60; j++){
            bit_a[i][j] = ((a[i] >> j) & 1);
        }
    }
    vector<long long> modpow(61, 1);
    for (int i = 1; i < 61; i++) modpow[i] = modpow[i - 1] * 2 % mod;
    vector<int> tmp(120, 0);
    long long ans = 0;
    for (int i = n - 1; i > 0; i--){
        for (int j = 0; j < 60; j++){
            if (bit_a[i][j]) tmp[j + 60]++;
            else tmp[j]++;
        }
        for (int j = 0; j < 60; j++){
            if (bit_a[i - 1][j]){
                ans += modpow[j] * tmp[j] % mod;
                ans %= mod;
            }
            else {
                ans += modpow[j] * tmp[j + 60] % mod;
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 23680
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
typedef long long LL;

const int Pt = 1e9 + 7;
const int MaxN = 1e5;
LL n, m;
LL fac[MaxN + 5];

int main()
{
	fac[0] = 1;
	for (int i = 1; i <= 100000; i++) fac[i] = (fac[i - 1] * (LL)i) % Pt;
	while (~scanf("%lld%lld", &n, &m)) {
		if (abs(n - m) > 1) printf("0\n");
		else {
			if (abs(n - m) == 1) {
				printf("%lld\n", fac[n] * fac[m] % Pt);				
			}
			else {
				printf("%lld\n", ((fac[n] * fac[n] % Pt) * 2) % Pt);
			}
		}
	}
	return 0;
}

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

int main() {
	ll d;
	cin >> d;
	vector<ll> c(26);
	vector<ll> co(d,0);

	rep(i,26) {
		cin >> c[i];
	}

	vector<int> last(26,-1);

	rep(i, 26) {
		last[i]=0;
	}

	ll s[370][30];

	rep(j, d) {
		rep(i, 26) {
			cin >> s[j][i];
		}
	}
	
	rep(j, d) {

		ll count = 0;
		ll max_d=0;

		rep(i, 26) {
			ll tmp = s[j][i] + c[i] * (j - last[i]);
		
			if (tmp > count) {
				count = tmp;
				max_d = i;
			}
		}
		last[max_d] = j;
		co[j] = max_d+1;
		//cout << max_d << endl;
	}

	rep(j, d) {
		cout << co[j]<<endl;
	}

	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;
constexpr int MAX = 2000200;
constexpr double EPS = 1E-11;

using namespace std;

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

	bool ok = false;

	ll x = 0;
	ll y = 0;
	
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			x = i;
			y = n / i;
		}
	}



	cout << x - 1 + y - 1 << endl;
}




Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
//#include "ext/pb_ds/tree_policy.hpp"
//#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
const ld eps = 1e-9;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a) {
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}

template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}

template<typename T> inline void in(T &x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch))  {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}

ll twop(int x) {
    return 1LL<<x;
}

template<typename A,typename B > inline void in(A&x,B&y) {
    in(x);
    in(y);
}
template<typename A,typename B,typename C>inline void in(A&x,B&y,C&z) {
    in(x);
    in(y);
    in(z);
}
template<typename A,typename B,typename C,typename D> inline void in(A&x,B&y,C&z,D&d) {
    in(x);
    in(y);
    in(z);
    in(d);
}

namespace SOLVE {
    void main(){
    }
}

int dp[200010][2];
int main() {
    int n;
    cin>>n;
    vector<PII> v;
    REP(i,0,n){
        int c;in(c);
        if(sz(v) && v.back().fi == c)v.back().se++;
        else v.PB(MP(c,1));
    }
    int ans = 0;
    for(auto i:v){
        ans+=i.se/2;
    }
    cout<<ans;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())	
ka = sorted([list(map(int, input().split())) for _ in range(n)])
cnt={}
for i in range(n):
    for j in range(ka[i][0]):
        if ka[i][j+1] not in cnt:
            cnt[ka[i][j+1]]=1
        else:
            cnt[ka[i][j+1]]+=1
ans=0
for c in cnt:
    if cnt[c]==n:
        ans+=1
print(ans)



Measured memory_bytes: 3064
s = input()

def dfs(i,f,sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    
    else:
        dfs(i+1,f + "+" + s[i+1],sum + int(s[i+1]))
        dfs(i+1,f + "-" + s[i+1],sum - int(s[i+1]))

dfs(0,s[0],int(s[0]))   

Measured memory_bytes: 9124