akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

vector<pair<ll, pll> > v;
ll l[N], r[N], c[N], d[N], ans[N];
int main()
{
	int n, q;
	cin >> n >> q;
	for(int i = 1; i <= n; i ++)
	{
		cin >> l[i] >> r[i] >> c[i];
		v.pb(M(l[i]-c[i],M(-1, c[i])));
		v.pb(M(r[i]-c[i],M(1, c[i])));
	}
	for(int i = 1; i <= q; i ++)
	{
		cin >> d[i];
		v.pb(M(d[i], M(200, i)));
	}
	sort all(v);
	multiset<ll> s;
	for(auto it : v)
	{
		ll x = it.F, k = it.S.S, ty = it.S.F;
		if(ty == -1)
		{
			s.insert(k);
		}
		else
		if(ty == 1)
		{
			s.erase(s.find(k));
		}
		else
		{
			ll o = 0;
			if(s.empty())
				ans[k]=-1;
			else
				ans[k] = *s.begin();
		}
	}
	for(int i = 1; i <= q; i ++)
		cout << ans[i] << '\n';





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

void solve(long long n, std::vector<long long> a) {
  ll currSum = 0;
  ll ops = 0;
  for (int i = 0; i < a.size(); i++) {
    currSum += a[i];
    if (i % 2) {
      if (currSum <= 0) {
        ops += abs(currSum) + 1;
        currSum = 1;
      }
    } else {
      if (currSum >= 0) {
        ops += abs(currSum) + 1;
        currSum = -1;
      }
    }
  }
  currSum = 0;
  ll ops2 = 0;
  for (int i = 0; i < a.size(); i++) {
    currSum += a[i];
    if ((i % 2) == 0) {
      if (currSum <= 0) {
        ops2 += abs(currSum) + 1;
        currSum = 1;
      }
    } else {
      if (currSum >= 0) {
        ops2 += abs(currSum) + 1;
        currSum = -1;
      }
    }
  }
  cout <<  min(ops, ops2) << endl;
}

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

  long long n;
  scanf("%lld", &n);
  std::vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  solve(n, std::move(a));
  return 0;
}


Measured memory_bytes: 1024
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long;

const long long MOD = 1000000007;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


void solve(long long n, std::vector<long long> a){
    vector<int> cnt(n + 1, 0);
    cnt[0] = 3;
    mint ans = 1;
    for(auto& x : a){
        if(cnt[x] == 0){
            ans = 0;
            break;
        }
        ans *= cnt[x];
        --cnt[x];
        ++cnt[x + 1];
    }
    cout << *ans << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

int main() {
    string S,T;
    cin >> S >> T;
    int size = 0;
    size = S.length();
    int count = 0;
    
    if(S.compare(T)==0){
        cout << "0" << endl;
        
    }else{
    
    for(int i = 0;i<size;i++){
        if(S.at(i)!=T.at(i)){
            count++;
        }
    }
    cout << count << endl;
    }
    
    
    
}

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

int main() {
  stack<int> s;
  int l;
  while(cin>>l){
    if(l==0){
      cout<<s.top()<<endl;
      s.pop();
    }else{
      s.push(l);
    }
  }
  return 0;
}




Measured memory_bytes: 3024
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	static class Restaurant {
		private int num;
		private int point;
		private String name;

		public Restaurant(int num, String name, int point) {
			this.num = num;
			this.point = point;
			this.name = name;
		}

		public int getNum() {
			return num;
		}

		public int getPoint() {
			return point;
		}

		public String getName() {
			return name;
		}
	}

	static class Sorter implements Comparator<Restaurant> {
		public int compare(Restaurant c1, Restaurant c2) {
			int ret = 0;
			if(c1.getName().compareTo(c2.getName()) == 0){
				if (c1.getPoint() < c2.getPoint()) {
					ret = 1;
				} else if (c1.getPoint() > c2.getPoint()) {
					ret = -1;
				}
			}else{
				ret = c1.getName().compareTo(c2.getName());
			}

			return ret;
		}
	}

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

		// 整数の入力
		int N = sc.nextInt();
		ArrayList<Restaurant> target = new ArrayList<Restaurant>();

		for (int i = 0; i < N; i++) {
			target.add(new Restaurant(i + 1, sc.next(), sc.nextInt()));
		}

		Collections.sort(target, new Sorter());

		for(Restaurant c : target) {
            System.out.println(c.getNum());
        }
	}
}


Measured memory_bytes: 21712
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long ans = 0;
    int N,M;
    cin >> N >> M;
    vector<int> X(M),d(M-1);
    for (int i=0;i<M;i++) {
        cin >> X[i];
    }
    if (N < M) {
        sort(X.begin(), X.end());
        for (int i=0;i<M-1;i++) {
            d[i] = X[i+1] - X[i];
        }
        sort(d.begin(), d.end());
        for (int i=0;i<M-N;i++) {
            ans += d[i];
        }
    }
    cout << ans << '\n';
    return 0;
}

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

int main(){
  int n,ans=0;
  cin >> n;
  vector<int> x(n);
  for(int i = 0; i < n; i++){
    cin >> x.at(i);
  }
  
  int p = 0;

  sort(x.begin(), x.end());
  p = x.at(0);
  int min = 1000000000;

  while(p <= x.at(n-1)){
    ans = 0;
    for(int i = 0; i < n; i++){
      ans += (x.at(i) - p) * (x.at(i) - p);
    }
    p++;
    if(min > ans) min = ans;
  }
  cout << min << endl;
  return 0;
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int H,W;

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

	cin >> H >> W;
	vector<string> board(H);
	int cnt = 0;
	FOR(i,0,H){
		cin >> board [i];
		cnt += count(ALL(board [i]),'#');
	}
	if(cnt == H + W - 1){
		cout << "Possible" << endl;
	}
	else{
		cout << "Impossible" << endl;
	}
	

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination1(int, int);
};
int Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_Curtain(void) {

	int A, B; cin >> A >> B;
	
	cout << ((A > B * 2) ? A - B * 2 : 0) << flush;
	return;
}

void B_TAKOYAKI_FESTIVAL(void) {

	int N; cin >> N;
	vector<int> d(N); for (int& it : d)cin >> it;

	int sum = 0;
	sum = (int)pow(accumulate(d.begin(), d.end(), 0), 2);
	for (int it : d) sum -= it * it;
	sum /= 2;

	cout << sum << flush;
	return;
}

void C_Slimes(void) {

	int N; cin >> N;
	vector<char> color(N); for (char& it : color)cin >> it;

	int counter = 1;
	for (int index = 1; index < N; index++) {
		if (color[index] != color[index - 1]) counter++;
	}

	cout << counter << flush;
	return;
}

int main(void) {

	//A_Curtain();
	//B_TAKOYAKI_FESTIVAL();
	C_Slimes();
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    int a, b, c;
    cin >> a >> b >> c;

    if(a == b) cout << c << endl;
    if(a == c) cout << b << endl;
    if(c == b) cout << a << endl;

    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)
N,M,K = map(int, input().split())
V = []

color = [-1]*N
V_block = []

#各連結成分の次元テーブル
dic = {}

dim = 0
#深さ優先探索
def dfs(node, c):
    global dim

    if color[node]!=-1:
        return
    color[node] = c
    dim = dim + 1
    for next_node in V[node]:
        dfs(next_node, c)
    return

for _ in range(N):
    V.append(set())
    V_block.append(set())
for _ in range(M):
    a,b = map(int, input().split())
    V[a-1].add(b-1)
    V[b-1].add(a-1)

#一旦捨てる
for _ in range(K):
    c,d = map(int, input().split())
    V_block[c-1].add(d-1)
    V_block[d-1].add(c-1)
    
c = 0
for node in range(N):
    if color[node]!=-1:
        continue
    dim = 0
    dfs(node, c)
    dic[c] = dim

    c = c + 1

ans_list = []
for node in range(N):
    num = 0
    for block_node in V_block[node]:
        if color[node]==color[block_node]:
            num = num + 1
    ans_list.append(dic[color[node]]-num-len(V[node])-1)

print(*ans_list)



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

int main(void)
{
	int N, M;
	int i, a;

	cin >> N >> M;

	for (i = 0;i < M;i++)
	{
		cin >> a;
		N -= a;
	}

	if (N < 0)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << N << endl;
	}
	
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[300100],he,mi,MOD=1000000007LL;
bool wei[300100][80];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		he+=a[i];
		he%=MOD;
		int cur=0;
		while(a[i]){
			wei[i][cur]=(a[i]&1LL);
			a[i]/=2LL;
			cur++;
		}
	}
	he*=(n-1);
	he%=MOD;
	long long powe=1LL;
	for(int i=0;i<=70;i++){
		int cnt=0;
		for(int j=1;j<=n;j++)
			cnt+=wei[j][i];
		mi=(mi+(((long long)(cnt)*(long long)(cnt-1))%MOD*powe)%MOD)%MOD;
		powe*=2LL;
		powe%=MOD;
	}
	he-=mi;
	he+=MOD;
	he%=MOD;
	cout<<he<<endl;
	return 0;
}


Measured memory_bytes: 26112
n=int(input())
list=[]
for i in range(n):
    a,b=input().split()
    b=int(b)
    list.append([a,b,i+1])

tmp = sorted(list, key=lambda x:x[1], reverse=True)
ans=sorted(tmp, key=lambda x:x[0])

for i in ans:
    print(i[2])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mp make_pair
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-9;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T& t,const V& v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T& t,const V& v){for(auto &e:t)fill_v(e,v);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n;cin>>n;
    vector<int> c(n+10),b(200010,-1);
    for(int i=1;i<=n;i++)cin>>c[i];
    vector<ll> dp(n+10);
    dp[0]=1;
    for(int i=1;i<=n;i++){
        dp[i]+=dp[i-1];
        if(b[c[i]]!=-1&&b[c[i]]!=i-1){
            dp[i]+=dp[b[c[i]]];
        }
        b[c[i]]=i;
        dp[i]%=MOD;
    }
    cout<<dp[n]<<endl;
}

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

template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }

priority_queue<pair<long long, int>>pq;
int n, g, d[16], c[16], p, np;
long long dist[200050], e, ne;
const long long INF = (long long)1e16;
int main()
{
	cin >> n >> g;
	for (int i = 0; i < n; i++)
		cin >> d[i] >> c[i];
	for (int i = 0; i < 200000; i++)
		dist[i] = INF;
	dist[g] = 0;
	pq.emplace(0, g);
	while (!pq.empty())
	{
		p = pq.top().second;
		e = -pq.top().first;
		pq.pop();
		if (dist[p] < e)
			continue;
		for (int i = 0; i < n; i++)
		{
			np = abs(p + d[i]);
			ne = e + c[i];
			if (np >= 200050)
				continue;
			if (dist[np]>ne)
			{
				dist[np] = ne;
				pq.emplace(-ne, np);
			}
		}
		for (int i = 0; i < n; i++)
		{
			np = abs(p - d[i]);
			ne = e + c[i];
			if (np >= 200050)
				continue;
			if (dist[np]>ne)
			{
				dist[np] = ne;
				pq.emplace(-ne, np);
			}
		}
	}
	if (dist[0] >= INF)dist[0] = -1;
	cout << dist[0] << endl;

	return 0;
}


Measured memory_bytes: 7212
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin>>N;
    string S; cin>>S;
    int maximum=0;
    for(int i=1;i<N-1;i++){
        vector<int> a(123,0);
        vector<int> b(123,0);
        for(int j=0;j<i;j++){
            a[S[j]]=1;
        }
        for(int k=i;k<N;k++){
            b[S[k]]=1;
        }
        int count=0;
        for(int l=97;l<=122;l++){
            if(a[l]==b[l]&&a[l]==1){
                count++;
            }
        }
        maximum=max(maximum,count);
    }

    cout<<maximum;
    return 0;
}

Measured memory_bytes: 256
from functools import lru_cache


class MatrixRKSearch:
    shift = 40
    size = 33554393

    def __init__(self, m1, m2):
        self.haystack = self._encode(m1)
        self.needle = self._encode(m2)

    def find(self):
        i1, j1 = len(self.haystack), len(self.haystack[0])
        i2, j2 = len(self.needle), len(self.needle[0])
        if i1 < i2 or j1 < j2:
            return

        hs1 = [self._hash(s, j2) for s in self.haystack]
        hs2 = [self._hash(s, j2) for s in self.needle]
        dm = self.shift**(j2-1) % self.size

        for j in range(j1-j2+1):
            for i in range(i1-i2+1):
                if hs1[i:i+i2] == hs2:
                    yield (i, j)
            if j+j2 < j1:
                for i in range(i1):
                    hs1[i] = self._shift(hs1[i], self.haystack[i][j+j2],
                                         self.haystack[i][j], dm)

    def _shift(self, h, add, remove, dm):
        return ((h - remove*dm) * self.shift + add) % self.size

    def _hash(self, s, length):
        h = 0
        for i in range(length):
            h = (h * self.shift + s[i]) % self.size

        return h

    def _encode(cls, m):
        basea = ord('a')
        based = ord('0')
        es = []
        for s in m:
            bs = []
            for c in s:
                if c.isdigit():
                    bs.append(ord(c) - based + 27)
                else:
                    bs.append(ord(c) - basea)
            es.append(bs)

        return es


def search(matrix, pattern):
    """Search matrix for pattern
    """
    def _check(y, x):
        for m in range(py):
            for n in range(px):
                if matrix[y+m][x+n] != pattern[m][n]:
                    return False
        return True

    mx = len(matrix[0])
    my = len(matrix)
    px = len(pattern[0])
    py = len(pattern)
    for i in range(my-py+1):
        for j in range(mx-px+1):
            if _check(i, j):
                yield (i, j)


def run():
    h, w = [int(x) for x in input().split()]
    m = []

    for _ in range(h):
        m.append(input())

    r, c = [int(x) for x in input().split()]
    pt = []

    for _ in range(r):
        pt.append(input())

    sch = MatrixRKSearch(m, pt)
    result = []
    for i, j in sch.find():
        result.append((i, j))

    result.sort()
    for i, j in result:
        print(i, j)


if __name__ == '__main__':
    run()



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

int main(){
	int a, b, c;
	cin >> a >> b >>c;
    if(a > b) swap(a,b);
    if(b > c) swap(b,c);
    if(a > b) swap(a,b);
	printf("%d %d %d\n", a, b, c);
	return 0;
}

Measured memory_bytes: 1144
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);		
		int chairLen = sc.nextInt();
		int humanLen = sc.nextInt();
		int width = sc.nextInt();
		
		int firstLen = width;
		int len = humanLen + width;
		int cnt = 0;
		while (firstLen + cnt * len <= chairLen) {
			cnt++;
		}
		System.out.println(cnt-1);
		return;
	}
}




Measured memory_bytes: 22996
import itertools

N, X, Y = map(int, input().split())

# dp = [[float('inf')] * (N+1) for _ in range(N+1)]
# # dp[Y][X] = 1
# dp[X][Y] = 1

# for i in range(1,N+1):
#     for j in range(i,N+1):
#         if i == j:
#             dp[i][j] = 0
#         elif i == X and j == Y:
#             dp[X][Y] = 1
#         elif i <= X:
#             dp[i][j] = min(dp[i][j-1] + 1, dp[i][X] + abs(Y - j) + 1)
#         else:
#             dp[i][j] = min(dp[i][j-1]+ 1, abs(i - X)+ abs(Y - j) + 1 )

# dp = list(itertools.chain.from_iterable(dp))
# for i in range(1,N):
#     print(dp.count(i))

result = [0] * N

for i in range(1, N):
    for j in range(i+1, N+1):
        dist = min(abs(j-i), abs(X-i) + 1 + abs(j-Y), abs(Y-i)+1+abs(j-X))
        result[dist] += 1

for i in range(1, N):
    print(result[i])


Measured memory_bytes: 47836
<?php
$ans = 0;
define('MAX', 2000);

fscanf(STDIN, "%d", $N);
$L = array_map('intval', explode(" ", trim(fgets(STDIN))));
$max = max($L);
$sum = array_pad(array(), MAX + 1, 0);
foreach ($L as $v) {
    $sum[$v]++;
}
for ($i = 1; $i <= MAX; $i++) {
    $sum[$i] = $sum[$i - 1] + $sum[$i];
}
sort($L);
// var_dump($L);
// var_dump($sum);
// a<b+c
// b<c+a
// c<a+b
// var_dump($sum);
for ($i = 0; $i < $N - 2; $i++) {
    for ($j = $i + 1; $j < $N - 1; $j++) {
        $x = $L[$i] + $L[$j] - 1;
        $ans += $sum[$x] - $j - 1;
        // printf("i:%d j:%d L[i]:%d L[j]:%d x:%d ans:%d\n", $i, $j, $L[$i], $L[$j], $L[$i] + $L[$j] - 1, $ans);
    }
}
echo $ans;


Measured memory_bytes: 4728
#include <stdio.h>
#include <vector>


int getDiv2Count(int a) {

	int res = 0;
	while(a%2==0) {
		res += 1;
		a = a/2;
	}

	return res;
}

int main() {

	int n;
	std::vector<int> a;

	scanf("%d", &n);

	int tmp;
	for(int i=0;i<n;i++) {
		scanf("%d", &tmp);
		a.push_back(tmp);
	}

	int res = 0;
	for(auto itr = a.begin();itr != a.end();++itr) {
		tmp = getDiv2Count(*itr);
		res += tmp;
	}


	printf("%d\n", res);

	return 0;
}


Measured memory_bytes: 384
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
 

int main() {
  string s;
  cin >> s;
  bool flag = true;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != s[s.size() - i - 1]) {
      flag = false;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
A1=[]
A2=[]
A3=[]


a11, a12, a13 = map(int,input().split())
A1.append(a11)
A1.append(a12)
A1.append(a13)

a21, a22, a23 = map(int,input().split())
A2.append(a21)
A2.append(a22)
A2.append(a23)

a31, a32, a33 = map(int,input().split())
A3.append(a31)
A3.append(a32)
A3.append(a33)

N = int(input())
for i in range(N):
    b = int(input())
    if b==A1[0]:
        A1[0] ="OK"
    if b==A1[1]:
        A1[1]="OK"
    if b==A1[2]:
        A1[2]="OK"
    if b==A2[0]:
        A2[0] ="OK"
    if b==A2[1]:
        A2[1]="OK"
    if b==A2[2]:
        A2[2]="OK"
    if b==A3[0]:
        A3[0] ="OK"
    if b==A3[1]:
        A3[1]="OK"
    if b==A3[2]:
        A3[2]="OK"

ans ="No"
if A1[0]==A1[1] and A1[0]==A1[2]:
    ans ="Yes"
if A2[0]==A2[1] and A2[0]==A2[2]:
    ans ="Yes"
if A3[0]==A3[1] and A3[0]==A3[2]:
    ans ="Yes"

if A1[0]==A2[0] and A1[0]==A3[0]:
    ans ="Yes"
if A1[1]==A2[1] and A1[1]==A3[1]:
    ans ="Yes"
if A1[2]==A2[2] and A1[2]==A3[2]:
    ans ="Yes"

if A1[0]==A2[1] and A1[0]==A3[2]:
    ans ="Yes"
if A1[2]==A2[1] and A1[2]==A3[0]:
    ans ="Yes"

print(ans)


Measured memory_bytes: 3192
K = int(input())
A, B = (int(x) for x in input().split())

#倍数が何個含まれるかで考える場合
# a = A // K
# b = B // K
# 
# if b-a >= 1 or K == 1:
#     print("OK")
# elif B%K==0 or A%K==0:
#     print("OK")
# else:
#     print("NG")

#B以下の最大のKの倍数がAを超えるかどうかで考える場合
#B以下の最大のkの倍数
maxbk = (B//K)*K

if maxbk >= A:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;


int main() {
    int N,M;
    cin>>N>>M;
    vector<int> cnt(N,1);
    vector<bool> poss(N,false);
    poss[0]=true;
    int x,y;
    for (int i = 0; i < M; ++i) {
        cin>>x>>y; --x; --y;
        --cnt[x]; ++cnt[y];
        if(cnt[x]>0){
            if(poss[x]) poss[y]=true;
        }else{
            if(poss[x]){
                poss[x]=false;
                poss[y]=true;
            }
        }
    }

    int ans=0;
    for (int i = 0; i < N; ++i) {
        if(poss[i]) ++ans;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
signed main() {
  ios::sync_with_stdio(false);
  int N; cin >> N;
  int ans;
  for(int k = 1; ; ++k) {
    if(k * (k + 1) / 2 >= N) {
      ans = k;
      break;
    }
  }
  for(int k = 1; k <= ans; ++k) {
    if(ans * (ans + 1) / 2 - k == N) {
    }
    else {
      cout << k << endl;
    }
  }
}


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

signed main(){
  
  int r, g, b, n;
  cin>>r>>g>>b>>n;
  
  int ans = 0;
  
  for(int i=0;i<=3000;i++){
    
    for(int j=0;j<=3000;j++){
      
      int k = n - ( i*r + j*g );
      
      if( 0 <= k && k % b == 0 ){
	
	ans++;
	
      }
      
    }
    
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import std.stdio;

void main() {
	int animals, legs;
	readf("%s %s", &animals, &legs);

	if (legs % 2 != 0) {
		writeln("No");
		return;
	}

	auto turtles = legs / 2 - animals;

	if (turtles >= 0 && turtles <= animals) {
		writeln("Yes");
	} else {
		writeln("No");
	}
}


Measured memory_bytes: 2832
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
queue<P> q;
char c[1010][1010];
int d[1010][1010];
int main(){
    int H,W;
    cin>>H>>W;
    for(int i=0;i<H;i++){
        cin>>c[i];
        for(int j=0;j<W;j++){
            d[i][j]=10000000;
            if(c[i][j]=='#'){
                q.push(P(i,j));
                d[i][j]=0;
            }
        }
    }
    int ans=0;
    while(!q.empty()){
        P now=q.front();q.pop();
        int nh=now.first;
        int nw=now.second;
        int dh[4]={0,0,1,-1};
        int dw[4]={1,-1,0,0};
        for(int i=0;i<4;i++){
            int h=nh+dh[i];
            int w=nw+dw[i];
            if(0<=h && h<H && 0<= w && w<W){
                if(d[h][w] > d[nh][nw]+1){
                    d[h][w]=d[nh][nw]+1;
                    ans=max(ans,d[h][w]);
                    q.push(P(h,w));
                }
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 13456
def foo(m,n)
	while m != n
		m>n ? m -= n : n -= m
	end
	m
end

def max(m,n)
	m > n ? [m,n] : [n,m]
end

na = Hash.new
an = Hash.new
('a'..'z').each_with_index {|c,i| an[c] = i;na[i] = c}
n = gets.chomp.to_i
max = 1000
n.times do
	line = gets.chomp
	decoded = " "*line.size
	1.upto(max) do |a|
		next if foo(*max(a,26)) != 1
		flag = false
		0.upto(max)	do |b|
			temp = (0..25).map{|y| (a*y+b).modulo(26)}
			next if temp.size > temp.uniq.size
			0.upto(line.size-1) {|i| decoded[i] = (line[i] == ' ' ? ' ' : na[(an[line[i]]*a+b).modulo(26)])} 
			flag = true if decoded.include?("this") || decoded.include?("that")
			break if flag
		end
		break if flag
	end
	puts decoded
end

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

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int n; string s; 
	vector<int> idx[3]; // R, G, B
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		switch (s[i]) {
			case 'R': idx[0].push_back(i); break;
			case 'G': idx[1].push_back(i); break;
			case 'B': idx[2].push_back(i); break;
		}
	}

	ll ans = 0;
	ll temp = idx[2].size();
	for (auto i : idx[0]) {
		for (auto j : idx[1]) {
			ans += temp;
			int l = min(i, j);
			int r = max(i, j);
			int diff = r - l;
			if (binary_search(idx[2].begin(), idx[2].end(), l - diff)) ans--;
			if (binary_search(idx[2].begin(), idx[2].end(), r + diff)) ans--;
			if (diff % 2 == 0 && binary_search(idx[2].begin(), idx[2].end(), (l+r)/2)) ans--;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3644
N, M = map(int, input().split())
X = [int(x) for x in input().split()]

if N >= M:
    print(0)
else:
    X.sort()
    dX = [(i, X[i + 1] - X[i]) for i in range(M - 1)]
    dX.sort(key=lambda x: x[1], reverse=True)
    print(sum(d[1] for d in dX[N - 1:]))

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

using namespace std;

int main(void) {
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for(int i = 1; i <= N; i++){
        int c = 0, t = i;
        for(int j = 0; j < 5; j++){
            c+=t%10;
            t/=10;
        }
        if(A <= c && c <= B) ans+=i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=400015;
#define M 1000000007
#define double long double
#define BINF 100000000000000
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

struct Fenwick {
    int n; vector<int> t;
    Fenwick(int n_): n(n_), t(n_ + 1) {}

    //range update point query
    int query(int i) { int v = 0; for (; i > 0; i -= (i & -i)) v += t[i]; return v; }
    void update(int i, int v) { for (; i <= n; i += (i & -i)) t[i] += v; }
    void range_update(int l, int r, int v) { update(l,v); update(r + 1, -v); }
};

#undef int
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);

	
    int n;

    cin >> n;
    int d, a;
    cin >> d >> a;

    vector<pair<int, int>>v(n + 1);
    v[0] = {-1, -1};

    for(int i = 1; i <= n; i++)
    	cin >> v[i].F >> v[i].S;
    sort(v.begin(), v.end());

    Fenwick bit(n);
    for(int i = 1; i <= n; i++){
    	bit.range_update(i, i, v[i].S);
    }

    vector<int>pos;
    for(auto i : v)
    	pos.push_back(i.F);
    sort(pos.begin(), pos.end());


    int ans = 0;

    for(int i = 1; i <= n; i++){
    	int cur = bit.query(i);
    	if(cur <= 0) continue;

    	int need = (cur / a) + (cur % a != 0);
    	ans += need;

    	int x = v[i].F + 2 * d;
    	//cout << x + 2 * d << endl;

    	int l = i;
    	int r = lower_bound(pos.begin(), pos.end(), x) - pos.begin();

    	if(r != pos.size()){
    		if(pos[r] > x) r--;
    	}
    	

    	bit.range_update(l, r, - (need * a));

    }

    cout << ans << endl;
	
	
 
return 0;
}



Measured memory_bytes: 7156
import java.util.Scanner;

// Main
class Main {
	static final int[] I = new int[] {0,1,5,4,0,2,5,3};

	static class Dice {
		private int[] dig;
		public Dice(Scanner s) {
			dig = new int[6];
			for (int i = 0; i < dig.length; i++) {
				dig[i] = s.nextInt();
			}
		}
		private void rot(int q, int s) {
			int p = (s > 0) ? q : q + 3;
			int dd = dig[I[p]];
			for (int i = 0; i < 3; i++, p += s) {
				dig[I[p]] = dig[I[p + s]];
			}
			dig[I[p]] = dd;
		}
		public int roll(String op) {
			int sz = op.length();
			for (int i = 0; i < sz; i++) {
				char ch = op.charAt(i);
				switch (ch) {
				case 'N': rot(0, 1); break;
				case 'S': rot(0,-1); break;
				case 'W': rot(4, 1); break;
				case 'E': rot(4,-1); break;
				}
			}
			return dig[0];
		}
	}

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			Dice d = new Dice(sc);
			sc.nextLine();
			String op = sc.nextLine();
			int top = d.roll(op);
			System.out.println(Integer.toString(top));
		}
	}
}



Measured memory_bytes: 26064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define pri(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
//#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[1050000];
int sosuu[100010];
void Eratosthenes() {
	ll N = 1050000;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu[c] = i;
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}

bool visited[100010];
int N,M;
int p[100010];
int X[100010],Y[100010];
vector<int>graph[100010];
int color[100010];
void func(int n,int col){
	visited[n]=true;
	color[n]=col;
	for(auto x:graph[n]){
		if(!visited[x]){
			func(x,col);
		}
	}
}
int main() {
	m0(visited);
	cin>>N>>M;
	REP(i,N){
		cin>>p[i];
		p[i]--;
		graph[i].pb(i);
	}
	REP(i,M){
		int x,y;
		cin>>x>>y;
		x--;y--;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	int col=0;
	REP(i,N){
		if(!visited[i]){
			func(i,col);
			col++;
		}
	}
	ll ans=0;
	REP(i,N){
		//pe(color[i]);cout<<endl;
		if(color[p[i]]==color[i])ans++;
	}
	pri(ans);
}


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

int main(){
  int n,m;
  cin>>n>>m;
  int temp;
  temp = 1900*m + 100*(n-m);
  REP(i,m){
    temp *= 2;
  }
  cout<<temp<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>  
typedef long long ll;  
using namespace std;  
  
const ll INF = 1LL<<32;  
  
int n,e;  
  
ll dp[110][110];  
  
void floyd(){  
    for(int k = 0 ; k<n ; k++){  
        for(int i = 0 ; i<n ; i++){  
            if(dp[i][k] == INF)  
                continue;  
            for(int j = 0 ; j<n ; j++){  
                if(dp[k][j] == INF)  
                    continue;  
                dp[i][j] = min(dp[i][j] , dp[i][k]+dp[k][j]);  
            }  
        }  
    }  
}  
  
int main(){  
    ios::sync_with_stdio(false);  
    cin>>n>>e;  
      
    for(int i = 0 ; i<n ; i++){  
        for(int j = 0 ; j<n ; j++){  
            if(i == j)  
                dp[i][j] = 0;  
            else  
                dp[i][j] = INF;   
        }  
    }  
      
    for(int i = 0 ; i<e ; i++){  
        int s,t,d;  
        cin>>s>>t>>d;  
        dp[s][t] = d;  
    }  
      
    floyd();  
      
    bool flag = 0;  
    for(int i = 0 ; i<n ; i++){  
        if(dp[i][i] < 0){  
            flag = 1;  
            break;  
        }  
    }  
    if(flag){  
        cout<<"NEGATIVE CYCLE"<<endl;  
    }  
    else{  
        for(int i = 0 ; i<n ; i++){  
            for(int j = 0 ; j<n ; j++){  
                if(j) cout<<" ";  
                if(dp[i][j] == INF){  
                    cout<<"INF";  
                }  
                else  
                    cout<<dp[i][j];  
            }  
            cout<<endl;  
        }  
    }  
      
    return 0;  
}  



Measured memory_bytes: 3276
Q=int(input())
N=10**5+2
prime=[1]*N
prime[0]=0
prime[1]=0
for i in range(N):
    if not prime[i]:
        continue
    for j in range(i*2,N,i):
        prime[j]=0
like=[0]*N
for i in range(1,N,2):
    if prime[i] and prime[(i+1)//2]:
        like[i]=1
a=[0]
for i in range(1,N):
    a.append(a[-1]+like[i])
#a=list(accumulate(like))

for i in range(Q):
    l,r=map(int,input().split())
    print(a[r]-a[l-1])


Measured memory_bytes: 53836
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,st,ed) for(int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(int i=st,i##end=ed;i>=i##end;--i)
const int maxn=100005;
long long tag=0;
int n,l,t;
int p[maxn];
int main(){
	scanf("%d%d%d",&n,&l,&t);
	REP(i,1,n){
		int x,dir;
		scanf("%d%d",&x,&dir);
		if(dir==1){
			p[i]=x+t;
			tag+=p[i]/l;
			p[i]%=l;
		}else{
			p[i]=x-t;
			tag+=p[i]/l;
			p[i]%=l;
			if(p[i]<0)p[i]+=l,--tag;
		}
	}
	sort(p+1,p+1+n);
	tag%=n;
	if(tag<0)tag+=n;
	REP(i,1,n)
		printf("%d\n",p[(i+tag-1)%n+1]);
	return 0;
}

Measured memory_bytes: 1536
# -*- coding: utf-8 -*-
"""
A - Round One
https://atcoder.jp/contests/abc148/tasks/abc148_a

"""
import sys


def solve(A, B):
    return set([1, 2, 3]) - set([A, B])


def main(args):
    A, B = int(input()), int(input())
    ans = solve(A, B)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b;
	cin>>a>>b;
	
	for(int i=0; i<b+2; i++){
		cout<<'#';
	}
	cout<<endl;
	//最初の＃
	
	
	vector<string> vec(b);
    for(int j=0; j<a; j++){
		cout<<'#';
		int k;
		cin>>vec.at(k);
		cout<<vec.at(k);
		cout<<'#'<<endl;
	}
	
		for(int i=0; i<b+2; i++){
		cout<<'#';
	}
	cout<<endl;
	//最後の＃
}

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

int main(void) {
  int n;
  string s, t;
  cin >> n >> s >> t;
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j <= i; j++) {
      if (t[j] == s[n - 1 - i + j]) cnt++;
    }
    if (cnt == i + 1) ans = cnt;
  }
  cout << 2 * n - ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int henkan(char,char);
int main(void)
{
	int i,d,min,minban,X[8][3]={0,0,0,
				   0,0,255,
				   0,255,0,
	               0,255,255,
				   255,0,0,
				   255,0,255,
				   255,255,0,
				   255,255,255};
	char RGB[8];
	while(1){
		min = 99999;
		scanf("%s",RGB);
		if(RGB[0] == '0')
			break;
		for(i=0;i<8;i++){
			d = (henkan(RGB[1],RGB[2])-X[i][0]) * (henkan(RGB[1],RGB[2])-X[i][0]) +
				(henkan(RGB[3],RGB[4])-X[i][1]) * (henkan(RGB[3],RGB[4])-X[i][1]) +
				(henkan(RGB[5],RGB[6])-X[i][2]) * (henkan(RGB[5],RGB[6])-X[i][2]) ;
			if(min > d ){
				min = d;
				minban = i;
			}
		}
		switch(minban){
			case 0:
				printf("black\n");
				break;
			case 1:
				printf("blue\n");
				break;
			case 2:
				printf("lime\n");
				break;
			case 3:
				printf("aqua\n");
				break;
			case 4:
				printf("red\n");
				break;
			case 5:
				printf("fuchsia\n");
				break;
			case 6:
				printf("yellow\n");
				break;
			case 7:
				printf("white\n");
				break;
		}
	}
	return 0;
}

int henkan(char a,char b)
{
	int oza=0;
	if(a == '1')       oza = oza + 16;
	else if(a == '2')  oza = oza + 32;
	else if(a == '3')  oza = oza + 16 + 32;
	else if(a == '4')  oza = oza + 64;
	else if(a == '5')  oza = oza + 16 + 64;
	else if(a == '6')  oza = oza + 32 + 64;
	else if(a == '7')  oza = oza + 16 + 32 + 64;
	else if(a == '8')  oza = oza + 128;
	else if(a == '9')  oza = oza + 16 + 128;
	else if(a == 'a')  oza = oza + 32 + 128;
	else if(a == 'b')  oza = oza + 16 + 32 + 128;
	else if(a == 'c')  oza = oza + 64 + 128;
	else if(a == 'd')  oza = oza + 16 + 64 + 128;
	else if(a == 'e')  oza = oza + 32 + 64 + 128;
	else if(a == 'f')  oza = oza + 16 + 32 + 64 + 128;
	if(b == '1')       oza = oza + 1;
	else if(b == '2')  oza = oza + 2;
	else if(b == '3')  oza = oza + 3;
	else if(b == '4')  oza = oza + 4;
	else if(b == '5')  oza = oza + 5;
	else if(b == '6')  oza = oza + 6;
	else if(b == '7')  oza = oza + 7;
	else if(b == '8')  oza = oza + 8;
	else if(b == '9')  oza = oza + 9;
	else if(b == 'a')  oza = oza + 10;
	else if(b == 'b')  oza = oza + 11;
	else if(b == 'c')  oza = oza + 12;
	else if(b == 'd')  oza = oza + 13;
	else if(b == 'e')  oza = oza + 14;
	else if(b == 'f')  oza = oza + 15;
	return oza;
}

Measured memory_bytes: 524
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=2003;
const ll lmod = 1e9+7;

int c[MAX_N][MAX_N],ch[MAX_N][MAX_N];

int main(){
  int h,w,d;
  cin >> h >> w >> d ;
  rep(i,MAX_N) ch[0][i] = (i%2);
  REP(i,1,MAX_N){
    rep(j,MAX_N){
      ch[i][j] = (ch[i-1][j]+2)%4;
      // cout << ch[i][j] << ",";
    }
    // cout << "" << endl;
  }
  string s = "RGYB";
  rep(i,h) rep(j,w) c[i][j] = ch[(i+j)/(d)][(i-j+1000*d)/(d)];
  rep(i,h){
    rep(j,w) cout << s[c[i][j]];
    cout << endl;
  }
  // rep(i,h){
  //   rep(j,w) cout <<  (i+j)/(d) << "," << (i-j+10*d)/d << " ";
  //   cout << "" << endl;
  // }
  
  return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var S = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
            var count = 0;
            for(var i=0;i<S.Count()-2;i++)
            {
                var so = new List<int>();
                so.Add(S[i]);
                so.Add(S[i+1]);
                so.Add(S[i+2]);
                so.Sort();
                if (so[1] == S[i + 1]) count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13396
N = int(input())
H = list(map(int,input().split()))
cnt = 0
cntmax = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        cnt += 1
    else:
        if cnt > cntmax:
            cntmax = cnt
        cnt = 0
else:
    if cnt > cntmax:
            cntmax = cnt

print(cntmax)

Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  if(a[0]!=0) {
    cout << -1 << endl;
    return 0;
  }

  ll ans = 0;
  rep(i,1,n) {
    if(a[i]==0) {
      continue;
    }
    if(a[i] > a[i-1]+1) {
      cout << -1 << endl;
      return 0;
    }
    if(a[i] == a[i-1]+1) {
      ans++;
    }
    else /* if(a[i] <= a[i-1]) */ {
      ans += a[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4024
#include <stdio.h>

int main(void)
{
    int A,B,C,D,s,t;

    scanf("%d %d %d %d",&A ,&B ,&C ,&D);


    if(A>B)
       s=B;
    else
       s=A;

    if(C>D)
       t = s+D;
    else
       t = s+C;

    printf("%d\n",t);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

const int MOD = (int)1e9 + 7;

signed main(){
	int N, M;
	cin >> N >> M;
	vector<int> A(N), B(M);
	for(int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	for(int j = 0; j < M; ++j) {
		cin >> B[j];
	}
	sort(ALL(A)); A.erase(unique(ALL(A)), A.end());
	sort(ALL(B)); B.erase(unique(ALL(B)), B.end());

	if (A.size() != N || B.size() != M) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> C(N * M + 1, -1), D;
	D.insert(D.end(), ALL(A));
	D.insert(D.end(), ALL(B));
	sort(ALL(D)); D.erase(unique(ALL(D)), D.end());
	for(auto a: A) {
		int i = lower_bound(ALL(B), a) - B.begin();
		if(i < M && B[i] == a) {
			C[a] = 1;
		} else {
			C[a] = M - i;
		}
	}
	for(auto a: B) {
		int i = lower_bound(ALL(A), a) - A.begin();
		if(i < N && A[i] == a) {
			C[a] = 1;
		} else {
			C[a] = N - i;
		}
	}
	/*
	cerr << D.size() << endl;
	for(int i = 0; i <= N * M; ++i) {
		cerr << C[i] << " ";
	}
	cerr << endl;
	*/
	int res = 1, sum = 0, cnt = D.size();
	for(int k = N * M; k >= 1; --k) {
		if(C[k] >= 0) {
			res *= C[k];
			res %= MOD;
			sum += C[k];
			sum--;
			cnt--;
		}/* else if (cnt > 0) {
			res *= sum;
			res %= MOD;
			sum--;
		} else {
			res *= k;
			res %= MOD;
		}
		*/
		else {
			res *= (int)(A.end() - lower_bound(ALL(A), k)) * (B.end() - lower_bound(ALL(B), k)) - (N * M - k);
			res %= MOD;
		}
		//cerr << ">" << res << endl;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
#define INF 1000000000000000
#define REP(i,b,n) for(int i = (b); i < n; i++)
#define rREP(i,b,n) for(int i = (n-1); i >= (b); i--)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
int gcd(int a, int b){return b ? gcd(b, a % b): a;}
void yes(){cout<<"Yes"<<endl;return;}
void no(){cout<<"No"<<endl;return;}

int main()
{
    ll n;
    ll c[5];
    cin >> n;
    ll cmin = INF;
    int imin = 0;
    REP (i,0,5) {
        cin >> c[i];
        cmin = min(cmin, c[i]);
    }
    ll ans = n / cmin + 5 - (n % cmin == 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256