akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	// your code goes here
    string s,w;
    cin>>s>>w;
    int dp[s.length()+1][w.length()+1];
    for(int i=0;i<=w.length();i++)
    dp[0][i]=0;
    for(int i=0;i<=s.length();i++)
    dp[i][0]=0;
    for(int i=1;i<=s.length();i++)
    {
        for(int j=1;j<=w.length();j++)
        {
            if(s[i-1]==w[j-1])
            dp[i][j]=1+dp[i-1][j-1];
            else
            dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
        }
    }
    if(dp[s.length()][w.length()]==0)
    {cout<<"";
        return 0;
    }
    string s2;
    int i=s.length(),j=w.length();
    while(i>0 && j>0)
    {
        if(s[i-1]==w[j-1])
        {s2+=s[i-1];
            i--;
            j--;
        }
        else
        {
            if(dp[i][j-1]>dp[i-1][j])
            j--;
            else
            i--;
        }
    }
    for(int i=s2.length()-1;i>=0;i--)
    cout<<s2[i]<<"";
    

	return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
struct initon
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main(){
int N,K,ans;
cin >> N >>K;
ans =K*pow((K-1),(N-1));
cout <<ans;
}

Measured memory_bytes: 384
k, x = gets.split.map(&:to_i)

MIN = -1_000_000
MAX = 1_000_000

head = x - (k - 1)
tail = x + (k - 1)

if head <= MIN
  puts (head + (MIN - head)..(MIN + k - 1)).to_a.join(' ')
elsif tail >= MAX
  puts (MAX - (k - 1)..tail + (MAX - tail)).to_a.join(' ')
else
  puts (head..tail).to_a.join(' ')
end


Measured memory_bytes: 1788
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  double n,m,a,b,c,d,x,y,z;
  string s,t;
  //

  // ここから
  IN(n);
  OUT(800*n - floor(n/15)*200);
}

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

signed main() {
    ios_base::sync_with_stdio(0);
    string xd;
    int n, i;
    cin>>n;
    cin>>xd;
    for(i=0; i<xd.length(); ++i){
        int d = int(xd[i]);
        d += n;
        if(d>90){
            d -= 26;
        }
        cout<<(char)d;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
const int INF = 0x3f3f3f3f, nINF = 0xcfcfcfcf, INFMEM = 0x3f, nINFMEM = 0xcf;
const int PR1 = 1e6 + 3, PR2 = 1e9 + 7;
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 5003, mod=1e9+7;
int n,f[N][N],sz[N],g[N],tf[N];
//f[i,S]: 以i为根的子树,i在大小为S的连通块中,不包括包含i的连通块,方案数
//f[i,0]: 以i为根的子数中所有情况的统计
VI G[N];

void dfs(int x, int fz){
	f[x][1]=1; sz[x]=1;
	for(int y : G[x]) if(y!=fz){
		dfs(y,x);
		rep(i,1,sz[x]) tf[i]=f[x][i],f[x][i]=0;
		rep(i,1,sz[x]) rep(j,0,sz[y]) f[x][i+j]=(f[x][i+j]+(ll)tf[i]*f[y][j])%mod;
		//当j=0时即为i与该子树切断
		//乘法原理相乘即为总方案数
		sz[x]+=sz[y];
	}
	rep(i,1,sz[x]) f[x][0]=(f[x][0]-(ll)f[x][i]*g[i]%mod+mod)%mod;
	//统计不再加点的情况下该子树内方案总数
	//且此处'-'符合容斥原理,故输出答案时要mod-f[1][0]
}

int main(){
	scanf("%d",&n);
	g[0]=1; rep(i,2,n) g[i]=(ll)g[i-2]*(i-1)%mod;
	rep(i,1,n-1) { int x,y; scanf("%d%d",&x,&y); G[x].pb(y); G[y].pb(x); }
	dfs(1,0);
	printf("%d\n",mod-f[1][0]);
	return 0;
}

Measured memory_bytes: 97408
#include<bits/stdc++.h>
using namespace std;
#define MAXN	1000005
#define P	998244353
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
long long fac[MAXN], inv[MAXN];
void update(long long &x, long long y) {
	x = (x + y) % P;
}
long long power(long long x, long long y) {
	if (y == 0) return 1;
	long long tmp = power(x, y / 2);
	if (y % 2 == 0) return tmp * tmp % P;
	else return tmp * tmp % P * x % P;
}
long long getc(long long x, long long y) {
	return fac[x] * inv[y] % P * inv[x - y] % P;
}
int main() {
	int n, m;
	read(n), read(m);
	if (n < m) swap(n, m);
	fac[0] = 1;
	for (int i = 1; i <= n + m; i++)
		fac[i] = fac[i - 1] * i % P;
	inv[n + m] = power(fac[n + m], P - 2);
	for (int i = n + m - 1; i >= 0; i--)
		inv[i] = inv[i + 1] * (i + 1) % P;
	long long ans = 0;
	for (int i = 1; i <= m; i++)
		update(ans, getc(2 * i, i) * getc(n + m - 2 * i, m - i));
	ans = ans * power(getc(n + m, m) * 2 % P, P - 2) % P;
	update(ans, n);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15872
import java.math.BigDecimal;
import java.util.Scanner;

class Main{
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);
        double  r  = sc.nextDouble();
        sc.close();
        
        double pi = Math.PI;
        double ci = 2*pi*r;
        double ar = pi*Math.pow(r,2);

        String circ = BigDecimal.valueOf(ci).toPlainString();
        String area = BigDecimal.valueOf(ar).toPlainString();
        
        System.out.println(new StringBuilder()
            .append(area).append(" ")
            .append(circ));
    }
}

Measured memory_bytes: 28364
# Your code here!

n=gets.to_i


array=Array.new(26,50)
array2=Array.new(26,0)
jj="abcdefghijklmnopqrstuvwxyz"

n.times{
    ss=gets.chomp.split("")
    
    i=0
    26.times{
        kk=ss.count(jj[i])
        if kk<=array[i]
            array[i]=kk
        end
        
        
        i+=1
    }
    
    
}






answer=[]

sss=0
26.times{
     array[sss].times{
         answer<<jj[sss]
         
         
     }
    
    sss+=1
    
    
}



puts answer.join

















Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= 31622; i++){
        if(i * i <= N){
            ans = i;
        }
    }
    cout << ans * ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	int n;
	cin >> n;
	vector<llint>a(n + 1);
	for (int i = 0;i <= n;i++) {
		if (i == 0) {
			a[i] = 2;
		}
		else if (i == 1) {
			a[i] = 1;
		}
		else {
			a[i] = a[i - 1] + a[i - 2];
		}
	}
	cout << a[n] << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Program
{
    static int[][] Solve(int N)
    {
        var dict = new Dictionary<int, int>();
        for (int i = 2; i * (i - 1) / 2 <= 100000; ++i)
        {
            dict[i * (i - 1) / 2] = i;
        }
        if (dict.ContainsKey(N))
        {
            int n = dict[N];
            var rows = new List<int>[n];
            for (int i = 0; i < n; ++i) { rows[i] = new List<int>(); }
            int c = 1;
            for (int i = 0; i < n; ++i)
            {
                for (int j = i + 1; j < n; ++j)
                {
                    rows[i].Add(c);
                    rows[j].Add(c);
                    ++c;
                }
            }
            return rows.Select(row => row.ToArray()).ToArray();
        }
        else
        {
            return null;
        }
    }

    static void Main(string[] args)
    {
        var rows = Solve(int.Parse(Console.ReadLine()));
        if (rows != null)
        {
            Console.WriteLine("Yes");
            Console.WriteLine(rows.Length);
            foreach (var row in rows)
            {
                Console.WriteLine("{0} {1}", row.Length, string.Join(" ", row));
            }
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 19380
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

int main()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    if (A * B >= C * D) { cout << A * B << endl; }
    else { cout << C * D << endl; }
}

Measured memory_bytes: 256
implicit none
integer :: i,a,b,ans=0
character(5) :: charI

read*,a,b

do i = a,b
  write(charI,'(I0)') i
  if( charI(1:1)==charI(5:5) .and. charI(2:2)==charI(4:4) )then
    ans = ans + 1
  end if
end do
print*,ans
end


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ABC
{
    class ABC168A
    {
        const string FILE = "/tmp/data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            var s = Console.ReadLine();

            char c = s.ToCharArray()[s.Length - 1];


            string result = "hon";
            if (c == '3')
            {
                result = "bon";
            }
            else if (c == '0' || c == '1' || c == '6' || c == '8')
            {
                result = "pon";
            }
            Console.WriteLine(result);

#if DEBUG
            Console.WriteLine();
#endif
        }
    }
}


Measured memory_bytes: 25876
#include <iostream>
#include <stack>
#include <math.h>
#include <string.h>

using namespace std;

int D, G;
int p[20];
int c[20];

int pow2(int i) {
    return 1 << i;
}

int main(int argc, char** argv) {
    cin >> D >> G;
    for (int i = 1; i <= D; i++) {
        cin >> p[i] >> c[i];
    }

    int min_count = 100000;
    for (int comp = 0; comp < pow(2, D); comp++) {
        int last_score = G;
        int count = 0;
        //cout << comp << endl;
        for (int i = 1; i <= D; i++) {
            if (comp / pow2(i - 1) % 2 == 1) {
                last_score -= p[i] * 100 * i + c[i];
                count += p[i];
            }
        }
        //cout << "score1" << last_score << endl;
        //cout << "count" << count << endl;
        for (int i = D; 1 <= i; i--) {
            if (comp / pow2(i - 1) % 2 == 0) {
                int use = max(min(last_score / (100 * i), p[i] - 1), 0);
                count += use;
                //cout << "count!" << use << endl;
                last_score -= 100 * i * use;
            }
        }
        //cout << "score2" << last_score << endl;
        if (last_score <= 0) min_count = min(min_count, count);
    }
    cout << min_count << endl;
}


Measured memory_bytes: 256
#include <iostream>

#define UNDEF -1
using namespace std;

typedef long long int int64;

int64 N,A[4000],dp[4000][4000];

int64 dfs(int64 a,int64 b)//always a > b
{
	if(dp[a][b] == UNDEF)
	{
		if(a == b)
		{
			if(N % 2 == 0)
				dp[a][b] = 0;
			else
				dp[a][b] = A[a];
		}
		else if((N - (a - b)) % 2 == 0)
		{
			if(A[a] > A[b])
				dp[a][b] = dfs(a-1,b);
			else
				dp[a][b] = dfs(a,b+1);
		}
		else
		{
			dp[a][b] = max(dfs(a-1,b)+A[a],dfs(a,b+1)+A[b]);
		}
	}
	return dp[a][b];
}

int main(void)
{
	for(int64 i = 0;i < 4000;i++)
	{
		for(int64 ii = 0;ii < 4000;ii++)
			dp[i][ii] = UNDEF;
	}
	cin >> N;
	for(int64 i = 0;i < N;i++)
	{
		cin >> A[i];
		A[i+N] = A[i];
	}
	int64 result = 0;
	for(int64 i = 1;i <= N;i++)
	{
		result = max(result,dfs(i+(N-2),i)+A[i-1]);
	}
	cout << result << endl;
}

Measured memory_bytes: 128220
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> to(3 * n);
    rep(i, m){
        int u, v;
        cin >> u >> v;
        u--; v--;
        to[3*u+0].push_back(3*v+1);
        to[3*u+1].push_back(3*v+2);
        to[3*u+2].push_back(3*v+0);
    }
    int s, t;
    cin >> s >> t;
    s--; t--;
    int INF = 1001001001;
    vector<int> d(3*n, INF);
    d[3*s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(make_pair(0, 3*s));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int dist = p.first;
        int v = p.second;
        if(d[v] < dist)continue;
        for(int t : to[v]){
            if(d[t] > d[v] + 1){
                d[t] = d[v] + 1;
                que.push(make_pair(d[t], t));
            }
        }
    }
    if(d[3*t] == INF)cout << -1 << endl;
    else cout << d[3*t] / 3 << endl;
}

Measured memory_bytes: 17792
N = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_ans = []

for i in range(N):
    r = list_A[i] + list_A[i+1] - list_B[i]
    list_ans.append(list_B[i] if r >= 0 else list_A[i] + list_A[i+1])
    if r < 0:
        list_A[i+1] = 0
    elif list_A[i] < list_B[i]:
        list_A[i+1] = r

print(sum(list_ans))

Measured memory_bytes: 18476
def main() -> None:
    H, W = map(int, input().split())
    s = ['0' + input() + '0' for _ in range(H)]
    s.insert(0, '0' * (W + 2))
    s.append('0' * (W + 2))
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            # print(s[i][j])
            if s[i][j] == "#":
                if s[i+1][j] == "#" or s[i-1][j] == "#" or s[i][j+1] == "#" or s[i][j-1] == "#":
                    continue
                else:
                    print("No")
                    exit()
    print("Yes")


if __name__ == '__main__':
    main()


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

using namespace std;

#define debug1(x) cerr << "WHY" << x << '\n';
#define debug2(s, x) cerr << "The Value of " << s << " is : " << x << '\n';
#define ios ios_base::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second

typedef long long ll;
typedef pair<int, int> ii;
typedef long double db;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, m;

map<int, map<int, bool> >mp;


int main(){


  int n, m;

  scanf("%d%d", &n, &m);

  int u, v;

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

    scanf("%d%d", &u, &v);
    mp[u][v] = mp[v][u] = 1;

  }
  bool f = false;
  for(int i = 2; i < n; i++)
    f |= (mp[1][i] & mp[i][n]);

  puts(f? "POSSIBLE" : "IMPOSSIBLE");




  return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

double dp[301][301][301] = {};
int n;

double dfs(int a, int b, int c){
  if(a == 0 && b == 0 && c == 0) return 0;
  if(dp[a][b][c] != 0) return dp[a][b][c];
  double x = 0, y = 0, z = 0;
  if(a > 0){
    x = dfs(a-1,b,c);
  }
  if(b > 0){
    y = dfs(a+1,b-1,c);
  }
  if(c > 0){
    z = dfs(a,b+1,c-1);
  }
  return dp[a][b][c] = (n + x*(double)a + y*(double)b + z*(double)c)/(double)(a+b+c);
}

int main(){
  fix20;

  cin >> n;
  vi a(n);
  int r[3] = {};
  long sum = 0;
  rep(i,n){
    int a;
    cin >> a;
    sum += a;
    r[a-1]++;
  }
  cout << dfs(r[0], r[1], r[2]) << endl;
}

Measured memory_bytes: 111088
h,w = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(h)]

cnt = 0
ans = []

for i in range(h):
    for j in range(w-1):
        if lst[i][j] %2 == 1:
            lst[i][j] -= 1
            lst[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(h-1):
    if lst[i][-1] %2 == 1:
        lst[i][-1] -= 1
        lst[i+1][-1] += 1
        ans.append([i+1,w,i+2,w])

print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 30288
#include<stdio.h>
#include<string.h>
#include<math.h>
void move(int d, char ch)
{
    while(d)
    {
        printf("%c",ch);
        d--;
    }
}
int main()
{
    int x1,x2,y1,y2,x,y,i;
    while(scanf("%d %d %d %d",&x1,&y1,&x2,&y2)!=EOF)
    {
        int x=x2-x1;
        int y=y2-y1;
        for(i=1;i<=4;i++)
        {
            if(i==1)
            {
                move(y,'U');
                move(x,'R');
            }
            else if(i==2)
            {
                move(y,'D');
                move(x,'L');
            }
            else if(i==3)
            {
                printf("L");
                move(y+1,'U');
                move(x+1,'R');
                printf("D");
            }
            else
            {
                printf("R");
                move(y+1,'D');
                move(x+1,'L');
                printf("U");
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
int a, b, c;
    int tmp;
    scanf("%d %d %d", &a, &b, &c);
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    if(b>c){
        tmp=b;
        b=c;
        c=tmp;
    }
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define loop(n) for(int i=0; i<n; i++)

void solve()
{
     int n,k;cin>>n>>k;
     int A[n+1],B[n+1]={0};
     bool visited[n+1]={0};
     for(int i=1;i<=n;i++)
     {
          cin>>A[i];
          B[i]=A[i];
     }
     int cyclelength=0;
     bool cycle=false;
     int i=1;
     while(k-cyclelength>0)
     {
          if(visited[i]==true)
          {
               cycle=true;
               break;
          }
          visited[i]=true;
          i=B[i];
          cyclelength++;
     }
     if(!cycle)cout<<i;
     else
     {
          int p=1;
          int templength=0;
          while(i!=p)
          {
               p=B[p];
               templength++;
          }
          cyclelength-=templength;
          k-=templength;
          k%=cyclelength;
          while(k--)
          {
               i=B[i];
          }
          cout<<i;
     }
	return;
}
int32_t main() 
{ 
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0; 
}

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

using namespace std;

int main() {
  int n, k, q;
  scanf("%d %d %d", &n, &k, &q);

  vector<int> a(n, k - q);
  for (int i = 0; i < q; ++i) {
    int x;
    scanf("%d", &x);
    x--;
    a[x]++;
  }

  for (int i = 0; i < n; ++i) {
    if (a[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;
}



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

int main(){
  int n,m,s;
  while(1){
    cin >> n >> m >> s;
    if(n == 0 && m == 0 && s == 0) break;
    int ans = 0;
    for(int i=s-1;i>=1;i--){
      for(int j=1;j<=s-1;j++){
	int x = i*(100+n)/100;
	int y = j*(100+n)/100;
	if(x+y == s) {
	  ans = max(ans,(i*(100+m)/100)+(j*(m+100)/100));
	}
      }
    }
    cout << ans << endl;
  } 
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    long long w,s,i;
    while(scanf("%lld",&w)!=EOF)
    {
        i=1;
        s=0;
        while(i<=w)
        {
            s++;
            w-=i;
            i++;
        }
        if (w!=0) s++;
        printf("%lld\n",s);
    }
    return 0;
}

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

typedef long long ll;
// const int INF = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, int> P;


ll H, W;
int main() {
    cin >> H >> W;

    if (H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        cout << (H * W + 1) / 2 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}
ll powe(ll x, ll y,ll m)
{
    if(y==0)
        return 1;
    else
    {
        ll t = powe(x,y/2,m)%m;
        if(y%2==0)
            return (t*t)%m;
        else
            return (((t*t)%m)*x)%m;
    }
}
string itb(ll n)
{
    string s="";
    while(n>0)
    {
        ll d = n%2;
        s = (char)(d+48)+s;
        n=n/2;
    }
    return s;
}

bool parity(int a, int b)
{
    if(a%2==0 && b%2==0)
        return false;
    else if(a%2==1 && b%2==1)
        return false;
    else
        return true;
}
void build(int node,int start,int end,int tree[],int a[])
{
    if(start==end)
    {
        tree[node]=a[start];
    }
    else
    {
        int mid= (start+end)/2;
        build(2*node,start,mid,tree,a);
        build(2*node+1,mid+1,end,tree,a);
        tree[node] = min(tree[2*node+1],tree[2*node]);
    }
}
void update(int node,int start,int end,int idx,int val,int tree[],int a[])
{
    if(start==end)
    {
        a[idx]=val;
        tree[node]=val;
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx && idx <= mid)
        {
            update(2*node, start, mid, idx, val,tree,a);
        }
        else
        {
            update(2*node+1, mid+1, end, idx, val,tree,a);
        }
        tree[node] = min(tree[2*node+1],tree[2*node]);
    }
}
int query(int node, int start, int end, int l, int r,int tree[])
{
    if(r < start || end < l)
    {
        return 100005;
    }
    if(l <= start && end <= r)
    {
        return tree[node];
    }
    int mid = (start + end)/2;
    int p1 = query(2*node, start, mid, l, r,tree);
    int p2 = query(2*node+1, mid+1, end, l, r,tree);
    return min(p1,p2);
}
int bs_lower_bound(int a[], int n, int x) {
    int l = 0;
    int h = n;
    while (l < h) {
        int mid = (l + h) / 2;
        if (x <= a[mid]) {
            h = mid;
        } else {
            l = mid + 1;
        }
    }
    if(l>=n)
        l=-1;
    return l;
}
int main()
{
    fastio();
   
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        int f=0;
        for(int i=0;i<n/2;i++)
        {
            if(s[i]!=s[i+n/2])
                f=1;
        }
        if(f==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}   

Measured memory_bytes: 256
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	ll N,K;
	scan(N>>K);
	ll ans=N;
	rep(i,1000000){
		if(N>K) N%=K;
		else N=abs(N-K);
		ans=min(ans,N);
	}
	prin(ans);
	return 0;
}


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

int main() {
  int N, X, m, min = 1001, cnt = 0;
  cin >> N >> X;

  for (int i = 1; i <= N; i++) {
    cin >> m;
    X -= m;
    if (m < min) min = m;
  }
  while (X - min >= 0) {
    ++cnt;
    X -= min;
  }
  cout << N + cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

struct segtree{
	using D = int;
	D inf = 1e9;

	int N;
	vector<D> val;

	segtree(){}
	segtree(int n){
		N=1;
		while(N<n) N*=2;
		val.assign(N*2,inf);
	}
	segtree(const vector<D>& ds){
		int n = ds.size();
		N=1;
		while(N<n) N*=2;
		val.assign(N*2,inf);
		rep(i,n) val[i+N] = ds[i];
		for(int i=N-1;i>0;i--) val[i] = min(val[i*2],val[i*2+1]);
	}
	void assign(int k,D d){
		k+=N;
		chmin(val[k],d);
		k/=2;
		while(k){
			val[k] = min(val[k*2],val[k*2+1]);
			k/=2;
		}
	}
	D getmin(int a,int b){
		D res = inf;
		a+=N,b+=N;
		while(a<b){
			if(a&1) chmin(res,val[a++]);
			if(b&1) chmin(res,val[--b]);
			a/=2,b/=2;
		}
		return res;
	}
};

int N;
int Q;
const int MN = 200010;
int b[MN];
int num0[MN],num1[MN];
int main(){
	cin>>N;
	rep(i,N) cin>>b[i];
	b[N] = 1;
	N++;
	rep(i,N){
		if(b[i]==0) num0[i+1]=1;
		else num1[i+1]=1;
	}
	rep(i,N){
		num0[i+1] += num0[i];
		num1[i+1] += num1[i];
	}
	cin>>Q;
	using P = pair<int,int>;
	vector<P> ps;
	rep(i,Q){
		int l,r;
		cin>>l>>r;
		l--;
		ps.pb(P(l,r));
	}
	ps.pb(P(N-1,N));
	sort(all(ps));

	segtree seg0(N),seg1(N);

	seg0.assign(0,0);
	seg1.assign(0,0);

	int ans = 0;

	for(P p:ps){
		int l = p.fs, r = p.sc;
		int val = 1e9;
		chmin(val,seg0.getmin(l,r)+num0[r]);
		chmin(val,seg1.getmin(0,l)+num1[l]+num0[r]-num0[l]);
		seg0.assign(r,val-num0[r]);
		seg1.assign(r,val-num1[r]);
		ans = val;
	}
	cout << ans << endl;
}


Measured memory_bytes: 8432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a= sc.nextInt();
		int b = sc.nextInt();
		if(n*a>b) {
			System.out.println(b);
		} else {
			System.out.println(n*a);
		}
	}

}


Measured memory_bytes: 23636
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,m,k,a,b,ans=0;
    cin >> n >> m >> k;
    for(a=0;a<=n;a++){
        for(b=0;b<=m;b++){
            if(k==a*b+(n-a)*(m-b))ans = 1;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int n;
    cin >> n;
    vector<int> p(n), s(n);
    int d = 1000000;
    REP(i, n)
    {
        int x;
        cin >> x;
        p[i] = x;

        if (x < d)
            d = x;
        s[i] = d;
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (i == 0)
        {
            ans++;
            continue;
        }
        if (p[i] < s[i - 1])
            ans++;
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long h = 1;
        long n = 1;
        long w = 1;
        boolean found = false;
        for (int i = 3500; i > 0; i--) {
            for (int j = 3500; j > 0; j--) {
                long k1 = N * i * j;
                long k2 = 4 * i * j - N * (i + j);
                if (k2 > 0 && k1 % k2 == 0) {
                    h = i;
                    n = j;
                    w = k1 / k2;
                    found = true;
                    break;
                }
            }
            if (found) {
                break;
            }
        }
        StringJoiner sj = new StringJoiner(" ");
        sj.add(String.valueOf(h));
        sj.add(String.valueOf(n));
        sj.add(String.valueOf(w));
        System.out.println(sj);
    }

}


Measured memory_bytes: 35880
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication27
{
    class Program
    {
        static void Main()
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (a[0] < a[1] && a[1] < a[2]) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 9356
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_A
#????????????17:15~
def decode_heap(target_list):
    for i, key in enumerate(target_list):
        node_index = i + 1
        parent_index = int(node_index / 2) - 1
        parent = ""
        if not parent_index < 0:
            parent = " parent key = " + str(target_list[parent_index]) + ","
            
        left_index = node_index * 2 - 1
        left = ""
        if left_index < len(target_list):
            left = " left key = {},".format(target_list[left_index])
            
        right_index = node_index * 2
        right = ""
        if right_index <  len(target_list):
            right = " right key = {},".format(target_list[right_index])

        print("node {}: key = {},{}{}{} ".format(node_index, key, parent, left, right))

        
def main():
    n_nodes = int(input())
    target_list = [int(a) for a in input().split()]
    decode_heap(target_list)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 7656
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
int n,k;
int a[maxn];
int h[maxn], p[maxn];
vector<int> from[maxn];
void dfs(int x,int last) {
    int i,y;
    h[x] = 1;
    for(i=0;i<from[x].size();i++) {
        y = from[x][i];
        if(y==last) continue;
        dfs(y,x);
        h[x] = max(h[x],h[y]+1);
    }
    if(h[x]==k) {
        h[x] = 0;
        p[x] = 1;
    }
    else p[x] = last;
}
main() {
    int i,x,ans;
    scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++) {
        scanf("%d",&a[i]);
        if(i>1) from[a[i]].push_back(i);
    }
    dfs(1,1);
    ans = 0;
    for(i=1;i<=n;i++) if(p[i]!=a[i]) ans++;
    printf("%d",ans);
}


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

using namespace std;

int n, cnt;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			if (i * j >= n) break;
			cnt ++;
		}
	}
	
	cout << cnt << '\n';
	
	return 0; 
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;



int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k; cin >> n >> k;
    vector<int> s;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        s.push_back(a);
    }
    int ans = 0;
    sort(s.begin(),s.end());
    for (int i = 0; i < k; i++) {
        ans += s[n-1-i];
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
 
class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int t[] = new int[N+1];
        int x[] = new int[N+1];
        int y[] = new int[N+1];

        for(int i=1; i<=N; i++){
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        t[0] = 0;
        x[0] = 0;
        y[0] = 0;


        boolean flag = true;

        for(int i=0; i<N; i++){
            int dt = t[i+1] - t[i];
            int dist = Math.abs(x[i+1] - x[i]) + Math.abs(y[i+1] - y[i]);
            if(dt < dist) {
                flag = false;
                break;
            }
            if(dt%2 != dist%2){
                flag = false;
                break;
            }
        }

        if(flag){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

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

int count_bomb(string *map, int H, int W, int h, int w) {
    int cnt = 0;
    for(int h2 = h - 1; h2 <= h + 1; h2++) {
        if(h2 < 0 || h2 == H) {
            continue;
        }
        for(int w2 = w - 1; w2 <= w + 1; w2++) {
            if(w2 < 0 || w2 == map[0].size()) {
                continue;
            }
            if(map[h2].at(w2) == '#') {
                cnt++;
            }
        }
    }
    return cnt;
}

int main() {
    int H, W;
    cin >> H >> W;
    string map[H];
    for(int i = 0; i < H; i++) {
        cin >> map[i];
    }

    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            if(map[h].at(w) == '#') {
                continue;
            }
            int cnt = count_bomb(map, H, W, h, w);
            map[h].at(w) = to_string(cnt).at(0);
        }
    }

    for(int h = 0; h < H; h++) {
        cout << map[h] << endl;
    }
}

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


int main() {

	int N;
	int mochi[110];
	int result = 0;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> mochi[i];

	int num[110] = {0};

	for (int i = 0; i < N; i++) {
		num[mochi[i]]++;
	}

	for (int i = 0; i <= 100; i++) {
		if (num[i] >= 1) result++;
	}

	cout << result;

}

Measured memory_bytes: 256
h,w = map(int,input().split())
s = 10**8
if h%3==0 or w%3==0:
  print(0)
  exit()
else:
  for i in range(1,w):
    a = h*i
    b = (w-i)*(h//2)
    c = (w-i)*(h//2+h%2)
    s = min(s,max(a,b,c)-min(a,b,c))
    a = h*i
    b = h*((w-i)//2)
    c = h*((w-i)//2+(w-i)%2)
    s = min(s,max(a,b,c)-min(a,b,c))
  
  h,w = w,h
  for i in range(1,w):
    a = h*i
    b = (w-i)*(h//2)
    c = (w-i)*(h//2+h%2)
    s = min(s,max(a,b,c)-min(a,b,c))
    a = h*i
    b = h*((w-i)//2)
    c = h*((w-i)//2+(w-i)%2)
    s = min(s,max(a,b,c)-min(a,b,c))
  print(s)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    if (b==0) return (int)1;
    int x = p(a, b>>1);
    if (b & 1) return m(x*m(a*x));
    return m(x*x);
}
signed main(){
    fast();
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(u == s)  a--;
    else if(u == t) b--;
    cout << a << " " << b <<endl;
} 

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
	os << "[ "; for(auto v : V) os << v << " "; return os << "]";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1> void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << endl;
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1<<" | ";
	__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mems(x, y) memset(x, y, sizeof(x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define irep(i, n) for (int i = 1; i <= n; ++i)
#define print(x) cout << x << '\n'
#define err(x) clog << x << '\n'
typedef long long ll;
#define int ll
typedef long double ld;
#define double ld
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 0x3f3f3f3f;
const int M = 1e9+7;
const int N = 1e5+5;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int n, k; cin >> n >> k;
	int h[n]; rep(i, n) cin >> h[i];

	int dp[n]; mems(dp, INF); dp[0] = 0;
	irep(i, n-1) irep(j, k) {
		if (i >= j) dp[i] = min(dp[i-j] + abs(h[i]-h[i-j]), dp[i]);
	}

	print(dp[n-1]);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<int> solve(const string& s){
  int r = 0, l;
  int odd = 0, even = 0;
  rep(i,s.size()){
    if(s[i] == 'R') r = i;
    if(i%2==0) even++;
    else odd++;
  }
  l = r+1;

  vector<int> res;
  rep(i,s.size()){
    if(i == r){
      if(i%2==0) res.push_back(even);
      else res.push_back(odd);
    }
    else if(i == l){
      if(i%2==0) res.push_back(even);
      else res.push_back(odd);
    }
    else res.push_back(0);
  }
  return res;
}


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

  vector<string> v;
  rep(i,S.size()){
    int j = i;
    string tmp = "R";
    while(j+1<S.size() && S[j+1]=='R'){
      j++;
      tmp += "R";
    }
    while(j+1<S.size() && S[j+1]=='L'){
      j++;
      tmp += "L";
    }
    v.push_back(tmp);
    i = j;
  }

  vector<int> ret;
  rep(i,v.size()){
    vector<int> res = solve(v[i]);
    rep(j,res.size()){
      ret.push_back(res[j]);
    }
  }

  rep(i,ret.size()){
    if(i>0) cout << " ";
    cout << ret[i];
  }
  cout << endl;
  
  return 0;
}



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

ll n,a,b;
vector<ll> h(100001);
//N回爆発させたとして
bool bin(ll N)
{
	vector<ll> H = h;
	ll c =  a-b;
	ll cnt = 0;
	for(ll i = 0;i<n;i++)
	{
		H[i] = H[i]-N*b;
	}
	for(ll i =0;i<n;i++)
	{
		if(H[i]>0)
		{
			cnt+=(H[i]+c-1)/c;
		}
	}

	if(N<cnt)
	{
		return false;
	}
	return true;
}

int main()
{
	
	cin >> n >> a >> b;
	
	for(ll i =0;i<n;i++)
	{
		cin >> h[i];
	}
	ll  l =-1,r=1e9+1;
	while(1)
	{
		ll mid = (l+r)/2;
		if(bin(mid))
		{
			r = mid;
		}
		else
		{
			l = mid;
		}
		if(r-l<2)break;
	}
	cout<<r<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long[] a = sc.LongArray();

        Dictionary<long, long> dic = new Dictionary<long, long>();

        foreach (var num in a)
        {
            if (dic.ContainsKey(num))
            {
                dic[num]++;
            }
            else
            {
                dic.Add(num, 1);
            }
        }

        long eat = 0;

        long even = 0;

        foreach (var item in dic)
        {
            var count = item.Value;
            if (item.Value >= 2)
            {
                var num = (count - 1) / 2;
                eat += num;
                count -= num * 2;
                if (count == 2)
                {
                    even++;
                }
            }
        }

        eat += (even + 1) / 2;

        long answer = n - eat * 2;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 41152
N,M=gets.split.map(&:to_i)

h={}

M.times do
    a,b=gets.split.map(&:to_i)
    h[a] ||= []
    h[a] << b
    h[b] ||= []
    h[b] << a
end

a=Array.new(N+1,true)
q=[[1,0]]
until q.empty?
    x,d = q.shift
    a[x] = false
    if x == N && d <= 2
        puts 'POSSIBLE'
        exit 0
    end
    (h[x]||[]).each do |n|
        next if !a[n]
        q << [n,d+1]
    end
end

puts 'IMPOSSIBLE'

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

int main(){
  int n;
  cin >> n;
  vector<ll> a(n+1), b(n);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];

  ll sum = 0;
  rep(i, n){
    if(b[i] > a[i]){
      sum += a[i];
      b[i] -= a[i];
      a[i] = 0;
      if(b[i] > a[i+1]){
        sum += a[i+1];
        b[i] -= a[i+1];
        a[i+1] = 0;
      }
      else{
        sum += b[i];
        a[i+1] -= b[i];
      }
    }
    else{
      sum += b[i];
      a[i] -= b[i];
    }
  }

  cout << sum << endl;

}


Measured memory_bytes: 1792
n=int(input())
s=input()
d={'R':0,'G':0,'B':0}
for i in s:
  d[i]+=1
ans=1
for i in d:
  ans*=d[i]
for k in range(n//2+1):
  for i in range(n-2*k):
    if len(set([s[i],s[i+k],s[i+2*k]]))==3:ans-=1
print(ans)

Measured memory_bytes: 73872
#include <bits/stdc++.h>
#include <limits>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define lli long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define um unordered_map
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define mem(data_structure, val) memset(data_structure, val, sizeof(data_structure))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl "\n"
const ll mod = 1e9+7;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 
um<pii, int, hash_pair> map_with_pair{};
priority_queue <int, vector<int>, greater<int> > pq_desc; // decreasing order

string lcs(string s, string t) {
	int s_size = s.size();
	int t_size = t.size();
	int dp[s_size+1][t_size+1];
	pii track[s_size+1][t_size+1];

	mem(dp, 0);

	Fo(i, 1, s_size+1) {
		Fo(j, 1, t_size+1) {
			if(s[i-1] == t[j-1]) {
				dp[i][j] = dp[i-1][j-1]+1;
				track[i][j] = mp(i-1, j-1);
			} else {
				if(dp[i-1][j] > dp[i][j-1]) {
					dp[i][j] = dp[i-1][j];
					track[i][j] = mp(i-1, j);
				} else {
					dp[i][j] = dp[i][j-1];
					track[i][j] = mp(i, j-1);
				}
			}
		}
	}

	string ans = "";
	int i = s_size, j = t_size;
	while(dp[i][j] != 0 && i>0 && j>0) {
		pii p = track[i][j];
		if(p.F == i-1 && p.S == j-1) {
			ans = s[i-1] + ans;
		}
		i = p.F;
		j = p.S;
	}

	return ans;
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string s, t;
	cin >> s >> t;

	string ans = lcs(s, t);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 105856