akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))//数组(结构体)清零 
#define ll long long
//int A(int a,int b){if(a<b||a<1||b<0)return 0;int k=1;while(b--){k*=a--;}return k;}//数学中的Aab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
//int C(int a,int b){if(a<b||a<1||b<0)return 0;b=min(a-b,b);int k=A(a,b),t=1;while(--b)k/=++t;return k;}//数学中的Cab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
//int HW(char*HWa,int HWl,int HWr){if(HWr<HWl)swap(HWl,HWr);for(int i=0;i<(HWr-HWl)/2+1;i++)if(HWa[HWl+i]!=HWa[HWr-i])return 0;return 1;}//传递字符串名,判断区间l r,如果是回文字符串就返回1,否则返回0 
//int SS(int a){if(a>4&&((a-1)%6)&&((a+1)%6))return 0;for(int i=2;i<=sqrt(a);i++)if(a%i==0)return 0;return 1;}//判断一个数是不是质数，是1 否0；请确保a>1; 
/*记得如果改int为long long,就把printf与scanf中相应的%d也改成%lld*/
//char c[200010];
//bool b[200010];
//int main()
//{
//	int n,i,k,C,s,j,flag;//共n天 ,一次隔C天，共需要k天 
//	scanf("%d%d%d%s",&n,&k,&C,c);
//	//int ge=C+1;
//	for(i=0;i<n;i++)
//	{
//		if(c[i]=='o')b[i]=1;
//	}
//	//for(i=0;i<n;i++)cout<<b[i]<<"***\n";//**********
//	for(i=0;i<n;i++)
//	{
//		bool t=b[i];
//		b[i]=0;//如果这天不工作 
//		for(flag=0,s=0,j=0;j<n;j++)
//		{
//			//printf("j=%d,",j);//*************
//			if(b[j])s++,j+=C;//结束循环后j++，正好C+1
//			//printf("s=%d\n",s);//************
//			if(s>=k) {flag=1;break;}
//		}
//		//printf("i=%d,flag=%d\n",i,flag);//*******
//		if(!flag)printf("%d\n",i+1);
//		b[i]=t;
//	}
//	return 0;
//}
int p[200010];
char c[200010];
int main()
{
	int n,C,k,j,i;
	cin>>n>>k>>C>>c;
	if(C)
	{
		for(j=k-1,i=n-1;j>=0;i--)
		{
			if(c[i]=='o')
			{
				if(c[i]=='o')
					p[j--]=i,i-=C;
			}
		}
		//printf("j=%d\n",j);//**********
		for(i=j=0;j<k;i++)
		{
			if(c[i]=='o')
			{
				if(p[j++]==i)
					printf("%d\n",i+1);
				i+=C;
			}
		}
	}
	else
	{
		int sum=0;
		for(i=0;i<n;i++)
		if(c[i]=='o')
			sum++;
		if(sum==k)
		for(i=0;i<n;i++)
		{
			if(c[i]=='o')
				printf("%d\n",i+1);
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
	int a,b;
	char s[9];
	int ans = 0;
	scanf("%d%d",&a,&b);
	for(int i = a; i <= b; i++){
		int ge = i%10;
		int shi = (i/10)%10;
		int bai = (i/100)%10;
		int qian = (i/1000)%10;
		int wan = (i/10000)%10;
		if(ge == wan && shi == qian) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
#include <functional>
#include <map>
#include <set>
using namespace std;
const long INF = 1000000009;

int x, y, z;
int main(){
	scanf("%d%d%d", &x, &y, &z);
	printf("%d\n", (x-z)/(y+z));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> e(100001), o(100001);
    REP(i, 0, N) {
        int v; cin >> v;
        if (i % 2 == 0) {
            e[v]++;
        } else {
            o[v]++;
        }
    }

    vector<pair<int, int>> E, O;
    REP(i, 0, 100001) {
        if (e[i] > 0) {
            E.push_back(make_pair(e[i], i));
        }
        if (o[i] > 0) {
            O.push_back(make_pair(o[i], i));
        }
    }

    sort(ALL(E), greater<pair<int, int>>());
    sort(ALL(O), greater<pair<int, int>>());
    int ans;
    if (E[0].second != O[0].second) {
        ans = (N / 2 - E[0].first) + (N / 2 - O[0].first); 
    } else {
        ans = (N / 2 - E[1].first) + (N / 2 - O[0].first); 
        ans = min(ans, (N / 2 - E[0].first) + (N / 2 - O[1].first)); 
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2044
/* Filename: ARC084C.java
 * Author: Mushiyo
 */

import java.util.Scanner;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		while(input.hasNext()){
			int N = input.nextInt();
			int[] A = new int[N];
			int[] B = new int[N];
			int[] C = new int[N];
			
			for(int i = 0; i < A.length; ++i){
				A[i] = input.nextInt();
			}
			
			for(int i = 0; i < B.length; ++i){
				B[i] = input.nextInt();
			}
			
			for(int i = 0; i < C.length; ++i){
				C[i] = input.nextInt();
			}
			
			Arrays.sort(A);
			Arrays.sort(B);
			Arrays.sort(C);
			
			long[] CLargerB = new long[N];
			for(int b = 0 , c = 0; b < B.length; ++b){
				while(c < C.length && C[c] <= B[b]){
					++c;
				}
				
				CLargerB[b] = C.length - c;
			}
			
			for(int i = C.length - 1; i > 0; --i){
				CLargerB[i - 1] += CLargerB[i];
			}
			
			long ways = 0;
			for(int a = 0, b = 0; a < A.length; ++a){
				while(b < B.length && B[b] <= A[a]){
					++b;
				}
				
				if(b < B.length){
					ways += CLargerB[b];
				}
			}
			
			System.out.println(ways);
		}
	}

}


Measured memory_bytes: 97272
#include <stdio.h>

int main() {
        int N, A, B[100000];
        int i;

        scanf("%d", &N);
        for(i = 0; i < N; i++) {
                scanf("%d", &A);
                B[A-1] = i+1;
        }

        for(i = 0; i < N; i++) {
                printf("%d ", B[i]);
        }
        printf("\n");

        return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5 + 1e5;
int n,t,k,m;
char s[N];
LL ans;
int main()
{
	cin>>n>>k;
	cin>>s;
	for(int i=1;i<=n;i++)
	{
		if(s[i]==s[i-1])m++;
	}
	cout<<min(n-1,m+2*k);

}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int R;
	cin >> R;
	
	if (R < 1200)
	{
		cout << "ABC" << endl;
	}
	else if (R < 2800)
	{
		cout << "ARC" << endl;
	}
	else
	{
		cout << "AGC" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int point[200100];
vector<vector<int>> vec(200100);

int n,q;

bool dfs(int a,int b) {
  for(auto x: vec[a]){
    if(x==b) continue;
    point[x] += point[a];
    dfs(x,a);
  }
}

int main() {
  cin >> n >> q;
  FOR(i,0,n-2){
    int a,b; cin >> a >> b;
    --a; --b;
    vec[a].PB(b);
    vec[b].PB(a);
  }
  FOR(i,0,q-1){
    int p,x; cin >> p >> x;
    --p;
    point[p] += x;
  }
  dfs(0,0);
  FOR(j,0,n-1) cout << point[j] << " ";
    cout << "\n";
  
  

}



Measured memory_bytes: 23424
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            if (str.Contains("a") && str.Contains("b") && str.Contains("c"))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

// THINK: INT vs LONG LONG?

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

	ll ans = 1;
	int a, b;
	cin >> a >> b;
	int c, d;
	cin >> c >> d;

	// neg, neg - choose most negative
	ans = max({(ll) a * c, (ll) a * d, (ll) b * c, (ll) b * d});
	cout << ans << endl;
	// ll p1 = (ll) a * c;
	// ll p2 = (ll) a * d;
	// ll p

	return 0;
}

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


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

    if(b/a>c) cout<<c<<endl;
    else cout<<b/a<<endl;
        
    return 0;
}



Measured memory_bytes: 256
# coding: utf-8
A, B = map(int, input().split())
S = input()
num_list = list(map(str, list(range(0, 10, 1))))
ans_cnt = A + B + 1
cnt = 0
for i, s in enumerate(S):
    if i == A:
        if s == "-":
            cnt += 1
    else:
        if s in num_list:
            cnt += 1
if cnt == ans_cnt:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<string> s(N);
	for (string& i : s) {
		cin >> i;
		sort(i.begin(), i.end());
	}
	long a = 0, ans = 0;
	sort(s.begin(), s.end());
	for (int i = 1; i < N; ++i) {
		if (s[i - 1] == s[i]) ++a;
		else {
			ans += (1 + a) * a / 2;
			a = 0;
		}
	}
	ans += (1 + a) * a / 2;
	cout << ans;
}

Measured memory_bytes: 7296
$N=<>;
($a,$b,$c)=split($",<>),$$a{$b}=$$b{$a}=$c for 1..$N-1;
($Q,$K)=glob<>;
@q=$K;
while($q=shift@q){
	$d[$_]or$d[$_]=$d[$q]+$$q{$_},push@q,$_ for keys%$q;
}
($x,$y)=split,print$d[$x]+$d[$y],$/for<>

Measured memory_bytes: 121344
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define c2(n,m) cin>>n>>m
#define c3(n,m,k) cin>>n>>m>>k
#define c4(n,m,k,l) cin>>n>>m>>k>>l
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b,c,d,e;
  c3(a,b,c);
  long x[3];
  x[0]=a; x[1]=b; x[2]=c;
  sort(x,x+3);
  if(a%2==0 || b%2==0 || c%2==0) co(0);
  else co(x[0]*x[1]);
  return 0;
}


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

int main(){
    int n, ma = -1000000, mi = 1000000, tmp;
    long long int su = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%d", &tmp);
        su += tmp;
        ma = max(ma, tmp);
        mi = min(mi, tmp);
    }
    printf("%d %d %lld\n", mi, ma, su);
    return 0;
}


Measured memory_bytes: 2744
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    int n,k ;
    cin >> n >> k ;
    vector<int> a(n) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    int ans = 0 ;
    for (size_t i = 0; i < n; i++)
    {
        if (a.at(i) >= k)
        {
            ans ++ ;
        }
        
    }
    cout << ans << endl ;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

struct UnionFind {
    UnionFind(int n) : p(n, -1) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    int size(int u) {
        return -p[root(u)];
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
    }
    vector<int> p;
};
int main() {
    cout << fixed << setprecision(10);
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind u(n);
    vector<vector<int>> f(n);
    vector<vector<int>> block(n);
    vector<int> ans(n);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        u.unite(a,b);
        f[a].push_back(b);
        f[b].push_back(a);
    }

    REP(i, k) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        block[a].push_back(b);
        block[b].push_back(a);
    }

    REP(i, n) {
        int ans = u.size(i)-1-f[i].size();
        for (auto& fac : block[i])
        {
            if (u.same(fac, i)) {
                ans--;
            }
        }
        cout << ans<<" ";
    }
    return 0;
}

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

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> A)
{
    set<long long> set;
    bool isDuplicate = 0;

    for (long long i = 0; i < N; i++)
    {
        auto it = set.insert(A[i]);
        if (it.second == false)
        {
            isDuplicate = 1;
            cout << "NO" << endl;
            break;
        }
    }

    if (isDuplicate == 0)
    {
        cout << "YES" << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	int q = 0, n, k; std::string s; std::cin >> n >> k >> s;
	for (int i = 0; i < n; ++i) s[i] -= 'A';
	while (q < n && k) {
		--k;
		if ((s[q] ^ q) & 1) ++q; else s[q] ^= 1;
	}
	if (k) {
		if (n & 1) std::cout << char('A' + (k & 1));
		for (int i = 1; i < n; i += 2) std::cout << "BA";
	} else {
		for (int i = q; i < n; ++i) std::cout << char(((s[i] ^ q) & 1) + 'A');
		for (int i = 0; i < q; ++i) std::cout << char('B' - (q - i & 1));
	}
	std::cout << '\n';
	return 0;
}

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

int main(){
	string a;
	string b;
	cin >> a;
	cin >> b;
	if(a.size() != b.size()){
		cout << "No" << endl;
		return 0;
	}
	for(int i = 0; i < a.size(); i++){
		char z = a[0];
		a.erase(a.begin());
		a.push_back(z);
		if(a == b){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
	A = int(input())
	B = int(input())
	C = int(input())
	X = int(input())
	ans = 0
	for i in range(A+1):
		five_h = 500*i
		if five_h > X:
			break
		for j in range(B+1):
			one_h = 100*j
			if five_h + one_h > X:
				break
			for k in range(C+1):
				fifty = 50*k
				total = five_h + one_h +fifty
				if total > X:
					break
				if total == X:
					ans += 1
	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(d.begin(),d.end());
    vector<int> v(24);
    rep(i,n){
        if(d[i] == 0){
            cout << 0 << endl;
            return 0;
        }
        if(i&1) v[d[i]]++;
        else v[24-d[i]]++;
    }
    rep(i,24){
        if(v[i] >= 2){
            cout << 0 << endl;
            return 0;
        }
    }
    int before = 0;
    int ans = 24;
    rep(i,24){
        if(v[i]){
            ans = min(ans,i-before);
            before = i;
        }
    }
    ans = min(ans,24-before);
    cout << ans << endl;
} 




Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;

int main(void) {
	int count = 0;
	string str;
	cin >> str;

	for (int i = 0; i < 3; i++) {
		if (str[i] == '1')
			count++;
	}


	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int k;

        if(a>=13){
            k=b;
        }else if(a>=6){
            k=b/2;
        }else{
            k=0;
        }

        System.out.println(k);

    }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	int[][] map;
	int w;
	int h;
	int sx = -1;
	int sy = -1;
	int gx = -1;
	int gy = -1;
	public Main() {
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			map = new int[h][w];
			
			if(h==0 && w==0)
				break;
			
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					map[i][j] = sc.nextInt();
					if(map[i][j] == 2){
						sx = j;
						sy = i;
					}else if(map[i][j] == 3){
						gx = j;
						gy = i;
					}
				}
			}
//			System.out.println(sx + " "+sy);
			solve();
		}
	}

	public void solve() {
		int res = rec(0, sx, sy);
		System.out.println(res>=100 ? -1 : res);
	}

	int[] dx = { -1, 0, 1, 0 };
	int[] dy = { 0, -1, 0, 1 };
	private int rec(int n, int x, int y) {
		if(n>=10)
			return 100;
		
		int res = 100;
		for(int i=0;i<4;i++){
			int nx = x+dx[i];
			int ny = y+dy[i];
			if(nx<0 || w<=nx || ny<0 || h<=ny || map[ny][nx]==1)
				continue;
			
			while(!(nx<0 || w<=nx || ny<0 || h<=ny || map[ny][nx]==1)){
				if(map[ny][nx]==3)
					return n+1;
				nx += dx[i];
				ny += dy[i];
				
			}
			
			if(nx<0 || w<=nx || ny<0 || h<=ny)
				continue;
			nx -= dx[i];
			ny -= dy[i];
			
			map[ny+dy[i]][nx+dx[i]] = 0;
			res = Math.min(res, rec(n+1, nx, ny));
			map[ny+dy[i]][nx+dx[i]] = 1;
		}
		
		
		return res;
	}

}

Measured memory_bytes: 37260
n = gets.to_i
a = n.times.map{gets.split.map(&:to_i)}

cnt = 0
flag = 0
ans = 0
for i in 0..(n-1)
  if flag == 0
    if a[i][0] == a[i][1]
      cnt = 1
      flag = 1
    end
  else
    if a[i][0] == a[i][1]
      cnt += 1
    else
      flag = 0
      cnt = 0
    end
    if cnt == 3
      ans = 1
      break
    end
  end
end
(ans == 1) ? (puts "Yes"):(puts "No")

Measured memory_bytes: 14404
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
def Yes(x):print("Yes")if x==True else print("No")

D=N()
c=[0]+L()
s=[[0]*27]+[[0]+L() for i in range(D)]

dp=[]
T=[0]
ld=[0]*(27)
for i in range(1,D+1):
    ma=0
    t=0
    for j in range(1,27):
        tmp=s[i][j]+(i-ld[j])*(D-i+1)*c[j]
        if tmp>ma:
            ma=tmp
            t=j
    T.append(t)
    ld[t]=i
        
sc=sum(c)
def point():
    ld=[0]*(27)
    score=-sc*((D+1)*D//2)
    for i in range(1,D+1):
        t=T[i]
        score+=s[i][t]+(i-ld[t])*(D-i+1)*c[t]
        ld[t]=i
    return score

now=point()
import random
for i in range(8000):
    d,q=random.randrange(1,D+1),random.randrange(1,27)
    old=T[d]
    T[d]=q
    new=point()
    if new>now:
        now=new
    else:
        T[d]=old

for i in T[1:]:
    print(i)

Measured memory_bytes: 79808
let list_of_str s = let rec f i = if i >= String.length s then [] else s.[i] :: f (i+1) in f 0
let rec solve t xs ys zs =
  if t = 'a'      then match xs with [] -> "A" | (x::xs') -> solve x xs' ys zs
  else if t = 'b' then match ys with [] -> "B" | (y::ys') -> solve y xs ys' zs
  else                 match zs with [] -> "C" | (z::zs') -> solve z xs ys zs'
let () = Scanf.scanf "%s %s %s" (fun a b c ->
  solve 'a' (list_of_str a) (list_of_str b) (list_of_str c)) |> print_endline


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
int N, ans;
char str[200010];
int main()
{
	scanf("%d", &N);
	scanf("%s", str);
	int l = 0, r = strlen(str)-1;
	int len = strlen(str);
	while(l<=r)
	{
		while(str[r]!='R'&&r>l)
		    r--;
		while(str[l]!='W'&&l<r)
		    l++;
	    str[r] = 'W';
	    str[l] = 'R';
	    if(l!=r)
	        ans++;
	    r--;
	    l++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1892
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 550;
const int maxm = 2e5+50;
const int inf = 1e9;

int block[maxn];
int a[maxn][maxn];
int b[maxn][maxn];
struct node
{
    int l, r;
    int id;
    friend bool operator < (node a, node b)
    {
        if (block[a.l] != block[a.r]) return block[a.l] < block[b.l];
        return a.r < b.r;
    }
} st[maxm];
int ans[maxm];

int main()
{
    int n, m, q;
    scanf("%d %d %d", &n, &m, &q);
    int B = sqrt(n + 0.5);
    for (int i = 1; i <= n; ++i)
        block[i] = i / B;
    for (int i = 0; i < m; ++i)
    {
        int l, r;
        scanf("%d %d", &l, &r);
        a[l][r] ++;
        if (l != r) a[r][l] ++;
    }
    for (int i = 1; i <= n; ++i)
    {
        b[i][i] = a[i][i];
        for (int j = i+1; j <= n; ++j)
            b[i][j] = b[i][j-1] + a[i][j];
        for (int j = i-1; j >= 1; --j)
            b[i][j] = b[i][j+1] + a[i][j];
    }
    for (int i = 0; i < q; ++i)
    {
        st[i].id = i;
        scanf("%d %d", &st[i].l, &st[i].r);
    }
    //sort(st, st + q);
    int L = 1, R = 0;
    int sum = 0;
    for (int i = 0; i < q; ++i)
    {
        while (R < st[i].r) sum += b[++R][L];
        while (L > st[i].l) sum += b[--L][R];
        while (R > st[i].r) sum -= b[R--][L];
        while (L < st[i].l) sum -= b[L++][R];
        ans[st[i].id] = sum;
    }
    for (int i = 0; i < q; ++i)
        printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>

int main()
{
    int a,b,d,r;
    double f;
    
    scanf("%d%d",&a,&b);
    d = a / b;
    r = a % b;
    f = 1.0 * a / b;
    printf("%d %d %f\n", d,r,f);
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    ll N, K; cin >> N >> K;
    ll sum = 0;
    repi(i,K,N+2) {
        ll l = (ll)(i-1)*i/2;
        ll r = N*(N+1)/2 - (N-i)*(N-i+1)/2;
        (sum += r - l + 1) %= MOD;
    }
    cout << sum << endl;
    return 0;
}


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

const int MAX = 666667;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int x;
  int y;

  cin >> x >> y;

  int a = 2 * x - y;
  int b = x - 2 * y;

  if (a < 0 || b > 0) {
    cout << 0 << endl;
  } else if (a % 3 !=0 || b % 3 != 0) {
    cout << 0 << endl;
  } else {
    int k = a / 3;
    int l = (-1) * b / 3;

    COMinit();
  
    cout << COM(k + l, k) << endl;
  }

  return 0;
}

Measured memory_bytes: 15872
import math

n=int(input())
A=list(map(int,input().split()))
A.sort()
m=10**6+10
C=[0]*m
C[0]=-1
ans=0
now=0
flag=0
for a in A:
    if now!=a:
        flag=0
        now=a
    if now==a and flag:
        flag=0
        ans-=1
        continue
    if C[a]==0:
        ans+=1
        flag=1
        j=a
        while j<m:
            C[j]=1
            j+=a

print(ans)

Measured memory_bytes: 105940
def monster(X):
    global cnt
    if(X!=0):
        cnt+=1
        monster(X//2)
        




import sys
H=int(input())
cnt=0
if(H==1):
    print('1')
else:
    i=2
    j=3
    tmp=1
    while (True):
        if(i <= H and j >= H):
            print(j)
            sys.exit()
        i*=2
        j=j*2+1
        
        
        


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
string s;
int cntR[N], cntL[N];
int ans[N];

int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> s;
	n = s.length();
	cntR[0] = 1, cntL[n-1] = 1;
	for(int i=1; i<n; i++) {
		if (s[i] == 'R') cntR[i] = 1 + cntR[i-1];
		else cntR[i] = 0;
		if (s[n-1-i] == 'L') cntL[n-1-i] = 1 + cntL[n-1-i+1];
		else cntL[n-1-i] = 0;
	}
	
	for(int i=1; i<n; i++){
		if (cntR[i] == 0 && cntR[i-1]>0){
			ans[i-1] = (cntR[i-1] + 1)/2 + cntL[i]/2;
			ans[i] = cntR[i-1] + cntL[i] - ans[i-1];
		}
	}	
	for(int i=0; i<n; i++) {
		cout << ans[i] << ' ';
	}
	cout << endl;
	return 0;
}


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

int main() {
	int x, y, ans = 0;
	cin >> x >> y;
	ans += max(abs(x), abs(y)) - min(abs(x), abs(y));
	if (x >= 0) {
		if (y > 0) {
			if (x > y) ans += 2;
		}
		else {
			ans++;
		}
	}
	else {
		if (y > 0) {
			ans++;
		}
		else {
			if (x > y) ans += 2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// header {{{
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    26
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)
#define INF         1000000005

typedef long long ll;
typedef unsigned long long ull;
// }}}

int main() {
    ll n;cin >> n;
    ll t, a;cin >> t >> a;
    for(ll i=1;i<n;i++){
        ll tt, aa;cin >> tt >> aa;
        for(ll j=max(t/tt, a/aa);;j++){
            if(tt*j >= t && aa*j >= a){
                t = tt*j;
                a = aa*j;
                break;
            }
        }
    }
    printf("%lld\n", t+a);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int l = sc.nextInt(); int r = sc.nextInt(); int d = sc.nextInt();
        int ans = 0;
        for (int i = l; i <= r; i++) if (i % d == 0) ans++;
        out.println(ans);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 32792
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
  int n;
  cin >> n;
  vector<P> an(n);
  for(int i=0; i<n; ++i){
    cin >> an[i].first;
    an[i].second = i;
  }
  sort(an.begin(),an.end());
  int ans = 0;
  for(int i=0; i<n; ++i){
    int x = an[i].second - i;
    if(x%2 != 0) ++ ans;
  }
  ans /= 2;
  cout << ans << endl;
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
int main(){
  int n;cin >>n;
  string s;
  unordered_map<string,ll> m;
  for(int i=0;i<n;i++){
    cin >> s;sort(s.begin(),s.end());
    
    if(m.count(s)>0)m[s]++;
    else m[s]=1;
  }
  ll ans=0;
  for(auto it=m.begin();it!=m.end();it++){
    if(it->second==1)continue;
    ll tmp=it->second;
    ans+=tmp*(tmp-1)/(ll(2));
  }
  cout << ans << endl;
}

  
  

Measured memory_bytes: 10660
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

B=[[0]*W for _ in range(H)]

C=[0]
for a in A:
    C.append(C[-1]+a)
K=0
X,Y=0,0
D=1
while K<H*W:
    K+=1

    B[Y][X]=D

    if Y%2:
        if X==0:
            Y+=1
        else:
            X-=1
    else:
        if X==W-1:
            Y+=1
        else:
            X+=1

    if K==C[D]:
        D+=1

L=[" ".join(map(str,P)) for P in B]
print("\n".join(L))


Measured memory_bytes: 74292
#include <iostream>

using i64 = long long;

const i64 MOD = 1000000007;
const int N = 600 + 3;

int n;
int a[N], v[N], u[N];
i64 f[2][N][N], ans;

void init() {
	static int b[N], c[N];
	scanf("%d", &n);
	for (int i = 1; i <= n << 1; ++i) scanf("%d", c + i);
	for (int i = 1; i <= n; ++i)
		if (~c[2 * i - 1] && ~c[2 * i]) b[c[2 * i - 1]] = b[c[2 * i]] = 1;
	for (int i = 1; i <= 2 * n; ++i)
		b[i] += b[i - 1];
	int m = 0;
	for (int i = 1; i <= n; ++i) {
		if (~c[2 * i - 1] && ~c[2 * i]) continue;
		a[++m] = ~c[2 * i - 1] ? c[2 * i - 1] - b[c[2 * i - 1]] : -1,
		a[++m] = ~c[2 * i] ? c[2 * i] - b[c[2 * i]] : -1;
	}
	n = m / 2;
}

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	init();
	if (!n) return printf("1"), 0;
	for (int i = 1; i <= n << 1; ++i)
		if (~a[i]) v[a[i]] = 1;
	f[1][0][0] = 1;
	for (int i = 2 * n; i; --i)
		for (int j = 0; j <= n; ++j)
			for (int k = 0; k <= n; ++k) {
				if (v[i]) {
					if (j) ( f[i & 1][j - 1][k] += f[i & 1 ^ 1][j][k] ) %= MOD;
					( f[i & 1][j][k + 1] += f[i & 1 ^ 1][j][k] ) %= MOD;
				} else {
					if (j) ( f[i & 1][j - 1][k] += f[i & 1 ^ 1][j][k] ) %= MOD;
					if (k) ( f[i & 1][j][k - 1] += f[i & 1 ^ 1][j][k] * k ) %= MOD;
					( f[i & 1][j + 1][k] += f[i & 1 ^ 1][j][k] ) %= MOD;
				}
				f[i & 1 ^ 1][j][k] = 0;
			}
	ans = f[1][0][0];
	for (int i = 1, j = 0; i <= n; ++i)
		if (a[2 * i - 1] == -1 && a[2 * i] == -1) ans = ans * ++j % MOD;
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 6684
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

double dp[301][301][301];
int N;

double f(int n1, int n2, int n3) {
    double &re = dp[n1][n2][n3];
    if (re > -1)RT re;
    re = 0;
    if (n1 + n2 + n3 == 0)RT re;

    const int M = n1 + n2 + n3;
    // ループ脱出までの期待値
    re += N;
    if (n1 > 0)re += f(n1 - 1, n2, n3)*n1;
    if (n2 > 0)re += f(n1 + 1, n2 - 1, n3)*n2;
    if (n3 > 0)re += f(n1, n2 + 1, n3 - 1)*n3;
    re /= M;
    RT re;
}

void solve() {
    rep(i, 301)rep(j, 301)rep(k, 301)dp[i][j][k] = -2;

    cin >> N;
    int C[3] = {};
    rep(i, N) {
        int a;
        cin >> a;
        C[--a]++;
    }

    cout << f(C[0], C[1], C[2]) << endl;
}

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


Measured memory_bytes: 213376
#!/usr/bin/python3
# coding: utf-8

# 整数 > 整数型
def I(): return int(input())

# 整数列 '1 2 3 4' > 整数型リスト
def IsIl(): return list(map(lambda x: int(x), input().split()))

# 改行挟む整数列　'1/n 2/n 3/n' > 整数型りすと
def InIl(n): return [input() for i in range(n)]

# 整数列 '1 2' > 整数型タプル
def IsIt(): return map(lambda x: int(x), input().split())

# 改行挟む整数列　'1\n 2\n 3\n' > 整数型たぷる
def InIl(n): return map(input() for i in range(n))

# 文字列 'abcd' > 文字型リスト
def SsSl(): return list(map(lambda x: x, input()))

# 整数 '1234' > 整数型リスト

# 文字列 'aba' > 辞書（文字型:個数）{'a':2,'b':1}
def SSd():
    from collections import defaultdict
    A = input() # [int(i) for i in input().split()]
    dd=defaultdict(int)
    for a in A:
        dd[a]+=1
    return dd

import math

n=I()

nmax = int(n**0.5)
for i in reversed(range(nmax)):
    if n%(i+1) == 0:
        print(int(n/(i+1))+(i-1))
        break


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

using namespace std;
 

int main() {
     int N;
     cin>>N;int sum=0,i=0;
     for( i=0;;i++)
     {
         sum+=i;
         if(sum>=N) break;
         
     }
    
    cout<<i<<endl;
	 
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int r,c,i,j;
	int a[102][102]={0};
	scanf("%d %d",&r,&c);
	
	for(i=1;i<=r;i++){
		for(j=1;j<=c;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(i=1;i<=r;i++){
		for(j=1;j<=c;j++){
		 a[r+1][j]+=a[i][j];
		 a[i][c+1]+=a[i][j];
		 a[r+1][c+1]+=a[i][j];
		}
	}
		
		
	for(i=1;i<=r+1;i++){
		for(j=1;j<=c+1;j++){
		if(j==c+1){
			printf("%d",a[i][j]);
		}else{
			printf("%d ",a[i][j]);
		}
		
	}printf("\n");
	}

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,m,x;
  cin>>n>>m>>x;

  vll c(n);
  vvll a(n,vll(m));
  REP(i,n){
    cin>>c[i];
    REP(j,m)
      cin>>a[i][j];
  }

  ll ans=LLINF;
  REP(bit,(1<<n)){
    vll rikai(m);
    ll sum=0;
    REP(j,n){
      if((bit>>j)&1){
        sum+=c[j];
        REP(k,m)
          rikai[k]+=a[j][k];
      }
    }

    bool flag=true;
    REP(k,m){
      if(rikai[k]<x)
        flag=false;
    }

    if(flag)
      ans=min(ans,sum);
  }

  if(ans==LLINF)
    ans=-1;

  cout<<ans<<endl;
}



Measured memory_bytes: 3576
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define Rep(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SMALLPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000007;
const int mod=1000000007;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
int main(){
  int n,k,ans=0;cin>>n>>k;
  string s;cin>>s;
  if(s[0]=='L')ans++;
  if(s[n-1]=='R')ans++;
  rep(i,n-1)if(s[i]=='R'&&s[i+1]=='L')ans+=2;
  if(ans-2*k<=1)cout<<n-1<<endl;
  else cout<<n-(ans-2*k)<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
  string K = "keyence"; // 7文字
  string S, SS;
  cin >> S;
  int N = S.size(); // 文字列Sの長さを取得する
  if(N == 7){
    if(S == K){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }else{
    // substr(開始位置, 【取り出す長さ】) 部分文字列を取得する
    rep(i, 8){
      SS = S.substr(0, i) + S.substr(i+(N-7));
      if(SS == K){
        cout << "YES" << endl;
        return 0;
      }
    }
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN

import sys

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

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            if S.find(str(k), code2 + 1) != -1:
                ans += 1

print(ans)


Measured memory_bytes: 3060
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(m)]

l = sorted(A)[0]+sorted(B)[0]
for d in D:
    l = min(l, A[d[0]-1]+B[d[1]-1]-d[2])
print(l)


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

int main(){
  int n; cin >> n;
  int ans = 1000 - (n % 1000);
  if(ans == 1000) ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#ABC114C-755.py

N = int(input())

All753 = {"33","35","37","53","55","57","73","75","77"}


for i in range(9):
    list1 = {s+"3" for s in All753 if N >= int(s+"3")}
    list2 = {s+"5" for s in All753 if N >= int(s+"5")}
    list3 = {s+"7" for s in All753 if N >= int(s+"7")}
    All753 = All753 | list1 | list2 | list3

list = {s for s in All753 if "3" in s and "5" in s and "7" in s}

print(len(list))


Measured memory_bytes: 14344
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
int main() {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
 
long long t,n,a[200001];
 
bool check(int b,long long x){
  int l=b,r=b+n,m;
  while(l<r){
    m=(l+r)/2;
    if(a[m]-a[b]>=x)r=m;
    else l=m+1;
  }
  int d=l;
  r=min(n+d,2*n);
  while(l<r){
    m=(l+r)/2;
    if(a[m]-a[d]>=x)r=m;
    else l=m+1;
  } 
  if(l<b+n&&a[b+n]-a[l]>=x)return 1;  
  return 0;
}
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i],t+=a[i],a[i]=t;
  for(int i=0;i<n;i++)a[i+n]=a[i]+t;
  long long ans=-1;
  for(int i=0;i<n;i++){
    long long l=0,r=1e18,m;
    while(l<r){
      m=(l+r)/2;
      if(check(i,m))l=m+1;
      else r=m;
    }
    ans=max(ans,l-1);
  }
  cout<<ans<<endl;
  return 0;
}

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

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

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll a, b;
  cin >> a >> b;
  ll ans = 0;
  ll out = 1;
  while (out < b) {
    out--;
    out += a;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }


    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        Map<Integer, Map<Integer, Integer>> edges = new HashMap<>();
        for (int i = 0; i < N - 1; i++) {
            int[] e = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            if (!edges.containsKey(e[0])) {
                edges.put(e[0], new HashMap<>());
            }
            edges.get(e[0]).put(e[1], e[2]);
            if (!edges.containsKey(e[1])) {
                edges.put(e[1], new HashMap<>());
            }
            edges.get(e[1]).put(e[0], e[2]);
        }

        boolean[] c = new boolean[N + 1];

        Set<Integer> visited = new HashSet<>();
        Queue<Integer> q = new ArrayDeque<>();
        q.add(1);
        while (!q.isEmpty()) {
            int curr = q.poll();
            if (visited.add(curr)) {
                for (Map.Entry<Integer, Integer> e: edges.getOrDefault(curr, Collections.emptyMap()).entrySet()) {
                    int next = e.getKey();
                    int cost = e.getValue();
                    c[next] = (cost % 2 == 0) ? c[curr] : !c[curr];
                    q.add(next);
                }
            }
        }

        for (int i = 1; i < N + 1; i++) {
            System.out.println(c[i] ? 0 : 1);
        }

    }

}


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

int main() {
  char b;
  cin >> b;
  if (b == 'A')
    cout << 'T' << endl;
  else if (b == 'T')
    cout << 'A' << endl;
  else if (b == 'C')
    cout << 'G' << endl;
  else
    cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

typedef long long ll;
typedef long double ld;

template<typename T>
using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 2e3+3;
ll a[maxn][maxn];
vector<pair<ll,ll>> g[maxn][maxn];
pair<ll,ll> rofl(ll i, ll j){
    return mp(min(i,j), max(i,j));
}
ll used[maxn][maxn];
vector<pair<ll,ll>> topsort;
bool cycle = false;
void dfs(ll i, ll j){
    used[i][j] = 1;
    for(auto p : g[i][j]){
        ll ii = p.X; ll jj = p.Y;
        if(used[ii][jj] == 1){
            cycle = true;
            continue;
        }
        else if(used[ii][jj] == 2) continue;
        dfs(ii,jj);
    }
    used[i][j] = 2;
    topsort.push_back({i,j});
}
ll dp[maxn*maxn];
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n; cin >> n;
    for(ll i = 1;i<=n;i++){
        for(ll j = 0;j<n-1;j++){
            cin >> a[i][j];
        }
        for(ll j = 1;j<n-1;j++){
            auto p = rofl(i, a[i][j-1]);
            auto p1 = rofl(i, a[i][j]);
            g[p.X][p.Y].push_back(p1);
        }
    }
    for(ll i = 1;i<=n;i++){
        for(ll j = i+1;j<=n;j++){
            if(!used[i][j]) dfs(i,j);
        }
    }
    if(cycle){
        cout << -1;
        return 0;
    }
    else{
        reverse(all(topsort));
        ll ans = 0;
        map<pair<ll,ll>, ll>kek;
        for(ll i = 0;i<topsort.size();i++){
            kek[topsort[i]] = i;
        }
        for(ll i = 0;i<topsort.size();i++){
            auto p = topsort[i];
            for(auto p1 : g[p.X][p.Y]){
                dp[kek[p1]] = max(dp[kek[p1]], dp[i] + 1);
                ans = max(ans, dp[kek[p1]]);
            }
        }
        cout << ans + 1 << endl;
    }
    return 0;
}
/*

*/


Measured memory_bytes: 197608