akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll INF = ~(1<<31);
#define fs first
#define sc second
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
    return (a % b + b) % b;
}

ll memo[102][100'050];
ll n;
ll W[120];
ll V[120];

ll dp(ll at, ll weight) {
    if(at >= n) return 0;
    if(memo[at][weight] != -1) return memo[at][weight];
    ll mx = dp(at+1,weight);
    if(weight - W[at] >= 0) mx = max(mx, dp(at+1, weight - W[at])+V[at]);
    return memo[at][weight] = mx;
}

int main() {
    cin.sync_with_stdio(false);
    memset(memo,-1,sizeof(memo));
    ll w;
    cin >> n >> w;
    rep(i,0,n) {
        cin >> W[i] >> V[i];
    }
    cout << dp(0,w) << endl;
    return 0;
}



Measured memory_bytes: 80128
a=int(input())
b=int(input())
c=int(input())
x=int(input())

cnt=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                cnt+=1

print(cnt)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
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 MOD = 1e9+7;

vector<int> G[10010];
bool isvisit[10010];
map<int, int> K;
map<int, set<int> > Kinv;
int S[10010];

priority_queue<int, vector<int>, greater<int> > que;

void dfs(int v){
    isvisit[v] = true;
    for(auto x : G[v]){
        if(isvisit[x]) continue;
        dfs(x);
    }
    int c = que.top();
    que.pop();
    S[v] = c;
}

int A[10010];
int B[10010];

int main(){
    int N;
    cin >> N;
    REP(i,N-1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        A[i] = a;
        B[i] = b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    REP(i,N){
        int c;
        cin >> c;
        que.push(c);
    }

    dfs(0);

    ll ans = 0;
    REP(i,N-1){
        int a = A[i];
        int b = B[i];
        ans += min(S[a], S[b]);
    }

    cout << ans << endl;
    REP(i,N){
        printf("%d ", S[i]);
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 1408
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
    a: usize,
    b: usize
    }
    println!("{}", calc(a, b));
}

fn calc(a: usize, b: usize) -> usize {
    let af = a as f32;
    let bf = b as f32;
    f32::ceil((bf-1.0)/(af-1.0)) as usize
}

Measured memory_bytes: 4352
def resolve():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    ans = []
    for a in range(A + 1):
        for b in range(B + 1):
            c = (X - 500 * a - 100 * b) / 50
            if c <= C and c >= 0:
                ans.append((a, b, c))

    print((len(set(ans))))

    return

resolve()

Measured memory_bytes: 38896
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    ll N,D,A,X,H;
    vector<pair<ll,ll>> vec;
    vector<pair<ll,ll>> bomb;
    ll ans=0;
    ll temp_num;
    cin>>N>>D>>A;
    rep(i,N) {cin>>X>>H; vec.push_back(make_pair(X,H));}
    sort(vec.begin(),vec.end());
    // rep(i,N){
    //     X=vec[i].first;
    //     H=vec[i].second;

    //     out=0;
    //     rep(j,bomb.size()){
    //         pos=bomb[j].first;
    //         num=bomb[j].second;
    //         if(X<=pos+2*D){
    //             H-=num*A;
    //         }else out++;            
    //     }
    //     rep(j,out) bomb.erase(bomb.begin());

    //     if(H<=0) continue;
    //     else{
    //         bomb.push_back(make_pair(X,(H-1)/A + 1));
    //         ans+=(H-1)/A + 1;
    //     }
    // }
    // cout<<ans<<endl;
    temp_num=0;ans=0;
    ll hoge;
    rep(i,N){
        X=vec[i].first;
        H=vec[i].second;
        hoge=bomb.size();
        rep(j,hoge){
            if (bomb[0].first <X-2*D){
                temp_num-=bomb[0].second;
                bomb.erase(bomb.begin());
            }else break;
        }
        H-=temp_num*A;
        if(H<=0) continue;
        bomb.push_back(make_pair(X,(H-1)/A+1));
        temp_num+=(H-1)/A+1;
        ans+=(H-1)/A+1;
    }
    cout<<ans<<endl;
    return 0;
}

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

vector<int> av;
int c=0,dc=0,res=0;

void solve(int count,int sm){
    if(count == c){
        if(sm%10 == 0) res++;
        return;
    }

    for(auto x:av){
        if(count < dc){
            int t=2*x;
            if(t>=10){
                string s=to_string(t);
                t = s[0]-'0'+s[1]-'0';
            }
            solve(count+1,sm+t);
        }
        else solve(count+1,sm+x);
    }
}


int main(){
    int n,m,sum=0;
    string s;
    cin>>n>>s>>m;
    av.resize(m);
    for(auto& x:av) cin >> x;

    for(int i=0;i<n;i++){
        if(s[i] == '*'){
            c++;
            if((n-1-i) & 1) dc++;
        }else{
            int t=s[i]-'0';
            if((n-1-i) & 1){
                t*=2;
                if(t>=10){
                    string ss=to_string(t);
                    t = ss[1]-'0'+ss[0]-'0';
                }
            }
            sum += t;
        }
    }

    solve(0,sum);

    cout << res << endl;
}

Measured memory_bytes: 1368
def abc097_c():
    S = str(input())
    K = int(input())
    subs = set()

    for i in range(len(S)):
        for j in range(i+1, min(len(S)+1, i+K+1)):
            subs.add(S[i:j])

    subs_asc = sorted(list(subs))
    ans = subs_asc[K-1]
    print(ans)

abc097_c()

Measured memory_bytes: 4592
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
int MOD=1000000000+7;
int INF=1e6;

using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

int n,k,q;
int v[3000];
int GO(int f){
    vector<int> t;
    int pos=0;
    while(pos<n){
        while((v[pos]<f)&&pos<n){
            pos++;
        }
      	if(pos==n) break;
        vector<int> s;
        while(v[pos]>=f){
            s.push_back(v[pos]);
            pos++;
        }
        
        sort(s.begin(),s.end());
        int m=s.size();
        if(m-k+1>0){
        rep(i,s.size()-k+1){
            t.push_back(s[i]);
        }}
    }
    sort(t.begin(),t.end());
    if(t.size()<q) return 2000000000;
    return t[q-1];
}


main(){
    cin>>n>>k>>q;
    vector<int> p;
    rep(i,n){
        int a;
        cin>>a;
        v[i]=a;
        p.push_back(a);
    }
    v[n]=-1;
    sort(p.begin(),p.end());
    int ans=2000000000;
    rep(i,n){
        ans=min(ans,GO(p[i])-p[i]);

    }
    cout<<ans;
}

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

using namespace std;

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

    int x;
    cin >> x;
    vector<int> a(x);
    for (int i = 0; i < x; i++)cin >> a[i];
    int y;
    cin >> y;
    vector<int> b(y);
    for (int i = 0; i < y; i++)cin >> b[i];
    int z;
    cin >> z;
    vector<int> c(z);
    for (int i = 0; i < z; i++)cin >> c[i];

    int ret = 0;
    for (auto member:c) {
        bool nota = true;
        for (auto amem:a)
            if (member == amem)nota = false;
        bool foundb = false;
        for (auto bmem:b)
            if (member == bmem)foundb = true;

        if (nota || foundb)ret++;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 3080
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		boolean[] arg = null;
		int length=0,out=0;
        int i=0;
        boolean first=true;
        int[] score=null;
        boolean[] rui=new boolean[3];

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null ) {
            	if(first){
            		length=Integer.parseInt(line);
            		score=new int[length];
            		first=false;
            	}else{
            		if(line.equals("OUT")){
            			out++;
            		}else if(line.equals("HIT")){
            			if(rui[2]){
            				score[i]++;
            				rui[2]=false;
            			}
            			if(rui[1]){
            				rui[2]=true;
            				rui[1]=false;
            			}
            			if(rui[0]){
            				rui[1]=true;
            			}
            			rui[0]=true;
            		}else if(line.equals("HOMERUN")){
            			score[i]++;
            			for(int j=0;j<3;j++){
            				if(rui[j]){
            					score[i]++;
            				}
            				rui[j]=false;
            			}
            		}
            	}
            	if(out==3){
            		rui=new boolean[3];
            		i++;
            		for(int k=0;k<3;k++){
            			rui[k]=false;
            		}
            		out=0;
            		if(length==i){
            			break;
            		}
            	}

            }
            for(int k=0;k<score.length;k++){
            	System.out.println(score[k]);
            }
		}
	}
}

Measured memory_bytes: 24088
#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;

    int maxv = 0;
    vector<int> A(N);
    REP(i, 0, N) {
        cin >> A[i];
        maxv = max(maxv, A[i]);
    }

    int half = 0;
    REP(i, 0, N) {
        if (abs(maxv / 2 - half) > abs(maxv / 2 - A[i])) half = A[i];
    }

    cout << maxv << " " << half << endl;
    return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)
struct T{
	ll y,x,id;
};

ll W,H,N;
vector<ll> xs;
vector<ll> ys;
P p[100001];
const ll INF = 0xffffffffffffff;
P ansp;
ll ans;

ll calc(ll y,ll x){
	ll maxd=0;
	ll res=0;
	ll d;
	rep(i,N){
		d=abs(y-p[i].fr)+abs(x-p[i].sc);
		maxd=max(d,maxd);
		res+=2*d;
	}
	return res-maxd;
}

int main()
{
	cin>>W>>H>>N;
	rep(i,N){
		cin>>p[i].sc>>p[i].fr;
		ys.pb(p[i].fr);
		xs.pb(p[i].sc);
	}
	sort(xs.begin(),xs.end());
	sort(ys.begin(),ys.end());
	if(N%2==1){
		ans=calc(ys[N/2],xs[N/2]);
		ansp=P(ys[N/2],xs[N/2]);
	}
	else{
		ans=INF;
		ansp=P(0,0);
		ll nxt=calc(ys[N/2-1],xs[N/2-1]);
		if(ans>nxt){
			ans=nxt;
			ansp=P(ys[N/2-1],xs[N/2-1]);
		}
		nxt=calc(ys[N/2],xs[N/2-1]);
		if(ans>nxt){
			ans=nxt;
			ansp=P(ys[N/2],xs[N/2-1]);
		}
		nxt=calc(ys[N/2-1],xs[N/2]);
		if(ans>nxt){
			ans=nxt;
			ansp=P(ys[N/2-1],xs[N/2]);
		}
		nxt=calc(ys[N/2],xs[N/2]);
		if(ans>nxt){
			ans=nxt;
			ansp=P(ys[N/2],xs[N/2]);
		}
	}
	cout<<ans<<endl;
	cout<<ansp.sc<<" "<<ansp.fr<<endl;
}

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

using namespace std;
//int graph[100005][100005]; <-CompileError????????????????????????
vector<int> graph[100005];
int d[100005];
int color[100005];	
void bfs(int s, int n, int gpc){
	queue<int> Q;
	for(int i=0;i<n;i++){
		d[i] = 2e9;
	}
	color[s] = -1;
	d[s] = 0;
	Q.push(s);
	while(Q.size()!=0){
		int u = Q.front();
		Q.pop();
		for(int i=0;i<(int)graph[u].size();i++){
			int v = graph[u][i];
			if(color[v] == -2){
				color[v] = -1;
				d[v] = d[u] +1;
				Q.push(v);
			}
		}
		color[u] = gpc;
	}
}
void check(int n){
	int group = 0;
	for(int i=0;i<n;i++) color[i] = -2;
	for(int u=0;u<n;u++){
		if(color[u] == -2)bfs(u, n, group++);
	}
}

int main(){
	int n, m;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int num;
		int tmp;
		cin >> num >> tmp;
		graph[num].push_back(tmp);
		graph[tmp].push_back(num);
	}
	check(n);
	int q;
	cin >> q;
	for(int i=0;i<q;i++){
		int s, t;
		cin >> s >> t;
		if(color[s] == color[t]) cout << "yes"<<endl;
		else cout <<"no" << endl;
	}
}



Measured memory_bytes: 9400
s= "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"
dat = s.split(",")
n = int(input())
print(dat[n-1].strip())

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'



// ********** CODE STARTS HERE ****************//

int main()
{
	fastio;
    
        char c;
        cin>>c;
        if(c>=65&&c<=90)    cout<<"A\n";
        else    cout<<"a"<<'\n';
    // }

	return 0;
}

Measured memory_bytes: 3636
/*
    Author : Pranav_Raut.
*/

#include<bits/stdc++.h>
using namespace std;
#define input(arr,n) for(ll i=0;i<n;i++){cin>>arr[i];}
typedef long double ll;
typedef int lll;
const ll MOD = 1000000007;
const ll MAXN = 100005;
lll H,T,N;
ll dp[3000][3000];
ll ar[2][3000];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    cin >> N;
  	for(lll i=0;i<N;i++)
    {
        cin>>ar[0][i];
        ar[1][i] = 1.000000000 - (ar[0][i]*1.000000000);
    }
    
    for(lll j=0;j<3000;j++)
    {
        for(lll k=0;k<3000;k++)
        {
            dp[j][k] = 0.000000000;
        }
    }
    
    H = (N/2)+1;
    T = N-H;
  	
  	if(N==1)
  	{
  	    cout << ar[0][0] << endl;
  	    return 0;
  	}
  	
  	dp[N-1][1] = ar[0][N-1];
  	dp[N-1][0] = ar[1][N-1];
  	
  	for(lll i=N-2; i>=0; i--)
  	{
  	    for(lll k=0;k<=N;k++)
  	    {
  	        dp[i][1+k] += ar[0][i]*dp[i+1][k];
  	        dp[i][k] += ar[1][i]*dp[i+1][k]; 
  	    }
  	}
  	
  	ll ans = 0.0;
  	for(lll i=N; i>=H; i--)
  	{
  	    ans += dp[0][i];
  	}
  	
  	cout<<setprecision(9)<<fixed;
  	cout<<ans<<endl;
  	
    return 0;
}


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

int N, M, Q;
int seq[50][4];

int calculateScore(std::vector<int> permut)
{
    int score = 0;
    for (int i = 0; i < Q; i++)
    {
        int a = seq[i][0];
        int b = seq[i][1];
        int c = seq[i][2];
        int d = seq[i][3];

        if (permut[b - 1] - permut[a - 1] == c)
        {
            score += d;
        }
    }

    return score;
}

int getMaxScore(int missing, std::vector<int> permut)
{
    if (missing == 0)
    {
        return calculateScore(permut);
    }

    int maxScore = 0;
    int start;
    if (permut.empty())
    {
        start = 1;

    }
    else
    {
        start = permut.back();
    }

    for (int i = start; i <= M; i++)
    {
        permut.push_back(i);
        maxScore = std::max(maxScore, getMaxScore(missing - 1, permut));
        permut.pop_back();
    }

    return maxScore;
}

int main()
{
    std::cin >> N >> M >> Q;

    for (int i = 0; i < Q; i++)
    {
        std::cin >> seq[i][0] >> seq[i][1] >> seq[i][2] >> seq[i][3];
    }

    std::cout << getMaxScore(N, {});
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
long long int a[200001],n,ans,k;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	k=a[1];
	for(int i=2;i<=n;i++)
	{
		if(k>a[i])
			ans+=k-a[i];
		if(k<a[i])
			k=a[i];
	}
	cout<<ans;
}

Measured memory_bytes: 5160
from collections import deque

H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
S = [input() for _ in range(H)]
ch-=1
cw-=1
dh-=1
dw-=1

walk = [(0, 1), (1, 0), (-1, 0), (0, -1)]
jump = [(-2,-2),(-2,-1),(-2,0),(-2,1),(-2,2),(-1,-2),(-1,-1),(-1,1),(-1,2),(0,-2),(0,2),(1,-2),(1,-1),(1,1),(1,2),(2,-2),(2,-1),(2,0),(2,1),(2,2)]
step = 0
already = set()
already.add((ch,cw))
next = set()
next.add((ch,cw))
while len(next) > 0:
    d = deque(list(next))
    step_already = list(next)
    while len(d) > 0:
        pop = d.popleft()
        for h, w in walk:
            nh, nw = pop[0]+h, pop[1]+w
            if (nh, nw) not in already and nh >= 0 and nh<H and nw >= 0 and nw<W and S[nh][nw] != '#':
                if nh == dh and nw == dw:
                    print(step)
                    exit()
                already.add((nh, nw))
                step_already.append((nh, nw))
                d.append((nh,nw))
    next = set()
    step += 1
    for h, w in step_already:
        for jh, jw in jump:
            nh, nw = h+jh, w+jw
            if (nh, nw) not in already and nh >= 0 and nh<H and nw >= 0 and nw<W and S[nh][nw] != '#':
                if nh == dh and nw == dw:
                    print(step)
                    exit()
                next.add((nh,nw))
                already.add((nh,nw))

print(-1)

Measured memory_bytes: 147768
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
   ll n;
   cin>>n;
   string s;
   ll a=0,b=0,c=0,d=0;
   for(ll i=0;i<n;i++)
   {
       cin>>s;
       if(s=="AC")
       a++;
       else if(s=="WA")
       b++;
       else if(s=="TLE")
       c++;
       else if(s=="RE")
       d++;
   }
   cout<<"AC x "<<a<<endl;
   cout<<"WA x "<<b<<endl;
   cout<<"TLE x "<<c<<endl;
   cout<<"RE x "<<d<<endl;
}

Measured memory_bytes: 3632
def main():
    import sys
    input=sys.stdin.readline
    N=2*10**5+3
    mod=998244353
    fac=[1]*(N+1)
    for i in range(1,N+1):
        fac[i]=fac[i-1]*i%mod
    inv_fac=[1]*(N+1)
    inv_fac[N]=pow(fac[N],mod-2,mod)
    for i in range(N-1,0,-1):
        inv_fac[i]=inv_fac[i+1]*(i+1)%mod
    def nCr(n,r):
        if n<0 or r<0 or r>n:
            return 0
        return fac[n]*inv_fac[r]%mod*inv_fac[n-r]%mod
    n,m,k=map(int,input().split())
    m_mod=[1]
    for _ in range(n):
        m_mod.append(m_mod[-1]*(m-1)%mod)
    ans=0
    for i in range(k+1):
        ans_=nCr(n-1,i)*m%mod*m_mod[n-i-1]%mod
        ans=(ans+ans_)%mod
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 32604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean ans = true;
		String s = sc.nextLine();
		char c[] = s.toCharArray();
		for (int i = 0; i < s.length(); i++) {
			if (i % 2 == 0) {
				// Lのとき
				if (c[i] == 'L') {
					ans = false;
				}
			} else {
				// Rのとき
				if (c[i] == 'R') {
					ans = false;
				}
			}

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


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

using namespace std;

#define int long long

const int N = 1e5 + 100, INF = 3e18;

int a[N], b[N], c[N], arr[N], l[N], r[N];
int x, y, z, n, sum, ans;
multiset<int> s;

int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> x >> y >> z;
    n = x + y + z;
    for (int i = 0; i < n; i++) {
	cin >> a[i] >> b[i] >> c[i];
	sum += c[i];
	a[i] -= c[i]; b[i] -= c[i];
	arr[i] = i;
    }
    sort(arr, arr + n, [&] (int i, int j) {return a[i] - b[i] < a[j] - b[j];});
    int tmp = 0;
    for (int o = 0; o < n; o++) {
	int i = arr[o];
	if (o < y) {
	    tmp += b[i];
	    s.insert(b[i]);
	}
	else {
	    tmp += max(0LL, b[i] - *s.begin());
	    s.insert(b[i]);
	    s.erase(s.begin());
	}
	l[o] = (o < y - 1 ? -INF : tmp);
    }
    s.clear();
    tmp = 0;
    for (int o = n - 1; o >= 0; o--) {
	int i = arr[o];
	if (o >= n - x) {
	    s.insert(a[i]);
	    tmp += a[i];
	}
	else {
	    tmp += max(0LL, a[i] - *s.begin());
	    s.insert(a[i]);
	    s.erase(s.begin());
	}
	r[o] = (o > n - x ? -INF : tmp);
    }
    ans = -INF;
    for (int i = 0; i < n - 1; i++)
	ans = max(ans, l[i] + r[i + 1]);
    return cout << ans + sum, 0;
}


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

using ll = long long;

int main(int argc, char **argv)
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

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

  int res = -1e9;
  int res_abs = 1e9;
  for(int i=0; i<n; i++) {
    if( abs(s - (s-(l+i)) < res_abs )) {
      res = l+i;
      res_abs = abs(s - (s-(l+i)));
    }
  }

  cout << s - res << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int a,b,c;
    while(scanf("%d %d %d",&a,&b,&c)==3)
    {
        if(a==b&&a==c)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 128
#include<iostream>
using namespace std;
	int d[200000]={},pre[200000],nex[200000];
int main(){
	int n,m,q,pos=0;
	cin>>n>>m>>q;
	for(int i=0;i<n;i++){
		pre[i]=i-1;
		nex[i]=i+1;
		d[i]=1;
	}
	pre[0]=n-1;
	nex[n-1]=0;
	for(int i=0;i<m;i++){
		int a;
		cin>>a;
		if(a%2) while(a--)pos=pre[pos];
		else while(a--)pos=nex[pos];
		d[pos]=0;
		pre[nex[pos]]=pre[pos];
		nex[pre[pos]]=nex[pos];
		pos=nex[pos];
	}
	for(int i=0;i<q;i++){
		int a;
		cin>>a;
		cout<<d[a]<<endl;
}
	return 0;
}

Measured memory_bytes: 3504
#include <iostream>

struct {
    size_t val, cost;
} gems [20];

int main(){
    std::ios_base::sync_with_stdio(0);
    size_t N;
    std::cin >> N;
    for(size_t i=0; i<N; i++) std::cin >> gems[i].val;
    for(size_t i=0; i<N; i++) std::cin >> gems[i].cost;
    size_t result = 0;
    for(size_t i=0; i<N; i++) { 
        if(gems[i].val > gems[i].cost){
            result += gems[i].val - gems[i].cost;
        }
    }
    std::cout << result;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n;
 sc(n);
 ll a[n+10];
 map<ll,ll>cnt;
 rep(i,0,n){
  sc(a[i]);
  cnt[a[i]]++;
  if(cnt[a[i]]>a[i]){ans++;}
 }
 rep(i,0,n){
  if(cnt[a[i]]<a[i]){ans++;}
 }
 pr(ans);
return 0;}

Measured memory_bytes: 10376
N = int(input())
p = list(map(int,input().split()))
P = sorted(p)

d = []

for i in range(N):
  d.append(p[i]-P[i])
  
D = d[:]
while 0 in D:
  D.remove(0)
  
if max(d) == 0:
  print('YES')
elif len(D) == 2:
  if D[0] == (-D[1]):
    print('YES')
  else:
    print('NO')
else:
  print('NO')
  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int serch(int i,int j,int n)
{
    if(!n&&!j)return 1;
    else if(i==10||!n)return 0;
    return serch(i+1,j-i,n-1)+serch(i+1,j,n);
}
int main()
{
    int n,s;
    while(cin>>n>>s&&n!=0)cout<<serch(0,s,n)<<endl;
}

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

int main(){
	int N,M,Q;cin>>N>>M>>Q;
	vector<int> l(M),r(M),p(Q),q(Q);
for(int i=0;i<M;i++){
	cin>>l[i]>>r[i];l[i]--;r[i]--;
}
for(int i=0;i<Q;i++){
	cin>>p[i]>>q[i];p[i]--;q[i]--;
}
vector<vector<int>>tbl(N+1,vector<int>(N+1,0));

for(int i=0;i<M;i++){tbl[l[i]+1][r[i]+1]++;}
for(int i=0;i<N;i++)for(int j=0;j<N+1;j++){tbl[i+1][j]+=tbl[i][j];}
for(int i=0;i<N+1;i++)for(int j=0;j<N;j++){tbl[i][j+1]+=tbl[i][j];}
for(int i=0;i<Q;i++){
	int ans=tbl[q[i]+1][q[i]+1]-tbl[q[i]+1][p[i]]-tbl[p[i]][q[i]+1]+tbl[p[i]][p[i]];
	cout<<ans<<endl;

}

}


Measured memory_bytes: 4224
// B.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main()
{
	unsigned int N;
	unsigned int K;
	cin >> N;
	cin >> K;
	vector<unsigned int> prices;
	for (unsigned int i = 0; i < N; ++i)
	{
		unsigned int p;
		cin >> p;
		prices.emplace_back(p);
	}

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

	unsigned long result = 0u;
	for (unsigned int i = 0; i < K; ++i)
	{
		result += prices[i];
	}

	cout << result << endl;
}

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

#define endl '\n'

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  
  int s;
  cin >> s;
  
  int hh = s / 3600;
  s %= 3600;
  int mm = s / 60;
  s %= 60;
  int ss = s;
  
  printf("%d:%d:%d\n", hh, mm, ss);
  
  return 0;
}



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

typedef struct{

  double x,y;
}vec_t;

int main(){

  double x1,y1,x2,y2,x3,y3,xp,yp;
  vec_t AB,BC,CA,AP,BP,CP;

  while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>xp>>yp){

    AB.x=x2-x1 , AB.y=y2-y1;
    BC.x=x3-x2 , BC.y=y3-y2;
    CA.x=x1-x3 , CA.y=y1-y3;
    AP.x=xp-x1 , AP.y=yp-y1;
    BP.x=xp-x2 , BP.y=yp-y2;
    CP.x=xp-x3 , CP.y=yp-y3;

    double c1=AB.x*BP.y - AB.y*BP.x;
    double c2=BC.x*CP.y - BC.y*CP.x;
    double c3=CA.x*AP.y - CA.y*AP.x;

    if((c1<0&&c2<0&&c3<0) || (c1>0&&c2>0&&c3>0))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

  return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>
#include <math.h>

int main(void) {
  double xa,xb,ya,yb,xdis,ydis,dis;
  double distance;
  scanf("%lf %lf %lf %lf",&xa,&ya,&xb,&yb);
  xdis = xb - xa; if(xdis < 0)xdis = -xdis;
  ydis = yb - ya; if(ydis < 0)ydis = -ydis;

  dis = xdis * xdis + ydis * ydis;
  distance = sqrt(dis);

  printf("%lf\n",distance);
  return 0;
}


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

using namespace std;

int values[101][10001] = {};
int N,W;

int main() {
    cin>>N>>W;
    for (int n = 1; n <= N; n++) {
        int value,weight;
        cin>>value>>weight;
        for (int w = 0; w <= W; w++) {
            if (w < weight) values[n][w] = values[n-1][w];
            else values[n][w] = max(values[n-1][w], values[n-1][w-weight]+value);
        }
    }
    cout<<values[N][W]<<endl;
}

Measured memory_bytes: 6996
x,y = list(map(int,input().split()))
## １頭の条件
if x == 1:
  if (y == 2) or (y == 4):
    print("Yes")
  else:
    print("No")
    
## 51頭以上はそもそもNo    
elif x > 50:
  print("No")
  
##2頭以上の条件
else:   
  check = True
  for i in range(x+1):
    if sum([2]*(i) + [4]*(x-i)) == y:
      print("Yes")
      check=False
      break
  if check:
    print("No")


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;



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

	int n , k;
	cin >> n >> k;
	
	deque<int> v(n);
	for(auto& el : v) cin >> el;
	
	ll ans = 0;
	rep(i , k + 1)
	{
		rep(l , i + 1)
		{
			rep(r , i - l + 1)
			{
				if(l + r > i) continue; //why not
				
				vi cur;
				auto d = v;
				
				rep(_ , l) if(!d.empty()) { cur.pb(d[0]); d.pop_front(); }
				rep(_ , r) if(!d.empty()) { cur.pb(d[d.size() - 1]); d.ppb(); }
				
				SORT(cur);
				reverse(all(cur));
				//for(auto el : cur) cout << el << " ";cout<<nl;
				//cout << "k - i = " << k - i << endl;
				rep(j , k - i)
				{
					if(!cur.empty() && cur.back() < 0)
						cur.ppb();
				}
				
				ans = max(ans , accumulate(all(cur), 0LL));
			}
		}
	}
	
	die(ans);
	
	
	return 0;
}

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

typedef long long ll;

int main() {
	int n;
	while(cin >> n, n) {
		vector<ll> a(n), b(n-1);
		ll sum = 0;
		for(int i = 0; i < n; i++) cin >> a[i];
		for(int i = 0; i < n; i++) sum += a[i];
		for(int i = 0; i < n-1; i++) cin >> b[i];
		sort(b.rbegin(), b.rend());
		ll res = sum*n;
		for(int i = 0; i < b.size(); i++) {
			sum += b[i];
			res = max(res, sum*(n-1 -i));
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 3780
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
bool eq(char* a, char* b, char* f, char* g){
  REP(i,8){
    if(a[i]!='?'&&a[i]!=f[i]){
      return false;
    }
    if(b[i]!='?'&&b[i]!=g[i]){
      return false;
    }
  }
  return true;
}

int main(){
  int n,m;
  while(scanf("%d %d",&n,&m),n||m){
    char a[1024][9];
    char b[1024][9];
    char c[1024][7];
    REP(i,n){
      scanf("%s %s %s",c[i],a[i],b[i]);
    }
    char f[1024][9],g[1024][9],h[1024][51];
    int count = 0;
    char* p[1024];
    char* q[1024];
    char* r[1024];
    REP(i,m){
      scanf("%s %s %s",f[i],g[i],h[i]);
      for(int j = n-1; j >= 0; j--){
        if(eq(a[j],b[j],f[i],g[i])){
          if(c[j][0]=='p'){
            p[count] = f[i];
            q[count] = g[i];
            r[count++] = h[i];
          }
          break;
        }
      }
    }

    printf("%d\n",count);
    REP(i,count){
      printf("%s %s %s\n",p[i],q[i],r[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(){
    int num = 0;
    int num_mochies = 0;

    int num_steps = 1;
    
    scanf("%d\n",&num_mochies);

    int mochies[num_mochies];

    for(int i=0; i<num_mochies; i++){
        scanf("%d",&mochies[i]);
    }

    // bubble sort
    for(int j=0; j<num_mochies;j++ ){
        for(int i=0; i<num_mochies-(j+1); i++){
            if(mochies[i] < mochies[i+1]){
                num = mochies[i];
                mochies[i] = mochies[i+1];
                mochies[i+1] = num;
            }
        }
    }

    // for testing confirm bubble sort 
    // for(int c=0;c<num_mochies;c++){
    //     printf("%d\n",mochies[c]);
    // }

    for(int k=0; k<num_mochies-1; k++ ){
        if(mochies[k] > mochies[k+1]){
            num_steps ++;
        }
    }

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

    return 0;
}

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

int main()
{
  int n, m, k;
  cin >> n >> m >> k;
  int i, j;
  bool ok = false;
  for(i = 0; i <= n; i++)
  {
    for(j = 0; j <= m; j++)
    {
      if(i*m+j*n-2*i*j == k)
      {
        ok = true;
      }
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
array = []
while True:
	LIST = []
	INPUT = [ n for n in input().split()]
	a = int(INPUT[0])
	opperant = INPUT[1]
	b = int(INPUT[2])
	if opperant == '?':
		break
		
	LIST.append(a)
	LIST.append(opperant)
	LIST.append(b)
	array.append(LIST)
	
	 
for i in range(len(array)):
	 	
	if array[i][1] == '+':
		print(array[i][0] + array[i][2])
	 
	elif array[i][1] == '-':
		print(array[i][0] - array[i][2])
	 	
	elif array[i][1] == '*':
		print(array[i][0] * array[i][2])
	 	
	else:
		print(int(array[i][0] / array[i][2]))
	


Measured memory_bytes: 5608
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
    int n; scanf("%d", &n);
    n %= 10;
    if (n == 3) {
        puts("bon");
    } else if (n == 0 || n == 1 || n == 6 || n == 8) {
        puts("pon");
    } else {
        puts("hon");
    }
    return 0;
}

Measured memory_bytes: 1608
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	string s, t, c;
	cin >> s >> t >> c;
	cout << "A" << t[0] << "C";
 	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

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

	int n;
	cin >> n;

	REP(i, 1, 10) {
		if (n % i == 0 && (n / i) < 10) {
			cout << "Yes" << "\n";
			return 0;
		}
	}

	cout << "No" << "\n";

    return 0;
}


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

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define dbg(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

template <typename Arg1> ostream& operator << (ostream& out, const vector<Arg1> &a) {out<<"[ ";for(const auto &x:a)out<<x<<" ";return out<<"]";}


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

    string s,t;
    cin>>s;
    cin>>t;
    ll ans = 0;
    rep(i,s.length()){
        if(s[i] == t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
    timer();
    return 0;
}


Measured memory_bytes: 256
A,B,C,D = map(int,input().split())
TD = 0
AD = 0
if A%D == 0:
	TD = A//D
else:
	TD = A//D + 1
if C%B == 0:
	AD = C//B
else:
	AD = C//B + 1
if TD>=AD:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
const ll INF = 1e18;
const int MX=3e5+1;
int N, M, k;
ll L[100];
int main()
{
    ll a=2, b=1, c=a+b;
    cin>>N;
    L[0]=2 ;
    L[1]=1;
    for(int i=2;i<87;i++)
    {
        L[i]=L[i-1]+L[i-2];
    }
    cout<<L[N];
    return 0;
}


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

typedef pair<long long, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF (1LL<<58)
#define MOD 1000000007

int N, M, Q;
vector<P> G[200], S[200];
int Z[1000];
long long dp[1000][200];
long long rikuro[200][200], kairo[200][200];


signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> N >> M) {
    if (N == 0 && M == 0) break;
    rep(i, N) G[i].clear(), S[i].clear();
    rep(i, M) {
      int x, y, d; char t;
      cin >> x >> y >> d >> t;
      x--, y--;
      if (t == 'L') {
        G[x].pb(P(y, d));
        G[y].pb(P(x, d));
      }
      else {
        S[x].pb(P(y, d));
        S[y].pb(P(x, d));
      }
    }
    rep(i, N) {
      rep(j, N) rikuro[i][j] = kairo[i][j] = INF;
      rikuro[i][i] = kairo[i][i] = 0;
      priority_queue<P, vector<P>, greater<P> > q;
      q.push(P(0, i));
      while (!q.empty()) {
        long long d; int x;
        tie(d, x) = q.top(); q.pop();
        if (rikuro[i][x] < d) continue;
        for (P p : G[x]) {
          int t = p._1;
          long long nd = d + p._2;
          if (rikuro[i][t] > nd) {
            rikuro[i][t] = nd;
            q.push(P(nd, t));
          }
        }
      }
      q.push(P(0, i));
      while (!q.empty()) {
        long long d; int x;
        tie(d, x) = q.top(); q.pop();
        if (kairo[i][x] < d) continue;
        for (P p : S[x]) {
          int t = p._1;
          long long nd = d + p._2;
          if (kairo[i][t] > nd) {
            kairo[i][t] = nd;
            q.push(P(nd, t));
          }
        }
      }
    }

    cin >> Q;
    rep(i, Q) {
      cin >> Z[i];
      Z[i]--;
    }

    rep(i, Q) {
      rep(j, N) dp[i][j] = INF;
    }
    dp[0][Z[0]] = 0;
    for (int i=1; i<Q; i++) {
      int x = Z[i-1], t = Z[i];
      rep(s, N) {
        // x (s) -> t (st)
        if (dp[i-1][s] == INF) continue;
        dp[i][s] = min(dp[i][s], dp[i-1][s] + rikuro[x][t]);

        rep(st, N) {
          dp[i][st] = min(dp[i][st], dp[i-1][s] + rikuro[x][s] + kairo[s][st] + rikuro[st][t]);
        }
      }
    }
    cout << *min_element(dp[Q-1], dp[Q-1]+N) << "\n";
  }
  return 0;
}

Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const int inf = 1<<29;

int dist[100005][3];
vector<int> adj[100005];

void bfs(int sv){
    queue<pair<int, int>> q;
    q.push(make_pair(sv, 0));
    dist[sv][0] = 0;

    while(!q.empty()){
        int v = q.front().first;
        int l = q.front().second;
        q.pop();
        for(int u:adj[v]){
            int nl = (l+1)%3;
            if(dist[u][nl] != inf) continue;
            dist[u][nl] = dist[v][l] + 1;
            q.push(make_pair(u, nl));
        }
    }
}

int main(){
    int N, M; cin >> N >> M;
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        --a; --b;
        adj[a].push_back(b);
    }
    int sv, tv;
    cin >> sv >> tv;
    --sv; --tv;

    for(int i=0; i<N; i++) for(int j=0; j<3; j++) dist[i][j] = inf;
    bfs(sv);

    int ans;
    if(dist[tv][0] == inf) ans = -1;
    else ans = dist[tv][0]/3;

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



Measured memory_bytes: 6912
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

s = s()

ans = 0
cnt = 0
for i in range(len(s)):
	if cnt == 0:
		if s[i] in ["A", "T", "G", "C"]:
			cnt += 1
			if i == len(s)-1:
				ans = max(ans, cnt)
	elif cnt >= 1:
		if s[i] in ["A", "T", "G", "C"]:
			cnt += 1
			if i == len(s)-1:
				ans = max(ans,cnt)
		else:
			ans = max(ans,cnt)
			cnt = 0
print(ans)

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

//-----------------------------------------------------------------------------

int n;
vector<P> v;
int dp[5010];
int inf=1e9*2;

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

	cin>>n;
	REP(i,n) {
		int h,p; cin>>h>>p;
		v.pb(P(h+p,p));
	}
	sort(ALL(v));

	REP(i,5010) dp[i]=inf;
	dp[0]=0;

	REP(i,n) {
		for(int j=i;j>=0;j--) {
			if(dp[j]!=inf&&dp[j]<=v[i].fi-v[i].se) {
				dp[j+1]=min(dp[j+1],dp[j]+v[i].se);
			}
		}
	}

	int ans=0;
	REP(i,n+1) {
		if(dp[i]!=inf) ans=i;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> Es(N, vector<int>());
    for (int m = 0; m!= M; ++m){
        int a, b;
        cin >> a >> b;
        Es[a - 1].push_back(b - 1);
        Es[b - 1].push_back(a - 1);
    }
    vector<vector<int>> dp(1 << N, vector<int>(N, 0));
    vector<pair<int, int>> frontiers;
    frontiers.emplace_back(make_pair(1, 0));
    dp[1][0] = 1;
    for (int depth = 0; depth < N - 1; ++depth){
        vector<pair<int, int>> new_frontiers;
        for (auto p : frontiers){
            auto visited = p.first;
            auto v = p.second;
            auto val = dp[visited][v];
            for (auto u : Es[v]){
                if ((1 << u) & visited) continue;
                auto new_visited = visited | (1 << u);
                if (dp[new_visited][u] == 0){
                    new_frontiers.emplace_back(make_pair(new_visited, u));
                }
                dp[new_visited][u] += val;
            }
        }
        frontiers = new_frontiers;
    }
    int mask_all = (1 << N) - 1;
    cout << accumulate(dp[mask_all].begin(), dp[mask_all].end(), 0) << endl;
    return 0;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << std::fixed << std::setprecision(10);

	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < n / 2; i++) {
		if (s[i] != s[n / 2 + i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
from heapq import *
N = int(input())
A = [int(a) for a in input().split()]
x, t, s, i, h = 0, 0, 0, 59, []
for a in A:
    t ^= a
for a in A:
    heappush(h, -(a&~t))
while h:
    a = -heappop(h)
    while i >= 0 and (a >> i) & 1 == 0:
        i -= 1
        x = 0
    if i < 0: break
    if x:
        heappush(h, -(a^x))
    else:
        x = a
        s = max(s, s^x)
print(s+(t^s))

Measured memory_bytes: 88992
#include <stdio.h>

void swap(int *a, int *b) {
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

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



Measured memory_bytes: 2044
def main():
  n, a = map(int, input().split())
  xlst = list(map(int, input().split()))

  """
  dp[i][j][k] ... iまででj個使ってkを作る
  dp[i][j][k] += dp[i - 1][j - 1][k - x]
  """
  
  """
  xlst.insert(0, 0)
  dp =  [[[0] * (50 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
  for i in range(n + 1):
    dp[i][0][0] = 1
  
  
  for i in range(1, n + 1):
    x = xlst[i]
    dpi = dp[i]
    dpi_1 = dp[i - 1]
    for j in range(1, n + 1):
      dpij = dpi[j]
      dpi_1j = dpi_1[j]
      dpi_1j_1 = dpi_1[j - 1]
      for k in range(1, n * 50 + 1):
        if k >= x:
          #dp[i][j][k] += dp[i - 1][j - 1][k - x] + dp[i - 1][j][k]
          dpij[k] += dpi_1j_1[k - x] + dpi_1j[k]
        else:
          #dp[i][j][k] += dp[i - 1][j][k]
          dpij[k] += dpi_1j[k]

  ans = 0
  for j in range(1, n + 1):
    ans += dp[n][j][j * a]
  
  print(ans)

  """

  dp = [[0] * (n * 50 + 1) for _ in range(n + 1)]
  dp[0][0] = 1

  for x in xlst:
    for j in range(n, 0, -1):
      dpj = dp[j]
      dpj1 = dp[j - 1]
      for k in range(n * 50, x - 1, -1):
        dpj[k] += dpj1[k - x]

  print(sum([dp[j][j * a] for j in range(1, n + 1)]))
main()

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

using namespace std;
typedef long long int ll;
bool comp(ll a, ll b)
{
   return a>b;
}

int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h, n;
    cin>>h;
    if(h==1)
        {
            cout<<1;
            exit(0);
        }
    n=1;ll i=1;
    while(h!=1)
    {
        h=floor(h*1.0/2);
        n=n+pow(2,i);
        i++;
    }
    cout<<n;
    return 0;
}

Measured memory_bytes: 256