akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(){
    string S;
    int i, count = 0, flag = 0;
    string ans = "AC";
    cin >> S;
    int len = S.size();
    if(S[0]!='A'){
        ans = "WA";
    }
    for(i=1; i<=len; i++){
        if(isupper(S[i])){
            if(S[i]!='C' || i==1 || i==len-1){
                ans = "WA";
            }
            count++;
        }
    }
    if(count!=1){
        ans="WA";
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 2019;

int main()
{
    int l, r;
    cin >> l >> r;
    ++ r;

    int ans = INT_MAX;
    if(r - l >= MOD){
        ans = 0;
    }
    else{
        for(int i=l; i<r; ++i){
            for(int j=i+1; j<r; ++j){
                int tmp = (i % MOD) * (j % MOD) % MOD;
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  ll n, k;
  cin >> n >> k;
  ll x = abs(n - k);
  cout << min({n % k, (n + k) % k, (k - (n % k)) % k}) << endl;
  
  return 0;
}

Measured memory_bytes: 256
while 1:
    w,h=map(int,input().split())
    if w==h==0:break
    maze,wall=[[float("inf") for i in range(w)] for j in range(h)],[]
    maze[0][0]=1
    for i in range(2*h-1):wall.append(list(map(int,input().split())))
    flag=0
    step=0
    while 1:
        if flag==1:break
        flag=1
        step+=1
        for i in range(w):
            for j in range(h):
                if maze[j][i]==step:
                    if i-1>=0 and wall[j*2][i-1]==0 and maze[j][i-1]>step+1:
                        maze[j][i-1],flag=step+1,0
                    if i+1<w and wall[j*2][i]==0 and maze[j][i+1]>step+1:
                        maze[j][i+1],flag=step+1,0
                    if j-1>=0 and wall[j*2-1][i]==0 and maze[j-1][i]>step+1:
                        maze[j-1][i],flag=step+1,0
                    if j+1<h and wall[j*2+1][i]==0 and maze[j+1][i]>step+1:
                        maze[j+1][i],flag=step+1,0
        if maze[-1][-1]!=float("inf"):break
    if maze[-1][-1]==float("inf"):print(0)
    else:print(maze[-1][-1])


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

typedef long long ll;

ll H, W;
const ll INF = 1ll << 60;

ll N;
vector<vector<ll>> Cap;
// S, T, row 0, ..., row H-1, column 0, ..., column W-1
const ll Src = 0, Tgt = 1;
ll row(ll y) { return 2 + y; }
ll column(ll x) { return 2 + H + x; }
typedef pair<ll, ll> VCap;
ll R;

int main() {
  cin >> H >> W;
  N = 2 + H + W;
  Cap.resize(N);
  for (auto &cap : Cap) cap.resize(N);
  for (ll y = 0; y < H; ++y)
    for (ll x = 0; x < W; ++x) {
      char c;
      cin >> c;
      if (c == 'S')
        Cap[Src][row(y)] = Cap[Src][column(x)] = INF;
      else if (c == 'T')
        Cap[row(y)][Tgt] = Cap[column(x)][Tgt] = INF;
      else if (c == 'o')
        Cap[row(y)][column(x)] = Cap[column(x)][row(y)] = 1;
    }
  while (true) {
    ll flow = -1;
    vector<ll> parent;
    {
      queue<VCap> que;
      vector<bool> visited;
      visited.resize(N);
      parent.resize(N, -1);
      que.push(VCap(Src, INF));
      visited[Src] = true;
      while (!que.empty()) {
        ll v, cap;
        tie(v, cap) = que.front();
        que.pop();
        if (v == Tgt) {
          flow = cap;
          break;
        }
        for (ll w = 0; w < N; ++w) {
          if (!visited[w] && Cap[v][w] > 0) {
            que.push(VCap(w, min(cap, Cap[v][w])));
            parent[w] = v;
            visited[w] = true;
          }
        }
      }
    }
    if (flow < 0) break;
    R += flow;
    for (ll v = Tgt; v != Src; v = parent[v]) {
      ll u = parent[v];
      Cap[u][v] -= flow;
      Cap[v][u] += flow;
    }
  }
  cout << (R >= INF ? -1 : R) << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<iomanip>
#include<stdlib.h>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<algorithm>
#include<complex>
using namespace std;
#define loop(i,l,r) for(int (i)=(int)(l);(i)<(int)(r);(i)++)
#define rloop(i,l,r) for(int (i)=(int)(l);(i)>(int)(r);(i)--)
#define rep(i,n) loop(i,0,n)
#define rrep(i,n) rloop(i,n-1,-1)
#define INF 0x3f3f3f3f
#define mod 1000000007LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef complex<double> C;
 
int main(){
	string s;
	cin>>s;
	int K;
	cin>>K;
	rep(i,s.size()){
			if(s[i]!='a'&&('z'-s[i])<K){
					K=K-('z'-s[i])-1;
					s[i]='a';
			}
	}
	if(K>0)s[s.size()-1]+=K%26;
	cout<<s<<endl;
}
		

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i += 2) {
    if (a[i] % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n,d;
    cin >> n >> d;
    int k = 2*d+1;
    int ans = 0;
    while(n > 0){
        n -= k;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>
#define N 10000

int main(){
  char c[N+1];
  int a, b, i;

  while(scanf("%s",&c) != EOF){
    a = 0; b = 0;
    for(i = 0 ; c[i] != '\0' ; i++){
      if(c[i] == 'J' && c[i+1] == 'O' && c[i+2] == 'I')
	a = a++;
      else continue;
    }
    for(i = 0 ; c[i] != '\0' ; i++){
      if(c[i] == 'I' && c[i+1] == 'O' && c[i+2] == 'I')
	b = b++;
      else continue;
    }
    printf("%d\n",a);
    printf("%d\n",b);
  }
  return 0;
}

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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

#define PB(N) push_back(N)

using namespace std;

using Graph = vector<vector<int>>;

int main(){
  char N; cin >> N;
  if('A'<=N&&N<='Z'){
    cout << "A";
  }
  else{
    cout << "a";
  }
  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define ll long long
#define inf 9999999999999999
#define F first
#define S second
#define eb emplace_back
#define mpp make_pair
#define P(x) cout<<__LINE__ <<": "<<#x<<' '<<(x)<<'\n'
#define dbg cout<<__LINE__ <<": 0manush\n"
#define read(x) freopen("input.txt","r",stdin)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi 2*acos(0.0)
#define ee exp(1)
#define mx 100009
#define mod 10000007
using namespace std;
ll dp[mx];
int main(){//read(x);
//fast;
ll r,g,h,i,j,x,t,y,z=0,e,f,a,b,c,d,n,l,k;

    cin>>n>>k;
    ll m[n];
    for(i=0;i<n;i++)cin>>m[i];
    dp[n-1]=0;
    for(i=n-2;i>=0;i--){
        l=inf;
        for(j=i+1;j<=i+k && j<n;j++){
            a=dp[j]+abs(m[i]-m[j]);
            l=min(l,a);
        }
        dp[i]=l;
    }

    cout<<dp[0]<<endl;

}


Measured memory_bytes: 5180
import Foundation
#if os(OSX) || os(iOS)
    import Darwin
#elseif os(Linux)
    import Glibc
#endif
var N = 0, a = 0, b1 = 0, b2 = 0, b4 = 0
withUnsafeMutablePointer(&N){withVaList([COpaquePointer($0)]){vscanf("%d",$0)}}
while N != 0 {
    withUnsafeMutablePointer(&a){withVaList([COpaquePointer($0)]){vscanf("%d",$0)}}
    if a % 4 == 0 {
        b4 += 1
    } else if a % 2 == 0 {
        b2 += 1
    } else {
        b1 += 1
    }
    N -= 1
}
if b2 > 0 {
    b1 += 1
}
print((b1 <= b4 + 1) ? "Yes" : "No")

Measured memory_bytes: 1024
#include <stdio.h>

int const M = 998244353;
int i = 1, n, x, c[7 << 14];

int pow(int a, int b) {
  long long r = 1;
  for(; b; b >>= 1) {
    if(b & 1)
      r = r * a % M;
    a = (long long)a * a % M;
  }
  return r;
}  

int main() {
  scanf("%d%d", &n, &x);
  int r = 0;
  if(x == 0) {
    for(c[x]++; i < n; c[x]++, i++) scanf("%d", &x);
    if(c[0] == 1) {
      r = 1;
      for(i = 1; c[i]; i++) {
        n -= c[i];
        r = (long long) r * pow(c[i - 1], c[i]) % M;
      }
    }
  }
  printf("%d\n", n > 1 ? 0 : r);
  return 0;
}


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

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define w(t) int t;cin>>t;while(t--)



int main(){
	
		fast
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		ll max=0;
		if(a+b+c>=d)
		{
			
				if(a>=d&&d>0)
				{
					cout<<d;
					d=d-a;
                  return 0;
				}
				if(a<d&&d>0)
				{
					max+=a;
					
					d=d-a;
                  d=d-b;
					
				}
				
				if(d>0)
				{	
					max=max+d*(-1);
				}
				cout<<max;

			
		}


	return 0;
}





Measured memory_bytes: 3612
import java.io.*
import java.util.*

fun solve(N: Long, S: String, T: String) {
    (0 until N.toInt()).map { S[it].toString() + T[it].toString() }.joinToString(separator="").let { println(it) }
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val S = sc.next()
    val T = sc.next()
    solve(N, S, T)
}


Measured memory_bytes: 29736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

static class CodeJam
{
    class Edge
    {
        private bool visited = false;
        public long sum = 0;
        public List<Edge> children = new List<Edge>();
        public void Calculate(long cnt)
        {
            sum += cnt;
            visited = true;
            foreach (var child in children)
            {
                if (!child.visited) { child.Calculate(sum); }
            }
            visited = false;
        }
    }

    static IEnumerable<long> Solve(int N, int Q, Edge[] edges, Tuple<int, int>[] tuples)
    {
        foreach (var tuple in tuples)
        {
            edges[tuple.Item1].sum += tuple.Item2;
        }
        edges[0].Calculate(0);
        return edges.Select(edge => edge.sum);
    }

    static void Main(string[] args)
    {
        int[] V1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int N = V1[0], Q = V1[1];
        var edges = new Edge[N];
        for (int i = 0; i < N; ++i) { edges[i] = new Edge(); }
        for (int i = 0; i < N - 1; ++i)
        {
            int[] V2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var a = edges[V2[0] - 1];
            var b = edges[V2[1] - 1];
            a.children.Add(b);
            b.children.Add(a);
        }
        var tuples = new Tuple<int, int>[Q];
        for (int i = 0; i < Q; ++i)
        {
            int[] V2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            tuples[i] = new Tuple<int, int>(V2[0] - 1, V2[1]);
        }
        Console.WriteLine(string.Join(" ", Solve(N, Q, edges, tuples)));
    }
}


Measured memory_bytes: 86408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

int main() {
	ll n;
	cin >> n;
	map<ll,ll> mp;
	ll sum=0;
	rep(i,n){
		ll input;
		cin >> input;
		sum+=input;
		mp[input]++;
	}
	ll q;
	cin >> q;
	vector<ll> ans;
	rep(i,q){
		ll b,c;
		cin >> b >> c;
		sum-=b*mp[b];
		sum+=c*mp[b];
		mp[c]+=mp[b];
		mp[b]=0;
		ans.push_back(sum);
	}
	rep(i,ans.size()){
		cout << ans[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 10028
#include<iostream>
#include<cmath>
#include<vector>
#include<iostream>

#define ll long long
using namespace std;

int main()
{
  ll N;
  cin >> N;
  ll t[N+1], x[N+1], y[N+1];
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  for (ll i=1; i<=N; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }

  for (ll i=1; i<=N; i++) {
    ll dis = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
    ll dift = t[i] - t[i-1]; 
    if (dis > dift || (dift - dis)%2 != 0) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

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

const ll MOD = 1e9+7;
int main() {
    ll n,m;
    std::cin >> n>>m;
    
    vector<ll> a(n);
    vector<ll> b(m);
    
    map<ll,pair<ll,ll>> ma;
    
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        ma[a[i]].first = i+1;
    }
    
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
        ma[b[i]].second = i+1;
    }
    
    
    
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    
    for (int i = 0; i < n-1; i++) {
        if(a[i]==a[i+1]){
            std::cout << 0 << std::endl;
            return 0;
        }
    }
    for (int i = 0; i < m-1; i++) {
        if(b[i]==b[i+1]){
            std::cout << 0 << std::endl;
            return 0;
        }
    }
    
    ll res = 1;
    
    for (ll i = 1; i <= n*m; i++) {
        if(ma[i].first!=0 && ma[i].second!=0){
            continue;
        }
        if(ma[i].first == 0 && ma[i].second ==0){
            ll t1 = n-distance(a.begin(),lower_bound(a.begin(),a.end(),i));
            ll t2 = m-distance(b.begin(),lower_bound(b.begin(),b.end(),i));
            res *= t1*t2-(n*m-i);
            res %= MOD;
        }else{
            if(ma[i].first==0){
                ll t1 = n-distance(a.begin(),lower_bound(a.begin(),a.end(),i));
                res *= t1;
                res %= MOD;
            }else{
                ll t2 = m-distance(b.begin(),lower_bound(b.begin(),b.end(),i));
                res *= t2;
                res %= MOD;
            }
        }
    }
    
    std::cout << res%MOD << std::endl;
    
}


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


int main() {
int N;
  cin >>N;
  int x=0;
  for(int i=1;i<=N;i++){
  int a=N/i;
    x+=a;
  }
  int y=0;
  for(int j=1;j<=N;j++){
  if(N%j==0){y++;}
  }
cout<<x-y<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 

using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


signed main()
{
int n;
std::cin >> n;
std::vector<int> a;
std::vector<int> dp;
int sum = 0; 
rep(i,n){
    int temp;
    cin >> temp;
    a.pb(temp);
    dp.pb(0);
    sum += temp;
}

std::sort(all(a),std::greater<int>());
std::vector<int> rsum;
rsum.pb(a[0]);
reps(i,n - 1){
    rsum.pb(rsum[i - 1] + a[i]);
}
int count = 1;
int flag = 0;
reps(i,n - 1){
    if(flag == 0 && 2*(sum - rsum[i - 1]) >= a[i - 1]){
        count++;
    } else if(2 * (sum - rsum[i - 1]) < a[i - 1]){
        flag = 1;
    }
}

std::cout << count << std::endl;
return 0;
}

Measured memory_bytes: 3308
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int N;
  cin >> N;
  vector<pair<int, int>> tasks(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    tasks[i] = make_pair(b, a);
  }
  sort(tasks.begin(), tasks.end());
  int now = 0;
  for (int i = 0; i < N; i++) {
    now += tasks[i].second;
    if (now > tasks[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3328
S = input()

INF = 10 ** 9 + 7

dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i+1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i+1][(mul * k + j) % 13] += dp[i][j]
                dp[i+1][(mul * k + j) % 13] %= INF
                
    else:
        k = int(x)
        for j in range(13):
            dp[i+1][(mul * k + j) % 13] += dp[i][j]
            dp[i+1][(mul * k + j) % 13] %= INF
    mul = mul * 10 % 13
    
print(dp[len(S)][5])

Measured memory_bytes: 62300
// 連結
#include <iostream>
#include <vector>
#include <map>
#include <utility>
using namespace std;
int n,k,l;
int x,y;
vector<int> a[200001],b[200001];
int A[200001],B[200001];
map<pair<int,int>,int> mp;

void dfs_a(int num,int node){
    A[node]=num;
    for(int i=0;i<a[node].size();i++){
        if(A[a[node][i]]==0) dfs_a(num,a[node][i]);
    }
    return;
}

void dfs_b(int num,int node){
    B[node]=num;
    for(int i=0;i<b[node].size();i++){
        if(B[b[node][i]]==0) dfs_b(num,b[node][i]);
    }
    return;
}

int main(){
    cin>>n>>k>>l;
    for(int i=0;i<k;i++){
        cin>>x>>y;
        a[x].push_back(y);
        a[y].push_back(x);
    }for(int i=0;i<l;i++){
        cin>>x>>y;
        b[x].push_back(y);
        b[y].push_back(x);
    }
    x=0;
    y=0;
    for(int i=1;i<=n;i++){
        if(A[i]==0) dfs_a(++x,i);
        if(B[i]==0) dfs_b(++y,i);
        mp[make_pair(A[i],B[i])]++;
    }
    for(int i=1;i<=n;i++){
        if(i-1)cout<<" ";
        cout<<mp[make_pair(A[i],B[i])];
    }
    cout<<endl;
}

Measured memory_bytes: 27904
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>

using namespace std;
typedef long long LL;
const int maxn = 100005;

int n,m,a[maxn];LL s1[maxn],s2[maxn];
void add1(int l,int r,LL w) {
	s1[l]+=w;s1[r+1]-=w;
}
void add2(int l,int r,LL w) {
	s2[l]+=w;s2[r+1]-=w;
}
int main()
{
	#ifdef Amberframe
		freopen("arc077e.in","r",stdin);
		freopen("arc077e.out","w",stdout);
	#endif
	
	scanf("%d %d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<n;i++)
	if (a[i]!=a[i+1]) {
		if (a[i+1]>a[i]) {
			add1(1,a[i],a[i+1]-a[i]);
			add1(a[i+1]+1,m,a[i+1]-a[i]);
			add2(a[i]+1,a[i+1],1);
			add1(a[i]+1,a[i+1],a[i+1]+1);
		}
		else {
			add1(a[i+1]+1,a[i],a[i+1]+m-a[i]);
			add1(1,a[i+1],a[i+1]+1);
			add2(1,a[i+1],1);
			add1(a[i]+1,m,m+1+a[i+1]);
			add2(a[i]+1,m,1);
		}
	}
	
	for (int i=1;i<=m;i++)
		s1[i]+=s1[i-1],s2[i]+=s2[i-1];
	LL ans=1ll<<50;
	for (int i=1;i<=m;i++)
		ans=min(ans,s1[i]-s2[i]*i);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define int             long long
#define ld              long double
#define rep0(i,n)       for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rep(i,x,y)      for(int i=x;i<=y;i++)
#define reprev1(i,n)    for(int i=n;i>0;i--)
#define reprev0(i,n)    for(int i=n-1;i>=0;i--)
#define reprev(i,x,y)   for(int i=x;i>=y;i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcount(x)
#define zerobits(x)     __builtin_ctz(x)
#define in(a,n)         vi a(n);rep0(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);rep1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define endl            '\n'
#define mod             1000000007
#define M               (int)1e6+6
#define inf             1e18
using namespace std;

int n,m,k,x,y,z,a1,b,c,d,i,j;





void sol()
{   string s,t;
    cin>>s>>t;
    c=0;
    rep0(i,3)if(s[i]==t[i])c++;
    
    
    
    
    cout<<  c<<endl;
}





int32_t main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // w(t)
    sol();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    vector<int>v;
    cin>>N>>M;
    if(N>=M){cout<<0<<endl;exit(0);}
    int X;
    for(int i=0;i<M;i++){
        cin>>X;
        v.push_back(X);
    }
    sort(v.begin(),v.end());
    vector<int>l;
    for(int i=0;i<M-1;i++){
        l.push_back(v[i+1]-v[i]);
    }
    sort(l.begin(),l.end());
    for(int i=0;i<N-1;i++){
        l.pop_back();
    }
    int sub=0;
    for(int i=0;i<l.size();i++){
        sub+=l[i];
    }
    cout<<sub<<endl;
}

Measured memory_bytes: 1400
import java.io.*;
import java.rmi.MarshalledObject;
import java.util.*;

public class Main {
    static final long MOD = 1000000007;

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long M;
        M = sc.nextLong();
        Set<Long> a = new HashSet<>();
        for(int i = 0 ; i < M ; i++){
            a.add(sc.nextLong());
        }

        final Solver solver = new Solver();
        System.out.println(solver.solve(N, a));
    }
}

class Solver {
    final Map<Long, Long> memo = new HashMap<>();

    public long solve(long N, Set<Long> a) {
        return count(0, N, a);
    }

    private long count(long start, long end, Set<Long> a) {
        if (memo.containsKey(start)) {
            return memo.get(start) % Main.MOD;
        }

        if (a.contains(start) || start > end) {
            return 0;
        }
        if (start == end) {
            return 1;
        }

        final long S1 = count(start + 1, end, a) % Main.MOD;
        memo.put(start + 1, S1);

        final long S2 = count(start + 2, end, a) % Main.MOD;
        memo.put(start + 2, S2);

        return (S1 + S2) % Main.MOD;
    }


}



Measured memory_bytes: 73204
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1000 8");
            WillReturn.Add("1 3 4 5 6 7 8 9");
            //2000
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("9999 1");
            WillReturn.Add("0");
            //9999
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0].Split(' ')[0]);
        int[] DArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        for (int I = N; I < int.MaxValue; I++) {
            HashSet<int> NumSet = DeriveNumSet(I);
            if (NumSet.Overlaps(DArr) == false) {
                Console.WriteLine(I);
                break;
            }
        }
    }

    static HashSet<int> DeriveNumSet(int pVal)
    {
        var WillReturn = new HashSet<int>();
        do {
            int ModVal = pVal % 10;
            WillReturn.Add(ModVal);
            pVal /= 10;
        } while (pVal > 0);
        return WillReturn;
    }
}


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

int main() {
	int n, ans = 0, max = 0;
	string s;

	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I') ans++;
		else ans--;
		if (ans > max) max = ans;
	}
	cout << max << endl;
}

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

int main()
{
	int n, k, r, s, p;
	cin >> n >> k >> r >> s >> p;
	string t;
	cin >> t;
	string sub[100001];
	bool visit[100001] = {};
	map<pair<char, char>, int> te;
	te[make_pair(0, 'r')] = 0;
	te[make_pair(0, 's')] = r;
	te[make_pair(0, 'p')] = 0;
	te[make_pair(1, 'r')] = 0;
	te[make_pair(1, 's')] = 0;
	te[make_pair(1, 'p')] = s;
	te[make_pair(2, 'r')] = p;
	te[make_pair(2, 's')] = 0;
	te[make_pair(2, 'p')] = 0;
	int count = 0;
	for (int i = 0; i < t.size(); ++i)
	{
		if(!visit[i])
		{
			++count;
			sub[i] = "";
			for (int j = i; j < t.size(); j += k)
			{
				visit[j] = 1;
				sub[i] += t[j];
			}
		}
	}
	int ans = 0;
	int dp[100001][3] = {};
	for (int i = 0; i < count; ++i)
	{
		for (int j = 0; j < sub[i].size(); ++j)
		{
			for (int kk = 0; kk < 3; ++kk)
			{
				dp[j][kk] = 0;
			}
		}
		dp[0][0] = te[make_pair(0, sub[i][0])];
		dp[0][1] = te[make_pair(1, sub[i][0])];
		dp[0][2] = te[make_pair(2, sub[i][0])];
		for (int j = 1; j < sub[i].size(); ++j)
		{
			dp[j][0] = max(dp[j-1][1], dp[j-1][2]) + te[make_pair(0, sub[i][j])];
			dp[j][1] = max(dp[j-1][2], dp[j-1][0]) + te[make_pair(1, sub[i][j])];
			dp[j][2] = max(dp[j-1][0], dp[j-1][1]) + te[make_pair(2, sub[i][j])];
		}
		ans += max(dp[sub[i].size()-1][0], max(dp[sub[i].size()-1][1], dp[sub[i].size()-1][2]));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6528
using System;
    class Program
{
    static void Main(string[] args)
    {
        var line = Console.ReadLine();
        long sum = 0;
        foreach(var item in line)
        {
            sum += long.Parse(item.ToString());
        }

        if(sum % 9 == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  bool can = false;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m; ++j) {
      if (i * m + j * n - 2 * i * j == k) {
        can = true;
        break;
      }
    }

  if (can)
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 256
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i,a,b) for (int i = a; i > b; --i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)
 
#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 	ll ans = 1;
	//freopen ("test.txt","r",stdin);
 	ll n,k;
 	cin>>n>>k;
 	ll a[n];
 	for (int i = 0; i < n; ++i)
 	{
 		cin>>a[i];
 	}
 	ll dp[n+1] ;
 	for (int i = 0; i <= n; ++i)
 	{
 		dp[i] = 100000000000000;
 	}


 	dp[1] = 0;
 	dp[2] = abs(a[1] - a[0]);

 	/*for (int i = 0; i <= n; ++i)
 	{
 		cout<<dp[i]<<" ";
 	}
 	cout<<endl;*/

 	for (int i = 3; i <= n; ++i)
 	 {
 	 	
 	 	for(int j = 1;j<=k;j++){



 	 	if(i - j < 1){break;}

 	 	//cout<<dp[i]<<endl;

 	    dp[i] = min(dp[i] ,dp[i-j]  + abs( a[i-1] - a[i - 1- j]) ) ;

 	 }

 	 //cout<<dp[i]<<endl;
 	 } 

 	 cout<<dp[n];
}

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

public class Main {

	static int[][] map;
	static int[][] directions8 = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 },
			{ 1, 1 } };
	static int[][] directions4 = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
	static int ans;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long K = sc.nextLong();

		if (K > A) {
			B -= (K - A);
			A = 0;
		} else {
			A -= K;
		}

		System.out.println(A + " " + Long.max(B, 0));
	}

	// BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for (int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	// //二分探索
	// k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray) {
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedArray[mid] <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// 二分探索
	// k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList) {
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedList.get(mid) <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}


Measured memory_bytes: 38704
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 1000010
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int k;
int a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
int main() {
	io(); cin >> k;
	cout << a[k - 1];
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    string s;
    cin>>s;
    ll k;
    cin>>k;
    ll cnt1 = 0, cnt2 = 0, cnt3 = 0;
    string t = s+s;
    string u = t+s;
    int n = s.size();
    bool same=true;
    rep(i, n-1){
      if(s[i]!=s[i+1]) same=false;
    }
    rep(i,n-1){
        if(s[i]==s[i+1])s[i+1]='#',++cnt1;
    }
    rep(i,2*n-1){
        if(t[i]==t[i+1])t[i+1]='#',++cnt2;
    }
    rep(i,3*n-1){
        if(u[i]==u[i+1])u[i+1]='#',++cnt3;
    }
    if(same) cout << (ll)n*k/2 << endl;
    else cout << cnt1+(cnt2-cnt1)*(k-1)<<endl;
    
    return 0;
}


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

#define Mset(s, n)      memset(s, n, sizeof(s))
#define Rp0(i, m)       for(int i = 0; i < m; ++i)
#define Rpd(i, m, l)    for(int i = l; i >= m; --i)
#define Rp1(i ,m)       for(int i = 1; i <= m; i++)
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define u_map           unordered_map
#define fi              first
#define se              second
#define pb              push_back
#define pf              push_front
#define is              insert
#define ooi             INT_MAX
#define ool             LLONG_MAX
#define ll              long long
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int, int>
#define vi              vector<int>
#define vpii            vector<pii>

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos((ld) -1);
inline int Get_bit(int x, int k){return (x >> (k - 1)) & 1;}
inline ll Gcd(ll a, ll b) {ll r; while(b){ r = a % b; a = b; b = r;} return a;}
inline ll Lcm(ll a, ll b) {return a / Gcd(a, b) * b;}
inline ll Pow(ll n, ll k) {ll r = 1; for(; k; k >>= 1, n = n * n % MOD){if(k & 1) r = r * n % MOD;} return r;}
const int base = 311;


const int N = 2e5 + 10;


int n;

int a[N], b[N], c[N];

void Solve(){
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    for(int i = 1; i < n; i++) cin >> c[i];
    for(int i = 1; i <= n; i++){
        ans += b[a[i]];
        if(a[i - 1] + 1 == a[i]) ans += c[a[i] - 1];
    }
    cout << ans;
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    Solve();
    return 0;
}


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

int main()
{
    double N;
    int temp = 0;
    cin >> N;

    for (int i = N; i > 0;i--){
        temp = sqrt(i);
        if((sqrt(i)-temp)==0){
            cout << i << endl;
            break;
        }

    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int, int>
#define LL long long
#define mp make_pair
#define pb push_back
using namespace std;
const int inf = 1 << 30;
const int maxn = 2e5 + 10;
int n, m, a[maxn], b[maxn];

struct SegmentTree{
	#define ls (o << 1)
	#define rs (o << 1 | 1)
	int lz[maxn << 2], Min[maxn << 2];
	void update(int o) {
		Min[o] = min(Min[ls], Min[rs]);
	}
	void build(int o, int l, int r) {
		if (l == r) {
			return ;
		}
		int mid = (l + r) >> 1;
		build(ls, l, mid);
		build(rs, mid + 1, r);
		update(o);
	}
	void setlazy(int o, int l, int r, int mxr) {
		lz[o] = mxr;
		Min[o] = l - mxr;
	}
	void lazydown(int o, int l, int r) {
		if (lz[o]) {
			int mid = (l + r) >> 1;
			setlazy(ls, l, mid, lz[o]);
			setlazy(rs, mid + 1, r, lz[o]);
			lz[o] = 0;
		}
	}
	void cover(int o, int l, int r, int ql, int qr, int mxr) {
		if (ql <= l && r <= qr) {
			setlazy(o, l, r, mxr);
			return ;
		}
		lazydown(o, l, r);
		int mid = (l + r) >> 1;
		if (ql <= mid) cover(ls, l, mid, ql, qr, mxr);
		if (qr > mid) cover(rs, mid + 1, r, ql, qr, mxr);
		update(o);
	}
	int getmxr(int o, int l, int r, int x) {
		if (lz[o]) return lz[o];
		if (l == r) return l;
		int mid = (l + r) >> 1;
		if (x <= mid) return getmxr(ls, l, mid, x);
		return getmxr(rs, mid + 1, r, x);
	}
}sgt;

int main() {
	#ifdef DEBUG
	freopen("text.in", "r", stdin);
	#endif
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", &a[i], &b[i]);
	sgt.build(1, 1, m);
	int dr = 0;
	for (int i = 1, mxr; i <= n; ++i) {
		if (a[i] <= dr + 1) {
			dr = max(dr, b[i]);
			sgt.cover(1, 1, m, 1, dr, -inf);
		} else {
			mxr = sgt.getmxr(1, 1, m, a[i] - 1);
			sgt.cover(1, 1, m, a[i], b[i], mxr);
		}
		if (sgt.Min[1] > m) puts("-1");
		else printf("%d\n", i + sgt.Min[1]);
	}
	return 0;
}

Measured memory_bytes: 9460
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> v(n , 0);
    for (int i = 0; i < n; i++) {
    	cin >> v[i];
    }
    sort(v.begin(), v.end());
    int res = accumulate(v.begin(), v.end(), 0);
    res -= v.back() / 2;
    cout << res << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {cin >> A.at(i);}
  vector<int> B(N);
  for (int i = 0; i < N - 1; i++) {B.at(i) = A.at(i + 1) - A.at(i);}
  B.at(N - 1) = A.at(0) + K - A.at(N - 1);
  int X = B.at(0);
  for (int i = 1; i < N; i++) {X = max(X, B.at(i));}
  cout << K - X << endl;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ln(a) cout << (a) << endl
#define debug(a, n) rep(hoge, n) printf("%lld%c", a[hoge], hoge == (n) - 1? '\n' : ' ');
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1e9
#define LINF 1e18

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

signed main() {
    int h, w;
    cin >> h >> w;
    string* maze = new string[h];
    rep(i, h) {
        cin >> maze[i];
    }

    int ans = 0;
    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};
    rep(i, h) {
        rep(j, w) {
            if(maze[i][j] == '#') continue;
            bool** used = new bool*[h];
            rep(m, h) {
                used[m] = new bool[w];
                fill(used[m], used[m] + w, false);
            }
            used[i][j] = true;
            queue<pair<P, int> > que;
            que.push(make_pair(P(i, j), 0));
            while(!que.empty()) {
                P p = que.front().first;
                int d = que.front().second;
                que.pop();
                rep(m, 4) {
                    int nx = p.first + dx[m];
                    int ny = p.second + dy[m];
                    if(0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] == '.' && !used[nx][ny]) {
                        used[nx][ny] = true;
                        que.push(make_pair(P(nx, ny), d + 1));
                        ans = max(ans, d + 1);
                    }
                }
            }
        }
    }

    ln(ans);
}


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

using namespace std;

int N;
int arr[1<<18];
multiset<int> st;
bool tkn[1<<18];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for(int i = 0; i<1<<N; i++){
        cin >> arr[i];
    }
    sort(arr, arr+(1<<N), greater<int>());
    tkn[0] = 1;
    for(int d = 0; d<N; d++){
        for(int i = 0; i<1<<N; i++){
            if(tkn[i]){
                st.insert(arr[i]);
            }
        }
        for(int i = 0; i<1<<N && st.size(); i++){
            if(!tkn[i] && *(--st.end()) > arr[i]){
                tkn[i] = 1;
                st.erase(--st.end());
            }
        }
        st.clear();
    }
    for(int i = 0; i<1<<N; i++){
        if(!tkn[i]){
            cout << "No"  << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define ll long long
#define MAX 500005
using namespace std;

template<typename T>
void read(T &n){
    n = 0;
    T f = 1;
    char c = getchar();
    while(!isdigit(c) && c != '-') c = getchar();
    if(c == '-') f = -1, c = getchar();
    while(isdigit(c)) n = n*10+c-'0', c = getchar();
    n *= f;
}
template<typename T>
void write(T n){
    if(n < 0) putchar('-'), n = -n;
    if(n > 9) write(n/10);
    putchar(n%10+'0');
}

int n, x;

int main()
{
    cin >> n >> x;
    int cnt = 0;
    while(n){
        n /= x;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=2e5+1;
const int inf=1e9;
int main(){
	int N; cin>>N;
	int C[N]; vector<int> id[size];
	rep(i,0,N){
        cin>>C[i];
        if(id[C[i]].size() == 0 || id[C[i]].back() < i) id[C[i]].push_back(i + 1);
    }
	long dp[N+1]; dp[0] = 1;
    long acm[size] = {};
	rep(i,1,N+1){
		dp[i] = dp[i-1];
        if(i > 1 && C[i-2] == C[i-1]) continue;
        (dp[i] += acm[C[i-1]]) %= mod;
        (acm[C[i-1]] += dp[i-1]) %= mod;
    }cout<<dp[N]<<endl;
}

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

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())


int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max(0,c-(a-b))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;


int main(){

    int n; cin>>n;
    ll a,b;
    cin>>a>>b;
    REP(i,n-1){
        ll t1,t2; cin>>t1>>t2;
        ll x=max((a%t1==0?a/t1:a/t1+1),(b%t2==0?b/t2:b/t2+1));
        a=x*t1;
        b=x*t2;
    }
    
    cout<<a+b<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <list>
#include <math.h>
#include <iomanip>

using namespace std;

int main(void) {
    long long N;

    scanf("%lld",&N);

    double ans = 0;


    for(int i = 0; i<N; i++) {
        double x;
        char u[255];
        scanf("%lf %s",&x,u);

        if(u[0] == 'J') {
            ans += x;
        } else {
            ans += x * 380000.0;
        }
    }

    printf("%lf\n",ans);

    return 0;
}

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

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

int main()
{
    int a, b, t;
    cin >> a >> b >> t;

    printf("%d\n", (t / a) * b);

    return 0;
}


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

struct card {
    char suit;
    int value;
};

void bubbleSort(card A[], const int N)
{
    int flag = 1;

    for( int i = 0; flag; ++i ){
        flag = 0;

        for( int j = N-1; i < j; --j )
            if( A[j].value < A[j-1].value ){
                swap(A[j], A[j-1]);
                flag = 1;
            }
    }
}

void selectionSort(card A[], const int N)
{
    for( int i = 0; i < N; ++i ){
        int min = i;
      
        for( int j = i; j < N; ++j )
            if( A[j].value < A[min].value )
                min = j;
       
        if( i != min ) swap(A[i], A[min]);
    }
}

int main()
{
    int N;
    scanf("%d%*c", &N);
    card A[N], B[N]; //A:bubbleSort, B:selectionSort
    for( int i = 0; i < N; ++i ){
        scanf("%c%d%*c", &A[i].suit, &A[i].value);
        B[i] = A[i];
    }


    bubbleSort(A, N);
    selectionSort(B, N);

    for( int i = 0; i < N; ++i ){
        if( 0 < i ) printf(" ");
        printf("%c%d", A[i].suit, A[i].value);
    }
    printf("\n");
    printf("Stable\n");

    int flag = 1;
    for( int i = 0; i < N; ++i ){
        if( 0 < i ) printf(" ");
        printf("%c%d", B[i].suit, B[i].value);
        if( !(B[i].suit == A[i].suit && B[i].value == A[i].value) ) flag = 0;
    }
    printf("\n");
    if( flag ) printf("Stable\n");
    else printf("Not stable\n");

    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
using namespace std;
int cnt[300005] = {0};
int pre[300005];

bool cmp(int a, int b) {
    return a > b;
}

int main() {
    int n;
    cin >> n;
    int tmp;
    for (int i = 0; i < n; i++) {
        scanf("%d", &tmp);
        cnt[tmp]++;
    }
    sort(cnt + 1, cnt + n + 1, cmp);
    pre[0] = 0;
    for (int i = 1; i <= n; i++) {
        pre[i] = pre[i - 1] + cnt[i];
    }
    cout << n << endl;
    for (int i = 2; i <= n; i++) {
        if (cnt[i] == 0) {
            printf("0\n");
        } else {
            int x = n / i;
            int lft = 1;
            int pos = lower_bound(cnt + 1, cnt + n + 1, x, greater<int>()) - cnt;
            while (pos != lft) {
                lft = pos;
                x = (n - pre[pos - 1]) / (i - lft + 1);
                pos = lower_bound(cnt + 1, cnt + n + 1, x, greater<int>()) - cnt;
            }
            printf("%d\n", x);
        }
    }
}



Measured memory_bytes: 6196
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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 long long lint;

using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<(n*800-(n/15)*200)<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
constexpr ll INF = 1000000000;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	ll k;
	cin >> s >> k;

	ll n = s.size();

	for (int i = 0; i < min(n, k); i++) {
		if (s[i] >= '2') {
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << '1' << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  d, n ; cin >>d>>n;
   long long sum=0 ;
   while(n--){int as; cin >> as; sum+=as; }
   if(sum<=d){cout<<d-sum <<endl;}
   else {cout<<"-1"<<endl;}

    return 0;
}



Measured memory_bytes: 3584