akhauriyash/Code-Regression huggingface dataset:
/*author : Yashvardhan
Saturday, January 12, 2019
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define int ll
#define pb push_back
#define make_pair mp
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pi>
#define ff first
#define ss second

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
	for (int i = 0; i < v.size(); ++i)
		os << v[i] << " ";
	return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v)
{
	for (auto it : v)
		os << it << " ";
	return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v)
{
	os << v.ff << " " << v.ss;
	return os;
}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int dp[100005][3];
int vals[100005][3];


int solve(int i,int j){
	if(dp[i][j] != -1) return dp[i][j];
	if(i == 1){
		dp[i][j] = vals[i][j];
		return dp[i][j];
	}
	else{
		if (j == 0)
		{
			dp[i][j] = max(solve(i-1,1),solve(i-1,2));
		}
		else if (j == 1)
		{
			dp[i][j] = max(solve(i - 1, 0), solve(i - 1, 2));
		}
		else
		{
			dp[i][j] = max(solve(i - 1, 1), solve(i - 1, 0));
		}
		dp[i][j] += vals[i][j];
		return dp[i][j];
	}
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#ifdef __APPLE__
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif

	time_t t1, t2;
	t1 = clock();

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		vals[i][0] = a;
		vals[i][1] = b;
		vals[i][2] = c;

		for(int j = 0;j<3;j++) dp[i][j] = -1;
	}
	
	int maxi = max(solve(n,0),solve(n,1));
	maxi = max(maxi, solve(n,2));

	cout << maxi << endl;

	t2 = clock();
	cerr << endl
		 << t2 - t1 << endl;

	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if(a % 2 == 1 && (i+1)%2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <queue>
#include <iomanip>
#include <iterator>

#define MOD 1000000007
#define INF 1000000001

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int main(int argc, char const *argv[]) {
    int N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N), z(N);
    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i] >> z[i];
    }

    vector<int> idxs(N);
    for (int i = 0; i < N; ++i) {
        idxs[i] = i;
    }

    ll ans = 0;
    for (int s = 0; s < 8; ++s) {
        int sx = ((s >> 0) & 1) * 2 - 1;
        int sy = ((s >> 1) & 1) * 2 - 1;
        int sz = ((s >> 2) & 1) * 2 - 1;
        sort(idxs.begin(), idxs.end(), [&](int a, int b) {
            return x[a]*sx + y[a]*sy + z[a]*sz > x[b]*sx + y[b]*sy + z[b]*sz;
        });
        ll sum = 0;
        for (int i = 0; i < M; ++i) {
            sum += x[idxs[i]]*sx + y[idxs[i]]*sy + z[idxs[i]]*sz;
        }
        if (ans < sum) {
            ans = sum;
        }
        // print(s, sx, sy, sz, sum);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
N = int(input())
res = (N * (N + 1)) / 2
three = ( (3 + 3 * (N // 3)) * (N // 3) )/ 2
five =  ( (5 + 5 * (N // 5)) * (N // 5) )/ 2
threefive =  ( (15 + 15 * (N // 15)) * (N // 15) )/ 2
print(int(res - three - five + threefive))

Measured memory_bytes: 61984
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

int N, a[200000];

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> a[j];
    }

    int b[200000];

    int li = 0, ri = N-1;
    for (int j = 0; j < N; ++j) {
        if (j % 2 == 0) {
            b[li] = a[N-1-j];
            li++;
        } else {
            b[ri] = a[N-1-j];
            ri--;
        }
    }

    for (int j = 0; j < N; ++j) {
        if (j > 0) cout << ' ';
        cout << b[j];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3712
// 154 C

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

using namespace std;

int main(){
    long long int n, m;
    cin >> n >> m;
    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i<(b); ++i)
#define rep(i, n) for (int i=0; i<(n); ++i)
#define out(x) cout << x << endl

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, N) cin >> A.at(i);
    int sumA = accumulate(A.begin(), A.end(), 0);
    int count=0;
    double th=(double)sumA/(4*M);
    for (int i : A) {
        if (i >= th) count++;
    }
    if (M <= count) out("Yes");
    else out("No");
}


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

#define ll                 long long
#define lcm(a,b)           (a*b)/__gcd(a,b) 
#define pb                 push_back
#define vecll              vector<ll>
#define F                  first
#define S                  second
#define all(v)             v.begin(),v.end()
#define mp(a,b)            make_pair(a,b)
#define MOD                1000000007
#define forn(i,n)          for(ll i=0;i<n;i++)
#define fori(i,a,n)        for(int i=a; i<n; i++)
using namespace std;
int n;
ll gcd(ll a,ll b)
{
  if(b==0)
    return a;
  else
    return gcd(b,a%b);
}
void solve()
{
  int n,k;
  cin>>n>>k;
  int arr[n]={0},a;
  for(int i=0;i<k;i++)
  {
    cin>>a;
    for(int j=0;j<a;j++)
    {
      int b;
      cin>>b;
      arr[b-1]++;
    }
  }
  int c=0;
  for(int i=0;i<n;i++)
  {
    if(arr[i]==0)
    {
      c++;
    }
  }
  cout<<c<<endl;
  return;
}
int main()
{
  int t;
  // cin>>t;
  t=1;
  while(t--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3620
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n= sc.nextInt();
        Integer a[] = new Integer[n];
        for (int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        
        int ans = 0;
        for(int i=0; i<n-2; i++){
            for(int j=i+1; j<n-1; j++){
                for(int k=j+1; k<n; k++){
                    if (a[k]<a[i]+a[j]){
                        ans++;
                    } else {
                        break;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 27880
N, X, Y = map(int,input().split()) #n:頂点数　w:辺の数
X -= 1
Y -= 1

ds = [0] * N
for i in range(N):
    for j in range(i+1, N):
        d = int(1e9)
        d = min(d, j - i)
        d = min(d, abs(i - X) + abs(j - Y) + 1)
        d = min(d, abs(i - Y) + abs(j - X) + 1)
        ds[d] += 1

for i in range(1, N):
    print(ds[i])
        
        

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

using namespace std;

const int maxn = 1e5 + 5;
char s[maxn][3];
int a[3], n;

signed main() {
  // freopen("in", "r", stdin);
  scanf("%d%d%d%d", &n, &a[0], &a[1], &a[2]);
  for(int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  vector<char> ans;
  bool flag = true;
  for(int i = 0; i < n; i++) {
    int ta = s[i][0] - 'A', tb = s[i][1] - 'A';
    if(a[ta] > a[tb]) {
      ans.push_back(s[i][1]);
      a[tb]++, a[ta]--;
    }else if(a[tb] > a[ta]){
      ans.push_back(s[i][0]);
      a[ta]++, a[tb]--;
    }else {
      if(a[ta] == 0) {
        flag = false;
        break;
      }
      if(i + 1 >= n || s[i][0] == s[i + 1][0] || s[i][0] == s[i + 1][1]) {
        ans.push_back(s[i][0]);
        a[ta]++, a[tb]--;
      }else {
        ans.push_back(s[i][1]);
        a[tb]++, a[ta]--;
      }
    }
  }
  if(flag) {
    printf("Yes\n");
    for(int i = 0; i < n; i++) {
      printf("%c\n", ans[i]);
    }
  }else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 4176
#include<stdio.h>
#include<string.h>
#include<stdbool.h>

void swap(int *a,int *b){
    int tmp;
    tmp=*a;
    *a=*b;
    *b=tmp;
}

void Bsort(int data[], int size) {
	int i, j;
    for(i=0;i<size-1;i++){
        for(j=0;j<size-1;j++){
            if(data[j]>data[j+1]){
                swap(&data[j],&data[j+1]);
            }
        }
    }
}

int main(void){
    int n;
    char st[4];
    scanf("%s",st);
    for(int n=0;n<4;n++){
        if(st[n]==55){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
}


Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int a, b, i, j;
	vector<string> s(100);
	cin >> a >> b;
	cout << "100 100\n";
	for (i = 0; i < 100; i++) {
		s[0] += "#";
		s[50] += ".";
	}
	for (i = 1; i < 50; i++)
		s[i] = s[0];
	for (i = 51; i < 100; i++)
		s[i] = s[50];
	j = 0;
	while (a > 1) {
		for (i = 0; i < 100 && a > 1; i += 2) {
			a--;
			s[j][i] = '.';
		}
		j += 2;
	}
	j = 99;
	while (b > 1) {
		for (i = 0; i < 100 && b > 1; i += 2) {
			b--;
			s[j][i] = '#';
		}
		j -= 2;
	}
	for (i = 0; i < 100; i++)
		cout << s[i] << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();

    int[] a = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
    }

    Arrays.sort(a);

    List<Integer> edges = new ArrayList<>();
    int c = 1;
    int prev = 0;
    for (int i = 0; i < N; i++) {
      if (a[i] == prev) {
        c++;
      } else {
        c = 1;
      }
      if (c > 1) {
        edges.add(a[i]);
        c = 0;
      }
      prev = a[i];
    }

    Collections.sort(edges);
    Collections.reverse(edges);

    if (edges.size() > 1) {
      System.out.println((long) edges.get(0) * edges.get(1));
    } else {
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 50196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  int c = (a + b) / 2;
  int d = a - b;
  if(d % 2 == 0){
    cout << c << "\n";
    return 0;
  }
  cout << c + 1 << "\n";
}

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

int main(){
  int a[3], ans = 0;
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  ans = a[2] - a[1];
  a[1] = a[2];
  a[0] += ans;
  if ( (a[2] - a[0]) % 2 == 0 ){
    ans += (a[2] - a[0]) / 2;
  } else {
    ans += (a[2] - a[0]) / 2 + 2;
  }

  cout << ans << endl;

  return 0;
}

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

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};

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

int main() {
  int N = 0;
  cin >> N;
  vector<string> po;
  rep(i, N) {
    string a;
    cin >> a;
    bool b = true;
    for (int i = 0; i < po.size(); i++) {
      if (po[i] == a) {
        b = false;
      }
    }
    if (b) {
      po.push_back(a);
    }
    if (po.size() == 4) {
      break;
    }
  }
  if (po.size() == 4) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }

  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);
		while(sc.hasNext()){
			int a=sc.nextInt();
			int b=sc.nextInt();
			int c=a+b;
			int count=0;
			while(0<c){
				c/=10;
				count++;
			}
			System.out.println(count);
		}
	}
}

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

using namespace std;

int main() {
    int N,D;
    cin>>N>>D;
    int ans=0;
    for(int i=1;i<N+1;i+=2*D+1){
        ans++;
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main(void){
    int n,box,s1=0,s2=0;
    cin >> n;
    vector<int> w;
    for(int i=0;i<n;i++){
        cin >> box;
        w.push_back(box);
        s2 += box;
    }
    int delta = s2;
    for(int i=0;i<n;i++){
        s1 += w[i];
        s2 -= w[i];
        if(abs(s2-s1) < abs(delta))delta = abs(s2-s1);
    }
    cout << delta << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL  long long
#define INF 0x7FFFFFFF
#define mod 1000000007
using namespace std;
 
int dp[100000 + 5];
int vis[100000 + 5];
int main(){
	int n, nu, m;
	cin >> n >> m;
	memset(vis, 0, sizeof vis);
	for(int i = 0; i < m; ++i){
		cin >> nu;
		vis[nu] = 1;
	}
	dp[0] = 1;
	dp[1] = !vis[1];
	for(int i = 2; i <= n; ++i){
		if(vis[i]){
			dp[i] = 0;
		}
		else{
			dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1024
use std::io;
use std::io::prelude::*;

fn main () {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let mut x: Vec<i32> = (0..m).map(|_| iter.next().unwrap().parse().unwrap()).collect();

    x.sort();
    let mut d: Vec<i32> = (0..(m-1)).map(|i| x[i+1] - x[i]).collect();
    d.sort();
    println!("{}", d.iter().rev().skip(n-1).sum::<i32>());
}


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

vector<vector<int>> G;
int K;
map<pair<int, int>, int> mp;
vector<int> col;

void dfs( int a, int p )
{
	int c = 1;
	for( int b : G[a] ) {
		if( b == p ) continue;
		if( c == col[a] ) c++;
		col[b] = c;
		mp[make_pair( a, b )] = c;
		mp[make_pair( b, a )] = c;
		K = max( K, c );
		c++;
		dfs( b, a );
	}
}

int main()
{
	int N;
	cin >> N;
	G = vector<vector<int>>( N );
	vector<pair<int, int>> e( N - 1 );
	col = vector<int>( N );
	for( int i = 0; i < N - 1; i++ ) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back( b );
		G[b].push_back( a );
		e[i] = make_pair( a, b );
	}

	dfs( 0, -1 );

	cout << K << endl;
	for( int i = 0; i < N - 1; i++ ) {
		cout << mp[ e[i] ] << endl;
	}
}


Measured memory_bytes: 19712
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int l,a,b,c,d;
	scanf("%d%d%d%d%d",&l,&a,&b,&c,&d);
	
	int x=0,y=0;
	
	x = (a%c == 0) ? a/c : a/c+1;
	y = (b%d == 0) ? b/d : b/d+1;
	
	//printf("%d %d\n",x,y);
	
	int z;
	z = max(x,y);
	
	printf("%d\n",l - z);

	return 0;
}
	

Measured memory_bytes: 1024
#include <stdio.h>

int main(){

  int n,a,ans=0,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){

    scanf("%d",&a);

    for(j=2;j*j<=a;j++) if(a%j==0) goto loop;
    ans++;

  loop:;

  }

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

  return 0;

}



Measured memory_bytes: 2124
n = input()
l = map(int, raw_input().split())

lastPos, lastNeg = l[0], l[0]
countPos, countNeg = 0, 0

if(lastPos<=0):
    countPos = 1 - lastPos
    lastPos = 1
if(lastNeg>=0):
    countNeg = lastNeg+1
    lastNeg = -1

for i in xrange(1,n):
    if(lastPos>0):
        #now it has to be negative
        if(lastPos+l[i] >= 0):
            diff = lastPos+l[i] + 1
            countPos+=diff
            lastPos = -1
        else:
            lastPos = lastPos + l[i]
    else:
        #now it has to be positive
        if(lastPos+l[i] <= 0):
            diff = 1 - (lastPos+l[i])
            countPos+=diff
            lastPos = 1
        else:
            lastPos = lastPos+l[i]
    
    if(lastNeg<0):
        #now it has to be positive
        if(lastNeg+l[i] <= 0):
            diff = 1 - (lastNeg+l[i])
            countNeg+= diff
            lastNeg = 1
        else:
            lastNeg = lastNeg + l[i]
    else:
        #now it has to be negative
        if(lastNeg+l[i] >= 0):
            diff = lastNeg+l[i]+1
            countNeg+= diff
            lastNeg = -1
        else:
            lastNeg = lastNeg + l[i]

print min(countPos, countNeg)

Measured memory_bytes: 11272
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
 
const int N = 2e6 + 6;
const int M = 1e9+7;
int A[N];
int n , k;

bool check(int x)
{
	int op = 0;	

	loop(i,0,n)
	{
		if(A[i] < x)continue;
		int rt = (A[i]/x);
		if(A[i]%x)rt++;
		op += (rt-1);
	}

	return op <= k;
}

void solve()
{
	cin >> n >> k;

	int mx = 0;

	loop(i,0,n)cin >> A[i];

	int st = 1  , en = 1e10;

	int ans = 0;

	while(st <= en)
	{
		int mid = (st+en)/2;
		if(check(mid))
		{
			ans = mid;
			en = mid-1;
		}
		else st = mid+1;
	}

	cout << ans;
}			
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 5128
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, r);

  cout << r * r << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

using namespace std;

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

    double P = 0.0;
    for(int i=1;i<=N;i++){
        double p = 1.0 / N;
        int s = i;
        while(s < K){
            s *= 2;
            p /= 2.0;
        }
        P += p;
    }

    cout << setprecision(12) << P << endl;
}

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

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

  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  for (int i = 0; i < n - 2; i++) {
    cnt += (s.substr(i, 3) == "ABC");
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    int t=0;
    for(char x:s){
        if(x=='C'){
            t+=1;
        }
        if(x=='F' && t>0){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


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

#define DEBUG

#ifdef DEBUG
#define dump(x) cout << "[*] " #x ": " << x << endl
#define debug(x) x
#else
#define dump(x)
#define debug(x)
#endif

//#define int long long
typedef long long ll;
//constexpr int INF = 1e9;
//constexpr int MOD = 1000000007;

decltype(1) main()
{
    //cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

const int N = 200010;

int n, k;
int a[N], cont[N];
int ql = 1, qr = 0;
int q[N], c[N];
int ql2 = 1, qr2 = 0;
int q2[N], c2[N];

int main() {
  scanf("%d%d", &n, &k);
  int ans = 1;
  bool flag = false;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    cont[i] = 1;
    if (i > 1 && a[i] > a[i - 1])
      cont[i] += cont[i - 1];
    if (i > k) {
      int cmax = q2[ql2], cmin = q[ql];
      bool good = true;
      if (cont[i] >= k) {
        if (flag)
          good = false;
        flag = true;
      }
      if (a[i] > cmax && a[i - k] < cmin)
        good = false;
      ans += good;
    }
    int cur = 1;
    while (ql <= qr && a[i] < q[qr])
      cur += c[qr--];
    ++qr;
    c[qr] = cur; q[qr] = a[i];
    cur = 1;
    while (ql2 <= qr2 && a[i] > q2[qr2])
      cur += c2[qr2--];
    ++qr2;
    c2[qr2] = cur; q2[qr2] = a[i];
    if (i >= k) {
      if (--c[ql] == 0) ++ql;
      if (--c2[ql2] == 0) ++ql2;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
bool check[4][4];
int ban[20][5];
int H;
bool flag;
int score;

/*
bool calc() {
  int start, end;
  bool flag = false;
  for(int i = 0; i < H; i++) {
    int len = 1;
    int prev = 0;
    int digit = 0;
    for(int j = 0; j < 5; j++) {
      if(prev == ban[i][j] && ban[i][j] != 0){
        if(len == 3) {
          start = j - 3;
          digit = ban[i][j];
        }
        len++;

      }else {
        if(len >= 3) end = j - 1;
        prev = ban[i][j];
        len = 1;
      }
    }
    if(prev == ban[i][4] && len >= 3){
      end = 4;
    }
    cout << digit << endl;
    if(digit != 0){
      flag = true;
      for(int j = 0; j < 5; j++) {
        if(j >= start && j <= end) ban[i][j] = 0;
      }
      score += (end - start + 1) * digit;
    }
  }
  return flag;
}
*/

  
bool calc()
{
  bool flag = false;
  for ( int i = 0; i < H; ++i ) {
    bool h[4][4] = {false};
    for ( int j = 0;j < 4; ++j ) {
      h[0][j] = (ban[i][j] != 0) &&(ban[i][j] == ban[i][j + 1]);
    }

    for ( int j = 1; j < 4; ++j ) {
      for ( int k = 0; k < 4 - j; ++k ) {
        h[j][k] = h[j - 1][k] && (h[j - 1][k] == h[j - 1][k + 1]);
      }
    }

    for ( int j = 3;j >=1; --j ) {
      for ( int k = 0; k < 4 - j; ++k ) {
        if ( h[j][k] == true )
          {
            for ( int l = 0; l < j + 2; ++l ) {
              score += ban[i][l + k];
              ban[i][l + k] = 0;
            }
            flag = true;
            goto END;
          }
      }
    }
  END:;

  }
  return flag;
}



void koushin() {
  queue<int> que;
  for(int i = 0; i < 5; i++) {
    for(int j = H - 1; j >= 0; j--) {
      if(ban[j][i] == 0) continue;
      que.push(ban[j][i]);
    }
    
    for(int j = H - 1; j >= 0; j--) {
      if(que.empty()) ban[j][i] = 0;
      else {
        ban[j][i] = que.front(); que.pop();
      }
    }
  }
}

void printban() {
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < 5 ;j++) {
      cout << " " << ban[i][j];
    }
    cout << endl;
  }
  cout << endl;
}

int main() {
  while(cin >> H && H != 0) {
    score = 0;
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < 5; j++) {
        cin >> ban[i][j];
      }
    }
    while(true) { 
      if(calc() == false){
        // printban();
        break;
      }
      else {
        koushin();
        // printban();
      }
    }
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < 5; j++) {
        ban[i][j] = 0;
      }
    }
    
    cout << score << endl;
  }
}

Measured memory_bytes: 3100
#include<stdio.h>

int main(void){
  int a,b,c,d;

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

  a+=b;
  c+=d;

  if(a>c)
    printf("Left\n");
  else if(a<c)
    printf("Right\n");
  else
    printf("Balanced\n");

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
	int r=0,l,k[100]={0},b=0,c=0,i,x[100]={0},j,math[100][100];
	cin>>r>>c;
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			cin>>math[i][j];
			x[i]+=math[i][j];
			k[j]+=math[i][j];
			b+=math[i][j];
		}
	}
	
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			cout<<math[i][j]<<" ";
		}
		cout<<x[i];
		cout<<endl;
	}
	for(l=0;l<c;l++){
	cout<<k[l]<<" ";
	}
	cout<<b;
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>
int main(void){
    // Here your code !
    int P,N,i,sum=0;
    int max=0,min=1000;
    while(1){
        sum=0;max=0;min=1000;
        scanf("%d",&N);
        if(N==0)break;
        for(i=0;i<N;i++){
            scanf("%d",&P);
            if(P>max)max=P;
            if(P<min)min=P;
            sum+=P;
        }
        printf("%d\n",(sum-max-min)/(N-2));
    }
    return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
namespace _6_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int cards = int.Parse(Console.ReadLine());
            List<int> supeedo = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
            List<int> heart = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
            List<int> club = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
            List<int> daiya = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
            for (int a = 0; a < cards; a++)
            {
                string[] s = Console.ReadLine().Split();
                int sa = int.Parse(s[1]);
                if (s[0] == "S") { supeedo.Remove(sa); }
                else if (s[0] == "H") { heart.Remove(sa); }
                else if (s[0] == "C") { club.Remove(sa); }
                else if (s[0] == "D") { daiya.Remove(sa); }
            }
            for(int i = 0; i < supeedo.Count; i++)
            {
                Console.WriteLine("S "+supeedo[i]);
            }
            for (int i = 0; i < heart.Count; i++)
            {
                Console.WriteLine("H " + heart[i]);
            }
            for (int i = 0; i < club.Count; i++)
            {
                Console.WriteLine("C " +club[i]);
            }
            for (int i = 0; i <daiya.Count; i++)
            {
                Console.WriteLine("D " + daiya[i]);
            }
        }
    }
}

Measured memory_bytes: 9580
n = int(input())
a = list( map(int,input().split()) )
b = list( map(int,input().split()) )

left = 0
for i in range(n):
  x = a[i] - b[i]
  if x >= 0:
    left += b[i]
    b[i] = 0
    continue
  else:
    left += min( a[i]+a[i+1] , b[i] )
    a[i+1] = max( 0, a[i]+a[i+1]-b[i])

print(left)


Measured memory_bytes: 18476
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  ll k;
  cin >> k;
  vector<int> A(n+1);
  for (int i = 1; i <= n; ++i) {
    int a;
    cin >> a;
    A[i] = a;
  }
  if (k > n) {
    int tort = A[1], hare = A[A[1]];
    while (tort != hare) {
      tort = A[tort];
      hare = A[A[hare]];
    }
    tort = 1;
    int start = 1;
    while (tort != hare) {
      tort = A[tort];
      hare = A[hare];
      start++;
    }
    int next = A[tort];
    int len = 1;
    while (tort != next) {
      len++;
      next = A[next];
    }
    int ret = 1;
    for(int i = 1; i <= start; i++) {
      ret = A[ret];
    }
    for(int i = 1; i <= ((k-start) % len); i++) {
      ret = A[ret];
    }
    cout << ret << endl;
  } else {
    int ret = 1;
    for(int i = 1; i <= k; i++) {
      ret = A[ret];
    }
    cout << ret << endl;
  }
  return 0;
}


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


/*
*/

int main() {
  int N;
  cin >> N;
  vector<vector<int>> a(N, vector<int>(3));
  for(int i = 0;i<N;i++){
    for(int j = 0;j<3;j++){
      cin >> a[i][j];
    }
  }
  vector<vector<ll>> dp(N+3, vector<ll>(3));
  for(int i = 0;i<N;i++){
   for(int k = 0;k<3;k++){
     //int res = 0;
     for(int j = 0;j<3;j++){
     if(j != k) {
       //res = max(dp[i][k] + a[i][j],res);
       dp[i+1][k] = max(dp[i][j] + a[i][k],dp[i+1][k]);
     }
    }
    
   }
  }
  cout << max(dp[N][0],max(dp[N][1],dp[N][2]));
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, ans = 100000; cin >> n;
	vector<int> w(n);
	vector<int> sum(n);
	cin >> w[0];
	sum[0] = w[0];
	rep(i, 1, n - 1)
	{
		cin >> w[i];
		sum[i] = sum[i - 1] + w[i];
	}
	rep(i, 0, n - 1)
	{
		ans = min(ans, abs(sum[n - 1] - 2 * sum[i]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		//キーボード入力メソッド
		Scanner sc = new Scanner(System.in);

		//入力
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		//処理
		int max_W = W - r;
		int max_H = H - r;
		if(r <= x && x <= max_W && r <= y && y <= max_H) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}



Measured memory_bytes: 26344
from collections import defaultdict


def check():
    N,M = map(int, input().split())
    B = []
    hune = defaultdict(list)
    for _ in range(M):
        a,b = map(int, input().split())
        if a == 1:
            B.append(b)
        hune[a].append(b)
    
    for b in B:
        for goal in hune[b]:
            if goal == N:
                print('POSSIBLE')
                return
    print('IMPOSSIBLE ')
    
check()

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

int main(void){
    int i;
    char S[1200];

    scanf("%[^\n]%*c",S);

    for(i=0;i<strlen(S);i++){
        if(S[i]>64&&S[i]<122){
            if(S[i]<97) S[i]=S[i]+32;
            else S[i]=S[i]-32;
        }
    }

    printf("%s\n",S);

    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int main() {
    int n,k;
    cin>>n>>k;
    ll a[n];
    rep(i,n)cin>>a[i];
    ll ans=INF;

    for (int i=1;i<(1<<n);i++){
        bitset<15> s(i);
        if (s.count()!=k)continue;
        ll ans1=0;
        ll now=0;
        rep(i,n){
            if (s.test(i)){
                if (now<a[i])now=a[i];
                else{
                    now=now+1;
                    ans1+=now-a[i];
                }
            }
            else{
                now=max(now,a[i]);
            }
            
        }
        ans=min(ans,ans1);

    }
    cout<<ans<<endl;


    return 0;
}

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

ll w[101010], b[101010];

int main() {
    int N, P;
    cin >> N >> P;
    vector<pair<ll, int>> wb(N);

    double blue = 0;
    rep(i, N) {
        cin >> w[i] >> b[i];
        wb[i] = {w[i] * (100 - P) + b[i] * P, i};
        blue += -b[i] * P;
    }

    sort(wb.rbegin(), wb.rend());

    rep(i, N) {
        blue += wb[i].first;
        if (blue >= 0) {
            cout << i+1 << endl;
            break;
        }
    }

    return 0;

}


Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	static int n = 26, d;
	static int[] c;
	static int[][] s;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		d = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = Integer.parseInt(sa[i]);
		}
		s = new int[d][n];
		for (int i = 0; i < d; i++) {
			sa = br.readLine().split(" ");
			for (int j = 0; j < n; j++) {
				s[i][j] = Integer.parseInt(sa[j]);
			}
		}
//		int[] t = inputB(br);
		br.close();

		int[] t = new int[d];
		int[] last = new int[n];
		for (int i = 0; i < d; i++) {
			int max = -1;
			int idx = -1;
			for (int j = 0; j < n; j++) {
				int val = s[i][j] + c[j] * (i + 1 - last[j]);
				if (val > max) {
					max = val;
					idx = j;
				}
			}
			t[i] = idx;
		}

		for (int i = 0; i < d; i++) {
			int max = Integer.MIN_VALUE;
			int idx = t[i];
			for (int j = 0; j < n; j++) {
				t[i] = j;
				int val = calc(t, i);
				if (val > max) {
					max = val;
					idx = j;
				}
			}
			t[i] = idx;
		}

		for (int i = 0; i < d; i++) {
			System.out.println(t[i] + 1);
		}
//		System.out.println(calc(t, d - 1));
	}

	static int calc(int[] t, int end) {
		int[] last = new int[n];
		int ret = 0;
		for (int i = 0; i <= end; i++) {
			ret += s[i][t[i]];
			last[t[i]] = i + 1;
			for (int j = 0; j < n; j++) {
				ret -= c[j] * (i + 1 - last[j]);
			}
		}
		return ret;
	}

//	static int[] inputB(BufferedReader br) throws Exception {
//		int[] t = new int[d];
//		for (int i = 0; i < d; i++) {
//			t[i] = Integer.parseInt(br.readLine()) - 1;
//		}
//		return t;
//	}

//	static int[] calc(int[] t, int end) {
//		int[] last = new int[n];
//		int[] ret = new int[end];
//		for (int i = 0; i < end; i++) {
//			if (i > 0) {
//				ret[i] += ret[i - 1];
//			}
//			ret[i] += s[i][t[i]];
//			last[t[i]] = i + 1;
//			for (int j = 0; j < n; j++) {
//				ret[i] -= c[j] * (i + 1 - last[j]);
//			}
//		}
//		return ret;
//	}
}


Measured memory_bytes: 37568
#include <bits/stdc++.h>
using namespace std;
int main(){
	int M, D; cin >> M >> D; 
	int count = 0; 
	for(int i = 1; i <= D; i++){
		int a = i / 10; int b = i % 10; 
		if(a > 1 && b > 1 && M >= a * b && a * b > 0) count ++; 
	}
	cout << count << endl; 
}

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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }

  int A, B;
  int half = 0;
  for (int i = 0; i < N; i++) {
    half += vec.at(i);
    if (half == sum - half) {
      cout << 0 << endl;
      return 0;
    }
    else if (half > sum - half) {
      A = half - (sum - half);
      B = (sum - (half - vec.at(i))) - (half - vec.at(i));
      break;
    }
  }

  if (abs(A) <= abs(B)) cout << A << endl;
  else cout << B << endl;
}

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

int main(void){
  int a, b, x; cin >> a >> b >> x;
  if(a > x) cout << "NO" << endl;
  else if(a + b < x) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;             
}


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

int main(){
  int n,ans=0,red=0;cin>>n;
  vector<bool> color(8,false);

  REP(i,n){
    int t;cin>>t;
    if(t<3200) color.at(t/400)=true;
    else red++;
  }
  REP(i,8){
    if(color.at(i)) ans++;
  }

  cout<<max(1,ans)<<" "<<ans+red;
}

Measured memory_bytes: 256
d=dict()
for i in range(10):
    if i==2 or i==4 or i==5 or i==7 or i==9:
        d[i]='hon'
    elif i==0 or i==1 or i==6 or i==8:
        d[i]='pon'
    else:
        d[i]='bon'
print(d[int(input())%10])

Measured memory_bytes: 61848
#include <stdio.h>

int main() {
	
	int K;
	int X;
			scanf("%d", &K);
				getchar();
			scanf("%d", &X);
				getchar();

	if (K * 500 >= X) {
			printf("Yes");
	}
	else {
			printf("No");
	}
	
	return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
#define lli long long int 
int main() {
	// your code goes here
	lli n,a;
	cin>>n;
	map<string,lli>mp;
	string s;
	while(n--)
	{
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
		cout<<"WA x "<<mp["WA"]<<endl;
			cout<<"TLE x "<<mp["TLE"]<<endl;
				cout<<"RE x "<<mp["RE"]<<endl;
	
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll a, b, q;
  cin >> a >> b >> q;
  vl s(a), t(b);
  rep(i, a) cin >> s[i];
  rep(i, b) cin >> t[i];
  sort(all(s));
  sort(all(t));
  rep(_, q) {
    ll x;
    cin >> x;
    vl u(2), v(2);
    u[0] = upper_bound(all(s), x) - s.begin() - 1;
    v[0] = upper_bound(all(t), x) - t.begin() - 1;
    u[1] = lower_bound(all(s), x) - s.begin();
    v[1] = lower_bound(all(t), x) - t.begin();
    ll ans = 1e18;
    rep(i, 2) rep(j, 2) {
      if(u[i] < 0 || v[j] < 0) continue;
      ll d1 = s[u[i]];
      ll d2 = t[v[j]];
      ll now;
      if(x <= d1 && x <= d2 || x > d1 && x > d2)
        now = max(abs(x - d1), abs(x - d2));
      else
        now = 2 * min(abs(x - d1), abs(x - d2)) + max(abs(x - d1), abs(x - d2));
      ans = min(ans, now);
    }
    cout << ans << '\n';
  }
}

Measured memory_bytes: 4780
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

L = str(input())
n = len(L)
dp = [[0,0] for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    if L[i] == "0": #a+b = 0
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = (dp[i][1] + dp[i][1]*2) % mod
    else:
        dp[i+1][0] = dp[i][0] * 2 % mod
        dp[i+1][1] = (dp[i][0] + dp[i][1] + dp[i][1]*2) % mod


print(sum(dp[n]) % mod)


Measured memory_bytes: 22028
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>


#define rep(i,n) for(int i=0; i< (n); ++i)

using namespace std;
int main()
{
  string S;
  cin >> S;

  for (int i = 0; i < (int)S.size(); ++i)
  {
    //奇数
    if (i % 2 == 0 && S[i] == 'L')
    {
      cout << "No" << endl;
      return 0;
    }
    //偶数
    else if (i % 2 != 0 && S[i] == 'R')
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}

int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m);
    vector<int> p(m);
    REP(i,m) {
        int k; cin >> k;
        REP(j,k) {
            int x; cin >> x;
            --x;
            s[i].push_back(x);
        }
    }
    REP(i,m) cin >> p[i];
    vector<int> b(n), c;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < s[i].size(); ++j) {
            b[s[i][j]]++;
        }
    }
    REP(i,n) if (b[i] == 0) c.push_back(i);
    ll ans = 0ll;

    for (ll bit = 0; bit < (1<<n); ++bit) {
        vector<int> l(m, 0);
        int tmp = 0;
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < s[i].size(); ++j) {
                if (bit & (1<<s[i][j])) {
                    l[i]++;
                }
            }
        }
        for (int k = 0; k < m; ++k) {
            if (l[k]%2 == p[k]) ++tmp;
        }
        if (tmp == m) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
int main(void){
    long long int N,A,B;
    scanf("%lld %lld %lld",&N,&A,&B);
    if(A==B)printf("1");
    else if(N==1)printf("0");
    else if(A>B)printf("0");
    else printf("%lld",(N-2)*(B-A)+1);
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	ll a, b, c , d;
	cin >> a >> b >> c >> d;
	OUT(max({a*c,b*d,a*d,b*c}));
    return 0;
}

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

using namespace std;

vector <int> base[2] = {{0, 1}, {1, 0}};

int ignore_bit(int x, int b) {
    int _left = x & ((1 << b) - 1);
    int _right = x >> (b + 1) << b;
    return _left + _right;
}
int add_bit(int x, int b) {
    int _left = x & ((1 << b) - 1);
    int _right = x >> b << (b + 1);
    return _left + _right;
}
int swap_bit(int x, int a, int b) {
    int r = x;
    if (x >> a & 1) r = r - (1 << a) + (1 << b);
    if (x >> b & 1) r = r - (1 << b) + (1 << a);
    return r;
}

vector <int> go(int n) {
    if (n == 1) return base[0];
    vector <int> v = go(n - 1), ret;
    for (int i = 0; i < v.size(); ++i) {
        if (i & 1) ret.push_back(v[i] * 2 + 1), ret.push_back(v[i] * 2);
        else ret.push_back(v[i] * 2), ret.push_back(v[i] * 2 + 1);
    }
    return ret;
}

vector <int> solve(int nbit, int s, int f) {
    if (nbit == 1) return base[s];
    int x = s ^ f;
    int b = log2(x & -x);
    if (__builtin_popcount(x) == 1) {
        vector <int> ret = go(nbit);
        for (auto &y: ret) y = swap_bit(y, nbit - 1, b) ^ s;
        return ret;
    }
    int xx = x ^ (1 << b);
    int c = log2(xx & -xx);
    int nx = ignore_bit(1 << c, b);
    vector <int> _left = solve(nbit - 1, 0, nx);
    for (auto &y: _left) y = add_bit(y, b);
    int nf = ignore_bit(x, b);
    vector <int> _right = solve(nbit - 1, nx, nf);
    for (auto &y: _right) y = add_bit(y, b) + (1 << b);
    vector <int> res = _left;
    for (auto y: _right) res.push_back(y);
    for (auto &y: res) y ^= s;
    return res;
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int n, a, b;
    cin >> n >> a >> b;
    int x = a ^ b;
    if (__builtin_popcount(x) % 2 == 0) return cout << "NO" << endl, 0;
    vector <int> ans = solve(n, a, b);
    cout << "YES" << endl;
    for (auto x: ans) cout << x << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 1644
import java.io.PrintWriter;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        if(1<=A&&A<=9&&1<=B&&B<=9){
          out.println(A*B);
        }
        else{
          out.println(-1);
        }
		
 
		out.flush();
	}
}

Measured memory_bytes: 22996