akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define li long
#define pb push_back
#define mem(arr,x) memset(arr,x,sizeof(arr))

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    int i,j,n=s.size(),m=t.size();
    int dp[n+1][m+1];
    mem(dp,0);
    for(i=0;i<=n;i++)
    {
      for(j=0;j<=m;j++)
      {
        if(i==0||j==0)
        dp[i][j]=0;
        else if(s[i-1]==t[j-1])
        dp[i][j]=1+dp[i-1][j-1];
        else
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
    }
    // cout<<dp[n][m];
    int len=dp[n][m];
    string ans;
    while(len>0)
    {
      if(s[n-1]==t[m-1])
      {
        ans+=s[n-1];
        len--;
        n--;
        m--;
      }
      else if(dp[n-1][m]>dp[n][m-1])
      n--;
      else
      m--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}

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

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

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

pi calc(deque<pi>&d,int s){
	int n=d.size();
	int a=d[0].first,b=d[n-1].first;
	if(b<=s)
		return pi(s-a,a);
	if(s<=a)
		return pi(b-s,b);
	if(d[0].second>=d[n-1].second){
		d[0].second+=d[n-1].second;
		d.pop_back();
		pi g=calc(d,s);
		return pi(g.first+b-g.second,b);
	}else{
		d[n-1].second+=d[0].second;
		d.pop_front();
		pi g=calc(d,s);
		return pi(g.first+g.second-a,a);
	}
}

signed main(){
	int n=read(),s=read();
	deque<pi> d;
	REP(i,n){
		int x=read(),p=read();
		d.PB(pi(x,p));
	}
	pi ans=calc(d,s);
	print(ans.first);
}


Measured memory_bytes: 7736
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  long a,b;cin>>a>>b;
  if(a*500>=b)cout<<"Yes\n";else cout<<"No\n";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  
#include <numeric>
#include <sys/resource.h>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
using ll = long long;
 
const int precision = 15;
const int modulo =  1000000007; // 10^9 + 7
const ll lmodulo =  1000000007; // 10^9 + 7
 
const double EPS = 1e-9;
const ll inf = 1e18;


void increaseStack() {
	const rlim_t kStackSize = 50 * 1024 * 1024;   // min stack size = 50 MB
	struct rlimit rl;
	int result;

	result = getrlimit(RLIMIT_STACK, &rl);
	if (result == 0) {
		if (rl.rlim_cur < kStackSize) {
			rl.rlim_cur = kStackSize;
		    result = setrlimit(RLIMIT_STACK, &rl);
		    if (result != 0) {
		    	fprintf(stderr, "setrlimit returned result = %d\n", result);
		    }
		}
	}
}

vector<ll> dfs(int u, int parent, vector<vector<int>> & adj) {
	ll white = 1;
	ll black = 0;
	for (auto v : adj[u]) {
		if (v == parent) continue;
		auto cur = dfs(v, u, adj);
		auto curWhite = cur[1];
		auto curBlack = cur[0];

		black = (curBlack * white) % lmodulo
			+ ((curWhite + curBlack) * black) % lmodulo;

		white = (white * curWhite) % lmodulo;
	}
	return {white, (white + black) % lmodulo};
}

void solve () {
	int n; cin >> n;
	vector<vector<int>> adj(n + 1);

	for (auto i = 0; i < n - 1; ++i) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	auto vRet = dfs(1, -1, adj);
	auto ret = (vRet[0] + vRet[1]) % lmodulo;
	cout << ret;
	
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(precision);
  cout.setf(ios_base::fixed);
  solve();
  return 0;
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int a, b;
bool ans[100][100];

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

    cin >> a >> b;

    rep(i, 50) rep(j, 100) ans[i][j] = true;

    int cnt = 0;
    for(int i = 0; i < 50; i += 2)
        for(int j = 0; j < 100; j += 2)
            if(++cnt < a) ans[i][j] = false;

    cnt = 0;
    for(int i = 51; i < 100; i += 2)
        for(int j = 0; j < 100; j += 2)
            if(++cnt < b) ans[i][j] = true;

    cout << "100 100\n";

    rep(i, 100) rep(j, 100) cout << (ans[i][j] ? '#' : '.')
                                 << (j < 99 ? "" : "\n");

    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes";
    else cout << "No";    
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int n;
int p[25];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> p[i];
	
	int ans = 0;
	for(int i = 2; i < n; i++){
		if(p[i-1] > p[i] && p[i] > p[i+1]) ans++;
		if(p[i-1] < p[i] && p[i] < p[i+1]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int a,b;
    cin>>a>>b;
    if (a%3==0 || b%3==0 || (a+b)%3==0)
        cout<<"Possible\n";
    else
        cout<<"Impossible\n";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int n, t, c[1000], m[1000], x=0, i;

   scanf("%d%d",&n,&t);
   for(i=0;i<n;i++){
      scanf("%d%d",&c[i],&m[i]);
      if((m[i]<=t)&&((x==0)||(x>c[i])))
         x=c[i];
   }

   if(x!=0)
      printf("%d\n",x);
   else
      printf("TLE\n");
   return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<bitset>
#include<cstdio>
#include<string>
using namespace std;
int main() {
	int a[1000], b[1000], n, m, i, min1 = 100, min2 = 100, num,sa=0,sa1=0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	cin >> m;
	for (int j = i; j < m + i; j++) {
		cin >> a[j] >> b[j];
	}
	for(int i=0;i<m+n;i++){
		for(int j=0;j<m+n;j++){
			if(i==j){
				continue;
			}
			if(a[i]==a[j] && b[i]==b[j]){
				sa++;
			}
		}
	}
	sa1=sa/2;
	for (int j = 0; j < n + m-sa1; j++) {
		for (int l = 0; l < n + m; l++) {
			if (min1 == a[l]) {
				if (min2 > b[l]) {
					min1 = a[l];
					min2 = b[l];
					num = l;
				}
			}
			else if (min1 > a[l]) {
				min1 = a[l];
				min2 = b[l];
				num = l;
			}
		}
		cout << min1 << ":";
		printf("%02d", min2);
		if(j==n+m-sa1-1){
			cout<<endl;
		}
		else{
			cout<<" ";
		}
		for(int k=0;k<n+m;k++){
			if(min1==a[k] && min2 == b[k]){
				a[k]=100;
				b[k]=100;
			}
		}
		a[num] = 1000;
		b[num] = 1000;
		min1 = 100;
		min2 = 100;
	}
	return 0;
}

Measured memory_bytes: 3236
# -*- coding: utf-8 -*-
"""
Created on Sat May 18 23:11:54 2019

@author: maezawa
"""

import collections
import heapq


class Dijkstra():
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d, directed=False):
        """
        0-indexedでなくてもよいことに注意
        u = from, v = to, d = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.e[u].append([v, d])
            self.e[v].append([u, d])
        else:
            self.e[u].append([v, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def Dijkstra_search(self, s):
        """
        0-indexedでなくてもよいことに注意
        s = 始点
        return: 始点から各点までの最短経路
        """
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d
    
v, e, r = list(map(int, input().split()))
graph1 = Dijkstra()
for _ in range(e):
    si, ti, di = list(map(int, input().split()))
    graph1.add(si, ti, di, directed=True)
    
res = graph1.Dijkstra_search(r)
for i in range(v):
    ans = res[i]
    if ans == float('inf'):
        print('INF')
    else:
        print(ans)
    


Measured memory_bytes: 120648
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		//8パターン考える
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		long[][] cakes = new long[n][3];
		long[][] sums = new long[4][n];
		long ans = 0;
		for(int i=0; i < n; i++) {
			cakes[i][0] = scanner.nextLong();
			cakes[i][1] = scanner.nextLong();
			cakes[i][2] = scanner.nextLong();
		}
		for(int r = 0; r < n; r++) {
			sums[0][r] = cakes[r][0] + cakes[r][1] + cakes[r][2];
			sums[1][r] = cakes[r][0] + cakes[r][1] - cakes[r][2];
			sums[2][r] = cakes[r][0] - cakes[r][1] + cakes[r][2];
			sums[3][r] = cakes[r][0] - cakes[r][1] - cakes[r][2];
//			sums[4][r] = -cakes[r][0] + cakes[r][1] + cakes[r][2];
//			sums[5][r] = -cakes[r][0] + cakes[r][1] - cakes[r][2];
//			sums[6][r] = -cakes[r][0] - cakes[r][1] + cakes[r][2];
//			sums[7][r] = -cakes[r][0] - cakes[r][1] - cakes[r][2];
		}
		Arrays.sort(sums[0]);
		Arrays.sort(sums[1]);
		Arrays.sort(sums[2]);
		Arrays.sort(sums[3]);
//		Arrays.sort(sums[4]);
//		Arrays.sort(sums[5]);
//		Arrays.sort(sums[6]);
//		Arrays.sort(sums[7]);
		for(int k = 0; k < 4; k++) {
			long tmp = 0;
			for(int l = 0; l < m; l++) {
				tmp -= sums[k][l];
			}
			if(tmp > ans) ans = tmp;
		}
		
		for(int k = 0; k < 4; k++) {
			long tmp2 = 0;
			for(int l = n-1; l > n-m-1; l--) {
				tmp2 += sums[k][l];
			}
			if(tmp2 > ans) ans = tmp2;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 28468
import math
N = int(input())
N_sqrt = math.floor(math.sqrt(N))

ans = float('inf')
for i in range(1, N_sqrt + 1):
    if N % i == 0:
        if ans > max(len(str(i)), len(str(N // i))):
            ans = max(len(str(i)), len(str(N // i)))

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define f first
long long const mod = 998244353; 
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update> */

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

ll power(ll x,ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
	
    ll n;
    cin>>n;
    ll x,m;
    cin>>x>>m;
    vector<ll>v;
    bool a[m];
    memset(a,false,sizeof(a));
    ll prev=x;
    v.push_back(x);
    ll f=-1;
    while(true)
    {
        if(a[prev])
        {
            f=prev;
            break;
        }
        ll z=(prev*prev)%m;
        v.push_back(z);
        a[prev]=true;
        prev=z;
        //cout<<z<<endl;
    }

    ll sum1=0;
    ll num=0;
    for(ll i=0;i<v.size();i++)
    {
        sum1+=v[i];
        num++;
        if(n==num)
        {
            cout<<sum1<<endl;
            return 0;
        }
        if(v[i]==f)
        {
            break;
        }
    }


    ll sz=v.size()-num;
    n=n-num;
    ll q=n/sz;
    ll r=n%sz;
    ll sum2=0;
    for(ll i=num;i<v.size();i++)
        sum2+=v[i];
    ll sum3=0;
    for(ll i=num;i<num+r;i++)
    {
        sum3+=v[i];
    }
    cout<<sum1+sum2*q+sum3<<endl;
    
    return 0;
}




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

#define mp make_pair
#define pb push_back
#define int long long

using namespace std;
const int inf = 1e18;
const double EPS = 0.00000001;
const int mod = 1000000007;

signed main(){
    int n;
    cin >> n;
    int mass[n];
    for(int i = 0;i<n;i++) cin >> mass[i];
    int c = 0;
    for(int i = 0;i<n;i++) c ^= mass[i];
    for(int i =0;i<n;i++){
        cout << (c^mass[i]) << " ";
    }
}


Measured memory_bytes: 5084
#define LOCAL

#undef _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define LLINF 1e18
#define INF (int)1e9+1

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// End of Gennady-Korotkevich's template 

using llong = long long;
using PII = pair<int, int>;

const llong MOD = 998244353LL;

int main() {
	IOS;
	string s1, s2; cin >> s1 >> s2;
	int n1, n2; cin >> n1 >> n2;
	string s; cin >> s;
	if (s == s1) cout << n1 - 1 << " "<<  n2;
	else cout << n1 << " " << n2-1;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, k;
    cin >> n >> k;
    vector<pair<int, ll>> vp;
    rep(i, n) {
        int a;
        ll b;
        cin >> a >> b;
        vp.eb(a, b);
    }
    sort(vp.begin(), vp.end());
    for (auto p : vp) {
        k -= p.se;
        if (k <= 0) {
            cout << p.fi << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 2420
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
// constexpr int INF = 1e7;

int main(){
    int H;cin>>H;
    int W;cin>>W;
    int xmove[4] = {1, -1, 0, 0};
    int ymove[4] = {0,  0, 1, -1};
    int bracknum = 0;
    vector<vector<int>> I(H, vector<int>(W, -1));

    vector<string> area;
    queue<pair<int, int>> brack;
    for(int y = 0; y < H; y++){
        string s;cin>>s;
        area.push_back(s);
    }
    for(int i = 0; i< H; i++){
        for(int j=0; j< W; j++){
            if(area[i][j]=='#'){
                brack.push(make_pair(i, j));
                I[i][j] = 0;
            }
        }
    }
    bracknum += brack.size();
    int ans = 0;

    while(!brack.empty()){
        // ans++;
        auto q = brack.front();
        brack.pop();
        int y = q.first;
        int x = q.second;
        // vector<vector<int>> I(H, vector<int>(W, -1));
        for(int i = 0; i < 4; i++){
            int moveX = x + xmove[i];
            int moveY = y + ymove[i];
            if(moveY < 0 || moveY >= H || moveX < 0 || moveX >= W) continue;
            else if(area[moveY][moveX] == '#')continue;
            else if(I[moveY][moveX] == -1){
                area[moveY][moveX] = '#';
                I[moveY][moveX] = I[y][x] + 1;
                brack.push(make_pair(moveY,moveX));
            }
        }
    }

    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) ans = max(ans, I[i][j]);

    cout<<ans<<endl;
    
}

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

const int inf = 99999999;
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

vector<int> lis_fast(const vector<int>& a) {
  const int n = a.size();
  vector<int> A(n, inf);
  vector<int> id(n);
  for (int i = 0; i < n; ++i) {
    id[i] = index_of(A, a[i]);
    A[ id[i] ] = a[i];
  }
  int m = *max_element(id.begin(), id.end());
  vector<int> b(m+1);
  for (int i = n-1; i >= 0; --i)
    if (id[i] == m) b[m--] = a[i];
  return b;
}


int main(void){
    int N;
    scanf("%d",&N);
    vector<int> po(N);
    for(int i=0;i<N;i++){
        int a;
        scanf("%d",&a);
        po[N-1-i]=-a;
    }
    vector<int> b=lis_fast(po);
    long long ans=0;
    for(int i=0;i<b.size();i++)ans-=b[i];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4336
n,k=map(int,input().split())
h=[0 for _ in range(n)]
for i in range(n):
    h[i]=int(input())
h.sort()
ans=10**9+7
for i in range(n-k+1):
    ans=min(ans,h[i+k-1]-h[i])
print(ans)

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


ll x;

void solve()
{
    cin >> x;
    ll ans = 0;
    ans += 2 * (x / 11);
    x %= 11;
    if(0 < x)
    {
        if(x <= 6) ans++;
        else ans += 2;
    }

    cout << ans << endl;
}

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

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

template<typename T, typename S>
istream& operator>> (istream& in, pair<S, T>& p) {
    in >> p.fs >> p.sn;
    return in;
}
template<typename T, typename S>
ostream& operator<< (ostream& out, pair<S, T>& p) {
    out << p.fs << ' ' << p.sn << ' ';
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}
template<typename T>
ostream& operator<< (ostream& out, vector<T>& v) {
    for (T& x : v) out << x << ' ';
    return out;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int N = 310 * 2;
int a[N][N], u[N][N];
vector<pair<int, int>> go;

void dfs(int n, int i, int j, int val, int col) {
    //cerr << i << ' ' << j << '\n';
    if (i < 0 || i >= n || j < 0 || j >= n) return;
    if (u[i][j]) return;
    u[i][j] = 1;
    if (col) a[i][j] += val;
    for (auto p : go) {
        int x = p.fs, y = p.sn;
        dfs(n, i + x, j + y, val, col ^ 1);
    }
}

void solve(int n, int d, int val) {
    memset(u, 0, sizeof u);
    go.clear();
    forn(i, 0, n)
        forn(j, 0, n)
            if (i * i + j * j == d) {
                go.eb(i, j);
                go.eb(-i, j);
                go.eb(i, -j);
                go.eb(-i, -j);
            }
    forn(i, 0, n)
        forn(j, 0, n)
            if (!u[i][j]) {
                dfs(n, i, j, val, 0);
            }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n, d1, d2;
    cin >> n >> d1 >> d2;
    solve(2 * n, d1, 1);
    solve(2 * n, d2, 2);
    vector<int> cnt(4);
    forn(i, 0, 2 * n)
        forn(j, 0, 2 * n)
            ++cnt[a[i][j]];
    forn(q, 0, 4)
        if (cnt[q] >= n * n) {
            int todo = n * n;
            forn(i, 0, 2 * n)
                forn(j, 0, 2 * n) {
                    if (a[i][j] == q) {
                        cout << i << ' ' << j << '\n';
                        --todo;
                        if (todo == 0) return 0;
                    }
                }
            return 1;
        }
    return 1;
}


Measured memory_bytes: 32000
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>
#include<numeric>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define what_is(x) cout<<#x<<" is "<<x<<en;

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	string s;
	cin >> s;
	int n = s.length();
	string t1 = s.substr(0, (n - 1) / 2);
	string t2 = s.substr((n + 3) / 2 - 1);
	string rs = s;
	reverse(all(rs));
	string t1_rev = t1, t2_rev = t2;
	reverse(all(t1_rev));
	reverse(all(t2_rev));
	if (s == rs && t1 == t1_rev && t2 == t2_rev)
		cout << "Yes";
	else
		cout << "No";
}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

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

        int count = 0;
        while(true) {
            String s2 = sc.nextLine();
            if(s2.equals("END_OF_TEXT")) {
                break;
            }
            String[] ss = s2.split(" ");
            for(String s : ss) {
                String s3 = s.toLowerCase();
                if(s3.equals(s1)) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26224
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,i,j;
    cin>>a;
    b=0;
    int num[a-1];
    for(i=0;i<a-1;i++){
        cin>>num[i];
    }
    for(i=0;i<a;i++){
        if(i==0)
        b=num[i];
        else if(i==a-1)
        b=b+num[i-1];
        else{
            if(num[i-1]<num[i])
            b=b+num[i-1];
            else
            b=b+num[i];
        }
    }
    cout<<b<<endl;
    
}


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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    int a,b,c;
    int cnt=0;
    cin>>a>>b>>c;
    for(int i=a;i<=b;i++){
        if(c%i == 0)    cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}



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

int main(void)
{
  int k;
  int a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++)
  {
    if (i % k == 0)
    {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}

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

#ifdef _DEBUG
    #include "/home/v-o_o-v/deb.h"
    #define deb(x...)cerr << "[" << #x << "] = [";_print(x);
#else
    #define deb(x...)
#endif

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int cnt[55];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin >> s;
    set<char> st;
    for(auto ch: s)st.insert(ch);
    if(st.size() == s.size())puts("yes");
    else puts("no");
    return 0;
}
// Write Here


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

const int N = 200;
const int INF = 0x3f3f3f3f;

int n, m, r, ans = INF;
int bh[N + 10], dis[N + 10][256 + 10];
vector <pair<int, int> > G[N + 10];
queue <pair <int, int> > dl;
map <pair<int, int>, int> dic;

void in() {
	cin >> n >> m >> r;
	for (int i = 1; i <= r; i++) {
		int x;
		cin >> x;
		bh[x] = i;
	}
	for (int i = 1; i <= m; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		G[x].push_back(make_pair(y, z));
		G[y].push_back(make_pair(x, z));
	}
}

void bfs() {
	while (!dl.empty()) {
		int x = dl.front().first, sta = dl.front().second;
		dic[make_pair(x, sta)] = 0;
		dl.pop();
		for (pair<int, int> temp : G[x]) {
			int y = temp.first, cost = temp.second, tsta = sta;
			if (bh[y]) tsta |= (1 << (bh[y] - 1));
			if (dis[y][tsta] > dis[x][sta] + cost) {
				dis[y][tsta] = dis[x][sta] + cost;
				if (dic[make_pair(y, tsta)] == 0) {
					dl.push(make_pair(y, tsta));
				}
			}
		}
	}
}

void get_ans() {
	memset(dis, INF, sizeof dis);
	for (int i = 1; i <= n; i++)
		if (bh[i]) {
			dis[i][1 << (bh[i] - 1)] = 0;
			dl.push(make_pair(i, 1 << (bh[i] - 1)));
			dic.clear();
			dic[make_pair(i, 1 << (bh[i] - 1))] = 1;
			bfs();
		}
	for (int i = 1; i <= n; i++)
		if (bh[i])
			ans = min(ans, dis[i][(1 << r) - 1]);
}

void out() {
	cout << ans << endl;
}

int main() {
	//freopen("F:\\rush.txt", "r", stdin);
	ios::sync_with_stdio(0), cin.tie(0);
	in();
	get_ans();
	out();
	return 0;
}

Measured memory_bytes: 3072
while True:
    n=input()
    if n==0:
        break
    board=[[0]*n for unused in xrange(n)]
    y,x=n/2+1,n/2
    board[y][x]=1
    for i in xrange(2,n*n+1):
        ny,nx=(y+1)%n,(x+1)%n
        while True:
            if board[ny][nx]==0:
                y,x=ny,nx
                break
            else:
                ny,nx=(ny+1)%n,(nx+n-1)%n
        board[y][x]=i
        
    for i in xrange(n):
        print "".join(map(lambda s:str(s).rjust(4),board[i]))

Measured memory_bytes: 4268
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL f(LL x){
	return x * x * x;
}
int main(){
	LL N, K;
	scanf("%lld %lld", &N, &K);
	if(K & 1) printf("%lld", f(N / K));
	else printf("%lld", f(N / K) + f(N / K + (N % K >= K / 2)));
}

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

using namespace std;

int main(){
  int n;
  cin>>n;
  while(n--){
    int p,q;
    cin>>p>>q;
    bool f=false;
    for(long long i=0;i<=20000;i++){
      for(long long j=0;i*i+j*j<p*p+q*q;j++){
	if(i==0&&j==0||min(i,j)==0&&max(i,j)==1)continue;
	for(int k=-1;k<=1;k+=2){
	  long long n=j*k;
	  f|=((i*p+n*q)%(i*i+n*n)==0)&&((i*q-n*p)%(i*i+n*n)==0);
	}
      }
    }
    cout<<"PC"[f]<<endl;
  }
}

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

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

  map<int,vector<int>> mp;

  int a,b;
  for(int i=0;i<n;i++){
    cin >> a >> b;
    mp[a].push_back(b);
  }
  int ans = 0;
  priority_queue<int> q;
  for(int i=1;i<=m;i++){
    for(int x : mp[i]){
      q.push(x);
    }
    if(q.size() == 0){
      continue;
    }else{
      ans+=q.top();
      q.pop();
    }
  }
  cout << ans;
}

Measured memory_bytes: 10880
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;

ll modadd(ll a,ll b,ll mod=MOD){
    return (a%mod+b%mod)%mod;
}

ll modsub(ll a,ll b,ll mod=MOD){
    a%=mod;
    b%=mod;
    if(a>=b) return a-b;
    else return mod-b+a;
}

ll modmul(ll a,ll b,ll mod=MOD){
    return ((a%mod)*(b%mod))%mod;
}

ll modpow(ll a, ll n,ll mod=MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll moddiv(ll a,ll b,ll mod=MOD) {
    return modmul(a, modpow(b, mod-2));
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,M;
    cin>>N>>M;
    
    if(N>M){
        ll tmp=N;
        N=M;
        M=tmp;
    }
    
    vll factorial(M+1);
    factorial[0]=1;
    for(ll i=1;i<=M;i++){
        factorial[i]=modmul(factorial[i-1],i);
    }
    
    if(N==M-1){
        cout<<modmul(factorial[N],factorial[M])<<endl;
    }else if(N==M){
        cout<<modmul(modmul(factorial[N],factorial[M]),2)<<endl;
    }else cout<<0<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
  int h, w, f=0;
  char qq[53][53];
  cin >> h >> w;
  for(int i=0; i<52; i++){
    for(int j=0; j<52; j++){
      qq[i][j] = '.';
    }
  }
  for(int i=1; i<h+1; i++){
    for(int j=1; j<w+1; j++){
      cin >> qq[i][j];
    }
  }
  for(int i=0; i<52; i++){
    for(int j=0; j<52; j++){
      if(qq[i][j]=='#'){
        if(qq[i-1][j]=='.'&&qq[i][j-1]=='.'&&qq[i+1][j]=='.'&&qq[i][j+1]=='.'){
          f++;
        } 
      }
    }
  }
  if(f>0) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
from fractions import gcd
def lcm(x,y):
    return x*y//gcd(x,y)
n,m = map(int,input().split())
s=input()
t=input()

l=lcm(n,m)
x=dict()

for i in range(n):
    x[i*(l//n)]=s[i]

for i in range(m):
    j=i*(l//m)
    if j in x and x[j]!=t[i]:
        print(-1)
        exit()
print(l)


Measured memory_bytes: 17488
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N,A,B;

int main(){
    cin >> N >> A >> B;
    vector<int> P(N); 
    rep(i,N) cin >> P[i];
    sort(all(P));

    int x=0,y=0,z=0;
    rep(i,N){
        if(P[i] <= A) x++;
        else if(A+1<=P[i] and P[i]<=B) y++;
        else if(B+1<=P[i]) z++;
    }

    cout << min({x,y,z}) << endl;
}


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

int main(){
    ll n,m; cin >> n >> m;
    ll s=0,c=0;
    ll ans = min(n,m/2);
    c=m-ans*2;
    if(c>1){
        ans+=c/4;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    LL n,l,t,init,rr;
    vector<LL> pos,dir,right,left;
    vector<pair<LL,LL>> fin;
    Problem(LL n):n(n),rr(-1),pos(n),dir(n),fin(n){};

    void solve(){
        cin >> l >> t;
        bool rev=true, cl=true;
        for(LL i=0; i<n; ++i){
            cin >> pos[i] >> dir[i];
            if(dir[i]==1){
                rev=false;
                if(rr==-1)rr=i;
                fin[i]={(pos[i]+t)%l,1};
            }else{
                cl=false;
                fin[i]={((pos[i]-t)%l+l)%l,2};
            }
        }
        if(rev){
            for(LL i=0; i<n; ++i){
                cout << ((pos[i]-t)%l+l)%l <<"\n";;
            }
            return;
        }
        if(cl){
            for(LL i=0; i<n; ++i){
                cout << ((pos[i]+t)%l+l)%l <<"\n";;
            }
            return;
        }
        for(LL i=0; i<n; ++i){
            if(dir[i]==1){
                right.push_back((pos[rr]-pos[i]+l)%l);
            }else{
                left.push_back((pos[i]-pos[rr]+l)%l);
           }
        }
        sort(right.begin(),right.end());
        sort(left.begin(),left.end());
        init=left[0];
        DBG(init)
        for(auto & x: left){
            x-=init;
        }
        DBG(left)
        sort(fin.begin(),fin.end());
        LL ub=1e9, lb=-1;
        LL tmp=0;
        while(ub-lb>1){
            LL mid=(ub+lb)/2;
            if(check(mid,tmp))ub=mid;
            else lb=mid;
        }
        LL findir=ub%2==0?1:2;
        LL finpos=0;
        check(ub,finpos);
        DBG(finpos,findir)
        finpos=((finpos+pos[rr])%l+l)%l;
        LL it=lower_bound(fin.begin(),fin.end(),make_pair((LL)finpos,findir))-fin.begin();
        DBG(ub,it)
        for(LL i=0; i<n; ++i){
            DBG( fin[((i+it-rr)%n+n)%n])
            cout << fin[((i+it-rr)%n+n)%n].first <<"\n";
        }
    }
    bool check(LL m, LL &tm){
        LL sum=init,rcnt=(m+1)/2,lcnt=m/2;tm=init;
        DBG(tm)
        sum+=rcnt/(LL)right.size()*l+(rcnt%(LL)right.size()==0?0:right[rcnt%(LL)right.size()]);
        tm-=rcnt/(LL)right.size()*l+(rcnt%(LL)right.size()==0?0:right[rcnt%(LL)right.size()]);
        DBG(m,sum,tm)
        sum+=lcnt/(LL)left.size()*l+(lcnt%(LL)left.size()==0?0:left[lcnt%(LL)left.size()]);
        tm+=lcnt/(LL)left.size()*l+(lcnt%(LL)left.size()==0?0:left[lcnt%(LL)left.size()]);
        DBG(m,sum,tm)
        if(m%2==0){
            assert((tm-sum+t*2)%2==0);
            tm=(tm-sum+t*2)/2;
        }else{
            //tm=round((double)tm/2+(double)t-(double)sum/2.0);
            assert((tm+sum-t*2)%2==0);
            tm=(tm+sum-t*2)/2;

        }
        DBG(tm)
        return sum>=2*t;
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 5364
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = -(1e18+1);
    chmax(ans,a*c);
    chmax(ans,a*d);
    chmax(ans,b*c);
    chmax(ans,b*d);
    cout << ans << endl;
}

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

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
    int N;
    string S;
    cin >> N >> S;
    for (char c : S) {
        char t = c + N;
        if (t > 'Z') t -= 26;
        cout << t;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	int n; cin >> n;
	ll a[n], l = 0, h = 0;
	FOR(n) cin >> a[i], h += a[i];
	ll ans = h;
	FOR(n){
		l += a[i];
		h -= a[i];
		ans = min(ans,abs(h-l));
	}
	cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

int main() {
#ifdef LOCAL
  freopen("d.txt", "r", stdin);
// freopen("main.txt", "w", stdout);
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  int n, r;
  set<int> st;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r;
    st.insert(r);
  }
  cout << SZ(st) << endl;
  return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int dx[]={1,0,-1,0};
constexpr int dy[]={0,1,0,-1};
constexpr int ddx[] = {1,1,-1,-1,2,2,2,2,2,-2,-2,-2,-2,-2,1,0,-1,1,0,-1};
constexpr int ddy[] = {1,-1,1,-1,0,1,2,-1,-2,2,1,0,-1,-2,2,2,2,-2,-2,-2};
constexpr int INF = 1<<28;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W,C_h,C_w,D_h,D_w;
  cin>>H>>W>>C_h>>C_w>>D_h>>D_w;
  C_h--,C_w--,D_h--,D_w--;
  vector S(H,vector<char>(W));
  rep(i,H)rep(j,W)cin>>S[i][j];

  vector dist(H,vector(W,INF));
  dist[C_h][C_w] = 0;
  priority_queue<int,vector<int>,greater<>> que;
  que.emplace(C_h*W+C_w);
  while(!que.empty()){
    int cur = que.top();
    que.pop();
    int y = cur/W;
    int x = cur%W;
    rep(i,4){
      int ny = y+dy[i];
      int nx = x+dx[i];
      if(ny<0||nx<0||ny>=H||nx>=W)continue;
      if(S[ny][nx]=='#')continue;
      if(dist[ny][nx]>dist[y][x]){
        dist[ny][nx] = dist[y][x];
        que.emplace(ny*W+nx);
      }
    }
    rep(j,20){
      int ny = y+ddy[j];
      int nx = x+ddx[j];
      if(ny<0||nx<0||ny>=H||nx>=W)continue;
      if(S[ny][nx]=='#')continue;
      if(dist[ny][nx]>dist[y][x]+1){
        dist[ny][nx] = dist[y][x]+1;
        que.emplace(ny*W+nx);
      }
    }
  }
  int ans = dist[D_h][D_w];
  cout<<(ans==INF?-1:ans)<<endl;
}


Measured memory_bytes: 8324
import bisect
import sys
sys.setrecursionlimit(10 ** 7)

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

S = list(input())
T = list(input())

LS = len(S)
LT = len(T)

POS = [[] for _ in range(26)]

for i in range(LS):
    n = ord(S[i]) - 97
    POS[n].append(i)


cnt = 0
prev = -1
for i in range(LT):
    n = ord(T[i]) - 97

    if not POS[n]:
        print(-1)
        exit()

    ps = POS[n]
    p = bisect.bisect_right(ps, prev)

    if p == len(ps):
        cnt += 1
        p = bisect.bisect_right(ps, -1)

    prev = ps[p]


ans = cnt * LS + prev + 1
print(ans)


Measured memory_bytes: 8932
#include <iostream>
#include <stdio.h>
using namespace std;


int main(void){
int e=0,y=0;
cin>>e>>y;
if(e == 0){
if(y >= 1868&& y <= 1911){
cout << "M" << y - 1867<<endl;
}
else if(y>=1912&&y<=1925)
{
cout<<"T"<<y-1911<<endl;
}
else if(y>=1926&&y<=1988)
{cout<<"S"<<y-1925<<endl;
}
else {
cout<<"H"<<y-1988<<endl;
}
}
else{switch (e)
{

case 1:cout<<y+1867<<endl;  break;
case 2:cout<<y+1911<<endl;  break;
case 3:cout<<y+1925<<endl;  break;
case 4:cout<<y+1988<<endl;  break;
}
}



return 0;
}

Measured memory_bytes: 3120