akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll t1, t2, a1, a2, b1, b2, c1, c2, d, e;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    c1 = a1 - b1;
    c2 = a2 - b2;
    if(c1 < 0){
        c1 = -c1;
        c2 = -c2;
    }
    d = t1 * c1;
    e = t1 * c1 + t2 * c2;
    if(e > 0){
        printf("%d\n", 0);
    }
    else if(e == 0){
        printf("infinity\n");
    }
    else{
        e = -e;
        if(d % e == 0){
            printf("%lld\n", 2 * (d/e));
        }
        else{
            printf("%lld\n", 1 + 2 * (d/e));
        }
    }

}

Measured memory_bytes: 3724
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[410][410];
ll dp2[410][410];

int main(){
  int n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  for(int len=1;len<=n;len++){
    for(int i=0;i+len<=n;i++){
      int j=i+len;
      dp[i][j]=min(a[i]+dp[i+1][j],dp[i][j-1]+a[j-1]);
      if(len>=2){
        dp2[i][j]=1e18;
        for(int k=i;k<=j;k++){
          chmin(dp2[i][j],dp2[i][k]+dp2[k][j]+dp[i][j]);
        }
      }
    }
  }
  cout << dp2[0][n] << endl;
}

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

vector<string> divide = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;

    reverse(S.begin(), S.end());
    rep(i, 4) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for(int i = 0; i < (int)S.size(); ) {
        bool can2 = false;
        rep(j, 4) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2) {
            can = false;
            break;
        }
    }
    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;

}


Measured memory_bytes: 512
import java.util.HashMap;
import java.util.Scanner;

public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);

                int N = scan.nextInt();

                HashMap<String, Integer> Shash = new HashMap<String, Integer>();

                for (int i = 0; i < N; i++) {
                	String s = scan.next();
                	if (!Shash.containsKey(s)) {
                		Shash.put(s, 1);
                	}
                }

                System.out.println(Shash.size());

        }

}

Measured memory_bytes: 77048
#include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define pb push_back
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);


void solve() {
    int x;
    cin >> x;
    cout << (x ? "0": "1");
}

int main() {_
    int t = 1;
//    cin >> t;
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


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

char a, b;

int main() {
  cin >> a >> b;
  if (a == 'H') {
    cout << b << endl;
  } else {
    if (b == 'H') {
      cout << 'D' << endl;
    } else {
      cout << 'H' << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import scala.util.control.Breaks
object Main extends App {

  val b = new Breaks

  b.breakable {
    while (true) {
      val Seq(n, x) = readLine().split(' ').map(_.toInt).toList

      if (n == 0 && x == 0) b.break

      val nums = for {
        i <- 1 to n
        j <- 1 until i
        k <- 1 until j
      } yield { (i, j, k) }

      val ans = nums.count(t => t._1 + t._2 + t._3 == x)

      println(ans)
    }
  }
}


Measured memory_bytes: 190256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int l[110];
int r[110];
int t[110];
double PI=acos(-1.0);
double ABS(double a){return max(a,-a);}
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%d%d%d",l+i,r+i,t+i);
		double x=0;
		double y=0;
		double th=PI/2;
		for(int i=0;i<a;i++){
			if(l[i]==r[i]){
				x+=cos(th)*l[i]*t[i]*PI/180;
				y+=sin(th)*l[i]*t[i]*PI/180;
			}
			if(l[i]*r[i]<0){
				double cl=ABS(l[i])/(ABS(l[i])+ABS(r[i]));
				double cx=x-cos(th-PI/2)*b+cos(th-PI/2)*2*b*cl;
				double cy=y-sin(th-PI/2)*b+sin(th-PI/2)*2*b*cl;
				double cL=2.0*b*cl;
				double cR=2.0*b*(1.0-cl);
				double len=(ABS(l[i])+ABS(r[i]))*t[i]*PI/180;
				double dt=len/(cL+cR);
			//	printf("(%f %f), %f %f\n",cx,cy,cL,cR);
				if(l[i]<0)th+=dt;
				else th-=dt;
				x=cx+(cL-b)*cos(th+PI/2);
				y=cy+(cL-b)*sin(th+PI/2);
				continue;
			}
			if(ABS(l[i])<ABS(r[i])){
				double cl=2.0*b*l[i]/(r[i]-l[i])+b;
				double cx=x+cl*cos(th+PI/2);
			double	cy=y+cl*sin(th+PI/2);
				double dt=(l[i]+r[i])*t[i]*PI/180/2/cl;
				th+=dt;
				x=cx+cl*cos(th-PI/2);
				y=cy+cl*sin(th-PI/2);
			}
			if(ABS(l[i])>ABS(r[i])){
				double cl=2.0*b*r[i]/(l[i]-r[i])+b;
				double cx=x+cl*cos(th-PI/2);
				double cy=y+cl*sin(th-PI/2);
				double dt=(l[i]+r[i])*t[i]*PI/180/2/cl;
				th-=dt;
				x=cx+cl*cos(th+PI/2);
				y=cy+cl*sin(th+PI/2);
			}
		//	printf("%f\n",th);
		}
		printf("%f\n%f\n",x,y);
	}
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    string  a,b;
    cin >> a >> b;
    if ((int)a[0] < (int)b[0]) {
        cout << "<" << endl;
    }else if((int)a[0] > (int)b[0]){
        cout << ">" << endl;
    }else{
        cout << "=" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
flag = 0
for cake in range(n//4 + 1):
    for donuts in range(n//7 + 1):
        if cake*4 + donuts*7 == n:
            flag = 1
            break
    if flag == 1:
        break
if flag == 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 2940
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define Icin(s) ll (s);cin>>(s);
#define Scin(s) ll (s);cin>>(s);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD=1e9+7;
//ここから
VV dp;
VV reg;
ll res=1;
int main() {
    int n;
    cin>>n;
    V A(n),B(n),C(n);
    rep(i,n)cin>>A[i];
    rep(i,n)cin>>B[i];
    rep(i,n)cin>>C[i];
    V regB(n);
    sort(all(A));
    sort(all(B));
    sort(all(C));
    rep(i,n)regB[i]=lower_bound(all(A),B[i])-A.begin();
    rep3(i,1,n)regB[i]+=regB[i-1];
 //   rep(i,n)cout<<regB[i]<<" ";
   // cout<<endl;
    ll res=0;
    rep(i,n){
        int k=lower_bound(all(B),C[i])-B.begin();
        if(k==0)continue;
        res+=regB[k-1];
        
     //   cout<<k-1<<" "<<i<<" "<<regB[k-1]<<endl;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3328
import sys

input=sys.stdin.readline

N,M=map(int,input().split())
h=list(map(int,input().split()))
edge=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

ans=0
for i in range(0,N):
    m=h[i]
    if edge[i]:
        data=[h[j] for j in edge[i]]
        M=max(data)
        if m>M:
            ans+=1
    else:
        ans+=1

print(ans)


Measured memory_bytes: 92656
#include <stdio.h>
#define MAX 100000

int A[MAX];

int partition(int p,int r){
  int x,i,j,tmp;

  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      tmp=A[j];
      A[j]=A[i];
      A[i]=tmp;
    }
  }
  tmp=A[r];
  A[r]=A[i+1];
  A[i+1]=tmp;

  return i+1;
}

int main(){
  int n,i,j;

  scanf("%d",&n);

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

  j=partition(0,n-1);


  for(i=0;i<n;i++){
    if(i) printf(" ");
    if(i==j)printf("[");
    printf("%d",A[i]);
    if(i==j)printf("]");
  }
  printf("\n");

  return 0;
}
	


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

int main(){
  int n;
  cin >> n;
  int v1[n/2],v2[n/2],i,c;
  vector<int> c1(100000),c2(100000);
  for(i=0;i<n;i++){
    if(i%2==0){
      cin >> v1[i/2];
      c1[v1[i/2]]++;
    }else{
      cin >> v2[(i-1)/2];
      c2[v2[(i-1)/2]]++;
    }
  }
  vector<int>::iterator iter1 = std::max_element(c1.begin(), c1.end());
  vector<int>::iterator iter2 = std::max_element(c2.begin(), c2.end());
  int max1 = std::distance(c1.begin(), iter1);
  int max2 = std::distance(c2.begin(), iter2);
  if(max1!=max2){
    int j;
    for(j=0;j<n;j++){
      if(j%2==0){
        if(v1[j/2]!=max1){
          c++;
        }
      }else{
        if(v2[(j-1)/2]!=max2){
          c++;
        }
      }
    }
    cout << c << endl;
  }else{
    int co1=0,co2=0;
    c1[max1]=0;
    iter1 = std::max_element(c1.begin(), c1.end());
    int max3 = std::distance(c1.begin(), iter1);
    int j;
    for(j=0;j<n;j++){
      if(j%2==0){
        if(v1[j/2]!=max3){
          co1++;
        }
      }else{
        if(v2[(j-1)/2]!=max2){
          co1++;
        }
      }
    }

    c2[max2]=0;
    iter2 = std::max_element(c2.begin(), c2.end());
    int max4 = std::distance(c2.begin(), iter2);
    for(j=0;j<n;j++){
      if(j%2==0){
        if(v1[j/2]!=max1){
          co2++;
        }
      }else{
        if(v2[(j-1)/2]!=max4){
          co2++;
        }
      }
    }
    if(co1>=co2){
      cout << co2 <<endl;
    }else{
      cout << co1 <<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1408
N = int(input())

for i in range(1, 100):
    if N<=26**i:
        ans = ''
        N -= 1
        
        for j in range(i):
            ans += chr(ord('a')+N%26)
            N //= 26
            
        break
    else:
        N -= 26**i

print(ans[::-1])

Measured memory_bytes: 61940
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#define Abs                           \
	ios_base::sync_with_stdio(false); \
	cout.tie(NULL);                   \
	cin.tie(NULL);
#define FOR(i, b, a) for (ll i = b; i < a; i++)
#define FOR1(i, b, a) for (ll i = b; i <= a; i++)
#define FORd(i, b, a) for (ll i = (a)-1; i >= b; i--)
const double PI = acos(-1);
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define iq(v)   v.resize(unique(v.begin(), v.end()) - v.begin())
#define endl "\n"
#define sz(v) ((ll)((v).size()))
#define fx(n)           fixed << setprecision(n)
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
const int mod = 1e9 + 7;
int main()
{
	Abs;
	ll n, q, s = 0;
	cin >> n;
	map<ll, ll> m;
	FOR(i, 0, n)
	{
		ll x;
		cin >> x;
		s += x;
		m[x]++;
	}
	cin >> q;
	while (q--)
	{
		ll b, c;
		cin >> b >> c;
		if (m.find(b) != m.end())
		{
			ll k = m[b];
			s -= (b * k);
			s += (k * c);
			if (m.find(c) == m.end())
				m[c] = k;
			else
				m[c] += k;
			m.erase(b);
		}
		cout << s << endl;
	}
}

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

using namespace std;
typedef long long ll;
typedef pair < int, int > P;

const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;

int main() {
  ll n, k;
  cin >> n >> k;
  ll N = n;
  ll K = k;
  ll a[n];
  ll sorted[n], sorted2[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sorted[i] = sorted2[i] = a[i];
  }
  ll left = -1000000000000000001;
  ll right = 1000000000000000001;
  sort(sorted, sorted + n);
  sort(sorted2, sorted2 + n, std::greater < > ());
  while(right - left > 1) {
  ll mid = (right + left) / 2;
    ll totalCnt = 0;
    for(ll i = 0;i < N;++i) {
    ll item = sorted[i];
      if(item < 0) {
ll leftIdx = -1;
        ll rightIdx = N - i - 1;
        while(rightIdx - leftIdx > 1) {
ll midIdx = (rightIdx + leftIdx) / 2;
          if(sorted2[midIdx] * item<= mid) leftIdx = midIdx;
          else rightIdx = midIdx;
        }
        totalCnt += leftIdx + 1;
      }else {
      ll leftIdx = i;
        ll rightIdx = N;
        while(rightIdx - leftIdx > 1) {
ll midIdx = (rightIdx + leftIdx) / 2;
          if(sorted[midIdx] * item <= mid) leftIdx = midIdx;
          else rightIdx = midIdx;
        }
        totalCnt += leftIdx - i;
      }
    }
    if(totalCnt < K) left = mid;
    else right = mid;
  }
  cout << right << std::endl;
}

Measured memory_bytes: 4992
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
for(var i=0;i<Arr.length;i++){
var v=Arr[i];
var sum=0;
if(v==0)break;
v=1000-v;
if(v>=500){sum++;v=v-500;}
sum+=Math.floor(v/100);
v=v%100;
if(v>=50){sum++;v=v-50;}
sum+=Math.floor(v/10);
v=v%10;
if(v>=5){sum++;v=v-5;}
console.log(sum+v);
}

Measured memory_bytes: 7644
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().strip()
INF = 10**18
di = [1, 0, -1, 0]
dj = [0, 1, 0, -1]

def main():
    H, W, K = map(int, input().split())
    x1, y1, x2, y2 = map(int, input().split())
    x1, y1, x2, y2 = x1 - 1, y1 - 1, x2 - 1, y2 - 1
    C = [input() for _ in range(H)]

    """
    まずはKの制約がない時を考える。単純なBFSでは明らかに間に合わないが、
    「位置」と「向き」の直積を頂点として扱うのがポイント。
    隣の頂点に同じ向きで移動するのにコスト0、同じ頂点で向きを変えるのにコスト1かかるとして
    辺を張れば、ダイクストラにより計算量O((4HW + 4HW) * log(4HW))で解ける。

    ではKの制約がある時はどうするかというと、コストを(従来のコスト, 直線移動距離)のペアに変更する。
    直線移動距離がKを超えたら従来のコストを１つ繰り上げる。
    このペアによるコストは辞書式順序により全順序構造を持つので同様にダイクストラで扱える。

    さらに実はこのコストはペアで扱わないにすることもでき、
        直線移動のコスト＝1/K
        方向転換のコスト＝切り上げ
    と定めると整数部分が本問で求めるコストになっている。
    少数は少し怖いので実際にはK倍して扱う。
    """

    # 向き付き2次元配列を１次元に押し込める補助関数を用意
    def toId(i, j, v):
        return (i * W + j) * 4 + v

    dist = [INF] * (H * W * 4)
    q = []

    # ダイクストラ更新１回分の補助関数
    def push(i, j, v, x):
        id = toId(i, j, v)
        if dist[id] <= x: return
        dist[id] = x
        heappush(q, (x, id))

    # ダイクストラ
    for v in range(4): push(x1, y1, v, 0)
    while q:
        x, id = heappop(q)
        if dist[id] != x: continue # 途中で値が書き換わっていたら伝搬は無効化する！
        i, j, v = (id // 4) // W, (id // 4) % W, id % 4
        # 方向転換
        push(i, j, (v + 1) % 4, (x + K - 1) // K * K)
        push(i, j, (v + 2) % 4, (x + K - 1) // K * K)
        push(i, j, (v + 3) % 4, (x + K - 1) // K * K)
        # 直進
        ni, nj = i + di[v], j + dj[v]
        if 0 <= ni < H and 0 <= nj < W and C[ni][nj] == '.':
            push(ni, nj, v, x + 1)
    ans = min(dist[toId(x2, y2, v)] for v in range(4))
    if ans == INF: print(-1)
    else: print((ans + K - 1) // K)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 223880
n=int(input())
a=sorted(list(map(int,input().split())))
m=a[n-1]
a=a[:n]
h=m/2
d=abs(a[0]-h)
x=0
for i in range(1,n-1):
  if abs(a[i]-h)<d:
    x=i
    d=abs(a[i]-h)
print(m,a[x])

Measured memory_bytes: 14428
S=gets.chomp

i = S.length-1
while 0 <= i
    if S[i-5..i] == 'eraser'
        i -= 6
    elsif S[i-6..i] == 'dreamer'
        i -= 7
    elsif S[i-4..i] == 'erase'
        i -= 5
    elsif S[i-4..i] == 'dream'
        i -= 5
    else
        puts 'NO'
        exit 0
    end
end

puts 'YES'

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))





ll d = 1e9 + 7;
ll gyaku(ll num){
   ll jou = d - 2;
   ll bai = num;
   ll ret = 1;
   while (jou > 0){
       if (jou % 2 == 1){
           ret *= bai;
           ret %= d;
       }
       bai *= bai;
       bai %= d;
       jou /= 2;
   }
   return ret;
}




int main(void){
    ll lim = 1e5+10;
    vector <ll> kaijou = {1};
    for(int i=1; i<lim; i++){
        kaijou.push_back(kaijou[i-1] * i % d);
    }
    vector <ll> kaijou_gyaku;
    for(int i=0; i<lim; i++){
        kaijou_gyaku.push_back(gyaku(kaijou[i]));
    }

    ll n; cin >> n;
    vector <ll> zahyos;
    REP(i, n){
        ll z; cin >> z;
        zahyos.push_back(z);
    }
    vector <ll> kaisas;
    REP(i, n-1){
        kaisas.push_back(zahyos[i+1] -zahyos[i]);
    }
    dumparr(kaijou)
    dumparr(kaisas)
    ll ans = 0;
    ll base = 0;
    for(int i=1; i<n; i++){
        base = base*i + kaijou[i-1];
        base %= d;
        ll add = base;
        add *= kaijou[n-1];
        add %= d;
        add *= kaijou_gyaku[i];
        add %= d;
        add *= kaisas[i-1];
        add %= d;

        ans += add;
        ans %= d;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4084
from collections import defaultdict
from bisect import bisect_right
s = input()
t = input()
ss = set(s)
tt = set(t)
count = 0
for i in tt:
  if not i in ss:
    print(-1)
    break
else:
  dic = defaultdict(list)
  for i in range(len(s)):
    dic[s[i]] += [i+1]
  ans = 0
  for i in range(len(t)):
    x = ans%len(s)
    if dic[t[i]][-1]<=x:
      ans = ans - x + len(s) + dic[t[i]][0]
    else:
      ind = bisect_right(dic[t[i]], x)
      ans = ans - x + dic[t[i]][ind]
  print(ans)

Measured memory_bytes: 7924
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, C, K;
  cin >> N >> C >> K;
  vector<int>A(N);
  for (int i = 0; i < N; i ++) cin >> A[i];
  sort(A.begin(), A.end());
  int ans = 1;
  int now = 0;
  int ps = 1;
  for (int i = 1; i < N; i ++) {
    if (ps < C && (A[i] - A[now]) <= K) ps ++;
    else {
      now = i;
      ans ++;
      ps = 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
	
	int a, o;
	
	for(a = 1; a <= 9; a++){
		
		for(o = 1; o <= 9; o++){
			
			printf("%dx%d=%d\n", a, o, a*o);
			
		}
		
	}
	
    return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int calc(const vector<int>&v,int a,int b,int c){
  int ret=0;
  const int n=v.size();
  priority_queue<int>q;
  auto add=[&](int e){ret+=e,q.push(-e);};
  for(int i=0;i<a;i++)add(v[i]);
  for(int i=0;i<b;i++)add(v[n-i-1]);
  for(int i=0;i<c&&q.size()&&q.top()>0;i++){
    ret+=q.top();q.pop();
  }
  return ret;
}
int main(){
  int N,K;
  cin>>N>>K;
  vector<int>v(N);
  for(int& x:v)cin>>x;
  
  int n=min(N,K);
  int ans=-2e9;
  for(int i=0;i<=n;i++){
    for(int j=0;i+j<=n;j++){
      int k=K-i-j;
      ans=max(ans,calc(v,i,j,k));
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int ans = 0;
  for (auto &e : a)
  {
    cin >> e;
    ans += e;
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    if (a[i] >= (double)(ans / (4.0 * m)))
    {
      cnt++;
    }
  }
  if (cnt >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

int main() {
	int n;
	cin >> n;
	int res = 0;
	for(int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if(a % 2 == 1 && i % 2 == 0)
			res++;
	}
	cout << res <<  '\n';
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> ss(n);
    for(int i=0; i<n; ++i){
        cin >> ss[i];
    }
    int sum=accumulate(ss.begin(), ss.end(), 0);
    if(sum%10==0){
        sort(ss.begin(), ss.end());
        int sub=sum;
        for(int i=0; i<n; ++i){
            if(ss[i]%10!=0){
                sub=ss[i];
                break;
            }
        }
        sum-=sub;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using tpl = tuple<char, int>;
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
int A[200100];
int B[200100];
int B2[200100];

int main(){

    fastStream();

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

    int ans = 0;
    for(int k = 0; k < 29; k++){
        const int p = (1 << k);
        for(int i = 0; i < N; i++) B2[i] = B[i] % (p * 2);
        sort(B2, B2 + N);
        ll cnt = 0;
        for(int i = 0; i < N; i++){
            const int a = A[i] % (p * 2);
            // [p - a, 2 * p - a), [3 * p - a, 4 * p - a)
            {
                int pos1 = lower_bound(B2, B2 + N, max(p - a, 0)) - B2;
                int pos2 = lower_bound(B2, B2 + N, 2*p - a) - B2;
                cnt += pos2 - pos1;
            }
            {
                int pos1 = lower_bound(B2, B2 + N, 3*p - a) - B2;
                int pos2 = lower_bound(B2, B2 + N, 4*p - a) - B2;
                cnt += pos2 - pos1;
            }
        }
        if(cnt % 2) ans |= (1 << k);
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    unordered_map<long long, long long> mp;
    for(int i=0; i<n; i++){
        cin >> v[i];
        mp[v[i]]++;
    }
    long long sum = 0;
    for(auto it = mp.begin(); it!=mp.end(); it++)
        sum += (it->second*(it->second-1))/2;
    for(int i=0; i<n; i++){
        long long temp = sum;
        long long occur = mp[v[i]];
        temp -= (occur*(occur-1))/2;
        occur--;
        temp += (occur*(occur-1))/2;
        cout << temp << endl;
    }
    return 0;
}

Measured memory_bytes: 8392
#include <iostream>
#include <algorithm>
#include<vector>
#include<climits>
#include<set>
#include<string>
#include<map>
#define ll long long
#define fr(j,p) for (int i=j; i<p ;i++)
#define fastScan ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define inp(x,n) fr(0,n) cin>>x[i];
#define out(x,n) fr(0,n) cout<<x[i]<<" ";
#define test int t; cin>>t; while(t--)
#define YESF if(flag==0)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define yesf if(flag==0)cout<<"Yes"<<endl; else cout<<"No"<<endl; 
const long long md=1e9+7;
using namespace std;
int main()
{
  fastScan
  //test
  {
    ll n ;
    cin>>n;

    ll ans=0;


    ll t500 = n/500;

   // cout<<t500<<endl;
    ans  = ans + (1000*t500);
    
    n = n%500;

    ll t5 = n/5;
    ans+= 5*(t5);


    cout<<ans<<endl;
    

   
      
  } 
     return 0;
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<string.h>

#define F first
#define S second

using namespace std;

int map[100][100];
pair<int,int> st[100 * 100];
int mx[] = { 0,1,0,-1 };
int my[] = { 1,0,-1,0 };
int move(int, int, int);
int n, m,anss=1;

int main() {
	
	while (scanf("%d%d", &m, &n), m != 0 && n != 0) {
		memset(map, 0, sizeof(map));
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				scanf("%d", &map[i][j]);
				if (map[i][j] == 1) st[cnt++] = make_pair(i, j);
			}
		}

		int ans = 0;
		for (int i = 0; i < cnt; i++) {
			map[st[i].F][st[i].S] = 0;
			ans = max(ans, move(st[i].first, st[i].second, 1));
			map[st[i].F][st[i].S] = 1;
		}
		printf("%d\n", ans);
		ans = 0; anss = 0;
	}
}

int move(int i, int j, int cnt) {

	anss = max(anss, cnt);

	for (int l = 0; l < 4; l++) {
		int MX = mx[l];
		int MY = my[l];
		if (map[i + MX][j + MY] == 1) {
			map[i + MX][j + MY] = 0;
			move(i + MX, j + MY, cnt + 1);
			map[i + MX][j + MY] = 1;
		}
	}
	return anss;
}



Measured memory_bytes: 2748
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define ll long long 
ll ans[3][121340],visited[3][121340];
ll mini(ll a,ll b,ll c)
{
	ll z=a;
	z=min(z,b);
	z=min(z,c);
	return z;
}

int main()
{
	ll n=1,a,b,c;
    string ans;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
char ch[1314520];
int main(){
	scanf("%s",ch);
	int a=0;
	for(int i=0;i<strlen(ch);i++){
		if(ch[i]=='C'&&!a){
			a++;
			continue;
		}
		if(ch[i]=='F'&&a==1){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>

#define For(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  For(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define chk(a) rep(i, a.size()) cout << a[i] << " "
#define SORT(c) sort((c).begin(),(c).end())
#define ll long long
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)


using namespace std;
typedef pair<int, int> pii;
#define WARU 1000000007;

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

int main(void) {
	ll result = 1;
	int n;
	cin >> n;
	vector<ll> vt(n);
	vector<ll> v(n);
	vector<ll> v2(n);
	rep(i, n)
		v[i] = -1;
	vector<ll> va(n);
	rep(i, n)
		cin >> vt[i];
	rep(i, n)
		cin >> va[i];

	if (*max_element(vt.begin(), vt.end()) != *max_element(va.begin(), va.end())) {
		cout << 0 << endl;
		return 0;
	}
	ll prev = 0;
	rep(i, n) {
		if (vt[i] != prev) {
			v[i] = 0;
			v2[i] = vt[i];
			prev = vt[i];
		}
		else {
			v[i] = vt[i];
		}
	}
	//rep(i, n) {
	//	cout << v[i] << " ";
	//}
	//cout << endl;

	prev = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (va[i] != prev) {
			if (v[i] != 0 && v[i] < va[i]) {
				cout << 0 << endl;
				return 0;
			}
			if (v2[i] != 0 && v2[i] != va[i]) {
				cout << 0 << endl;
				return 0;
			}
			v[i] = 0;
			prev = va[i];
		}
		else {
			v[i] = min(v[i], va[i]);
		}
	}

	//rep(i, n) {
	//	cout << v[i] << " ";
	//}
	//cout << endl;

	rep(i, n) {
		if (v[i] == 0) {
			continue;
		}
		result = (result * v[i]) % WARU;
	}

	cout << result << endl;



	return 0;
}


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


using namespace std;


using ll = long long;


template<long long M>
class modint {
    public:
        long long a;
        modint(const long long x = 0LL) : a((x % M + M) % M) {}
        long long &value() { return a; }
        modint operator+(const modint rhs) const {
            return modint(*this) += rhs;
        }
        modint operator-(const modint rhs) const {
            return modint(*this) -= rhs;
        }
        modint operator*(const modint rhs) const {
            return modint(*this) *= rhs;
        }
        modint operator/(const modint rhs) const {
            return modint(*this) /= rhs;
        }
        modint &operator+=(const modint rhs) {
            a += rhs.a;
            if (a >= M) {
                a -= M;
            }
            return *this;
        }
        modint &operator-=(const modint rhs) {
            if (a < rhs.a) {
                a += M;
            }
            a -= rhs.a;
            return *this;
        }
        modint &operator*=(const modint rhs) {
            a = a * rhs.a % M;
            return *this;
        }
        modint pow(long long n) const {
            modint ret(1);
            modint x = *this;
            while (n) {
                if ((n & 1) == 1) {
                    ret *= x;
                }
                n >>= 1;
                x *= x;
            }
            return ret;
        }
        modint inv() const {
            return pow(M - 2);
        }
        modint &operator/=(const modint rhs) {
            return *this *= rhs.inv();
        }
};

const long long M = 1000000007;

using mint = modint<M>;


int main(void) {
    ll N, K;
    cin >> N >> K;

    vector<mint> d(K + 1, mint(0));
    for (ll i = K; i >= 1; i--) {
        d[i] += mint(K / i).pow(N);
        for (ll j = i + i; j <= K; j += i) {
            d[i] -= d[j];
        }
    }
    mint ans = 0;
    for (ll i = 1; i <= K; i++) {
        ans += d[i] * i;
    }
    cout << ans.a << endl;
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=1,tmp=0;;i++){
        tmp+=a;
        if(i%7==0)
            tmp+=b;
        if(tmp>=c){
            cout<<i<<endl;
            return 0;
        }
    }
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
ll n,m,s,c,x,y,z,countx,county,countz;

x=-1;
y=-1;
z=-1;
countx=0;
county=0;
countz=0; 

cin >> n >> m;

for(ll i=0 ; i<m ; i++){

  cin >> s >> c;
    
  if(s==1){
     countx+=1;
    if(countx==1){
      x=x+1;
      x+=c; 
      }else{
        if(c!=x){
          cout << "-1" << endl;
          return 0;
        }
      }
  }
  
  if(s==2){
     county+=1;
    if(county==1){
      y=y+1;
      y+=c; 
      }else{
        if(c!=y){
          cout << "-1" << endl;
          return 0;
        }
      }
  }
    
  if(s==3){
     countz+=1;
    if(countz==1){
      z=z+1;
      z+=c; 
      }else{
        if(c!=z){
          cout << "-1" << endl;
          return 0;
        }
      }
  }
}



if(n==1){
  if(x==-1){
    x=0;
    cout << x << endl;
    return 0;
  }else{
  cout << x << endl;
  return 0;
  }
 }

if(n==2 && ((x*10+y)!=0) && x!=0 ){
  if(x==-1){
    x=1;
    if(y==-1){
      y=0;
    }
    cout << x*10+y << endl;
    return 0;
  }else{
    if(y==-1){
      y=0;
    }
  cout << x*10+y << endl;
  return 0;
  }
}
  

if(n==3 && ((x*100+y*10+z)!=0) && x!=0){
  if(x==-1){
    x=1;
    if(y==-1){
      y=0;
    }
     if(z==-1){
      z=0;
    }
    cout << x*100+y*10+z <<endl;
    return 0;
    }else{
      if(y==-1){
      y=0;
    }
     if(z==-1){
      z=0;
    }
  cout << x*100+y*10+z <<endl;
  return 0;
  } 
}

cout << "-1" << endl;

}






Measured memory_bytes: 256
import sys
input=sys.stdin.readline

n,k=map(int,input().split())
snuke=[0]*n
for _ in range(k):
    d=int(input().rstrip())
    a=[int(i) for i in input().split()]
    for i in a:
        snuke[i-1]+=1
ans=0
for i in snuke:
    if i==0:
        ans+=1
print(ans)

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

int main(){
	string s; cin>>s;
	rep(i,s.size()){
		if(s[i]=='1') cout << 9;
		else cout << 1;
	}
	cout << endl;	
}


Measured memory_bytes: 256
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare |> List.rev

let rec loop sum acc = function
  | 0 -> sum
  | 1 -> sum + (List.hd acc)
  | i -> loop (sum + (List.hd acc) * 2) (List.tl acc) (i - 2)

let () = Printf.printf "%d\n" @@ loop (List.hd a) (List.tl a) (n - 2)

Measured memory_bytes: 31180
import sys


def B(T):
    global S, Z, D
    _last = [0] * Z
    cnt = 0
    for d in range(1, D + 1):
        t = T[d]
        _last[t] = d
        up = S[d][t]
        down = sum(C[i] * (d - _last[i]) for i in range(Z))
        cnt += up - down
    return cnt


def checkScore(r):
    global D, last
    L = last[r]
    rst = 0
    for d in range(1, D + 1):
        down = C[r] * (d - L[d])
        up = S[d][r] if L[d] == d else 0
        rst += up - down
    return rst


Z = 26
D = int(input())
C = list(map(int, input().split()))
S = [tuple([0] * Z)]
S += [tuple(map(int, input().split())) for _ in range(D)]
T = [None] + [int(input()) - 1 for _ in range(D)]

M = int(input())
Q = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]


last = [[0] * (D + 1) for _ in range(Z)]
V = [0] * Z
for d in range(1, D + 1):
    t = T[d]
    for p in range(Z):
        last[p][d] = last[p][d - 1]
    last[t][d] = d
for p in range(Z):
    V[p] = checkScore(p)

score = sum(V)

for d, q in Q:
    d += 1

    p = T[d]
    T[d] = q

    for r, L in ((p, last[p]), (q, last[q])):
        for e in range(1, D + 1):
            L[e] = L[e - 1] if r != T[e] else e

    score -= V[p] + V[q]
    V[p] = checkScore(p)
    V[q] = checkScore(q)
    score += V[p] + V[q]
    # # if M > 10 ** 4:
    #     print(score)
    # else:
    #     print(B(T))
    print(score)


Measured memory_bytes: 94820
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define sll            set<ll int>
#define msll        multiset<ll int>
#define io    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;


int main()
{
    io
    ll i,j,a,b,c;
    cin>>a>>b>>c;
    cout<<((a==b and b==c)?"Yes":"No");






    return 0;
}

Measured memory_bytes: 256
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
    int n;
    int a[100];

    cin >> n;
    rep(i, n) cin >> a[i];

    sort(a, a+n, greater<int>());

    int alice = 0, bob = 0;
    rep(i, n) {
        if( i%2 == 0 ) alice += a[i];
        else bob += a[i];
    }

    cout << alice - bob << endl;
}


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

int main(){
  int n,i,cnt=0;
  vector<int> p(n);
  vector<int> num(3);
  cin >> n;

  for(i=0;i<n;i++)
  cin >> p.at(i);

  for(i=1;i<n-1;i++){
    num.at(0) = p.at(i-1);
    num.at(1) = p.at(i);
    num.at(2) = p.at(i+1);
    sort(num.begin(),num.end());
    if(p.at(i)==num.at(1))
    cnt++;
  }
  cout << cnt << endl;
}

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

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"

#define ll long long
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"

#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll, ll> pll;
typedef map< ll, ll> mll;

#define pie_value 3.14159265358979323846

int main() {

	// Use ctrl+shift+b ( second option )
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
#endif

	ll n;
	cin >> n;


	string s;
	cin >> s;

	ll no_red = 0;
	for (ll i = 0; i < n; i++) {
		if (s[i] == 'R')
			no_red++;
	}

	ll no_w = 0;
	for (ll i = 0; i < no_red; i++) {
		if (s[i] == 'W')
			no_w++;
	}

	cout << no_w << nl;


	return 0;
}


Measured memory_bytes: 3740
def main():
    N = int(input())
    P = [int(input()) - 1 for _ in range(N)]
    indices = [0] * N
    for i, p in enumerate(P):
        indices[p] = i
    max_cnt = 0  # indexの値が単調増加になるような最長の列長
    cur_index, cur_cnt = -1, 0
    for p in range(N):
        index = indices[p]
        if index > cur_index:
            cur_cnt += 1
        else:
            max_cnt = max(max_cnt, cur_cnt)
            cur_cnt = 1
        cur_index = index
    max_cnt = max(max_cnt, cur_cnt)
    print(N - max_cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 24940
//Jai Shree Krishna
#include <bits/stdc++.h>
using namespace std;

deque<int>q1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    for (int i =0 ; i<n; i+=1) {
        int x;
        cin>>x;
        if(i%2==0)
        {
            q1.push_back(x);
        }
        else{
            q1.push_front(x);
        }
    }
    if(n%2==0){
    for(int i = 0 ;i<q1.size();i+=1)
    {
        cout<<q1[i]<<" ";
    }
    }
    else{
        reverse(q1.begin(), q1.end());
        for(int i = 0 ;i<q1.size();i+=1)
        {
            cout<<q1[i]<<" ";
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

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

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	string s;
	cin >> s;
	map<char,int> m;

	rep(i,0,sz(s))m[s[i]]++;

	for(auto ite:m){
        if(ite.sd > 1){
            no;
            ret 0;
        }
	}
	yes;
	return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
char s[310][310];
bool check(int r, int c) {
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) { // check s[r+i][c+j] is symmetric
			int y1 = (r + i) % n;
			int x1 = (c + j) % n;
			int y2 = (r + j) % n;
			int x2 = (c + i) % n;
			if(s[y1][x1] != s[y2][x2]) return 0;
		}
	}
	return 1;
}
int main() {
	scanf("%d", &n);
	for(int i=0; i<n; i++)
		scanf("%s", s[i]);
	int cnt = 0;
	for(int i=0; i<n; i++) { // left top is (0, i)
		if(check(0, i)) cnt += n - i;
	}
	for(int i=1; i<n; i++) { // left top is (i, 0)
		if(check(i, 0)) cnt += n - i;
	}
	printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 384
import collections
n = int(input())
v = list(map(int, input().split()))
v1 = v[::2]
v2 = v[1::2]
c1 = collections.Counter(v1).most_common()
c2 = collections.Counter(v2).most_common()

if c1[0][0] != c2[0][0]:
  print(len(v1)-c1[0][1] + len(v2)-c2[0][1])
else:
  if len(c1) == len(c2) == 1:
    print(n // 2)
  elif len(c1) == 1:
    print(len(v2)-c2[1][1])
  elif len(c2) == 1:
    print(len(v1)-c1[1][1])
  else:
    print(min(len(v1)-c1[0][1]+len(v2)-c2[1][1], len(v1)-c1[1][1]+len(v2)-c2[0][1]))

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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int res = 0;
    for (int i = 0; i < N; i++) {
        int cnt = 0;
        for (int j = i; j < N; j++) {
            char s = S[j];
            if (s == 'A' || s == 'C' || s == 'G' || s == 'T') {
                cnt++;
            } else {
                break;
            }
        }
        res = max(res, cnt);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
using namespace std;
bool IsKaiBun(string &S,int start,int end)
{
	int i=start-1;
	int j=end-1;
	while (i<j && i!=j){
		if (S[i]==S[j]){
			i++;
			j--;
			continue;
		}
		return false;
	}
	return true;
}
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	int N=S.size();
	if (IsKaiBun(S,1,N) && IsKaiBun(S,1,(N-1)/2) && IsKaiBun(S,(N+3)/2,N)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
  string s; cin >> s;
  int K; cin >> K;

  vector<string> v;

  for (int i = 0; i < s.size(); ++i) {
    for (int j = 1; j < K+1 and i+j <= s.size(); ++j) {
      // cout << s.substr(i, j) << endl;
      v.push_back(s.substr(i, j));
    }
  }

  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  cout << v[K-1] << endl;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int a,b,c ,k;
 cin>>a>>b>>c>>k;
 int count=0;
 if(k>a)
 {
 	k=k-a;
 	count=count+a*1;
 }else
 {
 	cout<<k<<endl;
 	return 0;
 }
 if(k>b)
 {
 	k=k-b;
 	count=count+b*0;
 }else
 {
 	cout<<count+0*k<<endl;
 	return 0 ;
 }
 if(k<=c)
 {
 
 	cout<<count-k<<endl;
 }
 
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	int q;
	cin >> q;
	rep(u, q){
		string S, L;
		cin >> S >> L;
		int dp[1002][1002];
		rep(i, S.size())
			rep(j, L.size()){
				if(S[i] == L[j]){
					dp[i+1][j+1] = dp[i][j]+1;
				}else{
					dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
				}
			}
			FIN(dp[S.size()][L.size()]);
	}

	return 0;
}

Measured memory_bytes: 5124