akhauriyash/Code-Regression huggingface dataset:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    S = input()
    count = 0
    for i in S:
        if i == 'R':
            count += 1
    if count == 0:
        print(0)
    elif count == 1:
        print(1)
    elif count == 3:
        print(3)
    else:
        if S[1] == 'R':
            print(2)
        else:
            print(1)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 72768
import java.io.*;
import java.util.*;
public class Main {
 
  public static void main(String[] args) { 
        solve();
      out.close();
  }

  private static void solve() {
      int h = sc.nextInt();
      int w = sc.nextInt();
      int sx = sc.nextInt() - 1;      
      int sy = sc.nextInt() - 1;
      int tx = sc.nextInt() - 1;
      int ty = sc.nextInt() - 1;

      char[][] grid = new char[h][w];
      int[][] dp = new int[h][w];
      for(int i = 0; i < h; i++) {
        grid[i] = sc.next().toCharArray();
        Arrays.fill(dp[i], 1_000_000_000);
      }

      dp[sx][sy] = 0;
      int[] rows = new int[]{-1, 1, 0, 0};
      int[] cols = new int[]{0, 0, -1, 1};

      ArrayDeque<int[]> queue = new ArrayDeque<>();
      queue.offer(new int[]{sx, sy});

      while(queue.size() > 0) {
        int[] pos = queue.poll();
        int curX = pos[0];
        int curY = pos[1];
        if(curX == tx && curY == ty) break;
        for(int j = 0; j < 4; j++) {
          int next_x = curX + rows[j];
          int next_y = curY + cols[j];
          if(!isValid(grid, next_x, next_y)) continue;
          if(dp[next_x][next_y] > dp[curX][curY]) {
               dp[next_x][next_y] = dp[curX][curY];
               queue.addFirst(new int[]{next_x, next_y});
          }
        }

        for(int i = curX-2; i <= curX+2; i++) {
          for(int j = curY-2; j <= curY+2; j++) {
            if(!isValid(grid, i, j)) continue;
            if(dp[i][j] > dp[curX][curY] + 1) {
               dp[i][j] = dp[curX][curY] + 1;
               queue.addLast(new int[]{i, j});
            }
          }
        }
      }
      out.println(dp[tx][ty] >= 1_000_000_000 ? -1 : dp[tx][ty]);
  }

  private static boolean isValid(char[][] grid, int row, int col) {
    if(row < 0 || row >= grid.length || col < 0 || col >= grid[row].length || grid[row][col] == '#')
      return false;
 
    return true;
  }

  public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
 
  public static FastScanner sc = new FastScanner();

  static class FastScanner {
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st=new StringTokenizer("");
      String next() {
        while (!st.hasMoreTokens())
          try {
            st=new StringTokenizer(br.readLine());
          } catch (IOException e) {
            e.printStackTrace();
          }
        return st.nextToken();
      }
      
      int nextInt() {
        return Integer.parseInt(next());
      }
      int[] readArray(int n) {
        int[] a=new int[n];
        for (int i=0; i<n; i++) a[i]=nextInt();
        return a;
      }
      long nextLong() {
        return Long.parseLong(next());
      }
  }

}


Measured memory_bytes: 59316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	vector<ll> h(26);
	for(const char c : s){ ++h[c - 'a']; }
	ll answer = 1;
	for(const char c : s){
		const int k = c - 'a';
		--h[k];
		for(int i = 0; i < 26; ++i){
			if(i != k){ answer += h[i]; }
		}
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 720
#include<iostream>
#include<cmath>

using namespace std;

int number=0;
int input[10000];
int answer=0;

int main(){
    cin>>number;
    for (int i=0; i<number; i++) {
        cin>>input[i];
    }
    for (int i=0; i<number; i++) {
        if (input[i]==1) {
            break;
        }
        int j = floor(sqrt(input[i]));
        while (j>1) {
            if (input[i]%j==0) {
                break;
            }
            j--;
        }
        if (j==1) {
            answer++;
        }
    }
    cout<<answer<<endl;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <queue>

typedef long long int ll;

using namespace std;

int N, M;


int main()
{
	priority_queue<ll> costs;
	cin >> N >> M;
	ll cost, maxCost, sumCost = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> cost;
		costs.push(cost);
	}
	for (int i = 0; i < M; i++)
	{
		maxCost = costs.top();
		costs.pop();
		// 半額に
		costs.push(maxCost / 2);
	}
	for (int i = 0; i < N; i++)
	{
		sumCost += costs.top();
		costs.pop();
	}
	cout << sumCost;
}

Measured memory_bytes: 1400
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(void)
{
    int n;
    int t, a, h;
    int ave;

    cin >> n >> t >> a;

    int min = 1 << 30;
    int min_index = 1;
    for (int i = 1; i <= n; i++) {
        cin >> h;
        ave = t * 1000 - h * 6;
        if (min > abs(ave-a*1000)) {
            min = abs(ave-a*1000);
            min_index = i;
        }
    }

    cout << min_index << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
main () {
	cin>>s;

	if (s[0]=='0' || s[s.size()-1]=='1') { cout<<-1<<endl; return 0; }

	for (int i=0; i<=s.size()-i-2; i++) 
		if (s[i]!=s[s.size()-i-2]) { cout<<-1<<endl; return 0; }

	int cnt=1,last=1;
	for (int i=0; i<s.size()-1; i++) 
		if (s[i]=='1') { cout<<cnt<<" "<<i+2<<endl; cnt=i+2; }
				  else cout<<cnt<<" "<<i+2<<endl;
}

Measured memory_bytes: 1664
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 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:
                count += 1                
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll N , M , K ;
    cin >> N >> M  >> K ; 
    ll l = 0;
    ll r = 0;

    rep(i, M){
        ll inp; cin >> inp;
        if(inp < K) l ++;
        else if(inp > K)r ++;
    }

    cout << min(l, r) << endl;


    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	double x1,y1,r1,x2,y2,r2,d2;
	int ans,n,i;

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&r1,&x2,&y2,&r2);
		d2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		
		if(d2>=(r1-r2)*(r1-r2)&&d2<=(r1+r2)*(r1+r2)){ans=1;}
		if(d2>(r1+r2)*(r1+r2)){ans=0;}
		if(d2<(r1-r2)*(r1-r2))
		{
			if(r1>r2){ans=2;}
			else{ans=-2;}
		}

		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<"  "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

ll fact[1001];
ll inv[10001];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,d;
	cin >> n >> d;
	cout << n/(2*d + 1) + bool(n%(2*d + 1));
	return 0;
}

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

using namespace std;

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

    int naj = 0;

    int now = 0;

    for(int i = 0; i < n; i++)
    {

        int a;
        cin>>a;
        if(i == 0)
            naj = a;

        now +=a;
        if(a < naj) naj = a;

    }

    int don = x - now;

    int licz = n;

    while(don >= naj)
    {

    licz++;
    don = don - naj;

    }

    cout<<licz;




    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    ll N, X, M;
    cin >> N >> X >> M;

    auto f = [&](ll A){
        return A*A%M;
    };

    vec<ll> cycle;
    unordered_map<ll,ll> mp;
    ll now = X;
    ll tail = X;
    ll tailcnt = 1;
    ll roop = 0;
    while(true){
        now=f(now);
        if(mp[now]==1){
            cycle.push_back(now);
            roop+=now;
            mp[now] = 2;
        } else if(mp[now] == 0){
            ++tailcnt;
            mp[now] =1;
            tail+=now;
        } else {
            break;
        }
    }

    int roopcnt = cycle.size();

    ll ans = 0;
    if(N<=tailcnt){
        ll n = X;
        ans = X;
        rep(i,N-1){
            n=f(n);
            ans+=n;
        }
    } else {
        // cout << tail << " " << tailcnt << " " << roop << " " << roopcnt << endl;
        ans = tail;
        N-=tailcnt;
        ans += (N/roopcnt)*roop;
        N=N%roopcnt;
        rep(i,N){
            ans+=cycle[i];
        }
    }
        cout << ans << '\n';

}


Measured memory_bytes: 6072
function Main(input) {
  input = input.split(' ').map( n => parseInt(n, 10) );
  const n = input[0];
  const y = input[1];
  let ans = "-1 -1 -1"
  for (var a_i = 0; a_i <= n; a_i++) {
    for (var b_i = 0; a_i + b_i <= n; b_i++) {
      for (var c_i = 0; a_i + b_i + c_i <= n; c_i++) {
        if ((a_i + b_i + c_i === n) &&
            (10000*a_i + 5000*b_i + 1000*c_i === y)) {
          ans = `${a_i} ${b_i} ${c_i}`;
          break;
        }
      }
    }
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 32616
// Problem : A - Calc
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n;
    cin>>n;
    cout<<n+n*n+n*n*n;
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
using namespace std;
char a[60];
int main()
{
	int n,k,i;
	cin>>n>>k;
    cin>>a;
    if(a[k-1]=='A')
    a[k-1]='a';
    else if(a[k-1]=='B')
    a[k-1]='b';
    else
    a[k-1]='c';
    for(i=0;i<n;i++)
    cout<<a[i];
    return 0;
}

Measured memory_bytes: 256
import atexit
import io
import sys

_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER


@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

import math
R = lambda : map(int,input().split())
ans = sys.maxsize
n,k = R()
for i in range(n,k):
    for j in range(i+1,k+1):
        ans = min(ans,(i*j)%2019)
        if ans==0:
            print(ans)
            exit()

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
  vector<int> p(a+1), q(b+1), r(c+1);
  p[a] = q[b] = r[c] = -1;
  for(int i = 0; i < a; i++){
    cin >> p[i];
  }
  for(int i = 0; i < b; i++){
    cin >> q[i];
  }
  for(int i = 0; i < c; i++){
    cin >> r[i];
  }
  vector<pair<int, int>> v;
  for(int i = 0; i < a; i++){
    v.push_back({p[i], 0});
  }
  for(int i = 0; i < b; i++){
    v.push_back({q[i], 1});
  }
  for(int i = 0; i < c; i++){
    v.push_back({r[i], 2});
  }
  sort(v.rbegin(),v.rend());

  int A = 0, B = 0, C = 0;
  for(int i = 0; i < x + y; i++){
    if(v[i].second == 0) A++;
    if(v[i].second == 1) B++;
    if(v[i].second == 2) C++;
  }
  sort(p.rbegin(),p.rend());
  sort(q.rbegin(),q.rend());
  sort(r.rbegin(),r.rend());

  int ans = 0;
  int D;
  if(A > x){
    D = A - x;
    A = x;
    for(int i = 0; i < A; i++){
      ans += p[i];
    }
    for(int i = 0; i < B; i++){
      ans += q[i];
    }
    for(int i = 0; i < C; i++){
      ans += r[i];
    }

    while(D--){
      if(q[B] > r[C]){
        ans += q[B++];
      }else{
        ans += r[C++];
      }
    }
  }else if(B > y){ //B > y
    D = B - y;
    B = y;
    for(int i = 0; i < A; i++){
      ans += p[i];
    }
    for(int i = 0; i < B; i++){
      ans += q[i];
    }
    for(int i = 0; i < C; i++){
      ans += r[i];
    }
    while(D--){
      if(p[A] > r[C]){
        ans += p[A++];
      }else{
        ans += r[C++];
      }
    }
  }else{
    for(int i = 0; i < A; i++){
      ans += p[i];
    }
    for(int i = 0; i < B; i++){
      ans += q[i];
    }
    for(int i = 0; i < C; i++){
      ans += r[i];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12524
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int w, h;
	boolean[][] map;
	int cnt;
	int max;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int w = sc.nextInt();
			int h = sc.nextInt();
			if( (w|h) == 0 ) break;
			map = new boolean[h+2][w+2];
			for(int i=1;i<=h;i++) for(int j=1;j<=w;j++)
				map[i][j] = sc.nextInt() == 1;
			max = 0;
			for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) {
				cnt = 0;
				if(map[i][j]) dfs(i, j);
			}
			System.out.println(max);
		}
	}
	int dx[] = {-1, 0, 1, 0};
	int dy[] = {0, -1, 0, 1};
	void dfs(int x, int y) {
		cnt++;
		max = max(cnt, max);
		map[x][y] = false;
		for(int i=0;i<4;i++) {
			if(map[ x+dx[i] ][y+dy[i]]) dfs(x+dx[i], y+dy[i]);
		}
		map[x][y] = true;
		cnt--;
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
n = int(input())
i = 2
print(str(n)+":",end = "")

while True:
  if n%i == 0:
    n //= i
    print("",i,end = "")
    i = 2
    if n == 1:
      print("")
      break
    continue
  if i > n**0.5:
    print("",n)
    break
  i += 1


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

using namespace std;

int dp[100001];

int main()
{
	int n; cin >> n;
	vector<int> height(n);
	for (auto& el : height) cin >> el;

	dp[1] = abs(height[0] - height[1]);
	for (auto i = 2; i < n; i++)
		dp[i] = min(dp[i - 2] + abs(height[i - 2] - height[i]), dp[i - 1] + abs(height[i - 1] - height[i]));

	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        sc.close();

        int tmp = K;
        int times = 1;
        boolean results = false;
        while (tmp <= B) {
            if (tmp <= B && tmp >= A) {
                results = true;
                break;
            }
            times++;
            tmp = times * K;
        }

        if (results) {
            System.out.println("OK");
        } else {
            System.out.println("NG");
        }
    }
}


Measured memory_bytes: 35708
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x=0;
	cin>>n>>m;
	int a,b,c[n],d[n];
	for(int i=0;i<n;i++){
		c[i]=1;
		if(i)d[i]=0;
		else d[i]=1;
	}
	for(int i=0;i<m;i++){
		cin>>a>>b;
		a--;
		b--;
		if(d[a]==1){
			if(c[a]==1)d[a]=0;
			d[b]=1;
		}
		c[a]--;
		c[b]++;
	}
	for(int i=0;i<n;i++){
		if(d[i])x++;
	}
	cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int H, W, N;
	cin >> H >> W >> N;

	if(H>W){
		cout << (N+H-1) / H << endl;
	} else {
		cout << (N+W-1) / W << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>Set;
typedef tree<int,int,less<int>,rb_tree_tag,tree_order_statistics_node_update> Map;

#define ipow(a,b)+0.5 (int)pow(a,b)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fi first
#define se second
#define pll pair<ll,ll>
#define ook order_of_key
#define findby find_by_order
#define pii pair<int,int>

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

template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
template<typename X> inline X sqr(const X& a) { return (a * a); }

const ld EPS = ld(1e-9);
const ld PI = ld(3.141592653589);

struct comp
{
    bool operator()(pii a, pii b)
    {
        if(a.fi<b.fi)
        return true;
        else if (a.fi>b.fi)
        return false;
        else
        {
             if(a.se<b.se)
             return true;
             else
             return false;
        }
    }
};

map<int,pii>check;
vector<pii>store;
vector<int>res;

class Task
{
public:
    void solve(istream& in,ostream& out)
    {
          int n,m;
          in>>n>>m;

          int a,b;

          rep(i,n)
          {
                in>>a>>b;
                store.pb(mp(a,b));
          }

          rep(i,m)
          {
                in>>a>>b;
                check.insert(mp(i+1,mp(a,b)));
          }

          for(auto j=store.begin();j!=store.end();j++)
          {
                pii A=*j;

                ll mini=mod;
                ll store=0;
                for(auto h=check.begin();h!=check.end();h++)
                {
                      pii B=(*h).se;

                      if(dist(A,B)<mini)
                      {
                           mini=dist(A,B);
                           store=(*h).fi;
                      }
                }

                res.pb(store);
          }

          rep(i,n)
          {
                out<<res[i]<<endl;
          }
    }

    int dist(pii a, pii b)
    {
          return abs(a.fi-b.fi)+abs(a.se-b.se);
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Task solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in,out);
	out.flush();

    return 0;
}





Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division, print_function
from sys import stdin


def max_heapify(a, i, heap_size):
    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest, heap_size)


def build_max_heap(a, heap_size):
    for i in range(heap_size//2, 0, -1):
        max_heapify(a, i, heap_size)


heap_size = int(stdin.readline())
assert heap_size <= 500000
data = [0]
data.extend(int(s) for s in stdin.readline().split())
build_max_heap(data, heap_size)
print('', *data[1:])

Measured memory_bytes: 51316
n, k = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n-1):
    a[i+1] += a[i]

b = []
for i in range(n-1):
    for j in range(i+1, n):
        b.append(a[j] - a[i])
for i in range(n):
    b.append(a[i])

ans = 0
for m in range(40, -1, -1):
    count = 0
    for i in range(len(b)):
        if ((b[i] >> m) & 1) == 1:
            count += 1
    if count >= k:
        ans += (1 << m)
        c = []
        for i in range(len(b)):
            if ((b[i] >> m) & 1) == 1:
                c.append(b[i])
        b = c

print(ans)

Measured memory_bytes: 66684
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MAX int(2* 1e5 +5)


int main(){
    int n;
    cin >> n;
    llong A[MAX];
    REP(i,n) scanf("%lld",&A[i]);
    llong rui[MAX];
    rui[0] = 0;
    REP(i,n) rui[i+1] = rui[i] + A[i];
    map<llong,llong> m;
    REP(i,n+1){
        if(m.find(rui[i]) == m.end() ) m[rui[i]] = 1;
        else m[rui[i]] += 1;
    }
    llong ans = 0;
    itrfor(itr,m){
        if( (*itr).second <2) continue;
        else ans += (*itr).second * ((*itr).second -1 ) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
def _input():
    number = input()
    array = input().split()
    number_array = []
    for i in array:
        number_array.append(int(i))
    return number_array

def sum(array):
    total = 0
    for i in array:
        total += (1 / i)
    return total

def output(number):
    return (1 / number)


if __name__ == "__main__":
    number_array = _input()
    total = sum(number_array)
    print(output(total))



Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main(){

  int A, B, K;
  cin >> A >> B >> K;

  int counter = 0;

  for(int i = min(A, B); i > 0; i--){
    if((A % i == 0)&&(B % i == 0)){
      counter++;
    }
    if(counter==K){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second

signed main(){
    int a,b;
    cin>>a>>b;
    if((a+b)%2)puts("IMPOSSIBLE");
    else cout<<(a+b)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
line=input().split(" ")
a=int(line[0])
b=int(line[1])
c=int(line[2])
d=int(line[3])

while a>0 and c>0:
  c=c-b
  if c<=0:
    print("Yes")
    break
  a=a-d
  if a<=0:
    print("No")
    break

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

import sys
import time
from collections import deque

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 ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

start = time.time()

N = INT()
A = [deque()]
for i in range(N):
    A.append(deque(LIST()))

cnt = N*(N-1)//2
day = 0
while cnt > 0:
    prev = cnt
    skip = [False] * (N+1)
    for i in range(1, N+1):
        if len(A[i]) and not skip[i]:
            a = A[i][0]
            if len(A[a]) and not skip[a]:
                b = A[a][0]
                if i == b:
                    A[i].popleft()
                    A[a].popleft()
                    cnt -= 1
                    skip[i] = skip[a] = True
    if prev == cnt:
        print(-1)
        exit()
    day += 1

    elapsed_time = time.time() - start
    if elapsed_time > 1:
        print(N*(N-1)//2)
        exit()
print(day)


Measured memory_bytes: 36080
import kotlin.math.abs
import kotlin.math.min

fun main() {
  val (n,k) = readLine()!!.split(' ').map { it.toInt() }
  val h = readLine()!!.split(' ').map { it.toInt() }
  val dp = IntArray(n+1){1000000001}
  dp[0] = 0

  for(i in 1 until n){
    for (j in 1..min(k, i)){
      dp[i] = min(dp[i], dp[i-j]+ abs(h[i]-h[i-j]))
    }
  }
  println(dp[n-1])
}

Measured memory_bytes: 50944
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, s[110000], ans[110000];
int main() {
	cin >> n;
	REP(i, n) {
		cin >> s[i];
		if (i % 2 == 0)ans[0] += s[i];
		else ans[0] -= s[i];
	}
	REPR(i, n) {
		ll j = (i + 1) % n;
		ll k = (i - 1 + n) % n;
		ans[i] = min(s[i] - ans[j] / 2, s[k]) * 2;
	}
	REP(i, n) {
		if (i != 0)cout << " ";
		cout << ans[i];
	}
	cout << endl;
}


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

using namespace std;

int main(){
    int k, n, i;
    cin >> k >> n;
    int v[n];
    for(i = 0; i < n; i++){
        cin >> v[i];
    }
    int aux;
    aux = k - (v[n-1] - v[0]);

    for(i = 1; i < n; i++){
        aux = max(aux,v[i]-v[i-1]);
    }
    cout << k - aux << endl;

    return 0;
}

Measured memory_bytes: 4412
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
int main()
{
    long long a, b, p;
    std::string bs;
    std::cin >> a >> bs;
    int i = 1;
    b = (bs[0] - '0') * 100ll + (bs[2] - '0') * 10ll + (bs[3] - '0') * 1ll;
    long long ans = (a * b / 100);
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int sum = 0, a, sum_diag = 0;;
	for (int i = 0; i < 9; i++) {
		cin >> a;
		if (i % 4 == 0) sum_diag += a;
		sum += a;
	}
	if (sum % 3 == 0&&sum/3==sum_diag)cout << "Yes";
	else cout << "No";

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    int a;
    cin>>a;
    vector<int> vec1(a);
    vector<int> vec2(a);
    rep(i,a){
        cin>>vec1.at(i);
    }
    rep(i,a){
        cin>>vec2.at(i);
    }
    vector<int> tes(a);
    rep(i,a){
        tes.at(i)=i+1;
    }
    int f;
    int num=-1;
    do {
        num++;
        bool flag=true;
        rep(i,a){
            if(tes.at(i)!=vec1.at(i)){
                flag=false;
            }
        }
        if(flag){
            f=num;
            //cout<<f<<endl;
        }
    } while (std::next_permutation(tes.begin(), tes.end()));
    int z;
    num=-1;
    sort(tes.begin(),tes.end());
    do {
        num++;
        bool flag=true;
        rep(i,a){
            if(tes.at(i)!=vec2.at(i)){
                flag=false;
            }
        }
        if(flag){
            z=num;
            //cout<<z<<endl;
        }
    } while (std::next_permutation(tes.begin(), tes.end()));
    cout<<abs(z-f)<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

int main(){
    string s;
    cin >> s;
    int a[s.length()+1];
    int ch[s.length()+1];
    for(int i=0;i<s.length();i++){
        a[i]=(int)s[i]-48;
    }
    for(int i=0;i<pow(2,s.length()-1);i++){
        fill(ch,ch+s.length(),0);
        int sum=a[0];
        int temp[s.length()-1];
        fill(temp,temp+s.length(),0);
        for(int j=0;j<s.length();j++){
            if((1&i>>j)==1) temp[j]=1;
        }
        ch[0]=1;
        ch[s.length()]=-1;
        for(int j=1;j<s.length();j++){
            ch[j]=temp[j-1];
        }
        for(int j=1;j<s.length();j++){
            if(ch[j]==1) sum+=a[j];
            else if(ch[j]==0) sum-=a[j];
            if(sum==7&&j==s.length()-1){
                for(int k=0;k<s.length();k++){
                    cout << a[k];
                    if(ch[k+1]==1) cout << "+";
                    else if(ch[k+1]==0) cout << "-";
                    else if(ch[k+1]==-1){
                        cout << "=7"<< endl;
                        return 0; 
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
# ab = [list(map(int, input().split())) for _ in range(m)]
graph = [[] for _ in range(n+1)]
good = {}
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

for i in range(n):
    h_i = h[i]
    if i in good.keys():
        continue
    if not graph[i+1]:
        good[i] = True
        continue
    for j in graph[i+1]:
        if h_i > h[j-1]:
            good[j-1] = False
        else:
            good[i] = False
            break
    if i not in good.keys():
        good[i] = True

ans = 0
for v in good.values():
    if v:
        ans += 1
print(ans)

Measured memory_bytes: 40956
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0

ans += sum(b)
for i in range(n-1):
  if a[i]+1 == a[i+1]:
    
    ans += c[a[i]-1]
    
    
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define vi vector<int>
#define vll vector<long long>
#define ll long long
#define ull unsigned long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define nl cout<<'\n'
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pll pair<long long,long long>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define sll set<long long>
#define all(v) (v).begin(),(v).end()
#define Unique(x)           (x).erase(unique(all(x)), x.end())
#define v_present(vec,x)  (find(all(vec),x)!=(vec).end())
#define present(myset,x)    ((myset).find(x)!=(myset).end())
#define Cprint(c)  for(auto i:(c)) { cout<<i<<" "; } nl

ll mod = 1e9+7;
const int MAX = 1e5+5;
using namespace std;
ll m[200005];

int main()
{
FAST_IO;
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
	m[i%k]++;
}
ll ans=0;
for(int i=1;i<=n;i++)
{
	int var=i;
	i=i%k;
	//cout<<m[i]<<" "<<m[k-i]<<endl;
	if(i==0)
	{
		ll curr=m[i];
		ll left=m[k-i];
		ans+=(curr+left)*(curr+left);
	}
	else if((2*i)%k==0){
		ans+=m[k-i]*m[i];
	}
	i=var;
}
cout<<ans<<endl;

return 0;
}



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

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef long double ld;



void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> cnt(n);
    for (int i = 0; i < k; ++i) {
        int d;
        cin >> d;
        while (d--) {
            int x;
            cin >> x; --x;
            cnt[x]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) ans += (cnt[i] == 0);
        cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3656
n=int(input())
a=[0]*n
b=a.copy()
c=a.copy()
for i in range(n):
    a[i],b[i],c[i]=map(lambda x: int(x), input().split())

INF=1<<60
dpa=[INF]*(10**5+10)
dpb=dpa.copy()
dpc=dpa.copy()

dpa[0]=a[0]
dpb[0]=b[0]
dpc[0]=c[0]
for i in range(n-1):
    dpa[i+1]=max(a[i+1]+dpb[i], a[i+1]+dpc[i])
    dpb[i+1]=max(b[i+1]+dpa[i], b[i+1]+dpc[i])
    dpc[i+1]=max(c[i+1]+dpa[i], c[i+1]+dpb[i])
print(max(dpa[n-1],dpb[n-1],dpc[n-1]))

Measured memory_bytes: 26788
def main():
    n = int(input())
    s = list(input())
    t = list(input())
    if s == t:
        print(n)
        exit()
    ans = float("inf")
    for i in range(n):
        S = s + t[i:]
        #print(S[:n], S[2 * n - n:])
        if S[:n] == s and S[2 * n - n - i:] == t:
            ans = min(ans, len(S))
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

constexpr int64_t inf = (1ll << 60);

int main() {
  int N;
  std::cin >> N;
  std::vector<int64_t> A(N + 1);
  for (auto &x: A) {
    std::cin >> x;
  }
  std::vector<int64_t> back(N + 1);
  for (int i: revrange(0, N)) {
    back[i] = back[i + 1] + A[i + 1];
  }
  int64_t cur = 1, ans = 1;
  for (int i: range(0, N + 1)) {
    if (cur < A[i]) {
      std::cout << "-1\n";
      return 0;
    }
    cur -= A[i];
    ans += std::min(cur * 2, back[i]);
    cur = std::min(cur * 2, back[i]);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4840
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll h1,m1,h2,m2,k;cin>>h1>>m1>>h2>>m2>>k;
  cout<<(h2-h1)*60+m2-m1-k<<endl;
  return 0;
}

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

using ll = long long;

int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0;i < n;i++){
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	vector<vector<int>> dp(n);
	vector<vector<int>> dis(n);
	vector<int> pos(n);
	int res = 0;
	for(int i = 0;i < n;i++){
		for(int j = i - 1;j >= 0;j--){
			while(pos[j] < (int)dp[j].size() && dis[j][pos[j]] < v[i] - v[j]) ++pos[j];
			if(pos[j] < (int)dp[j].size() && dis[j][pos[j]] == v[i] - v[j]){
				dp[i].push_back(dp[j][pos[j]] + 1);
			}
			else{
				dp[i].push_back(2);
			}
			res = max(res, dp[i].back());
			dis[i].push_back(v[i] - v[j]);
		}
	}
	cout << res << endl;
	return 0;
}




Measured memory_bytes: 125876
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner in=new Scanner(System.in);
        long n=in.nextLong();
        while (true) {
            int cnt=0;
            for (int i=2; i*i<=n; i++) {
                if (n%i==0) {
                    cnt++; break;
                }
            }
            if (cnt==0) {
                System.out.println(n);
                return ;
            }
            n+=(n%2)+1;
        }
     }
}


Measured memory_bytes: 23636
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
 
int main() {
  int N;
  cin >> N;
  vector<long long> v(N, 0);
  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    v[a]++;
  }
 
  long long ans = 1;
 
  //偶数なら初期値1、奇数なら初期値0
  for (int i = (N % 2 == 0) ? 1 : 0; i < N; i += 2) {
    //奇数で0が一つじゃ無い時と、数値が2以外の時
    if ((i == 0 && v[0] != 1) || (i != 0 && v[i] != 2)) {
      ans = 0;
      break;
    } else
      ans = ans * v[i] % 1000000007;
  }
 
  cout << ans << endl;
 
  return 0;
}


Measured memory_bytes: 1024
/*
	Bakul Gaur (caesar1551)
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PrePro ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,n) for(ll i = 0; i < n; i++)
#define fre(i,a,b) for(ll i = a; i <= b; i++)
#define fb(i,n) for(ll i = n; i >= 0; i--)
#define fbe(i,a,b) for(ll i = a; i >= b; i--)
#define umap(x,y) unordered_map<x,y>
#define uset(x) unordered_set<x>
#define vv(x) vector<x>
#define pp(x,y) pair<x,y>
#define prar(a,n) fr(i,n){cout << a[i] << " ";}
#define inar(a,n) fr(i,n){cin >> a[i];}
#define mk make_pair
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define MAX 1000001
inline ll gcd(ll a, ll b){
	if(b == 0){
		return a;
	}
	return gcd(b,a%b);
}
inline ll pwr(ll a, ll b, ll modulo = mod){
	if(a == 0 && b == 0){
		return 0;
	}
	ll ans = 1;
	while(b > 0){
		if(b&1){
			ans = ((ans%modulo) * (a%modulo))%modulo;
		}
		b >>= 1;
		a = ((a%modulo) * (a%modulo))%modulo;
	}
	return (ans+modulo)%modulo;
}
inline ll modInverse(ll a, ll p){
	// Only if p is prime.
	return pwr(a,p-2,p);
}



/* #############
   START SOLVING 
   ############# */



void solve(){
	string s, t;
	cin >> s >> t;
	ll n = s.size(), m = t.size();
	vv(vv(ll)) dp(n+1,vv(ll)(m+1,0));
	fre(i,1,n){
		fre(j,1,m){
			if(s[i-1] == t[j-1]){
				dp[i][j] = 1 + dp[i-1][j-1];
			}
			else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	string ans = "";
	ll i = n, j = m;
	while(i > 0 && j > 0){
		if(s[i-1] == t[j-1]){
			ans = s[i-1] + ans;
			i--, j--;
		}
		else if(dp[i-1][j] > dp[i][j-1]){
			i--;
		}
		else{
			j--;
		}
	}
	cout << ans << endl;
}
int main(){
	PrePro
	/* #ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif */
    ll t = 1;
    // cin >> t;
    fr(i,t){
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    	// cout << endl;
    }
	return 0;
}

Measured memory_bytes: 74124
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

bool inside(int x, int y, int w, int h) {
  return (x >= 0 && y >= 0 && x < w && y < h);
}

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

int h, w;

vector<string> mat(1005);
vector<vector<int>> dist(1005, vector<int>(1005, INF));

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

  IN(h, w);
  rep(i, h) IN(mat[i]);

  queue<pii> que;

  rep(i, h) rep(j, w) {
    if (mat[i][j] == '#') {
      que.push(make_pair(i, j));
      dist[i][j] = 0;
    }
  }

  i64 res = 0;
  while (!que.empty()) {
    int y = que.front().first;
    int x = que.front().second;
    que.pop();

    for (int i = 0; i < 4; ++i) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (inside(nx, ny, w, h) &&
          dist[ny][nx] > dist[y][x] + 1 &&
          mat[ny][nx] != '#') {

        int norm = dist[y][x] + 1;
        mat[ny][nx] = '#';
        chmin(dist[ny][nx], norm);
        chmax(res, dist[ny][nx]);
        que.push(make_pair(ny,nx));
      }
    }
  }

  OUTL(res);

  return 0;
}


Measured memory_bytes: 21684
H,W = map(int,input().split())

A = [list(input()) for i in range(H)]

for i in range(H):
	for j in range(W):
		if A[i][j] != '#':
			count = 0
			for k in range(-1,2):
				for l in range(-1,2):
					if -1 < i + k and i + k < H and -1 < j + l and j + l < W:
						if A[i+k][j+l] == '#':
							count += 1
			
			A[i][j] = str(count)

for i in A:
	print(''.join(i))

Measured memory_bytes: 3316