akhauriyash/Code-Regression huggingface dataset:
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

int64_t N, M;
vector<vector<int64_t>> nexts;
vector<bool> visited;
vector<int64_t> length;

int64_t Dfs(const int64_t vertex) {
  if (visited[vertex]) {
    return length[vertex];
  }
  visited[vertex] = true;
  int64_t result = 0;
  for (const int64_t n : nexts[vertex]) {
    result = max(result, Dfs(n) + 1);
  }
  length[vertex] = result;
  return result;
}

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

  cin >> N >> M;
  nexts = vector<vector<int64_t>>(N + 1);
  visited = vector<bool>(N + 1, false);
  length = vector<int64_t>(N + 1, 0);
  for (int64_t i = 0; i < M; ++i) {
    int64_t from, to;
    cin >> from >> to;
    nexts[from].emplace_back(to);
  }

  int64_t result = 0;
  for (int64_t v = 1; v <= N; ++v) {
    if (!visited[v]) {
      result = max(result, Dfs(v));
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 11536
S=str(input())

if S[0]==S[1] and S[0]!=S[2] and S[0]!=S[3] and S[2]==S[3]:
    print("Yes")
elif S[0]==S[2] and S[0]!=S[1] and S[2]!=S[3] and S[1]==S[3]:
    print("Yes")
elif S[0]==S[3] and S[0]!=S[2] and S[0]!=S[1] and S[1]==S[2]:
    print("Yes")
else :
    print("No")


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

int main() {
	int n;
	cin >> n;
	int ans = (n-400)/200;
	ans = 8-ans;
	cout << ans << endl;
	return 0;
}

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

int dif[100001];

int main(void) {
	int N;
	cin >> N;

	for (int i = 0; i <= 100000; i++) dif[i] = 0;

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

	bool err = false;
	int st,  en = N-1;
	if ((N%2) == 0) {
		if (dif[0] > 0) err = true;
		st = 1;
	} else {
		if (dif[0] != 1) err = true;
		st = 2;
	}

	for (int i = st; i <= en; i += 2) {
		if (dif[i] != 2) err = true;
		if (dif[i+1] > 0) err = true;
	}

	if (err) {
		cout << 0 << endl;
		return 0;
	}

	long long ans = 1;
	for (int i = 0; i < (N/2); i++) {
		ans = (ans * 2) % 1000000007;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
X = int(input())
d100 = X // 100
Xm = X % 100

for y2 in range(0, 51):
    for y3 in range(0, 34):
        for y4 in range(0, 26):
            for y5 in range(0, 21):
                if y2 + y3 + y4 + y5 > d100:
                    continue

                y1 = Xm - ((2 * y2) + (3 * y3) + (4 * y4) + (5 * y5))
                if y1 < 0:
                    continue

                if 101 * y1 + 102 * y2 + 103 * y3 + 104 * y4 + 105 * y5 > X:
                    continue

                if (X - (101 * y1 + 102 * y2 + 103 * y3 + 104 * y4 + 105 * y5)) % 100 == 0:
                    print(1)
                    exit()

print(0)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
   int n;
   long long a[10001]={0};
   cin>>n;
   for(int i=0;i<n;i++){
       cin>>a[i];
   }
   long long int min=1000000,max=-1000000,sum=0;
   for(int i=0; i<n; i++){
       if(a[i]<min){
           min=a[i];
       }
       if(a[i]>max){
           max=a[i];
   }
      sum=sum+a[i];
 }
   cout<<min<<" "<<max<<" "<<sum<<endl;
}



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

for a in range(1, 3501):
    for b in range(1, 3501):
        if 4 * a * b - N * (a + b) == 0:
            continue
        c = N * a * b / (4 * a * b - N * (a + b))
        if c.is_integer() and c > 0:
            print(*list(map(int, [a, b, c])))
            exit()

Measured memory_bytes: 40684
import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ansL = 1;
		int ansR = sc.nextInt();
		int M = sc.nextInt();
		for(int i = 0; i < M ; i++){
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		}
		sc.close();
		System.out.println(Math.max(0,ansR-ansL+1));
	}
};



Measured memory_bytes: 62420
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::*,
    std::{cmp::*, collections::*, convert::*, iter::*, marker::*, mem::*, ops::*},
};
fn main() {
    input! {//
        s:Chars,
        t:Chars,
    }
    let mut ok = true;
    for i in 0..s.len() {
        if s[i] != t[i] {
            ok = false;
        }
    }
    pub fn yn(ans: bool) {
        if ans {
            println!("Yes");
        } else {
            println!("No");
        }
    }
    yn(ok);
}


Measured memory_bytes: 2128
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
ll n, s[210000], a, res;
map<ll, ll> mp;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> a;
        s[i + 1] = s[i] + a;
    }
    for (ll i = 0; i <= n; i++) {
        mp[s[i]]++;
    }
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        res += itr->second * (itr->second - 1) / 2;
    }
    cout << res << endl;
}


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

#define INF 1e+9

int main(){

	  int N,W;
	  cin >> N >> W;

	  int w[N]={},v[N]={};
	  for(int i=0; i<N; i++) cin >> v[i] >> w[i];

	  int dp[N][W+1]={};
	  for(int i=0; i<N; i++)
			for(int j=0; j<=W; j++)
				  dp[i][j] = -INF;
	  dp[0][0] = 0;
	  for(int i=0; i<N; i++){
			for(int j=0; j<=W; j++){
				  if(j-w[i] >= 0)
						dp[i][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
				  if(i!=0)
						dp[i][j] = max(dp[i][j],dp[i-1][j]);
			}
	  }
	  int ans = 0;
	  for(int i=0; i<=W; i++)
			ans = max(ans,dp[N-1][i]);
	  cout << ans << endl;
				  
	  

}

Measured memory_bytes: 7020
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}
 
const int N=200005;
int a[N],b[N],c[N],n;
ll A,B,S,ans;
 
int main(){
	read(n);
	rep(i,1,n){
		read(a[i]),read(b[i]);
		A+=a[i],B+=b[i];
		if(a[i]>b[i])swap(a[i],b[i]);
		c[i*2-1]=a[i],c[i<<1]=b[i];
	}
	ans=min(A,B);
	sort(c+1,c+n*2+1);
	rep(i,1,n-2)S+=c[i];
	rep(i,1,n){
		ll s=S+a[i]+b[i]; int k=n-2;
		if(a[i]<=c[k]) s=s-a[i]+c[++k];
		if(b[i]<=c[k]) s=s-b[i]+c[++k];
		ans=min(ans,s);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    int i,j;
    for(i=0;i<n;i++){
        cin >> s.at(i);
    }
    string tmp = s.at(0);
    for(i=0;i<n-1;i++){
        for(j=1;j+i<n;j++){
            if(s.at(i)>s.at(i+j)){
                tmp=s.at(i+j);
                s.at(i+j)=s.at(i);
                s.at(i)=tmp;
            }
        }
    }
    for(i=0;i<n;i++){
        cout << s.at(i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=[0]+list(map(int,input().split()))+[0]
B=[0]*N

sum_=sum([abs(A[i+1]-A[i]) for i in range(N+1)])

for i in range(N):
    if (A[i+1]-A[i]>0 and A[i+2]-A[i+1]<0) or (A[i+1]-A[i]<0 and A[i+2]-A[i+1]>0):
        ans=2*min(abs(A[i+1]-A[i]),abs(A[i+2]-A[i+1]))
        print(sum_-ans)
    else:
        print(sum_)

Measured memory_bytes: 14172
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        String s = br.readLine();
        int k = Integer.parseInt(br.readLine());

        char c = s.charAt(k - 1);
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++) {
            if(s.charAt(i) == c) sb.append(s.charAt(i));
            else sb.append('*');
        }

        System.out.println(sb);

        br.close();
    }
}

Measured memory_bytes: 21204
#include<iostream>
#include<limits.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	int min_abs = INT_MAX;
	long sum=0;
	int tmp = 0;
	int to_reverse = 0;
	for(int i=0; i<n; i++){
		cin >> tmp;
		sum += abs(tmp);
		if(tmp < 0) to_reverse++;
		if(abs(tmp)<min_abs) min_abs=abs(tmp);
	}
	if(to_reverse%2 == 1) sum -= 2*min_abs;
	cout << sum << endl;

	return 0;
}


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


void solve(long long N, std::vector<long long> h){
  vector<long long> dp(N);
  dp[1] = abs(h[0] - h[1]);
  for(long long i = 2; i < N; i++) {
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
  }

  cout << dp[N-1] << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> h(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&h[i]);
  }
    solve(N, std::move(h));
    return 0;
}


Measured memory_bytes: 1792
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var whn=arr.shift().split(" ").map(Number);
var xy=arr.shift().split(" ").map(Number);
var n=whn[2]-1;
var X=xy[0];
var Y=xy[1];
var sum=0;
while(n--){
   var xy=arr.shift().split(" ").map(Number);
   var x=xy[0];
   var y=xy[1];
   var dx=Math.abs(X-x);
   var dy=Math.abs(Y-y);
   if((x<X && y<Y) || (x>X && y>Y)){
      while(dx>0 && dy>0){
         dx--;
         dy--;
         sum++;
      }
   }
   sum+=dx+dy;
   X=x;
   Y=y;
}
console.log(sum);

Measured memory_bytes: 17384
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<cstdio>
#include<sstream>
#include<vector>
#include<algorithm>
#include<unordered_map>

using namespace std;
#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define gc(x)  scanf(" %c",&x);
#define mmt(x,y)  memset(x,y,sizeof x)
#define write(x) printf("%d\n",x)
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define ll long long
#define mod (ll)(1e9 + 7)
const int N = 1e6 + 5;
const int M = 1e6 + 5;
ll mulit(ll a,ll b,ll m)
{
    ll ans=0;
    while(b)
    {
        if(b&1)
            ans=(ans+a)%m;
        a=(a<<1)%m;
        b>>=1;
    }
    return ans;
}
ll quick_mod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=mulit(ans,a,m);
        a=mulit(a,a,m);
        b>>=1;
    }
    return ans;
}
ll comp(ll a,ll b,ll m)
{
    if(a<b)
        return 0;
    if(a==b)
        return 1;
    if(b>a-b)
        b=a-b;
    ll ans=1,ca=1,cb=1;
    for(int i=0; i<b; i++)
    {
        ca=ca*(a-i)%m;
        cb=cb*(b-i)%m;
    }
    ans=ca*quick_mod(cb,m-2,m)%m;
    return ans;
}
ll lucas(ll a,ll b,ll m)
{
    ll ans=1;
    while(a&&b)
    {
        ans=(ans*comp(a%m,b%m,m))%m;
        a/=m;
        b/=m;
    }
    return ans;
}
int main()
{
    ll x,y;
    cin>>x>>y;
    if((x + y)%3!=0) return cout<<0,0;
    ll num = (x + y) /3;
    if(x <= 2*num&&x >= num&&y <= 2*num&&y >= num) {}
    else return cout<<0,0;
   // cout<<"YES"<<endl;
    ll a = num,b = 2*num;
    ll sum = 0;
    while(a != x&&b != y){
         a ++;b --;
         sum ++;
    }
    if(sum == 0 || sum == num) cout<<1;
    else cout<<lucas(num,sum,mod);
   // cout<<c(num,sum);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> adj[N];
int n , m , dg[N] , dp[N];

int32_t main(){
	scanf("%d%d" , &n , &m);
	for(int i = 1 ; i <= m; i ++){
		int x , y;
		scanf("%d%d" , &x , &y);
		adj[x].push_back(y);
		dg[y]++;
	}
	queue<int> q;
	for(int i = 1 ; i <= n; i ++){
		dp[i] = 0;
		if(dg[i] == 0) q.push(i);
	}
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(auto w : adj[u]){
			dg[w]--;
			dp[w] = max(dp[w] , dp[u] + 1);
			if(dg[w] == 0) q.push(w);
		}
	}
	int ans = 0;
	for(int i = 1 ; i <= n; i ++) ans = max(ans , dp[i]);
	printf("%d\n" , ans);
}

Measured memory_bytes: 6528
s = input().split()
s2 = input().split()
s3 = input()

if s3 == s[0]:
    ss = int(s2[0]) - 1
    print(str(ss) + " " + s2[1])
else:
    ss = int(s2[1]) - 1
    print(s2[0] + " " + str(ss))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}


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

int main()
{
    int a, b, t;
    cin>>a>>b>>t;
    int total = 0;
    int time = 0;
    while(true)
    {
        time = time + a;
        if(time <= (t+0.5))
        {
            total = total + b;
            continue;
        }
        else break;
    }
    cout<<total;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char a[10];
    char b[10];
    scanf("%s%s",a,b);

    if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])printf("YES\n");
    else printf("NO\n");

    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Comparator;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Pair[] pair = new Pair[N];
		for (int i = 0; i < N; i++) {
			pair[i] = new Pair(sc.nextInt(), sc.nextInt());
		}

		Arrays.sort(pair, Comparator.comparingInt(Pair::getA));
		long sum = 0;
		for (Pair p : pair) {
			long buy = Math.min(M, p.B);
			M -= buy;
			sum += p.A * buy;

			if (M <= 0) {
				break;
			}
		}
		System.out.println(sum);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Pair {
		private int A;
		private int B;

		public Pair(int a, int b) {
			super();
			A = a;
			B = b;
		}

		public int getA() {
			return A;
		}

		public int getB() {
			return B;
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 29192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> a(100001), b(100001);
    for (int i = 0; i < 100001; i++)
    {
        a[i] = make_pair(0, i + 1);
        b[i] = make_pair(0, i + 1);
    }
    for (int i = 0; i < n; i++)
    {
        int v;
        cin >> v;
        if (i % 2 == 0)
            a[v].first++;
        else
        {
            b[v].first++;
        }
    }
    sort(a.rbegin(),a.rend());
    sort(b.rbegin(),b.rend());
    ll mxa = a[0].first,mxb = b[0].first;
    if(a[0].second == b[0].second){
        if(a[1].first > b[1].first)
        mxa = a[1].first;
        else if(a[1].first < b[1].first)
        mxb = b[1].first;
        else if(a[1].first == 0 && b[1].first == 0){
            cout << n / 2 << endl;
            return 0;
        }
    }
    cout << n - mxa - mxb << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static const long long MOD_NUM = 1000000007LL;

static void C_task();

int main()
{
	C_task();
	fflush(stdout);
	return 0;
}

static void C_task()
{
	int L;
	getint(L);
	
	double len = (double)L;
	double edge = len / 3.0;

	double surp = len - (edge * 3.0);

	printf("%.7lf\n", edge * edge * (edge + surp));
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
typedef pair<int, int> P;

P f(int x) {
	int a = x % 10;
	int b = 0;
	while (x > 0) {
		b = x;
		x /= 10;
	}
	return P(a, b);
}

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n; cin >> n;
		map<P, int> freq;
		for (int i = 1; i <= n; ++i) {
			P p = f(i);
			freq[p]++;
		}
		int64 ans = 0;
		for (int i = 1; i <= n; ++i) {
			P p = f(i);
			P q(p.second, p.first);
			ans += freq[q];
		}
		cout << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define MAX 1120

bool isprime[MAX + 1];
vector< int > prime;

void setprime(){
  for(int i = 2; i < MAX + 1; i++){
    if(!isprime[i]){
      for(int j = 2; i * j < MAX + 1; j++){
        isprime[i * j] = true;
      }
      prime.push_back(i);
    }
  }
}

int dp[MAX + 1][15];
void solve(){ //dpかきたくないよ
  dp[0][0] = 1;
  for(int i = 0; i < prime.size() ; i++){
    for(int j = 13 ; j >= 0; j--){
      for(int k = 0 ; k <= MAX - prime[i] ; k++){
        dp[k + prime[i]][j + 1] += dp[k][j];
      }
    }
  }
}

int main(){
  setprime();
  solve();
  int n, k;
  while(cin >> n >> k, n|k){
    cout << dp[n][k] << endl;
  }
}

Measured memory_bytes: 1284
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int x, y, z, k;
    std::cin >> x >> y >> z >> k;

    std::vector<long long> a(x);
    for (int i = 0; i < x; i++) {
        std::cin >> a[i];
    }

    std::vector<long long> b(y);
    for (int i = 0; i < y; i++) {
        std::cin >> b[i];
    }

    std::vector<long long> c(z);
    for (int i = 0; i < z; i++) {
        std::cin >> c[i];
    }

    std::sort(a.begin(), a.end(), std::greater<long long>());
    std::sort(b.begin(), b.end(), std::greater<long long>());
    std::sort(c.begin(), c.end(), std::greater<long long>());

    std::priority_queue<std::pair<long long, int>> q;

    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            q.push(std::make_pair(a[i] + b[j] + c[0], 0));
        }
    }

    for (int i = 0; i < k; i++) {
        std::pair<long long, int> top = q.top();
        q.pop();

        std::cout << top.first << std::endl;

        if (top.second == z - 1) {
            continue;
        }

        q.push(std::make_pair(top.first - c[top.second] + c[top.second + 1], top.second + 1));
    }
}


Measured memory_bytes: 19044
"ICPCの順位づけ"
while True:
    M, T, P, R = map(int, input().split())
    if M == 0:
        break
    submits = []  # ログを管理する配列
    for i in range(R):
        submits.append(list(map(int, input().split())))

    team_scores = {}
    for i in range(1, T+1):
        team_scores[i] = [0, 0]  # 正解数, 時間の合計

    for i in range(R):
        if submits[i][3] == 0:
            add_time = 0
            for j in range(0, i):
                if submits[j][1] == submits[i][1] and submits[j][2] == submits[i][2]:
                    add_time += 20
            team_scores[submits[i][1]][0] += 1
            team_scores[submits[i][1]][1] += (submits[i][0] + add_time)

    team_scores = sorted(team_scores.items(), key=lambda x: (x[1][0], -x[1][1], x[0]), reverse=True)

    ans = ''
    for i in range(len(team_scores)):
        if i == 0:
            ans += str(team_scores[i][0])
        else:
            if team_scores[i][1] == team_scores[i-1][1]:
                ans += '='+str(team_scores[i][0])
            else:
                ans += ','+str(team_scores[i][0])

    print(ans)



Measured memory_bytes: 5880
#include <bits/stdc++.h> // imports every library in c++
using namespace std; // ; is essential | says that you are USING the libraries

//  COMMAND TO USE WHEN RUNNING CODE: g++ day6.cpp -o day6 -std=c++11 -O2  | to run: ./(name of file)  //

int N, K;
int c = 0;

int main() {
    cin >> N;
    cin >> K;
    int h[N];
    for ( int i=0; i < N; i++ ) {
        cin >> h[i];
    }
    for ( int i=0; i < N; i++ ) {
        if ( h[i] >= K ) {
            c += 1;
        }
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 640
module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
import           Data.Ord
--import           Data.Vector.Algorithms.Search
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.IO                 as AIO
import qualified Data.Set                      as S


getVUIL :: IO (VU.Vector Int)
getVUIL = VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
readI :: BSC8.ByteString -> Int
readI = fst . fromJust . BSC8.readInt
readIL :: BSC8.ByteString -> [Int]
readIL = map readI . BSC8.words
getI :: IO Int
getI = readI <$> BSC8.getLine
getIL :: IO [Int]
getIL = readIL <$> BSC8.getLine

getNIS :: Int -> IO [(Int, BSC8.ByteString)]
getNIS 0 = return []
getNIS n = do
    [aFst, aSnd] <- BSC8.words <$> BSC8.getLine
    next         <- (getNIS (n - 1))
    return ((readI aFst, aSnd) : next)

il2ss :: [Int] -> String
il2ss = unwords . map show

il2sn :: [Int] -> String
il2sn = unlines . map show

modNum = 10 ^ 9 + 7
newtype Mint = M Int
instance Num Mint where
    (M a) + (M b) = M $ mod (a + b) modNum
    (M a) - (M b) = M (a - b)
    (M a) * (M b) = M $ mod (a * b) modNum
    fromInteger a = M $ mod (fromInteger a) modNum
    abs (M a) = M $ abs a
    signum (M a) = M $ signum a
instance Show Mint where
    show (M a) = show (mod a modNum)

int2MInt :: Int -> Mint
int2MInt a = M (mod a modNum)

main :: IO ()
main = do
    [aN, aM] <- getIL
    aA       <- getIL
    let ret' = aN - (sum aA)
    let ret  = if ret' < 0 then -1 else ret'
    print ret


Measured memory_bytes: 5288
#include <iostream>
#include <algorithm>
using namespace std;
using ll=long long;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
//https://atcoder.jp/contests/abc073/tasks/abc073_c
int cnt_digits(ll n){

    int digits =0;
    while(n > 0){

        digits++;
        n /= 10;

    }
    return digits;
}

//最大公約数
ll gcd(ll a,ll b){
    if(b ==0) return a;
    else return gcd(b ,a % b);
}

//最小公倍数
ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return (a / g) * b;
}

int main() {
     
   int N=0 , ptr=0 , res=0 ;
    int A[100000] ={0};
    scanf( "%d" ,& N );

	for(int i =0; i < N ; i ++) scanf( "%d" ,& A [ i ]);
	sort(A , A + N );
	while ( ptr < N )
	{
		int cc = A [ptr],f =0;
		while ( ptr < N && A [ ptr ]== cc ) f ++ , ptr ++;
		res += f %2;
	}
	printf( "%d\n" , res );
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    while (1){
        int n, x, ans=0;
        cin >> n >> x;
        if (n == 0&& x == 0) break;
        for (int i=1; i<=n; i++){
            for (int j=i+1; j<n; j++){
                for (int k=j+1; k<=n; k++){
                    if (i+j+k==x) ans++;
                }
            }
        }
        cout << ans << endl;
    }
}


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

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxn = 1005;
int main(){
    int n; cin >> n;
    for(int x = 1;x <= n; ++x){
        if((int)(x*1.08) == n){
            return cout << x,0;
        }
    }
    puts(":(");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int r,D,x;
    cin >> r >> D >> x;
    vector<int> X(11);
    X[0] = x;
    for(int i = 1; i < 11; i++){
        X[i] = r*X[i-1] - D;
    }
    for(int i = 1; i < 11; i++){
        cout << X[i] << endl;
    }
}


Measured memory_bytes: 256
//貪欲？
#include<cstdio>
#include<climits>
#include<iostream>
#include<vector>
using namespace std;

vector<int> cs;
vector<vector<int> > sm;

int total_satisfaction(vector<int>& ts, int d) {
	vector<int> ls;
	for (int i = 0; i < 26; i++) ls.push_back(0);
	int s = 0;

	for (int i = 0; i < d; i++) {
		int t = ts[i];
		t--;
		s += sm[i][t];
		ls[t] = i + 1;
		
		int dis = 0;
		for (int j = 0; j < 26; j++) {
			dis += cs[j] * ((i+1) - ls[j]);
		}
		s -= dis;
	}

	return s;
}

int main() {
	int d;
	vector<int> ts;

	cin >> d;

	int x;
	for (int i = 0; i < 26; i++) {
		cin >> x;
		cs.push_back(x);
	}
	for (int i = 0; i < d; i++) {
		vector<int> v;
		sm.push_back(v);
		for (int j = 0; j < 26; j++) {
			cin >> x;
			sm[i].push_back(x);
		}
	}

	for (int i = 0; i < d; i++) {
		int mx = INT_MIN;
		int mxt = -1;

		for (int t = 1; t <= 26; t++) {
			ts.push_back(t);
			int s = total_satisfaction(ts, i + 1);
			if (s > mx) {
				mx = s;
				mxt = t;
			}
			ts.pop_back();
		}

		ts.push_back(mxt);
		cout << mxt << endl;
	}
}


Measured memory_bytes: 3672
A, B, C, D = map(int, list(input()))


def s(sign):
    return "+" if sign == 1 else "-"


for i in (1, -1):
    for j in (1, -1):
        for k in (1, -1):
            if A + i * B + j * C + k * D == 7:
                print("{}{}{}{}{}{}{}=7".format(A, s(i), B, s(j), C, s(k), D))
                exit()


Measured memory_bytes: 3060
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e6 + 3);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

#define MAXN (1 << 20)

mod f[MAXN];

int solve() {
	int tx, td, tn;
	cin >> tx >> td >> tn;
	mod x(tx), d(td);
	if (td == 0) {
		return (x.mypow(tn)).x;
	}
	x *= d.inv();
	if ((x.x + tn - 1 >= MOD) || (x.x == 0)) {
		return 0;	
	}
	return ((f[x.x + tn - 1] * f[x.x - 1].inv()) * d.mypow(tn)).x;
	
}

int main() {
	cout << fixed << setprecision(12);	
	f[0] = mod(1);
	for (int i = 1; i < MOD; i++) {
		f[i] = f[i - 1] * mod(i);
	}
	
	int q;
	cin >> q;
	while (q--) {
		cout << solve() << endl;
	}

	return 0;
}


Measured memory_bytes: 11820
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    double T,X;
    cin>>T>>X;
    cout <<setprecision(15)<<T/X<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (S == "Cloudy") {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(input())
ans = 0
for a in range(1, N):
    ans += N // a
    if N % a == 0:
        ans -= 1
print(ans)


Measured memory_bytes: 68012
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

input_n = lambda: int(readline())
input_nn = lambda: map(int, readline().split())
input_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, M = input_nn()
    AB = sorted([list(input_nn()) for _ in range(N)])

    m = M
    ans = 0
    for i in range(N):
        if AB[i][1] < m:
            ans += AB[i][0] * AB[i][1]
            m -= AB[i][1]
        else:
            ans += AB[i][0] * m
            break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 37648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y));

int sort_int(const void *a,const void *b)
{
	if(*(int*)a > *(int*)b)
		return 1;
	if(*(int*)a < *(int*)b)
		return -1;
	return 0;
}

int index_l(int* list,int n,int key)
{
	int i;
	int num = 0;
	int width = 32768;
	for (i = 0; i < 16; i += 1)
	{
		int nn = num + width;
		width >>= 1;
		if(n > nn && list[nn] <= key)
			num = nn;
	}
	return num;
}

void paint(int x,int y,int** list,int width,int height)
{
	list[x][y] = 2;
	if(x > 0)
	{
		if(list[x-1][y] == 0)
		{
			paint(x-1,y,list,width,height);
		}
	}
	if(x < (width-1))
	{
		if(list[x+1][y] == 0)
		{
			paint(x+1,y,list,width,height);
		}
	}
	if(y > 0)
	{
		if(list[x][y-1] == 0)
		{
			paint(x,y-1,list,width,height);
		}
	}
	if(y < (height-1))
	{
		if(list[x][y+1] == 0)
		{
			paint(x,y+1,list,width,height);
		}
	}
}

int fixl(int* list,int n)
{
	int* nl = mem(int,n);
	int i,j = 1;
	nl[0] = list[0];
	for(i = 1;i < n;i++)
	{
		if(list[i] != list[i-1])
		{
			nl[j] = list[i];
			j++;
		}
	}
	for(i = 1;i < j;i++)
	{
		list[i] = nl[i];
	}
	return j;
}

int main()
{
	int w,h,i,j,k,l;
	int** list;
	while(scanf("%d %d",&w,&h),w)
	{
		int n;
		scanf("%d",&n);
		int* lx = mem(int,n*2+2);
		int* ly = mem(int,n*2+2);
		int** list = mem(int*,n);
		for(i = 0;i < n;i++)
		{
			list[i] = mem(int,4);
			int x1,y1,x2,y2;
			scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
			list[i][0] = lx[i*2] = x1;
			list[i][1] = lx[i*2+1] = x2;
			list[i][2] = ly[i*2] = y1;
			list[i][3] = ly[i*2+1] = y2;
		}
		lx[n*2] = 0;
		lx[n*2+1] = w;
		ly[n*2] = 0;
		ly[n*2+1] = h;
		qsort(lx,n*2+2,sizeof(int),sort_int);
		qsort(ly,n*2+2,sizeof(int),sort_int);
		int nlx = fixl(lx,n*2+2);
		int nly = fixl(ly,n*2+2);
		int** table = mem(int*,nlx);
		for(i = 0;i < nlx;i++)
		{
			table[i] = mem(int,nly);
			memset(table[i],0,sizeof(int)*nly);
		}
		for(i = 0;i < n;i++)
		{
			table[index_l(lx,nlx,list[i][0])][index_l(ly,nly,list[i][2])]++;
			table[index_l(lx,nlx,list[i][1])][index_l(ly,nly,list[i][2])]--;
			table[index_l(lx,nlx,list[i][0])][index_l(ly,nly,list[i][3])]--;
			table[index_l(lx,nlx,list[i][1])][index_l(ly,nly,list[i][3])]++;
		}
		for(i = 0;i < nlx;i++)
		{
			for(j = 1;j < nly;j++)
			{
				table[i][j] += table[i][j-1];
			}
		}
		for(i = 1;i < nlx;i++)
		{
			for(j = 0;j < nly;j++)
			{
				table[i][j] += table[i-1][j];
			}
		}
		int c = 0;
		for(i = 0;i < nlx-1;i++)
		{
			for(j = 0;j < nly-1;j++)
			{
				if(table[i][j] == 0)
				{
					c++;
					paint(i,j,table,nlx-1,nly-1);
				}
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	if(n < 11)
		return cout << n, 0;
	queue<long long> q;
	for(int i = 1; i < 10; ++i)
		q.push(i);
	int cnt = 0;
	while(cnt != n) {
		long long x = q.front();
		q.pop();
		++cnt;
		if(cnt == n)
			return cout << x, 0;
		if(x % 10 != 0)
			q.push(10 * x + x % 10 - 1);
		q.push(10 * x + x % 10);
		if(x % 10 != 9)
			q.push(10 * x + x % 10 + 1);
	}
}


Measured memory_bytes: 5160
N,A,B = map(int,input().split())

if A == 0 and B == 0:
    cnt = 0
    print(cnt)
elif A != 0 or B != 0:
    m = N // (A+B)
    n = N % (A+B)

    cnt = A * m
    if n <= A:
        cnt += n
    elif n > A:
        cnt += A
    print(cnt)

Measured memory_bytes: 3060
int[] arr;
void main() {
	arr ~= 1;
	arr ~= 6;
	arr ~= 9;
	foreach(i; [6, 9]) {
		int j = i;
		int k = 2;
		j = j ^^ 2;
		while(j <= 1e5) {
			arr ~= j;
			j = i ^^ k;
			k++;
		}
	}
	arr = arr.sort().uniq.array;

	auto N = ri;
	dp = new int[](N+1);
	dp[] = -1;
	dp[0] = 0;
	solve(N).writeln;
}

int[] dp;

int solve(int i) {
	//i.writeln;
	if(dp[i] >= 0) return dp[i];
	int tmp = int.max;
	foreach(k; arr) {
		if(i < k) break;
		tmp = min(solve(i-k)+1, tmp);
	}
	return dp[i] = tmp;
}


// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 10492
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, N, ans=0, L, X;
    vector<int> v(3);
    char tmp, tmp2;
    string S, S2, S3;
    bool flag=true;
    
    cin >> a >> b >> c;
    tmp = c-(a-b);
    // ans = a<=b ? a:a-1;

    cout <<(tmp>=0? tmp: 0) <<endl;

    // if(S[1]==S[2] &&(S[0]==S[1] | S[2]==S[3]))
    // 	cout << "Yes" <<endl;
    // else
    // 	cout << "No" <<endl;

    // string S;
    // cin >>S;
    // // cout << S + "pp"<<endl;
    // if(flag)
    // 	puts("Yes");
    // else
    // 	puts("No");
}



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  while(A>0&&C>0) {
      C -= B;
      if(C<=0) break;
      A -= D;
  }
  cout << (A>0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
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; }

bool isInField(int x, int y, int h, int w) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

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

    int h, w;
    cin >> h >> w;
    vector<vector<char>> field(h, vector<char>(w));
    for (auto& row : field) {
        for (auto& c : row) {
            cin >> c;
        }
    }


    vector<vector<int>> cnt(h, vector<int>(w, 0));

    vector<int> dx = { -1, 0, 1};
    vector<int> dy = { -1, 0, 1};

    for (size_t i = 0; i < h; i++)
    {
        for (size_t j = 0; j < w; j++)
        {
            if (field[i][j] == '#') {
                continue;
            }
            for (size_t k = 0; k < 3; k++)
            {
                for (size_t l = 0; l < 3; l++)
                {
                    if (dx[k] == 0 && dy[l] == 0) {
                        continue;
                    }
                    int nx = j + dx[k];
                    int ny = i + dy[l];
                    if (isInField(nx, ny, h, w)) {
                        if (field[ny][nx] == '#') {
                            cnt[i][j]++;
                        }
                    }
                }
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (field[i][j] == '.') {
                cout << cnt[i][j];
            }
            else {
                cout << field[i][j];
            }
        }
        cout << "\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    map<string, int> cnt;
    rep (i, n)
    {
        string s;
        cin >> s;
        ++cnt[s];
    }

    string cand[] = {"AC", "WA", "TLE", "RE"};
    rep (i, 4)
    {
        cout << cand[i] << " x " << cnt[cand[i]] << "\n";
    }

    return 0;
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e14;
const LL MOD = 1e9 + 7;

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

LL check(auto s)
{
  LL res = 0;
  int idx = 0;
  while(true)
  {
    if (idx >= s.size()) break;
    if (s[idx] == s[idx+1])
    {
      res++;
      idx += 2;
    }
    else idx++;
  }
  return res;
}

bool check2(auto s, auto &ctf, auto&ctb)
{
  REP2(i, 1, s.size())
  {
    if (s[i-1] == s[i]) ctf++;
    else break;
  }
  REPR2(i, 1, s.size())
  {
    if (s[i-1] == s[i]) ctb++;
    else break;
  }
  if (ctf % 2 && ctb % 2) return true;
  else return false;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  LL K;
  cin >> S >> K;
  LL ans = 0;
  ans += check(S) * K;
  LL ctf = 1, ctb = 1;
  if (S.front() == S.back())
  {
    if (check2(S, ctf, ctb))
    {
      if (ctf == ctb)
      {
        if (ctf == S.size()) ans = (K * S.size()) / 2;
        else
        {
          ans += K-1;
        }
      }
      else ans += K-1;
    }
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main(){
    int n,pos,count = 0;
    string s;

    cin >> n >> s;

    pos = s.find("ABC");

    while(pos != std::string::npos){
        count++;
        pos = s.find("ABC",pos+3);
    }

    cout << count << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
  int rooms[4][3][10];
  int n;
  cin >> n;
  REP(i, 4)
  {
    REP(j, 3)
    {
      REP(k, 10)
      {
        rooms[i][j][k] = 0;
      }
    }
  }

  int b, f, r, v;
  REP(i, n){
    cin >> b >> f >> r >> v;
    rooms[b-1][f-1][r-1] += v;
  }

  REP(i, 4)
  {
    if (i > 0) cout << "####################\n";
    REP(j, 3)
    {
      REP(k, 10)
      {
        cout << " ";
        cout << rooms[i][j][k];
      }
      cout << "\n";
    }
  }
}



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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    string s, t; cin >> s >> t;

    string x = t.substr(0, sz(t)-1);

    cout << ((s == x) ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3656