akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail]=x;
  if(tail+1==LEN)tail=0;
  else tail=tail+1; 
}

P dequeue(void){
  P x;
  x=Q[head];
  if(head+1==LEN)head=0;
  else head=head+1;
  return x;
}

int main(){
  int time=0, c;
  int i, j;
  P p;
  scanf("%d %d",&n,&j);

  for(i=1;i<=n;i++){
    scanf("%s %d",Q[i].name, &Q[i].t);
  }
  head = 1;
  tail =n+1;

  while(head != tail){
    p = dequeue();
    if(j<p.t)c=j;
    else c=p.t;
    p.t=p.t-c;
    time=time+c;
    if(p.t>0)enqueue(p);
    else{
      printf("%s %d\n",p.name,time);
    }
  }

  return 0;
}

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

int main(void) {
  int x, y;
  scanf("%d %d", &x, &y);
  if ((4 * x - y) % 2) printf("No\n");
  else if ((4 * x - y) / 2 <= x && (4 * x - y) / 2 >= 0) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 1644
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,k;
	int arr[1000];
	
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	
	sort(arr,arr+n);
	
	int temp=0;
	for(int i=0;i<k;i++){
		temp+=arr[i];
	}
	cout<<temp;
}

Measured memory_bytes: 3572
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> p;
	for (int i = 0;i < n;i++)
	{
		int num;
		cin >> num;
		p.push_back(num);
	}
	
	int oper;
	cin >> oper;
	while (oper--)
	{
		int finda;
		cin >> finda;
		vector<int>::iterator pp = lower_bound(p.begin(), p.end(), finda);
			cout << pp - p.begin() << endl;
	}
}


Measured memory_bytes: 3524
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cstring>
using namespace std;

typedef long long ll;

struct Event {
  ll kind, depth, x1, x2, y1, y2;
};
bool operator<(const Event &e, const Event &f) {
  if (e.depth != f.depth) return e.depth < f.depth;
  if (e.kind != f.kind) return e.kind < f.kind;
  return e.x1 < f.x1;
}

int cnt[101][101];

int main() {
  int N,K;
  cin>>N>>K;
  set<ll> x,y;
  int x1,x2,y1,y2,d1,d2;
  vector<Event> evs;
  for (int i=0; i<N; ++i) {
    cin>>x1>>y1>>d1>>x2>>y2>>d2;
    x.insert(x1); x.insert(x2);
    y.insert(y1); y.insert(y2);
    evs.push_back((Event){0,d1,x1,x2,y1,y2});
    evs.push_back((Event){1,d2,x1,x2,y1,y2});
  }

  map<ll,ll> ix, iy, rx, ry;
  for (set<ll>::iterator it = x.begin(); it != x.end(); ++it) {
    if (ix.find(*it) == ix.end()) {
      ll p = ix.size(); ix[*it] = p;
      rx[p] = *it;
    }
  }
  for (set<ll>::iterator it = y.begin(); it != y.end(); ++it) {
    if (iy.find(*it) == iy.end()) {
      ll p = iy.size(); iy[*it] = p;
      ry[p] = *it;
    }
  }

  for (int i=0; i<evs.size(); ++i) {
    evs[i].x1 = ix[evs[i].x1];
    evs[i].x2 = ix[evs[i].x2];
    evs[i].y1 = iy[evs[i].y1];
    evs[i].y2 = iy[evs[i].y2];
  }

  sort(evs.begin(), evs.end());
  memset(cnt, 0, sizeof(cnt));

  ll idx = 0, pd = 0;
  ll ca = 0, ans = 0;
  while(idx < evs.size()) {
    ll cd = evs[idx].depth;
    if (ca > 0) {
      ans += ca*(cd-pd);
      ca = 0;
    }
    pd = cd;
    while(idx < evs.size()) {
      if (evs[idx].depth != cd) break;
      if (evs[idx].kind == 0) {
        for (int i=evs[idx].x1; i<evs[idx].x2; ++i) {
          for (int j=evs[idx].y1; j<evs[idx].y2; ++j)
            cnt[j][i]++;
        }
      } else {
        for (int i=evs[idx].x1; i<evs[idx].x2; ++i) {
          for (int j=evs[idx].y1; j<evs[idx].y2; ++j)
            cnt[j][i]--;
        }
      }
      idx++;
    }

    // calc
    //cout<<idx<<endl;
    for (int i=0; i<101; ++i) {
      for (int j=0; j<101; ++j) {
        //cout<<cnt[i][j]<<" ";
        if (cnt[i][j] >= K) {
          ca += (ll)(rx[j+1]-rx[j])*(ry[i+1]-ry[i]);
        }
      }
      //cout<<endl;
    }

  }

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

Measured memory_bytes: 1296
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	if(n<105){
		cout<<0;
		return 0;
	}
	int ans=0;
	rep(i,105,n+1){
		if(i%2==0)continue;
		int k=i;
		int cnt=1;
		for(int j=2;j*j<=i;j++){
			if(k%j==0){
				int a=0;
				while(k%j==0){
					a++;
					k/=j;
				}
				cnt*=(a+1);
			}
		}
		if(cnt==8)ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3528
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int x, a, b;
  cin >> x >> a >> b;

  if (b <= a) {
    cout << "delicious" << endl;
  }
  else if (b <= a + x) {
    cout << "safe" << endl;
  }
  else {
    cout << "dangerous" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
int  D,N;
cin >> D >> N ;
long long ans = 0;
if(D == 0){
  if(N == 100) ans = 101;
   else ans = N;
 }
else if(D == 1){
  if(N == 100)ans = 10100;
  else ans = 100 * N;
}
else {
  if(N == 100 ) ans = 1010000;
  else ans = 100* 100 *  N;
}
cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char a,b;
    cin>>a>>b;
    if (a<b)
    {
        cout<<"<"<<endl;
    }
    else if (a==b)
    {
        cout<<"="<<endl;
    }
    else
    {
        cout<<">"<<endl;
    }
    return 0;
}


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

int main()
{
    string c;
    cin >> c;
    if (c == "a" || c == "i" || c == "u" || c == "e" || c == "o") cout << "vowel" << endl;
    else cout << "consonant" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,c,d,e=0;
	scanf("%d %d %d",&a,&b,&c);
	for(d=a;d<=b;d++){
		if(c%d==0){
			e++;
		}
	}
	printf("%d\n",e);
		
    
return 0;	
}

Measured memory_bytes: 2756
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: Chars,
    }

    let mut ans = 0;
    let mut now = 'o';
    for c in s {
        if now != c {
            ans += 1;
            now = c;
        }
    }

    println!("{}", ans - 1);
}


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

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

using ll = long long;
ll INF = LLONG_MAX;
 
using vc = vector<char>;
using vi = vector<int>;
using segment = pair<int, pair<int, int>>;

int N, Q;
vi startTimes;
vi queryPerm;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N >> Q;
    vector<pair<pair<int, int>, int>> segments (N);
    F0R(i, N) {
        int S, T, X;
        cin >> S >> T >> X;
        segments[i] = {{S-X, T-X-1}, X};
    }
    
    sort(segments.begin(), segments.end());

    startTimes.resize(Q);
    F0R(i, Q) {
        cin >> startTimes[i];
    }

    int curSegment = 0;
    priority_queue<segment, vector<segment>, greater<segment>> q;
    
    F0R(i, Q) {
        while (curSegment < N && segments[curSegment].first.first <= startTimes[i]) {
            q.push({segments[curSegment].second, segments[curSegment].first});
            curSegment++;
        }

        while (!q.empty() && q.top().second.second < startTimes[i]) {
            q.pop();
        }

        cout << ((q.empty()) ? -1 : q.top().first) << endl;
    }
}

Measured memory_bytes: 7796
n, k = map(int, input().split())
lst = []
for i in range(n):
  lst.append(int(input()))
lst.sort()
res = 10 ** 9
for i in range(n - k + 1):
  temp = lst[i + k - 1] - lst[i]
  if temp < res:
    res = temp
print(res)

Measured memory_bytes: 13340
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    REP(i, S.size()) {
        if (S[i] != T[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define forn(i,n) forr(i,0,n)

int main() {
    string s;
	cin >> s;
	long long count = 0;
	long long count2 = 0;
	forn(i,(int)s.length()){
		if(s[i]=='B'){
			count++;
		}else{
			count2+=count;
		}
	}
	cout << count2 << endl;
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b;
    if(b%a==0)Cout(a+b);
    else Cout(b-a);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[2][9] = {{0, 1, -1, 2, -2, 0, 1, -1, 0}, {0, 1, -1, 2, -2, 0, 1, -1, 0}};
const int dx[2][9] = {{1, 1, 1, 1, 1, 2, 2, 2, 3}, {-1, -1, -1, -1, -1, -2, -2, -2, -3}};
const int MAX_N = 70;
char field[MAX_N][MAX_N];
int dist[MAX_N][MAX_N][2];
int h, w;
struct edge 
{
    int cost;
    int y, x;
    bool flag;
    bool operator > (const edge &d) const
    {
        return d.cost < cost;
    }
};
int dijkstra(int y, int x, bool foot)
{
    priority_queue<edge, vector<edge>, greater<edge>> que;
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) for(int k = 0; k < 2; k++) dist[i][j][k] = INF;
    dist[y][x][foot] = 0;
    edge v = {0, y, x, foot};
    que.push(v);
    while(!que.empty())
    {
        edge p = que.top();
        que.pop();
        int ty = p.y;
        int tx = p.x;
        bool flag = (p.flag ? false : true);
        if(dist[ty][tx][p.flag] < p.cost) continue;
        for(int i = 0; i < 9; i++)
        {
            int ny = ty + dy[flag][i];
            int nx = tx + dx[flag][i];
            if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
            if(field[ny][nx] == 'X' || field[ny][nx] == 'S') continue; 
            int cost = 0;
            if(field[ny][nx] != 'T') cost = field[ny][nx] - '0';
            if(dist[ny][nx][flag] > dist[ty][tx][p.flag] + cost)
            {
                dist[ny][nx][flag] = dist[ty][tx][p.flag] + cost;
                edge tmp = {cost, ny, nx, flag};
                que.push(tmp);
            }
        }
    }
    int ret = INF;
    for(int j = 0; j < w; j++)
    {
        if(field[0][j] != 'T') continue;
        for(int k = 0; k < 2; k++) ret = min(dist[0][j][k], ret);
    }
    return ret;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> w >> h, w | h)
    {
        int ans = INF;
        vector<P> start;
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                char ch;
                cin >> ch;
                if(ch == 'S') start.push_back(P(i, j));
                field[i][j] = ch;
            }
        }
        for(int i = 0; i < start.size(); i++)
        {
            for(int j = 0; j < 2; j++)
            {
                ans = min(dijkstra(start[i].first, start[i].second, j), ans);
            }
        }
        cout << (ans == INF ? -1 : ans) << endl;
    }
    return 0;
}


Measured memory_bytes: 3920
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int N;
int a[200010];
int b[200010];

signed main()
{
	cin >> N;

	rep1(i, N) cin >> a[i];

	for (int i = N; i >= 1; --i) {
		int counter = 0;

		for (int j = i; j <= N; j += i) {
			counter += b[j];
		}

		if (a[i] == 1 and counter % 2 == 0) {
			b[i]++;
		} else if (a[i] == 0 and counter % 2 == 1) {
			b[i]++;
		}
	}

	vector<int> ans;

	for (int i = 1; i <= N; ++i) if (b[i]) ans.PB(i);

	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); ++i) printf("%lld%c", ans[i], i==ans.size()-1?'\n':' ');
}




Measured memory_bytes: 4852
import java.util.*;
import java.io.*;

class Main {
  public static void main(String argv[]) {
    int n;
    
    Scanner sc = new Scanner(System.in);
    n = Integer.parseInt(sc.next());
    
    int a[] = new int[n];
    int b[] = new int[n];
    
    for (int i = 0;i < n;i++) {
      a[i] = Integer.parseInt(sc.next());
    }
    for (int i = 0;i < n;i++) {
      b[a[i] - 1] = i + 1;
    }
    PrintWriter out = new PrintWriter(System.out);
    for (int i = 0;i < n;i++) {
      out.print(b[i] + " ");
    }
    out.println();
    out.flush();
  }
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int n, k, m;

int solve(int n)
{
  return n == 0 ? 0 : (solve(n - 1) + k) % n;
}

int main()
{
  while(cin >> n >> k >> m, n){
    cout << (solve(n - 1) + m) % n + 1 << endl;
  }

  return 0;
}

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

int n;
int a[20];
int y[20][20];
int x[20][20];

int countbit(bitset<15> bit) {
    int numbit = 0;
    bitset<15> b(0);
    while (bit != b){
        if (bit[0] == 1){ numbit++; }
        bit = bit >> 1;
    }
    return numbit;
}

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int maxHonest() {
    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++){
        bool ok = true;
        for (int i = 0; i < n; i++) {
            if (!ok) { break; }
            for (int j = 0; j < a[i]; j++){
                // if (i == j) { continue; }
                if(!(bit & (1 << i))) continue;
                if (((bit >> (x[i][j]-1)) & 1) ^ y[i][j]) { ok = false; break; }
            }
        }
        if (ok) ans = max(ans, counter(bit));
        if (!ok) { ok = true; }
    }
    return ans;
}

int main() {
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        for (int j=0; j<a[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    cout << maxHonest() << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9 ; j++) {
			if (i * j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
  	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;

vector<int> graf[N];
vector<int> h[2];
void dfs(int x, int y = 0, int d = 0)
{
    h[d].push_back(x);
    for (int v : graf[x])
        if (v != y)
            dfs(v, x, d ^ 1);
}
int ans[N];
int main()
{
    int n;
    scanf("%d", &n);
    for(int i=1;i<n;i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        graf[a].push_back(b);
        graf[b].push_back(a);
    }
    dfs(1, 0);
    vector<int> p[3];
    for (int i = 1; i <= n; ++i)
        p[i % 3].push_back(i);

    for (int c = 1; c <= 2; ++c)
    {
        bool did = true;
        for (int d =0; d < 2;d++)
            if (h[d].size() >= p[c].size())
            {
                for (int x : p[c])
                {
                    ans[h[d].back()] = x;
                    h[d].pop_back();
                }
                did = true;
                break;
            }
        //assert(did);
    }
    for (int i = 1; i <= n; ++i)
        if (ans[i] == 0)
        {
            ans[i] = p[0].back();
            p[0].pop_back();
        }
    for (int i = 1; i <= n; ++i)
        printf("%d ", ans[i]);
    printf("\n");
}

Measured memory_bytes: 22260
#include<bits/stdc++.h>
using namespace std;
int n,x,y,t,X,Y,T;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d%d%d",&T,&X,&Y);
		if (abs(x-X)+abs(y-Y)>T-t) return puts("No"),0;
		if ((X+Y-T)&1) return puts("No"),0;
		x=X;y=Y;t=T;
	}
	puts("Yes");
	return 0;
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


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

	vector < vector <char> > t(n, vector <char>(m));


	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> t[i][j];
		}
	}


	vector < vector <int> > r(n, vector <int> (m));
	vector < vector <int> > l(n, vector <int> (m));
	vector < vector <int> > d(n, vector <int> (m));
	vector < vector <int> > u(n, vector <int> (m));

	for(int i = 0; i < n; i++){
		int current = 0;
		for(int j = 0; j < m; j++){
			if(t[i][j] != '#'){
				l[i][j] = current;
				current++;
			}else{
				current = 0;
			}
		}
	}

	for(int i = 0; i < n; i++){
		int current = 0;
		for(int j = m - 1; j >= 0; j--){
			if(t[i][j] != '#'){
				r[i][j] = current;
				current++;
			}else{
				current = 0;
			}
		}
	}


	for(int i = 0; i < m; i++){
		int current = 0;
		for(int j = 0; j < n; j++){
			if(t[j][i] != '#'){
				u[j][i] = current;
				current++;
			}else{
				current = 0;
			}
		}
	}

	for(int i = 0; i < m; i++){
		int current = 0;
		for(int j = n - 1; j >= 0; j--){
			if(t[j][i] != '#'){
				d[j][i] = current;
				current++;
			}else{
				current = 0;
			}
		}
	}


	int record = 0;

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(t[i][j] != '#'){
				record = max(record, 1 + l[i][j] + r[i][j] + u[i][j] + d[i][j]);
			}
		}
	}



	cout << record << endl;


	return 0;
}

Measured memory_bytes: 129536
S = input().split()
stack = []
for x in S:
    if x == "+":
        stack.append(stack.pop(-2) + stack.pop(-1))
    elif x == "-":
        stack.append(stack.pop(-2) - stack.pop(-1))
    elif x == "*":
        stack.append(stack.pop(-2) * stack.pop(-1))
    else:
        stack.append(int(x))
print(stack[0])


Measured memory_bytes: 5596
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int ww(int c)
{
	if (c==0) return 0;
	return ww(c/10)+1;
}
int main()
{
//	freopen("1 21.in","r",stdin);
//	freopen("1 21.out","w",stdout);
 	int a,b,t,l;
 	cin>>a>>b;
 	t=ww(b);
 	while (t)
 	{
 		a=a*10;
 		t--;
 		}
 	a+=b;
 	b=floor(sqrt(a));
 	if (b*b==a) cout<<"Yes"<<endl;
 	else cout<<"No"<<endl;
	return 0;
}



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

using namespace std;

#define INF (1LL << 62)

struct Human {
	int direct;
	long long position;
	long long save;
} human[100001];

int main() {
	long long t;
	int n, q;

	cin >> n >> t >> q;
	for (int i = 1; i <= n; ++i) {
		cin >> human[i].position >> human[i].direct;
	}
	human[0].direct = 1;
	human[0].position = -INF;
	human[n + 1].direct = 2;
	human[n + 1].position = INF;

	for (int i = 0; i <= n; ++i) {
		if (human[i].direct == 1 && human[i + 1].direct == 2) {
			long long d = (human[i].position + human[i + 1].position) / 2;
			for (int j = i; j >= 1 && human[j].direct == 1; --j) {
				human[j].save = d;
			}
			for (int j = i + 1; j <= n && human[j].direct == 2; ++j) {
				human[j].save = d;
			}
		}
	}

	int id;
	for (int i = 0; i < q; ++i) {
		cin >> id;
		if (human[id].direct == 1) {
			cout << (human[id].position + t < human[id].save ? human[id].position + t : human[id].save) << endl;
		}
		else {
			cout << (human[id].position - t > human[id].save ? human[id].position - t : human[id].save) << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 5404
n = int(input())
a = list(map(lambda x:int(x)-1,input()))
ans = 0
for i in range(n):
    if (n-1) & i == i:
        ans += a[i]
if ans % 2 == 1:
    print(1)
else:
    if a.count(1) != 0:
        print(0)
    else:
        ans = 0
        b = list(map(lambda x:x//2,a))
        for i in range(n):
            if (n-1) & i == i:
                ans += b[i]
        if ans % 2 == 1:
            print(2)
        else:
            print(0)

Measured memory_bytes: 119240
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>


using namespace std;

double solvet(int x){

    double t;

    t = sqrt(1.0*x/4.9);

    return t;

}

void funcv(double v_clash){
   int build=0;
   double v_theo = 0.0;
   double t=0.0;
   int count = 1;

  while(1){
      build = 5*count-5;

      t = solvet(build);
      

      v_theo = 9.8*t;
     // cout << build <<" "<< t << " "<<v_theo <<endl;

      if(v_clash < v_theo){
       cout << count << endl;
       break;
   }
   ++count;
   
  }
  



   
}


int main(){

 double v=0.0;


 while(cin >> v){

  funcv(v);   

 }



    return 0;



}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a="ABC";
    string b="ARC";
    string s;
    cin>>s;
    if(s==a)
    {
        cout<<b;
    }
    else if(s==b)
    {
        cout<<a;
    }
}

Measured memory_bytes: 3600
suit = ['S','H','C','D']
num = range(0, 13)
deck = {'S':[0]*13, 'H':[0]*13, 'C':[0]*13, 'D':[0]*13} 

n = input()
 
for i in range(0, n):
    a, b = raw_input().split(" ")
    deck[a][int(b)-1] = 1
 
for i in suit:
    for j in num:
        if (deck[i][j] == 0):
            print("%s %d" % (i, j+1))

Measured memory_bytes: 6456
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a,b,t;
		
		while(scan.hasNext())
		{
			a=scan.nextInt();
			b=scan.nextInt();
			t=scan.nextInt();
			
			int count=0;
			int i=0;
			while(true)
			{
				 i++;
				 if(a*i<=t)
					 count+=b;
				 else break;
			}
			System.out.println(count);
		}
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B>>C>>D;
  if(A+B > C+D){
    cout << "Left" << endl;
  }
  else if(A+B == C+D){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

using namespace std;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define PI 3.141592653589793
#define vi vector<int>
#define vll vector<long long>
#define p pair<int,int>
const int MOD = 1000000007;
inline double degcos(double ang) {return cos(ang*PI/180);}
inline double degsin(double ang) {return sin(ang*PI/180);}
#define rep(i,j,k,in) for (int i = j; i < k; i += in)


/*---END OF TEMPLATE---*/
int L[3005][3005];
string a,b;


int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    //ifstream fin("data.in");
    //ofstream fout("data.out");
    
    cin >> a >> b;
    memset(L,0,sizeof(L));
    int x = a.size(), y = b.size();
    rep(i,0,x+1,1) {
        rep(j,0,y+1,1) {
            if (i == 0 || j == 0) L[i][j] = 0;
            else if (a[i-1] ==  b[j-1]) {
                L[i][j] = L[i-1][j-1]+1;
            }
            else {
                L[i][j] = max(L[i-1][j],L[i][j-1]);
            }
        }
    }
    int idx = L[x][y];
    int i = x, j = y;
    string lcs = "";
    while (i > 0 && j > 0) {
        if (a[i-1] == b[j-1]) {
            lcs = a[i-1] + lcs;
            --i;
            --j;
            --idx;
        }
        else if (L[i-1][j] > L[i][j-1]) --i;
        else j--;
    } 
    cout << lcs;



}

Measured memory_bytes: 38972
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define space putchar(' ')
#define endl putchar('\n')
#define debug puts("------------------------")
#define F(i,x,n) for(int i=x;i<=n;++i)
#define F_(i,x,n) for(int i=x;i>=n;--i)
using namespace std;
inline void read(int &a) {a=0;int c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();a*=b; }
inline int  Rem() {int a=0,c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();return a*=b; }
inline void write(int x) {if(x>9)write(x/10);putchar('0'+x%10);}
inline void W(int x) {if(x<0){putchar('-'),x=-x;}write(x);}
/**/
const int N=1e5+5;
int n,m;
ll ans;
struct node
{
	int x,num;
	bool operator<(const node b)const
	{
		return x<b.x;
	}
}a[N];
/**/
int main()
{
	// freopen("test.in","r",stdin);
	// freopen("test.out","w",stdout);
	read(n);read(m);
	for(int i=1;i<=n;i++)
	{
		read(a[i].x);read(a[i].num);
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	{
		if(a[i].num<=m) m-=a[i].num,ans+=1LL*a[i].num*a[i].x;
		else {ans+=1LL*m*a[i].x;break;}
	}
	cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){ll mod=1e9+7,x,y,z=1,w=0,o,p,q,v[93],t[91][91][2],a,b;v[0]=1,v[1]=1;for(ll i=2;i<93;i++)v[i]=v[i-1]+v[i-2];for(ll i=2;i<91;i++){for(ll j=0;j<i;j++){a=v[i],b=v[i+1];if(j==0){t[i][j][0]=a,t[i][j][1]=b;continue;}if(j==1){t[i][j][0]=b,t[i][j][1]=2*b-a;continue;}t[i][j][0]=t[i-1][j-1][1],t[i][j][1]=t[i-1][j-1][1]+t[i-1][j-1][0];}}cin>>q;for(ll i=0;i<q;i++){cin>>x>>y;if(x>y)swap(x,y);if(y==1){cout<<"1 1"<<endl;continue;}for(ll i=0;i<93;i++){if(v[i]>x||v[i+1]>y){z=i-1;break;}}cout<<z<<" ";if(z==1){cout<<x*y%mod<<endl;continue;}w=0;for(ll j=0;j<z;j++){o=t[z][j][0],p=t[z][j][1];if(o>x||p>y)continue;w+=(y-p)/o+1;w%=mod;if(x>=p)w+=(x-p)/o+1;w%=mod;}cout<<w<<endl;}}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] a= new int[4];
		for(int i=3;i>=0;i--)
		{
			int x=n%10;
			a[i]=x;
			n=n/10;
		}
		if(a[0]==a[1]&&a[1]==a[2]){
			System.out.println("Yes");
			return;
		}

		if(a[1]==a[2]&&a[2]==a[3]){
			System.out.println("Yes");
			return;
		}
		System.out.println("No");

	}

}


Measured memory_bytes: 23252
fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        a_s: [usize; n],
    }
    let mut bm = std::collections::BTreeMap::<usize, usize>::new();
    for a in a_s {
        *bm.entry(a).or_insert(0) += 1;
    }
    for _ in 0..m {
        let (max, count) = bm.iter().rev().next().unwrap();
        let (max, count) = (*max, *count);
        if count == 1 {
            bm.remove(&max);
        } else {
            *bm.get_mut(&max).unwrap() -= 1;
        }
        let new_num = max / 2;
        if bm.contains_key(&new_num) {
            *bm.get_mut(&new_num).unwrap() += 1;
        } else {
            bm.insert(new_num, 1);
        }
    }
    let ans = bm.iter().map(|(num, count)| num * count).sum::<usize>();
    println!("{}", ans);
}


Measured memory_bytes: 7132
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) cin >> a[i];
    bool check = true;
    if (a[0] != 0) check = false;
    for (Int i = 0; i < n - 1; i++) {
        if (a[i + 1] > a[i] && a[i + 1] - a[i] != 1) {
            check = false;
        }
    }
    if (!check) {
        dump(-1);
        return 0;
    }
    Int res = 0;
    Int pre = 0;
    for (Int i = n - 1; i >= 0; i--) {
        if (pre <= a[i]) {
            res += a[i];
        }
        pre = a[i];
    }
    dump(res);
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (i % 2 == 1) {
      if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
import math

N, M = map(int, input().split())
mod = 10**9 + 7

if abs(N - M) > 1:
    print(0)
    exit()

n = math.factorial(N)
if N == M:
    m = n
    ans = (2 * n * m) % mod
else:
    if N < M:
        m = M * n
    else:
        m = n // N
    ans = (n * m) % mod

print(ans)

Measured memory_bytes: 5180
#include <stdio.h>
#include <stdlib.h>
using namespace std;


int linear_search(const int n, int S[], const int q, int T[])
{
    int count = 0;

    for (int i = 0; i < q; i++) {
        for (int j = 0; j < n; j++) {
            if (S[j] == T[i]) {
                count++;
                break;
            }
        }
    }
    return count;
}

int main (void) {

    int n;
    int q;

    scanf("%d", &n);
    int *S = new int[n];
    for (int i = 0; i < n; i++) scanf("%d", &S[i]);
    scanf("%d", &q);
    int *T = new int[q];
    for (int i = 0; i < q; i++) scanf("%d", &T[i]);

    printf("%d\n", linear_search(n, S, q, T));
    return 0;
}





Measured memory_bytes: 2804
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int r;
	std::cin >> r;
	std::cout << r*r << "\n";
}


Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    x = list(map(int, input().split()))
    ans = 10000000000
    for i in range(n - k + 1):
        l, r = x[i], x[i + k - 1]
        if l < 0 and r > 0:
            d = max(abs(l), abs(r)) + min(abs(l), abs(r)) * 2
        else:
            d = max(abs(l), abs(r))
        ans = min(d, ans)
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
    string s;
    int n;
    cin >> n >> s;
    string out;
    for (int i = 0; i < s.size(); ++i) {
        int c = s[i] - 'A';
        c += n;
        char c1 = 'A' + (c % 26);
        out += c1;
    }
    cout << out;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a + b == c) {
		cout << "Yes" << endl;
	}
	else if (a + c == b) {
		cout << "Yes" << endl;
	}
	else if (b + c == a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


}


Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main()
{
	int X, Y;
	cin >> X >> Y;

	if ((Y - 2 * X) % 2 == 0 && (Y - 2 * X) >= 0 && (X - (Y - 2 * X) / 2) >= 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3620
use proconio::{fastout, input};

fn pow(mut x: i64, mut y: i64, z: i64) -> i64 {
    let mut r = 1;
    while y > 0 {
        if y & 1 == 1 {
            r = r * x % z;
        }
        x = x * x % z;
        y >>= 1;
    }
    r
}

fn inv(x: i64, y: i64) -> i64 {
    pow((x % y + y) % y, y - 2, y)
}

#[fastout]
fn main() {
    const M: i64 = 1_000_000_007;
    input! {
        n: usize, mut k: usize,
        mut a: [i64; n],
    }
    let mut pos = 0;
    let mut zero = 0;
    let mut neg = 0;
    for &x in a.iter() {
        if x > 0 {
            pos += 1;
        } else if x < 0 {
            neg += 1;
        } else {
            zero += 1;
        }
    }
    if k > pos + neg {
        println!("0");
        return;
    }
    a.sort();

    if pos == 0 {
        if k % 2 == 0 {
            let mut acc = 1;
            for i in 0..k {
                acc = acc * a[i] % M;
            }
            acc = (acc % M + M) % M;
            if zero > 0 && acc < 0 {
                println!("0");
            } else {
                println!("{}", acc);
            }
        } else {
            let mut acc = 1;
            for i in n - k..n {
                acc = acc * a[i] % M;
            }
            acc = (acc % M + M) % M;
            if zero > 0 && acc < 0 {
                println!("0");
            } else {
                println!("{}", acc);
            }
        }
        return;
    }
    {
        let mut l = 0;
        let mut acc = 1;
        while k > pos {
            acc = acc * a[l] % M * a[l + 1] % M;
            l += 2;
            k -= 2;
        }
        for i in n - k..n {
            acc = acc * a[i] % M;
        }
        for _ in 0..(neg - l) / 2 {
            if n - k + 1 >= n {
                break;
            }
            if a[l] * a[l + 1] > a[n - k] * a[n - k + 1] {
            } else {
                break;
            }
            acc = acc * a[l] % M * a[l + 1] % M;
            acc = acc * inv(a[n - k], M) % M * inv(a[n - k + 1], M) % M;
            l += 2;
            k -= 2;
        }
        acc = (acc % M + M) % M;
        println!("{}", acc);
    }
}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
int main()
{
	dhoom;
	int n;
	cin >> n;
	if(n < 1200)
		cout << "ABC" << endl;
	else if(n < 2800)
		cout << "ARC" << endl;
	else
		cout << "AGC" << endl;
	return 0;
} 



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

#define INF 1234567890
#define ll long long

int N, M, K, A, B, C, D, L, R;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	int res = 0;
	for(int i=1; i<=N; i++)
	{
		int t;
		cin >> t;
		if (i%2 && t%2) res++;
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int h,w,k;
int dx[] = {0,-1,0,1};
int dy[] = {-1,0,1,0};
vector< vector<int> > dist;
vector<string> v;

void bfs( int x , int y )
{
    queue< pair<int,int> > q;
    q.push(pair<int,int>(x,y));
    dist[x][y] = 0;
    while( !q.empty() )
    {
        pair<int,int> p = q.front();
        q.pop();
        int nx = p.ft;
        int ny = p.sd;
        rep(d,0,4){
            rep(j,1,k+1){
                int tx = nx + dx[d]*j;
                int ty = ny + dy[d]*j;
                if ( tx < 0 || tx >= h || ty < 0 || ty >= w ){
                    break;
                }
                if ( v[tx][ty] == '@' ){
                    break;
                }
                   if ( dist[tx][ty] != -1 && dist[tx][ty] <= dist[nx][ny] ){
                    break;
                }
                if ( dist[tx][ty] != -1 ){
                    continue;
                }
                dist[tx][ty] = dist[nx][ny] + 1;
                q.push(pair<int,int>(tx,ty));
            }
        }
    }
}

//START OF CODE ->->->->->->->

void solve()
{
    cin>>h>>w>>k;
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    x1--;x2--;y2--;y1--;
    v = vector<string>(h);
    dist = vector< vector<int> >(h,vector<int>(w,-1));
    rep(i,0,v.size()){
        cin>>v[i];
    } 
    bfs(x1,y1);
    cout<<dist[x2][y2]<<endl;

}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 18780
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int n;
ull col[510],row[510],ans[510][510];
bool cc[510],rr[510];
namespace MaxFlow{
	const int N=1010,M=2000000;
	int head[N],cur[N],dep[N],cnt,S,T,res,deg[N],sum,s,t;
	struct node{
		int to,next,val;
	}edge[M];
	void ae(int u,int v,int l,int r){
//		printf("%d %d %d %d\n",u,v,l,r);
		deg[v]+=l,deg[u]-=l;
		edge[cnt].next=head[u],edge[cnt].to=v,edge[cnt].val=r-l,head[u]=cnt++;
		edge[cnt].next=head[v],edge[cnt].to=u,edge[cnt].val=0,head[v]=cnt++;
	}
	queue<int>q;
	inline bool bfs(){
		memset(dep,0,sizeof(dep)),q.push(S),dep[S]=1;
		while(!q.empty()){
			register int x=q.front();q.pop();
			for(register int i=cur[x]=head[x];i!=-1;i=edge[i].next)if(edge[i].val&&!dep[edge[i].to])dep[edge[i].to]=dep[x]+1,q.push(edge[i].to);
		}
		return dep[T]>0;
	}
	bool reach;
	inline int dfs(int x,int flow){
		if(x==T){
			res+=flow;
			reach=true;
			return flow;
		}
		int used=0;
		for(register int &i=cur[x];i!=-1;i=edge[i].next){
			if(!edge[i].val||dep[edge[i].to]!=dep[x]+1)continue;
			register int ff=dfs(edge[i].to,min(edge[i].val,flow-used));
			if(ff){
				edge[i].val-=ff;
				edge[i^1].val+=ff;
				used+=ff;
				if(used==flow)break;
			}
		}
		return used;
	}
	inline void Dinic(){
		while(bfs()){
			reach=true;
			while(reach)reach=false,dfs(S,0x3f3f3f3f);
		}
	}
}
using namespace MaxFlow;
void func(int ip){
	memset(head,-1,sizeof(head)),cnt=res=sum=0,memset(deg,0,sizeof(deg));
	for(int i=1;i<=n;i++){
		if(!cc[i]){
			if(col[i]&(1ull<<ip))ae(s,i,n,n);
			else ae(s,i,0,n-1);
		}else{
			if(col[i]&(1ull<<ip))ae(s,i,1,n);
			else ae(s,i,0,0);
		}
	}
	for(int i=1;i<=n;i++){
		if(!rr[i]){
			if(row[i]&(1ull<<ip))ae(i+n,t,n,n);
			else ae(i+n,t,0,n-1);
		}else{
			if(row[i]&(1ull<<ip))ae(i+n,t,1,n);
			else ae(i+n,t,0,0);
		}
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)ae(i,j+n,0,1);
	ae(t,s,0,0x3f3f3f3f);
//	for(int i=1;i<=t;i++)printf("%d ",deg[i]);puts("");
	for(int i=1;i<=t;i++){
		if(deg[i]>0)ae(S,i,0,deg[i]),sum+=deg[i];
		if(deg[i]<0)ae(i,T,0,-deg[i]);
	}
	Dinic();
	if(sum!=res){puts("-1");exit(0);}
	for(int i=1;i<=n;i++)for(int j=head[i];j!=-1;j=edge[j].next){
		if(!(edge[j].to>n&&edge[j].to<=2*n))continue;
		if(!edge[j].val)ans[i][edge[j].to-n]|=1ull<<ip;
	}
}
int main(){
	scanf("%d",&n),s=2*n+1,t=2*n+2,S=2*n+3,T=2*n+4;
	for(int i=1;i<=n;i++)scanf("%d",&cc[i]);
	for(int i=1;i<=n;i++)scanf("%d",&rr[i]);
	for(int i=1;i<=n;i++)scanf("%llu",&col[i]);
	for(int i=1;i<=n;i++)scanf("%llu",&row[i]);
	for(int i=0;i<64;i++)func(i);
	for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)printf("%llu ",ans[i][j]);puts("");}
	return 0;
}
/*
3
1 1 0
0 0 1
23 3 1
0 0 23 
*/ 

Measured memory_bytes: 13332
#include<iostream>
using namespace std;
int main(){
  int N,ans;
  ans = 0;
  cin >> N;
  int A[N];
  for(int i = 0;i<N;i++){
    cin>>A[i];
    ans += A[i];
  }
  
  cout << ans - N << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define ull unsinged long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
const int inf=1039074182;
const ll llinf=1LL*inf*inf;
using namespace std;

int main()
{
//	freopen("input.txt","r",stdin);
	ll a,b,c;
	cin>>a>>b>>c;
	if(c-a-b<0) over("No");
	bool yes=(a*a+b*b+c*c-2ll*b*c-2ll*a*c>2ll*a*b);
	if(yes) cout<<"Yes\n";else cout<<"No\n";
	return 0;
}

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

int main()
{
  int64_t N, ans = 0;
  cin >> N;
  vector<int64_t> V(N * 3);
  for (int i = 0; i < N * 3; i++)
    cin >> V.at(i);
  sort(V.begin(), V.end());
  for (int i = N * 3 - 2; i >= N; i -= 2)
    ans += V.at(i);
  cout << ans << endl;
}

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

int main() {
	int a, b;
	cin >> a >> b;

	vector<int> s = {0, 14, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

	if(s.at(a) > s.at(b)) cout << "Alice" << endl;
	if(s.at(a) < s.at(b)) cout << "Bob" << endl;
	if(s.at(a) == s.at(b)) cout << "Draw" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

LL mygcd(LL a, LL b){
	if(b > a){
		LL tmp = b;
		b = a;
		a = tmp;
	}
	while(b > 0){
		LL tmp = b;
		b = a%b;
		a = tmp;
	}
	return a;
}

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

    LL T;
	cin >> T;
	vector<LL> a(T),b(T),c(T),d(T);

	for(int i = 0; i < T; i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}

	vector<string> ans;

	for(int i = 0; i < T; i++){
		LL start;
		LL tmp = a[i] - c[i];
		if(tmp > 0){
			if(tmp%b[i] == 0){
				start = a[i] - (tmp/b[i])*b[i];
			}else{
				start = a[i] - (tmp/b[i])*b[i] - b[i];
			}
		}else{
			start = a[i] - b[i];
		}
		if(start < 0){
			ans.push_back("No\n");
		}else{
			if(d[i] >= b[i]){
				LL dist = mygcd(b[i],abs(d[i] - b[i]));
				LL line = c[i] - start;
				LL min = start + (1 + line/dist)*dist;
				if(min - b[i] >= 0){
					ans.push_back("Yes\n");
				}else{
					ans.push_back("No\n");
				}
			}else{
				ans.push_back("No\n");
			}
		}
	}

	for(int i = 0; i < T; i++){
		cout << ans[i];
	}
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const int maxn=2e5+10;
int a[maxn];
bool cmp(int x,int y){
	return x>y;
}
int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n,cmp);
	ll ans=0;
	if(n==2){
		printf("%lld\n",a[0]);
		return 0;
	}
	if(n&1){
		for(int i=1;i<=n/2;i++){
			ans+=a[i];
		}
		for(int i=0;i<n/2;i++){
			ans+=a[i];
		}
	}else{
		for(int i=0;i<n/2-1;i++){
			ans+=a[i];
			//cout<<a[i]<<" ";
		}
		for(int i=1;i<n/2;i++){
			ans+=a[i];
			//cout<<a[i]<<" ";
		}
		ans+=a[n/2-1];
		//cout<<a[n/2+1]<<" ";
	}
	
	printf("%lld\n",ans);
 	return 0;
}







Measured memory_bytes: 4548
S = int(input())
MOD = 10**9 + 7

class Combination:
    #クラス外にMODの宣言をする必要がある。
    def __init__(self, N):
        self.fac = [1] * (N + 1)
        for i in range(1, N + 1):
            self.fac[i] = (self.fac[i - 1] * i) % MOD
        self.invmod = [1] * (N + 1)
        #逆元?
        self.invmod[N] = pow(self.fac[N], MOD - 2, MOD)
        for i in range(N, 0, -1):
            self.invmod[i - 1] = (self.invmod[i] * i) % MOD

    def calc(self, n, k):  # nCk
        return self.fac[n] * self.invmod[k] % MOD * self.invmod[n - k] % MOD

N = S//3
comb = Combination(10**6+2)
ans = 0
for n in range(1,N+1):
    s = S - 3 * n
    val = comb.calc(s+n-1,n-1)
    ans = (ans+val)%MOD

print(ans)

Measured memory_bytes: 79832