akhauriyash/Code-Regression huggingface dataset:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    bound=0
    ans=[]
    s=input()
    for k,v in groupby(s):
        bound+=len(list(v))
#        ans.append()
        ans.append(max(bound,len(s)-bound))
    print(min(ans))
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 7500
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, now[10][5];

int Solve(){
  for (int i = 0; i < H; i++){
    for (int j = 0; j < 5; j++){
      scanf("%d", &now[i][j]);
    }
  }
  int ans = 0;
  while (true){
    int sum = 0;

    for (int i = 0; i < H; i++){
      int cnt = 1;
      for (int j = 1; j < 5; j++){
        if (now[i][j] == now[i][j - 1]) cnt++;
        else{
          if (cnt >= 3) {
            sum += now[i][j - 1] * cnt;
            for (int k = 0; k < cnt; k++){
              now[i][j - 1 - k] = 0;
            }
          }
          cnt = 1;
        }
      }
      if (cnt >= 3) {
        sum += now[i][4] * cnt;
        for (int k = 0; k < cnt; k++){
          now[i][4 - k] = 0;
        }
      }
    }

    if (sum == 0) break;
    ans += sum;

    for (int j = 0; j < 5; j++){
      queue <int> que;
      for (int i = H - 1; i >= 0; i--){
        if (now[i][j] != 0) que.push(now[i][j]);
      }
      
      for (int i = H - 1; i >= 0; i--){
        if (que.empty()) now[i][j] = 0;
        else now[i][j] = que.front(), que.pop();
      }
    }
  }
  
  printf("%d\n", ans);

  return 0;
}

int main(){
  while (cin >> H){
    if (H == 0) return 0;
    Solve();
  }
  
  return 0;
}



Measured memory_bytes: 3136
#include<stdio.h>
int a,s,d[1001],f[1001],g[1001][1001],h,j,k,i;
int main(void)
{
	scanf("%d %d",&a,&s);
	for(i=0;i<a;i++){
		scanf("%d",&d[i]);
	}
	for(i=0;i<s;i++){
		scanf("%d",&f[i]);
	}
	for(i=0;i<=s;i++){
		for(j=0;j<=a;j++){
			g[i][j]=200000000;
		}
	}
	g[0][0]=0;
	for(i=0;i<s;i++){
		for(j=0;j<=a;j++){
		h=d[j]*f[i];
			if(g[i][j]<g[i+1][j]){
				g[i+1][j]=g[i][j];
			}
			if(g[i+1][j+1]>g[i][j]+h&&j<=a){
				g[i+1][j+1]=h+g[i][j];
			}
		}
	}
	printf("%d\n",g[s][a]);
	return 0;
}

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

int main(void) {
  char a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a == b ||  b==c  || c==d) {
    cout << "Bad" << endl;
  }else {
    cout << "Good" << endl;
  }
  return 0;
}

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

int main() {
  int x, y ;
  cin >> x>> y;
  vector<int> a(x);
  for(int i=0;i<x;i++){
    cin>>a.at(i);}
  double sum=0;
  for(int i=0;i<x;i++){
    sum+=a.at(i);}
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0;i<y;i++){
   if(a.at(i)<sum/(4*y)){
   cout<<"No"<<endl;
   return 0;}}
   cout <<"Yes"<<endl;
}




Measured memory_bytes: 256
n, q = gets.split.map(&:to_i)
a = [0] * (n+1)
sq = ((n+1)**0.5).to_i
sa = [0] * (n/sq+1)
q.times do
	com, x, y = gets.split.map(&:to_i)
		#p [com,x,y,a]
	if com == 0
		a[x] += y
		sa[x/sq] += y
	else
		sum = 0
		if x/sq+1 >= y/sq
			x.upto(y) do |ai|
				sum += a[ai]
			end
		else
			x.upto((x/sq+1)*sq-1) do |ai|
				sum += a[ai]
			end
			(x/sq+1).upto(y/sq-1) do |sai|
				sum += sa[sai]
			end
			(y/sq*sq).upto(y) do |ai|
				sum += a[ai]
			end
		end
		p sum
	end
end

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

int main() {
    vector<int>usi(5);
    for(int i = 0; i < 5; i++) {
        cin >> usi[i];
    }
    int ans = 1000;
    do{
        int cnt = 0;
        cnt+=(usi[0]+9)/10*10;
        cnt+=(usi[1]+9)/10*10;
        cnt+=(usi[2]+9)/10*10;
        cnt+=(usi[3]+9)/10*10;
        cnt+=usi[4];
        ans = min(ans,cnt);
    }while(next_permutation(usi.begin(), usi.end()));
    cout << ans << endl;
}

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


string S;

int main()
{
    cin >> S;

    for(int i = S.size() - 2;i >= 0;i--)
    {
        int len = i;
        if(len % 2 == 1) continue;
        string b = S.substr(0,len / 2);
        string e = S.substr(len / 2,len / 2);
        if(b == e)
        {
            cout << len<< endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
line = gets.split(' ').map(&:to_i)

W = line[0]
H = line[1]
X = line[2]
Y = line[3]

ans1 = W.to_f * H.to_f / 2.0
if X * 2 == W and Y * 2 == H then
  ans2 = 1
else
  ans2 = 0
end
  
print ans1.to_s + " " + ans2.to_s

Measured memory_bytes: 14380
#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
typedef vector <int> vi;
typedef vector <long long int> v1;
#define pb push_back
#define iter(i,a,b) for(i=a;i<b;i++)

int main()
{
    ios_base::sync_with_stdio(false);      //for fast cin and cout streams
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    while(test--)
{

string a,b;
      int i;
      
int c=0;
      cin>>a>>b;
      iter(i,0,a.length())
      {if(a[i]!=b[i])
        c++;
      }
      cout<<c;







}

return 0;
}






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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> s(h, vector<char>(w));
  rep(i, h) rep(j, w) cin >> s[i][j];

  vector<vector<int>> a(h, vector<int>(w, 0));
  int num_s = 0;
  rep(i, h) {
    int li = 0;
    bool empty = true;
    rep(j, w) {
      if (s[i][j] == '#') {
        ++num_s;
        empty = false;
      }
      if (j == w-1 && empty) continue;
      if (j == w-1) {
        for (int k = li; k < w; ++k) {
          a[i][k] = num_s;
        }
        continue;
      }
      if (s[i][j+1] == '#' && !empty) {
        for (int k = li; k <= j; ++k) {
          a[i][k] = num_s;
        }
        li = j + 1;
      }
    }
  }

  int ci;
  rep(i, h) if (a[i][0] > 0) {
    ci = i;
    break;
  }

  rep(i, h) {
    if (a[i][0] > 0) {
      ci = i;
      continue;
    }
    rep(j, w) a[i][j] = a[ci][j];
  }

  rep(i, h) {
    rep(j, w-1) printf("%d ", a[i][j]);
    printf("%d\n", a[i][w-1]);
  }
  return 0;
}

Measured memory_bytes: 4156
class FordFulkerson:
    def __init__(self,n):
        self.visited=[False]*n
        self.G=[[0]*n for _ in range(n)]
        self.n=n
    def add_edge(self,fr,to,cap):
        self.G[fr][to]=cap
    def dfs(self,start,goal,f):
        if start==goal:
            return f
        self.visited[start]=True
        for i in range(self.n):
            if i==start:
                continue
            if (not self.visited[i]) and self.G[start][i]>0:
                d=self.dfs(i,goal,min(f,self.G[start][i]))
                if d>0:
                    self.G[start][i]-=d
                    self.G[i][start]+=d
                    return d
        return 0
    def maxflow(self,source,sink):
        flow=0
        while True:
            self.visited=[False]*self.n
            f=self.dfs(source,sink,float('inf'))
            if f==0:
                break
            flow+=f
        return flow

def BipartiteMatching(Pairs,a,b):
    solver=FordFulkerson(a+b+2)
    for x,y in Pairs:
        solver.add_edge(x+1,a+y+1,1)
    for x in range(a):
        solver.add_edge(0,x+1,1)
    for y in range(b):
        solver.add_edge(a+y+1,a+b+1,1)
    return solver.maxflow(0,a+b+1)

N = int(input())
R = [list(map(int,input().split())) for i in range(N)]
B = [list(map(int,input().split())) for i in range(N)]
Pairs = []
for i in range(N):
    for j in range(N):
        if R[i][0] < B[j][0] and R[i][1]<B[j][1]:
            Pairs.append((i,j))
print(BipartiteMatching(Pairs,N,N))

Measured memory_bytes: 3572
#include <iostream>
#include<queue>
#include<string>
#define NIL -1
using namespace std;
string color[101];//白色未访问，灰色访问，黑色退出队列
queue<int >BreathFirstSearch;//创建队列
int Distance[101];
int AM[101][101];
int total;
void includeInsertQueue(int i)
{
	for (int j = 0; j <= total; j++)
	{
		if (AM[i][j] && color[j] == "White")//存在且未被访问
		{
			color[j] = "Grey", Distance[j] =Distance[i]+1;//找到的点距离是其上一个再加一
			BreathFirstSearch.push(j);
		}
	}
}
void includeFirstSearch(int i)
{
	int next;
	BreathFirstSearch.push(i);//压入起点
	Distance[i] =0;//起点到起点的距离为0；
	color[i] = "Grey";
	while (!BreathFirstSearch.empty())
	{
		next = BreathFirstSearch.front();//队列头中取出元素
		BreathFirstSearch.pop();
		color[next] = "Black";
		includeInsertQueue(next);

	}
}
int main()
{	int TotalOfConnectedNode, node[101], connectednode;
	for (int i = 0; i < 101; i++) Distance[i]= NIL;
	for (int i = 0; i < 101; i++)color[i] = "White";
	for (int i = 0; i < 101; i++)
		for (int j = 0; j < 101; j++)
			AM[i][j] = 0;
	cin >> total;
	for (int i = 0; i < total; i++)//有向图
	{
		cin >> node[i] >> TotalOfConnectedNode;
		if (TotalOfConnectedNode == 0) continue;
		for (int j = 0; j < TotalOfConnectedNode; j++)
		{
			cin >> connectednode;
			AM[node[i]][connectednode] = 1;
		}
	}
	includeFirstSearch(node[0]);
	for (int i = 0; i < total; i++)
		cout << node[i] << " " << Distance[node[i]] << endl;

	
	return 0;
}



Measured memory_bytes: 3260
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;

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

int used[25][25];
int dd[25][25];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int h,w; cin >> h >> w;
	char fi[h][w];
	int a,b,c,d;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> fi[i][j];
			if(fi[i][j]=='.'){
				a=i,b=j;
			}
		}
	}
	queue<pair<int,int>> q;
	q.push(make_pair(a,b));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(fi[i][j]=='.')dd[i][j]=1e9;
		}
	}
	dd[a][b]=0;
	c=a,d=b;
	while(q.size()){
		int x=q.front().first,y=q.front().second;
		q.pop();
		for(int i=0;i<4;i++){
			int nx=x+dx[i],ny=y+dy[i];
			if(0<=nx&&nx<h&&0<=ny&&ny<w){
				if(fi[nx][ny]=='#')continue;
				if(dd[nx][ny]>dd[x][y]+1){
					dd[nx][ny]=dd[x][y]+1;
					q.push(make_pair(nx,ny));
				}
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(dd[c][d]<dd[i][j]){
				c=i,d=j;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(fi[i][j]=='.')dd[i][j]=1e9;
		}
	}
	q.push(make_pair(c,d));
	dd[c][d]=0;
	while(q.size()){
		int x=q.front().first,y=q.front().second;
		q.pop();
		for(int i=0;i<4;i++){
			int nx=x+dx[i],ny=y+dy[i];
			if(0<=nx&&nx<h&&0<=ny&&ny<w){
				if(fi[nx][ny]=='#')continue;
				if(dd[nx][ny]>dd[x][y]+1){
					dd[nx][ny]=dd[x][y]+1;
					q.push(make_pair(nx,ny));
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(fi[i][j]=='.'){
				for(int ii=0;ii<h;ii++){
					for(int jj=0;jj<w;jj++){
						if(fi[ii][jj]=='.')dd[ii][jj]=1e9;
					}
				}
				queue<pair<int,int>> q;
				q.push(make_pair(i,j));
				dd[i][j]=0;
				while(q.size()){
					int x=q.front().first,y=q.front().second;
					q.pop();
					for(int i=0;i<4;i++){
						int nx=x+dx[i],ny=y+dy[i];
						if(0<=nx&&nx<h&&0<=ny&&ny<w){
							if(fi[nx][ny]=='#')continue;
							if(dd[nx][ny]>dd[x][y]+1){
								dd[nx][ny]=dd[x][y]+1;
								q.push(make_pair(nx,ny));
							}
						}
					}
				}
				for(int i=0;i<h;i++){
					for(int j=0;j<w;j++){
						ans=max(ans,dd[i][j]);
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
const int N=(int)4e5+5;
void solve()
{
    int n,i;cin>>n;
    ll A[n],all_xor=0ll;
    fo(i,0,n){cin>>A[i];all_xor^=A[i];}
    fo(i,0,n)cout<<(A[i]^all_xor)<<" ";
    cout<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 5168
def gcd(A,B):
    if(A<B):
        tmp=A
        A=B
        B=tmp

    r=A%B

    while(r!=0):
        A=B
        B=r
        r=A%B
        
    return B


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

l = a * b /gcd(a, b)
l = int(l)
print("{}".format(l))

Measured memory_bytes: 3060
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var L, R int
	fmt.Scan(&L, &R)
	ans := 0
	// R - L >= 2018ならば、必ず2019の倍数(0を含む)が存在するので、(i*j)mod 2019 == 0となるような(i,j)の組みを選べる
	if R-L < 2018 {
		ans = 2020
		for i := L; i < R; i++ {
			for j := i + 1; j <= R; j++ {
				// fmt.Printf("(%d x %d) mod 2019=%d\n", i, j, (i*j)%2019)
				ans = min(ans, (i*j)%2019)
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        BigInteger[] t = new BigInteger[n];
        for (int i = 0; i < t.length; i++) {
            t[i] = sc.nextBigInteger();
        }
        BigInteger ans = BigInteger.ONE;
        for (int i = 0; i < t.length; i++) {
            ans = lcm(ans, t[i]);
        }
        System.out.println(ans);

    }

    public static BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply(b).divide(gcd(a, b));
    }

    public static BigInteger gcd(BigInteger a, BigInteger b) {
        if(b == BigInteger.ZERO) return a;
        else return gcd(b, a.mod(b));
    }
}


Measured memory_bytes: 36284
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S;
    cin>>S;

    rep(i,3){
        cout << S[i];
    }
    cout << endl;

    

    



}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 1000000000000005
#define MOD 1000000007
#define N 10005
#define M 27000
#define LOG 1000000
#define KOK 650
#define EPS 0.000000001
using namespace std;

struct reyiz {

	int w,s,v;

} r[N];

int n;
ll dp[2][N];

int main() {

	//freopen("input.txt","r",stdin);	

	scanf("%d",&n);

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

		scanf("%d %d %d",&r[i].w,&r[i].s,&r[i].v);

	}

	sort(r+1,r+1+n,[](reyiz a,reyiz b) {

		return a.w+a.s<b.w+b.s;

	});

	for(int j=0;j<=10001;j++) dp[1][j]=dp[0][j]=-inf;

	dp[1][0]=0;

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

		bool cur=i&1;
		bool nx=!cur;

		for(int j=0;j<=10001;j++) {

			umax(dp[nx][j],dp[cur][j]);

			if(j<=r[i].s) {

				umax(dp[nx][min(10001,j+r[i].w)],dp[cur][j]+r[i].v);

			}

			dp[cur][j]=-inf;

		}

	}

	ll ans=-inf;

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

		umax(ans,dp[!(n&1)][i]);

	}

	printf("%lld",ans);

}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    static int[] A = new int[1000000];
    static int n;

    public static int binarySearch(int key) {
        int left = 0;
        int right = n;
        int mid;

        while(left < right)
        {
            mid = (left + right) / 2;
            if(key == A[mid]) return 1;
            if(key > A[mid]) left = mid + 1;
            else if(key < A[mid]) right = mid;
        }
        return 0;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int i, q, k, sum = 0;
        for(i = 0; i < n; i++) {
            A[i] = sc.nextInt();
        }
        q = sc.nextInt();
        for(i = 0; i < q; i++) {
            k = sc.nextInt();
            if(binarySearch(k) == 1) sum++;
        }
        System.out.println(sum);
    }
}



Measured memory_bytes: 95932
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut a: Vec<u32> = Vec::new();

    for _ in 0..n {
        a.push(parse_line().unwrap());
    }

    let mut cp = a.clone();
    cp.sort();
    let (max1, max2) = (cp.pop().unwrap(), cp.pop().unwrap());

    for num in a {
        if num == max1 {
            println!("{}", max2);
        } else {
            println!("{}", max1);
        }
    }
}


Measured memory_bytes: 3944
N, M, X = map(int, input().split())
C = [list(map(int, input().split())) for i in range(N)]

ans = float('inf')
for i in range(1, 2**N):
    score = [0] * M
    cost = 0
    for j in range(N):
        if i >> j & 1:
            cost += C[j][0]
            for m in range(M):
                score[m] += C[j][m+1]
    
    if all([s>=X for s in score]):
        ans = min(ans, cost)

if ans < float('inf'):
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9224
<?php
$n = trim(fgets(STDIN));
$blue = [];
for($i = 0; $i < $n; $i++) {
    $temp = trim(fgets(STDIN));
    if(!empty($blue[$temp])) {
        $blue[$temp] += 1;
    } else {
        $blue[$temp] = 1;
    }
}
$m = trim(fgets(STDIN));
$red = [];
for($j = 0; $j < $m; $j++) {
    $temp = trim(fgets(STDIN));
    if(!empty($red[$temp])) {
        $red[$temp] -= 1;
    } else {
        $red[$temp] = -1;
    }
}
//var_dump($blue);
//var_dump($red);
$ret = [];

foreach($blue as $blue_key => $blue_val) {
    $ret[$blue_key] = '';
    if(array_key_exists($blue_key, $red)) {
        $ret[$blue_key] = $blue_val + $red[$blue_key];
    } else {
        $ret[$blue_key] = $blue_val;
    }
}
//var_dump($ret);
$max = max($ret);
echo ($max > 0) ? $max : '0';

Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <cmath>

using namespace std;

int main() {
    size_t h, n;
    cin >> h >> n;
    vector<size_t> a(n, 0);
    for (size_t i = 0; i < n; ++i)
        cin >> a[i];
    for (auto e : a) {
        if (h > e) {
            h -= e;
        } else {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}




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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 1e5 + 10;

int n, a[N];

void dfs(int x)
{
	long long s = 0;
	for (int i = 1; i <= n; ++i) 
		s += a[i] - 1;
	if (s & 1)
	{
		puts(x ? "Second" : "First");
		return;
	} 
	int cnt = 0;
	for (int i = 1; i <= n; ++i)
		if (a[i] & 1) ++cnt;
	for (int i = 1; i <= n; ++i)
		if (a[i] == 1) cnt = 233;
	if (cnt != 1)
	{
		puts(x ? "First" : "Second");
		return;
	}
	for (int i = 1; i <= n; ++i) 
		if (a[i] & 1) --a[i];
	int v = 0;
	for (int i = 1; i <= n; ++i) v = __gcd(v, a[i]);
	for (int i = 1; i <= n; ++i) a[i] /= v;
	dfs(x ^ 1);
}

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i]);
	dfs(0);
}

Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

struct uf_tree {
  vector<int> par, sizes;
  uf_tree(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  }
  int find(int x) {
    if (x == par[x])
      return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (sizes[x] < sizes[y]) {
      swap(x, y);
    }
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sizes[find(x)]; }
};

int N, M;
vector<int> A, B;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  A.resize(M);
  B.resize(M);
  for (int i = 0; i < M; i++) {
    int ai, bi;
    cin >> ai >> bi;
    A[i] = ai - 1;
    B[i] = bi - 1;
  }
  uf_tree uf(N);

  vector<long> ans_vec(M, 0);
  ans_vec[M - 1] = (long)N * (long)(N - 1) / 2L;

  for (int i = M - 1; i > 0; i--) {
    long a_par = uf.find(A[i]);
    long b_par = uf.find(B[i]);

    if (a_par == b_par) {
      ans_vec[i - 1] = ans_vec[i];
    } else {
      long an = uf.size(a_par);
      long bn = uf.size(b_par);
      ans_vec[i - 1] = ans_vec[i] - (long)an * (long)bn;
    }

    uf.unite(A[i], B[i]);
  }

  for (auto &e : ans_vec) {
    cout << e << endl;
  }

  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define read(arr,n)	for(int i=0;i<n;i++) cin>>arr[i];
#define print(arr,n) for(int i=0;i<n;i++) cout << arr[i]<<' ';cout << endl;

using namespace std;

typedef long long ll;

double exp(ll p) {
	return (p+1)/2.0;
}

void solve() {
	ll n, k;
	cin >> n >> k;
	vector<ll> arr(n);	read(arr,n);
	double sum = 0, maxsum = 0;
	
	for (int i = 0; i < k; i++){
		sum += exp(arr[i]);
//		cout << sum << endl;
	}
	
	maxsum = max(maxsum, sum);

	int r = k;
	int l = 0;		

	while (r < n) {
		sum += exp(arr[r]);
		sum -= exp(arr[l]);	
		l++;
		r++;
//		cout << maxsum << endl;
		maxsum = max(maxsum, sum);
	}
	
	cout <<setprecision(15) << maxsum << endl;	return;
}

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


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

int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    cout << H2 * 60 + M2 - H1 * 60 - M1 - K;
    return 0;
}

Measured memory_bytes: 3640
//sppsfver - 20.08.2020
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair <ll, ll>;
const int MAX = 1e5+5;
const ll MOD = 1e9+7;

ll n;
ll memo[2005];

ll fexpo (ll a, ll b){
	ll ans= 1;
	while (b){
		if (b&1) ans = (ans*a)% MOD;
		a = (a*a)%MOD;
		b>>=1;
	}
	return ans % MOD;
}

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

	cin >> n;
	cout << ((fexpo (10, n) - 2*fexpo(9,n) + MOD)%MOD + fexpo (8,n) + MOD)%MOD << endl;
    return 0;
}


Measured memory_bytes: 3648
namespace VainZero.Procon.FSharp

open System
open System.Collections.Generic

[<AutoOpen>]
module Operators =
  let read f = Console.ReadLine().Split([|' '|]) |> Array.map f

module Program =
  let bellmanFord (g: array<array<_>>) v =
    let inf = Int64.MaxValue / 3L
    let n = g.Length
    let dist = [|for _ in 0..(n - 1) -> inf|]
    dist.[v] <- 0L
    let tryUpdate () =
      let mutable didUpdate = false
      for u in 0..(n - 1) do
        for (v, w) in g.[u] do
          if dist.[u] < inf then
            let d = dist.[u] + w
            if dist.[v] > d then
              dist.[v] <- d
              didUpdate <- true
      didUpdate
    for i in 0..(n - 2) do
      tryUpdate () |> ignore
    if tryUpdate () then
      None
    else
      Some dist

  let adjacencyList n edges =
    let g = [|for _ in 0..(n - 1) -> ResizeArray()|]
    for (u, v, w) in edges do
      g.[u].Add((v, w))
    g |> Array.map (fun list -> list.ToArray())

  let reachableNodesTo sink (n, m, (edges: array<_>)) =
    // 双対グラフの隣接リスト表現
    // 辺の重みは、その辺の番号を表す。
    let g = [|for _ in 0..(n - 1) -> ResizeArray()|]
    for j in 0..(m - 1) do
      let (u, v, _) = edges.[j]
      g.[v].Add((u, j))

    let reachable = [|for e in 0..(m - 1) -> false|]
    let visited = [|for u in 0..(n - 1) -> false|]
    let queue = Queue<_>()
    queue.Enqueue(sink)
    while queue.Count > 0 do
      let u = queue.Dequeue()
      if not visited.[u] then
        visited.[u] <- true
        for (v, j) in g.[u] do
          reachable.[j] <- true
          queue.Enqueue(v)

    [|
      for j in 0..(m - 1) do
        if reachable.[j] then
          yield edges.[j]
    |]

  [<EntryPoint>]
  let main _ =
    let [|n; m|] = read int
    let edges =
      [|
        for _ in 0..(m - 1) do
          let [|a; b; c|] = read int64
          yield (int a - 1, int b - 1, c)
      |]

    let calc () =
      // 終点に到達できない辺を除去する。
      let edges = (n, m, edges) |> reachableNodesTo (n - 1)
      // スコアを -1 倍することで、最大化問題を最小化問題 (最短経路問題) に変換する。
      let edges = [|for (u, v, w) in edges -> (u, v, -w)|]
      let g = adjacencyList n edges
      bellmanFord g 0
      |> Option.map (fun dist -> (- dist.[n - 1]))

    match calc () with
    | Some score ->
      printfn "%d" score
    | None ->
      printfn "inf"

    0


Measured memory_bytes: 14684
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 200200;
const int inf = 1e9;

char s[MAX];
int f[1<<26];
int g[MAX];
int mask[MAX];

int main(void) {
  scanf("%s", s);
  int n = strlen(s);
  REP(i, n) s[i] -= 'a';

  memset(f, 63, sizeof(f));
  
  mask[n] = 0;
  for (int i = n-1; i >= 0; --i) {
    mask[i] = mask[i + 1] ^ (1<<s[i]);
  }

  g[n] = 0;
  f[mask[n]] = 0;
  for (int i = n-1; i >= 0; --i) {
    int fi = f[mask[i]];
    REP(j, 26) fi = min(fi, f[mask[i] ^ (1<<j)]);
    fi++;
    g[i] = fi;
    f[mask[i]] = min(f[mask[i]], g[i]);
  }

  printf("%d\n", g[0]);
  return 0;
}


Measured memory_bytes: 264192
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define IO ios::sync_with_stdio(0);cin.tie(0); cout.tie(0) ; 
#define adsw  ll Test ;cin >> Test; while(Test--)
using namespace std;

int main(){ IO 


   string s,t;
   cin >> s >> t;
   
   ll ans=0;
   for(int i=0;s[i];i++)
   {
       if(s[i]!=t[i])
       ans++;
   }
   
   cout<<ans<<"\n";
  

 
   
    return 0;
} 


Measured memory_bytes: 3884
#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 = (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 T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T 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,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-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, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
vector<ll>dist(100005);
void dfs(ll k,vector<vector<ll>>&g,ll par,ll d){
  dist[k]=d;
  for(auto to:g[k]){
    if(to != par){
      dfs(to,g,k,d+1); 
    }
  }
}
ll ret=0;
void dfs2(ll k,vector<vector<ll>>&g,ll par,ll d){
  if(d>dist[k])return;
  chmax(ret,dist[k]-1);
  for(auto to:g[k]){
    if(to != par){
      dfs2(to,g,k,d+1); 
    }
  }
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  ll u,v;cin>>u>>v;u--;v--;
  vector<vector<ll>>g(n);
  rep(i,0,n-1){
    ll a,b;cin>>a>>b;a--;b--;
    g[a].PB(b);
    g[b].PB(a);
  }
  dfs(v,g,-1,0);
  dfs2(u,g,-1,0);
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 11776
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
using lint = long long;

#pragma GCC optimize ("-O3", "unroll-loops")
const int nmax = 204800, block = 4096, unrl = 8;
int a[nmax], b[nmax];

int main() {

	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	for (int i = 0; i < N; i++) scanf("%d", &b[i]);

	int ans = 0;
	for (int i = 0; i + unrl <= N; i += unrl) {
		for (int j = 0; j + block <= N; j += block) {
			for (int k = j; k < block + j; k++) {

				ans ^= (a[i + 0] + b[k]) ^ (a[i + 1] + b[k]);
				ans ^= (a[i + 2] + b[k]) ^ (a[i + 3] + b[k]);
				ans ^= (a[i + 4] + b[k]) ^ (a[i + 5] + b[k]);
				ans ^= (a[i + 6] + b[k]) ^ (a[i + 7] + b[k]);

			}
		}
	}

	for (int i = 0; i < N / unrl * unrl; i++) {
		for (int j = N / block * block; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}	
	for (int i = N / unrl * unrl; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}

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

	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main (){
	int n,d,max,min;
	long long sum;
	scanf("%d %d",&n,&d);
	sum = max = min = d;
	while(--n > 0){
		scanf("%d",&d);
		if(d > max)max = d;
		if(d < min)min = d;
		sum += d;
	}
	printf("%d %d %lld\n",min,max,sum);
	return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2017
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
#define maxn 100009
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;

int main()
{
    int jishu = 0,oushu = 0;
    LL num[maxn];
    for(int i=0;i<3;i++){
        cin>>num[i];
        if(num[i] & 1)
            jishu++;
        else
            oushu++;
    }
    sort(num,num+3);
    if(jishu == 3 || oushu == 3)
        cout<<(2 * num[2] - num[1] - num[0])/2<<endl;
    else if(jishu == 1)
    {
        for(int i=0;i<3;i++)
            if(!(num[i] & 1))
                num[i] += 1;
        cout<<(2 * num[2] - num[1] - num[0])/2 + 1<<endl;
    }
    else if(oushu == 1)
    {
        for(int i=0;i<3;i++)
            if(num[i] & 1)
                num[i] += 1;

        cout<<(2 * num[2] - num[1] - num[0])/2 + 1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int N,K,half,low,high;
int card[1002][1002];
bool bit[1002];

bool check(){
  rep(i,K){
    int sum = 0;
    rep(j,half){
      sum += bit[card[i][j] - 1];
      if(sum > high) return false;
    }
    if(sum < low) return false;
  }
  return true;
}

int main(){
  srand((unsigned)time(NULL));

  while(scanf("%d%d",&N,&K) != EOF){
    half = N / 2;
    low = N / 8;
    high = 3 * N / 8;
    rep(i,K){
      rep(j,half){
        scanf("%d",&card[i][j]);
      }
    }

    while(1){
      rep(i,N){
        bit[i] = rand() % 2;
      }
      if(check()) break;
    }
    rep(i,N) printf("%d",bit[i]);
    putchar('\n');
  }
}

Measured memory_bytes: 2588
#include<stdio.h>
int main(){

    int a,b,c;

    scanf("%d%d",&a,&b);

    if(a<=5){
     c=0;
    }else if(a<=12){
     c=b/2;
    }else{
     c=b;
    }

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

    return 0;

}

Measured memory_bytes: 128
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        int aa = (int)a.charAt(0);
        int bb = (int)b.charAt(0);
        
        if(aa==bb){
            System.out.print("=");
        }else if(aa<bb){
            System.out.print("<");
        }else{
            System.out.print(">");
        }
   }
}


Measured memory_bytes: 35428
#include <iostream>
#include <algorithm>

const int MAX_N  = 100001;

int dp[MAX_N];

using namespace std;

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

  for(int i = 0; i < MAX_N; i++) dp[i] = N;
  dp[0] = 0;

  for(int n = 1; n <= N; n++){
    for (int pow6 = 1; pow6 <= n; pow6*= 6){
      dp[n] = min(dp[n], dp[n - pow6] + 1);
    }

    for(int pow9 = 1; pow9 <= n; pow9 *= 9){
      dp[n] = min(dp[n], dp[n - pow9] + 1);
    }
  }

  cout << dp[N] <<endl;
  
  return 0;
}

Measured memory_bytes: 640
s = input()
gx,gy = map(int, input().split())

x_lis=[]
y_lis=[]

cnt=0
now="x"
for i in range(len(s)):
    if s[i]=="F":
        cnt+=1
    else:
        if now=="x":
            x_lis.append(cnt)
            now="y"
        else:
            y_lis.append(cnt)
            now="x"
        cnt=0

if now=="x":
    x_lis.append(cnt)
    now="y"
else:
    y_lis.append(cnt)
    now="x"

now=set([0])
for i in range(len(x_lis)):
    nxt=set()
    for itm in now:
        nxt.add(itm + x_lis[i])
        if i!=0:
            nxt.add(itm - x_lis[i])
    now=nxt

if not gx in now:
    print("No")
    exit()

now=set([0])
for i in range(len(y_lis)):
    nxt=set()
    for itm in now:
        nxt.add(itm + y_lis[i])
        nxt.add(itm - y_lis[i])
    now=nxt

if not gy in now:
    print("No")
else:
    print("Yes")

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/****** define constant end ********/
/****** define variable start ******/

string sa, sb, sc;

/*
ll n;
vl a;

*/
/******* define variable end *******/
int solve() {
	cin >> sa >> sb >> sc;
	ll a = sa.size();
	ll b = sb.size();
	ll c = sb.size();
	ll a_ite = 0;
	ll b_ite = 0;
	ll c_ite = 0;
	ll turn = 0;
	while(!(turn == 0 && a_ite == sa.size()) && !(turn == 1 && b_ite == sb.size()) && !(turn == 2 && c_ite == sc.size())){
		if(turn == 0){
			if(sa.substr(a_ite, 1) == "a"){
				a--;
				a_ite++;
				turn = 0;
			}else if(sa.substr(a_ite, 1) == "b"){
				a--;
				a_ite++;
				turn = 1;
			}else if(sa.substr(a_ite, 1) == "c"){
				a--;
				a_ite++;
				turn = 2;
			}
		}else if(turn == 1){
			if(sb.substr(b_ite, 1) == "a"){
				b--;
				b_ite++;
				turn = 0;
			}else if(sb.substr(b_ite, 1) == "b"){
				b--;
				b_ite++;
				turn = 1;
			}else if(sb.substr(b_ite, 1) == "c"){
				b--;
				b_ite++;
				turn = 2;
			}
		}else{
			if(sc.substr(c_ite, 1) == "a"){
				c--;
				c_ite++;
				turn = 0;
			}else if(sc.substr(c_ite, 1) == "b"){
				c--;
				c_ite++;
				turn = 1;
			}else if(sc.substr(c_ite, 1) == "c"){
				c--;
				c_ite++;
				turn = 2;
			}
		}
	}
	if(turn == 0 && a_ite == sa.size()){
		cout << "A" << endl;
	}else if(turn == 1 && b_ite == sb.size()){
		cout << "B" << endl;
	}else if(turn == 2 && c_ite == sc.size()){
		cout << "C" << endl;
	}
/*
	cin >> n;
	a.resize(n);
	REP(i, n){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll tmp = 0;
	ll ans = 0;
	REP(i, n){
		if(i % 2 == 0){
			if(i != 0){
				ans += abs(tmp - a[i/2 + 1 + ceil((long double)n/2)]);
			}
			tmp = a[i/2 + 1 + ceil((long double)n/2)];
			cout << tmp << endl;
		}else{
			if(i != n-1){
				ans += abs(tmp - a[i/2]);
			}
			tmp = a[i/2];
			cout << tmp << endl;
		}
	}
	cout << ans << endl;
	*/
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 256
// Code for D - Div Game
#include <bits/stdc++.h>
using namespace std;

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int count_of(int x) {
  int i = 1;
  while (x >= 0) {
    x -= i;
    i++;
  }

  return i - 2;
}

int main() {
  int64_t N;
  cin >> N;

  map<int64_t, int> primes = prime_factor(N);

  int count = 0;
  for (map<int64_t, int>::iterator itr = primes.begin(); itr != primes.end(); itr++) {
    count += count_of(itr->second);
  }

  cout << count << endl;
	return 0;
}


Measured memory_bytes: 3636
n = int(input())
a = [int(i) for i in input().split()]

def stockBuySell(price, n): 
    balance = 1000
    # Prices must be given for at least two days 
    if (n == 1): 
        return
      
    # Traverse through given price array 
    i = 0
    while (i < (n - 1)): 
          
        # Find Local Minima 
        # Note that the limit is (n-2) as we are 
        # comparing present element to the next element 
        while ((i < (n - 1)) and 
                (price[i + 1] <= price[i])): 
            i += 1
          
        # If we reached the end, break 
        # as no further solution possible 
        if (i == n - 1): 
            break
          
        # Store the index of minima 
        buy = i 
        i += 1
          
        # Find Local Maxima 
        # Note that the limit is (n-1) as we are 
        # comparing to previous element 
        while ((i < n) and (price[i] >= price[i - 1])): 
            i += 1
              
        # Store the index of maxima 
        sell = i - 1
          
        balance = balance + (balance // price[buy]) * (price[sell] - price[buy])

    return balance
          
print(stockBuySell(a, n))

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


#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007

//MIN-MAX
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))



main()
{
	FASTIO;

	ll n,k,c;
	 cin>>n>>k>>c;;
	 string s;
	  cin>>s;
	  vector<ll>a;
	  ll i=0;
	  while(i<n)
	  {

          if(s[i]=='o')
          {
               a.eb(i);
               i+=(c+1);

          }
          else
            i++;

         if(a.size()==k)
            break;

      }


      vector<ll>b;
      i=n-1;

      while(i>=0)
      {
           if(s[i]=='o')
          {
               b.eb(i);
               i-=(c+1);

          }
          else
            i--;

         if(b.size()==k)
            break;
      }
      sort(b.begin(),b.end());


      for(int i=0;i<min(a.size(),b.size());i++)
      {
          if(a[i]==b[i])
            cout<<a[i]+1<<"\n";
      }



}













Measured memory_bytes: 5108
def examA():
    N = I()
    T = LI()
    A = LI()
    S = [-1]*N
    S[0] = T[0]; S[-1]=A[-1]
    ans = 1
    for i in range(1,N):
        if T[i]==T[i-1]:
            continue
        S[i] = T[i]
    flag = -1
    for i in range(N):
        if S[i]==A[i]:
            flag = i
            break
    if not (A[flag]==A[0] and A[flag]==T[-1]):
        print(0)
        return
    for i in range(N-1)[::-1]:
        if A[i]==A[i+1]:
            continue
        if S[i]==-1:
            S[i] = A[i]
        else:
            S[i] = max(S[i],A[i])
    #print(S)
    P = []
    pindex = []
    for i in range(N):
        if S[i]==-1:
            continue
        P.append(S[i])
        pindex.append(i)
    flag_U = True
    for i in range(len(P)-1):
        if P[i+1]>P[i]:
            if not flag_U:
                print(0)
                return
        elif P[i+1]<P[i]:
            flag_U = False
    ans = 1
    p = -1
    for i in range(N):
        if S[i]==-1:
            cur = min(P[p + 1], P[p])
            ans *= cur
            ans %= mod
        else:
            p += 1

    print(ans)
    return

def examB():
    T = I()
    A = LI()

    ans = 0
    print(ans)
    return

def examC():
    def dfs(n,s,edges,visited):
        cost = BC[s]
        now = []
        for i in edges[s]:
            if visited[i]:
                continue
            visited[i] = True
            cur,visited = dfs(n,i,edges,visited)
            now.append((cur, i))
        now.sort()
        for c,i in now:
            cost += c-now[0][0]
            children[i] = c-now[0][0]
        return cost,visited

    N, M = LI()
    V = [[]for _ in range(N)]
    for i in range(N-1):
        p = I()
        V[i+1].append(p)
        V[p].append(i+1)
    children = [-1]*N
    BC = defaultdict(int)
    for i in range(M):
        b, c = LI()
        BC[b] = c
    visited = [False]*N
    visited[0] = True
    ans = dfs(N,0,V,visited)
    print(children)
    print(ans)
    return

def examD():
    N, K = LI()
    W = [LI()for _ in range(N)]
    l = 0; r = 10**20
    while(r-l>1):
        now = (l+r)//2
        cur = 0
        for i in range(N):
            if now>=W[i][0]:
                cur += ((now-W[i][0])//W[i][1]+1)
        if cur<K:
            l = now
        else:
            r = now
    ans = r
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

Measured memory_bytes: 59100
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  rep(i, s.size()){
    if(s[i] != t[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a;i < b;i++)
#define rrep(i,a,b) for(int i = a;i >= b;i--)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << #x << ": " << x << endl;
typedef long long ll;
using namespace std;

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

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

   int a;
   cin >> a;
   cout << (a % 2 != 0 ? (a + 1) / 2 * (a / 2) : a / 2 * a / 2) << endl;

   return 0;
}

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

int main(){
  int h, w;

  while(true){
    cin >> h >> w;
    if( h + w == 0 ){ break; }

    for( int i = 0; i < h; i++){
      for( int j = 0; j < w; j++){
        cout << "#";
      }
      cout << "\n";
    }
    cout << "\n";
  }

  return 0;
}

Measured memory_bytes: 1120