akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int m, d;
    cin >> m >> d;

    int ans = 0;

    repd(i, 1, m + 1) {
        repd(j, 1, d + 1) {
            string a = to_string(i), b = to_string(j);

            if ((j / 10) * (j % 10) == i) {
                if (j / 10 >= 2 && j % 10 >= 2) {
                    ans++;
                }
            }
        }
    }

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

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
import numpy as np
n, targw = map(int,input().split())
w = [0 for _ in range(n)]
v = [0 for _ in range(n)]
for i in range(n):
	w[i], v[i] = map(int,input().split())
dp = np.zeros(targw+1, dtype=np.int64)
for i in range(n):
	dp[w[i]:] = np.maximum(dp[:-w[i]] + v[i], dp[w[i]:])
print(dp[targw])

Measured memory_bytes: 29760
def main():
    Ss = input()
    S = list(Ss)
    now = 0
    T = ''
    Sr = []
    for i in range(1,len(S)+1):
        Sr.append(S[-i])
    ans = []
    while True:
        tmp5 = Sr[now:now+5]
        tmp6 = Sr[now:now+6]
        tmp7 = Sr[now:now+7]
        if tmp5[0] == 'e' and tmp5 == ['e','s','a','r','e']:
            ans.append('erase')
            now += 5
        elif tmp5[0] == 'm' and tmp5 == ['m','a','e','r','d']:
            ans.append('dream')
            now += 5
        elif tmp6[0] == 'r' and tmp6 == ['r','e','s','a','r','e']:
            ans.append('eraser')
            now += 6
        elif tmp7[0] == 'r' and tmp7 == ['r','e','m','a','e','r','d']:
            ans.append('dreamer')
            now += 7
        else:
            print('NO')
            
            return

        if now >= len(S):
            break
    for i in range(1,len(ans)+1):
        T += ans[-i]
    if Ss == T:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()


Measured memory_bytes: 4992
import sys
input = sys.stdin.readline

from collections import deque

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

L = [deque([]) for _ in range(N)]

for _ in range(Q):
    q = list(map(int,input().split()))
    if q[0] == 0:
        L[q[1]].append(q[2])
    elif q[0] == 1:
        if L[q[1]]:
            print(' '.join(map(str,L[q[1]])))
        else:
            print()
    else:
        if L[q[1]]:
            if L[q[2]]:
                if len(L[q[1]]) == 1:
                    L[q[2]].append(L[q[1]][0])
                elif len(L[q[2]]) == 1:
                    L[q[1]].appendleft(L[q[2]][0])
                    L[q[2]] = L[q[1]]
                else:
                    L[q[2]].extend(L[q[1]])
            else:
                L[q[2]] = L[q[1]]
        L[q[1]] = deque([])



Measured memory_bytes: 61712
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  
  int max = min(A, B);
  int min = (A + B) - N;
  if (min < 0) min = 0;
  
  cout << max << " " << min << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

class Main{
	
	public static ArrayList<Integer> return_list(String word){
		ArrayList<Integer> list = new ArrayList<Integer>();
		char[] wArray = word.toCharArray();

		for (int i=0; i < wArray.length; i++){
			if (wArray[i] == 'I') list.add(1);
			else if (wArray[i] == 'V') list.add(5);
			else if (wArray[i] == 'X') list.add(10);
			else if (wArray[i] == 'L') list.add(50);
			else if (wArray[i] == 'C') list.add(100);
			else if (wArray[i] == 'D') list.add(500);
			else list.add(1000);
		}
		
		return list;
	}

	public static int return_number(String word){
		int sum = 0;
		ArrayList<Integer> nlist = new ArrayList<Integer>();

		nlist = return_list(word);
		int i;

		for (i=0; i<nlist.size()-1;i++){
			if(nlist.get(i) >= nlist.get(i+1))sum+=nlist.get(i);
			else {
				sum += nlist.get(i+1) - nlist.get(i);
				i++;
			}
		}
		if(i<nlist.size())sum += nlist.get(i);

		return sum;
	}
	public static void print_number(ArrayList<String> list){
		for (int i=0; i<list.size();i++ ){
			System.out.println(return_number(list.get(i)));
		}
	}

	public static void main(String args[]) throws IOException{
		String str;
		ArrayList<String> inp = new ArrayList<String>();

		Scanner scan = new Scanner(System.in);

		while(scan.hasNext()){
			str = scan.next();
			inp.add(str);
		}
		print_number(inp);
	}
}

Measured memory_bytes: 0
// ※※※ 解答不能 ※※※
// 解き直し.
// tourist氏.
// https://atcoder.jp/contests/arc103/submissions/3295800
#include <bits/stdc++.h>
using namespace std;
char S[123321];

int main() {

    // 1. 入力情報取得.
    scanf("%s", S);
    int N = strlen(S);
    
    // 2. サイズ N の連結成分 を 持つ木は, 存在しないはず.
    if(S[N - 1] == '1'){
        printf("%d\n", -1);
        return 0;
    }
    
    // 3. サイズ i の 連結成分があれば, サイズ N - i の 連結成分もあるはず.
    for(int i = 0; i < N - 1; i++){
        if(S[i] != S[N - 2 - i]){
            printf("%d\n", -1);
            return 0;
        }
    }
    
    // 4. サイズ 1 の連結成分 を 持たない木は, 存在しないはず.
    if(S[0] == '0'){
        printf("%d\n", -1);
        return 0;
    }
    
    // 5. グラフ出力 ～ 後処理.
    int last = 0;
    printf("%d %d\n", 1, 2);
    for(int i = 1; i < N - 1; i++){
        printf("%d %d\n", last + 1, i + 2);
        if(S[i] == '1') last = i + 1;
    }
    return 0;

}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};



ll mod_div(ll a,ll b){
  ll tmp=MOD-2,c=b,ret=1;
  while(tmp>0){
    if(tmp&1){
      ret*=c;ret%=MOD;
    }
    c*=c;c%=MOD;tmp>>=1;
  }
  return a*ret%MOD;
}
 
#define MAX_K 200100
vector<ll> kaijo(MAX_K);
ll combination(ll n, ll r){
  if(n<r||n<0||r<0)
    return 0;
  if(kaijo[0]!=1){
    kaijo[0]=1;
    for(ll i=1;i<MAX_K;i++)kaijo[i]=(kaijo[i-1]*i)%MOD;
  }
  ll ret=kaijo[n];
  long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
  return mod_div(ret,tmp);
}

void modadd(ll &a, ll b){
  a+=b;
  a%=MOD;
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<ll>A(n+10);
  pair<ll,ll> appear[n+10]={};
  int from,to;
  for(int i=0;i<n+1;i++){
    cin>>A[i];
    if(appear[A[i]].F){
      from=appear[A[i]].S;
      to=i;
    }
    appear[A[i]]=mp(1,i);
  }
  for(int i=1;i<=n+1;i++){
    if(i==1){
      cout<<n<<endl;
    }else if(i==n+1){
      cout<<1<<endl;
    }else{
      ll num=combination(n+1,i);
      ll minus;
      if(from+n-to<i-1)minus=0;
      else minus=combination(from+n-to,i-1);
      cout<<(num-minus+MOD)%MOD<<endl;
    }
  }
  return 0;
}





Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main(){
    int a, b; cin >> a >> b;
    cout << max(a+b, max(a-b, a*b)) << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque


def main():
    """
    ab: red
    cd: blue

    仲良しペア: 最大で何個
        赤い点の x座標が青い点の x座標より小さい
        赤い点の y座標も青い点の y座標より小さい
        1つの点が複数のペアに所属することはできません。
    """
    N = int(input())

    ab = [
        tuple(map(int, input().split()))
        for _ in range(N)
    ]
    cd = [
        tuple(map(int, input().split()))
        for _ in range(N)
    ]

    f(N, ab, cd)


def f(N, ab, cd):
    """
    sortしてみたけどダメだった
        左下にある青
        右上にある赤
    N=100
    全ペア作ってみる: TLE
        ab/cdの全並べ方の組合せ
            ab permutation N!
            cd permutation N!
            N! * N!

    左下にある赤は価値が高い
    x座標の小さい青から始めているので, 赤x座標は青xより小さいものが対象
    y座標が高いものを選ぶのは
    選定中の赤座標と次の青と比較した時,
        次の青は今の青よりxは大きい
        つまり今y選定している赤のxより必ず大きいためどのx座標であるかは気にならない
        yが小さいものとペアにしたとき,とらなかったmax_yが次の青yより大きい可能性があるため
    """
    cd = deque(sorted(cd))

    used = [False] * N
    ans = 0
    while cd:
        c, d = cd.popleft()
        ai, ay = None, -1
        for i, (a, b) in enumerate(ab):
            if used[i]:
                continue
            if a < c and b < d:
                if b > ay:
                    ai, ay = i, b

        if ai is not None:
            # sorted abに対して見つかった瞬間にペアにしていたがy判断をする
            used[ai] = True
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m, x[100100], y[100100], s, t;
const ll mod = 1000000007;
int main(void){
    // Your code here!
    cin >> n >> m;
    for (ll i = 0; i < n; i++) cin >> x[i];
    for (ll i = 0; i < m; i++) cin >> y[i];
    for (ll i = 1; i < n; i++) {
        (s += ((x[i] - x[i - 1]) * i * (n - i)) % mod) %= mod;
    }
    for (ll i = 1; i < m; i++) {
        (t += ((y[i] - y[i - 1]) * i * (m - i)) % mod) %= mod;
    }
    cout << (s * t) % mod << endl;
}


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

int main(){
  int64_t n, m, d; 
  cin >> n >> m >> d;

  double ans = (double)max((int64_t)0, n-d) * (m-1) / (n*n);
  if(d != 0) ans *= 2;
  cout << setprecision(10);
  cout << ans << endl;

  
}


  
  

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    long N;
    cin >> N;

    vector<long> a;
    for(long i = 0; i < N; i++)
    {
        long temp;
        cin >> temp;
        a.push_back(temp);
    }
    
    long count = 0;
    bool found = false;
    long next = 1;
    while(count < N)
    {
        next = a[next-1];
        count++;
        if (next == 2)
        {
            found= true;
            break;
        }
        if (a[next-1] == next)
        {
            break;
        }
    }
    
    if (found)
    {
        cout << count << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    
}

Measured memory_bytes: 1528
/*************************************************************************
	> File Name: 4.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Blog: https://blog.csdn.net/Pig_cfbsl 
	> Created Time: 2020/9/19 20:06:01
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	int n=read(),ans=0;
	For(i,1,n){
		int x=n/i;
		if(x*i==n) --x;
		ans+=x;
	}
	cout<<ans;
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int x;
	cin>>x;
	int lcm=x*360/__gcd(x,360);
	cout<<lcm/x<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,a[50],b[50];
int d[55][55];
bool check(vector<int>v){
    rep(i,51){
        rep(j,51){
            if(i==j)d[i][j]=0;
            else d[i][j]=INF;
        }
    }
    rep(i,51){
        for(int t:v){
            d[i][i%t]=1;
        }
    }
    rep(k,51){
        rep(i,51){
            rep(j,51){
                chmin(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    rep(i,n){
        if(d[a[i]][b[i]]==INF)return false;
    }
    return true;
}
signed main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    vector<int>v;
    for(int i=1;i<=50;i++)v.pb(i);
    if(!check(v)){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=49;i>=0;i--){
        vector<int>u=v;
        u.erase(u.begin()+i);
        if(check(u))v=u;
    }
    int ans=0;
    for(int k:v)ans+=(1ll<<k);
    cout<<ans<<endl;
    return 0;
}


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

#define int long long
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const int N=1e5+5;
 
int solve(vector <int> A, int n)
{
    int dp[n+1];
    memset(dp,0,sizeof(dp));
    for(int i=1; i<n; i++) {
        if (A[i] <= A[i-1])
            dp[i] = dp[i-1] + 1;
    }
    return *max_element(dp, dp+n);
}
 
int32_t main()
{
	IOS;
	int n;
	cin>>n;
	vector <int> v(n);
	for(int i=0; i<n; i++) cin>>v[i];
	cout<<solve(v,n)<<endl;
	
	return 0;
}

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

int mod(int x,int y){
    if(x>=y)return x-y;
    else return y-x;
}

int main(int argc, const char * argv[]) {
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    
    int bp[n];
    bp[0] = 0;
    for(int i=1;i<n;i++){
        int least=INT_MAX;
        int j=1;
        while(j<=k && i-j>=0){
            least = min(least,bp[i-j] + mod(arr[i],arr[i-j]));
            j++;
        }
        bp[i] = least;
    }
    
    cout<<bp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 4396
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		int ans = (int)(1e7);
		String S = I.next();
		int[] E = new int[N+1];
		int[] W = new int[N+1];
		for (int i = 1; i <= N; i++) {
			E[i]=E[i-1];
			W[i]=W[i-1];
			E[i]+=S.charAt(i-1)=='W'?0:1;
			W[i]+=S.charAt(i-1)=='W'?1:0;
		}
		for (int ldr = 1; ldr<=N; ldr++) {
			int L = W[ldr-1]; //People facing left even though they're left need to be turned
			int R = E[N]-E[ldr]; //People facing right even though they're right need to be turned
			ans=Math.min(ans, L+R);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 33020
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int n;

int solve(string& s, int i, bool zero)
{
    if(s == string(s.size(), 'B')){
        return s.size();
    }else if(s == string(s.size(), 'R')){
        return 0;
    }

    string t;
    int j;

    t = s;
    j = (i + n - 1) % t.size();
    t.erase(j, 1);
    int ret = solve(t, j, zero);

    if(zero){
        t = s;
        j = (i + n) % t.size();
        t.erase(j, 1);
        ret = max(ret, solve(t, j, false));
    }

    return ret;
}

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

    while(--d >= 0){
        string s;
        cin >> n >> s;
        cout << solve(s, 0, true) << endl;
    }

    return 0;
}

Measured memory_bytes: 1276
#include <stdio.h>

int main(void) {
	int N;
	scanf("%d",&N);
	int ans=N;
	for(int i=0;i<=N;i++){
		int six=i;
		int nine=N-i;
		int count=0;
		while(six>0){
			count+=six%6;
			six/=6;
		}
		while(nine>0){
			count+=nine%9;
			nine/=9;
		}
		if(ans>count)ans=count;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;

ll N;
ll a[100000];
ll sum;
int main(void) {
	cin >> N;
	FOR(i, 0, N) {
		ll A, B;
		cin >> A >> B;
		sum -= B;
		a[i] += A + B;
	}
	sort(a, a + N);
	int flag = 0;
	FOR(i, 0, N) {
		if(flag==0)sum += a[N-1 - i];
		flag = (flag + 1) % 2;
	}
	ct(sum);
	return 0;
}

Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
	s=input()
	len_s=len(s)
	T=[0]*(len_s+1)
	T[-1],T[-2]=0,int(s[-1])
	mod=2019
	for i in range(len_s-2,-1,-1):
		T[i]=(T[i+1]+int(s[i])*pow(10,len_s-i-1,mod))%mod
	tc=list(Counter(T).values())
	ans=0
	for tcc in tc:
		ans+=tcc*(tcc-1)//2
	print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 16496
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int m;
    cin >> m;
    cout << 48 - m << endl;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int ans = 0, tmp = 0;
  string str = readString();
  REP(i, str.length()) {
    if (str[i] - '0' != i % 2)
      ans++;
    else
      tmp++;
  }
  print(min(ans, tmp));
}


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

int ctoi(const char c){
  if('0' <= c && c <= '9') return(c - '0');
  return -1;
}

int main(){
  string s;
  cin >> s;
  int m;
  m = ctoi(s.at(5)) * 10 + ctoi(s.at(6));
  if(m >= 5){
    cout << "TBD";
  }
  else{
    cout << "Heisei";
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int sprime(int x); 

int main(){
  int n,i,a[10000],con=0;
  scanf("%d",&n);
  for (i = 0 ;i < n; i++){
    scanf("%d",&a[i]);
  }


  for (i = 0 ;i < n; i++){
    if( sprime(a[i])==0)
      con++;
  }
  printf("%d",con);
  printf("\n");
  return 0;
}

int sprime(int x){
  int i;
  if( x == 2)
    return 0;

  if (x < 2 ||x % 2==0)
    return -1;

  i = 3;
  while (i <= sqrt(x)){
    if(x%i==0)
      return -1;
    i = i + 2;
  }
  return 0;
    
}

Measured memory_bytes: 632
//package abc052a;

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int a, b, c, d;
		Scanner sc = new Scanner(System.in);
		a= sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		
	
		if(a * b > c * d)
			System.out.println(a * b);
		else
			System.out.println(c * d);



	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define endl '\n'  
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< int , int > mypair;
typedef priority_queue <int> max_heap;
typedef priority_queue <int, vector<int>, greater<int> > min_heap;
const ll mod=1e9+7;
const ll inf=1e9;
const ll N=1e3+10;
int total;
int dp[1<<12];


int main()
{
	boost;
	int n,m;
	cin>>n>>m;
	int a[m];
	int b[m];
	for(int i=0;i<m;i++)
	{
		int temp=0;
		int x,y;
		cin>>x>>y;
		a[i]=x;
		while(y--)
		{
			int z;
			cin>>z;
			z--;
			temp+=1<<z;
		}
		b[i]=temp;
	}
	total=1<<n;
	dp[0]=0;
	for(int i=1;i<total;i++)
	{
		dp[i]=inf;
		for(int j=0;j<m;j++)
		{
			if(dp[(~b[j])&(i)]!=inf) dp[i]=min(dp[i],a[j]+dp[(~b[j])&(i)]);
		}
	}
	if(dp[total-1]!=inf) cout<<dp[total-1];
	else cout<<"-1";
	
   	return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim().split_whitespace()
            .map(|e| e.parse().ok().unwrap()).collect();
        v2.push(v);
    }
    v2
}

fn main() {
    let input = read_vec::<i32>();
    if input[0] % input [1] == 0 {
   		println!("0");
   	} else {
   		println!("1");
   	}
}

Measured memory_bytes: 4352
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 6010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, a[MAXN], dp[MAXN][MAXN], last[MAXN], nex[MAXN], res;

int getCost(int x, int y, int z) {
    return a[x] == a[y] && a[y] == a[z];
}

void transition(int i, int j, int pos) {
    if (pos > 3*n) return;
    if (pos == 3*n) {
        res = max(res, dp[i][j] + getCost(i, j, pos));
        return;
    }
    // 5C2 = 10 but we don't go with the case of choosing i, j because dp[i][j] would still
    // be the same as we removed all equal groups.

    dp[pos + 0][pos + 1] = max(dp[pos + 0][pos + 1], dp[i][j] + getCost(i, j, pos + 2));
    dp[pos + 0][pos + 2] = max(dp[pos + 0][pos + 2], dp[i][j] + getCost(i, j, pos + 1));
    dp[pos + 1][pos + 2] = max(dp[pos + 1][pos + 2], dp[i][j] + getCost(i, j, pos + 0));
    
    dp[i][pos + 0] = max(dp[i][pos + 0], dp[i][j] + getCost(j, pos + 1, pos + 2));
    dp[i][pos + 1] = max(dp[i][pos + 1], dp[i][j] + getCost(j, pos + 0, pos + 2));
    dp[i][pos + 2] = max(dp[i][pos + 2], dp[i][j] + getCost(j, pos + 0, pos + 1));
    
    dp[j][pos + 0] = max(dp[j][pos + 0], dp[i][j] + getCost(i, pos + 1, pos + 2));
    dp[j][pos + 1] = max(dp[j][pos + 1], dp[i][j] + getCost(i, pos + 0, pos + 2));
    dp[j][pos + 2] = max(dp[j][pos + 2], dp[i][j] + getCost(i, pos + 0, pos + 1));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,3*n) cin >> a[i];
    FOR(i,1,3*n) FOR(j,1,3*n) dp[i][j] = -1e9;
    dp[1][2] = 0;
    
    int equalGroup = 0;
    bool change = true;
    while (change) {
        change = false;
        for (int i = 3; i + 2 <= 3 * n; i += 3)
            if (a[i] == a[i+1] && a[i+1] == a[i+2]) {
                equalGroup++;
                FOR(j,i+3,3*n) a[j-3] = a[j];
                n--;
                change = true;
                break;
            }
    }
    FOR(i,1,3*n) last[i] = 3*n+1;
    FORE(i,3*n,1) {
        nex[i] = last[a[i]];
        last[a[i]] = i;
    }

    FOR(i,1,3*n)
        FOR(j,i+1,3*n) {
            // proceed next immediate group
            transition(i, j, (j+3) / 3 * 3);
            if (j / 3 * 3 < nex[i] / 3 * 3) transition(i, j, nex[i] / 3 * 3);
            if (j / 3 * 3 < nex[j] / 3 * 3) transition(i, j, nex[j] / 3 * 3);
        }

    cout << res + equalGroup;
    return 0;
}


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

using namespace std;
#define ll long long
const ll mx=1e18+7;

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


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <atcoder/lazysegtree>
#include <atcoder/modint>

using namespace std;

using ll = long long int;
using modint = atcoder::modint998244353;

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N, Q;
struct q {int l,r,d;};
vector<q> Qs;
void input(){
    fast_io();
    cin >> N >> Q;
    Qs.resize(Q);
    for (int i = 0; i < Q; i++)
    {
        int l,r,d; cin >> l >> r >> d;
        l--, r--;
        Qs[i] = q{l,r,d};
    }
}

vector<modint> pow_10;
struct S{modint val; int sz;};
S op(S x, S y){return S{x.val*pow_10[y.sz] + y.val, x.sz + y.sz};}
S e(){return S{0, 0};}
using F = int;
S mapping(F f, S x){
    if(f!=0) return S{(pow_10[x.sz]-1)/modint(9)*f, x.sz};
    return x;
}
F composition(F f, F g){
    if(f!=0) return f;
    return g;
}
F id(){return 0;}

int solve(){
    pow_10.resize(N);
    pow_10[0] = 1;
    for (int i = 0; i < N; i++) pow_10[i+1] = pow_10[i]*10;

    vector<S> Init(N);
    for (int j = 0; j < N; j++) Init[j] = S{1, 1};    
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(Init);
    vector<modint> Ans;
    for (int i = 0; i < Q; i++)
    {
        int l, r, d;
        l = Qs[i].l;
        r = Qs[i].r;
        d = Qs[i].d;
        seg.apply(l, r + 1, d);
        modint ans = seg.all_prod().val;
        Ans.push_back(ans);
    }
    for(auto ans:Ans) cout << ans.val() << "\n";
    return 0;
}

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

Measured memory_bytes: 14108
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

	int N;

	scanf("%d",&N);

	int i;

	vector< pair<int, int> >A(N);

	for (i = 0; i < N; i++) {
		scanf("%d",&A[i].first);
		A[i].second = i;
	}

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

	int ans = 0;

	for (i = 0; i < N; i++) {
		if (A[i].second % 2 != i % 2) {
			ans++;
		}
	}
	printf("%d\n",ans/2);

	return 0;
}

Measured memory_bytes: 1152
/**
 * This line was copied from template
 * This is bsol.cpp
 * 
 * @author: Nikolay Kalinin
 * @date: Sat, 23 Mar 2019 16:04:14 +0300
 */
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

vector<pair2<int>> edges;

int main()
{
    int n;
    cin >> n;
    if (n % 2 == 0)
    {
        for (int j = 1; j <= n; j++)
        {
            for (int i = j + 1; i <= n; i++) if (i + j != n + 1) edges.pb({i, j});
        }
    } else
    {
        n--;
        for (int j = 1; j <= n; j++)
        {
            for (int i = j + 1; i <= n; i++) if (i + j != n + 1) edges.pb({i, j});
        }
        n++;
        for (int i = 1; i <n; i++) edges.pb({i, n});
    }
    printf("%d\n", (int)edges.size());
    for (auto t : edges) printf("%d %d\n", t.fi, t.se);
    return 0;
}


Measured memory_bytes: 384
import sys
S = list(input())
T = str(input())

for i in range(len(S)):
	mojiretsu = ''.join(S)
	if T == mojiretsu :
		print('Yes')
		sys.exit()
	else:
		#リストの入れ替えを行う
		target = S[-1]
		S.pop(-1)
		S.insert(0,target)

print('No')


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

string S, T;

void input(){
  cin >> S >> T;
}

void judge(){
  T.pop_back();
  if(S == T) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main(){
  input();
  judge();
  return 0;
}
  

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
using namespace std;
#define INFTY (1000000001)

int times = 0;

void merge(int A[], int left, int mid, int right){
    int n1, n2, i, j;
    n1 = mid - left;
    n2 = right - mid;
    int L[n1 + 1], R[n2 + 1];
    for(i = 0; i < n1; i++){
        L[i] = A[left + i];
    }
    for(i = 0; i < n2; i++){
        R[i] = A[mid + i];
    }
    L[n1] = INFTY;
    R[n2] = INFTY;
    i = 0; j = 0;
    for(int k = left; k < right; k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
            times++;
        }else{
            A[k] = R[j];
            j++;
            times++;
        }
    }
}

void mergeSort(int A[], int left, int right){
    int times;
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(){
    int n;
    scanf("%d", &n);
    int S[n];
    for(int i = 0; i < n; i++){
        scanf("%d" , &S[i]);
    }
    mergeSort(S, 0, n);
    for(int i = 0; i < n; i++){
        if(i != 0) cout << " ";
        cout << S[i];
    }
    cout << endl;
    cout << times << endl;
    return 0;
}


Measured memory_bytes: 7044
#if defined(LOCAL)
#define PROBLEM_NAME "b"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define C(x, ...) ;
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)

void solve(istream& cin, ostream& cout) {
  l n, c; cin >> n >> c;
  vl v(n), d(n);
  F(i, 0, n) cin >> d[i] >> v[i];
  vl ff(n), rr(n);
  l s = 0;
  F(i, 0, n - 1) {
    s += v[i];
    ff[i + 1] = max(ff[i], s - 2 * d[i]);
  }
  s = 0;
  B(i, 0, n - 1) {
    s += v[i + 1];
    rr[i] = max(rr[i + 1], s - 2 * (c - d[i + 1]));
  }
  l ans = 0;
  s = 0;
  F(i, 0, n) {
    s += v[i];
    ans = max(ans, s - d[i] + rr[i]);
  }
  s = 0;
  B(i, 0, n) {
    s += v[i];
    ans = max(ans, s - (c - d[i]) + ff[i]);
  }
  cout << ans << lf;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


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

int n, ada=0;

int main (){
	cin >>n;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==n)
			ada++;
		}
	}
	if(ada>0) cout << "Yes";
	else cout << "No";
}


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

using namespace std;

#define LIMIT 100
typedef pair<int64_t, int64_t> ii;
typedef int64_t ll;
int gcd(ll a, ll b) { return (b==0)?a:gcd(b, a%b); }
int lcm(ll a, ll b) { ll i=(a/gcd(a,b))*b; assert(i>0); return i; }

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int mind = 65;
  int a;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    int d = 0;
    while(a%2==0) {a= a>>1; d++;}
    mind = min(mind, d);
  }
  std::cout << mind << std::endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>
#include <string>
#include <queue>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max<int>(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max<int>(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
inline T scan() {
  T res;
  std::cin >> res;
  return res;
}

int main() {
  const int N = scan<int>();
  const int M = scan<int>();
  const std::string S = scan<std::string>();
  std::vector<std::vector<int>> graph(N);
  for (const int i: range(0, M)) {
    const int a = scan<int>() - 1;
    const int b = scan<int>() - 1;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  std::vector<int> count_A(N, 0), count_B(N, 0);
  std::vector<bool> done(N, false);
  std::queue<int> que;
  for (const int u: range(0, N)) {
    for (const int v: graph[u]) {
      if (S[v] == 'A') {
        ++count_A[u];
      }
      else {
        ++count_B[u];
      }
    }
    if ((count_A[u] <= 0 || count_B[u] <= 0) && !done[u]) {
      done[u] = true;
      que.push(u);
    }
  }
  int count = 0;
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    ++count;
    for (const int v: graph[u]) {
      if (S[u] == 'A') {
        --count_A[v];
      }
      else {
        --count_B[v];
      }
      if ((count_A[v] <= 0 || count_B[v] <= 0) && !done[v]) {
        done[v] = true;
        que.push(v);
      }
    }
  }
  std::cout << (count == N ? "No" : "Yes") << '\n';
  return 0;
}


Measured memory_bytes: 12164
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin >> s;

	int sz = s.size();

	int k = 1;	
	string prev = "", curr = "";
	prev += s[0];
	for (int i = 1; i < sz; ++i) {
		curr += s[i];
		if (prev != curr) {
			++k;
			prev = curr;
			curr = "";
		}
	}

	cout << k << "\n";

	return 0;

}

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

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		
		List<Integer> list = new ArrayList<Integer>();
		
		list.add(a);
		list.add(b);
		list.add(c);
		list.add(d);
		list.add(e);
		
		List<Integer> nlist = new ArrayList<Integer>();
		
		nlist.add(a);
		nlist.add(b);
		nlist.add(c);
		nlist.add(d);
		nlist.add(e);
		
		list = list.stream().map(s -> s % 10).collect(Collectors.toList());
		int min = list.stream().filter(s -> s != 0).min(Comparator.naturalOrder()).orElse(0);
		int minval = nlist.get(list.indexOf(min));
		nlist.remove(list.indexOf(min));
		List<Double> n2list = nlist.stream().map(s -> (double)s/10).map(s -> Math.ceil(s)).map(s -> s * 10).collect(Collectors.toList());
		
		double result = 0;
		for(double s :n2list) {
			result += s;
		}
		result += minval;
		int result1 = (int)result;
		System.out.println(result1);
		
	}
}

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

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> p(D), c(D);
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
  }
  int ans = 1000;
  for (int i = D - 1; i >= 0; i--) {
    for (int j = 0; j <= p[i]; j++) {
      int total = (i + 1) * 100 * j, tmp = j;
      if (j == p[i]) total += c[i];

      for (int bit = 0; bit < (1 << D); bit++) {
        int total2 = 0, tmp2 = 0;
        for (int k = 0; k < D; k++) {
          if (k != i && ((bit >> k) & 1)) {
            total2 += p[k] * (k + 1) * 100 + c[k];
            tmp2 += p[k];
          }
        }
        if (total + total2 >= G) {
          ans = min(ans, tmp + tmp2);
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  if(n<=k) cout<<n*x<<endl;
  else cout<<k*x+(n-k)*y<<endl;
  return 0;
}

Measured memory_bytes: 256
macro_rules! input {
     (source = $s:expr, $($r:tt)*) => {
         let mut iter = $s.split_whitespace();
         input_inner!{iter, $($r)*}
     };
     ($($r:tt)*) => {
         let s = {
             use std::io::Read;
         let mut s = String::new();
         std::io::stdin().read_to_string(&mut s).unwrap();
         s
     };
     let mut iter = s.split_whitespace();
     input_inner!{iter, $($r)*}
     };
}
     
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

//#[proconio::fastout]
fn main() {
    input!{
        n: usize,
        t: i32,
        a: i32,
        h: [i32; n],
    }
    let mut ans = 1;
    let mut min = std::f64::MAX;
    for i in 0..n {
        let diff = ((t as f64) - 0.006 * (h[i] as f64) - (a as f64)).abs();
        if diff < min {
            min = diff;
            ans = i + 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
X = int(input())

import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

x = X
while(not is_prime(x)):
    x += 1
print(x)

Measured memory_bytes: 2940
#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d %d", &a, &b);
    if (a == 1)
        a = 14;
    if (b == 1)
        b = 14;
    if (a > b) 
        printf("Alice");
    if (a < b)
        printf("Bob");
    if (a == b)
        printf("Draw");
    
    return 0;
}


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

int main() {
	int k;
	scanf("%d", &k);
	int arr[k];
	for (int i=0; i<k; i++) scanf("%d", &arr[i]);
	long long lo=2, hi=2;
	bool pos=true;
	for (int i=k-1; i>=0; i--) {
		long long nlo=lo%arr[i]==0?lo:(lo/arr[i]+1)*arr[i];
		long long nhi=(hi+1)%arr[i]==0?hi:(hi/arr[i]+1)*arr[i]-1;
		//printf("%d %d\n", nlo, nhi);
		lo=nlo; hi=nhi;
	}
	long long clo=lo, chi=hi;
	for (int i=0; i<k; i++) {
		clo-=clo%arr[i];
		chi-=chi%arr[i];
	}
	pos = clo==2 && chi==2;
	if (!pos) printf("-1\n");
	else printf("%lld %lld\n", lo, hi);
}


Measured memory_bytes: 640