akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <complex>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)


void solve(std::string S){
  int sz=S.size();
  if(S[sz-1]=='s'){
    cout<<S<<"es"<<endl;
  }else{
    cout<<S<<"s"<<endl;
  }
}

int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int isprime(int n){
    for(int i=2;i<n;i++){
        if(n%i==0)
            return 0;
        }
    return 1;
}

int main(){
    int num;
    while(1){
        scanf("%d",&num);
        if(num==0)break;
        for(int i=num;i>3;i--){
            if(isprime(i)==1&&isprime(i-2)==1){
                printf("%d %d\n",i-2,i);
                break;
            }
        }
    }
    return 0;
}
    

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

int main(){
	int number=0;
	int A, B, K;
	cin>>A>>B>>K;
	for(int k=A;k>0;k-=1){
		int amari=A%k;
		if(amari==0){
			int amari2 = B%k;
			if(amari2==0){
				number += 1;
			}
		}
		if(number==K){
			cout<<k;
			return 0;
		}
	}
	return 0;
}


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

#define INF 100000
//???,???,???,???
int dx[4]={-1, 0, 1, 0}, dy[4]={0, 1, 0, -1};
typedef struct DIR{
  int cango[4];
  int d;
}dir;

int w, h;

int main(){
    while(cin>>w>>h, !(w==0&&h==0)){
    dir a[h][w];
    //??\???
    for(int i=0; i<h*2-1; i++){
      if(i%2==0){
	for(int j=0; j<w-1; j++){//?¨???????
	  int tmp;
	  cin>>tmp;
	  a[i/2][j].cango[1]=tmp;
	  a[i/2][j+1].cango[3]=tmp;
	}
      }
      else{
	for(int j=0; j<w; j++){//?????????
	  int tmp;
	  cin>>tmp;
	  a[i/2][j].cango[2]=tmp;
	  a[i/2+1][j].cango[0]=tmp;
	}
      }
    }
    for(int i=0; i<h; i++)
      for(int j=0; j<w; j++)
	a[i][j].d=INF;
    a[0][0].d=0;
    queue< pair<int, int> > q;
    q.push(pair<int, int>(0, 0));
    bool flag=false;
    while(!q.empty()){
      pair<int, int> now=q.front(); q.pop();
      if(now.first==h-1 && now.second==w-1){
	flag=true;//??´???????????§??????????????????
	break;
      }
      for(int i=0; i<4; i++){
	int nx=now.first+dx[i], ny=now.second+dy[i];
	if(0<=nx && nx<h && 0<=ny && ny<w && a[now.first][now.second].cango[i]==0 && a[nx][ny].d==INF){
	  a[nx][ny].d=a[now.first][now.second].d+1;
	  q.push(pair<int, int>(nx, ny));
	  //printf("push x=%d, y=%d\n", nx, ny);
	}
      }
    }
    if(flag)cout<<a[h-1][w-1].d+1<<endl;
    else cout<<"0"<<endl;
    }
  return 0;
}

Measured memory_bytes: 1232
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r1 = ReadSplit();
            var n = r1[0].ToInt();
            var m = r1[1].ToInt();
            var r2 = ReadSplit();
            var l = new List<int>();
            for (int i = 0; i < n; i++)
            {
                var a = r2[i].ToInt();
                l.Add(a);
            }
            var sum = l.Sum();
            var count = 0;
            for (int i = 0; i < n; i++)
            {
                if (l[i] < (decimal)sum / (decimal)(4 * m))
                {
                    continue;
                }
                count++;
            }
            var ans = "Yes";
            if (m > count) ans = "No";
            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {   
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 13268
import math

n, m = map(int, input().split())
a = list(map(int, input().split()))

total = sum(a)
under = math.ceil(total/(4*m))

cnt = 0

for i in a:
    if i >= under:
        cnt += 1

if cnt >= m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <stdio.h>
const int C=3001;

int n, i, j;
double dp[C][C], p, wn=0;

int main(){
	scanf ("%d", &n);
	
	dp[0][0]=1.0;	
	for (i=1;i<=n;i++){
		scanf ("%lf", &p);
		dp[i][0]=dp[i-1][0]*(1-p);
		for (j=1;j<=n;j++)		dp[i][j]=dp[i-1][j-1]*p+dp[i-1][j]*(1-p);
		
	}
	
	for (i=n/2+1;i<=n;i++)	wn+=dp[n][i];
	
	printf ("%.9lf", wn);
	
return 0;}

Measured memory_bytes: 70528
#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)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = 1LL << 32;

ll getq(priority_queue<ll>& q, ll t) {
  ll ret = 0;
  vll buf;
  for (ll i = 0; i < t; i++) {
    ret += q.top();
    buf.push_back(q.top());
    q.pop();
  }
  for (auto v : buf) {
    q.push(v);
  }

  return ret;
}

int main() {
  ll n, w;

  cin >> n >> w;

  vll ws(n);
  vll vs(n);

  priority_queue<ll> q[4];

  ll tw, tv;
  cin >> tw >> tv;
  ll w0 = tw;
  q[0].push(tv);
  for (ll i = 1; i < n; i++) {
    cin >> tw >> tv;
    bool chk = false;
    for (ll j = 0; j < 4; j++) {
      if (tw == w0 + j) {
        q[j].push(tv);
        chk = true;
        break;
      }
    }  // j
    assert(chk);
  }  // i

  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    if (i > (ll)q[0].size()) continue;
    for (ll j = 0; j <= n; j++) {
      if (j > (ll)q[1].size()) continue;
      for (ll k = 0; k <= n; k++) {
        if (k > (ll)q[2].size()) continue;
        for (ll l = 0; l <= n; l++) {
          if (l > (ll)q[3].size()) continue;
          ll wt = w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l;
          if (wt <= w) {
            ll tmp = 0;
            tmp += getq(q[0], i);
            tmp += getq(q[1], j);
            tmp += getq(q[2], k);
            tmp += getq(q[3], l);
            chmax(ans, tmp);
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;



signed main() {
	int a, b, k;
	cin >> a >> b >> k;
	if (a >= k)cout << a - k << " " << b << endl;
	else cout << 0 << " " << max(0LL,a + b - k) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int sum,s = 0;
	int n,m,c;
	int b[101],a[101];
	scanf("%d %d %d",&n,&m,&c);
	for(int i = 0;i < m;i++){
		scanf("%d",&b[i]);
	}
	for(int i = 0;i < n;i++){
		sum = 0;
		for(int j = 0;j < m;j++){
			scanf("%d",&a[j]);
			sum += b[j] * a[j];
		}
		if(sum + c > 0) s++;
	}
	printf("%d",s);
	return 0;
}

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

int bitsum(int n){
    int sum=0;
    int dis;
    sum += n/10000; dis = n%10000;
    sum += dis/1000; dis = dis%1000;
    sum += dis/100; dis = dis%100;
    sum += dis/10; dis = dis%10;
    sum += dis;
    return sum;
}

int main(){

    int n, a, b;
    int sum=0;
    int dispose;
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++){
        dispose = bitsum(i);
        if(dispose>=a && dispose<=b)
            sum += i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3552
n, u, v, m = gets.split.map &:to_i

number_pos = {}
marked = {}
%w(usagi neko).each do |name|
	number_pos[name] = {}
	(0..n-1).each do |i|
		gets.split.map(&:to_i).each.with_index do |k, j|
			(number_pos[name][k] ||= []) << [i, j]
		end
	end

	marked[name] = {
		:h => [0] * n,
		:v => [0] * n,
		:up => 0,
		:down => 0
	}
end

bingo = Hash.new(0)
m.times do
	k = gets.to_i
	%w(usagi neko).each do |name|
		a = number_pos[name][k]
		next if !a
		a.each do |i, j|
			marked[name][:h][i] |= (1 << j)
			bingo[name] += 1 if marked[name][:h][i]+ 1 == (1 << n)
			marked[name][:v][j] |= (1 << i)
			bingo[name] += 1 if marked[name][:v][j] + 1 == (1 << n)
			if i == j
				marked[name][:up] |= (1 << i)
				bingo[name] += 1 if marked[name][:up] + 1 == (1 << n)
			end
			if i + j == n-1
				marked[name][:down] |= (1 << i)
				bingo[name] += 1 if marked[name][:down] + 1 == (1 << n)
			end
		end
	end

	c = (n == 1 ? 3 : 1)

	if bingo['usagi'] / c >= u && bingo['neko'] / c >= v
		puts 'DRAW'
		exit
	end
	if bingo['usagi'] / c >= u
		puts 'USAGI'
		exit
	end
	if bingo['neko'] / c >= v
		puts 'NEKO'
		exit
	end
end

puts 'DRAW'

Measured memory_bytes: 75164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for (int i = 0; i < s.size()-1; i++) {
        for (int j = i+1; j < s.size(); j++) {
            if (s[i] == s[j]) {
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    vector<ll>t(n);
    ll g=0;
    ll lcm=1;
    for (int i = 0; i < n; ++i) {
        cin >>t[i];
        g=__gcd(lcm,t[i]);
        lcm=lcm*(t[i]/g);
//        cout <<lcm <<endl;
    }
    cout <<lcm <<endl;
}



Measured memory_bytes: 256
n = int(input())
A = sorted(list(map(int, input().split())))
from collections import Counter
c = Counter(A)

MAX = 10 ** 6 + 1000
dp = [True] * MAX

for k, v in c.items():
    if dp[k] == False: continue
    if v > 1: dp[k] = False
    for x in range(k + k, MAX, k):
        dp[x] = False

res = 0
for x in range(n):
    if dp[A[x]]: res += 1
print(res)

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

#define int long long
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define veci vector<int>
#define pii pair<int,int>
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define repi(i,a,b) for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define fi first 
#define se second
#define all(v) v.begin(),v.end()

int mod=1e9+7;

int powerm(int x,int y, int M){ int res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
int  power(int x,int y){ int res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
bool isprime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
    T=1;
//    cin>>T;
while(T--){
    int n,k;
    cin>>n>>k;
    veci p(n);
    rep(i,n) cin>>p[i];
    sort(all(p));
    int price=0;
    rep(i,k) price+=p[i];
    cout<<price;
}
    
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int nums[200];
  for (int i = 0; i < N; i++) {
    cin >> nums[i];
  }

  int count = 0;
  bool isAllEven = true;
  while (true) {
    for (int i = 0; i < N; i++) {
      if (nums[i] % 2 != 0) {
        isAllEven = false;
        break;
      }
      nums[i] /= 2;
    }
    if (isAllEven == false) {
      break;
    }
    count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h> 
using namespace std;
int solve(int N, vector<int>& heights, vector<int>& dp){
	if (N<=1) return 0;
	if (N==2) return dp[N]=abs(heights[0]-heights[1]);
	if (dp[N]!=-1) return dp[N];
	return dp[N]=min(solve(N-1,heights,dp)+abs(heights[N-1]-heights[N-2]),solve(N-2,heights,dp)+abs(heights[N-1]-heights[N-3]));
}
int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int N;
    cin>>N;
    vector<int> heights(N);
    vector<int> dp(N+1,-1);
    for (int i=0;i<N;i++){
    	cin>>heights[i];
    }
    if (N==1) cout<<heights[0];
    else
	    cout<< solve(N,heights,dp)<<endl;
    // for (int i=0;i<=N;i++) cout<<dp[i]<<" ";
    return 0; 
}


Measured memory_bytes: 7220
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
#define rep2(i,a,b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int N; cin >> N;
    string s; cin >> s;
    int ans = 0;
    rep(i,N + 1) {
        vector<int> a(26,0),b(26,0);
        rep(j,i) a[s[j] - 'a'] = 1;
        rep2(j,i,N) b[s[j] - 'a'] = 1;
        int cnt = 0;
        rep(j,26) {
            if (a[j] && b[j]) ++cnt;
        }
        ans = max(ans,cnt);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
const long long mod=1e9+7;
int main(){
    int N,M;
    cin>>N>>M;
    vector<int> a(N+1,true);
    REP(i,M){
        int k;cin>>k;
        a[k]=false;
    }

    vector<long long> dp(N+1);
    dp[0]=1;
    REP(i,N){
        for(int j=i+1;j<=min(N,i+2);j++){
            if(a[j]){
                dp[j]+=dp[i]%mod;
                dp[j]%=mod;
            }
        }
    }
    cout<<dp[N]<<endl;
}

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

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

int n, a, b;

void solve() {
  cout << min(n * a, b) << endl;
}

int main() {
  cin >> n >> a >> b;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, N, a[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	
	int count = 0;
	for (i = 1; i <= N; i++) if (a[a[i]] == i) count++;
	
	printf("%d\n", count / 2);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main(void)
{
    ll n;
    cin >> n;
    ll ma = 0, ans = 0;
    for (int i = 0; i < n;i++){
        int a, b;
        cin >> a >> b;
        if(a>ma){
            ans = a + b;
            ma = a;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    long long A, V, B, W, T, dist;
    cin >> A >> V >> B >> W >> T;
    dist = abs(A - B);
    if(dist <= V * T - W * T){
        cout << "YES";
    }
    else cout << "NO";
    cout << endl;
}


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

ll solve() {
    ll N;
    cin >> N;
    ll a, n = 1, no = 1;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        n *= 3;
        if ( a&1 ) {
            no *= 1;
        } else {
            no *= 2;
        }
    }
    ll ans = n - no;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

N, M, K = map(int, input().split())
A = list(accumulate([0] + list(map(int, input().split()))))
B = list(accumulate([0] + list(map(int, input().split()))))


ans, j = 0, M

for i in range(N+1):
    if A[i] > K:
        break
    while B[j] > K-A[i]:
        j -= 1
    ans = max(ans, i+j)


print(ans)

Measured memory_bytes: 42848
n = int(input())

pair = [n, 1]
i = 2
d_min = n**2 + 1
while i * i <= n:
    if n % i == 0 and d_min > (n/i)**2 + i**2:
        pair[0] = int(n/i)
        pair[1] = i
    i += 1

print(pair[0]+pair[1]-2)

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    ll n, t; cin >> n >> t;
    vector<ll> time(n);
    rep(i, n) cin >> time[i];
    
    ll ans = 0;
    ll now = time[0];
    REP(i, 1, n) {
        if(now + t <= time[i]) ans += t;
        else ans += time[i] - now;
        now = time[i];
    }

    cout << ans+t << '\n';
    return 0;
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] p = new int [n];
    for(int i = 0; i < n; i++) {
    	p[i] = sc.nextInt();
    }
    Arrays.sort(p);
    
    int ans = 0;
    for(int i = 0; i < k; i++) {
    	ans += p[i];
    }
    System.out.println(ans);
  }
}



Measured memory_bytes: 38524
n = int(input())

A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...
B =        list( map(int, input().split()) )	# 1 2 3 4 5 ...
C =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

ans=0

x=-2
for a in A:
	a-=1
	ans+=B[a]
	if a==x+1:
		ans+=C[a-1]
	x=a

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
int main(){

char d;
int N=0,W=0,S=0,E=0;
while (1)
{
  scanf("%c",&d);
  if (N&&W&&S&&E){
    puts("Yes");
    exit(0);
    break;
  }
  if (d=='\n'){break;}
  switch (d)
  {
  case 'N':
    N=1;
    break;
  case 'W':
    W=1;
    break;
  case 'S':
    S=1;
    break;
  case 'E':
    E=1;
    break;
  default:
    break;
  }
}

if((N&S)&(!W&!E)){
  puts("Yes"); 
} else if ((!N&!S)&(W&E))
{
  puts("Yes"); 
}else
{
  puts("No");
}

return 0;

}

Measured memory_bytes: 1580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  ll l=0,m=0,n=s.size(),ans=0;
  s += '0';
  for(int i=0;i<n;i++){
    if(s.at(i)=='<') l++;
    else if(s.at(i)=='>') m++;
    if((s.at(i)=='>'&&s.at(i+1)=='<')||i==n-1){
      ll j=max(l,m),k= min(l,m);
      ans += j*(j+1)/2+k*(k-1)/2;
      l=0;m=0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 900
n = int(input())
s = input()

r = g = b = 0
for i in range(n):
    if s[i] == 'R':
        r += 1
    elif s[i] == 'G':
        g += 1
    else:
        b += 1

x = 0
for i in range(n):
    for j in range(i+1, n):
        k = j + j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            x += 1
print(r*g*b-x)


Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
string a,b;
int ans=1e8;
int main(){
	cin>>a>>b;
	for(int i=0;i<a.size()-b.size()+1;i++){
		string tmp=a.substr(i,b.size());
		//cout<<tmp;
		int cnt=0;
		for(int j=0;j<b.size();j++){
			if(tmp[j]!=b[j]) cnt++;
		}
		ans=min(ans,cnt);
	}
	cout<<ans;
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int ph; cin>>ph; --ph;
	bool yes=true;
	for(int i=1;i<n;++i){
		int p; cin>>p;
		if(ph>p)yes=false;
		if(p>ph)--p;
		ph=p;
	}
	cout<<(yes?"Yes"s:"No"s)<<"\n"s;
}

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

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

const double EPS = 1e-10;

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

ll n,a,b,c,d;
map<ll, ll> dp;

ll dfs(ll now){
    if(now == 0) return dp[0] = 0;
    if(now == 1) return dp[1] = d;
    if(dp.count(now)) return dp[now];
    ll res = LINF;
    if((LINF)/d > now) res = now*d;
    vector<ll> v = {a,b,c};
    rep(i,3){
        int next = vector<int>{2,3,5}[i];
        if(now % next == 0){
            res = min(res,dfs(now/next)+v[i]);
        }
        else{
            ll l = now/next*next, r = l+next;
            res = min(res,dfs(l/next)+v[i]+(now-l)*d);
            res = min(res,dfs(r/next)+v[i]+(r-now)*d);
        }
    }
    return dp[now] = res;

}

int main(){
    int t; cin >> t;
    while(t--){
        cin >> n >> a >> b >> c >> d;
        dp.clear();
        dfs(n);
        cout << dp[n] << endl;
    }
}



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

int n,i,s;
int a[100005];

int main ()
{
	cin >> n;
	
	for ( i = 1 ; i <= n ; ++ i )
		cin >> a[i];
	
	s = a[2] - a[1];
	for ( i = 3 ; i <= n ; ++ i )
		s = a[i] - s;
	
	a[0] = s / 2;
	
	for ( i = 1 ; i <= n ; ++ i )
		a[i] -= a[i-1];
	
	for ( i = 0 ; i < n ; ++ i )
		cout << 2 * a[i] << ' ';
	
	return 0;
	
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=1e6+5,MAX=3e7,MOD=1e9+7;
 
using namespace std;

int a[10];
int n,A,B,C;
int solve(int indx,int c1,int c2,int c3){
	if(indx==n){
		if(!c1 || !c2 || !c3)return 1e9;
		return abs(A-c1)+abs(B-c2)+abs(C-c3);
	}

	int ret = 0;

	ret = solve(indx+1,c1,c2,c3);
	ret = min(solve(indx+1,a[indx]+c1,c2,c3)+(c1!=0)*10,ret);
	ret = min(solve(indx+1,c1,a[indx]+c2,c3)+(c2!=0)*10,ret);
	ret = min(solve(indx+1,c1,c2,a[indx]+c3)+(c3!=0)*10,ret);

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


      scanf("%d %d %d %d",&n,&A,&B,&C);

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

      printf("%d\n",solve(0,0,0,0) );
      
 }

Measured memory_bytes: 256
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP
*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define PB push_back
#define IN insert
#define MP make_pair
#define PI acos(-1)
#define LW(v) sort(v.begin(),v.end());
#define HI(v) sort(v.begin(),v.end(),greater<long long>());
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie (0);
    long long y,a,m=0,n=0,x=0;//t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m;
    l(i,0,m)
    {
        cin>>a;
        v.PB(a);
    }
    x=accumulate(v.begin(),v.end(),0);
    y=n-x;

    if(y<0)
    {
        cout<<"-1"<<endl;
    }
    else{cout<<y<<endl;}


  //  cout<<setprecision(20)<<fixed<<m<<endl;
}


Measured memory_bytes: 3752
# coding: utf-8
# Your code here!
N = int(input())
A = list(map(int,input().split()))
B = [0] + list(map(int,input().split()))
C = [0] + list(map(int,input().split()))
#print(A,B,C)
manzoku = 0
for i in range(N):
    manzoku += B[A[i]]
    if i > 0 and A[i] == A[i-1]+1:
        manzoku += C[A[i-1]]
    
print(manzoku)

Measured memory_bytes: 3064
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int M = 3e5 + 10;
const int mod = 998244353;

int n, a, b;
ll x;
int fac[M], inv[M]; 

inline int pwr(int a, int b) {
	int ret = 1;
	while(b) {
		if(b&1) ret = 1ll * ret * a % mod;
		a = 1ll * a * a % mod;
		b >>= 1;
	}
	return ret;
}

inline int C(int n, int m) {
	if(m>n || n<0 || m<0) return 0;
	return 1ll * fac[n] * inv[m] % mod * inv[n-m] % mod;
}

int main() {
	fac[0] = 1;
	for (int i=1; i<=300000; ++i) fac[i] = 1ll * fac[i-1] * i % mod; 
	inv[300000] = pwr(fac[300000], mod-2);
	for (int i=299999; i; --i) inv[i] = 1ll * inv[i+1] * (i+1) % mod;
	inv[0] = 1;
	cin >> n >> a >> b >> x;
	ll res;
	int ans = 0;
	for (int i=0; i<=n; ++i) {
		res = x - (ll)i * a;
		if(res % b) continue;
		res /= b;
		ans += 1ll * C(n, i) * C(n, res) % mod;
		if(ans >= mod) ans -= mod;
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 2560
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

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

	ll A, P;
	cin >> A >> P;

	P += A * 3;

	P = P / 2;

	cout << P << endl;




	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 
 
int main() {
    int n; cin >> n;
    vector<int> a(n); 
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    rep(i,n){
        if(a[i+1]==a[i]) {
             NO;
             return 0;
        }     
    }
    YES;
}            

Measured memory_bytes: 1024
// Undone
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    double N = ReadDouble();
    double[] a = new double[5];
    for (int i = 0; i < a.Length; i++) {
      double d = ReadDouble();
      a[i] = (d < N) ? Math.Ceiling(N/d) : 0;
    }
    double ans = 0;
    if (a.Max() == 0) {
      ans = 5;
    } else {
      ans = a.Max() + 4;
    }
    Console.WriteLine((long)ans);
  }

  private static List<int> _var;
  public static int cin() { if (_var == null || _var.Count() == 0) { _var = Console.ReadLine().Split(' ').Select(int.Parse).ToList<int>(); } int ans = _var[0]; _var.RemoveAt(0); return ans; }
  public static void Swap<T>(ref T a, ref T b) {T temp = a;a = b;b = temp;}
  public static string ReadStr() { return Console.ReadLine(); }
  public static int ReadInt() { return int.Parse(Console.ReadLine()); }
  public static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  public static long ReadLong() { return long.Parse(Console.ReadLine()); }
  public static char ReadChar() { return Console.ReadLine()[0]; }
  public static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  public static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  public static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  public static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  public static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  public static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}


Measured memory_bytes: 13396
N = int(input())
A = list(input().split())
number = [int(a[1]) for a in A]
mark = [a[0] for a in A]

def bubbleSort(C_number, C_mark, N):
    for i in range(N):
        for j in reversed(range(i+1, N)):
            if C_number[j] < C_number[j-1]:
                # 番号の順番交換
                temp = C_number[j]
                C_number[j] = C_number[j-1]
                C_number[j-1] = temp
                # マークも順番交換
                temp = C_mark[j]
                C_mark[j] = C_mark[j-1]
                C_mark[j-1] = temp
    return C_number, C_mark

def selectionSort(num, mark, N):
    for i in range(N):
        min_val = min(num[i:])
        min_index = num[i:].index(min_val) + i
        if num[i] != min_val:
            # 番号の順番交換
            temp = num[i]
            num[i] = min_val
            num[min_index] = temp
            # マークも順番交換
            temp = mark[i]
            mark[i] = mark[min_index]
            mark[min_index] = temp

    return num, mark

b_num, b_mark = bubbleSort(number.copy(), mark.copy(), N)
s_num, s_mark = selectionSort(number, mark, N)

b = [b_mark[i]+str(b_num[i]) for i in range(N)]
s = [s_mark[i]+str(s_num[i]) for i in range(N)]

print(*b)
print("Stable")
print(*s)
is_same = [b[i]==s[i] for i in range(N)]
if all(is_same):
    print("Stable")
else:
    print("Not stable") 

            







Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    string s;
    cin >> s;

    REP(i, s.size()) {
        s[i] = (s[i]-'A' + n) % 26 + 'A';
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int cnt[805]={};
int node[805][805]={};
int d[805][805]={};
int tmp[805]={};
int ok[805]={};
int min(int a,int b){
    return (a<b?a:b);
}
int max(int a,int b){
    return (a>b?a:b);
}
int dfs(int cur,int par){
    int i=0,res=0;
    for(i=0;i<cnt[cur];i++){
       int  v=node[cur][i];
       //printf("%d\n",v);
        if(par==v)continue;
        res=max(res,dfs(v,cur)+d[cur][v]);
    }
    return res;
}
int main(void){
    int n,i,j;
    while(1){
        scanf("%d",&n);
        if(n==0)return 0;
        for(i=0;i<805;i++){
            cnt[i]=0;
            ok[i]=1;
        }
        for(i=0;i<805;i++)for(j=0;j<805;j++)node[i][j]=-1;
        int b,sum=0;
        for(i=1;i<n;i++){
            scanf("%d",&b);
            b--;
            tmp[i]=b;
            node[i][cnt[i]++]=b;
            node[b][cnt[b]++]=i;
        }
        for(i=1;i<n;i++){
            scanf("%d",&d[i][tmp[i]]);
            d[tmp[i]][i]=d[i][tmp[i]];
            sum+=d[i][tmp[i]];
        }
         if(n==3){
             printf("%d\n",sum);
             continue;
        }
        int dist=0,j;
        int cp[n];
        for(i=0;i<n;i++)cp[i]=cnt[i];
        for(i=0;i<n;i++){
            if(cp[i]==1){
                dist+=d[i][node[i][0]];
                sum-=d[i][node[i][0]];
                cnt[i]=0;
                int v=node[i][0];
                for(j=0;j<cnt[v];j++){
                    if(i==node[v][j]){
                        node[v][j]=-1;
                        while(node[v][j+1]!=-1){
                            node[v][j]=node[v][j+1];
                            node[v][j+1]=-1;
                            j++;
                        }
                        break;
                    }
                }
                 cnt[v]--;
            }
        }
        int ans=(int)(1e9);
        int ok=1;
        for(i=0;i<n;i++){
            if(cnt[i]==1){
                //直径を求める
                int max_dist=dfs(i,-1);
                ans=min(ans,(sum-max_dist)*3+max_dist*2);
                ok=0;
            }
        }
        if(ok)ans=0;
       printf("%d\n",ans+dist);
    }
}


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

int main() {
  int64_t V,E,s,A=0;
  cin>>V>>E>>s;
  vector<vector<tuple<int64_t,int64_t,int64_t>>> G(V);
  for(int i=0;i<E;i++){
    int64_t a,b,c;
    int64_t d;
    cin>>a>>b>>c>>d;
    a--,b--;
    G.at(a).push_back(make_tuple(b,c,d));
    G.at(b).push_back(make_tuple(a,c,d));
    A=max(A,c);
  }
  vector<vector<int64_t>> r(V,vector<int64_t>(A*V+1,-1));
  vector<int64_t> z(V,-1);
  vector<pair<int64_t,int64_t>> T(V);
  for(int i=0;i<V;i++){
    int64_t c;
    int64_t d;
    cin>>c>>d;
    T.at(i)=make_pair(c,d);
  }
  if(s>A*V){
    s=A*V;
  }
  priority_queue<tuple<int64_t,int64_t,int64_t>,vector<tuple<int64_t,int64_t,int64_t>>,greater<tuple<int64_t,int64_t,int64_t>>> pq;
  pq.push(make_tuple(0,0,s));
  r.at(0).at(s)=0;
  while(!pq.empty()){
    int64_t t,a,m;
    tie(t,a,m)=pq.top();
    pq.pop();
    if(r.at(a).at(m)<t){
      continue;
    }
    if(z.at(a)==-1){
      z.at(a)=t;
    }
    for(tuple<int64_t,int64_t,int64_t> x:G.at(a)){
      int64_t b,g,k;
      tie(b,g,k)=x;
      if(m>=g){
        if(r.at(b).at(m-g)==-1||r.at(b).at(m-g)>t+k){
          r.at(b).at(m-g)=t+k;
          pq.push(make_tuple(t+k,b,m-g));
        }
      }
    }
    if(r.at(a).at(min(A*V,m+T.at(a).first))>t+T.at(a).second||r.at(a).at(min(A*V,m+T.at(a).first))==-1){
    r.at(a).at(min(A*V,m+T.at(a).first))=t+T.at(a).second;
    pq.push(make_tuple(t+T.at(a).second,a,min(A*V,m+T.at(a).first)));
    }
  }
  for(int i=1;i<V;i++){
    cout<<z.at(i)<<endl;
  }
  

}




Measured memory_bytes: 7216
#include <iostream>
#include <bitset>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

int D;
long long G;
int ans = INT_MAX;
vector<long long> p(10);
vector<long long> c(10);

int bitSearch(){
    
    for(int i = 0; i < (1 << D); i++){
        
        long long  sum = 0;
        int count = 0;
        bitset<10> bit(i);
        
        // ボーナスポイントを加えるとき
        for(int j = 0; j < D; j++){
            
            int point = 100 * (j + 1); 
            
            if( bit.test(j) ){
                sum += (point * p[j]) + c[j]; // 合計＝（問題の点数　×　問題個数）＋　ボーナスポイント
                count += p[j];
            }
        }
        
        // ボーナスポイントを加えないとき
        for(int j = D - 1; j >= 0; j--){
            
            int point = 100 * (j + 1); 
            
            if( !bit.test(j) ){
                for(int k = 0; k < p[j]; k++){
                    if(sum >= G) break;
                    sum += point;
                    count++;
                }
            }
        }        

        // 最小の個数を求める
        ans = min(ans, count);
    }
    
    return ans;
    
}



int main(void){
    
    cin >> D >> G;
    for(int i = 0; i < D; i++){
        int Q;
        long long bonus;
        cin >> Q >> bonus;
        p[i] = Q;
        c[i] = bonus;
    }
    
    int ans = bitSearch();
    cout << ans << endl;
    
}


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

int A[305][305];
int B[305][305];

int main() {
    int N; cin >> N;
    rep(i, N){
        rep(j, N){
            cin >> A[i][j];
            B[i][j] = A[i][j];
        }
    }

    rep(k, N){
        rep(i, N){
            rep(j, N){
                B[i][j] = min(B[i][j], B[i][k]+B[k][j]);
            }
        }
    }

    rep(i, N){
        rep(j, N){
            if(A[i][j] != B[i][j]){
                cout << -1 << endl;
                return 0;
            }
        }
    }

    ll ans = 0;

    rep(i, N){
        rep(j, N){
            bool ch = true;
            rep(k, N){
                if(i == k || j == k)continue;
                if(A[i][j] == B[i][k] + B[k][j]){
                    ch = false;
                    break;
                }
            }
            if(ch)ans += A[i][j];
        }
    }

    ans /= 2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4396
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int a, b, c, ans=0;
    cin>>a>>b>>c;
    if(a==1&&b==10000&&c==10000)ans=ans+1;
    while(1){
        if(c%a==0){
            ans=ans+1;
            /*cout<<a<<endl;*/
            }
        a=a+1;
        if(a>=b)break;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main(){
  int a,b ,c,d;
  cin >> a >> b >> c>>d;
  int x=c-a;
  int y=d-b;
  rep(i,x)cout << 'R';
  rep(i,y+1)cout << 'U';
  rep(i,x+1)cout << 'L';
  rep(i,y+1)cout << 'D';
  cout << 'R';
  cout << 'D';
  rep(i,x+1)cout << 'R';
  rep(i,y+1)cout << 'U';
  rep(i,x+1)cout << 'L';
  rep(i,y)cout << 'D';
  cout << endl;
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    String ans = "NO";
    long r = (long)(n - 1);
    for(long i = 0; i <= r; i++) {
      long t = i * d - (r - i) * c;
      long s = i * c - (r - i) * d;
      if(((b - a) >= s) && ((b - a) <= t)) ans = "YES";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint X, Y, Z; cin >> X >> Y >> Z;
    cout << (X - Z) / (Y + Z) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef pair<ut,ut> prs;
const int SIZE=3*1e5;
const LL p=7+1e9;
int minium[SIZE];
LL x[SIZE];
LL solve(int n){
	LL ans=0;
	REP(i,n){
		cin >> x[i];
		if(i){
			LL longs=(x[i]-x[i-1])%p;
			ans+=longs*(i)%p*(n-i)%p;
		}
		ans%=p;
	}
	return ans;
}
int main(){
	int n,m;
	cin >> n >> m;
	LL ans=solve(n);
	ans*=solve(m);
	ans%=p;
	cout << ans << endl;
	return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    std::cin >> s;
    
    ll q;
    std::cin >> q;
    bool rev = false;
    for (int i = 0; i < q; i++) {
        ll t;
        std::cin >> t;
        if(t==1){
            rev = !rev;
            continue;
        }else{
            ll f;
            string c;
            std::cin >> f>>c;
            
            if((f==1 && !rev) || (f==2&&rev)){
                s.insert(0,c);
            }else{
                s.append(c);
            }
        }
    }
    if(rev){
        reverse(s.begin(),s.end());
    }
    std::cout << s << std::endl;
}


Measured memory_bytes: 912
#include<iostream>
using namespace std;
#define MAX_N 100
int bubble_sort(int *arr, int size)
{
	int step = 0;
	for (int i = 0; i < size - 1; i++)
	{
		for (int j = size - 1; j > i; j--)
		{
			if (arr[j] < arr[j - 1])
			{
				int temp = arr[j];
				arr[j] = arr[j - 1];
				arr[j - 1] = temp;
				step++;
			}
		}
	}
	return step;
}

int main()
{
	int n;
	int arr[MAX_N];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	int step = bubble_sort(arr, n);
	for (int i = 0; i < n - 1; i++)
	{
		cout << arr[i] << ' ';
	}
	cout << arr[n - 1] << endl << step << endl;
	return 0;
}


Measured memory_bytes: 3108
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  string S;
  rep(i, 0, 3) {
    string s;
    cin >> s;
    S += s;
  }
  int x = stoi(S);
  if (x % 4 == 0)
    puts("YES");
  else
    puts("NO");
}

int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;
using ll = long long;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int x;
  cin >> x;
  int cp_x = x;
  
  int res = cp_x/=100;
  int num = res *100;
  int a = x-num;
  if(res*5>=a) cout << 1;
  else cout << 0;
    
}

Measured memory_bytes: 3604
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

INF=10**9+7

N=int(input())
A=[int(i) for i in input().split()]

temp=A[0]
for i in range(1,N):
    temp=lcm(temp,A[i])

ans=0
for a in A:
    ans+=(temp//a)

print(ans%INF)


Measured memory_bytes: 4084
#回文であるか調べる
def kaibuncheck(S):
    N=len(S)
    if N == 1:
        return 1

    N_val=N-1
    center=int((N-1)/2)
    checkpoint=0
    if N == 1:
        return 1
    for i in range(center-1):
        if S[i] == S[N_val]:
            checkpoint+=1
        N_val -= 1

    if checkpoint == center-1:
        return 1
    else:
        return 0

S = list(input())
N = len(S)
N2 = int((N-1)/2)

S_start=list()
S_end=list()
for i in range(N2):
    S_start.append(S[i])
    S_end.append(S[N2+1+i])

if N%2 == 1:
    if kaibuncheck(S) == 1 and kaibuncheck(S_start) == 1 and kaibuncheck(S_end) == 1:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3064
n=int(input())
a=input()
ans=0
for i in range(1000):
    i=str(i).zfill(3)
    x=a.find(i[0])
    y=a.find(i[1],x+1)
    z=a.find(i[2],y+1)
    if x!=-1 and y!=-1 and z!=-1:
        ans+=1
print(ans)

Measured memory_bytes: 3060
a, v = gets.chomp.split(" ").map(&:to_i)
b, w = gets.chomp.split(" ").map(&:to_i)
t = gets.to_i

dif = b - a
fast = v - w

if fast <= 0 
  puts"NO" 
else
  time = dif.abs / fast.to_f
  if time <= t
    puts "YES"
  else
    puts "NO"
  end
end

Measured memory_bytes: 14400
n, m, point = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }

graph = Array.new(n+1) { [] }
reverse_graph = Array.new(n+1) { [] }
edges = []

abc.each do |a, b, c|
  edges << [a, b, (c-point)*-1]
  graph[a] << [b, (c-point)*-1]
  reverse_graph[b] << [a, (c-point)*-1]
end

def reachable(graph, s)
  visit = []
  visit.push(s)
  q=[s]
  until q.empty?
    u=q.shift
    graph[u].each do |n, _|
      next if visit.include?(n)
      visit.push(n)
      q.push(n)
    end
  end
  visit
end

reachable_from_s = reachable(graph, 1)
reachable_to_g = reachable(reverse_graph, n)
retrenched_nodes = (1..n).to_a.select {|t| reachable_from_s.include?(t) && reachable_to_g.include?(t) }

edges = edges.select {|from, to,  _| retrenched_nodes.include?(from) && retrenched_nodes.include?(to) }

INF = 1<<60
dist = Array.new(n+1, INF)
dist[1]=0
c=0

loop do
  updated = false
  edges.each do |from, to, cost|
    if dist[from] != INF && dist[to] > dist[from] + cost
      dist[to] = dist[from] + cost
      updated=true
    end
  end
  break unless updated
  c+=1
  if c==n
    p -1
    exit
  end
end

p [-dist[n], 0].max


Measured memory_bytes: 5372
n, y_in  = map(int, input().split())

flg=0
x=-1
y=-1
z=-1
for i in range(n+1):
    for j in range(n+1-i):
        total = 10000*i+5000*j+1000*(n-i-j)
        #print(total,i,j)
        if total==y_in:
            x=i
            y=j
            z=n-i-j

print(x,y,z)

Measured memory_bytes: 3188