akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;

  vector<int> a(n);
  for (auto &i : a) cin >> i;

  vector<int> zip = a;
  sort(zip.begin(), zip.end());
  zip.erase(unique(zip.begin(), zip.end()), zip.end());

  for (int i = 0; i < n; ++i) {
    a[i] = lower_bound(zip.begin(), zip.end(), a[i]) - zip.begin();
  }

  vector<int> ans;
  map<int, int> m;
  for (int k = 0; k < n; ++k) {
    m[a[k]]++;
    m[a[n - k - 1]]--;

    if (!m[a[k]]) m.erase(a[k]);
    if (!m[a[n - k - 1]]) m.erase(a[n - k - 1]);

    if (m.size() == 0) ans.push_back(k + 1);
  }

  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << (i + 1 == ans.size() ? "\n" : " ");
  }
}



Measured memory_bytes: 4580
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;
  vector<int> p(m);
  for(int i=0;i<m;i++) cin>>p[i];
  
  vector<int> cnt(n+1,0);
  for(int i=0;i+1<m;i++) cnt[p[i+1]-p[i]-1]++;

  vector<int> v(n+2,0);
  int sum=0;
  for(int i=n;i>=1;i--){
    sum+=cnt[i];
    v[i]=v[i+1]+sum;
    //cout<<i<<":"<<v[i]<<endl;
  }
  
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int x;
    cin>>x;
    x-=p[0]-1;
    if(x<0){
      cout<<-1<<"\n";
      continue;
    }
    int l=0,r=n;
    while(l+1<r){
      int mid=(l+r)>>1;
      if(max(0,n-p[m-1]-(mid-1))+v[mid]<=x) r=mid;
      else l=mid;
    }
    cout<<r<<"\n";
  }
  cout<<flush;
  return 0;
}



Measured memory_bytes: 3860
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <regex>

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

using namespace std;

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

int X;

int main() {
    cin >> X;

    int ans = 0;
    while (X >= 500) {
        ans += 1000;
        X -= 500;
    }
    while (X >= 5) {
        ans += 5;
        X -= 5;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

#pragma gcc target ("avx2")
#pragma gcc optimization ("o3")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2.0) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}
#define nopf(T) [](T a){return a;}
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	string s;
	scans(s);
	set<char> t;
	for(const auto &aa : s){
	  if(t.find(aa) != t.end()){
	    printf("no\n");
	    return AC;
		}
		t.insert(aa);
	}
	printf("yes\n");

	Please AC;
}


Measured memory_bytes: 888
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	string s;
	cin>>s;
	int pc=0,gc=0,wi=0,lo=0;
	REP(i,s.size()){
		if(s[i]=='g' && pc<gc){pc++; wi++;}
		else if(s[i]=='g' && pc==gc)gc++;
		else if(s[i]=='p' && pc<gc)pc++;
		else{gc++; lo++;}
	}
	cout<<wi-lo<<endl;
	return 0;
}




















Measured memory_bytes: 512
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;

    public static void main(String[] args) {
        String s = ns();
        int first = Integer.parseInt(s.substring(0, 2));
        int second = Integer.parseInt(s.substring(2, 4));
        
        if (isMonth(first) && isMonth(second)) {
            so.println("AMBIGUOUS");
        } else if (isMonth(first)) {
            so.println("MMYY");
        } else if (isMonth(second)) {
            so.println("YYMM");
        } else {
            so.println("NA");
        }
    }
    
    private static boolean isMonth(int i) {
        return 1 <= i && i <= 12;
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static int[] nints(int n) {
        return nints(n, 0);
    }

    private static int[] nints(int n, int padding) {
        int[] a = new int[padding + n];
        for (int i = 0; i < n; i++)
            a[padding + i] = ni();
        return a;
    }
}


Measured memory_bytes: 22228
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(m), y(m);
    vector<vector<pair<int, int>>> v(n);

    rep(i, m) {
        cin >> p[i] >> y[i];
        v[p[i]-1].push_back(make_pair(y[i], i));
    }

    rep(i, n) {
        sort(v[i].begin(), v[i].end());

        rep(j, v[i].size()) {
            y[v[i][j].second] = j+1;
        }
    }

    rep(i, m) {
        printf("%06d%06d\n", p[i], y[i]);
    }
    
    return 0;
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    ll A, B, K; cin >> A >> B >> K;
    ll tmp = min(A,K);
    A -= tmp;
    K -= tmp;
    B = max(0LL,B-K);
    cout << A << " " << B << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    const char acgt[]={'A', 'C', 'G', 'T'};
    string s; cin>> s;
    int ans = 0;
    int cnt = 0;
    int judge = 0;
    for(int i=0; i<s.size(); i++){
        rep(j, 4){
            judge++;
            if(acgt[j] == s[i]){
                judge = 5;
                cnt++;
                ans = max(ans, cnt);
            }
        }
        if(judge == 4) cnt=0;
        judge = 0;
    }
    cout<< ans << endl;
}

Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var aDic = A.GroupBy(x => x).ToDictionary(k => k.Key, e => {
            var count = e.Count();
            return new {
                a = (2 <= count) ? Combination(count, 2) : 0, 
                b = (2 <= count - 1) ? Combination(count - 1, 2) : 0 
            }; 
        });

        var sum = aDic.Sum(x => x.Value.a);

        for (int i = 0; i < N; i++)
        {
            var ans = sum;
            ans -= aDic[A[i]].a;
            ans += aDic[A[i]].b;
            WriteLine(ans);
        }
    }

    static long Combination(long n, long r)
    {
        var a = 1L;
        for (long i = 1; i <= r; i++)
            a = a * (n - i + 1) / i;
        return a;
    }
}


Measured memory_bytes: 71068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> C(M);
  for (int i=0;i<M;i++){
    cin >> C[i];
  }
  int cost=0;
  for (int i=0;i<M;i++){
    if (C[i]<X){
      cost++;
    }
    else {
      break;
    }
  }
  cost=min(cost,M-cost);
  cout << cost << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
int main()
{
	int n, m=0;
	while (cin >> n>>m,n+m){
		int h[1600], w[1600];
		for (int i = 1; i <= n; i++) {
			cin >> h[i];
			h[i] += h[i - 1];
		}
		for (int i = 1; i <= m; i++) {
			cin >> w[i];
			w[i] += w[i - 1];
		}
		vector<int> v1, v2;
		for (int i = 1; i <= n; i++) {
			for (int j = i; j <= n; j++) {
				v1.push_back(h[j] - h[i - 1]);
			}
		}
		for (int i = 1; i <= m; i++) {
			for (int j = i; j <= m; j++) {
				v2.push_back(w[j] - w[i - 1]);
			}
		}
		int ans = 0;
		sort(v2.begin(), v2.end());
		for (int i = 0; i < v1.size();i++) {
			int a = v1[i];
			ans += upper_bound(v2.begin(), v2.end(), a) - lower_bound(v2.begin(), v2.end(), a);
		}
		cout << ans << endl;
	}

	return	0;
}





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




typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
const double pi = acos(-1.0);
const long long INF = 2e18;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"
#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number
#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value
#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

    int t = 1;
    //cin>>t;
    while(t--)
    {
        int n; cin>>n; ll a[n];
        ll ans=1;
        ll most=1e18;
        bool z=0;
        for0(i,n) {
            cin>>a[i];
            if(a[i]==0) z=1;
        }
        if(z) {cout<<0; return 0;}
        bool brk=0;
        for0(i,n){
            if(log10(ans) + log10(a[i]) >18) {brk =1; break;}
            else ans*=a[i];
        }
        if(brk) cout<<-1;
        else if(ans>most) cout<<-1;
        else cout<<ans;
    }
    return 0;
}

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

int n;
double b[59];

int main(){
	cin>>n;
	
	for(int i=0;i<n;i++)
	cin>>b[i];
	
	sort(b,b+n);
	
	double t=b[0];
	for(int i=1;i<n;i++)
	t=(t+b[i])/2;
	cout<<t;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	M := nextInt()
	maxleft := 1
	minright := N
	// 全てのMに置いて重複している範囲が分かれば良い
	// 値を格納する必要はなく、一つ一つ比較していけばOK
	for i := 0; i < M; i++ {
		L := nextInt()
		R := nextInt()
		// 重なるところがなかった場合はその時点で0確定
		if maxleft > R || minright < L {
			fmt.Println(0)
			return
		}
		maxleft = max(L, maxleft)
		minright = min(R, minright)
	}
	fmt.Println(minright - maxleft + 1)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

// 引数のうち最小のもの
func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

// 引数のうち最大のもの
func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}


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

int main(){
    int x ,y ,z;
    cin >> x >> y >> z;
    int a = x,b = y,c = z;
    int temp = a;
    a = b;
    b = temp;
    temp = a;
    a = c;
    c = temp;
    cout << a << " " << b << " " << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,k,x,y,r;
	scanf("%d",&n);
	scanf("%d",&k);
	scanf("%d",&x);
	scanf("%d",&y);
	if(n<=k)	{
		r=x*n;
	}
	else{
		r=x*k+y*(n-k);
	}
		printf("%d\n",r);
		return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

class UnionFind {
public:
  vector<int> parent;
  int root(int a) {
    if(parent[a] < 0) return a;
    return parent[a] = root(parent[a]);
  }
  UnionFind(int n) { parent = vector<int>(n, -1); }
  int size(int a) { return -parent[root(a)]; }
  int connect(int a, int b) {
    a = root(a);
    b = root(b);
    if(a == b) return false;
    if(size(a) < size(b)) swap(a, b);
    parent[a] += parent[b];
    parent[b] = a;
    return true;
  }
};

const int MAX_V = 100000;
vector<vector<int>> fto(MAX_V);
vector<vector<int>> bto(MAX_V);

int main() {
  int n;
  cin >> n;
  int m, k;
  cin >> m >> k;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    uf.connect(a, b);
    fto[a].push_back(b);
    fto[b].push_back(a);
  }
  rep(i, k) {
    int c, d;
    cin >> c >> d;
    c--, d--;
    bto[c].push_back(d);
    bto[d].push_back(c);
  }
  rep(i, n) {
    int ans = uf.size(i) - fto[i].size() - 1;
    for(auto x : bto[i]) {
      if(uf.root(i) == uf.root(x)) ans--;
    }
    cout << ans << ' ';
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 12152
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
  s <- B.getLine
  putStrLn $ if solve s then "Yes" else "No"

solve :: B.ByteString -> Bool
solve s = B.index s 2 == B.index s 3 && B.index s 4 == B.index s 5


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+23;
int a[maxn];
int n,k;
bool check(int x){
	ll cnt=0;
	for(int i=0;i<n;i++){
		cnt+=(a[i]-1)/x;
	}
	return cnt<=k;
}

int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	int l=0,r=1e9;
	while(r-l>1){
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid;
	}
	cout<<r;
}

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

int main(){
  int n,m,t;
  cin>>n>>m>>t;
  vector<int> a(n+2);
  a[0]=-m;
  a[n+1]=t+m;
  for(int i=1;i<=n;i++) cin>>a[i];
  long long int res=0;
  for(int i=0;i<n+1;i++){
    res+=max(0,a[i+1]-a[i]-2*m);
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3092
num_array = gets.chomp.split("")

diff = 753
num_array.each_with_index do |item, idx|
  if (idx+2 == (num_array.length))
    break
  end

  number = (item + num_array[idx+1] + num_array[idx+2]).to_i
  if ((753-number).abs < diff)
    diff = (753-number).abs
  end
end

puts diff


Measured memory_bytes: 1788
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		int [] A = new int[N];

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

		int now = 1;
		long[] visitCount = new long[N];
		Arrays.fill(visitCount, 0);
		visitCount[now - 1] += 1;


		//System.out.print("front Part" + " ");
		//System.out.print(now + " ");
		long frontPart = 0;
		while(visitCount[A[now-1]-1] == 0) {
			now = A[now-1];
			visitCount[now-1] += 1;
			//System.out.print(now + " ");
			frontPart ++;
		}
		//System.out.println();
		//System.out.print("cycle Part" + " ");
		long cyclePart = 0;

		while(visitCount[A[now-1]-1] == 1) {
			now = A[now-1];
			visitCount[now-1] += 1;
			//System.out.print(now + " ");
			cyclePart ++;
		}
		
		//System.out.println();

		now = 1;
		//System.out.println("frontPart = " + frontPart);
		//System.out.println("cyclePart = " + cyclePart);
		//System.out.println("show ans");

		if(K <= frontPart ) {
			for(long i = 0; i < K; i++) {
				now = A[now-1];
			}
		}else {
			for(long i = 0; i < frontPart; i++) {
				now = A[now-1];
			}
			K = (K - frontPart)%cyclePart;
			for(long i = 0; i < K; i++) {
				now = A[now-1];
			}
		}


		System.out.println(now);


	}
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    string s, t;
    cin >> s >> t;
    cout << (t.substr(0, s.size()) == s ? "Yes" : "No") << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3648
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
HUGE_NUM = 9999999999999999
MOD = 1000000007
EPS = 0.000000001


global nodes

class Node:
    def __init__(self):
        self.left = -1
        self.right = -1
    def set(self,arg_node_left,arg_node_right):
        self.left = arg_node_left
        self.right = arg_node_right


def Preorder(node_id):
    print(" %d"%(node_id),end = "")

    if nodes[node_id].left != -1:
        Preorder(nodes[node_id].left)

    if nodes[node_id].right != -1:
        Preorder(nodes[node_id].right)


def Inorder(node_id):

    if nodes[node_id].left != -1:
        Inorder(nodes[node_id].left)

    print(" %d"%(node_id),end = "")

    if nodes[node_id].right != -1:
        Inorder(nodes[node_id].right)


def Postorder(node_id):

    if nodes[node_id].left != -1:
        Postorder(nodes[node_id].left)

    if nodes[node_id].right != -1:
        Postorder(nodes[node_id].right)

    print(" %d"%(node_id),end = "")




V = int(input())
nodes = [Node() for _ in range(V)]
in_num = [0]*V


for loop in range(V):
    node_id,left,right = map(int,input().split())
    nodes[node_id].set(left,right)
    if left != -1:
        in_num[left] += 1
    if right != -1:
        in_num[right] += 1

root = -1

for i in range(V):
    if in_num[i] == 0:
        root = i
        break

print("Preorder")
Preorder(root)
print()

print("Inorder")
Inorder(root)
print()

print("Postorder")
Postorder(root)
print()




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

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

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

const int MAX_N = 200010;

struct Node {
	int prev, next;
	bool f;
	void out(){
		cout << f << endl;
	}
};

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

	int n, m, q;
	cin >> n >> m >> q;

	int a[MAX_N];
	for(int i = 0; i < m; ++i){
		cin >> a[i];
	}

	Node node[MAX_N];
	for(int i = 0; i < n; ++i){
		node[i].f = true;
		node[i].prev = (i - 1 + n) % n;
		node[i].next = (i + 1) % n;
	}

	int now = 0;
	for(int i = 0; i < m; ++i){
		if(a[i] % 2 == 0){
			for(int j = 0; j < a[i]; ++j){
				now = node[now].next;
			}
		}
		else {
			for(int j = 0; j < a[i]; ++j){
				now = node[now].prev;
			}
		}

		node[now].f = false;
		node[node[now].prev].next = node[now].next;
		node[node[now].next].prev = node[now].prev;
		now = node[now].next;
	}

	for(int i = 0; i < q; ++i){
		int b;
		cin >> b;
		cout << node[b].f << endl;
		//node[b].out();
	}

	return 0;
}

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

	int n, m, q;
	cin >> n >> m >> q;

	int a[MAX_N];
	for(int i = 0; i < m; ++i){
		cin >> a[i];
	}

	list<int> l;
	for(int i = 0; i < n; ++i){
		l.push_back(i);
	}

	list<int>::iterator it = l.begin();

	int v[MAX_N];
	fill(v, v + n, 1);
	for(int i = 0; i < m; ++i){
		if(a[i] % 2 == 0){
			for(int j = 0; j < a[i]; ++j){
				it++;
				if(it == l.end()){
					it = l.begin();
				}
			}
		}
		else {
			for(int j = 0; j < a[i]; ++j){
				if(it == l.begin()){
					it = l.end();
				}
				it--;
			}
		}

		v[*it] = 0;
		it = l.erase(it);
		if(it == l.end()){
			it = l.begin();
		}
	}

	for(int i = 0; i < q; ++i){
		int b;
		cin >> b;
		cout << v[b] << endl;
	}

	return 0;
}
*/

Measured memory_bytes: 4316
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define pb push_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define Forn(i, a) for(int i=1; i<=a; i++)
#define read(x) ((scanf("%s", &_), (x) = _))
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
#define HASH 1543 
#define FAST ios_base::sync_with_stdio(0)

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;
typedef vector<vector<ll> > matrix;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0;
	}
    do 
	{
		x=(x<<3)+(x<<1)+(c^48); 
	}
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}
using namespace std;

int N, K, a[100005], res=1e9; 

inline void calcu(int x, int y)
{
    if(x==y)
    {
        res=min(res, abs(x));
        return;
    }
    if(x==0)
    {
        res=min(res, y);
        return;
    }
    if(y==0)
    {
        res=min(res, -x);
        return;
    }
    if(x<0&&y<0)
    {
        res=min(res, -x);
        return;
    }
    if(x<0&&y>0)
    {
        res=min(res, min(-x*2+y, -x+y*2));
        return;
    }
    if(x>0&&y>0)
    {
        res=min(res, y);
        return;
    }
}

int main()
{
    N=in(), K=in();
    forn(i, N)
        a[i]=in();
    for(int i=0; i+K-1<N; i++)
    {
        int l=i, r=l+K-1;
        calcu(a[l], a[r]);
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FOR(i,n,m) for(int i = m;i<n;i++)
#define rep(i,n) FOR(i,n,0)
#define ll long long
#define INF (1e9)
#define PI (acos(-1))
int dy[] = { 0, 0, 1, -1 };
int dx[] = { 1, -1, 0, 0 };
using namespace std;
int h, w;
char s[52][52];
int main() {
	rep(i, 52)rep(j, 52)s[i][j] = '.';
	cin >> h >> w;
	rep(i, h)rep(j, w)cin >> s[i][j];
	rep(i, h)rep(j, w) {
		if (s[i][j] != '#')continue;
		int flg = false;
		rep(k, 4)if(s[i + dx[k]][j + dy[k]] == '#')flg = true;
		if (flg)continue;
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int dp[100001];
vector<int> adj[100001];
ll dfs(int s)
{
    if (s < 1)
        return 0;
    if (dp[s] != -1)
        return dp[s];
    if (adj[s].size() == 0)
    {
        dp[s] = 0;
    }
    else
    {
        for (auto it = adj[s].begin(); it != adj[s].end(); it++)
        {
            dp[s] = max((ll)dp[s], 1 + dfs(*it));
        }
    }

    return dp[s];
}

int main()
{

    int v;
    int e;
    cin >> v;
    cin >> e;
    memset(dp,-1,sizeof(dp));
    for (int i = 1; i <= e; i++)
    {
        int a;
        int b;
        cin >> a;
        cin >> b;
        adj[a].push_back(b);
    }

    for (int i = 1; i <= v; i++)
    {
        if (dp[i] == -1)
        {
            dfs(i);
        }
    }

    int *ma;
    ma = max_element(dp, dp + (v + 1));
    cout << *ma << "\n";
}


Measured memory_bytes: 7424
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<tuple>
using namespace std;


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

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


int main(){
  int a, b;
  vector<int> v(4);
  v[1] = 1;
  v[2] = 2;
  v[3] = 3;
  cin >> a >> b;
  v[a] = 0;
  v[b] = 0;
  int ans = 0;
  rep(i, 4){
    ans += v[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
N,A,B,C,D=map(int, input().split())
S=input()
result = ""

for i in range(A,max(C,D)-1):
    if S[i:i+2]=="##":
        result ="No"
        break

if result == "":
    if C < D:
        result ="Yes"
    else: # D < C
        if S[B-2] == "." and S[B] == ".":
            result = "Yes"
        else:
            for i in range(B-2,D-1):
                if S[i:i+3] == "...":
                    result = "Yes"
            #if S[B-2:D+1].count('...')>0:
            #    result = 'Yes'
      
if result == "":
    result = "No"

print(result)


Measured memory_bytes: 3572
#include <iostream>
#include <istream>
#include <ostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

// 5^12
// 0 -
// 1 A
// 2 G
// 3 C
// 4 T

// AAA = 1 * 4^0 + 1 * 4^1 + 1 * 4^3
// data[x] == 0 : none
// data[x] == 1 : found

int encode_ch(char ch) {
	switch (ch) {
	case 'A': return 1;
	case 'G': return 2;
	case 'C': return 3;
	case 'T': return 4;
	default: return 0;
	}
}

int encode(std::string str) {
	int x = 0;
	for (int i = 0; i < str.size(); i++) {
		x += encode_ch(str[str.size() - 1 - i]) * std::pow(4, i);
	}
	return x;
}

int main() {

	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	
	std::vector<bool> d;
	d.resize(244140625, false);//5^12 = 244140625

	int n;
	std::cin >> n;

	for (int i = 0; i < n; i++) {
		std::string op;
		std::string w;
		std::cin >> op >> w;

		if (op == "insert") {
			d[encode(w)] = true;
		}
		else if (op == "find") {
			std::cout << (d[encode(w)] ? "yes" : "no") << std::endl;
		}
	}
	return 0;
}

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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define FOR(i,l,r) for(long long i=l; i<r; i++)
#define FOR_REV(i,r,l) for(long long i=r; i>=l; i--)
#define pb push_back
#define mp make_pair

int main()
{
    ll n;
    cin>>n;

    if (n == 2)
    {
        cout<<1<<endl;
        return 0;
    }

    ll ans = 2;

    // Checking for N-1
    for (ll i=2; i*i<=n-1; i++)
    {
        if ((n-1)%i == 0)
        {
            ans += 2;
        }
        if (i*i == n-1)
        {
            ans--;
        }
    }

    //Check for N
    for (ll i=2; i*i<=n; i++)
    {
        if (n%i == 0)
        {
            ll x = n;
            while (x%i == 0)
            {
                x = x/i;
            }
            if (x%i == 1)
            {
                ans += 1;
            }

            x = n;
            ll d = n/i;
            if (i*i != n)
            {
                while (x%d == 0)
                {
                    x = x/d;
                }
                if (x%d == 1)
                {
                    ans += 1;
                }
            }
        }
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	ll RT,RA;
	cin >> N;
	cin >> RT >> RA;
	FOR(i,0,N-1){
		ll t,a;
		cin >> t >> a;
		ll k = max((RT+t-1)/t,(RA+a-1)/a);
		RT = t*k;
		RA = a*k;
	}
	cout << RA+RT << endl;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

long long gcd (long long a, long long b ){
  int c;
  while ( a != 0 ) {
     c = a; a = b%a;  b = c;
  }
  return b;
}

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> a;

	ll ma = -1;
	for(int i=0; i<n; i++){
		ll t;
		cin >> t;
		a.pb(t);
		ma = max(ma, t);
	}

	ll p = a[0];
	for(int i=1; i<n; i++){
		p = gcd(p, a[i]);
	}

	if(k % p == 0 && k <= ma) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	
	return 0;
}


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

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int main(){
    string s;
    vector<char> v;
    bool flag=true;
    cin >> s;

    for(int i=0;i<s.size();i++){
        v.push_back(s[i]);
    }
    sort(v.begin(),v.end());

    for(int i=0;i<s.size()-1;i++){
        if(v[i]==v[i+1]){
            flag=false;
            break;
        }
    }

    if(flag)
        printf("yes\n");
    else
        printf("no\n");    

    return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;





signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<bool> isprime(200000, true);
	isprime[0] = isprime[1] = false;
	rep(i, 200000) {
		if (isprime[i]) {
			int k = 2 * i;
			while (k < 200000) {
				isprime[k] = false;
				k += i;
			}
		}
	}
	int x; cin >> x;
	for (int i = x; i < 200000; i++) {
		if (isprime[i]) {
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var nl = Console.ReadLine().Split();
        var n = int.Parse(nl[0]);
        var l = int.Parse(nl[1]);

        var s = new string[n];
        for (int i = 0; i < n; i++)
        {
            s[i] = Console.ReadLine();
        }

        Array.Sort(s);

        var ans = "";
        for (int i = 0; i < n; i++)
        {
            ans += s[i];
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13408
<?php

(new Main)->execute();


class Rectangle
{
    private $height;
    private $width;
    private $style;

    private $rectangle = [];

    public function __construct($height, $width, $style)
    {
        $this->height = $height;
        $this->width  = $width;
        $this->style  = $style;

        $this->rectangle = $this->make();
    }

    private function make()
    {
        $rectangle = [];
        for ($height = 0; $height < $this->height; $height++) {
            $rectangle[$height] = str_repeat($this->style, $this->width);
        }
        return $rectangle;
    }

    private function setColsInnerFrame($thickness, $style)
    {
        foreach ($this->rectangle as $height => $_) {
            for ($width = 0; $width < $thickness; $width++) {
                $this->rectangle[$height][$width]                = $style;
                $this->rectangle[$height][$this->width - $width - 1] = $style;
            }
        }
    }

    private function setRowsInnerFrame($thickness, $style)
    {
        foreach ($this->rectangle as $height => $_) {
            if ($height >= $thickness) { return; }

            $this->rectangle[$height]                 = str_repeat($style, $this->width);
            $this->rectangle[$this->height - $height - 1] = str_repeat($style, $this->width);
        }
    }

    public function setInnerFrame($thickness = 1, $style = '#')
    {
        if ($thickness > $this->width) {
            $thickness = $this->width;
        }

        $this->setRowsInnerFrame($thickness, $style);
        $this->setColsInnerFrame($thickness, $style);

        return $this;
    }

    public function get()
    {
        return implode(PHP_EOL, $this->rectangle).PHP_EOL;
    }
}

class Main
{
    public function execute()
    {
        while (true) {
            list($height, $width) = $this->getStdinExplodedBy(' ');
            if ($this->invalid($height, $width)) { return; }

            $rectangle = (new Rectangle($height, $width, '.'))
                ->setInnerFrame()
                ->get();

            $this->draw($rectangle);
        }
    }

    private function getStdinExplodedBy($delimiter)
    {
        return explode($delimiter, trim(fgets(STDIN)));
    }

    private function invalid($height, $width)
    {
        return $height == 0 && $width == 0;
    }

    public function draw($shape)
    {
        echo $shape, PHP_EOL;
    }
}

Measured memory_bytes: 15520
#include <iostream>
using namespace std;
using ll = long long;
    const int AMAX = 100000;
    ll cnt[AMAX + 1];
int main(void){
    int n;
    ll k;
    cin >> n >> k;
    
    for(int i = 0;i < n;i++){
        int a,b;
        cin >> a >> b;
        cnt[a] += b;
    }
    
    for(int ans = 1;ans <= AMAX;ans++){
        if(k <= cnt[ans]){
            cout << ans << endl;
            break;
        }
        k -= cnt[ans];
    }
    
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
    int n;
    cin>>n;
    V<ll> a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    priority_queue<P> q;
    for(int i=0;i<n;i++){
        if(a[i]==b[i]){
            q.emplace(b[i],i);
        }
    }
    V<bool> ok(n,false);
    for(int i=0;i<2*n;i++){
        int ind=i%n;
        while(q.size()&&ok[q.top().se])q.pop();
        if(q.size()&&a[ind]!=q.top().fi&&b[ind]!=a[q.top().se]){
            swap(b[ind],b[q.top().se]);
            ok[ind]=true;ok[q.top().se]=true;
            q.pop();
        }
    }
    if(q.size()){
        cout<<"No"<<"\n";
    }else{
        cout<<"Yes"<<"\n";
        for(int i=0;i<n;i++){
            cout<<b[i]<<" ";
        }
        cout<<"\n";
    }
}


Measured memory_bytes: 10564
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"


template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef cc_hash_table<int, int, hash<int > > ht;


#define int long long 
#define  st first
#define  nd second

const int M = 1000000007;
const int  maxn = 100001;
const int  inf =  1e16;
int dp[2001];

void solve(){
   dp[0]=1;
   dp[1]=0;
   dp[2]=0;
   for(int i =3 ; i<=2000 ; i++){
	   for(int j=i-3;j>=0;j-=1){
		   dp[i]= (dp[i] + dp[j])%M;
	   }
   }
   int s ;
   cin >> s ;
   cout << dp[s];

}
int32_t main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int te ; 
 // cin >> te ;
  te = 1; 
  while(te--){
    solve();
  }
  
  }

  
  

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

vector<pair<int, int>> coords;
vector<vector<int>> prefix_sum;

int manhattan(pair<int, int> a, pair<int, int> b){
	return abs(a.first - b.first) + abs(a.second - b.second);
}

int crank(int label, int D){
	return (label - label % D) / D;
}

int main(){
	int H, W, D;
	cin >> H >> W >> D;
	coords.resize(H * W + 3);
	prefix_sum.assign(D + 1, vector<int>());
	int n;
	for (int i = 0; i < H; ++i){
		for (int j = 0; j < W; ++j){
			cin >> n;
			n--;
			coords[n] = {i, j};
		}
	}

	for (int i = 0; i < D; ++i){
		prefix_sum[i].push_back(0);
		for (int j = i + D; j < H * W; j+=D){
			int next_dist = manhattan(coords[j - D], coords[j]);
			prefix_sum[i].push_back(prefix_sum[i].back() + next_dist);
		}
	}
	int q; cin >> q;
	int L, R;
	while(q--){
		cin >> L >> R;
		L--; R--;
		int modulo = L % D;
		vector<int>& psum = prefix_sum[modulo];
		cout << psum[crank(R, D)] - psum[crank(L, D)] << endl;
	}
}

Measured memory_bytes: 6016
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int X;
  cin>>X;
  if(X/100*100<=X&&X<=X/100*105) cout<<1;
  else cout<<0;
return 0;}


Measured memory_bytes: 3616
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        scan.close();

        System.out.println(c + " " + a + " " +  b);
    }
}

Measured memory_bytes: 22228
import java.util.Scanner; 

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s,h,m;
        s = sc.nextInt();
        m = s / 60;
        s = s%60;
        h = m /60;
        m = m%60;
        System.out.println(h+":"+ m +":" + s);

    }
    
}



Measured memory_bytes: 26168
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n;
    cin >> n;

    vector<ll> a(n), b(n);
    rep(i, n)cin >> a[i] >> b[i];

    vector<ll> ord(n);
    iota(ALL(ord), 0);
    sort(ALL(ord), [&](ll x, ll y){
        return b[x] < b[y];
    });

    ll time = 0;
    rep(i, n){
        ll pos = ord[i];

        time += a[pos];

        if(time > b[pos]){
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";
}

Measured memory_bytes: 7972
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  set<int> st;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    if(st.find(a) != st.end()){
      st.erase(a);
    }else{
      st.insert(a);
    }
  }
  cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
 
using namespace std;

const int N = 323;
const ll mod = 1e9 + 7;             

double dp[N][N][N];
int cn[4], n;

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
                
    cin >> n;
    for(int i = 1;i <= n;i++){
    	int x;
    	cin >> x;
    	cn[x]++;
    }

    dp[0][0][0] = 0;
    for(int k = 0;k <= n;k++){
    	for(int j = 0;j <= n;j++){
    		for(int i = 0;i <= n;i++){
    			 if(i + j + k == 0)
    		 		continue;
    			 double a = 0;
    			 if(i > 0)
    			 	a = dp[i - 1][j][k];
    			 double b = 0;
    			 if(j > 0)
    			 	b = dp[i + 1][j - 1][k];
    			 double c = 0;
    			 if(k > 0)
    			 	c = dp[i][j + 1][k - 1];
    			 dp[i][j][k] = (i * a + b * j + c * k + n)  / (i + j + k + 0.0);
    			 //cout << i << " " << j << " " << k << endl;
    		}
    	}
    }

    cout << setprecision(12) << fixed;
    cout << dp[cn[1]][cn[2]][cn[3]];
}

Measured memory_bytes: 245888
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
a = Counter(A)
tmp = 0
for x, y in a.items():
    if y != 0:
        tmp += y*(y-1)//2
ans = {}
for x, y in a.items():
    if y > 1:
        ans[x] = tmp-(y-1)
    else:
        ans[x] = tmp
for x in A:
    print(ans[x])


Measured memory_bytes: 30908
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

    int N;
    cin >> N;

    const long double btc2jpy = 380000.0;

    long double x, ans = 0.;
    string u;
    REPinit(i, 0, N) {
        cin >> x >> u;
        if (u == "JPY") ans += x;
        else ans += (x * btc2jpy);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
#define RER(i, n) for(int i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;

signed main(){
	cin >> n;
	if(n == 3) cout << "2 5 63" << endl;
	else if(n == 4) cout << "2 5 20 63" << endl;
	else if(n == 5) cout << "2 5 20 30 63" << endl;
	else{
		vector<double> v;
		REP(i, n/4+1){
			if(v.size() < n) v.pb(6 * i + 2);
			if(v.size() < n) v.pb(6 * i + 3);
			if(v.size() < n) v.pb(6 * i + 4);
			if(v.size() < n) v.pb(6 * i + 6);
		}
		int s = accumulate(ALL(v), 0) % 6;
		if(s == 0); 
		else if(s == 2) v[4] = 6 * (v.size() / 4 + 1);
		else if(s == 3) v[5] = 6 * (v.size() / 4 + 1);
		else if(s == 5) v[n-1]++;
		for(auto c: v) cout << c << " ";
		cout << endl;
		// bool up = false;
		// for(auto c: v) up |= (c > 30000);
		// if(!up) cout << "success" << endl;
		// else cout << "fali" << endl;
	}
    return 0;
}

Measured memory_bytes: 640