akhauriyash/Code-Regression huggingface dataset:
/*
[dp] J - Sushi
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 300;

int N;
int a[MAX_N];

double solve() {
    vector<vector<vector<double>>> dp(
        N + 1, vector<vector<double>>(N + 1, vector<double>(N + 1)));
    int cnt[4];

    for (int j = 1; j <= 3; j++) {
        cnt[j] = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] >= j) {
                cnt[j]++;
            }
        }
    }

    dp[0][0][0] = 0;
    for (int i = 1; i <= cnt[1]; i++) {
        for (int j = 0; j <= min(i, cnt[2]); j++) {
            for (int k = 0; k <= min(j, cnt[3]); k++) {
                dp[i][j][k] = N;
                if (k > 0) {
                    dp[i][j][k] += dp[i][j][k - 1] * k;
                }
                if (j > k) {
                    dp[i][j][k] += dp[i][j - 1][k] * (j - k);
                }
                if (i > j) {
                    dp[i][j][k] += dp[i - 1][j][k] * (i - j);
                }
                dp[i][j][k] /= i;
            }
        }
    }

    return dp[cnt[1]][cnt[2]][cnt[3]];
}

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

    cout << setprecision(16) << solve() << endl;

    return 0;
}


Measured memory_bytes: 216832
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lloop(i, a, b) for(ll i=a;i<(ll)b; i++)
#define loop(i, a, b) for(int i=a;i<b;i++)

int main(){
	int n;
	cin>>n;
	string s="";
	getchar();
	cin>>s;
	ll ans=0;
	int count[n][3];
	loop(i, 0, n)
		count[i][0]=count[i][1]=count[i][2]=0;
	for(int i=n-1;i>=0;i--){
		if(s[i]=='R')
			++count[i][0];
		else if(s[i]=='G')
			++count[i][1];
		else if(s[i]=='B')
			++count[i][2];
		if(i==n-1)
			continue;
		count[i][0]+=count[i+1][0];
		count[i][1]+=count[i+1][1];
		count[i][2]+=count[i+1][2];
	}
	loop(i, 0, n-2){
		loop(j, i+1, n-1){
			if(s[i]!=s[j]){
				if(j+j-i < n && s[j+j-i]!=s[j] && s[j+j-i]!=s[i])
					--ans;
				bool r=0, g=0, b=0;
				if(s[i]=='R'||s[j]=='R')
					r=1;
				if(s[i]=='G'||s[j]=='G')
					g=1;
				if(s[i]=='B'||s[j]=='B')
					b=1;
				if(!r)
					ans+=count[j+1][0];
				if(!g)
					ans+=count[j+1][1];
				if(!b)
					ans+=count[j+1][2];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	for(int i=1;i<10000;i++) if(floor(i*0.08) == a && floor(i*0.1) == b) {
		cout << i; return 0;
	}
	cout << -1;
}

Measured memory_bytes: 256
import bisect
import sys
input = sys.stdin.readline

A, B, Q=map(int,input().split())
INF=10**18

s=[-INF]+[int(input()) for i in range(A)]+[INF]
t=[-INF]+[int(input()) for i in range(B)]+[INF]

for q in range(Q):
  x = int(input())
  b, d = bisect.bisect_right(s, x),bisect.bisect_right(t, x)
  res=INF
  for S in [s[b-1], s[b]]:
    for T in [t[d-1], t[d]]:
      d1, d2 = abs(S-x)+abs(T-S),abs(T-x)+abs(S-T)
      res = min(res, d1, d2)
  print(res)

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

int main()
{
  int k;
  cin >> k;
  
  int ans = 0;
  for(int a = 1; a <= k; a++){
    for(int b = 1; b <= k; b++){
      for(int c = 1; c <= k;c++){
        ans += gcd(gcd(a,b),c);
      }
    }
  }
  
  cout << ans << endl;
}

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

#define pb push_back
#define mp make_pair

#define fi first
#define se second

typedef long long ll;

using namespace std;
ll n, a[100500];
ll pref[100500];

int main(){

cin >> n;

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

int t = 0;
for(int i=2;i<=n;i++){
    if(a[i] > a[i - 1] * 2){
        t = i - 1;
    }
    a[i] += a[i - 1];
}
cout << n - t;

return 0;
}


Measured memory_bytes: 1024
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

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

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
const lli maxN = 100000L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vii e[maxN+5];
    lli col[maxN+5];

void dfs(lli u,lli p,lli k)
{
    lli cnt=0;
    for(auto x:e[u])
    {
        if(x.X==p)
            continue;
        cnt++;
        if(cnt==k)
            ++cnt;
        col[x.Y]=cnt;
        dfs(x.X,u,cnt);
    }
}
int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    repA(i,1,n-1)
    {
        cin>>u>>v;
        e[u].pb({v,i});
        e[v].pb({u,i});
    }

    lli rt=0;
    repA(i,1,n)
    {
        if(sz(e[rt])<sz(e[i]))
            rt=i;
    }

    cout<<sz(e[rt])<<endl;
    dfs(rt,-1,0);

    repA(i,1,n-1)
        cout<<col[i]<<endl;
}   aryanc403();
    return 0;
}

Measured memory_bytes: 8704
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

bool check(string s) {
	int N = s.size();

	for (int i = 0; i < N / 2; i++) {
		if (s[i] != s[N - i - 1]) {
			return false;
		}
	}

	return true;
}

int main(void) {
	int cnt = 0;
	string s;
	while (getline(cin, s)) {
		if (check(s)) {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1184
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        v: [i64; 3],
        k: usize
    }
    fn f(remain: usize, a: i64, b: i64, c: i64) -> i64 {
        if remain == 0 {
            a + b + c
        } else {
            let v = [
                f(remain - 1, a * 2, b, c),
                f(remain - 1, a, b * 2, c),
                f(remain - 1, a, b, c * 2),
            ];
            *v.iter().max().unwrap()
        }
    }
    let ans = f(k, v[0], v[1], v[2]);
    println!("{}", ans);
}


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

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

int main() {
  int n;
  cin >> n;
  vector<i64> a(n);
  int n2 = log(1e13) / log(2) + 1;
  int n5 = log(1e13) / log(5) + 1;
  vector<i64> cnt(n2 * n5, 0);
  for (i64& x : a) {
    long double f;
    cin >> f;
    x = f * 1e9 + 0.5;
    int c2 = 0, c5 = 0;
    while (x % 2 == 0) {
      c2++;
      x /= 2;
    }
    while (x % 5 == 0) {
      c5++;
      x /= 5;
    }
    cnt[c2 * n5 + c5]++;
  }
  i64 ans = 0;
  rep(i, n2 * n5) {
    for (int j = i; j < n2 * n5; j++) {
      int i2 = i / n5, i5 = i % n5;
      int j2 = j / n5, j5 = j % n5;
      if (i2 + j2 < 18 || i5 + j5 < 18) continue;
      if (i == j) {
        ans += cnt[i] * (cnt[i] - 1) / 2;
      } else {
        ans += cnt[i] * cnt[j];
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    string s;
    while (cin >> s) {
        int n = s.size(), mn = s[0];
        fore(i,0,n) {
            if (s[i] > mn) {
                mn++;
                break;
            }
        }
        cout << string(n, mn) << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <set>
#include <string>
#include <sstream>
#include<map>
#include <vector>
#define maxn 100000+15
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[maxn];
	int b[maxn];
	int j=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==i){
			b[j++]=i;
		}
	}
	int swp=0;
	for(int i=0;i<j;i++){
		if(a[b[i]]==b[i]){
			if(b[i]+1!=n-1){
				int x=a[b[i]];
				a[b[i]]=a[b[i]+1];
				a[b[i]+1]=x;
			}
			swp++; 
		}
	}
	cout<<swp<<endl;
	
}

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

double a[100000];
double b[100000];

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

	int N;
	cin >> N;
	map<double, int> cnt;
	for(int i = 0; i < N; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + N);
	for(int i = 0; i < N; i++) {
		int win = lower_bound(b, b + N, a[i]) - b;
		int draw = (upper_bound(b, b + N, a[i]) - b) - win - 1;
		cout << 3 * win + draw << endl;
	}
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	int n;
	cin >> n;

	vector<int> a(n);
	rep (i, 0, n)
		cin >> a[i];

	int res = 0;
	rep (i, 0, n) {
		while (!(a[i] & 1)) {
			a[i] >>= 1;
			res++;
		}
	}

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


Measured memory_bytes: 256
//....SARANSH GUPTA....\\  

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(p,n) for(int i=p;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define endl "\n"
#define mp make_pair
#define pb push_back
#define mod 1000000007

int main()
{
    FIO
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==0)
    cout<<"0";
    else
    {
        if(a%b==0)
        {
            ll val=a/b;
            cout<<val*c;
        }
        else
        {
            ll val=a/b +1;
            cout<<val*c;
        }
    }
}

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

using namespace std;

int main(){

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

    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    } 

    sort(a.begin(), a.end());
    for(int i = 0; i < n; i++){
        cout << a.at(i);
    } 

}

Measured memory_bytes: 256
n, k = [int(v) for v in input().split()]
h = [int(input()) for i in range(n)]

h.sort()
ans = h[k-1] - h[0]
for i in range(1, n - k + 1):
    diff = h[i + k - 1] - h[i]
    ans = min(ans, diff)

print(ans)

Measured memory_bytes: 7488
#include <iostream>
#include <unordered_set>

int main()
{
    const std::unordered_set<int> g1{1, 3, 5, 7, 8, 10, 12}, g2{4, 6, 9, 11}, g3{2};
    int x, y;
    std::cin >> x >> y;

    bool same = false;
    if (g1.find(x) != g1.end())
    {
        same = g1.find(y) != g1.end();
    }
    else if (g2.find(x) != g2.end())
    {
        same = g2.find(y) != g2.end();
    }
    else
    {
        same = false;
    }

    if (same)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    string S, T;
    while (cin >> S >> T) {
        int N = S.size();
        if (T.size() == S.size() + 1 && T.substr(0, N) == S) puts("Yes");
        else puts("No");
    }
}

















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

namespace ITP1_6B
{
    class Program
    {
        static void Main(string[] args)
        {
            var cardCount = int.Parse(Console.ReadLine());
            var cards = 0L;
            var marks = "SHCD";

            for (var i = 0; i < cardCount; ++i)
            {
                var words = Console.ReadLine().Split(' ');
                var cardType = marks.IndexOf(words[0]);
                if (cardType < 0)
                {
                    continue;
                }

                cards |= 1L << (int.Parse(words[1]) - 1 + 13 * cardType);
            }

            for (var i = 0; i < marks.Length; ++i) 
            {
                var cardsOfKind = (cards >> (13 * i)) & 0x1fff;
                for (var h = 0; h < 13; ++h)
                {
                    var hasAnyCards = cardsOfKind != 0;
                    if (hasAnyCards == false || (cardsOfKind & 0x01) == 0)
                    {
                        Console.WriteLine("{0} {1}", marks[i], h + 1);
                    }
                    if (hasAnyCards) 
                    {
                        cardsOfKind >>= 1;
                    }
                }
            }

        }
    }
}

Measured memory_bytes: 6256
fun main(args: Array<String>) {
    val n= readLine()!!.toLong()
    val a = readLine()!!.split(" ").map(String::toLong)
    println(gcd2(a))
}

fun gcd1(a: Long, b: Long): Long {
    return if (b > 0) gcd1(b, a % b) else a
}

fun gcd2(param: List<Long>): Long {
    var g = gcd1(param[0], param[1])
    for (i in 2 until param.size) g = gcd1(g, param[i])
    return g
}


Measured memory_bytes: 53492
#include<stdio.h>
#include<algorithm>
using namespace std;
long long  a[55];
int main()
{
    int n,m,i,j,k;
    long long sum=0;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
        sort(a,a+n);
        for(i=n-1;i>=n-m;i--)
            sum=sum+a[i];
        printf("%lld\n",sum);
        return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+7;
int dir[4][2] = {
    0,1,
-1,0,   1,0,
    0,-1
};
int n,m;
ll ans;
char s[405][405];
int p[maxn],cnt[maxn],c_[maxn];
int Hash(int x,int y){
    return x*400+y;
}
int Find(int x){
    return x == p[x]?x:p[x] = Find(p[x]);
}
void Merge(int x,int y){
    x = Find(x),y = Find(y);
    if(x!=y){
        p[x] = y;
        cnt[y] += cnt[x];
        c_[y] += c_[x];
    }
}
int main(){
    for(int i=0;i<maxn;i++)
        p[i] = i,cnt[i] = 1;
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>s[i]+1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(s[i][j] == '#')
                c_[Hash(i,j)] = 1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            for(int k=0;k<4;k++){
                int x = i+dir[k][0];
                int y = j+dir[k][1];
                if(x>0&&x<=n&&y>0&&y<=m && s[i][j]!=s[x][y]){
                    Merge(Hash(x,y),Hash(i,j));
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int h = Find(Hash(i,j));
            if(cnt[h]>1){
                ans += 1ll*c_[h]*(cnt[h]-c_[h]);
                cnt[h] = -1;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
typedef long long ll;
using namespace std;
int main(){
  ll b_cnt=0,sum=0;
  string s;
  cin >> s;
  for(int i=0;i<s.length();i++){
    if(s[i]=='B') b_cnt++;
    else{
      sum+=b_cnt;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;




int main(){

    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;


        VEC rui(n);
        rui[0] = 0;
        for(int i = 1; i < n; ++i)
        {
            rui[i] = rui[i - 1];
            if (s[i - 1] == 'A' && s[i] == 'C')
            {
                rui[i]++;
            }
        }

        for(int j = 0; j < q; ++j)
        {
            int l;cin>>l;l--;
            int r;cin>>r;r--;
            cout<<rui[r]-rui[l]<<endl;
        }

        
}



Measured memory_bytes: 1792
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		long ans = 0;
		for (int i = 0; i < N; i++) {
			char[] s = sc.next().toCharArray();
			Arrays.sort(s);
			if (map.get(String.valueOf(s)) == null) {
				map.put(String.valueOf(s), 1);
			} else {
				int now = map.get(String.valueOf(s));
				ans += now;
				map.replace(String.valueOf(s), ++now);
			}
		}
		System.out.println(ans);
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 51012
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char  **argv)
{
	char *str = (char *)malloc(sizeof(char)*1000);
	int i, n;

	scanf("%s", str);
	n = strlen(str);
	
	for(i = 0; i < n; i++){
		if(str[i] == 'A'){
			printf("X");
		} else if(str[i] == 'B'){
			printf("Y");
		} else if(str[i] == 'C'){
			printf("Z");
		} else {
			printf("%c", (str[i]-3));
		}
	}
	printf("\n");
	
	free(str);
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
using namespace std;
vector<pair<int,int> > vpii(80);
string num;
void print(int s,int f){
  switch(f-48){
  case 1:switch(s%5){
    case 1:cout<<'.';break; case 2:cout<<',';break; case 3:cout<<'!';break;case 4:cout<<'?';break; case 0:cout<<" ";break;}break;
  case 2:switch(s%3){
    case 1:cout<<'a';break; case 2:cout<<'b';break; case 0:cout<<'c';break;}break;
  case 3:switch(s%3){
    case 1:cout<<'d';break;case 2:cout<<'e';break;case 0:cout<<'f';break;}break;
  case 4:switch(s%3){
    case 1:cout<<'g';break;case 2:cout<<'h';break;case 0:cout<<'i';break;} break;
  case 5:switch(s%3){
    case 1:cout<<'j';break;case 2:cout<<'k';break;case 0:cout<<'l';break;} break;
  case 6:switch(s%3){
    case 1:cout<<'m';break;case 2:cout<<'n';break;case 0:cout<<'o';break;} break;
  case 7:switch(s%4){
    case 1:cout<<'p';break;case 2:cout<<'q';break;case 3:cout<<'r';break;case 0:cout<<'s';break;} break;
  case 8:switch(s%3){
    case 1:cout<<'t';break;case 2:cout<<'u';break;case 0:cout<<'v';break;}break; 
  case 9:switch(s%4){
    case 1:cout<<'w';break;case 2:cout<<'x';break;case 3:cout<<'y';break;case 0:cout<<'z';break;}break;
  default :break; 
  }
}
int main(){
  int k=0,l=0,n;
  cin >> n;
  for(int q=0;q<n;q++){
    l=0;
    cin >> num;
    int a;
    for(int i=0;i<num.size();i++){
      if(i==0)
	a=num[0];
      k++;
      if(i!=0&&num[i]=='0' &&num[i-1]=='0'){
	k=0;
	continue;
      }else {
      if(num[i]!='0')
	a=num[i];
      if(num[i]=='0'){
	vpii[l]=make_pair(a,k-1);
	l++;
	k=0;
      }}
    }
    for(int j=0;j<l;j++){
      int w=0;
      print(vpii[j].second,vpii[j].first);
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    int N;
    double T,A;
    int H[1001];
    vector<double> diff;
    cin>>N>>T>>A;
    
    for(int i=0;i<N;i++){
        cin>>H[i];
        diff.emplace_back(abs(T-0.006*H[i]-A));
    }
    int min=min_element(diff.begin(),diff.end())-diff.begin();
    
    printf("%d",min+1);
    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;

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

    int n;
    cin >> n;

    long long ans = 1;
    for(int i = 1; i <= n; i++){
        ans = (ans * i) % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


vector<ll> finstate;

ll odd, even, pR, pL;
char tmp;

int main() {
	string S; cin >> S;
	finstate.assign(S.size(), 0);
	tmp = 'R';
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'R') {
			if (tmp == 'R') {
				if (i % 2 == 0)even++;
				else odd++;
			}
			else {
				tmp = 'R';
				if (pR % 2 == 0) {
					finstate[pR] += even;
					finstate[pL] += odd;
				}
				else {
					finstate[pR] += odd;
					finstate[pL] += even;
				}
				even = 0;
				odd = 0;
				if (i % 2 == 0)even++;
				else odd++;
			}

		}

		if (S[i] == 'L') {
			if (tmp == 'R') {
				tmp = 'L';
				pR = i - 1;
				pL = i;
				if (i % 2 == 0)even++;
				else odd++;

			}
			else {
				if (i % 2 == 0)even++;
				else odd++;

			}

		}

	}
	if (pR % 2 == 0) {
		finstate[pR] += even;
		finstate[pL] += odd;
	}
	else {
		finstate[pR] += odd;
		finstate[pL] += even;
	}

	for (int i = 0; i < S.size(); i++) {
		cout << finstate[i];
		if (i != S.size() - 1)cout << " ";
	}
	cout << endl;



	return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.nextLine();
		int len=s.length();
		char c = s.charAt(len-1);
		if(c=='s')s+="es";
		else s+='s';
		System.out.println(s);

	}

}


Measured memory_bytes: 38588
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> v(N);
	rep(i, 0, N*(N - 1) / 2) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		a--, b--;
		if (c > d)v[a] += 3;
		else if (c < d)v[b] += 3;
		else if (c == d)v[a]++, v[b]++;
	}
	dump(v);
	vector<int> v2 = v;
	sort(all(v2));
	dump(v2);
	rep(i, 0, N) {
		cout << N - (upper_bound(v2.begin(), v2.end(), v[i]) - v2.begin()) + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap();
    let mut x = it.next().unwrap().parse::<i32>().unwrap();
    let mut a = (0..n).map(|_| it.next().unwrap().parse::<i32>().unwrap()).collect::<Vec<_>>();
    a.sort();
    let mut res = 0;
    for &t in &a {
        if t <= x {
            x -= t;
            res += 1;
        }
    }
    if res == n && x != 0 { res -= 1; }
    println!("{}", res);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void)
{
		int a,b,c,d,e,f,x;
		scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
		x=a*1+b*5+c*10+d*50+e*100+f*500;
		if(x>=1000){
			printf("1\n");
			}
		else{
			printf("0\n");
			}
		return 0;
}

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

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define SPACE " "

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

// BEGIN //////////////////////////////////////////////////////////////
int main() {
  while (true) {
    int N = nextInt();
    if (N == 0) break;
    int ans = 0;
    int h, m, s;
    int arr[100000] = {0};
    REP(i, N) {
      scanf("%d:%d:%d", &h, &m, &s);
      arr[h * 60 * 60 + m * 60 + s] ++;
      scanf("%d:%d:%d", &h, &m, &s);
      arr[h * 60 * 60 + m * 60 + s] --;
    }

    REP(i, 100000 - 1) {
      arr[i + 1] += arr[i];
      if (ans < arr[i + 1]) {
        ans = arr[i + 1];
      }
    }

    PRINT(ans);
  }
  return 0;
}
// END   //////////////////////////////////////////////////////////////

Measured memory_bytes: 1636
x, y = map(int,input().split())

for i in range(y + 1) :
  print ('#', end = '')
print ('#')

for i in range(x) :
  print ('#', end = '')
  print (input(), end = '')
  print ('#')

for i in range(y + 1) :
  print ('#', end = '')
print ('#')


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#define INF 100000
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int moneyA(int gram){
	int n=gram/200;
	int res=gram%200;
	if(res)return INF;
	int money=0;
	int sell=n/5;
	int normal=n%5;
	money=sell*5*380*0.8+normal*380;
	return money;
}

int moneyB(int gram){
	int n=gram/300;
	int res=gram%300;
	if(res)return INF;
	int money=0;
	int sell=n/4;
	int normal=n%4;
	money=sell*4*550*0.85+normal*550;
	return money;
}

int moneyC(int gram){
	int n=gram/500;
	int res=gram%500;
	if(res)return INF;
	int money=0;
	int sell=n/3;
	int normal=n%3;
	money=sell*3*850*0.88+normal*850;
	return money;
}

int money=INF;

void func(int gram,int count,int cost){
	if(count==0){
		for(int i=0;i<=gram;i+=100){
			if(moneyA(i)!=INF)func(gram-i,count+1,cost+moneyA(i));
			else func(gram,count+1,cost);
		}
	}else if(count==1){
		for(int i=0;i<=gram;i+=100){
			if(moneyB(i)!=INF)func(gram-i,count+1,cost+moneyB(i));
			else func(gram,count+1,cost);
		}
	}else if(count==2){
		for(int i=0;i<=gram;i+=100){
			if(moneyC(i)!=INF)func(gram-i,count+1,cost+moneyC(i));
			else func(gram,count+1,cost);
		}
	}else{
		if(gram!=0)return;
		else{
			money=min(money,cost);
			return;
		}
	}
	count++;
}


int main(){
	int want;
	while(cin>>want,want){
		money=INF;
		func(want,0,0);
		cout<<money<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  ll N; cin >> N;
  vector<pair<ll,ll>> BA(N);
  for(ll i = 0; i < N; i++){cin >> BA[i].second  >> BA[i].first;}
  
  sort(BA.begin(),BA.end());
   ll sum = 0;
  bool flag = true;
  for(ll i = 0; i < N; i++){
    sum += BA[i].second;
    if(sum > BA[i].first){ flag = false; break;}}
  
  if( !flag){ cout << "No" << endl;}
else{ cout << "Yes" << endl;}
  return 0;}


Measured memory_bytes: 3328
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
double pi= 3.14159265358979323846;
int main(){
	int R;
	cin>>R;
	printf("%.20lf\n",2*pi*R);
	return 0;
} 
//458.67252742410977361942
//458.67252742410977361942

//6.28318530717958623200
//6.28318530717958623200

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           (long long)1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigint        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(aint(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 

template <typename T>
T ceil(T a, T b){ return (a+b-1)/b; }


template<typename T>
T binpow(T a, T b, T m) {
    a %= m;
    T res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

void solve(){
    int n; cin>>n;
    int a[n];
    FOR(i, 0, n) cin>>a[i];
    if(is_sorted(a, a+n)) {
        cout<<0<<endl;
        return;
    }
    int mx = a[0], res=0;
    FOR(i, 1, n) {
        if(a[i]>mx) {
            mx = a[i];
        } else {
            res += mx-a[i];
        }
    }
    cout<<res;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);     
    int t=1;
    //cin>>t;
    FOR(i, 1, t+1){ 
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
 
}


Measured memory_bytes: 5176
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

ll euclidean_gcd(ll a, ll b) {
  if(a < b) euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


int main() {

  ll n, x;
  cin >> n >> x;

  vector<ll> array(n);
  REP(i, n){
    cin >> array[i];
    array[i] = abs(array[i] - x);
    //cout << array[i] << endl;
  }
  ll min_gcd = array[0];
  REP(i, n){
    min_gcd = euclidean_gcd(min_gcd, array[i]);
  }

  cout << min_gcd << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long Int;
Int mod = 1e9+7;
Int MOD = 998244353;

int main() {
    Int n, p;
    cin >> n >> p;
    if (n == 1) {
        dump(p);
        return 0;
    }
    Int c = 0;
    Int res = 1;
    for (Int i = 2; i*i <= p; i++) {
        c = 0;
        while (p%i == 0) {
            p /= i;
            c++;
            if (c%n == 0) res *= i;
        }
    }
    dump(res);
    return 0;  
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.insert(0, 0)
A.append(0)
distance = []
sum_val = 0
for i in range(1,len(A)):
    d = abs(A[i] - A[i - 1])
    sum_val += d
    distance.append(d)
banish_list = []
now_direct = "no"
for next in range(1,len(A)):

    if A[next - 1] < A[next]:
        next_direct = "right"
    elif A[next - 1] > A[next]:
        next_direct = "left"
    else:
        next_direct = "no"
    if now_direct != next_direct and (next_direct != "no" and now_direct != "no"):
        d = min(distance[next - 1] , distance[next - 2])
    else:
        d = 0
    banish_list.append(d)
    now_direct = next_direct
banish_list.pop(0)
for b in banish_list:
    print(sum_val - b * 2)

Measured memory_bytes: 14172
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  vector<vector<int>> B(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>B[i][j];
    }
  }
  int N;
  cin>>N;
  vector<int> b(N);
  for(int i=0;i<N;i++){
    cin>>b[i];
  }
  for(int k=0;k<N;k++){
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        if(b[k]==B[i][j]){
          B[i][j]=0;
        }
      }
    }
  }
  if(B[0][0]==0&&B[1][0]==0&&B[2][0]==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(B[0][1]==0&&B[1][1]==0&&B[2][1]==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(B[0][2]==0&&B[1][2]==0&&B[2][2]==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(B[0][0]==0&&B[1][1]==0&&B[2][2]==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(B[0][2]==0&&B[1][1]==0&&B[2][0]==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(B[0][0]==0&&B[0][1]==0&&B[0][2]==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(B[1][0]==0&&B[1][1]==0&&B[1][2]==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(B[2][0]==0&&B[2][1]==0&&B[2][2]==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  else{
    cout<<"No"<<endl;
    return 0;
  }
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <random>
#include <math.h>
#include <algorithm>
#include <queue>
#define LL long long

using namespace std;

const int mod = 1e9+7;
const int maxn = 11234567;

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

    int t;
    int n, k, m;

    scanf("%d", &t);

    if (t%2 == 0) puts("0.5000000000");
    else printf("%.8f\n", ((t+1)*1.0/2/t));

    return 0;
}


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

int main(){
  
  int n;
  
  cin >> n;
  vector<int> A(n);
  for(int i = 0;i < n;i++) A[i] = i + 1;
  
  do{
    for(int i = 0;i < n;i++){
      cout << (i?" ":"");
      cout << A[i];
    }
    cout << endl;
  }while(next_permutation(A.begin(), A.end()));
  
  return 0;
}


Measured memory_bytes: 3092
import java.util.*;


public class Main {

    public static void main(String[] args) {
      Scanner reader=new Scanner(System.in);
      int k=reader.nextInt();
      int a=reader.nextInt();
      int b=reader.nextInt();
      for(int i=a;i<=b;i++)
      {
        if(i%k==0)
        {
          System.out.println("OK");
          return;
        }


      }
        System.out.println("NG");

}




}


Measured memory_bytes: 35872
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define INF (1<<9)

struct P {
    int from, money, damage;

    bool operator >(const P& p) const {
        return damage > p.damage;
    }
};

struct edge {
    int from, cost, damage;
};

int main() {
    int town_n, road_n, money;
    while (cin >> town_n >> road_n >> money, town_n|road_n|money) {
        vector<vector<edge>> E(town_n+1);
        REP(i, road_n) {
            int to, from, cost, damage;
            cin >> to >> from >> cost >> damage;
            E[to].push_back({from, cost, damage});
            E[from].push_back({to, cost, damage});
        }

        bool G[town_n+1][money+1];
        fill_n((bool *)G, (town_n+1)*(money+1), false);

        priority_queue<P, vector<P>, greater<P>> que;
        que.push({1, money, 0});
        while (!que.empty()) {
            P p = que.top(); que.pop();
            if (p.from == town_n) {
                cout << p.damage << endl;
                break;
            }

            if (!G[p.from][p.money]) {
                G[p.from][p.money] = true;
                for (edge e : E[p.from]) {
                    if (p.money >= e.cost) {
                        que.push({e.from, p.money - e.cost, p.damage});
                    }
                    que.push({e.from, p.money, p.damage + e.damage});
                }
            }
        }
    }
}

Measured memory_bytes: 1884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int n;
    cin >> n;
    vi a(n);
    vi b(n);
    rep(i, n)
    {

        cin >> a[i];
    }
    rep(i, n)
    {
        if (n % 2 == 0)
        {
            if (i + 1 <= n / 2)
            {
                cout << a[n - 1 - i * 2] << " ";
            }
            else
            {
                cout << a[2 * (i - n / 2)] << " ";
            }
        }
        else
        {
            if (i <= n / 2)
            {
                cout << a[n - 1 - i * 2] << " ";
            }
            else
            {
                cout << a[2 * (i - n / 2) - 1] << " ";
            }
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4768
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

struct UnionFind{
  vector<ll> par;
  vector<ll> rank;
  vector<ll> sizes;

  UnionFind(ll n){
    init(n);
  }

  void init(ll n){
    par.resize(n);
    rank.resize(n);
    sizes.resize(n);
    REP(i,n){
      par[i] = i;
      rank[i] = 0;
      sizes[i] = 1;
    }
  }

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

  void unite(ll x, ll y){
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(rank[x]<rank[y]){
      par[x] = y;
      sizes[y] += sizes[x];
    }else{
      par[y] = x;
      sizes[x] += sizes[y];
      if(rank[x]==rank[y]) rank[x]++;
    }
  }

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

  ll size(ll x){
    return sizes[find(x)];
  }
};
struct edge{ll from, to, cost;};
bool compare_edge(const edge& e1, const edge& e2){
  return e1.cost<e2.cost;
}
struct graph{
  vector<edge> es;
  ll V;
  graph(ll n){
    init(n);
  }
  void init(ll n){
    V = n;
  }
  void add_edge(ll from, ll to, ll cost){
    edge e;
    e.from = from, e.to = to, e.cost = cost;
    es.push_back(e);
  }
  ll kruskal(){
    sort(es.begin(),es.end(),compare_edge);
    UnionFind uf(V);
    ll res = 0;
    for(auto e : es){
      if(!uf.same(e.from,e.to)){
        uf.unite(e.from,e.to);
        res += e.cost;
      }
    }
    return res;
  }
};

int main(){
  ll V, E;
  cin >> V >> E;
  graph g(V);
  REP(i,E){
    ll s,t,w;
    cin >> s >> t >> w;
    g.add_edge(s,t,w);
  }
  cout << g.kruskal() << endl;
  return 0;
}



Measured memory_bytes: 6000
#include <cstdio>

typedef long long ll;

ll myabs(ll a) {
	return a > 0 ? a : -a;
}

int main() {
	ll a, b, v, w, t;
	scanf("%lld%lld%lld%lld%lld", &a, &v, &b, &w, &t);
	ll dif = myabs(a - b);
	if (dif > t * (v - w))
		puts("NO");
	else
		puts("YES");
	return 0;
}


Measured memory_bytes: 1656
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n;
  cin >> n;
  
  vector<string> p={"1","2","3","4","5","6","7","8","9"};
  vector<vector<string>> q(11,p);

  repo(i,11){
   for(string s : q[i-1]){
    char a,b,c;
    b=s[s.size()-1];
    a=b-1;
    c=b+1;
    string x,y,z;
    x=s+a;
    y=s+b;
    z=s+c;
    if(b=='0') {
      q[i].pb(y);
      q[i].pb(z);
    }
    else if('1'<=b && b<='8') {
      q[i].pb(x);
      q[i].pb(y);
      q[i].pb(z);
    }
    else if(b=='9') {
      q[i].pb(x);
      q[i].pb(y);
    }
   }
  }
  
  
  
  
  
  
  cout << q[10][n-1] << endl;

}

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

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

Measured memory_bytes: 256