akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int num = sc.nextInt();//整数の数
		int n[] = new int[num];//配列

		//配列の格納
		for (int i = 0; i < n.length; i++) {
			int x = sc.nextInt();//格納する数字
			n[i] = x;

		}

		//逆順に出力
		for (int i = n.length - 1; i >= 0; i--) {

			if (i != 0) {
				System.out.print(n[i] + " ");
			} else {
				System.out.println(n[i]);
			}

		}
	}
}



Measured memory_bytes: 26296
import java.util.Scanner;
class Main{
  public static void main (String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int big = Math.max(a,b);
    int small = Math.min(a,b);
    String ans = "";
    for(int i=0;i<big;i++){
      ans += small;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21076
/*input 
7 4 2
3
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ld double
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e16;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int arr[3];
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    REP(i,mypow(3,k)){
        int z=i;
        
        arr[0]=a,arr[1]=b,arr[2]=c;
        REP(j,k){
            arr[z%3]*=2;
            z/=3;
        }
        if(arr[1]>arr[0] and arr[2]>arr[1]){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}


Measured memory_bytes: 3632
import numpy as np

n, d = map(int,input().split())
li = []
for i in range(n):
    li.append(list(map(int,input().split())))

li = np.array(li)
count = 0

for i in range(n-1):
    for j in range(i+1,n):
         x = np.linalg.norm(li[i]-li[j])
         if float.is_integer(x):
             count += 1

print(count)

Measured memory_bytes: 12504
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m = nm()
    a = nl()

    if sum(a) > n:
        print(-1)
    else:
        print(n - sum(a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 68336
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
LL v[maxn];

// edge
int cnt, h[maxn];
struct edge
{
    int to, pre;
} e[maxn<<1];
void add(int from, int to)
{
    cnt++;
    e[cnt].pre = h[from];
    e[cnt].to = to;
    h[from] = cnt;
}

int deg[maxn], ok;
LL dfs(int x, int f)
{
    if(deg[x] == 1) return v[x];
    LL ret = v[x] + v[x];
    for(int i = h[x]; i; i = e[i].pre)
    {
        int to = e[i].to;
        if(to == f) continue;
        LL tmp = dfs(to, x);
        if(tmp > v[x]) ok = 0;
        if(tmp > ret) ok = 0;
        ret -= tmp;
    }
    if(ret > v[x]) ok = 0;
    return ret;
}

int main(void)
{
    int N;
    scanf("%d", &N);
    for(int i = 1; i <= N; i++) scanf("%lld", v + i);
    for(int i = 1; i < N; i++)
    {
        int a, b;
        scanf("%d %d", &a, &b);
        add(a, b); add(b, a);
        deg[a]++; deg[b]++;
    }
    if(N == 2)
    {
        if(v[1] == v[2]) puts("YES");
        else puts("NO");
        return 0;
    }
    int rt = 0;
    for(int i = 1; i <= N; i++)
    if(deg[i] != 1) {rt = i; break;}
    ok = 1;
    if(dfs(rt, 0)) ok = 0;
    puts(ok ? "YES" : "NO");
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<ll> a(m);
  vector<ll> b(m);
  for (ll i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  ll ans = 0;
  for (ll i = 0; i < m; ++i) {
    vector<vector<ll>> g(n);
    for (ll j = 0; j < m; ++j) {
      if (i == j) continue;
      g[a[j]].push_back(b[j]);
      g[b[j]].push_back(a[j]);
    }

    function<void(ll, vector<bool>&)> solve;
    solve = [&](ll pos, vector<bool> &seen) {
      seen[pos] = true;

      each (v, g[pos]) {
        if (seen[v]) continue;
        solve(v, seen);
      }
    };

    vector<bool> seen(n);
    solve(0, seen);

    ll cnt = 0;
    for (ll i = 0; i < seen.size(); ++i) if (seen[i]) ++cnt;

    if (cnt == n) continue;
    ++ans;
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main()
{
    string s;
    long long n, k;
    cin >> n;
    while (n--)
    {
        k = n % 26 + 97;
        n /= 26;
        s += char (k);
    }
    reverse (s.begin(), s.end());
    cout << s;
    return 0;
}


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

using ll = long long;

const ll MAX = 1e+12;

ll GCD(ll a, ll b) {

    if(b > a)
        swap(a, b);

    ll c = a % b;
    while(c != 0) {

        a = b;
        b = c;
        c = a % b;
        
    }

    return b;

}

int main() {

    ll a, b;
    vector<ll> num;
    ll n;

    cin >> a >> b;

    n = GCD(a, b);

    for(ll i = 2; i * i <= n; ++i) {
        if(n % i != 0)
            continue;

        num.push_back(i);
        while(n % i == 0) {
            n /= i;

        }

    }
    if(n != 1)
        num.push_back(n);


    cout << num.size() + 1 << endl;

    return 0;



}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>
// #include "utiltime.hpp"

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef complex<double> cdouble;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define readfile(filename) ifstream in(filename); cin.rdbuf(in.rdbuf());
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
bool nearlyeq(double x, double y) { return abs(x - y) < 1e6; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(double x) { ll m = (ll)sqrt(x); return m + (m * m <= (ll)(x) ? 0 : -1); }
ll ceilsqrt(double x) { ll m = (ll)sqrt(x); return m + ((ll)x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }

/*******************************************************/

int main() {
	int n; cin >> n;
	int N = 1e5 + 3;
	vector<P> a(N), b(N);
	Loop(i, N) {
		a[i] = { 0, i };
		b[i] = { 0, i };
	}
	Loop(i, n / 2) {
		int x; cin >> x;
		a[x].first++;
		int y; cin >> y;
		b[y].first++;
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	ll ans = INT_MAX;
	Loop(i, N) {
		ll buf = n / 2 - a[i].first;
		if (b[N - 1].second == a[i].second) {
			buf += n / 2 - b[N - 2].first;
		}
		else {
			buf += n / 2 - b[N - 1].first;
		}
		ans = min(ans, buf);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;

int main(){
	char s[3];
    int count = 0;
    
    cin >> s;
    
    if(s[0] == '1'){
        count++;
    }
    if(s[1] == '1'){
        count++;
    }
    if(s[2] == '1'){
        count++;
    }
    
    cout << count;
    
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  
  int r[n][m];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      r[i][j]=0;
    }
  }
  
  int k;
  int a;
  for(int i=0;i<n;i++){
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>a;
      r[i][a-1]=1;
    }
  }
  
  int ans=0;
  int flag;
  for(int j=0;j<m;j++){
    flag=1;
    
    for(int i=0;i<n;i++){
      if(r[i][j]==0){
        flag=0;
        break;
      }
    }
    
    if(flag==1){
      ans++;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
  
struct P{
  int x,y;
  bool operator <(const P &a) const{
    return y<a.y;
  };
};
  
int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[4];
int l[3];
int j[3];


long long x,y,z,mod=1000000007;
string r[200101];
//char r[1];
vector<int> v[1],v1;
queue<int> q;
stack<int> s;
map<string,int> p;
P u[1];
  
bool as(P a,P b)
{
  if(a.x!=b.x)
  return a.x<b.x;
  return a.y<b.y;
}

int main()
{
  scanf("%d",&a);
  for(int t=1;t<=a;t++)
  cin>>r[t];
  sort(r+1,r+1+a);
  for(int t=1;t<=a;k=max(k,p[r[t]]),t++)
    p[r[t]]++;
  for(int t=1;t<=a;t++)
  if(p[r[t]]==k)
  {
    p[r[t]]=0;
    cout<<r[t]<<"\n";
  }
}


Measured memory_bytes: 26752
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] arr = line.split(" ");
        double a = Double.parseDouble(arr[0]);
        double b = Double.parseDouble(arr[1]);
        double C = Double.parseDouble(arr[2]);
 
        double h = b * Math.sin(Math.toRadians(C));
        double S = a * h / 2;
        double c2 = Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b
                * Math.cos(Math.toRadians(C));
        double c = Math.sqrt(c2);
 
        System.out.printf("%.5f %.5f %.5f%n", S, a + b + c, h);
 
        if (br != null) {
            br.close();
            br = null;
        }
    }
}

Measured memory_bytes: 17084
#include<bits/stdc++.h>
using namespace std;
int a[400005],n;
int small(int i,int j,int k)
{
	return a[j]<=k&&a[i]<=k;
}
int big(int i,int j,int k)
{
	return a[j]>k&&a[i]>k;
}
int check(int k)
{
	for(int i=0;i<=n-1;i++)
	{
		if(small(n+i,n+i+1,k)||small(n-i,n-i-1,k))
		{
			return 1;
		}
		if(big(n+i,n+i+1,k)||big(n-i,n-i-1,k))
		{
			return 0;
		}
	}
	return small(1,1,k);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n-1;i++)
	{
		scanf("%d",&a[i]);
	}
	int l=1,r=2*n-1;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(check(mid)==1)
		{
			r=mid;
		}else
		{
			l=mid+1;
		}
	}
	cout<<r;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>
#include <iomanip>
using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;
#define int ll

ll lcm(ll a,ll b){
    return a*b/__gcd(a,b);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b; cin >> a >> b;
    
    cout << lcm(a,b) << endl;
}

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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

string s;

int main()
{
  cin >> s;

  i64 res = 0, bc = 0;
  for (int i = s.length()-1; i >= 0; i--)
    if (s[i] == 'B') {
      res += s.length()-1-bc-i;
      bc++;
    }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	//C問題

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scan = new Scanner(System.in);

		int a1,a2,a3;

		a1 = scan.nextInt();
		a2 = scan.nextInt();
		a3 = scan.nextInt();

		if ( a1 + a2 + a3 >= 22) {
			System.out.println("bust");
		}else {
			System.out.println("win");
		}
	}

}

Measured memory_bytes: 21716
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
    int x[102] = {};
    int y[102] = {};
    long int sum;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> y[i];
    }

    //p=1
    sum = 0;
    for(int i = 0; i < n; i++) {
        sum += abs(x[i] - y[i]);        
    }
    printf("%.10lf\n", (double)sum);

    //p=2
    sum = 0;
    for(int i = 0; i < n; i++) {
        sum += (x[i] - y[i])*(x[i] - y[i]);        
    }
    printf("%.10lf\n", sqrt(sum));

    //p=3
    sum = 0;
    for(int i = 0; i < n; i++) {
        sum += abs(x[i] - y[i])*abs(x[i] - y[i])*abs(x[i] - y[i]);        
    }
    printf("%.10lf\n", pow(sum, 1.0/3.0));

    //p=inf
    sum = 0;
    int max = 0;
    for(int i = 0; i < n; i++) {
        if(max < abs(x[i]-y[i])) max = abs(x[i]-y[i]);
    }
    printf("%.10lf\n", (double)max);
    return 0;
}


Measured memory_bytes: 3348
import bisect

N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
A.sort()
B.sort()
C.sort()
# print(A)
# print(B)
# print(C)

ans=0
for j in range(N):
    a_num=bisect.bisect_left(A,B[j])
    c_num=bisect.bisect_right(C,B[j])
    # print(B[j],A[:a_num],C[c_num:])
    # print(a_num,c_num)
    ans+=a_num*(N-c_num)
print(ans)


Measured memory_bytes: 23232
#include <iostream>
#include <algorithm>
#include <map>

#define int long long

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

#define INF (3e9)

using namespace std;

int N;
int A[100003];

signed main()
{
    cin >> N;

    std::map<int, int> count;
    REP(i, N)
    {
        int a;
        cin >> a;
        if (count.find(a) != count.end())
        {
            count[a] = (count[a] + 1) % 2;
        }
        else
        {
            count[a] = 1;
        }
    }

    int ans = 0;
    for (auto c : count)
    {
        ans += c.second;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------


//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string n;cin>>n;
    if(n[0]==n[2])
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
#include <stdio.h>

#define abs(a) (a) > 0 ? (a) : (-(a))

int	main()
{
	long long X, K, D;
	long long ans;

	scanf("%lld", &X);
	X = abs(X);
	scanf("%lld", &K);
	scanf("%lld", &D);

	long long div;
	long long mod;
	div = X / D;
	mod = X % D;

	// 近づける数より原点が遠い
	if (div > K)
		ans = X - D * K;
	else
	{
		if ((K - div) % 2 == 0)
			ans = mod;
		else
			ans = D - mod;
	}
	printf("%lld\n", ans);
	return (0);
}


Measured memory_bytes: 1736
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
#include <list>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> vi;

bool checkset(vi &ub){
	REP(i, ub.size()){
		if(ub[i] > 1) return false;
	}
	return true;
}

int main(void) {
	int n;
	cin >> n;
	vector<ll> a(n);
	REP(i, n) cin >> a[i];
	ll ans = 0;
	int left = 0, right = -1;
	vi usebit(25, 0);
	while(right < n) {
		right++;
		ll x = a[right];
		for(int i = 0; i<= 20; i++) if((x >> i) & 1) usebit[i]++;
		if(right == n) break;
		while(!checkset(usebit)){
			ll x = a[left];
			for(int i = 0; i <= 20; i++){
				if((x >> i) & 1) usebit[i]--;
			}
			left++;
			if(right == left) break;
		}
		//cout << "left right" << " " << left << " " << right << endl;
		ans += (right - left);
	}
	cout << ans + n << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int w,h,i,j;
int ans=11;
int x,y;
int dp[21][21];
void dfs(int n,int i,int j){
  if(n>=ans){
    return;
  }
  int nx,ny;
  for(int k=-1;k<2;k++){
    for(int l=-1;l<2;l++){
      if(k!=0&&l!=0){
        continue;
      }
      if(k==0&&l==0){
        continue;
      }
      nx=i+k;
      ny=j+l;
      if(0>nx||nx>=h||0>ny||ny>=w){
        continue;
      }
      if(dp[nx][ny]==1){
        continue;
        }
  while(1){
    if(dp[nx][ny]==3){
      ans=n;
      return ;
    }
    nx+=k;
    ny+=l;
    if(nx<0||nx>=h||ny<0||ny>=w){
      break;
    }
    if(dp[nx][ny]==1){
        dp[nx][ny]=0;
        dfs(n+1,nx-k,ny-l);
        dp[nx][ny]=1;
        break;
        }
      }
    }
  }
}

int main(){
  while(1){
  cin>>w;
  cin>>h;
  if(w==0&&h==0){
    break;
  }
  ans=11;
  rep(i,h){
    rep(j,w){
      cin>>dp[i][j];
      if(dp[i][j]==2){
        x=i;
        y=j;
      }
    }
  }
  dfs(1,x,y);
  if(ans<11){
  cout<<ans<<endl;
} else {
  cout<<-1<<endl;
}
}
  return 0;
}



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

 
int main(){
   
    int a;
    cin>>a;
  int dp[a][3];
    cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
   
    for(int x=1; x<a; x++){
        int p,q,r;
        cin>>p>>q>>r;
     
        dp[x][0]=p+max(dp[x-1][1],dp[x-1][2]);
        dp[x][1]=q+max(dp[x-1][2],dp[x-1][0]);
        dp[x][2]=r+max(dp[x-1][0],dp[x-1][1]);
     

}
    
    cout<<max(dp[a-1][0],max(dp[a-1][1],dp[a-1][2]));
}
    
    


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

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var A = int.Parse(inputs[0]);
        var B = int.Parse(inputs[1]);

        string ans;
        if (A * B % 2 == 0)
        {
            ans = "No";
        }
        else
        {
            ans = "Yes";
        }

        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
const int N=2100;
int n,a[N],ht=0,hd[N];
struct edge{int v,n;}e[N*2];
void addedge(int u,int v){
    e[++ht]=(edge){v,hd[u]};
    hd[u]=ht;
}
int d[N],f[N],s[N],ans=1e9+10;
void dfs1(int u,int F){
    d[u]=0,s[u]=a[u];f[u]=0;
    for(int i=hd[u],v;i;i=e[i].n){
        v=e[i].v;if(v==F)continue;
        dfs1(v,u);s[u]+=s[v],d[u]+=d[v]+s[v];
    }
}
void dfs2(int u,int F){
    int mx=0;
    for(int i=hd[u];i;i=e[i].n){
        if(e[i].v==F) continue;
        if(!mx||d[mx]<d[e[i].v])
            mx=e[i].v;
    }
    if(!mx||d[u]>=2*(d[mx]+s[mx])) f[u]=d[u]/2;
    else {
        dfs2(mx,u);
        f[u]=(d[u]-d[mx]-s[mx])+min(f[mx],(d[mx]+s[mx])-(d[u]+1)/2);
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%1d",&a[i]);
    for(int i=1,u,v;i<n;i++){
        scanf("%d%d",&u,&v);
        addedge(u,v);addedge(v,u);
    }
    for(int i=1;i<=n;i++){
        dfs1(i,0);
        if(d[i]&1) continue;
        dfs2(i,0);
        if(d[i]==f[i]*2)
            ans=min(ans,f[i]);
    }
    if(ans>1e9) puts("-1");
    else printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 512
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      long A =sc.nextLong();
	  long B =sc.nextLong();
      
      long a = A;
      long b = B;
      long o = 0;
      
      if(A>B){
      while(b !=0){
      o = a%b;
      //次にb%oにしたいからa%bを更新していく
      //最後に余りが出なくなるまで割っていけばそれが最大公約数となる
      a = b;
      b = o;
      }
        //aはbに代入されて更新された状態であるため、aは実際割る側の数となっている
        //最小公倍数=入力された数(A*B)/最大公約数を出したさに最後に割った数(bの位置)
      System.out.println(A*B/a);   
      }
      
   if(B>A){
      while(a !=0){
       o = b%a;
        b = a;
        a = o;
      }
     System.out.print(A*B/b);
   }
  }
}

Measured memory_bytes: 23764
################AUTHOR:@electivire##############
###############CODECHEF TEMPLATE @PYTHON########

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians,gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, bisect_right
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
#import pandas as pd 
#import numpy as np 
import os
import datetime
import statistics
import platform 
import fractions
import decimal
# def input(): return sys.stdin.readline().strip()
# def INT(): return int(input())
# def MAP(): return map(int, input().split())
# def LIST(): return list(map(int, input().split()))
# def ZIP(n): return zip(*(MAP() for _ in range(n)))
#modd=10**9+7
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
# For getting input from input.txt file 
if __debug__ and platform.platform()=='Darwin-18.7.0-x86_64-i386-64bit':
	sys.stdin = open('input.txt', 'r')  
	  
	# Printing the Output to output.txt file 
	sys.stdout = open('out.txt', 'w') 

#--------------------MAIN FUNCTION STARTS----------------------
def main():
    s,w=map(int,input().split())
    if w>=s:
    	print("unsafe")
    else:print("safe")

if __name__ == '__main__':
    main()





















































Measured memory_bytes: 74060
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 直前要素との差から，自分スタートが何回かわかる
# その和が全試行回数と一致すれば可能

N = I()
A = LI()

red_once = (N+1)*N//2
s = sum(A)

if s%red_once != 0:
    print('NO')
else:
    num = s//red_once
    t = [0]*N
    for i in range(N):
        d,m = divmod(num-A[i]+A[i-1],N)
        if m != 0 or d < 0:
            print('NO')
            exit()
        else:
            t[i] = d
    if sum(t) == num:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 62704
#include <stdio.h>
int main(void){
	int w,h,n,x,y,a,ox=0,oy=0,ans;
	scanf("%d %d %d",&w,&h,&n);
	while(n--){
		scanf("%d %d %d",&x,&y,&a);
		if(a==1&&ox<x)ox=x;
		if(a==2&&w>x)w=x;
		if(a==3&&oy<y)oy=y;
		if(a==4&&h>y)h=y;
		if(w<ox||h<oy){
			ans=0;
			break;
		}
		ans=(w-ox)*(h-oy);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a>b && a>c){
		for(int i=1;i<=k;i++)  a*=2;
		cout<<a+b+c;
		return 0;
	}
	else if(b>c && b>a){
		for(int i=1;i<=k;i++)  b*=2;
		cout<<a+b+c;
		return 0;
	}
	else{
		for(int i=1;i<=k;i++)  c*=2;
		cout<<a+b+c;
		return 0;
	}
}

Measured memory_bytes: 256
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<class T>void put_double(T a){cout<<setprecision(15);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

double pi = 3.14159265358979;

int main(void) {
    double a, b, h, m; cin >> a >> b >> h >> m;
    double r = 2 * pi * abs(h * 60 - m * 11) / 720.0;
    double sqr = a*a + b*b - 2 * a * b * cos(r);
    double ans = sqrt(sqr);
    put_double(ans);
    return 0;
}


Measured memory_bytes: 4228
fun main(args: Array<String>) {
    val a  = readLine()!!.split(" ").map { it.toInt() }
    val s = mutableListOf<String>()
    for (i in 0 until a[0]) {
        s.add(readLine()!!)
    }
    s.sort()
    println(s.joinToString(""))
}



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

int n;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	if(n == 3 || n == 5 || n == 7){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    long long int a,b,x,h=0;
    scanf("%lld",&x);
    a = x/500;
    h += a*1000;
    x = x%500;
    b = x/5;
    h += b*5;
    printf("%lld",h);
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll X[51],Y[51];

double ret;

void hoge(double x,double y) {
	double r=0;
	int i;
	FOR(i,N) r=max(r,hypot(X[i]-x,Y[i]-y));
	ret=min(ret,r);
}

void solve() {
	int i,j,k,l,r,x,y,z; string s;
	
	cin>>N;
	FOR(i,N) cin>>X[i]>>Y[i];
	ret=1e9;
	
	FOR(z,N) FOR(y,z) {
		double rx=(X[y]+X[z])/2.0;
		double ry=(Y[y]+Y[z])/2.0;
		hoge(rx,ry);
		
		FOR(x,y) {
			double a=hypot(X[y]-X[z],Y[y]-Y[z]);
			double b=hypot(X[z]-X[x],Y[z]-Y[x]);
			double c=hypot(X[x]-X[y],Y[x]-Y[y]);
			
			if(abs(a+b-c)<1e-9) continue;
			if(abs(a+c-b)<1e-9) continue;
			if(abs(c+b-a)<1e-9) continue;
			
			double rx=(a*a*(b*b+c*c-a*a)*X[x]+b*b*(a*a+c*c-b*b)*X[y]+c*c*(b*b+a*a-c*c)*X[z])/(a*a*(b*b+c*c-a*a)+b*b*(a*a+c*c-b*b)+c*c*(b*b+a*a-c*c));
			double ry=(a*a*(b*b+c*c-a*a)*Y[x]+b*b*(a*a+c*c-b*b)*Y[y]+c*c*(b*b+a*a-c*c)*Y[z])/(a*a*(b*b+c*c-a*a)+b*b*(a*a+c*c-b*b)+c*c*(b*b+a*a-c*c));
			hoge(rx,ry);
		}
	}
	_P("%.12lf\n",ret);
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    bool flag = false;

    if (c < a + b) flag = false;
    else{
        if (4 * a * b < (c-a-b) * (c-a-b)) flag = true;
    }

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

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

#define ll long long
#define ii pair<int, int>
#define dd pair<double, double>
#define pb(i) push_back(i)

char mat[60][60];
int mark[60][60];
int adj[2][4] = {{1, -1, 0, 0}, {0, 0, 1, -1}};
 
int bfs(int yi, int xi){
	memset(mark, -1, sizeof(mark));
	queue<pair<int, int>> Q;
	Q.push({yi, xi});
	mark[yi][xi] = 0;
	int resp = -1;
	while(!Q.empty()){
		pair<int, int> v = Q.front();
		Q.pop();
 
		for (int k = 0; k < 4; k++){
			int y = v.first + adj[0][k];
			int x = v.second + adj[1][k];
 
			if (mark[y][x] == -1 && mat[y][x] == '.'){
				Q.push({y, x});
				mark[y][x] = mark[v.first][v.second] + 1;
				resp = mark[y][x];
			}
		}
	}
	return resp;
}
 
int main(){
	int h, w;
	memset(mat, 0, sizeof(mat));
	scanf("%d %d%*c", &h, &w);
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++)
			scanf("%c", &mat[i][j]);
		scanf("%*c");
	}
	
	int ans = -1;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			if (mat[i][j] == '.'){
				ans = max(ans, bfs(i, j));
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3768
k, n = map(int, input().split())
a = list(map(int, input().split()))
l = []
for i in range(n):
  if i == 0:
    l.append(a[-1] - a[i])
  else:
    l.append(k - a[i] + a[i - 1])
print(min(l))

Measured memory_bytes: 26436
#include <iostream>
int main(){
    int a,b;
    std::cin>>a>>b;
    if(a<b)
        std::cout<<"a < b"<<std::endl;
    else if(a>b)
        std::cout<<"a > b"<<std::endl;
    else
        std::cout<<"a == b"<<std::endl;
}


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

int main() {
  int N; cin >> N; // 駐車時間
  int A; cin >> A; // 時間単価
  int B; cin >> B; // 定額料金

  int x = N * A; // 時間単位で計算した料金
  
  if ( x < B ) {
    cout << x << endl;
  } else {
    cout << B << endl;
  }


}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Make a Rectangle
            int n = int.Parse(Console.ReadLine());
            var A = ReadLine();

            var sides = new Dictionary<long, int>();

            foreach(var Ai in A)
            {
                if (!sides.ContainsKey(Ai))
                {
                    sides.Add(Ai, 1);
                }
                else
                {
                    sides[Ai]++;
                }
            }

            var query = sides.OrderByDescending(x => x.Key);
            long area = 1;
            int count = 0;

            foreach(var q in query)
            {
                if (q.Value >= 4 && count == 0)
                {
                    area = q.Key * q.Key;
                    count += 2;
                }
                else if (q.Value >= 2)
                {
                    area *= q.Key;
                    count++;
                }

                if (count >= 2)
                {
                    break;
                }
            }

            if (count < 2)
            {
                area = 0;
            }

            Console.WriteLine(area);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 27872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    cin >> N;
    int ac = 0, wa = 0, tle = 0, re = 0;
    rep(i, 0, N)
    {
        string tmp;
        cin >> tmp;
        if (tmp == "AC")
            ++ac;
        if (tmp == "WA")
            ++wa;
        if (tmp == "TLE")
            ++tle;
        if (tmp == "RE")
            ++re;
    }
    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);
}
int main()
{
    func();
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll n;
  cin >> n;
  vll a(n),b(n);
  rep(i,0,n) cin >> a[i];
  rep(i,0,n) cin >> b[i];
  
  ll j=0,now=-1;
  rep(i,0,n){
   if(now!=a[i]) j=0;
   if(a[i]==b[i]){ 
    for(;j<n;j++){
     if(a[j]!=a[i]&&b[j]!=a[i]){
      swap(b[i],b[j]);
      break;
     }
    }
    if(a[i]==b[i]){
     cout << "No" << endl;
      return;
    }
   }
    now=a[i];
  }
  
  cout << "Yes" << endl;
  rep(i,0,n) {
    cout << b[i];
    if(i!=n-1) cout << " ";
  }
  cout << endl;
  
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 6356
import java.util.Scanner;


class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	String str = scanner.nextLine();			//入力
	  	String con[] =  new String[1200];
		int count = 0;
		
  		//初期化
  		for(int i = 0; i < 1200 ;i ++) {
	  		con[i] = "";
		}
			count = str.length();		//文字数取得
			
			//大文字小文字変換
			for(int i = 0; i < count ;i ++) {
			    if( Character.isUpperCase( str.charAt( i ) ) ) {
		  			con[i] = str.substring(i,i + 1);
		  			con[i] = con[i].toLowerCase();
				}
		        else {
		  			con[i] = str.substring(i,i + 1);
		  			con[i] = con[i].toUpperCase();
				}
			}
			
			//出力
			for(int i = 0; i < count ;i ++) {
				if(i == count - 1){
					System.out.println(con[i]);
				}else{
					System.out.print(con[i]);
				}
			}
		scanner.close();
  }
}


Measured memory_bytes: 26996
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll x[100010], v[100010];
ll sumR[100010];
ll sumL[100010];
ll maxL[100010];
ll maxR[100010];
int main()
{
	int N;
	ll C;
	cin >> N >> C;
	x[0] = 0, v[0] = 0;
	for (int i = 1; i <= N; i++) cin >> x[i] >> v[i];
	ll ans = 0;
	x[N + 1] = C; v[N + 1] = 0;
	for (int i = 0; i <= N; i++) {
		sumR[i + 1] = sumR[i] + v[i + 1] - (x[i + 1] - x[i]);
		maxR[i + 1] = max(maxR[i], sumR[i + 1]);
	}
	for (int i = N; i >= 0; i--) {
		sumL[i] = sumL[i + 1] + v[i] - (x[i + 1] - x[i]);
		maxL[i] = max(maxL[i + 1], sumL[i]);
	}
	for (int i = N + 1; i >= 0; i--) {
		ll kcal = sumL[i] - (C - x[i]);
		kcal += maxR[i - 1];
		ans = max(ans, kcal);
		//cout << ans << endl;
	}
	for (int i = 0; i <= N; i++) {
		ll kcal = sumR[i] - x[i];
		kcal += maxL[i + 1];
		ans = max(ans, kcal);
		//cout << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8308
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl;exit(0);}else return;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; 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 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 <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int Q; cin >> Q;
	V<ll> ans(Q);
	REP(i,Q) {
		ll A, B; cin >> A >> B;
		if (A > B) swap(A, B);
		ll ok = A, ng = B + 1;
		while(ng-ok>1){
			ll md = (ok + ng) / 2;
			ll m = (A + md) / 2;
			((max(m*(A + md - m), (m + 1)*(A + md - (m + 1))) < A*B) ? ok : ng) = md;
		}
		ans[i] = A + ok - 2;
	}
	REP(i, Q) cout << ans[i] << endl;
	cin >> Q;

	return 0;
}



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

int main()
{
	auto& in = cin;

	long long N, M, K;
	in >> N >> M >> K;

	vector<long long> A;
	long long num = 0;
	long long time = 0;
	bool ignore = false;
	for (long long i = 0; i < N; ++i) {
		long long a;
		in >> a;
		if (((time + a) <= K) && !ignore) {
			++num;
			time += a;
			A.push_back(a);
		}
		else {
			ignore = true;
		}
	}
	long long numMax = num;
	ignore = false;
	for (long long i = 0; i < M; ++i) {
		long long b;
		in >> b;
		while ((time + b) > K) {
			if (A.empty())
				break;
			time -= A.back();
			--num;
			A.pop_back();
		}
		if (((time + b) <= K) && !ignore) {
			++num;
			numMax = max(num, numMax);
			time += b;
		}
		else {
			ignore = true;
		}
	}
	cout << numMax;

	return 0;
}


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

int main() {
  
long long int a, b, count, ans,A,B;
  ans = 1;
  vector<int> answer(10000);
  cin >> a >> b;
  A =a;
  B =b;

  for(int i = 10001; i > 1; i--){
    if(a % i == 0 && b % i == 0){
      a = a/i;
      b = b/i;
      answer[i] = i;
    }
    
  }
  
  for(int i = 0; i < 10001; i++){
    if(answer[i] != 0){
    ans *= answer[i];

    }
  }

  

  cout << (A*B)/ans<< endl;
  
}


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

using namespace std;

template <class T>
inline T updmax(T &a, T b) { return a = max(a, b); }
template <class T>
inline T updmin(T &a, T b) { return a = min(a, b); }

template <unsigned long long mod>
class modint
{
public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod - this->v); }
	modint &operator+=(const modint rhs)
	{
		v += rhs.v;
		if (v >= mod)
			v -= mod;
		return *this;
	}
	modint &operator-=(const modint rhs)
	{
		if (v < rhs.v)
			v += mod;
		v -= rhs.v;
		return *this;
	}
	modint &operator*=(const modint rhs)
	{
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a)
	{
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp)
		{
			if (exp % 2)
			{
				ret *= a;
			}
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint &operator/=(modint rhs)
	{
		(*this) *= inverse(rhs);
		return *this;
	}
};
using mint = modint<1000000007>;

int dfs(vector<vector<int>> &g, int u, int p, vector<int> &cnt, vector<bool> &visit)
{
	int f1 = 0, f2 = 0;
	if (u != 0)
		f1++;
	visit[u] = true;
	cnt[u] = p;
	for (auto v : g[u])
	{
		if (visit[v])
		{
			continue;
		}
		else
		{
			f1++;
			f2 += dfs(g, v, f1, cnt, visit);
		}
	}
	return f1;
}

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	vector<vector<int>> g(n);
	vector<int> cnt(n, 0);
	vector<bool> visit(n);
	for (int i = 0; i < n - 1; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--, b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	dfs(g, 0, 0, cnt, visit);
	mint ans = 1;
	for (int i = 0; i < n; i++)
	{
		ans *= max(k - cnt[i], 0);
	}
	printf("%lld\n", ans);

	return 0;
}

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

#define N 100000

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

int main(){
	int n,i,j;
	long long h,a[N],b[N];
	scanf("%d%lld",&n,&h);
	for(i=0;i<n;i++)scanf("%lld%lld",&a[i],&b[i]);
	qsort(a,n,sizeof(long long),compare_int);
	qsort(b,n,sizeof(long long),compare_int);
	int tmp,ans=0;
	for(i=0;i<n;i++){
		if(h<=0)break;
		if(a[0]>b[i])break;
		h-=b[i];
		ans++;
	}
	if(h>0){
		ans+=h/a[0];
		h%=a[0];
		if(h>0)ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2556
import java.util.Scanner;

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

		int H = reader.nextInt();
		int W = reader.nextInt();
		int[][] arr = new int[H][W];
		String ans = "Yes";
		for (int i = 0; i< H; i++) {
			String row = reader.next();
			for (int j = 0; j< W; j++) {
				char ch = row.charAt(j);
				if (ch == '#') {
					arr[i][j] = 1;
				} else {
					arr[i][j] = 0;
				}
			}
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j< W; j++) {
				if (arr[i][j] == 1) {
					boolean flag = false;
					if (i > 0) {
						flag = (arr[i-1][j] == 1) || flag;
					}
					if (i < H - 1) {
						flag = (arr[i+1][j] == 1) || flag;
					}
					if (j > 0) {
						flag = (arr[i][j-1] == 1) || flag;
					}
					if (j < W - 1) {
						flag = (arr[i][j+1] == 1) || flag;
					}
					if (!flag) {
						ans = "No";
					}
				}

			}
		}
		System.out.print(ans);
		reader.close();
	}
}





Measured memory_bytes: 21716