akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 2505

// it's swapnil07 ;)

int dist[MAXN];

struct Edge { 
    int src, dest, weight; 
}; 
  
struct Graph { 
    int V, E; 
    struct Edge* edge; 
}; 
  
struct Graph* createGraph(int V, int E) { 
    struct Graph* graph = new Graph; 
    graph->V = V; 
    graph->E = E; 
    graph->edge = new Edge[E]; 
    return graph; 
}

bool BellmanFord(struct Graph* graph, int src) 
{ 
    int V = graph->V; 
    int E = graph->E; 
    for (int i = 0; i < V; i++) 
        dist[i] = INT_MAX; 
    dist[src] = 0;
    for (int i = 1; i <= V - 1; i++) { 
        for (int j = 0; j < E; j++) { 
            int u = graph->edge[j].src; 
            int v = graph->edge[j].dest; 
            int weight = graph->edge[j].weight; 
            if (dist[u] != INT_MAX && dist[u] + weight < dist[v]) 
                dist[v] = dist[u] + weight; 
        } 
    } 
    int x = dist[V-1];
    for(int i=1; i<= V-1; i++){
        for(int i = 0; i < E; i++) { 
            int u = graph->edge[i].src; 
            int v = graph->edge[i].dest;
            int weight = graph->edge[i].weight; 
            if (dist[u] != INT_MAX && dist[u] + weight < dist[v]) {
                dist[v] = dist[u]+weight;
            } 
        }
    }
    int y = dist[V-1];
    if(y < x)
        return 0;
    return 1;
} 



signed main(){
    fast
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    int n, m, p; cin>>n>>m>>p;
    Graph* graph = createGraph(n, m);
    For(i, 0, m){
        int x, y, c;
        cin>>x>>y>>c;
        c -= p;
        c *= -1;
        x--;
        y--;
        graph->edge[i].src = x;
        graph->edge[i].dest = y; 
        graph->edge[i].weight = c;
    }
    bool v = BellmanFord(graph, 0);
    // For(i, 0, n){
    //     cout<<dist[i]<<" ";
    // }
    // cout<<endl;
    if(v){
        int ans = dist[n-1];
        ans *= -1;
        ans = max(ans, 0LL);
        cout<<ans;
    }
    else{
        cout<<-1;
    }
    return 0;
}

Measured memory_bytes: 512
N,K = map(int,input().split())
A = [0]*N
for _ in range(K):
  d = input()
  List = list(map(int,input().split()))
  for item in List:
    A[item-1] += 1 
counter = 0
for item in A:
  if item == 0:
    counter += 1
print(counter)

Measured memory_bytes: 9208
from operator import itemgetter
N, K = map(int, raw_input().split())
a = []
for i in range(N):
    a.append(map(int, raw_input().split()))
a.sort(key=itemgetter(0))
thre = 0
for i in a:
    thre += i[1]
    if thre >= K:
        print(i[0])
        break

Measured memory_bytes: 24308
#include<bits/stdc++.h>
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

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

    int N; cin>>N;
    string s; cin>>s;
    for(int i=0;i<s.size();i++){
        int c=((s[i]-'A')+N)%26;
        cout<<(char)(c+'A');
    }
    cout<<endl;
    return 0;
}

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

int main()
{
  int N,M,C,cnt=0;
  cin>>N>>M>>C;
  vector <int> B(M);
  for(int i=0;i<M;i++){
    cin>>B[i];
  }
  for(int i=0;i<N;i++){
    int sum=0;
    for(int j=0;j<M;j++){
      int tmp;
      cin>>tmp;
      sum+=tmp*B[j];
    }
    if(sum+C>0)cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 100000  //check the limits, man
int main()
{
    int i,n,d;
    ll m;
    ll sum=0,ans=0;
    in(n);
    rep(i,n)
    {
        in(d);
        cin >> m;
        ans+=m;
        m*=d;
        sum+=m;
    }
    ans--;
    if(sum>9)
        ans+=(sum-1)/9;
    llout(ans);
}




Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include<random> 
#define int long long 
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back 
#define mod 1000000007 
#define mk(arr,n,type) type *arr=new type[n]; 
#define sl s1.length(); 
#define yes cout<< "Yes"<<endl 
#define no cout<< "No"<<endl 
#define all(v) (v).begin(),(v).end() 
#define mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
using namespace std; 
void fastio() 
{ 
    #ifndef ONLINE_JUDGE 
    freopen("INPUT.txt","r",stdin); 
    freopen("OUTPUT.txt","w",stdout); 
    #endif 
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL) ; 
    cout.tie(NULL); 
    
}
int dp(int a[],int n)
{
    if(n==0)
    return 0;
    if(n==1)
    return a[n-1];
    if(n==2)
    return abs(a[n-1]-a[n-2]);
    if(abs(a[n-1]-a[n-3])<=abs(a[n-1]-a[n-2]))
    return abs(a[n-1]-a[n-3])+dp(a,n-2);//dp(a,n-3));
    else
    return dp(a,n-1)+abs(a[n-1]-a[n-2]);//,dp(a,n-2));
    //return min(abs(a[n-1]-a[n-2])+dp(a,n-1),abs(a[n-1]-a[n-3])+dp(a,n-2));
}
signed main() 
{ 
    fastio(); 
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n],s=0;
        for(int i=0;i<n;i++)
        cin>>a[i];
        for(int i=1;i<n;i++)
        {
            if(a[i]<a[i-1])
            {
                s+=a[i-1]-a[i];
                a[i]=a[i-1];
            }
        }
        cout<<s;
    }
}

Measured memory_bytes: 5136
# ABC 126: B – YYMM or MMYY
s = input()
first = int(s[0] + s[1])
last = int(s[2] + s[3])

if 0 < first <= 12 and 0 < last <= 12:
    print('AMBIGUOUS')
elif 0 < first <= 12:
    print('MMYY')
elif 0 < last <= 12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
N=int(input())
D={}
from decimal import Decimal
B=[Decimal(input()) for _ in range(N)]
B=[int(i*10**9) for i in B]
A=[[0]*19 for i in range(19)]
for i in range(N):
  x=B[i]
  y=x
  tcnt,fcnt=0,0
  while x%2==0 and tcnt<18:
    tcnt+=1
    x=x//2
  while y%5==0 and fcnt<18:
    fcnt+=1
    y=y//5
  A[fcnt][tcnt]+=1

cnt=0
for i in range(19):
  for j in range(19):
    for k in range(19):
      for l in range(19):
        if i+k>=18 and j+l>=18:
          if i!=k and j!=l:
            d=A[i][j]
            e=A[k][l]
            p=d*e
          elif i==k and j==l:
            d=A[i][j]
            p=d*(d-1)
          else:
            d=A[i][j]
            e=A[k][l]
            p=d*e
          cnt+=p
print(cnt//2)

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

using namespace std;
typedef long long ll;
int n, k, a[200005];

template <class T>
void read(T &x, T f = 1) {
    char ch = getchar();
    x = 0;
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

int main() {
    read(n), read(k);
    for (int i = 1; i <= n; i++) read(a[i]);
    int l = 1, r = k + 1;
    while (r <= n) {
        if (a[r] > a[l])
            puts("Yes");
        else
            puts("No");
        l++, r++;
    }
    return 0;
}

Measured memory_bytes: 4400
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int A[11],C;

int main(){
    rep(i,3){
        cin>>C;
        A[C]++;
    }
    if(A[5]==2&&A[7]==1)out("YES");
    else out("NO");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
ll power(ll x, ll n, ll M = mod){
    ll res = 1;
    if(n > 0){
        res = power(x, n / 2, M);
        if(n%2 == 0)res = (res * res) % M;
        else res = (((res * res) % M) * x) % M;
    }
    return res;
}

ll gcd(ll x, ll y){
    return y ? gcd(y, x % y) : x;
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll ans = 0;
    map<pair<ll,ll>,ll> m;
    rep(i,n){
        ll a, b; cin >> a >> b;
        if (a==0 && b==0){ans++;continue;}
        ll GCD = gcd(a,b);
        a /= GCD; b /= GCD;
        m[make_pair(a,b)]++;
    }
    n -= ans;

    ll y = 1;
    for (auto &&i : m){
        if (i.first.first < 0 || i.first.second < 0) continue;
        if (i.first.first && !i.first.second) continue;
        ll x = m[make_pair(-i.first.second, i.first.first)] + m[make_pair(i.first.second, -i.first.first)];
        if (x > 0){
            n -= i.second + x;
            y *= (power(2, i.second)-1) + (power(2, x)-1) + 1 + mod;
            y %= mod;
        }
    }
    y *= power(2, n);
    y %= mod;
    ans += y + mod - 1;
    ans %= mod;
    cout << ans << endl;
}

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

int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    ll ans = 0;
    ll min_a = 10000000000;
    ll x;
    int flag = 0;
    for(int i = 0; i < n; i++){
        cin >> x;
        ans += abs(x);
        if(abs(x) < min_a){
            min_a = abs(x);
        }
        if(flag == 1){
            x *= -1;
        }
        if(x < 0){
            flag = 1;
        }else{
            flag = 0;
        }
    }
    if(flag == 1){
        ans = ans - 2 * min_a;
    }
    cout << ans << endl;


}

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

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1; i < n+1; i++){
        cin >> a[i];
    }
    vector<int> b(n+1);
    for(int i = n; i >= 1; i--){
        int sum = 0;
        for(int j = i+i; j <= n; j += i){
            sum ^= b[j];
        }
        b[i] = sum^a[i];
    }
    vector<int> ans;
    for(int i = 1; i <= n; i++){
        if(b[i]) ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

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

const int INF = 1000000007;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pr;

int main(){
    int N;
    scanf("%d", &N);
    printf("%d\n", (int)ceil(log(N) / log(3)));
    return 0;
}

Measured memory_bytes: 1232
//  LINK ZADATKA: http://abc069.contest.atcoder.jp/tasks/abc069_a

#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <fstream>
#include <cstring>
#include <string>
#include <climits>

using namespace std;

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;


#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define INF 999999999
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define _gcd __gcd
#define eps 1e-9

int n, m, sol;
int main(){
	
	scanf("%d %d", &n, &m);
	
	sol = (n-1) * (m-1);
	
	printf("%d\n", sol);
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll long long
# define pb push_back
# define fi first
# define se second
# define mp make_pair
using namespace std;


ll dp[101][100*1000+1];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,w;
    cin>>n>>w;
    vector <ll> weight(n+1),value(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>weight[i]>>value[i];
    }
    ll sum=0;
    for(ll x:value) sum+=x;
    // dp[i][j] -> minimum weight required to get the total value of j by selecting any subset till the ith element
    // Base Case
    // dp[1][x] will be w1 if x=1 else infinity
    // dp[1][0]=0
    dp[1][0]=0;
    for(ll i=1;i<=sum;i++)
    {
        if(i==value[1]) dp[1][i]=weight[1];
        else dp[1][i]=INT_MAX;
    }
    for(ll i=2;i<=n;i++)
    {
        for(ll j=0;j<=sum;j++)
        {
            if(j-value[i]>=0)
            dp[i][j] = min(dp[i-1][j],dp[i-1][j-value[i]]+weight[i]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    ll ans = 0;
    for(ll i=0;i<=sum;i++)
    {
        if(dp[n][i]<=w) ans=max(ans,i);
    }
    cout<<ans<<endl;
}


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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
using namespace std;

int main(){
	int k, n;	cin >> k >> n;
	int a[n];
	for( int i = 0; i < n; i++ ){
		cin >> a[i];
	}
	int distance[n];
	int ans = 0;

	for( int i = 0; i < n - 1; i++ ){
		distance[i] = a[i+1] - a[i];
	}
	distance[n - 1] = k - a[n - 1] + a[0];

	sort( distance, distance + n );

	for( int i = 0; i < n - 1; i++ ){
		ans += distance[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5156
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	h, w := nextInt(), nextInt()
	s := make([]string, h)
	for i := range s {
		s[i] = next()
	}

	dp := make([][]int, h)
	for i := range dp {
		dp[i] = make([]int, w)
	}
	if s[0][0] == '#' {
		dp[0][0] = 1
	}
	for i := 1; i < w; i++ {
		dp[0][i] = dp[0][i-1]
		if s[0][i] != s[0][i-1] && s[0][i] == '#' {
			dp[0][i]++
		}
	}
	for i := 1; i < h; i++ {
		dp[i][0] = dp[i-1][0]
		if s[i][0] != s[i-1][0] && s[i][0] == '#' {
			dp[i][0]++
		}
	}

	for i := 1; i < h; i++ {
		for j := 1; j < w; j++ {
			down, right := dp[i-1][j], dp[i][j-1]
			if s[i][j] != s[i-1][j] && s[i][j] == '#' {
				down++
			}
			if s[i][j] != s[i][j-1] && s[i][j] == '#' {
				right++
			}
			dp[i][j] = min(down, right)
		}
	}
	// for i := range dp {
	// 	puts(dp[i])
	// }

	puts(dp[h-1][w-1])
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}


Measured memory_bytes: 768
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int k;
    cin>>k;
    queue<ll> q;
    for(ll i=1;i<=9;i++) q.push(i);
    ll ans;
    while(k){
        ans=q.front(); q.pop();
        if(ans%10>0) q.push(10*ans+ans%10-1);
        q.push(10*ans+ans%10);
        if(ans%10<9) q.push(10*ans+ans%10+1);
        k--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5076
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c;
        if(a>=13){
            c=b;
        }else if(a>=6){
            c=b/2;
        }else{
            c=0;
        }
        System.out.println(c);
    }
}

Measured memory_bytes: 23252
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
#include <utility>
using namespace std;

bool sortpair(const pair<long, long> a, const pair<long, long> b){
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<long, long>> store(n);
    for(auto &x : store){
        cin >> x.first >> x.second;
    }
    sort(store.begin(), store.end(), sortpair);
    
    long money = 0;
    long ndrink = 0;
    for(auto &x : store){
        if(ndrink < m){
            auto nbuy = min(static_cast<long>(m - ndrink), x.second);
            money += x.first * nbuy;
            ndrink += nbuy;
        }
    }
    cout << money;
    return 0;
}



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

int main() {
	int N;
	cin>>N;
	vector<int>P(N);
	for(int i=0;i<N;i++){
		cin>>P.at(i);
	}
	int atai=P.at(0);
	int count=1;
	for(int i=0;i<N;i++){
		if(atai>P.at(i)){
			atai=P.at(i);
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

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

//#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> Tree;

#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define ll long long
#define pr pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define For(i,n,a) for(int i=a;i<(n);++i)
#define Forr(i,n) for(int i=n-1;i>=0;i--)
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#define fin ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define sz(a) (int)a.size()
#define Fill(a,b) memset(a,b,sizeof(a));
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
const int INF=1e9;

void solve(){
	string s,t;
	cin>>s>>t;
	int n=sz(s),m=sz(t);
	int dp[n+1][m+1];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	if(!dp[n][m])cout<<" ";
	else{
		string ans;
		int i=n,j=m;
		while(i>=1 && j>=1){
			if(dp[i][j]==dp[i-1][j])i--;
			else if(dp[i][j]==dp[i][j-1])j--;
			else ans=s[i-1]+ans,i--,j--;
		}
		cout<<ans;
	}	
}



int main(){
    fin;
    solve();
}

Measured memory_bytes: 38792
import math
n=int(input())
s=0
for i in range(n):
    a=int(input())
    b=math.ceil(a**0.5)
    if a==2:
        s+=1
    elif a%2==0 or a < 2:
        continue
    else:
        c=0
        for j in range(3,b+1,2):
            if a%j==0:
                c+=1
                break
        if c==0:
            s+=1
print(s)

Measured memory_bytes: 7960
#include<bits/stdc++.h>
using namespace std;
string rem_dup(string &a){
	set<char> s;
	int n=a.length();
	for(int i=0;i<n;i++){
		s.insert(a[i]);
	}
	string b="";
	for(int i=0;i<n;i++){
		if(s.find(a[i])!=s.end()){
			b+=a[i];
			s.erase(a[i]);
		}
	}
	return b;
}
int main(){
	string a,b;
	cin>>a>>b;
//	rem_dup(a);
//	rem_dup(b);
	int ans=0;
	for(int i=0;i<a.length();i++){
		if(a[i]!=b[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3812
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>

using namespace std;

int main()
{int N; cin >> N;
 vector<int> A(N);
 for(int i = 0; i < N; i++)
 {cin >> A[i];}
 
 map<int, int>mp;
 for(int i = 0; i < N; i++)
 {mp[A[i]]++;}
 
 long long cnt = 0;
 
 for(auto p: mp){
   int s = p.first;
   int t = p.second;
   if( t >= s){cnt += t - s;}
   else{cnt += t;}}
 
 cout << cnt << endl;

 return 0;
}
 


Measured memory_bytes: 5120
from math import comb
h,w,a,b = map(int,input().split())
s = 0
nC = b-1
kC = 0
nD = w-b-1+h-1
kD = h-1
p = 1000000007
fac = [1]
ff = 1
for i in range(1,200001):
  ff *= i
  ff %= p
  fac.append(ff)
def ncr(n, r, p): 
  return (fac[n] * pow(fac[r], p-2, p) % p * pow(fac[n-r], p-2, p) % p);

for i in range(h-a):
  C = ncr(nC, kC, 1000000007)
  D = ncr(nD, kD, 1000000007)
  s = (s + C * D) % 1000000007
  nC += 1
  kC += 1
  kD -= 1
  nD -= 1
print(s)


Measured memory_bytes: 16920
/*input
11
*/
#include <bits/stdc++.h>
#define fastIo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
using namespace std;

//#define LOCAL
#ifdef LOCAL
	#define DEBUG(x) do { cout << #x << ": " << x << '\n'; } while (0)
#else
	#define DEBUG(x) 
#endif

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

const int dr[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};

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

int main(){
	fastIo;

	int x;
	cin >> x;

	int cur = 0, sum = 0;
	while(sum < x){
		sum += cur;
		cur++;
	}
	cout << cur - 1 << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define R_MAX 1000000000

int main(void) {
    int n; // 入力の数
    int maxv = -R_MAX; // ある時点までのR[j] - R[i]の最大値
                       // R[t]が1以上なので初期値は1 - R_MAX以下にする
    int minv; // ある時点までの価格の最小値
    int t; // 時刻を表すループ変数
    int Rt; // ループ内でscanfする用
    scanf("%d", &n);
    scanf("%d", &minv); // minvの初期値はR[0]としておく
    // 時刻t-1までのmaxvとminvが分かっているとき、
    // 時刻tまでのmaxvは、Rt - minvと時刻t-1までのmaxvを
    // 比較して大きい方。
    for (t = 1; t < n; t++) {
        scanf("%d", &Rt);
        if (Rt - minv > maxv) maxv = Rt - minv;
        if (Rt < minv) minv = Rt;
    }
    printf("%d\n", maxv);
    return 0;
}



Measured memory_bytes: 2108
import math

x1, y1, x2, y2 = input().split()
x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2)
l = math.sqrt((x1-x2)**2 + (y1-y2)**2)
print('{0:.6f}'.format(l))


Measured memory_bytes: 5660
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0) break;
            int[] a = new int[n];
            int sumA = 0;
            int ave = 0;
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
                sumA += a[i];
            }
            ave = sumA/n;
            for (int i = 0; i < n; i++) {
                if(a[i]<=ave) {
                    cnt++;
                }
            }

            System.out.println(cnt);
        }
    }
}


Measured memory_bytes: 58900
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define int long long
#define ll long long
#define mod (int)1000000007
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = DBL_EPSILON;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = n / (a + b) * a;
	ans += min(a, n % (a + b));
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll =long long;

static const int inf = (1<<21);
static const int white = 0;
static const int gray =  1;
static const int black = 2;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int n;
vector<pair<int,int>> adj[10010]; // 重み付き有向グラフのリスト表現


void dijkstra(){
	priority_queue<pair<int, int> > p_que;
	int color[10010];
	int d[10010];
	rep(i, n){
		d[i] = inf;
		color[i] = white;
	}

	d[0] = 0;
	p_que.push(make_pair(0,0));
	color[0] = gray;

	while( !p_que.empty() ){
		pair<int, int> f = p_que.top(); p_que.pop();
		int u = f.second;
		color[u] = black;

		// 最小値を取り出し、それが最短でなければ無視
		if(d[u] < f.first * (-1)) continue;

		for (int j = 0; j < adj[u].size(); j++) {
			int v = adj[u][j].first;
			if ( color[v] == black ) continue;
			if (d[v] > d[u] + adj[u][j].second ){
				d[v] = d[u] + adj[u][j].second;
				p_que.push(make_pair(d[v] * (-1), v));
				color[v] = gray;
			}
		}
	}
	rep(i, n){
		cout << i << " " << (d[i] == inf ? -1 : d[i]) << endl;
	}
}

int main()
{
	cin >> n;
	rep(i,n){
		int u, k;
		cin >> u >> k;
		rep(j,k){
			int a, b;
			cin >> a >> b;
			adj[u].push_back(make_pair(a,b));
		}
	}
	dijkstra();
	return 0;
}



Measured memory_bytes: 8096
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

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

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

int main(){
  int n;
  cin >> n;
  vector<int> t(n), a(n);
  for(int i=0; i<n; i++){
    cin >> t.at(i) >> a.at(i);
  }
  long long T, A, nt, na, N;
  for(int i=0; i<n; i++){
    if(!i){
      T = t.at(i);
      A = a.at(i);
    }else{
      nt = (t[i] + T - 1)/t[i];
      na = (a[i] + A - 1)/a[i];
      N = max(nt, na);
      T = N * t.at(i);
      A = N * a.at(i);
    }
  }
  cout << T + A << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

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

    int n,k,q,tmp;
    int mem[100001];
    cin >> n >> k >> q;
    memset(mem,0,sizeof(mem));
    for(int i = 0; i < q; i ++){
        cin >> tmp;
        mem[tmp] ++;
    }
    for(int i = 1; i <= n; i ++){
        if(mem[i]-q+k > 0) cout << "Yes";
        else cout << "No";

        cout << "\n";
    }


    return 0;
}









Measured memory_bytes: 4020
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt();
		if(Math.abs(a-b) >= 2 && a > b) {
			System.out.println(a + (a - 1));
		}else if(Math.abs(a-b) >= 2 && a <= b) {
			System.out.println(b + (b - 1));
		}else {
			System.out.println(a + b);
		}
	}
}

Measured memory_bytes: 23764
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

int main() {
  string s;
  cin >> s;
  string ans;
  if (s == "AAA" || s == "BBB")
    ans = "No";
  else
    ans = "Yes";

    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define YY "YES\n"
#define NN "NO\n"
#define LL long long
#define mp make_pair
using namespace std;

int n,m,tt,tar,k,tmp,l,ans[200001],dsua[200001],dsub[200001];
vector<int> ar[200001];

int finda(int now){
	if (dsua[now]==now) return now;	
	return dsua[now]=finda(dsua[now]); 
}
int findb(int now){
	if (dsub[now]==now) return now;	
	return dsub[now]=findb(dsub[now]); 
}

int main(){
	int x,y;
	cin>>n>>k>>l;
	for (int i=1;i<=n;i++){
		dsua[i]=i;
		dsub[i]=i;
	}
	for (int i=1;i<=k;i++){
		cin>>x>>y;
		int a=finda(x);
		int b=finda(y);
		if (a!=b){
			dsua[a]=dsua[b];
		}
	}
	for (int i=1;i<=l;i++){
		cin>>x>>y;
		int a=findb(x);
		int b=findb(y);
		if (a!=b){
			dsub[a]=dsub[b];
		}
	}
	for (int i=1;i<=n;i++){
		finda(i);
		findb(i);
	}
	map<pair<int,int>,int> mpp;
	for (int i=1;i<=n;i++){
		mpp[mp(dsua[i],dsub[i])]++;
	}
	for (int i=1;i<=n;i++){
		cout<<mpp[mp(dsua[i],dsub[i])]<<" ";
	}
}

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

#define int long long
#define INF 9223372036854775807

int memo[100009];

vector<int> v(100009);

int n;

int dp(int index){
    if(index >= n) return INF/2;
    if(index == n-1) return 0;
    if(memo[index] != -1) return memo[index];
    return memo[index] = min(dp(index+1)+abs(v[index+1]-v[index]), dp(index+2)+abs(v[index+2]-v[index]));
}

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

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    for(int i = 0; i < 100009; i++){
        memo[i] = -1;
    }
    cout << dp(0) << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int r, w, C, R;
    while(cin>>r>>w>>C>>R, r||w||C||R) {
        int need = w*C-r;
        int ans = 0;
        while (need>0) {
            need-=R;
            ans++;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3148
#include <iostream>
using namespace std;
int main(void){
    int n,x;
    cin>>n;
    
    for(int i=1;i<=n;i++){
        x=i;
        if(x%3==0)cout<<" "<<i;
        else{
            do{
            if(x%10==3){
                cout<<" "<<i;
                break;
            }
            x=x/10;
            }while(x!=0);
        }
    }
    cout << endl;
}


Measured memory_bytes: 3096
import itertools
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split()))for _ in range(q)]
ans=0
for i in itertools.combinations_with_replacement(range(m),n):
  anss=0
  for a,b,c,d in abcd:
    if i[b-1]-i[a-1]==c:anss+=d
  ans=max(ans,anss)
print(ans)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int calc(int N){
    int res=0;
    while(N>0){
        res++; N/=10;
    }
    return res;
}

signed main()
{
    int N; cin>>N;
    int ans=100;
    for(int i=1;i*i<=N;i++){
        if(N%i==0) ans=min(ans,calc(N/i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    int n;
    cin>>n;
    vi x(n);
    lli ans=INF;
    rep(i,n){
        cin>>x[i];
    }
    rep(i,101){
        int p=i;
        lli now=0;
        rep(j,n){
            now+=pow(x[j]-p,2);
        }
        ans=min(now,ans);
    }
    out(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, ans=0;
  string si;
  set<string> s;
  
  cin >> N;
  
  for(int i = 0; i < N; i++){
    cin >> si;
    if(!s.count(si)){
      s.insert(si);
      ans++;
    }
  }
      
  
  cout << ans << endl;
}

Measured memory_bytes: 19224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
using namespace std;

int main(){
    string s; cin >> s;
    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
return 0;
}
 

Measured memory_bytes: 3624
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
static long p = 1000000007;
static long factMax = 200000;//nCkにおけるnの最大値
static long[] factorials = new long[factMax+1];//i!(mod p)をO(n)で先にメモ。
static long[] factorialRs = new long[factMax+1];//i!^-1(mod p), pは素数でO(n)。

	static void Main()
	{
    string[] input = Console.ReadLine().Split(' ');
		long n = long.Parse(input[0]);
		long a = long.Parse(input[1]);
    long b = long.Parse(input[2]);
    factorials[0] = 1;
    factorialRs[factMax] = DivideModFactorial(factMax,p);
    for(long i = 1; i <= factMax; i++)
    {
      factorials[i] = (factorials[i-1]*i)%p;//i!(mod p)
      factorialRs[factMax-i] = (factorialRs[factMax+1-i]*(factMax+1-i))%p;//逆元も先にメモ
    }

    long answer = DivideMod(2,n,p)-1;
    if(answer < 0) answer += p;

    long answerMemo = 1;
    for(long i = 0; i < a; i++)
    {
      answerMemo *= n-i;
      answerMemo %= p;

      answerMemo *= DivideModReverse(a-i,p);
      answerMemo %= p;
    }
    answer -= answerMemo;
    answer %= p;
    if(answer < 0) answer += p;

    answerMemo = 1;
    for(long i = 0; i < b; i++)
    {
      answerMemo *= n-i;
      answerMemo %= p;

      answerMemo *= DivideModReverse(b-i,p);
      answerMemo %= p;
    }
    answer -= answerMemo;
    answer %= p;
    if(answer < 0) answer += p;
    
    Console.WriteLine(answer);
	}

  static long MathPow(long x, long a)//戻り値はx^a。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x;
  
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
      }
    memo *= memo;
    num *= 2;
    }
    return answer;
  }

  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x%p;
    
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
        answer %= p;
      }
    memo *= memo;
    memo %= p;
    num *= 2;
    }
    return answer;
  }

  static long DivideModReverse(long x, long p)//戻り値はx^-1(mod p), pは素数。O(logp)
  {
    long answer = DivideMod(x, p-2, p);
    return answer;
  }

  static long ModFactorial(long x, long p)//戻り値はx!(mod p)
  {
    long answer = 1;
    for(int i = 2; i <= x; i++)
    {
      answer *= i;
      answer %= p;
    }
    return answer;
  }

  static long DivideModFactorial(long x, long p)//戻り値はx!^-1(mod p), pは素数
  {
    long answer = 1;
    for(long i = x; i >= 2; i--)
    {
      answer *= DivideModReverse(i, p);
      answer %= p;
    }
    return answer;
  }

  static long Comb(long a, long b, long p)//組み合わせC(a,b)(mod p)をO(1)で返す
  {
    if(a-b < 0) return 0;//引数a-bが負なら0を返す
    long answer = 1;
    answer *= factorials[a];
    answer %= p;
    answer *= factorialRs[a-b];
    answer %= p;
    answer *= factorialRs[b];
    answer %= p;
    return answer;
  }
  
}


Measured memory_bytes: 14292
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

    int n;
    long long int k;
    cin >> n >> k;

    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i]--;
    }

    int b[n+1]={};
    vector<int> c;

    int d=0;

    for(int i=0;i<n+3;i++){
        b[d]++;
        c.push_back(d);
        if(b[d]==2)break;
        d=a[d];
    }

    int p;
    p=c.size();
    int q=0;

    for(int i=0;i<p;i++){
        if(c[i]==c[p-1]){
            q=i;
            break;
        }
    }

    if(k<p)cout << c[k]+1 << endl;
    else cout << c[q+(k-p+1)%(p-q-1)]+1 << endl;
    
}

Measured memory_bytes: 5884
#!usr/bin/env python3

import sys
import re


def main():
    s = sys.stdin.readline()  # haystack
    p = sys.stdin.readline()  # needle

    s = s.strip('\n') * 2
    p = p.strip('\n')

    if len(re.findall((p), s)) > 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 7632
#include <stdio.h>
#include <math.h>
#include <string.h>
#define pai 3.1415926535

int main(void) {
	int N;
	scanf("%d", &N);
	char u[4];
	double x[10];
	double sum = 0.0;
	for (int i = 0; i < N; i++) {
		scanf("%lf", &x[i]);
		scanf("%s", u);
		if (u[0] =='B') {
			sum += 380000.0*x[i];
		}
		else {
			sum += x[i];
		}
	}
	printf("%f", sum);


	return 0;
}




Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==7 && b==5 && c==5)cout<<"YES"<<endl;
  else if(a==5 && b==7 && c==5)cout<<"YES"<<endl;
  else if(a==5 && b==5 && c==7)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int n, x; cin >> n >> x;
  int rem = x;
  int min = 1000;
  vector<int> m(100);
  REP(i, n) { 
    cin >> m[i];
    // 最低一種類
    rem -= m[i];
    if (min > m[i]) min = m[i];
  }
  cout << n + rem / min << endl;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxn = 200100;

int n,res;
string a[maxn];

void roll(char &a, char &b, char &c, char &d) {
   char temp = a;
   a = b;
   b = c;
   c = d;
   d = temp;
}

void rotate90() {
    for(int i=0; i<n/2; i++)
        for(int j=0; j<(n+1)/2; j++)
            roll(a[i][j], a[n-1-j][i], a[n-1-i][n-1-j], a[j][n-1-i]);

}

bool check() {
   for (int i=0;i<n;i++)
      for (int j=0;j<n;j++)
         if (a[i][j]!=a[j][i]) return false;
   return true;
}

int main() {
     // freopen("in.txt","r",stdin);
      ios_base::sync_with_stdio(0); cin.tie(0);
      cin>>n;
      for (int i=0;i<n;i++) cin>>a[i];
      for (int time=0;time<n;time++) {
         for (int i=0;i<n;i++) rotate(a[i].begin(),a[i].begin()+1,a[i].end());
         res+=check();
      }
      cout<<res*n;
}


Measured memory_bytes: 1920
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <math.h>
#include <string.h>

using std::endl;
using std::string;

#define ll long long int
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std

ll A, B, C, X, Y, Min;
ll Ans = 0;

int main()
{

	IN >> A >> B >> C >> X >> Y;

	if (A + B >= C * 2)
	{
		Min = std::min(X, Y);
		Ans = Min * C * 2;
		X -= Min;
		Y -= Min;
	}
	else
	{
		Ans = X * A + Y * B;
		OUT << Ans << endl;
		return 0;
	}
	
	if (X * A + Y * B >= (X + Y) * 2 * C)
	{
		Ans += (X + Y) * 2 * C;
	}
	else
	{
		Ans += X * A + Y * B;
	}

	OUT << Ans << endl;

	return 0;
}

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

const int SIZE = 20;
const int MAX = 255;
int town,way;
int e[SIZE][SIZE];
int cost[SIZE];
bool used[SIZE];

int dijkstra(int start, int end){
	for(int i=0; i<town; i++){
		cost[i] = MAX;
		used[i] = false;
	}
	cost[start] = 0;

	while(1){
		//step1
		int v = -1;
		for(int i=0; i<town; i++)
			if(!used[i] && (v==-1 || cost[v]>cost[i])) v=i;
		if(v==-1) break;
		//step2
		used[v] = true;
		//step3
		for(int i=0; i<town; i++)
			cost[i] = min(cost[i],cost[v]+e[v][i]);
	}

	return cost[end];
}

int main(void){
	int start,end,money,price,prize;
	char dummy;

	cin >> town >> way;
	for(int i=0; i<town; i++){
		for(int j=0; j<town; j++){
			e[i][j]=MAX;
		}
	}
	for(int i=0; i<way; i++){
		int a,b,atob,btoa;
		cin >> a >> dummy >> b >> dummy >> atob >> dummy >> btoa;
		a--; b--;
		e[a][b] = atob;
		e[b][a] = btoa;
	}
	cin >> start >> dummy >> end >> dummy >> money >> dummy >> price;
	end--; start--;

	prize = money - price;
	prize -= dijkstra(start,end);
	prize -= dijkstra(end,start);

	cout << prize << endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  ll sum=0,l=s.length();
  rep(i,l) sum+=s[i]-'0';
  print((sum%9==0)?"Yes":"No");
  return 0;
}

Measured memory_bytes: 3768
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i,n) cin >> a[i];
	
	ll ans=-1*n;
	REP(i,n){
		ans += a[i];
	}
	
	cout << ans << endl;
	
	return 0;
}

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

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

int main()
{
  string str;
  int n;
  cin >> n;
  cin.get();
  while (n--){
    getline(cin, str);
    REP(i, sz(str) - 6){
      if (str.substr(i, 7) == "Hoshino") str.replace(i, 7, "Hoshina");
    }
    cout << str << endl;
  }
}

Measured memory_bytes: 1216