akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, a, b; cin >> n >> a >> b;
	vector<int>x(n); rep(i, n)cin >> x[i];
	int ans = 0;
	rep(i, n - 1) {
		int tmp = x[i + 1] - x[i];
		ans += min(tmp*a, b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    long long N;
    cin >> N;
    vector<long long> vec(N);

    // マイナスの数値の出現回数
    int minus_num = 0;
    // 絶対値の合計値
    long long sum = 0;

    for(int i=0; i < N; i++) {
        long long tmp;
        cin >> tmp;
        
        if(tmp < 0) minus_num++;

        vec.at(i) = abs(tmp);
        sum += vec.at(i);
    }

    if(minus_num % 2 != 0) {
        sort(vec.begin(), vec.end());
        sum -= vec.at(0) * 2;
    }

    cout << sum << endl;

    return 0;
}



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

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

  unordered_map<string, int> freq;
  for(int i=0; i<N; i++){
  	string str;
  	cin >> str;
  	sort(str.begin(), str.end());
    if(freq.count(str)){
      freq.at(str)++;
    }
    else{
      freq[str]= 1;
    }
  }

  int64_t ans= 0;
  for(auto p:freq){
    int64_t cnt= p.second;

    ans+= cnt*(cnt-1)/2;
  }

  cout << ans << endl;
}


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

int main() {
    while (true) {
        int x, y;
        cin >> x >> y;
        
        if (x == 0 && y == 0) break;
        else cout << min(x, y) << " " << max(x, y) << endl;
    }
}


Measured memory_bytes: 3080
#include <stdio.h>

int getReturnMoney( int week, int Money );

int main( void )
{
	int week;
	int returnMoney;
	int i;
	double ratio;
	
	//ratio = 1.05;
	scanf( "%d", &week );
	/*for( i = 1; i < week; i++ )
	{
		ratio *= 1.05;
	}*/
	returnMoney = getReturnMoney( week, 100000 );
	
	printf( "%d\n", returnMoney );
	
	return (0);
}

int getReturnMoney( int week, int Money )
{
	int returnMoney;
	
	returnMoney = Money * 1.05;
	
	//printf( "week:%d money:%d\n", week, returnMoney );
	
	if( returnMoney % 1000 > 0 )
	{
		returnMoney = returnMoney / 1000 * 1000 + 1000;
	}
	
	if( week == 1 )
	{
		return (returnMoney);
	}
	else
	{
		return ( getReturnMoney( week - 1, returnMoney ) );
	}
}

Measured memory_bytes: 592
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

static const int MOD = 1e9 + 7;

bool f(int x, int a, int b) {
    return x < (a + b);
}

int main() {

    int N;
    cin >> N;
    vector<int>L(N);
    for (int i = 0; i < N; i++)cin >> L[i];

    long long ans = 0;
    sort(L.begin(), L.end());

    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            for (int k = j + 1; k < N; k++) {
                if ((L[i] + L[j]) > L[k])ans++;
                else break;
            }
        }
    }

    cout << ans;
}

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

int main(){
  int N,M,total=0,count=0;
  cin>>N>>M;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  for(int i=0;i<N;i++){
    total+=A.at(i);
  }

  for(int i=0;i<N;i++){
    if(A.at(i)<double(double(total)/double(4*M))){

    }
    else
      count++;
  }
  if(count>=M)
    cout<< "Yes"<<endl;
  else{
    cout<< "No"<<endl;
  }
  
 
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        n: usize, k: usize,
        // d1: usize,
        // a1: [usize; d1],
        // d: [usize; k-1],
        // ak: [usize; d[k-2]],
    }
    let mut dp = vec![false; n];

    for _ in 0..k {
        input! {
            d: usize,
            a: [usize; d],
        }
        for i in 0..d {
            dp[a[i] - 1] = true;
        }
    }

    println!("{}", dp.iter().filter(|&&x| x == false).count());
}


Measured memory_bytes: 2208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////



int main(){
    string s;ll d;cin>>s>>d;
    ll n=s.size();
    ll dp[n+1][d][2];memset(dp,0,sizeof(dp));
    dp[0][0][0]=1;
    rep(i,0,n-1){
        rep(j,0,d-1){
            rep(k,0,9){
                Add(&dp[i+1][(j+k)%d][1],dp[i][j][1]);
            }
            ll t=s[i]-'0';
            rep(k,0,t-1){
                Add(&dp[i+1][(j+k)%d][1],dp[i][j][0]);
            }
            Add(&dp[i+1][(j+t)%d][0],dp[i][j][0]);
        }
    }
    ll ans=0;
    rep(i,0,1){
        Add(&ans,dp[n][0][i]);
    }
    cout<<mod(ans-1)<<endl;
    
    return 0;
}






Measured memory_bytes: 15872
#include<stdio.h>
double x[22];
double y[22];
int main(){
    double a,b;
    int now=1;
    while(~scanf("%lf,%lf",&a,&b)){
        x[now]=a;
        y[now++]=b;
    }
    x[0]=x[now-1];
    x[now]=x[1];
    double S=0;
    for(int i=1;i<now;i++){
        S+=(x[i+1]-x[i-1])*y[i];
    }
    if(S<0)S=-S;
    printf("%.8lf",S/2.0);
}


Measured memory_bytes: 2012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp fixed << setprecision
#define pb(x) push_back(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll X, Y;
    cin >> X >> Y;
    if(abs(X-Y) <= 1) cout << "Brown" << endl;
    else cout << "Alice" << endl;
}

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

int main()
{
  string S, T;
  int count= 0;
  cin >> S >> T;  

  for(int i = 0; i < (int)S.size(); i++)
  {
    if(S[i] == T[i]){
      count++;
    }
  }
  cout << count;
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int P[220000];
signed main() {
    cin >> N;
    rep(i, N) { cin >> P[i]; }
    int ans = 0, lb = LLONG_MAX;
    rep(i, N) {
        if (P[i] < lb) {
            lb = P[i];
            ans++;
        }
    }
    cout << ans << endl;
}


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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    string a,b,c;
    cin>>a>>b>>c;
    bool cnd1 = a[a.size() - 1] == b[0];
    bool cnd2 = b[b.size() - 1] == c[0];
    if (cnd1 && cnd2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


Measured memory_bytes: 256
n=int(input())
res=[]
for i in range(n):
    res.append(input())

from collections import defaultdict
cnt=defaultdict(int)
cnt["AC"]=0
cnt["TLE"]=0
cnt["WA"]=0
cnt["RE"]=0
for i in res:
    cnt[i]+=1
for i in ["AC","WA","TLE","RE"]:
    print(i,"x",cnt[i])

Measured memory_bytes: 16544
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

const int N=2e5+5;

ll id[N],a[N];

int main()
{ios_base::sync_with_stdio(false);
ll n,x,m;
cin>>n>>x>>m;
ll ans=0;

ll ptr=1,lo=0,hi=0;
a[1]=x;

while(1)
{
	if(ptr>n)
	{
		ol(ans);
		return 0;
	}
	if(ptr!=1)
	{
		a[ptr]=(a[ptr-1]*a[ptr-1])%m;
	}
	if(id[a[ptr]])
	{
		lo=id[a[ptr]];
		hi=ptr-1;
		break;
	}
	id[a[ptr]]=ptr;
	ans=ans+a[ptr];
	ptr++;
}
ll rem=n-ptr+1;
ll cyc=hi-lo+1;
ll cnt=rem/cyc,s=0;
rep(i,lo,hi)s+=a[i];

ans+=cnt*s;

rem%=cyc;

rep(i,lo,lo+rem-1)ans+=a[i];

ol(ans);

return 0;
}



Measured memory_bytes: 4772
#include <iostream>
#include<vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define int long long

vector<int> mai;
vector<int> pras;

signed main(){
    int n,k;cin>>n>>k;
	pras.push_back(0);
	FOR(i,0,n-1)
	{
		int a;cin>>a;
		if(a<0) mai.push_back(a);
		else if (a > 0) pras.push_back(a);
		else k--;
	}
	
	if(k == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	mai.push_back(0);
	reverse(mai.begin(),mai.end());
	
	int ans = 123456789012345;

	FOR(i,0,k)
	{
		
		if(i > mai.size()-1 || k-i > pras.size()-1) continue;
		ans = min(ans,-mai[i]+pras[k-i]+min(-mai[i],pras[k-i]));
		
	}
	
	cout << ans << endl;
	
}


Measured memory_bytes: 1656
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std; 
typedef unsigned long long ll;
//Have your way LORD (YAH-WEH)
ll binpow(ll a, ll b){
	ll res = 1;
	while(b>0){
		if(b&1) res = (res*a)%998244353;
		a = (a*a)%998244353;
		b >>= 1;
		res %= 998244353;
	}
	return res%998244353;
}
int main(){
	ll n; cin>>n; vector<ll> v;
	ll arr[n];
	for(int i = 0; i < n; i++){
		cin>>arr[i];
	}
	if(arr[0] != 0) { cout<<0<<"\n"; return 0;}
	sort(arr,arr+n);
	for(int i = 1; i < n; i++){
		if(arr[i]-arr[i-1] > 1) { cout<<0<<"\n"; return 0;}
	}
	for(int i = 1; i < n; i++){
		if(arr[i] == 0) { cout<<0<<"\n"; return 0;}
	}
	ll co = 1;
	for(int i = 2; i < n; i++){
		if(arr[i] == arr[i-1]) co++;
		else{
			v.push_back(co);
			co = 1;
		}
	}
	v.push_back(co);
	ll ans = 1; ll prev = 1;
	for(int i = 0; i < v.size(); i++){
		ans *= binpow(prev,v[i]);
		ans %= 998244353;
		prev = v[i];
	}
	cout<<ans%998244353<<"\n";
}


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

signed main(){
  
  int N;
  string A, B, C;

  cin>>N>>A>>B>>C;
  
  int ans = 0;

  for(int i=0;i<N;i++){
    
    map<char,int> cnt;
    
    cnt[A[i]]++;
    cnt[B[i]]++;
    cnt[C[i]]++;
    
    int maxp = 0;
    
    for(auto p : cnt){
      maxp = max( maxp, p.second );
    }
    
    ans += 3 - maxp;
    
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  long long n;
  cin>>n;
  long long ans;
  if(n==1) ans=0;
  if(n==2) ans=1;
  if(n>=3){
    ans=n*(n-1)/2;
  }
  //  cout<<ans<<endl;
  int buf=n;
  int tmp=0;
  long long sum=0;
  while(1){
    tmp=buf/2+1;
    sum=sum+buf%tmp-tmp+1;
    buf=tmp-1;
    if(buf<=4) break;
  }
  if(sum>0) ans+=sum;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
#pragma comment(linker, "/STACK:16000000")
//#define map gp_hash_table
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
namespace Geometry{
	struct point{
		double x;double y;
		void print(){
			printf("Point:x:%.8lf,y:%.8lf",x,y);
		}
	};
	struct line{
		double x;double c;
		void print(){
			printf("Line:x:%.8lf,c:%.8lf\n",x,c);
		}
	};
	line make_line(point a,point b){
		double x=(a.x-b.x)/(a.y-b.y);
		double c=a.y-(a.x)*(x);
		return (line){x,c};
	}
}
#define int long long
using namespace Geometry;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const long long inf2=0x3f3f3f3f3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
const int MAX_N=1e6;
struct BIT{
	int bit[MAX_N+1],BITN=1e6;
	//sum a[1,i]
	void init1(){
		for(int i=0;i<MAX_N;i++)bit[i]=0;
	}
	void init(vector<int> v){
		for(int i=0;i<v.size();i++)add(i+1,v[i]);
	}
	int sum(int i){
		int s=0;
		while(i>0){
			s+=bit[i];
			i=(i)&(i-1);
		}
		return s;
	}
	//a[i]+=x
	void add(int i,int x){
		while(i<=BITN){
			bit[i]+=x;
			i+=(i)&(-i);
		}
	}
}bit;
int n;
int a[111111];
int cmp[111111];
int pre[111111];
bool check(int x){
	bit.init1();
	int sum=0;
	memset(pre,0,sizeof(pre));
	for(int i=1;i<=n;i++)pre[i]=pre[i-1]+(a[i]>=x?1:-1);
	for(int i=0;i<=n;i++){
		sum+=bit.sum(pre[i]+5e5);
		bit.add(pre[i]+5e5,1);
	}
	return sum>=1ll*(n+1)*n/4;
}
signed main(){
	scanf("%d",&n);
	if(n==1){
		int x;
		cin>>x;
		cout<<x<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int l=-1,r=2e9;
	while(r-l>1){
		int mid=l+r>>1;
		bool data=check(mid);
		if(data)l=mid;
		else r=mid;
	}
	cout<<l<<endl;
	return 0;
}
/*
10
5 9 5 9 8 9 3 5 4 3
*/

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

#define eb emplace_back
#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define ll long long

const int N = 1e6 + 9;
const int INF = 1e9 + 9;

#define int ll

void solve() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    for (int i = 0; i < n; ++ i) {
    	ll m1 = a + c * i - d * (n - 1 - i);
    	ll m2 = a + d * i - c * (n - 1 - i);
    	if (m1 <= b and b <= m2) {
    		cout << "YES\n";
    		return;
    	}
    }
    cout << "NO";
}

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


Measured memory_bytes: 256
n,m = map(int,input().split())
ac = [0 for _ in range(n)]
wa = [0 for _ in range(n)]
for _ in range(m):
  a,b = input().split()
  a = int(a) - 1
  if b == 'AC':
    ac[a] = 1
  elif ac[a] == 0:
    wa[a] += 1
for i in range(n):
  wa[i] *= ac[i]
print(sum(ac),sum(wa))

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()

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



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

using namespace std;
#define pb push_back
const int Nmax = 100000 + 5;
int n, Fi[Nmax], Fj[Nmax], m, d, q;
vector<int> v[Nmax];
int main()
{
    cin >> n >> m >> d;
    for(int i = 1; i <= n; ++i)
        for(int j = 1, x; j <= m; ++j)
        {
            cin >> x;
            Fi[x] = i;
            Fj[x] = j;
        }
    for(int r = 1; r <= d; ++r)
    {
        int cc = 0, li = Fi[r], lj = Fj[r], rr = r;
        while(rr <= 300 * 300 && Fi[rr])
        {
            cc += abs(li - Fi[rr]) + abs(lj - Fj[rr]);
            li = Fi[rr]; lj = Fj[rr];
            v[r].pb(cc);
            rr += d;
        }
    }
    cin >> q;
    for(int i = 1, x, y; i <= q; ++i)
    {
        cin >> x >> y;
        int rr = x % d;
        if(!rr)rr = d, y--, x--;
        int ans = v[rr][y / d];
        if(x / d != 0)ans -= v[rr][x / d];
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 6272
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define ll long long
using namespace std;
int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	/*int x;
	cin >> x;
	ll sum = 0;
	sum += (x / 500) * 1000;
	x = x % 500;
	sum += x / 5 * 5;
	cout << sum << endl;*/
	string s;
	cin >> s;
	if (s[2]==s[3]&&s[4]==s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    from collections import Counter

    n, m = map(int, input().split())
    a = Counter(list(map(int, input().split())))

    for i in range(m):
        bi, ci = map(int, input().split())
        a[ci] += bi

    cards = sorted(a.items(), key=lambda x: x[0], reverse=True)
    ans = 0

    for number, count in cards:
        if n > count:
            ans += number * count
            n -= count
        else:
            ans += number * n
            print(ans)
            exit()



if __name__ == '__main__':
    main()


Measured memory_bytes: 42652
#include <iostream>

using namespace std;

int main()
{
	int x, y;

	while(1){
		cin >> x >> y;
		if(x == 0 && y == 0)
			break;

		if(x < y)
			cout << x << " " << y << endl;
 		else
			cout << y << " " << x << endl;
	}

	return 0;
}


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

using namespace std;

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

    uint64_t minima = UINT64_MAX;
    for (uint64_t x = 1; x*x <= n; x++) {
        if (n % x == 0) {
            uint64_t y = n / x;
            minima = min(minima, (x + y - 2));
        }
    }

    cout << minima << endl;
}

Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import sys
import math
import fractions
def j(a):
    if a==1: print("Yes")
    else :print("No")


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#x = ip()                              #入力整数1つ
x,y = (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#a,b,c,k = (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
a = []
num=x
for i in range(x):
    a.append(ip())
y-=sum(a)
while y>=min(a):
    num+=1
    y-=min(a)
print(num)

Measured memory_bytes: 5104
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b=mp()
if a%3==0 or b%3==0 or (a+b)%3==0:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 5076
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 998244353

N = int(input())
XY = [[int(x) for x in input().split()] for _ in range(N)]
XY.sort() # X ascending
X,Y = zip(*XY)
Y_rank = {x:i for i,x in enumerate(sorted(Y),1)}

def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x & (-x)

def BIT_sum(tree,x):
    ret = 0
    while x:
        ret += tree[x]
        x -= x & (-x)
    return ret

pow2 = [1]
for _ in range(N):
    pow2.append(pow2[-1] * 2 % MOD)

answer = 0
tree = [0] * (N+1)
for L,(x,y) in enumerate(XY):
    y = Y_rank[y]
    R = N - 1 - L
    D = y - 1
    U = N - 1 - D
    LD = BIT_sum(tree,y)
    BIT_update(tree,y)
    LU = L - LD
    RD = D - LD
    RU = R - RD
    # bounding box が自分自身を含むような集合を数える
    # 全体から引く
    cnt = pow2[N]
    cnt -= pow2[L]
    cnt -= pow2[R]
    cnt -= pow2[D]
    cnt -= pow2[U]
    cnt += pow2[LD]
    cnt += pow2[LU]
    cnt += pow2[RD]
    cnt += pow2[RU]
    cnt -= 1
    answer += cnt

answer %= MOD

print(answer)

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

typedef long long LL;

const int N=500;
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};

int n,p[N*N+9][2];

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n*n;++i){
	int x;
	scanf("%d",&x);
	p[i][0]=(x-1)/n+1;p[i][1]=(x-1)%n+1;
  }
}

int dis[N+9][N+9],vis[N+9][N+9];
queue<int>qx,qy;

bool Out_map(int x,int y){return x<1||x>n||y<1||y>n;}

void Bfs_dis(){
  for (int i=1;i<=n;++i){
	dis[1][i]=dis[i][1]=dis[n][i]=dis[i][n]=1;
	qx.push(1);qy.push(i);
	qx.push(i);qy.push(1);
	qx.push(n);qy.push(i);
	qx.push(i);qy.push(n);
  }
  for (;!qx.empty();){
	int x=qx.front(),y=qy.front();qx.pop();qy.pop();
	vis[x][y]=1;
	for (int i=0;i<4;++i){
	  int nx=x+dx[i],ny=y+dy[i];
	  if (Out_map(nx,ny)) continue;
	  if (dis[nx][ny]) continue;
	  dis[nx][ny]=dis[x][y]+1;
	  qx.push(nx);qy.push(ny);
	}
  }
}

void Dfs_dis(int x,int y){
  for (int i=0;i<4;++i){
	int nx=x+dx[i],ny=y+dy[i];
	if (Out_map(nx,ny)) continue;
	if (dis[nx][ny]<=dis[x][y]+vis[nx][ny]) continue;
	dis[nx][ny]=dis[x][y]+vis[nx][ny];
	Dfs_dis(nx,ny);
  }
}

int ans;

void Get_ans(){
  for (int i=1;i<=n*n;++i){
	int x=p[i][0],y=p[i][1];
	vis[x][y]=0;
	ans+=--dis[x][y];
	Dfs_dis(x,y);
  }
}

void work(){
  Bfs_dis();
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 26888
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  int sum = 0;
  
  for(int &x : a){
    cin >> x;
    sum += x;
  }
  
  sort(a.rbegin(), a.rend());
  sum -= a.at(0);
  if(sum > a.at(0)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <bitset>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 10050;
int N;
std::string S[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> S[i];
    }

    long long ret = 0;;
    long long A_last = 0;
    long long B_first = 0;
    long long both = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < S[i].size() - 1; j++) {
            if (S[i][j] == 'A' && S[i][j+1] == 'B') {
                ret++;
            }
        }
        if (S[i][0] == 'B' && S[i][S[i].size()-1] == 'A') {
            both++;
        } else if (S[i][0] == 'B') {
            B_first++;
        } else if (S[i][S[i].size()-1] == 'A') {
            A_last++;
        }
    }

    //std::cout << both << " " << B_first << " " << A_last << " " << ret << std::endl;

    if (0 < both) {
        ret += both - 1;
        both = 1;
    }

    if (both == 1 && 0 < A_last && 0 < B_first) {
        ret += 2;
        both = 0;
        A_last--;
        B_first--;
        ret += std::min(A_last, B_first);
    } else if (both == 1 && 0 < A_last + B_first) {
        ret++;
    } else {
        ret += std::min(A_last, B_first);
    }

    

    std::cout << ret << std::endl;
    

    return 0;
}


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

using namespace std;

int cnt[100010];

int main(){
        vector <int> a;
        int N;
        cin>>N;
        for(int i=0;i<100010;i++){
                cnt[i]=0;
        }
        for(int i=0;i<N;i++){
                int aa;
                cin>>aa;
                a.push_back(aa);
                cnt[aa]++;
                if(aa<=99999)
                        cnt[aa+1]++;
                if(aa>0)
                        cnt[aa-1]++;
        }
        int res=0;
        for(int i=0;i<100001;i++){
                if(res<cnt[i]){
                        res=cnt[i];
                }
        }
        cout<<res<<endl;
        return 0;
}


Measured memory_bytes: 1276
a,b,c=map(int,input().split())
import math
import sys
m=9223372036854775808
A=math.sqrt(a)
B=math.sqrt(b)
C=math.sqrt(c)
d=c-a-b
e=a*b*4
f=d*d
if e<f and d>0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
"use strict";
const main = arg => {
  let Min = arg.split(" ")[0];
  let Max = arg.split(" ")[1];
  let cnt = 0;
  for(let i = Min; i <= Max; i++) {
    if(String(i) === String(i).split('').reverse().join('')){
    	cnt++;
    };
  }
  console.log(cnt);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 13468
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,m;
	int ans=0;
	cin >>n>>m;
	priority_queue<int>data;
	VPi list(n);
	int a,b;
	rep(i,n){
		cin>>a>>b;
		list[i]=mp(a,b);
	}
	sort(all(list));
	auto ter=list.begin();
	rep(i,m){
		while(ter->F <=i+1){
			data.push(ter->S);
			ter++;
			if(ter==list.end()){
				list[0].F=INF;
				ter=list.begin();
				
			}
		}
		if(!data.empty()){
		ans+=data.top();
		data.pop();
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4680
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000

int main(){
    int A,B,K;
    cin>>A>>B>>K;
    int l=min(A,B),ans=0;
    for(int i=l;;i--){
        if(A%i==0 and B%i==0){
            ans++;
        }
        if(ans==K){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+100;
int main(){
	int n;
	cin >> n;
	int x = n / 500;
	ll ans = 0;
	ans = 1000 * 1ll * x;
	int p = n % 500;
	p = p / 5;
	ans += 1ll * p * 5;
	cout << ans << endl;
	return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
int N;
	cin >> N;
	int ans = INT_MAX;
	fx(N+1) {
		int nine = x;
		int six = N - x;
		int sum = 0;
		while(nine>0){
			sum += nine % 9;
			nine /= 9;
		}
		while (six>0) {
			sum += six % 6;
			six /= 6;
		}
		ans = min(sum, ans);

	}
	ce(ans)

    return 0;
}



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

int main()
{
    std::string s;
    std::cin >> s;
    if ((s.front() == s.back()) == (s.size() % 2 == 1))
    {
        std::cout << "Second";
    }
    else
    {
        std::cout << "First";
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 512
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    from itertools import accumulate
    S = [i for i in accumulate(range(1, min(N+1, 100000)))]

    def is_ok(mid):
        if N <= S[mid]:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = len(S)
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right

    ans = binary_search_meguru() + 1
    print(ans)


if __name__ == '__main__':
    main()


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

// 2^i <= x を満たす最大の i
int log_x(int x){
    return 31 - __builtin_clz(x);
}

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    multiset<int> se;
    for (int i = 0; i < N; ++i) {
        se.insert(A[i]);
    }
    ll ans = 0;
    while (! se.empty()){
        auto iter = se.end();
        iter--;
        int x = *iter;
        se.erase(iter);
        int i = log_x(x);
        x = pow(2, i+1) - x;
        iter = se.find(x);
        if(iter != se.end()){
            ans++;
            se.erase(iter);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 10368
# -*- coding: utf-8 -*-

N = int(input())

values = [0]*N
value_count_map = {}
for i in range(N):
    in_value = int(input())
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1

sorted_values = sorted(value_count_map.keys(), reverse=True)
max_value = sorted_values[0]
max_value_count = value_count_map[max_value]
next_max_value = max_value
if len(sorted_values) > 1:
    next_max_value = sorted_values[1]

for row in range(N):
    if values[row] == max_value and max_value_count == 1:
        print(next_max_value)
    else:
        print(max_value)


Measured memory_bytes: 19580
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	


	void solve(){

		ini(n);
		ini(k);
		vi w(n);
		vi m(n);
		vi tmp[4];
		FOR(i,0,n){
			in(w[i]);
			in(m[i]);
			tmp[w[i]-w[0]].push_back(m[i]);
		}
		sort(all(tmp[0]),greater<int>());
		sort(all(tmp[1]),greater<int>());
		sort(all(tmp[2]),greater<int>());
		sort(all(tmp[3]),greater<int>());
		int rick = 0;
		FOR(i,0,tmp[0].size()+1){
			FOR(i1,0,tmp[1].size()+1){
				FOR(i2,0,tmp[2].size()+1){
					FOR(i3,0,tmp[3].size()+1){
						int tmp1 = 0;
						tmp1+=i*(w[0]+0);
						tmp1+=i1*(w[0]+1);
						tmp1+=i2*(w[0]+2);
						tmp1+=i3*(w[0]+3);
						if(tmp1>k)continue;
						tmp1 = 0;
						FOR(x,0,i){
							tmp1+=tmp[0][x];
						}
						FOR(x,0,i1){
							tmp1+=tmp[1][x];
						}
						FOR(x,0,i2){
							tmp1+=tmp[2][x];
						}
						FOR(x,0,i3){
							tmp1+=tmp[3][x];
						}
						rick = max(tmp1,rick);
					}
				}
			}
		}
		out(rick);









	}	























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 1000100;


int main(){
    ll w,h,v,t,x,y,p,q;
    cin >>w >>h >>v >>t >>x >>y >>p >>q;

    ll r = v*t;

    ll y1 = q, y2 = h+(h-q);
    vector<ll> yy;
    for(int i=-N/2; i<=N/2; ++i){
        yy.pb(y1+h*i*2);
        yy.pb(y2+h*i*2);
    }
    sort(all(yy));

    ll ans = 0;
    for(int i=-N; i<=N; ++i){
        ll X = w*i;
        if(i%2==0) X+=p;
        else X+=w-p;

        if(abs(X-x) > r) continue;

        ll D = r*r - (X-x)*(X-x);
        if(D<0) continue;

        ll ly = y-(ll)sqrt(D);
        ll ry = y+(ll)sqrt(D);

        int lidx = lower_bound(all(yy), ly) - yy.begin();
        int ridx = upper_bound(all(yy), ry) - yy.begin();
        ans += ridx-lidx;

        // printf(" %d: [%d] %d ~ [%d] %d\n",i,lidx,yy[lidx],ridx,yy[ridx]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 19372
from collections import deque
import sys

h, w = map(int, input().split())
sy, sx = map(lambda x: int(x)-1, input().split())
gy, gx = map(lambda x: int(x)-1, input().split())
S = [[0 if s == '.' else -1 for s in input()] for _ in range(h)]

d = deque([(sy, sx)])
cur = 1
while True:
    visited = set()
    while d:
        y, x = d.pop()
        visited.add((y, x))
        S[y][x] = cur
        if (y, x) == (gy, gx):
            print(cur-1)
            sys.exit()
        for dyi, dxi in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            if 0<=y+dyi<h and 0<=x+dxi<w and S[y+dyi][x+dxi] == 0:
                d.append((y+dyi, x+dxi))

    for y, x in visited:
        for dyi in range(-2, 3):
            for dxi in range(-2, 3):
                if 0<=y+dyi<h and 0<=x+dxi<w and S[y+dyi][x+dxi] == 0:
                    d.append((y+dyi, x+dxi))
    if not d:
        print(-1)
        sys.exit()
    cur += 1


Measured memory_bytes: 92856
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const ll INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool reversedx = false;
bool reversedy = false;

ll funcx(ll x){
	if(x>=0)return x;
	reversedx = true;
	return -x;
}

ll funcy(ll y){
	if(y>=0)return y;
	reversedy = true;
	return -y;
}


ll outx(ll x){
	return x * (reversedx ? -1 : 1);
}

ll outy(ll x){
	return x * (reversedy ? -1 : 1);
}

int main(){
	bool swaped = false;
	ll k;
	ll x, y;
	cin >> k >> x >> y;
	x = funcx(x);
	y = funcy(y);
	if(x<y){
		swap(x, y);
		swaped = true;
	}
	if((~k&1)&&(x+y)&1){
		cout << -1 << endl;
		return 0;
	}
	vector<pll> line;
	line.emplace_back(0, 0);
	if(x+y<k&&(x+y)&1){
		line.emplace_back(x, x-k);
		line.emplace_back(x + (k+x-y)/2, x-k + (k-x+y)/2);
		line.emplace_back(x, y);
		cout << 3 << endl;
		if(swaped)foreach(i, line)swap(i.first, i.second);
		repa(i, line.size())cout << outx(line[i].first) << " " << outy(line[i].second) << endl;
		return 0;
	}
	int n;
	if(x+y<k&&~(x+y)&1){
		n = 2;
	}
	else if(((k-(x+y)%k)%k)&1){
		n = (x+y+k-1)/k+1;
	}else{
		n = (x+y+k-1)/k;
	}
	if(n==1){
		if(swaped)swap(x, y);
		cout << 1 << endl;
		cout << outx(x) << " " << outy(y) << endl;
		return 0;
	}
	cout << n << endl;
	ll d = (n * k - x - y) / 2;
	line.emplace_back(k-d, -d);
	repa(i, n){
		ll nx = line.back().first;
		ll ny = line.back().second;
		d = x-nx;
		line.emplace_back(nx + min(k, d), ny + max(0ll, k-d));
	}

	if(swaped)foreach(i, line)swap(i.first, i.second);

	repa(i, line.size())cout << outx(line[i].first) << " " << outy(line[i].second) << endl;


	return 0;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  if (s == "zyxwvutsrqponmlkjihgfedcba") {
    puts("-1");
  }
  else if (s.size() == 26) {
    int i = 25;
    while (i > 0 && s[i] < s[i-1]) --i;
    --i;
    int j = 25;
    while (s[j] < s[i]) --j;;
    swap(s[i], s[j]);
    s.resize(i+1);
    cout << s << endl;
  }
  else {
    string now = s;
    sort(now.begin(), now.end());
    char c = 'a';
    for (char x : now)
      c += c == x;
    s.push_back(c);
    cout << s << endl;
  }
  return 0;
}

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

using namespace std;

char dx[] = {-1,1,0,0};
char dy[] = {0,0,-1,1};
char dice[6][2] = {
  {4,2}, {3,5}, {5,0}, {1,4}, {0,3}, {2,1}
};
int board[9], goal[9];

void dfs(int x, int y, int px, int py, int step, int &ans){
  if(step>ans) return;
  int space = 3*x+y;
  for(int i=0;i<4;i++){;
    int nx = x + dx[i], ny = y + dy[i];
    if(nx<0||3<=nx||ny<0||3<=ny) continue;
    if(nx==px&&ny==py) continue;
    int mv = 3*nx+ny;
    int tmp = board[mv];
    board[space] = dice[board[mv]][i/2];
    board[mv] = 6;
    int dif = 0;
    for(int j=0;j<9;j++) dif += (goal[j]!=board[j]/2);
    if(dif==0) ans = step;
    if(step+dif-1<ans) dfs(nx, ny, x, y, step+1, ans);
    board[space] = 6;
    board[mv] = tmp;
  }
}

int main(){
  int x, y;
  while(cin >> y >> x, y){
    char c;
    for(int i=0;i<9;i++) {
      cin >> c;
      if(c=='W') goal[i] = 0;
      if(c=='B') goal[i] = 1;
      if(c=='R') goal[i] = 2;
      if(c=='E') goal[i] = 3;
    }
    memset(board,0,sizeof(board));
    board[3*(x-1)+y-1] = 6;
    int dif = 0;
    for(int i=0;i<9;i++) dif += (goal[i]!=board[i]/2);
    int ans = dif==0?0:31;
    dfs(x-1,y-1,-1,-1,1,ans);
    cout << (ans==31?-1:ans) << endl;
  }
}

Measured memory_bytes: 868
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define ll long long
const int N = 2e5 + 5;
int main(){
	int x , y;
	cin >> x >> y;
	if(y >= x) cout << "unsafe" << endl;
	else cout << "safe" << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i > 0; i--)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
template <typename Iter> std::string join(Iter begin, Iter end, std::string const& separator){ std::ostringstream result; if (begin != end){ result << *begin++; }; while (begin != end){ result << separator << *begin++; }; return result.str(); }
using namespace std;
typedef long long ll;
void solve() {
  ll N; cin >> N;
  cout << (N * (N - 1) / 2) << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

#include <algorithm>
#include <array>
#include <chrono>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define FORr(i, m, n) for (ll i = n; i >= (ll)m; i--)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define sortAl(v) sort(v.begin(), v.end())
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())
#define cout(n) cout << fixed << setprecision(n)

int main() {
  ll N;

  cin >> N;
  vector<ll> A(N + 1);

  FOR(i, 1, N + 1) {
    cin >> A[i];
    A[i] -= i;
  }

  vector<ll> tmp(N + 1);
  tmp = A;

  sort(tmp.begin() + 1, tmp.end());

  // 偶数の場合、tmp[(N+1)/ 2] 〜 tmp[(N+2)/2]の間ならなんでもOK
  ll b = tmp[(N + 1) / 2];
  ll sum = 0;
  FOR(i, 1, N + 1) { sum += abs(A[i] - b); }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 8e3 + 30, Mod = 1e9 + 7;
const ll SQ = 330;
const ll K = 2222;
const ll T = 2100;
const ll NN = 2e5 +10;

ll F[N], I[N], x[NN], y[NN], n, ans;
ll dp[2 * K][2 * K];
ll sub(ll a, ll b) {
	return (a + Mod - b) % Mod;
}
ll sum(ll a, ll b) {
	return (a + b) % Mod;
}
ll mul(ll a, ll b) {
	return (a * b) % Mod;
}
ll Pow(ll a, ll b) {
	ll res = 1;
	for (; b; b >>= 1, a = mul(a, a))
		if (b & 1) res = mul(res, a);
	return res;
}
ll C(ll r, ll n) {
	if (r < 0 || r > n) return 0;
	return mul(mul(I[r], I[n - r]), F[n]);
}
int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    F[0] = 1;
    for (int i = 1; i < N; i ++) F[i] = mul(F[i - 1], i);
    I[N - 1] = Pow(F[N - 1], Mod - 2);
    for (int i = N - 2; ~i; i --) I[i] = mul(I[i + 1], i + 1);
	//cout << C(2, 4) << endl;
    cin >> n;
    for (int i = 1; i <= n; i ++)
    	cin >> x[i] >> y[i];
    
    for(int i = 1; i <= n; i ++)
		dp[-x[i] + K][-y[i] + K] ++;
	for (int i = -T + 3; i <= T; i ++)
		for (int j = -T + 3; j <= T; j ++)
			dp[i + K][j + K] = sum(dp[i + K][j + K], sum(dp[i - 1 + K][j + K], dp[i + K][j - 1 + K]));
	for (int i = 1; i <= n; i ++)
		ans = sum(ans, dp[x[i] + K][y[i] + K]);
	for (int i = 1; i <= n; i ++)
		ans = sub(ans, C(x[i] + x[i], x[i] + x[i] + y[i] + y[i]));
	ans = mul(ans, Pow(2, Mod - 2));
	cout << ans << endl;
    return (0);
}

Measured memory_bytes: 151680
#include <stdio.h>

int main(){

    
    int W[100],H[100],i=0,j,k,l; 

 	  scanf("%d",&H[0]);
 	  scanf("%d",&W[0]);
 	  
     while((H[i]!=0)&&(H[i]!=0)){
        
      ++i;
      scanf("%d",&H[i]);
 	  scanf("%d",&W[i]);
      }
      
 	 for(j=0;j<i;++j){
 	 
 	   for(k=0;k<H[j];++k){
	 
	      for(l=0;l<W[j];++l){	
		    printf("#");
	      }
	      printf("\n");
	   }
	      printf("\n");
	 }

    
	return 0;
}

Measured memory_bytes: 572