akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
vector<vector<int>> gridb(2010,vector<int>(2010,0));
int n,k,x,y;
ll getb(int x1,int y1,int x2,int y2){
    return gridb[x2][y2]-gridb[x1][y2]-gridb[x2][y1]+gridb[x1][y1];
}
ll get(int i,int j){
    return getb(0,0,i,j)+getb(i+k,0,2*k,j)+getb(i,j,i+k,j+k)+getb(0,j+k,i,2*k)+getb(i+k,j+k,2*k,2*k);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;
    cin >> n >> k;
    rep(i,n){
        cin >> x >> y >> c;
        if (c == 'W') y += k;
        gridb[x%(2*k)+1][y%(2*k)+1]++;
    }
    rep(i,2*k){
        rep(j,2*k){
            gridb[i+1][j+1] += gridb[i][j+1]+gridb[i+1][j]-gridb[i][j];
        }
    }
    /*
    rep(i,2*k+1){
        rep(j,2*k){
            cout << gridb[i][j] << " ";
        }
        PRINT(gridb[i][2*k]);
    }
    */
    ll ans = 0;
    rep(i,k+1){
        rep(j,k+1){
            chmax(ans,get(i,j));
            chmax(ans,n-get(i,j));
        }
    }
    PRINT(ans);
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll long long

int main() {
	//入力
	int n;
	cin >> n;
	vector<int> x(n);
	vector<int> sortx(n);
	rep(i, n) {
		cin >> x[i];
		sortx[i]= x[i];
	}
	//sort
	sort(sortx.begin(), sortx.end());
	//答え
	rep(i,n) {
		if (x[i] <= sortx[n / 2 - 1]) {
			std::cout << sortx[n / 2] << endl;
		}
		else {
			std::cout << sortx[n / 2 - 1] << endl;
		}
	}
}


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

vector<int> g[100005];
int main(void){
    int n, m;
    cin>>n>>m;
    vector<ll> h(n);
    rep(i, n) cin>>h[i];
    rep(i, m){
        int a, b;
        cin>>a>>b;
        --a;--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    vector<bool> ta(n, true);
    rep(i, n){
        if(ta[i] == false) continue;
        bool ok = true;
        for(auto p : g[i]){
            if(h[p]>=h[i]) ok = false;
            else ta[p] = false;
        }
        if(ok) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9268
#include <iostream>

using namespace std;

struct Dice
{
    int lable1;
    int lable2;
    int lable3;
    int lable4;
    int lable5;
    int lable6;
};

struct Dice num[101];

void mN(Dice &num)
{
    int tmp = num.lable1;
    num.lable1 = num.lable2;
    num.lable2 = num.lable6;
    num.lable6 = num.lable5;
    num.lable5 = tmp;
    
    return ;
}

void mS(Dice &num)
{
    int tmp = num.lable1;
    num.lable1 = num.lable5;
    num.lable5 = num.lable6;
    num.lable6 = num.lable2;
    num.lable2 = tmp;
    
    return ;
}
    
void mE(Dice &num)
{
    int tmp = num.lable1;
    num.lable1 = num.lable4;
    num.lable4 = num.lable6;
    num.lable6 = num.lable3;
    num.lable3 = tmp;
    
    return ;
}

void mW(Dice &num)
{
    int tmp = num.lable1;
    num.lable1 = num.lable3;
    num.lable3 = num.lable6;
    num.lable6 = num.lable4;
    num.lable4 = tmp;
    
    return ;
}

void mSpin(Dice &num)
{
    int tmp = num.lable2;
    num.lable2 = num.lable4;
    num.lable4 = num.lable5;
    num.lable5 = num.lable3;
    num.lable3 = tmp;
    
    return ;
}

bool judge(Dice numA, Dice numB)
{
    int bFlag = false;
    
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if ((numA.lable1 == numB.lable1) && (numA.lable2 == numB.lable2)
                && (numA.lable3 == numB.lable3) && (numA.lable4 == numB.lable4)
                && (numA.lable5 == numB.lable5) && (numA.lable6 == numB.lable6))
            {
                bFlag = true;
                break;
            }
            
            mSpin(numB);
        }
        
        if (true == bFlag)
        {
            break;
        }
        
        mN(numB);
    }
    
    mE(numB);
    
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if ((numA.lable1 == numB.lable1) && (numA.lable2 == numB.lable2)
                && (numA.lable3 == numB.lable3) && (numA.lable4 == numB.lable4)
                && (numA.lable5 == numB.lable5) && (numA.lable6 == numB.lable6))
            {
                bFlag = true;
                break;
            }
            
            mSpin(numB);
        }
        
        if (true == bFlag)
        {
            break;
        }
        
        mN(numB);
    }
    
    return bFlag;
}

int main()
{
    bool bFlag = false;
    int cnt = 0;
    
    cin >> cnt;
    for (int i = 0; i < cnt; i++)
    {
        cin >> num[i].lable1 >> num[i].lable2 >> num[i].lable3 >> num[i].lable4 >> num[i].lable5 >> num[i].lable6;
    }
    
    for (int i = 0; i < cnt - 1; i++)
    {
        for (int j = i + 1; j < cnt; j++)
        {
            if (true == judge(num[i], num[j]))
            {
                bFlag = true;
                break;
            }
        }
        
        if (true == bFlag)
        {
            break;
        }
    }
    
    if (true == bFlag)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3092
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n = ii()
    a = li()

    a = reversed(a)

    m = 100000000000
    for i in a:
        m = min(m,i)
        if i > m+1:
            print("No")
            exit()

    print("Yes")



    
main()


Measured memory_bytes: 14832
n,m,v[10000],w[2500],W[2500],o,x,y,r;F(a){for(r=a=m*m;r&&a--;)if(~w[a]&&v[x+a%m+n*(y+a/m)]-w[a])r=0;}main(d,t,f){for(;scanf("%d%d",&n,&m)*n;printf(f<n*n?"%d %d\n":"NA\n",1+f%n,1+f/n)){for(f=0;f<n*n;f++)scanf("%d",v+f);for(x=0;x<m*m;x++)scanf("%d",w+x);for(d=4;d--;){memcpy(W,w,4*m*m);for(x=m*m;x--;o=~w[x]?x:o)w[x]=W[m-1-x/m+x%m*m];for(y=0;y+m<=n;y++)for(x=0;x+m<=n;x++)if((t=x+o%m+(n+o/m)*y)<f?F(),r:0)f=t;}}}

Measured memory_bytes: 468
A,B,C = map(int,input().split())
ans = 0
while True:
    if any([x % 2 == 1 for x in [A,B,C]]):
        print(ans)
        exit(0)
    if A == B and B == C:
        print(-1)
        exit(0)
    a = (B+C)//2
    b = (A+C)//2
    c = (A+B)//2
    A = a
    B = b
    C = c
    ans += 1


Measured memory_bytes: 3060
n = int(input())
xs = [int(x) for x in input().split()]
xmap = {}
for x in xs:
    if x in xmap:
        xmap[x] += 1
    else:
        xmap[x] = 1
    if x+1 in xmap:
        xmap[x+1] += 1
    else:
        xmap[x+1] = 1
    if x-1 in xmap:
        xmap[x-1] += 1
    else:
        xmap[x-1] = 1
ret = 0
for x in xmap.keys():
    if xmap[x] > ret:
        ret = xmap[x]
print(ret)

Measured memory_bytes: 18788
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef long long int int64;
typedef unsigned long long int uint64;

int64 combination(int n,int k){
    int64 nck[n+1][n+1];
    REP(i,n+1){
        REP(j,n+1){
            nck[i][j]=0;
        }
    }
    REP(i,n+1){
        nck[i][0]=1;
        nck[i][i]=1;
    }
    FOR(i,2,n+1){
        FOR(j,1,i){
            if(nck[i][j]!=1){
                nck[i][j] = nck[i-1][j-1]+nck[i-1][j];
            }
        }
    }
    return nck[n][k];
}


int main(){
    int N,P;
    cin >> N >> P;
    int A[N];
    int cnt=0;
    REP(i,N){
        cin >> A[i];
        A[i] %= 2;
        if(A[i]==0){
            cnt++;
        }
    }
    int64 ans=0;
    REP(i,N-cnt+1){
        if(i%2==P){
            ans += combination(N-cnt,i);
        }
    }
    ans *= pow(2,cnt);
    cout << ans;
}

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

long long euclid (long long a, long long b){
  if (b == 0){
    return a;
  }
  return euclid(b, a%b);
}
long long lcm(long long a, long long b){
  return (a/euclid(a, b))*b;
}
int main(){
  int n;
  cin >> n;
  long long last = 1;
  for (int i=0; i<n; i++){
    long long current;
    cin >> current;
    last = lcm(current, last);
  }
  cout << last;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
    int c;
    while(b!=0) {
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}
int main () {
    ios_base::sync_with_stdio(false);
    int ans = 0;
    int N;
    cin>>N;
    for(int i=1;i<=N;i++) {
        for(int j=1;j<=N;j++) {
            int n = gcd(i,j);
            for(int k=1;k<=N;k++) {
                ans+=gcd(n,k);
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


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

int main(){
	char alpha[26]={false};

	string s;	cin>>s;
	for(int i=0;i<s.length();i++){
		alpha[s[i]-'a']=true;
	}

	int flag=false;
	for(int i=0;i<26;i++){
		if(alpha[i]==false){
			char x;
			x=i+'a';
			cout<<x<<endl;
			flag=true;
			break;
		}
	}
	if(flag==false)cout<<"None"<<endl;

	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll tri[101010];

int main(){

    tri[0] = 1;
    for(ll i = 1; i < 101000; i++){
        tri[i] = (tri[i - 1] * 3) % MOD;
    }

    string s;
    cin >> s;
    ll sz = s.size();

    ll ans = 0;
    ll tmp = 1;
    for(ll i = 0; i < sz; i++){
        if(s[i] == '0')continue;
        ans += (tmp * tri[sz - i - 1]) % MOD;
        tmp = (tmp + tmp) % MOD;
    }
    ans = (ans + tmp) % MOD;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1280
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string str;
int par[11];
int main(){
	int n;
	while(cin>>n,n){
		cin>>str;
		rep(i,11){
			par[i] = 0;
		}
		int turn = 0;
		int place = 0;
		for(int i = 0;i<str.size();i++){
			if(str[i]=='M'){
				par[turn]+=1;
			}else if(str[i]=='L'){
				par[turn]+=(place+1);
				place = 0;
			}else if(str[i]=='S'){
				place += (par[turn]+1);
				par[turn] = 0;
			}
			turn =(turn+1)%n;
		}
		sort(par,par+n);
		for(int i = 0;i < n;i++){
			cout <<par[i]<<" ";
		}
		cout<<place<<endl;
	}
	return 0;
}

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

using ll = long long;


int main(){
    ll H;
    cin >> H;
    ll cnt = 0ll;
    ll mn = 1;
    while(H > 0ll){
        H /= 2;
        cnt += mn;
        mn *= 2;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3548
// I 
// A M 
// T H E
// B E S T

// I 
// B E L I E V E 
// I N
// M Y S E L F
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin() , x.end()
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define F first
#define S second
#define left (node << 1)
#define right (node << 1) + 1
#define pii pair<int,int> 
#define mii map<int,int>
#define vi vector<int>
#define umii unordered_map<int,int>
// #define mod 998244353
#define mod 1000000007 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define FILL(name,val) memset(name , val , sizeof(name))
#define repo(i,o,e) for(int i = o ; i < e ; i++)
#define rep(n) for(int i = 0 ; i < n ; i++)
#define repa(i,sta,end,inc) for(int i = sta ; i <= end ; i += inc)
#define repb(i,sta,end,inc) for(int i = sta ; i >= end ; i -= inc)
const ll sz = 1e5+5;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
 
const ll inf = 1000000000LL * 1000000000LL;

/*
ll power(ll x , ll y){
    ll res = 1;
    x %= mod;
    while(y){
        if(y&1){
            res = res * x % mod;
        }
        x = x*x % mod;
        y /= 2;
    }
    return res%mod;
}
*/

void solve(){
    int a , b;
    cin >> a >> b;
    if(max(a,b) > 9){
        cout << -1 << endl;
    }
    else{
        cout << a*b << endl;
    }
    return;
}



int main(){
    FIO;
    int t = 1;
    // cin >> t;   
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
//べき乗を計算する関数
int myCalc(int b, int p)
{
  int i = b;
  int j;

  for(j=1; j<=p-1; j++){
    b=b*i;
  }
  return b;
}

int main(void)
{
  int x = 0;
  int i,j;
  int max = 1;

  scanf("%d", &x);

  for(i=2; myCalc(i, 2)<=x; i++){
    for(j=2; myCalc(i, j)<=x; j++){
      if(myCalc(i, j) >= max) max = myCalc(i, j);
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  long long x;
  cin >> n >> x;
  vector<long long> v;
  for(int i = 0; i < n; i++){
    long long a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for(int i = 0; i < n-1; i++){
    if(x >= v[i]){
      x -= v[i];
      ans++;
    }
    else break;
  }
  if(x == v[n-1]) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,x,y=map(int,input().split())
ans=[0]*(n-1)
for i in range(1,n):
    for j in range(i+1,n+1):
        ans[min(j-i,abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x))-1]+=1
for i in range(n-1):
    print(ans[i])

Measured memory_bytes: 3444
N = int(input())
A = list(map(int, input().split()))

stock = 0
money = 1000
for i in range(N-1):
    today = A[i]
    tomorrow = A[i+1]
    if today < tomorrow:
        # Buy
        n = money // today
        money -= n * today
        stock += n
    elif today > tomorrow:
        # Sell
        money += stock * today
        stock = 0
print(money + stock * A[-1])


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

int main(){
    int n;
    cin >> n;
    vector <long> x(n),y(n);
    rep(i,n){
        cin >> x[i];
        y[i]=x[i];
    } 

    vector <long> ans(n);

    sort(all(y));
    long smid=y[n/2-1];
    long bmid=y[n/2];

    if(smid==bmid){
        rep(i,n) cout << smid << endl;
        return 0;
    }

    for(int i=0; i<n; i++){
        if(x[i]<bmid){
            ans[i]=bmid;
        }
        else{
            ans[i]=smid;
        }
    }

    rep(i,n) cout << ans[i] << endl;
}


Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main() {

	uint N, W;
	cin >> N >> W;

	vector<pair<uint, uint>> vw(N);
	ull vmax = 0;
	ull wmax = 0;
	for(uint i=0; i<N; i++) {
		uint w, v;
		cin >> w >> v;
		vw[i] = make_pair(v, w);
		vmax += v;
		wmax += w;
	}

	sort(vw.begin(), vw.end());
	vector<vector<ull>> dp(vmax+1, vector<ull>(N+1, wmax));

	for(uint i=0; i<=N; i++) {
		dp[0][i] = 0;
	}

	ull ans = 0;

	for(uint j=vw[0].first; j<=vmax; j++) {
		for(uint i=1; i<=N; i++) {
			uint wi = vw[i-1].second;
			uint vi = vw[i-1].first;

			if(j >= vi) {
				dp[j][i] = min(dp[j-vi][i-1] + wi, dp[j][i-1]);
			} else {
				dp[j][i] = dp[j][i-1];
			}

			if(dp[j][i] <= W) {
				ans = j;
			}
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


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

    ll cnt1 = 0;
    for(int i = 1; i <= n; i++){
        if(i%k == 0){
            cnt1++;
        }
    }
    ll cnt2 = 0;
    if(k%2==0){
        for(int i = 1; i <= n; i++){
            if(i%k == k/2){
                cnt2++;
            }
        }
    }
    cout << cnt1*cnt1*cnt1+cnt2*cnt2*cnt2 << endl;
    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int N, K;
    scanf("%d %d", &N, &K);
    char str[N];
    scanf("%s", &str);
    for (int i = 0; i < N; i++) {
        if (i == K - 1) printf("%c", str[i] + 32);
        else printf("%c", str[i]);
    }
    return 0;
}

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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main() {

  int n;
  cin>> n;
  while(n--) {
    int l_hand, s_hand;
    double l_angle, s_angle;
    double angle;

    scanf("%d:%d",&l_hand, &s_hand);
    l_angle = (double)l_hand*30 + (double)s_hand*0.5;
    s_angle = (double)s_hand*6;
    angle = abs(l_angle-s_angle);
    angle = min(angle, 360-angle);

    if(angle>=90 && angle<=180) {
      cout<< "safe"<< endl;
    }
    else if(0<=angle && angle<30) {
      cout<< "alert"<< endl;
    }
    else {
      cout<< "warning"<< endl;
    }
  }
}

Measured memory_bytes: 1236
#input
N,M,C=input().split(" ")
B=input().split(" ")
N=int(N)
M=int(M)
C=int(C)
B=[int(b) for b in B]
A=[]
for i in range(N):
	l=input().split(" ")
	A.append([int(a) for a in l])

import numpy as np

c=0
for a in A:
	if(np.dot(a,B)+C>0):
		c+=1
print(c)
	







Measured memory_bytes: 20928
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,r,c,p;
    vector<int> s,s2;
    while(1){
        cin >> n >> r;
        if(n==0&&r==0)  break;
        for(int i=1;i<=n;i++){
            s.push_back(i);
        }
        while(r--){
            cin >> p >> c;
            for(int i=0;i<n-c-p+1;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-p+1;i<n;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-c-p+1;i<n-p+1;i++){
                s2.push_back(s[i]);
            }
            s.clear();
            for(int i=0;i<n;i++){
                s.push_back(s2[i]);
            }
            s2.clear();
        }
        cout << s[n-1] << "\n";
        s.clear();
    }
}

Measured memory_bytes: 3088
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    s = S()
    return eval(s)

print(main())


Measured memory_bytes: 5648
#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
#include<unordered_map>
#include<map>
#include<vector>
#define P pair<int,int>
using namespace std;

int main()
{
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		if (b)cout << endl;
		bool k[9][9]{};
		int c[9][9];
		for (int d = 0; d < 9; d++) {
			for (int e = 0; e < 9; e++) {
				cin >> c[d][e];
			}
		}
		for (int f = 0; f < 9; f++) {
			vector<P>h[10];
			for (int g = 0; g < 9; g++) {
				h[c[f][g]].push_back(P(f, g));
			}
			for (auto i : h) {
				if (i.size() > 1) {
					for (P j : i) {
						k[j.first][j.second] = true;
					}
				}
			}
		}
		for (int f = 0; f < 9; f++) {
			vector<P>h[10];
			for (int g = 0; g < 9; g++) {
				h[c[g][f]].push_back(P(g, f));
			}
			for (auto i : h) {
				if (i.size() > 1) {
					for (P j : i) {
						k[j.first][j.second] = true;
					}
				}
			}
		}
		for (int f = 0; f < 3; f++) {
			for (int g = 0; g < 3; g++) {
				vector<P>h[10];
				for (int k = 0; k < 3; k++) {
					for (int l = 0; l < 3; l++) {
						h[c[f * 3 + k][g * 3 + l]].push_back(P(f*3+k,g*3+l));
					}
				}
				for (auto i : h) {
					if (i.size() > 1) {
						for (P j : i) {
							k[j.first][j.second] = true;
						}
					}
				}
			}
		}
		for (int x = 0; x < 9; x++) {
			for (int y = 0; y < 9; y++) {
				if (k[x][y])cout << '*';
				else cout << ' ';
				cout << c[x][y];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
int Max(int &a,int b){return a=max(a,b);}
int Min(int &a,int b){return a=min(a,b);}

/*?????¬??????TOP?????????????????¢?????????*/
/*TOP??¨BOTTOM???FRONT?????????????????¢?????????*/
/************/
/*  0       */
/*  1 3 4 2 */
/*  5       */
/************/
class Cube{
public:
  struct cdat{char num[3][3];};
  const int TOP = 0, FRONT = 1, LEFT = 2;
  const int RIGHT = 3, BACK = 4, BOTTOM = 5;
  cdat cube[6];

  void rot(string cmd){
    if(cmd == "N") rotN();
    else if(cmd == "E") rotE();
    else if(cmd == "S") rotS();
    else if(cmd == "W") rotW();
    else if(cmd == "CW") rotCW();
    else if(cmd == "CCW") rotCCW();
    else exit(1);
  }

  void pr(){
    map<int,string> M;
    M[0] = "TOP",M[1] = "FRONT",M[2] = "LEFT";
    M[3] = "RIGHT", M[4] = "BACK", M[5] = "BOTTOM";
    for(int i=0;i<6;i++){
      cout<<M[i]<<endl;
      for(int j=0;j<3;j++){
        for(int k=0;k<3;k++)cout<<cube[i].num[j][k];
        cout<<endl;
      }
    }
  }

  void rot90(cdat &a){
    cdat b = a;
    for(int i=0;i<3;i++)
      for(int j=0;j<3;j++) a.num[i][j] = b.num[2-j][i];
  }
  void reverseX(cdat &a){for(int i=0;i<3;i++) reverse(a.num[i],a.num[i]+3);}
  void reverseY(cdat &a){rot90(a),reverseX(a),rot90(a),rot90(a),rot90(a);}
  

  void rotN(){  //?\\?????¢??????
    swap(cube[TOP],cube[FRONT]);
    swap(cube[FRONT],cube[BOTTOM]);
    swap(cube[BOTTOM],cube[BACK]);
    rot90(cube[TOP]),rot90(cube[TOP]);
    rot90(cube[BOTTOM]),rot90(cube[BOTTOM]);
    rot90(cube[LEFT]),rot90(cube[LEFT]),rot90(cube[LEFT]);
    rot90(cube[RIGHT]);
  }


  void rotCCW(){  //??????????????????????¨???????????????????
    swap(cube[FRONT],cube[LEFT]);
    swap(cube[LEFT],cube[BACK]);
    swap(cube[BACK],cube[RIGHT]);
    rot90(cube[TOP]),rot90(cube[TOP]),rot90(cube[TOP]);
    rot90(cube[BOTTOM]);
  }
  
  void rotE(){rotCCW();rotN();rotCW();}//????????¢??????
  void rotS(){rotN(),rotN(),rotN();}//???????????¢??????
  void rotW(){rotE(),rotE(),rotE();}//????????¢??????
  void rotCW(){rotCCW(),rotCCW(),rotCCW();}//???????????????????¨????????????????
};

Cube C;
const int TOP = 0, FRONT = 1, LEFT = 2;
const int RIGHT = 3, BACK = 4, BOTTOM = 5;


bool check(const Cube &c){
  bool front=0,back=0;
  for(int i=0;i<3;i++) front |= c.cube[FRONT].num[2][i] == '*';
  for(int i=0;i<3;i++) back |= c.cube[BACK].num[2][i] == '*';
  return front && back;
}

string dir[] = {"N","E","S","W"};
int ans;
void dfs(int dep){
  if(check(C)) ans = dep;
  if(ans <= dep) return;
  for(int i=0;i<4;i++){
    C.rot(dir[i]);
    dfs(dep+1);
    C.rot(dir[(i+2)%4]);
  }
}

signed main(){
  while(1){
    int ord[]={FRONT,RIGHT,BACK,LEFT,TOP,BOTTOM};
    for(int i=0;i<6;i++)
      for(int j=0;j<3;j++)
        for(int k=0;k<3;k++){
          char ch;
          cin>>ch;
          if(ch == '#') return 0;
          C.cube[ord[i]].num[j][k] = ch;
        }

    
    C.rot90(C.cube[TOP]);
    C.rot90(C.cube[TOP]);

    ans = 10;
    dfs(0);
    cout<<ans<<endl;
  }
  return 0;
}

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

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

    double x[n];
    string u[n];
    double total=0;

    for(int i=0; i<n; i++){
        cin >> x[i] >> u[i];
        if(u[i]=="JPY"){
            total+=x[i];
        }
        else{
            total+=x[i]*380000.0;
        }
    }

    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
import math

while True:
    n = int(input())
    if n == 0:
        break
    else:
        s = list(map(int,input().split()))
        m = sum(s)/n
        a = 0
        for i in s:
            a += (i - m)**2
            ans = math.sqrt(a/n)
        print(ans)
    


Measured memory_bytes: 5700
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N;cin>>N;
  cout<<(1999-N)/200+1<<endl;
  return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

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

	int x, sum;
	x = sum = 0;
	long long ret = 0;
	for(int l=0, r=0; l<N; l++){
		while(r<N && (sum+A[r] == (x^A[r]))){
			sum += A[r];
			x ^= A[r];
			r++;
		}
		//cout << l << " : " << r << " " << sum << " " << xor << endl;

		ret += r - l;
		sum -= A[l];
		x ^= A[l];
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n;
    cin >> n;
    vll a(n),tmp(n);
    rep(i,n){
        cin >> a[i];
        tmp[i]=a[i];
    }
    sort(rall(tmp));
    ll max1=tmp[0];
    ll max2=tmp[1];
    rep(i,n){
        cout << (a[i]==max1?max2:max1) << endl;
    }
    return 0;
}

Measured memory_bytes: 4736
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let n = scan "%d" id
let ls = scan_lines n "%d %d" Tuple2.make

let rec gcd a b =
  if b = 0 then a
  else gcd b (a mod b)

let () =
  let open ModOp in
  let (ks, ms) = ListL.partition ls ~f:(fun (a,b) -> a = 0 && b = 0) in
  let ms = ListL.map ms ~f:(fun (a, b) ->
      if a = 0 then (0,1)
      else
        let m = gcd (abs a) (abs b) in
        if a < 0 then (-a/m, -b/m)
        else (a/m, b/m)) in
  let h0 = Hashtbl.create n in
  let h1 = Hashtbl.create n in
  ListL.iter ms ~f:(fun (a,b) ->
      if b <= 0 then Hashtbl.modify_def 0 (a,b) succ h0
      else (Hashtbl.modify_def 0 (b,-a) succ h1;
            Hashtbl.modify_def 0 (b,-a) id h0));
  Hashtbl.map (fun v n ->
      let x = Hashtbl.find_default h1 v 0 in
      pow 2 n + pow 2 x - 1) h0
  |> Hashtbl.to_list |> List.map Tuple2.second
  |> ListL.fold_left ~init:1 ~f:( * )
  |> ((+) (List.length ks - 1))
  |> Printf.printf "%d\n"


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

int main(){
  string S;
  cin >> S;
  
  string ans = "yes";
  
  for(int i=0; i<S.size(); i++){
    int j=0;
    while(j<S.size()){
     if(S.at(i) == S.at(j) && i != j){
       ans = "no";
       break;
     }
     j++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, m, c;
  cin >> n >> m >> c;
  int b[m];
  for(int i = 0; i < m; i++){
    cin >> b[i];
  }
  int a[n][m];
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }

  int count = 0;
  for(int i = 0; i < n; i++){
    int sum = 0;
    for(int j = 0; j < m; j++){
      sum += a[i][j] * b[j];
    }
    if(sum + c > 0) ++count;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
// ハッシュ
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch)
{
    if( ch == 'A' ) return 1;
    else if( ch == 'C' ) return 2;
    else if( ch == 'G' ) return 3;
    else if( ch == 'T' ) return 4;
    else return 0;
}

// 文字列から数値へ変換して　key を生成する
long long getKey(char str[])
{
    long long sum = 0, p = 1, i;

    for( i = 0; i < strlen(str); i++ )
    {
        // 文字列の並び順を考慮した処理
        sum += p * ( getChar(str[i]) );
        p *= 5;
    }

    return sum;
}

// ハッシュ関数 1
int h1(int key)
{
    // keyの値は, 0 〜 M - 1
    return key % M;
}

// ハッシュ関数 2
int h2(int key)
{
    // keyの値は, 0 〜 M - 1
    return 1 + ( key % ( M - 1 ) );
}

// 文字列の検索関数
int find(char str[])
{
    long long key, i, h;

    // 文字列を数値に変換
    key = getKey(str);

    for( i = 0; ; i++ )
    {
        // ハッシュ値を生成
        h = ( h1(key) + i * h2(key) ) % M;

        if( strcmp(H[h], str) == 0 )
        {
            // 検索文字列が見つかった
            return 1;
        }
        else if( strlen(H[h]) == 0 )
        {
            // 検索文字列が見つからなかった
            return 0;
        }
    }

    return 0;
}

// 文字列の挿入関数
int insert(char str[])
{
    long long key, i, h;

    // 文字列を数値に変換
    key = getKey(str);

    for( i = 0; ; i++ )
    {
        // ハッシュ値を生成
        h = ( h1(key) + i * h2(key) ) % M;

        if( strcmp(H[h], str) == 0 )
        {
            // 文字列は既に登録済み
            return 1;
        }
        else if( strlen(H[h]) == 0 )
        {
            // 文字列を入れる所が見つかった
            strcpy(H[h], str);
            return 0;
        }
    }

    return 0;
}

int main(void)
{
    int i, n, h;
    char str[L], com[9];

    for( i = 0; i < M; i++ )
    {
        // 配列の初期化
        H[i][0] = '\0';
    }

    scanf("%d", &n);

    for( i = 0; i < n; i++ )
    {
        scanf("%s %s", com, str);

        if( com[0] == 'i' )
        {
            insert(str);
        }
        else
        {
            if( find(str) )
            {
                printf("yes\n");
            }
            else
            {
                printf("no\n");
            }
        }
    }

    return 0;
}



Measured memory_bytes: 17056
#include <set>
#include <cstdio>
int i,n,v[9999];
main(){for(;scanf("%d",&n),n;){
	std::set<int>t;
	for(i=1;i<n;i++)v[i]=0,t.insert(i*i%n);
	std::set<int>::iterator s,S;
	for(s=t.begin();s!=t.end();s++)for(S=s;++S!=t.end();v[i>n/2?n-i:i]+=2)i=*S-*s;
	for(i=1;i<=n/2;i++)printf("%d\n",v[i]);
}}

Measured memory_bytes: 1296
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		int ansA = 0;
		int ansB = 0;
		for(int a = 0; a < S.length(); a++){
			if(S.charAt(a) == 'A'){
				ansA++;
			}
			else{
				ansB++;
			}
		}
		if(ansA == 3){
			System.out.println("No");
		}
		else if(ansB == 3){
			System.out.println("No");
		}
		else{
			System.out.println("Yes");
		}
		stdIn.close();
	}
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

bool ck(vector<int> v, int x)
{
    rep(i, v.size())
    {
        if (v[i] < x)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i, n)
    {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }

    int ans = 1001001001;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        vector<int> getit(m, 0);
        int res = 0;
        rep(i, n)
        {
            if (bit & (1 << i))
            {
                res += c[i];
                rep(j, m)
                {
                    getit[j] += a[i][j];
                }
            }
        }
        if (ck(getit, x))
        {
            ans = min(ans, res);
        }
    }

    cout << ((ans == 1001001001) ? -1 : ans) << '\n';
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  ll h,a;
  cin>>h>>a;
  cout<<(h-1)/a+1<<endl;

}

Measured memory_bytes: 256
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

bool s[1005][1005];
ll road[1005][1005];
void dfs(int i, int j, int h, int w, int c) {
    if (i < 0 || i >= h || j < 0 || j >= w) return;
    if (!s[i][j] || road[i][j] != 0) return;
    road[i][j] = c;
    dfs(i+1, j, h, w, c);
    dfs(i-1, j, h, w, c);
    dfs(i, j+1, h, w, c);
    dfs(i, j-1, h, w, c);
}

void solve()
{
    IN(h, w);
    IN(ch, cw);
    IN(dh, dw);
    --ch, --dh;
    --cw, --dw;
    rep(i, h) {
        TIN(string, l);
        rep(j, w) {
            s[i][j] = l[j] == '.';
        }
    }
    ll c = 1;
    rep(i, h) {
        rep(j, w) {
            if (!s[i][j] || road[i][j] != 0) continue;
            dfs(i, j, h, w, c);
            ++c;
        }
    }
    vector<set<ll>> g(c);
    rep(i, h) {
        rep(j, w) {
            if (!s[i][j]) continue;
            reps(x, -2, 3) {
                reps(y, -2, 3) {
                    if (x == 0 && y == 0) continue;
                    if (i+x < 0 || i+x >= h || j+y < 0 || j+y >= w) continue;
                     if (!s[i+x][j+y]) continue;
                    g[road[i][j]].emplace(road[i+x][j+y]);
                }
            }
        }
    }
    vector<ll> dist(c, -1);
    dist[road[ch][cw]] = 0;
    queue<ll> q;
    q.push(road[ch][cw]);
    while (!q.empty()) {
        ll v = q.front();
        q.pop();
        for (auto nv : g[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            q.push(nv);
        }
    }
    cout << dist[road[dh][dw]] << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 39168
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>

#define MOD 1000000007
#define ll long long
#define ld long double

using namespace std;


ll N;
string s1,s2;

int main(){
  ll result=0;
  ll before; // before case : 1 1      or 2
             //                           2
  ll i=0;
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  cin >> s1;
  cin >> s2;

  if(s1[i]==s2[i]){
    result = 3;
    before = 1;
  }
  else {
    result = 6;
    before = 2;
    i+=1;
  }
  for(i+=1;i<s1.size();i++){
    //case 1
    if(s1[i]==s2[i]){
      if(before == 1) result *= 2;//1->1     
      else  result *= 1;//2->1
      
      //renew
      before = 1;
    }
    //case 2
    else{
      if(before == 1) result*=2;// 1->2
      else result*=3;// 2-> 2

      //renew
      before = 2;
      i+=1;
    }
    result %= MOD;
  }


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


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

namespace ABC128B
{
    class Rating
    {
        public int No { get; }
        public string City { get; }
        public int Score { get; }

        public Rating(int no, string city, int score)
        {
            this.No = no;
            this.City = city;
            this.Score = score;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine().Trim());

            var ratingList = new List<Rating>();
            for (var i = 0; i < N; i++)
            {
                var input = Console.ReadLine().Trim().Split();
                var S = input[0];
                var P = int.Parse(input[1]);
                ratingList.Add(new Rating(i + 1, S, P));
            }

            foreach (var rating in ratingList.OrderBy(x => x.City).ThenByDescending(x => x.Score))
            {
                Console.WriteLine(rating.No);
            }

            Console.Read();
        }
    }
}

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

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


from itertools import accumulate
acc = [0] + a
acc = list(accumulate(acc))

import collections

c = collections.Counter(acc)

ans = 0
for key,val in c.items():
    if val>1:
        ans +=val*(val-1)//2

print(ans)


Measured memory_bytes: 42088
import java.util.Scanner;

public class Main {
	static Scanner scn=new Scanner(System.in);
	public static void main(String[] args) {
		
		int A =Integer.parseInt(scn.next());
		int B =Integer.parseInt(scn.next());
		int X =0;
		for(int i =1;i<=3;i++){
			X=A*B*i;
			if(X%2==1)break;
		}
		if(X%2==1){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 25300
x, y = map(str, input().split())
d = {"A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15}

if d[x] < d[y]:
  print("<")
elif d[x] > d[y]:
  print(">")
else:
  print("=")

Measured memory_bytes: 3060
"""
@auther: SPD_9X2
https://atcoder.jp/contests/abc086/tasks/arc089_b

考察：

まず、x,y座標を2Kで割っておいてよい。

黒白
白黒　で考え、左下(0,0)で開始。

縦軸を固定し、左に動かしていくことを考える。
すると、現在　x%K == 0　となる部分にいる希望のみ、達成・非達成が反転する

初期の達成数を記録しておき、各列で達成・非達成がいくつあるのかをリストに記録
ずらすと、現在の達成数 += 新たに達成する要求 - 非達成になる要求
となる。2*K回操作して元に戻す

縦軸の移動は各行について、どの列に要求があるのかをおいておき、その部分の達成・非達成数を反転する
各要求で高々2回しかチェックしないため、O(N + K^2)で処理できる
"""




N,K = map(int,input().split())

cansub = [ [] for i in range(2*K) ]
notsub = [ [] for i in range(2*K) ]

notlis = [0] * (2*K)
canlis = [0] * (2*K)

for i in range(N):

    x,y,c = input().split()
    x = int(x)
    y = int(y)
    x %= (2*K)
    y %= (2*K)

    if (x >= K and y >= K) or (x < K and y < K):
        nc = "W"
    else:
        nc = "B"

    if nc == c:
        cansub[x].append(y)
        canlis[y] += 1
    else:
        notsub[x].append(y)
        notlis[y] += 1



ans = 0

for i in range(2*K):

    ncan = sum(canlis)

    for j in range(2*K):

        j %= (2*K)

        ans = max(ans,ncan)
        ncan += notlis[j]
        ncan -= canlis[j]

        t = notlis[j]
        notlis[j] = canlis[j]
        canlis[j] = t

        j += K
        j %= (2*K)

        ncan += notlis[j]
        ncan -= canlis[j]

        t = notlis[j]
        notlis[j] = canlis[j]
        canlis[j] = t


    for k in cansub[i]:
        notlis[k] += 1
        canlis[k] -= 1
    for k in notsub[i]:
        notlis[k] -= 1
        canlis[k] += 1

    t = cansub[i]
    cansub[i] = notsub[i]
    notsub[i] = t

    i += K
    i %= (2*K)

    for k in cansub[i]:
        notlis[k] += 1
        canlis[k] -= 1
    for k in notsub[i]:
        notlis[k] -= 1
        canlis[k] += 1

    t = cansub[i]
    cansub[i] = notsub[i]
    notsub[i] = t

print (ans)

Measured memory_bytes: 60376
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const ll inf = 1e8;
const ll co = 1000005;

ll dp[2][1000005];

int main() {
    rep(i,2)rep(j,co) dp[i][j] = inf;
    dp[0][0] = dp[1][0] = 0;
    for (int i = 1; i*(i+1)*(i+2)/6 < co; i++) {
        int l = i*(i+1)*(i+2)/6;
        for (int j = 1; j <= co; j++) {
            if (j >= l) dp[0][j] = min(dp[0][j],dp[0][j-l]+1);
        }
        if (l&1) {
            for (int j = 1; j <= co; j++) {
                if (j >= l) dp[1][j] = min(dp[1][j],dp[1][j-l]+1);
            }
        }
    }

    while (true) {
        int x;
        cin >> x;
        if (x == 0) break;
        cout << dp[0][x] << " " << dp[1][x] << endl;
    }
}


Measured memory_bytes: 18724
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <sstream>
#include <numeric>
using namespace std;

int main(){
    int a,b,k ;
    cin >> a >> b >> k ;
    bool nowa = true ;
    for (size_t i = 0; i < k; i++)
    {
        if (nowa == 1)
        {
            b += a/2 ;
            a = a/2 ;
            nowa = 0 ;
        }else
        {
            a += b/2 ;
            b = b/2 ;
            nowa = 1 ;
        }
        
        
    }
    cout << a << " " << b << endl ;
}

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



int main()
{
    int N;
    double x[11];
    vector<string> u(11);

    cin >> N;
    for( int i = 0; i < N; ++i ) cin >> x[i] >> u[i];

    double ans = 0;
    for( int i = 0; i < N; ++i ){
        if( u[i] == "JPY" )  ans += x[i];
        else ans += x[i] * 380000.;
    }

    cout << ans << endl;

    return 0;
}

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

int board[150];

int main()
{
	char ch[30];
	scanf("%s",ch);
	for(int i=0 ; i<strlen(ch) ; i++)
	{
		board[ch[i]-'a']++;
	}
	for(int i=0 ; i<100 ; i++)
	{
		if(board[i]>1)
		{
			printf("no");
			return 0;
		}
	}
	printf("yes");
	return 0;
}

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

int f(int h) {
    if(h == 0)
        return 0;
    int half = (h >> 1);
    return (f(half) << 1) + 1;
}

int32_t main() {
    cin >> h;
    cout << f(h) << '\n';
}


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

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i=0;i<n;++i) {
    cin >> a[i];
    b[i]=a[i];
  }
  sort(b.begin(), b.end());
  reverse(b.begin(),b.end());
  for (int i=0;i<n;++i) {
    if (b[0]!=a[i]) {
      cout<<b[0]<<endl;
    } else {
      cout<<b[1]<<endl;
    }
  }
}

Measured memory_bytes: 3200