akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn i_l(mut i: i64) -> i64 {
    let mut cnt = 0;
    while i != 0 {
        i /= 10;
        cnt+=1;
    }
    cnt
}

fn main() {
    input! {
        n: i64,
        m: usize,
        py: [(i64, i64); m],
    }
    let mut py = py;
    let mut x = 1;
    let mut py = py.into_iter().map(|c| {x+=1; (c.0, c.1, x)}).collect::<Vec<_>>();
    py.sort_by_key(|c| c.1);
    let mut p = vec![0; n as usize];
    let mut s = vec![(String::new(), 0); m];
    for (i, j) in py.into_iter().zip(0..) {
        for _ in 0..6 - i_l(i.0) {
            s[j].0.push('0');
        }
        s[j].0.push_str(&i.0.to_string());

        p[(i.0 - 1) as usize]+=1;
        for _ in 0..6 - i_l(p[(i.0 - 1) as usize]) {
            s[j].0.push('0');
        }
        s[j].0.push_str(&p[(i.0  - 1)as usize].to_string());
        s[j].1 = i.2;
    }
    s.sort_by_key(|c| c.1);
    for i in s {
        println!("{}", i.0);
    }
}

Measured memory_bytes: 16712
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	long long int l,r;
	cin>>l>>r;
	if(r-l>=2019) {
		cout<<0<<endl;
		return 0;
	}
	l=l%2019;
	r=r%2019;
	if(r<l){
		cout<<0<<endl;
		return 0;
	}
	int min=3000;
	for(int i=l+1;i<=r;i++){
		for(int j=l;j<i;j++){
			if(min>(i*j)%2019) min=(i*j)%2019;
		}
	}
	cout<<min<<endl;


	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N - 1);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  for (int i = 0; i < N - 1; i++) cin >> C.at(i);

  int ans = B.at(A.at(0) - 1);

  for (int i = 1; i < N; i++) {
    ans += B.at(A.at(i) - 1);
    if (A.at(i) - 1 == A.at(i - 1)) ans += C.at(A.at(i) - 2);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;

    return 0;
}


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

namespace contest
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int x = 1; x < 10; x++)
            {
                for (int y = 1; y < 10; y++)
                {
                    Console.WriteLine("{0}x{1}={2}",x,y,x*y);
                }

            }
            Console.ReadKey();
        }

    }
}

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

int main()
{
	long long int a, b, c, d, e, ans, t1, t2, t3, t4;
	cin >> a >> b;
	cin >> c >> d;
	e=(c*d)/(__gcd(c,d));
	t4=b-a+1;
	
	t1=(b/c)-((a-1)/c);
	t2=(b/d)-((a-1)/d);
	t3=(b/e)-((a-1)/e);

	ans=t3+t4-t1-t2;
	//cout << t1 << " " << t2 << " " << t3 << " " << t4 << endl;
	cout << ans << endl;
}

Measured memory_bytes: 256
#define rep(i,n) for(i=0;i<(n);++i)
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<utility>
#include<string>
#include<algorithm>
#include<bitset>
#include<queue>
#include<cmath>
#include<iomanip>
using ll = unsigned long long int;
using namespace std;

int src(){

    int a,b;
    cin>>a>>b;
    if(a<10 and b<10){
        cout<<a*b;
    }else{
        cout<< "-1";
    }
    return 0;
}

int main(int argc,char* argv[]){
    //ifstream in( argv[1] );
    //cin.rdbuf(in.rdbuf());
    src();    
    return 0;
}

Measured memory_bytes: 256
# ABC 051: C – Back and Forth
sx, sy, tx, ty = [int(i) for i in input().split()]

dx = tx - sx
dy = ty - sy

# r1
r1 = 'U' * dy + 'R' * dx

# r2
r2 = 'D' * dy + 'L' * dx

# r3
r3 = 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D'

# r4
r4 = 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U'

print(r1 + r2 + r3 + r4)

Measured memory_bytes: 9024
#include<bits/stdc++.h>
using namespace std;
long long n,k,c;
string s;
long long l[200100],r[200100];
vector<int> v;
int main()
{
	cin>>n>>k>>c;
	cin>>s;
	long long sum=0;
	for(int i=0;i<s.size();i++)
		if(s[i]=='o')
		{
			sum++;
			v.push_back(i);
			i+=c;
		}
	if(sum>k)
		return 0;
	if(s[0]=='o')
		l[0]=1;	
	for(int i=1;i<s.size();i++)
	{
		if(i>=c+1)	
			l[i]=max(l[i-1],l[i-c-1] + (s[i]=='o'));
		else
			l[i]=max(l[i-1], (long long)(s[i]=='o'));	
	}
	for(int i=s.size()-1;i>=0;i--)
	{
		if(i+c+1 < s.size())	
			r[i]=max(r[i+1],r[i+c+1] + (s[i]=='o'));
		else
			r[i]=max(r[i+1], (long long)(s[i]=='o'));	
	}	
	vector<int> ans;
	for(int i=0;i<v.size();i++)
	{
		if(v[i]==0 && sum!=+r[v[i]+1])
			cout<<(v[i]+1)<<endl;
		else if(v[i]==s.size()-1 && sum!=l[v[i]-1])	
			cout<<v[i]+1<<endl;
		else if(sum!=l[v[i]-1]+r[v[i]+1])
			cout<<(v[i]+1)<<endl;	
	}
}

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

#define ll long long

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

int N, M, A[1010], B[1010], C[1010], D[1010], E[1010], F[1010];
int XC, X[3030], YC, Y[3030]; int Z[3030][3030]; bool K[3030][3030];

int getx(int x) { return lower_bound(X, X + XC, x) - X; }
int gety(int y) { return lower_bound(Y, Y + YC, y) - Y; }

queue<pair<int, int> > Q;
void enq(int x, int y)
{
	if (!K[x][y]){
		Q.push({ x,y }); K[x][y] = 1;
	}
}

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

	cin>>N>>M;
	for (int i = 0; i < N; i++){
		cin>>A[i]>>B[i]>>C[i];
		X[XC++] = A[i];
		X[XC++] = B[i];
		Y[YC++] = C[i];
	}
	for (int i = 0; i < M; i++){
		cin>>D[i]>>E[i]>>F[i];
		X[XC++] = D[i];
		Y[YC++] = E[i];
		Y[YC++] = F[i];
	}
	X[XC++] = -1.1e9;
	X[XC++] = 0;
	X[XC++] = 1.1e9;
	Y[YC++] = -1.1e9;
	Y[YC++] = 0;
	Y[YC++] = 1.1e9;

	sort(X, X + XC);
	XC = unique(X, X + XC) - X - 1;
	sort(Y, Y + YC);
	YC = unique(Y, Y + YC) - Y - 1;

	for (int i = 0; i < N; i++){
		int a = getx(A[i]);
		int b = getx(B[i]);
		int c = gety(C[i]);

		for (int j = a; j < b; j++){
			Z[j][c - 1] |= (1 << 0);
			Z[j][c] |= (1 << 2);
		}
	}

	for (int i = 0; i < M; i++){
		int d = getx(D[i]);
		int e = gety(E[i]);
		int f = gety(F[i]);

		for (int j = e; j < f; j++){
			Z[d - 1][j] |= (1 << 1);
			Z[d][j] |= (1 << 3);
		}
	}

	int sx = getx(0), sy = gety(0);
	for (int p=0;p<2;p++) for (int q=0;q<2;q++) enq(sx - p, sy - q);
	while (!Q.empty()){
		int x = Q.front().first, y = Q.front().second; Q.pop();
		for (int k = 0; k < 4; k++)
            if (~Z[x][y] & (1 << k)){
                int px = x + dx[k];
                int py = y + dy[k];
                if (px < 0 || px >= XC || py < 0 || py >= YC)
                    continue;
                enq(px, py);
		}
	}

	for (int i = 0; i < YC; i++){
		if (K[0][i] || K[XC - 1][i]){
			cout<<"INF";
			return 0;
		}
	}
	for (int i = 0; i < XC; i++){
		if (K[i][0] || K[i][YC - 1]){
			cout<<"INF";
			return 0;
		}
	}
	ll ans = 0;
	for (int i = 0; i < XC; i++)
        for (int j = 0; j < YC; j++)
            if (K[i][j])
                ans += 1ll * (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]);

	cout<<ans;
	return 0;
}


Measured memory_bytes: 45516
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 1<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };


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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

int main(void){
	int n; cin >> n;
	cout << n*n*n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x;
	cin>>x;
	ll a=-200;
	range(i,a,200){
		range(j,a,200){
			ll cur=i*i*i*i*i-j*j*j*j*j;
			if(cur==x){
				puta(i,j);
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3660
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define inf 1000000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}


//edge cases when n=1,m=1.wrong variable in loop.if<->while;merge resize;LLONG_MAX
signed main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
    speed
    //global var
    int n;cin>>n;
    int lim=10000000000;
    vector<vector<int>> count(100,vector<int>(100,0));
    set<pair<int,int>> st;
    for(int i=0;i<n;++i){
        string str;cin>>str;
        int ix=0;
        int tmp=0;
        for(;ix<str.length();++ix)
        {
            if(str[ix]=='.'){++ix;break;}
            tmp*=10;tmp+=str[ix]-'0';
        }
        int cnt;
        for(cnt=0;ix<str.length();++ix,++cnt){
            tmp*=10;tmp+=str[ix]-'0';
        }

        for(int _=cnt;_<10;++_){tmp*=10;}
        int _2=0,_5=0;
        while(tmp>0 and tmp%2==0){++_2;tmp/=2;}
        while(tmp>0 and tmp%5==0){++_5;tmp/=5;}
        ++count[_2][_5];
        st.insert(make_pair(_2,_5));
    }
    vector<pair<int,int>> vec;
    for(auto it:st){vec.push_back(it);}
    int m=vec.size();
    int ans=0;
    for(int i=0;i<m;++i){
        for(int j=0;j<=i;++j){
            if((vec[i].first+vec[j].first>=20) and (vec[i].second+vec[j].second>=20)){
                if(j!=i){
                    ans+=count[vec[i].first][vec[i].second]*count[vec[j].first][vec[j].second];
                }
                else{
                    int cnt=count[vec[i].first][vec[i].second];
                    ans+=((cnt*(cnt-1))/2);
                }
            }
        }
    }
    cout<<ans<<"\n";
    
}
//try thinking from a different angle after spending some time


Measured memory_bytes: 3784
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define rrep(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

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

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


//////////////////////////////////////////////////

long long gcd (long long a, long long b) {
    if(a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a%b);
}

int main() {
    int n; cin >> n;
    vector<int> a(n+1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }

    vector<int> l(n+2), r(n+2);

    for (int i = 1; i <= n; i++)
    {
        l[i] = gcd(a[i], l[i-1]);
    }
    
    for (int i = n; i >= 1; i--)
    {
        r[i] = gcd(a[i], r[i+1]);
    }
    
    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        chmax(ans, gcd(l[i-1], r[i+1]));
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void){
  char s[6] = { '\0' };
  scanf("%s", s);
  int i = 0;
  int flag = 0;
  while(s[i + 1] != '\0'){
    if(s[i] == 'A' && s[i + 1] == 'C') {
      flag = 1;
      break;
    }
    i++;
  }
  if(flag) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 200100;
double t[N], u[N];

int main(void){
  int n;
  double d0, x;
  cin >> n >> d0 >> x;
  t[1] = 0.5;
  u[1] = 0;
  REP(i, 1, N - 1) {
    t[i + 1] = t[i] * (i + 2) / (i + 1) + 0.5;
    u[i + 1] = u[i] * (i + 3) / (i + 1) + t[i] * 3.0 / (2 * i + 2) + i / 4.0;
  }
  printf("%.9f\n", (2 * d0 + 1 * x) * t[n] + 4 * x * u[n]);
}


Measured memory_bytes: 3328
#include <iostream>
#include <set>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    std::cin >> B[i];
  }
  std::set<std::pair<int, int>, std::greater<std::pair<int, int>>> s;

  for (int i = 0; i < N; i++) {
    s.emplace(B[i], i);
  }

  long long ans = 0;
  while (!s.empty()) {
    int i = s.begin()->second;
    s.erase(s.begin());

    int d = B[i] - A[i], t = B[(i + 1) % N] + B[(N + i - 1) % N];
    if (d != 0 && d < t) {
      ans = -1;
      break;
    }
    ans += d / t;
    B[i] -= d / t * t;

    if (B[i] != A[i])
      s.emplace(B[i], i);
  }

  std::cout << ans;

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  if(n>81){
    cout << "No" << endl;
    return 0;
  }else if(n%9==0&&n/9<=9 || 
  		   n%8==0&&n/8<=9 ||
           n%7==0&&n/7<=9 ||
           n%6==0&&n/6<=9 ||
           n%5==0&&n/5<=9 ||
           n%4==0&&n/4<=9 ||
           n%3==0&&n/3<=9 ||
           n%2==0&&n/2<=9 ||
           n%1==0&&n/1<=9){
     cout << "Yes" << endl;
     return 0;
     }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    if(N/100 == N%10) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  string e = "";
 
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == '0') {
      e.push_back('0');
    }
    else if(s[i] == '1') {
      e.push_back('1');
    }
    else if (s[i] == 'B' && e.size() > 0) {
      e.pop_back();
    }
  }
  cout << e << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    string s;

    cin >> n >> m >> s;
    
    for (size_t i = 0; i < s.size(); ++i) {
        if (i == m - 1) {
            if (s[i] == 'A') {
                cout << 'a';
            }
            else  if (s[i] == 'B') {
                cout << 'b';
            }
            else {
                cout << 'c';
            }
        }
        else {
            cout << s[i];
        }
        
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
INF = float("inf")

N, x = s_inpl()
a = inpl()

ans = 0
if a[0] > x:
    ans += a[0] - x
    a[0] = x

for i in range(N-1):
    if a[i] + a[i+1] > x:
        tmp = copy.deepcopy(a[i+1])
        a[i+1] = x - a[i]
        ans += tmp - a[i+1]

print(ans)

Measured memory_bytes: 66780
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == ',') s[i] = ' ';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t; cin>>s;
  t=s; sort(t.begin(), t.end());
  auto IT=unique(t.begin(), t.end());
  t.erase(IT, t.end());
  if(t.size()==1){
    cout<<0<<endl;
    return 0;
  }
  long long ans=100, count=0, temp=0;
  for(int i=0; i<t.size(); i++){
    for(int j=0; j<s.size(); j++){
      if(s[j]==t[i] && j<s.size()-1){
        temp=max(temp,count), count=0;
        continue;
      }
      count++;
      if(j==s.size()-1) temp=max(temp,count), count=0, ans=min(ans,temp), temp=0;
    }
//    cout<<"i:"<<i<<" t:"<<t[i]<<" temp:"<<temp<<" ans:"<<ans<<endl;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N=gets.to_i
A=gets.chomp.split.map(&:to_i)
t=0
0.upto(N-1) do |i|
  if i.even?
    t+=A[i]
  else
    t-=A[i]
  end
end
ans = [t]
0.upto(N-2) do |i|
  ans << A[i] * 2 - ans[-1]
end
puts ans.join(" ")

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

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

	int k, t;
	cin >> k >> t;
	int mx = 0;
	for(int i = 0; i < t; i++) {
		int a;
		cin >> a;
		mx = max(a, mx);
	}
	cout << max(0, mx - 1 - (k - mx)) << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
/*
 * sepstr("hoge,fuga:piyo/poya", ",:/");    //1つ目の文字列を、2つ目で与えた区切り文字のセットで分割した結果を返す。O(ND)
 *                                          //この例だと、{"hoge", "fuga", "piyo", "poya"}が返る
 * bitstr(100)          //引数の数値をビット列を示す文字列に変換する
 *                      //宣言内のto_string()には引数を入れることが出来、例えば('_','#')とすると、0をアンダーバー、1を#として表示できる
 * bitcnt(100)          //引数の数値が何ビット立っているか返す
 * bitdig(100)          //ビット列が何ビットあるか返す。
 * bitpow(100)          //その数字の約数に2がいくつあるか。8なら3, 16なら4, 20なら2
 */

template<class T>string bitstr(T x){return typeid(T)==typeid(int)?bitset<32>(x).to_string():bitset<64>(x).to_string();}
template<class T>int bitcnt(T x){return typeid(T)==typeid(int)?__builtin_popcount(x):__builtin_popcountll(x);}
template<class T>int bitdig(T x){return x?typeid(T)==typeid(int)?32-__builtin_clz(x):64-__builtin_clzll(x):0;}
template<class T>int bitpow(T x){return x?typeid(T)==typeid(int)?__builtin_ctz(x):__builtin_ctzll(x):0;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
    int n;
    cin>>n;
    cout<<((n-1)/111+1)*111<<endl;
}


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

using namespace std;

int l[9];
int main() {
	int n, a, b, c, r = 1e9;
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++)
		cin >> l[i];
	for (int i = 0; i < 1 << n + n; i++) {
		int x[4] = {}, u[] = { -1,-1,-1,-1 };
		for (int j = 0; j < n; j++)
			x[i >> j + j & 3] += l[j], u[i >> j + j & 3]++;
		if (u[1] < 0 || u[2] < 0 || u[3] < 0)
			continue;
		r = min(r, (u[1] + u[2] + u[3]) * 10 + abs(x[1] - a) + abs(x[2] - b) + abs(x[3] - c));
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++){
        int cnt = 0;
        if (i % 2 == 1) {
            for(int j = 1; j <= i; j++){
                if (i % j == 0) {
                    cnt++;
                }
            }
            if (cnt == 8) {
                ans++;
            }
        }
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int MAX_N = 100000;
int MAX_W = 100000;

int main (){
  int N;cin >> N;
  vector<int>a(N);
  priority_queue<int> que;
  REP(i,N) {
    cin >> a[i];
    que.push(a[i]);
  }
  int sum = 0;
  int count = 0;
  while(!que.empty()){
    if(count % 2 == 0){
      sum += que.top();que.pop();
      count++;
    }else{
      sum -= que.top();que.pop();
      count++;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

using ll = long long;

ll n;
ll dp[1234567];
ll im[1234567];
const ll MOD = 1000000007;

int main(void)
{
	cin >> n;
	dp[n - 1] = n;
	im[n - 1] = n;
	for (int i = n - 2; i >= 0; --i)
	{
		dp[i] = (n - 1) * (n - 1);//1
		dp[i] %= MOD;
		dp[i] += dp[i + 1];//2
		dp[i] %= MOD;
		if (i + 3 <= n)
		{
			dp[i] += im[i + 3];
			dp[i] += (i + 2);
		}
		else
		{
			dp[i] += n - 1;
		}
		dp[i] %= MOD;
		im[i] = im[i + 1] + dp[i];
		im[i] %= MOD;
	}
	cout << dp[0] << endl;
	return 0;
}


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

using namespace std;

using ll = long long;

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

    ll N, W;
    cin >> N >> W;

    vector<ll> w(N), v(N);
    for (int i = 0; i < N; ++i)
        cin >> w[i] >> v[i];

    const ll MAX_W = 3 * N;
    vector<vector<vector<ll>>> dp(N + 1,
                                  vector<vector<ll>>(N + 1, vector<ll>(MAX_W + 1)));

    dp[0][1][0] = v[0];
    for (int i = 1; i < N; ++i) {
        ll dw = w[i] - w[0];
        for (int j = 0; j <= i; ++j) {
            for (int k = 0; k + dw <= MAX_W; ++k) {
                dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k]);
                dp[i][j + 1][k + dw] = max(dp[i][j][k + dw], dp[i - 1][j][k] + v[i]);
            }
        }
    }

    ll max_v = 0;
    for (int j = 0; j <= N; ++j) {
        for (int k = 0; k <= MAX_W; ++k) {
            if (w[0] * j + k <= W)
                max_v = max(max_v, dp[N - 1][j][k]);
        }
    }

    cout << max_v << endl;

    return 0;
}


Measured memory_bytes: 24832
#include<bits/stdc++.h>
using namespace std;
int resum(int64_t n)
{
    int64_t t=0;
    for(int64_t i=1; i<=n; i++){
        t+=i;
    }
    return t;
}

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin >> s.at(i);
    }
    map<string,long long> v;
    for(int i=0; i<n; i++){
        sort(s.at(i).begin(),s.at(i).end());
        if(v.count(s.at(i))){
            v.at(s.at(i))++;
        }
        else{
            v.insert(make_pair(s.at(i),1));
        }  
    }
    int64_t ans=0;
    for(map<string,long long>::iterator it=v.begin(); it!=v.end(); it++){
        long long partial_sum=0;
        ans += it->second * (it->second - 1) / 2;

    }
    cout << ans << endl;

}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll N;
ll A[200005];
int main() {
    init();
    cin >> N;
    rep(i, N) cin >> A[i];

    map<ll, ll> mp;
    rep(i, N) mp[i - A[i]]++;

    ll ans = 0;
    rep(i,N){
        mp[i - A[i]]--;
        ans += mp[A[i] + i];
    }
    cout << ans << endl;
}

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

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> c;
    
    int count = 0;
    
    for(int i = 1; i <= min(a,b); i++) {
        if(a % i == 0 && b % i == 0) {
            c.push_back(i);
            count++;
        }
    }
    
    
     cout << c[count - k] << endl;

     return 0;
}


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

typedef long long ll;
const int N = 2e5;
ll arr[N + 5];

int main() {
	ll total = 0;
	ll n;
	cin>>n;
	ll cur = 1;
	while(n) {
		total += cur;
		n /= 2;
		cur *= 2;
	}
	cout<<total<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();

    if((n % 2 == 0) ^ (s[0] == s[n-1]))
        cout << "Second" << endl;
    else
        cout << "First" << endl;

    return 0;
}


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

struct Node{
    int pos;
    int cost;
    bool operator< (const Node &r) const{
        return cost > r.cost;
    }
};
 
 
int n, k, INF = 2005;
vector<int> g[2005];

int count(int src, int avoid){
    priority_queue<Node> q;
    q.push({src,0});
    vector<ll> res(n,INF);

    int inside = 0;
    while(q.size()){
        Node n = q.top(); q.pop();
        res[n.pos] = n.cost;
        inside++;
        
        for(auto to : g[n.pos]){
            if(to != avoid)
            if(res[to] == INF)
            if(n.cost+1 <= k/2.0) q.push({to, n.cost + 1});
        }
    }

    return inside;
}


int main(){
    cin >> n >> k;
    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }
  
    priority_queue<int, vector<int>, greater<int>> q;
    rep(src, n){
        if(k%2 == 0)    q.push(n-count(src, -1));
        else{
            for(auto avoid : g[src]){
                q.push(n-count(src, avoid)-count(avoid, src));
            }
        }
    }

    
    cout << q.top() << endl;
 
 
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){
    int a,b,k,i;
    scanf("%d%d%d",&a,&b,&k);
    for(i=a;i<b+1;i++){
        if(i<a+k || i>b-k){
            printf("%d\n",i);
        }
    }
    return 0;
}


Measured memory_bytes: 128
import sys
import copy
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    if A[0] >= 0:
        ans = sum(A[1:]) - A[0]
        plus = copy.deepcopy(A[1:])
        minus = [A[0]]
    elif A[-1] <= 0:
        ans = -sum(A[:-1]) + A[-1]
        plus = [A[-1]]
        minus = copy.deepcopy(A[:-1])
    else:
        plus = []
        minus = []
        ans = 0
        for a in A:
            if a >= 0:
                ans += a
                plus.append(a)
            else:
                ans -= a
                minus.append(a)

    plus = deque(plus)
    minus = deque(minus)
    print(ans)

    # minusをまず一つにする
    while len(minus) > 1:
        p = plus.pop()
        m = minus.pop()
        print(p, m)
        plus.append(p - m)

    # minusが1つになったあとの処理
    p = plus.pop()
    m = minus.pop()
    if len(plus) == 0:
        print(p, m)
        return

    print(m, p)
    cur = m - p
    while len(plus) > 1:
        p = plus.pop()
        print(cur, p)
        cur -= p
    if len(plus) != 0:
        p = plus.pop()
        print(p, cur)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14904
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int64_t> vec(N+1,10000000000);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  int ans = 0;
  int cnt = 0;
  for(int i=0; i<N; i++){
    if(vec.at(i) >= vec.at(i+1)){
      cnt++;
    }
    else{
      ans = max(ans,cnt);
      cnt = 0;
    }
  }
  cout << ans << endl;     
}

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

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

ll N,M,X;
ll C[20];
ll A[20][20];

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

    cin >> N >> M >> X;

    for (int i = 0;i < N;i++){
        cin >> C[i];
        for (int j = 0;j < M;j++){
            cin >> A[i][j];
        }
    }

    ll minimum = 1e10;

    for (int i = 0;i < (1LL<<N);i++){
        ll sum = 0;
        ll skill[20];
        memset(skill,0,sizeof(skill));
        for (int j = 0;j < N;j++){
            if(i&(1<<j)){
                sum += C[j];
                for (int k = 0;k < M;k++){
                    skill[k]+=A[j][k];
                }
            }
        }
        bool f = true;
        for (int j = 0;j < M;j++){
            if(skill[j] < X) f= false;
        }

        if(f) minimum = min(minimum,sum);
    }

    if(minimum == 1e10) cout << -1 << endl;
    else cout << minimum << endl;

    return 0;

}

Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<random>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<cstdlib>
#include<unordered_map>
#include<time.h>
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
#define int long long
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf = 999999999999999999;
using namespace std;
int n, m, a[20], dp[60001];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> a[i];
	fill(dp, dp + 60001, inf);
	dp[0] = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j <= n; j++) {
			dp[j + a[i]] = min(dp[j + a[i]], dp[j] + 1);
		}
	}
	cout << dp[n] << endl;
	getchar(); getchar();
}

Measured memory_bytes: 3568
N, A, B, C = map(int, raw_input().split())
l = [input() for _ in range(N)]
 
def cost(X, x):
  t = 0
  c = 0
  for i in range(N):
    if x>>i&1:
      t += l[i]
      c += 1
  return (c-1)*10 + abs(X-t)
 
ans = 10000
for a in range(1, 1<<N):
  ac = cost(A, a)
  for b in range(1, 1<<N):
    if (a&b)==0:
      bc = cost(B, b)
      for c in range(1, 1<<N):
        if ((a|b)&c)==0:
          cc = cost(C, c)
          ans = min(ans, ac+bc+cc)
print ans


Measured memory_bytes: 2692
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void){
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = max({a * c, a * d, b * c, b * d});
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

int n, q;

struct segtree {
    static const llong inf = 1e18;
    llong offset, seg[1 << 19];
    
    segtree() : offset(0) {
        for (int i = 1 << 19; i--; ) seg[i] = inf;
    }

    void update(int i, int s, int e, int x, llong v) {
        if (s == e) {
            seg[i] = min(seg[i], v);
            return;
        }
        int m = (s + e) / 2;
        if (x <= m) update(i << 1, s, m, x, v);
        else update(i << 1 | 1, m + 1, e, x, v);
        seg[i] = min(seg[i << 1], seg[i << 1 | 1]);
    }

    void update(int x, llong v) {
        update(1, 1, n, x, v - offset);
    }

    llong query(int i, int s, int e, int x, int y) const {
        if (e < x || y < s) return inf;
        if (x <= s && e <= y) return seg[i];
        int m = (s + e) / 2;
        return min(query(i << 1, s, m, x, y), query(i << 1 | 1, m + 1, e, x, y));
    }

    llong query(int x, int y) const {
        return offset + query(1, 1, n, x, y);
    }

    llong getans(int i, int s, int e) const {
        if (s == e) return seg[i] + s;
        int m = (s + e) / 2;
        return min(getans(i << 1, s, m), getans(i << 1 | 1, m + 1, e));
    }

    llong getans() const {
        return getans(1, 1, n) + offset;
    }
} AP, AN, BP, BN;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int A, B, x, p;
    cin >> n >> q >> A >> B >> x;
    AP.update(B, abs(A - x) + B);
    AN.update(B, abs(A - x) - B);
    BP.update(A, abs(B - x) + A);
    BN.update(A, abs(B - x) - A);
    while (--q) {
        p = x;
        cin >> x;
        llong AxBp = min({ BP.query(x, n) - x, BN.query(1, x) + x });
        llong ApBx = min({ AP.query(x, n) - x, AN.query(1, x) + x });
        llong d = abs(x - p);
        AP.offset += d; AN.offset += d; BP.offset += d; BN.offset += d;
        AP.update(p, AxBp + p);
        AN.update(p, AxBp - p);
        BP.update(p, ApBx + p);
        BN.update(p, ApBx - p);
    }
    printf("%lld\n", min(AN.getans(), BN.getans()));
}

Measured memory_bytes: 16640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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

            s = string.Join("", s.OrderBy(c => c).ToArray());
            t = string.Join("", t.OrderByDescending(c => c).ToArray());
            Console.WriteLine(string.Compare(s, t) < 0 ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11488
import sys
r=sys.stdin.readline
for e in iter(r,'0 0\n'):
 N,M=map(int,e.split())
 k,p=1,0
 S=[int(r()) for _ in[0]*N]
 for d in[int(r())for _ in[0]*M]:
  p+=d if N<=p+d else d+S[p+d]
  if N<=p+1:break
  k+=1
 print(k)


Measured memory_bytes: 5644
#include<iostream>
using namespace std;
int main(){
  int d,n;
  int pow_d[3]={1,100,10000};
  cin>>d>>n;
  if (n==100)
    cout<<(n+1)*pow_d[d]<<endl;
  else
    cout<<n*pow_d[d]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b) {
	return b ? GCD(b, a%b) : a;
}
//sort(a, a + N, greater<int>())   // descend
//sort(a, a+N)                    //  ascend

using ll = long long;
using namespace std;


int main() {
	int n, x;
	cin >> n >> x;
	int l[110];
	for (int i = 0; i < n; i++) cin >> l[i];
	int p = 0;
	int j = 0;
	while (p <= x  ) {
		p += l[j];
		j++;
	}
	cout << j;

}

Measured memory_bytes: 256
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

typedef long long LL;
typedef long double LD;
const LL MOD = 1000000007;
const LD EPS = 1e-10;
static const size_t MAX_N = 1000001;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

modll combination(LL n, LL r) {
	static modll fact[MAX_N + 1], inv[MAX_N + 1];
	if (!fact[0]) {
		fact[0] = 1;
		for (int i = 1; i <= MAX_N; ++i) {
			fact[i] = fact[i - 1] * i;
		}
		inv[MAX_N] = modll::modinv(fact[MAX_N]);
		for (int i = MAX_N; i >= 1; --i) {
			inv[i - 1] = inv[i] * i;
		}
	}
	if (r > n) {
		return 0;
	}
	return (fact[n] * inv[r]) * inv[n - r];
}

vector<int> gen_primes(int m) {
	vector<int> primes;
	primes.push_back(2);
	for (int i = 3; i <= m; i += 2) {
		for (int prime : primes) {
			if (i < prime * prime) {
				primes.push_back(i);
				break;
			}
			if ((i % prime) == 0) {
				break;
			}
		}
	}
	return primes;
}

int main(int argc, char* argv[]) {
	vector<int> primes = gen_primes(100005);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1;
		cin >> n;
		if (n < 0) return 0;
		vector<int> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		map<int, int> m;
		for (int i = 0; i < n; ++i) {
			int x = a[i];
			for (int p : primes) {
				if ((x % p) == 0) {
					int c = 0;
					while ((x % p) == 0) {
						++c;
						x /= p;
					}
					m[p] = max(m[p], c);
				}
			}
			if (x > 1) {
				m[x] = 1;
			}
		}
		modll lcm = 1;
		for (auto kv : m) {
			for (int i = 0; i < kv.second; ++i) {
				lcm *= kv.first;
			}
		}
		modll ans = 0;
		for (int i = 0; i < n; ++i) {
			modll x = modll::modinv(a[i]);
			x *= lcm;
			ans += x;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 768
// Submitted By SUbhash Yadav

import java.util.*;
import java.lang.*;
import java.math.BigInteger;
import java.io.*;


public class Main
{ static class Interval { 
    int buy, sell; 
} 
public static int Swaps(int[] arr, int l, int m, int r) 
{ 

  //left
    int[] left = Arrays.copyOfRange(arr, l, m + 1); 

    // Right  
    int[] right = Arrays.copyOfRange(arr, m + 1, r + 1); 

    int i = 0, j = 0, k = l, swaps = 0; 

    while (i < left.length && j < right.length) { 
        if (left[i] <= right[j]) 
            arr[k++] = left[i++]; 
        else { 
            arr[k++] = right[j++]; 
            swaps += (m + 1) - (l + i); 
        } 
    } 

    
    while (i < left.length) 
        arr[k++] = left[i++]; 

   
    while (j < right.length) 
        arr[k++] = right[j++]; 

    return swaps; 
} 
public static int Count(int[] arr, int l, int r) 
{ 

 
    int count = 0; 

    if (l < r) { 
        int m = (l + r) / 2; 

        

        // Left subarray count 
        count += Count(arr, l, m); 

        // Right subarray count 
        count += Count(arr, m + 1, r); 

        //  count 
        count += Swaps(arr, l, m, r); 
    } 

    return count; 
} 

	public static void main (String[] args) throws java.lang.Exception
	{
		
		FastScanner sc=new FastScanner();
		int n=sc.nextInt();
		int a[]=sc.readArray(n);
		
		 long ans=1000;
        
		 for(int i=0;i<n-1;i++)
		 {   long stocks = 0;
         if (a[i] < a[i + 1]) stocks = ans / a[i];
         ans += (a[i + 1] - a[i]) * stocks;
		 }
        
         
         
         
        System.out.println(ans);
		
		}
		static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
}
}


Measured memory_bytes: 32700
import java.util.Scanner;
import java.util.Arrays;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int [] a = new int[4];
    Arrays.fill(a,0);
    for(int i = 0; i<N; i++){
      String S = sc.next();
      if(S.equals("AC")) a[0]++;
      else if(S.equals("WA")) a[1]++;
      else if(S.equals("TLE")) a[2]++;
      else a[3]++;
    }    
    System.out.println("AC x "+ a[0]);
    System.out.println("WA x "+ a[1]);
    System.out.println("TLE x "+ a[2]);
    System.out.println("RE x "+ a[3]);
  }
}

Measured memory_bytes: 59056
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <numeric>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

//最大公約数 GCD
long long gcd( long long x, long long y ){
    int r;
    if ( x < y ) swap( x, y );
    
    while ( y > 0 ){
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
//最小公倍数 LCM
long long lcm(long long x, long long y){

    return (x * y / gcd(x, y));
}


int main(void){

long long a[3],m[3];

	while(!cin.eof()){
		
		rep(i,3) cin >> a[i] >> m[i];
		if(accumulate(a,a+3,0)+accumulate(m,m+3,0)==0) break;

		long long x[3]={1,1,1}, ct[3]={0},cnt=1;
		
		rep(k,3){
			while(1){
				x[k] = a[k]*x[k]%m[k];
				ct[k]++;
				if(x[k]==1) break;
			}
		}
//		printf("%d:%d:%d, \n",ct[0],ct[1],ct[2]);
		
		cout << lcm(lcm(ct[0],ct[1]),ct[2]) << endl;
	}

	return 0;
	
}

Measured memory_bytes: 1156