akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;i++)
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    ll n;
    cin >> n;
    vll v(n);
    rep(i,n)cin >> v[i];
    
    vll memo(100001,0);
    rep(i,(int)v.size()){
        memo[v[i]]++;
    }
    
    ll sum = accumulate(v.begin(),v.end(),0LL);
    ll q;
    cin >> q;
    rep(i,q){
        ll b,c;
        cin >> b >> c;
        sum += (c - b) * memo[b];
        ll temp = memo[b];
        memo[b] = 0;
        memo[c] += temp;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 4344
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  char S[N];
  cin >> S;
  int X = 1;
  char now;
  now = S[0];
  for (int i = 1; i < N; i++) {
    if (S[i] == now) {
      continue;
    } else {
      X++;
      now = S[i];
    }
  }
  cout << X << endl;
  return 0;
}


Measured memory_bytes: 632
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	val n = Scanner.nextInt()
	val a = Array.fill(n)(Scanner.nextInt())
	
	val c = Array.fill(n+1)(0)
	a foreach { c(_) += 1 }
	
	val ans = c.foldLeft(0L) { case (z, e) => e.toLong * (e-1) / 2 + z}
	
	a foreach { ak => pw.println(ans - c(ak) + 1) }

	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 38900
def step(N, A):
    sum = 0
    for i in range(1, N):
        if A[i-1] > A[i]:
            sum += A[i-1] - A[i]
            A[i] = A[i-1]
    return sum
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(step(N, A))

Measured memory_bytes: 32212
#include <vector>
#include <iostream>
using namespace std;
#define ll long long
ll mod = 1000000007;
int main(){
    int n; cin >> n;
    ll a = 1;
    ll b = 2; 
    ll c = 1;
    for(int i=1;i<=n;i++){
        a*=10;
        a%=mod;
    }
    for(int i=1;i<=n;i++){
        b*=9;
        b%=mod;
    }
    for(int i=1;i<=n;i++){
        c*=8;
        c%=mod;
    }
    ll ans = a-b+c;
    ans%=mod;
    if(ans<0) ans+=mod;
    cout << ans;
}



Measured memory_bytes: 3176
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
//NIL is NULL
#define NIL NULL

//Node structure
struct Node{
  int key;
  struct Node *parent;
  struct Node *leftc;
  struct Node *rightc;
};
//define Nodepointer
typedef struct Node * Nodepointer;

//root
Nodepointer root;

//function insert
void insert(int k){
  Nodepointer x,y,z;
  y=NIL;
  x=root;
  z=new struct Node();

  z->key=k;
  z->leftc=NIL;
  z->rightc=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->leftc;
    else x=x->rightc;
  } 
 
  z->parent=y;

  if(y==NIL) root=z;
   
  else if(z->key<y->key) y->leftc=z;

  else y->rightc=z;
 
 
}

//print
void inorderprint(Nodepointer now){
  if(now!=NIL){
    inorderprint(now->leftc);
    printf(" %d",now->key);
    inorderprint(now->rightc);
  }
}

void preorderprint(Nodepointer now){
  if(now!=NIL){
    printf(" %d",now->key);
    preorderprint(now->leftc);
    preorderprint(now->rightc);
  }
}



int main(){

  int n,i,j,data;
  char str[10];

  //load numbaer
  scanf("%d",&n);

  //load command
  for(i=0;i<n;i++){
    scanf("%s",str);
    //insert
    if(strcmp(str,"insert")==0) {
      scanf("%d",&data);
      insert(data);
    }
    //print
    else if(strcmp(str,"print")==0){
      inorderprint(root);
      cout <<endl;
      preorderprint(root);
      cout <<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 12000
#a,b=map(int,input().split())
#p_3,p_4=map(int,input().split())
n=int(input())
#g=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
s=[list(input())for _ in range(n)]
#h=list(map(int,input().split()))
#b=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#s=[list(input().split())for _ in range(n)]
#s=[input()for _ in range(n)]
ans=[]
dic={}
cnt=0
#文字列をソートする
for i in range(n):
    s[i].sort()
    tmp="".join(s[i])
    ans.append(tmp)

#同じ文字列があるかを調べ、その数を数える
for i in range(n):
    if not ans[i]  in dic:
        dic[ans[i]]=1
    else:
        dic[ans[i]]+=1

for val in dic.values():
    cnt+=val*(val-1)//2
print(cnt)

Measured memory_bytes: 40688
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

bool solve() {
	int n; cin >> n; set<int> se;
	REP (i,n) {
		int x; cin >> x;
		if (se.find(x) != se.end()) {
			se.erase(x);
		} else {
			se.insert(x);
		}
	}
	cout << se.size() << endl;
}

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

Measured memory_bytes: 4992
#include <stdio.h>

long long dp[110][100010];

long long min(long long a, long long b){
    if(a<b)
        return a;

    return b;    
}

int main(){
    int i,j,n;
    long long v[110],w[110];
    long W,v_sum = 0;

    scanf("%d %ld",&n,&W);

    for(i = 1; i<= n ; i++){
        scanf("%lld %lld",&w[i],&v[i]);
        v_sum += v[i];
    }

    for(i = 0; i <= n ;i++){
        for(j = 0 ; j <= v_sum  ;j++){
            dp[i][j] = 1000000001;
        }
    }

    
    dp[1][v[1]] = w[1];
    dp[1][0] = 0;
    for(i = 2; i<= n ; i++){
        dp[i][v[i]] = w[i];
        for(j = 0; j <= v_sum ; j++){
            if(j-v[i] >= 0){
                dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
            //printf("%lld",dp[i][j]);
        }
        //printf("\n");
    }
    for(i = n ; i >= 1 ; i--){
        for(j = v_sum ; j >= 1 ; j--){
            if(dp[i][j] <= W)
                break;
        }
        if(dp[i][j] <= W)
                break;
    }
    printf("%lld\n",j);
    return 0;


}

Measured memory_bytes: 80000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "3";
            if (sS[0] == sS[1] && sS[1] == sS[2]) { sOut = "1"; }
            else if (sS[0] == sS[1] || sS[1] == sS[2] ||  sS[2] == sS[0]) { sOut = "2"; }

            // 出力
            Console.WriteLine("{0}", sOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 11220
#include<cstdio>

using namespace std;

int n, a[1000005];

int main(){
	scanf("%d", &n);
	if(n == 0)	return puts("0"), 0;
	while(n){
		int t = n / (-2);
		if(n - t * (-2) < 0)	t++;
		a[++a[0]] = n - t * (-2);
		n = t;
	}
	for(int i = a[0]; i; i--)	printf("%d", a[i]);
	putchar(10);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define ll long long int

int main(void) {
    ll l, r;
    int k, a = 2020;
    scanf("%lld%lld", &l, &r);
    if((r - l) >= 2019) {
        a = 0;
        printf("%d\n", a);
        return 0;
    }
    for(ll i = l; i < r; i++) {
        for(ll j = i+1; j <= r; j++) {
            if(i < j) {
                k = (i * j) % 2019;
                if(a > k) a = k;
            }
        }
    }
    printf("%d\n", a);
    return 0;
}


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

int main() {
    string s; cin >> s;
    string az = "abcdefghijklmnopqrstuvwxyz";
    unordered_set<int> S;
    for(int i = 0; i < s.size(); i ++) S.insert(s[i]);
    if(S.size()==26) {
        cout << "None" << endl;
        return 0;
    }
    for(int i = 0; i < S.size(); i ++) {
        if(S.find(az[i]) != S.end()) {
            az.erase(az.begin()+i);
            i --;
        }
    }
    cout << az[0] << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(ll i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1e9+7;

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

//********************************template END****************************************//

void solve(void){

	int N, M, Q;
	cin >> N >> M >> Q;
	vec ls(M), rs(M);
	rep(M, i) {
		cin >> ls[i] >> rs[i];
		ls[i]--, rs[i]--;
	}

	mat m(N, vec (N, 0));

	rep(M, i)
	{
		Rep(rs[i], N-1, r)
		{
			m[ls[i]][r]++;
		}
	}

	while(Q--)
	{
		int p, q;
		cin >> p >> q;
		p--, q--;
		int cnt = 0;
		Rep(p, q, i)
		{
			cnt += m[i][q];
		}

		cout << cnt << endl;
	}

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int BinarySerch(vector<int>& array,int serching){
	int lp = 0;
	int rp = array.size()-1;
	
	while(rp != lp){
		int middle = (rp + lp)/2;
		if(array[middle] > serching){
			rp = middle - 1; 
		}
		else if(array[middle] < serching){
			lp = middle + 1;
		}
		else{
			return middle;
		}
	}
	return rp;
}

int main(){
	int N;
	cin>>N;
	vector<int> data;
	
	vector<int> sorted_data;
	REP(i,N){
		int inp;
		cin>>inp;
		data.push_back(inp);
		sorted_data.push_back(inp);	
	}
	
	sort(sorted_data.begin(),sorted_data.end());

	int ans = 0;
	for(int i = 0; i < data.size(); i++){
		int sorted_order_num = BinarySerch(sorted_data,data[i]);
		//cout<<sorted_order_num<<" "<<i<<endl;
		if( (sorted_order_num % 2) != (i % 2) ){
			ans++;
		}
	}
	cout<<ans/2<<endl;
	
	return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>
#include <utility>

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<int> a(N+1);
    vector<bool> ball(N+1, false);
    int ball_count = 0;

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

    for (int i = N; i >= N/2 + 1; i--){
        if (a[i] == 1){
            ball[i] = true;
            ball_count++;
        }
    }

    for (int i = N/2; i >= 1; i--){
        int count = 0;
        for (int j = 2; i*j <= N; j++){
            if (ball[i*j] == true){
                count++;
            }
        }
        if (count % 2 == 0 && a[i] == 1){
            ball[i] = true;
            ball_count++;
        } else if (count % 2 == 1 && a[i] == 0){
            ball[i] = true;
            ball_count++;
        }
    }

    if (ball_count == 0){
        cout << 0 << endl;
        return 0;
    }

    cout << ball_count << endl;
    for (int i = 1; i <= N; i++){
        if (ball[i] == true){
            cout << i << " ";
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 1e5+10;

using namespace std;

main()
{
    fast;
    int n,a,b,i;
    ll k;
    cin>>n>>k;
    ll f[N]={0};
    for (i=0;i<n;i++)
    {
        cin>>a>>b;
        f[a]+=b;
    }
    int ctr=1;
    while (k)
    {
        if (f[ctr])
        {
            if (f[ctr]>=k)
            {
                cout<<ctr<<endl;
                break;
            }
            k-=f[ctr];
        }
        ctr++;
    }
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------
long long a, b;
void solve(){
    int cnt = 0;
    long long i = a;
    while(i <= b){
        cnt++;
        i *= 2;
    }
    cout << cnt << endl;
}
int main(){
    cin >> a >> b;
    solve();
    return 0;
}



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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

signed main() {
  int n, m;
  cin >> n >> m;
  if(n == m) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    for(int i = 0; i < K; i++){
        if(A >= B){
            B = 2 * B;
        }
        else if(B >= C){
            C = 2 * C;
        }
    }
    
    if(A < B && B < C){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

 
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
        vector<vector<ll>> d(n+100,vector<ll>(3,-INF));
        d[0][0]=a[0];
        d[1][1]=a[1];
        d[2][2]=a[2];
        rep(i,n){
            if (i%2==1){
                if (i<n){
                    d[i+2][1]=max(d[i+2][1],d[i][1]+a[i+2]);
                    d[i+3][2]=max(d[i+3][2],d[i][1]+a[i+3]);
                }
            }
            else{
                if (i<n){
                    d[i+2][0]=max(d[i+2][0],d[i][0]+a[i+2]);
                    d[i+3][1]=max(d[i+3][1],d[i][0]+a[i+3]);
                    d[i+4][2]=max(d[i+4][2],d[i][0]+a[i+4]);
                    d[i+2][2]=max(d[i+2][2],d[i][2]+a[i+2]);
                }
            }
        }
        ll ans;
        if (n%2==1){
        ans=max(d[n-1][2],d[n-2][1]);
        ans=max(ans,d[n-3][0]);}
        if (n%2==0) cout << max(d[n-1][1],d[n-2][0]) << endl;
        else cout << ans << endl;
}

Measured memory_bytes: 15580
#include<stdio.h>

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}

//next_permutation
//https://qiita.com/Nikkely/items/0ddca51b3c0e60afbaab
int next_permutation(int a[],int n){
  int i=-1,j,k;
  for(k=n-2;k>=0;k--){
    if(a[k]<a[k+1]){i=k;break;}
  }
  if(i==-1){return -1;}
  for(k=n-1;k>=0;k--){
    if(a[i]<a[k]){j=k;break;}
  }
  swap(&a[i],&a[j]);
  for(k=i+1;k<n;k++){
    j=n-(k-i);
    if(k<j){swap(&a[j],&a[k]);}
    else{break;}
  }
  return 0;
}

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

int main(){
  int i,j,n,p[16],q[16],arr[16],x,y;
  scanf("%d",&n);
  for(i=0;i<n;i++){scanf("%d",&p[i]);p[i]--;}
  for(i=0;i<n;i++){scanf("%d",&q[i]);q[i]--;}
  for(i=0;i<n;i++){arr[i]=i;}
  for(i=0;i<fact(n);i++){
    for(j=0;j<n;j++){
      if(p[j]!=arr[j]){break;}
      if(j==n-1){x=i;}
    }
    for(j=0;j<n;j++){
      if(q[j]!=arr[j]){break;}
      if(j==n-1){y=i;}
    }
    next_permutation(arr,n);
  }
  printf("%d\n",zt(x,y));
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;
 
int N;
int D[50];
int E[50];
 
int main(void){
    scanf("%d",&N);
    REP(i,N)
        scanf("%d",D+i);
    if(23<N){
        printf("0\n");
        return 0;
    }else if(N==23){
        int A[12];
        REP(i,12)
            A[i]=2;
        A[0]--;
        REP(i,N){
            if(D[i]==12)
                A[0]--;
            else
                A[D[i]]--;
        }
        REP(i,12)
            if(A[i]<0){
                printf("0\n");
                return 0;
            }
        printf("1\n");
        return 0;
    }
    int ans=0;
    REP(i,(1<<N)){
        REP(j,N)
            E[j]=(i&(1<<j))?D[j]:-D[j];
        E[N]=0;
        sort(E,E+N+1);
        // printf("------\n");
        // REP(j,N+1)
            // printf("%d ",E[j]);
        // printf("\n");
        int res=24-(E[N]-E[0]);
        // printf("res=%d\n",res);
        REP(j,N){
            res=min(res,E[j+1]-E[j]);
            // printf("j=%d res=%d E[j+1]-E[j]=%d\n",j,res,E[j+1]-E[j]);
        }
        // printf("res=%d\n",res);
        ans=max(ans,res);
    }
    printf("%d",ans);
     return 0;
}

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

using namespace std;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int n;
	cin >> n;
	if(n%3 != 0){
		int a[n];
		REP(i, n){
			cin >> a[i];
			if(a[i] != 0){
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
	else{
		int a[n];
		REP(i, n) cin >> a[i];
		sort(a, a+n);
		REP(i, n){
			if(a[i] != a[(i / (n/3))*(n/3)]){
				cout << "No" << endl;
				return 0;
			}
		}
		ll x = a[0] ^ a[n/3] ^ a[2*n/3];
		if(x == 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
} 


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

int main(){
        int a,b;
        char op;
        cin >> a >> op >> b;
        if(op == '-') cout << a-b << endl;
        else cout << a+b << endl;
        return 0;
}


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

int main(void){
  int N, K, temp;
  cin >> N >> K;
  int count = 0;
  for(int i = 0; i < N; i++){
    cin >> temp;
    if(temp >= K){
     count++; 
    }
  }
  cout << count << endl;
 return 0; 
}

Measured memory_bytes: 256
#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 {
  printf("a == b\n");
 }
  return 0;
}




Measured memory_bytes: 2048
// Problem : A - Registration
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf INT_MAX
#define mninf INT_MIN
#define infl 1e18+5
#define mninfl -1e18-5
#define Mod 1000000007
#define newmod  998244353
int ah=911382323;
int bh=972663749;
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const long double pi=acos(-1);
//looping
#define int long long
#define For(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' ';  cout<<endl
#define pv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";  cout<<endl
#define pm(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";cout<<endl;}cout<<endl
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}
#define deb(x) cerr << #x << " = " << x << endl;
#define deb2(x,y)  cerr << #x << " = " << x <<"   "<< #y << " = " << y << endl;
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define all(v) (v).begin(),(v).end()
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,1,-1,1,-1};
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef vector < pair <int, int> > vpii;
typedef pair<int,int>  pii;
/*/----------------------------Code begins----------------------------------/*/
int32_t main(){
fio;
string s,t;
cin>>s>>t;
if(t.substr(0,s.size())==s)
cl("Yes");
else cl("No");


}




























Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <tuple>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int N,A,B; cin>>N>>A>>B;
  int ans_sum = 0;
  for(int i = 1; i<= N; i++) {
    int target = i;
    int sum = 0;
    while(target != 0) {
      sum += target % 10;
      target /= 10;
    }
    if(sum >= A && sum <= B) {
      ans_sum += i;
    }
  }

  cout << ans_sum << endl;
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N, K; cin >> N >> K;
        vector<int> T(N), D(N); rep(i, N) cin >> T[i] >> D[i];

        map<int, pii> top1;
        rep(i, N) set_max(top1[T[i]], make_pair(D[i], i));

        set<int> top1_indices;
        for(auto &p : top1) top1_indices.insert(p.second.second);

        vector<int> top1_list, other_list;
        rep(i, N) (top1_indices.count(i) ? top1_list : other_list).push_back(D[i]);

        while(other_list.size() < N) other_list.push_back(0);

        auto make_sum = [] (vector<int> &l) {
            sort(all(l), greater<int>());
            vector<ll> sum(l.size() + 1);
            rep(i, l.size()) sum[i + 1] = sum[i] + l[i];
            return sum;
        };
        auto top1_sum = make_sum(top1_list);
        auto other_sum = make_sum(other_list);

        ll ans = 0;
        repeat(k, 1, K + 1) {
            ll l = K - k;
            if(k >= top1_sum.size()) continue;
            ll sum = top1_sum[k] + other_sum[l];

            if(l > 0) {
                int m = upper_bound(all(top1_list), other_list[l - 1], greater<int>()) - begin(top1_list) - 1 + 1;

                if(m - k > l) m = k + l;

                if(k < m and m < top1_sum.size()) {
                    sum = top1_sum[m] + other_sum[K - m];
                }
            }
            set_max(ans, sum + (ll)k * k);
        }
        cout << ans << endl;

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

int main() {
    //input
    vector<int> a(5);
    cin >> a.at(0);
    cin >> a.at(1);
    cin >> a.at(2);
    cin >> a.at(3);
    cin >> a.at(4);

    int f = 10;
    int l = 0;
    for(int i=0;i<5;i++){
        if((a.at(i)-1)%10 < f){
            f = (a.at(i)-1)%10;
            l = i;
        }
    }

    int sum = 0;
    for(int i=0;i<5;i++){
        if(i == l){
            sum += a.at(i);
        }else{
            if(a.at(i)%10){
                sum += (1 + a.at(i)/10)*10;
            }else{
                sum += (a.at(i)/10)*10;
            }
        }
    }

    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
p = 1/n
ans = [0 for i in range(n)]
for i in range(n):
    tensu = i+1
    cnt = 0
    while k>tensu:
        tensu *=2
        cnt+=1
    saikoro = 0.5**cnt
    ans[i] = p*saikoro
print(sum(ans))

    

Measured memory_bytes: 6296
//jinhaonan
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
template<class T>inline void read(T &x){
	x=0;char c=getchar();bool f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	x=f?-x:x;
}
template<class T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
template<class T>inline bool chkmax(T &a,T const &b){
	return a<b?a=b,1:0;
}
template<class T>inline bool chkmin(T &a,T const &b){
	return a>b?a=b,1:0;
}
const int N=100000+10;
void Main(){
	static char s[N];
	scanf("%s",s+1);
	int n=strlen(s+1);
	bool flag=s[n]=='1';
	flag|=s[1]=='0';
	for(int i=1;i<n;++i){
		flag|=s[i]!=s[n-i];
	}
	if(flag){
		puts("-1");
		return;
	}
	s[n]='1';
	vector<pair<int,int>> ans;
	int j=1;
	for(int i=1;i<=n;++i){
		if(s[i]=='1'){
			for(;j<i;++j){
				ans.push_back({i,j});
			}
		}
	}
	for(auto x:ans){
		write(x.first),putchar(' '),write(x.second),putchar('\n');
	}
}
int main(){
    // freopen("in.txt","r",stdin);
    // int test;read(test);
    // while(test--){
        Main();
    // }
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;
typedef long long ll;

typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.1415926535897932384626;
long long int mod = 1000000007;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}

ll i,j,k,ii,jj;
ll n,m,num;
ll a,b,c,d,e,g,h,r;
ll f[500005],x[500005],y[500005],z[500005];
bool dame;
bool check[500005];
char s[500005],t[500005];




int main(){
    cin>>n;
	for(i=1;i<=n;i++)cin>>x[i];
	a = 1;
	for(i=1;i<=n;i++){
		a *= i;
		a %= mod;
	}
	b = a;
	for(i=1;i<=n;i++){
		a = b;
		a *= rui(i,mod-2);
		a %= mod;
		f[i] = a;
	}
	//for(i=1;i<=n;i++)p(f[i]);
	ll sum = 0;
	for(i=1;i<=n;i++){
		sum += f[i];
		sum %= mod;
	}
	
	ll ans = 0;
	for(i=1;i<=n;i++){
		//p(sum);
		ans += (x[i] * sum)%mod;
		ans %= mod;
		if(i==n)break;
		sum += (mod - f[n-i+1]);
		sum += f[i+1];
		sum %= mod;
	}
	
	p(ans);
	
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int points[N + 2];
    points[0] = 0;
    points[N + 1] = 0;
    int all = 0;
    for(int i = 1; i <= N; i++){
        cin >> points[i];
        all += abs(points[i] - points[i - 1]);
    }
    all += abs(points[N]);
    for(int i = 1; i <= N; i++){
        if((points[i - 1] <= points[i] && points[i] <= points[i + 1]) || (points[i - 1] >= points[i] && points[i] >= points[i + 1])){
            cout << all << endl;
        }else{
            cout << all - min(abs(points[i] - points[i - 1]), abs(points[i] - points[i + 1])) * 2 << endl;
        }
    }
    
}


Measured memory_bytes: 1664
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) //cerr<< #x <<": "<<x<<endl
#define debug2(x,y) //cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int r, c, n;
bool on_edge(int x, int y) {
  return (x == 0 || x == r) || (y == 0 || y == c);
}

double xcenter, ycenter;
double get_atan(vi &a) {
  return atan2(a[1] - ycenter, a[0] - xcenter);
}

int main() {
  scanf("%d %d %d", &r, &c, &n);
  xcenter = r / 2.0;
  ycenter = c / 2.0;
  vvi points;
  rep (i, n) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    if (on_edge(x1, y1) && on_edge(x2, y2)) {
      vi point1 = {x1, y1, i};
      vi point2 = {x2, y2, i};
      points.push_back(point1);
      points.push_back(point2);
    }
  }
  int m = points.size();
  sort(all(points), [](vi a, vi b) {
      return get_atan(a) < get_atan(b);
      });

  deque<int> stk;
  rep (i, m) {
    int num = points[i][2];
    if (stk.empty()) {
      stk.push_back(num);
      continue;
    }
    if (stk.back() == num) {
      stk.pop_back();
    } else {
      stk.push_back(num);
    }
  }
  if (stk.empty()) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 12460
import sys
sys.setrecursionlimit(4100000)

N = int(input())
mod = 10 ** 9 + 7
L = [{} for i in range(101)]

def check(txt):
    if 'AGC' in txt:
        return False
    List = list(txt)
    for i in range(3):
        List[i], List[i+1] = List[i+1], List[i]
        if 'AGC' in ''.join(List):
            return False
        List[i], List[i+1] = List[i+1], List[i]
    return True
    
def dfs(i, txt):
    if i == N:
        return 1
    if txt in L[i]:
        return L[i][txt]
    ans = 0
    for char in 'AGCT':
        if check(txt[1:] + char):
            ans += dfs(i+1, txt[1:] + char)
    L[i][txt] = ans % mod
    return ans % mod

print(dfs(0, 'TTTT'))

Measured memory_bytes: 6156
#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7;
long long mod(long long a)
{
  return((a%M+M)%M);
}
long long add(long long x,long long y)
{
  return mod(mod(x)+mod(y));
}
long long multiply(long long x,long long y)
{
  return mod(mod(x)*mod(y));
}
long long subtract(long long x,long long y)
{
  return mod(mod(x)-mod(y));
}

int main()
{
  long long int N;
  cin>>N;
  long long int A=1,B=1,D=1;
  for(long long int i=0;i<N;i++)
  {
    A=multiply(A,10);
    B=multiply(B,9);
    D=multiply(D,8);
  }
  A=add(A,-B);
  A=add(A,-B);
  A=add(A,D);
  cout<<mod(A);
}

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

using namespace std;
vector<int>v;
int main(){
	int n;
	int cnt = 0;
	cin >> n;

	for(int i = 1; i <=n; i+=2){
		for(int j = 1; j <= i; j++){
			if(i % j == 0){
				cnt++;
			}
		}
		if(cnt == 8){
			v.push_back(i);
		}
		cnt = 0;
	}


	cout << v.size();

	return 0;
}

Measured memory_bytes: 256
"""
AtCoder Educational DP Contest
https://atcoder.jp/contests/dp/tasks/dp_a

B - Frog 2
"""
INF = 100000007
import collections

def cost(i, j):
    if i < 0:
        return INF
    return abs(hs[i] - hs[j])

def solve(hs):
    dp = collections.defaultdict(lambda: INF)
    dp[0] = 0
    for i in range(1, N):
        dp[i] = min(
            dp[i - kk] + cost(i - kk, i)
            for kk in range(1, K + 1)
        )
    return dp[N - 1]

N, K = map(int, input().split())
hs = [int(s) for s in input().split()]
assert len(hs) == N
res = solve(hs)
print(res)


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

int main(){
  int n;
  double sum=0;
  cin>>n;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
    sum+=1.0/num[i];
  }
  cout<<1.0/sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	string S;
	int counter=0,Sc=0;
	cin>>S;
	REP(i,(int)S.length()){
		counter++;
		if(S[i]=='S') Sc++;
		else{
			if(Sc>=1){
				counter-=2; Sc--;
			}
		}
	}
	print(counter);
}


Measured memory_bytes: 640
from bisect import bisect_left

N, K = map(int, input().split())
D = [int(s) for s in input().split()]

ans = -float("inf")
for i in range(1 + min(N, K)):
    for j in range(1 + min(N - i, K - i)):
        if i == j == 0:
            ans = max(ans, 0)
            continue
        remk = K - i - j
        v = D[:i] + D[N-j:]
        v.sort()
        numge0 = bisect_left(v, 0)
        ans = max(ans, sum(v[min(remk, numge0):]))

print(ans)


Measured memory_bytes: 40816
s = input()

s1 = ''.join(['1' if i%2 == 0 else '0' for i in range(len(s))])
s2 = ''.join(['0' if i%2 == 0 else '1' for i in range(len(s))])

num1 = 0
num2 = 0
for i in range(len(s)):
    if s1[i] != s[i]:
        num1 += 1
    if s2[i] != s[i]:
        num2 += 1
        
print(min(num1,num2))

Measured memory_bytes: 4068
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#define endl '\n'
#define ll long long

using namespace std;


int main(void)
{
        cin.tie(NULL); ios_base::sync_with_stdio(false);
        string str1, str2; cin >> str1 >> str2;

        if(str1[1] != str2[1])
                cout << "NO";
        else if(str1[0] == str2[2] && str1[2] == str2[0])
                cout << "YES";
        else
                cout << "NO";

        return 0;
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int table[26][26];

int main()
{
	memset(table, 0, sizeof(table));
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	string S, T; cin >> S >> T;

	int n = (int)S.length();
	rep (i, n){
		++table[S[i] - 'a'][T[i] - 'a'];
	} // end rep

	bool ok = true;
	rep (i, 26){
		int cnt = 0;
		rep (j, 26){
			if (table[i][j] != 0){
				++cnt;
			} // end if
		} // end rep
		if (cnt > 1){
			ok = false;
		} // end if

		cnt = 0;
		rep (j, 26){
			if (table[j][i] != 0){
				++cnt;
			} // end if
		} // end rep
		if (cnt > 1){
			ok = false;
		} // end if
	} // end rep	
		
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}

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

from collections import defaultdict
from copy import deepcopy

def greedy(D, c, s):

    ret = []
    last = defaultdict(int)

    for d in range(1, D+1):

        last = defaultdict(int)
        scores = dict()


        for choice in range(1,27):
            _last = deepcopy(last)  
            satisfaction = s[(d, choice)]
            _last[choice] = d
            for i in range(1,27):
                satisfaction -= c[i]*(d - _last[i])

            scores[choice] = satisfaction

        choice = max(scores, key=scores.get)
        ret += [choice]
        last[choice] = d

    return '\n'.join(map(str, ret))

D = int(input())
c = input().split(' ')
c = list(map(int, c))
c = [float("inf")] + c
s = dict()
for i in range(D):
    row = input().split(' ')
    for j, e in enumerate(row):
        e = int(e)
        s[(i+1, j+1)] = e

print(greedy(D, c, s))

Measured memory_bytes: 72396
#include<bits/stdc++.h>
using namespace std;
const int MAXN=0x3f3f3f;  
int a[105];
int n,i,j,k,minv=MAXN,ans;
int main(){
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1); 
	for(i=a[1];i<=a[n];i++){ 
		for(k=1;k<=n;k++)  
		ans+=(a[k]-i)*(a[k]-i);
		minv=min(minv,ans);
		ans=0; 
	}
	cout<<minv;
	return 0;
}

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{

    int r, d, a;
    long x;

    public void AtCoder()
    {
        string[] input;
        input = Console.ReadLine().Split(' ');
        r = int.Parse(input[0]);
        d = int.Parse(input[1]);
        a = int.Parse(input[2]);
        x = a;
        for(int i=0; i<10; i++)
        {
            x = x * r - d;
            Console.WriteLine(x);
        }
    }
    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}


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

inline ll read(){
    ll s = 0, w = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){ if(ch == '-') w = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

inline void print(ll x){
    if(x < 0) x = ~x + 1, putchar('-');
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

int main(){
    ll n;
    n = read();
    ll a = n % 1000;
    if(a != 0)
        print(1000 - a);
    else
        print(0);

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>  
using namespace std;
using ll = long long int;
using graph = vector<vector<char>>;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using pll = pair<ll, ll>;

int main() {
  string s; ll k;
  cin>>s>>k;
  ll n=0;
  rep(i,s.size()-1){
    if(s[i]==s[i+1]){n++; i++;}
  }
  ll ans=n*k;
  if(count(s.begin(),s.end(),s[0])==s.size()){
    if(s.size()%2==1){ans=s.size()*k/2;}
    
  }
  else if(s[0]==s[s.size()-1]){
    int i=1;ll m=2;
    while(s[i]==s[0]){m++; i++;}
    i=s.size()-2;
    while(s[i]==s[0]){m++; i--;}
   if(m%2==0){ans+=k-1;}
  }
  cout<<ans;
}

Measured memory_bytes: 3560
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        int[] array = new int[n];
        String[] input = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            array[i] = Integer.parseInt(input[i]);
        }
        int[] sorted = array.clone();
        Arrays.sort(sorted);

        int left = sorted[n/2-1];
        int right = sorted[n/2];
        
        for(int i = 0; i < n; i++){
            if(array[i] <= sorted[n/2-1]){
                System.out.println(right);
            }else{
                System.out.println(left);
            }
        }
    }
}

Measured memory_bytes: 90852