akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <assert.h>

using namespace std;

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

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	static ll n,a,b;
	static ll p[5002];
	scanf("%lld%lld%lld",&n,&a,&b);
	rep1(i,n)scanf("%lld",&p[i]);
	
	static ll dp[2][5002] = {};
	static int t = 0, t_ = 1;
	rep1(i,n){
		rep1(j,n){
			dp[t_][j] = dp[t][j];
			if(j < p[i])dp[t_][j] += a;
			else if(j > p[i])dp[t_][j] += b;
			if(j > 1)dp[t_][j] = min( dp[t_][j] , dp[t_][j-1] );
		}
		swap(t,t_);
	}
	cout << dp[t][n] << endl;
}



Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    int K,A,B,flag=0;
    cin>>K>>A>>B;
    for(int i=A;i<=B;i++){
        if(i%K==0) flag=1;
    }
    if(flag) p("OK");
    else p("NG");
}

Measured memory_bytes: 3636
line1 = input().split(' ')
line2 = input().split(' ')
N = int(line1[0])
K = int(line1[1])
R = int(line2[0])
S = int(line2[1])
P = int(line2[2])
T = input()
score = 0
mem = list(range(K))

for i in range(N):
  index = i % K

  if (mem[index] != T[i:i+1]):
    if (T[i:i+1] == 'r'):
      score = score + P
    elif (T[i:i+1] == 's'):
      score = score + R
    elif (T[i:i+1] == 'p'):
      score = score + S
    mem[index] = T[i:i+1]
  else:
    mem[index] = 0

print(score)

Measured memory_bytes: 6644
n = int(input())
l = input().split()
max = 0
sum = 0
for i in range(n):
    l[i] = int(l[i])
    sum += l[i]
    if max <= l[i]:
        max = l[i]


if max * 2 < sum:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
a, b = map(int, input().split())
# n個さしたら口はn*a-(n-1) = a*n-n+1個
if b == 1:
  print(0)
else:
  for i in range(1,21):
    if a*i - i + 1 >= b:
      n = i
      break	
  print(n)


Measured memory_bytes: 2940
d, g = map(int, input().split())

p = []
c = []
for _ in range(d):
    P, C = map(int, input().split())
    p.append(P)
    c.append(C)

ans = 1e9
for i in range(2 ** d):
    sum_ = 0
    num = 0
    rest_max = -1
    for j in range(d):
        if ((i >> j) & 1):
            sum_ += 100 * (j + 1) * p[j] + c[j]
            num += p[j]
        else:
            rest_max = j
    if (sum_ < g):
        s1 = 100 * (rest_max + 1)
        need = (g - sum_ + s1 - 1) // s1
        if need >= p[rest_max]:
            continue
        num += need
    ans = min(ans, num)
print(ans)


Measured memory_bytes: 3064
n, k, d = map(int,input().split(' '))
n = abs(n)
ans = []
cur = n // d
if cur >= k: print (n - k * d)
else:
    n -= (cur * d)
    ans.append(n)
    ans.append(abs(n - d))
    k -= cur
    print (ans[k & 1])


Measured memory_bytes: 9040
#include <stdio.h>
#include <vector>
#include <iostream>
#include <math.h>
#include <string.h> //memset
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
using namespace std;
#define INF 1e9
#define MAX_V 1000
//辺の構造体
struct edge { int to, cap, rev; };

vector<edge> G[MAX_V];
bool used[MAX_V];

//from-to 容量capの辺を追加
void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});   //場所が被るごとに0,1,...がrevに入る
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

//増加パスをDFS
int dfs(int v, int t, int f) {
    if(v == t) return f;
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f,e.cap));
            if(d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

//s-tの最大流
int max_flow(int s, int t) {
    int flow = 0;
    while(1) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f == 0) return flow;
        flow += f;
    }
}

signed main() {
    int x,y,e,from,to;
    cin >> x >> y >> e;
    rep(i,x) add_edge(210, i, 1);
    rep(i,y) add_edge(i+100, 220, 1);
    rep(i,e) {
        cin >> from >> to;
        add_edge(from, to+100, 1);
    }
    cout << max_flow(210,220) << endl;
    return 0;
}


Measured memory_bytes: 3384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int n, k;
Int a[216000];

Int f(Int x){
  Int res = 0;
  for(int i = 0;i < n;i++)res += x ^ a[i];
  return res;
}

int main(){
  cin >> n >> k;
  for(int i = 0;i < n;i++)cin >> a[i];
  Int ans = 0;
  for(int i = 40;i >= 0;i--){
    if(ans + (1LL << i) > k)continue;
    if(f(ans) < f(ans + (1LL << i)))ans += 1LL << i;
  }
  cout << f(ans) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll maxans=0;
  cin>>n;
  vi ans(n);
  vvi x(n, vi(n,-1));  // N * M の2次元配列
  REP(i,n){
    int A;
    cin>>A;
    REP(j,A){
      int b,c;
      cin>>b>>c;
      b--;
      x[i][b]=c;
    }
  }


  for(int i=0;i<(1<<n);i++){
    int ii=i;
    ll score=0;
    for(int j=0;j<n;j++){
      ans[j]=ii%2;
      score+=ii%2;
      ii/=2;
    }

    int flag=0;//0ならok
    for(int j=0;j<n;j++)
    {
      REP(k,n)
      {
        if (ans[k]==1){
          REP(l,n){
            if (x[k][l]!=-1){
              if (ans[l]!=x[k][l])
              flag=1;
            }
          }
        }
      }
    }

    if (flag==0){
      maxans=max(maxans,score);
    }
  }



  cout<<maxans<<endl;
  return 0;
}

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

int main() {
   string s ;
  cin >> s ;
   if(s=="Sunny") cout << "Cloudy" << endl;
   if(s=="Cloudy") cout << "Rainy" << endl;
   if(s=="Rainy") cout << "Sunny" << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int D = 9901;

struct Hash{
    Hash(){
        hash_value = 0;
        num = 0;
        left_child = right_child = -1;
    }
    ull hash_value;
    ull num,left_child,right_child;
};

struct HashTree{
public:
    void init(int size){
        hash = new Hash[size];
        num_of_node = 0;
    }

    void addHash(ull value){
        if(num_of_node == 0){
            hash[0].hash_value = value;
            hash[0].num = 1;
            num_of_node++;
            return;
        }else{
            int index = 0;

            while(true){
                if(value == hash[index].hash_value){
                    hash[index].num++;
                    return;
                }else if(value > hash[index].hash_value){
                    if(hash[index].right_child == -1){
                        hash[index].right_child = num_of_node;
                        hash[num_of_node].hash_value = value;
                        hash[num_of_node].num = 1;
                        num_of_node++;
                        return;
                    }else{
                        index = hash[index].right_child;
                    }
                }else{ //value < hash[index].hash_value
                    if(hash[index].left_child == -1){
                        hash[index].left_child = num_of_node;
                        hash[num_of_node].hash_value = value;
                        hash[num_of_node].num = 1;
                        num_of_node++;
                        return;
                    }else{
                        index = hash[index].left_child;
                    }
                }
            }
        }
    }

    ull calc_ans(){
        ull sum = 0;

        for(int i = 0; i < num_of_node; i++){
        	sum += (hash[i].num)*(hash[i].num-1)/2;
        }
        return sum;
    }

    Hash* hash;
    int num_of_node;
};

struct Node{
    vector<int> children;
    int parent;
};

Node* node;
HashTree HT;

ull calc(int node_id){

    ull Ret = 1;
    ull child;

    for(int i = 0; i < node[node_id].children.size();i++){
        child = calc(node[node_id].children[i]);
        Ret = (Ret+child*D)%MOD;
    }

    HT.addHash(Ret);

    return Ret;
}

int main(){

    int N;
    scanf("%d",&N);

    node = (Node*)malloc(sizeof(Node)*(N+1));
    HT.init(N);

    int parent,child;
    for(int i = 0; i < N-1; i++){
        scanf("%d %d",&parent,&child);
        node[parent].children.push_back(child);
        node[child].parent = parent;
    }

    calc(1);

    printf("%lld\n",HT.calc_ans());

    return 0;
}

Measured memory_bytes: 16784
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,c = inpl()
s = [inpl() for i in range(n)]
s.sort()
rec = [[0,0]]
for i in range(n):
    flag = False
    for j in range(len(rec)):
        if s[i][0] > rec[j][0] or s[i][2] == rec[j][1]:
            rec[j] = [s[i][1],s[i][2]]
            flag = True
            break
    if flag == False:
        rec.append([s[i][1],s[i][2]])
print(len(rec))



Measured memory_bytes: 29020
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,L = map(int, input().split())
    apples = [L+i-1 for i in range(1,N+1)]
    if apples[0] > 0:
        print(sum(apples[1:]))
    elif apples[-1] < 0:
        print(sum(apples[:-1]))
    else:
        print(sum(apples))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3700
# 総数-Cで割り切れる個数-Dで割り切れる個数+CでもDでも割り切れる個数


def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


a, b, c, d = map(int, input().split())

total = b-a+1
sub_c = total//c
if total % c != 0 and (a % c > b % c or (a % c == 0 and b % c == 0)):
    sub_c += 1

sub_d = total//d
if total % d != 0 and (a % d > b % d or (a % d == 0 and b % d == 0)):
    sub_d += 1

cd = c*d//gcd(c, d)
sub_cd = total//cd
if total % cd != 0 and (a % cd > b % cd or (a % cd == 0 and b % cd == 0)):
    sub_cd += 1

ans = total - sub_c - sub_d + sub_cd
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int ALP='z'-'a'+1;
int N;

int imi[ALP],ima[ALP];
list<char> S;
list<char>::iterator itmi[ALP],itma[ALP];
set<char> allc;

int main(){
	{
		string s;
		cin>>s;
		N=(int)s.size();
		REP(i,N){
			S.push_back(s[i]);
			allc.insert(s[i]);
		}
	}
	REP(i,ALP){
		imi[i]=N;
		ima[i]=-1;
	}
	{
		auto ite=S.begin();
		REP(i,N){
			int c=*ite-'a';
			if (i<imi[c]){
				imi[c]=i;
				itmi[c]=ite;
			}
			if (i>ima[c]){
				ima[c]=i;
				itma[c]=ite;
			}
			ite++;
		}
	}
	bool flg=true;
	{
		bool f=false;
		vector<char> cnt(ALP);
		for(auto c:S){
			cnt[c-'a']++;
		}
		REP(i,ALP){
			if (cnt[i]%2){
				if (!f){
					f=true;
				}else{
					flg=false;
					break;
				}
			}
		}
	}
	if (flg){
		ll ans=0;
		REP(i,N/2){
			char mc;
			int lb,ub,f;
			{
				auto ite=S.begin();
				mc=*ite;
				lb=ima[mc-'a']+1;
				ub=N-i;
				f=-1;
				ite=S.end();
				ite--;
				if (N-1-ima[mc-'a']-i>imi[*ite-'a']-i){
					mc=*ite;
					lb=i;
					ub=imi[mc-'a'];
					f=1;
				}
				ans+=(imi[mc-'a']-i)+(N-1-ima[mc-'a']-i);
			}
			{
				auto tem=S.begin();
				if (f==-1){
					tem=S.erase(itma[mc-'a']);
					tem--;
					ima[mc-'a']--;
					S.push_back(mc);
					auto ite=itmi[mc-'a'];
					ite++;
					imi[mc-'a']++;
					while(*ite!=mc){
						ite++;
						imi[mc-'a']++;
					}
					itmi[mc-'a']=ite;
					while(*tem!=mc){
						tem--;
						ima[mc-'a']--;
					}
					itma[mc-'a']=tem;
				}else{
					tem=S.erase(itmi[mc-'a']);
					S.push_front(mc);
					imi[mc-'a']++;
					while(*tem!=mc){
						tem++;
						imi[mc-'a']++;
					}
					itmi[mc-'a']=tem;
					auto ite=itma[mc-'a'];
					ite--;
					ima[mc-'a']--;
					while(*ite!=mc){
						ite--;
						ima[mc-'a']--;
					}
					itma[mc-'a']=ite;
				}
				auto ite=S.begin();
				S.erase(ite);
				ite=S.end();
				ite--;
				S.erase(ite);
			}
			for(auto c:allc){
				if (c!=mc){
					int *i=&imi[c-'a'];
					if (lb<=*i && *i<ub){
						*i+=f;
					}
					i=&ima[c-'a'];
					if (lb<=*i && *i<ub){
						*i+=f;
					}
				}
			}
		}
		cout<<ans<<endl;
	}else{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 6660
s=input()
n=len(s)
ans=0
for i in range(2**(n-1)):
  res=s[0]
  for j in range(n-1):
    if i & (1<<j):
      res+='+'
    res+=s[j+1]
  ans+=sum(map(int,res.split('+')))
print(ans)

Measured memory_bytes: 68148
# !/usr/bin/python3

"""
https://atcoder.jp/contests/abc151/tasks/abc151_d
Maze Master.
"""

from collections import deque
from copy import deepcopy

def bfs(chw, i, j):
    dq = deque()

    dq.append([i, j])
    chw[i][j] = '#'

    dist = [[-1 for _ in range(w)] for _ in range(h)]
    dist[i][j] = 0

    # for each in dist: print(each)

    while dq:
        y, x = dq.popleft()
        for dy, dx in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            ny = y+dy
            nx = x+dx
            if 0 <= nx < w and 0 <= ny < h and chw[ny][nx] == '.':
                dq.append([ny, nx])
                chw[ny][nx] = '#'
                dist[ny][nx] = dist[y][x]+1

    # for each in dist: print(each)
    temp_ans = 0
    for each in dist:
        temp_ans = max(temp_ans, max(each))

    return temp_ans



def solve(h, w, hw):
    ans = 0
    for i in range(h):
        for j in range(w):
            if hw[i][j] == '.':
                chw = deepcopy(hw)
                dist = bfs(chw, i, j)
                ans = max(dist, ans)
    return ans

if __name__ == "__main__":
    h, w = list(map(int, input().split(" ")))
    hw = [list(input()) for _ in range(h)]
    print(solve(h, w, hw))


Measured memory_bytes: 9568
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}


int main() {
    long long n, m, a, b;
    cin >> n;
    multiset<long long> ss;
    for (int i = 0; i < n; i++){
        cin >> a;
        ss.insert(a);
    }
    cin >> m;
    if (m > n){
        cout << "NO" << endl;
        return 0;
    }
    for (int i = 0; i < m; i++){
        cin >> b;
        if (ss.count(b)) {
            ss.erase(ss.find(b));
            continue;
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 9600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_120
{
    class UnionFind
    {
        private int N;        
        private int[] parents; //親の番号を格納. 親の場合は-(メンバサイズ)

        public UnionFind(int n)
        {
            parents = new int[n];
            for (int i = 0; i < n; i++) parents[i] = -1;
            N = n;
        }

        //グループのボスを取得
        public int Root(int x)
        {
            if (parents[x] < 0) return x;
            parents[x] = Root(parents[x]); //次からはボスに直結するように構造を変える
            return parents[x];
        }

        //グループのメンバ数
        public int Size(int x)
        {
            int r = Root(x);
            return -parents[r];
        }

        public bool Unite(int x, int y)
        {
            x = Root(x);
            y = Root(y);
            if (x == y) return false;
            //メンバサイズが大きい方をボスとして合併
            if (Size(x) < Size(y))
            {
                parents[y] += parents[x];
                parents[x] = y;
            }
            else
            {
                parents[x] += parents[y];
                parents[y] = x;
            }
            return true;
        }
    }

    class D
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = a[0], M = a[1];

            List<int[]> list = new List<int[]>();
            for (int i = 0; i < M; i++)
            {
                int[] b = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                list.Add(b);
            }

            UnionFind uf = new UnionFind(N);
            long r = (long)N * (N - 1) / 2;
            long[] numUnconnected = new long[M];
            numUnconnected[M - 1] = r;

            for (int i = 0; i < M - 1; i++)
            {
                int[] b = list[M - 1 - i];
                int A = b[0] - 1, B = b[1] - 1;
                if (uf.Root(A) != uf.Root(B))
                {
                    long sa = (long)uf.Size(A);
                    long sb = (long)uf.Size(B);
                    r -= sa * sb;
                    uf.Unite(A, B);
                }                
                numUnconnected[M - 2 - i] = r;
            }
            for (int i = 0; i < M; i++)
            {
                Console.WriteLine(numUnconnected[i]);
            }
        }

    }
}




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

int main(){
    int n; cin >> n;
    vector<int> A(n, INT_MAX);
    vector<int> B(n+1);
    for(int i = 0; i < n-1; i++) cin >> B[i];
    B[n] = INT_MAX;
    //--
    for(int in = 1; in < n; in++) {
        int minB = n;
        for(int i = 0; i < n-1; i++) {
            minB = (B[minB] > B[i] ? i : minB);
        }
        //
        A[minB]    = min(A[minB], B[minB]);
        A[minB+1]  = min(A[minB+1], B[minB]);
        B[minB] = INT_MAX;
    }
    //
    long long sum = 0;
    for(int i = 0; i < n; i++) sum += A[i];
    cout << sum;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var abx=Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToList();
            Console.WriteLine(abx[0]<=abx[2]&&abx[2]<=abx[0]+abx[1]?"YES":"NO");
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string t;
    cin>>t;
    int s=t.size();
    for(int i=0;i<s;i++){
        if(t.at(i)=='?'){
            t.at(i)='D';
        }
    }
    out(t);
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        if(a/c<=b)
        {
            if(a%c&&a/c==b)
            {
                cout<<"No";
            }
            else
            {
                cout<<"Yes";
            }
        }
        else
        {
            cout<<"No";
        }
    }
    return 0;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	static PrintWriter out;
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		
		int[] occ = new int[4];
	
		for (int i = 0; i < 3; i++) {
			occ[sc.nextInt()-1]++;
			occ[sc.nextInt()-1]++;
		}
		
		boolean ans = true;
		
		for (int i = 0; i < 4; i++) {
			if (occ[i] > 2)
				ans = false;
		}
		
		if(ans)
			out.println("YES");
		else
			out.println("NO");
		
		out.flush();
	}

}
	
class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream system) {
		br = new BufferedReader(new InputStreamReader(system));
	}

	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 double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public char nextChar() throws IOException {
		return next().charAt(0);
	}

	public Long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public boolean ready() throws IOException {
		return br.ready();
	}

	public void waitForInput() throws InterruptedException {
		Thread.sleep(3000);
	}

}


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

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
	if(A.size() == n+1){
		int now = 0;
		rep(i, q){
			if(A.at(b.at(i)) - A.at(a.at(i)) == c.at(i))
				now += d.at(i);
		}
		ans = max(ans, now);
		return ;
	}

	A.push_back(A.back());
	while(A.back() <= m){
		dfs(A);
		A.back()++;
	}

}

int main(){
	cin >> n >> m >> q;
	a = b = c = d = vector<int>(q);
	rep(i, q) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);

	dfs(vector<int> (1, 1));
	cout << ans << endl;
	return 0;
}


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

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

long long ans[10];
set<pair<int, int>> s;
int h, w, n;

int check(int u, int l, int a, int b) {
	if (u <= 0 || l <= 0) return -1;
	if (u+2 > h || l+2 > w) return -1;
	int cnt = 0;
	for (int i = u; i < u+3; ++i) {
		for (int j = l; j < l+3; ++j) {
			cnt += s.count(make_pair(i, j));
		}
	}
	return cnt;
}

void solve() {
	scanf("%d %d %d", &h, &w, &n);
	ans[0] = (long long)(h-2)*(w-2);
	for (int i = 0; i < n; ++i) {
		int a, b; scanf("%d %d", &a, &b);
		vector<int> v;
		for (int j = -2; j <= 0; ++j) {
			for (int k = -2; k <= 0; ++k) {
				v.push_back(check(a+j, b+k, a, b));
				if (v.back() == -1) v.pop_back();
			}
		}
		s.emplace(a, b);
		for (int e: v) {
			--ans[e];
			++ans[e+1];
		}
	}
	for (int i = 0; i < 10; ++i) {
		printf("%lld\n", ans[i]);
	}
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
std::vector<int> v;
int main() {
	string s;
	cin >> s;
	int a=0,b=0,c=0,d=0;
	for(auto x:s){
	    // coNSNNSNSNut << x<<" ";
	     if(x=='S'){
	          a+=1;
	     }
	     if(x=='N'){
	          b+=1;
	     }
	     if(x=='W'){
	          c+=1;
	     }
	     if(x=='E'){
	          d+=1;
	     }
	}
// 	cout << endl;
	int done = 0;
	if((a>0&&b>0)||(a==0&&b==0)){
	          if((c>0&&d>0)||(c==0&&d==0)){
	               cout << "Yes";
	               done = 1;
	          }
	     }
	
	if(done==0){
	
	     cout << "No";
	}
	return 0;
}


Measured memory_bytes: 3596
k = int(input())
candili = []
for i in range(1, 1000):
    candili.append(i)

tmpli = []
for i in candili:
    for j in range(1, 15):
        tmpli.append(int(str(i) + "9" * j))
tmpli = list(set(tmpli))

tmp2li = []
for i in tmpli:
    if i <= 10 ** 15:
        tmp2li.append(i)
candili += tmp2li
candili = list(set(candili))
candili.sort()

def S(n):
    return sum(int(i) for i in str(n))

conli = []

for i in candili:
    conli.append(i/S(i))

ansli = []
for i in range(len(conli)):
    for j in range(i, len(conli)):
        if conli[i] > conli[j]:
            break
    else:
        ansli.append(candili[i])

for i in range(k):
    print(ansli[i])

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



int main(){
	int N , M , x;
	cin >> N >> M ;
	multiset < int > s ;
	multiset < int > :: iterator it ;
	for( int i = 1 ; i<= N ; i++ ){
		cin >> x ;
		s.insert(x);
	} 
	for( int i = 0 ; i < M ; i++ ){
		it = s.end() ;
		it-- ;
		x = *it;
		s.erase(it);
		s.insert(x/2) ;
		// for( it = s.begin() ; it != s.end() ; it++ ){
		// cout << (*it) << " " ;
		// }
		// puts("");
	}
	long long sum = 0 ;
	for( it = s.begin() ; it != s.end() ; it++ ){
		sum += (*it) ;
	}
	cout << sum << endl ;

	return 0 ;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int h = Integer.parseInt(sc.nextLine().split(" ")[0]);

		for (int i = 0; i < h; i++) {
			String c = sc.nextLine();
			System.out.println(c + "\n" + c);
		}
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, tt;
int M[N][N], color[N], d[N], f[N], nt[N]; 

int next(int u) {
	for(int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if(M[u][v]) return v;
	}
	return -1;
}

void dfs_visit(int r) {
    for(int i = 0; i < n; i++) {
        nt[i] = 0;
	}
	
	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;
	
	while(!S.empty()) {
		int u = S.top();
		int v = next(u);
		if(v != -1) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   d[v] = ++tt;
			   S.push(v); 	
			}
		} else {
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


void dfs() {
	for(int i = 0; i < n; i++) {
	     color[i] = WHITE;
	}
	tt = 0;
		
	for(int u = 0; u < n; u++) {
		if(color[u] == WHITE) dfs_visit(u);
	}

	
	for(int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;	
	}
}

int main() {
	int k , u, v;
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}
	
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
	    u--;
	    for(int i = 0; i < k; i++) {
	        cin >> v;
	        v--;
		   M[u][v] = 1; 
     	}
	} 
	
	dfs();
	
	return 0;
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define vv vector<ll>
#define pb push_back
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define fe(it,v) for(auto it:v)
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000001
using namespace std;

void solve(){
	string s,t;
	cin>>s>>t;
	ll ans=t.length();
	rep(i,0,s.length()-t.length()+1){
		ll count=0;
	string sub=s.substr(i,t.length());
	rep(j,0,t.length()) if(sub[j]!=t[j]) count++;
	ans = min(ans,count);
	}
	cout<<ans;

}

int main()
{
	// ll t;
	// cin>>t;
	// while(t--){
		solve();
		// cout<<endl;
// }
return 0 ;
}


Measured memory_bytes: 3628
H,W=map(int, input().split())
S = [input() for _ in range(H)]
d = [-1,0,1,0,-1]
b = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == ".": continue
        if any(S[h+x][w+y]=="#" for x,y in zip(d,d[1:]) if 0<=h+x<H and 0<=w+y<W):
            continue
        b = 1
print("YNeos"[b::2])

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main() {
	string S;
	cin >> S;
	for (int i = 0; i < 3; i++)
	{
		if (S[i] == '1') {
			S[i] = '9';
		}
		else if (S[i] == '9') {
			S[i] = '1';
		}
	}

	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>

using namespace std;

int main(){
  string s,t; cin>>s>>t;
  string tmp,ans="No";
  int n=s.length();
  for(int l=0;l<n;l++){
    if(s==t){
      ans="Yes";
      break;
    }
    tmp=s;
    s[0]=tmp[n-1];
    for(int i=1;i<n;i++){
      s[i]=tmp[i-1];
    }
  }
  
  cout<<ans;
  
  return 0;
}

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


int main() {
  string s;
  cin>>s;
  if(s[0]=='?') {
    s[0]='D';
  }
  for(int i=1;i<s.size();i++) {
    if(s[i]=='?') {
      s[i]='D';
    }
  }
  cout<<s;
  return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            # 下を探しに行く
            ok = mid
        else:
            # 上を探しに行く
            ng = mid
    return ok

N, K = MAP()
A = LIST()
B = LIST()

A.sort(reverse=True)
B.sort()

def check(m):
    k = 0
    for i, a in enumerate(A):
        b = B[i]
        k += max(ceil(a - m/b), 0)
        if k > K:
            return False
    return True

print(bisearch_min(-1, INF, check))


Measured memory_bytes: 115200
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int cnt[200005];
int main () {
  int n;
  scanf("%d", &n);
  FOR(i, 2, n) {
    int p;
    scanf("%d", &p);
    cnt[p]++;
  }
  FOR(i, 1, n) printf("%d\n", cnt[i]);
  return 0;
}

Measured memory_bytes: 4496
h, w = map(int, input().split())

plan = []
for i in range(h):
  plan.append(input())

canvas = [[False] * w for _ in range(h)]

for i in range(h):
  for j in range(w - 1):
    if plan[i][j] == plan[i][j + 1] == '#':
      canvas[i][j] = canvas[i][j + 1] = True

for j in range(w):
  for i in range(h - 1):
    if plan[i][j] == plan[i + 1][j] == '#':
      canvas[i][j] = canvas[i + 1][j] = True

if all([all([plan[i][j] == '.' or canvas[i][j] for j in range(w)]) for i in range(h)]):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
#include<stdio.h>
#define M 100
#define N 1000000
int min(int,int);
int main(){
  int k,j,l,i,n,p[M+1],m[M+1][M+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }
  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=N;
      for(k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}
int min(int a,int b){
  if(a<b)return a;
  else return b;
}



Measured memory_bytes: 2108
import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(' ').map { it.toInt() }
    val s = IntArray(M) { 0 }
    val c = IntArray(M) { 0 }
    for (i in 0 until M) {
        val sc = readLine()!!.split(' ').map { it.toInt() }
        s[i] = sc[0]
        c[i] = sc[1]
    }
    val start = if (N == 1) 0 else Math.pow(10.0, N-1.0).toInt()
    for (x in start until Math.pow(10.0,N.toDouble()).toInt()) {
        val S = x.toString()
        var ok = true
        for (i in 0 until M) {
            if (S[s[i]-1].toString() != c[i].toString()) {
                ok=false
                break
            }
        }
        if (ok) {
            println(x)
            return
        }
    }
    println(-1)
}

Measured memory_bytes: 38180
#include<iostream>
#include <math.h>
using namespace std;

int main(){
  double A, B;
  cin >> A >> B;
  int answer = -1;
  for(int i=1; i<=100100; ++i){
    if(floor(i*0.08)==A && floor(i*0.10)==B && answer==-1){
    	answer = i;  
    }
  }
  cout << answer << endl;
  return 0;
}

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

using Int = long long;
using ll = long long;

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}

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

  Int n,m;
  while(cin>>n>>m,n||m){
    vector<Int> as(n),bs(n);
    for(Int i=0;i<n;i++) cin>>as[i];
    for(Int i=0;i<n;i++) cin>>bs[i];

    const Int MAX = 1020;
    const Int INF = 1e15;
    vector<Int> dp(MAX,INF);
    dp[0]=0;
    Int pre=0;
    for(Int i=0;i<n;i++){
      vector<Int> nx(MAX,INF);
      Int dif=bs[i]-as[i];
      if(dif<0) dif+=m;

      for(Int j=0;j<MAX;j++){
        for(Int k=j-10;k<j+10;k++){
          if(k<0||k>=MAX) continue;
          if(dif+k*m<=pre+j*m)
            chmin(nx[k],dp[j]);
          else
            chmin(nx[k],dp[j]+(dif+k*m)-(pre+j*m));
        }
      }

      pre=dif;
      swap(dp,nx);
    }
    cout<<*min_element(dp.begin(),dp.end())<<endl;
  }
  return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <deque>
#include <climits>

using namespace std;

const int _MERRY[] = {4, 1, 4, 1, 2, 1, 2, 1};
int arr[8];

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

    while(true) {
        for(int i = 0; i < 8; ++i) {
            cin >> arr[i];
        }
        if(cin.eof()) break;

        deque<int> MERRY(_MERRY, _MERRY+8), ans(8, 9);
        int best = INT_MAX;
        for(int start = 0; start < 8; ++start) {
            int rem = 0;
            for(int i = 0; i < 8; ++i) {
                rem += max(0, arr[i] - MERRY[i]);
            }
            if(rem < best || (rem == best && MERRY < ans)) {
                ans = MERRY;
                best = rem;
            }
            MERRY.push_back(MERRY[0]);
            MERRY.pop_front();
        }
        for(int i = 0; i < 8; ++i) {
            if(i > 0) cout << ' ';
            cout << ans[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  vll a(n);
  scan(a);
  int cnt = 0;
  ll minelm = LLONG_MAX;
  rep (i, n) {
    if (a[i] < 0) {
      cnt += 1;
      a[i] *= (-1);
    }
    minelm = min(minelm, a[i]);
  }
  ll sum = 0;
  rep (i, n) {
    sum += a[i];
  }
  if (cnt % 2 == 1) {
    sum -= minelm * 2;
  }
  print(sum);

  return 0;
}


Measured memory_bytes: 1024
//https://hiramekun.hatenablog.com/entry/2020/08/23/033048
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ll long long
using namespace std;
const ll dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
//const ll ll_inf=1e9*1e9;
int main(){
    ll h,w;
    cin>>h>>w;
    ll startX,startY,endX,endY;
    cin>>startX>>startY>>endX>>endY;
    startX--;startY--;endX--;endY--;

    vector<vector<char>> s(h,vector<char>(w));
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>s[i][j];
    vector<vector<ll>> cnts(h,vector<ll>(w,(ll)1e9));
    queue<pair<ll,ll>> q,visited;

    q.push(make_pair(startX,startY));
    cnts[startX][startY]=0;

    while (!q.empty() || !visited.empty()){
        ll nowX,nowY;
        if(!q.empty()){
            nowX=q.front().first,nowY=q.front().second;
            visited.push(make_pair(nowX,nowY));
            q.pop();
            for (int i=0;i<4;i++){
                ll nextX=nowX+dx[i],nextY=nowY+dy[i];
                if(0<=nextX && nextX<=h-1 && 0 <= nextY && nextY <= w-1){
                    if(s[nextX][nextY]=='#') continue;
                    if(cnts[nowX][nowY] < cnts[nextX][nextY]){
                        cnts[nextX][nextY]=cnts[nowX][nowY];
                        q.push(make_pair(nextX,nextY));
                    }
                }
            }
        }else{
            nowX=visited.front().first,nowY=visited.front().second;
            visited.pop();
            for (ll ix=-2;ix<=2;ix++){
                for(ll jy=-2;jy<=2;jy++){
                    ll nextX=nowX+ix,nextY=nowY+jy;
                    if(0<=nextX && nextX<=h-1 && 0 <= nextY && nextY <= w-1){
                        if(s[nextX][nextY]=='#') continue;
                        if(cnts[nowX][nowY]+1<cnts[nextX][nextY]){
                            cnts[nextX][nextY]=cnts[nowX][nowY]+1;
                            q.push(make_pair(nextX,nextY));
                        }

                    }
                }
            }
        }
    }
    if(cnts[endX][endY]==1e9){
        cout<<-1<<endl;
    }else{
        cout<<cnts[endX][endY]<<endl;
    }



    return 0;
}

Measured memory_bytes: 12552
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	int H,W;
	Scanner scan=new Scanner(System.in);
	while(true)
	    {
		H=scan.nextInt();
		W=scan.nextInt();
		if((H==0) && (W==0))break;
		for(int i=0;i<H;i++)
		    {
			for(int j=0;j<W;j++)
			    {
				if((i==0) || (j==0) || (i==(H-1)) || (j==(W-1)))
				    System.out.print("#");
				else
				    System.out.print(".");
			    }
			System.out.println();
		    }
		System.out.println();
	    }
    }
}

Measured memory_bytes: 22944
/***  بسم الله الرحمن ا لرحيم   ***/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl                         '\n'
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define watch(x) cout<<#x<<" = { "<<x<<" }\n"
#define test int t;cin>>t;while(t--)
const int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 2e5 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y)) * y); }
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int n, m;
char a[1005][1005];
int memo[1005][1005];
int dp(int i, int j) {
	if (i >= n || j >= m || a[i][j]=='#') {
		return 0;
	}
	if (i == n -1 && j == m-1)return 1;
	int& ret = memo[i][j];
	if (~ret)return ret;
	ret = 0;
	ret += dp(i + 1, j)%mod;
	ret += dp(i , j+1)%mod;
	return ret%mod;
}
void solve() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)for (int j = 0; j < m; j++)cin >> a[i][j];
	mem(memo, -1);
	cout << dp(0, 0) << endl;

}
int main() {
	file();
	solve();

	return 0;
}

Measured memory_bytes: 8608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;
int upcmpii(const void *a, const void *b){
    return (*(int*)a == *(int*)b ? 0 : (*(int*)a > *(int*)b ? 1 : -1));
}
void sort_ui(int *a, int n){ qsort(a, n, sizeof(int), upcmpii);}

int main(){
    //input
    int n, k;
    scanf("%d%d", &n, &k);
    int a[201010];
    rep(i, n) scanf("%d", a+i);

    //solve
    sort_ui(a, n);
    if(k == 0) {
        printf("%d\n", a[n-1]);
    }else{
        int left = 0, right = a[n-1]+1;
        while(right - left > 1){
            ll tmp = 0;
            int mid = (right+left)/2;
            rep(i, n){
                if(a[i] > mid) {
                    tmp += (a[i]-1)/mid;
                }
            }
            if(tmp > k) left = mid;
            else right = mid;
        }
        printf("%d", right);
    }
}

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


void solve(long long A, long long B, long long C, long long X, long long Y){
  long long mymin = INT_MAX;

  for(long long i = 0; i <= 100000; i++) {
    mymin = min(mymin, i * (2 * C) + max(0ll, X - i) * A + max(0ll, Y - i) * B);
  }

  cout << mymin << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long C;
  scanf("%lld",&C);
  long long X;
  scanf("%lld",&X);
  long long Y;
  scanf("%lld",&Y);
    solve(A, B, C, X, Y);
    return 0;
}


Measured memory_bytes: 256
//日野茜★担当
//的場梨沙★担当
//結城晴★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>

using namespace std;

int main(void) {
    int N,X,T;
    cin>>N>>X>>T;
    int ans=0;
    while(N>0){
        N-=X;

        ans+=T;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3648
a,b=map(int,input().split())
mod=2019

if b-a+1>=mod:
    print(0)
else:
    l=sorted([i%mod for i in range(a,b+1)])
    m=l[0]*l[1]
    for i in range(len(l)):
        for j in range(i+1,len(l)):
            if l[i]*l[j]%mod<m:
                m=l[i]*l[j]%mod
    print(m)



Measured memory_bytes: 3060