akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n=3,m;
    vii a(n,vi(n));
    FOR(i,0,n){
        FOR(j,0,3){
            cin>>a[i][j];
        }
    }
    cin>>m;
    vi b(m);
    FOR(k,0,m){
        cin>>b[k];
        FOR(i,0,n){
            FOR(j,0,3){
                if(a[i][j]==b[k]){
                    a[i][j]=mod;
                }
            }
        }
    }
    FOR(i,0,n){
        int f=1;
        FOR(j,0,n){
            if(a[i][j]!=mod){
                f=0;
            }
        }
        if(f){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    FOR(i,0,n){
        int f=1;
        FOR(j,0,n){
            if(a[j][i]!=mod){
                f=0;
            }
        }
        if(f){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    if(1){
        int f=1;
        FOR(i,0,n){
            if(a[i][i]!=mod){
                f=0;
            }
        }
        if(f){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    if(1){
        int f=1;
        FOR(i,0,n){
            if(a[i][n-1-i]!=mod){
                f=0;
            }
        }
        if(f){
            cout<<"Yes"<<endl;
            return 0;
        }
    }


    cout<<"No"<<endl;

}


Measured memory_bytes: 256
use std::cmp;

const MOD: usize = 998244353;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let red: Vec<usize> = sc.chars().iter().map(|&c| c as usize - '0' as usize).collect();
    let n = red.len();

    let mut dp = vec![0; 2 * n + 1];
    dp[red[0]] = 1;
    for turn in 0..(2 * n) {
        let mut next = vec![0; 2 * n + 1];

        let cur_balls = 2 * cmp::min(turn + 1, n) - turn;
        let supplied_red = if turn + 1 < n { red[turn + 1] } else { 0 };

        for cur_red in 0..(cur_balls + 1) {
            if cur_red > 0 {
                // pop red
                next[cur_red + supplied_red - 1] += dp[cur_red];
                next[cur_red + supplied_red - 1] %= MOD;
            }
            if cur_balls - cur_red > 0 {
                // pop blue
                next[cur_red + supplied_red] += dp[cur_red];
                next[cur_red + supplied_red] %= MOD;
            }
        }

        dp = next;
    }

    println!("{}", dp[0]);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4476
function Main(input)
{
	input = input % 10;
	var d = "";

	if (input == 3)
	{
		d = "bon";
	}else if ([2, 4, 5, 7, 9].includes(input))
	{
		d = "hon";
	}else{
		d = "pon";
	}

	console.log(d);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29508
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define mod 1000000007
#define F first
#define S second
#define mk make_pair
#define B(v) v.begin(), v.end()
int main()
{	
	int n;
	cin>>n;
	int a[n+10];
	map<int,int>mp;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
	}
	int ans=0;
	for(auto it:mp)
	{
		if(it.S%2)
		{	
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    ll c1 = a*c;
    ll c2 = a*d;
    ll c3 = b*c;
    ll c4 = b*d;
    cout << max({c1,c2,c3,c4}) << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

struct RSQ{
  ll size;
  ll *tree;
  RSQ(ll sz){
    ll logsize; for(logsize=0;(1ll<<logsize)<=sz;logsize++);
    size=(1ll<<logsize);
    tree=new ll[size*2-1];
    REP(i,size*2-1) tree[i]=0;
  }
  void add(ll i,ll x){
    ll k=i+size-1;
    tree[k]+=x;
    while(k>0){
      k=(k-1)/2;
      tree[k]+=x;
    }
  }
  ll getSum(ll s,ll t,ll l,ll r,ll k){
    if(t<=l||r<=s||l>=r) return 0;
    if(l+1==r) return tree[k];
    if(s<=l&&r<=t) return tree[k];
    ll mid=(l+r+1)/2;
    return getSum(s,t,l,mid,k*2+1)+getSum(s,t,mid,r,k*2+2);
  }
  ll getSum(ll s,ll t){
    return getSum(s,t,0,size,0);
  }
};

int main(){
  ll n,q; cin>>n>>q;
  RSQ rsq(n);
  REP(i,q){
    ll com,x,y; cin>>com>>x>>y;
    if(com==0) rsq.add(x,y);
    else cout<<rsq.getSum(x,y+1)<<endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  vi x(n);
  rep(i, n) cin >> x[i];
  int ans = 1e9;
  rep2(i, 1, 101) {
    int sum = 0;
    rep(j, n) sum += pow(x[j] - i, 2);
    ans = min(ans, sum);
  }
  cout << ans << endl;
}

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

typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }

    int las = -1;
    for (int i=0; i<n-1; i++) {
        if (a.at(i) + a.at(i+1) >= l) {
            las = i + 1;
            break;
        }
    }
    if (las == -1) {
        cout << "Impossible" << '\n';
    } else {
        cout << "Possible" << '\n';
        for (int i=1; i<las; i++) {
            cout << i << '\n';
        }
        for (int i=n-1; i>=las; i--) {
            cout << i << '\n';
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

auto merge(vector<int> &A, int left, int mid, int right) {
  int nl = mid - left, nr = right - mid;
  vector<int> L(nl + 1), R(nr + 1);
  L[nl] = INT_MAX;
  R[nr] = INT_MAX;
  copy(A.begin() + left, A.begin() + mid, L.begin());
  copy(A.begin() + mid, A.begin() + right, R.begin());

  int il = 0, ir = 0;
  long cnt = 0;
  for (int c = left; c < right; c++) {
    if (L[il] > R[ir]) {
      A[il + ir + left] = R[ir];
      cnt += nl - il;
      ir++;
    } else {
      A[il + ir + left] = L[il];
      il++;
    }
  }
  return cnt;
}

auto mergeSort(vector<int> &A, int left, int right) {
  if ((right - left) <= 1) return 0L;
  int mid = (left + right) / 2;
  auto L_cnt = mergeSort(A, left, mid);
  auto R_cnt = mergeSort(A, mid, right);
  auto merged_cnt = merge(A, left, mid, right);
  return L_cnt + R_cnt + merged_cnt;
}
int main() {
  int n, CNT = 0;
  cin >> n;
  vector<int> A(n);
  for (size_t i = 0; i < n; i++) {
    cin >> A[i];
  }

  cout << mergeSort(A, 0, n) << endl;
}


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

using namespace std;

typedef long long ll;
const int N=3e5+9;

inline ll read()
{
    ll x=0;char ch=getchar();
    while(ch<'0' || '9'<ch)ch=getchar();
    while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
    return x;
}

ll n,a[N];

int main()
{
    if(fopen("vj.in","r"))
    {
        freopen("vj.in","r",stdin);
        freopen("vj.out","w",stdout);
    }

	n=read();
	for(int i=1;i<=n*3;i++)
		a[i]=read();
	sort(a+1,a+n*3+1);
	reverse(a+1,a+n*3+1);
	ll ans=0;
	for(int i=1;i<=n;i++)
		ans+=a[i*2];
	printf("%lld\n",ans);
    return 0;
}

                    


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>

using namespace std;

int main() {
	int n; 
	while (cin >> n && n) {
		vector<int> x(n, 0);
		vector<int> y(n, 0);
		int xmax = 0, ymax = 0, xmin = 0, ymin = 0;
		int dix[] = { 0,1,0,-1 }, diy[] = { -1,0,1,0 };
		for (int i = 1; i < n; ++i) {
			int no, d; cin >> no >> d;
			x[i] = x[no] + dix[d];
			y[i] = y[no] + diy[d];
			xmax = max(xmax, x[i]);
			ymax = max(ymax, y[i]);
			xmin = min(xmin, x[i]);
			ymin = min(ymin, y[i]);
		}
		cout << ymax - ymin + 1 << " " << xmax - xmin + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3052
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

### そもそもクーポン使わない最小の組み合わせを初期値とする
smallest = min(a) + min(b)
for i in range(M):
    x, y, c = list(map(int, input().split()))
    x -= 1
    y -= 1
    price = a[x] + b[y] - c
    smallest = min(smallest, price)
print(smallest)


Measured memory_bytes: 18736
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a;
    cin>>b;
    cin>>c;
    cin>>d;
    if(abs(a-c)<=d){
        cout<<"Yes"<<endl;
        return 0;
    } else if(abs(a-b)<=d&&abs(b-c)<=d){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   int N;
   int count = 0;
   string s;
   cin >> s;
   N = s.size();
   for(int i = 0;i<N;i++){
     if(s[i] != s[N-1-i]){
          count++;
     }
   }
   cout << count /2 << endl;
}

Measured memory_bytes: 3588
// https://atcoder.jp/contests/abc049/tasks/arc065_a

// 探索文字の内、どれかが別の部分文字列になっているようなケースをprefixという。
// こういう場合の探索は一筋縄では行かない。

// この問題の場合、文字列を逆順にするとprefixになる組み合わせがなくなるので、
// 単純なループ探索で解けるようになる。

package main

import (
	"fmt"
	"strings"
)

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

func main() {
	var s string

	fmt.Scan(&s)

	s = reverse(s)

	ds := [4]string{reverse("dream"),
		reverse("dreamer"),
		reverse("erase"),
		reverse("eraser"),
	}

	for len(s) > 0 {
		trimmed := false
		for _, d := range ds {
			if strings.HasPrefix(s, d) {
				s = s[len(d):]
				trimmed = true
				break
			}
		}
		if !trimmed {
			fmt.Println("NO")
			return
		}
	}
	if len(s) == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1792
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n; cin >> n;

	LL tb[5] = {};

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

		char initial = buf[0];
		
		if (initial == 'M')tb[0]++;
		if (initial == 'A')tb[1]++;
		if (initial == 'R')tb[2]++;
		if (initial == 'C')tb[3]++;
		if (initial == 'H')tb[4]++;
	}
	LL ans = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 4; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += tb[i] * tb[j] * tb[k];
			}
		}
	}

	cout << ans << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/05/26  Problem: ABC 128 C / Link: http://abc128.contest.atcoder.jp/tasks/abc128_c  ----- */


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

	LL N, M; cin >> N >> M;

	VVI s(M);
	FOR(i, 0, M) {
		int k; cin >> k;
		FOR(j, 0, k) {
			int a; cin >> a;
			a--;
			s[i].push_back(a);
		}
	}
	VI p(M);
	FOR(i, 0, M) {
		cin >> p[i];
	}
	LL ans = 0;
	FOR(state, 0, 1 << N) {
		int cnt = 0;
		FOR(i, 0, M) {
			int c = 0;
			for (auto it : s[i]) {
				if (state & 1 << it)c++;
			}
			if (c % 2 == p[i])cnt++;
		}
		if (cnt == M)ans++;
	}


	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,sum,a[100005],cnt,t;
int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum += a[i];
    }
    if (sum % (n * (n+1)/2)) return printf("NO"),0;
    cnt = t = sum / (n*(n+1)/2);
    for(int i=0;i<n;i++){
        ll delta = - a[(i- 1+n)%n] + a[i] - t;
        if (delta > 0) return printf("NO"),0;
        if (delta % n != 0) return printf("NO"),0;
        cnt += delta / n;
    }
    if (cnt) return printf("NO"),0;
    printf("YES");
}


Measured memory_bytes: 1024
<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);
fscanf(STDIN, "%s", $S);
$S = str_replace("BC", "D", $S);
$len = strlen($S);
$ans = 0;
$cnt = $streak = 0;
$streak = 0;
for ($i = 0; $i < $len; $i++) {
    if ($S[$i] === 'A' || $S[$i] === 'D') {
        $streak++;
        if ($S[$i] === 'A') {
            $cnt++;
        } else {
            $ans += $cnt;
        }
    } else {
        $cnt = $streak = 0;
    }
}
echo $ans;


Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <vector>

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=jp
// 安定ソート
static void printArray(vector<string> vector) {
    int size = vector.size();
    for (int i = 0; i < size; ++i) {
        if (i == size - 1) {
            cout << vector[i] << endl;
        } else {
            cout << vector[i] << " ";
        }
    }
}

static string isStable(vector<string> in, vector<string> out) {
    int N = in.size();
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            for (int a = 0; a < N; ++a) {
                for (int b = a + 1; b < N; ++b) {
                    if (in[i].substr(1, 1) == in[j].substr(1, 1) && in[i] == out[b] && in[j] == out[a]) {
                        return "Not stable";
                    }
                }
            }
        }
    }
    return "Stable";
}


int main() {
    int N;
    cin >> N;
    vector<string> cards(N);

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

    vector<string> bubbleCards(N);
    bubbleCards = cards;

    vector<string> selectionCards(N);
    selectionCards = cards;

    // Bubble Sort
    for (int i = 0; i < N; ++i) {
        for (int j = N - 1; j > i; --j) {
            if (bubbleCards[j].substr(1, 1) < bubbleCards[j - 1].substr(1, 1)) {
                swap(bubbleCards[j], bubbleCards[j - 1]);
            }
        }
    }

    // printArray(bubbleCards);
    // cout << isStable(cards, bubbleCards) << endl;

    // Selection Sort
    for (int i = 0; i < N; ++i) {
        int minj = i;
        for (int j = i; j < N; ++j) {
            if (selectionCards[j].substr(1, 1) < selectionCards[minj].substr(1, 1)) {
                minj = j;
            }
        }
        swap(selectionCards[i], selectionCards[minj]);
    }


    printArray(bubbleCards);
    cout << isStable(cards, bubbleCards) << endl;

    printArray(selectionCards);
    cout << isStable(cards, selectionCards) << endl;
    return 0;
}




Measured memory_bytes: 3184
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-8-11 21:05:07
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
ll M;
map<ll, ll> X;
ll A[100010];

int main()
{
  cin >> N >> M;
  for (auto i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  ll sum = 0;
  ll ans = 0;
  for (auto i = 0; i < N; i++)
  {
    if (X.find(sum) == X.end())
    {
      X[sum] = 1;
    }
    else
    {
      X[sum]++;
    }
    sum += A[i];
    sum %= M;
    ans += X[sum];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
from collections import deque
h,w=map(int,input().split())
s=[input() for _ in range(h)]
def bfs(maze,visited,sy,sx):
  queue=deque([[sy,sx]])
  visited[sy][sx]=1
  while queue:
    y,x=queue.popleft()
    if [y,x]==[h-1,w-1]:
      return visited[y][x]
    for j,k in ([1,0],[-1,0],[0,1],[0,-1]):
      n_y,n_x=y+j,x+k
      if not (0<=n_y<h and 0<=n_x<w):
        continue
      if maze[n_y][n_x]=='.' and visited[n_y][n_x]==0:
        visited[n_y][n_x]=visited[y][x]+1
        queue.append([n_y,n_x])
  return -1
cnt=0
for i in s:
  cnt+=i.count('.')
visited=[[0]*w for _ in range(h)]
route=bfs(s,visited,0,0)
print(-1 if route<0 else cnt-route)

Measured memory_bytes: 3316
#include <cstdio>
#define min(a,b) ((a)<=(b)?(a):(b))
int toC(int A,int B,int C) {
	if(A==0&&B==0) return 0;
	if(C&1) return toC(A>>1,B>>1,C>>1);
	if(B&1) return toC(C>>1,B>>1,A>>1)+1+toC((A|B|C)>>1,0,0);
	if(A&1) return toC(A>>1,B>>1,C>>1)+2*toC((A|B|C)>>1,0,0)+2;
}
int main() {
	int n,m;
	while(scanf("%d %d",&n,&m),n) {
		int x,y,z[3]={0};
		for(int i=0;i<3;i++) {
			scanf("%d",&x);
			for(int j=0;j<x;j++) {
				scanf("%d",&y);
				z[i]|=1<<(y-1);
			}
		}
		int mn=min(toC(z[0],z[1],z[2]),toC(z[2],z[1],z[0]));
		printf("%d\n",mn<=m?mn:-1);
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e17;
const int mod = 1e9 + 7;

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> G(N + 1);
    vector<vector<int>> dist(N, vector<int>(N, inf));
    for (int i = 0; i < N; i++) {
        string temp;
        cin >> temp;
        for (int j = 0; j < N; j++) {
            if (temp[j] == '1') {
                dist[i][j] = 1;
                G[i].push_back(j);
            }
        }
    }
    vector<int> bipartite(N + 1, -1);
    function<bool(int, bool)> check = [&](int next, bool count) {
        if (bipartite[next] == -1) {
            bipartite[next] = count;
            for (auto i : G[next]) {
                if (!check(i, !count)) return false;
            }
        }
        else if (bipartite[next] != count) return false;
        return true;
    };
    if (!check(0, false)) {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0; i < N; i++) dist[i][i] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) ans = max(ans, *max_element(dist[i].begin(), dist[i].end()));
    cout << ans + 1 << endl;
}


Measured memory_bytes: 1024
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    P = 2019

    ans,base = 0,1
    MOD_list = [0]

    for st in S[::-1]:
        num = int(st)
        MOD = (MOD_list[-1]+num*base)%P
        MOD_list.append(MOD)
        base *= 10
        base %= P

    c = Counter(MOD_list)
    for v in c.values():
        ans += (v*(v-1))//2
        
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 87364
#include<iostream>
#include<string>

using namespace std;

int main (){

  string in;

  while(cin >> in){

    for(int i = 0; i < in.length(); i++){
      if(in[i] == 'A'){
	in[i] = 'X';
	continue;
      }
      if(in[i] == 'B'){
	in[i] = 'Y';
	continue;
      }
      if(in[i] == 'C'){
	in[i] = 'Z';
	continue;
      }

      in[i] -= 3;
    }


    cout << in << endl;

  }

  return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
#define MOD 1e9+7

int main(){
	int A, B;
	cin >> A >> B;
	if((A+B)%2 == 0){
		cout << min(A,B) + abs(A-B) / 2 << endl;;
	}
	else{
		cout << "IMPOSSIBLE" << endl;
	}
}

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

int main() {

	long long n,i,j,k,sum=0,count=0,ans=0,x,c,d,mx=0,mn=1000000;
	cin>>n;
    long long a[n],b[n];
    vector<pair<long long ,long long>>v;
    for(i=0;i<n;i++)
    {cin>>a[i]>>b[i];
     v.push_back(make_pair(b[i],a[i]));
    }
    sort(v.begin(),v.end());
    k=1;
    for(i=0;i<n;i++)
    {
        count+=v[i].second;
        if(count<=v[i].first)
        k=1;
        else
        {
            k=0; break;
        }
    }
    if(k==1)
    cout<<"Yes";
    else cout<<"No";
	return 0;
}


Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N;
  cin >> N;
  int64_t mod = 1000000007;
  vector<int64_t> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  vector<int64_t> cnt(60);
  for(int i=0; i<N; i++){
    int64_t j = 2;
    int num = 0;
    for(int k=0; k<60; k++){
      if(vec.at(i) %j >= (j/2)){
        cnt.at(num)++;
      }
      j*=2;
      num++;
    }
  }
  
  int64_t ans = 0;
  int64_t j = 1;
  for(int i=0; i<60; i++){
    int64_t pre = (N - cnt.at(i)) * cnt.at(i);
    int64_t j_pre = j %mod;
    pre %= mod;
    pre *= j_pre;
    pre %= mod;
    ans += pre;
    ans %= mod;
    j *= 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define vrep(vec, vecs) for(auto& vec : vecs)
#define all(x) (x).begin(), (x).end()

struct e { int v, id; };

int main() {
	int n;
	cin >> n;

	vector<vector<e>> G(n);
	vector<int> ans(n-1);

	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;		

		G[a].push_back(e{ b, i });
		G[b].push_back(e{ a, i });		
	}

	queue<e>q;
	q.push(e{ 0,-1 });
	vector<int> visited(n, false);
	int cur = 0;

	while (!q.empty() && cur < n) {
		e t = q.front();
		q.pop();
		
		if (visited[t.v]) continue;
		visited[t.v] = true;

		cur++;
		int k = 0;

		vrep(u, G[t.v]) {
			if (visited[u.v]) continue;
			if (t.id == k) k++;

			ans[u.id] = k;
			q.push(e{ u.v, k });
			k++;
		}
	}

 	cout << *max_element(all(ans))+1 << endl;
  	vrep(a, ans) cout << a+1 << endl;

	return 0;
}

Measured memory_bytes: 7424
N=int(input())
a=[0,]*9
rates=list(map(int,input().split()))
for i in range(N):
    rank=int(rates[i]/400)
    if rank>8:
        rank=8
    a[rank]+=1
variation=0
for i in range(8):
    if a[i] > 0:
        variation+=1
if variation==0:
    print("1 " + str(a[8]))
else:
    print(str(variation)+" "+str(variation+a[8]))

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        int count = 0;
        String[] a = new String[2];
        int[] b = new int[2];
        Scanner sc = new Scanner(System.in);
        for(int i = 0;i < 2;i++){
        a[i] = sc.next();
        }
        for(int i = 0;i<2;i++){
        b[i]=Integer.parseInt(a[i]);    
        }
        if(b[0]>=b[1]){
            count += 10;
        }
        System.out.println(count);

    }
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define N 200001
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
vector <P> G[N];
ll n;
ll par[N];
ll Rank[N];
ll Cnt[N];

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    Rank[i]=0;
    Cnt[i]=1;
  }
}

ll find(int x){
  if(par[x]==x)return x;
  return par[x]=find(par[x]);
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(Rank[x]<Rank[y]){
    par[x]=y;
    Cnt[y]+=Cnt[x];
    Cnt[x]=0;
  }
  else{ 
    par[y]=x;
    Cnt[x]+=Cnt[y];
    Cnt[y]=0;
    if(Rank[x]==Rank[y])Rank[x]++;
  }
}

bool same(int x,int y){return find(x)==find(y);}

vector<PP> path;

ll solve(){
  ll res=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<G[i].size();j++) 
      path.push_back(PP(G[i][j].f,P(i,G[i][j].s)));

  sort(path.begin(),path.end());
  for(int i=0;i<path.size();i++){
    int a=path[i].s.f;
    int b=path[i].s.s;
    int c=path[i].f;
    if(same(a,b))continue;
    res+=(Cnt[find(a)]*Cnt[find(b)])*c;
    unite(a,b);
  }
  return res;
}


int main(){
  init(N);
  cin>>n;
  for(int i=1,a,b,c;i<n;i++){
    cin>>a>>b>>c;
    G[a].push_back(P(c,b));
    G[b].push_back(P(c,a));
  }
  cout <<solve()<<endl;
  return 0;
}

Measured memory_bytes: 34764
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main() {
    int N;cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++) {cin >> a[i];a[i]--;}
    int ans=0;
    for(int i=0;i<N;i++){
        if(a[a[i]] == i) ans++;
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {

	int n;
	cin >> n;
	vector<pair<string, int>>s(n);
	vector<pair<string, int>>a(n);

	for (int i = 0; i < n; i++) {
		cin >> s[i].first >> s[i].second;
		s[i].second = 100 - s[i].second;
		a[i].first = s[i].first;
		a[i].second = s[i].second;
	}



	sort(s.begin(), s.end());

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
			if (s[i] == a[j]) {
				cout << j + 1 << endl;
				break;
			}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back
using namespace std;
typedef long long int ll;
int  main(){
	ll n,m;
	cin>>n>>m;
	if(m==n){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class Dinic{
public:
  
  struct edge{
    int to,cap,rev;
    edge(){};
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){};
  };

  int V;
  vector<vector<edge> > G; //グラフの隣接リスト表現
  vector<int> level;       //sからの距離
  vector<int> iter;        //どこまで調べ終わったか
  int INF;
  
  Dinic():V(-1){};
  Dinic(int V,int INF=1e9):V(V),G(V),level(V),iter(V),INF(INF){}

  //fromからtoへ向かう容量capの辺をグラフに追加。
  void add_edge(int from,int to,int cap){
    assert(from < V && to < V);
    G[from].push_back(edge(to,cap,G[to].size()));
    G[to].push_back(edge(from,0,G[from].size()-1));
  }

  //sからの最短距離をBFSで計算する
  void bfs(int s){
    level.clear(); level.resize(V,-1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
      int v = que.front(); que.pop();
      for(edge &e : G[v])
        if(e.cap > 0 && level[e.to] < 0){
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
    }
  }

  //増加パスをDFSで探す。
  int dfs(int v,int t,int f){
    if(v==t) return f;
    for(int &i= iter[v]; i<(int)G[v].size(); i++){
      edge &e = G[v][i];
      if(e.cap > 0 && level[v] < level[e.to]){
        int d = dfs(e.to, t, min(f, e.cap));
        if(d > 0){
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  //sからtへの最大流を求める
  int max_flow(int s,int t){
    assert(V >= 0);
    int flow=0;
    for(;;){
      bfs(s);
      if(level[t] < 0) return flow;
      iter.clear();iter.resize(V,0);
      int f;
      while((f=dfs(s ,t ,INF)) > 0 ) flow += f;
    }
  }
};


signed main(){
  int n;
  cin>>n;
  vector<P> A(n);
  vector<P> B(n);
  cin>>A>>B;

  Dinic C(n + n + 10);
  const int S = n + n + 8,T = S - 1;
  for(int i=0;i<n;i++) C.add_edge(S,i,1);
  for(int i=0;i<n;i++) C.add_edge(i+n,T,1);

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
      int a,b; tie(a,b) = A[i];
      int c,d; tie(c,d) = B[j];
      if(a < c && b < d) C.add_edge(i,n+j,1);
    }

  int ans = C.max_flow(S,T);
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;
    rep(i, a, b+1){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3588
N,A,B,K=map(int,input().split())
P=998244353
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,P)[0]
Fact=[0 for i in range(N+1)]
Finv=[0 for i in range(N+1)]
Fact[0]=1
Finv[0]=1
for i in range(1,N+1):
    Fact[i]=(i*Fact[i-1])%P
    Finv[i]=(Finv[i-1]*inv(i))%P
def NC(k):
    tmp=(Finv[k]*Finv[N-k])%P
    return (Fact[N]*tmp)%P
ans=0
for s in range(N+1):
    t=(K-s*A)//B
    if s*A+t*B==K and 0<=t<=N:
        ans+=(NC(s)*NC(t))%P
print(ans%P)



Measured memory_bytes: 67084
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

    
    string s;
    cin >> s;

    int cnt = 0;
    int ans = 0;

    REPinit(i, 0, s.size()) {
        if (s[i] == 'R') {
            cnt++;
        }
        else {
            cnt = 0;
        }
        ans = max(cnt, ans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    int N;cin>>N;
    vector<int> T(13,0);
    for(int i=0;i<N;i++){
        int a;cin>>a;
        T[a]++;
    }
    bool ok=true;
    if(T[0]) ok=false;
    for(int i=0;i<13;i++){
        if(T[i]>2) ok=false;
    }

    if(!ok) cout<<0<<endl;
    else{
        int ans=0;
        for(int bit=0;bit<(1<<12);bit++){
            vector<int> S(24,0);
            S[0]=1;
            for(int i=0;i<13;i++){
                if(T[i]==0) continue;
                if(T[i]==2){
                    S[i]++;
                    S[24-i]++;
                }else{
                    if(bit&(1<<(i-1))){
                        S[i]++;
                    }else S[24-i]++;
                }
            }
            int m=INF,pre=0;
            for(int i=1;i<24;i++){
                if(S[i]){
                    m=min(m,i-pre);
                    pre=i;
                }
            }
            m=min(m,24-pre);
            ans=max(ans,m);

        }

        cout<<ans<<endl;
    }
}


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> list(N), dp(N, MOD);
    for (int i = 0; i < N; i++)
        cin >> list[i];
    dp[0] = 0;
    for (int i = 1; i < N; i++)
    {
        for (int j = 1; j <= K; j++)
        {
            if (i - j < 0)
                break;
            dp[i] = min(dp[i], dp[i - j] + abs(list[i] - list[i - j]));
        }
    }
    cout << dp[N - 1];
}

Measured memory_bytes: 4036
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int a, b, s, t, c;
	while(cin >> a >> b){
		s = a;
		t = b;
		c = 1;
		for(int tmp = (a > b)? b : a, i = 2; i <= tmp; i++){
			while(s%i == 0 && t%i == 0){
				s /= i;
				t /= i;
				tmp /= i;
				c *= i;
			}
		}
		cout << c << " " << (a/c*b) << endl;
	}
	
	return 0;
}

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

int main () {
	string s;
	
	cin>>s;
	
	sort(s.begin(), s.end());
	
	int x = s.length();
	
	if(x==1){
		cout<<"No"<<endl;
		return 0;
	}
	int sum =1;
	for(int i=1; i<x; i++){
		if(s[i] == s[i-1]){
			sum++;
		} else {
			if(sum%2!=0) {
				cout<<"No"<<endl;
				return 0;
			}
			sum=1;
		}
		
		if(i==x-1 && s[i] == s[i-1]){
			if(sum%2==0){
				cout<<"Yes"<<endl;
				break;
			} else {
				cout<<"No"<<endl;
				break;
			}
		} else if(i==x-1 && s[i] != s[i-1]){
			cout<<"No"<<endl;
			break;
		}
	}
}

Measured memory_bytes: 3592
#ifndef LOCAL
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#else
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair


int main() {
    ios::sync_with_stdio(false);
    
    ll n, a, b;
    cin >> n >> a >> b;
    ll hm = n / (a + b);
    ll xd = n % (a + b);

    cout << hm * a + min(a, xd);
    

}


Measured memory_bytes: 256
using System;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            int countOfS = s.Length;

            string yobun = t.Substring(countOfS, 1);

            if(t.Equals(s + yobun))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 25796
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=true;

/*---------------------------------------------------*/

int main(){
  int n;
  int a,b;
  int max_a=-1,max_b=-1;
  cin>>n;
  rep(i,n){
    cin>>a>>b;
    if(max_a<a){max_a=a;max_b=b;}
  }
  cout<<max_a+max_b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
#define ll long long
const int maxn = 1000100;

ll inv[maxn];

void get_inv() {
    for (int i = 1; i < maxn; ++i) {
        if (i == 1) inv[i] = 1;
        else {
            inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
            if (inv[i] < 0) inv[i] += mod;
        }
    }
}

ll modpow(int n, int r) {
    ll ret = 1;
    ll tmp = (ll)n;
    while (r) {
        if (r & 1) {
            ret = ret * tmp;
        }
        tmp *= tmp;
        tmp %= mod;
        ret %= mod;
        r /= 2;
    }
    return ret;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    get_inv();
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    set<int> s;
    for (auto &x : a) s.insert(x);
    map<int, int> m;
    for (auto &x : s) {
        int p = x;
        for (int i = 2; i * i <= p; ++i) {
            if (p % i == 0) {
                int cnt = 0;
                while (p % i == 0) ++cnt, p /= i;
                m[i] = max(m[i], cnt);
            }
        }

        if (p != 1) m[p] = max(m[p], 1);
    }

    ll lcm = 1;
    for (auto &iter : m) {
        lcm *= modpow(iter.first, iter.second);
        lcm %= mod;
    }

    ll ans = 0;
    for (auto &x : a) {
        ans = (ans + lcm * inv[x] % mod) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9088
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
int main(){
  double  x1,x2,y1,y2;
  double ans,sax,say; 
  cin>>x1>>y1>>x2>>y2;
  sax=x1-x2;
  say=y1-y2;
  sax=pow(sax,2);
  say=pow(say,2);
  ans=sqrt(sax+say);
  cout<<setprecision(12)<<ans<<endl;
  return 0;
  
}


Measured memory_bytes: 3268
import std.stdio, std.string, std.conv, std.algorithm;

immutable int n = 2019;

void divmod(int x, ref int a, ref int b) {
    a = x / n;
    b = x % n;
}

void main() {
    int[] tmp = readln.split.to!(int[]);
    int ld, lm, rd, rm;
    divmod(tmp[0], ld, lm);
    divmod(tmp[1], rd, rm);
    if (ld != rd) {
        0.writeln;
    } else {
        int minv = n;
        foreach (i; lm .. rm) {
            foreach (j; i+1 .. rm+1) {
                minv = min(minv, i * j % n);
            }
        }
        minv.writeln;
    }
}

Measured memory_bytes: 364
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


int main(){
	int N;
	int a[200005];
	ll ans=0;

	cin >> N;
	rep(i,N) cin >> a[i];
	
	ll sum[200005]={};
	stack<pii> st;
	st.emplace(0,-1);
	rep(i,N){
		while(st.size() && st.top().first > a[i]) st.pop();
		auto p = st.top();
		sum[i] += (ll)(i - p.second) * (ll)a[i];
		sum[i] += sum[p.second];
		ans += sum[i];
		//cout << ans << endl;
		st.emplace(a[i], i);
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main(void) {
    int n, m;
    while (cin >> n >> m, n) {
        int t[110], h[110], sumt = 0, sumh = 0;
        for (int i = 0; i < n; i++) {
            cin >> t[i];
            sumt += t[i];
        }
        for (int i = 0; i < m; i++) {
            cin >> h[i];
            sumh += h[i];
        }
        
        int flag = 0, cpyt, cpyh;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cpyt = sumt - t[i] + h[j];
                cpyh = sumh - h[j] + t[i];
                if (cpyt != cpyh) continue;
                cout << t[i] << " " << h[j] << endl;
                flag = 1;
                break;
            }
            if (flag) break;
        }

        if (!flag) cout << "-1\n";
    }

    return 0;
}

Measured memory_bytes: 2992