akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 250005;
const int P = 1e9 + 7;
const int val[6] = {18, 40, 23, 2333333, 58, 720};
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
struct Hash {int val[6]; };
struct info {Hash k, b; };
bool operator < (Hash a, Hash b) {
	for (int i = 0; i <= 5; i++)
		if (a.val[i] != b.val[i]) return a.val[i] < b.val[i];
	return false;
}
map <Hash, int> mp;
char s[MAXN];
int inv[6];
Hash unit() {
	Hash ans;
	memset(ans.val, 0, sizeof(ans.val));
	return ans;
}
info unitinfo() {
	info ans;
	for (int i = 0; i <= 5; i++) {
		ans.b.val[i] = 0;
		ans.k.val[i] = 1;
	}
	return ans;
}
Hash operator * (Hash x, info a) {
	Hash ans;
	for (int i = 0; i <= 5; i++)
		ans.val[i] = (1ll * a.k.val[i] * x.val[i] + a.b.val[i]) % P;
	return ans;
}
int power(int x, int y) {
	if (y == 0) return 1;
	int tmp = power(x, y / 2);
	if (y % 2 == 0) return 1ll * tmp * tmp % P;
	else return 1ll * tmp * tmp % P * x % P;
}
void pls(Hash &tmp) {
	for (int i = 0; i <= 5; i++)
		tmp.val[i] = (tmp.val[i] + 1) % P;
}
void mns(Hash &tmp) {
	for (int i = 0; i <= 5; i++)
		tmp.val[i] = (tmp.val[i] + P - 1) % P;
}
void rit(Hash &tmp) {
	for (int i = 0; i <= 5; i++)
		tmp.val[i] = (1ll * tmp.val[i] * val[i]) % P;
}
void lft(Hash &tmp) {
	for (int i = 0; i <= 5; i++)
		tmp.val[i] = (1ll * tmp.val[i] * inv[i]) % P;
}
void pls(info &tmp) {
	for (int i = 0; i <= 5; i++)
		tmp.b.val[i] = (tmp.b.val[i] + tmp.k.val[i]) % P;
}
void mns(info &tmp) {
	for (int i = 0; i <= 5; i++)
		tmp.b.val[i] = (tmp.b.val[i] + P - tmp.k.val[i]) % P;
}
void rit(info &tmp) {
	for (int i = 0; i <= 5; i++)
		tmp.k.val[i] = (1ll * tmp.k.val[i] * val[i]) % P;
}
void lft(info &tmp) {
	for (int i = 0; i <= 5; i++)
		tmp.k.val[i] = (1ll * tmp.k.val[i] * inv[i]) % P;
}
int main() {
	for (int i = 0; i <= 5; i++)
		inv[i] = power(val[i], P - 2);
	int n; read(n);
	scanf("\n%s", s + 1);
	Hash now = unit();
	for (int i = n; i >= 1; i--) {
		if (s[i] == '+') pls(now);
		if (s[i] == '-') mns(now);
		if (s[i] == '>') rit(now);
		if (s[i] == '<') lft(now);
	}
	Hash tmp = unit(); mp[tmp]++;
	info Now = unitinfo(), Tmp = unitinfo();
	long long ans = 0;
	for (int i = n; i >= 1; i--) {
		if (s[i] == '-') pls(Now), pls(Tmp);
		if (s[i] == '+') mns(Now), mns(Tmp);
		if (s[i] == '<') rit(Now), rit(Tmp);
		if (s[i] == '>') lft(Now), lft(Tmp);
		ans += mp[now * Now];
		mp[tmp * Tmp]++;
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 39552
#include <bits/stdc++.h>
#define DEBUG true
#define coutd if(DEBUG) cout
#define ff first
#define ss second
#define len(x) int(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;


int main(){
	ios_base::sync_with_stdio(0);
	int r, d, x;
	cin >> r >> d >> x;
	for(int i=0; i<10; i++){
		x = r*x-d;
		cout << x << endl;
	}
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
 
  int a,b,c;
    
  scanf("%d %d %d",&a,&b,&c); 
  
  switch(a)
  {
    case 5:
      if(b==5 && c==7)   {printf("YES");}  
      else if(b==7 && c==5) {printf("YES");}
      else {printf("NO");}
      break;
      
    case 7:
      if(b==5 && c==5)  {printf("YES");}
      else {printf("NO");}
      break;
  
    default:
      printf("NO");
      break;
  
  }

return 0;
}

Measured memory_bytes: 128
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	N, K := getInt(), getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	var dp [100001][2]int

	for i := 1; i <= K; i++ {
		for j := 0; j < 2; j++ {
			for _, v := range a {
				if i >= v {
					if dp[i-v][(j+1)%2] == 0 {
						dp[i][(j+1)%2] = 1
					}
				}
			}
		}
	}

	ans := "First"
	if dp[K][0] == 0 {
		ans = "Second"
	}

	out(ans)
}

/*
var dp [100001][2]int

func loop(k, j int, a []int) int {
	if dp[k][j] != -1 {
		return dp[k][j]
	}
	ret := 0
	for _, v := range a {
		if k-v >= 0 {
			if loop(k-v, (j+1)%2, a) == 0 {
				ret = 1
			}
		}
	}
	dp[k][j] = ret
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	N, K := getInt(), getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	for i := 0; i <= 100000; i++ {
		dp[i][0] = -1
		dp[i][1] = -1
	}

	ret := loop(K, 0, a)

	ans := "First"
	if ret == 0 {
		ans = "Second"
	}

	out(ans)
}
*/


Measured memory_bytes: 2176
#include <stdio.h>

#define S 101

int main(void)
{
    char a[S], b[S], c[S];
    char *p[] = { a, b, c };
    scanf("%s %s %s", a, b, c);

    char d = *p[0]++;
    for (;;) {
        if (*p[d - 'a'] == '\0') {
            printf("%c\n", d - 'a' + 'A');
            break;
        }
        d = *p[d - 'a']++;
    }

    return 0;
}


Measured memory_bytes: 128
// 154 B

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>

using namespace std;

int main(){
    int n, m, q;
    long long int sum=0, max=0;
    cin >> n >> m >> q;

    vector<long long int> a(n, 1);
    vector<vector<long long int>> v (q, vector<long long int>(4, 0));

    for(int i=0; i<q; i++){
        cin >> v.at(i).at(0) >> v.at(i).at(1) >> v.at(i).at(2) >> v.at(i).at(3);
    }

    while(true){
        for(int i=n-1; i>0; i--){
            if(a.at(i) > m){
                a.at(i-1)++;
            }
        }
        for(int i=1; i<n; i++){
            if(a.at(i) > m){
                a.at(i) = a.at(i-1);
            }
        }
        if(a.at(0) > m) break;

        sum = 0;
        for(auto buf: v){
            if( a.at(buf.at(1)-1) - a.at(buf.at(0)-1) == buf.at(2)){ sum += buf.at(3);}
        }
        if(sum > max) max = sum;

        a.at(n-1)++;
    }

    cout << max << endl;

    return 0;
}

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

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


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int integerX = sc.nextInt();  //元の整数
		int youso = sc.nextInt();  //整数列の要素数
		List<Integer> list = new ArrayList<Integer>();  //整数列を入れるリスト

		//配列を入力
		for(int i=0 ; i<youso ; i++) {
			list.add(sc.nextInt());
		}

		if(list.isEmpty() || list.contains(integerX) != true) {
			System.out.println(integerX);
			return;
		}

		for(int i=1 ; i<=100 ; i++) {
			if(! list.contains(integerX-i)) {
				System.out.println(integerX-i);
				break;
			}
			else if(! list.contains(integerX+i)) {
				System.out.println(integerX+i);
				break;
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 27156
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

using namespace std;

int main(){
	long long n,a,b;
	cin>>n>>a>>b;
	cout<<(long long)(n/(a+b)*a+min(n%(a+b),a))<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(str, input().split()))

B = ['_' for _ in range(N)]
if N % 2 == 0:
    for i, a in enumerate(A):
        if i % 2 == 0:
            B[N//2 + i//2] = a
        else:
            B[N//2 - (i+1)//2] = a
else:
    for i, a in enumerate(A):
        if i % 2 == 0:
            B[N//2 - i//2] = a
        else:
            B[N//2 + (i+1)//2] = a

print(' '.join(B))

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

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

	int N = S.size();
	if (N%2 == 0) S = S.substr(0,N-2);
	else S = S.substr(0,1);
	while (1) {
		N = S.size();
		string sl = S.substr(0, N/2);
		string sr = S.substr(N/2, N/2);
		if (sl == sr) break;
		S = S.substr(0,N-2);
	}

	cout << N << endl;

	return 0;
}


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

int main() {
	int R, G;
	cin >> R >> G;
	cout << 2 * G - R;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

次のコンテストで取ったパフォーマンスをbとする
すると、(R+b)/2==Gであるから移項してb==2G-Rであると求められる
*/

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    if (n % 2L == 1L) {
        println(0)
        return
    }

    println(xx(n))
}

private fun xx(x: Long): Long {
    var e = 0L
    var div = 10L
    while (div <= x) {
        e += (x / div)
        div *= 5
    }
    return e
}


Measured memory_bytes: 31748
# Union Find

# xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        tank = []
        while par[x] >= 0:
            tank.append(x)
            x = par[x]
        for elt in tank:
            par[elt] = x
        return x


# xとyの属する集合の併合
def unite(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        # sizeの大きいほうがx
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


# xとyが同じ集合に属するかの判定
def same(x, y):
    return find(x) == find(y)


# xが属する集合の個数
def size(x):
    return -par[find(x)]


# 初期化
# 根なら-size,子なら親の頂点
n,m = map(int,input().split())
par = [-1] * n
ans = 0
for i in range(m):
    X,Y = map(int,input().split())
    unite(X-1,Y-1)

for i in range(n):
    ans = max(size(i),ans)
print(ans)

Measured memory_bytes: 14500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define plint pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int n,ans=0;
    cin >> n;
    vector <int > a(n), b(n), c(n-1);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    REP(i,n-1) cin >> c[i];

    int prev_a = -2;
    REP(i,n){
        if(prev_a + 1 == a[i]){
            ans += c[prev_a-1];
        }
        ans += b[a[i]-1];
        prev_a = a[i];
    }
    cout << ans <<  endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

vi a; // number of node
vvi g;
vvi child;
set<int, greater<int> > root;
deque<bool> reached;

void dfs(int s) {
  root.insert(s);
  deque<int> st;
  st.push_back(s);
  reached[s] = true;
  while (!st.empty()) {
    int u = st.back();
    for (int v : g[u]) {
      if (!reached[v]) {
        child[u].push_back(v);
        st.push_back(v);
        reached[v] = true;
        st.push_back(v);
        break;
      }
    }
    if (st.back() == u) {
      st.pop_back();
    }
  }
}

vi retrieve(int r) {
  int sz = (int)child[r].size();
  if (sz == 0) {
    return (vi){r};
  }
  int ret_size = 0;
  vvi tmp(sz);
  rep (i, sz) {
    tmp[i] = retrieve(child[r][i]);
    tmp[i].push_back(-1);
    ret_size += (int)tmp[i].size();
  }
  vi ret;
  ret.reserve(ret_size + 10);
  ret.push_back(r);
  vi index(sz, 0);
  while (true) {
    int next_i = -1;
    int selected = -1;
    rep (i, sz) {
      if (next_i < tmp[i][index[i]]) {
        next_i = tmp[i][index[i]];
        selected = i;
      }
    }
    if (next_i == -1) {
      break;
    }
    ret.push_back(next_i);
    index[selected] += 1;
  }
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  a.resize(n);
  rep (i, n) {
    scanf("%d", &a[i]);
  }
  sort(all(a));

  g.resize(n);
  rep (i, n) {
    rep (j, n) {
      if (i == j) {
        continue;
      }
      if (__gcd(a[i], a[j]) == 1) {
        continue;
      }
      g[i].push_back(j);
      g[j].push_back(i);
    }
  }
  rep (i, n) {
    sort(all(g[i]));
  }

  // construct tree
  child.resize(n);
  reached.assign(n, false);
  rep (i, n) {
    if (reached[i]) {
      continue;
    }
    if (a[i] == 1) {
      root.insert(i);
      reached[i] = true;
      continue;
    }
    dfs(i);
  }

  for (int r : root) {
    vi tmp = retrieve(r);
    for (int i : tmp) {
      printf("%d ", a[i]);
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 31872
n,m,k=map(int,input().split())
mod = 10**9+7
fac = [1]
caf = [1]
def pow(n,p):
    res=1
    while p >0:
        if p%2==0:
            n = n**2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod

for i in range(1,n*m):
    fac.append((fac[i-1]*i)%mod)
    caf.append(pow(fac[i],mod-2))

def ncr(n,r):
    if n < r or r < 0: return 0
    return fac[n]*caf[r]*caf[n-r]

div2 = caf[2]

sums = [0]
for i in range((max(n,m))):
    sums.append((sums[-1]+i+1) % mod)

res1 = 0
for i in range(m):
    res1 += sums[i]+sums[m-1-i]
    res1 %= mod
res1 *= (n*n)%mod
res1 %= mod

res2 = 0
for i in range(n):
    res2 += sums[i]+sums[n-1-i]
    res2 %= mod
res2 *= (m*m)%mod
res2 %= mod

res = ((res1+res2)*div2)%mod
kc2 = ncr(n*m-2,k-2)
print((res*kc2)%mod)

Measured memory_bytes: 75228
from itertools import accumulate
from collections import deque
N,K=list(map(int,input().split()))
p=list(map(int,input().split()))
p2=list(accumulate(p))
p2=deque(p2)
p2.appendleft(0)
p3=[]
ans=0
counter=0
ans2=0
for i in range(N-K+1):
    if counter<p2[i+K]-p2[i]:
        counter=p2[i+K]-p2[i]
        ans=i
for i in range(K):
    ans2+=sum(list(range(1,p[ans+i]+1)))/p[ans+i]
    
print(ans2)

Measured memory_bytes: 80136
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int S = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < N; i++) {
            if (i < K) {
                sb.append(S + " ");
            } else if (S == 1000000000) {
                sb.append(999999999 + " ");
            } else {
                sb.append(1000000000 + " ");
            }
        }
        System.out.println(sb);
    }

}

Measured memory_bytes: 47700
#include <bits/stdc++.h>
using namespace std;
int main(){
	int h,w;
	cin >> h >> w;
	int n;
	cin >> n;
	int num[n];
	for(int i=0;i<n;i++)
		cin >> num[i];
	int ans[h][w];
	int col=1;
	int t=0,j=0,i=0;
	while(t<n){
		int cnt=0,y=num[t];
		while(cnt<y){
			ans[i][j]=t+1;
			if(i%2==0)j++;
			else j--;
			if(j==-1 )i++,j=0;
			else if(j==w)i++,j=w-1;	
			if(i>=h)break;
			cnt++;
		}
		if(i>=h)break;
		t++;
	}
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cout << ans[i][j] <<" \n"[j==w-1];
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define repins(a,n) vector<string> a(n);rep(i,n){cin>>a[i];}
#define repind(a,n) vector<double> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define ins(a) string a;cin>>a;
#define ind(a) double a;cin>>a;
template<class T>
inline void out(T a){cout<<a<<endl; }
inline void out(double a){ printf("%.10f\n", a);} 
#define all(x) (x).begin(),(x).end()
#define rep2(i,a,b) for(ll i=(a);i<(b);++i)
using vell = vector<ll>;
using ves = vector<string>;
using ved = vector<double>;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main()
{
	ins(s);
	if(s[0]==s[1]&&s[1]==s[2]){
		out("No");
	}else{
		out("Yes");
	}
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n,q = li()
a = list(li())
x = [ni() for _ in range(q)]


cum_nor = list(accumulate(a))
cum_odd = list(accumulate(a[::2]))
cum_evn = list(accumulate(a[1::2]))
cum_kog = [cum_odd[i//2] if i%2==0 else cum_evn[i//2] for i in range(n)]

# 高橋君が左からtak個取れるならTrue そうでないならFalse
def check(a:list, tak:int, pivot:int):
    if tak > (len(a)+1)//2:
        return False
    
    if pivot-a[-2*tak+1] > a[-tak]-pivot:
        return False
    else:
        return True
        
    
def binsearch(a:list,xi:int):
    low = 1
    high = len(a)
    while high-low > 1:
        mid = (high+low) // 2
        if check(a,mid,xi):
            low = mid
        else:
            high = mid
            
    return low


for xi in x:
    tak = binsearch(a,xi)
    ans = cum_nor[-1] - cum_nor[-tak-1]
    if 2*tak < n:
        ans += cum_kog[-2*tak-1] 
    
    print(ans)

Measured memory_bytes: 25180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18,MOD=1e9+7;
int main(){
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='o')cnt++;
    }
    if(s.length()==15){
        if(cnt>=8)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }
    else{
        //8-(15-(s.length())
        if(cnt>=(int)s.length()-7)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		long L = sc.nextLong();
		long R = sc.nextLong();

		if(R-L >= 2019) {
			System.out.println(0);
		}else {
			long ans = 2019;
			for(long i=L;i<=R;i++) {
				for(long j=i+1;j<=R;j++) {
					if(i*j % 2019 < ans) {
						ans = i*j % 2019;
					}

					if(ans == 0) {
						System.out.println(0);
						return;
					}
				}
			}
			System.out.println(ans);
		}
	}

}


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

template <typename T> inline void read(T& x)
{
    int f = 0, c = getchar(); x = 0;
    while (!isdigit(c)) f |= (c == '-'), c = getchar();
    while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
    if (f) x = -x;
}
template <typename T, typename... Args>
inline void read(T& x, Args&... args)
{
    read(x); read(args...);
}
template <typename T> void write(T x)
{
    if (x < 0) x = -x, putchar('-');
    if (x > 9) write(x / 10);
    putchar(x % 10 + 48);
}
template <typename T> void writeln(T x) { write(x); puts(""); }
template <typename T> inline bool cmin(T& x, const T& y)
{ return y < x ? (x = y, true) : false; }
template <typename T> inline bool cmax(T& x, const T& y)
{ return x < y ? (x = y, true) : false; }

#define LL long long
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
#define dwn(i, a, b) for (int i = a; i >= b; -- i)
#define ptc putchar
#define pii pair<int, int>
#define fi first
#define se second

using namespace std;

const int N = 2e5 + 5;
const double eps = 1e-20;
const int INF = 0x7fffffff;
const LL mod = 1e9 + 7;

int n;
LL k, a[N], b[N];

bool check(LL x)
{
    LL kk = 0;
    for (int i = 1, j = n; i <= n; ++ i, -- j)
    {
        if (a[i] * b[j] <= x) continue;
        LL dx = a[i] * b[j] - x;
        kk += dx / b[j] + (dx % b[j] != 0);
    }
    return kk <= k;
}

void main_solve()
{
    read(n, k);
    for (int i = 1; i <= n; ++ i)
        read(a[i]);
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; ++ i)
        read(b[i]);
    sort(b + 1, b + 1 + n);
    LL l = 0, r = 1e12 + 5, ans = 0, mid;
    while (l <= r)
    {
        mid = (l + r) >> 1;
        if (check(mid))
        {
            ans = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    writeln(ans);
    return ;
}

signed main()
{
    int T = 1;
    while (T --)
    {
        main_solve();
    }
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
using namespace std;
const int N=1e5+5;
void fast()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}
int a,b;
int main()
{
	cin>>a>>b;
	cout<<max(a+b,max(a*b,a-b))<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	A := ReadInts(N)
	s := make([]int, N+1)
	for i := 0; i < N; i++ {
		s[i+1] = (s[i] + A[i]) % M
	}
	m := make(map[int]int)
	for i := 0; i < N+1; i++ {
		m[s[i]]++
	}
	ans := 0
	for _, v := range m {
		ans += (v * (v - 1)) / 2
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 9412
n=gets.chomp.to_i
a=gets.chomp.split.map(&:to_i)

cnt = 0
i = 0
max = 0
a.each do |v|
  if i > 0 && max > v
    mae = max - v
    cnt += mae
    max = mae + v
  else
    max = v
  end
  i += 1
end

puts cnt.abs

Measured memory_bytes: 30220
N, M, Q = map(int, input().split())

S = []
for _ in range(Q):
    S.append(list(map(int, input().split())))

Max = 0

for i1 in range(1,M+1):
  for i2 in range(i1,M+1):
    for i3 in range(i2,M+1):
      for i4 in range(i3,M+1):
        for i5 in range(i4,M+1):
          for i6 in range(i5,M+1):
            for i7 in range(i6,M+1):
              for i8 in range(i7,M+1):
                for i9 in range(i8,M+1):
                  for i10 in range(i9,M+1):
                    A = [0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                    Sum = 0
                    for s in S:
                      if A[s[1]]-A[s[0]]==s[2]:
                        Sum += s[3]
                    Max = max(Max, Sum)                          

print(Max)

Measured memory_bytes: 9256
def main():
    N, K = map(int,input().split(' '))
    to = list(map(int,input().split(' ')))
    to.insert(0, 0)
    dist = [0] * (N+1) # 頭からの距離
    distance = 0
    node = 1 # start
    mod = 1
    for _ in range(N):
        node = to[node]
        K-=1
        distance += 1
        if K==0:
            print(node)
            exit(0)
        if node == 1:
            mod = distance
            break
        elif dist[node] == 0:
            dist[node] = distance
        else:
            mod = distance - dist[node]
            break
    K %= mod
    for _ in range(K):
        node = to[node]
    print(node)

    
if __name__ == "__main__":
    main()


Measured memory_bytes: 32276
#include <iostream>
using namespace std;
const int MAX=50;
int main(){
    int n,m;
    cin>>n>>m;
    string a[MAX],b[MAX];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    bool flag;
    for(int i=0;i<n-m+1;i++){
        for(int j=0;j<n-m+1;j++){
            flag=true;
            for(int ii=0;ii<m;ii++){
                for(int jj=0;jj<m;jj++){
                    if(b[ii][jj]!=a[i+ii][j+jj]){
                        flag=false;
                    }
                }
            }
            if(flag){
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[]args){

        Scanner sc = new Scanner(System.in);
        
        int A=sc.nextInt();
        int P=sc.nextInt();
        
        int max=(A*3+P)/2;
        
        
        System.out.println(max);
        sc.close(); 
    }
}

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

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

	int mini = (int)1e9;

	for (int i = 0; i < s.size() - 2; i++) {
		int s_ = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
		mini = min(mini, abs(753 - s_));
	}
	cout << mini << endl;

	return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(long long X, long long Y, long long Z){
    swap(X,Y);
    swap(X,Z);
    cout<<X<<" "<<Y<<" "<<Z<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    func(X, Y, Z);
    return 0;
}


Measured memory_bytes: 256
# 割り切る数は、Aの総和の約数である
# 自分自身を除く約数について大きい順にすべて試して、当てはまるものがあれば答え

# 8,20を7の倍数に近づけるとき、
# 8 -> mod 7が1であり、-1か+6で7の倍数になる
# 20 -> mod 7が6であり、-6か+1で7の倍数になる

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
A = list(map(int,readline().split()))

all = sum(A)
divisors = []
for i in range(1,int(all ** 0.5) + 1):
  if all % i == 0:
    divisors.append(i)
    divisors.append(all // i)

divisors = sorted(divisors,reverse = True)

for d in divisors:
  mods = [0] * (N)
  for i in range(len(A)):
    mods[i] = A[i] % d
  mods = sorted(mods)
  mods_front = [0] * N
  mods_front[0] = mods[0]
  for i in range(1,N):
    mods_front[i] = mods_front[i - 1] + mods[i]
  mods_back = [0] * N
  mods_back[-1] = d - mods[-1]
  for i in range(N - 2,-1,-1):
    mods_back[i] = mods_back[i + 1] + (d - mods[i])
  for i in range(N - 1):
    if mods_front[i] == mods_back[i + 1]:
      if K >= mods_front[i]:
        print(d)
        exit(0)
else:
  print(1)

Measured memory_bytes: 3192
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<Integer> one = nextIntArray();
      int N = one.get(0);
      int K = one.get(1);
      ArrayList<Integer> list = nextIntArray();
      myout(((N - 1) + (K - 1) - 1) / (K - 1));
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 47544
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        var s = System.Console.ReadLine();


        System.Console.WriteLine(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");

    }
}

Measured memory_bytes: 11092
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(long long S, long long W) {
  ANS((S <= W ? "unsafe" : "safe"));
}

// clang-format off
int main() {
  long long S;
  scanf("%lld",&S);
  long long W;
  scanf("%lld",&W);
  solve(S, W);
  return 0;
}


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

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999

typedef long long ll;

int main()
{
	ll N, P;
	cin >> N >> P;

	// ★N == 1の場合、a1 ={ P }の配列1種類しか存在しない
	if(N == 1){
		cout << P << endl;
		return 0;
	}

	ll res = 1;
	ll cur = P;
	for(ll k = 2; k * k <= P; k++){
		int cnt = 0;
		while(cur % k == 0){
			cur /= k;
			cnt++;
		}

		res *= pow(k, cnt / N);
	}

	cout << res << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
  	set<int> s;
  	cin>>a>>b>>c>>d;
  	s.insert(a);s.insert(b);s.insert(c);s.insert(d);
  	if(s.count(1)&&s.count(9)&&s.count(7)&&s.count(4)) cout<<"YES";
  	else cout<<"NO";
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<functional>

using namespace std;

using ll = long long;

int sumDigit(int v)
{
	int rtn = 0;

	while (v != 0)
	{
		rtn += v % 10;
		v /= 10;
	}

	return rtn;
}

int main()
{
	int N;

	cin >> N;

	int ans = 1000000000;

	for (int i = 1; i <= N / 2; ++i)
	{
		int a = sumDigit(i) + sumDigit(N - i);

		//cout << sumDigit(i) << " " << sumDigit(N - i) << endl;

		if (a < ans) { ans = a; }
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,k,i,count;
  cin >> a >> b >> k;count = 0;i = a+1;
  while(count != k){
    i -= 1;
    if (a%i==0 && b%i==0) count += 1;
  }
  cout << i << endl;
}
  

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
#define dame {puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
template <class T>
map< T, int > prime_factor(T n) {
    map< T, int > ret;
    for(T i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

void Main(){
  ll n,m;
  cin>>n>>m;
  if(n*2>m){ cout<<m/2<<endl;}
  else cout<< n + (m-n*2)/4<<endl;
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

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

int n, p, a[64];

int main() {
    for (;;) {
        scanf("%d%d", &n, &p);
        if (n == 0) return 0;
        memset(a, 0, sizeof(a));
        int i = 0, x = p;
        for (;;) {
            if (x) {
                x--, a[i]++;
                if (a[i] == p) {
                    printf("%d\n", i);
                    break;
                }
            }
            else {
                x = a[i];
                a[i] = 0;
            }
            i = (i+1) % n;
        }
    }
}

Measured memory_bytes: 756
#include <stdio.h>

int main(){
  int a[3];
  
  for(int i=0; i<3; i++)  scanf("%d", a+i);

  for(int i=0; i<2; i++)
    for(int j=i+1; j<3; j++)
      if(a[i] > a[j]){
	a[i] ^= a[j];
	a[j] ^= a[i];
	a[i] ^= a[j];
      }

  printf("%d\n", a[0]+a[1]);
  
  return 0;
}


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

int main() {
    vector<int> vec(3);
    for (int i = 0; i < 3; i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    cout << vec.at(0) * 10 + vec.at(1) + vec.at(2) << endl;

}


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

string s;
int cnt;

int main(){

    cin >> s;

    cnt = 0;

    for(int i=0; i<s.size()/2; i++){
        if (s.at(i) != s.at(s.size()-1-i)){
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>

using namespace std;

uint32_t set_bit(uint32_t val, int pos, int b)
{
	uint32_t mask = (-1) ^ (1 << pos);
	return (val & mask) | (b << pos);
}

vector<uint32_t> solve_one(uint32_t a, uint32_t b)
{
	return {a, b};
}

vector<uint32_t> solve(uint32_t a, uint32_t b, uint32_t sel, uint32_t n)
{
	if (n == 1) {
		return solve_one(a, b);
	}

	int p = 0;
	while (true) {
		uint32_t mask = (1U << p);
		if (sel & mask && (a ^ b) & mask) {
			break;
		}
		p++;
	}

	int c_p = 0;
	while (!(sel & (1U << c_p)) || p == c_p) {
		c_p++;
	}

	uint32_t n_sel = sel ^ (1U << p);
	uint32_t c     = a ^ (1U << c_p);

	vector<uint32_t> first_half = solve(a, c, n_sel, n - 1);
	vector<uint32_t> last_half  = solve(c, b, n_sel, n - 1);

	for (auto& elem : first_half) {
		elem = set_bit(elem, p, (a >> p) & 1);
	}
	for (auto& elem : last_half) {
		elem = set_bit(elem, p, (b >> p) & 1);
	}

	first_half.insert(first_half.end(), last_half.begin(), last_half.end());

	return first_half;
}

int main() {
	uint32_t n, a, b; cin >> n >> a >> b;

	uint32_t d = a ^ b;
	int bits = 0;

	{
		for (int i = 0; i < 32; i++) {
			if (d & (1U << i)) bits++;
		}
	}

	if ((bits & 1) == 0) {
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;
	vector<uint32_t> series = solve(a, b, (1U << n) - 1, n);
	for (auto it = series.begin(); it != series.end(); it++) {
		cout << *it;
		if (it + 1 != series.end()) {
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 1648
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine().Trim().Replace("/", "-");
            var time = DateTime.Parse(s);
            Console.WriteLine(time > DateTime.Parse("2019-04-30") ? "TBD" : "Heisei");
        }
    }
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:


bool edge[710][710];
int one[710],other[710];

vector<int> graph[710];

int color[710];

bool ok = true;

void dfs(int v,int c,int r){
	color[v] = c;

	if(c == 0)
		one[r]++;
	else
		other[r]++;

	for(auto &v2:graph[v]){
		if(color[v2] == -1){
			dfs(v2,c^1,r);
		}

		if(color[v2] == c) ok = false;
	}
}

bool dp[710][710];

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

	rep(i,m){
		int a,b;
		cin >> a >> b;
		edge[a-1][b-1] = edge[b-1][a-1] = true;
	}

	rep(i,n)rep(j,n) if(i != j and edge[i][j] == false) graph[i].push_back(j);

	rep(i,n) color[i] = -1;

	dp[0][0] = true;
	int total = 0;

	rep(v,n){
		if(color[v] == -1) dfs(v,0,v);
		
		if(ok == false){
			cout << -1 << endl;
			return 0;
		}

		rep(i,total+1){
			if(dp[total][i] == false) continue;
			dp[total + one[v] + other[v]][i + one[v]] = true;
			dp[total + one[v] + other[v]][i + other[v]] = true;
		}

		total += one[v] + other[v];
	}

	int ans = 1 << 20;

	rep(i,n+1){
		if(dp[n][i] == false) continue; 
		int cur = i * (i-1)/2 + (n-i) * (n-i-1)/2;
		chmin(ans,cur);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    string s;cin>>s;
    if(s=="RRR")cout<<3<<endl;
    else if(s=="SRR"||s=="RRS")cout<<2<<endl;
    else if(s=="SSS")cout<<0<<endl;
    else cout<<1<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
//#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 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 * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n, a[114], sum;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	int m; cin >> m;
	rep(i, m) {
		int x, y; cin >> x >> y;
		cout << sum - a[x - 1] + y << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a; cin >> a;
	cout << a + a*a + a*a*a;
}


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

int main() {
    int N, D ,X;
    cin >> N >> D >> X;
    int count = X;

    vector<int> v(N);
    for(int i=0; i<N; i++) cin >> v[i];

    for(int i=0; i<N; i++) {
        int day = 1;
        while(day <= D) {
            day += v[i];
            count++;
        }
    }
    cout <<count << endl;
}


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

int main(void)
{
  long long a,b;
  scanf("%lld %lld",&a,&b);
  if((a+b)%2==0){
    printf("%lld\n",(a+b)/2);
    return 0;
  }

  puts("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>
#include <map>

using namespace std;

int main(){
	int a,b_,b;
	cin>>a>>b;
	int digs = 0;
	b_ = b;
	while(b_ != 0){
		b_ /= 10;
		a *= 10;
	}
	int x =0;
	while (x*x <= (a+b)){
		if (x*x == a+b){
			cout<<"Yes"<<endl;
			return 0;
		}
		x++;
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
H = list(map(int,input().split()))[::-1]

ans = [0 for i in range(n)]

for i in range(1,n):
  if H[i-1] <= H[i]:
    ans[i] = ans[i-1]+1
  else:
    ans[i] = 0
print(max(ans))
    



Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s, t; cin >> s;
	for(auto c : s){
		if(t.empty()) t.push_back(c);
		else if(t.back() == 'S' && c == 'T') t.pop_back();
		else t.push_back(c);
	}
	cout << t.size() << endl;
	return 0;
}


Measured memory_bytes: 776
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    K, X = map(int, input().split())
    if 500 * K >= X:
        print("Yes")
    else:
        print("No")


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9768
#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);

    int N;
    cin>>N;
    string S[N];
    int t[N];
    string X;
    int ans=0;
    bool z=false;
    rep(i,N){
        cin>>S[i]>>t[i];
    }
    cin>>X;
    rep(i,N){
        if(z)ans+=t[i];
        if(X==S[i])z=true;
    }
    cout << ans << endl;








}


Measured memory_bytes: 3588