akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

x,n=map(int,input().split())
p=list(map(int,input().split()))

# num=[i for i in range(1,101)]
# for i in p:
#     num[i-1]=-1

# num.append(0)
# num.append(101)
# num.sort()
# while True:
#     if num[0]!=-1:
#         break
#     num.pop(0)
# print(num)

# min=1000
# for i in num:
#     if min>abs(x-i):
#         min=abs(x-i)
#         ans=i
# print(ans)

i=0
while True:
    if not x-i in p :
        print(x-i)
        break
    elif not x+i in p:
        print(x+i)
        break
    i+=1

# num=[]
# for i in range(101):
#     num.append(x-i)
#     num.append(x+i)



Measured memory_bytes: 61824
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll n;
    ll cnt[5];
    string s;

    rep(i, 5){
        cnt[i] = 0;
    }

    cin >> n;
    rep(i, n){
        cin >> s;
        if(s[0] == 'M') cnt[0]++;
        if(s[0] == 'A') cnt[1]++;
        if(s[0] == 'R') cnt[2]++;
        if(s[0] == 'C') cnt[3]++;
        if(s[0] == 'H') cnt[4]++;
    }

    ll res = 0;
    rep(i, 3){
        reps(j, i+1, 4){
            reps(k, j+1, 5){
                res += cnt[i]*cnt[j]*cnt[k];
                //cout << i << " " << j << " " << k << endl;
                //cout << cnt[i] << " " << cnt[j] << " " << cnt[k] << endl << endl;
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func debug(a ...interface{}) {
	if os.Getenv("ONLINE_JUDGE") == "false" {
		fmt.Fprintln(os.Stderr, a...)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1001), 1001001)

	x1, y1, x2, y2 := scanInt(), scanInt(), scanInt(), scanInt()

	dx := x2 - x1
	dy := y2 - y1
	x3, y3 := x2-dy, y2+dx
	x4, y4 := x3-dx, y3-dy
	fmt.Fprintln(wr, x3, y3, x4, y4)
}


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

using namespace std;



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

	int n; cin >> n;
	for(int i = 0; i < n; ++i) {
		int x; cin >> x;
		if (x & 1) continue;
		if (x%3 && x%5) {
			cout << "DENIED" << '\n';
			return 0;
		}
	}

	cout << "APPROVED" << '\n';

	return 0;	
}

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

int main(){
  int N;
  cin >> N;
  
  for(int i = 0 ; i < N ; i++ ){
    string x;
    cin >> x;
    
    if ( x == "Y" ){
      cout << "Four" << endl;
      break;}

    if ( i == N - 1){
      cout << "Three" << endl;
  }
}
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
s = input()
ans = 0
for i in range(len(s) - 1):
  if(s[i] == s[i + 1]):
    ans += 1

if(ans + (k * 2) > n - 1):
  ans = n - 1
else:
  ans += (k * 2)
        
print(ans)

Measured memory_bytes: 3316
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

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

    vector<ll> a(n);

    bool  flag = true;
    rep(i, n)  {
        cin >> a[i];
        if(a[i]==0) flag = false;
    }
    if(!flag) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    ll tmp = 1e18;

    rep(i, n) {
        ans *= a[i];
        tmp /= a[i];
        if(tmp == 0) {
            cout << -1 << endl;
            return 0;
        }
    }


    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4052
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
		long[] b= new long[100001];
  		long sum=0;
  
		for(int c=0;c<n;c++){
    		int a=sc.nextInt();
            b[a]++;
          	sum+=a;
    	}
  	int q=sc.nextInt();
  
  for(int d=0;d<q;d++){
 	 int b1=sc.nextInt();
    int c=sc.nextInt();
    sum=sum-b[b1]*(long)b1+b[b1]*(long)c;
    System.out.println(sum);
    b[c]+=b[b1];
    b[b1]=0;
  
  }

    	
    }
}

Measured memory_bytes: 60708
#include<stdio.h>
#include<cassert>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>

using namespace std;

#define x first
#define y second
#define ll long long
#define NMAX 20005
#define INF 1000000005

char s1[NMAX], s2[NMAX];
int a[NMAX], b[NMAX], sp[NMAX], leftLast[NMAX], rightLast[NMAX];
int answer = INF, n;
pair<int,int> request[NMAX];

void prep() {
    int last = -INF;
    for(int i = 1; i <= 3 * n; i++) {
        sp[i] = sp[i - 1] + b[i];
        if(b[i])
            last = i;
        leftLast[i] = last;
    }
    
    last = INF;
    for(int i = 3 * n; i >= 1; i--) {
        if(b[i])
            last = i;
        rightLast[i] = last;
    }
    
    if(sp[3 * n] == 0) {
        for(int i = 1; i <= 3 * n; i++)
            if(a[i] == 1) {
                printf("-1");
                exit(0);
            }
        printf("0\n");
        exit(0);
    }
}

int solveRequests(int len, int shiftRight) {
    if(!len)
        return shiftRight;
    sort(request + 1, request + len + 1);
    int ans = 2 * request[len].x + shiftRight, maxRight = 0;
    for(int i = len; i >= 1; i--) {
        maxRight = max(maxRight, request[i].y);
        ans = min(ans, 2 * maxRight - shiftRight + 2 * request[i - 1].x);
    }
    return ans;
}

void solve() {
    prep();
    for(int diff = 0; diff < n; diff++) {
        int solChanges = 0, numReq = 0;
        for(int i = n + 1; i <= 2 * n; i++) {
            if(a[i] != b[i + diff]) {
                solChanges++;
                if(sp[i + diff] - sp[i - 1] > 0)
                    continue;
                request[++numReq] = make_pair(i - leftLast[i], rightLast[i] - i);
            }
        }
        int solShifts = solveRequests(numReq, diff);
        answer = min(answer, solChanges + solShifts);
    }
}

void reverseStrings() {
    reverse(a + 1, a + 3 * n + 1);
    reverse(b + 1, b + 3 * n + 1);
}

void letsBeNormal() {
    for(int i = 1; i <= n; i++) {
        a[i] = s1[i] - '0';
        b[i] = s2[i] - '0';
    }
}

int main () {

    scanf("%s", s1 + 1);
    scanf("%s", s2 + 1);
    n = strlen(s1 + 1);
    letsBeNormal();
    
    for(int i = n + 1; i <= 3 * n; i++) {
        a[i] = a[i - n];
        b[i] = b[i - n];
    }
        
    solve();
    reverseStrings();
    solve();
    
    printf("%d\n", answer);
    
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
    string s;
    cin >> s;
    ll cnta = count(s.begin(), s.end(), 'a');
    ll cntb = count(s.begin(), s.end(), 'b');
    ll cntc = count(s.begin(), s.end(), 'c');
    ll difab = abs(cnta - cntb);
    ll difbc = abs(cntb - cntc);
    ll difca = abs(cntc - cnta);
    if (difab <= 1 and difbc <= 1 and difca <= 1) cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;


int main ()
{

int a,b;
cin >> a >> b;
bool flag=false;

for(int i=1;i<=3;i++)
{
	if((a*b*i)%2!=0)
	{
		flag=true;
		break;

	}
}

if(flag)
{
	cout << "Yes" << endl;
}
else
{
	cout << "No" << endl;
}

 	return 0;
}












Measured memory_bytes: 3552
S = input()

if len(S) % 2 != 0:
    print("No")
    exit()

for i in range(0, len(S)):
    if i % 2 == 0:
        if S[i] != 'h':
            print("No")
            exit()
    else:
        if S[i] != 'i':
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 2940
n = int(input())
inputs = input().split()
a = [int(s) for s in inputs]

ans = [0]*n

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

for i in range(n):
	if i != n-1:
		print(ans[i],end=" ")
	else:
		print(ans[i])


Measured memory_bytes: 18444
#include <stdio.h>
#include <string.h>

int main()
{
	int n;
	char *p;
	char str[1000];
	scanf("%d\n",&n);
	while(n--){
	gets(str);
	while(p=strstr(str,"Hoshino"),p)p[6]='a';
	puts(str);
	}
	return 0;
}

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


public class Main {

  void solve() throws IOException {
    int n = nextInt();
    int k = nextInt();
    int[] h = new int[n];
    for (int i = 0; i < n; i++) {
      h[i] =nextInt();
    }
    Arrays.sort(h);
    long ans = 0;
    for (int i = 0; i < n - k; i++) {
      ans += h[i];
    }
    out.println(ans);
  }

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

  void run() throws IOException {
    reader = new BufferedReader(new InputStreamReader(System.in));
//		reader = new BufferedReader(new FileReader("input.txt"));
    tokenizer = null;
    out = new PrintWriter(new OutputStreamWriter(System.out));
//		out = new PrintWriter(new FileWriter("output.txt"));
    solve();
    reader.close();
    out.flush();

  }

  BufferedReader reader;
  StringTokenizer tokenizer;
  PrintWriter out;

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  String nextToken() throws IOException {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine());
    }
    return tokenizer.nextToken();
  }
}


Measured memory_bytes: 54740
#include <stdio.h>

struct point {
    double x, y;
};

double slope(struct point a, struct point b)
{
    return (b.y - a.y) / (b.x - a.x);
}

int main(void)
{
    int n;
    struct point p1, p2, p3, p4;

    scanf("%d", &n);
    while (n--) {
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
                &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y, &p4.x, &p4.y);
        if (slope(p1, p2) == slope(p3, p4))
            printf("YES\n");
        else
            printf("NO\n");
    }
    
    return 0;
}

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

int main() {
    int n,m;
    map <string,int> mm;
    cin >> n;
    rep(i,n){
    	string s; cin >> s;
    	mm[s]++;
    }
    cin >> m;
    rep(i,m){
    	string s; cin >> s;
    	mm[s]--;
    }
    int ans = 0;
    for(auto i:mm){
    	if(i.second>ans) ans=i.second;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const long double EPS = 1e-9;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<char> &o) {
    string a;
    in >> a;
    for (char c : a) o.insert(c);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

class CumulativeSum {
    vector<ll> numbers;
    vector<ll> sums;

public:
    CumulativeSum(int n) {
        numbers.resize(n);
        sums.resize(n);
    }

    void set(int i, ll value) {
        numbers[i] = value;
    }

    ll getSum(int i) {
        if (i == -1) return 0;
        if (i == sums.size()) return sums.back();
        return sums[i];
    }

    ll getSectionSum(int start, int end) {
        return getSum(end) - getSum(start - 1);
    }

    void calculate() {
        for (int i = 0; i < numbers.size(); i++) {
            sums[i] = getSum(i - 1) + numbers[i];
        }
    }

};


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

    vector<ll> sizes(n + 1);
    rep(i, n + 1) cin >> sizes[i];

    if (sizes[0] == 1) {
        if (n == 0) {
            cout << 1 << endl;
            ret();
        } else {
            cout << -1 << endl;
            ret();
        }
    }

    if (n == 0) {
        cout << -1 << endl;
        ret();
    }

    if (sizes.back() == 0) {
        cout << -1 << endl;
        ret();
    }

    CumulativeSum cs(n + 1);
    rep(i, n + 1)cs.set(i, sizes[i]);
    cs.calculate();


//    vector<P> mis(n + 1);
//    mis[n] = P(0, sizes[n]);
//    for (int i = n - 1; i >= 0; i--) {
//        ll mi = mis[i + 1].first + mis[i + 1].second;
//        mis[i] = P(mi, sizes[i]);
//    }
//
    vector<P> mas(n + 1);
    mas[0] = P(1, 0);

    rep(i, n + 1) {
        if (i == 0) continue;
        ll ma1 = mas[i - 1].first * 2;
        ll ma2 = cs.getSectionSum(i, n + 1);
        ll mi = min(ma1, ma2);
        ll s = sizes[i];
        mas[i] = P(mi - s, s);

    }


    for (P p : mas) {
        if (p.first < 0) {
            cout << -1 << endl;
            ret();
        }
    }
//    rep(i, n) {
//        if (mis[i].first * 2 < mis[i + 1].first + mis[i + 1].second) {
//            cout << -1 << endl;
//            ret();
//        }
//    }


    ll ans = 0;
    for (P p : mas) ans += (p.first + p.second);

    cout << ans << endl;


}


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

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int n, a[10] = { 0 };
int f[100][10];
ll p[100][11];
ll ans;
bool ed = 1;

void dfs(int i) {
	if (i == 10) {
		int e = 0;
		ll d = 0;
		FOR(j, n) {
			int x = 0;
			FOR(k, 10) {
				if (a[k] && f[j][k]) {
					x++;
					e++;
				}
			}
			d += p[j][x];
		}
		if (!e)return;
		if (ed) {
			ans = d;
			ed = 0;
		}
		else ans = max(ans, d);
		return;
	}
	a[i] = 0;
	dfs(i + 1);
	a[i] = 1;
	dfs(i + 1);
}

int main() {

	cin >> n;
	
	FOR(i, n) {
		FOR(j, 10)cin >> f[i][j];
	}
	FOR(i, n) {
		FOR(j, 11)cin >> p[i][j];
	}
	dfs(0);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[52][52][2510];

signed main(){
	int n, A; scanf("%d%d", &n, &A);
	vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	dp[0][0][0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= 2500; k++){
				dp[i + 1][j][k] += dp[i][j][k];
				if(j >= 1 && k - a[i] >= 0) dp[i + 1][j][k] += dp[i][j - 1][k - a[i]];
			}
		}
	}
	ll ans = 0;
	for(int j = 1; j <= n; j++){
		ans += dp[n][j][j * A];
	}
	cout << ans << endl;
}

Measured memory_bytes: 53872
n=int(input())
dic={}
for i in range(n):
  wk={}
  s=input()
  for i in range(len(s)):
    if s[i] in wk:
      wk[s[i]]+=1
    else:
      wk[s[i]]=1
  list=sorted(wk.items(),key=lambda x:x[0])
  key="".join(map(str,list))
  if key in dic:
    dic[key]+=1
  else:
    dic[key]=1
ans=0
for i in dic.values():
  if i==1:
    continue
  else:
    ans+=i*(i-1)/2
print(int(ans))

Measured memory_bytes: 23228
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

signed main() {
	double a, b, p, q, r;
	cin >> a >> b >> p >> q >> r;
	double dis = b * p - (b - a) * q;
	printf("%.12lf\n", dis / (q + r) + b);

	return 0;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int a,b,c,x=0;
    cin>>a>>b>>c;
    if(a==b)
    x++;
    if(b==c)
    x++;
    if(c==a)
    x++;
    //cout<<x<<endl;
    if(x==1)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

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

	int ans = 0;
	int a, b, n;
	cin >> a >> b >> n;
	auto tr = [&](int x) {
		if (x <= n) {
			ans = max(ans, (x % b) * a - (a * x) % b);
		}
	};
	for (int x = n; x >= 0 && x >= n - 10 * a; x--) {
		tr(x);
	}
	tr(b - 1);
	cout << ans / b << endl;
}


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <string>
typedef long long ll;
const int MAXN=100007;
using namespace std;

struct data{
    int num;
    char pic;
    int ind;
};

void BubbleSort(data* B, int n){
    for(int i=0; i<n; i++){
        for(int j=n-1; j>i; j--){
            if(B[j].num < B[j-1].num){
                swap(B[j], B[j-1]);
            }
        }
    }
}

int partition(data A[], int p, int r){
    int x = A[r].num;
    int i = p-1;

    for(int j=p; j<=r-1; j++){
        if(A[j].num <= x){
            i++;
            swap(A[i], A[j]);
        }
    } 
    swap(A[i+1], A[r]);

    return i+1;
}

void quicksort(data A[], int p, int r){
    if(p < r){
        int q;
        q = partition(A, p, r);
        quicksort(A, p, q-1);
        quicksort(A, q+1, r);
    }    
}

int main(){
    int n; cin >> n;
    
    data A[MAXN];
    for(int i=0; i<n; i++){
        cin >> A[i].pic >> A[i].num;
        A[i].ind = i;
    }
    
    quicksort(A, 0, n-1);

    bool flg = true;
    for(int i=0; i<n; i++){
        if(A[i].num == A[i+1].num && A[i].ind > A[i+1].ind){
            flg = false;
            break;
        }
    }
    if(flg){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    for(int i=0; i<n; i++) printf("%c %d\n", A[i].pic, A[i].num);
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int h, w, d;
  scanf("%d %d %d", &h, &w, &d);
  vector<int> X(h * w + 5), Y(h * w + 5);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int num = 0;
      scanf("%d", &num);
      X[num] = j;
      Y[num] = i;
    }
  }
  vector<int> cost(h * w + 5, 0);
  for (int dest = d + 1; dest <= h * w; ++dest) {
    cost[dest] = cost[dest - d] + abs(X[dest] - X[dest - d]) + abs(Y[dest] - Y[dest - d]);
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", cost[r] - cost[l]);
  }

  return 0;
}


Measured memory_bytes: 2176
#include<cmath>
#include<iostream>
#include<algorithm>
#include <string>
#include <stdexcept>
using namespace std; 
int main(){
  int a,b,c,d,e;
   char g[3]; string h,i;
    cin >> g;
  if(g[0]=='1')g[0]='9';
   else if(g[0]=='9')g[0]='1';
   if(g[1]=='1')g[1]='9';
  else if(g[1]=='9')g[1]='1';
   if(g[2]=='1')g[2]='9';
  else if(g[2]=='9')g[2]='1';
  cout <<g;
  
}

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

using namespace std;

struct Edge {
    int v[2];
    double d, c;
    Edge() {}
    Edge(int v1, int v2, double d, double c) :
        v{v1, v2}, d(d), c(c) {}
};
bool operator<(const Edge &e1, const Edge &e2) {
    return e1.c >= e2.c;
}
using Edges = vector<Edge>;
using Graph = vector<Edges>;
const double INF = 1e8;

double MinimumTime(const int n, const int start, const int goal, const Graph &g) {
    // tm[前の頂点][現在の頂点][速度]
    vector<vector<vector<double>>> tm(n, vector<vector<double>>(n,
                                                                vector<double>(31, INF)));

    for (int v = 0; v < n; ++v) tm[v][start][1] = 0.0;

    // 前の頂点，現在の頂点，速度，経過時間
    priority_queue<Edge> que;
    for (const auto &e : g[start]) {
        que.push(Edge(start, e.v[1], 1, e.d));
        tm[start][e.v[1]][1] = e.d;
    }

    while (!que.empty()) {
        int prev = que.top().v[0], cur = que.top().v[1];
        double velocity = que.top().d, elapsed = que.top().c;
        que.pop();

        if (tm[prev][cur][velocity] < elapsed) continue;

        for (const auto &e : g[cur]) {
            if (e.v[1] == prev) continue;

            for (int add = -1; add <= 1; ++add) {
                const double nxt_velocity = velocity + add;

                if (nxt_velocity <= 0.0 || e.c < nxt_velocity) continue;

                double tmp_tm = elapsed + e.d / nxt_velocity;
                if (tmp_tm < tm[e.v[0]][e.v[1]][nxt_velocity]) {
                    tm[e.v[0]][e.v[1]][nxt_velocity] = tmp_tm;
                    que.push(Edge(cur, e.v[1], nxt_velocity, tmp_tm));
                }
            }
        }
    }

    double res = INF;
    for (int v = 0; v < n; ++v) res = min(res, tm[v][goal][1]);
    return (INF <= res) ? -1.0 : res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(8) << setiosflags(ios::fixed);

    int n, m, s, g, x, y, d, c;

    while (cin >> n >> m, n) {
        cin >> s >> g;

        Graph graph(n);
        for (int i = 0; i < m; ++i) {
            cin >> x >> y >> d >> c;
            graph[x - 1].emplace_back(Edge(x - 1, y - 1, d, c));
            graph[y - 1].emplace_back(Edge(y - 1, x - 1, d, c));
        }

        double time = MinimumTime(n, s - 1, g - 1, graph);
        if (time < 0.0) cout << "unreachable\n";
        else cout << time << '\n';
    }

    return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std; 
int n,k;
string s; 
int main(){
    cin>>n>>k;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
    	if(i==k-1) s[i]+=32,cout<<s[i];
    	else cout<<s[i];
	}
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;

vector<pair<ll, ll> > v[111111];
ll dist[111111];

void dfs(ll parent, ll node, ll len)
{
	ll i;

	dist[node] = len;

	for (i = 0; i < v[node].size(); i++)
		if (parent != v[node][i].first)
            dfs(node, v[node][i].first, len + v[node][i].second);
}
int main(void)
{
    ll n, q, k, i;

    scanf("%lld" ,&n);
    for (i = 1; i < n; i++)
	{
		ll a, b, c;

		scanf("%lld %lld %lld" ,&a, &b, &c);

		v[a].push_back(make_pair(b, c));
		v[b].push_back(make_pair(a, c));
	}
	scanf("%lld %lld" ,&q, &k);

	dfs(0, k, 0);

    while (q--)
	{
		ll x, y;

		scanf("%lld %lld" ,&x, &y);

        printf("%lld\n" ,dist[x] + dist[y]);
	}
	return 0;
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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;
}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define INF 999999999

    /*Solve*/

int main(){
    int n;
    cin >> n;
    int p[n];
    rep(i,n)cin >> p[i];
    int ans=0;
    
    sort(p,p+n,greater<int>());
    p[0]/=2;
    rep(i,n)ans+=p[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()s[]
#define hell        (ll int)2e9+7
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--) 
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define MAXN        200001
#define ordered_set tree<pair<ll int,ll int>, null_type,less<pair<ll int,ll int>>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
    ll int h,w,a,b;
    cin >> h >> w >> a >> b;
    if (a>(w/2) or b>(h/2))
        {cout << -1 << endl;exit(0);}
    rep(i,0,h)
    {
        ll int u1=0;
        if (i>=(b))
        {
            u1=1;
        }
        rep(j,0,w)
        {
            if (j<a)
                cout << u1;
            else
                cout << 1-u1;
        }
        cout << endl;
    }
    cout << endl;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i)
        if (a[i]=='b') a[i]='d'; else
            if (a[i]=='d') a[i]='b'; else
                if (a[i]=='p') a[i]='q'; else
                    if (a[i]=='q') a[i]='p';
    if (a==b) printf("Yes"); else printf("No");
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>

int comp(const void* a, const void* b);

int main() {
	int t,n, k,i, j;
	int *x,*ans,*bou;
	scanf("%d", &t);
	ans = (int*)malloc(t * sizeof(int));
	for (i = 0; i < t; i++) {
		ans[i] = 0;
		scanf("%d%d", &n, &k);
		x = (int*)malloc(n * sizeof(int));
		bou = (int*)malloc((n - 1) * sizeof(int));
		for(j=0;j<n;j++)scanf("%d", &x[j]);
		if (k >= n)ans[i] = 0;
		else {
			for (j = 0; j < n - 1; j++) {
				bou[j] = x[j + 1] - x[j];
			}
			qsort(bou, n - 1, sizeof(int), comp);
			for (j = k-1 ; j < n - 1; j++)ans[i] += bou[j];
		}
	}
	for (i = 0; i < t; i++) {
		printf("%d\n", ans[i]);
	}

	return 0;
}

int comp(const void* a, const void* b) {
	return *((int*)b) - *((int*)a);
}

Measured memory_bytes: 5036
MOD = 10 ** 9 + 7
FACT_MAX = 2 * 10 ** 6 + 3
fact = [1] * FACT_MAX
for i in range(1, FACT_MAX):
    fact[i] = fact[i - 1] * i % MOD
def comb(n, r):
    return fact[n] * pow(fact[n - r], MOD - 2, MOD) * pow(fact[r], MOD - 2, MOD)
def g(r, c):
    return (comb(r + c + 2, c + 1) - 1) % MOD
r1, c1, r2, c2 = map(int, input().split())
print((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % MOD)


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define _upgrade                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template <typename _T>
inline void _DBG(const char *s, _T x)
{
    cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a)
{
    while (*s != ',')
        cerr << *s++;
    cerr << " = " << x << ',';
    _DBG(s + 1, a...);
}

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr \
    if (0)   \
    cout
#endif

// ********************** CODE ********************** //

int main()
{
    _upgrade
    int n; cin >> n;
    vector < int > A(n), B(n);
    for(int i = 0; i < n; i++) cin >> A[i];
    for(int i = 0; i < n; i++) cin >> B[i];
    for(int i = 0; i < n; i++)
        A[i] = B[i] - A[i];
    LL ile = 0, ile2 = 0;
    for(int i = 0; i < n; i++)
    {
        if(A[i] < 0)
        {
            ile -= A[i];
            A[i] = 0;
        }
    }
    for(int i = 0; i < n; i++)
    {
        if(A[i] > 0)
            ile2 += A[i] / 2;
    }
    if(ile2 >= ile)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i=0 ; i<n ; i++)
    cin >> h.at(i);
  
  int ans = 0;
  for (int i=0 ; i<n ; i++){
    if (h.at(i) >= k)
      ans++;
  }
  
  cout << ans << endl;
}

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

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

  string n;
  cin >> n;
  string ans;
  rep(i, 3) {
    if (n[i] == '1') {
      ans += '9';
    } else {
      ans += '1';
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
using namespace std;
int main()
{
	char s[105];
	char t[105];
	scanf("%s", s);
	scanf("%s", t);
	int len = strlen(s);
	int k = len;
	int vis = 0;
	if(strcmp(s,t) == 0)vis = 1;
	while(k--){
		char c = s[len - 1];
		for(int i = len - 1 ; i >= 1 ; i--){
			s[i] = s[i - 1];
		}
		s[0] = c;
		if(strcmp(s,t) == 0)vis = 1;
	}
	if(vis)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;

ll n;

int main() {
    ios::sync_with_stdio(false);
    cin>>n;
    ll sum=0;
  for(ll i=1;i<=n;++i){
      if(i%3!=0 && i%5!=0 && i%15!=0){
          sum+=i;
      }
  }
  printf("%lld\n",sum);

    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define siz 100005

typedef pair< pair<int,int> , pair<int,int> > ppp;

ll dp[100005],wight[105],value[105];

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

  // freopen("street.in","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,w;
    ll sum=0;
    scanf("%d%d",&n,&w);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&wight[i],&value[i]);
        sum+=value[i];
    }
    for(int i=1;i<=sum;i++){
        dp[i]=1e13+7;
    }

    for(int i=1;i<=n;i++){
     for(int j=sum-value[i];j>=0;j--){
        dp[j+value[i]]=min(dp[j+value[i]],dp[j]+wight[i]);
     }
    }
    ll ans=0;
    for(int i=0;i<=sum;i++){
        if(dp[i]<=w)
            ans=max(ans,(ll)i);
    }
   printf("%lld",ans);

return 0;

}




Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main(){
    int a,b;
    while(cin>>a>>b){
        int x=a,y=b;
        while(true){
            if(x==y)
                break;
            if(x>y)
                x-=y;
            else if(y>x)
                y-=x;
        }
        cout<<x<<" ";
        int keep=x;
        x=a/keep;
        y=b/keep;
        cout<<x*y*keep<<endl;
    }
    return 0;
}
 

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

int N, A[10010];

int max(){
    int max = A[0];
    for (int i = 1; i < N; i++){
        if (A[i] > max){
            max = A[i];
        }
    }
    return max;
}

long long int sum(){
    long long int sum = 0;
    for (int i = 0; i < N; i++){
        sum += A[i];
    }
    return sum;
}

int min(){
    int min = A[0];
    for (int i = 1; i < N; i++){
        if (A[i] < min){
            min = A[i];
        }
    }
    return min;
}

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    cout << min() << ' ' << max() << ' ' << sum() << endl;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
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; }

const long long w[10] = {1, 2, 4, 7, 12, 20, 29, 38, 52, 73};

long long dp[(1<<10)+1][11];
long long calc(vector<vector<long long> > &G, int N) {
    memset(dp, 0, sizeof(dp));
    for (int bit = 0; bit < (1<<N); ++bit) {
        for (int v = 0; v < N; ++v) {
            if (!(bit & (1<<v))) continue;
            for (int nv = 0; nv < N; ++nv) {
                if (bit & (1<<nv)) continue;
                int nbit = bit | (1<<nv);
                chmax(dp[nbit][nv], dp[bit][v] + G[v][nv]);
            }
        }
    }
    long long res = 0;
    for (int v = 0; v < N; ++v) chmax(res, dp[(1<<N)-1][v]);
    return res;
}

int main() {
    int N; cin >> N;
    vector<vector<long long> > G(N, vector<long long>(N, 0));

    G[0][1] = 1; G[1][0] = 1;
    for (int n = 2; n < N; ++n) {
        long long M = calc(G, n);
        for (int v = 0; v < n; ++v) G[v][n] = G[n][v] = (M+1) * w[v];

        //cout << n << ": " << M << endl;
    }

    //cout << calc(G, N) << endl;
    
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) cout << G[i][j] << " ";
        cout << endl;
    }
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    import math
    
    
    # cf. https://qiita.com/suecharo/items/14137fb74c26e2388f1f
    def make_prime_list_2(num):
        if num < 2:
            return []
    
        # 0のものは素数じゃないとする
        prime_list = [i for i in range(num + 1)]
        prime_list[1] = 0  # 1は素数ではない
        num_sqrt = math.sqrt(num)
    
        for prime in prime_list:
            if prime == 0:
                continue
            if prime > num_sqrt:
                break
    
            for non_prime in range(2 * prime, num, prime):
                prime_list[non_prime] = 0
    
        return [prime for prime in prime_list if prime != 0]
    
    
    def prime_factorization_2(num):
        """numの素因数分解
        素因数をkeyに乗数をvalueに格納した辞書型dict_counterを返す"""
    
        if num <= 1:
            # 例えば1を食ったときの対処の仕方は問題によって違うと思うのでそのつど考える。
            # cf. https://atcoder.jp/contests/abc110/submissions/12688244
            return False
        else:
            num_sqrt = math.floor(math.sqrt(num))
            prime_list = make_prime_list_2(num_sqrt)
    
            dict_counter = {}  # 何度もこの関数を呼び出して辞書を更新したい時はこれを引数にして
            # cf. https://atcoder.jp/contests/arc034/submissions/12251452
    
            for prime in prime_list:
                while num % prime == 0:
                    if prime in dict_counter:
                        dict_counter[prime] += 1
                    else:
                        dict_counter[prime] = 1
                    num //= prime
            if num != 1:
                if num in dict_counter:
                    dict_counter[num] += 1
                else:
                    dict_counter[num] = 1
    
            return dict_counter
    d=prime_factorization_2(n)
    val=1
    for v in d.values():
        val*=(v+1)
    print(len(d),val-1)

    
resolve()


Measured memory_bytes: 45936
MOD = 998244353
def resolve():
    # 多項式 解
    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    q = [0]*(S+1)
    ans = 0
    for i in range(N):
        q[0] += 1
        q2 = [0]*(S+1)
        for j in range(S+1):
            # q *= (1 + x^A[i])
            q2[j] += q[j]
            if j + A[i] <= S:
                q2[j + A[i]] += q[j]
                q2[j + A[i]] %= MOD
        q = q2
        ans += q[S]
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 74280
# -*- coding: utf-8 -*-
import sys
import collections

def main():
	N, M = map(int, input().split(" "))
	
	bridge = []
	for _ in range(M):
		a, b = map(int, input().split(" "))
		bridge.append((a, b))
		
	bridge.reverse()
	uf = UnionFind(N)
	ans = []
	fuben = 0
	ans.append(N * (N-1) // 2)
	
	for i, val in enumerate(bridge):
		a, b = val
		a, b = a-1, b-1
		if False == uf.is_same(a, b):
			child_a = uf.getCoun(a)
			child_b = uf.getCoun(b)
			ans.append(ans[i] - (child_a * child_b))
		else:
			ans.append(ans[i])
		uf.union(a, b)
		
	ans.pop()
	ans.reverse()
	for val in ans:
		print(val)
	

class UnionFind(object):
	def __init__(self, n=1):
		self.par = [i for i in range(n)]
		self.rank = [0 for _ in range(n)]
		self.size = [1 for _ in range(n)]
		
	# x が属するグループを探索
	def find(self, x):
		if self.par[x] == x:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]
		
	# x と y のグループを結合
	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x != y:
			x_size = self.size[x]
			y_size = self.size[y]
			sum = x_size + y_size
			self.size[x] = sum
			self.size[y] = sum
			if self.rank[x] < self.rank[y]:
				x, y = y, x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1
			self.par[y] = x
	
	# x と y が同じグループがどうか
	def is_same(self, x, y):
		return self.find(x) == self.find(y)
		
	def getCoun(self, a):
		x = self.find(a)
		return self.size[x]

if __name__ == "__main__":
	main()
	

Measured memory_bytes: 27588
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  int tmp = 60 * c + d - 60 * a - b;

  int ans = tmp - e;
  prt(ans);
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	string s;
	cin >> s;
	if (s == "keyence") {
		cout << "YES" << endl;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		for (int j = i; j < s.size(); j++) {
			string sk = "";
			for (int k = 0; k < s.size(); k++) {
				if (k<i || k>j) sk += s[k];
			}
			if (sk == "keyence") {
				cout << "YES" << endl;
				return 0;
			}
		}
	}

	cout << "NO" << endl;
}

Measured memory_bytes: 384
n,m=gets.chomp.split.map(&:to_i)
humanPoints = n.times.map{ gets.chomp.split.map(&:to_i) }
checkPoints = m.times.map{ gets.chomp.split.map(&:to_i) }
humanPoints.each do |xy1|
  distance=-1
  indexNumber=0
  checkPoints.each_with_index do |xy2,index|
    tempDistance = (xy1[0]-xy2[0]).abs + (xy1[1]-xy2[1]).abs
    if distance == -1 || distance > tempDistance
      indexNumber = index
      distance = tempDistance 
    end
  end
  puts (indexNumber+1)
end

Measured memory_bytes: 1788
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int A=in.nextInt();
			int B=in.nextInt();
			int an[]=new int[A];
			int br[]=new int[B];
			for(int i=0;i<A;i++)
				an[i]=in.nextInt();
			for(int i=0;i<B;i++)
				br[i]=in.nextInt();
			int ans=0;
				for(int i=0;i<B;i++)
				{
					int I=i;//スタート地点
					int cnt=0;
					for(int j=0;j<A;j++)
					{
						if(br[i]==an[j])
						{
							cnt++;
							i++;
						}
						if(i>=B)
							break;
					}
					ans=Math.max(ans, cnt);
					i=I;
				}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 13000
#include<iostream>
#include<algorithm>
#include<cstdint>

int64_t const MOD = 1e9+7;
int const MAXN = 1e5;
int N, K;
int64_t A[MAXN];

template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};
typedef mod_int<MOD> mint;

mint fact[MAXN+1], ifact[MAXN+1];
void init() {
  fact[0] = fact[1] = mint(1);
  for(int i = 2; i <= N; ++i) fact[i] = fact[i-1]*i;
  ifact[N] = fact[N].inv();
  for(int i = N-1; i >= 0; --i) ifact[i] = ifact[i+1]*(i+1);
}
mint comb(int n, int k) { return fact[n]*ifact[k]*ifact[n-k]; }

int main() {
  std::cin >> N >> K;
  init();
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  std::sort(A, A+N);
  mint ans;
  for(int i = 0; i+K <= N; ++i) {
    mint diff = 
    ans += (mint(A[N-1-i]) - mint(A[i]))*comb(N-i-1, K-1);
  }
  std::cout << ans.v_ << std::endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
using namespace std;
long long a,b,c,d,n,x;
int main(void){
   cin>>a>>d>>n>>b>>c>>n>>n;
   if(a*b*c){
       if(a%2==b%2&&b%2==c%2)n=0;
       else n=1;
   }else n=a%2+b%2+c%2;
   cout<<a+b+c+d-n;
}

Measured memory_bytes: 256
s = input()
a = 0
b = 1
x = 0
y = 0
for i in range(len(s)):
  t = ord(s[i]) - 48
  if t != a:
    x += 1
  if t != b:
    y += 1
  a ^= 1
  b ^= 1
print(min(x, y))


Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

#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 all(c) c.begin(),c.end()

using namespace std;

int A, B;

int N, M, C, D;


int main() {
	string C1, C2;
	cin >> C1 >> C2;
	if (C1[0] == C2[2] && C1[1] == C2[1] && C1[2] == C2[0]) cout << "YES";
	else cout << "NO";


}




Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    int N, K;

    if (scanf("%d%d", &N, &K) < 2) return 0;

    vector<int> a(N);

    vector<long long int> vSM(100001);
    vector<long long int> vZR(100001);

    for (int i = 0; i < N; i++)
    {
        if (scanf("%d", &a[i]) < 1) return 0;
        vSM[i + 1] = vSM[i] + a[i];
        vZR[i + 1] = vZR[i] + max((long long int)a[i], 0LL);
    }

    long long int score = 0LL;
    for (int i = 0; i < N - K + 1; i++)
    {
        int l = i;
        int r = i + K;

        // 最後に塗るところ以外
        long long int pre = vZR[l] + (vZR[N] - vZR[r]);

        // 最後に白く塗る(0LL)、黒く塗る(vSM[r] - vSM[l])
        score = max(score, pre + max(vSM[r] - vSM[l], 0LL));
    }

    printf("%lld\n", score);
    return 0;
}


Measured memory_bytes: 2304