akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 105
int n, m, linky[N], mat[N][N];
bool A[N][N], vis[N];
vector<int>vec[N][N];
bool Dfs(int x)
{
	for (int i = 1; i <= n; i++)
	{
		if (!vis[i] && A[x][i])
		{
			vis[i] = 1;
			if (!linky[i] || Dfs(linky[i]))
			{
				linky[i] = x;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			int x;
			scanf("%d",&x);
			vec[i][(x - 1) / m + 1].push_back(x);
		}
	}
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
			for (int k = 1; k <= n; k++)
				A[j][k] = (!vec[j][k].empty());
		memset(linky, 0, sizeof(linky));
		for (int j = 1; j <= n; j++)
		{
			memset(vis, 0, sizeof(vis));
			Dfs(j);
		}
		for (int j = 1; j <= n; j++)
		{
			int k = linky[j];
			mat[k][i] = vec[k][j].back();
			vec[k][j].pop_back();
		}
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			printf("%d%c",mat[i][j], j == m ? 10 : 32);
	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= n; j++)
			for (int k = j + 1; k <= n; k++)
				if (mat[j][i] > mat[k][i])
					swap(mat[j][i], mat[k][i]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			printf("%d%c", mat[i][j], j == m ? 10 : 32);
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}
int GCD(int x, int y) {
	return x ? GCD(y % x, x) : y;
}

int main()
{
	string s;
	cin>>s;
	vector<int>num(3);
	int n=s.size();
	rep(i,n){
		int t=s[i]-97;
		num[t]++;
	}
	bool ans=false;
	if((num[0]==num[1]&&abs(num[2]-num[0])<=1) or (num[0]==num[2]&&abs(num[1]-num[0])<=1)
	 or(num[2]==num[1]&&abs(num[2]-num[0])<=1)){
		 ans=true;	
	}
	if(ans){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MAXN 1000000
#define MOD 1000000007
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int cnt;
typedef pair<int,int>p;
map<p,int>mp;
struct edge
{
    int to,cost;
};
vector<edge>v[100010*10];
int getid(int x,int y)
{
    p pp=make_pair(x,y);
    if(mp.count(pp))return mp[pp];
    mp[pp]=++cnt;
    return cnt;
}
int dis[100010*10];
void dijkstra()
{
    fill(dis+1,dis+cnt+1,INF);
    dis[1]=0;
    priority_queue<p,vector<p>,greater<p> >q;
    q.push(p(0,1));
    while(!q.empty())
    {
        p temp=q.top();
        q.pop();
        int w=temp.first;int id=temp.second;
        if(w>dis[id])continue;
        for(int i=0;i<v[id].size();i++)
        {
            edge &e=v[id][i];
            if(w+e.cost<dis[e.to])
            {
                dis[e.to]=w+e.cost;
                q.push(p(dis[e.to],e.to));
            }
        }
    }
}
int main()
{
    int n,m,x,y,z;
    scanf("%d%d",&n,&m);
    cnt=n;
    while(m--)
    {
        scanf("%d%d%d",&x,&y,&z);
        int temp1,temp2;
        temp1=getid(x,z);temp2=getid(y,z);
        v[x].push_back(edge{temp1,1});
        v[temp1].push_back(edge{x,1});
        v[temp1].push_back(edge{temp2,0});
        v[temp2].push_back(edge{temp1,0});
        v[temp2].push_back(edge{y,1});
        v[y].push_back(edge{temp2,1});
    }
    dijkstra();
    if(dis[n]==INF)printf("-1\n");
    else printf("%d\n",dis[n]/2);
    return 0;
}


Measured memory_bytes: 71804
import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
mod = 10**9 + 7

#maincode-------------------------------------------------

n = ini()
ans = 'No'
c = 0
for i in range(n):
    a,b = inm()
    if a == b:
        c += 1
    else:
        c = 0
    if c >= 3:
        ans = 'Yes'

print(ans)

Measured memory_bytes: 9348
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  int n, m;
  cin >> n >> m;
  set<int> candidates;
  vector<int> nums(n, 1);
  candidates.insert(0);
  rep(i, m) {
    int x, y; cin >> x >> y; x--; y--;
    if (candidates.find(x) != candidates.end()) {
      if (nums[x] == 1) {
        candidates.erase(x);
      }
      candidates.insert(y);
    }
    nums[x]--;
    nums[y]++;
  }

  cout << candidates.size() << endl;

  return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,l;cin >> n >> l;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }
    int t=-1;
    REP(i,n-1){
        if(a[i]+a[i+1]>=l) t=i+1;
    }
    if(t==-1){
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    FOR(i,1,t){
        cout << i << endl;
    }
    FORR(i,n-1,t){
        cout << i << endl;
    }
}

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

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repr(i,a,b) for(int i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x),end()
typedef long long ll;

int N;

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

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 1005;

// gcd
ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}
bool pal(int x)
{

    deque<int> q;
    while ( x > 0)
    {
        int r = x  % 10;
        q.push_back(r);
        
        x /= 10;
    }
    while ( q.size() > 1)
    {
        int a = q.front();
        int b = q.back();
        q.pop_back();
        q.pop_front();
        if ( a != b)
            return false;
    }
    return true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    int a, b;
    cin >> a >> b;
    int ans = 0;
    for ( int i= a; i <= b; i++)
    {
        if( pal(i))
            ans ++;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
ll a[100005];
ll b[100005];
priority_queue<int> q;
ll total_a;
ll total_b;

int main()
{
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		total_a += a[i];
	}
	for (int i = 0;i < n;i++) {
		cin >> b[i];
		total_b += b[i];
	}

	if (total_a < total_b) {
		cout << -1 << endl;
		return 0;
	}

	ll needed = 0;
	int ans = 0;

	for (int i = 0;i < n;i++) {
		if (b[i] > a[i]) {
			needed += (b[i] - a[i]);
			ans++;
		}
		else if (b[i] < a[i]) {
			q.push(a[i] - b[i]);
			ans++;
		}
		else continue;
	}

	while (needed > 0) {
		ll top = q.top();
		q.pop();
		needed -= top;
	}

	cout << ans - q.size() << endl;

	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <sstream>
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

string m_replace(string str, string replaced) {
    string::size_type find = 0;

    while ((find = str.find('X', find)) != string::npos) {
        str.replace(find, replaced.size(), replaced);
    }

    return str;
}


void cal(string& op1, string& op2, string& ans) {
    stringstream ss;

    for (int i = 0; i <= 9; i++) {
        ss << i;
        const string is = ss.str();

        string n = m_replace(op1, is), m = m_replace(op2, is);
        string a = "";

        // short
        unsigned int n_size = n.size();
        // long
        unsigned int m_size = m.size();

        if (m_size < n_size) {
            swap(n, m);
            swap(n_size, m_size);
        }

        while (n_size != m_size) {
            n.insert(0, "0");
            n_size = n.size();
        }

        int c = 0;
        for (int j = n_size - 1; 0 <= j; --j) {
            // clear
            ss.str("");

            int n1 = n[j] - '0';
            int n2 = m[j] - '0';
            int add = (n1 + n2 + c);
            ss << (add % 10);
            c = add / 10;

            a.insert(0, ss.str());
        }

        if (c != 0) {
            a.insert(0, "1");
        }
        // std::cout << a << std::endl;
        // std::cout << n << std::endl;
        // std::cout << m << std::endl;

        if (a == m_replace(ans, is)) {
            std::cout << i << std::endl;
            return;
        }

        // sstream clear
        ss.str("");
    }

    std::cout << "NA" << std::endl;
}


int main(void) {
    string exp;
    while (cin >> exp) {
        string::size_type t, u;
        t = u = exp.find_first_of('+', 0);

        string op1(exp, 0, u);
        u = exp.find_first_of('=', t);

        string op2(exp, t + 1, u - t - 1);
        string ans(exp, u + 1, exp.size());

        cal(op1, op2, ans);
    }

    return 0;
}

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

typedef long long ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> pii;
typedef tuple<ll,ll,ll> tii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef map<ll,ll> mi;
typedef map<pii,ll> mii;


#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define rep(i,a,b) for(int i = a; i < b; i++)
ll mod=1000000007;
#define PI 3.141592653589793238

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n/2;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    IOS

    ll n;
    cin>>n;

    for(int i=0;i<=200;i++)
    {
        for(int j=-200;j<=200;j++)
        {
            if(i*i*i*i*i-j*j*j*j*j==n)
            {
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }

    cout<<-1<<endl;
    
    return 0;
}

Measured memory_bytes: 3600
import java.util.Arrays;
import java.util.Scanner;

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

        int N;
        String S;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            S = sc.next();
        }
        char[] carr = S.toCharArray();
        int[] west = new int[N];
        int[] east = new int[N];

        int sum = 0;
        for (int i = 0; i < N; i++) {
            west[i] = sum;
            if (carr[i] == 'W') {
                sum++;
            }
        }
        sum = 0;
        for (int i = N - 1; i >= 0; i--) {
            east[i] = sum;
            if (carr[i] == 'E') {
                sum++;
            }
        }
        int result = Integer.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            if (west[i] + east[i] < result) {
                result = west[i] + east[i];
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 31036
#include "bits/stdc++.h"
using namespace std;

// #include "debug.h"
#define debug(...) 42


using ll = long long;

void solve() {
   int n;
   cin >> n;
   vector <int> v(n);
   for(int i = 0; i < n; i++) {
      cin >> v[i];
   }

   sort(v.begin(), v.end());
   int a, b;
   a  =  v.back();
   double min_diff = a;
   for(int i = 0; i < n - 1; i++) {
      if(abs(v[i] - a / 2) < min_diff) {
         min_diff = abs(v[i] - a / 2.0);
         b = v[i];
      }
   }
   cout << a << " " << b << endl; 
} 

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


Measured memory_bytes: 3696
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

void get_turn(const string& s, int i, vector<int>& place, vector<int>& turn)
{
    if (place[i] != -1)
    {
        return;
    }
    if (s[i] == 'R')
    {
        if (s[i] == s[i + 1])
        {
            get_turn(s, i + 1, place, turn);
            place[i] = place[i + 1];
            turn[i] = turn[i + 1] + 1;
        }
        else
        {
            place[i] = i;
            turn[i] = 0;
        }
    }
    else
    {
        if (s[i] == s[i - 1])
        {
            get_turn(s, i - 1, place, turn);
            place[i] = place[i - 1];
            turn[i] = turn[i - 1] + 1;
        }
        else
        {
            place[i] = i;
            turn[i] = 0;
        }
    }
}

int main()
{
    string s;
    cin >> s;
    const int n = s.size();
    vector<int> place(n, -1);
    vector<int> turn(n, -1);

    for (int i = 0; i < n; i++)
    {
        if (place[i] == -1)
        {
            get_turn(s, i, place, turn);
        }
    }
    vector<int> count(n, 0);
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
        {
            count[turn[i] % 2 == 0 ? place[i] : (place[i] + 1)]++;
        }
        else
        {
            count[turn[i] % 2 == 0 ? place[i] : (place[i] - 1)]++;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (i > 0)
        {
            cout << " ";
        }
        cout << count[i];
    }
    cout << endl;
}


Measured memory_bytes: 6528
S = input()

l = 0

for i in range(len(S)+1):
    for j in range(i,len(S)+1):
        if(( \
            (S[i:j].count('A')) + \
            (S[i:j].count('C')) + \
            (S[i:j].count('G')) + \
            (S[i:j].count('T')) \
            ) == len(S[i:j])):
            if(len(S[i:j]) > l):
                l = len(S[i:j])

print(l)


Measured memory_bytes: 38256
#include <iostream>
using namespace std;
static const int N = 100;

int main(){
    int M[N][N]; // 0?????????????????£??\??????
    int n, u, k, v;
    
    cin >> n;
    
    for( int i = 0; i < n; i++){
        for( int j = 0; j < n; j++) M[i][j] = 0;
    }
    
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        u--; // 0?????????????????????
        for( int j = 0; j < k; j++){
            cin >> v;
            v--; // 0?????????????????????
            M[u][v]  = 1; //u??¨v?????????????????????
        }
    }
    
    for ( int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if (j) cout << " "; // j = 0??\???????????????????????\?????§?????????????????\??????
            cout << M[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <map>
#include <set>
#include <string>
#include<string.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=55;
int n,m;
int a[maxn],b[maxn];
bool graph[maxn][maxn];
bool vis[maxn];

void dfs(int v){
    vis[v]=true;
    for(int v2=0;v2<n;++v2){
        if(graph[v][v2]==false) continue;
        if(vis[v2]==true) continue;
        dfs(v2);
    }
}

int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
    int ans=0;
    for(int i=0;i<m;i++){
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
        for(int j=0;j<n;j++){
            vis[j]=false;
        }
        dfs(0);
        bool bridge=false;
        for(int i=0;i<n;i++){
            if(!vis[i]) bridge=true;
        }
        if(bridge) ans++;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#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 arr[32] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int k;
  cin >> k;

  cout << arr[k - 1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n,k,Q,a[N];
priority_queue<int> q;
vector<int> v;
void update()
{
	while(!q.empty())
	{	
		if(q.size()>=k)
			v.push_back(-q.top());
		q.pop();
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k>>Q; 
	for(int i=1;i<=n;i++)	cin>>a[i];
	int res=2e9;
	for(int i=1;i<=n;i++)
	{
		int mn=a[i];
		for(int j=1;j<=n;j++)
		{
			if(a[j]>=mn)
				q.push(-a[j]);
			else
				update();	
		}
		update();
		if(v.size()>=1)
			sort(v.begin(),v.end());
		if(v.size()>=Q&&v[0]==mn)
			res=min(res,v[Q-1]-mn);
		v.clear();
	}
	cout<<res<<'\n';
	return 0;
} 

Measured memory_bytes: 384
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    N = int(input())
    C = list(input())
    ans1 = C.count('W')
    ans2 = C.count('R')
    ans = min(ans1, ans2)
    if not ans:
        print(ans)
        return

    ans3 = 0
    l = 0
    r = N-1
    while l<r:
        if C[l] == 'W' and C[r] == 'R':
            ans3 += 1
            l += 1
            r -= 1
            continue
        elif C[l] == 'R':
            l+=1
        elif C[r] == 'W':
            r-=1
    print(min(ans, ans3))

if __name__ == "__main__":
    run()

Measured memory_bytes: 10700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>

using namespace std;

int gcd(int n, int m) {
    if (n == 0) return m;
    return gcd(m % n, n);
}

int bit_count(int i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = (i + (i >> 4)) & 0x0f0f0f0f;
    i = i + (i >> 8);
    i = i + (i >> 16);
    return i & 0x3f;
}

int main() {
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n, m, ans = 0;
    cin >> n >> m;
    vector<int> l(m), r(m);
    for(int i = 0; i < m; ++i){
        cin >> l.at(i) >> r.at(i);
    }
    sort(l.rbegin(), l.rend());
    sort(r.begin(), r.end());
    for(int i = 1; i <= n; ++i){
        if(i >= l.at(0) && i <= r.at(0)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3996
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
prev = -1
r = 0
ans = 0
for t in T:
    if prev > 0 and t - prev > K:
        prev = t
        r = 1
        ans += 1
    elif prev < 0:
        prev = t
        ans += 1
        r = 1
    else:
        r += 1

    if r == C:
        prev = -1
        r = 0


print(ans)


Measured memory_bytes: 7512
// 18:36 -> 18:58 = 22min
#include <bits/stdc++.h>
#define REP(i, n, s) for (int i = (s); i < (n); i++)
#define SIZE 1
using namespace std;
typedef long long int LL;
typedef long double LD;

set<int> D;

int _max(int n) {
	int res = -1;
	REP(i, 10, n) {
		if (D.count(i) == 0) {
			res = i;
			break;
		}
	}
	return res;
}

int main() {
	int N, K, d, logV;
	vector<int> v;
	scanf("%d %d", &N, &K);
	REP(i, K, 0) {
		scanf("%d", &d);
		D.insert(d);
	}
	for (logV = 1; logV <= N; logV *= 10) {
		v.push_back((N%(logV*10))/logV);
	}
	reverse(v.begin(), v.end());

	vector<int> r;
	r.push_back(0);
	bool chk = false;
	REP(i, v.size(), 0) {
		int res = _max((chk)? 0 : v[i]);
		if (res != v[i]) chk = true;
		if (res == -1) {
			chk = true;
			int _i = i;
			while(1) {
				r[_i]++;
				if (_max(r[_i]) == -1) {
					r[_i] = _max(0);
					_i--;
				} else {
					r[_i] = _max(r[_i]);
					break;
				}
			}
			r.push_back(_max(0));
		} else {
			r.push_back(res);
		}
	}

	if (r[0] > 0) cout << r[0];
	for (int i = 1; i < r.size(); i++) cout << r[i];
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
// parameter "input" gets all data
function Main(input) {
	// the first line is assigned to input[0], the second line is assigned to input[1] similarly.

  var first_word = input.slice(0, 4).toUpperCase();
  var second_word = input.slice(4, 12).toUpperCase();
	//output
	console.log(first_word + ' ' + second_word);
}
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 6904
x,k,d = map(int, input().split())
x = abs(x)
a= x//d
b = x%d
if a>=k:
  print(x-k*d)
  exit(0)
c = abs(b-d)
if (k-a)%2==0:
  print(b)
else:
  print(c)

Measured memory_bytes: 61856
#include <bits/stdc++.h>
using namespace std;
int main(){
    int K,S,sum=0;
    cin>>K>>S;
    for(int i=0;i<K+1;i++){
        for(int j=0;j<K+1;j++){
            int z=S-i-j;
                if(0<=z && z<K+1){
                    sum++;
                }
            }
        }
cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  string S;
  cin >> N >> S;
  int white[N] = {0};
  int black[N] = {0};
  if (S[0] == '.') {
    white[0] = 1;
    black[0] = 0;
  }
  else {
    white[0] = 0;
    black[0] = 1;
  }
  for (int i = 1; i < N; i++) {
    if (S[i] == '.') {
      white[i] = white[i - 1] + 1;
      black[i] = black[i - 1];
    }
    else {
      white[i] = white[i - 1];
      black[i] = black[i - 1] + 1;
    }
  }
  int ans = 11451419;
  for (int i = 0; i < N; i++) {
    ans = min(ans,black[i] + white[N - 1] - white[i]);
  }
  ans = min(ans,white[N - 1]);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
    long long n;
    cin >> n;
    vector<long long> d(n);
    for (long long i = 0; i < n; ++i) cin >> d[i];
    sort(d.begin(), d.end());
    cout << d[n / 2] - d[n / 2 - 1] << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 1024
N = int(input())
x = list(map(int, input().split()))
x_s = sorted(x)
m_l, m_r = x_s[N // 2 - 1], x_s[N // 2]
d = dict()
for i, s in enumerate(x_s):
    if i < N // 2:
        d[s] = m_r
    else:
        d[s] = m_l
for i in x:
    print(d[i])

Measured memory_bytes: 34824
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

void solve(){
  int N,Y;
  cin>>N>>Y;
  rep(i,N+1){
    if (10000*i>Y)break;
    if (Y-10000*i>5000*(N-i))continue;
    rep(j,N-i+1){
      if (10000*i+5000*j>Y)break;
      else if (Y-10000*i-5000*j>1000*(N-i-j))continue;
      else if (Y==10000*i+5000*j+1000*(N-i-j)){
        cout<<i<<' '<<j<<' '<<N-i-j;
        return;
      }
    }
  }
  cout<<-1<<' '<<-1<<' '<<-1;
  return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-9
using namespace std;
int n, k;
int memo[100005];
int arr[100005];
int solve(int stones){
    if(stones == 0)
        return 1;
    int &ans = memo[stones];
    if(ans != -1)
        return ans;
    for(int i = 0; i < n; ++i){
        if(arr[i] > stones)
            continue;
        if(solve(stones-arr[i]) == 1){
            return ans = 0;
        }
    }
    return ans = 1;
}
int main(){
    IO;
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
        cin >> arr[i];
    memset(memo, -1, sizeof memo);
    cout << (!solve(k) ? "First" : "Second");

    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
	int n, d, x;
	cin >> n >> d >> x;
	vector<int> A(n);

	for(int i = 0; i < n; i++){
		cin >> A[i];
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		int temp = 0;
		int j= 1;
		ans++;
		temp = A[i] * j + 1;
		j++;
		while(temp <= d){
//			cout << temp << endl;
			temp = A[i] * j + 1;  
			ans++;
			j++;
		}
	}
	ans += x;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.lang.Math.*

fun main(args: Array<String>?): Unit {
    while(true) {
        val n = readLine()!!.trim().toInt()
        if (n == 0) break
        val vertex = Array(n){
            val (x, y) = readLine()!!.trim().split(' ').map(String::toDouble)
            Point(x, y)
        }
        val angles = vertex.indices.map{i ->
            val h = (i + n - 1) % n
            val j = (i + 1) % n
            val ih = (vertex[h] - vertex[i]).toVec().toAngle()
            val ij = (vertex[j] - vertex[i]).toVec().toAngle()
            AngleRange(vertex[i], ij, ih)
        }
        val lines = vertex.indices.map{i -> Line(vertex[i], vertex[(i + 1) % n])}
        val crossPoint = lines.indices.flatMap{i -> (0 until i).mapNotNull{j -> lines[i].crossPoints(lines[j])}}
        println(
                if (crossPoint.any{p -> angles.all{a -> a.contains(p)}}) 1 else 0
        )
    }
}
const val EPSILON: Double = 1e-9
data class AngleRange(val origin: Point, val min: Angle, val max: Angle) {
    private val rad = (max - min).toRad()
    operator fun contains(that: Point): Boolean {
        return ((that - origin).toVec().toAngle() - min).toRad().let{a -> (a in (-EPSILON .. rad + EPSILON) || (a - PI * 2) in (-EPSILON .. rad + EPSILON))}
    }
}
data class Angle(val sin: Double, val cos: Double) {
    fun toRad(): Double = Math.atan2(sin, cos).let{if (it < 0) it + 2 * PI else it}
    operator fun minus(that: Angle): Angle = Angle(sin * that.cos - cos * that.sin, cos * that.cos + sin * that.sin)
}
data class Point(val x: Double, val y: Double) {
    operator fun minus(that: Point): Point = Point(x - that.x, y - that.y)
    fun toVec(): Vector = Vector(x, y)
}
data class Vector(val x: Double, val y: Double){
    val length: Double
        get() = sqrt(x * x + y * y)
    fun toAngle(): Angle {
        val len = length
        return Angle(y / len, x / len)
    }
}
class Line(private val a: Double, private val b: Double, private val c: Double) {
    private constructor(ax: Double, dy: Double, ay: Double, dx: Double):this(ay, -ax, ax * dy - ay * dx)
    constructor(pa: Point, pb: Point):this(pa.x - pb.x, pb.y, pa.y - pb.y, pb.x)
    fun crossPoints(that: Line): Point? {
        val d = a * that.b - b * that.a
        return if (abs(d) < 1e-9) {
            null
        }
        else {
            Point((b * that.c - c * that.b) / d, (c * that.a - a * that.c) / d)
        }
    }
}



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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b+c >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

const int inf = 1e9 + 10;
int n, a, b, c;
long long ans;
bool fl;

bool cmp(int a, int b) {return a > b;}

int main()
{
    scanf("%d", &n); c = inf;
    for(int i = 1; i <= n; ++i)
    {
        scanf("%d%d", &a, &b);
        if (a != b) fl = 1;
        ans += a;
        if (a > b) c = min(c, b);
    }
    if (fl) printf("%lld\n", ans - c); else puts("0");
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

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

    int sum = 0;
    for(int i = n; i > 0; i /= 10){
        sum += i % 10;
    }

    bool ans = n % sum == 0;
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
int main()
{
   double a,b,c8,c0,d8,d0;
   cin>>a>>b;
   int ans;
   for(int i=1;i<1000000;++i)
   {
   	ans=i;
   	if(i*2>=a*25&&i>=b*10&&i*2<(1+a)*25&&i<(1+b)*10)
   	{
   		
   		break;
   	}
   	if(i==1000000-1)ans=-1;
   }
   cout<<ans;
  }


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long long n,a[100005],b[100005],c[100005],f1[100005],f2[100005],f3[100005];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld %lld",&a[i],&b[i],&c[i]);
	}
	f1[1]=a[1];
	f2[1]=b[1];
	f3[1]=c[1];
	for(int i=2;i<=n;i++)
	{
		f1[i]+=a[i]+max(f2[i-1],f3[i-1]);
		f2[i]+=b[i]+max(f1[i-1],f3[i-1]);
		f3[i]+=c[i]+max(f1[i-1],f2[i-1]);
	}
	printf("%lld",max(f1[n],max(f2[n],f3[n])));
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>

using namespace std;

struct card {
	int num;
	char ch;
};

void show(card cd[], int n) {
	for (int i = 0; i < n - 1; i++)
		cout << cd[i].ch<<cd[i].num << " ";
	cout << cd[n - 1].ch<< cd[n - 1].num << endl;
}
void insertionSort(card cd[],int n) {
	int j;
	card v;
	for (int i = 1; i < n; i++) {
		v = cd[i];
		j = i - 1;
		while (j >= 0 && cd[j].num > v.num) {
			cd[j + 1] = cd[j];
			j--;
		}
		cd[j + 1] = v;
	}
}

void stable(card cd_1[], card cd_2[], int n) {
	int i = 0;
	while (cd_1[i].ch == cd_2[i].ch) {
		if (i >= n - 1)
			break;
		i++;
	}
	if (i == n - 1)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
}

void bubbleSort(card cd[], int n) {
	bool f = true;
	while (f) {
		f = false;
		for (int i = n - 1; i >= 1; i--)
			if (cd[i].num < cd[i - 1].num) {
				swap(cd[i],cd[i-1]);
				f = true;
			}
	}
}

void selsctionSort(card cd[], int n) {
	int minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = i + 1; j < n; j++) {
			if (cd[j].num < cd[minj].num)
				minj = j;
		}
		if (i != minj) {
			swap(cd[i], cd[minj]);
		}
	}
}

int main() {
	card cd[100];
	card cd_m[100];
	card cd_t[100];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> cd[i].ch >> cd[i].num;
		cd_t[i] = cd_m[i] = cd[i];
	}

	insertionSort(cd_m, n);

	bubbleSort(cd, n);
	show(cd, n);
	stable(cd, cd_m, n);

	for (int i = 0; i < n; i++)
		cd[i] = cd_t[i];

	selsctionSort(cd, n);
	show(cd, n);
	stable(cd, cd_m, n);
	return 0;
}

Measured memory_bytes: 1160
import random 

def dice_move(a,s): 

    if s=="E": 

        return [a[3],a[1],a[0],a[5],a[4],a[2]] 

    elif s=="S": 

        return [a[4],a[0],a[2],a[3],a[5],a[1]] 

    elif s=="W": 

        return [a[2],a[1],a[5],a[0],a[4],a[3]] 

    elif s=="N": 

        return [a[1],a[5],a[2],a[3],a[0],a[4]] 

     

n=int(input()) 

a=[list(map(int,input().split())) for _ in range(n)] 

h=("N","W","S","E") 

judge=[True]*n 

cnt=0 

for i in range(30000): 

    num=random.randrange(4) 

    a[0]=dice_move(a[0],h[num]) 

    for i in range(1,n): 

        if judge[i] and a[0]==a[i]: 

            cnt+=1 

            judge[i]=False 

print("Yes" if cnt==0 else "No") 


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

int main() {
  int A, B;
  char op;
  
  cin >> A >> op >> B;
  
  if ( op == '+' ) {
  	cout << A + B << endl;
  }
  else if ( op == '-' ) {
  	cout << A - B << endl;
  }
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	if N%2 == 0 {
		fmt.Println(1.0 / 2)
	} else {
		var odd int
		for i := 1; i <= N; i++ {
			if i%2 != 0 {
				odd++
			}
		}
		fmt.Println(float64(odd) / float64(N))
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc046/tasks/abc046_b

int main() {
    int N, K;
    cin >> N >> K;

    printf("%d\n", (int)(K * pow(K-1, N-1)));

    return 0;
}


Measured memory_bytes: 256
L = list(map(int,list(input())))
num = len(L)
mod = 10 ** 9 + 7

dp1 = [0] * num
#AおよびBの値の上からk桁目(k>=0)までを確定させ、その時点で
#既にA+BがL以下であることが分かっているような値組(A, B)の個数
dp2 = [0] * num
#AおよびBの値の上からk桁目(k>=0)までを確定させ、その時点では
#まだA+BがL以下になるかどうか分かっていないような値組 (A, B) の個数

dp1[0] = 1 #(A,B)=(0,0)
dp2[0] = 2 #(A,B)=(1,0),(0,1)

for i in range(1,num):
    if L[i] == 1:
        dp1[i] = dp1[i-1] * 3 + dp2[i-1]
        dp2[i] = dp2[i-1] * 2
    else:
        dp1[i] = dp1[i-1] * 3
        dp2[i] = dp2[i-1]
    dp1[i] %= mod
    dp2[i] %= mod

print((dp1[num-1] + dp2[num-1])%mod)

Measured memory_bytes: 11672
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

const int mod=1000000007;
struct mint{
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const{return mint(-x);}
  mint& operator+=(const mint a){
    if((x+=a.x)>=mod) x-=mod;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x+=mod-a.x)>=mod) x-=mod;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=mod;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a=pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }

  // for prime mod
  mint inv() const{
    return pow(mod-2);
  }
  mint& operator/=(const mint a){
    return (*this)*=a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

map<ll,ll> pfmp; //各素因数の冪指数の総和を格納
vector<ll> pfv(0); //異なる素因数を昇順に格納

void PF(ll N){
  ll n=N;
  if(n<=0) return;
  if(n%2==0){
    if(pfmp[2]==0) pfv.push_back(2);
    while(n%2==0){
      n/=2;
      pfmp[2]++;
    }
  }
  if(n==1) return;
  for(ll i=3;i<=sqrt(N);i+=2){
    if(n%i==0){
      if(pfmp[i]==0) pfv.push_back(i);
      while(n%i==0){
        n/=i;
        pfmp[i]++;
      }
    }
  }
  if(n!=1){
    if(pfmp[n]==0) pfv.push_back(n);
    pfmp[n]++;
  } 
  sort(all(pfv));
}

const int MAX=200001; //nCrのnのMAX+1
ll 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;
  }
}
ll 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;
}
//Add COMinit(); in main function.

int main(){
  COMinit();
  int N,M; cin >> N >> M;
  PF(M);
  mint ans=1;
  for(auto c:pfmp){
    ans*=COM(N-1+c.second,N-1);
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vvi vector<vector<int>>;
#define mi  map<int,int>
#define mii map<pii,int>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(x) (int)x.size()
#define all(v) (v).begin(), (v).end()
#define ret(x) return cout<<x,0;
#define rety return cout<<"YES",0;
#define retn return cout<<"NO",0;
#define fl fflush(stdout)   
#define hell 1000000007  
#define hell2 998244353 
#define pi 3.14159265358979323846

int solve(){
    int n,w,a,b;
    cin>>n>>w;vii v;
    rep(i,0,n){
        cin>>a>>b;
        v.pb({a,b});
    }
    int dp[100005];
    memset(dp,0,sizeof dp);
    rep(i,0,n){
        repn(j,100002,0){
            if(j+v[i].ff<100005)dp[j+v[i].ff]=max(dp[j+v[i].ff],dp[j]+v[i].ss);
        }
        //rep(j,0,20)cout<<dp[j]<<" ";
       // cout<<"\n";
    }
    cout<<dp[w];
    return 0;
}

signed main(){
    IOS;
    int t=1;
   
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
} 

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll X, A;
    cin >> X >> A;
    if(X < A) cout << 0;
    else cout << 10;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3600
#pragma GCC optimize("O3")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef unsigned long long parallel_type;
const int bit_width=8*sizeof(parallel_type);

int main(){
	int H,W;
	for(;~scanf("%d%d",&H,&W)&&H&&W;){
		vector<string>m(H);
		for(int h=0;h<H;h++)cin>>m[h];
		if(H<=21){
			vector<vector<parallel_type> >l(H);
			int parallel_width=(W+bit_width-1)/bit_width;
			for(int h=0;h<H;h++){
				l[h].resize(parallel_width);
				for(int w=0;w<W;w++)l[h][w/bit_width]|=parallel_type(m[h][w]=='1')<<(w%bit_width);
			}
			int R=0;
			for(int i=0;i<1<<H;i++){
				vector<parallel_type> v(parallel_width);
				int r=0;
				for(int j=0;j<H;j++)if(i>>j&1){
					r++;
					for(int k=0;k<parallel_width;k++)v[k]^=l[j][k];
				}
				if(none_of(v.begin(),v.end(),[](parallel_type e){return e;}))R=max(R,r);
			}
			cout<<R<<endl;
		}else{
			vector<int>b(H);
			for(int h=0;h<H;h++){
				for(int w=0;w<W;w++)b[h]=(b[h]<<1)|(m[h][w]=='1');
			}
			vector<short>s(1<<W),t(1<<W);
			for(int w=1;w<1<<W;w++)s[w]=-1;
			for(int h=0;h<H;h++){
				for(int w=0;w<1<<W;w++){
					t[w]=max(s[w],short(s[w^b[h]]>=0 ? 1+s[w^b[h]] : -1));
				}
				swap(s,t);
			}
			cout<<s[0]<<endl;
		}
	}
}

Measured memory_bytes: 19504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
#define all(x) x.begin(),x.end()
const int inf=0x3f3f3f3f;

int N,dp[200010][64];
ll K;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>N>>K;
	for(int i=1;i<=N;i++) cin>>dp[i][0];
	for(int j=1;j<64;j++) for(int i=1;i<=N;i++) dp[i][j]=dp[dp[i][j-1]][j-1];
	int ans=1;
	for(int j=0;j<64;j++) if(K&(1LL<<j)) ans=dp[ans][j];
	cout<<ans;
	return 0;
}

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

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator &itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() {return i;}
  Iterator &end() {return n;}
};

template<class T> T at(vector<T> v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

typedef int Weight;
struct Edge {
  int from, to;
  Weight weight;
  Edge(int from, int to, Weight weight) :
    from(from), to(to), weight(weight) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

Matrix adjacency(const Graph &graph) {
  int n = graph.size();
  Matrix distance(n, Array(n, 1e9));
  for (const Edges &edges : graph) for (const Edge &edge : edges) {
    distance[edge.from][edge.to] = edge.weight;
  }
  return distance;
}

void debug(const Graph &g) {
  for (const Edges &es : g) for (const Edge &e : es) {
    cerr << e.from << " " << e.to << " " << e.weight << endl;
  }
}

#include <algorithm>

bool visit(const Graph &g, int v, vector<int> &order, vector<int> &color) {
  color[v] = 1;
  for (const Edge &e : g[v]) {
    if (color[e.to] == 2) continue;
    if (color[e.to] == 1) return false;
    if (!visit(g, e.to, order, color)) return false;
  }
  order.emplace_back(v);
  color[v] = 2;
  return true;
}

bool topologicalSort(const Graph &g, vector<int> &order) {
  vector<int> color(g.size(), 0);
  order.clear();
  for (int u : range(g.size())) if (!color[u] && !visit(g, u, order, color)) return false;
  reverse(order.begin(), order.end());
  return true;
}

bool dp[100000][100];

int main() {
  int v, e, w;
  cin >> v >> e >> w;
  Graph graph(v), graph_r(v);
  for (int i : range(e)) {
    int s, t, c;
    cin >> s >> t >> c;
    graph[s].emplace_back(s, t, c);
    graph_r[t].emplace_back(t, s, c);
  }
  vector<int> order;
  topologicalSort(graph, order);
  reverse(order.begin(), order.end());
  for (int i : range(v)) dp[i][0] = true;
  int res = -1000;
  for (int i : range(v)) {
    int t = order[i];
    for (const auto &edge : graph_r[t]) {
      for (int j : range(100)) if (dp[t][j]) {
        if (j + edge.weight + w < 0) res = max(res, j + edge.weight + w);
        if (j + edge.weight < 100)  dp[edge.to][j + edge.weight] = true;
      }
    }
  }
  if (res == -1000) cout << "NA" << endl;
  else cout << res << endl;
}


Measured memory_bytes: 43400
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

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

def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# a_list = [0] * a
sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    n = get_int()
    s = ""
    for _ in range(n):
        s += "ACL"

    print(s)


if __name__ == '__main__':
    main()

Measured memory_bytes: 10984