akhauriyash/Code-Regression huggingface dataset:
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

 */

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005


signed main(){
	fast
	int n;
	cin>>n;
	vector<int> a, b;
	int temp;
	int tot=0;
	For(i, 0, n+1){
		cin>>temp;
		a.pb(temp);
		tot+=temp;
	}
	For(i, 0, n){
		cin>>temp;
		b.pb(temp);
	}

	int count = 0;
	For(i, 0, n){
		if(b[i]>a[i]){
			int val = (a[i+1]-(b[i]-a[i]));
			if(val>0){
				a[i+1] = val;
			}else{
				a[i+1] = 0;
			}
		}else{
			count+=a[i]-b[i];
		}
	}

	count+=a[n];
	int ans = tot-count;
	cout<<ans<<endl;
    return 0;
}
    



Measured memory_bytes: 2548
#include<iostream>

using namespace std;

int main(){
  int N,M; cin >> N >> M;
  int isfavorite[M + 5];
  for(int i = 1; i <= M; i++){
    isfavorite[i] = 0;}
  for(int i = 0; i < N; i++){
    int k ; cin >> k;
    for(int j = 0; j < k; j++){
      int a ; cin >> a; isfavorite[a]++;}}
  int cnt = 0;
  for(int i = 1; i <= M ; i++){
    if(isfavorite[i] == N){ cnt++;}}
  
  cout << cnt << endl;
  
  return 0;}

Measured memory_bytes: 256
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n;
    std::cin >> n;
    vec<i64> a(3*n);
    for (i64& x: a) std::cin >> x;

    std::sort(ALL(a), std::greater<>{});
    i64 ans = 0;
    for (usize i=1; i<2*n; i+=2) {
        ans += a.at(i);
    }
    std::cout << ans << '\n';
}


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

using namespace std;

int main(){
    int n,ans = 0;
    string s;
    cin >> n;
    cin >> s;
    size_t len = s.length();
    if(len % 2 == 1) ans = 1;
    for(int i = 0; i < len / 2; i++){
        if(s[i] != s[len / 2 + i]){
            ans = 1;
            break;
        }
    }
    if(ans == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import itertools

n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]


cnt=0
num=0
for v in itertools.permutations(xy):
  num+=1
  for i in range(n-1):
    a=(v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2
    b=a**0.5
    cnt+=b

print(cnt/num)

Measured memory_bytes: 9428
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



/*

BFSで距離を求める．
1からの距離 <= N からの距離　ならば黒
1からの距離 > N からの距離　ならば白
*/
using Graph = vector<vector<int>>;

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

  Graph G(N);

  REP(i,N-1){
    int a, b;
    cin >> a >>b;
    --a; --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> distf(N, -1); //未訪問に初期化
  queue<int> que;

  //init
  distf[0] = 0;
  que.push(0);

  //BFS
  while(!que.empty()){
    int v = que.front(); que.pop();

    for( int nv : G[v]){
      if( distf[nv] != -1) continue;
      distf[nv] = distf[v] + 1;
      que.push(nv);
    }

  }




   vector<int> dists(N, -1); //未訪問に初期化
   queue<int> ques;

   //init
   dists[N-1] = 0;
   ques.push(N-1);

   //BFS
   while(!ques.empty()){
     int v = ques.front(); ques.pop();

     for( int nv : G[v]){
       if( dists[nv] != -1) continue;
       dists[nv] = dists[v] + 1;
       ques.push(nv);
     }

   }

   int cnts = 0;
   int cntf = 0;

   REP(i,N){
     if(distf[i] <= dists[i]) ++cntf;
     else ++cnts;
   }

   // REP(i,N) cout << i << ": " << distf[i] << endl;
   // REP(i,N) cout << i << ": " << dists[i] << endl;


   if(cntf > cnts) cout << "Fennec" << endl;
   else cout << "Snuke" << endl;




  return 0;
}


Measured memory_bytes: 9508
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main()
{
  int N;
  vector<int> W;
  cin >> N;
  W.reserve(N);

  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    W.push_back(a);
  }

  int sum = accumulate(W.begin(), W.end(), 0);

  int S = 0;
  int last_diff = 999999999;
  
  for (int w: W) {
    S += w;
    int diff = std::abs(sum - 2 * S);
    if (last_diff <= diff) {
      cout << last_diff << endl;
      return 0;
    }
    last_diff = diff;
  }

  if (last_diff <= sum) {
    cout << last_diff << endl;
  } else {
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int k,a,b;
main()
{
	cin>>k>>a>>b;
	if(a+1>=b||k<a)cout<<k+1<<'\n',exit(0);
	k-=a-1;
	cout<<a+k/2*(b-a)+k%2<<'\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M,blue_point,red_point,best_sum=-110;
    cin >> N;
    vector<string>blue(N);
    for(int i=0;i<N;i++)cin >> blue.at(i);
    cin >> M;
    vector<string>red(M);
    for(int i=0;i<M;i++)cin >> red.at(i);

    for(int i=0;i<N;i++){
        blue_point=count(blue.begin(),blue.end(),blue.at(i));
        red_point=count(red.begin(),red.end(),blue.at(i));
        best_sum=max(blue_point-red_point,best_sum);
    }

    if(best_sum>=0){
        cout << best_sum;
    } else {
        cout << 0;
    }
    return 0;
}

Measured memory_bytes: 3576
use std::io;
use std::cmp;

fn min(w: i64, h: i64) -> i64 {
    let x = (w as f64 / 2f64).floor() as i64;
    let y = (h as f64 / 2f64).floor() as i64;
    cmp::max(x*h, w*y)
}

fn solve(w: i64, h: i64) -> i64 {
    let mut min = w * h + 1;
    for y in 0..h {
        let vmin = {
            let x = (w as f64 / 2f64).floor() as i64;
            let a = y*w;
            let b = (h-y)*x;
            let c = (h-y)*(w-x);
            let smax = cmp::max(cmp::max(a, b), c);
            let smin = cmp::min(cmp::min(a, b), c);
            smax - smin
        };
        let hmin = {
            let z = ((h-y) as f64 / 2f64).floor() as i64;
            let a = y*w;
            let b = z*w;
            let c = (h-y-z)*w;
            let smax = cmp::max(cmp::max(a, b), c);
            let smin = cmp::min(cmp::min(a, b), c);
            smax - smin
        };
        min = cmp::min(cmp::min(vmin, hmin), min);
    }
    min
}

fn main() {

    let mut input = String::new();

    io::stdin().read_line(&mut input);
    let mut iter = input.split_whitespace();

    let h = iter.next().unwrap().parse::<i64>().unwrap();
    let w = iter.next().unwrap().parse::<i64>().unwrap();

    println!("{}", cmp::min(solve(h,w), solve(w,h)));
}

Measured memory_bytes: 4352
#include<stdio.h>

int main( void )
{
	int a ,b ,c ;
	scanf( "%d %d %d" ,&a ,&b ,&c ) ;

	c -= a ;
	b -= c ;

	if( b < 0 )
	{
		puts( "NA" ) ;
	}

	else if( c < 0 )
	{
		puts( "0" ) ;
	}

	else
	{
		printf( "%d\n" ,c ) ;
	}

	return 0 ;
}


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

using namespace std;
using ll = long long;

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

int main() {
	int n, m;
	int h[100000], ma[100000];

	cin >> n >> m;
	rep(i, n) {
		cin >> h[i+1];
		ma[i+1] = 0;
	}
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		ma[a] = max(ma[a], h[b]);
		ma[b] = max(ma[b], h[a]);
	}
	int ans = 0;
	rep(i,n) {
		ans += h[i+1] > ma[i+1];
	}

	cout << ans << endl;

}



Measured memory_bytes: 4388
// AtCoder Beginner Contest 092 - Problem C: Travelling Plan (https://atcoder.jp/contests/abc092/tasks/arc093_a)
#include <bits/stdc++.h>

using namespace std;

vector<int> solve(int N, const vector<int>& as)
{
    vector<int> dist(N + 1), skip(N);

    for (int i = 0; i <= N; ++i)
        dist[i] = abs(as[i] - as[i + 1]);

    for (int i = 0; i < N; ++i)
        skip[i] = abs(as[i] - as[i + 2]);

    auto d = accumulate(dist.begin(), dist.end(), 0);

    vector<int> ans(N);

    for (int i = 1; i <= N; ++i)
        ans[i - 1] = d - dist[i - 1] - dist[i] + skip[i - 1];

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> as(N + 2, 0);

    for (int i = 1; i <= N; ++i)
        cin >> as[i];
 
    auto ans = solve(N, as);

    for (auto x : ans)
        cout << x << '\n';

    return 0;
}


Measured memory_bytes: 2032
#include<cstdio>
#include<iostream>
using namespace std;
int fun(int a,int b,int c)
{
    int i;
    int mins;
    int y;
    mins=min(a,b);
    mins=min(mins,c);
    for(i=1;i<=mins;i++)
        if(a%i==0&&b%i==0&&c%i==0)
            y=i;
        return y;
}
int main()
{
    long long sum=0;
    int k;
    scanf("%d",&k);
    for(int a=1;a<=k;a++)
        for(int b=1;b<=k;b++)
        for(int c=1;c<=k;c++)
        sum+=fun(a,b,c);
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;



int main(void) {

    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1){
        fin("No");
        return 0;
    }
    if(s.substr(0,n/2)==s.substr(n/2)){
        fin("Yes");
        return 0;
    } else {
        fin("No");
    }

}


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

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

    map<char, int> cnt;
    for (int i = 0; i < s.size(); i++) {
        cnt[s[i]]++;
    }

    int ans = 1000;
    for (auto x: cnt) {
        char c = x.first;
        

        int tans = 0;
        string ts = s;
        string ns = "";
        while (1) {
            
            bool ok = true;
            for (int i = 0; i < ts.size(); i++) {
                if (ts[i] != c) {
                    ok = false;
                }
            }
            if (ok) {
                break;
            }

            tans++;
            for (int i = 0; i < ts.size() - 1; i++) {
                if (ts[i] == c || ts[i + 1] == c) {
                    ns.push_back(c);
                }
                else {
                    ns.push_back('.');
                }
            }
            ts = ns;
            ns = "";
        }
        if (tans < ans) {
            ans = tans;
        }
    }

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

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include<vector>
typedef long long ll;
using namespace std;
struct node {
	vector<pair<int,ll>>v;
	bool b = 1; ll ans = 0;
};
node tree[114514];
void f(int k) {
	for (int i = 0; i < tree[k].v.size(); i++) {
		int p = tree[k].v[i].first;
		if (tree[p].b) {
			tree[p].ans = tree[k].ans + tree[k].v[i].second;
			tree[p].b = 0;
			f(p);
		}
	}
	return;
}
signed main() {
	int n; cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b; ll c;
		cin >> a >> b >> c;
		tree[a].v.push_back(make_pair(b, c));
		tree[b].v.push_back(make_pair(a, c));
	}
	int q, k; cin >> q >> k;
	tree[k].b = 0;
	f(k);
	for (int i = 0; i < q; i++) {
		int x, y; cin >> x >> y;
		cout << tree[x].ans + tree[y].ans << endl;
	}
	return 0;
}

Measured memory_bytes: 14080
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	ll n;
	cin >> n;
	vector<ll> as(3 * n);
	for(auto &a : as) cin >> a;
	RSRT(as);
	ll answer = 0;
	for(ll i = 1, j = 0; i < 3 * n && j < n; i += 2, ++j) answer += as[i];
	cout << answer << '\n';
}

Measured memory_bytes: 5468
N = int(input())
D = [input().split() for i in range(N)]
ans = 0
for i in range(N-2):
    if D[i][0] == D[i][1]:
        if D[i+1][0] == D[i+1][1]:
            if D[i+2][0] == D[i+2][1]:
                ans = 1
                break
if ans == 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define ll long long 
#define int ll
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int32_t main(){
    int xi{},yi{},xf{},yf{};    cin>>xi>>yi>>xf>>yf;
    int h = yf-yi;
    int l = xf-xi;
    for(int i=0;i<h;i++)    cout<<"U";
    for(int i=0;i<l;i++)    cout<<"R";
    for(int i=0;i<h;i++)    cout<<"D";
    for(int i=0;i<l;i++)    cout<<"L";
    cout<<"L";
    for(int i=0;i<h+1;i++)    cout<<"U";
    for(int i=0;i<l+1;i++)    cout<<"R";
    cout<<"DR";
    for(int i=0;i<h+1;i++)    cout<<"D";
    for(int i=0;i<l+1;i++)    cout<<"L";
    cout<<"U"<<endl;
    return 0;
}

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

using namespace std;

#define WMAX 10005
#define NMAX 105
#define DIAGONAL 1
#define TOP 0


struct Item
{
    int value, weight;
};

Item items[NMAX];
int C[NMAX][WMAX], G[NMAX][WMAX];
int N, W;

int compute(){
    for (int i = 0; i <= W; ++i)
    {
        C[0][i] = 0;
    }

    for (int i = 0; i <= N; ++i)
    {
        C[i][0] = 0;
    }

    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= W; ++j)
        {
            C[i][j] = C[i-1][j];
            if (j < items[i].weight) continue;//?????????<=??????????????????????????§??????????????????????????? 
            if (C[i-1][j-items[i].weight] + items[i].value > C[i-1][j]) {
                C[i][j] = C[i-1][j-items[i].weight] + items[i].value;
            }
        }
    }
    return C[N][W];
}

void input(){
    cin >> N >> W;
    for (int i = 0; i < N; ++i)
    {
        cin >> items[i+1].value >> items[i+1].weight;
    }
}

int main(){
    input();
    cout << compute() << endl;
}

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

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


    if(n==1)
    {
        if(a==b)
        cout<<"1"<<endl;
        else{
            cout<<"0"<<endl;
        }

    }
    else{
    if(a>b)
    {
        cout<<"0"<<endl;
    }
    else{
        cout<<b * (n-2) - a * (n-2) + 1<<endl;
    }
    }
}


Measured memory_bytes: 3624
function main(input) {
    var data = input.split(' ');
    var a = parseInt(data[0]);
    var b = parseInt(data[1]);
    var ans = a + b;
    if(a>b){
        ans = 2 * a - 1;
    }else if(a<b){
        ans = 2 * b - 1;
    }
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <stdio.h>
int main(void) {
	int n, k;
	int h[100000];
	int count = 0;
	scanf("%d %d", &n, &k);
	for (int i = 0; i <= n; i++) {
		scanf("%d", &h[i]);
	}
	for (int i = 0; i <= n; i++) {
		if (h[i] >= k) {
			count++;
		}
	}
	printf("%d", count);
	return 0;
}

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

const int N = 100005;
int x, y, a, b, c;
long long d[2 * N], p[N], q[N], r[N], pp, pq, sd, fp;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> x >> y >> a >> b >> c;
	for(int i = 1; i <= a; ++i) cin >> p[i];
	sort(p + 1, p + a + 1);
	reverse(p + 1, p + a + 1);
	for(int i = x + 1; i <= a; ++i) p[i] = 0;

	for(int i = 1; i <= b; ++i) cin >> q[i];
	sort(q + 1, q + b + 1);
	reverse(q + 1, q + b + 1);
	for(int i = y + 1; i <= b; ++i) q[i] = 0;

	for(int i = 1; i <= c; ++i) cin >> r[i];
	sort(r + 1, r + c + 1);
	reverse(r + 1, r + c + 1);
	pp = pq = 1;
	for(int i = 1; i <= x + y; ++i) {
		d[i] = d[i - 1] + (p[pp] > q[pq] ? p[pp++] : q[pq++]);
	}
	c = min(c, x + y);
	for(int i = 0; i <= c; ++i) {
		sd += r[i];
		fp = max(fp, sd + d[x + y - i]);
	}
	cout << fp << endl;
	return 0;
}


Measured memory_bytes: 3968
#include<iostream>
using namespace std;
int main(){
    int x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    int sides_x=-x1+x2,sides_y=-y1+y2;
    cout<<x2-sides_y<<" "<<y2+sides_x<<" "<<x1-sides_y<<" "<<y1+sides_x<<endl;
}

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

#define MAX 100002


struct st{
	string s;
	vector<int> im;
	void init(){
		im.assign(s.size(), 0);
		for (int i = 0; i < s.size(); i++){
			if (s[i] == 'A'){
				im[i]++;
			}
			if (i)im[i] += im[i - 1];
		}
	}
	int get_cnt_A(int l,int r){
		int rr = im[r];
		if (l)rr -= im[l - 1];
		return rr;
	}
	int get_cnt_B(int l, int r){
		return r - l + 1 - get_cnt_A(l, r);
	}
};
char buf[MAX];

st aa;
st bb;
int main(){
	scanf("%s", buf);
	aa.s = buf;
	scanf("%s", buf);
	bb.s = buf;
	aa.init();
	bb.init();
	int q;
	cin >> q;
	while (q--){
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		a--;
		b--;
		c--;
		d--;
		int c1 = aa.get_cnt_A(a, b) + aa.get_cnt_B(a, b) * 2;
		int c2 = bb.get_cnt_A(c, d) + bb.get_cnt_B(c, d) * 2;
		c1 %= 3;
		c2 %= 3;
		if (c1 == c2){
			puts("YES");
		}
		else{
			puts("NO");
			//cout << c1 << " " << c2 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin>>n;
	if(n/100==7||(n%100)/10==7||n%10==7)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pr pair<int, int>
#define v1d vector<int>
#define mp make_pair
#define pb push_back
#define v1p vector<pr>
#define vb vector<bool>
#define v2d vector<vector<int>>
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define S(v) sort(v.begin(), v.end())
#define RS(v) sort(v.rbegin(), v.rend())
#define eb emplace_back
#define endl "\n"
#define MOD 1000000007
#define pqx priority_queue <int>
#define pqn priority_queue <int, v1d, greater<int> >
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int32_t main() {
    fio
    int n; cin >> n;
    int k = n % 10;
    if(k == 1 || k == 0 || k == 6 || k == 8) cout << "pon";
    if(k == 3) cout << "bon";
    if(k == 2 || k == 4 || k == 5 || k == 7 || k == 9) cout << "hon";
}

Measured memory_bytes: 3608
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sum = 0
for i in range(len(A)):
  sum += B[A[i]-1]
  if i != len(A)-1:
    if A[i+1]-A[i] == 1:
      #print(C[i])
      sum += C[A[i]-1]
      
print(sum)

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

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

    set<char> s;
    for(int i = 0; i < n; i++) {
        char c;
        cin >> c;
        s.insert(c);
    }

    if(s.size() == 3) cout << "Three" << endl;
    else if(s.size() == 4) cout << "Four" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main() {
    
    string S;
    
    cin >> S;
    
    bool is_same = ( S.front() == S.back() );
    
    cout << ( ( S.size() % 2 ) ? ( is_same ? "Second" : "First" ) : ( is_same ? "First" : "Second" ) ) << endl;
    
    
    return 0;
}

Measured memory_bytes: 512
import copy
import queue

input_int_list = list(map(int, input().split()))

H = input_int_list[0]
W = input_int_list[1]

MAX_DIST = 100000

# master_maze_list =[ [0] * H ] * W
master_maze_list = [[-1 for i in range(H+2)] for j in range(W+2)]
for vertical_i in range(H):
	input_str_H = input()
	for holizontal_i in range(W):
		if input_str_H[holizontal_i] == '#':
			master_maze_list[holizontal_i+1][vertical_i+1] = -1
		elif input_str_H[holizontal_i] == '.':
			master_maze_list[holizontal_i+1][vertical_i+1] = MAX_DIST


# print(master_maze_list)


distance_max = 0

for vertical_i in range(H):
	for holizontal_i in range(W):
		search_target_maze = copy.deepcopy(master_maze_list)
		root_h = holizontal_i+1
		root_v = vertical_i+1
		if search_target_maze[root_h][root_v] == -1:
			continue
		next_place_queue = queue.Queue()
		next_place_queue.put(root_h)
		next_place_queue.put(root_v)
		search_target_maze[root_h][root_v] = 0
		
		while next_place_queue.empty() != True:
			now_h = next_place_queue.get()
			now_v = next_place_queue.get()
			now_place_val = search_target_maze[now_h][now_v]

			if now_place_val == -1:
				pass
			else:
				if search_target_maze[now_h+1][now_v] > now_place_val+1:
					search_target_maze[now_h+1][now_v] = now_place_val+1
					next_place_queue.put(now_h+1)
					next_place_queue.put(now_v)

				if search_target_maze[now_h][now_v+1] > now_place_val+1:
					search_target_maze[now_h][now_v+1] = now_place_val+1
					next_place_queue.put(now_h)
					next_place_queue.put(now_v+1)

				if search_target_maze[now_h-1][now_v] > now_place_val+1:
					search_target_maze[now_h-1][now_v] = now_place_val+1
					next_place_queue.put(now_h-1)
					next_place_queue.put(now_v)

				if search_target_maze[now_h][now_v-1] > now_place_val+1:
					search_target_maze[now_h][now_v-1] = now_place_val+1
					next_place_queue.put(now_h)
					next_place_queue.put(now_v-1)
		distance_max = max(distance_max, now_place_val)
#		print(distance_max)

print(distance_max)



Measured memory_bytes: 4052
def main():
    N = int(input())
    A_lst = [0] * N
    xy_lst = [[]] * N
    ans = 0

    for i in range(N):  # 入力
        A = int(input())
        A_lst[i] = A
        xy_lst[i] = [[]] * A

        for j in range(A):
            x, y = map(int, input().split())
            xy_lst[i][j] = [x, y]  # 3次元配列 i人目のj番目の証言の[x,y]

    for i in range(2 ** N):  # ビット全探索
        honest_unkind = [0] * N
        flag = True

        for j in range(N):  # 1つ状態を決める
            if (i >> j) & 1 == 1:
                honest_unkind[j] = 1  # 1:honest, 0:unkind

        for j in range(N):  # 1人ずつ証言を検証する
            if flag == False:
                break

            for k in range(A_lst[j]):  # 各人の証言がk個
                if honest_unkind[j] == 1:  # j番目の人がhonestだったら
                    if xy_lst[j][k][1] == 0 and honest_unkind[xy_lst[j][k][0] - 1] == 1:
                        flag = False  # 矛盾したら終了
                        break
                    if xy_lst[j][k][1] == 1 and honest_unkind[xy_lst[j][k][0] - 1] == 0:
                        flag = False
                        break
                # if honest_unkind[j] == 0:  # j番目の人がunkindだったら
                #     if xy_lst[j][k][1] == 0 and honest_unkind[xy_lst[j][k][0] - 1] == 0:
                #         flag = False
                #         break
                #     if xy_lst[j][k][1] == 1 and honest_unkind[xy_lst[j][k][0] - 1] == 1:
                #         flag = False
                #         break

        if flag == True:  # 全員の証言が矛盾しなかった場合
            cnt = sum(honest_unkind)
            if cnt > ans:
                ans = cnt

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9252
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
long long int x[100], y[100];
int ind[100], ind2[200];

long long int naiseki(int a, int b){
    long long int x_a = x[ind2[a]];
    long long int y_a = y[ind2[a]];
    long long int x_b = x[ind2[b]];
    long long int y_b = y[ind2[b]];
    return x_a*x_b + y_a*y_b;
}
long long int gaiseki(int a, int b){
    long long int x_a = x[ind2[a]];
    long long int y_a = y[ind2[a]];
    long long int x_b = x[ind2[b]];
    long long int y_b = y[ind2[b]];
    return x_a * y_b - y_a * x_b;
}
int compare_angle(const void* a_, const void* b_){
    //(1, 0)を基準に偏角ソートを厳密に行う関数(qsortで呼び出されることを想定)
    //同じ角度の場合や(0，0)の入力は想定していない(が，ソートする上では-1でも1でも問題ないはず)
    int a = *(int *)a_;
    int b = *(int *)b_;
    long long int x_a = x[a];
    long long int y_a = y[a];
    long long int x_b = x[b];
    long long int y_b = y[b];
    if(y_a == 0 && x_a >= 0){
        return -1;
    }
    if(y_b == 0 && x_b >= 0){
        return 1;
    }

    if(y_a > 0 && y_b < 0){
        return -1;
    }
    if(y_a < 0 && y_b > 0){
        return 1;
    }

    if(x_a * y_b - y_a * x_b > 0){
        return -1;
    }else{
        return 1;
    }
}
int isUnder180(int a, int b){
    //外積を計算
    return gaiseki(a, b) >= 0;
}
double dist(int a, int b){
    return pow(pow(a, 2) + pow(b, 2), 0.5);
}
int main(void){
    int n;
    scanf("%d", &n);
    double d_max = 0;
    int i, j, k;
    long long int x_tmp, y_tmp;
    for(i = 0; i < n; i++){
        scanf("%lld%lld", &x[i], &y[i]);
    }
    for(i = 0; i < n; i++){
        ind[i] = i;
    }
    qsort(ind, n, sizeof(int), compare_angle);
    for(j = 0; j < n; j++){
        ind2[j] = ind[j];
    }
    for(j = 0; j < n; j++){
        ind2[j+n] = ind[j];
    }

    for(i = 0; i < n; i++){
        int right = i + n;
        int left = i;
        while(right - left > 1){
            int mid = (right + left)/2;
            if(isUnder180(i, mid)){
                left = mid;
            }else{
                right = mid;
            }
        }
        x_tmp = 0;
        y_tmp = 0;
        for(j = i; j <= left; j++){
            x_tmp += x[ind2[j]];
            y_tmp += y[ind2[j]];
            d_max = d_max > dist(x_tmp, y_tmp) ? d_max : dist(x_tmp, y_tmp);
        }
        
    }
    printf("%.20lf\n", d_max);
}

Measured memory_bytes: 2760
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

#define ll long long
using namespace std;

int main() {
	ll s, hoge;
	vector <int>f;
	cin >> s;
	f.push_back(s);
	hoge = s;
	while (1) {
		if (hoge % 2 == 0) {
			hoge = hoge / 2;
		}
		else {
			hoge = 3 * hoge + 1;
		}
		auto itr = f.begin();
		itr = find(itr, f.end(), hoge);
		if (itr == f.end()) {
			f.push_back(hoge);
			continue;
		}
		cout << f.end() - f.begin() + 1 << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input().split()
l=[int(s[i]) for i in range(n)]
l.sort()
if l[0]==l[-1]:
    if l[0]<=n//2 or l[0]==n-1:
        print("Yes")
    else:
        print("No")
elif l[-1]-l[0]>1:
    print("No")
else:
    a=l.count(l[0])
    b=l.count(l[-1])
    if a+1<=l[-1]<=a+b//2:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 13964
#include<cstdio>
#include<algorithm>
using namespace std;
int x[100000],a,n,q;
int main(){
	scanf("%d",&n);getchar_unlocked();
	for(int i = 0; i < n; i++){
		while(true){
			char c = getchar_unlocked();
			if('0' <= c && c <= '9'){
				x[i] = x[i] * 10 + (c - '0');
			}
			else{break;}
		}
	}
	scanf("%d",&q);x[n]=1<<30;int cnt=0;
	for(int i=0;i<q;i++){
		scanf("%d",&a);
		int pos=lower_bound(x,x+n,a)-x;
		if(x[pos]==a)cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

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

int main(){
    while (true)
    {
        int a,b;
        string s;
        cin >> a >> s >> b;
        if(s=="+"){
            cout << a+b << endl;
        } 
        else if(s=="-"){
            cout << a-b << endl;
        }
        else if(s=="*"){
            cout << a*b << endl;
        }
        else if(s=="/"){
            cout << a/b << endl;
        }
        else if(s=="?"){
            break;
        }
    }
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<pair<ll, ll>> vp(n);
    rep(i, n) {
        cin >> vp[i].first;
        vp[i].second = i;
    }
    sort(rall(vp));
    multiset<ll> idx;
    idx.insert(-1);
    idx.insert(-1);
    idx.insert(n);
    idx.insert(n);
    ll ans = 0;
    rep(i, n) {
        ll p = vp[i].second;
        ll v = vp[i].first;
        idx.insert(p);
        auto it = idx.lower_bound(p);
        auto rin = it; rin++;
        auto rout = rin; rout++;
        auto lin = it; lin--;
        auto lout = lin; lout--;
        ll cnt = 0;
        cnt += (*rin - p) * (*lin - *lout);
        cnt += (p - *lin) * (*rout - *rin);
        ans += cnt * v;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  string s; cin >> s;
  for(int i=0; i<8; i++){
    int res=(s[0]-'0');
    for(int j=0; j<3; j++){
      if(i&(1<<j)){
        res+=(s[j+1]-'0');
      }else{
        res-=(s[j+1]-'0');
      }
    }
    if(res==7){
      cout << s[0] << (i&(1<<0)?"+":"-") 
        << s[1] << (i&(1<<1)?"+":"-") 
        << s[2] << (i&(1<<2)?"+":"-") 
        << s[3] << "=7" << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int ctr = sc.nextInt();
		
		while(ctr > 0) {
			if(b <= a) {
				b *= 2;
			}
			else if(c <= b) {
				c *= 2;
			}
			ctr--;
		}
		if(b > a && c > b) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}		
	}
}

Measured memory_bytes: 35624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int main(void){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n){
  cin >> h.at(i);
  }
  int count = 0;
  int x = h.at(0);
  rep(i,n){
    if(h.at(i) >= x){
      count++;
       x = h.at(i);
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int i=0,kara=0,tya=0;
	char a[2000000];
	scanf("%s",a);
	while(a[i]!='\0'){
		kara=kara+a[i]-'0';
		i++;
	}
	tya=kara%9;
	if(tya==0){
		printf("Yes\n");
	}
	else if(tya>=1){
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1828
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(int i=0; i<v; i++)
#define forj(v) for(int j=0; j<v; j++)
#define fork(v) for(int k=0; k<v; k++)
#define forl(v) for(int l=0; l<v; l++)
#define fort(v) for(int t=0; t<v; t++)
#define forz(v) for(int z=0; z<v; z++)
#define forx(v) for(int x=0; x<v; x++)
#define ll long long
#define lll __int128
#define MAX (int)(4*pow(10,3) + 100)
#define pb(a) push_back(a)
#define ch (int)(4*pow(10,4) + 100)
#define ld long double
// #define cout out
// #define cin in
ll inf = pow(10,18);
ll modulo = pow(10,9)+7 ;
double eps = 1e-9;
ifstream in;
ofstream out;
 


 
void deal(){
	ll n , a, b;
	cin>>n>>a>>b;
	ll sy = n/(a+b) * a;
	sy += min(a, n%(a+b));
	cout<<sy;
}
 
 
int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}
 
 
 
/* 
6 8 
1 2
2 3
3 4
4 1
2 5
3 5
1 6
4 6
*/

Measured memory_bytes: 256
import sys
import math

input = sys.stdin.readline

class BIT:
    def __init__(self, len_A):
        self.N = len_A + 10
        self.bit = [0]*(len_A+10)

    def query(self, i):
        res = 0
        idx = i+1
        while idx:
            res += self.bit[idx]
            idx -= idx & (-idx)
        return res

    def update(self, i, x):
        idx = i+1
        while idx < self.N:
            self.bit[idx] += x
            idx += idx & (-idx)

    def lower_left(self, w):
        if (w < 0):
            return -1
        x = 0
        k = 1 << (self.N.bit_length()-1)
        while k > 0:
            if x+k < self.N and self.bit[x+k] < w:
                w -= self.bit[x+k]
                x += k
            k //= 2
        return x


N = int(input())
xy = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])
P = 998244353

# 頂点上の圧縮
for i in range(N):
    xy[i][1] = i
xy = sorted(xy)
for i in range(N):
    xy[i][0] = i

# 各領域の点の数数える
ld, lu, rd, ru = [-1] * N, [-1] * N, [-1] * N, [-1] * N

bit = BIT(N)

for i in range(N):
    ld[i] = bit.query(xy[i][1])
    lu[i] = bit.query(N) - ld[i]
    bit.update(xy[i][1], 1)

bit = BIT(N)

for i in range(N-1, -1, -1):
    rd[i] = bit.query(xy[i][1])
    ru[i] = bit.query(N) - rd[i]
    bit.update(xy[i][1], 1)

ans = 0  #(pow(2, N, P)-1) * N % P
for i in range(N):
    ans = (ans + pow(2, N, P) - 1) % P
    ans = (ans - (pow(2, rd[i] + ru[i], P)-1 )) % P
    ans = (ans - (pow(2, ld[i] + lu[i], P) - 1)) % P
    ans = (ans - (pow(2, rd[i] + ld[i], P) - 1)) % P
    ans = (ans - (pow(2, ru[i] + lu[i], P) - 1)) % P
    ans = (ans + (pow(2, ru[i], P) - 1)) % P
    ans = (ans + (pow(2, rd[i], P) - 1)) % P
    ans = (ans + (pow(2, lu[i], P) - 1)) % P
    ans = (ans + (pow(2, ld[i], P) - 1)) % P
print(ans)


Measured memory_bytes: 128700
let ans (s, t) (a, b) u =
  if s = u then (a - 1, b) else (a, b - 1)

let () =
  let (s, t) = Scanf.sscanf (read_line ()) "%s %s" (fun s1 s2 -> (s1, s2))
  in
  let (a, b) = Scanf.sscanf (read_line ()) "%d %d" (fun n1 n2 -> (n1, n2))
  in
  let u = read_line ()
  in
  let t = ans (s, t) (a, b) u
  in
  Printf.printf "%d %d" (fst t) (snd t)


Measured memory_bytes: 2432
class NormalInput{
  input: string[];
  pointer: number;
  constructor(raw:string){
    this.input=raw.split(/ |\n/);
    this.pointer=0;
  }
  int():number{
    const ret= parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str():string{
    const ret= this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length:number):string[]{
    let ret:string[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.str());
    }
    return ret;
  }
  ints(length:number):number[]{
    let ret:number[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.int());
    }
    return ret;
  }
}
function Main(_: NormalInput) {
  const [K,X]=[_.int(),_.int()];
  for(let i=X-K+1;i<=X+K-1;i++)
  console.log(i);
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 9264
n,m = map(int,input().split())
city = [{} for i in range(n)]
for i in range(m):
    p,y = map(int,input().split())
    city[p-1][i] = y
all_dict = {}
for j in range(n):
    temp_dict = sorted(city[j].items(),key=lambda x:x[1])
    for i in range(len(temp_dict)):
        all_dict[temp_dict[i][0]] = str(j+1).zfill(6)+str(i+1).zfill(6)
for k in range(len(all_dict)):
    print(all_dict[k])



Measured memory_bytes: 71008
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B; cin >> A >> B;
    cout << (A - 1) * (B - 1) << endl;

    return 0;
}


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

int main(void)
{
	int yeardays[3]= {200, 195, 195};
	int monthdays[2]= {0, 20};

	int num;
	cin>>num;

	for(int i= 0; i < num; i++)
	{
		int year, month, day;
		cin>>year>>month>>day;

		long long int sum= 1;
		for(int j= year; j < 1000; j++)
			sum+= yeardays[j%3];

		if(year % 3 == 0)
			monthdays[0]= 20;
		else
			monthdays[0]= 19;
		for(int j= 1; j < month; j++)
			sum-= monthdays[j%2];
		sum-= day;

		cout<<sum<<endl;
	}
	return 0;
}			

Measured memory_bytes: 3096
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
int main(){
  int n,t;
  cin >> n;
  t = 0;
  REP(i,n){
    int l,r;
    cin >> l >> r;
    t += 1 - l + r;
  }
  cout << t << endl;
}

Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

    link = [set() for _ in range(n+1)]
    edge = []

    for i, ab in enumerate(args[1:]):
        a, b = sorted(map(int, ab.split()))
        edge.append((a, b))
        link[a].add(b)
        link[b].add(a)

    n_color = max(map(len, link))

    color = {}

    queue = [(0, 1)]

    while queue:
        parent, cur = queue.pop()
        used = color[tuple(sorted((parent, cur)))] if 0 < parent else 0
        c = 1

        for child in link[cur]:
            if child == parent:
                continue

            if c == used:
                c += 1
            color[tuple(sorted((cur, child)))] = c
            c += 1

            queue.append((cur, child))

    return str(n_color) + '\n' \
        + '\n'.join(map(str, (color[ab] for ab in edge)))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 70948
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	string s; cin >> s;
	int ans = 1;
	for(int i = 1; i < n; i++) ans += s[i] != s[i - 1];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
n=int(input())
a,b=list(map(int,input().split())),0
a.insert(0,0)
a.append(0)
for i in range(n+1):
    b+=abs(a[i+1]-a[i])
for i in range(n):
    if a[i]<=a[i+2]:
        if a[i]<=a[i+1] and a[i+1]<=a[i+2]:
            print(b)
        else:
            if a[i+1]<a[i]:
                print(b-2*(a[i]-a[i+1]))
            else:
                print(b-2*(a[i+1]-a[i+2]))
    else:
        if a[i]>=a[i+1] and a[i+1]>=a[i+2]:
            print(b)
        else:
            if a[i+1]>a[i]:
                print(b-2*(a[i+1]-a[i]))
            else:
                print(b-2*(a[i+2]-a[i+1]))

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

int main()
{
  int N, M;
  std::cin >> N >> M;
  std::vector<int> result(M,1);
  for(int i=0; i<N; i++)
  {
    std::vector<int> answer(M,0);
    int k;
    std::cin >> k;
    for(int j=0; j<k; j++)
    {
      int a;
      std::cin >> a;
      answer[a-1] = 1;
    }
    for(int j=0; j<M; j++)
    {
      if( ! answer[j] ) { result[j] = 0; }
    }
  }

  std::cout <<
    std::count_if(result.begin(), result.end(), [](auto i){ return i;});
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>
#include <cstdint>
#include<deque>
#include<stdio.h>
typedef long long ll;

using namespace std;

int gcd(int x, int y) {
	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (n == 1) {
		cout << a[0] << endl;
	}
	else {
		int ans = gcd(a[0], a[1]);
		if (n == 2) {
			cout << ans << endl;
		}
		else {
			for (int i = 2; i < n; i++) {
				ans = gcd(ans, a[i]);
			}
			cout << ans << endl;
		}
	}
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    set<int> s;
    for (int j=B, cnt = 0; cnt < K and j >= A and j <= B; j--, cnt++) {
        s.insert(j);
    }
    for (int j=A, cnt = 0; cnt < K and j >= A and j <= B; j++, cnt++) {
        s.insert(j);
    }
    vector<int> ans;
    for (int tmp : s) {
        cout << tmp << endl;
    }
    return 0;
}


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

public class Main {
    public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
      int a = scan.nextInt();
      int b = scan.nextInt();
      int c = scan.nextInt();
      int sum = 0;
      for(int i = a;i <= b;i++){
        int q = c % i;
        if(q == 0){
          sum++;
        }
        if(i == b){
          System.out.println(sum);
        }
      }
     }
    }



Measured memory_bytes: 26136
n = int(input())

list = list(map(int, input().split()))
all = sum(list)
ans = 10**10
sunuke = 0

for i in range(0,n-1):
    sunuke += list[i]
    arai = all - sunuke
    sa = abs(sunuke - arai)
   
    if sa < ans:
      ans = sa

print(ans)


Measured memory_bytes: 24824
N, M = map(int, input().split())
E = {}
for v in range(1,N*3+1):
    E[v] = []
for _ in range(M):
    u, v = map(int, input().split())
    E[u].append(v+N)
    E[u+N].append(v+2*N)
    E[u+2*N].append(v)
S, T = map(int, input().split())
dist = [-1 for _ in range(3*N)]
dist[S-1] = 0

q = []
q.append(S)
while q:
    n = q.pop(0)
    if n == T:
        break
    for t in E[n]:
        if dist[t-1] < 0:
            dist[t-1] = dist[n-1] + 1
            q.append(t)
print(-1 if dist[T-1] < 0 else dist[T-1] // 3)


Measured memory_bytes: 79248
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<unordered_map>

using namespace std;
#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define gc(x)  scanf(" %c",&x);
#define mmt(x,y)  memset(x,y,sizeof x)
#define write(x) prllf("%d\n",x)
#define FAST  ios::sync_with_stdio(false);cin.tie(0);
#define INF 0x3f3f3f3f
#define ll long long
#define mod  998244353
const ll N = 1e5 + 7LL;
int main(){
    FAST
    ll n,a,b;
    cin  >> n >> a >> b;
    if(a > b) swap(a,b);
    ll d = abs(a - b);
    if(!(d&1)){
        cout<<d/2<<endl;
    }
    else {
       if(b-1<=n-a){
           cout<<a +(b-a-1)/2<<endl;
       }
       else {
           cout<<n-b+1 + (b-a-1)/2<<endl;
       }

       
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string N;
    cin >> N;
    int ans = 0;
    rep(i,N.size()){
      if(N[i] == '2') ans++;
    }
    print(to_string(ans));
}

Measured memory_bytes: 256