akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>

using namespace std;


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

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	string N;
	int x = 0;
	
	cin >> N ;

	for ( int i = 0; i < N.length(); i++ )
	{
		x += N[ i ] - '0';
	}

	if ( ( x % 9 ) == 0 )
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int n, k; cin >> n >> k;
  ll ans = k;
  for(int i=2; i<=n; i++) {
    ans *= k-1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int sum = 0;
  int nozoku = 0;
  int maxnum;
  for(int i=1;i<=N;++i) {
    sum += i;
    if(sum>=N) {
      nozoku = sum - N;
      maxnum = i;
      break;
    }
  }
  for(int i=1;i<=maxnum;++i) {
    if(i==nozoku) continue;
    cout<<i<<endl;
  }
}



Measured memory_bytes: 3548
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//COMinit();
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	rep(i, n)a[i] *= 2;
	int tmp = 0;
	rep(i, n)tmp = a[i] - tmp;
	int x = tmp / 2;
	rep(i, n) {
		cout << x << endl;
		x = a[i] - x;
	}
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main(){
    int N;
    string S;
    cin >> N >> S;
    int cnt = 0,ans = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'R') {
            cnt++;
        }
    }
    for(int i = 0; i < cnt; i++) {
        if(S[i] == 'W') {
            ans++;
        }
    }
    cout << ans << endl;
}


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

int main(){
    char b;
    cin >> b;
    if(b=='A'){
        cout << 'T' << endl;
    } else if(b=='T'){
        cout << 'A' << endl;
    } else if(b=='G'){
        cout << 'C' << endl;
    } else if(b=='C'){
        cout << 'G' << endl;
    }
    return 0;
}

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

using namespace std;

#define LL long long
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    FAST();
    LL n,x;
    string ans="";
    cin >> n;
    while(n > 0)
    {
        x=(n-1)%26;
        ans+=(char)(x+'a');
        n=(n-x-1)/26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans;
    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main(){
	int n,m;
	int i,j;
	int max=0,min=0;
	int b[101]={};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&m);
		for(j=0;j<m;j++) scanf("%d",&b[j]);
		for(j=0;j<m-1;j++){
			if(b[j+1]-b[j]>0 && b[j+1]-b[j]>max) max=b[j+1]-b[j];
			else if(b[j+1]-b[j]<0 && (b[j+1]-b[j])*-1>min) min=(b[j+1]-b[j])*-1;
		}
		printf("%d %d\n",max ,min);
		max=0;
		min=0;
		for(j=0;j<=100;j++) b[j]=0;
	}
return 0;
}

Measured memory_bytes: 596
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;
const int INF = 1<<29;

signed main(){
    ll n,s1=0,s2=0,ans;
    cin>>n;
    vector<ll> np1;
    vector<ll> np2;
    rep(i,floor(sqrt(n))){
        if(n%(i+1)==0) {
            if(i+1 != n/(i+1)){ 
                np1.push_back(i+1);
                np1.push_back(n/(i+1));
            }else np1.push_back(i+1);
        }
    }
    s1 = np1.size();
    rep(i,floor(sqrt(n-1))){
        if((n-1)%(i+1)==0) {
            if(i+1 != (n-1)/(i+1)){ 
                np2.push_back(i+1);
                np2.push_back((n-1)/(i+1));
            }else np2.push_back(i+1);
        }
    }
    s2 = np2.size();
    // rep(i,s2) cout<<np2[i]<<endl;
    ans = s2-1;
    sort(np1.begin(),np1.end());
    rep(i,s1-1){
        ll tmp1 = n;
        while(tmp1%np1[i+1]==0) tmp1 /= np1[i+1];
        if(tmp1%np1[i+1]==1) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
N=int(input())
t=[0]*N
r=set(range(N))
for _ in[0]*N:
 x,y,z=map(int,input().split())
 t[x]=[y,z]+[0]*5
 r-={y,z}
def f(i,p,s,d):
 if i<0:return-1
 l,r=t[i][:2]
 t[i][2:]=[p,s,(l!=-1)+(r!=-1),d,max(f(l,i,r,d+1),f(r,i,l,d+1))+1]
 return t[i][-1]
f(r.pop(),-1,-1,0)
for i in range(N):
 print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(i,*t[i][2:],'root'if not t[i][5]else'internal node'if t[i][4]else'leaf'))


Measured memory_bytes: 5612
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

int main(void){
    int n,k;
    std::cin >> n;
    std::cin >> k;
    double result = 0;
    for(int i = 1;i < n+1; i++){
        // すでに超えてるなら飛ばす
        if(i >= k){
            result += (double)1.0 / (double)n;
            continue;
        }
        int require = 1;
        int now = i * 2;
        while(now < k){
            require++;
            now *= 2;
        }
        result += (double)1.0 / (double)n * std::pow((double)0.5,(double)require);
    }
    std::cout << std::setprecision(15) <<  result << std::endl;
}

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

using namespace std;

map<string, int> a;
vector<int> b;

int main(){
	int N; cin >> N;
	for(int i = 0; i < N; ++i){
		string str; cin >> str;
		a[str]++;
	}
	int M; cin >> M;
	for(int i = 0; i < M; ++i){
		string str; cin >> str;
		a[str]--;		
	}
	for(map<string, int>::iterator itr = a.begin(); itr != a.end(); ++itr){
		b.push_back((*itr).second);
	}
	sort(b.begin(), b.end(), greater<int>());
	if(b[0] < 0) cout << 0 << endl;
	else cout << b[0] << endl;
}


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

using namespace std;

int main() {
	string S;
	while( cin >> S ) {
		if( S == "0" ) {
			break;
		}
		long long int ans = 0;
		vector<vector<long long int>>dp( S.length(), vector < long long int >( 2 ) );
		for( size_t i = 0; i < S.length(); i++ ) {
			if( i ) {
				dp[i] = dp[i - 1];
			}
			if( i % 2 ) {
				dp[i][0] += S[i] - '0';
			} else {
				dp[i][1] -= S[i] - '0';
			}
		}
		for( size_t i = 0; i < S.length(); i++ ) {
			dp[i][0] += dp[i][1];
			while( dp[i][0] < 0 ) {
				dp[i][0] += 11;
			}
			dp[i][0] %= 11;
		}
		vector<long long int>X( 11 );
		X[0]++;
		for( size_t i = 0; i < S.length(); i++ ) {
			ans += X[dp[i][0]];
			if( !( i < S.length() - 1 && S[i + 1] == '0' ) ) {
				X[dp[i][0]]++;
			}
		}

		cout << ans << endl;
	}
}

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

int main() {

	int a, b, c; cin >> a >> b >> c;
	int ans;
	if (a == b) ans = c;
	if (b == c) ans = a;
	if (c == a) ans = b;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3560
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] numArray = new int[n];

		for(int i = 0; i < n; i++){
			numArray[i] = sc.nextInt();
		}

		double sum = 0;
		for(int i = 0; i < n; i++){
			sum += 1.0/numArray[i];
		}

		System.out.println(1.0/sum);
	}
}

Measured memory_bytes: 23636
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author indy256
 */

#include <bits/stdc++.h>

using namespace std;

void solve(istream &in, ostream &out) {
    int m1, d1, m2, d2;
    in >> m1 >> d1 >> m2 >> d2;

    int res = m1 == m2 ? 0 : 1;
    out << res << '\n';
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solve(in, out);
}


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

#define    ll     long long int

int main( )
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    if (b > c) swap(c, b);
    if (a > b) swap(a, b);
    int i, j, k, s = 0;
    i = (c - a) / 2;
    s += i;
    a += 2 * i;
    i = (c - b) / 2;
    s += i;
    b += 2 * i;
    if (a != b) {
        s += 2;
    }
    else if (a != c){
        s++;
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 256
num = int(input())
stn = list(input())
num_W = stn.count('W')
num_R = stn.count('R')
cnt = 0

if num_W >= num_R:
    for i in range(num_R):
        if stn[i] == "W":
            cnt += 1

else:
    for i in range(num_W):
        if stn[-i-1] == "R":
            cnt += 1

print(cnt)


Measured memory_bytes: 10752
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

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

  static class DKatanaThrower {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      int h = in.nextInt();
      ArrayList<Pair<Integer, Integer>> p = new ArrayList<>();
      int swing = 0;
      int res = 0;
      // まず振る刀は最も強いものだけを使う
      // 投げる刀は振る刀よりも強いものを強いものから順に使う
      // 投げ終わったら振る
      //
      for (int i = 0; i < n; i++) {
        p.add(new Pair<>(in.nextInt(), in.nextInt()));
      }

      p.sort(Comparator.comparing(a -> -1 * a.getY()));

      for (int i = 0; i < n; i++) {
        swing = Math.max(swing, p.get(i).getX());
      }

      for (int i = 0; i < n; i++) {
        int pitch = p.get(i).getY();
        if (pitch <= swing) {
          break;
        }
        h -= pitch;
        res++;
        if (h <= 0) {
          break;
        }
      }

      if (h > 0) {
        res += (h + swing - 1) / swing;
      }

      out.println(res);
    }

  }

  static class Pair<T, U> {

    private T x;
    private U y;

    public Pair(T t, U u) {
      this.x = t;
      this.y = u;
    }

    public T getX() {
      return x;
    }

    public U getY() {
      return y;
    }

    public String toString() {
      return this.x.toString() + " " + this.y.toString();
    }

  }
}



Measured memory_bytes: 97180
package main

import (
	"fmt"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n, x, y, t, prevX, prevY, prevT int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&t, &x, &y)
		dx := abs(x - prevX)
		dy := abs(y - prevY)
		dt := t - prevT
		if dist := dx + dy; dt < dist || dist % 2 != dt % 2 {
			fmt.Println("No")
			return
		}
		prevX, prevY, prevT = x, y, t
	}
	fmt.Println("Yes")

}


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

int main()
{
  int n;
  cin >> n;
  vector<char> s(n);
  int i;
  bool yellow = false;
  for(i = 0; i < n; i++)
  {
    cin >> s.at(i);
    if(s.at(i) == 'Y')
    {
      yellow = true;
    }
  }
  if(yellow == true)
  {
    cout << "Four" << endl;
  }
  else
  {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
 
class Main {
  public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
    
    int D = scanner.nextInt(); //next(文字列), nextDouble, nextLine(1行)とか   
    int G = scanner.nextInt();
    int[] p = new int[D];
    int[] q = new int[D];
    
    for (int i = 0; i < D; i++){
      p[i] = scanner.nextInt();
      q[i] = scanner.nextInt();
    }    
    
    int min = 0;
    int ans = 1000000;
    for (int bit = 0; bit < (1<<D);bit++){
      int temp = 0;
      int tempAns = 0;
      for (int j = 0; j < D; j++){
        if ((bit & (1 << j)) != 0){
          temp += 100*(j+1)*p[j] + q[j];
          tempAns += p[j];
        }
      }
      if (temp >= G){
        if (ans > tempAns){
          ans = tempAns;
        }
      }else{
        for (int j = D-1; j>=0;j--){
        	if ((bit & (1 << j)) == 0){
              for (int k = 0; k < p[j]; k++){
                temp += (j+1)*100;
                tempAns++;

                if(temp >= G){break;}
              }
            }
            if(temp >= G){break;}
        }
        if(ans>tempAns){
          ans = tempAns;
        }
      }
    }
    System.out.println(ans);     
  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
const int maxn=2e2+5;
ll k;
int len,n=0;
int a[maxn];
vector<int>A;
void pb(int x){
	a[++len]=x;
}
void pf(int x){
	++len;
	per(i,len,2)a[i]=a[i-1];
	a[1]=x;
}
int main(){
	read(k);k++;
	while(k)A.pb(k&1),k>>=1;
	reverse(A.begin(),A.end());
	rep2(i,1,SZ(A)){
		pb(++n);
		if(A[i])pf(++n);
	}
	rep(i,1,n)pb(i);
	printf("%d\n",len);
	rep(i,1,len)printf("%d ",a[i]);
	return 0;
}

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

int main() {
  bool is_possible;
  int s[12];
  int tmp_cost;
  int min_cost = INT_MAX;
  
  int n, m, x;
  int c[12];
  int a[12][12];
  
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  
  for (int k = 0; k < 2 << n; k++) {
    is_possible = true;
    tmp_cost = 0;
    for (int j = 0; j < m; j++) {
      s[j] = 0;
    }
    for (int i = 0; i < n; i++) {
      if (k / (2 << i) % 2 == 0) {
        continue;
      }
      tmp_cost += c[i];
      for (int j = 0; j < m; j++) {
        s[j] += a[i][j];
      }
    }
    for (int j = 0; j < m; j++) {
      if (s[j] < x) {
        is_possible = false;
      }
    }
    if (is_possible && tmp_cost < min_cost) {
      min_cost = tmp_cost;
    }
  }
  
  if (min_cost == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << min_cost << endl;
  }
}


Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£????????????
		Scanner sc =  new Scanner(System.in);
		//??????????????£?¨?
		boolean[][] card = new boolean[4][13];
		//String???????????????????????????
		String make = new String();
		//?????????????????¨????????°????????£?????\???
		int n = sc.nextInt();
		//??\?????????????????????????????°????????????
		for(int i =0; i< n;i++){
			//?????????????????£?????\???
			make = sc.next();
			//?????????????????´????????? OK
			if(make.equals("S")){
				//S??¨??°?????????????????? true
				card[0][sc.nextInt()-1] = true;
			}else if(make.equals("H")){
				card[1][sc.nextInt()-1] = true;
			}else if(make.equals("C")){
				card[2][sc.nextInt()-1] = true;
			}else if(make.equals("D")){
				card[3][sc.nextInt()-1] = true;
			}
		}
		//??¨???????????????????????????
		for(int i = 0;i<card.length;i++){
			for(int j = 0;j<card[0].length;j++){
				//?????????????????´?????????????????´???
				if(!card[i][j]){
					if(i ==0){
						System.out.println("S " + (j+1));
					}
					if(i ==1){
						System.out.println("H "+ (j+1));
					}
					if(i ==2){
						System.out.println("C "+ (j+1));
					}
					if(i ==3){
						System.out.println("D "+ (j+1));
					}
				}
			}
		}
	}
}

Measured memory_bytes: 26120
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
using namespace std;

int main(){

    int N;
    // vector<int> L;
    // int L[2000] = {};
    cin >> N;
    vector<int> vec(N, 0);
    for(int i = 0 ; i < N ; i++){
        // int tmp;
        // cin >> tmp;
        // vec.push_back(tmp);
        cin >> vec[i];
    }

    sort( vec.begin(), vec.end(), greater<int>() );

    int ans = 0;

    for(int i = 0 ; i < N - 2; i++){
        for(int j = i+1 ; j < N - 1; j++){
            for(int k = j+1 ; k < N ; k++){
                // printf("(i, j, k) = (%d, %d, %d)\n", i, j, k);
                if( vec[i] < vec[j] + vec[k] ) ans++;
                // cout << ans << endl;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 1000005;

int a;
int used[N];

int f(int x) {
	if (x&1) return 3*x+1;
	return x>>1;
}

int main() {

	a=read(); int ans=1;
	while (!used[a]) {
		++ans; used[a]=1; a=f(a);
	}
	printf("%d\n",ans);


	return 0;
	
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>
using namespace std;

int n , a[505] , sum , k;

int factor[100005] , tot;

pair<int , int> pa[505];

long long check(int fac)
{
	long long pos = 0 , neg = 0;
	for(int i = 1 ; i <= n ; i ++)
	{
		int low =  a[i] / fac * fac;
		pa[i] = make_pair(a[i] - low , fac - a[i] + low);
		pos += fac - a[i] + low;
	}
	sort(pa + 1 , pa + 1 + n);
	for(int i = 1 ; i <= n ; i ++)
	{
		neg += pa[i].first , pos -= pa[i].second;
		if(neg == pos) return neg;
	}
	assert(0); 
}

int main()
{
	scanf("%d %d" , &n , &k);
	for(int i = 1 ; i <= n ; i ++)
		scanf("%d" , a + i) , sum += a[i];
		
	for(int i = 1 ; i * i <= sum ; i ++)
		if(sum % i == 0)
		{
			factor[++tot] = i;
			if(i * i != sum) factor[++tot] = sum / i;
		}
	sort(factor + 1 , factor + 1 + tot);
	for(int i = tot ; i ; i --)
		if(check(factor[i]) <= k)
			return printf("%d\n" , factor[i]) & 0;
	assert(0);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <string>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;
typedef pair<int,int> pii;

int main () {
    int N, Q;
    while (cin >> N >> Q, N + Q) {
        vector<string> name(N);
        vector<pii> len(N);
        REP (i, 0, N) {
            cin >> name[i];
            int f, e;
            cin >> f >> e;
            len[i].first = e - f + 1;
            len[i].second = e;
        }
        REP (i, 0, Q) {
            int q;
            cin >> q;
            int cnt = 0;
            string ans = "";
            int l = 0;
            REP (j, 0, N) {
                if (len[j].first <= q && q <= len[j].second) {
                    cnt++;
                    ans = name[j];
                    l = q - len[j].first + 1;
                }
            }
            if (cnt >= 1) {
                cout << ans << ' ' << l << endl;
            } else {
                cout << "Unknown" << endl;
            }

        }
    }
    return 0;
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve()
    {
    int n;
    cin>>n;
    if(n>=400&&n<=599)
    {
        cout<<"8"<<endl;
        return;
    }
    if(n>=600&&n<=799)
    {
        cout<<"7"<<endl;
        return;
    }
    if(n>=800&&n<=999)
    {
        cout<<"6"<<endl;
        return;
    }
    if(n>=1000&&n<=1199)
    {
        cout<<"5"<<endl;
        return;
    }
    if(n>=1200&&n<=1399)
    {
        cout<<"4"<<endl;
        return;
    }
    if(n>=1400&&n<=1599)
    {
        cout<<"3"<<endl;
        return;
    }
    if(n>=1600&&n<=1799)
    {
        cout<<"2"<<endl;
        return;
    }
    if(n>=1800&&n<=1999)
    {
        cout<<"1"<<endl;
        return;
    }

  
  
  
  
    }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

   // wi(t)
    {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}







Measured memory_bytes: 10688
N=int(input())
A=list(map(int, input().split()))

if N==0:
    print(0)
    exit()

now=A[0]
ans=0
for i in range(1,N):
    if A[i]<now:
        ans+=now-A[i]
    now=max(now, A[i])

print(ans)

Measured memory_bytes: 94256
fun main(args: Array<String>) {
    val primeTable = primeTable(100000)
    val table2017 = BooleanArray(100000 + 1) { false }
    for (i in primeTable.indices) {
        val tmp = (i + 1) / 2
        table2017[i] = tmp >= 0 && primeTable[i] && primeTable[tmp]
    }

    val cumulativeSumList = IntArray(table2017.size + 1)
    for (i in 1 until cumulativeSumList.size) {
        cumulativeSumList[i] += cumulativeSumList[i - 1] + if (table2017[i - 1]) 1 else 0
    }

    val q = readInteger()
    val ans = StringBuilder()
    repeat(q) {
        val (l, r) = readIntegerList()
        ans.appendln(cumulativeSumList[r + 1] - cumulativeSumList[l])
//        println(cumulativeSumList[r + 1] - cumulativeSumList[l])
    }
    println(ans)
}

fun primeTable(n: Int): BooleanArray {
    val table = BooleanArray(n + 1) { true }
    if (n >= 0) table[0] = false
    if (n >= 1) table[1] = false
    var i = 2
    while (i * i <= n) {
        if (table[i]) {
            for (j in (i + i)..n step i) {
                table[j] = false
            }
        }

        i++
    }
    return table
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 56632
#include<stdio.h>
using namespace std;

int main() {
    
 int W,H,x,y,r;
 scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
 
 if(x - r < 0 || x + r > W || y - r < 0 || y + r > H){
     printf("No\n");
 }
 else{
      printf("Yes\n");
 }
 return 0;
}


Measured memory_bytes: 2704
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    ll N; cin >> N;
    vector<ll> V(5);
    ll mn = 1LL << 60;
    for(int i=0; i<5; i++){
        cin >> V[i];
        mn = min(mn, V[i]);
    }
    
    
    
    cout << 4 + (N + mn - 1)/mn << endl;

    return 0;
}


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

int main() {
	string s;
	cin >> s;
	int num = 0;
	for (int i = 0; i < (int)s.length(); i++) {
		if (s[i] == '1') {
			num++;
		}
	}
	cout << num << endl;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    int k = (a+b)/2;
    if(abs(a-k) == abs(b-k)){
        cout << k << endl;
    }
    else{
        cout <<"IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ld dp[3010][2],pr[3010];
int n;
ld ds() {
	int g = 0,s=1;
	for(int i=0;i<n;i++) {
		for(int j=0;j<=i+1;j++) {
			dp[j][s] = dp[j][g]*(1-pr[i]);
			if(j > 0) {
				dp[j][s] += dp[j-1][g]*(pr[i]);
			}
		}
		g=1-g;s=1-s;
	}
	ld tp=0;
	for(int i=n;i>n/2;i--) {
		tp += dp[i][g];
	}
	return tp;
}
int main() {
	scanf("%d ",&n);
	memset(dp,0,sizeof(dp));
	dp[0][0] = 1;
	for(int i=0;i<n;i++) {
		ld v;scanf("%Lf ",&v);pr[i] = v;
	}
	cout << setprecision(15) << ds() << '\n';
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=998244353;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n,m,lim;
int fac[2500005],inv[2500005];
int qpow(int x,int y){
    int res = 1;
    while(y){
        if(y & 1) res = (ll)res * x % mod;
        x = (ll)x * x % mod;
        y >>= 1;
    }
    return res;
}
int C(int a,int b){
    if(b < 0 || a < 0 || a < b) return 0;
    return (ll)fac[a] * inv[b] % mod * inv[a - b] % mod;
}
int F(int a,int b){
    return C(a + b - 1, a - 1);
}
int main()
{
    scanf("%d%d",&n,&m);
    lim = n + 3 * m;
    fac[0] = 1;
    rep(i,1,lim) fac[i] = (ll)fac[i - 1] * i % mod;
    inv[lim] = qpow(fac[lim], mod - 2);
    per(i,lim-1,0) inv[i] = (ll)inv[i + 1] * (i + 1) % mod;

    int ans = F(n, 3 * m);
    rep(x,m + m + 1, 3 * m) ans = (ans - (ll)F(n - 1,3 * m - x) * n % mod + mod) % mod;

    rep(x,m + 1,n) if((3 * m - x) % 2 == 0) ans = (ans - (ll)F(n, (3 * m - x) / 2) * C(n,x) % mod + mod) % mod;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 19712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  int n ;
  cin >> n ;
  vector<int> A ;
  for(int i = 1 ; i <= 1000 ; i++ ) for(int j = 2 ; j <= 1000 ; j++ ) if( pow(i,j) <= n )A.push_back(pow(i,j)) ;
  sort(A.begin(),A.end()) ;
  cout << A[A.size() - 1 ] << endl;
}
      

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

typedef long long int ll;
ll n, q, b, c;
map<ll, ll> occ;
ll sum;

int main() {
    scanf("%lld", &n);
    for(ll i = 0; i < n; ++i) {
        scanf("%lld", &b);
        occ[b]++;
        sum += b;
    }

    scanf("%lld", &q);
    for(ll i = 0; i < q; ++i) {
        scanf("%lld %lld", &b, &c);
        sum += (c - b) * occ[b];
        occ[c] += occ[b];
        occ[b] = 0;
        cout << sum << endl;
    }

    return 0;    
}

Measured memory_bytes: 9516
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

struct UnionFind
{
  vector<i64> data;
  UnionFind(i64 size)
  {
    data.resize(size, -1);
  }
  i64 unite(i64 x, i64 y)
  {
    x = root(x);
    y = root(y);
    if (x != y)
    {
      if (data[y] < data[x])
        swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return 0;
  }
  bool same(i64 x, i64 y)
  {
    return root(x) == root(y);
  }
  i64 root(i64 x)
  {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  i64 size(i64 x)
  {
    return -data[root(x)];
  }
};

int main()
{
  i64 n, m;
  cin >> n >> m;
  UnionFind uf(n + m);
  for (i64 i = 0; i < n; i++)
  {
    i64 k;
    cin >> k;
    for (i64 j = 0; j < k; j++)
    {
      i64 l;
      cin >> l;
      uf.unite(i, n + l - 1);
    }
  }
  bool ans = true;
  for (i64 i = 1; i < n; i++)
    if (!uf.same(i, i - 1))
      ans = false;
  cout << (ans ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int x, y, a, b, c;
	scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
	vector<int> red(a);
	for (int i=0; i<a; i++)
		cin >> red[i];
	sort(rall(red));
	vector<int> grn(b);
	for (int i=0; i<b; i++)
		cin >> grn[i];
	sort(rall(grn));
	vector<int> sum(c);
	for (int i=0; i<c; i++)
		cin >> sum[i];
	for (int i=0; i<x; i++)
		sum.push_back(red[i]);
	for (int i=0; i<y; i++)
		sum.push_back(grn[i]);
	sort(rall(sum));
	ll ans = 0;
	for (int i=0; i<x+y; i++)
		ans += sum[i];
	cout << ans << endl;
}


Measured memory_bytes: 2552
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
p = list(map(int, input().split()))

total = [0] * N
total[0] = p[0]
for i in range(1, N):
  total[i] = total[i-1] + p[i]

total_K = 0
max_i = 0
for i in range(N-K+1):
  if i == 0:
    total_K = total[K-1]
  else:
    if total[i+K-1] - total[i-1] > total_K:
      total_K = total[i+K-1] - total[i-1]
      max_i = i

ans = 0
for i in range(K):
  ans += (p[max_i + i] + 1) / 2
print(ans)

Measured memory_bytes: 98780
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

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

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int X, A, B;
    cin >> X >> A >> B;

    if (B - A <= 0) {
        cout << "delicious" << endl;
    } else if (B <= A + X) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int cards[4][14];
    int n,rank;
    char mark;
    //cards＝総枚数　n＝手持ちのカード枚数
    //rank＝カード番号　mark＝マーク
    for(int s=0;s<4;s++){
    for(int r=1;r<=13;r++)
    cards[s][r]=0;
    }
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>mark>>rank;
        if(mark=='S') cards [0][rank]=1;
        if(mark=='H') cards [1][rank]=1;
        if(mark=='C') cards [2][rank]=1;
        if(mark=='D') cards [3][rank]=1;
    }//手元にあるカードを1とする
    for(int s=0;s<4;s++){
        for(int r =1;r<=13;r++){
            if(cards[s][r])continue;
            if(s==0)mark='S';
            if(s==1)mark='H';
            if(s==2)mark='C';
            if(s==3)mark='D';
            cout<<mark<<" "<<r<<endl;
        }
    }
    
}



Measured memory_bytes: 3004
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int n;
int ans;

void dfs(ll x, int mask) {
  if (x > n) return;
  if (mask == 7) ans++;

  dfs(10*x+3, mask|1);
  dfs(10*x+5, mask|2);
  dfs(10*x+7, mask|4);
  return;
}

int main () {
  cin >> n;
  ans = 0;
  dfs(0LL, 0);
  cout << ans << endl;
  return 0;
}

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

/*==========type============*/
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
typedef std::pair<std::string,ll> psl;

/*==========constant============*/
#define INF INT_MAX
#define INF_L LONG_MAX
#define INF_LL LLONG_MAX
#define MOD 1000000007

/*==========function============*/
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

using namespace std;

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

    ll n;
    cin >> n;
    vector<ll> h(n);
    REP(i,0,n)cin >> h[i];

    vector<ll> dp(n,INF);

    dp[0] = 0;
    REP(i,0,n){
        REP(j,1,3){
            if(j + i >= n)break;
            ll cost = abs(h[i] - h[i+j]) + dp[i];
            dp[i + j] = dp[i + j] > cost ? cost : dp[i+j];
        }
        // cout << "i:" << i << " dp:" << dp[i] << endl;
    }

    ll ans = dp[n - 1];

    cout << ans << endl;

    return 0;
}    

Measured memory_bytes: 4704
#!/usr/bin/env python3
def prime_factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

a, b = [int(item) for item in input().split()]    
afct = set(prime_factorize(a) + [1])
bfct = set(prime_factorize(b) + [1])

ans = 0
for item in bfct:
    if item in afct:
        ans += 1

print(ans)

Measured memory_bytes: 38896
import java.util.Scanner;
public class Main {
	public static int top = 0;
	public static int[] stack = new int[10000];
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int a, b;
		String[] s = (sc.nextLine()).split(" ");
		
		for(int i = 0; i < s.length; i++){
			if(s[i].equals("+")){
				a = pop();
				b = pop();
				push(b + a);
			}
			else if(s[i].equals("-")){
				a = pop();
				b = pop();
				push(b - a);
			}
			else if(s[i].equals("*")){
				a = pop();
				b = pop();
				push(b * a);
			}
			else{
				push(Integer.parseInt(s[i]));
			}
		}
		System.out.println(pop());
	}
	
	public static void push(int x){
		stack[++top] = x;
	}
	
	public static int pop(){
		top--;
		return stack[top+1];
	}
}


Measured memory_bytes: 26320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
int n,s,a[3010];
ll dp[3010][3010];
int main() {
    cin >> n >> s;
    for (int i = 0; i < n; i++) cin >> a[i];
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= s; j++) {
            dp[i+1][j] += dp[i][j] * 2;
            dp[i+1][j] %= mod;
            if (j + a[i] <= s) {
                dp[i+1][j+a[i]] += dp[i][j];
                dp[i+1][j+a[i]] %= mod;
            }
        }
    }
    cout << dp[n][s] << endl;
    return 0;
}

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

typedef int Weight;
typedef int Capacity;
struct Edge {
	int src, dst; Capacity cap;
	Edge(int s, int d, Capacity c) : src(s), dst(d), cap(c) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

struct Dinic {
	int n, s, t;
	vector<int> level, prog, que;
	vector<vector<Capacity> > cap, flow;
	vector<vector<int> > g;
	Capacity inf;
	Dinic() {}
	Dinic(const Graph &graph)
		: n(graph.size()),
		cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
		g(n, vector<int>()), inf((int)1e9) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < graph[i].size(); j++) {
				const Edge& e = graph[i][j];
				int u = e.src, v = e.dst;
				Capacity c = e.cap;
				add_edge(u, v, c);
			}
		}
	}
	Dinic(int n_) : n(n_), cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
		g(n, vector<int>()), inf((int)1e9) {
	}
	void add_edge(int u, int v, Capacity c) {
		cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
		g[u].push_back(v); g[v].push_back(u);
	}
	void reset() {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				cap[i][j] = flow[i][j] = 0;
			}
			g[i].clear();
		}
	}
	inline Capacity residue(int u, int v) { return cap[u][v] - flow[u][v]; }
	Capacity solve(int s_, int t_) {
		this->t = t_, this->s = s_;
		que.resize(n + 1);
		Capacity res = 0;
		while(levelize()) { prog.assign(n, 0); res += augment(s, inf); }
		return res;
	}
	bool levelize() {
		int l = 0, r = 0;
		level.assign(n, -1); level[s] = 0; que[r++] = s;
		while(l != r) {
			int v = que[l++]; if(v == t) break;
			for(int i = 0; i < g[v].size(); i++) {
				const int& d = g[v][i];
				if(level[d] == -1 && residue(v, d) != 0) {
					level[d] = level[v] + 1; que[r++] = d;
				}
			}
		}
		return level[t] != -1;
	}
	Capacity augment(int v, Capacity lim) {
		Capacity res = 0;
		if(v == t) return lim;
		for(int &i = prog[v]; i < (int)g[v].size(); i++) {
			const int &d = g[v][i];
			if(residue(v, d) == 0 || level[v] >= level[d]) continue;
			const Capacity aug = augment(d, min(lim, residue(v, d)));
			flow[v][d] += aug; flow[d][v] -= aug;
			res += aug; lim -= aug;
			if(lim == 0) break;
		}
		return res;
	}
};

int u[1000];
int v[1000];

int G[300][300];

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

	int N, M;
	cin >> N >> M;

	Dinic d(N);
	for(int i = 0; i < M; i++) {
		cin >> u[i] >> v[i];
		u[i]--, v[i]--;
		d.add_edge(u[i], v[i], 1);
		d.add_edge(v[i], u[i], 1);
	}

	int s, t;
	cin >> s >> t;
	s--, t--;
	int flow = d.solve(s, t);

	vector<int> ans;
	for(int i = 0; i < M; i++) {
		if(d.residue(v[i], u[i]) == 0) {
			ans.push_back(i + 1);
		}
	}

	cout << flow << endl;
	cout << ans.size() << endl;
	for(auto a : ans) {
		cout << a << endl;
	}
}

Measured memory_bytes: 3612