akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int a[55], b[55], n, dp[55][55]; long long cost = 0; vector<int>vec;

bool solve(int p) {
	for (int i = 1; i <= n; i++) {
		vector<int>vec2 = vec;
		for (int j = p; j >= 1; j--) vec2.push_back(j);

		for (int j = vec2.size() + 1; j >= 0; j--) {
			for (int k = 0; k <= a[i]; k++) dp[j][k] = 0;
		}
		int s = a[i]; dp[vec2.size()][a[i]] = 1;

		reverse(vec2.begin(), vec2.end());

		for (int j = vec2.size(); j >= 1; j--) {
			int G = vec2[j - 1];
			for (int k = 0; k <= s; k++) {
				if (dp[j][k] == 0) continue;
				dp[j - 1][k] = true;
				dp[j - 1][k%G] = true;
			}
		}
		if (dp[0][b[i]] == 0) return false;
	}
	return true;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	int V = 52;
	while (true) {
		int cnt = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] == b[i]) cnt++;
		}
		if (cnt == n) break;
		int s = -1;
		for (int i = 0; i <= V - 1; i++) {
			bool I = solve(i);
			if (I == true) { s = i; break; }
		}
		if (s == 0) break;
		if (s == -1) {
			cout << "-1" << endl;
			return 0;
		}
		cost += (1LL << s); vec.push_back(s);
		V = s;
	}
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int a,b,t ; cin >> a >> b >>t;
	int ans=0;
	for(int i=a;i<=t;i+=a){
		ans+=b;
	}
	cout << ans  << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N; cin >> N;
    string C; cin >> C;
    vector<int> R(N + 1);
    for (int i = 0; i < N; i++) {
        R[i + 1] = R[i] + (C[i] == 'R');
    }
    int ans = 1e9;
    for (int i = 0; i <= N; i++) {
        int w2r = i - R[i];
        int r2w = R[N] - R[i];
        ans = min(ans, max(w2r, r2w));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4340
#include <iostream>
#include <map>

template <class S, class T> inline void chmin(S& x, const T& y){ if(x > y) x = y; }

std::map<long long int, long long int> dp;
int a, b, c, d;

long long int solver(const long long int n, const int div, const int x);

long long int subsolve(long long int n){
    if(n <= 1) return n ? d : 0;
    if(const auto itr = dp.find(n); itr != dp.end()) return itr -> second;
    long long int res = INT64_MAX;
    if(n < INT64_MAX / d) chmin(res, n * d);
    chmin(res, solver(n, 2, a));
    chmin(res, solver(n, 3, b));
    chmin(res, solver(n, 5, c));
    return dp[n] = res;
}

long long int solver(const long long int n, const int div, const int x){
    const long long int p = n / div, q = n % div;
    if(!q) return subsolve(p) + x;
    const long long int koho1 = subsolve(p) + x + q * d;
    const long long int koho2 = subsolve(p + 1) + x + (div - q) * d;
    return (koho1 < koho2) ? koho1 : koho2;
}

void solve(void){
    dp.clear(); long long int n; std::cin >> n >> a >> b >> c >> d;
    std::cout << subsolve(n) << std::endl;
}

int main(void){
    std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
    unsigned int t; std::cin >> t;
    while(t--) solve();
    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

struct RUP{
    int n; vector<ll> dat,laz;
    RUP(){}
    RUP(int n_){init(n_);}
    void init(int n_){
        n=1; while(n<n_) n*=2;
        dat.clear(); dat.resize(2*n-1,INF);
        laz.clear(); laz.resize(2*n-1,-INF);
    }
    inline void eval(int len,int k){
        if(laz[k]==-INF) return;
        if(k*2+1<n*2-1)laz[k*2+1]=laz[k],laz[k*2+2]=laz[k];
        dat[k]=laz[k];laz[k]=-INF;
    }
    ll update(int a,int b,ll x,int k,int l,int r){
        eval(r-l,k);
        if(r<=a||b<=l) return dat[k];
        if(a<=l&&r<=b) return laz[k]=x;
        eval(r-l,k);
        dat[k]=min(update(a,b,x,k*2+1,l,(l+r)/2),
        update(a,b,x,k*2+2,(l+r)/2,r));
        return dat[k];
    }
    void update(int a,int b,ll x){update(a,b,x,0,0,n);}
    ll query(int a,int b,int k,int l,int r){
        eval(r-l,k);
        if(r<=a||b<=l) return INF;
        if(a<=l&&r<=b) return dat[k];
        return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
    ll query(int a,int b){return query(a,b,0,0,n);}
};

int main(){
    int n; scanf("%d",&n);
    vector<int> a(n);
    rep(i,0,n)scanf("%d",&a[i]);
    RUP seg(n);//max
    rep(i,0,n){
        seg.update(i,i+1,-a[i]);
    }
    ll ans=0,add;
    int l[2],r[2],lb,rb,mid;//l0.l1.r0.r1
    rep(i,0,n){ add=1;
        lb=-1,rb=i;
        while(rb-lb>1){
            mid=(lb+rb)/2;
            if(seg.query(mid,i+1)<-a[i])lb=mid;
            else rb=mid;
        }
        l[1]=lb;
        lb=-1; rb=l[1];
        while(rb-lb>1){
            mid=(lb+rb)/2;
            if(seg.query(mid,l[1])<-a[i])lb=mid;
            else rb=mid;
        }
        l[0]=lb;
        lb=i,rb=n;
        while(rb-lb>1){
            mid=(lb+rb)/2;
            if(seg.query(i+1,mid+1)<-a[i])rb=mid;
            else lb=mid;
        }
        r[0]=rb;
        lb=r[0],rb=n;
        while(rb-lb>1){
            mid=(lb+rb)/2;
            if(seg.query(r[0]+1,mid+1)<-a[i])rb=mid;
            else lb=mid;
        }
        r[1]=rb;
        cerr<<l[0]<<l[1]<<r[0]<<r[1]<<endl;
        if(l[0]==l[1]&&r[0]==r[1])continue;
        add+=(l[1]-l[0])*(r[0]-i);
        add+=(i-l[1])*(r[1]-r[0]);
        add--;ans+=a[i]*add;
        cerr<<add<<endl;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4736
// ABC139-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    ll n;
    cin>>n;
    cout<<(n-1)*n/2<<endl;
    return 0;
}

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

public class Main {
    static ArrayList<Integer>adj[];
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int a =sc.nextInt();
        int b = sc.nextInt();
        int c= sc.nextInt();
        int diff = a-b;
        pw.println(Math.max(c-diff,0));
        pw.flush();
    }
    static int max;
    static int start;
    static class SufT{
        static class Node{Node[]nxt= new Node[26];int val=0;int dis=0;};
        Node root= new Node();
        void put(char[]s){
            Node cur = root;
            for (char c:s){
                Node nxt=cur.nxt[c-'a'];
                if (nxt==null){
                    nxt=cur.nxt[c-'a']= new Node();
                    nxt.dis=cur.dis+1;
                }
                cur=nxt;
                cur.val++;
            }
        }
        void search(){
            Queue<Node>q= new LinkedList<>();
            ((LinkedList<Node>) q).add(root);
//            boolean[][]vis= new boolean[26][200];
            while (!q.isEmpty()) {
                Node x = q.poll();
                for (int i =0;i<26;i++){
                    Node nxt=x.nxt[i];
                    if (nxt!=null){
                        ((LinkedList<Node>) q).add(nxt);
//                        vis[i][nxt.dis]=true;
                    }
                }
                if (x.val>=3){
                    max=x.val;
                    start=Math.max(start,x.dis);
                }
            }
        }
    }

    static long modPow(long a ,int e ,int mod){
        a%=mod;
        long res=1;
        while (e>0){
            if ((e%2)==1){
                res=(res*a)%mod;
            }
            a=(a*a)%mod;
            e>>=1;
        }
        return res%mod;
    }
    static class Scanner{
        StringTokenizer st;
        BufferedReader br;
        public  Scanner(InputStream s){
            br = new BufferedReader(new InputStreamReader(s));
        }
        public String next() throws IOException{
            while (st==null||!st.hasMoreTokens())st= new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        public String nextLine() throws IOException {return br.readLine();};
        public int nextInt() throws IOException {return Integer.parseInt(next());}
        public long nextLong() throws IOException {return Long.parseLong(next());}

    }
}


Measured memory_bytes: 21204
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String sList = sc.next();
        sc.close();
        String r = "";
        for (char s : sList.toCharArray()) {
            s += n;
            if ('Z' < s) {
                s -= 26;
            }
            r += (char) s;
        }
        System.out.println(r);
    }
}


Measured memory_bytes: 149460
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
	int c[5];
	while( scanf("%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4]) != EOF){
		map<int, int> card;
		int mex = 0;
		for(int i=0;i<5;i++){
			card[ c[i] ]++;
			mex = max( mex, card[ c[i] ] );
		}
		bool full = true;
		bool A = false, B = false;
		for(int i=0;i<5;i++){
			if(c[i]==1) A = true;
			if(c[i]==13) B = true;
		}
		if( A && B ){
			for(int i=0;i<5;i++){
				if(c[i]==1) c[i]=14;
			}
		}
		sort(c, c+5);
		for(int i=0;i<4;i++){
			if(c[i]+1 != c[i+1]) full = false;
		}
		
		// 判定
		if( mex == 4){
			cout<<"four card"<<endl;
		}else if( mex==3 && card.size()==2 ){
			cout<<"full house"<<endl;
		}else if( full ){
			cout<<"straight"<<endl;
		}else if( mex==3){
			cout<<"three card"<<endl;
		}else if( card.size()==3 ){
			cout<<"two pair"<<endl;
		}else if( mex==2 ){
			cout<<"one pair"<<endl;
		}else{
			cout<<"null"<<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 1220
N=int(input())
L=[1]
now=6
while now<=10**6:
    L.append(now)
    now*=6
now=9
while now<=10**6:
    L.append(now)
    now*=9
#print(L)
dp=[float("INF")]*(N+1)
dp[0]=0
for i in range(1,N+1):
    for x in L:
        if i-x>=0:
            dp[i]=min(dp[i], dp[i-x]+1)
print(dp[N])
#print(dp)

Measured memory_bytes: 74664
#include<stdio.h>
int main ()
{
    int x1,x2,x3,x4,x5;
    scanf ("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
        if (x1==0)
        printf ("1\n");
        if (x2==0)
        printf ("2\n");
        if (x3==0)
        printf ("3\n");
        if (x4==0)
        printf ("4\n");
        if (x5==0)
        printf ("5\n");
    return 0;
}


Measured memory_bytes: 1608
local mfl = math.floor
local n = io.read("*n", "*l")
local s = io.read()
local tot = 1
for i = 1, n do
  tot = tot * 2
end
local first_str_by_ruse = {}
for i = 0, n do
  first_str_by_ruse[i] = {}
end
for i = 0, tot - 1 do
  local left = 1
  local right = n
  local t = {}
  for j = 1, n do
    t[j] = 0
  end
  local ruse = 0
  for j = 1, n do
    if i % 2 == 0 then
      t[left] = s:sub(j, j)
      ruse = ruse + 1
      left = left + 1
    else
      t[right] = s:sub(j, j)
      right = right - 1
    end
    i = mfl(i / 2)
  end
  local str = table.concat(t)
  if first_str_by_ruse[ruse][str] then
    first_str_by_ruse[ruse][str] = first_str_by_ruse[ruse][str] + 1
  else
    first_str_by_ruse[ruse][str] = 1
  end
end
local ret = 0
for i = 0, tot - 1 do
  local left = 1
  local right = n
  local t = {}
  for j = 1, n do
    t[j] = 0
  end
  local ruse = 0
  for j = n, 1, -1 do
    if i % 2 == 0 then
      t[left] = s:sub(j + n, j + n)
      ruse = ruse + 1
      left = left + 1
    else
      t[right] = s:sub(j + n, j + n)
      right = right - 1
    end
    i = mfl(i / 2)
  end
  local str = table.concat(t)
  if first_str_by_ruse[ruse][str] then
    ret = ret + first_str_by_ruse[ruse][str]
  end
end
print(ret)


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

int main(void){
  string s;
  cin >> s;
  int y = stoi(s.substr(0,4));
  if(y <= 2018){
    cout << "Heisei" << endl;
  }else if(y >= 2020){
    cout << "TBD" << endl;
  }else{
    int a = stoi(s.substr(5,1))*10+stoi(s.substr(6,1));
    if(a <= 4){
      cout << "Heisei" << endl;	 
    }else{
      cout << "TBD" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int s,ST[1000];

void push(int x){
  ST[++s]=x;
}
int sreturn(){
  s--;
  return ST[s+1];

}

int main(){
  int x,y;
  s=0;
  char t[100];

  while((scanf("%s",t)) != EOF){

    if(t[0]=='+'){
        x=sreturn();
        y=sreturn();
        push(x+y);
      }
      else if(t[0]=='-'){
        y=sreturn();
        x=sreturn();
        push(x-y);
      }
      else if(t[0]=='*'){
        x=sreturn();
        y=sreturn();
        push(x*y);
      }
      else {
        push(atoi(t));
      }
    }
  printf("%d\n",sreturn());
  return 0;
}




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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    return 100 * (m*19 + n-m) * 2**m


print(main())




Measured memory_bytes: 6092
#include <iostream>
using namespace std;
int main() {
  int i;
    string  str,str1;
    getline(cin,str);
    getline(cin,str1);
    if((str.length()+1)==str1.length())
    {
        for(i=0;i<str.length();i++)
        {
            if(str[i]!=str1[i])
                break;
        }
        if(i==str.length())
          cout<<"Yes";
        else
          cout<<"No";
    }
    else  
      cout<<"No";
    return 0;
}


Measured memory_bytes: 3624
/*
	LINES :
		* a nice cumulative sum problem
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define OJ
#define pb push_back
#define F first
#define S second
#define WLL(t) while(t--)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define VFOR(i,a,b) for(int i = a; i >= b; i--)
#define ALL(v) v.begin(),v.end()
#define PRECISION(x) cout<<fixed<<setprecision(x)
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define MOD 1000000007

void solve(int arr[], int n, ll sum);
int main()
{
#ifndef OJ
	READ;
	WRITE;
#endif

	FASTIO;
	int n{};
	ll sum{};
	cin >> n;
	int arr[n];
	FOR(i, 0, n) {
		cin >> arr[i];
		sum += arr[i];
		sum %= MOD;
	}
	solve(arr, n, sum);
	return 0;
}
void solve(int arr[], int n, ll sum)
{
	//doing cumulative sum
	ll cusum{};
	FOR(i, 0, n) {
		sum -= arr[i];
		if (sum < 0)
		{
			sum += MOD;
		}
		cusum += arr[i] * sum;
		cusum %= MOD;
	}
	cout << cusum << "\n";
}

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
    int n;
    cin >> n;
    vi X(n), Y(n), H(n);
    rep(i, n) cin >> X[i] >> Y[i] >> H[i];

    auto check = [&](int x, int y, int h) {
        rep(i, n) {
            if (H[i] != max(0, h - abs(x - X[i]) - abs(y - Y[i]))) return false;
        }
        return true;
    };
    rep(y, 101) rep(x, 101) rep(i, n) {
        ll h = H[i] + abs(y - Y[i]) + abs(x - X[i]);
        bool f = true;
        rep(j, n) {
            if(!check(x, y, h)) {
                f = false;
                break;
            }
        }
        if(f) {
            cout << x << " " << y << " " << h << endl;
            return 0;
        }
    }
    return 0;
}

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;

bool check(string s)
{
   int k = s.size()/2;
   for(int i = 0; i <k; i++)
   {
      if(s[i] != s[i+k])
         return false;
   }
   return true;
}
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   string s; cin >> s;
   int n = s.size();
   for(int i = 0; i < n; i--)
   {
      s.pop_back();
      if(s.size()%2)
         continue;
      else
      {
         if(check(s))
         {
            cout << s.size() << nl;
            return 0;
         }
      }
   }
}


Measured memory_bytes: 3608
from collections import Counter
s = input()

s = s[::-1]

x = 1
mod = 2019
total = 0
ans = 0
cnt = Counter()

for i in range(len(s)):
    cnt[total] += 1
    total = total + int(s[i])*x
    total %= mod
    ans += cnt[total]
    x = x*10%mod

print(ans)

Measured memory_bytes: 9712
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 1000004
typedef long long ll;
int main(){
    ll N;
    ll prime_index=0;
    ll prime_seq[MAX]={0};
    bool prime_flag[MAX];    //素数ならtrue;
    for(ll i=2;i<MAX;i++) prime_flag[i]=true;
    scanf("%lld",&N);
    //素数列作るよ
    for(ll i=2;i<MAX;i++){
        if(!prime_flag[i]) continue;
        for(ll j=2;i*j<MAX;j++)
            prime_flag[i*j]=false;
    }
    for(ll i=2;i<MAX;i++)
        if(prime_flag[i]) prime_seq[prime_index++]=i;
    //素数列作り終わったよ
    prime_index--;
    for(int i=0;i<prime_index;i++){
        if(N%prime_seq[i]!=0){
            break;
        }
    }
    ll ans=0;
    //素因数分解始まるよ
    ll prime_fac[MAX]={0};
    bool f=false;
    while(N!=1){
        ll i=0;
        while(N%prime_seq[i]!=0 && prime_index>i)i++;
        if(prime_index<=i){
            ans++;
            break;
        }
        N/=prime_seq[i];
        prime_fac[prime_seq[i]]++;
        f=true;
    }
    //素因数分解終わったよ

    //総和のテーブル作るよ
    ll table[100];
    table[1]=1;
    for(ll i=2;i<=100;i++)
        table[i]=table[i-1]+i;
    //総和のテーブル作り終わったよ
    for(ll i=0;i<prime_index;i++){
        if(!prime_fac[prime_seq[i]]) continue;
        ll j=1;
        while(table[j]<=prime_fac[prime_seq[i]]) j++;
        j--;
        ans+=j;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 18336
#include <bits/stdc++.h>
    using namespace std;
 
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define mod 1000000007
    #define qmod 998244353
    #define M 1000001
    #define endl "\n"
    #define all(a) (a).begin(),(a).end()
    #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 F first
    #define S second
    #define pb push_back
    #define mp make_pair

    typedef long long ll;
    typedef pair<int,int> pii;
    typedef vector<int> vi;
    typedef vector<string> vs;
    typedef vector<pii> vii;
    typedef vector<vi> vvi; 

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

    ll modInverse(ll n){ 
        return power(n,mod-2); 
    } 

    ll ncr(ll n,ll r){
        ll num=1,den=1;
        while(r>0){
            num=(num*n)%mod;
            den=(den*r)%mod;
            n--;
            r--;
        }
        den=modInverse(den);
        return (num*den)%mod;
    }

    int main(){
        
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin); 
    freopen("output.txt","w",stdout);   
    #endif  */
 
        fast;
        ll n,a,b;
        cin>>n>>a>>b;
        ll total=power(2,n)-1;//cout<<ncr(n,a)<<" "<<ncr(n,b);
        total-=ncr(n,a);
        total-=ncr(n,b);
        total=total%mod;
        if(total<0) total+=mod;
        cout<<total<<endl;
        return 0;  
    } 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef struct{
  int A[1000];
}node;
node T[105];
int main(){
  int n;
  int num;
  int son;
  int z;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>num;
    cin>>son;
    for(int j=0;j<son;j++){
      cin>>z;
      T[num].A[z]=1;
      }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(j==1)cout<<T[i].A[j];
      else cout<<" "<<T[i].A[j];
    }
    cout<<endl;
  }
  return 0;
}

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

typedef long long ll;

int ans[100001];
vector<int> v[100001];
/*
void bfs (int idx, int depth) {
	if (ans[idx] != -1)
		return;
	ans[idx] = depth;
	for (int i=0; i<v[idx].size(); i++)
		dfs (v[idx][i], depth+1);
}
*/
int main () {
	int N;
	int M;
	cin >> N >> M;
	for (int i=1; i<=N; i++)
		ans[i] = -1;
	for (int i=0; i<M; i++) {
		int A, B;
		cin >> A >> B;
		v[A].push_back (B);
		v[B].push_back (A);
	}
	queue< pair<int, int> > que;
	que.push( make_pair(1,0));
	while (!que.empty()) {
		pair<int,int> p = que.front();
		que.pop();
		if (ans[p.first] != -1)
			continue;
		ans[p.first] = p.second;
		for (int i=0; i<v[p.first].size(); i++)
			que.push (make_pair (v[p.first][i], p.first));
	}
	cout << "Yes" << endl;
	for (int i=2; i<=N; i++)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 12276
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	x := make([]int, m)
	for i := range x {
		fmt.Scan(&x[i])
	}
	fmt.Println(stream(n, m, x))
}

func stream(n, m int, x []int) int {
	sort.Ints(x)
	var d []int
	for i := range x {
		if i+1 == len(x) {
			continue
		}
		d = append(d, x[i+1]-x[i])
	}
	sort.Ints(d)
	var t int
	for i := range d {
		if i+1 > len(d)-(n-1) {
			continue
		}
		t += d[i]
	}
	return t
}


Measured memory_bytes: 6272
#include <cstdio>
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

const int NIL = 2001;
const int MAX = 100;
int G[MAX][MAX];
int color[MAX];
int W[MAX];
int n;

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

void MST() {
	priority_queue<pair<int, int>> PQ;
	PQ.push(make_pair(0, 0));
	W[0] = 0;
	color[0] = BLACK;
	while (!PQ.empty()) {
		int u = PQ.top().second;
		PQ.pop();
		color[u] = BLACK;
		for (int i = 0; i < n; ++i) {
			if (G[u][i] != -1 && G[u][i] < W[i] && color[i] != BLACK) {
				PQ.push(make_pair(G[u][i] * -1, i));
				W[i] = G[u][i];
//				cout << u << ":" << i << ":" << G[u][i] << endl;
			}
		}
	}
}

int main() {

	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		W[i] = NIL;
		color[i] = WHITE;
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			int a;
			scanf("%d", &a);
			G[i][j] = a;
		}
	}

	MST();

	int sum = 0;
	for (int i = 0; i < n; ++i) {
//		cout << i << ":" << W[i] << endl;
		sum += W[i];
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3180
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);
	static boolean flag = false;

	public static void main(String[] args){
		
		int n = scan.nextInt();
		int[] d = new int[6];
		Dice[] dices = new Dice[n];

		
		for(int i = 0; i < n ; i++){
			for(int j = 0; j < 6; j++){
				d[j] = scan.nextInt();
			}
			dices[i] = new Dice(d);
		}

		boolean ans = true;
		for(int i = 0; ans && i < n; i++){
			for(int j = i + 1; j < n; j++){
				if(dices[i].equals(dices[j])){
					ans = false;
					break;
				}
			}
		}
		System.out.println(ans? "Yes" : "No");
	}
}

class Dice{

	int[] _d = new int[6];
	public static final int
		TOP = 0, SOUTH = 1, EAST = 2,
		WEST = 3, NORTH = 4, BOTTOM = 5; // ?????°

	public Dice(int[] d){ // ?????????????????????
		for(int i = 0; i < 6; i++){
			_d[i] = d[i];
		}
	}

	public int[] showAll(){
		return _d;
	}

	@Override
	public boolean equals(Object obj){
		boolean result = false;
		Dice dice = (Dice) obj;
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 4; j++){
				if(Arrays.equals(showAll(), dice.showAll())){
					result = true;
					break;
				}
				dice.rollEast();
			}
			for(int j = 0; j < 4; j++){
				if(Arrays.equals(showAll(), dice.showAll())){
					result = true;
					break;
				}
				dice.rollNorth();
			}
			if(Arrays.equals(showAll(), dice.showAll())){
				result = true;
				break;
			}
			dice.rollRight();
		}
		return result;
	}

	public void rollSouth(){
		int tmp = _d[TOP];
		_d[TOP] = _d[NORTH];
		_d[NORTH] = _d[BOTTOM];
		_d[BOTTOM] = _d[SOUTH];
		_d[SOUTH] = tmp;
	}

	public void rollNorth(){
		int tmp = _d[TOP];
		_d[TOP] = _d[SOUTH];
		_d[SOUTH] = _d[BOTTOM];
		_d[BOTTOM] = _d[NORTH];
		_d[NORTH] = tmp;
	}

	public void rollEast(){
		int tmp = _d[TOP];
		_d[TOP] = _d[WEST];
		_d[WEST] = _d[BOTTOM];
		_d[BOTTOM] = _d[EAST];
		_d[EAST] = tmp;
	}

	public void rollWest(){
		int tmp = _d[TOP];
		_d[TOP] = _d[EAST];
		_d[EAST] = _d[BOTTOM];
		_d[BOTTOM] = _d[WEST];
		_d[WEST] = tmp;
	}

	public void rollRight(){
		int tmp = _d[SOUTH];
		_d[SOUTH] = _d[WEST];
		_d[WEST] = _d[NORTH];
		_d[NORTH] = _d[EAST];
		_d[EAST] = tmp;
	}
}

Measured memory_bytes: 29416
#include <bits/stdc++.h>
using namespace std;
void push(int);
int pop(void);

int stack_array[100];
int top=0;

char Str[100];

int main(){
  int x,y,top;
  char str[100];
  while(scanf("%s",str)!=EOF){
    if(str[0] == '+'){
      x = pop();
      y = pop();
      push(x + y);
    }else if(str[0] == '-'){
      y = pop();
      x = pop();
      push(x - y);
    }else if(str[0] == '*'){
      x = pop();
      y = pop();
      push(x * y);
    }else{
      push(atoi(str));
    }
  }

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

  return 0;
}

void push(int x){
  stack_array[top] = x;
  top++;
}

int pop(){
  top--;
  return stack_array[top];
}

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

using namespace std;

int w[100002], v[100002];
long long dp[102][100002];

long long go(int pos, int W) {
    if(W < 0) return -(1 << 30); /// minus infinity
    if(pos < 0) return 0;

    if(dp[pos][W] != -1) return dp[pos][W];

    return dp[pos][W] = max(go(pos - 1, W), 1LL * v[pos] + go(pos - 1, W - w[pos]));
}

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

    int n, W;
    cin >> n >> W;

    for(int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    memset(dp, -1, sizeof dp);

    cout << go(n - 1, W) << endl;
}

/**
 * Knapsack 1
 */

Measured memory_bytes: 80256
def acinput():
    s=input()
    if len(s)==0:
        return False

    return list(map(int,s.split(" ")))
    

def search(x):
    global g,N,nodenum
    queue=[(x,1)]
    wnum=2
    nodenum=[-1]*N
    nodenum[x]=1
    visited=[0]*N
    while True:
        nqueue=[]
        for node,k in queue:
            for snode in g[node]:
                if nodenum[snode]<0:                    
                    nodenum[snode]=wnum
                    nqueue.append((snode,wnum))
                else:
                    if (not visited[snode]) and nodenum[snode]!=wnum:
                        return -1
            visited[node]=1

        queue=nqueue
        if len(queue)==0:
            return wnum-1
        wnum+=1
        
        

N=int(input())

g=[[] for i in range(N)]
for i in range(N):
    s=list(input())
    for j in range(len(s)):
        if s[j]=="1":
            g[i].append(j)

res=-1
for i in range(N):
    res=max(res,search(i))

print(res)


Measured memory_bytes: 3444
//b.c B-Cakes and Donuts
#include<stdio.h>
#include<stdbool.h>

int main(void){
    int n;
    bool flag = false;
    scanf("%d",&n);
    for(int i=0;i<=25;++i){
        for(int j=0;j<15;++j){
            if(n==4*i+7*j){
                flag = true;
            }
        }
    }
    if(flag){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    string s;
    cin>>s;
    ll k;
    cin>>k;
    ll n = s.size();
    vector<vector<vector<ll> > > dp(n,vector<vector<ll> >(k+1,vector<ll>(2,0) ) );
    for(int i=1;i<n;i++)dp[i][1][0]=9;
    dp[0][1][0] = (s[0]-'0')-1;
    dp[0][1][1] = 1;
    for(int i=1;i<n;i++){
	if( s[i] =='0' ){
	    for(int j=1;j<=k;j++){
		dp[i][j][1] +=dp[i-1][j][1];
	    }
	    for(int j=1;j<=k;j++){
		dp[i][j][0] += dp[i-1][j-1][0]*9 + dp[i-1][j][0];
	    }
	}else{
	    for(int j=1;j<=k;j++){
		dp[i][j][1] +=dp[i-1][j-1][1];
	    }
	    for(int j=1;j<=k;j++){
		dp[i][j][0] += dp[i-1][j-1][0]*9 + dp[i-1][j][0] + dp[i-1][j-1][1]* ((s[i]-'0')-1) + dp[i-1][j][1];
	    }
	}
    }
    ll res = 0;
  //  cout<<dp[n-1][k][0]<<' '<<dp[n-1][k][1]<<endl;
    //for(ll i=0;i<=k;i++)
	res += dp[n-1][k][0] + dp[n-1][k][1];
    cout<<res<<endl;
    return 0;
}


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

using namespace std;

long long gcd(long long a, long long b) {
    long long maxv = max(a, b);
    long long minv = min(a, b);

    long long res = maxv % minv;

    if(res == 0) return minv;
    else return gcd(res, minv);
}

int main() {
    int N;
    cin >> N;
    vector<long long> v(N);
    for(int i = 0; i < N; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    if(v.size() == 2) {
        cout << max(v[0], v[1]) << endl;
        return 0;
    }

    long long a = gcd(v[0], v[1]);
    long long b = gcd(v[0], v[2]);
    long long c = gcd(v[1], v[2]);

    long long maxv = max({a,b,c});
    for(int i = maxv; i > 0; i--) {
        int count = 0;
        for(int j = 0; j < N; j++) {
            if(v[j] % i != 0) count++;
            if(count >= 2) break;
        }
        if(count <= 1) {
            cout << i << endl;
            break;
        }
    }

    return 0;


}

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

using namespace std;

typedef long long ll;

int main() {

    ll n;
    cin >> n;
    vector<ll>v;
    map<ll, ll>m;

    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        m[x]++;
        if(m[x] == 1) {
            v.push_back(x);
        }
    }

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

    ll mx = 1e6+5;

    vector<bool>ans(mx, true);

    for (ll i = 0; i < v.size(); i++) {
        ll g = v[i];
        if(ans[g]) {
            for (ll j = g + g; j <= mx; j = j + g) {
                ans[j] = false;
            }
        }
    }

    ll c = 0;
    for (ll i = 0; i < v.size(); i++) {
        if(ans[v[i]]) {
            if(m[v[i]] == 1) {
                c++;
            }
        }
    }

    cout << c << endl;
    return 0;
}


Measured memory_bytes: 17380
s = gets.chomp.split("")
flag = 1

flag = 0 if s.length % 2 == 1

if flag == 1
  for i in 0..(s.length/2-1)
    if [s[i*2], s[i*2+1]].join != "hi"
      flag = 0
      break
    end
  end
end
(flag == 1) ? (puts "Yes"):(puts "No")

Measured memory_bytes: 1788
<?php

fscanf(STDIN, "%d %d", $n, $k);
$ds = explode(' ', fgets(STDIN));
$d = [];
for ($i = 0; $i < count($ds); $i++) {
	$d[(int)$ds[$i]] = true;
}

$continue = false;
for ($i = 1; $i < 100000; $i++) {
	if ($i < $n) {
		continue;
	}
	$str = (string)$i;
	for ($j = 0; $j < strlen($str); $j++) {
		if (isset($d[$str[$j]])) {
			$continue = true;
			break;
		}
	}
	if ($continue) {
		$continue = false;
		continue;
	}
	break;
}

echo $i, "\n";

Measured memory_bytes: 4604
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  first := nextInt()
  second := nextInt()
  third := nextInt()
  if first <= second && second <= third{
    fmt.Println(strconv.Itoa(first) + " " + strconv.Itoa(second) + " " + strconv.Itoa(third))
  } else if first <= third && third <= second {
    fmt.Println(strconv.Itoa(first) + " " + strconv.Itoa(third) + " " + strconv.Itoa(second))
  } else if second <= first && first <= third {
    fmt.Println(strconv.Itoa(second) + " " + strconv.Itoa(first) + " " + strconv.Itoa(third))
  } else if second <= third && third <= first {
    fmt.Println(strconv.Itoa(second) + " " + strconv.Itoa(third) + " " + strconv.Itoa(first))
  } else if third <= second && second <= first {
    fmt.Println(strconv.Itoa(third) + " " + strconv.Itoa(second) + " " + strconv.Itoa(first))
  } else if third <= first && first <= second {
    fmt.Println(strconv.Itoa(third) + " " + strconv.Itoa(first) + " " + strconv.Itoa(second))
  }
}


func nextInt() (int) {
    sc.Scan()
    v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
  return  v
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

int popcnt(int n, int now){
  if(n == 0)
    return now;
  bitset<32> s(n);
  int cnt = 0;
  rep(i, 0, 32){
    if(s.test(i))
      cnt++;
  }
  n = n%cnt;
  return popcnt(n, now+1);
}

int main(){
  int n;
  string x;
  cin >> n >> x;
  
  int cnt = 0;
  
  rep(i, 0, n){
    if(x[i] == '1')
      cnt++;
  }
  
  int modxm1[n], modxp1[n];
  modxm1[0] = 1;
  modxp1[0] = 1;
  
  rep(i, 1, n){
    if(cnt != 1)
      modxm1[i] = (modxm1[i-1] * 2) %(cnt-1);
    modxp1[i] = (modxp1[i-1] * 2) %(cnt+1);
  }
  
  int sm = 0, sp = 0;
  
  rep(i, 0, n){
    if(x[n-i-1] == '1'){
      if(cnt != 1)
        sm = (sm + modxm1[i]) %(cnt-1);
      sp = (sp + modxp1[i]) %(cnt+1);
    }
  }
  
  rep(i, 0, n){
    int y = n-i-1;
    int sum;
    if(x[i] == '1'){
      if(cnt == 1){
        cout << 0 << endl;
        continue;
      }
      sum = sm;
      sum = (sum - modxm1[y]) %(cnt-1);
      if(sum < 0)
        sum += (cnt-1);
    }
    else{
      sum = sp;
      sum = (sum + modxp1[y]) %(cnt+1);
    }
    int ans = 1;
    ans = popcnt(sum, ans);
    
    cout << ans << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 5240
<?php
$size_list = array(0.25,0.5,1,2);
$price_array = explode(" ", trim(fgets(STDIN)));
$n = trim(fgets(STDIN));

$price_weight[0] = $price_array[0] * 4;
$price_weight[1] = $price_array[1] * 2;
$price_weight[2] = $price_array[2]; 
$price_weight[3] = $price_array[3] / 2;

if ( asort($price_weight) === FALSE ) {
	// ソート失敗したらどうしようもないｗ
	echo "1";
	return 0;
}

$purchase_price = 0;
while ( $n > 0 ) {
	foreach ( $price_weight as $size => $value ) {
		$tmp = intval(floor($n / $size_list[$size]));
		$purchase_price += $price_array[$size] * $tmp;
		$n -= $size_list[$size] * $tmp;
		
		// ちょうどかどうかチェック
		if ( $n == 0 ) {
			break;
		}
	}
}

echo $purchase_price.PHP_EOL;


Measured memory_bytes: 4604
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);


using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
const int M = 1e6 + 500;

void solve()
{
    lli k, x;
    cin>>k>>x;
    lli l = x - k + 1, r = x + k - 1;
    for(int i = l; i <= r; i ++)
        cout<<i<<' ';
    return ;
}
/*
10
6
10 3 2 5 7 8
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

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


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

typedef long long ll;

double func(ll n){
	ll tmp=n, sum=0;
	while(tmp!=0){
		sum+=tmp%10;
		tmp/=10;
	}
	return (double)n/sum;
}

ll sunuke(ll N){//n以上の最小のすぬけ数
	ll n=N+(9-N%10);
	ll ans=n;
	double value=func(n);
	ll mul=100;
	while(n<=10*N){
		if(n%mul==mul-1){
			mul*=10;
			continue;
		}
		n+=mul/10;
		if(value>func(n)){
			value=func(n);
			ans=n;
		}
	}
	return ans;
}

int main()
{
    ll K;
	cin >> K;
	for(int i=1; i<min(K, (ll)10); i++){
		cout << i << endl;
	}
	if(K>=10){
		ll ans=9;
		for(int i=9; i<K; i++){
			ans=sunuke(ans+1);
			cout << ans << endl;
		}
	}
	

    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct node{
	string s;
	int score;
	bool operator < (const node& b){
		if(s!=b.s){
			return s<b.s;
		}
		return score>b.score;
	}
	int th;
};
node a[150];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin>>a[i].s>>a[i].score;
		a[i].th=i+1;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		printf("%d\n",a[i].th);
	}
	return 0;
}


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


int n,r;
main(){
	int i,j,p,c;
	while(cin >> n >> r, n){
		int ans;
		int Deck[51];
		for(i=1;i<=n;i++) Deck[i] = i;
		for(j=1;j<=r;j++){
			cin >> p >> c;
			for(i=1;i<=n;i++){
				if(Deck[i] < p) Deck[i] += c;
				else if(Deck[i] < p+c) Deck[i] -= p-1;
			}
		}
		for(i=1;i<=n;i++){
			if(Deck[i] == 1) break;
		}
		cout << n-i+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
from collections import deque

H, W, K = map(int, input().split())
sx, sy, tx, ty = map(lambda a: int(a) - 1, input().split())
INF = 10**18

A = [input() for _ in range(H)]

minDist = [[INF] * W for _ in range(H)]
minDist[sx][sy] = 0
que = deque([(0, sx, sy)])

while que:
    dist, nx, ny = que.popleft()

    for i in range(1, K + 1):
        if nx + i >= H:
            break
        if minDist[nx + i][ny] <= dist or A[nx + i][ny] == '@':
            break
        if minDist[nx + i][ny] > dist + 1:
            minDist[nx + i][ny] = dist + 1
            que.append((dist + 1, nx + i, ny))
    for i in range(1, K + 1):
        if nx - i < 0:
            break
        if minDist[nx - i][ny] <= dist or A[nx - i][ny] == '@':
            break
        if minDist[nx - i][ny] > dist + 1:
            minDist[nx - i][ny] = dist + 1
            que.append((dist + 1, nx - i, ny))
    for i in range(1, K + 1):
        if ny + i >= W:
            break
        if minDist[nx][ny + i] <= dist or A[nx][ny + i] == '@':
            break
        if minDist[nx][ny + i] > dist + 1:
            minDist[nx][ny + i] = dist + 1
            que.append((dist + 1, nx, ny + i))
    for i in range(1, K + 1):
        if ny - i < 0:
            break
        if minDist[nx][ny - i] <= dist or A[nx][ny - i] == '@':
            break
        if minDist[nx][ny - i] > dist + 1:
            minDist[nx][ny - i] = dist + 1
            que.append((dist + 1, nx, ny - i))

ans = minDist[tx][ty]
print(ans if ans < INF else -1)


Measured memory_bytes: 38472
#include<iostream>
#include<vector>

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=(j);i<=(k);i++)
#define fs first
#define sc second
#define pb push_back
#define in(i,j,k) (i<=j&&j<=k)
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

int w,h;
int bd[20][20];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int dfs(int cnt, pii p){
	if(cnt>10) return cnt;
	int ret = 11;
	rep(i,4){
		bool c = false;
		int x = p.sc, y = p.fs;
		if(in(0,x+dx[i],w-1)&&in(0,y+dy[i],h-1)&&bd[y+dy[i]][x+dx[i]]==1)continue;
		while(!c && in(0,x+dx[i],w-1) && in(0,y+dy[i],h-1)){
			switch(bd[y+dy[i]][x+dx[i]]){
			case 0:
				x+=dx[i];y+=dy[i];break;
			case 1:
				c = true;break;
			case 3:
				return cnt+1;
			default:break;
			}
		}
		if(c){
			bd[y+dy[i]][x+dx[i]] = 0;
			ret = min(dfs(cnt+1, pii(y,x)), ret);
			bd[y+dy[i]][x+dx[i]] = 1;
		}
	}
	return ret;
}

int main(){
	while(cin >> w >> h){
		if(!w)break;
		pii s,g;
		rep(i,h)rep(j,w){
			cin >> bd[i][j];
			if(bd[i][j]==2){
				s = pii(i,j);
				bd[i][j]=0;
			}
			//if(bd[i][j]==3) g = pii(i,j);
		}
		int ans = dfs(0,s);
		if(ans>10) ans = -1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
/*
bool prime[10000001];
void Sieve(long int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    memset(prime, true, sizeof(prime));

    for (long int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (long int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}*/
int main()
{
    long long int a,b;
       cin>>a>>b;

     /*
       Sieve(10000001);
       */

       long long int x=a > b ? b : a;
        long long int y=a > b ? a : b;


          long int count=1;

           for(int i=2;i<=sqrt(x);i++)
           {
             bool p=false;
                 if(a % i ==0)
                 {
                      p=true;
                      while(a % i==0)
                      a=a/i;
                 }

                  if(b % i ==0)
                  {
                     if(p)
                        count++;

                       while(b % i==0)
                        b=b/i;
                  }
           }
          if((a!=1 && b!=1) && (a % b==0 || b % a ==0))
           count++;

      cout<<count;
}


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

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<vector<bool>> G(N, vector<bool>(N));
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a][b] = G[b][a] = true;
  }
  vector<int> perm(N);
  REP(i, N) perm[i] = i;
  auto is_ok = [&]() -> bool {
    int v = perm[0];
    if (v != 0) return false;
    for (int j = 1; j < N; ++j) {
      int u = perm[j];
      if (!G[v][u]) return false;
      v = u;
    }
    return true;
  };

  i64 cnt = 0;
  do {
    if (is_ok()) {
      ++cnt;
    }
  } while (next_permutation(perm.begin(), perm.end()));
  cout << cnt << endl;
}

Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    S=[list(input()) for _ in range(2)]
    ans=1
    prev=0
    i=0
    while i<N:
        if S[0][i]==S[1][i]:
            ans*=3-prev
            prev=1
            i+=1
        else:
            if prev==0:
                ans*=6
            elif prev==1:
                ans*=2
            else:
                ans*=3
            prev=2
            i+=2
        ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
N = int(input())

seeking_range =[0,N-1]
seat_condition = ["" for _ in range(N)]

print(0, flush = True)
seat_condition[0] = input()


if seat_condition[0] != "Vacant":
    for n in range(19):
        next_target = sum(seeking_range)//2
        if seeking_range[0] == N-2:
            next_target = N-1
        print(next_target, flush = True)
        seat_condition[next_target] = input()
        
    
        if "Vacant" in seat_condition:
            break

        if (next_target - seeking_range[0] +1) % 2 == 0:

            if (seat_condition[seeking_range[0]] == seat_condition[next_target]):
                seeking_range[1] = next_target
            else:
                seeking_range[0] = next_target

        else:

            if (seat_condition[seeking_range[0]] == seat_condition[next_target]):
                seeking_range[0] = next_target
            else:
                seeking_range[1] = next_target

  


Measured memory_bytes: 9960
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);

    List<String> week = new ArrayList<String>();
    week.add("SUN");
    week.add("MON");
    week.add("TUE");
    week.add("WED");
    week.add("THU");
    week.add("FRI");
    week.add("SAT");

    String S = sc.next();

    int remainNextSunday = week.indexOf(S);
    System.out.println(7 - remainNextSunday);
  }
}


Measured memory_bytes: 23636
#include<stdio.h>
#include<math.h>
int main( )
{ 
	long long int n;
	long long int x=100;
	scanf("%lld",&n);
	int i=0;
	while(x<n)
	{
		x=x*1.01;
		i++;
	}
	printf("%d",i);
}

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

int main() {
    int A, B;
    cin >> A >> B;

    int ans = -1;
    for (int i = 1250; i > 0; i--) {
        int a = floor(i * 0.08);
        int b = floor(i * 0.1);
        if (a == A && b == B) ans = i;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int query(int i)
{
	cout<<i<<endl;
	flush(cout);
	string res;
	cin>>res;
	if(res=="Male")
		return 1;
	else if(res=="Female")
		return -1;
	return 0;
}
int main()
{
	int n,tmp,yosou;
	ll ans=0;
	cin>>n;
	int l=0;int r=n;
	int lz,rz;
	tmp=query(0);
	if(tmp==0)
		return 0;
	lz=tmp;
	rz=tmp;
	while(1)
	{
		int mid=(l+r)/2;
		if((mid-l)&1)
			yosou=lz*-1;
		else
			yosou=lz;
		tmp=query(mid);
		if(tmp==0)
			break;
		if(yosou==tmp)
		{
			l=mid;
			lz=tmp;
		}else{
			r=mid;
			rz=tmp;
		}
	}
	return 0;
}

Measured memory_bytes: 852