akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	////////////////
	vector<int> hist(100001, 0);
	for (int i = 0; i < N; ++i) {
		hist[A[i]] ++;
	}
	int count = 0;
	int sum = 0;
	for (int i = 0; i < 100001; ++i) {
		int ter = hist[i];
		if (ter >= 3) {
			if (ter & 1) {
				ter = 1;
			}
			else {
				ter = 2;
			}
		}
		hist[i] = ter;

		if (ter == 2) {
			count++;
		}
		sum += ter;
	}
	
	sum -= (count / 2)*2;
	if (count & 1) {
		sum -= 2;
	}
	cout << sum << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1152
// https://atcoder.jp/contests/abc174/tasks/abc174_e
#include <bits/stdc++.h>
 
using namespace std;

#define ll long long
#define ld long double

const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

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; }

ll n,k;
# define BSEARCH_TYPE ll
vector<BSEARCH_TYPE> v;
BSEARCH_TYPE key;

// val が条件を満たすかどうか
bool isOK(ll val) {
    // // 普通のbsearch, valはindex
    // if (v[val] >= key) {
    //     return true;
    // } else {
    //     return false;
    // }

    ll cnt = 0;
    for(auto&& a : v) {
        cnt += (a + val - 1) / val;
    }
    return cnt <= k + n;
}

ll bsearch(ll left, ll right) {
    while (abs(right - left) > 1) {
        ll mid = (right + left) / 2;

        if (isOK(mid)) right = mid;
        else left = mid;
    }
    return right;
}

// vから普通にbsearchする
ll bsearchVec(BSEARCH_TYPE _key) {
    key = _key;
    return bsearch(-1, (int)v.size());
}

int main() {
    INIT();

    cin >> n >> k;
    v.resize(n);
    REP(i, n) {
        cin >> v[i];
    }
    cout << bsearch(0, *max_element(v.begin(), v.end()));
    return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

typedef pair<int,int> Pii;

int main() {

    int n;

    int v;
    int cnt1[200001] = {};
    int cnt2[200001] = {};

    int maxv = 0;
    Scd(n);

    Rep(i,n){
        Scd(v);
        if(i % 2){
            cnt1[v]++;
        }else{
            cnt2[v]++;
        }
        maxv = max(maxv,v);
    }
    maxv++;

    int ans1 = 0, ans2 = 0;
    int hit1 = 0, hit2 = 0;
    Rep(i,maxv){
        if(cnt1[i] > ans1){
            ans1 = cnt1[i];
            hit1 = i;
        }
        if(cnt2[i] > ans2){
            ans2 = cnt2[i];
            hit2 = i;
        }
    }


    int pre1 = 0, pre2 = 0;
    int preans = ans1 + ans2;
    if( hit1 == hit2 ){
        Rep(i,maxv){
            if(i == hit1) continue;
            if(cnt2[i] > pre2){
                pre2 = cnt2[i];
            }
        }
        Rep(i,maxv){
            if(i == hit1) continue;
            if(cnt1[i] > pre1){
                pre1 = cnt1[i];
            }
        }
        int preans1 = pre1 + ans2;
        int preans2 = pre2 + ans1;
        preans = max(preans1,preans2);
    }



    int ans = n - preans;
    printf ("%d\n", ans);

    return 0;
}



Measured memory_bytes: 1792
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_s = Array.init m @@ fun _ -> Scanf.scanf " %d" (+) 0
let dp = Array.make (n + 1) 0
let bs = Array.make (n + 1) false
let f i v = if not bs.(i) then dp.(i) <- v
let _ = Array.iter (fun a -> bs.(a) <- true) a_s;
  f 0 1; f 1 1;
  for i = 2 to n do f i @@ (dp.(i - 1) + dp.(i - 2)) mod 1000000007 done;
  Printf.printf "%d\n" @@ dp.(n)

Measured memory_bytes: 6400
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    K, N = MI()
    A = LI()

    dis = [0] * len(A)
    dis[0] = A[0] + (K - A[-1])
    for i in range(1, N):
        dis[i] = A[i] - A[i - 1]

    max_dis = max(dis)

    print(K-max_dis)


main()


Measured memory_bytes: 103844
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<double> x(N);
  vector<string> u(N);
  REP(i, N)
  cin >> x[i] >> u[i];
  double ans = 0.0;
  REP(i, N)
  {
    if (u[i] == "BTC")
      ans += 380000.0 * x[i];
    else
      ans += x[i];
  }
  printf("%.8f\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1000000007;
vector<ll> dp,h;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    h.resize(n,0);
    dp.resize(n,0);
    for(int i=0;i<n;i++)
        cin>>h[i];
    dp[1] = abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1];
    
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>

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

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		char s[101]; scanf("%s",s);
		int a[100],b[100];
		rep(i,n) scanf("%d%d",a+i,b+i), a[i]--, b[i]--;

		for(int i=n-1;i>=0;i--){
			int d=b[i]-a[i];
			s[a[i]]=(s[a[i]]-'a'+d)%26+'a';
			s[b[i]]=(s[b[i]]-'a'+d)%26+'a';
			swap(s[a[i]],s[b[i]]);
		}

		puts(s);
	}

	return 0;
}

Measured memory_bytes: 0
import math
q = int(input())
for i in range(q):
  a,b = map(int,input().split())
  if a == b:
    print(a*2-2)
    continue
  y = max(a,b)
  z = min(a,b)
  ind = math.sqrt(a*b)
  d = int(ind)
  if ind.is_integer():
    d -= 1
  cnt = 0
  if d*(d+1) < a*b:
    if d >= z:
      cnt = 1
    if d+1 >= y:
      cnt = 2
    print(2*d-cnt)
  else:
    if d >= z:
      cnt = 1
    print(2*d-1-cnt)

Measured memory_bytes: 3064
def how(c):
    if float(c).is_integer() == True:
        return int(float(c)),0
    else:
        dot=0
        while c[dot]!=".":
            dot+=1
        c = list(c)
        del c[dot]
        c ="".join(c)
        return int(c),len(c)-dot

def lo2(n):
    count = 0
    while n%2==0:
        n=n//2
        count+=1
    return count

def lo5(n):
    count=0
    while n%5==0:
        n=n//5
        count+=1
    return count

N = int(input())

A = []

for i in range(N):
    A.append(how(input()))


ruiseki = [[0]*120 for i in range(120)]

motoseisuu=0
for i in range(N):
    ruiseki[A[i][1]-lo2(A[i][0])+60][A[i][1]-lo5(A[i][0])+60]+=1
    if A[i][1]==0:
        motoseisuu +=1

for i in range(1,120):
    for j in range(1,120):
        ruiseki[i][j]=ruiseki[i-1][j]+ruiseki[i][j-1]-ruiseki[i-1][j-1]+ruiseki[i][j]


ans = 0
for i in range(N):
    ans+=ruiseki[lo2(A[i][0])+60-A[i][1]][lo5(A[i][0])+60-A[i][1]]

print((ans-motoseisuu)//2)


Measured memory_bytes: 90028
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

bool check(string s, vector<int>& a, int k) {
    if (a[0]==0) {
        if (s[0]=='o' && a[k]!=a[1]) return false;
        if (s[0]=='x' && a[k]==a[1]) return false;
    } else {
        if (s[0]=='x' && a[k]!=a[1]) return false;
        if (s[0]=='o' && a[k]==a[1]) return false;
    }
    return true;
}

void answer(vector<int>& a) {
    for(const auto& aa: a) cout << ((aa==0)?'S':'W');
    cout << endl;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<int> a(n);
    const int ini[] = {0, 1}; // 羊:0, 狼:1
    rep(i, 2) rep(j, 2) {
        rep(k, n) a[k]=-1;
        a[0] = ini[i]; a[1] = ini[j];
        FOR(k, 1, n) {
            if (k<n-1) {
                if (a[k]==0) {
                    if (s[k]=='o') a[k+1] = a[k-1];
                    else a[k+1] = 1-a[k-1];
                } else {
                    if (s[k]=='x') a[k+1] = a[k-1];
                    else a[k+1] = 1-a[k-1];
                }
            } else {
                debug(a);
                if (a[k]==0) {
                    if (s[k]=='o') {
                        if (a[k-1]==a[0]) {
                            if (!check(s, a, k)) continue;
                            answer(a);
                            return 0;
                        }
                    } else {
                        if (a[k-1]!=a[0]) {
                            if (!check(s, a, k)) continue;
                            answer(a);
                            return 0;
                        }
                    }
                } else {
                    if (s[k]=='x') {
                        if (a[k-1]==a[0]) {
                            if (!check(s, a, k)) continue;
                            answer(a);
                            return 0;
                        }
                    } else {
                        if (a[k-1]!=a[0]) {
                            if (!check(s, a, k)) continue;
                            answer(a);
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 1024
def check(a, b)
  3.times do |i|
    ret = a * b * (i + 1)
    return true if ret % 2 == 1
  end
  false
end

a, b = STDIN.gets.split(" ").map(&:to_i)

if check(a, b)
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
#define mx 500001
using namespace std;
ll mi(ll n,ll m){ll pw=n;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define mkp make_pair
//#define d double
void solve(){
ll h;
cin>>h;
ll cnt=0;
while(h!=1){
	cnt++;
	h/=2;
}
ll mul=2;
ll ans=1;
rep(i,0,cnt) ans+=(mul),mul*=2;
cout<<ans;
}
int32_t main(){
FIO;
int t=1;
//cin>>t;
while(t--){
	solve();
}
}



Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        mut n: u64,
    }

    let mut r = String::new();
    while n > 0 {
        n -= 1;
        r.insert(0, ((n % 26) as u8 + b'a') as char);
        n /= 26;
    }
    println!("{}", r);
}


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

using namespace std;

const int INF = 1e9 + 5;
const int N = 1e4;
const int MOD = 998244353;
const double EPS = 1e-9;

const double PI = acos(-1);


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    string ans[10] = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};
    cout << ans[n % 10];
}

Measured memory_bytes: 3676
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] points = new int[n];
    for (int i = 0; i < n; i++) {
      points[i] = sc.nextInt();
    }
    int left = 0;
    int right = k;
    for (int i = 0; i < n - k; i++) {
      if (points[left] < points[right]) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
      left++;
      right++;
    }
  }
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

inline int64 modPow(int64 x, int64 n) {
  if(n == 0) return (1);
  int64 ret = modPow(x, n / 2);
  (ret *= ret) %= mod;
  if(n & 1) (ret *= x) %= mod;
  return (ret);
}

inline int64 modInv(int64 a) {
  return (modPow(a, mod - 2));
}

inline int64 modCombination(int p, int q) {
  static int64 fact[202020], rfact[202020];
  if(fact[0] == 0) {
    fact[0] = rfact[0] = 1;
    for(int i = 1; i < 102020; i++) {
      fact[i] = fact[i - 1] * i % mod;
      rfact[i] = modInv(fact[i]);
    }
  }
  if(q < 0 || p < q) return (0);
  return (fact[p] * rfact[q] % mod * rfact[p - q] % mod);
}

inline int64 count2_3(int n, int k) {
  return (modCombination(n - 1, k - 1));
}

int main() {
  int N, K;
  cin >> N >> K;
  cout << count2_3(N, K) << endl;
}






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

int main() {
  int l1, l2, r1, r2;
  
  cin >> l1 >> l2 >> r1 >> r2;
  
  if (l1 + l2 > r1 + r2) {
    cout << "Left" << endl;
  } else if (l1 + l2 == r1 + r2) {
    cout << "Balanced" << endl;
  } else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
a,b,c = gets.split.map(&:to_f)
s = Math.sin(c/180.0 * Math::PI) * a * b /2
ll =a**2 + b**2 - 2*a*b*Math.cos(c/180.0 * Math::PI)
l = Math.sqrt(ll)
p s
p a + b + l
p (s*2)/a


Measured memory_bytes: 8992
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        long sum=0;
        for(int i=0;i<n;i++) {
            sum+=sc.nextInt();
        }
        System.out.println(sum/n);
    }
}


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

typedef long long int ll;

int main()
{
    ll x, y, n;
    cin >> x >> y >> n;
    vector<tuple<ll,ll,ll>> xya(n);
    for(ll i = 0;i < n;i++){
        cin >> get<0>(xya[i]) >> get<1>(xya[i]) >> get<2>(xya[i]);
    }

    ll ans = 0;
    ll ax = 0, ay = 0, zx = x, zy = y;
    for(ll i = 0;i < n;i++){
        if(get<2>(xya[i]) == 1 && get<0>(xya[i]) > ax){
            ax = get<0>(xya[i]);
        }
        else if(get<2>(xya[i]) == 2 && get<0>(xya[i]) < zx){
            zx = get<0>(xya[i]);
        }
        else if(get<2>(xya[i]) == 3 && get<1>(xya[i]) > ay){
            ay = get<1>(xya[i]);
        }
        else if(get<2>(xya[i]) == 4 && get<1>(xya[i]) <zy){
            zy = get<1>(xya[i]);
        }
    }

    ans = (zx - ax) * (zy - ay);
    //cout << zx << ax << zy << ay<<endl;
    if(zx - ax < 0 || zy - ay < 0) ans = 0;
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+10;

int n;
LL a,b,h[maxn];
LL l,r;

int main()
{
	scanf("%d%I64d%I64d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&h[i]);
		r=max(r,h[i]);
	}
	l=0;
	
	while(l+1<r)
	{
		LL mid=(l+r)>>1;
		LL ss=0;
		
		for(int i=1;i<=n;i++)
		{
			LL temp=h[i]-mid*b;
			if (temp>0)
			{
				if (temp%(a-b)==0) ss+=temp/(a-b);
				else ss+=temp/(a-b)+1;
			}
		}
		
		if (ss<=mid) r=mid;
		else l=mid;
	}
	
	printf("%I64d\n",r);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
//#include<stdint-gcc.h>

using namespace std;

map<int,int> mp;

bool sortcol(const vector<int>& v1, const vector<int>& v2 )
{
    return v1[1] < v2[1];
}

int main()
{
    int test=1;
    //cin>>test;
    while(test--)
    {
        int n,m;
        cin>>n>>m;
        string s[n];
        for(int i=0;i<n;++i)
            cin>>s[i];

        long long int dp[n][m];
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        for(int i=0;i<n;++i)
        {
            for(int j=0;j<m;++j)
            {
                if(s[i][j]=='.')
               {
                   if(i!=0 && s[i-1][j]=='.')
                    dp[i][j]=(dp[i][j]+dp[i-1][j])%1000000007;
                   if(j!=0 && s[i][j-1]=='.')
                    dp[i][j]=(dp[i][j]+dp[i][j-1])%1000000007;
               }
            }
        }
        cout<<dp[n-1][m-1];

    }

    return 0;
}



Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
    if(flg) {
        cout << hoge << endl;
        exit(0);
    }
}
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
vl A,B(MAX_N,0);
map<ll,ll> dp;
int main() {
    cin >> n >> k;
    rep(i, n) {
        cin >> a;
        a--;
        A.push_back(a);
    }

    rep(i, n) {
        B[i+1] = B[i];
        B[i+1] += A[i];
    }

    ans = 0;
    auto ite1 = A.begin(), ite2 = A.begin();
    while (ite2 != A.end()) {
        dp[B[ite2 - A.begin()] % k]++;
        ite2++;
        while (ite2-ite1>=k) {
            dp[B[ite1 - A.begin()] % k]--;
            ite1++;
        }
        ans += dp[B[ite2 - A.begin()]%k];
    }
    cout << ans << endl;
}


Measured memory_bytes: 18160
import sys

N = int(input())
A = list(map(int, input().split()))

mod = (10**9) + 7
abc = [0] * 3
ans = 1
for i in range(N):
	pos = abc.count(A[i])
	if pos == 0:
		print(0)
		sys.exit()
	ind = abc.index(A[i])
	ans *= pos
	ans %= mod
	abc[ind] += 1

print(ans)

Measured memory_bytes: 14396
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = sum(b)
for i in range(1,n+1):
    kd = max(a[i-1] - b[i-1], 0)
    kd = a[i-1] - kd
    a[i-1] -= kd
    b[i-1] -= kd
    kd = max(a[i] - b[i-1], 0)
    kd = a[i] - kd
    a[i] -= kd
    b[i-1] -= kd
print(ans - sum(b))

Measured memory_bytes: 18624
a,b=map(int,input().split())
s=str(input())
f=0
if s[a] !="-":
    f =0
else:
    c=s[:a]
    d=s[a+1:]
    if len(c)==a and len(d)==b:
        if "-" not in c:
            if "-" not in d:
                f=1
print("Yes" if f==1 else "No")

Measured memory_bytes: 3060
def solve(string):
    n, *sp = string.split()
    sp = sorted([(s, -int(p), i) for i, (s, p) in enumerate(zip(*[iter(sp)] * 2), start=1)])
    return "\n".join([str(i) for *_, i in sp])


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;



int main(){

    ll N;
    cin >> N;
    vector<ll>A(N);
    for(ll i = 0; i < N; i++)cin >> A[i];
    A.push_back(-191919);
    sort(A.begin(), A.end());
    A[0] = A[N];
    A[N] = -1;
    ll M = A[0];
    vector<ll>X, Y;
    for(ll i = 1; i < N; i++){
        if(A[i + 1] > 0){
            X.push_back(min(M, A[i]));
            Y.push_back(max(M, A[i]));
            M = -abs(M - A[i]);
        }
        else{
            X.push_back(max(M, A[i]));
            Y.push_back(min(M, A[i]));
            M = abs(M - A[i]);
        }
    }
    cout << M << endl;
    for(ll i = 0; i < X.size(); i++){
        cout << X[i] << " " << Y[i] << endl;
    }
    
    return 0;
}

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

int main()
{
	int N, X;
	while(cin >> N >> X && N != 0 || X != 0)
	{
		int ans = 0;
		for(int i = 1; i <= N; ++i)
		{
			for(int j = i + 1; j <= N; ++j)
			{
				for(int k = j + 1; k <= N; ++k)
				{
					if(i + j + k == X)
					{
						++ans;
					}
				}
			}
		}
		
		cout << ans << endl;
	}

    return 0;
}



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

using namespace std;

int main() {
	int n, m = 100000;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		m *= 1.05;
		if (m % 1000) {
			m += 1000 - m % 1000;
		}
	}
	cout << m << endl;
}

Measured memory_bytes: 1160
N, M, K = map(int,input().split())

ok = False
for n in range(N+1):
    for m in range(M+1):
        #  行選択n回,列選択m回
        black = n*M+m*N-n*m*2
        if black == K:
            print("Yes")
            ok = True
            break
    if ok:break
if ok == False:
    print("No")



Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end(), greater<int>());
	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += l[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<int, pair<int,int> >P;

const int INF = 1<<30;

int R,H[2],W[2],X[2],Y[2];
int G[2][512][512];
int dy[]={0,-1,0,1},dx[]={-1,0,1,0};
int L[2][100005];

void C(int h, int w, int x, int y, int l[100005], int g[512][512]){

  int vis[512][512];
  memset(vis, -1, sizeof vis);
  priority_queue<P, vector<P>, greater<P> >q;
  q.push(make_pair(1, make_pair(y,x)));
  vis[y][x] = 0;
  for(int i=0;i<=R;i++) l[i] = INF;
  l[0] = min(l[0], 0);

  for(int i=1;i<=R && i<=h*w;i++){
    P p = q.top(); q.pop();
    l[i] = min(l[i],p.first);
    int cy = p.second.first, cx = p.second.second;
    for(int d=0;d<4;d++){
      int ty=cy+dy[d],tx=cx+dx[d];
      if(ty<0||ty>=h||tx<0||tx>=w||vis[ty][tx]!=-1) continue;
      vis[ty][tx] = 0;
      //      cout << g[ty][tx] << endl;
      q.push(make_pair(max(g[ty][tx], l[i]), make_pair(ty, tx)));
    }
  }
}

int main(){
  while(scanf("%d", &R) && R){
    for(int i=0;i<2;i++){
      scanf("%d%d%d%d", &W[i],&H[i],&X[i],&Y[i]); X[i]--; Y[i]--;
      for(int j=0;j<H[i];j++) for(int k=0;k<W[i];k++) scanf("%d", &G[i][j][k]);
    }

    for(int i=0;i<2;i++){
      C(H[i],W[i],X[i],Y[i],L[i],G[i]);
      //      for(int j=0;j<=R;j++) printf("%d ", L[i][j]); puts("");
    }

    int res = INF;
    for(int i=0;i<=R;i++) res = min(res, L[0][i] + L[1][R-i]);
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 5140
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class NumMatrix {
private:
    int row, col;
    vector<vector<int>> sums;
public:
    NumMatrix(vector<vector<int>> &matrix) {
        row = matrix.size();
        col = row>0 ? matrix[0].size() : 0;
        sums = vector<vector<int>>(row+1, vector<int>(col+1, 0));
        for(int i=1; i<=row; i++) {
            for(int j=1; j<=col; j++) {
                sums[i][j] = matrix[i-1][j-1] + 
                             sums[i-1][j] + sums[i][j-1] - sums[i-1][j-1] ;
            }
        }
    }

    int sumRegion(int row1, int col1, int row2, int col2) {
        return sums[row2+1][col2+1] - sums[row2+1][col1] - sums[row1][col2+1] + sums[row1][col1];
    }
};
void solve(){
	int n,m,Q;
	cin >> n >> m >> Q;
	vector<vector<int>> matrix(n+1,vector<int>(n+1,0));
	for(int  i = 0 ;i < m ;i++){
		int L,R;
		cin >> L >> R;
		matrix[L][R]++; 
	}
	NumMatrix numMatrix(matrix);
	while(Q--){
		int p,q;
		cin >> p >> q;
		cout << numMatrix.sumRegion(p,p,q,q) << "\n";
	}
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.size(),count=0;
    if(s[0]=='A')
    {
        if(int(s[1])<97)
            {
                cout<<"WA";
                return 0;
            }
        for(int i=2;i<n-1;i++)
        {
            if(s[i]=='C')
            {
                count++;
                continue;
            }
            if(int(s[i])<97)
            {
                cout<<"WA";
                return 0;
            }
            if(int(s[n-1])<97)
            {
                cout<<"WA";
                return 0;
            }
        }
    }
    if(count==1)
        cout<<"AC";
    else
        cout<<"WA";
    return 0;
}


Measured memory_bytes: 256
n,K = map(int,input().split())

x,y = [],[]
xx,yy = [],[]

for _ in range(n):
    X,Y = map(int,input().split())

    x.append(X)
    xx.append(X)
    y.append(Y)
    yy.append(Y)

xx.sort()
yy.sort()

ans = 10**20
for i in range(n):
    for j in range(i):
        lx,rx = xx[j],xx[i]

        num = [0 for _ in range(n+1)]
        for k in range(n):
            if lx <= x[k] <= rx:
                num[yy.index(y[k])+1] += 1

        for k in range(n):
            num[k+1] += num[k]

        for k in range(n):
            for l in range(k):
                ly,ry = yy[l],yy[k]

                if num[k+1] - num[l] >= K:
                    ans = min(ans, (rx-lx)*(ry-ly))

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

template <class T> T gcd(T a, T b)
{
    if (a < b) swap(a, b);
    if (a % b == 0) return b;
    return gcd(a % b, b);
}


int main()
{
    long N, X0;
    cin >> N >> X0;

    vector<long> X(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> X[i];
        X[i] = abs(X[i] - X0);
    }
    sort(X.begin(), X.end());

    long d = X[0];
    for (int i = 1; i < N and d > 1; ++i)
        d = gcd(d, X[i]);

    cout << d << endl;
}


Measured memory_bytes: 1024
import bisect
from collections import defaultdict

S = input()
T = input()

if set(T) - set(S) != set():
    print(-1)
    exit()

d = defaultdict(list)
l = [0 for _ in range(26)]

for i, v in enumerate(S, 1):
    l[ord(v)-ord('a')] += 1
    d[v].append(i)

len_S = len(S)

# print(l)

ans = 0
c = 0
for t in T:
    i = bisect.bisect_left(d[t], c)
    # print(l[ord(t)-ord('a')])
    if i < l[ord(t)-ord('a')]:
        ans += d[t][i]-c+1
        c = d[t][i]+1
        # print(d[t][i])
    else:
        # print(ans, len_S, c, d[t][0])
        ans += len_S-c+d[t][0]+1
        c = d[t][0]+1
    # print(ans)

if ans > 10**100*len_S:
    print(-1)
else:
    print(ans-1)


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m;
    cin >> n >> m;
    vector<pii> ab(n);
    REP(i,n)cin >> ab[i].first >> ab[i].second;
    sort(ALL(ab));
    priority_queue<int32> b;
    int32 ans = 0;
    int32 x = 0;
    FOR(i,1,m+1){
        while(x != n && ab[x].first <= i){
            b.push(ab[x].second);
            ++x;
        }
        if(b.empty())continue;
        ans += b.top();
        b.pop();
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 2936
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int main(){
    int n, cnt = 0;
    cin >> n;
    vector<int> P(n);
    rep(i,n) cin >> P[i];
    rep(i,n) if(P[i] != i+1)cnt++;
    if(cnt == 0 || cnt == 2)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable.ListBuffer
import scala.math.BigDecimal.RoundingMode

object Main {
  def main(args : Array[String]) = {
    val scanner = new Scanner(System.in)
    val inputs = ListBuffer.empty[Array[BigDecimal]]
    while(scanner.hasNextLine) {
      inputs += scanner.nextLine().split(" ").map(BigDecimal(_))
    }

    inputs.foreach{
      case Array(a,b,c,d,e,f) =>
        var wA = a / a
        var wB = b / a
        var wC = c / a
        var wD = d - wA * d
        var wE = e - wB * d
        var wF = f - wC * d

        wD = wD / wE
        wF = wF / wE
        wE = wE / wE

        wA = wA - wD * wB
        wC = wC - wF * wB
        wB = wB - wE * wB

        println(s"${wC.setScale(3, RoundingMode.HALF_UP)} ${wF.setScale(3, RoundingMode.HALF_UP)}")
    }
  }
}

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

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

    int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';

    if (a + b + c + d == 7) cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
    else if (a + b + c - d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
    else if (a + b - c + d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
    else if (a - b + c + d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
    else if (a + b - c - d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
    else if (a - b + c - d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
    else if (a - b - c + d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
    else cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	long long int N,A,B;
	cin >> N >> A >> B;
	
	if ((N == 1 && A != B) || (A > B)) {
		cout << "0" << endl;
	} else {
		cout << (((N-1)*B+A) - ((N-1)*A+B)) + 1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;
const ll INF = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2); return sq*sq; } else { return N*RS(N, P - 1); } } //power(repeat-square,fast)
ll nPr(ll n, ll r) { ll ans = 1; rep(i, r) { ans = ans * (n - i); } return ans; } //permutation
ll nCr(ll n, ll r) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1); bunshi = bunshi * (n - i); } return bunshi / bunbo; } //combination
ll RS(ll N, ll P, ll Mod) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination


char in[120];
pair<pair<string,int>,int> p[110];
int main(){
int a;scanf("%d",&a);
for(int i=0;i<a;i++){
int t;scanf("%s%d",in,&t);
string tmp=in;
p[i]=make_pair(make_pair(in,-t),i);
}
std::sort(p,p+a);
for(int i=0;i<a;i++)printf("%d\n",p[i].second+1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int H,W;
int main(){
    cin >> H >> W;
    char fd[H][W];
    rep(i,H) rep(j,W) cin >> fd[i][j];
    rep(i,H){
        bool flag = true;
        rep(j,W) if(fd[i][j] == '#') flag = false;
        if(flag) rep(j,W) fd[i][j] = '0';
    }
    rep(j,W){
        bool flag = true;
        rep(i,H) if(fd[i][j] == '#') flag = false;
        if(flag) rep(i,H) fd[i][j] = '0';
    }
    
    rep(i,H){
        bool flag = false;
        rep(j,W) if(fd[i][j] != '0') cout << fd[i][j], flag = true;
        if(flag) cout << '\n';
    }
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()

inline bool ok(li x) {
	li cnt = 0;
	repp(i, 1, x + 1) {
		if (x % i == 0)++cnt;
	}
	return cnt == 8;
}

int main(void)
{
	li n;
	cin >> n;
	li now = 7;
	li res = 0;
	while (now <= n) {
		if (ok(now))++res;
		now += 2;
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    X, K, D = map(int, input().split())

    cnt = abs(X) // D
    if X >= 0:
        X -= min(K, cnt) * D
    else:
        X += min(K, cnt) * D

    K -= min(K, cnt)
    if K % 2 == 0:
        ans = abs(X)
    else:
        ans = min(abs(X - D), abs(X + D))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);
const int MAX = 1000100;
const int MOD = 1e9 + 7;
using P = pair<int,int>;
map<P,ll> m;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    int x,y;
    cin >> x >> y;
    if((x+y)%3!=0) {
        cout << 0 << endl;
        return 0;
    }
    //int p = (x+y)/3;
    int a = (2*x - y) / 3;
    int b = (2 * y - x) / 3;
    COMinit();
    cout << COM(a+b,a) << endl;
}

Measured memory_bytes: 23680
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	int w, n;
	vector<int> vertical;
	vector< pair<int,int> > horizontal;
	string buffer;

	cin >> w;

	for ( int i = 1; i <= w; i++ )
	{
		vertical.push_back( i );
	}

	cin >> n;

	for ( int i = 0; i < n; i++ )
	{
		cin >> buffer;

		for ( unsigned int i = 0; i < buffer.size(); i++ )
		{
			if ( buffer[i] == ',' )
			{
				buffer[i] = ' ';
				break;
			}
		}

		int a, b;
		sscanf( buffer.c_str(), "%d %d", &a, &b );

		horizontal.push_back( make_pair( a - 1, b - 1 ) );
	}

	for ( unsigned int i = 0; i < horizontal.size(); i++ )
	{
		swap( vertical[ horizontal[i].first ], vertical[ horizontal[i].second ] );
	}
	

	for ( unsigned int i = 0; i < vertical.size(); i++ )
	{
		cout << vertical[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;

macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}

#[fastout]
fn main() {
  input! {
     N:usize,
     XYP:[(i64,i64,i64);N]
  }
  let N: usize = N;
  let mut XYP: Vec<(i64, i64, i64)> = XYP;
  let inf = std::i64::MAX;
  let mut xkyori = vec![vec![inf; N]; 2usize.pow(N as u32)];
  let mut ykyori = vec![vec![inf; N]; 2usize.pow(N as u32)];

  for pat_i in 0..2usize.pow(N as u32) {
    for i in 0..N {
      if pat_i >> i & 1 == 1 {
        // 都市 i に鉄道が引かれている場合の距離は0。
        xkyori[pat_i][i] = 0;
        ykyori[pat_i][i] = 0;
      } else {
        // そうでない場合、すべての路線への距離の最小値を求める。
        let (x, y, p) = XYP[i];
        xkyori[pat_i][i] = x.abs();
        ykyori[pat_i][i] = y.abs();
        for j in 0..N {
          if pat_i >> j & 1 == 1 {
            xkyori[pat_i][i] = min(xkyori[pat_i][i], (x - XYP[j].0).abs());
            ykyori[pat_i][i] = min(ykyori[pat_i][i], (y - XYP[j].1).abs());
          }
        }
        xkyori[pat_i][i] *= p;
        ykyori[pat_i][i] *= p;
      }
      debug!(pat_i, i, xkyori[pat_i]);
    }
  }
  debug!(xkyori);
  debug!(ykyori);
  // ここまでで前処理。xkyoriとykyoriが計算できた。
  let mut ans = vec![inf; N + 1];
  // 3進数を計算。0=線路なし,1=X路線, 2=Y路線
  for pat_i in 0..3usize.pow(N as u32) {
    // pat_xとpat_yの作成
    let mut k = N;
    let mut pat = pat_i;
    let mut pat_x = 0;
    let mut pat_y = 0;
    for i in 0..N {
      match pat % 3 {
        1 => pat_x += 2usize.pow(i as u32),
        2 => pat_y += 2usize.pow(i as u32),
        _ => k -= 1,
      }
      pat /= 3;
    }
    let mut t_ans = 0;
    for i in 0..N {
      t_ans += min(xkyori[pat_x][i], ykyori[pat_y][i]);
    }
    ans[k] = min(ans[k], t_ans);
  }
  for a in ans {
    println!("{}", a);
  }
}


Measured memory_bytes: 11848
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val n, m, k = Scanner.nextInt()

	val linked = Array.fill(n)(0)
	val friend = UnionFind(0 until n)
	loop(0, m) { _ =>
		val a, b = Scanner.nextInt() - 1
		friend.unite(a, b)
		linked(a) += 1
		linked(b) += 1
	}

	val blocked = Array.fill(n)(0)
	loop(0, k) { _ =>
		val c, d = Scanner.nextInt() - 1
		if (friend.same(c, d)) {
			blocked(c) += 1
			blocked(d) += 1
		}
	}

	loop(0, n) { i =>
		pw.println(friend.size(i) - blocked(i) - linked(i) - 1)
	}
	pw.flush()
}

case class UnionFind[T](seq: Seq[T]) {
	import scala.collection.mutable.Map
	private[this] val par: Map[T, T] = Map[T,T](seq.map(elem => elem -> elem): _*)
	private[this] val sz: Map[T, Int] = Map[T, Int](seq.map(elem => elem -> 1): _*)

	@scala.annotation.tailrec
	private[this] def find(t: T, acc: Seq[T] = Nil): T = {
		val p = par(t)
		if (p == t) {acc foreach { par(_) = t }; t} else find(p, p +: acc)
	}

	def unite(a: T, b: T): Unit = {
		val pa = find(a)
		val pb = find(b)

		if (pa == pb) return

		if (sz(pa) <= sz(pb)) {
			par(pa) = pb
			sz(pb)  = sz(pa) + sz(pb)
		} else {
			par(pb) = pa
			sz(pa)  = sz(pa) + sz(pb)
		}
	}

	def same(a: T, b: T) = find(a) == find(b)

	def size(a: T) = sz(find(a))
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 76464
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int depth = Integer.parseInt(sc.nextLine());
		int[] A = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		int[] numStr = A.clone();
		int[] B = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		int[] ans = new int[2];

		Arrays.sort(numStr);

		Main main = new Main();
		int[] con = new int[1];
		ans = main.searchPermutation(numStr, new boolean[depth], new int[depth], depth, 0,A,B,new int[2],con);

		System.out.println(Math.abs(ans[0] - ans[1]));
	}

	public int[] searchPermutation(int[] numStr,boolean[] flgs,int[] outStr,int depth,int steps,int[] A,int[] B,int[] ans,int[] con) {
		if (steps == depth) {
			con[0]++;
			int Aflg = 0;
			int Bflg = 0;
			for (int i = 0; i < depth; i++) {
				if (outStr[i] == A[i]) {
					Aflg++;
				}
				if (outStr[i] == B[i]) {
					Bflg++;
				}
			}

			if (Aflg == depth) {
				ans[0] = con[0];
			}
			if (Bflg == depth) {
				ans[1] = con[0];
			}
		}else {
			for (int i = 0; i < numStr.length; i++) {
				if (flgs[i] == false) {
					flgs[i] = true;
					outStr[steps] = numStr[i];
					searchPermutation(numStr, flgs, outStr, depth, steps + 1,A,B,ans,con);
					flgs[i] = false;
				}
			}
		}
		return ans;
	}

}

Measured memory_bytes: 37392
#include <iostream>

using namespace std;

int main() {
    string str;
    cin >> str;
    char cur=str[0];
    int ans=0;
    for(int i=1; i<str.size(); i++) {
        if(cur!=str[i]) {
            ans++;
            cur = str[i];
        }
    }
    cout << ans << endl;



    return 0;
    
}

Measured memory_bytes: 512