akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N, C;
int rec[100010][30];

signed main(){
    cin >> N >> C;
    int s, t, c;
    REP(i, N){
        cin >> s >> t >> c;
        c--;
        FOR(i, s - 1, t){
            rec[i][c] = 1;
        }
    }
    int ans = 0;
    REP(i, 100010){
        int use = 0;
        REP(j, C){
            if(rec[i][j]) use++;
        }
        ans = max(ans, use);
    }
    PRINT(ans);
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<queue<int>> P(N, queue<int>());
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - 1; j++) {
            int a;
            cin >> a;
            a--;
            P[i].push(a);
        }
    }

    queue<int> que1;
    for (int i = 0; i < N; i++)
        que1.push(i);
    queue<int> que2;
    bool updated = true;

    int res = 0;
    while (updated) {
        updated = false;
        vector<bool> used(N, false);

        while (!que1.empty()) {
            int a = que1.front(); que1.pop();
            if (!P[a].empty() && !used[a]) {
                int b = P[a].front();
                if (!P[b].empty() && !used[b] && P[b].front() == a) {
                    P[a].pop(); P[b].pop();
                    used[a] = true; used[b] = true;
                    que2.push(a); que2.push(b);
                    updated = true;
                }
            }
        }
        if (updated) res++;
        swap(que1, que2);
    }

    for (int i = 0; i < N; i++) {
        if (!P[i].empty()) {
            cout << "-1" << endl;
            return 0;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4736
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

#include <bits/stdc++.h>
using namespace std;

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

#define fi first
#define se second

int main() {
    int n = read();
    int m = read();
    using P = pair<int, int>;
    vector<P> bomb;
    for (int i = 0; i < n; ++i) {
        int a = read(), b = read();
        bomb.emplace_back(a, b);
    }
    sort(begin(bomb), end(bomb));
    vector<int> b(n + 1);
    int lst = 0;
    for (int i = 0; i < n; ++i) {
        lst ^= b[i] = bomb[i].se ^ lst;
    }
    b[n] = lst;
    vector<vector<P> > g(n + 1);
    for (int i = 1; i <= m; ++i) {
        int l = read(), r = read();
        int ll = lower_bound(begin(bomb), end(bomb), P(l, 0)) - begin(bomb);
        int rr = upper_bound(begin(bomb), end(bomb), P(r, 1)) - begin(bomb);
        g[ll].emplace_back(rr, i);
        g[rr].emplace_back(ll, i);
    }
    vector<int> ans;
    vector<bool> vis(n + 1);
    function<void(int)> dfs = [&](int u) {
        vis[u] = true;
        for (auto &e : g[u]) {
            int v = e.fi, id = e.se;
            if (!vis[v]) {
                dfs(v);
                if (b[v]) {
                    b[u] ^= 1;
                    b[v] ^= 1;
                    ans.emplace_back(id);
                }
            }
        }
    };
    for (int i = 0; i <= n; ++i) {
        if (!vis[i]) {
            dfs(i);
            if (b[i]) {
                puts("-1");
                return 0;
            }
        }
    }
    cout << ans.size() << '\n';
    sort(begin(ans), end(ans));
    for (int i : ans) {
        printf("%d ", i);
    }
    return 0;
}


Measured memory_bytes: 16884
package main

import (
	"fmt"
	"math/big"
)

func gcd(m, n uint64) uint64 {
	x := new(big.Int)
	y := new(big.Int)
	z := new(big.Int)
	a := new(big.Int).SetUint64(m)
	b := new(big.Int).SetUint64(n)
	return z.GCD(x, y, a, b).Uint64()
}

func solve(n, x int) {
	fmt.Print(3 * (uint64(n) - gcd(uint64(n), uint64(x))))
}

func main() {
	var n, x int
	fmt.Scan(&n)
	fmt.Scan(&x)
	solve(n, x)
}

Measured memory_bytes: 640
### main

while line = gets
  a, l, x = line.split.map(&:to_f)

  h = Math.sqrt(l ** 2 - (a / 2) ** 2)
  abc = a * h / 2

  hx = Math.sqrt(((l + x) / 2) ** 2 - (l / 2) ** 2)
  adc = l * hx / 2

  area = abc + 2 * adc

  puts "%.10f" % area
end

Measured memory_bytes: 6164
a, b, c = map(int, input().split())
count = 0
#aに１～bの数をかけたリスト
for i in range(b + 1):
    if ((i * a) % b) == c:
      print("YES")
      count += 1
      break
    else:
      pass

if count == 0:
  print("NO")
else:
  pass
  

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

int main()
{ 
	int N;
	cin >> N;
	if((N / 90) == 1 || (N % 10) == 9)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}


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

int a[110];
int dp[201000];

main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);	
	}
	dp[0]=0;
	for(int i=0;i<100100;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(dp[i]==0)
				if(dp[i+a[j]]==0)
				{
					dp[i+a[j]]=1;
				}
		}
	}/*
	for(int i=0;i<10;i++)
	{
		printf("%d ",dp[i]);
	}*/
	printf("%s",dp[k]==1? "First":"Second");
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	cout<<min(a*e,b+max(0,e-c)*d)<<endl;
	return 0;
}


Measured memory_bytes: 3064
import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=list(map(int, readline().strip().split()))
    #arr=list(map(int, readline().strip().split()))
    #n=int(readline().strip())
    h,w=list(map(int, readline().strip().split()))
    for _ in range(h):
        s=readline().strip()
        print(s)
        print(s)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()


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

using namespace std;


int main() {
  int n, m; cin >> n >> m;
  vector<vector<int>> v(n);
  for(int i = 0; i < m; ++i) {
    int x, y; cin >> x >> y;
    --x; --y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  queue<pair<int, int>> q;
  q.emplace(0, -1);
  vector<bool> vis(n);
  vector<int> par(n);
  vis[0] = true;
  while(!q.empty()) {
    int c = q.front().first;
    par[c] = q.front().second;
    q.pop();
    for (auto x: v[c]) {
      if (!vis[x]) { 
	vis[x] = true;
	q.emplace(x, c);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; ++i) {
    cout << 1+par[i] << endl;
  }
}



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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  blank(a > b?b : a) fin(n > (a + b)?0:(a + b - n))
  return;
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
while 1:
	n, x = map(int, raw_input().split())
	if n == 0 and x == 0:
		break
	a = [int(m) for m in range(1, n+1)]
	N = 0
	for k in range(2, n):
		for j in range(1, k):
			for i in range(j):
				if a[i]+a[j]+a[k] == x:
					N += 1
				else:
					pass
	print N

Measured memory_bytes: 4644
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  string A;
  cin >> A;
  
  bool N = false;
  bool S = false;
  bool W = false;
  bool E = false;
  for( int i = 0; i < A.size(); i++ ){
    if( A.at(i) == 'N' ) N = true;
    if( A.at(i) == 'S' ) S = true;
    if( A.at(i) == 'W' ) W = true;
    if( A.at(i) == 'E' ) E = true;
  }
  if( N == S && W == E ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(n + 1);
  for (int i = 0; i < m; ++i) {
    int l, r; cin >> l >> r, --l;
    ++c[l], --c[r];
  }
  for (int i = 0; i < n; ++i) c[i + 1] += c[i];
  int res = 0;
  for (int i = 0; i < n; ++i) {
    res += c[i] == m;
  }
  cout << res << '\n';
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <climits>
using namespace std;

#define MAX_N 500001

class Node
{
    public:
    int k, l = MAX_N, r = MAX_N;
};
vector<Node> nodes(MAX_N);
int p, n, r = 0;

void insert(int k)
{
    nodes[p].k = k;
    if (0 == p) { p++; return; }
    int *cur = &r;
    while (MAX_N != *cur) {
        if (k < nodes[*cur].k) cur = &nodes[*cur].l;
        else cur = &nodes[*cur].r;
    }
    *cur = p++;
}

int find(int cur, int k)
{
    if (cur == MAX_N) return 0;
    if (nodes[cur].k == k) return 1;
    return k < nodes[cur].k ? find(nodes[cur].l, k) : find(nodes[cur].r, k);
}

void preorder(int cur)
{
    if (MAX_N == cur) return;
    cout << " " << nodes[cur].k;
    preorder(nodes[cur].l);
    preorder(nodes[cur].r);
}

void inorder(int cur)
{
    if (MAX_N == cur) return;
    inorder(nodes[cur].l);
    cout << " " << nodes[cur].k;
    inorder(nodes[cur].r);
}

int main()
{
    cin >> n;
    p = 0;
    while (n--) {
        string command;
        int k;
        cin >> command;
        if (command == "insert") {
            cin >> k;
            insert(k);
        } else if (command == "find") {
            cin >> k;
            cout << (find (r, k) ? "yes" : "no") << endl;
        } else {
            inorder(r);
            cout << endl;
            preorder(r);
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 8480
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;
string k;
int n,m,ans;

signed main(){
	string s,t;
	cin>>s>>t;
	s+=t[t.size()-1];
	if(s==t)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();

int main(){
 int n,d,res=0; cin>>n>>d;
 
 res+=n/(2*d+1);
 if(n%(2*d+1)!=0)res++;

 cout<<res<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long i,ans;
	ans=0;
	string s,t;
	cin>>s;
	cin>>t;
	for (i=0;i<3;i++)
	{
		if (s[i]==t[i])
		{
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    char s[11]; 
    cin >> s;

    char ans[11];

    int j = 0;
    for(int i = 0; i < 11; i++){
        if(s[i] == '0'){
            ans[j] = '0';
            j++;
        }
        else if(s[i] == '1'){
            ans[j] = '1';
            j++;
        }
        else if(s[i] == 'B'){
            if(j != 0){
                ans[j-1] = '\0';
                j--;
            }
        }
    }

    ans[j] = '\0';

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

    return 0;
}

Measured memory_bytes: 256
def MAP(): return map(int, input().split())
def LIST(): return list(MAP())
 
N = int(input())
count = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
    string_i = str(i)
    initial = int(string_i[0])
    end = int(string_i[-1])
    count[initial][end] += 1
ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += count[i][j] * count[j][i]
print(ans)

Measured memory_bytes: 73476
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n; cin>>n;
    string s; cin>>s;
    s+= "????";
    int ans = 0;
    
    for(int i=0;i<n;i++){
        string x = s.substr(0, i);
        string y = s.substr(i);
        //cout<<x<<' '<<y<<endl;
        vector <bool>  a1(26), a2(26) ;
        rep(j, x.size()) if(x[j] == '?') continue; else a1[x[j] - 'a']= true;
        rep(j, y.size()) if(y[j] == '?') continue; else a2[y[j] - 'a']= true;
        int cnt = 0;
        rep(i,26) if(a1[i]&&a2[i]) cnt++;
        ans = max(ans, cnt);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

	ll a[N],b[N];
    void main()
    {
		int n=qread();fo(i,1,n) a[i]=qread(),b[i]=qread();
		ll ans=0;fd(i,n,1) ans+=ceil(1.0*(a[i]+ans)/b[i])*b[i]-(a[i]+ans);write(ans);
    }
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}

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

int main() {
  int n, l;
  cin >> n >> l;
  vector<int> Aji(n+1);
  int tot = 0;
  bool flg = 0;
  int plus = 1001;
  int minus = -1001;
  for (int i = 1;i <= n; i++) {
    Aji[i] = l+i-1;
    tot += Aji[i];
    if (Aji[i] == 0) flg = 1;
    else if (flg != 1 && Aji[i] > 0) plus = min(Aji[i], plus);
    else if (flg != 1 && Aji[i] < 0) minus = max(Aji[i], minus);
  }

  int ans;
  if (flg) ans = tot;
  else if (plus == 1001) {
    ans = tot-minus;
  } else if (minus == -1001) {
    ans = tot-plus;
  } else {
    ans = min(tot-plus, tot - minus);
  }

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

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    int N;
    cin >> N;
    long long x[N],y[N];
    long long h[N];
    bool flag = true;
    bool flag2 = false;
    long long H;
    int ansx,ansy,ansh;
    long long b = 0;
    for (int i = 0;i<N;i++){
        cin >> x[i] >> y[i] >> h[i];
    } 
    for (int i = 0;i<101;i++){
        for (int j = 0;j<101;j++){
            for (int k = 0;k<N;k++){
                if(h[k] != 0){
                    H = h[k] + abs(x[k] - i) + abs(y[k] - j);
                    break;
                }
            }
            for (int k=0;k<N;k++){
                if(max((H - abs(x[k] - i) - abs(y[k] - j)),b) != h[k]){
                    flag = false;
                    break;
                }
            }
            if (flag == true){
                ansx = i;
                ansy = j;
                ansh = H;
                flag2 = true;
                break;
            }
            flag = true;
        }
        if(flag2 == true){
            break;
        }
    }
    cout << ansx << " " << ansy << " " << ansh << endl;
    
}

Measured memory_bytes: 256
M=min
def f(x,y):
	m=x*(x%3>0)
	for i in(0,1):
		d=x//3+i;e=x-d;l=[d*y,y//2*e,-~y//2*e];m=M(m,max(l)-M(l))
	return m
h,w=map(int,input().split());print(M(f(h,w),f(w,h)))

Measured memory_bytes: 3060
#include<iostream>
#include<string.h>
using namespace std;

int  yoko[1001][1001];

int main() {
	int n, m, a, h, p, q;
	while (cin >> n >> m >> a) {
		if (n == 0 && m == 0 && a == 0)break;
		memset(yoko, 0, sizeof(yoko));
		for (int i = 0; i < m; i++) {
			cin >> h >> p >> q;
			yoko[h][p] = 1;
		}
		for (int i = 1000; i >= 1; i--) {
			if (yoko[i][a] == 1) a++;
			else if (yoko[i][a - 1] == 1) a--;
		}
		cout << a << endl;
	}
}

Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin >> S;
  int temp=S.length();
  
  for(int i=1;i<temp/2;i++){
    S.erase(S.length()-2);
    if(S.substr(S.length()/2)==S.substr(0,S.length()/2)){
      cout<<S.length()<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

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

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}

int main() {
	ll a, b, n;
	cin >> a >> b >> n;
	ll x;
	if (n < b) {
		x = n;
	}
	else {
		x = b - 1;
	}
	ll ans = (a*x / b) - a * (x / b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, m;
ll k[11], s[11][11], p[11];
int main() {
    cin>>n>>m;
    REP(i, 0, m){
        cin>>k[i];
        REP(j, 0, k[i]) cin>>s[i][j];
    }
    REP(i, 0, m) cin>>p[i];

    ll ans=0;
    REP(i, 0, 1<<n){
        bool flag=true;
        REP(j, 0, m){
            ll cnt=0;
            REP(l, 0, k[j]){
                if(i & 1<<(s[j][l]-1)) cnt++;
            }

            if(cnt%2!=p[j]){
                flag=false;
                break;
            }
        }

        if(flag) ans++;
    }

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

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, C; cin >> N >> C;
  ll A[N]; rep(i,N) cin >> A[i];
  ll B[N]; rep(i,N) cin >> B[i];
  ll sum[N][C+1] = {}, tnum[401] = {}; fill_n(tnum,401,1);
  rep(i,C+1) {
    rep(j,N) repr(k,A[j],B[j]+1) { sum[j][i] += tnum[k]; sum[j][i] %= MOD; }
    rep(j,401) { tnum[j] *= j; tnum[j] %= MOD; }
  }
  // rep(i,N) debug(sum[i],sum[i]+C+1);

  ll dp[N+1][C+1] = {}; dp[0][0] = 1;
  rep(i,N) {
    rep(j,C+1) {
      rep(k,j+1) {
        dp[i+1][j] += dp[i][j-k] * sum[i][k];
        dp[i+1][j] %= MOD;
      }
    }
  }
  // rep(i,N+1) debug(dp[i],dp[i]+C+1);

  ll result = dp[N][C];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 2816
#include<string>
std::string minus2(long long n) {
  std::string res = n ? "" : "0";
  for(auto p = -2ll; n; p *= -2) {
    if(n % p) res = "1" + res, n += p / 2;
    else      res = "0" + res;
  }
  return res;
}

#include<bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  cout << minus2(N) << endl;
}


Measured memory_bytes: 256
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
int n,m,k;
string s[500];
int ans[500][500];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

	int cur = 0;
	cin >> n >> m >> k;
	for(int i=1;i<=n;i++){
		cin >> s[i];
		s[i] = " " + s[i];
	}
	bool flag = true;
	int start = 0;
	for(int i=1;i<=m;i++){
		int cnt = 0;
		for(int j=1;j<=n;j++){
			if(s[j][i]=='#')cnt++;
		}
		if(cnt == 0 && flag){
			start = i;
			continue;
		}
		if(cnt){
			cur++;
			flag = false;
			int c = 0;
			for(int j=1;j<=n;j++){
				if(s[j][i]=='#' && c!=0 )cur++;
				if(s[j][i]=='#')c++;
				ans[j][i] = cur;
				//cout << cur << " " << j << " " << i << " " << c << endl; 
			}
		}
		if(!flag && cnt == 0){
			for(int j=1;j<=n;j++){
				ans[j][i] = ans[j][i-1];
			}
		}
	}
	for(int i=start;i>=1;i--){
		for(int j=1;j<=n;j++){
			ans[j][i] = ans[j][i+1];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}

    

return 0;
}
///....


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  string s;
  cin>>n>>s;
 //////全探索でいけっるかな？
  int ans=0;
  for(int i=0;i<1000;i++){
   int a,b,c;//100 10 1
    a=i/100;
    b=(i-a*100)/10;
    c=i%10;
    ////////
    
    bool oka=0,okb=0,okc=0;
    rep(j,0,n){
      
      if(!oka && s[j]==char(a)+'0') {
        oka=true;
        continue;
      }
      if(!okb && oka&&s[j]==char(b)+'0'){
        okb=1;continue;}
      if(!okc &&okb&&s[j]==char(c)+'0'){
        okc=true;
        break;
      }
    }
    if(okc) ans++;
   // if(okc) cout<<a<<b<<c<<endl;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long long sum = 0, min, max;
	int i, n, x;
	min = 1000000;
	max = -1000000;

	scanf("%d", &x);

	for (i = 0;i < x;i++)
	{
		scanf("%d", &n);
		if (max <= n)
		{
			max = n;
		}
		if (min >= n)
		{
			min = n;
		}
		sum = sum + n;
	}

	printf("%lld %lld %lld\n", min, max, sum);

	return 0;
}


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

int main() {
    int H,W;
    while (cin >> H >> W) {
        if (H == 0) {
            break;
        }
        for (int i = 0; i < H; i++) {
            for (int j= 0; j < W; j++) {
                if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
                    cout << "#";
                }
                
                else {
                  cout << ".";
                }
                
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}




Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int min = 1000000;
		int max = -1000000;
		long sum = 0;
		
		for (int i = sc.nextInt(); i > 0; i--) {
			int a = sc.nextInt();
			if (a <= min) {
				min = a;
			}
			if (a >= max) {
				max = a;
			}
			sum += a;
		}
		sc.close();
		System.out.println(min + " " + max + " " + sum);
	}
}

Measured memory_bytes: 42608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

class Main{

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
		int d1=Math.abs(b-a),d2=Math.min(Math.abs(b-a),Math.abs(c-a)),d3=Math.abs(c-b);
		int d4=Math.min(Math.abs(a-b), Math.abs(c-b)),d5=Math.abs(a-c);
		int d6=Math.min(Math.abs(a-c), Math.abs(b-c)),d7=Math.abs(a-b);
		System.out.println(Math.min(d2+d3, Math.min(d4+d5, d6+d7)));
	}
}

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



int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	ll a; double b; cin >> a >> b;

	int b_ = b *100+0.5;

	//cout << b_ << endl;

	//int b = (s[0]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0');
	
	cout << ll(a * b_ / 100) << endl;
	
	return 0;
}


Measured memory_bytes: 3668
package main

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

var scan = bufio.NewScanner(os.Stdin)

func main() {
	scanWords()
	w := readNextInt()
	h := readNextInt()
	x := readNextInt()
	y := readNextInt()
	r := readNextInt()

	result := checkCondition(w, h, x, y, r)
	if result {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func scanWords() {
	scan.Split(bufio.ScanWords)
}

func readNextInt() int {
	scan.Scan()

	input, err := strconv.Atoi(scan.Text())
	if err != nil {
		panic(err)
	}

	return input
}

func checkCondition(w, h, x, y, r int) bool {
	if x-r < 0 || y-r < 0 {
		return false
	}

	if x+r > w || y+r > h {
		return false
	}
	return true
}



Measured memory_bytes: 1112
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a; i<n; i++)
#define ll long long
#define MOD 998244353
using namespace std;;
 
int main() {
  int N, K; cin >> N >> K;
  vector<int> L(K),R(K); rep(i,0,K) cin >> L[i] >> R[i];
  vector<ll> dp(N + 1, 0); dp[0] = 1; dp[1] = -1;
  rep(i,0,N) { 
    dp[i] = ((dp[i] % MOD) + MOD) % MOD;
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    rep(j,0,K) {
      if (i + L[j] < N) dp[i + L[j]] += dp[i];
      if (i + R[j] + 1 < N) dp[i + R[j] + 1] -= dp[i];
    }
  }
  cout << dp[N - 1] << endl;
}

Measured memory_bytes: 4824
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
using namespace std;
int n;ll sum;
inline void solve(){
	vector<pii>v1,v2;
	set<int>s1,s2;
	cin>>n;sum=0;
	for(int i=1,l,r,k;i<=n;++i){
		cin>>k>>l>>r;sum+=r;
		if(l>r)v1.push_back({l-r,k});
		else v2.push_back({l-r,k});
	}
	for(int i=1;i<=v1.size();++i)s1.insert(i);
	for(int i=v1.size()+1;i<=n;++i)s2.insert(i);
	sort(v1.rbegin(),v1.rend());
	sort(v2.begin(),v2.end());
	for(int i=0;i<v1.size();++i){
		pii p=v1[i];
		set<int>::iterator it=s1.upper_bound(p.second);
		if(it!=s1.begin()){
			--it;
			s1.erase(it);
			sum+=p.first; 
		}
	}
	for(int i=0;i<v2.size();++i){
		pii p=v2[i];
		set<int>::iterator it=s2.upper_bound(p.second);
		if(it==s2.end())sum+=p.first;
		else s2.erase(it);
	}
	cout<<sum<<'\n';
}
int main(){
	ios_base::sync_with_stdio(false);
	int T;cin>>T;
	for(;T--;)solve(); 
}

Measured memory_bytes: 14080
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
	string s;
	cin >> s;
	vector<int> ans(s.size());
	int x;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'R') x = i;
		else {
			if ((i - x) % 2 == 1) ans[x + 1]++;
			else ans[x]++;
		}
	}
	for (int i = s.size() - 1; i >= 0; i--) {
		if (s[i] == 'L') x = i;
		else {
			if ((x - i) % 2 == 1) ans[x - 1]++;
			else ans[x]++;
		}
	}
	rep(i, s.size()) {
		if (i) cout << " ";
		cout << ans[i];
	}
}

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

using namespace std;

int count(vector<int> &h, const int l, const int r, const int minh)
{
    if (l == r)
        return h[l];

    int nl = -1, nminh = INT_MAX, ans = minh;
    for (int i = l; i <= r; i++)
    {
        h[i] -= minh;
        if (h[i] == 0)
        {
            if (nl >= 0)
            {
                ans += count(h, nl, i - 1, nminh);
                nl = -1;
                nminh = INT_MAX;
            }
            continue;
        }

        if (nl < 0)
        {
            nminh = h[i];
            nl = i;
        }
        else if (nl >= 0)
        {
            if (h[i] < nminh)
            {
                nminh = h[i];
            }
        }
    }

    if (nl >= 0)
        ans += count(h, nl, r, nminh);

    return ans;
}

int main()
{
    int n, min = INT_MAX, minI = -1;
    scanf("%d", &n);
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &h[i]);
        if (h[i] < min)
        {
            min = h[i];
            minI = i;
        }
    }

    printf("%d\n", count(h, 0, n - 1, min));

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        boolean op = sc.next().equals("+");
        int b = Integer.parseInt(sc.next());
        if (op)
            System.out.println(a + b);
        else
            System.out.println(a - b);
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

const int COUNT = 6;


class Dice
{
private:
	int num[6];

public:
	Dice();
	void play_dice(string);
	void play(int, int, int, int);
	void print_(int x) {printf("%d\n", num[x]);}
	void to_top_and_front(int, int);
};

Dice::Dice()
{
	for (int i = 0; i < COUNT; ++i)
	{
		cin >> num[i];
		
	}
}


void Dice::play_dice(string s)
{
	if(s == "E") {play(0, 2, 5, 3); }
		
	if(s == "N") {play(0, 4, 5, 1); }
		
	if(s == "S") {play(0, 1, 5, 4); }
	
	if(s == "W") {play(0, 3, 5, 2); }
}

void Dice::play(int a, int b, int c, int d)
{
	int temp;
	temp = num[d]; num[d] = num[c]; num[c] = num[b]; num[b] = num[a]; num[a] = temp;
}


void Dice::to_top_and_front(int top, int front)
{
	string str[7] = {"N", "N", "N", "W", "N", "N", "N"};
	for (int i = 0; i < 7; ++i)
	{
		if(front == num[1]) break;
		play_dice(str[i]);
	}
	while(top != num[0])
	{
		play_dice("W");
	}
}


int main(int argc, char const *argv[])
{
	Dice c;
	int count = 0;
	cin >> count;
	int top = 0, front = 0;
	
	for (int i = 0; i < count; ++i)
	{
		cin >> top >> front;
		c.to_top_and_front(top, front);
		c.print_(2);
	}

	return 0;
}

Measured memory_bytes: 1188
import math

(n,m,o) = map(float, raw_input().split())
#s=(n+m+o)/2.0
c=math.radians(o)
cs=math.sqrt(n**2+m**2-2*n*m*math.cos(c))
h=m*math.sin(c)
#ans=(s*(s-m)*(s-n)*(s-o))**0.5
#print ((n-o)**2 + (m-p)**2)**0.5
#print ans
S=h*n/2
L=n+m+cs
print S
print L
print h

Measured memory_bytes: 4432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int x[200010],sorted[200010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",x+i);
		sorted[i]=x[i];
	}
	sort(sorted+1,sorted+1+n);
	for(int i=1;i<=n;i++){
		int pos=lower_bound(sorted+1,sorted+1+n,x[i])-sorted;
		if(pos<=(n>>1)) printf("%d\n",sorted[(n>>1)+1]);
		else printf("%d\n",sorted[n>>1]);
	}
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>

using namespace std;

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

	if (k % 2 == 0) {
		cout << a - b << endl;
	}
	else {
		cout << b - a << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 2e5+9;
bool check(string s) {
    int n = s.size();
    if(~n & 1) return 0;
    if(n == 1) return 1;
    string t = s;
    reverse(t.begin(), t.end());
    return s == t && check(s.substr(0, (n-1)/2));
}
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    int l; cin >> l;
    cout << fixed << setprecision(15) << l*l*l/27.l << endl;



    return 0;
    
}

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

int main() {
	int n , m;
	cin >> n >> m;
	vector<vector<int>> g(m,vector<int>(2));
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < 2; j++) {
			cin >> g[i][j];
		}
	}
	int l = 1, r = n;
	for (int i = 0; i < m; i++) {
		if(g[i][0] > l) l = g[i][0];
		if (g[i][1] < r) {
			r = g[i][1];
		}
	}
	if (r - l < 0) {
		cout << 0 << endl;
	}
	else cout << r - l + 1 << endl;
}


Measured memory_bytes: 5760
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    int n, x, t;
    cin >> n >> x >> t;
    auto ans = (n + x - 1) / x * t;
    cout << ans << endl;
    return 0;
}


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

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

        if (a>b) {t=a; a=b; b=t;};
        if (b>c) {t=b; b=c; c=t;};
        if (a>b) {t=a; a=b; b=t;};

        cout << a << " " << b << " " << c<< endl;
        return 0;
}

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

using namespace std;

char get(int a, int b, int c) {
    long long a1, a2, b1, b2, x, y, l, r, m;
    
    l = 0, r = max(a, b), m = (l + r) / 2;
    
    while (r - l > 1) {
        a1 = (a + m - 1) / m;
        a2 = a;
        b1 = (b + m - 1) / m;
        b2 = b;
        
        if (a1 > b2 + 1 || b1 > a2 + 1) {
            l = m;
            m = (l + r) / 2;
        } else {
            r = m;
            m = (l + r) / 2;
        }
    }
    
    x = r;
    
    l = 0, r = a / x + 1, m = (l + r) / 2;
    
    while (r - l > 1) {
        long long aa = a - m * x;
        long long bb = b - m;
        
        if (aa < 0 || bb < 0 || bb > aa * x) {
            r = m;
            m = (l + r) / 2;
        } else {
            l = m;
            m = (l + r) / 2;
        }
    }
    
    y = l;
    
    if (c < y * (x + 1)) {
        if (c % (x + 1) == x) {
            return 'B';
        } else {
            return 'A';
        }
    }
    
    a -= y * x;
    b -= y;
    c -= y * (x + 1);
    
    if (b == 0) return 'A';
    
    if (b % x == 0) {
        long long z = b / x - 1;
        
        if (c < a - z) {
            return 'A';
        } else {
            c -= a - z;
            if (c % (x + 1) == x) {
                return 'A';
            } else {
                return 'B';
            }
        }
    } else {
        long long z = b / x;
        
        if (c < a - z) {
            return 'A';
        } else if (c < a - z + b % x) {
            return 'B';
        } else {
            c -= a - z + b % x;
            if (c % (x + 1) == 0) {
                return 'A';
            } else {
                return 'B';
            }
        }
    }
}

int main() {
    int q, i, j;
    
    scanf("%d", &q);
    
    for (i = 0; i < q; i++) {
        int a, b, c, d;
        
        scanf("%d %d %d %d", &a, &b, &c, &d);
        
        for (j = c; j <= d; j++) putchar(get(a, b, j - 1));
        puts("");
    }
    
    return 0;
}


Measured memory_bytes: 256
import math
A,B=list(map(int,input().split()))
ans=-1
start=math.ceil(B*(10))
cntr=start
end=math.ceil((B+1)*(10))
while(cntr<end):
    if(math.floor(cntr*0.08)==A):
        ans=cntr
        break
    else:
        cntr+=1
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int S, T;
        cin >> S >> T;

        
                cout << S*S-T << endl;
        

        return 0;
}


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

void solve(void)
{
    string s;
    cin >> s;
    map<char, int> mp;
    for (auto i : s)
        mp[i]++;
    if (mp['N'] > 0 && mp['S'] > 0 && mp['E'] > 0 && mp['W'] > 0)
        cout << "Yes" << endl;
    else if (mp['N'] > 0 && mp['S'] > 0 && mp['E'] == 0 && mp['W'] == 0)
        cout << "Yes" << endl;
    else if (mp['N'] == 0 && mp['S'] == 0 && mp['E'] > 0 && mp['W'] > 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
int main(void)
{
    solve();
}

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

int main(){
	int m,d;
	cin>>m>>d;
	int ct = 0;
	for(int i=1;i<=m;i++){
		for(int j = 10;j<=d;j++){
			int d1 = j%10;
			int d2 = j/10;
			if(d1 >= 2 and d2 >= 2 and d1 * d2 == i)
				ct++;
		}
	}
	cout<<ct;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            a = int.Parse(Console.ReadLine());
            if (a == 3 || a == 5 || a == 7)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            Console.ReadKey();
        }
    }
}


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

int main(void)
{
  int n;
  cin >> n;
  while(1)
  {
    bool can = true;
    for(int i = 2; i < n; i++)
    {
      if(n % i == 0)
      {
        can = false;
      }
    }
    if(can)
    {
      cout << n << endl;
      break;
    }else{
      n++;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <fstream>
#include <string.h>
#pragma GCC optimize("Ofast") //高速化
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//小数点計算
using namespace std;
//strtok(str, ",");  //","で分解
#define prf(f) printf("%f\n", f) //double
#define prc(c) printf("%c\n", c) //char
#define prs(s) printf("%s\n", n) //string
#define prd(d) printf("%d\n", d) //int
#define gno cin.ignore() //一文字無視
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, f, n) for(int i = f; i < n; i++)
#define ch(s1, N) (s1[0]+N) //文字列入れ替え
#define gl(s1) getline(cin,s1) //一列読み込み（一文字無視を使用する）
int main(){
	//cinの高速化
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
		int a , b, c;
		cin >> a >> b;
		c = a * (a-1) /2;
		c = c + b * (b-1) /2;
		cout << c;
		return 0;
}

Measured memory_bytes: 888
# cook your dish here
# from math import * 
#for _ in range(int(input().strip())):

order=['+++','++-','+-+','+--','-++','-+-','--+','---']

s=input()
flag=-1
for i in range(8):
    ans=int(s[0])
    for j in range(1,len(s)):
        if order[i][j-1]=='+':
            ans+=(int(s[j]))
        else:
            ans-=(int(s[j]))
    if ans==7:
        flag=i
#print(flag)
if flag>-1:
    for i in range(3):
        print(s[i],order[flag][i],sep="",end="")
    print(s[3],"=7",sep="")

Measured memory_bytes: 3064
import sys
from collections import deque
input = sys.stdin.buffer.readline

def bfs(v):
    dist = [-1 for _ in range(n)]
    dist[v] = 0
    q = deque()
    q.append(v)

    while len(q) > 0:
        u = q.popleft()
        for nv in g[u]:
            if dist[nv] == -1:
                dist[nv] = dist[u] + 1
                q.append(nv)
    for d in dist:
        ans[d] += 1
n, x, y = map(int,input().split())
g = [[] for _ in range(n)]
for i in range(n - 1):
    g[i].append(i + 1)
    g[i+1].append(i)
g[x - 1].append(y - 1)
g[y - 1].append(x - 1)
ans = [0]*n
for i in range(n):
    bfs(i)
for i in range(1,n):
    print(ans[i]//2)

Measured memory_bytes: 4208
class Combination:
    '''MOD上の
    計算量：階乗・逆元テーブルの作成O(N)
    nCkを求めるO(1)'''

    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [pow(self.fact[i], MOD - 2, MOD) for i in range(n + 1)]
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD

n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
comb = Combination(n, MOD)

effi = [0] * n
effi[0] = 1
for i in range(n - 1):
    effi[i + 1] = effi[i] + pow(i + 2, MOD - 2, MOD)
    effi[i + 1] %= MOD

ans = 0
for i in range(n - 1):
    ans += effi[i] * (a[i+1] - a[i])
    ans %= MOD

print(ans * comb.factorial(n - 1) % MOD)

Measured memory_bytes: 65304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(d<=a){
      cout<<d;
  }
  else{
      if(d<=a+b){
          cout<<a;
      }
      else{
          cout<<a+(d-a-b)*(-1);
      }
  }
}

Measured memory_bytes: 3636
n = gets.chomp.to_i
k = gets.chomp.to_i
a = gets.chomp.split.map &:to_i
ans = 0
n.times do |i|
  if (a[i]-0).abs > (a[i]-k).abs
    ans += (a[i]-k).abs*2
  elsif (a[i]-0).abs < (a[i]-k).abs
    ans += (a[i]-0).abs*2
  else
    ans += (a[i]-0).abs*2
  end
end
puts ans


Measured memory_bytes: 1788