akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
	
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();
		int rc = i * (i - 1) / 2;
		int ten[] = new int[i];
		for(int j = 0; j < i; j++){
			ten[j] = 0;
		}
		for(int j = 0; j < rc; j++){
			int team1 = sc.nextInt();
			int team2 = sc.nextInt();
			int score1 = sc.nextInt();
			int score2 = sc.nextInt();
			if(score1 > score2){
				ten[team1-1] = ten[team1-1] + 3;
			}else if(score1 < score2){
				ten[team2-1] = ten[team2-1] + 3;
			}else if(score1 == score2){
				ten[team1-1] = ten[team1-1] + 1;
				ten[team2-1] = ten[team2-1] + 1;
			}
		}
		for(int j = 0; j < i; j++){
			int cnt = 0;
			for(int k = 0; k < i; k++){
				if(j == k){
					continue;
				}else if(ten[j] >= ten[k]){
					cnt = cnt + 1;
				}
			}
			int rank = i - cnt;
			System.out.println(rank);
		}
	}
}

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

long long a[100001], b[100001];
int main()
{
    long long n, m, cost=0;
    vector<pair<long long, long long> >vec;
    cin>>n>>m;
    for(int i=0; i<n; i++)
        cin>>a[i]>>b[i], vec.push_back(make_pair(a[i], b[i]));
    sort(vec.begin(), vec.end());
    for(int i=0; i<n; i++)
    {

        if(m==0) break;
        if(m>vec[i].second)
        {
            cost+=(vec[i].first*vec[i].second);
            m-=vec[i].second;
        }
        else
        {
            cost+=(vec[i].first*m);
            m=0;
        }
    }
    cout<<cost<<endl;

    return 0;
}


Measured memory_bytes: 3444
n,k = map(int,input().split())
d = list(input().split())

ans = n
while 1:
    a = str(ans)
    count = 0
    for i in range(len(a)):
        if a[i:i+1] in d:
            count += 1
    if count == 0:
        break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3060
N, K = map(int, input().split())
P = [int(i) for i in input().split()]

s_max = sum(P[:K])

s = s_max
for i in range(K, N):
    s = s + P[i] - P[i - K]
    s_max = max(s_max, s)

print((s_max + K)  / 2)



Measured memory_bytes: 71792
N,M,C = map(int, raw_input().split())
B = map(int, raw_input().split())
ans = 0
for _ in range(N):
  A = map(int, raw_input().split())
  s = C
  for j in range(M):
    s += A[j]*B[j]
  if s>0:
    ans += 1
print ans


Measured memory_bytes: 2568
#include <iostream>
#include <string>

#define FOR(i,a,b) for (int i = a; i < b; i++)

using namespace std;

int main(){
  	string s;
  	cin >> s;
    FOR(i,0,s.length()) 
        if (s[i] == '1') cout <<9;else cout<<1;
  	return 0;
}

Measured memory_bytes: 256
import sys


class BIT:
    def __init__(self, node_size):
        self._node = node_size+1
        self.bit = [0]*self._node

    def add(self, index, add_val):
        index += 1
        while index < self._node:
            self.bit[index] += add_val
            index += index & -index

    def sum(self, index):
        index += 1
        res = 0
        while index > 0:
            res += self.bit[index]
            index -= index & -index
        return res

if __name__ == '__main__':
    n, q = map(int, sys.stdin.readline().split())
    bt = BIT(n)
    for i in range(q):
        a, b, c = map(int, sys.stdin.readline().split())
        if a == 0:
            bt.add(b-1, c)
        else:
            print(bt.sum(c-1)-bt.sum(b-2))



Measured memory_bytes: 8144
a,b = map(int,input().split())
if int(a/(0.08)) == int(b/(0.1)):
    mn = int(a/(0.08))
else:
    inter = abs(int(a/(0.08)) - int(b/(0.1)))
    mn = min(int(a/(0.08)) , int(b/(0.1)))
             
    for i in range(inter*2):
        if int(mn*(0.08))==a:
            if int(mn*(0.1))==b:
                break
        mn += 1
        if i ==inter*2-1:
            mn = -1
print(mn)

Measured memory_bytes: 38512
using System;
namespace kozaiyApp
{
    public class C
    {
        static ulong ans;
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            ulong N = ulong.Parse(input[0]);
            ulong K = ulong.Parse(input[1]);
            ulong n = N % K;

            ans = n;
            Recursion(n, K);
            Console.WriteLine(ans);
        }

        static void Recursion(ulong n, ulong k)
        {
            ulong x = n > k ? n - k : k - n;
            if (x < n)
            {
                ans = x;
                Recursion(x, k);
            }
        }
    }
}

Measured memory_bytes: 11092
#include <stdio.h>



 int main()
 {
   int H;
   int W;
   int i=0;
   int j=0;


while (1){
  scanf("%d %d",&H,&W);

  if(H==0 && W ==0) break;


  for(i=0;i < H ;i++){
      for(j = 0; j < W; j++){
        if(i == 0 || i == H-1){
          printf("#");
        }
        else{
           if(j == 0 || j== W-1){
             printf("#");
           }
           else{
          printf(".");
        }
      }
    }
     printf("\n");
  }
     printf("\n");
    }

return(0);
}

Measured memory_bytes: 572
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define REVE(x) reverse(x.begin(),x.end())
#define all(x) (x).begin(),(x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define pob pop_back
#define sw swap
using LL = long long;
using ULL = unsigned long long;
#define FOR(i, m, n) for(int i = m;i < n;i++)
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;}
int main(){
 float n,a,b,c;
 cin >> n;
 while(n--){
 	cin>>a;
 	b+=1/a;
 }
 cout <<1/b<<endl;
 return 0;
  }

Measured memory_bytes: 256
import math
def main():
  from builtins import input, int, map
  N = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  A.sort()
  B.sort()
  C.sort()
  n = int(math.log(N,2))+1

  ans = 0

  for i in range(N):
    if A[0] >= B[i]:
      continue
    if A[N-1] < B[i]:
      a = N
    else:
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if  B[i]> A[mid]:
          left = mid
        else:
          right = mid
      a = left + 1
    if C[N-1] <= B[i]:
      continue
    if C[0] > B[i]:
      c = N
    else:      
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if B[i]>= C[mid]:
          left = mid
        else:
          right = mid
      c = N - right
    ans += a*c
  print(ans)
main()


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int a[10];

int solve() {
  int ret = 0;

  rep (i, 4) {
    int val = a[i];
    while (1) {
      if (val % 10 == 0) break;
      val++;
    }
    ret += val;
  }

  ret += a[4];

  return ret;
}

signed main() {
  rep (i, 5) {
    cin >> a[i];
  }

  sort(a, a+5);

  int ans = 1e18;
  do {
    int t = solve();
    chmin(ans, t);
  } while (next_permutation(a, a+5));

  cout << ans << endl;

  return 0;
}

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

int N, a[50], b[50], c[51][51];
bool A[50][51];
long long res;

int main(){
	cin>>N;
	for(int i=0;i<N;++i){
		cin>>a[i];
		A[i][a[i]]=true;
	}
	for(int i=0;i<N;++i){
		cin>>b[i];
	}
	for(int i=0;i<=50;++i){
		for(int j=0;j<=50;++j){
			c[i][j]=0xE869120;
		}
	}
	for(int i=0;i<=50;++i){
		for(int j=1;j<=i;++j){
			c[i][i%j]=min(c[i][i%j],j);
		}
	}
	for(int i=0;i<=50;++i){
		for(int j=1;j<=i;++j){
			for(int k=0;k<=i%j;++k){
				c[i][k]=min(c[i][k],max(j,c[i%j][k]));
			}
		}
	}
	for(int i=0;i<N;++i){
		if(c[a[i]][b[i]]==0xE869120&&a[i]!=b[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	for(int i=0;i<N;++i){
		pair<int,int>p=make_pair(-1,-1);
		for(int j=0;j<N;++j){
			if(A[j][b[j]])continue;
			int m=0xE869120;
			for(int k=0;k<=50;++k){
				if(A[j][k]){
					m=min(m,c[k][b[j]]);
				}
			}
			p=max(p,make_pair(m,j));
		}
		if(p==make_pair(-1,-1))break;
		res+=(1ll<<p.first);
		for(int j=0;j<N;++j){
			if(A[j][b[j]])continue;
			for(int k=0;k<=50;++k){
				if(A[j][k]){
					A[j][k%p.first]=true;
				}
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int n; cin >> n;
  vec a(n); rep(i,n) cin >> a[i];

  ll res1 = 0, sum1 = 0;
  for(int i=0,sign=1; i<n; i++,sign*=-1){   // start sign=1
    sum1+=a[i];
    if(sign==1) while(sum1<=0) {sum1++; res1++;}
    else while(sum1>=0) {sum1--; res1++;}
  }

  ll res2 = 0, sum2 = 0;
  for(int i=0,sign=-1; i<n; i++,sign*=-1){  // start sign=-1
    sum2+=a[i];
    if(sign==1) while(sum2<=0) {sum2++; res2++;}
    else while(sum2>=0) {sum2--; res2++;}
  }

  ll res = min(res1, res2);
  cout << res << endl;

  return 0;
}


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

int w[10],k[10];

int main(){
  for(int i=0;i<10;i++)cin>>w[i];
  for(int i=0;i<10;i++)cin>>k[i];
  sort(w,w+10);
  sort(k,k+10);
  cout<<(w[7]+w[8]+w[9])<<" ";
  cout<<(k[7]+k[8]+k[9])<<endl;
  return 0;
}

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class {
        static void Main(string[] args) {
            var N = long.Parse(Console.ReadLine());
            long AC = 0;
            long WA = 0;
            long TLE = 0;
            long RE = 0;
            for (var i = 0; i < N; i++) {
                var t = Console.ReadLine();
                if (t == "AC") AC++;
                if (t == "WA") WA++;
                if (t == "TLE") TLE++;
                if (t == "RE") RE++;
            }
            Console.WriteLine("AC x {0}",AC);
            Console.WriteLine("WA x {0}",WA);
            Console.WriteLine("TLE x {0}",TLE);
            Console.WriteLine("RE x {0}",RE);
        }
    }
}

Measured memory_bytes: 30684
// Aizu 0212: Highway Express Bus
// 2017.9.9 bal4u@uu

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

#define INF 0x7fffffff
#define MAX 10000
typedef struct { int t, k, c; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
  int l, r;
  int smallest;

  l = LEFT(i), r = RIGHT(i);
  if (l < qsize && que[l].t < que[i].t) smallest = l; else smallest = i;
  if (r < qsize && que[r].t < que[smallest].t) smallest = r;
  if (smallest != i) {
    QUE t = que[i]; que[i] = que[smallest]; que[smallest] = t;
    min_heapify(smallest);
  }
}

int deq(int *k, int *c)
{
  if (qsize == 0) return 0;
  *k = que[0].k, *c = que[0].c;
  que[0] = que[--qsize];
  min_heapify(0);
  return 1;
}

void enq(int k, int t, int c)
{
  int i, ii;

  i = qsize++;
  que[i].t = t, que[i].k = k, que[i].c = c;
  while (i > 0 && que[ii = PARENT(i)].t > que[i].t) {
    QUE tt = que[i]; que[i] = que[ii]; que[ii] = tt;
    i = ii;
  }
}

typedef struct { int len, to[102], f[102]; } TBL;
TBL tbl[102];
int node[102][11]; int size;
char visited[102][11];
int start, goal, cmax;

int search()
{
	int s, i, c, s2, f2, c2, k;
	TBL *p;

	qsize = 0;
	memset(node, -1, sizeof(node)), memset(visited, 0, sizeof(visited));
	node[start][cmax] = 0;
	enq(start, 0, cmax);
	while(deq(&s, &c)) {
		if (s == goal) return node[goal][c];
		if (visited[s][c]) continue;
		visited[s][c] = 1;
		for (p = tbl+s, i = 0; i < p->len; i++) {
			s2 = p->to[i], f2 = p->f[i];
			if (visited[s2][c]) continue;
			k = node[s][c] + f2;
			if (node[s2][c] < 0 || k < node[s2][c]) node[s2][c] = k, enq(s2, k, c);
			if (c > 0) {
				c2 = c-1;
				if (visited[s2][c2]) continue;
				k = node[s][c] + f2 / 2;
				if (node[s2][c2] < 0 || k < node[s2][c2]) node[s2][c2] = k, enq(s2, k, c2);
			}
		}
	}
	return -1;
}

int main()
{
	int m, i, a, b, f;
	TBL *p;

	while (scanf("%d%d%d%d%d", &cmax, &size, &m, &start, &goal) && cmax) {
		memset(tbl, 0, sizeof(TBL)*(size+1));
		for (i = 0; i < m; i++) {
			scanf("%d%d%d", &a, &b, &f);
			p = tbl + a, p->to[p->len] = b, p->f[p->len] = f, p->len++;
			p = tbl + b, p->to[p->len] = a, p->f[p->len] = f, p->len++;
		}
		printf("%d\n", search());
	}
	return 0;
}

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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int H=read(),W=read(),N=read();
	int a[N];
	int ans[H][W];

	int h=0,w=0;
	bool reverse=false;
	
	REP(i,N){
		a[i]=read();
	}
	
	REP(i,N){
		REP(j,a[i]){
			//cout << h << w << endl;
			ans[h][w] = i+1;
			if(w==0&&reverse || w==W-1&&!reverse){
				h++;
				reverse=!reverse;
			}
			else if(reverse) w--;
			else w++;
			
		}
	}
	
	REP(i,H){
		REP(j,W){
			cout << ans[i][j] << " ";
		}
		cout << "\n";
	}
	
}

Measured memory_bytes: 384
from math import sqrt

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

m=int(sqrt(N))
if N//(m+1)==m:
    dp=[[[0  for i in range(0,2)] for j in range(0,int(sqrt(N)))] for k in range(0,K+1)]

    for i in range(0,int(sqrt(N))):
        dp[1][i][1]=1
        dp[1][i][0]=(N//(i+1)-N//(i+2))

    for k in range(2,K+1):
        s=0
        for i in range(0,int(sqrt(N))):
            s=(s+dp[k-1][i][1])%mod
            dp[k][i][0]=(s*(N//(i+1)-N//(i+2)))%mod

        for j in range(0,int(sqrt(N))):
            i=int(sqrt(N))-j-1
            s=(s+dp[k-1][i][0])%mod
            dp[k][i][1]=s

    ans=sum(dp[K][i][0]+dp[k][i][1] for i in range(0,int(sqrt(N))))%mod
    print(ans)

else:
    dp0=[[0 for i in range(0,int(sqrt(N))-1)] for k in range(0,K+1)]
    dp1=[[0 for i in range(0,int(sqrt(N)))] for k in range(0,K+1)]

    for i in range(0,int(sqrt(N))-1):
        dp0[1][i]=(N//(i+1)-N//(i+2))
        dp1[1][i]=1

    dp1[1][-1]=1

    for k in range(2,K+1):
        s=0
        for i in range(0,int(sqrt(N))-1):
            s=(s+dp1[k-1][i])%mod
            dp0[k][i]=(s*(N//(i+1)-N//(i+2)))%mod

        s=(s+dp1[k-1][int(sqrt(N))-1])%mod
        dp1[k][int(sqrt(N))-1]=s%mod
        for j in range(1,int(sqrt(N))):
            i=int(sqrt(N))-j-1
            s=(s+dp0[k-1][i])%mod
            dp1[k][i]=s

    ans=sum(dp0[K][i]+dp1[K][i] for i in range(0,int(sqrt(N))-1))%mod
    ans=(ans+dp1[K][-1])%mod

    print(ans)


Measured memory_bytes: 356232
import java.util.Scanner;

/**
 * Created by malone on 2018/3/9.
 */
public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int W = scanner.nextInt();
        int H = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int r = scanner.nextInt();

        if (x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H) {
            System.out.println("Yes");
        } else System.out.println("No");
    }
}


Measured memory_bytes: 26268
#include <stdio.h>
int main(void){
  int n,i,s;
  s=0;
  scanf("%d",&n);
  for(i=1;i<=n/2;i++){
    if(i != n-i){
	  s=s+1;
	}
  }
  printf("%d",s);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
import static java.lang.System.*;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  
	  int N = sc.nextInt(); //問題数
	  int M = sc.nextInt(); //解答した回数
	  int ACcount=0;
	  int WAcount = 0;
	  Set<Integer> corrected = new HashSet<>(); //既に正解した問題番号
	  int[] WA = new int[N+10];
	  for(int i=0; i<M; i++) {
		  int p = sc.nextInt();
		  String s = sc.next();
		  
		  if(corrected.contains(p)) 
			  continue;
		  if( s.equals("AC")) {
			  ACcount++;
			  corrected.add(p);
			  WAcount += WA[p];
		  } else if (s.equals("WA")) {
			  WA[p]++;
		  }
	  }
	  
	  out.println(ACcount + " " + WAcount);
	  
	}
  }	

Measured memory_bytes: 69172
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if a[0] > x:
    ans += a[0] - x
    a[0] = x
for i in range(1, n):
    d = a[i - 1] + a[i] - x
    if d > 0:
        ans += d
        a[i] -= d
print(ans)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

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

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

int lcs[3009][3009];
string a, b;

string call(int i, int j)
{
    if(i == 0 || j == 0)
        return "";
    if(a[i-1] == b[j-1])
        return call(i-1, j-1) + a[i-1];
    else if(lcs[i-1][j] >= lcs[i][j-1])
        return call(i-1, j);
    else
        return call(i, j-1);
}

int main()
{
    int i, j, n, m;
    cin >> a >> b;

    n = a.size();
    m = b.size();

    for(i = 0; i <= n; i++)
        lcs[i][0] = 0;
    for(i = 0; i <= m; i++)
        lcs[0][i] = 0;

    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= m; j++)
        {
            if(a[i-1] == b[j-1])
                lcs[i][j] = lcs[i-1][j-1] + 1;
            else
                lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
        }
    }

    cout << call(n, m);
}


Measured memory_bytes: 35968
// https://atcoder.jp/contests/abc170/tasks/abc170_f

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;
VL dx = {-1, 0, 1, 0};
VL dy = {0, 1, 0, -1};

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll H, W, K;
  cin >> H >> W >> K;
  ll si, sj, ti, tj;
  cin >> si >> sj >> ti >> tj;
  --si, --sj, --ti, --tj;

  V<string> mat(H);
  rep(i, H) cin >> mat[i];

  V<ll> dist(H * W * 4, INF);

  auto to_id = [&](ll i, ll j, ll dir) { return (i * W + j) * 4 + dir; };

  priority_queue<PL, VPL, greater<PL>> q;

  auto push = [&](ll i, ll j, ll dir, ll cost) {
    ll id = to_id(i, j, dir);

    if (dist[id] <= cost) return;

    dist[id] = cost;
    q.emplace(cost, id);
  };

  auto mod_ceil = [&](ll x) { return (x + K - 1) / K * K; };

  rep(dir, 4) push(si, sj, dir, 0);

  while (!q.empty()) {
    PL pa = q.top();
    q.pop();

    ll cost = pa.fi;
    ll id = pa.se;

    if (cost > dist[id]) continue;

    ll i = id / W / 4;
    ll j = id / 4 % W;
    ll dir = id % 4;

    rep(ndir, 4) { push(i, j, ndir, mod_ceil(cost)); }

    {
      ll ni = i + dy[dir];
      ll nj = j + dx[dir];

      unless(0 <= ni && ni < H && 0 <= nj && nj < W) continue;
      unless(mat[ni][nj] == '.') continue;
      push(ni, nj, dir, cost + 1);
    }
  }

  ll res = INF;
  rep(dir, 4) chmin(res, dist[to_id(ti, tj, dir)]);

  if (res == INF) drop(-1);

  res = mod_ceil(res) / K;
  cout << res << "\n";
}


Measured memory_bytes: 44112
#include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<complex>
#include<set>
#include<map>
#include<list>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
typedef vector<int>vec;
typedef vector<vec>mat;
const int INF = 0x3f3f3f3f;
const int Mod = 1e9 + 7;
const double eps = 1e-7;
int main() {
	int a[10];
	int n = 0;
	cin >> n;
	while (n--) {
		int flag = 0;
		memset(a, 0, sizeof(a));
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		for (int cnt = 0; cnt < 1024; cnt++) {//cnt :number of choices
			deque<int> B; deque<int> C;
			for (int i = 0; i < 10; i++) {
				if ((cnt >> i) & 1)B.push_front(a[i]);
				else C.push_front(a[i]);
			}
			reverse(B.begin(), B.end()); reverse(C.begin(), C.end());
			if (is_sorted(B.begin(), B.end()) && is_sorted(C.begin(), C.end())) {
				flag = 1;
				break;
			}
		}
		if (flag)puts("YES");
		else puts("NO");
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 3044
N,A,B,C,D=map(int,input().split())

if N%A==0:
    X=B*N//A
else:
    X=B*(N//A+1)

if N%C==0:
    Y=D*N//C
else:
    Y=D*(N//C+1)

if X<Y:
    print(X)
else:
    print(Y)



Measured memory_bytes: 5596
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                ans += 1
print(ans)

Measured memory_bytes: 3064
s = input()

w_cnt = 0
_b_cnt = 0
b_flag = False
cnt = 0
for si in list(s)[::-1]:
    if si == 'B':
        _b_cnt += 1
    if si == 'W':
        cnt += w_cnt * _b_cnt
        w_cnt += 1
        _b_cnt = 0
cnt += w_cnt * _b_cnt

print(cnt)


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

namespace ABC144
{
	class Program
	{
		static void Main(string[] args)
			
		{
			int a, b, max;
			var word = Console.ReadLine().Split(' ');
			a = int.Parse(word[0]);
			b = int.Parse(word[1]);
			max = a + b;
			if (max < a - b) max = a - b;
			if (max < a * b) max = a * b;
			Console.WriteLine(max);
			Console.ReadKey();
		}
	}
}

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

int r,c,d;
int h,w;
bool table[20][20][16][4];

void move(void){
  if(d == 0){
    w++;
    if(w == c)w = 0;
  }
  else if(d == 2){
    w--;
    if(w < 0)w = c-1;
  }
  else if(d == 3){
    h--;
    if(h < 0)h = r-1;
  }
  else if(d == 1){
    h++;
    if(h == r)h = 0;
  }
}

bool check(int h,int w,int m,int l){
  if(table[h][w][m][l])return false;
  else table[h][w][m][l] = true;
  return true;
}

int main(){
  string tmp;
  vector<string> map;
  int m,pos,flag;
  vector<int> qh,qw,qm,qd;

  m = 0;
  d = 0;
  h = 0;
  w = 0;

  cin >> r >> c;

  for(int i=0;i<r;i++){
    cin >> tmp;
    map.push_back(tmp);
  }

  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      for(int k=0;k<16;k++){
	for(int l=0;l<4;l++)table[i][j][k][l] = false;
      }
    }
  }

  qh.clear();
  qw.clear();
  qm.clear();
  qd.clear();
  pos = 0;

  while(1){
    if(!check(h,w,m,d)){
      if(pos == qh.size()){
	cout << "NO" << endl;
	return 0;
      }else{
	h = qh[pos];
	w = qw[pos];
	m = qm[pos];
	d = qd[pos];
	pos++;
      }
    }

    if(map[h][w] == '@'){
      cout << "YES" << endl;
      return 0;
    }else if(map[h][w] == '>'){
      d = 0;
    }else if(map[h][w] == 'v'){
      d = 1;
    }else if(map[h][w] == '<'){
      d = 2;
    }else if(map[h][w] == '^'){
      d = 3;
    }else if(map[h][w] == '_'){
      if(m)d = 2;
      else d = 0;
    }else if(map[h][w] == '|'){
      if(m)d = 3;
      else d = 1;
    }else if(map[h][w] == '+'){
      m++;
      if(m == 16)m = 0;
    }else if(map[h][w] == '-'){
      m--;
      if(m < 0)m = 15;
    }else if(map[h][w] == '?'){
      flag = 1;
      for(int i=0;i<qh.size();i++){
	if(h == qh[i] && w == qw[i] && m == qm[i]){
	  flag = 0;
	  break;
	}
      }
      if(flag){
	d = 0;
	qh.push_back(h);
	qw.push_back(w);
	qm.push_back(m);
	qd.push_back(1);

	qh.push_back(h);
	qw.push_back(w);
	qm.push_back(m);
	qd.push_back(2);

	qh.push_back(h);
	qw.push_back(w);
	qm.push_back(m);
	qd.push_back(3);
      }
    }else if(map[h][w] == '.'){
    }else{
      m = map[h][w] - '0';
    }

    move();
  }
  
  return 0;
}

Measured memory_bytes: 1412
#include <stdio.h>
#include <stdbool.h>
#define MAX_F 3001

bool x[MAX_F], y[MAX_F];

int main(void)
{
    int a, b, c, d, e, f;
    scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
    for (int i = 0; a * i <= f; i++)
        for (int j = 0; a * i + b * j <= f; j++)
            x[a * i + b * j] = true;
    for (int i = 0; c * i <= f; i++)
        for (int j = 0; c * i + d * j <= f; j++)
            y[c * i + d * j] = true;
    double pct = -1.0;
    int finx, finy;
    for (int i = 1; i <= f; i++) if (x[i]) {
            for (int j = 0; i * 100 + j <= f && j <= e * i; j++)
                if (y[j] && 100.0 * j / (i * 100.0 + j) > pct) {
                    pct = 100.0 * j / (i * 100.0 + j);
                    finx = i * 100;
                    finy = j;
                }
    }
    printf("%d %d\n", finx + finy, finy);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<set>
using namespace std;
int main(void){
    int n; cin >> n;
    set <string> S;
    string s;
    
    for (int i = 0; i < n; i++){
        cin >> s;
        S.insert(s);
    }
    
    cout << S.size() << endl;
}

Measured memory_bytes: 19244
open Buffer
let a, b = Scanf.scanf " %s %s" @@ fun a b -> a, b
let n, m = String.length a, String.length b
let ma = max n m
let a', b' = create ma, create ma
let _ =
  List.iter (fun (b, s, l) -> add_string b @@ String.make (ma - l) '0'; add_string b s) [a', a, n; b', b, m];
  print_endline @@ if a' > b' then "GREATER" else if a' < b' then "LESS" else "EQUAL"

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstdio>
using namespace std;
#define PI acos(-1,0)
#define eps 1e-10
#define ll long long
#define mst(ss,b) memset((ss),(b),sizeof(ss))

int main()
{
    double n;
    int a=0;
    cin>>n;
    while(n>=2){
        a++;
        n=n/2;
    }
    int s=1;
    for(int i=1;i<=a;i++){
        s=s*2;
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, x, y, ans;
	cin >> n >> x >> y;
	if ((x > n) || (y > n)) ans = 0;
	else ans = (n + 1 - x) * (n + 1 - y);
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 888
<?php
  fscanf(STDIN, "%d %d", $n,$k);
  $arr = array_map('intval', explode(" ", trim(fgets(STDIN))));
  //print_r(array_slice($arr, 0, $k));
  $cnt=$n-$k;
//echo $cnt;
for($i=0;$i<$cnt;++$i){
  $a=$i+$k;
  if($arr[$i]<$arr[$a]){
   // echo $i." ".$arr[$i]." ".$a." ".$arr[$a]."\n";
    echo "Yes\n";
}else{
   // echo $i." ".$arr[$i]." ".$a." ".$arr[$a]."\n";
        echo "No\n";
  
}
}
?>

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

public class Main {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null; }
        String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try { tokenizer = new StringTokenizer(reader.readLine()); } 
                catch (IOException e) { throw new RuntimeException(e);} }
            return tokenizer.nextToken(); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = r.nextInt();
        pw.println(n*n*n);
        pw.close();
    }
}

/**
                _        _                 _                                                
               | |      | |               | |                                               
   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___  
  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \ 
 | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/ 
                                __/ |                               ______ __/ |            
                               |___/                               |______|___/             
 */

Measured memory_bytes: 22996
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=1000;i++){
		    if (i * 8/100 == a && i * 10/100 == b) {
            cout << i << endl;
            return 0;
        }
	}	
		cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

/* ??????????????? (0????????????) */
int selectionSort(int A[], int N) {
  int i, j, t, sw = 0, mini;
  for(i=0;i<N-1;i++) {
    mini = i;
    for(j=i; j<N; j++) {
      if(A[j] < A[mini]) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
    if(i!=mini) sw++;
  }
  return sw;
}

int main(void) {
  int A[100], N, i, sw;
  scanf("%d", &N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  sw = selectionSort(A,N);

  for(i=0;i<N;i++) {
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <tr1/unordered_map>
using namespace std;

#define map tr1::unordered_map

struct NODE{
	string to;
	int cost;
	NODE(string to,int cost): to(to) , cost(cost) {}
};
bool operator < (const NODE &a, const NODE &b){
		return a.cost > b.cost;
}


int main(){
	int n , m;
	while(cin >> n >> m && n){
		map<string,vector<NODE> > v;
		string A,B,C;
		cin >> A >> B >> C;
		for(int i = 0 ; i < m ; i++){
			string a,b; int c,d; cin >> a >> b >> c >> d;
			c = c / 40 + d;
			v[a].push_back(NODE(b,c));
			v[b].push_back(NODE(a,c));
		}
		map<string,int> done[3];
		priority_queue<NODE> Q;
		Q.push(NODE(A,0));
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if(done[0].count(q.to))continue;
			else done[0][q.to] = q.cost;
			for(int i = 0 ; i < v[q.to].size() ; i++){
				Q.push(NODE(v[q.to][i].to,q.cost+v[q.to][i].cost));
			}
		}
		Q.push(NODE(C,0));
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if(done[2].count(q.to))continue;
			else done[2][q.to] = q.cost;
			for(int i = 0 ; i < v[q.to].size() ; i++){
				Q.push(NODE(v[q.to][i].to,q.cost+v[q.to][i].cost));
			}
		}
		cout << done[0][B] + done[2][B] << endl;
		
		
	}
}

Measured memory_bytes: 1512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   string s;
           cin>>s;
           int n=s.size();
           rep(i,0,n){
            if(s[i]==',')s[i]=' '; 
           }
           cout<<s<<endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;

#define dump(x) (cerr << #x << " = " << (x) << endl)
#define dump2(x, y) (cerr << "(" << #x << ", " << #y << ") = (" << (x) << ", " << (y) << ")" << endl)

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPI(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)

#define ALL(v) v.begin(), v.end()

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

const int MAX = 1010;
const int HALF = MAX / 2;
const int LIMIT = 1000000;

int x, y;
int field[MAX][MAX];
int dp[MAX][MAX];
int lp[MAX][MAX];

vector<bool> sieve(int n) {
	vector<bool> prime(n, true);
	prime[0] = prime[1] = false;
	for(int i = 2; i < n; ++i) {
		if(prime[i]) {
			for(int j = i * 2; j < n; j += i)
				prime[j] = false;
		}
	}
	return prime;
}

void make_field() {
	const int INF = 0xfffffff;
	fill(field[0], field[0] + MAX * MAX, INF);
	field[HALF][HALF] = 1;
	x = HALF + 1;
	y = HALF;
	for(int num = 2, d = 0; num <= LIMIT; ++num) {
		field[y][x] = num;
		const int left = (d + 1) % 4;
		if(field[y + dy[left]][x + dx[left]] == INF)
			d = left;

		x += dx[d];
		y += dy[d];
	}
}

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

	vector<bool> is_prime = sieve(LIMIT + 1);
	make_field();

	for(int m, n; cin >> m >> n, m;) {
		int mnX = MAX, mnY = MAX, mxX = -1, mxY = -1;
		for(int i = 0; i < MAX; ++i) {
			for(int j = 0; j < MAX; ++j) {
				if(field[i][j] <= m) {
					mnX = min(mnX, j);
					mnY = min(mnY, i);
					mxX = max(mxX, j);
					mxY = max(mxY, i);

					if(field[i][j] == n) {
						x = j;
						y = i;
					}
				}
			}
		}

		memset(dp, -1, sizeof(dp));
		memset(lp, -1, sizeof(lp));
		dp[y][x] = 0;
		for(; y <= mxY; ++y) {
			for(; x <= mxX; ++x) {
				if(field[y][x] > m || dp[y][x] == -1)
					continue;

				if(is_prime[field[y][x]]) {
					++dp[y][x];
					lp[y][x] = field[y][x];
				}

				for(int k = -1; k <= 1; ++k) {
					if(dp[y + 1][x + k] < dp[y][x]) {
						dp[y + 1][x + k] = dp[y][x];
						lp[y + 1][x + k] = lp[y][x];
					}
				}
			}
			x = mnX;
		}

		int mx = 0, last = -1;
		for(x = mnX; x <= mxX; ++x) {
			y = mxY;
			if(field[y][x] > m) {
				--y;
			}

			if(mx < dp[y][x] || (mx == dp[y][x] && last < lp[y][x])) {
				mx = dp[y][x];
				last = lp[y][x];
			}
		}

		if(mx == 0)
			cout << "0 0" << endl;
		else
			cout << mx << " " << last << endl;
	}

	return 0;
}

Measured memory_bytes: 13284
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	string s;
  	cin >> s;
  int sum=0;
  for(int i=0;i<s.length();i++)
    	sum+=s[i]-'0';
  if(sum%9==0)
    cout << "Yes";
  else
    cout <<"No";
    
    return 0;
}

Measured memory_bytes: 3788
module Main where
import Control.Applicative((<$>))
import Data.List(sort)


main :: IO ()
main = do
  (w:h:x:y:r:_) <-  (map atoi ) <$> words <$> getLine
  putStrLn $ solve (w,h) (x,y,r)
  where
    atoi x = read x :: Int

solve :: (Int, Int) -> (Int, Int, Int) -> String
solve (w,h) (x,y,r) = if (left && right && bottom && top )
                         then "Yes"
                         else "No"
  where
    left = x - r  >= 0
    right = x + r <= w
    bottom = y - r  >= 0
    top = y + r <= h

Measured memory_bytes: 3612
/*优先队列
https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/9/ALDS1_9_C
insert 8
insert 2
extract
insert 10
extract
insert 11
extract
extract
end
*/
#include<iostream>
#include<cstring> 
using namespace std;
const int N=2000001;
const int INF=0x3f3f3f;
int a[N];
int h;
string opr; 
int key;
void maxHeapify(int *a,int root){
	int l=root*2;
	int r=root*2+1;
	int largest=root;
	if(l<=h&&a[l]>a[root])
		largest=l;
	if(r<=h&&a[r]>a[largest])
		largest=r;	
	if(largest!=root){
		swap(a[root],a[largest]);
		maxHeapify(a,largest);
	}	
}
void heapIncreaseKey(int *a,int i,int key){
	if(key<a[i])
		printf("error:new key < current key!\n");
	a[i]=key;
	while(i>1&&a[i/2]<a[i]){
		swap(a[i/2],a[i]);
		i/=2;
	}	
}
void insert(int key){
	h++;
	a[h]=-INF;
	heapIncreaseKey(a,h,key); 
}
int heapExtractMax(int *a){
	if(h<1)
		printf("error:the heap is empty!\n");
	int max=a[1];
	a[1]=a[h];
	h--;
	maxHeapify(a,1);
	return max;	
}
int main(){
	h=0;
while(cin>>opr){
	if(opr.compare("insert")==0){
		scanf("%d",&key);
		insert(key);
	}else if(opr.compare("extract")==0){
		printf("%d\n",heapExtractMax(a));
	}else if(opr.compare("end")==0){
		break;
	}
}	
	return 0;
} 


Measured memory_bytes: 7108
k=int(input())
if k==1 or k==7:
    print(1)
    exit()

ans = 1
amari = 7%k
s = amari

for i in range(k):
    ans += 1
    amari = amari*10 % k
    s += amari
    s %= k
    if s==0:
        print(ans)
        exit()
    
print(-1)


Measured memory_bytes: 9176
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

const lld N = 200043;
const lld MOD = 1000000007;

lld add(lld x, lld y)
{
    x =((x%MOD)+(y%MOD))%MOD;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

lld mul(lld x, lld y)
{
    return ((x%MOD)*(y%MOD))% MOD;
}

lld binpow(lld x, lld y)
{
    lld z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

lld inv(lld x)
{
    return binpow(x, MOD - 2);
}

lld divide(lld x, lld y)
{
    return mul(x, inv(y));
}

// Combinations

/*
lld fact[N];

void precalc()
{
    fact[0] = 1;
    for(lld i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

lld C(lld n, lld k)
{
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t,i,j;
    //cin>>t;
    t=1;
    while(t--)
    {   lld a,b,c;
        cin>>a>>b>>c;
        if((a/((double)c))<=b)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}





Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct CumulativeSum{
    vector<int> data;
    CumulativeSum(int sz) : data(sz, 0) {};
    void add(int k, int x){
        data[k] += x;
    }
    void build(){
        for(int i = 1; i < data.size(); i++){
            data[i] += data[i - 1];
        }
    }
    int query(int k){
        if(k < 0) return 0;
        return (data[min(k, (int)data.size() - 1)]);
    }
    int query(int l, int r){
        return query(r - 1) - query(l - 1);
    }
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    vector<CumulativeSum> cs(10, CumulativeSum(n));
    rep(i, 0, n){
        cs[s[i] - '0'].add(i, 1);
    }
    rep(i, 0, 10){
        cs[i].build();
    }
    set<string> st;
    rep(i, 1, n - 1){
        rep(j, 0, 10){
            rep(k, 0, 10){
                if(cs[j].query(0, i) && cs[k].query(i + 1, n)){
                    string tmp = "";
                    tmp += '0' + j;
                    tmp += '0' + s[i];
                    tmp += '0' + k;
                    st.insert(tmp);
                    // cout << i << " " << j << " " << k << " " << tmp << endl;
                }
            }
        }
    }
    cout << st.size() << endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int H,W;
    cin >> H >> W;

    int count[26]={};
    rep(i,0,H){
        string a;
        cin >> a;
        rep(j,0,W) ++count[a[j]-'a'];
    }

    int x=0,y=0,z=0;
    rep(i,0,H) rep(j,0,W){
        if(H%2 and W%2 and i==H/2 and j==W/2) ++x;
        else if((H%2 and i==H/2) or (W%2 and j==W/2)) ++y;
        else ++z;
    }

    while(z){
        bool ok=false;
        rep(i,0,26) if(count[i]>=4){
            ok=true;
            count[i]-=4;
            z-=4;
            if(z==0) break;
        }
        if(!ok){
            cout << "No" << endl;
            return;
        }
    }

    while(y){
        bool ok=false;
        rep(i,0,26) if(count[i]>=2){
            ok=true;
            count[i]-=2;
            y-=2;
            if(y==0) break;
        }
        if(!ok){
            cout << "No" << endl;
            return;
        }
    }

    while(x){
        bool ok=false;
        rep(i,0,26) if(count[i]>=1){
            ok=true;
            count[i]-=1;
            x-=1;
            if(x==0) break;
        }
        if(!ok){
            cout << "No" << endl;
            return;
        }
    }

    cout << "Yes" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	int[] suretu = new int[32];
	suretu[0] = 1;
	suretu[1] = 1;
	suretu[2] = 1;
	suretu[3] = 2;
	suretu[4] = 1;
	suretu[5] = 2;
	suretu[6] = 1;
	suretu[7] = 5;
	suretu[8] = 2;
	suretu[9] = 2;
	suretu[10] = 1;
	suretu[11] = 5;
	suretu[12] = 1;
	suretu[13] = 2;
	suretu[14] = 1;
	suretu[15] = 14;
	suretu[16] = 1;
	suretu[17] = 5;
	suretu[18] = 1;
	suretu[19] = 5;
	suretu[20] = 2;
	suretu[21] = 2;
	suretu[22] = 1;
	suretu[23] = 15;
	suretu[24] = 2;
	suretu[25] = 2;
	suretu[26] = 5;
	suretu[27] = 4;
	suretu[28] = 1;
	suretu[29] = 4;
	suretu[30] = 1;
	suretu[31] = 51;
	int k = sca.nextInt();

	System.out.println(suretu[k-1]);

	// 後始末
	sca.close();
	}
}




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

int main() {
	string s;
	cin >> s;

	bool bl = false;
	for(int i = 0; i < s.size(); ++i) {
		if(s[i] == '7') bl = true; 
	}

	cout << (bl ? "Yes":"No") << endl;
	
	return 0;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set>
#include<stdlib.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
vector<long long> Prime;
void SieveOfEratosthenes(long long e) //setup vector<long long>Prime(~x)
{
	bool *x=new bool[e];
	for (long long i = 0; i <= e; i++)x[i] = false;
	for (long long i = 2; i <= e; i++)
	{
		if (x[i]);
		else
		{
			Prime.push_back(i);
			for (long long l = i; l <= e; l += i)x[l] = true;
		}
	}
	return;
}
struct XY
{
	int x;
	int y;
};
int in()
{
	int x;
	cin >> x;
	return x;
}
/*
(char)'1' - (int)48 = (int)1;
???1111181
*/
////////////////////////////////////////////////////



int main()
{
	SieveOfEratosthenes(10000000);
	int n;
	while (cin >> n&&n)
	{
		if (binary_search(Prime.begin(), Prime.end(), n))
		{
			cout << 0 << endl;
		}
		else
		{
			cout << *lower_bound(Prime.begin(), Prime.end(), n) - *(lower_bound(Prime.begin(), Prime.end(), n) - 1) << endl;
		}


	}
	
}

Measured memory_bytes: 19048