akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int gcd(int a,int b){
	if (b==0) return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}

int main (){
	int a,b;
	while (cin >> a >> b){
		cout << gcd(a,b) << " " << lcm(a,b) << endl;
	}
}

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

void solve()
{
   int n, a, b;
   cin>>n>>a>>b;
   for(int i=a; i<=b; i++)
   {
       if(i%n==0)
       {
           cout<<"OK"<<endl;
           return;
       }
   }
   cout<<"NG"<<endl;

}
int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();

    }
return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n,k;
  cin>>n>>k;
  vector<ll> p(n),c(n);
  for(auto&& e: p) 
  {
    cin>>e;
    e--;
  }
  for(auto&& e: c) 
  {
    cin>>e;
  }

  ll ans=*max_element(c.begin(), c.end());
  
  //始点を決めたとき，取得できる最大点数を求める．
  for (int start = 0; start < n; ++start)
  {
    //一周するのに何回かかるか調べる
    //一周する間に何点得られるか調べる
    ll cycle_len=0,cycle_cost=0;
    ll i=start;
    do {
      cycle_len++;
      cycle_cost+=c[i];
      i=p[i];
    } while (i!=start);

    /*
    一周して増える場合は何回回って，
    残り何回移動できるか調べる．
    */
    ll point=0;
    ll time=cycle_len;
    if (cycle_cost > 0)
    {
      point+=cycle_cost*(k/cycle_len-1);
      time=cycle_len+k%cycle_len;
    }

    //time回の移動の中で最大何点得られるか決める．
    ll max_point=c[i];
    for (int j = 0; j < time; ++j)
    {
      point+=c[i];
      i=p[i];
      max_point=max(max_point,point);
    }

    ans=max(ans,max_point);
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 3712
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
strToInt s = (read :: String -> Int) s

main = do

    n <- readLn :: IO Int
    an <- map strToInt . words <$> getLine
    bn <- map strToInt . words <$> getLine

    let sa = array (1,n+1) ( (1,(an!!0)) : [(k , (an!!(k-1)) + (sa!(k-1))) | k <- [2,3..n]] )
    let sb = array (1,n+1) ( (1,(bn!!0)) : [(k , (bn!!(k-1)) + (sb!(k-1))) | k <- [2,3..n]] )

    let costmap = [sa!i + (costb sb n i) | i <- [1..n]]
    print $ maximum costmap

costb sb n 1 = sb!n
costb sb n i = sb!n - sb!(i-1)

Measured memory_bytes: 1020
;; D - Line++

(defun dist (p q x y)
  "頂点x,y間にショートカットがあるパスにおける頂点p,q間の距離"
  (min (- q p)
       (+ (abs (- x p)) 1 (abs (- y q)))))

(defun solve (n x y)
  "各k = 1,2,...,n-1について, 最短距離がkである頂点対の個数のリストを返す"
  (let ((n-dist (make-array n :initial-element 0)))
    ; 頂点p,q間の距離dを計算し, n-dist[d]++する.
    (loop for p from 1 to (1- n) do
      (loop for q from (1+ p) to n
        do (incf (aref n-dist (dist p q x y)))))
    (cdr (coerce n-dist 'list))))

(defun main ()
  (let ((n (read))
        (x (read))
        (y (read)))
    (format t "~{~a~%~}" (solve n x y))))

(main)


Measured memory_bytes: 16872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

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

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;string s;cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;

    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lop ios; ll t; cin>>t; while(t--)
#define pb push_back
#define vi vector<ll>
#define vivi vector<vector<ll>> 
#define vipa vector<pair<ll,ll>>
#define F first
#define S second
#define M 1000000007
#define kl endl
typedef long long ll;
ll lcm(ll x, ll y){ll k=x*y; k/=(__gcd(x,y)); return k;}
ll power(ll x,ll y){ ll r= 1;x = x % M;if(x==0) return 0; while(y>0) {if(y&1) r=(r*x)%M; y=y>>1; x=(x*x)%M;} return r;}  
void solve()
{ 
 ll n;
 cin>>n;
 if(n%1000){
     cout<<(1000-n%1000);
     return;
 }
 cout<<0;
}
int main() 
{ 
   //lop
    solve();
	return 0; 
} 




Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll box[3][1000000];//1e6までが'0'に、それ以上は、'1'に値、'2'に個数
int cnt_box;
void soinsuu(ll n){
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            if(i<1e6)box[0][i]++;
            else{
                if(cnt_box!=0&&box[1][cnt_box-1]==i){
                    box[2][cnt_box-1]++;
                }   
                else{
                    box[1][cnt_box]=i;
                    box[2][cnt_box]++;
                    cnt_box++;
                } 
            }
            n/=i;    
        }
        if(n==1)break;
    } 
}
int main(){
    ll n,p;
    cin>>n>>p;
    if(n==1){
        cout<<p<<endl;
        return 0;
    }
    soinsuu(p);
    ll ans=1;
    for(ll i=2;i*i<=p;i++){
        while(box[0][i]>=n){
            ans*=i;
            box[0][i]-=n;
        }
    }
    if(cnt_box!=0){
        for(int i=0;i<cnt_box;i++){
            while(box[2][i]>=n){
                ans*=box[1][i];
                box[2][i]-=n;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
// itne me hi thakk gaye?
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
#define ll long long 
#define ull unsigned long long
using ld = long double;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll rk = 256;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define print(a) for(auto j:a) {cout<<j<<",";} cout << "\n";
#define endl '\n'
#define whatis(x) cout << "> "<<#x << " ==> " << x << endl;
#define lwi(x) cout << " your " << #x << " is ---> " << x << " ";
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
// // Printing pair
ostream & operator << (ostream & os, pair <ll, ll> const& x) {
    os << x.first << "," << x.second;
    return os;
}
 
// printing vector
template <class T>
ostream & operator << (ostream & os, vector <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
// printing set
template <class T>
ostream & operator << (ostream & os, set <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
const int mxn = 1e6+5;

int32_t main(){
    FastIO;
    ld a, b;
    cin >> a >> b;
    cout << (ull)(a*b) << endl;
    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>void print(T x){cout << x << endl;}
template<class T>void printvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main()
{
    ll n; cin>>n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    vector<ll> cost(n, 0);
    cost[0]=0; cost[1]=abs(h[1]-h[0]);

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

    print(cost[n-1]);
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define N 100010
int a[300];
int main()
{
    int n,l,x,minn=200,sum=0;
    scanf("%d%d",&n,&l);
    for(int i=1;i<=n;i++)
    {
        a[i]=l+i-1;
        if(abs(a[i])<abs(minn))
            minn=a[i];
        sum+=a[i];
    }
    printf("%d\n",sum-minn);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i = 0; i < N ; i++) {
    cin >> A.at(i);
    B.at(i) = A.at(i);
  }

  sort(B.begin(), B.end());
  
  if(B.at(N - 1) == B.at(N - 2)) {
    for(int i = 0; i < N; i++) cout << B.at(N - 1) << endl;
  }
  else {
    for(int i = 0; i < N; i++) {
      if(A.at(i) == B.at(N - 1)) cout << B.at(N - 2) << endl;
      else cout << B.at(N - 1) << endl;
    }
  }
    
}

Measured memory_bytes: 3200
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    if ((r * 100 + g * 10 + b) % 4 == 0)
        cout << "YES"
             << "\n";
    else
        cout << "NO"
             << "\n";
    return 0;
}

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

int main()
{
  string A;
  cin >> A;
  int counter[26] = {0};
  for (auto c : A)
    counter[c - 'a'] ++;
  
  long long ans = 1;
  for (int i = 0; i < 26; ++ i) {
    for (int j = i + 1; j < 26; ++ j) {
      ans += counter[i] * 1LL * counter[j];
    }
  }

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


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>

using namespace std;

int second_win(
    const string& s, const string& t, const char left, const char right,
    int width, int start){
    int lb = 0; int ub = width;
    for(int i = s.size() - 1; i >= 0; --i){
        if(t.at(i) == left){
            ub = min(ub+1, width);
        }else if(t.at(i) == right){
            lb = max(lb-1, 0);
        }
        if(s.at(i) == left){
            lb++;
        }else if(s.at(i) == right){
            ub--;
        }
        if(lb >= ub){ return 0; }
    }
    return (lb <= start && start < ub);
}

int main(){
    int h, w, n;
    scanf("%d %d %d\n", &h, &w, &n);
    int sr, sc;
    scanf("%d %d\n", &sr, &sc);
    sr--; sc--;

    string s, t;
    getline(cin, s);
    getline(cin, t);

    if(second_win(s, t, 'L', 'R', w, sc) && second_win(s, t, 'U', 'D', h, sr)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 776
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> numbers = new ArrayList<>();
        
        for (int i = 0; i < n; i++) {
            numbers.add(sc.nextInt());
        }

        int count = 1000000;
        int newCount = 0;
        boolean isEven = true;
        for (Integer number : numbers) {
            newCount = 0;
            isEven = true;
            while (isEven) {
                if (number % 2 == 0) {
                    number = number / 2;
                    newCount++;
                } else {
                    isEven = false;
                }
            }
            if (count > newCount) {
                count = newCount;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
using namespace std;
int n,x;
int main() {
	while(scanf("%d %d",&n,&x)!=EOF&&(n!=0||x!=0)) {
		int sum=0;
		for(int i =1;i<=n;i++)
			for(int j =i;j<=n;j++)
				for(int k =j;k<=n;k++)
				{
					if(i+j+k==x&&i!=j&&i!=k&&j!=k) sum++;
				}
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3144
n, m = map(int, raw_input().split())
c = map(int, raw_input().split())

t = [float('inf') for i in range(n+1)]
t[0] = 0

for i in range(m):
    if c[i] > n:
        break
    else:
        for j in range(c[i], n+1):
            t[j] = min([t[j], t[j-c[i]]+1])
print t[n]

Measured memory_bytes: 10728
#include <stdio.h>

int main(){
    int a,b;
    scanf( "%d %d" , &a , &b );
    if( a == b ){
        printf("a == b\n");
    }else if( a < b ){
        printf("a < b\n");
    }else if( a > b ){
        printf("a > b\n");
    }
}


Measured memory_bytes: 2052
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<map>
#include<set>
#define ll long long int

using namespace std;

ll a , b;
int main() {
  cin>>a>>b;
  if((a<=0 && b>=0) || (a>=0 && b<=0)){
    cout<<"Zero"<<endl;
  }
  else {
    ll range = b - a;
    if(a >0 && b>0){
      cout<<"Positive"<<endl;
    }
    else {
      if(range%2==0){
        cout<<"Negative"<<endl;
      }
      else {
        cout<<"Positive"<<endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int gcd(int m, int n){
	int r;
	if(m >= n){
		while(m % n != 0){
			r = m % n;
			m = n;
			n = r; 
		}
		return (n);
	}
	else{
		while(n % m != 0){
			r = n % m;
			n = m;
			m = r; 
		}
		return (m);
	}
}

int lcm(int x, int y){
	int j;
	j = x / gcd(x ,y) * y;
	
	return (j);
}

int main(void)
{
	int a;
	int b;
	while (scanf("%d%d",&a, &b) != EOF){
		printf("%d %d\n", gcd(a, b), lcm(a, b));
	}
	
	return (0);
}

Measured memory_bytes: 0
s = input()
res = 0
index_a = -1
index_z = -1
for i in range(len(s)):
    if s[i] == 'A':
        index_a = i
        for j in range(len(s[i:])):
            if s[i+j] == 'Z':
                index_z = i+j
        break

#print(index_a,index_z)
print(index_z - index_a + 1)

Measured memory_bytes: 3516
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        int m=sc.nextInt();
        HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
        long d[]=new long[n], ans=0;
        d[0] = sc.nextInt()%m;
        if(d[0]==0){ans++; }
        map.put((int)d[0],1);
        for (int i=1,k; i<n; i++) {            
            d[i] = d[i-1] + sc.nextInt();
            d[i]%=m;
            k=(int)d[i];
            if(map.containsKey(k)){
                int e=map.get(k);
                ans+=e;
                map.put(k,e+1);
            }
            else 
                map.put(k,1);
            if(k==0)ans++;
        }

        out.println(ans);
        out.flush();
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 44220
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int N, M;
  cin >> N >> M;
  vector<int> height(N, 0);
  vector<bool> isGood(N, true);
  vector<bool> bend(N, false);
  for (int i = 0; i < N; i++)
    cin >> height[i];
  for (int i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    if (height[a - 1] > height[b - 1])
    {
      isGood[b - 1] = false;
    }
    if (height[b - 1] > height[a - 1])
    {
      isGood[a - 1] = false;
    }
    if (height[b - 1] == height[a - 1])
    {
      bend[a - 1] = true;
      bend[b - 1] = true;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    if (isGood[i] && !bend[i])
    {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <array>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main()
{
	int a;
	cin >> a;
//	int a, b;
//	cin >> a >> b;
//	int a, b, c;
//	cin >> a >> b >> c;

	string s1, s2;
	cin >> s1 >> s2;

	/*
	struct obj
	{
		bool wa = false;
		int ngCnt = 0;
	};

	vector< obj > vec( a+1 );

	int quiz = 0;
	string judge;

	int ok=0, ng=0; 

	for( int i=0 ; i<b ; i++ )
	{
		cin >> quiz >> judge;

		//	なし
		if( vec.at( quiz ).wa == false )
		{
			if( judge == "AC" )
			{
				ok++;
				ng += vec.at( quiz ).ngCnt;
				vec.at( quiz ).wa = true;
			}
			else
			{
				vec.at( quiz ).ngCnt++;
			}
		}
		
	}
	*/

//	sort( vec.begin(), vec.end(), []( const obj &a, const obj &b ){ return a.tim < b.tim; } );
	
	//	--------------------------------------------------

	string str;

	for( int i=0 ; i<a ; i++ )
	{
		str += s1[i];
		str += s2[i];
	}

	cout << str << endl;

	return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin >>n;
    string s = to_string(n),abc = "ABC";
    abc += s;


    //cout <<fixed<<setprecision(16)<< << endl;
    cout << abc << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
void main(){
	int n = inelm();
	(n/3).writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2712
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=a;s>0?i<n:i>n;i+=s)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int inf = 1e9+10, mod = 1e9+7; const long long llinf = 1e18;
// head
vector<string> ans;

void dfs(int n, string s){
  if (n == 0) ans.push_back(s);
  else{
    char k = *max_element(all(s)); k ++;
    for (char c = 'a'; c <= k; c++){
      dfs(n-1,s+c);
    }
  }
}


int main(){
  int n;
  cin >> n;
  string s = "a";
  dfs(n-1,s);
  sort(all(ans));
  for(auto ai : ans){cout << ai << " ";} cout << endl;
}

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

int main() {

  int N;
  cin >> N;

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

  vector<int> D(N+1);
  for (int i = 0; i < N; i++) {
    if (H[i] < H[i+1]) {
      D[i+1] = 0;
    } else {
      D[i+1] = D[i] + 1;
    }
  }

  int m = 0;

  for (int i = 0; i < N; i++) {
    m = max(m, D[i]);
  }

  cout << m << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);
inline void IO() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
}

int main(int argc, char const *argv[])
{
	//IO();
	FAST_IO
	
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for(auto &x: a) cin >> x;
	sort(a.begin(), a.end());
	ll sum = 0;
	for(int i=0 ; i < k ; i++) sum += a[i];
	cout << sum;		
	return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

int n,m,c;
bool vis[11][11];
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
int ans;

void change(int x, int y, int cur, int to, vector< vector<int> > &B) {
	B[x][y]=to;
	vis[x][y]=1;
	for(int i=0;i<4;++i) {
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx<0||nx>=n||ny<0||ny>=m) continue;
		if(vis[nx][ny]) continue;
		if(B[nx][ny]==cur) change(nx,ny,cur,to,B);
	}
}

int get(int x, int y, int cc, vector< vector<int> > &B) {
	vis[x][y]=1;
	int ret=1;
	for(int i=0;i<4;++i) {
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx<0||nx>=n||ny<0||ny>=m) continue;
		if(vis[nx][ny]) continue;
		if(B[nx][ny]==cc)
			ret+=get(nx,ny,cc,B);
	} return ret;
}

void backtr(int cnt, vector< vector<int> > &B) {
	if(cnt==5) {
		memset(vis,0,sizeof(vis));
		ans=max(ans,get(0,0,c,B));
	}
	else {
		for(int i=1;i<=6;++i) {
			vector< vector<int> > nB=B;
			memset(vis,0,sizeof(vis));
			change(0,0,B[0][0],i,nB);
			backtr(cnt+1,nB);
		}
	}
}

int main() {
	//freopen("input.txt","r",stdin);
	while(scanf("%d%d%d",&n,&m,&c),n) {
		vector< vector<int> > B(n,vector<int>(m));
		for(int i=0;i<n;++i) for(int j=0;j<m;++j)
			scanf("%d",&B[i][j]);
		ans=0,backtr(0,B);
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1056
x = int(input())

def main():
    Bool = [1]*(2*x + 1)
    for i in range(2,2*x + 1):
        if Bool[i]:
            for j in range(2*i,2*x + 1,i):
                Bool[j] = 0
    for i in range(x,2*x + 1):
        if Bool[i]:
            print(i)
            return

if __name__ == "__main__":
    main()

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


int main()
{
  int a, b;
  cin >> a >> b;
  printf("%d\n", max(0, a - b * 2));
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
unordered_map<ll,ll> memo;
ll solve(ll n ){
	if(n==1)return 1;
	if(n==2) return 3;
	if(memo.count(n)>0)return memo[n];
	memo[n]=1+2*solve(n/2);
	return memo[n];
}

int main(){
	//mahakal();fast;
	ll n ;
	cin>>n;
	ll dp[n+10];
	// dp[0]=0;dp[1]=1;dp[2]=3;
	// for(ll i=3;i<=n;i++){
	// 	dp[i]=1+dp[i/2]*2;
	// }
	// cout<<dp[n]<<endl;
	ll ans = solve(n);
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
//-----
const int N=1e5+10;
int n;
vi G[N];
int dis[2][N];
bool vis[N];
void bfs(int *d, int st){
	vi q;
	q.pb(st);
	memset(vis, 0, sizeof(vis));
	vis[st]=1;
	d[st]=0;
	rep(f, 0, sz(q)){
		int u=q[f];
		rep(i, 0, sz(G[u])){
			int v=G[u][i];
			if(vis[v])continue;
			d[v]=d[u]+1;
			vis[v]=1;
			q.pb(v);
		}
	}
}
int main() {
	scanf("%d", &n);
	rep(i, 1, n){
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		G[u].pb(v);
		G[v].pb(u);
	}
	bfs(dis[0], 0);
	bfs(dis[1], n-1);
	int cnt1,cnt2;
	cnt1=cnt2=0;
	rep(i, 0, n){
		//cout<<i+1<<' '<<dis[0][i]<<' '<<dis[1][i]<<endl;
		if(dis[0][i]<=dis[1][i])cnt1++;
		else cnt2++;
	}
	if(cnt1>cnt2)puts("Fennec");
	else puts("Snuke");
	return 0;
}


Measured memory_bytes: 7560
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;

int main() {
	int N; long int ans = 0;
	cin >> N;
	rep(i, N - 1) {
		ans += (i+1);
	}
	cout << ans << endl;

}













	


	 



































    





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

using namespace std;

int main()
{
    int i = 0;
    long long A = 0, result = 1;
    int B_int = 0, B_dec = 0;
    string B_txt;

    int N = 0;
    
    cin >> A;
    cin >> B_txt;

    B_int = 0; i = 0;
    while (B_txt[i] != '.')
    {
        B_int *= 10;
        B_int += B_txt[i] - '0';
        i++;
    }
    

    B_dec = (B_txt[i + 1] - '0') * 10 + (B_txt[i + 2] - '0');

    //cout << A << " " << B_int << " " << B_dec << "\n";

    result = A * B_int + ((A * B_dec) / 100);

    cout << result;

    
}



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

using namespace std;

int main(int argc, const char * argv[]) {
    int n,t;
    cin >> n >> t;
    vector<int> T(n);
    for (int i=0; i<n; i++) {
        cin >> T[i];
    }
    long long int ans = 0;
    
    for (int i=1; i<n; i++) {
        if(t > (T[i] - T[i-1]) ){
            ans += T[i] - T[i-1];
        }else{
            ans += t;
        }
    }
    ans += t;
    cout << ans;
    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    int n,k;
    
    
    cin>>n>>k;
    
    bool d[10]={false};
    for(int i=0;i<k;i++){
        int x;
        cin>>x;
        d[x] = true;
    }
    //cout<<"yo"<<endl;

    while(true){
        //cout<<n<<endl;
        vector<int> digits;
        int num=n;
        while(num){
            digits.push_back(num%10);
            num /= 10;
        }
        bool flag = true;
        for(int j=0;j<digits.size();j++){
            //cout<<digits[j]<<endl;
            if(d[digits[j]]){ 
                flag=false; 
                break;
            } 
        }
        if(flag)    break;
        else {
             n++;
             continue;
        }      
    }
    cout<<n<<endl;
    return 0;
}



Measured memory_bytes: 256
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    a,b = map(int,input().strip().split())
    print(str(a)*b if a<b else str(b)*a)


if __name__ == '__main__':
    main()

Measured memory_bytes: 59884
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}


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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  


    int n;
    cin>>n;
    pair<int,int>p[n+1];
    set<pair<int,int> >s1;
    set<pair<int,int>,greater<pair<int,int> > >s2;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i].first>>p[i].second;
        s2.insert({p[i].first,i});
        s1.insert({p[i].second,i});
    }
    int tot=0;
    int x=0;
    int mx=0;
    while (!s1.empty())
    {
        auto j=s1.begin();
        int ind=j->second;
        if(!(p[ind].first<=x && p[ind].second>=x))
        {
            tot+=abs(j->first-x);
            x=j->first;
        }
        s2.erase({p[j->second].first,j->second});
        s1.erase(j);
        if(!s2.empty())
        {
            j=s2.begin();
            int ind=j->second;
            if(!(p[ind].first<=x && p[ind].second>=x))
            {
                tot+=abs(j->first-x);
                x=j->first;
            }
            s1.erase({p[j->second].second,j->second});
            s2.erase(j);
        }
    }

    tot+=abs(x);
    mx=max(mx,tot);
    tot=0;
    s1.clear();
    s2.clear();
    for(int i=1;i<=n;i++)
    {
        s2.insert({p[i].first,i});
        s1.insert({p[i].second,i});
    }
    x=0;
    while (!s2.empty())
    {
        auto j=s2.begin();
        int ind=j->second;
        if(!(p[ind].first<=x && p[ind].second>=x))
        {
            tot+=abs(j->first-x);
            x=j->first;
        }
        s1.erase({p[j->second].second,j->second});
        s2.erase(j);
        if(!s1.empty())
        {
            j=s1.begin();
            int ind=j->second;
            if(!(p[ind].first<=x && p[ind].second>=x))
            {
                tot+=abs(j->first-x);
                x=j->first;
            }
            s2.erase({p[j->second].first,j->second});
            s1.erase(j);
        }
    }
    tot+=abs(x);
    mx=max(mx,tot);
    cout<<mx;

} 
    


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

char lowerCaseChar(char ch)
{
	char ret;
	if (ch >= 0x41 && ch <= 0x5a) {
		ret = ch + 0x20;
	}
	else {
		ret = ch;
	}
	return ret;
}

void lowerCase(char *str)
{
	int i;
	for (i = 0; str[i] != '\0'; i++) {
		str[i] = lowerCaseChar(str[i]);
	}
}

int main(int argc, char *argv[])
{
	char word[1001], search_word[11];
	int i, cnt = 0;

	memset(word, '\0', sizeof(word));
	memset(search_word, '\0', sizeof(search_word));

	scanf("%s", search_word);

	lowerCase(search_word);

	while (scanf("%s", word) != EOF) {
		if (strcmp(word, "END_OF_TEXT") == 0) {
			break;
		}

		lowerCase(word);

		if (strcmp(word, search_word) == 0) {
			cnt++;
		}
	}

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


	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

signed main() {
  int H1,M1,H2,M2; cin >> H1 >> M1 >> H2 >> M2;
  int K; cin >> K;
  int time1 = H1 * 60 + M1;
  int time2 = H2 * 60 + M2;

  if(time1 >= time2) time2+= 24*60;

  cout << time2 - time1 -K << endl;

}

Measured memory_bytes: 3584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long n = in.nextLong(), k = in.nextLong();
			long x = in.nextLong();
			long y = in.nextLong();

			if (n > k) {
				out.println(x * k + y * (n-k));
			} else {
				out.println(x * n);
			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
import java.util.*;


class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int K = sc.nextInt();
        sc.nextLine();

        int[] list = new int[N];
        double[] wa = new double[N+1];
        double max = 0;

        for (int i = 0; i < N; i++) {
            list[i] = sc.nextInt();
            wa[i+1] = wa[i] + pre(list[i]);
        }

        for (int i = 0; i < N+1-K; i++) {
            max = Math.max(max, wa[i+K] - wa[i]);
        }
        System.out.println(max);
    }

    static double pre (int x) {
        return ((double)x + 1) / 2;
    }
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> l(m);
  vector<int> r(m);
  int lmax = 0;
  int rmin = INF;
  rep(i, m) { cin >> l[i] >> r[i];
    lmax = max(lmax, l[i]);
    rmin = min(rmin, r[i]);
  }
  int ans = rmin - lmax + 1;
  if (ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

const int MAX_DIGIT = 40;
ll dp[41][2]; //桁dp[上からi桁まで][smaller]

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0; //初期条件
    rep(d, MAX_DIGIT) {
        ll mask = 1LL<<(MAX_DIGIT-d-1);
        //aでもともとd桁目にビットが立っているものの個数
        int num = 0;
        rep(i, n) if (a[i] & mask) num++;
        //xのd桁目を0, 1にしたときのコスト
        ll cost0 = mask*num;
        ll cost1 = mask*(n-num);

        //smaller -> smaller
        if (dp[d][1] != -1) {
            chmax(dp[d+1][1], dp[d][1]+max(cost0, cost1));
        }
        //exact -> smaller
        if (dp[d][0] != -1) {
            if (k & mask) { //kのd桁目が1だったら,xのd桁目は0にする
                chmax(dp[d+1][1], dp[d][0]+cost0);
            }
        }
        //exact -> exact
        if (dp[d][0] != -1) {
            if (k & mask) chmax(dp[d+1][0], dp[d][0]+cost1);
            else chmax(dp[d+1][0], dp[d][0]+cost0);
        }
    }

    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
    
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

using pii = pair<int, int>;

int N, M;
vector<int> G[1111];
bool visited[1111];
pii P[1111];

void dfs(int from, int a, int b) {
   // if (from == a || from == b) return;
   visited[from] = true;
   for (int to : G[from]) {
      if (from == a && to == b) continue;
      if (from == b && to == a) continue;
      if (visited[to]) continue;
      dfs(to, a, b);
   }
}

int main() {
   cin >> N >> M;
   rep (i, M) {
      int a, b;
      cin >> a >> b;
      a--; b--;
      G[a].push_back(b);
      G[b].push_back(a);
      P[i] = {a, b};
   }

   int ans = 0;
   rep (i, M) {
      fill(visited, visited+N, false);
      dfs(0, P[i].first, P[i].second);
      if (count(visited, visited+N, true) < N) {
         // debug2(P[i].first+1, P[i].second+1)
         ans++;
      }
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
let solve k =
  let q = Queue.create () in
  let rec f i =
    if i < 10 then (
      Queue.push i q;
      f (i + 1)
    )
  in
  f 1;
  let rec f i =
    let x = Queue.pop q in
    if i = k then x
    else (
      let m = x mod 10 in
      if m <> 0 then Queue.push (10 * x + m - 1) q;
      Queue.push (10 * x + m) q;
      if m <> 9 then Queue.push (10 * x + m + 1) q;
      f (i + 1)
    )
  in
  f 1

let ans k =
  if k < 10 then k
  else solve k

let () =
  print_int (ans (read_int ()))


Measured memory_bytes: 8064
#include <iostream>

using namespace std;

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

	long long total = 1;
	long long dec = 1;

	for (int i = 1; i <= n; ++i) {
		total *= 3;
		int x;
		cin >> x;
		if (x&1)
			dec *= 1;
		else dec *= 2;
	}

	cout << total - dec << "\n";
}

int main() {
	int tests = 1;

	for (;tests; --tests) {
		Solve();
	}
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		int[] n = new int[num.size()];
		for (int i = 0; i < num.size(); i++) {
			n[i] = num.get(i);
		}
		String[] p = new String[param.size()];
		for (int i = 0; i < param.size(); i++) {
			p[i] = param.get(i);
		}
		////////////////////////////////////////////////////////////////////
		int[] kekka = new int[num.size()];
		long min = 999999999999999999l;
		int ansewr = 0;

		for (int i = 0; i < n[0] * 2; i += 2) {
			for (int j = 0; j < n[1]; j++) {
				kekka[j] = Math.abs(n[i + 2] - n[j * 2 + 2 + n[0] * 2]) + Math.abs(n[i + 3] - n[j * 2 + 3 + n[0] * 2]);
				//System.out.println(min + " " + kekka[j]);
				//if(kekka[i] > 100000000) while(true);
				//System.out.println(kekka[j]);
				if (min > kekka[j]) {
					min = kekka[j];
					ansewr = j + 1;
				}
			}
			min = 999999999999999999l;
			System.out.println(ansewr);
		}

	}
}

Measured memory_bytes: 23764
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M = inpl()
xx = inpl()
yy = inpl()

l = 0
r = M-1
ySUM = 0
while True:
	if r-l <= 2:
		ySUM += (yy[r]-yy[l])*(r-l)%mod
		break
	else:
		ySUM += (yy[r]-yy[l])*(r-l)%mod
		r,l = r-1,l+1

l = 0
r = N-1
xSUM = 0
while True:
	if r-l <= 2:
		xSUM += (xx[r]-xx[l])*(r-l)%mod
		break
	else:
		xSUM += (xx[r]-xx[l])*(r-l)%mod
		r,l = r-1,l+1

print(xSUM*ySUM%mod)


Measured memory_bytes: 19492
# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, As):
    S = sum(As)
    Xs = [0] * N
    Xs[0] = S - (sum(As[1::2]) * 2)
    for i in range(1, N):
        Xs[i] = 2 * As[i - 1] - Xs[i - 1]
    print(' '.join([str(i) for i in Xs]))


if __name__ == '__main__':
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    As = [int(i) for i in input().split()]
    # Bs = [int(i) for i in input().split()]
    solve(N, As)


Measured memory_bytes: 24848
#include<iostream>
using namespace std;
int main(){
	char c[5];
	int i,vis1 = 0,vis2 = 0;
	cin >> c[0] >> c[1] >> c[2];
	for(i = 0;i < 3;i++){
		if(c[i]=='7')
			vis1++;
		if(c[i]=='5')
			vis2++;
	}
	if(vis1 == 1 && vis2 == 2)
		cout << "YES" << '\n';
	else
		cout << "NO" << '\n';
}

Measured memory_bytes: 384
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
typedef unsigned long long ULL;
using namespace std;

const int maxn = 1e5 + 24;
int v[maxn];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n, c, k;
	cin >> n >> c >> k;
	for(int i = 1; i <= n; i++) { cin >> v[i];}
	sort(v+1, v+n+1);
	// sort(v.begin(), v.end());
	int r = 1, ans = 1;
	for(int i = 2; i <= n; i++) {
		if(i - r + 1 > c || v[i] - v[r] > k) { ans++ ; r = i;}

	}
	printf("%d", ans);
	return 0;
}
/*
    input:
    output:
    modeling:
    methods:
    complexity:
    summary:
*/

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 1, inf = 1000111222;

int main()
{
    //freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    int cnt = 1;
    n -= k;
    k--;
    cnt += n / k;
    if (n % k) cnt++;
    cout << cnt;
    return 0;
}




Measured memory_bytes: 256
N = int(input())
S = [list(input())[0] for i in range(N)]

A=[]
A.append(S.count("M"))
A.append(S.count("A"))
A.append(S.count("R"))
A.append(S.count("C"))
A.append(S.count("H"))
ans=0

for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=A[i]*A[j]*A[k]
print(ans)

Measured memory_bytes: 54864