akhauriyash/Code-Regression huggingface dataset:
import numpy as np
max_hp, n_magic = map(int, input().split())
power = np.empty(n_magic, dtype='int')
mp = np.empty(n_magic, dtype='int')
for i in range(n_magic):
    power[i], mp[i] = map(int, input().split())

hp_gauge = np.array([float('inf')] * (max_hp+1))
hp_gauge[0] = 0

for remaining_hp in range(1, max_hp+1):
    pre_turn_hp = remaining_hp - power
    pre_turn_hp[pre_turn_hp < 0] = 0
    hp_gauge[remaining_hp] = np.min(hp_gauge[pre_turn_hp] + mp)
    
print(int(hp_gauge[max_hp]))

Measured memory_bytes: 12608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1e9+7;
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

int main(){
    int n, q, cnt = 0;
    cin >> n;
    VI S(n);
    REP(i, n){
        cin >> S[i];
    }
    cin >> q;
    VI T(n);
    REP(i, q){
        cin >> T[i];
        REP(j, n){
            if (T[i] == S[j]){
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
}


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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {

    string a, b;
    cin >> a >> b;
    if (b.substr(0, a.size()) == a) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

}



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

    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
using namespace std;

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        for(int j = 0; j < i; ++j) {
            sum += a[i] * a[j]; 
        }
    }
    cout << sum << '\n';

}


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

using namespace std;

class S{
public:
  int a, b, c;
  S(){}
  S(int a, int b, int c): a(a), b(b), c(c){}
  bool operator < (const S& s) const {
    return c < s.c;
  }
};

const int N = 200000;

int n;
vector<S> vec;
int size[N], par[N], rank[N];

void init(int n){
  for(int i=0;i<n;i++){
    par[i] = i;
    rank[i] = 0;
    size[i] = 1;
  }
}

int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;

  if(rank[x] < rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank[x] == rank[y]) rank[x]++;
  }
  size[x] += size[y];
  size[y] = size[x];
}

main(){
  cin >> n;
  for(int i=0;i<n-1;i++){
    S in;
    cin >> in.a >> in.b >> in.c;
    vec.push_back(in);
  }
  sort(vec.begin(), vec.end());
  long long ans = 0;
  init(n);
  for(int i=0;i<n-1;i++){
    ans += (long long) vec[i].c * size[find(vec[i].a)] * size[find(vec[i].b)];
    unite(vec[i].a, vec[i].b);
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  int lb = -1;
  for(int i = 0; i < M; i++){
    cin >> A[i];
    if(X<A[i]){
      lb = i - 1;
      break;
    }
  }
  int ans = 0;
  if(lb == -1) ans = 0;
  else{
    ans = min(lb + 1, M - (lb + 1));
  }
  cout << ans;

}


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

int main()
{
  int n;
  cin >> n;
  vector<int> v(2*n);
  for(int i = 0; i < 2*n; ++i)
  {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for(int i = 0; i < 2*n; i+=2)
  {
    ans += v[i];
  }

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


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

int main(int argc, char const *argv[])
{
    int n,q,t;
    std::string name;
    std::queue< std::pair< std::string,int > > Q;

    std::cin >> n >> q;

    for(int i = 0;i < n;i++){
        std::cin >> name >> t;
        Q.push(make_pair(name, t));
    }

    std::pair<std::string, int> u;
    int elaps = 0,a;

    while(!Q.empty()){
        u = Q.front();
        Q.pop();
        a = std::min(u.second,q);
        u.second -= a;
        elaps += a;
        if(u.second > 0) Q.push(u);
        else std::cout << u.first << ' ' << elaps << std::endl;
    }

    return 0;
}



Measured memory_bytes: 6352
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdio.h>

int main() {
	int a = -1, b = -1, c = -1;
	bool f = false;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a != i + 1) {
			if (f) {
				printf("NO\n");
				return 0;
			}
			if (b == -1) {
				b = a;
				c = i;
			}
			else {
				if (b == i + 1 && a == c + 1) {
					f = true;
				}
				else {
					printf("NO\n");
					return 0;
				}
			}
		}
	}
	printf("YES");
	return 0;
}

Measured memory_bytes: 128
import sys


def main():
    h, w = map(int, sys.stdin.buffer.readline().split())
    n = int(sys.stdin.buffer.readline())
    a = list(map(int, sys.stdin.buffer.readline().split()))
    ans = [0]*(w*h)
    now = 0
    for i, x in enumerate(a):
        for j in range(x):
            ans[now + j] = i+1
        now += x

    for i in range(h):
        if i % 2:
            print(*reversed(ans[i*w:(i+1)*w]))
        else:
            print(*ans[i*w:(i+1)*w])


if __name__ == "__main__":
    main()


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


int main() {
	
	int N;
	cin >> N;
	vector<tuple<string,int,int>> a(N);
	for(int i=0; i<N; i++){
		string s;
		int p;
		cin >> s >> p;
		a.at(i) = make_tuple(s,-p,i);
	}
	sort(a.begin(),a.end());
	for(int i=0; i<N; i++){
		cout << get<2>(a.at(i))+1 << endl;
	}
	
	
	return 0;
}

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

int main () {

    int i, j, n, x, c;
    double m;

    c = 0;

    scanf("%d", &n);

    for (i = 1; i <= n; i++) {

        scanf("%d", &x);
        m = sqrt(x);

        if (x == 2 || x == 3)
            c += 1;

        for (j = 2; j <= m + 1; j++) {

            if (x % 2 == 0 || x % 5 == 0 || x % j == 0) {
                break;
            } else if (j >= m) {
                c += 1;
                break;
            }

        }

    }

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

    return 0;

}


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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int,int>;
using ppa = pair<pa,int>;
#define SORT(v, n) sort(v, v+n);
#define ALL(v) v.begin(),v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v),greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)),v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i = (b-1); i >= a; i--)
#define rrep(i,n) RFOR(i,0,n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a,b) a = min(a,b)
#define maxs(a,b) a = max(a,b)

//4近傍
//int dy[]={0, 1, 0, -1};
//int dx[]={1, 0, -1, 0};

//8近傍
//int dy[]={0,0,1,-1,1,1,-1,-1};
//int dx[]={1,-1,0,0,1,-1,1,-1};

const ll MOD = 1000000007;

ll pow_mod(ll a,ll b,ll mod){
    ll tmp = 1;
    a %= mod;
    if(b > 0){
        tmp = pow_mod(a, b/2, mod);
        if(b % 2) tmp = (((tmp*tmp)%mod)*a)%mod;
        else tmp = (tmp*tmp)%mod;
    }
    return tmp;
}

void solve() {
    int n;
    cin >> n;
    long x;
    cin >> x;
    vector<long> a(n);
    for(auto &b : a) cin >> b;

    vector<vector<long>> dp(n,vector<long>(n,-1));

    for(int i = 0; i < n; i++){
        dp[i][0] = a[i];
        for(int j = 1; j < n; j++){
            dp[i][j] = min(dp[i][j - 1], a[(i - j + n) % n]);
        }
    }

    long ans = LONG_MAX;
    for(int i = 0; i < n; i++){
        long cur = 0;
        for(int j = 0; j < n; j++) {
            cur += dp[j][i];
        }
        ans = min(ans, cur + x * i);
    }
    cout << ans << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>

using namespace std;


int main(){
   int n[3];
   int k;
   cin>>n[0]>>n[1]>>n[2]>>k;
   int ans=0;
   sort(n,n+3);
   for(int i=0;i<k;i++){
      n[2] *= 2;
   }
   ans=n[0]+n[1]+n[2];
   cout<<ans<<endl;
   
}

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

const int INF = 0x3f3f3f3f;
typedef complex<double> P;

int main(){
    int N, W, D;
    cin >> N >> W >> D;
    int L = 2 * (W + D);
    P p1 = P(W, 0);
    P p2 = P(W, D);
    P p3 = P(0, D);
    P C = P(0, -1);
    
    //end, start
    vector<pair<int, int>> lines;
    
    for(int i=0; i<N; i++){
        int x, y; string f;
        cin >> x >> y >> f;
        P p = P(x, y);
        
        switch (f[0]) {
            case 'W':
                p = (p - p3) * C + p3;
            case 'N':
                p = (p - p2) * C + p2;
            case 'E':
                p = (p - p1) * C + p1;
            default:
                break;
        }
        lines.emplace_back(p.real()+p.imag(), p.real()-p.imag());
    }
    sort(lines.begin(), lines.end());
    
    int ans = INF;
    for(int s=0; s<N; s++){
        int tans = 0;
        for(int i=0; i<N; ){
            int p = lines[i].first;
            while(i<N && lines[i].second <= p) i++;
            tans++;
        }
        ans = min(ans, tans);
        
        lines[0].first += L;
        lines[0].second += L;
        sort(lines.begin(), lines.end());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    
		try {
			int lima = Integer.parseInt(in.readLine());
			String[] sa = in.readLine().split(" ");
			
			int limb = Integer.parseInt(in.readLine());
			String[] sb = in.readLine().split(" ");

			int hit = 0;
			boolean[] flag = new boolean[limb];
			for (int i = 0; i < limb; i++) {
				flag[i] = false;
			}
			
			for (int i = 0; i < lima; i++) {
				for (int j = 0; j < limb; j++) {
					if (flag[j]) continue;
					
					if (sb[j].equals(sa[i])) {
						flag[j] = true;
						hit++;
						break;
					}
				}
			}
			
			System.out.println(hit);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 26640
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

const ll MAX_N = 1E5;

ll N;

ll A[MAX_N], S[MAX_N];

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

    cin >> N;

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

    S[0] = A[0];
    for (int i = 1; i < N; i++) {
        S[i] = S[i - 1] + A[i];
    }

    ll cnt1 = 0;
    ll d = 0;
    for (int i = 0; i < N; i++) {
        if (i & 1) {
            if (S[i] + d >= 0) {
                int cost = S[i] + d + 1;
                d -= cost;
                cnt1 += cost;
            }
        } else {
            if (S[i] + d <= 0) {
                int cost = -(S[i] + d) + 1;
                d += cost;
                cnt1 += cost;
            }
        }
    }


    ll cnt2 = 0;
    d = 0;
    for (int i = 0; i < N; i++) {
        if (!(i & 1)) {
            if (S[i] + d >= 0) {
                int cost = S[i] + d + 1;
                d -= cost;
                cnt2 += cost;
            }
        } else {
            if (S[i] + d <= 0) {
                int cost = -(S[i] + d) + 1;
                d += cost;
                cnt2 += cost;
            }
        }
    }

    cout << min(cnt1, cnt2) << "\n";

    return 0;
}

Measured memory_bytes: 5216
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int>v;
map<int, int>m;
int gcd( int a,int b)
{
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);

}
void prime()
{
    bool p[201];
    for (int i=1;i<=200;i++) p[i]=true;
    for (int i=2;i*i<=200;i++)
    {
        if (p[i])
        {
            for (int j=2;i*j<=200;j++)
                p[i*j]=false;
        }
    }
    p[1]= false;
    for (int i=1;i<=200;i++)
    {
        if(p[i])
            v.push_back(i);
    }
    for (int i=0;i<v.size();i++)
    {
        for (int j=i+1;j<v.size();j++)
            m[i*j]++;
    }
    return ;
        
    
    
}
void f()
{
    ll x, y;
    x= 0 ,y=1;
    v.push_back(0);
    v.push_back(1);
    while (x<10000000)
    {
        ll t= x%10;
        x=y%10;
        y=t+y%10;
        cout <<y<<endl;
        v.push_back(y);
    }
}
void solve()
{
    int n; cin>>n;
    int x= (n+999)/1000;
    cout <<x*1000-n<<endl;
    return ;
    
}
int main()
{
    int t; t=1 ;while (t--)
    {
       solve();
       return 0;
    }
}


Measured memory_bytes: 3604
<?php
  fscanf(STDIN,"%d%d", $n,$k);
  $a = explode(" ",trim(fgets(STDIN)));
  for($i=0; $i<$n; $i++){
      $num[$a[$i]]++;
  }
  if(count($num) <= $k){
      echo "0";
      exit;
  }
  
  arsort($num);
  $j = 0;
  foreach($num as $d){
      $j++;
      if($j > $k){
          $sum += $d;
      }
  }
  echo $sum;

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

int main(){
	int a[10];
	int b[10];
	for(int i=0;i<10;i++){
		cin >> a[i];
	}
	for(int i=0;i<10;i++){
		cin >> b[i];
	}
	sort(a,a+10);
	sort(b,b+10);
	int w = a[7]+a[8]+a[9];
	int h = b[7]+b[8]+b[9];
	cout << w << " " << h << endl;
}

Measured memory_bytes: 0
N,M = [int(it) for it in input().split()]
li = [ [int(it)-1 for it in input().split()] for i in range(M)]

#1:red candi
k0 = [0]*N
c0 = [1]*N

k0[0] = 1


for a,b in li:
  ka,kb,ca,cb = k0[a],k0[b],c0[a],c0[b]
  ga,gb=ka,kb
  if (ca==1 and ka==1):
    ga,gb=0,1
  if (ca>1  and ka==1):
    ga,gb=1,1
  k0[a],k0[b]=ga,gb

  c0[a]-=1
  c0[b]+=1
  
print ( sum(k0) )
  
    

Measured memory_bytes: 62808
n = gets.chomp.to_i
n.times do
  ary = gets.chomp.split.map(&:to_i)
  max = ary.max
  index = ary.index(max)
  ary.delete_at(index)
  a, b = ary
  if max**2 == a**2 + b**2
    puts "YES"
  else
    puts "NO"
  end
end

Measured memory_bytes: 8624
#include <stdio.h>

int main(void){

  int A,B;
  int n;
  int i;
  int PointA,PointB;


  while(1){

    PointA = 0;
    PointB = 0;

    scanf("%d" ,&n);

    if( n == 0 ) break;

    for( i = 0 ; i < n ; i++ ){

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


      if( A < B ) PointB += A + B; 
     
      if( A > B ) PointA += B + A;

      if( A == B ){ 

	PointA += A;
	PointB += B;

      }

    }

    printf("%d %d\n" ,PointA ,PointB);

  }

  return 0;

}

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

int main() {
  vector<string> a;
  a ={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
  int N;
  cin>>N;
  string S;
  cin>>S;
  string k;
  for(int i=0;i<S.size(); i++){
    for(int j=0;j<26;j++){
      k=S[i];
      if(a[j] == k)
        cout<<a[(j+N)%26];
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n;
int a[101];

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int color[9] = {0};
    for(int i=0;i<n;i++){
        if(a[i] <= 399) color[0]++;
        else if(400 <= a[i] && a[i] <= 799) color[1]++;
        else if(800 <= a[i] && a[i] <= 1199) color[2]++;
        else if(1200 <= a[i] && a[i] <= 1599) color[3]++;
        else if(1600 <= a[i] && a[i] <= 1999) color[4]++;
        else if(2000 <= a[i] && a[i] <= 2399) color[5]++;
        else if(2400 <= a[i] && a[i] <= 2799) color[6]++;
        else if(2800 <= a[i] && a[i] <= 3199) color[7]++;
        else color[8]++;
    }
    int ans1 = 0;
    int ans2 = 0;
    for(int i=0;i<8;i++) if(color[i] > 0) ans1++;
    ans2 = ans1 + color[8];
    ans1 = max(ans1, 1);
    cout << ans1 << " " << ans2 << endl;
    return 0;
}

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


int main() {

	int count = 0, count_max = 0;
	long int tmp;
	int i, j;

	double D, T, S;

	cin >> D;
	cin >> T;
	cin >> S;


	if (D/S > T)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
	
	
	
	
	
	
	//cout << count << endl;
	
}

Measured memory_bytes: 3732
import math
N, K = list(map(int, input().split()))
S = str(input())
list = []
cnt = 1
list.append(1)
for i in range(len(S)):
  if(i + 1) >= len(S): 
    break
  if (S[i+1] != S[i]):
    list.append(i + 2)

# 切り替わりの最初の位置を記録した配列ができた
ans = 0
tmp = 0
# 1始まりのとき
if (S[0] == '1'):
  for i in range(len(list) // 2):
    if ((2 * i) + (2 * K) + 1) >= len(list):
      tmp = len(S) - list[(2 * i)] + 1
      if ans < tmp:
        ans = tmp
      break
    tmp = list[(2 * i) + (2 * K) + 1] - list[(2 * i)]
    if ans < tmp:
      ans = tmp
  # 1の塊しかない場合
  if(len(list) // 2) == 0: ans = len(S)
# 0始まりのとき
if (S[0] == '0'):
  for i in range(math.ceil(len(list) / 2)):
    # 先頭以外の時
    if ((2 * i) - 1) >= 0:
      if ((2 * i) + (2 * K) + 1) > len(list):
        tmp = len(S) - list[(2 * i) - 1] + 1
        if ans < tmp:
          ans = tmp
        break
      tmp = list[(2 * K) + (2 * i)] - list[(2 * i) - 1]
      if ans < tmp:
        ans = tmp
    # 先頭の時
    else:
      if ((2 * i) + (2 * K) + 1) > len(list):
        tmp = len(S)
        if ans < tmp:
          ans = tmp
        break
      tmp = list[(2 * K)] - 1
      if ans < tmp:
        ans = tmp
  # 0の塊しかない場合
  if(len(list) // 2) == 0: ans = len(S)
print(ans)

Measured memory_bytes: 7272
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

int gcd(int a, int b);
int lcm(int a, int b);

int cost(int a, int b){
    return fabs(a - b);
}

void solve_A(){
    int n;
    cin >> n;

    int h[n];
    REP(i,n) cin >> h[i];

    int dp[n];
    dp[0] = 0;
    dp[1] = cost(h[1], h[0]);

    for(int i = 1; i < n; i++){
        dp[i + 1] = min(dp[i] + cost(h[i], h[i+1]), dp[i-1] + cost(h[i-1], h[i+1]));
    }

    cout << dp[n-1];

}

int main(void){
    solve_A();
    
    return 0;
}

int gcd(int a, int b){
    if(a < b) swap(a, b);

    int r = a % b;
    while(r != 0){
        a = b;  b = r;  r = a % b;
    }
    return b;
}

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=3e5+5;
const int mod=998244353;
int n;
int s[3],t[3];
LL ans=1;
char str[maxn];
int main(){
	cin>>n>>str+1;
	for(int i=1;i<=n;i++) ans=(ans*i)%mod;
	for(int i=1,op;i<=n*3;i++){
		if(str[i]=='R') op=0;
		if(str[i]=='G') op=1;
		if(str[i]=='B') op=2;
		if(t[op]) ans=(ans*t[op]--)%mod;
		else if(s[(op+1)%3]){
			ans=(ans*s[(op+1)%3]--)%mod;
			t[(op+2)%3]++;
		}
		else if(s[(op+2)%3]){
			ans=(ans*s[(op+2)%3]--)%mod;
			t[(op+1)%3]++;
		}
		else s[op]++;
	}
	cout<<ans;
	return 0;
}

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

int main()
{
    int N, A, B, line;
    cin >> N >> A >> B;
    string S;
    cin >> S;
    line = A + B;
    int pass = 0;
    int foreigner = 0;

    for (int i = 0; i < N; i++)
    {
        char tmp;
        tmp = S[i];
        bool flg = false;

        switch (tmp)
        {
        case 'a':
            if (pass < line)
            {
                flg = true;
                pass++;
            }
            break;
        case 'b':
            if (pass < line && foreigner < B)
            {
                flg = true;
                pass++;
                foreigner++;
            }
            break;
        default:
            break;
        }

        if (flg)
        {
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 896
A = []
b = []
ok = False
for _ in range(3):
    A.append(list(map(int, input().split())))
n = int(input())
for _ in range(n):
    b.append(int(input()))

if A[0][0] in b and A[0][1] in b and A[0][2] in b:
    ok = True
elif A[1][0] in b and A[1][1] in b and A[1][2] in b:
    ok = True
elif A[2][0] in b and A[2][1] in b and A[2][2] in b:
    ok = True
elif A[0][0] in b and A[1][0] in b and A[2][0] in b:
    ok = True
elif A[0][1] in b and A[1][1] in b and A[2][1] in b:
    ok = True
elif A[0][2] in b and A[1][2] in b and A[2][2] in b:
    ok = True
elif A[0][0] in b and A[1][1] in b and A[2][2] in b:
    ok = True
elif A[0][2] in b and A[1][1] in b and A[2][0] in b:
    ok = True
    
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
use proconio::input;

fn main() {
    input! {
        (n, x, t): (usize, usize, usize),
    }
    if n % x == 0 {
        // 割り切れる場合
        println!("{}", (n / x) * t);
    } else {
        // 割り切れない場合
        println!("{}", ((n / x) + 1) * t);
    }
}


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

int main(){
	int mod = 1000000007;
	int H, W, K;
	cin >> H >> W >> K;
	int dp[H+1][W] = {};
	dp[0][0] = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			for (int k = 0; k < pow(2,W-1); k++) {
				bool ok = true;
				for (int l = 0; l < W-2; l++) {
					if (((k >> l) & 1) && ((k >> (l+1)) & 1)) {
						ok = false;
						break;
					}
				}
				if (ok) {
					// 左に行くとき
					if ((j > 0) && ((k >> (j-1)) & 1)) {
						dp[i+1][j-1] += dp[i][j];
						dp[i+1][j-1] %= mod;
					} else
					// 右に行くとき
					if ((j < W-1) && ((k >> j) & 1)) {
						dp[i+1][j+1] += dp[i][j];
						dp[i+1][j+1] %= mod;
					} else {
					// そのまま下に行くとき
						dp[i+1][j] += dp[i][j];
						dp[i+1][j] %= mod;
					}
				}
			}
		}
	}
	cout << dp[H][K-1] << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def solve(N: int, M: int, R: int, r: "List[int]", A: "List[int]", B: "List[int]", C: "List[int]"):
    import numpy as np    
    from scipy.sparse import coo_matrix    
    from scipy.sparse.csgraph import floyd_warshall
    from itertools import permutations, islice
    from functools import reduce
    # coo_matrix((data, (i, j)), [shape=(M, N)])
    mat = floyd_warshall(coo_matrix((C, (A, B)), shape=(N+1, N+1), dtype=np.int32).tocsr(), directed=False)
    f = lambda a, b: (a[0]+mat[a[1]][b], b)
    return int(min(reduce(f, q, (0, s))[0] for s, *q in permutations(r)))

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    r = [int(next(tokens)) for _ in range(R)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    print(solve(N, M, R, r, A, B, C))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 39548
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define INF 1000000000
 
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

int main() {
	int N, L;
	int a[100001];
	int i, j;
	int left, right;
	
	scanf("%d %d", &N, &L);
	for(i=1;i<=N;i++) {
		scanf("%d", &a[i]);
	}
	
	for(i=1;i<=N-1;i++) {
		if(a[i] + a[i+1] >= L) {
			left = i;
			break;
		}
	}
	if(i == N) {
		printf("Impossible\n");
		return 0;
	}
	
	
	printf("Possible\n");
	for(i=1;i<left;i++) {
		printf("%d\n", i);
	}
	for(i=N-1;i>=left;i--) {
		printf("%d\n", i);
	}
	
	/*
	left = 1;
	right = N;
	for(i=1;i<=N-1;i++) {
		if(a[left] < a[right]) {
			printf("%d\n", left++);
		} else {
			printf("%d\n", --right);
		}
	}
	*/
	
	return 0;
}

Measured memory_bytes: 1152
def main():
    L, R = map(int, input().split())
    ans = 2019
    for i in range(L, min(R, L+2019)):
        for j in range(i+1, min(R+1, i+2019)):
            ans = min(ans, (i % 2019) * (j % 2019) % 2019)
    print(ans)
main()

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

int main(){
    int entr[6], k, i, j, status = 0;
    for(i = 0; i < 5; i++)cin >> entr[i];
    cin >> k;
    for(i = 0; i < 5; i++){
        for(j = 0; j < 5; j++)if(abs(entr[i]-entr[j]) > k)status = 1;
    }
    if(!status)cout << "Yay!";
    else cout << ":(";
	return 0;
}

Measured memory_bytes: 3600
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
print(n//2 * ((n+1)//2))

Measured memory_bytes: 72532
#include <stdio.h>
#include <string.h>

int main(void) {
  char a[220];
  int i;
  fgets(a, sizeof(a), stdin);
  for(i = 0; i < strlen(a); ++i) {
    if(a[i] >= 'a' && a[i] <= 'z') a[i] += 'A' - 'a';
    printf("%c", a[i]);
  }
  return 0;
}


Measured memory_bytes: 2524
n = int(input())
s = input()
d = [0 for _ in range(2*n)]
ans = 1
cnt_l = 1
cnt_r = 0
d[0] = "L"
for i in range(1, 2*n):
    if s[i] != s[i-1]:
        d[i] = d[i-1]
    elif d[i-1] == "R":
        d[i] = "L"
    else:
        d[i] = "R"
    
    if d[i] == "L":
        cnt_l += 1
    elif d[i] == "R":
        ans = ans * (cnt_l - cnt_r) % (10**9 + 7)
        cnt_r += 1

import math
ans = math.factorial(n) % (10**9 + 7) * ans

if cnt_r == cnt_l and s[0] != "W" and s[-1] != "W":
    print(ans %(10**9 + 7))
else:
    print(0)


Measured memory_bytes: 5988
#include <iostream>
#include <vector>
#include <map>
#include <limits>
using namespace std;

void CountingSort(int* a, int* b, int n, int k)
{
    int c[k+1];
    for(int i=0; i<=k; i++) c[i] = 0;
    for(int j=0; j<n; j++) c[a[j]]++;
/*
    for(int i=1; i<=k; i++){
        //cout << i << ":" << c[i] << endl;
        c[i] = c[i] + c[i-1];
    }
*/  
    int index = 0;
    for(int i=0; i<=k; i++){
        //cout << "c[i] is " << c[i] << endl; 
        for(int j=0; j<c[i]; j++){
            //cout << "b[" << index << "] = " << i << endl;
            b[index] = i;
            index++;
        }
    }
}
int main()
{
    int n;
    cin >> n;
    int a[n];
    int max = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(max < a[i]) max = a[i];
    }
    int b[n];
    CountingSort(a, b, n, max);

    for(int i=0; i<n; i++){
        cout << b[i];
        if(i != n-1) cout << " ";
        else cout << endl;
    }
}


Measured memory_bytes: 18736
#include<stdio.h>
#include<string.h>
#define MAX 30

typedef struct{
  int p,l,r;
}Roll;

int PreorderPrint(int,Roll *);
int InorderPrint(int,Roll *);
int PostorderPrint(int,Roll *);
void init(Roll *);

int PreorderPrint(int root,Roll *Tree){
    if(root == -1) return -1;
    printf(" %d",root);
    PreorderPrint(Tree[root].l,Tree);
    PreorderPrint(Tree[root].r,Tree);
    return 0;
}
 
int InorderPrint(int root,Roll *Tree){
  if(root==-1)return -1;
  InorderPrint(Tree[root].l,Tree);
  printf(" %d",root);
  InorderPrint(Tree[root].r,Tree);
  return 0;
}
 
int PostorderPrint(int root,Roll *Tree){
  if(root==-1)return -1;
  PostorderPrint(Tree[root].l,Tree);
  PostorderPrint(Tree[root].r,Tree);
  printf(" %d",root);
  return 0;
}
 
void init(Roll *Tree){
  int i;
  for(i=0;i<MAX;i++)Tree[i].l=Tree[i].r=Tree[i].p=-1;
  
}
 
int main(){
  Roll Tree[MAX];
  int id,l,r,i,n,root=0;

  scanf("%d",&n);
  init(Tree);
  for(i=0;i<n;i++){
     scanf("%d%d%d",&id,&l,&r);
     Tree[id].l=l;
     Tree[id].r=r;
     if(l!=-1) Tree[l].p=id;
     if(r!=-1) Tree[r].p=id;
   }
  for(i=0;i<n;i++){
    if(Tree[i].p==-1){
      root=i;
      break;
    }
  }
  printf("Preorder\n"); 
  PreorderPrint(root,Tree);

  printf("\nInorder\n"); 
  InorderPrint(root,Tree);

  printf("\nPostorder\n"); 
  PostorderPrint(root,Tree);
  printf("\n");
  return 0;
}
  

Measured memory_bytes: 616
#include <stdio.h>
int main(void){
    int n;
    while(scanf("%d",&n)!=EOF){
        int a,b,c,d,count=0;
        
        for(a=0;a<=9;a++){
            for(b=0;b<=9;b++){
                for(c=0;c<=9;c++){
                    for(d=0;d<=9;d++)
                    if(a+b+c+d==n) count++;
                }
            }
        }
        printf("%d\n",count);
        
    }
    return 0;
    
}



Measured memory_bytes: 2024
N,X=map(int,input().split())
*A,=map(int,input().split())

B=[a if a<=X else X for a in A]
c=sum(A)-sum(B)
for i in range(N-1):
 t=B[i]+B[i+1]
 if X < t:
    d=t-X
    B[i+1]-=d
    c+=d
print(c)

Measured memory_bytes: 19960
from sys import stdin


def main():
    N = int(stdin.readline())
    H = [int(x) for x in stdin.readline().rstrip().split()]

    H_re = list(reversed(H))

    for i in range(N):
        if i == N-1:
            print("Yes")
            break

        if H_re[i] >= H_re[i+1]:
            pass
        else:
            if H_re[i] >= H_re[i+1] - 1:
                H_re[i+1] = H_re[i+1] - 1
                pass
            else:
                print("No")
                break


if __name__ == "__main__":
    main()


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  string s;
  cin >> s;
  int n=s.size();
  for(char c='a'; c<='z'; c++){
    int ind = -100;
    rep(i,n){
      if(s[i] == c){
        if(i-ind <= 2){
          cout << ind+1 << " " << i+1 << endl;
          return 0;
        }else{
          ind = i;
        }
      }
    }
  }
  cout << -1 << " " << -1 << endl;
}

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

#define INFTY 1000000000
int count, n, A[500000];

void merge(int, int, int);
void mergeSort(int, int);

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

  mergeSort(0,n);
  
  for(i = 0; i < n-1; i++) printf("%d ",A[i]);
  printf("%d\n%d\n",A[n-1],count);
 
  return 0;
}

void merge(int left, int mid, int right){
  int i = 0, j = 0, k;
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1+1], R[n2+1];

  for(i = 0; i < n1; i++){
    L[i] = A[left + i];
  }
  
  for(i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }
  
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  
  for(k = left; k < right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{
      A[k] = R[j];
      j = j + 1;
    }
    count++;
  }
}

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




Measured memory_bytes: 5688
import sys

N = int(input())

An = [int(_) for _ in input().split()]
An.sort()

ans = 1

for val in An:
    # 0がきたらすぐに抜ける
    if(int(val) == 0):
        print(0)
        sys.exit()
    ans *= val
    # ansが10^18を超えた時点で-1にする
    if(ans > 10 **18):
        print(-1)
        sys.exit()

print(ans)

Measured memory_bytes: 84860
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

ll n, d, x;
ld dp[220000];

int main() {
	cin >> n >> d >> x;
	dp[0] = 0;
	for (int i = 1; i <= n; ++i)
		dp[i] = dp[i - 1] + 1.0 / (2 * i);
	ld ans = 0;
	ld now = 0;
	for (int i = 0; i < n; ++i) {
		now += dp[i];
		ans += (d + 2.0 * i * x) * (1 + now / (i + 1)) / 2.0;
		ans += (d + 2.0 * i * x + x) * (now / (i + 1)) / 2.0;
	}
	now = 0;
	for (int i = n - 1; i >= 0; --i) {
		now += dp[n - 1 - i];
		ans += (d + 2.0 * i * x + x) * (1 + now / (n - i)) / 2.0;
		ans += (d + 2.0 * i * x) * (now / (n - i)) / 2.0;
	}
	cout.setf(ios::fixed);
	cout.precision(10);
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 3328
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String S  = scan.nextLine();
		int count = 0;
		for(int i=0;i<S.length()-1;i++){
			String s = S.substring(i,i+2);
			//System.out.println(s);
			if(s.equals("WB")||s.equals("BW")){
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 18612
while 1:
  s = raw_input().split()
  a, b =int(s[0]), int(s[2])
  op = s[1] 

  if op == "+":
    print "%d" %(a + b)
  elif op == "-":
    print "%d" %(a - b)
  elif op == "*":
    print "%d" %(a * b)
  elif op == "/":
    print "%d" %(a / b)
  else:
    break
  

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

int main(void)
{
    int n, k; cin >> n >> k;
    vector<int> p(n, 0);
    for (int i=0; i<n; i++)
    {
        int tmp; cin >> tmp;
        p[i] = tmp;
    }
    sort(p.begin(), p.end());
    int sum = 0;
    for (int i=0; i<k; i++)
    {
        sum += p[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3584
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

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

    for index, ai in enumerate(a, 1):
        if index % 2 == 1 and ai % 2 == 1:
            count += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
N,W = gets.split.map(&:to_i)
dp = [0]*(W+1)
N.times do
  w,v = gets.split.map(&:to_i)
  (W-w).downto(0) do |i|
    a,b=dp[i]+v,dp[i+w]
    dp[i+w] = a if a > b
  end
end
p dp[-1]

Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define repeat(i, n) for(int (i) = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const double EPS = numeric_limits<double>::epsilon();

int main() {
	int A, B;
	cin >> A >> B;
	vector<int> num{A+B, A-B, A*B};
	auto itr = max_element(num.begin(), num.end());
	int idx = distance(num.begin(), itr);
	cout << num[idx] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  cout << 800*N-N/15*200 << "\n";

  return 0;
}

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

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N,K;
    cin>>N>>K;
    int lim=((N-1)*(N-2))/2;
    if(K>lim) cout<<-1<<endl;
    else{
        int M=N-1+lim-K;
        cout<<M<<endl;
        int num=0;
        Rep(i,N){
            Rep(j,N-i){
                cout<<i<<" "<<i+j<<endl;
                num++;
                if(num==M) return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int x=sc.nextInt();
		int t=sc.nextInt();
		
		int i=n%x;
		int j=n/x;
		if(i==0) {
			System.out.println(t*j);
		}
		else {
			System.out.println(t*j+t);
		}
		sc.close();
				
	}
}

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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b));
    return 0;
}

Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  k=I()
  a,b=LI()

  for i in range(a,b+1):
    if i%k==0:
      return 'OK'
  return 'NG'

# main()
print(main())


Measured memory_bytes: 10784
from fractions import gcd
import numpy as np
n=int(input())
data=list(map(int,input().split()))
left=np.zeros(n+1,dtype=np.int)
right=np.zeros(n+1,dtype=np.int)
kotae=1
for i in range(n):
    left[i+1]=gcd(left[i],data[i])
    right[n-i-1]=gcd(right[n-i],data[n-i-1])
for j in range(n):
    num=gcd(left[j],right[j+1])
    kotae=max(num,kotae)
print(kotae)

Measured memory_bytes: 24560
from itertools import permutations

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

for i, order in enumerate(permutations(range(1,N+1))):
    if list(order) == P:
        a = i
    if list(order) == Q:
        b = i

print(abs(a-b))

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int r,d,x;cin>>r>>d>>x;

    rep(i,10){
        cout<<r*x-d<<endl;
        x=r*x-d;
    }
}


Measured memory_bytes: 256
// 5_abc134_e
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }

    vector<int> l;
    l.push_back(a[n - 1]);
    int length = 0;

    for(int i = n - 2; i >= 0; i--){
        if(a[i] >= l[length]){
            l.push_back(a[i]);
            length++;
        }else{
            auto j = upper_bound(l.begin(), l.end(), a[i]);
            int k = j - l.begin();
            l[k] = a[i];
        }
    }

    cout << length + 1 << endl;

    return 0;
}


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

int main() {
  string s;
  cin>>s;
  int n = s.length();
  for (int i=0; i<n-1; i++) {
    if (s[i] == s[i+1]) {
      cout<<i+1<<" "<<i+2<<endl;
      return 0;
    }
    if (i+2 < n && s[i] == s[i+2]) {
      cout<<i+1<<" "<<i+3<<endl;
      return 0;
    }
  }
  cout<<"-1 -1"<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)


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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,cnt=0;
  int a[53];
  int x[53],y[53];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    x[i]=a[i];
  }
sort(a,a+n);
for(int i=0;i<n;i++){
y[i]=a[i];
if(x[i]!=y[i]){
   cnt++;
}
  }
  if(cnt<=2) cout<<"YES";
  else cout<<"NO";
}


Measured memory_bytes: 256
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int x; cin >> x;
    print(360 / gcd(x, 360));

    return 0;
}

Measured memory_bytes: 3616
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let l: u64 = iterator.next().unwrap().parse().unwrap();
    let r: u64 = iterator.next().unwrap().parse().unwrap();

    return if (r - l) >= 2019 {
        String::from("0")
    } else {
        let mut ans: u64 = 2019;
        for i in l..r {
            for j in (l + 1)..(r + 1) {
                ans = min(ans, (i % 2019) * (j % 2019) % 2019);
            }
        }
        ans.to_string()
    }
}


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

signed main() {
  int N;
  cin >> N;
  
  int A = 1;
  for( int i = sqrt(N); i > 1; i-- ){
    if( N % i == 0 && A*i <= N ){
      A *= i;
      N /= i;
      i = sqrt(N);
    }
  }
  
  int count = 1;
  while( N / 10 > 0 ){
    N /= 10;
    count++;
  }
  cout << count << endl;
    
}


Measured memory_bytes: 256