akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

const int MAX_SIZE = 2501;

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

    int n;
    cin >> n;
    vector<int> t(n);
    rep(i, n) cin >> t[i];
    vector<vector<bool>> dp(MAX_SIZE, vector<bool>(MAX_SIZE, false));
    dp[0][0] = true;
    rep(i, n)
    {
        vector<vector<bool>> nxt(MAX_SIZE, vector<bool>(MAX_SIZE));
        rep(j, MAX_SIZE) rep(k, MAX_SIZE)
        {
            nxt[j][k] = dp[j][k];
            if (j >= t[i])
                nxt[j][k] = nxt[j][k] | dp[j - t[i]][k];
            if (k >= t[i])
                nxt[j][k] = nxt[j][k] | dp[j][k - t[i]];
        }
        rep(j, MAX_SIZE) rep(k, MAX_SIZE) dp[j][k] = nxt[j][k];
    }
    int ans = INF, sum = 0;
    rep(i, n) sum += t[i];
    rep(i, MAX_SIZE) rep(j, MAX_SIZE)
    {
        if (!dp[i][j])
            continue;
        int k = sum - (i + j);
        ans = min(ans, max({i, j, k}));
    }
    cout << ans << endl;
}


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(21<(a+b+c)?"bust":"win")<<endl;
}

Measured memory_bytes: 256
N=input()

dp0=[0]*(len(N)+1)
dp1=[0]*(len(N)+1)
dp1[0]=1

for i in range(len(N)):
    n=int(N[i])
    dp0[i+1]=min(dp0[i]+n, dp1[i]+(10-n))
    n+=1
    dp1[i+1]=min(dp0[i]+n, dp1[i]+(10-n))

#print(dp0)
#print(dp1)
print(dp0[-1])


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

int main(){
  int n; cin >> n;
  int ans;
  if(n%2 == 0){
    ans = n;
  }else{
    ans = n*2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//GeT AC

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,q;
    string s;
    cin>>n>>q>>s;
    vector<int>ka(n,0);
    rep(i,1,n){
        if(s[i-1]=='A'&&s[i]=='C')ka[i]++;
        if(i!=n-1)ka[i+1]=ka[i];
    }
    rep(i,0,q){
        int l,r;cin>>l>>r;
        cout<<ka[r-1]-ka[l-1]<<nnn;
    }
    return 0;
}

Measured memory_bytes: 1792
answer=gets.chomp
q=gets.to_i
first=""
last=""
zyun=true

q.times {
    input=gets.chomp.split
    if input[0]=="1"
       zyun=!zyun
   elsif input[1]=="1"
       if zyun
           first<<input[2]
       else
           last<<input[2]
       end
    else
       if !zyun
           first<<input[2]
       else
           last<<input[2]
       end
   end
    
}

answer=first.reverse+answer+last

if !zyun
   answer=answer.reverse 
end

puts answer

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int a,b,x;
    cin >> a >> b >> x;
    if(a <= x && x <= a + b) pr("YES");
    else pr("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int LL 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
int lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
const int MAX_N=105;
vec pre[4];
int v[MAX_N],w[MAX_N],n,W;
signed main()
{
	cin>>n>>W;
	rep(i,0,n)cin>>w[i]>>v[i];
	rep(i,0,n)
	{
		pre[w[i]-w[0]].pb(v[i]);
	}
	rep(i,0,4)sort(all(pre[i]));
	rep(i,0,4)pre[i].pb(0);
	rep(i,0,4)reverse(all(pre[i]));
	rep(i,0,4)
	{
		rep(j,1,pre[i].size())
		{
			pre[i][j]+=pre[i][j-1];
		}
	}
	int ans=0;
	rep(p0,0,pre[0].size())
	{
		rep(p1,0,pre[1].size())
		{
			rep(p2,0,pre[2].size())
			{
				int p3=(W-w[0]*p0-(w[0]+1)*p1-(w[0]+2)*p2)/(w[0]+3);
				if(p3<0)continue;
				if(p3>=pre[3].size())p3=pre[3].size()-1;
				if(W-w[0]*p0-(w[0]+1)*p1-(w[0]+2)*p2<0)continue;
				ans=max(ans,pre[0][p0]+pre[1][p1]+pre[2][p2]+pre[3][p3]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n-1);
    long ans=0;
    rep(i,n-1){
        cin>>b[i];
    }
    rep(i,n-1){
        if(i==0){
            a[i]=b[i];
            a[i+1]=b[i];
        }else{
            a[i+1]=b[i];
        }
        if(a[i]>a[i+1] && a[i]>b[i]) a[i]=b[i];
    }
    rep(i,n){
        ans+=a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>    //C++の標準ライブラリのヘッダを全て読み込む
 
int main() {
    using std::cout;
    using std::endl;
    using std::cin;

    int n = 0, a = 0;
    cin >> n >> a;
    cout << n*n - a << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a, b = 1;
	while(true)
		{
		cin >> a;
		if ( a == 0 )break;
		else if ( a != 0 )
			cout << "Case " << b << ": " << a << endl;
		b++;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

#include <stack>
#include <queue>
// #include <deque>
#include <set>
#include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;
typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/

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

    int n,k,c; cin>>n>>k>>c; cin.ignore();
    string s; cin>>s; cin.ignore();

    vector<int> gg(n+1,0);
    // vector<int> freq(n+1,0);
    vector<vector<int>> indwithgg(n+1);
    for (int i = n-1; i>=0; --i) {
        if (s[i]=='o') {
             //then add this;
             gg[i]=1;
             if (i+c+1<n) gg[i]+=gg[i+c+1];
        } else if (s[i]=='x') {
            gg[i]=gg[i+1];
        } else {
            cout<<"shouldn't be here"<<el;
        }
        // if (s[i]=='o') ++freq[gg[i]];
        if (s[i]=='o') indwithgg[gg[i]].push_back(i);
    }

    // cout<<"max possible from:  "<<el;
    // for (int i = 0; i<n; ++i) {
    //     cout<<"index "<<i+1<<": "<<s.substr(i)<<":   "<<gg[i]<<el;
    // }


    //nothing is forced;
    if (gg[0]>k || gg[0]<k) {
        return 0;
    }


    for (int i = 0; i<n; ++i) {
        if (s[i]=='x') continue;


        int numpossible = gg[i];
        // cout<<"max possible from "<<i+1<<":  "<<numpossible<<";  ";
        while ( !indwithgg[numpossible].empty() && indwithgg[numpossible].back() < i) indwithgg[numpossible].pop_back();
        // cout<<indwithgg[numpossible].size()<<el;
        if ( indwithgg[numpossible].size() == 1) {
            cout<<i+1<<el;
            i=i+c;
            // cout<<"found forced!! jumped to "<<i+1+1<<el;
            //and need to pop all
        } else {
            // do the earlier one;
            // int earliest = indwithgg[numpossible].back();

            int latest = indwithgg[numpossible].front();
            i=max(latest,i+c);
            // cout<<"assume we colored at "<<indwithgg[numpossible].back()+1<<" and jumped to "<<i+1+1<<el;
        }
    }





}

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

int main(){
    int n;
    cin >> n ;
    string s;
    cin >> s;
    int ans=0;
    vector<int> left(26,0);
    vector<int> right(26,0);
    for(int i=0;i<n-1;i++){
        int tmp=0;
        for(int j=0;j<26;j++){
            left[j] = 0;
            right[j] = 0;
        }

        for(int j=0;j<=i;j++){
            left[s[j]-'a']++;
        }
        for(int j=i+1;j<n;j++){
            right[s[j]-'a']++;
        }

        for(int j=0;j<26;j++){
        if(left[j] >0 && right[j] > 0){
            tmp ++;
        }
    }
        if(tmp > ans){
            ans = tmp;
        }
    }

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

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		puts("Draw");
		return 0;
	}
	if (a == 1) {
		puts("Alice");
		return 0;
	}
	if (b == 1) {
		puts("Bob");
		return 0;
	}
	puts((a > b ? "Alice" : "Bob"));
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> M(h);
	rep(i,h)cin>>M[i];
	//bfs
	vector<vector<int>> D(h,vector<int>(w));
	rep(i,h)
		rep(j,w)
		D[i][j]=-1;

	queue<pair<int,int>> Q;
	Q.push(make_pair(0,0));
	D[0][0]=1;
	while(!Q.empty())
	{
		//cout<<Q.size()<<endl;
		pair<int,int>now = Q.front();
		Q.pop();
		if(now.first>0)
			if(M[now.first-1][now.second]=='.'&&D[now.first-1][now.second]==-1)
			{
				D[now.first-1][now.second]=D[now.first][now.second]+1;
				Q.push(make_pair(now.first-1,now.second));
			}
		if(now.first<h-1)
			if(M[now.first+1][now.second]=='.'&&D[now.first+1][now.second]==-1)
			{
				D[now.first+1][now.second]=D[now.first][now.second]+1;
				Q.push(make_pair(now.first+1,now.second));
			}
		if(now.second>0)
			if(M[now.first][now.second-1]=='.'&&D[now.first][now.second-1]==-1)
			{				
				D[now.first][now.second-1]=D[now.first][now.second]+1;
				Q.push(make_pair(now.first,now.second-1));
			}
		if(now.second<w-1)
			if(M[now.first][now.second+1]=='.'&&D[now.first][now.second+1]==-1)
			{
				D[now.first][now.second+1]=D[now.first][now.second]+1;
				Q.push(make_pair(now.first,now.second+1));
			}
	}
	if(D[h-1][w-1]==-1)
	{
		cout<<-1<<endl;
		return 0;
	}

	int ans=h*w;
	rep(i,h)
		rep(j,w)
		if(M[i][j]=='#')ans--;
	
	ans-=D[h-1][w-1];
	cout<<ans<<endl;

	return 0;
}

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

using ll=long long; 

void solve(){
	string s,t;
	cin>>s>>t;
	int n=s.size();
	for(int i=0; i<n; i++){
		char c=s[0];
		s=s.substr(1,n-1)+c;
		if(s==t){
			cout<<"Yes"<<endl;
			return;
		}
	}
	cout<<"No"<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 200005
#define INF 0x3f3f3f3f
#define mod 1000000007
#define rep(i, a, n) for (ll i=(a); i<(n); i++)
#define per(i, a, n) for (ll i=(a); i>(n); i--)
typedef long long ll;
using namespace std;

ll x;

ll fpow(ll base, ll exp)
{
	ll res = 1;
	while(exp) {
		if ( exp&1 )
			res = (res*base);
		exp >>= 1;
		base = (base*base);
	}
	return res;
}

void slove()
{
	cin >> x;
	rep(i, -200, 201)
		rep(j, -200, 201) {
			if (fpow(i, 5) - fpow(j, 5) == x) {cout << i << ' ' << j << '\n'; return;}
		}
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:\\Users\\Fish_Brother\\Desktop\\in", "r", stdin);
	//freopen("C:\\Users\\Fish_Brother\\Desktop\\out", "w", stdout);
#endif
	slove();

	return 0;
}

Measured memory_bytes: 3664
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;
 
long long gcd(long long x, long long y){
			if (x==0)return y;
      if(y==0)return x;
      if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

   
int main(){
string S;
cin >> S;
int ans = 0;
string s = "CODEFESTIVAL2016";
for(int i = 0; i < 16;i++){
	if (s[i]!=S[i])
	{
		ans++;
	}
	
}
cout << ans << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int b[10]={0,2,5,5,4,5,6,3,7,6};

int N,M;
bool ok[10];


int dp[111111],len[111111];

signed main(){
    cin>>N>>M;
    rep(i,M){
        int a;cin>>a;ok[a]=true;
    }


    dp[0]=true;
    len[0]=0;
    for(int i=1;i<=N;i++){
        for(int j=1;j<10;j++){
            if(!ok[j])continue;
            if(i-b[j]<0)continue;
            if(dp[i-b[j]]){
                dp[i]=true;
                chmax(len[i],len[i-b[j]]+1);
            }
        }
    }


    int n=N;
    while(n){
        for(int i=9;i>=1;i--){
            if(!ok[i])continue;
            if(n-b[i]<0)continue;
            if(!dp[n-b[i]])continue;
            if(len[n]!=len[n-b[i]]+1)continue;
            cout<<i;
            n-=b[i];
            break;
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 384
def digit_sum(n)
  n.to_s.each_char.map {|c| c.to_i }.reduce(:+)
end

K = gets.to_i
#res  = []
#100000.times{|i|
##  res << (i+1)/digit_sum(i+1).to_f
#}
#puts res
res = [*1..9]
res = res.concat([*1..9].map{|i| i*10+9})
res = res.concat([*1..9].map{|i| i*100+99})
1.upto(13){|n|
  base = 10**n
  10.times{|i|
    10.times{|j|
      10.times{|k|
        res << base*(100*i+10*j+k)+base-1
      }
    }
  }
}
res = res.sort.uniq
result = []
(res.length-100).times{|i|
  flag = true
  2.times{|j|
    if (res[i]/digit_sum(res[i]).to_f > res[i+j+1]/digit_sum(res[i+j+1]).to_f)
      flag = false
    end
  }
  if (flag)
    result << res[i]
  end
}

res = []
(result.length-20).times{|i|
  flag = true
  10.times{|j|
    if (result[i]/digit_sum(result[i]).to_f > result[i+j+1]/digit_sum(result[i+j+1]).to_f)
      flag = false
    end
  }
  if (flag)
    res << result[i]
  end
}
puts res[0..K-1]

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

int main(void) {
    int n = 0;
    vector<int> a;
    while (true) {
        int x;
        cin >> x;
        a.push_back(x);
        if (a.at(n) == 0) {
            break;
        }
        n++;
    }
    for (int i = 0; i < n; i++) {
        cout << "Case " << i + 1 << ": " << a.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
# debug = lambda *a, **kw: print(*a, **kw, file=sys.stderr)

N = ini()
A = [ini() for _ in range(N)]


def solve():
    p_min = 1
    ans = 0
    # debug(A)
    for i in range(N):
        if A[i] < p_min:
            continue
        if A[i] == p_min:
            p_min += 1
            continue
        k = (A[i] - 1) // p_min
        ans += k
        A[i] = 1
        if p_min == 1:
            p_min += 1
        # debug(f">> {i=} {p_min=} {k=} {ans=} {A=}")
    return ans


print(solve())


Measured memory_bytes: 7108
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int ans = 0;
  string line;
  while(cin>>line){
	string tmp = line;
	reverse(ALL(tmp));
	if(tmp == line) ++ans;
  }
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

int ax[100005];
int top=0;
bool ok[100005];

signed main()
{
	int a, b;
	cin>>a>>b;
	if(a<=b)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	int n=a+b;
	for(int i=0; i<n; i++)
	{
		if(top==0)
		{
			top++;
			ax[top]=i;
		}
		else
		{
			cout<<"? "<<ax[top]<<" "<<i<<endl;
			char ans;
			cin>>ans;
			if(ans=='Y')
			{
				top++;
				ax[top]=i;
			}
			else
			{
				top--;
			}
		}
	}
	for(int i=0; i<n; i++)
	{
		cout<<"? "<<ax[top]<<" "<<i<<endl;
		char ans;
		cin>>ans;
		if(ans=='Y')
		{
			ok[i]=1;
		}
	}
	cout<<"! ";
	for(int i=0; i<n; i++)
	{
		cout<<ok[i];
	}
	cout<<endl;
}

Measured memory_bytes: 724
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 105;
int n, m;
int id[maxN * maxN];
vector < int > a[maxN];
vector < int > g[maxN];
bool was[maxN][maxN];
int mt[maxN];
bool used[maxN];
int b[maxN][maxN];
int c[maxN][maxN];
bool kuhn(int v) {
    if (used[v]) return false;
    used[v] = true;
    for (int to : g[v]) {
        if (mt[to] == -1 || kuhn(mt[to])) {
            mt[to] = v;
            return true;
        }
    }
    return false;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        a[i].resize(m);
        for (int& v : a[i]) {
            cin >> v;
            id[v] = (v - 1) / m + 1;
        }
    }
    for (int it = 0; it < m; it++) {
        memset(was, 0, sizeof was);
        memset(used, 0, sizeof used);
        memset(mt, -1, sizeof mt);
        for (int i = 1; i <= n; i++) {
            g[i].clear();
            for (int v : a[i]) {
                if (!was[i][id[v]]) {
                    g[i].push_back(id[v]);
                    was[i][id[v]] = true;
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            memset(used, 0, sizeof used);
            assert(kuhn(i));
        }
        for (int i = 1; i <= n; i++) {
            assert(mt[i] != -1);
            for (int j = 0; j < a[mt[i]].size(); j++) {
                if (id[a[mt[i]][j]] == i) {
                    b[mt[i]][it + 1] = a[mt[i]][j];
                    a[mt[i]].erase(a[mt[i]].begin() + j);
                    break;
                }
            }
        }
    }
    for (int col = 1; col <= m; col++) {
        for (int row = 1; row <= n; row++) {
            c[id[b[row][col]]][col] = b[row][col];
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << b[i][j] << " ";
        }
        cout << '\n';
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << c[i][j] << " ";
        }
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
int min(int a,int b,int c,int d){
    return min(min(a,b),min(c,d));
}
int max(int a,int b,int c,int d){
    return max(max(a,b),max(c,d));
}
int N,K,m[55][2];
int ans=8e18;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N>>K;
    for(int i=0;i<N;i++){
        cin>>m[i][0]>>m[i][1];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                for(int s=0;s<N;s++){
                    int a=min(m[i][0],m[j][0],m[k][0],m[s][0]);
                    int b=min(m[i][1],m[j][1],m[k][1],m[s][1]);
                    int c=max(m[i][0],m[j][0],m[k][0],m[s][0]);
                    int d=max(m[i][1],m[j][1],m[k][1],m[s][1]);
                    int cnt=0;
                    for(int t=0;t<N;t++){
                        if(m[t][0]>=a&&m[t][0]<=c&&m[t][1]>=b&&m[t][1]<=d){
                            cnt++;
                        }
                    }
                    if(cnt>=K){
                        ans=min(ans,(c-a)*(d-b));
                    }
                }
            }
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

void insertSort(int A[], int N) {
  for (int i = 1; i < N; i++) {
    int v;
    v = A[i];
    int j = i -1;
    while (j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      A[j--] = v;
    }
    for (int j = 0; j < N; j++) {
      if (j == N - 1) {
        printf("%d", A[N-1]);
      } else {
        printf("%d ", A[j]);
      }
    }
    printf("\n");
  }
}

int main() {
  int N;
  scanf("%d", &N);
  int A[N];

  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  for (int j = 0; j < N; j++) {
    if (j == N - 1) {
      printf("%d", A[N-1]);
    } else {
      printf("%d ", A[j]);
    }
  }
  printf("\n");

  insertSort(A, N);

  return 0;
}



Measured memory_bytes: 2040
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
int A[2000001];
int B[2000001];
long C[10001];
long n;
void CountingSort(int k){
	for (long j = 0; j < n; ++j) ++C[A[j]];
	for (long i = 1; i <= k; ++i) C[i] += C[i - 1];
	for (long j = n - 1; j >= 0; --j){
		B[C[A[j]]--] = A[j];
	}
}
int main(){
	scanf("%ld", &n);
	int MAX = -1;
	for (long i = 0; i < n; ++i) scanf("%d", &A[i]);
	for (long i = 0; i < n; ++i) MAX = max(MAX, A[i]);
	CountingSort(MAX);
	for (long i = 1; i <= n; ++i){
		if (i != 1) cout << ' ';
		cout << B[i];
	}
	cout << '\n';
}

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

int main(){
	int N, Y, x, y, z;
	
	cin >> N >> Y;  
	
	for (x=0; x<=Y/10000; x++)    
	  for (y=0; y<=Y/5000; y++)   
	  {
	  	    z = N - x - y;
	    	if (z>=0 && x*10000+y*5000+z*1000==Y)
	    	{
	    		cout << x << " " << y << " " << z;
	    		return 0;
	    	}
	  }
	
	cout << "-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;


int main() {

	int N;
	cin >> N;

	vector<int> vec(N, 0);

	for (int i = 0; i < N; i++) {
		cin >> vec[i];
	}

	vector<int> ans(N, 0);
	vector<int> ans2;
	int res = 1;
	int M = 0;


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


		int ansc = 0;

		res = floor(N / (k + 1));

		for (int j = 1; j <= res; j++) {
			ansc += vec[j * (k+1) -1];
		}

		ans[k] = ansc % 2;

		if (ans[k] == 1) {
			ans2.push_back(k + 1);
			M++;

		}

		vec[k] = ans[k];
	}


	cout << M << endl;

	for (int m = 0; m < ans2.size(); m++) {
		cout << ans2[m] << endl;
	}






}

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

int main(){
    int n, p, a[110], even = 0, odd = 0;
    ll ans = 0;
    cin >> n >> p;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2 == 0)   ++even;
        else    ++odd;
    }

    if(odd == 0){
        if(p == 0)  cout << (ll)pow(2.0f, n) << endl;
        else cout << "0\n";
    }
    else{
        cout << (ll)pow(2.0f, n-1) << endl;
    }
}

Measured memory_bytes: 256
$sumhash = {}

### subroutines

def check_sum(n, s, used = 0)
  key = "#{n},#{s},#{used}"
  return $sumhash[key] if ! $sumhash[key].nil?

  if n == 0
    return s == 0 ? 1 : 0
  end

  count = 0

  for i in (0..9)
    b = 1 << i
    ni = n * i
    if (used & b) == 0 && s >= ni
      used |= b
      count += check_sum(n - 1, s - ni, used)
      used ^= b
    end
  end

  return $sumhash[key] = count
end

### main

while (line = gets)
  n, s = line.chomp.split(" ").map{|s| s.to_i}

  puts check_sum(n, s)
end

Measured memory_bytes: 111652
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C, 0));
    REP(i, C) {
        REP(j, C) { cin >> D[i][j]; }
    }
    vector<vector<int>> c(N, vector<int>(N, 0));
    REP(i, N) {
        REP(j, N) { cin >> c[i][j]; }
    }
    // cout << "a" << endl;
    // 3とおりのグループに対してそれぞれを
    //あるいろで(C通り)で塗り分けた時のコストを
    //考える
    vector<vector<long long>> cost(3, vector<long long>(C, 0));
    REP(color, C) {
        REP(i, N) {
            REP(j, N) {
                int tmp = i + j;
                tmp %= 3;
                cost[tmp][color] += D[c[i][j] - 1][color];
            }
        }
    }
    long long res = INF;
    for(int i = 0; i < C; i++) {
        for(int j = i + 1; j < C; j++) {
            for(int k = j + 1; k < C; k++) {
                res = min(res, cost[0][i] + cost[1][j] + cost[2][k]);
                res = min(res, cost[1][i] + cost[2][j] + cost[0][k]);
                res = min(res, cost[2][i] + cost[0][j] + cost[1][k]);
                res = min(res, cost[0][i] + cost[2][j] + cost[1][k]);
                res = min(res, cost[2][i] + cost[1][j] + cost[0][k]);
                res = min(res, cost[1][i] + cost[0][j] + cost[2][k]);
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
#define FOR(i, a, b) for(LL i=(LL)(a);i<(LL)(b);i++)
#define REP(i,x) for(LL i=0;i<(LL)(x);i++)

int main()
{
    // ios::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout << fixed << setprecision(10);
    LL n;
    cin >> n;
    vector<LL> a_v;
    deque<LL> deq(n, 0);
    for(LL i=0; i<n; i++)
    {
        LL temp;
        cin >> temp;
        a_v.push_back(temp);
        deq[temp-1]++;
    }

    unordered_map<LL, pair<LL, LL>> a_map_cmb;
    deque<LL> deq_cmb(n, 0);
    LL all_sum = 0;

    REP(i, n)
    {
        LL temp = deq.at(i) * (deq.at(i) - 1) / 2;
        deq_cmb.at(i) = (deq.at(i) - 1) * (deq.at(i) - 2) / 2 - temp;
        all_sum = all_sum + temp;
    }

    for(auto it=a_v.begin(); it<a_v.end(); it++)
    {
        LL temp = 0;
        temp = all_sum + deq_cmb.at((*it)-1);
        cout << temp << endl;
    }
    return 0;
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    i64 a;
    string s;
    cin >> a >> s;

    int b = stoi(s.substr(0, 1) + s.substr(2, 2));

    cout << a * b / 100 << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3668
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var rank = IntArray(n+1){1}
    val cities=(1..m).map {
        val (p, y) = readLine()!!.split(" ").map { it.toInt() }
        return@map City(it, p, y)
    }.sortedBy { it.year }
            .map { Pair(it,rank[it.pref]++) }
            .sortedBy { it.first.no }
            .fold(StringBuilder()) { acc, pair ->
                acc.append("%06d%06d\n".format(pair.first.pref,pair.second) )
            }.let { println(it) }
}

class City(val no:Int, val pref:Int, val year:Int)


Measured memory_bytes: 135708
#!/usr/bin/env python
# coding: utf-8

# In[6]:


import math


# In[7]:


def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


# In[15]:


N,P = map(int, input().split())
A = list(map(int, input().split()))


# In[16]:


even_cnt = sum([1 for x in A if x%2 == 0])
odd_cnt = sum([1 for x in A if x%2 != 0])
if P == 0:
    ans1 = 2**even_cnt
    ans2 = 0
    for i in range(0,odd_cnt+1,2):
        ans2 += comb(odd_cnt,i)
else:
    ans1 = 2**even_cnt
    ans2 = 0
    for i in range(1,odd_cnt+1,2):
        ans2 += comb(odd_cnt,i)
print(ans1*ans2)


# In[ ]:






Measured memory_bytes: 9152
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int dp[110][20][1010];
signed main() {
    int n, s;
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    repq(i,1,100) {
        repq(j,0,15) {
            repq(k,0,1000) {
                dp[i][j][k] = dp[i-1][j][k];
                if(k - i < 0) continue;
                if(j != 0) dp[i][j][k] += dp[i-1][j-1][k-i];
            }
        }
    }
    while(cin >> n >> s, n || s) {
        cout << dp[100][n][s] + dp[100][n-1][s] << endl;
    }
    return 0;
}

Measured memory_bytes: 20440
using System;

namespace AGC024_B___Backfront
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var check = new int[N + 1];
            var max = 0;
            for (int i = 0; i < N; i++)
            {
                var read = int.Parse(Console.ReadLine());
                check[read] = check[read - 1] + 1;
                max = Math.Max(check[read], max);
            }
            Console.WriteLine(N - max);
        }
    }
}


Measured memory_bytes: 15836
#include <iostream>
#include <climits>
#include <vector>

using namespace std;

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

  int negative_count = 0;
  vector<long> a(n, 0);
  long sum = 0;
  long min_abs = LONG_MAX;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < 0) {
      long abso = - 1 * a[i];
      negative_count += 1;
      sum += abso;
      if (abso < min_abs) {
        min_abs = abso;
      }
    } else {
      sum += a[i];
      if (a[i] < min_abs) {
        min_abs = a[i];
      }
    }
  }


  if (negative_count % 2 == 0) {
    cout << sum << endl;
  } else {
    cout << sum - 2 * min_abs << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector< vector <int> > 
#define vb vector<bool>
#define si set<int>
#define mii map<int, int>
#define mci map<char, int>
#define md 1000000007
#define pb push_back
#define eb emplace_back
#define f(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define r(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define qw1(x) cerr<<#x<<": "<<x<<" "<<endl
#define qw2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define qw3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define qw4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl

void sieve(int n, vb &prime)
{
    prime[0]=false;     prime[1]=false;
    for(int i=2;i*i<=n;i++){
         if(prime[i]==true){
            for(int j=i*i;j<=n;j+=i)    prime[j]=false;
             }
    }
}
int32_t main ()
{
  //ios_base::sync_with_stdio (false); cin.tie (NULL);  cout.tie (NULL);
   
   int h;   cin>>h;
   int att=0; int cnt=1;
   while(h>0)
   {
       if(h==1) { att+=cnt*1; h=0; continue;}
       att+=cnt*1;
       h=h/2; cnt*=2;
       
   }
   cout<<att;
 
}






Measured memory_bytes: 256
// Last Change: 02/03/2019 23:15:20.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}

int main() {
  //入力部
  ll N, M;
  cin >> N >> M;
  vector<ll> X(M);
  vector<ll> diff(M - 1);
  for (int i = 0; i < M; ++i) {
    cin >> X.at(i);
  }

  sort(X.begin(), X.end());

  for (int i = 0; i < M - 1; ++i) {
    diff.at(i) = X.at(i + 1) - X.at(i);
  }

  sort(diff.begin(), diff.end());

  //計算部
  ll ans = 0;
  if (N < M) {
    ans = X.back() - X.front();
    for (int i = 0; i < N - 1; ++i) {
      ans -= diff.at(M - 2 - i);
    }
  } else {
  }
  cout << ans << endl;

  //LoopUntilZeroInpput();
}


Measured memory_bytes: 1792
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 1000006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
#define P 1000000007
int n , m , k;
int sx , sy , xx , yy;
char ch[MAXN]; int mm[MAXN] , vis[MAXN] , dis[MAXN];
int getid( int x , int y ) {
    return ( x - 1 ) * m + y;
}

int dirx[] = {0,1,-1,0};
int diry[] = {1,0,0,-1};

queue<pii> Q;
void bfs( ) {
    memset( dis , 0x3f , sizeof dis );
    Q.push( mp( sx , sy ) );
    dis[getid( sx , sy )] = 0;
    while( !Q.empty() ) {
        auto u = Q.front(); Q.pop();
        int x = u.fi , y = u.se , xx , yy;
//        cout << x << ' ' << y << ' ' << dis[getid( x , y )] << endl;
        for( int i = 0 ; i < 4 ; ++ i ) {
            xx = x , yy = y;
            for( int j = 0 ; j < k ; ++ j ) {
                xx = xx + dirx[i] , yy = yy + diry[i];
                int idd = getid( xx , yy );
                if( xx < 1 || yy < 1 || xx > n || yy > m || mm[idd] || ( vis[idd] && dis[getid( x , y )] + 1 > dis[idd]) ) break;
                else {
                    if( !vis[idd] ) Q.push( mp( xx , yy ) );
                    vis[idd] = 1 , dis[idd] = min( dis[idd] ,  dis[getid( x , y )] + 1 );
                }
            }
        }
    }
}

void solve() {
    cin >> n >> m >> k;
    cin >> sx >> sy >> xx >> yy;
    rep( i , 1 , n ) {
        scanf("%s",ch + 1);
        rep( j , 1 , m ) mm[getid( i , j )] = ( ch[j] == '@' ? 1 : 0 );
    }
    bfs( );
    if( dis[getid( xx , yy )] > 1e9 ) return puts("-1") , void();
    else printf("%d\n",dis[getid( xx , yy )]);
}

signed main() {
//    int T;cin >> T;while( T-- ) solve();
    solve();
}


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

using namespace std;
int n,m;

const int size=1e5+10;
vector<int> g[size];
int dp[size];

int path(int i){

  if(dp[i]) return dp[i];

  for(int &j:g[i]){
    dp[i]=max(dp[i],path(j)+1);
  }
  return dp[i];
}

int main(){

  scanf("%d %d",&n,&m);
  int x,y;

  for(int i=0;i<m;i++){
    scanf("%d %d",&x,&y);
    g[x].push_back(y);
  }
  
  int maxi=0;
  for(int i=1;i<=n;i++)
    maxi=max(maxi,path(i));

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

  return 0;
}


Measured memory_bytes: 7552
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
int now_grid[8][8] = {};
int simulation[8][8] = {};

int calc(pair<int, int> now,int coloring) {
	REP(i, 8) {
		REP(q, 8) {
			simulation[i][q] = now_grid[i][q];
 		}
	}
	int dx[3] = { 1,0,-1 };
	
	simulation[now.first][now.second] = coloring;
	int ans = 0;
	REP(i, 3) {
		REP(q, 3) {
			for (int t = 1; t < 9;++t) {
				int x = now.first + dx[i] * t;
				int y = now.second + dx[q] * t;
				if (x >= 0 && x < 8 && y >= 0 && y < 8) {
					if (simulation[x][y] != simulation[now.first][now.second]) {
						if (simulation[x][y] == -1) break;
					}
					else {
						for (int t = 1; t < 9; ++t) {
							int x = now.first + dx[i] * t;
							int y = now.second + dx[q] * t;
							if (simulation[x][y] == simulation[now.first][now.second]) break;
							simulation[x][y] = simulation[now.first][now.second];
							ans++;
						}
						break;
					}
				}
			}
		}
	}
	return ans;
}

void solve() {
	REP(i, 8) {
		string s;
		cin >> s;
		REP(q, s.length()) {
			if (s[q] == 'o') {
				now_grid[i][q] = 0;
			}
			else if (s[q] == 'x') {
				now_grid[i][q] = 1;
			}
			else {
				now_grid[i][q] = -1;
			}
		}
	}
	int cnter = 0;
	for (int i = 0;cnter != 2; ++i) {
		tuple<int, int, int> now = make_tuple(0, -1, -1);
		int color = i % 2;
		REP(i, 8) {
			REP(q, 8) {
				int x = i;
				int y = q;
				if (color == 1) {
					x = 7 - i;
					y = 7 - q;
				}
				if (now_grid[x][y] == -1) {
					if (get<0>(now) < calc(mp(x, y), color)) {
						now = make_tuple(calc(mp(x, y), color), x, y);
					}
				}
			}
		}
		if (get<0>(now) == 0) {
			cnter++;
			continue;
		}
		cnter = 0;
		calc(mp(get<1>(now), get<2>(now)), color);
		REP(i, 8) {
			REP(q, 8) {
				now_grid[i][q] = simulation[i][q];
			}
		}
	}
	REP(i, 8) {
		REP(q, 8) {
			if (now_grid[i][q] == 0) {
				cout << 'o';
			}
			else if(now_grid[i][q] == 1){
				cout << 'x';
			}
			else {
				cout << '.';
			}
		}
		cout << endl;
	}
}

#undef int
int main() {
	init();
	solve();
}


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

using namespace std;
using ll = long long;
using pint = pair<int, int>;

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

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;

		ans += (a - 1);
	}

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


Measured memory_bytes: 3592
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        double[] nk = Console.ReadLine().Split().Select(double.Parse).ToArray();
        double[] p = Console.ReadLine().Split().Select(double.Parse).ToArray();

        double ans = 0;
        //出目1-1000の期待値を求める
        double[] ex = new double[1001];
        ex[0] = 0;
        for (int i = 1; i <= 1000; i++)
        {
            double goukei = (1 + i) * i / 2;
            double heikin = goukei / i;
            ex[i] = heikin;
        }

        for (int i = 0; i < nk[1]; i++)
        {
            ans += ex[(int)p[i]];
        }

        double tmp2 = ans;

        for (int i = 0; i < nk[0] - nk[1]; i++)
        {
            tmp2 -= ex[(int)p[i]];
            tmp2 += ex[(int)p[i + (int)nk[1]]];
            ans = Math.Max(ans, tmp2);
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 33756
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

string YorN(bool P) { if (P)return "Yes"; else return "No"; }

int main() {

    int A, B;
    cin >> A >> B;
    
    cout << ((A%3==0||B%3==0||(A+B)%3==0)?"Possible":"Impossible") << endl;

    return 0;

}

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

void fnInput(vector<int> &rvnSort)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  
  rvnSort.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
    cin >> rvnSort[i];
}

void fnSelectionSort(vector<int> &rvnSort, int &rnSortCnt)
{
  for (int nSorting = 0; nSorting < rvnSort.size() - 1; nSorting++)
  {
    int nMin = nSorting;
    bool bSorting = false;

    for (int j = nSorting + 1; j < rvnSort.size(); j++)
    {
      if (rvnSort[j] < rvnSort[nMin])
      {
        nMin = j;
        bSorting = true;
      }
    }
    if (bSorting)
    {
      swap(rvnSort[nSorting], rvnSort[nMin]);
      rnSortCnt++;
    }
  }
}

void fnOutput(const vector<int> &cnrvnSort, int nSortCnt)
{
  for (int i = 0; i < cnrvnSort.size(); i++)
  {
    if (i) cout << " ";
    cout << cnrvnSort[i];
  }
  cout << endl;
  cout << nSortCnt << endl;
}

int main()
{ 
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int nSortCnt = 0;
  vector<int> vnSort;

  fnInput(vnSort);
  fnSelectionSort(vnSort, nSortCnt);
  fnOutput(vnSort, nSortCnt);

  return 0;
}

Measured memory_bytes: 3136