akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
#define mod 1000000007
#define point complex<long long>
#define pi acos(-1)
#define pb push_back


typedef long long ll;

using namespace std;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n, arr[25][25];
int dp[(1<<22)];
int vis;
ll solve(int i){
    if(i==n)
        return 1;
    if(dp[vis]!=-1)
        return dp[vis];
    ll res=0;
    for(int y=0; y<n; y++){
        if((vis>>y)%2==0 && arr[i][y]){
            vis+=(1<<y);
            res+=solve(i+1);
            vis-=(1<<y); res%=mod;
        }
    }
    return dp[vis]=res;
}
int main()
{
    Fastio();
    int ttt=1; //cin>>ttt;
    while(ttt--){
        cin>>n;
        for(int i=0; i<n; i++){
            for(int y=0; y<n; y++){cin>>arr[i][y];}
        }
        memset(dp, -1, sizeof dp);
        cout<<solve(0)<<'\n';
    }

    return 0;
}


Measured memory_bytes: 19960
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int main()
{
    std::ios::sync_with_stdio(false);
    string s;
    while(cin>>s)
    {
        int l=s.length();
        int sta,ed;
        for(int i=0;i<l;i++)
        {
            if(s[i]=='A')
            {
                sta=i;
                break;
            }
        }
        for(int i=l-1;i>=0;i--)
        {
            if(s[i]=='Z')
            {
                ed=i;
                break;
            }
        }
        cout<<ed-sta+1<<endl;
    }
    return 0;
}


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

int main(){
    int E,Y;
    cin>>E>>Y;
    switch(E){
        case 0:
            if(1868<=Y&&Y<=1911) cout<<"M"<<Y-1867<<endl;
            else if(1912<=Y&&Y<=1925) cout<<"T"<<Y-1911<<endl;
            else if(1926<=Y&&Y<=1988) cout<<"S"<<Y-1925<<endl;
            else if(1989<=Y&&Y<=2016) cout<<"H"<<Y-1988<<endl;
            break;
        case 1:
            cout<<Y+1867<<endl;
            break;
        case 2:
            cout<<Y+1911<<endl;
            break;
        case 3:
            cout<<Y+1925<<endl;
            break;
        case 4:
            cout<<Y+1988<<endl;
            break;
    }

    return 0;
}


Measured memory_bytes: 3104
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	flg := true
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		arr[i] = tmp
		flg = flg && tmp % 2 == 0
	}
	count := 0
	for flg {
		count++
		for i := 0; i < n; i++ {
			arr[i] = arr[i] / 2
			flg = flg && arr[i] % 2 == 0
		}
	}
	fmt.Println(count)
}

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

const double PI = acos(-1);

int main() {
  int a, b, h, m;
  std::cin >> a >> b >> h >> m;
  double th_m, th_h;
  th_h = ((double)h / 12.0 + (double)1/12 * ((double)m / 60) ) * 2 * PI;
  th_m = (double)m / 60 * 2 * PI;
  
  double xh = a * cos(th_h);
  double yh = a * sin(th_h);
  double xm = b * cos(th_m);
  double ym = b * sin(th_m);
  double dx = xh - xm, dy = yh - ym;
  double ans = sqrt(dx*dx + dy*dy);
  printf("%.10f\n", ans);
}


Measured memory_bytes: 4012
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007// prime modulo value 
#define C 1000000001
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x);
		y = y >> 1;
		x = (x * x);
	}
	return res;
}
double dist(ll x1, ll y1, ll x2, ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n+1, 0);
	vector<ll> b(n, 0);
	f(i, 0, n+1)
		cin >> a[i];
	f(i, 0, n)
		cin >> b[i];
	ll ans = 0;
	f(i, 0, n)
	{
		ans += min(b[i], a[i]);
		b[i] -= min(b[i], a[i]);
		ans += min(b[i], a[i+1]);
		a[i + 1] -= min(b[i], a[i+1]);
	}
	cout << ans;
	return 0;
}


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

using namespace std;


typedef long long ll;

int main(){
  ll A,B,C; ll res1, res2 ,res3;
  cin >> A >> B >> C;
  
  if( A % 2 == 0){ res1  = 0; }
  else{ res1 = B*C;}
  
  if( B % 2 == 0){ res2 = 0;}
  else{ res2 = A * C;}
  
  if( C % 2 == 0){ res3 = 0;}
  else{ res3 = A * B;}
  
  cout << min(res1,min(res2,res3)) << endl; return 0;}

Measured memory_bytes: 256
import kotlin.comparisons.compareValues

fun main(arg: Array<String>) {
    val (N, X) = listOfInt()
    var A = listOfLong().toLongArray()
    var ans = 0L
    for (n in 1 until N) {
        val s = (A[n - 1] + A[n]) - X
        if (s <= 0) continue
        ans += s
        if (A[n] >= s) A[n] -= s 
        else {
            A[n - 1] -= s - A[n]
            A[n] = 0
        }
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 73604
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 2005;
bitset<N> b[N], rb[N];
int w[N][N];

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

    int n;
    cin >> n;

    for (int i = 1; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < i; j++) {
            w[i + 1][j + 1] = s[j] - '0';
            w[j + 1][i + 1] = 1 - w[i + 1][j + 1];
        }
    }

    for (int i = 1; i <= n; i++) {
        w[0][i] = 0;
        w[i][0] = 1;
        w[n + 1][i] = 0;
        w[i][n + 1] = 1;
    }

    n += 2;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (abs(j - i) == 1) {
                rb[j][i] = w[i][j];
                b[i][j] = w[i][j];
            }
        }
    }

    for (int i = 2; i < n; i++) {
        for (int l = 0, r = i; r < n; l++, r++) {
            if ((b[l] & b[r]).count() ||
                (rb[l] & b[r]).count() ||
                (rb[r] & b[l]).count()) {
                if (w[l][r]) {
                    rb[r][l] = 1;
                    b[l][r] = 1;
                }
                else {
                    rb[l][r] = 1;
                    b[r][l] = 1;
                }
            }
        }
    }

    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < n; j++) {
    //         cout << b[i][j];
    //     }
    //     cout << "\n";
    // }
    // cout << "\n";

    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < n; j++) {
    //         cout << rb[i][j];
    //     }
    //     cout << "\n";
    // }
    // cout << "\n";

    int ans = 0;

    for (int i = 0; i < n; i++) {
        if (b[i][0] && b[i][n - 1]) {
            ans++;
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 17024
a, b, c, d= map(int,input().split())
if b*d > a*c and b*d > a*d and b*d > b*c:
  print(b*d)
elif a*d > a*c and a*d > b*c:
  print(a*d)
elif a*c > b*c:
  print(a*c)
else:
  print(b*c)

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

using namespace std;

int a[305][305];

int n, m;

vector <int> sp[305];

bool del[305];

int cur[305];

bool check(int lim) {
    for (int i = 0; i < m; ++i)
        sp[i].clear();
    for (int i = 0; i < n; ++i) {
        sp[a[i][0]].push_back(i);
        cur[i] = 0;
    }
    memset(del, 0, m * sizeof(bool));
    while (true) {
        int p = -1;
        for (int i = 0; i < m; ++i)
            if ((int)sp[i].size() > lim)
                p = i;
        if (p == -1)
            return true;
        del[p] = true;
        for (auto x : sp[p]) {
            while (cur[x] < m && del[a[x][cur[x]]])
                ++ cur[x];
            if (cur[x] == m)
                return false;
            sp[a[x][cur[x]]].push_back(x);
        }
        sp[p].clear();
    }
    return false;
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            scanf("%d", a[i] + j), -- a[i][j];
    int low = 1, high = n, ret;
    while (low <= high) {
        int mid = (low + high) >> 1;
        if (check(mid)) {
            ret = mid;
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }
    printf("%d\n", ret);
    return 0;
}


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> vec(M * 2);
  for (int i = 0; i < M * 2; i++) {
      cin >> vec.at(i);
  }
  vector<int> backet(N);
  for(int i = 0; i < M * 2; i++){
  	backet.at(vec.at(i)-1)++;
  }
  for(int i = 0; i < N; i++){
  	cout << backet.at(i) << endl;
  }
}


Measured memory_bytes: 256
import bisect
from collections import deque
def solve():
  n = int(input())
  a = [int(input()) for _ in range(n)]
  t = 1
  ans = deque([])
  for i,w in enumerate(a):
   if i == 0:
      ans.append(w)
   else:
    
    place = bisect.bisect_left(ans,w)
    if place == 0:
      ans.appendleft(w)
      t += 1
    else:
      ans[place-1] = w

  print(len(ans))
  
  
solve()

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

int main() {
  int n;
   cin >> n;
  vector<int> l(n);
  int ans = 0;
  for (int i = 0; i < n; i++) cin >> l[i];
  sort (l.begin(), l.end());
  reverse (l.begin(), l.end());
  
  for (int i = 0; i < n; i++){
    for (int j = i + 1; j < n; j++){
      for (int k = j + 1; k < n; k++){
        if(l[i] != l[j] && l[j] != l[k] && l[i] < l[j] + l[k]) ans++;
      }
    }
  }
  cout << ans << endl;
}



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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int x,y,z,K;
ll a[1001],b[1001],c[1001];
ll dp[3001];
vector<ll> d(1000100);
vector<ll> ans(3000300);
int main() {
    cin >> x >> y >> z >> K;
    for (int i=0;i<x;i++) {
        cin >> a[i];
    }
    for (int i=0;i<y;i++) {
        cin >> b[i];
    }
    for (int i=0;i<z;i++) {
        cin >> c[i];
    }
    sort(c,c+z,greater<int>());

    for (int i=0;i<x;i++) {
        for (int j=0;j<y;j++) {
            d.push_back(a[i]+b[j]);
        }
    }
    sort(d.begin(),d.end(),greater<ll>());

    for (int k=0;k<K;k++) {
        for (int i=0;i<z;i++) {
            ans.push_back(d[k]+c[i]);
        }
    }
    sort(ans.begin(),ans.end(),greater<ll>());
    for (int i=0;i<K;i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 64760
#include <iostream>
using namespace std;
int main()
{
    int A,B,k;
    cin >>A;
    cin >>B;
    k=((A+B)/2);
    
    if(abs(A-k)!=abs(B-k)){
        cout << "IMPOSSIBLE"<<endl;
    }
    else
        cout <<k<<endl;
}


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

using namespace std;

const int N = 1e5 + 7;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;


int solver() {
    int n, x, t; cin >> n >> x >> t;
    cout << ((n - 1 + x) / x) * t << endl;
    return 0;
}

int main() {
    int tests = 1;
    // cin >> tests;
    for (int i = 1; i <= tests; ++i) {
        solver();
    }
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int even = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] % 2 == 0) {
                even++;
            }
        }
        System.out.println((int) (Math.pow(3, n) - Math.pow(2, even)));
    }

}


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

int a[1000];

int main(){
	int i,j,m,n,t,s,k,ans = 0;
	scanf("%d",&k);
	for(i=1;i<=k;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=k;i++){
		bool f = true;
		for(j=1;j<=i-1;j++){
			if(a[j]>a[i])f = false;
		}
		if(f)ans++;
	}
	printf("%d",ans);
	return 0;
} 


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

int main()
{
  int h,w; //h side w vertical
  cin >> h >> w;
  
  char s[h][w];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> s[i][j];
    }
  }
  
  int flag = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '#'){
        if(s[i-1][j] == '#' && i != 0){
          continue;
        }else if(s[i][j-1] == '#' && j != 0){
          continue;
        }else if(s[i][j+1] == '#' && j != w-1){
          continue;
        }else if(s[i+1][j] == '#' && i != h-1){
          continue;
        }else{
          flag = 1;
          break;
        }//else
      }//if
    }//for
    if(flag == 1){
      break;
    }
  }//for
  
  if(flag == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 3640
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    long a = sc.nextLong();
    long b = sc.nextLong();

    long target = gcd(a, b);

    Set<Long> factors = factorize(target);
    factors.add(1L);

    os.println(factors.size());
  }

  private static Set<Long> factorize(long n) {
    Set<Long> factors = new HashSet<>();
    long root = (long) Math.sqrt(n) + 1;
    for (long i = 2; i <= root; i++) {
      if (n % i != 0) continue;
      do {
        n /= i;

      } while (n % i == 0);
      factors.add(i);
    }
    factors.add(n);
    return factors;
  }

  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }
}

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

int n,m,a,b;

int main()  {
    scanf("%d%d%d%d",&n,&m,&a,&b);
    for (int i=1;i<=n;++i)  {
        for (int j=1;j<=m;++j)
            putchar(((i<=b)^(j<=a))+'0');
        puts("");
    }
    return 0;
}

Measured memory_bytes: 1280
#                         author:  kagemeka 
#                         created: 2019-11-06 16:52:04(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n, *s = sys.stdin.read().split()
    l = len(set(s))
    if l == 3: ans = 'Three'
    else: ans = 'Four'
    print(ans)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
const int MAX_N=2*1e5+5;
int data[MAX_N];
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>data[i];
  }
  int l=0,r=1;//[l,r)
  long long  ans=1;
  int now=data[0];
  while(r<n){
    if((now+data[r])==(now^data[r])){
      ans+=r-l+1;
      now+=data[r];
      r++;
    }
    else {
      now-=data[l];
      l++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
import math
def ncr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

d = list(map(int, input().split()))
print(d[0]-d[1]+1)
for i in range(2, d[1]+1): #2~k
    if (d[0]-d[1]+1)<i:
        print(0)
    else:
        print(ncr(d[0]-d[1]+1, i)*ncr(d[1]-1, i-1)%1000000007)

Measured memory_bytes: 3316
#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;
vector<ll> appear(26, 0);
cin >> s;
for (ll i = 0; i < s.size(); i++) {
    appear[s[i] - 'a']++;
}
if(s.size()<26){
    for (ll i = 0; i < 26; i++) {
        if(appear[i]==0){
            s += ('a' + i);
            break;
        }
    }
}
else{
    ll flag = 32;
    for (ll i = s.size() - 1; i > 0; i--) {
        if (s[i-1] < s[i]){
            flag = i;
            break;
        }
    }
    if (flag == 32){
        cout << -1 << endl;
        return 0;
    }
    string t = s.substr(flag, s.end() - s.begin() - flag+1);
    s.erase(s.begin() + flag, s.end());
    ll plus = INF;
    ll tt;
    for (ll i = 0; i < t.size(); i++) {
        tt = t[i]-'a';
        if (s[s.size()-1] < t[i]) chmin(plus, tt);
    }
    s.pop_back();
    s += ('a' + plus);
}
    cout << s << endl;
}

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

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        int x, a, b;
        in >> x >> a >> b;
        out << (x < b - a ? "dangerous" : b > a ? "safe" : "delicious") << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

#include <fstream>
#include <iostream>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;

	cin >> S;

	if (S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int h[n+2];
  h[0] = 0,h[n+1] = 0;
  int num = 0, plus = 1;
  for(int i = 0; i < n; ++i) scanf("%d",&h[i+1]);
  int max = 0;
  for(int i = 1; i < n + 1; ++i) if(max < h[i]) max = h[i];
  int flag = 0;
  for(int j = 0; j < max; ++j){
    for(int i = 0; i < n + 2; ++i){
      if(h[i] <= 0) flag = 1;
      else if(h[i] > 0 && flag == 1){
        num++;
        flag = 0;
      }
      else flag = 0;
    }
    for(int i = 0; i < n + 2; ++i) h[i]--;
  }
  printf("%d\n",num);
  return 0;
}

Measured memory_bytes: 128
import numpy as np
ps = list(map(int, input().split()))
v1 = [ps[2]-ps[0], ps[3]-ps[1]]
res = []
res.append(ps[2]-v1[1])
res.append(ps[3]+v1[0])
res.append(res[0]-v1[0])
res.append(res[1]-v1[1])
print("{} {} {} {}".format(res[0],
                           res[1],
                           res[2],
                           res[3]))

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

#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

#include<unordered_map>
#include<random>


int main() {
	int N,K;cin>>N>>K;
	vector<int>xs(N);
	vector<int>ls,rs;
	for (int i = 0; i < N; ++i) {
		cin >> xs[i];
		if (xs[i] <= 0)ls.push_back(xs[i]);
		else rs.push_back(xs[i]);
	}

	int ans=1e9;
	for (int i = 0; i <= ls.size(); ++i) {
		if(i>K)break;
		else {
			int l,r;
			if(i==0)l=0;
			else {
				l=ls[ls.size()-i];
			}
			l=abs(l);

			int j=K-i;
			if(j==0)r=0;
			else {
				
				if (j > rs.size()) {
					r = 1e9;
				}
				else {
					r = rs[j-1];
				}
			}

			int nans=l+r+min(l,r);
			ans=min(ans,nans);
		}
	}
	cout<<ans<<endl;

	return 0;
} 

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


 int main(){ 

 int A, B, ans;

 cin >> A >> B;


 if (A < 6) ans = 0;
  else if (A >= 13) ans = B;
  else if ((A < 12) || (A >= 6)) ans = B/2;

 cout << ans << endl;

 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#include<bitset>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    int w,h,n; cin>>w>>h>>n;
    vector<vector<bool> >v(h+1,vb(w,true));
    rep(i,n){
        int x,y; cin>>x>>y; --x; --y;
        int key;cin>>key;
        if(key==1){
            for(int i=0;i<=x;i++)rep(j,h)v[j][i]=false;
        }else if(key==2){
            for(int i=x+1;i<w;i++)rep(j,h)v[j][i]=false;
        }else if(key==3){
            for(int i=0;i<=y;i++)rep(j,w)v[i][j]=false;
        }else if(key==4){
            for(int i=y+1;i<h;i++)rep(j,w)v[i][j]=false;
        }
    }
    int ans=0;
    rep(i,h)rep(j,w)if(v[i][j])ans++;
    cout<<ans<<endl;
    
}


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

int main() {
  int a, b, j;
  cin >> a >> b;
  j = 0;

  // ここにプログラムを追記
  for (int i = 0; i <= b - a; i++) {
    int x = a + i;
    int y = x % 100 / 10 + x % 10 * 10;
    if (x / 1000 == y) {
      j++;
    }
  }
  
  cout << j << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

void failure () {
  cout << "NO" << endl;
  exit(0);
}

const int MAX_N = 1e5 + 5;

vector<int> adj [MAX_N];
int arr [MAX_N];

ll dfs (int u, int p) {
  if ((int) adj[u].size() == 1) {
    return arr[u];
  }

  ll sum = 0, mx = 0;
  for (int nxt : adj[u]) {
    if (nxt != p) {
      ll nval = dfs(nxt, u);
      sum += nval;
      mx = max(mx, nval);
    }
  }

  if (p == 0) {
    if (2 * mx > sum) {
      failure();
    }
    
    if (sum != 2 * arr[u]) {
      failure();
    }
    return 0LL;
  } else {
    ll diff = sum - arr[u];
    if (diff < 0) failure();
    if (sum - 2 * diff < 0) failure();
    // diff is the number of pairs we match
    // we must be able to do this without needing
    // to take a pair from mx
    if (sum - mx < diff) failure();
    
    return sum - 2 * diff;
  }
}

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }

  if (n == 2) {
    if (arr[1] == arr[2]) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
    return 0;
  }

  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;

    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  int root = -1;
  for (int i = 1; i <= n; i++) {
    if (adj[i].size() != 1) {
      root = i;
    }
  }

  dfs(root, 0);
  cout << "YES" << endl;
}


Measured memory_bytes: 13312
n = int(input())
a,b = [],[]
for i in range(n):
  x,y = map(int,input().split())
  a.append(x+y)
  b.append(x-y)

a.sort()
b.sort()
ans = max(a[-1]-a[0],b[-1]-b[0])
print(ans)

Measured memory_bytes: 100012
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			//Initialization
			double[] a = {sc.nextDouble(), sc.nextDouble()};
			double[] b = {sc.nextDouble(), sc.nextDouble()};
			double[] c = {sc.nextDouble(), sc.nextDouble()};
			double[] p = {sc.nextDouble(), sc.nextDouble()};

			TwoVector vab, vac, vap, vca, vcb, vcp;
			vab = new TwoVector(b, a);
			vac = new TwoVector(c, a);
			vap = new TwoVector(p, a);
			vca = new TwoVector(a, c);
			vcb = new TwoVector(b, c);
			vcp = new TwoVector(p, c);

			if(TwoVector.getSgnSq(vab, vap) * TwoVector.getSgnSq(vap, vac) > 0 && TwoVector.getSgnSq(vca, vcp) * TwoVector.getSgnSq(vcp, vcb) > 0){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}
	class TwoVector{
		public double x, y;
		
		public TwoVector(double[] c){
			x = c[0];
			y = c[1];
		}
		public TwoVector(double[] c, double[] s){
			x = c[0] - s[0];
			y = c[1] - s[1];
		}

		public static double getSgnSq(TwoVector a, TwoVector b){
			return (a.x * b.y - a.y * b.x) / 2;
		}
	}

Measured memory_bytes: 12000
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((((a - b >= 0 && a - b <= d) || (b - a >= 0 && b - a <= d)) && ((c - b >= 0 && c - b <= d) || (b - c >= 0 && b - c <= d)))|| (c - a >= 0 && c - a <= d) || (a - c >= 0 && a - c <= d))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
} 

Measured memory_bytes: 3564
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    cout<<(s<t?"Yes":"No")<<endl;
    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int,pair<int,int> > iii;
#define PI 3.141592653589793
#define mod 1000000007
# define N 105
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF (ll)1e18
# define LG 20	

int main()
{
	IOS;
   int n;
   cin >> n;
   int a;
   vector<int>v;
   for(int i=0;i<n;i++)
    {
      cin >> a;
      v.pb(a);
    }
    sort(v.begin(),v.end());
    int mid;
    if(v[n-1]==1)
    {
    	cout << 1<<" "<<0<<"\n";
    	return 0;
    }
    if(v[n-1]&1)
     mid=v[n-1]/2+1;
    else
    	mid=v[n-1]/2;
    vector<int>::iterator it=upper_bound(v.begin(),v.end(),mid);
    int dist1=1000000005;
    int dist2=1000000005;
    int ans=1000000000;
    int aid;
    int id1,id2;
    if(it!=v.end())
    {
    	 id2=(it-v.begin());
    	  //trace1(id2);
    	if(id2!=n-1) 
    	dist2=abs(mid-v[id2]);
    	//trace1(dist2);
    }
    if(it!=v.begin())
    {
    	it--;
    	 id1=(it-v.begin());
    	 //trace1(id1);
    	 if(id1!=n-1);
    	dist1=abs(mid-v[id1]);
    	//trace1(dist1);
    }
    if(ans>dist1)
    {
    	ans=dist1;
    	aid=id1;
    }
    if(ans>dist2)
    {
    	ans=dist2;
    	aid=id2;
    }
    cout << v[n-1]<<" "<<v[aid];
}

Measured memory_bytes: 892
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nItems := scanInt(sc)
	items := make([]float64, nItems)
	for i := 0; i < nItems; i++ {
		items[i] = float64(scanInt(sc))
	}

	sort.Float64s(items)

	item := items[0]
	for i := 1; i < nItems; i++ {
		item = (item + items[i]) / 2
	}
	fmt.Println(item)
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 640
a = []
try:
    while True:
        a.append(input())
except EOFError:
    pass

for i in range(len(a)):
    a[i] = a[i].lower()

b=" ".join(a)

for j in "abcdefghijklmnopqrstuvwxyz":
    print(j,":",b.count(j))


Measured memory_bytes: 5572
#include <stdio.h>
int main(){
	int n,m;
	int a[110][110];
	int b[110];
	int i,j;
	int c;
	scanf("%d %d\n",&n,&m);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	for(i=0;i<n;i++){
		c=0;
		for(j=0;j<m;j++){
			c+=a[i][j]*b[j];
		}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    
int n ;
cin>>n;
vector<int> dp(10050,0);
for(int i=1;i<106;i++)
{
    for(int j=1;j<106;j++)
    {
        for(int k=1;k<106;k++) 
        {
        
            int temp = i*i+j*j+k*k+i*j+j*k+k*i;
        
        if(temp<=10040)
            dp[temp]++;
            
        }
    }
}
for(int i=0;i<n;i++)
{
    cout<<dp[i+1]<<endl;
}


}

Measured memory_bytes: 3652
#include<stdio.h>
#include<cmath>
struct Point{
    double x;
    double y;
};
double w=acos(-1)*60/180;
void koch(int n,Point P1,Point P2){
    if(n==0) return;
    Point s,t,u;
    s.x=(2*P1.x+1*P2.x)/3.0,s.y=(2*P1.y+1*P2.y)/3.0,t.x=(1*P1.x+2*P2.x)/3.0,t.y=(1*P1.y+2*P2.y)/3.0;
    u.x=(t.x-s.x)*cos(w)-(t.y-s.y)*sin(w)+s.x,u.y=(t.x-s.x)*sin(w)+(t.y-s.y)*cos(w)+s.y;
    koch(n-1,P1,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,P2);
}
int main(){
    int n;
    Point a,b;
    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;
    scanf("%d",&n);
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);    
    return 0;
}


Measured memory_bytes: 2988
#include <stdio.h>
#include <cstdio>
#include <queue>
#include <set>
using namespace std;

int main(){
  
  /* read input */
  int N;
  scanf("%d", &N); // read int
  
  /*solve problem*/
  if(N==7 || N==5 || N==3){
    printf("YES");
  }
  else
    printf("NO");
  
  return 0;
}


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

int main(){
  int i,j,k;
  int x,y;
  int inf = 1 << 10;
  int m[200]={};
  int memo[1000005]={};
  int memo2[1000005]={};
  vector <int>  odd;
  fill(memo,memo+1000005,inf);
  fill(memo2,memo2+1000005,inf);
  for(i=1;i<201;i++) {
    m[i-1]=i*(i+1)*(i+2)/6;
    if(m[i-1]%2==1) odd.push_back(m[i-1]);
  }
  memo[0]=0;
  for(i=0;i<200;i++) {
    for(j=m[i];j<1000005;j++){
      memo[j]=min(memo[j],memo[j-m[i]]+1);
    }
  }
  memo2[0]=0;
  for(i=0;i<odd.size();i++) {
    for(j=odd[i];j<1000005;j++){
      memo2[j]=min(memo2[j],memo2[j-odd[i]]+1);
    }
  }
  int n;
  cin >> n;
  while(n!=0){
    cout << memo[n] << " " <<  memo2[n] << endl;
    cin >> n;
  }
  return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;

const int MAX = 1 << 17;
int n, w;
PII a[MAX];
LL dp[101][MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);

	cin >> n >> w;
	FOR(i, 1, n + 1)
		cin >> a[i].X >> a[i].Y;
	
	FOR(i, 1, n + 1)
	{
		FOR(j, 0, w + 1)
			dp[i][j] = dp[i - 1][j];
		
		FOR(j, 0, w + 1 - a[i].X)
			dp[i][j + a[i].X] = max(dp[i][j + a[i].X], dp[i - 1][j] + a[i].Y);
	}
	
	//debug(dp[2][3])
	LL ans = 0;
	FOR(i, 0, w + 1)
		ans = max(ans, dp[n][i]);
	cout << ans << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 103424
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
const ll MOD = 1e9 + 7;
const ll INF = (ll)1e18;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string s;
  cin>>s;
  int n=s.size()-1;
  fi(0,1<<n){
    ll sum=s[n]-'0';
    int p=1;
    int d;
    for(int j=n-1;j>=0;--j){
      d=s[j]-'0';
      if((1<<j)&i){
        p=0;
      }
      ll to_add=d*pow(10,p++);
      // cout<<to_add<<endl;
      sum+=to_add;
    }
    // cout<<"sum:"<<sum<<endl;
    ans+=sum;
  }
  cout << ans << endl;
  return 0;
}



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

#define pb push_back

vector<int>g[100003];
vector<int>v(100003);
queue<int>q;

//original

string s;
int n;
int rem[2020];



int main()
{
    cin>>s;
    n = s.size();
    int pow10 =1;
    int num = 0;
    int total = 0;
    rem[0]=1;

    for(int i=n-1;i>=0;i--)
    {
        int digit = s[i]-'0';
        num += digit*pow10;

        total += rem[num%2019];
        rem[num%2019]++;


        pow10 *= 10;
        pow10 %= 2019;
    }
    cout<<total<<endl;


}







Measured memory_bytes: 6348
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	min_max
# CreatedDate:  2020-05-24 15:21:55 +0900
# LastModified: 2020-05-24 15:22:54 +0900
#


import os
import sys

def main():
    a = list(map(int,input().split()))
    print("{} {}".format(min(a),max(a)))

    


if __name__ == "__main__":
    main()



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int N = 1e5+5;
int n,c[N]={},ans[3]={};
vi T[N];

int dist(int u, int v) {
	if(v == n) return 0;
	int mn = 1<<30;
	for(auto w : T[v])
		if(w != u)
			mn = min(mn,dist(v,w));
	return mn+1;
}

void dfs1(int u, int v, int col, int mx) {
	if(!mx) return;
	c[v] = col;
	for(auto w : T[v])
		if(w != u)
			dfs1(v,w,col,mx-1);
}

void dfs2(int u, int v, int col) {
	if(c[v]) col = c[v];
	c[v] = col;
	++ans[col];
	for(auto w : T[v])
		if(w != u)
			dfs2(v,w,col);
}

int main() {
	scanf("%d",&n);
	for(int i = 1; i < n; ++i) {
		int a,b;
		scanf("%d%d",&a,&b);
		T[a].pb(b), T[b].pb(a);
	}
	int d = dist(-1,1)+1;
	dfs1(-1,1,1,d-d/2);
	dfs1(-1,n,2,d/2);
	dfs2(-1,1,0);
	if(ans[1] > ans[2]) printf("Fennec\n");
	else printf("Snuke\n");
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

using Real = double;
using Point = complex<Real>;
const Real Pi = acos(-1), EPS = 1e-9;
inline bool eq(Real a, Real b) { return fabs(a - b) < EPS; }

//scalar
Point operator*(const Point &p, const Real &c)
{
    return Point(c * real(p), c * imag(p));
}

//add
Point operator+(const Point &p, const Point &q)
{
    return Point(real(p) + real(q), imag(p) + imag(q));
}

//equal
bool operator==(const Point &p, const Point &q)
{
    return (real(p) == real(q)) && (imag(p) == imag(q));
}

Real radian_to_degree(Real r)
{
    return (r * 180.0 / Pi);
}

Real degree_to_radian(Real d)
{
    return (d * Pi / 180.0);
}

//rotate
Point rot(Real theta, const Point &p)
{
    return Point(cos(theta) * p.real() - sin(theta) * p.imag(), sin(theta) * p.real() + cos(theta) * p.imag());
}

//norm
Real norm(Point const &p)
{
    return (real(p) * real(p) + imag(p) * imag(p));
}

//argumant [0, 2 * Pi)
Real arg(Point const &p)
{
    Real a = atan2(imag(p), real(p));
    if (a < 0)
        a = fabs(a) + Pi;
    return a;
}

//input
istream &operator>>(istream &is, Point &p)
{
    Real a, b;
    is >> a >> b;
    p = Point(a, b);
    return is;
}

//output
ostream &operator<<(ostream &os, Point &p)
{
    os << fixed << setprecision(10) << p.real() << " " << p.imag();
}

// a line given two points
struct Line
{
    Point a, b;
    Line() = default;

    Line(Point a, Point b) : a(a), b(b) {}

    // Ax + By = C
    Line(Real A, Real B, Real C)
    {
        if (eq(A, 0))
            a = Point(0, C / B), b = Point(1, C / B);
        else if (eq(B, 0))
            b = Point(C / A, 0), b = Point(C / A, 1);
        else
            a = Point(0, C / B), b = Point(C / A, 0);
    }

    friend istream &operator>>(istream &is, Line &a)
    {
        return is >> a.a >> a.b;
    }

    friend ostream &operator<<(ostream &os, Line &p)
    {
        return os << p.a << " to " << p.b;
    }
};

using Points = vector<Point>;
using Polygon = vector<Point>;
using Lines = vector<Line>;

Real dot(const Point &p, const Point &q)
{
    return (real(p) * real(q) + imag(p) * imag(q));
}

//For given three points p1,p2,p, find the projection point x of p onto p1p2.
Point projection(const Line &l, const Point &p)
{
    double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); // direction vector
    return l.a + (l.a - l.b) * t;
}

//For given three points p1,p2,p, find the reflection point x of p onto p1p2.
Point reflection(const Line &l, const Point &p)
{
    return p + (projection(l, p) - p) * 2.0;
}

int main()
{
    Line l;
    cin >> l;
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        Point X;
        cin >> X;
        Point A = reflection(l, X);
        cout << A << endl;
    }
}


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


int main() {
  int k ; 
  cin >> k ;
  
  vector<long long> a ; 
  for(int i = 1 ; i <= 9 ; i++) a.push_back(i) ;
  while(1) {
    if( k <= a.size()){
      cout << a.at(k-1) << endl ;
      return 0 ; 
    }
    k -= a.size() ; 
    vector<long long> old ; 
    swap(old , a) ; 
    for(long long x : old){
      //cout << x << endl ;
      for(int i = -1 ; i <= 1 ; i++){
        int d = x%10 + i ; 
        if(d < 0 || d >9) continue ;
        long long nx = x*10 + d ; 
        a.push_back(nx) ; 
      }
    }
  }
}

Measured memory_bytes: 4668
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 9;
 
int _;

//========================================================================
int a[maxn];
int b[1000009];
bool vis[1000009];
int cmp(int a,int b) { return a>b; }
//========================================================================
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        b[a[i]]++;
    }
    int ans=0,flag=0;
    for(int i=1;i<=n;i++)
    {
        flag=0;
        b[a[i]]--;
        int k=sqrt(a[i]);
        for(int j=1;j<=k;j++)
        {
            if(a[i]%j==0) 
            {
                if(b[j]||b[a[i]/j]) flag=1; 
            }
        }
        if(!flag) ans++;
        b[a[i]]++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 8392
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    deque<int> A[N];
    rep(i, N) {
        deque<int> a(N-1);
        rep(j, N-1) cin >> a[j];
        rep(k, N-1) a[k]--; 
        A[i] = a;
    }
    ll ans = 0;
    ll match = 0;
    set<int> cand;
    rep(i, N) cand.insert(i);
    while (match < N * (N-1) / 2) {
        ans++;
        bool flag = false;
        vector<bool> used(N);
        set<int> next;
        for (int ca : cand) {
            if (A[ca].empty()) continue;
            if (used[ca]) continue;
            used[ca] = true;
            int op = A[ca].front();
            if (A[op].empty() || used[op]) continue;
            if (A[op].front() == ca) {
                match++;
                used[op] = true;
                A[ca].pop_front(); A[op].pop_front();
                if (!A[ca].empty()) next.insert(ca);
                if (!A[op].empty()) next.insert(op);
                flag = true;
            }
        }
        swap(cand, next);
        if (!flag) {
            cout << -1 << '\n';
            return 0;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 8596
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;


ll m=1000000007;

ll mod=1e9+7;
ll dp[2000+4];


int main()
{
  ll n,m,k;
  cin>>n>>m>>k;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  vector<ll>b(m);
  rep(i,m)cin>>b[i];
  vector<ll>aa(n+1);
  aa[0]=0;
  Rep(i,n+1)aa[i]=aa[i-1]+a[i-1];
  vector<ll>bb(m+1);
  bb[0]=0;
  Rep(i,m+1)bb[i]=bb[i-1]+b[i-1];
  ll ans=0;
  ll sum=0;
  ll j=m;
  for(ll i=0;i<=n;i++){
      sum=aa[i];
      if(k<sum)break;
      while(k<sum+bb[m]){
          m--;
      }
      ans=max(ans,i+m);
  }
  cout<<ans<<endl;
}
 


 

 




Measured memory_bytes: 9592
fun main(args:Array<String>) {
  val ba = readLine()!!.split(" ").map(String::toInt).toMutableList()
  val m = readLine()!!.toInt()
  val max = ba.max()!!
  val index = ba.mapIndexed { i,x ->
    if ( max == x )
      i
    else
      null
  }.filter { it != null }[0]!!
  val fold = (1..m).fold(max) { y, x -> 
    y * 2
  }
  ba[ index ] = fold
  ba.sum().let(::println)
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int num;
int H, W;

int main() {
	cin >> H >> W;
	rep(i, H) {
		string s;
		cin >> s;
		rep(j, W) num += (s[j] == '#');
	}
	puts(num == H+W-1 ? "Possible" : "Impossible");
	return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    auto I = iota(N).array;
    zip(A, I).sort();
    auto tmp = new long[](2 * 10 ^^ 5 + 1);
    long i;
    long sum;
    while (i < N)
    {
        long j = i;
        while (A[i] == A[j])
            j++;
        long x = j - i;
        tmp[A[i]] = x;
        long y = x * (x - 1) / 2;
        sum += y;
        i = j;
    }
    auto ans = new long[](N);
    foreach (j; 0 .. N)
    {
        ans[I[j]] = sum - (tmp[A[j]] * (tmp[A[j]] - 1) / 2) + ((tmp[A[j]] - 1) * (tmp[A[j]] - 2) / 2);
    }
    foreach (a; ans)
        writeln(a);
}


Measured memory_bytes: 17936
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int n,k;std::cin>>n>>k;
    int ans=0;
    for(int i=0;i<n;i++){
        int x;std::cin>>x;
        ans+=2*std::min(x,k-x);
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=(a); i<(b); i++)
typedef unsigned long long ll;
using namespace std;

int main(){
	int a,b,c;
	string s;
	cin>>a>>b>>c;
	if (a==b && b==c)
		s="No";
	else if (a==b || b==c || a==c)
		s="Yes";
	else
		s="No";
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>

using namespace std;

long long N,a,b;
long long A;
long long B;
long long C[200001] = {};
long long result=0;
string S,SN,bufS;
vector <long long>vl;
vector <long> v;
//typedef pair<long long, long long> pl;



int main() {

	cin >>N;

	for (int i = 0; i < N; i++) {
		cin >> C[i];
		v.push_back(C[i]);
	}

	sort(v.begin(), v.end());
	A = v[N-1];
	if (A % 2 == 0) {
		a = A/2;
		b = a + 1;
	}
	else {
		a = A / 2 + 1;
	}
	cout << A << endl;

	for (int i = 0; i < N; i++) {
		if (A / 2 <= v[i]) {
			if (i == 0) {
				B = v[0];
				break;
			}
			else if (v[i-1]==0) {
				if (v[i] == A) {
					B = 0;
				}
				else {
					B = v[i];
				}
				break;
			}
			else if(A % 2 == 0){
				if (a-v[i-1]<v[i]-b) {
					B = v[i-1];
				}
				else {
					B = v[i];
				}
				break;
			}
			else {
				if (a - v[i-1]<v[i] - a) {
					B = v[i-1];
				}
				else {
					B = v[i];
				}
				break;
			}

		}
		else if(i==N-1){
			B = v[i];
		}
	}

	cout << B << endl;

return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;

  if(a==b && b==c) cout << 1 << endl;
  else if(a==b || b==c || a==c) cout << 2 << endl;
  else cout << 3 << endl;
}

Measured memory_bytes: 256