akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int main()
{
    int n,k,q;
    cin >>n >>k >>q;
    int a[q];
    int b[n];
    for (int i=0; i<n; i++){
        b[i]=k-q;
    }
    
    for (int i=0; i<q; i++){
        cin >> a[i];
        b[a[i]-1]+=1;
        
    }
    for (int i=0; i<n; i++){
        if (b[i]>0) cout<<"Yes"<<endl;
        else {
            cout<<"No"<<endl;}
    }
    return 0;
}

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

s = []

for i in range(H):

    S = list(input())
    s.append(S)

Q = [[0,0]]
shnum = 0

#print (s)

for i in range(H):

    for j in range(W):

        if s[i][j] == "#":

            shnum += 1


while len(Q) > 0:

    #print (Q)
    #print (s)

    now = Q.pop(0)

    if now[0] == 0 and now[1] == 0:
        s[0][0] = 1
        Q.append([0,1])
        Q.append([1,0])

    elif s[now[0]][now[1]] == "#":
        continue;

    else:

        if s[now[0]][now[1]] == ".":

            far = 10000

        else:

            far = s[now[0]][now[1]]

        flag = 0

        if now[0]-1 >= 0 and s[now[0]-1][now[1]] not in [-1,"#","."]:

            if far > s[now[0]-1][now[1]]+1:
                far = s[now[0]-1][now[1]]+1
                flag = 1

        if now[1]-1 >= 0 and s[now[0]][now[1]-1] not in [-1,"#","."]:

            if far > s[now[0]][now[1]-1]+1:
                far = s[now[0]][now[1]-1]+1
                flag = 2

        if now[0]+1 < H and s[now[0]+1][now[1]] not in [-1,"#","."]:

            if far > s[now[0]+1][now[1]]+1:
                far = s[now[0]+1][now[1]]+1
                flag = 3

        if now[1]+1 < W and s[now[0]][now[1]+1] not in [-1,"#","."]:

            if far > s[now[0]][now[1]+1]+1:
                far = s[now[0]][now[1]+1]+1
                flag = 4

        if flag != 0:
            
            s[now[0]][now[1]] = far

            if now[0]-1 >= 0 and flag != 1:

                Q.append([now[0]-1,now[1]])

            if now[1]-1 >= 0 and flag != 2:

                Q.append([now[0],now[1]-1])

            if now[0]+1 < H and flag != 3:

                Q.append([now[0]+1,now[1]])

            if now[1]+1 < W and flag != 4:

                Q.append([now[0],now[1]+1])


if s[-1][-1] == -1:
    print (-1)

else:

    if s[-1][-1] == ".":
        print (-1)
    else:
        print (H*W - s[-1][-1] - shnum)


Measured memory_bytes: 3192
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int dp[1<<16];

int main(){
	int n;
	int t[16][17];
	while(scanf("%d",&n),n){
		rep(i,n) rep(j,n+1) scanf("%d", &t[i][j]);
		rep(i,1<<n) dp[i] = INF;
		dp[0] = 0;
		for(int i = 1; i < (1<<n); i++){
			bitset<16> bs(i);
			rep(j,n){
				if(bs[j]){
					int add = t[j][0];
					rep(k,n){
						if(bs[k] == true && j != k) add = min(add,t[j][k+1]);
					}
					dp[i] = min(dp[i],dp[i-(1<<j)]+add);
				}
			}
		}
		printf("%d\n", dp[(1<<n)-1]);
	}
}

Measured memory_bytes: 1448
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int> start(N),end(N);
  int sum=0;
 for(int i=0;i<N;i++){
   cin>>start.at(i)>>end.at(i);
   sum = sum+end.at(i)-start.at(i)+1;
 }
  cout<<sum<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MOD=1e9+7;
ll N,A[25][25],dp[1<<22];
bool Check(int ith,ll x)
{
    return x&(1<<ith);
}
ll Set(int ith,ll x)
{
    return x|(1<<ith);
}
ll solve(int idx,ll mask)
{
    if(__builtin_popcount(mask)==N)return 1;
    if(idx>=N)return 0;
    if(dp[mask]!=-1)return dp[mask];
    ll res=0;
    for(int j=0;j<N;j++){
        if(A[idx][j])
        {
            if(Check(j,mask)==0)
            {
                res+=solve(idx+1,Set(j,mask))%MOD;
            }
        }
    }
    return dp[mask]=res%MOD;
}
int main  ()
{
    memset(dp,-1,sizeof dp);
    cin >> N;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++)cin>>A[i][j];
    }
    cout<<solve(0,0);
    return 0;
}


Measured memory_bytes: 33024
#include<cstdio>
#include<cstdlib>
#include<map>
#include<vector>
using namespace std;
struct vertex {
    int par = 0, dist = 0;
    bool used = false;
    vector<int> to;
};

int n;
char s[200][201];
vertex ver[200];
int d[200][200];

bool dfs(int x, int y) {
    if (ver[x].used) {
        if (abs(ver[x].dist - y) % 2 == 1) return false; 
        else return true;
    }
    ver[x].used = true;
    if (ver[x].to.size() < 2 && ver[x].to[0] == ver[x].par) return true; 
    ver[x].dist = y;
    bool ans = true;
    for (auto &i : ver[x].to) {
        if (i == ver[x].par) continue;
        ver[i].par = x;
        ans = ans && dfs(i, ver[x].dist + 1);    
    }
    return ans;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%s", s[i]);
    
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (s[i][j] == '1') {
                ver[i].to.push_back(j);
                ver[j].to.push_back(i);
            }
        }
    }
    
    if (!dfs(0, 0)) {
        printf("-1\n");
        return 0;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            if (s[i][j] == '1') d[i][j] = 1;
            else d[i][j] = 200;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (d[i][j] == 200) continue;
            ans = max(ans, d[i][j]);
        }
    }
    printf("%d\n", ans + 1);
    return 0;
}



Measured memory_bytes: 512
A=int(input())
l=[chr(i) for i in range(97, 97+26)]
let=""
for i in range(100):
   if A%26==0:
      let="z"+let
      if A//26==1:
         break
      A=A//26-1
   else:
      let=l[A%26-1]+let
      A=A//26
   if A==0:
      break
print(let)

Measured memory_bytes: 8900
#include <stdio.h>

int main() {
  int cnt_num[100000 + 3]; // -1 <-> 100001
  int n;
  scanf("%d", &n);

  int i;
  for(i=0;i<100003;i++)
    cnt_num[i] = 0;
  
  for(i=0;i<n;i++) {
    int j;
    int ai;
    scanf("%d", &ai);
    for(j=0;j<3;j++)
      cnt_num[ai + j] += 1;
  }
  int i_max = 0;
  for(i=0;i<100003;i++)
    if(cnt_num[i] > i_max)
      i_max = cnt_num[i];
  printf("%d", i_max);
  
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
//input


 
//processing


//dpTable
//int dp[100050];

int main(){
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}


Measured memory_bytes: 3620
import scala.io.Source

object Main extends App{
  import scala.io.StdIn._
  val Array(n, m) = readLine().split(' ').map(_.toInt)
  solve(n, m)
  def solve(n:Int, m:Int):Unit = {
    if (n == 0 && m == 0) return
    val strength = readLine().split(' ').map(_.toInt)
    val boss = strength.last
    val enemy = strength.toList
    if (minBattle(enemy, strength.head, boss) < m) println(-1)
    else {
      var min = strength.head
      var max = strength.last
      var mid = 0
      while (min < max) {
        mid = (min + max + 1) / 2
        if (minBattle(enemy, mid, boss) >= m) {
          min = mid
        } else {
          max = mid - 1
        }
      }
      println(if (minBattle(enemy, min, boss) >= m) min else -1)
    }
    val Array(nn, mm) = readLine().split(' ').map(_.toInt)
    solve(nn, mm)
  }

  def max(i: Int, i1: Int) = if (i > i1) i else i1
  def minBattle(enemy:List[Int], x:Int, boss:Int, level:Int = 1, battleCount:Int = 1):Int = {
    if (level + x > boss) return battleCount
    def lowerAndHigher(e:List[Int]):(Option[Int], Int, List[Int]) = {
      e match{
        case l::h::t if l > level => (None, l, (h::t))
        case l::h::t if l <= level && level < h => (Some(l), h, t)
        case h::Nil => (None, h, Nil)
        case _::t => lowerAndHigher(t)
        case _ => ???
      }
    }
    def score(e:Int) = if (x - (e - level).abs > 0) x - (e - level).abs else 1
    lowerAndHigher(enemy) match{
      case (None, higher, rest) if (higher < level + x)=>{
        val diff = x - higher + level
        var i = 1
        var bc = battleCount + 1
        while (diff * i + level <= higher && diff * i + level + x <= boss){
          i = i * 2 + 1
          bc += 1
        }
        return minBattle((higher::rest), x, boss, level + diff * i, bc)
      }
      case (Some(lower), higher, rest) if (higher >= level + x) => {
        if (lower + x <= level)
          minBattle(higher :: rest, x, boss, higher - x + 1, battleCount + higher - x + 1 - level)
        else
          minBattle(lower :: higher :: rest, x, boss, lower + x, battleCount + 1)
      }
      case (Some(lower), higher, rest) => {
        if (score(lower) > score(higher)) {
          minBattle(lower :: higher :: rest, x, boss, lower + x, battleCount + 1)
        } else {
          val diff = x - higher + level
          var i = 1
          var bc = battleCount + 1
          while (diff * i + level <= higher) {
            i = i * 2 + 1
            bc += 1
          }
          minBattle((higher :: rest), x, boss, level + diff * i, bc)
        }
      }
    }
  }
}


Measured memory_bytes: 444940
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;

int main(){
  char x;
  char a,b;
  cin >> a >> b;
  if(a=='H'){
    if(b=='H'){
      x='H';
    }else{
      x='D';
    }
  }else{
    if(b=='H'){
      x='D';
    }else{
      x='H';
    }
  }
  cout << x <<endl;
  return 0;
}

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


void solve(std::string S){
    static const string table[] = {
            "SUM", "MON", "TUE", "WED", "THU", "FRI", "SAT"
    };
    int ret = 7 - int(find(table, table+7, S) - table);
    if (ret == 0) {
        ret = 7;
    }
    cout << ret << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    H, W = MI()
    grid = [ST() for _ in range(H)]
    dp = [[inf] * W for _ in range(H)]
    dp[0][0] = int(grid[0][0] == "#")
    for h in range(H):
        for w in range(W):
            if h < H-1:
                if grid[h + 1][w] == grid[h][w] or grid[h+1][w] == ".":
                    dp[h+1][w] = min(dp[h+1][w], dp[h][w])
                else:
                    dp[h+1][w] = min(dp[h+1][w], dp[h][w] + 1)
            if w < W-1:
                if grid[h][w+1] == grid[h][w] or grid[h][w+1] == ".":
                    dp[h][w+1] = min(dp[h][w+1], dp[h][w])
                else:
                    dp[h][w+1] = min(dp[h][w+1], dp[h][w]+1)
    print(dp[H-1][W-1])

if __name__ == '__main__':
    main()

    # H, W = MI()
    # grid = [ST() for _ in range(H)]
    #
    # # DP = [[[inf,inf] for _ in range(W)] for _ in range(H)]
    # # DP[0][0][0] = 0
    # DP = [[inf] * W for _ in range(H)]
    # DP[0][0] = int(grid[0][0] == "#")
    # for h in range(H):
    #     for w in range(W):
    #         if h + 1 < H:
    #             if grid[h][w] == grid[h + 1][w] or grid[h + 1][w] == ".":
    #                 DP[h + 1][w] = min(DP[h + 1][w], DP[h][w])
    #             else:
    #                 DP[h + 1][w] = min(DP[h + 1][w], DP[h][w] + 1)
    #         if w + 1 < W:
    #             if grid[h][w] == grid[h][w + 1] or grid[h][w + 1] == ".":
    #                 DP[h][w + 1] = min(DP[h][w + 1], DP[h][w])
    #             else:
    #                 DP[h][w + 1] = min(DP[h][w + 1], DP[h][w] + 1)
    # print(DP[-1][-1])


Measured memory_bytes: 68716
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int h,w,k;
  cin>>h>>w>>k;
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  x1--;y1--;x2--;y2--;
  char c[h][w];
  for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
          cin>>c[i][j];
      }
  }
  vector<vector<int>> dist(h,vector<int>(w,-1));
  dist[x1][y1]=0;
  queue<pair<int,int>> que;
  que.push(make_pair(x1,y1));
  while(!que.empty()){
      pair<int,int> current_pos=que.front();
      int y=current_pos.first;
      int x=current_pos.second;
      que.pop();
      for(int i=1;i<=k;i++){
          int next_x=x+i;
          if(next_x<0 or next_x>=w or c[y][next_x]=='@')break;
          if(dist[y][next_x]!=-1 and dist[y][next_x]<=dist[y][x])break;
          if(dist[y][next_x]>dist[y][x]+1 or dist[y][next_x]==-1){
              que.push(make_pair(y,next_x));
              dist[y][next_x]=dist[y][x]+1;
          }
      }
      for(int i=1;i<=k;i++){
          int next_x=x-i;
          if(next_x<0 or next_x>=w or c[y][next_x]=='@')break;
          if(dist[y][next_x]!=-1 and dist[y][next_x]<=dist[y][x])break;
          if(dist[y][next_x]>dist[y][x]+1 or dist[y][next_x]==-1){
              que.push(make_pair(y,next_x));
              dist[y][next_x]=dist[y][x]+1;
          }
      }
      for(int i=1;i<=k;i++){
          int next_y=y+i;
          if(next_y<0 or next_y>=h or c[next_y][x]=='@')break;
          if(dist[next_y][x]!=-1 and dist[next_y][x]<=dist[y][x])break;
          if(dist[next_y][x]>dist[y][x]+1 or dist[next_y][x]==-1){
              que.push(make_pair(next_y,x));
              dist[next_y][x]=dist[y][x]+1;
          }
      }
      for(int i=1;i<=k;i++){
          int next_y=y-i;
          if(next_y<0 or next_y>=h or c[next_y][x]=='@')break;
          if(dist[next_y][x]!=-1 and dist[next_y][x]<=dist[y][x])break;
          if(dist[next_y][x]>dist[y][x]+1 or dist[next_y][x]==-1){
              que.push(make_pair(next_y,x));
              dist[next_y][x]=dist[y][x]+1;
          }
      }
  }
  if(dist[x2][y2]!=-1) cout<<dist[x2][y2]<<endl;
  else cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 11916
#include<stdio.h>

int main(void){
	int m,d,now;
	char da[7][15]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
	for(;;){
		now=0;
		scanf("%d %d",&m,&d);
		if(!m||!d)break;
		for(int i=1;i<m;i++){
			now+= i==2 ? 29 : (i<8 ? 30+i%2 : 31-i%2);
		}
		now+=d;
		printf("%s\n",&da[now%7]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int ans=0, i;
    char s[3],t[3];

    scanf("%s%s", s, t);
    for(i=0; i<3; i++)
    {
        if(strncmp(&s[i], &t[i], 1)==0) ans++;
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>

using namespace std;

#define Set(a, b) memset(a, b, sizeof a)

const int N = 2e5 + 10;
const int Inf = INT_MAX / 2;

int n, m, a[N];
int tms, en[N], nxt[N], to[N];

void Link(int u, int v) {
	to[++tms] = v;
	nxt[tms] = en[u];
	en[u] = tms;
}

int fa[N], b[N], c[N];

void Dfs(int u) {
	if (~a[u]) 
		c[u] = (b[u] - a[u]) / 2;
	else
		c[u] = Inf;
	for (int p = en[u]; p; p = nxt[p]) {
		int v = to[p];
		if (!fa[v]) {
			fa[v] = u;
			b[v] = b[u] + 1;
			Dfs(v);
		}
	}
	if (~fa[u])
		c[fa[u]] = min(c[fa[u]], c[u]);
}

void Dfs(int u, int lst) {
	if ((~a[u] && a[u] != b[u] - lst * 2) || (a[u] == -1 && lst < c[u])) 
		++lst;
	b[u] -= lst * 2;
	for (int p = en[u]; p; p = nxt[p]) {
		int v = to[p];
		if (fa[v] == u) 
			Dfs(v, lst);
	}
}

int main() {

	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d %d", &u, &v);
		Link(u, v), Link(v, u);
	}
	scanf("%d", &m);
	int rt;
	Set(a, 255);
	for (int i = 1; i <= m; ++i) {
		int u, v;
		scanf("%d %d", &u, &v);
		a[u] = v;
		rt = u;
	}
	fa[rt] = -1;
	b[rt] = a[rt];
	Dfs(rt);
	Dfs(rt, 0);
	bool flag = 1;
	for (int i = 1; i <= n; ++i)
		if (~a[i] && a[i] != b[i]) {
			flag = 0;
			break;
		}
	if (!flag) 
		puts("No");
	else {
		puts("Yes");
		for (int i = 1; i <= n; ++i)
			printf("%d\n", b[i]);
	}

	return 0;
}


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

#define ran 202202

int n;
string s[ran];

int main() {
	cin>>n;
	for(int i=0;i<n;i++) cin>>s[i];
	sort(s, s+n);
	
	int ans = 1;
	for(int i=1;i<n;i++)
		if(s[i]!=s[i-1]) ans++;
	cout<<ans<<endl;
	
	return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m), c(m);
	vector<vector<int>> dist(n, vector<int>(n,INF));
	rep(i,m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--, b[i]--;
		dist[a[i]][b[i]] = c[i];
		dist[b[i]][a[i]] = c[i];
	}
	rep(k,n) rep(i,n) rep(j,n) {
		dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
	}
	int ans = 0;
	rep(i,m) {
		if (dist[a[i]][b[i]] != c[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3664
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

x, K, D = map(int, readline().split())
if x - K * D >= 0:
    print(abs(x - K * D))
elif x + K * D <= 0:
    print(abs(x + K * D))
else:
    low, high = 0, K
    while high - low > 1:
        mid = (high + low) // 2
        if x + (-K + 2 * mid) * D <= 0:
            low = mid
        else:
            high = mid
    print(min(abs(x + (-K + 2 * low) * D), abs(x + (-K + 2 * high) * D)))

Measured memory_bytes: 9212
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll h1,m1,h2,m2,k,ans=0,ti0=0,ti1;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  ti0 = 60*h1 + m1;
  ti1 = 60*h2 + m2;
  ll v = ti1 - ti0;
  cout << max(0ll,v-k)<<endl;
}


Measured memory_bytes: 3652
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  multiset<int> st;
  int query; cin >> query;

  for (int i = 0; i < query; ++i) {
    int op, x; cin >> op >> x;
    if (op == 0) {
      st.insert(x);
      cout << st.size() << '\n';
    } else if (op == 1) {
      cout << (distance(st.lower_bound(x), st.upper_bound(x))) << '\n';
    } else if (op == 2) {
      st.erase(x);
    } else {
      int r; cin >> r;
      auto it1 = st.lower_bound(x);
      auto it2 = st.upper_bound(r);
      for (auto it = it1; it != it2; ++it) {
        cout << *it << '\n';
      }
    }
  }

  return 0;
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;    
const int N = 3e3+6, M = 1e5+5, OO = 0x3f3f3f3f;


int n, mem[N][N],t;
pair <int,int> a[N];
int dp(int idx = 0, int time = t)
{
    if(time <= 0 || idx == n) return 0;
    int &ret = mem[idx][time];
    if(ret != 0) return ret;
    return ret = max(dp(idx+1, time),dp(idx+1, time-a[idx].first)+a[idx].second);
}

int main()
{
    int x,y;
    scanf("%d%d",&n,&t);
    for(int i=0;i <n ; i++)
    {
        scanf("%d%d",&x,&y);
        a[i].first = x;
        a[i].second = y;
    }
    sort(a, a+n);
    printf("%d\n",dp());
    return 0;
}

Measured memory_bytes: 34944
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        int ans = 0;
        for (int i = 0; i < s.Length; i++)
            if (s[i] == '+') ans++;
            else ans--;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	ps := make([]int32, n)
	for i := range ps {
		fmt.Scan(&ps[i])
	}

	var cnt int32
	tmpMin := ps[0]
	for _, p := range ps {
		if tmpMin >= p {
			tmpMin = p
			cnt++
		}
	}

	fmt.Print(cnt)
}



Measured memory_bytes: 5504
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;
int main(){
	int i,j,r,c,n,w,x,y,a[2];
	vector<pair<int,int>> p;
	cin >> r >> c >> n;
	for(i=0;i<n;i++){
		w = 0;
		for(j=0;j<2;j++){
			cin >> x >> y ;
			if(x==0){
				a[j] = y;
			}else if(y==c){
				a[j] = x+c;
			}else if(x==r){
				a[j] = 2*c+r-y;
			}else if(y==0){
				a[j] = 2*c+2*r-x;
			}else{
				w--;
			}
			w++;
		}
		if(w==2){
			p.push_back(make_pair(a[0],i));
			p.push_back(make_pair(a[1],i));
		}
	}
	stack<pair<int,int>> st;
	sort(p.begin(),p.end());
	for(i=0;i<p.size();i++){
		if(st.empty() || st.top().second!=p[i].second){
			st.push(p[i]);
		}else{
			st.pop();
		}
	}
	if(st.empty()){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 2544
#include<cstdio>
const int N = 1e5+5;
char s[N];

int main(){
    int n;
    scanf("%d%s",&n,s+1);
    int p = 1;
    int ans = 0;
    while(p<=n){
        int next = p;
        while(next+1<=n && s[next+1]==s[p]) next++;
        ans++;
        p = next+1;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 5005, mod = (int) 0;
long long dp[N];
int sum[N][N], p[N];
int main() {
	int n, cl, cr;
	cin >> n >> cl >> cr;
	p[n + 1] = n + 1;
	swap(cl, cr);
	for (int j = 1; j <= n; ++j)
		cin >> p[j];
	n += 2;
	for (int j = 0; j <= n; ++j) {
		for (int i = 0; i < n; ++i)
			sum[j][i + 1] = sum[j][i] + (p[i] < j);
	}
	memset(dp, 63, sizeof dp);	
	dp[1] = dp[0] = 0;
	for (int j = 1; j < n; ++j) {
		for (int i = 0; i < j; ++i) {
			if (p[i] < p[j]) {
				int less = sum[p[i]][j] - sum[p[i]][i + 1];
				int betw = (sum[p[j]][j] - sum[p[j]][i + 1]) - less;
				int more = (j - i - 1) - less - betw;
				long long cost = (LL) less * cl + (LL) more * cr + (LL) betw * min(cl, cr);
				dp[j + 1] = min(dp[j + 1], dp[i + 1] + cost);
			}
		}
//		cout << " hi " << j << ' ' << dp[j + 1] << endl;
	}
	cout << dp[n] << endl;
}



















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

typedef long long ll;
typedef pair<ll,ll> P;

int main(void){
    ll N,H;
    cin>>N>>H;
    
    vector<P> atk(N);
    ll maxv=0;
    for(int i=0;i<N;i++){
        cin>>atk[i].second>>atk[i].first;
        maxv=max(atk[i].second,maxv);
    }
    
    sort(atk.begin(),atk.end(),greater<P>());
    
    ll count=0;
    for(int i=0;i<N;i++){
        if(atk[i].first>maxv){H-=atk[i].first;count++;}
        if(H<=0)break;
    }
    
    if(H>0)count+=(H+maxv-1)/maxv;
    
    cout<<count<<endl;
    
}


Measured memory_bytes: 1792
from sys import stdin

def main():
  N, M = map(int, stdin.readline().rstrip().split())
  beforeA=-1
  Mlist=[]

  for i in range(M):
    a = int(stdin.readline().rstrip())
    if (a-beforeA)==1:
      print("0")
      exit()
    Mlist.append(a)
    beforeA = a

  Mindex=0
  broken=-2
  if len(Mlist) >0:
    broken = Mlist[Mindex]
  an2=0
  an1=1
  patern=1
  brokenNext=False
  for i in range(1,N+1):
    if broken == i:
      Mindex+=1
      if len(Mlist) > Mindex:
        broken = Mlist[Mindex]
      brokenNext=True
      continue
    if brokenNext:
      brokenNext=False
      an2=0
      continue
    patern=(an1+an2)%1000000007
    an2=an1
    an1=patern
    #print("{}: {}".format(i,patern))
  print(patern%1000000007 )

main()


Measured memory_bytes: 41820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

ll dp[10010][2][110];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int d;
  cin>>s>>d;
  dp[0][0][0]=1;
  rep(i,s.size())rep(j,2)rep(k,d){
    int now=(int)s[i]-'0';
    for(int l=0;l<=(j?9:now);l++){
      (dp[i+1][j|(l<now)][(k+l)%d]+=dp[i][j][k])%=mod;
    }
  }
  ll ans=(dp[s.size()][0][0]+dp[s.size()][1][0]-1+mod)%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 17408
//config = {stdin: 'tmp', newline: '\r\n'}; // win
config = {stdin: '/dev/stdin', newline: '\n'}; // linux

line = require('fs').readFileSync(config.stdin, 'ascii')
       .split(config.newline, 2);

a = line[0].split(' ');
b = line[1].split(' ');

dice_pos = {
  1: [0, 0, 0.5], 2: [0, -0.5, 0], 3: [0.5, 0, 0],
  4: [-0.5, 0, 0], 5: [0, 0.5, 0], 6: [0, 0, -0.5] };

function find(i) {
  return b.indexOf(a[i - 1]);
}

function sub(x, y) {
  return [x[0] - y[0], x[1] - y[1], x[2] - y[2]];
}

function get_vector_by_index(i, j) {
  var pi = find(i), pj = find(j);
  if (pi === -1 || pj === -1) return null;
  return sub(dice_pos[pi + 1], dice_pos[pj + 1]);
}

v16 = get_vector_by_index(6, 1);
v25 = get_vector_by_index(5, 2);
v34 = get_vector_by_index(4, 3);

if (v16 === null || v25 === null || v34 === null) {
  console.log("No");
} else {
  outer = [ v16[1] * v25[2] - v16[2] * v25[1],
            v16[2] * v25[0] - v16[0] * v25[2],
            v16[0] * v25[1] - v16[1] * v25[0] ];
  if (outer[0] === -v34[0] && outer[1] === -v34[1] && outer[2] == -v34[2])
    console.log("Yes");
  else
    console.log("No");
}

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

int main() {
  string b;
  cin >> b;
  if (b == "A")
  cout << "T" << endl;
  else if (b == "T")
  cout << "A" << endl;
  else if (b == "G")
  cout << "C" << endl;
  else if (b == "C")
  cout << "G" << endl;
}


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

using namespace std;

using ll = long long;

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

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N),B(N);
    for(int i=0;i<N;i++)
    {
        cin >> A[i];
    }
    for(int i=0;i<N;i++)
    {
        cin >> B[i];
    }

    vector<ll> timesOfPlus(N,0);

    for(int i=0;i<N;i++)
    {
        timesOfPlus[i] = max(0LL,((B[i]-A[i]+1)/2));
        A[i] += 2 * timesOfPlus[i];
    }

    ll Dif = 0;

    for(int i=0;i<N;i++)
    {
        Dif += (A[i] - B[i]);
    }

    if(accumulate(ALL(timesOfPlus),0LL) < Dif)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int
main(void)
{
	char line[80];
	unsigned long a;
	unsigned long b;

	while (gets(line)) {
		if (sscanf(line, "%lu %lu", &a, &b) == 2) {
			unsigned long x = a;
			unsigned long y = b;
			unsigned long q;
			unsigned long r;
			while (true) {
				q = x / y;
				r = x - q * y;
				if (r == 0) {
					break;
				}
				x = y;
				y = r;
			}
			printf("%lu %lu\n", y, (a/y)*b);
		}
	}

	return 0;
}

Measured memory_bytes: 1040
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int ans=0;
		int a[]=new int[n*2];
		for(int i=0;i<n*2;i++) {
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		for(int i=0;i<n*2;i+=2) ans+=a[i];
System.out.println(ans);
	}
}





Measured memory_bytes: 22740
#include<stdio.h>
int main(void)
{
    int a,b,c,d,e,x,y,z;
    while(scanf("%d %d",&a,&b)!=EOF) {
        if(a>=b) {
            x=a;
            y=b;
        }
        else {
            x=b;
            y=a;
        }
        while(y!=0) {
            z=x%y;
            x=y;
            y=z;
        }
        c=a/x;
        d=b/x;
        e=c*d*x;
        printf("%d %d\n",x,e);
    }
    return 0;
}

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

void Log(int A[], int n)
{
    for (int i = 0; i < n; ++i) {
        cout << A[i];
        if (i != n - 1) {
            cout << " ";
        }
    }
    cout << endl;
}

int BubbleSort(int A[], int n)
{
    int cnt = 0;
    bool flag = true;
    while (flag) {
        flag = false;
        for (int j = n - 1; j > 0; --j) {
            if (A[j-1] > A[j]) {
                swap(A[j-1], A[j]);
                flag = true;
                ++cnt;
            }
        }
    }
    return cnt;
}

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

    // Input
    int A[100];
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        A[i] = a;
    }

    int cnt = BubbleSort(A, n);

    // Output
    Log(A, n);
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  ll N;
  cin >> N;
  vll A(N);
  vll B(N);
  vector<pair<ll, int> > s(N);
  rep(i, N) {
    cin >> A[i] >> B[i];
    s[i] = mp(A[i] + B[i], i);
  }
    
  sort(all(s));
  reverse(all(s));
  
  ll ac = 0;
  ll bc = 0;
  rep(i, N) {
    if(i % 2 == 0) {
      ac += A[s[i].second];
    } else {
      bc += B[s[i].second];
    }
  }
  
  fin(ac - bc);
}

Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

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

    if(B % A)
        cout << B - A << endl;
    else
        cout << B + A << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int Root(int a, vector<int> &v) {
	while (a != v[a])
		a = v[a];
	return a;
}

int main(void) {
	int num, rn, tn, i, a, b, p, q;
	cin >> num >> rn >> tn;
	num++;
	vector<int> r(num), t(num), rlen(num, 0), tlen(num, 0);
	map<pair<int, int>, int> mp;
	for (i = 1; i < num; i++) {
		r[i] = i;
		t[i] = i;
	}
	for (i = 0; i < rn; i++) {
		scanf("%d%d", &a, &b);
		p = Root(a, r);
		q = Root(b, r);
		if (rlen[p] <= rlen[q]) {
			r[p] = q;
			if (rlen[p] == rlen[q])
				rlen[q]++;
		}
		else
			r[q] = p;
	}
	for (i = 0; i < tn; i++) {
		scanf("%d%d", &a, &b);
		p = Root(a, t);
		q = Root(b, t);
		if (tlen[p] <= tlen[q]) {
			t[p] = q;
			if (tlen[p] == tlen[q])
				tlen[q]++;
		}
		else
			t[q] = p;
	}
	for (i = 1; i < num; i++)
		mp[make_pair(Root(i, r), Root(i, t))]++;
	for (i = 1; i < num; i++)
		printf("%d ", mp[make_pair(Root(i, r), Root(i, t))]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 15104
import sys
from functools import reduce

def main(n, k, p):
    """ main
    """
    p.sort()
    return sum(p[0:k])

if __name__ == "__main__":
    N, K = map(int, sys.stdin.readline().split(" "))
    P = list(map(int, sys.stdin.readline().split(" ")))

    print(main(N, K, P))

Measured memory_bytes: 9656
s = str(input())
result = 'WA'
if s[0] == 'A':
    s = s[1:]
    flg = s[1:-1].find('C')
    if flg != -1:
        s = s[:flg + 1] + s[flg + 2:]
        if s[:-1].find('C') == -1 and str(s).islower():
            result = 'AC'
print(result)

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


signed main()
{   
    gearup;
    ll a;
    string b; cin >> a >> b;
    ll res = 0;
    ll b1 = b[0] - '0';
    ll b2 = b[2] - '0';
    ll b3 = b[3] - '0';
    ll b4 = b1*100+b2*10+b3;
    res = (a * b4)/100;
    out(res);
}


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

int main() {
  
  int X ,t ;
  cin >> X >> t ;
  


  if((X-t)>0 || (X-t)==0 ) {
    
    cout << X - t << endl ;
  }

else {
  
  cout << "0" << endl;
  
}
}



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

typedef long long ll;

#define N 200005

int n;
ll a[N], b[N];

typedef pair <ll, int> pli;

priority_queue <pli> pq;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i ++) scanf("%lld", &a[i]);
    for (int i = 0; i < n; i ++) {
		scanf("%lld", &b[i]);
        pq.push(pli(b[i], i));
    }
    ll ans = 0;
    while (!pq.empty()) {
        pli rpt = pq.top(); pq.pop();
        int id = rpt.second;
		if (rpt.first == a[id]) continue;
        ll sum = b[(id+n-1)%n] + b[(id+1)%n];
        ll mx = max(b[(id+n-1)%n], b[(id+1)%n]);
        mx = max(mx, a[id]);
        ll t = (b[id] - mx + sum - 1) / sum;
        b[id] -= sum * t;
        ans += t;
        if (b[id] < a[id]) {
            puts("-1");
            return 0;
        }
        pq.push(pli(b[id], id));
    }
    for (int i = 1; i <= n; i ++) if (b[i] != a[i]) {
        puts("-1");
        return 0;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 8944
### main

while true
  l = gets.strip.to_i
  break if l == 0

  total = 0
  mon = nil

  for i in (1..12)
    m, n = gets.strip.split(' ').map{|s| s.to_i}

    total += m - n
    if mon.nil? && total >= l
      mon = i
    end
  end

  puts (mon.nil? ? 'NA' : mon)
end

Measured memory_bytes: 6104
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

int H, W, D;
int Q;
const int Amax = 300 * 300;
int x[Amax + 1];
int y[Amax + 1];
ll cost[Amax + 1];//mod Dの正の最小値から、配列の要素までの魔力の消費量

//マンハッタン距離
ll dif(int x1, int x2, int y1, int y2) {
	return abs(x1 - x2) + abs(y1 - y2);
}

int main() {
	int A;
	int L, R;
	cin >> H >> W >> D;
	For(i, H)For(j, W) {
		cin >> A;
		x[A] = i + 1;
		y[A] = j + 1;
	}
	for (int i = 1; i <= D; ++i) {
		cost[i] = 0;
		for (int j = i + D; j <= H * W; j += D) {
			cost[j] = cost[j - D] + dif(x[j], x[j - D], y[j], y[j - D]);
		}
	}
	cin >> Q;
	rep(Q) {
		cin >> L >> R;
		say(cost[R] - cost[L]);
	}
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

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

	    long a=gl();
	    long b=gl();
	    long c=gl();
	    long d=Math.min(a+b+1,c);
	    d+=b;
//	    if (k>k2) {
//	    	System.out.println("NO");
//	    } else {
//	    	System.out.println("YES");
//	    }
	    System.out.println(d);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35656
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

int main() {
  int N; cin>>N;
  string S; cin>>S;
  string A; A="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if(N==26){
    cout<<S<<endl;
  }
  else{
    for(int i=0; i<S.size(); i++){
      if(A.at(0) <= S.at(i) && S.at(i) <= A.at(25-N)){
        S.at(i)+=N;
      }
      else{
        S.at(i)-=26-N;
      }
    }
    cout<<S<<endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String n = input.next();
        int index = n.length() - 1;
        int num = (int)n.charAt(index) - 48;
        if (
                num == 2 ||
                num == 4 ||
                num == 5 ||
                num == 7 ||
                num == 9){
            System.out.println("hon");
        } else if (
                num == 0 ||
                num == 1 ||
                num == 6 ||
                num == 8){
            System.out.println("pon");
        } else {
            System.out.println("bon");
        }
    }
}

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

int main()
{
	int N;
	long long C, K;
	cin >> N >> C >> K;
	vector<long long> T( N );
	for( int i = 0; i < N; i++ ) {
		cin >> T[i];
	}

	sort( T.begin(), T.end() );
	int ans = 0;
	int i = 0;
	while( i < N ) {
		long long cur = T[i];
		int j = 1;
		while( j < C && i + j < N && T[i + j] <= cur + K ) j++;
		ans++;
		i += j;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
char ans[1005][1005];
int main() {
	scanf("%d%d%d%d", &n, &m, &a, &b);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) ans[i][j] = '.';
	if (n % 2) {
		int cura = min(m / 2, a);
		for (int i = 1; i <= cura; i++) {
			ans[n][i * 2 - 1] = '<';
			ans[n][i * 2] = '>';
		}
		a -= cura;
	}
	if (m % 2) {
		int curb = min(n / 2, b);
		for (int i = 1; i <= curb; i++) {
			ans[i * 2 - 1][m] = '^';
			ans[i * 2][m] = 'v';
		}
		b -= curb;
	}
	if ((a + 1) / 2 + (b + 1) / 2 <= (n / 2) * (m / 2)) {
		for (int i = 1; i <= n / 2; i++) {
			for (int j = 1; j <= m / 2; j++) {
				if (a >= 2) {
					ans[i * 2 - 1][j * 2 - 1] = '<';
					ans[i * 2 - 1][j * 2] = '>';
					ans[i * 2][j * 2 - 1] = '<';
					ans[i * 2][j * 2] = '>';
					a -= 2;
				} else if (a) {
					ans[i * 2 - 1][j * 2 - 1] = '<';
					ans[i * 2 - 1][j * 2] = '>';
					a--;
				} else if (b >= 2) {
					ans[i * 2 - 1][j * 2 - 1] = '^';
					ans[i * 2][j * 2 - 1] = 'v';
					ans[i * 2 - 1][j * 2] = '^';
					ans[i * 2][j * 2] = 'v';
					b -= 2;
				} else if (b) {
					ans[i * 2 - 1][j * 2 - 1] = '^';
					ans[i * 2][j * 2 - 1] = 'v';
					b--;
				}
			}
		}
		puts("YES");
		for (int i = 1; i <= n; i++) {
			ans[i][m + 1] = 0;
			puts(ans[i] + 1);
		}
	} else if (n % 2 && m % 2 && a % 2 && b % 2 && (a + 1) / 2 + (b + 1) / 2 == (n / 2) * (m / 2) + 1) {
		for (int i = 1; i <= n / 2; i++) {
			for (int j = 1; j <= m / 2; j++) {
				if (a >= 2) {
					ans[i * 2 - 1][j * 2 - 1] = '<';
					ans[i * 2 - 1][j * 2] = '>';
					ans[i * 2][j * 2 - 1] = '<';
					ans[i * 2][j * 2] = '>';
					a -= 2;
				} else if (b >= 2) {
					ans[i * 2 - 1][j * 2 - 1] = '^';
					ans[i * 2][j * 2 - 1] = 'v';
					ans[i * 2 - 1][j * 2] = '^';
					ans[i * 2][j * 2] = 'v';
					b -= 2;
				}
			}
		}
		ans[n - 2][m - 2] = '^';
		ans[n - 1][m - 2] = 'v';
		ans[n - 1][m] = '^';
		ans[n][m] = 'v';
		ans[n - 2][m - 1] = '<';
		ans[n - 2][m] = '>';
		puts("YES");
		for (int i = 1; i <= n; i++) {
			ans[i][m + 1] = 0;
			puts(ans[i] + 1);
		}
	} else puts("NO");
	return 0;
}

Measured memory_bytes: 4696
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
const int maxn=1e5+5;
int n,m,a[maxn];
signed main(){
	n=read(),m=read();
	int sum=0;
	for(int i=1;i<=m;i++){a[i]=read();sum+=a[i];}
	n=n-sum;
	if(n<0)puts("-1");
	else printf("%lld\n",n);
	return 0;
}


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

int main(){
  int n, a, b;
  bool x, y;
  cin >> n;
  a=n/100;
  b=n%100;
  if(a!=0&&a<13)x=true;
  else x=false;
  if(b!=0&&b<13)y=true;
  else y=false;
  if(x==true&&y==true)puts("AMBIGUOUS");
  else if(x==true&&y==false)puts("MMYY");
  else if(x==false&&y==true)puts("YYMM");
  else if(x==false&&y==false)puts("NA");
  return 0;
}


Measured memory_bytes: 256