akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int ispalindrome(string s,int l,int r)
{
    
    while(l<r)
    {
        if (s[l]!=s[r])
        return 0;
        l++;
        r--;
    }
    return 1;
}
signed main() {
    fast;
    string s;
    cin>>s;
    if (!ispalindrome(s,0,s.length()-1))
    {
        cout<<"No"<<endl;
        return 0;
    }
    int n=s.length();
    s="#"+s;
    //int n=s.length();
    if (!ispalindrome(s,1,(n-1)/2))
    {
        cout<<"No"<<endl;
        return 0;
    }
    if (!ispalindrome(s,(n+3)/2,n))
    {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())
min_cost = 10**10

#fit x
price = 0
num_c = x * 2
price += c * num_c
if x < y:
  price += (y - x) * b
min_cost = min(min_cost, price)

#fit y
price = 0
num_c = y * 2
price += c * num_c
if x > y:
  price += (x - y) * a
min_cost = min(min_cost, price)

#buy each
min_cost = min(min_cost, a * x + b * y)

print(min_cost)

Measured memory_bytes: 38384
def myAnswer(N:int,K:int,Q:int,A:dict) -> None:
   for user,point in A.items():
      if( K -  (Q - point) <= 0):
         print("No")
      else:
         print("Yes")



def modelAnswer():
   tmp=1
def main():
   N, K, Q = map(int,input().split())
   A = {key:0 for key in range(1,N+1)}
   for _ in range(Q):
      tmp=int(input())
      A[tmp]+=1
   myAnswer(N,K,Q,A)

if __name__ == '__main__':
   main()

Measured memory_bytes: 15084
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
 
int main() {
    int a, b, x; cin >> a >> b >> x;
    if(x<=a+b && x>=a) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long i,k,p,n;
    long max;
    while(scanf("%ld",&n)!=EOF)
    {
        int j;
        max=0;
        p=1;
        for(i=1; i<=n; i++)
        {
            k=0;
            j=i;
            while(j/=2)
            {
                k++ ;
            }
            if(k>max)
            {
                max=k;
                p=i;
            }
        }
        printf("%ld\n",p);
    }
    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

N = int(input())

ans = 0
for i in range(1, N + 1, 2):
    count = 0
    for j in range(1, i + 1):
        if i % j == 0:
            count += 1
    if count == 8:
        ans += 1

print(ans)


Measured memory_bytes: 2940
// template version 1.11
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings {{{
#define infile "../test/sample-1.in"
#define int long long
const int INF=1e18;
const int MOD=1e9+7;
// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int dp[51][51][100];

int solve(){
  int n,k;cin>>n>>k;
  vector<int> v(n);
  rep(i, n) {
    cin>>v[i];
  }
  dump(v);

  int res=-INF;

  rep(bc, k){
    // get k-bc
    int d = k-bc;
    if (d>=n){
      vi dd = v;
      sort(all(dd));
      int r = bc;
      int ans=0;
      rep(i, sz(dd)){
        if (dd[i]<0 and r>0){
          r--;
        }
        else{
          ans += dd[i];
        }
      }
      chmax(res, ans);
    }
    else{
      rep(l, 0, d+1){
        vi dd;
        rep(i, l){
          dd.pb(v[i]);
        }
        int R = d-l;
        rep(i, n-R, n){  // d-l
          dd.pb(v[i]);
        }
        sort(all(dd));
        int r = bc;
        int ans=0;
        rep(i, sz(dd)){
          if (dd[i]<0 and r>0){
            r--;
          }
          else{
            ans += dd[i];
          }
        }
        chmax(res, ans);
      }
    }
  }
  cout << res << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q,l,r, x, y, u, v, n, m;
    cin>>n;
    vc a(n);
    Ff(i,0,n)
    cin>>a[i];

    vc dp(n,0);
    dp[0]=0;
    dp[1]=abs(a[1]-a[1-1]);

    Ff(i,2,n)
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));

    cout<<dp[n-1];
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 11892
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int T = sc.nextInt();
        int A = sc.nextInt();
        int ans = -1;
        int min = 10000000;
        for (int i = 0; i < N; i++) {
            int H = sc.nextInt();
            int diff = Math.abs(T * 1000 - 6 * H - A * 1000);
            if (diff < min) {
                min = diff;
                ans = i + 1;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22996
#include <iostream>
using namespace std;
int main(){
  int n,a[100],sum=0,r[2]={};
  cin>>n;
  for(int i=0;i<n&&cin>>a[i];sum+=a[i],i++);
  sum/=n;
  for(int j=0;j<2;j++,sum++) for(int i=0;i<n;i++) r[j]+=(a[i]-sum)*(a[i]-sum);
  cout<<min(r[0],r[1])<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

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

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

bool isAllVisit(const vector<bool>& visit) {
    for (auto&& v : visit) {
        if (!v)return false;
    }
    return true;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}


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

    int N;
    cin >> N;
    vector<pair<ll, ll>> TA(N);
    cin >> TA;

    vector<pair<ll, ll>> dp(N + 1);
    dp[0] = { 1,1 };


    auto solve = [&](int n) {
        ll mul = max(round_up(dp[n].first, TA[n].first), round_up(dp[n].second, TA[n].second));
        pair<ll, ll> res = TA[n];
        res.first *= mul;
        res.second *= mul;
        return res;
    };

    REP(i, N) {
        dp[i + 1] = solve(i);
    }

    cout << dp[N].first + dp[N].second << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int h, w;
    cin >> h >> w;
    vector<string> c(h);
    rep(i, h) cin >> c[i];
    vector<string> ans(2*h);
    rep(i, 2*h) {
        ans[i] = c[i/2];
        cout << ans[i] << endl;
    }
    
    return 0;
}


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

int main(){
  int a,b,c,array[101],i,j,array2[101]={};
  cin>>a>>b>>c;
  for(i=0;i<a;i++){
    cin>>array[i];
  }
  for(i=0;i<a;i++){
    for(j=0; ;j++){
      if(j*array[i]+1>b){
        break;
      }else{
        array2[i]+=1;
      }
    }
  }
  for(i=0;i<a;i++){
    c+=array2[i];
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int X=sc.nextInt();
        if(X-A<B&&A<=X){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 20692
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n,k,ans,di[101010];
struct d
{
	int x,y;
}a[10101],b[10101];
bool cmp(d u,d v){ return u.x<v.x;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].x,&a[i].y);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&b[i].x,&b[i].y);
	sort(a+1,a+n+1,cmp);
	sort(b+1,b+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		while(a[k].x<=b[i].x&&k<=n) k++;
		int ma=0;
		for(int j=1;j<k;j++)
		if(!di[j]&&a[j].y<=b[i].y)
			ma=a[ma].y>a[j].y?ma:j;
	//	cout<<k<<" "<<ma<<endl;
		if(ma) di[ma]=1,ans++;
	}
	printf("%d",ans);
	return 0;
}
		
		

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int H, N;
int A[10010];
int B[10010];
int dp[1010][10010];


signed main(){
    cin >> H >> N;
    rep(i, 0, N) cin >> A[i] >> B[i];

    repe(i, 0, N) repe(j, 0, H) dp[i][j] = INF32;
    repe(i, 0, N) dp[i][0] = 0;
    rep(i, 0, N) repe(j, 0, H){
        chmin(dp[i+1][j], dp[i][j]);
        chmin(dp[i+1][min(H, j+A[i])], dp[i+1][j]+B[i]);
    }

    cout << dp[N][H] << endl;

    return 0;
}

Measured memory_bytes: 78592
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>
#include<climits>
#include<cmath>
 
using namespace std;
 
long long f(long long b, long long n) {
	long long ans = 0;
	while (n) {
		ans += n % b;
		n /= b;
	}
	return ans;
}
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long n, s;
	cin >> n >> s;
	if (n < s) {
		cout << -1 << endl;
		return 0;
	}
	else if (n == s) {
		cout << n + 1 << endl;
		return 0;
	}
	double rootn = sqrt(n);
	for (int i = 2; i < rootn+1; i++) {
		if (f(i, n) == s) {
			cout << i << endl;
			return 0;
		}
	}
	for (long long p = (long long)(floor(rootn))+1; p > 0; p--) {
		if ((n - s) % p != 0) continue;
		long long b = (n - s) / p + 1;
		if (f(b, n) == s) {
			cout << b << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll n, k;
	cin >> n >> k;
	Vec a(n);
	rep(i, n) cin >> a[i];
	ll sum = 0;
	rep(i, n) sum += a[i];
	Vec1<bitset<50> > b(n);
	rep(i, n) b[i] = bitset<50>(a[i]);

	Vec cnt(50);
	rep(i, n) rep(j, 50) if(b[i][j]) cnt[j]++;

	bitset<50> l(k);

	Vec2<ll> dp(50, Vec(2));
	repr(i, 50){
		if(pow2(i) > k) continue;
		dp[i][0] = dp[i + 1][0];
		dp[i][1] = dp[i + 1][1];
		if(pow2(i + 1) <= k) dp[i][1] += max(0LL, (n - 2 * cnt[i]) * pow2(i));
		if(l[i]){
			dp[i][0] += (n - 2 * cnt[i]) * pow2(i);
			chmax(dp[i][1], dp[i + 1][0]);
		}
	}
	//co({dp[0][0], dp[0][1]});
	co(sum + max(dp[0][0], dp[0][1]));

	return 0;
}


Measured memory_bytes: 1792
from math import acos, degrees, sqrt

a, b, x = map(int, input().split())

if(x == a * a * b / 2):
    print(degrees(acos(a / sqrt(a * a + b * b))))
elif(x < a * a * b / 2):
    a = (2 * x) / (a * b)
    print(degrees(acos(a / sqrt(a * a + b * b))))
else:
    z = 2 * (x - (a * a * b / 2)) / (a * a)
    b = b - z
    print(degrees(acos(a / sqrt(a * a + b * b))))


Measured memory_bytes: 3064
L = [1, 2, 3]
a = int(input())
b = int(input())
if a == 1 and b == 2 or a == 2 and b == 1:
    print(3)
elif a == 1 and b == 3 or a == 3 and b == 1:
    print(2)
else:
    print(1)


Measured memory_bytes: 38256
function main(lines) {
    const [N, K] = parseNumberLine(lines[0])
    const prices = parseNumberLine(lines[1])
    	.sort((a, b) => a - b)

    let total = 0
    for (let i = 0; i < K; ++i) {
      total += prices[i]
    }
    console.log(total)
}

function parseNumberLine(line, radix = 10) {
    return line.split(/\s+/).map(_ => parseInt(_, radix))
}

main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"))


Measured memory_bytes: 29780
N = int(input())
takahashi = 1
aoki = 1
for _ in range(N):
  t, a = map(int, input().split())
  X = -(-(takahashi + t-1))//t # 切り上げ
  Y = -(-(aoki + a-1))//a      # 切り上げ
  n = max(X, Y)
  takahashi = t*n
  aoki = a*n
  
print(int(takahashi+aoki))

Measured memory_bytes: 3064
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n;
    scanf("%d",&n);
    int A[n];
 
    for(int i = 0; i < n; i++) scanf("%d",&A[i]);
 
    for(int i = n-1; i > 0; i--) printf("%d ",A[i]);
    printf("%d\n",A[0]);
}



Measured memory_bytes: 2712
//  ©   ___MRX___

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

#define ll long long int

int main()
{
    int H, W, h, w;

    cin >> H >> W >> h >> w;

    cout << (H - h) * (W - w) << '\n';

    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d", &x)
#define scc(x, y) scanf("%d %d", &x, &y)
#define lng long long
#define maxN 10005

map<string,int> mp;

int main(){
    int n, m;
    string s;
    cin>>n;
    while(n--){
        cin>>s;
        mp[s]++;
    }
    cin>>m;
    while(m--){
        cin>>s;
        mp[s]--;
    }
    int mx=0;
    for(auto a: mp){
        if(mx<a.second) mx = a.second;
    }
    cout<<mx;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

#define N_MAX 200000

int main(){
  long long int n;
  cin >> n;
  long long int a[N_MAX] = {};
  long long int a_num[N_MAX+1] = {};   // a_num[i]: iが書かれているボールの個数

  for(long long int i = 0; i < n; i ++){
    cin >> a[i];
    a_num[a[i]] ++;
  }

  // a[i] = a[j] (i!=j)の総数
  long long int sum = 0;

  for(long long int i = 1; i <= n; i ++){
    long long int m = a_num[i] * (a_num[i]-1) /2;
    sum += m;
  }

  for (long long int i = 0; i < n; i ++){
    // i番目のボールを使うのはa_num[a[i]]-1通り
    long long int ans = sum - (a_num[a[i]]-1);
    cout << ans;
    if (i < n-1){
      cout << endl;
    }
  }
  return 0;
}


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

int main(){
    int a[3],b[3],c[3],d[3],e[3];
    for (int i=0; i<3; ++i) cin >> c[i] >> d[i] >> e[i];
    a[0]=0;
    for (int i=0; i<3; ++i) b[i]=c[i];
    a[1]=d[0]-b[0];
    a[2]=e[0]-b[0];

    bool Y = false;
    bool Z = false;

        if (a[1]+b[0]==d[0]&&a[1]+b[1]==d[1]&&a[1]+b[2]==d[2]) Y =true;

        if (a[2]+b[0]==e[0]&&a[2]+b[1]==e[1]&&a[2]+b[2]==e[2]) Z =true;

    if ( Y && Z) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
//
//AtCoder Beginner Contest 154
//D - Dice in Line
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <functional>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int n, k;

    cin >> n >> k;

    int p[n];
    
    REP(i, n) cin >> p[i];

    vector<ld> sumList;

    ld sum = 0;
    REP(i, n){
        sum += (1.0+(ld)p[i])/2.0;
        sumList.push_back(sum);
    }

    ld ans = 0;
    if (n == k) ans = sum;
    else{
        REP(i, n-k){
            ans = max(ans, sumList[i+k] - sumList[i]);
        }
    }
    
    cout << fixed;
    cout << setprecision(12) << ans << endl;

    return 0;
}



Measured memory_bytes: 7280
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

func parseProblem() string {
	return scanString(sc)
}

func resolve(s string) {
	nums := map[byte]int{'a': 0, 'b': 0, 'c': 0}
	for i := 0; i < len(s); i++ {
		nums[s[i]]++
	}
	max, min := 0, math.MaxInt32
	for _, v := range nums {
		if max < v {
			max = v
		}
		if min > v {
			min = v
		}
	}
	if max-min <= 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2072
#include <stdio.h>
int a[10];
int main(){
	int i,n;
	n=5;
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
		if(!a[i])break;
	printf("%d\n",i);
	return 0;
}

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

#define ll long long
#define int ll
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

template <typename T, typename A> 
int vargmin(std::vector<T, A> const& vec) {
    return static_cast<int>(std::distance(vec.begin(), std::min_element(vec.begin(), vec.end())));
}

template <typename T, typename A>
int vmax(std::vector<T, A> const& vec) {
    return static_cast<int>(*std::max_element(vec.begin(), vec.end()));
}

using namespace std;

void solve() {
    int N, K;
    cin >> N >> K;

    int A[N];
    int F[N];
    FOR(i, 0, N) {
        cin >> A[i];
    }
    FOR(i, 0, N) {
        cin >> F[i];
    }
   
    //print("# End of input");

    sort(A, A+N);
    sort(F, F+N, greater<int>());
    
    vector<int> vecA;
    vector<int> vecF;
    int maxCost = 0;
    FOR(i, 0, N) {
        vecA.pb(A[i]);
        vecF.pb(F[i]);
        maxCost = max(maxCost, vecA[i]*vecF[i]);
        //print(vecA[i] << "," << vecF[i]);
    }
  
    //print("# Solving ...");
    int L = -1;
    int R = maxCost;
    while (L + 1 < R) {
        int M = (L + R)/2;
        int step = 0;
        FOR(i, 0, N) {
            int d = vecA[i] - floor(M/vecF[i]);
            step += max(0ll, d);
        }
        //print(step << "," << L << "," << M << "," << R);
        if (step <= K) {
            R = M;
            //print("step is lower");
        } else {
            L = M;
            //print("step is higher");
        }
    }

    print(R);
}

signed main() {
    solve();
}


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

using namespace std;

int main()
{
    //freopen("caitui.inp","r",stdin);
    long long int N, W, i, j;
    cin>>N>>W;
    long long int w[N+1], v[N+1], f[N+1][W+1];
    for(i=1; i<=N; i++) cin>>w[i]>>v[i];

    for(i=0; i<=N; i++) f[i][0]=0;
    for(i=0; i<=W; i++) f[0][i]=0;
    // Tinh f[i][j]
    for(i=1; i<=N; i++)
    {
        for(j=1; j<=W; j++)
        {
            if(w[i]<=j) f[i][j]=max(f[i-1][j-w[i]]+v[i], f[i-1][j]);// vat i duoc chon
            else f[i][j]=f[i-1][j]; //vat i khong duoc chon
        }
    }
    cout<<f[N][W];
    return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int L,R,ans;cin>>L>>R;
  if(R-L>2017)ans=0;
  
  else{
    int sub;ans=2019;
    vector<int> a(R-L+1);
    for(int i=0;i<R-L+1;i++)a.at(i)=(L+i)%2019;
    for(int i=0;i<R-L;i++){
      for(int j=i+1;j<R-L+1;j++){
        sub=a.at(i)*a.at(j)%2019;
        ans=min(ans,sub);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	vector<vector<int>> a(20, vector<int>(20));
	ll ans = 0;
	for (int i = 0; i < N; ++ i) {
		double x;
		cin >> x;
		auto y = (ll)(x * 1e9 + 0.5);
		int n2 = 0, n5 = 0;
		while (n2 < 18 && y % 2 == 0) {
			++ n2;
			y /= 2;
		}
		while (n5 < 18 && y % 5 == 0) {
			++ n5;
			y /= 5;
		}
		ans += a[18-n2][18-n5];
		for (int i = 0; i <= n2; ++ i) for (int j = 0; j <= n5; ++ j) {
			++ a[i][j];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) { cin >> a[i]; }
  sort(a.begin(), a.end(), greater<int>());
  ll alice = 0, bob = 0;
  REP(i,N){
    if(i%2==0){
      alice += a[i];
    }else{
      bob += a[i];
    }
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
#define repeat(i,n) for(int i=0;i<(n);i++)

int main(){

  string a, b, c; cin>> a>> b>> c;

  if(a.back()==b[0] && b.back()==c[0]) cout<< "YES"<< endl;
  else cout<< "NO"<< endl;

  return 0;
}


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

 


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

  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  s = " "+s;
  for(int i=1;i<=n/2;i++){
    if(s[i]!=s[n-i+1]){
      ans++;
    }
  }
  cout << ans << endl;

return 0;
}
///....


Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

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

char s[200010], st[200010];
int ss;

int main()
{
	scanf("%s",s);
	ss = 0;
	for (int i = 0; s[i]; i++) 
		if (ss > 0 && s[i] == 'T' && st[ss - 1] == 'S')
			ss--;
		else
			st[ss++] = s[i];
		printf("%d\n",ss);
	return 0;
}

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

int main() {
	int R0, W0, C, R;
	while (cin >> R0 >> W0 >> C >> R) {
		if (R0 == 0 && W0 == 0 && C == 0 && R == 0) return 0;
		int LOSS = W0 * C - R0;
		if (LOSS <= 0) cout << 0 << endl;
		else if (LOSS % R == 0) cout << LOSS / R << endl;
		else cout << LOSS / R + 1 << endl;
	}
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
const int NN = 1e6+10;
typedef long long ll;

ll n;
string str;
int arr[NN];
int main(){
    // freopen("test.in","r",stdin);
    cin>>str;
    int l = 0;
    n = str.length();
    for(int i = 1;i<n;i++){
        if(str[i-1] == 'R' && str[i] == 'L'){
            for(int j = l;j<=i;j++){
                if(j%2 == 1 && i%2 == 1 || j%2 == 0 && i%2 == 0) arr[i]++;
                else arr[i-1]++;
            }
            int j;
            for(j = i+1;j<n && str[j]!='R';j++){
                if(j%2 == 1 && i%2 == 1 || j%2 == 0 && i%2 == 0) arr[i]++;
                else arr[i-1]++;
            }
            l = j;
            i = j-1;
        }
    }
    for(int i = 0;i<n;i++) printf("%d ",arr[i]);
    return 0;
}

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

int main() {
  int64_t N,K,Q=1000000007,P=Q-2,Z=0;
  cin>>N>>K;
  vector<int64_t> q(100001,1);
  for(int i=1;i<=100000;i++){
    int64_t N=P; //ここから
       int64_t a=1,b=0,c=1;
       while(N>0){
         a*=2;
         if(N%a!=0){
           N-=a/2;
           int64_t d=i;
           for(int j=0;j<b;j++){
            d=d*d;
             d=d%Q;
          }
           c=c*d;
          c=c%Q;
         }
        b++;
      } //ここまで
    q.at(i)=(c*q.at(i-1))%Q;
  }
  vector<int64_t> r(100001,1);
  for(int i=1;i<=100000;i++){
    r.at(i)=(i*r.at(i-1))%Q;
  }

  vector<int64_t> p(N);
  for(int64_t i=0;i<N;i++){
    cin>>p.at(i);
  }
  sort(p.begin(), p.end());
  for(int64_t i=0;i<N;i++){
    if(i>=K-1){
      int64_t A=i,B=min(i-K+1,K-1),C=1;//A、Bを入れる
      C=(q.at(B)*q.at(A-B))%Q;
      C=(C*r.at(A))%Q;
    Z=(Z+C*p.at(i))%Q;
    }
    if(N>=K+i){
      int64_t A=N-1-i,B=min(N-K-i,K-1),C=1;//A、Bを入れる
      C=(q.at(B)*q.at(A-B))%Q;
      C=(C*r.at(A))%Q;
      Z=(Z-C*p.at(i))%Q;
    }
  }
  if(Z>=0){
    cout<<Z<<endl;
  }
  else{
    cout<<Z+Q<<endl;
  }  
}

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

using ll = long long;

const int MOD = 1e9 + 7;

int add(int a, int b) {
    return (a + b) % MOD;
}

int sub(int a, int b) {
    return (a - b + MOD) % MOD;
}

int mul(ll a, ll b) {
    return (a * b) % MOD;
}

int main() {
    int n, h, d;
    cin >> n >> h >> d;

    vector<int> f(n + 1);
    f[0] = 1;
    for (int i = 1; i <= n; i++)
        f[i] = mul(f[i - 1], i);

    int coef = accumulate(f.begin() + 1, f.end(), 0LL) % MOD;

    vector<int> dp(h + 1), pref(h + 2);
    dp[0] = f[n], pref[1] = f[n];
    for (int i = 1; i <= h; i++) {
        dp[i] = sub(pref[i], pref[max(i - d, 0)]);
        pref[i + 1] = add(pref[i], mul(coef, dp[i]));
    }

    cout << dp[h] << endl;
}


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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    int cnt1 = 0,cnt2 = 0;
    for(int i=0;i<N;i++){
        if(i%2 == 0 && S[i] != '0'){
            cnt1++;
        }
        if(i%2 == 1 && S[i] != '1'){
            cnt1++;
        }
    }
    for(int i=0;i<N;i++){
        if(i%2 == 0 && S[i] != '1'){
            cnt2++;
        }
        if(i%2 == 1 && S[i] != '0'){
            cnt2++;
        }
    }
    cout << min(cnt1, cnt2);
    return EXIT_SUCCESS;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			StringBuilder cd = new StringBuilder();
			StringBuilder nCd = new StringBuilder();
			cd.append(sc.next());
			String id = cd.toString();
			if(id.equals("-"))break;
			int m = sc.nextInt();
			for(int i = 0; i < m; i++) {
				int h = sc.nextInt();
				nCd.append(cd.substring(h));
				nCd.append(cd.substring(0, h));
				cd.setLength(0);
				cd.append(nCd);
				if( i == m -1 ) {
					System.out.println(nCd);
				}
				nCd.setLength(0);
			}
		
		}
		sc.close();
	}
	
}


Measured memory_bytes: 26308
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  long long ans = 0;
  long long c = 0;
  for (int i = 1; i <= n; i++) {
    c += i;
    ans += c;
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    if (u > v) swap(u, v);
    ans -= 1LL * u * (n - v + 1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
struct edge{ll to,cap,rev;};
vector<edge> G[4000010];
bool used[4000010];
void add_edge(ll from,ll to,ll cap){
    G[from].push_back((edge){to,cap,(ll)G[to].size()});
    G[to].push_back((edge){from,0,(ll)G[from].size()-1});
}
ll dfs(ll v,ll t,ll f){
    if(v==t)return f;
    used[v]=true;
    rep(i,0,G[v].size()){
        edge &e=G[v][i];
        if(used[e.to]==false&&e.cap>0){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
ll max_flow(ll s,int t){
    ll f=0;
    for(;;){
        memset(used,0,sizeof used);
        ll g=dfs(s,t,1000000000);
        if(g==0)return f;
        f+=g;
    }
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int h,w;cin>>h>>w;
    string s[h];
    rep(i,0,h)cin>>s[i];
    rep(i,0,h){
        rep(j,0,w){
            ll t=i*w+j;
            ll c=0;
            rep(k,0,4){
                ll ii=i+dh[k];
                ll jj=j+dw[k];
                if(ii<0||ii>=h||jj<0||jj>=w){
                    c=1;
                    continue;
                }
                add_edge(t+10000,ii*w+jj,1000000000);
                
            }
            if(c==1){
                add_edge(t+10000,30002,1000000000);
            }
            if(s[i][j]=='.')add_edge(t,t+10000,1);
            else{
                add_edge(t,t+10000,1000000000);
                add_edge(30001,t,1000000000);
            }
        }
    }
    ll ans=max_flow(30001,30002);
    if(ans>=100000000)cout<<-1<<endl;
    else cout<<ans<<endl;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> x(s.size() + 1), y(t.size() + 1);
    for (auto i : irange(0uL, s.size())) {
        x[i + 1] = x[i] + (s[i] == 'B' ? 2 : 1);
    }
    for (auto i : irange(0uL, t.size())) {
        y[i + 1] = y[i] + (t[i] == 'B' ? 2 : 1);
    }

    int64_t q;
    cin >> q;

    for (auto _ : irange(0L, q)) {
        int64_t a, b, c, d;
        cin >> a >> b >> c >> d;

        auto xx = x[b] - x[a - 1];
        auto yy = y[d] - y[c - 1];

        if ((xx - yy) % 3 == 0) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
}

Measured memory_bytes: 2432
#include <stdio.h>

int alpha[26];

int main(void){
    long n;
    scanf("%ld\n", &n);
    for(long i=0; i<n; i++){
        int c = getchar();
        alpha[c-'a']++;
    }
    long ans = 1;
    for(long i=0; i<26; i++){
        ans = ans * (alpha[i]+1) % 1000000007;
    }
    printf("%ld\n", ans-1);
    return 0;
}

Measured memory_bytes: 128
unittest
{
	assert( [ "4 2 9" ].parse.expand.solve == 8 );
	assert( [ "4 2 7" ].parse.expand.solve == 7 );
	assert( [ "4 2 8" ].parse.expand.solve == 8 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nab = input.front.split.to!( long[] );
	return tuple( nab[ 0 ], nab[ 1 ], nab[ 2 ] );
}

auto solve( long n, long a, long b )
{
	return min( n * a, b );
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int N=1e5+5;

int l[N],e[2*N],x[2*N];

void pshe(int t,int u,int v){
	x[t]=l[u];l[u]=t;e[t]=v;
}

int c[N],a[N],d[N];

queue<int>q;

int main()
{
	int n,i,j,u,v;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		++d[u],++d[v];
		pshe(i<<1,u,v);
		pshe(i<<1|1,v,u);
	}
	for(i=1;i<=n;i++)
		scanf("%d",&c[i]);
	sort(c+1,c+n+1);
	int ans=0;
	for(i=1;i<n;i++)
		ans+=c[i];
	printf("%d\n",ans);
	for(i=1;i<=n;i++)
		if(d[i]==1)
			q.push(i);
	for(j=1;j<=n;j++){
		v=q.front();q.pop();
		--d[v];a[v]=c[j];
		for(i=l[v];i;i=x[i])
			if(d[e[i]]){
				--d[e[i]];
				if(d[e[i]]==1)
					q.push(e[i]);
			}
	}
	for(i=1;i<=n;i++)
		printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#define swap(type, a, b) {type tmp = a; a = b; b = tmp;}

int selectionSort(int *a, int n) {
    int i, j, mini, sum;
    sum = 0;
    for (i = 0; i < n; i++) {
        mini = i;
        for (j = i; j < n; j++) {
            if (a[j] < a[mini]) mini = j;
        }
        if (i != mini) {
            swap(int, a[i], a[mini]);
            sum++;
        }
    }
    return sum;
}

int main(void) {
    int N;
    scanf("%d", &N);
    int A[N];
    int idx, ans;

    for (idx = 0; idx < N; idx++) {
        scanf("%d", &A[idx]);
    }

    ans = selectionSort(A, N);

    for (idx = 0; idx < N; idx++) {
        printf("%d", A[idx]);
        if (idx < N - 1) printf(" ");
        else printf("\n");
    }

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

    return 0;
}


Measured memory_bytes: 2112
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    static class DSU {
        int[] root;
        int[] rank;

        public DSU(int n) {
            root = new int[n];
            rank = new int[n];
            for(int i=0;i<n;i++) {
                root[i] = i;
            }
        }

        public int find(int x) {
            if(root[x] == x) {
                return x;
            }
            else {
                return find(root[x]);
            }
        }

        public void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if(x == y) {
                return;
            }
            if(rank[x] < rank[y]) {
                root[x] = y;
            }
            else {
                root[y] = x;
                if(rank[x] == rank[y]) {
                    rank[x]++;
                }
            }
        }

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

    public static boolean ok(int a, String s) {
        String temp = "" + a;
        for(int i=0;i<s.length();i++) {
            if(temp.indexOf(s.charAt(i)) != -1) {
                return false;
            }
        }
        return true;
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = "";

        for(int i=0;i<k;i++) {
            s += sc.next();
        }

        while(!ok(n, s)) {
            n++;
        }

        pw.println(n);
        pw.close();
	}

}


Measured memory_bytes: 27604
#include <stdio.h>
#include <math.h>
#include <limits.h>

long isPrime (long n) {
    int i;
    if (n < 2) return 0;
    else if (n == 2) return 1;
    if (n % 2 == 0) return 0;
    for (i = 3; i <= n / i; i += 2)
         if (n % i == 0) return 0;
    return 1;
}

long nextPrime(long n) {
	// return the next prime
	long i;
	for (i = n+1; i < LONG_MAX; i++) {
		if (isPrime(i)) return i;
	}
	return 0;
}

int main() {
	long n;
	scanf("%ld", &n);
	// round up sqrt(n)
	long limit = ceil(sqrt(n));
	long divisor = 2;
	printf("%ld:", n);
	while (1) {
		if (n % divisor == 0) {
			printf(" %ld", divisor);
			n /= divisor;
		} else if ((n != 1) && (nextPrime(divisor) < limit)) {
			divisor = nextPrime(divisor);
		} else {
			if (n != 1) printf(" %ld\n", n);
			else printf("\n");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 604
x = gets()
y = x.split()
m = y[0].to_i
n = y[1].to_i
k = y[2].to_i

p = m + n

until p == -2 && k == -1
 if m == -1 || n == -1
  puts "F"
 elsif 80 <= p
  puts "A"
 elsif 65 <= p && p < 80
  puts "B"
 elsif 50 <= p && p < 65
  puts "C"
 elsif 30 <= p && p < 50
  if 50 <= k
   puts "C"
  else
   puts "D"
  end
 elsif p < 30
  puts "F"
 end

 x = gets()
 y = x.split()
 m = y[0].to_i
 n = y[1].to_i
 k = y[2].to_i

 p = m + n
end


Measured memory_bytes: 6868
n = int(input())
p = [int(i) for i in input().split()]
answer,num = 0,0
for i in range(n):
	if i+1==p[i]: num += 1
	else:
		answer += (num+num%2)//2
		num = 0
answer += (num+num%2)//2
print(answer)

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

int main() {
  int N;
  cin >> N;
  vector<string> vec(N);
  for(int i = 0; i<N;i++){
    cin >> vec.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> vect(M);
  for(int i = 0; i<M;i++){
    cin >> vect.at(i);
  }
  
  int point = 0;
  int max = 0;
  
  for(int i= 0;i<N; i++){
    point = 0;
    string x = vec.at(i);
    for(int j = i; j<N;j++){
      if(x == vec.at(j)){
         point += 1;
      }
    }
    for(int j = 0; j<M;j++){
      if(x == vect.at(j)){
        point -= 1;
      }
    }
    if(point > max){
      max = point;
    }
  }
  
  cout << max <<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

class Dice{
    public static int[] saikoro(String h, int[] d){
        int surface = 0;
            switch (h) {
            case "E":
                surface = d[4];
                d[4] = d[6]; d[6] = d[3]; d[3] = d[1]; d[1] = surface;
                break;
                
            case "W":
                surface = d[3];
                d[3] = d[6]; d[6] = d[4]; d[4] = d[1]; d[1] = surface; 
                break;
                
            case "S":
                surface = d[5];
                d[5] = d[6]; d[6] = d[2]; d[2] = d[1]; d[1] = surface; 
                break;
                
            case "N":
                surface = d[2];
                d[2] = d[6]; d[6] = d[5]; d[5] = d[1]; d[1] = surface; 
                break;
                
            }
        return d;
    }
}
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int i, j, k, l, m, ans=0, n = sc.nextInt();
        int[] count = new int[n+1];
        
        int[] a = new int[7];
        int[] d = new int[7];
        
        for(i=0;i<6;i++)a[i+1] = sc.nextInt();
        
        for(j = 0; j < n-1; j++){
        
            for(k = 0;k < 6; k++)d[k+1] = sc.nextInt();
            
            String[] s = {"W", "E", "S", "N"};
            String h = "";
            int num =0;
            
            for(l = 0; l < 1000; l++){
                num = (int)(Math.random()*4);
                h = s[num];
                Dice.saikoro(h, d);
                if(Arrays.equals(a,d)){
                    /*count[j]*/ans += 1;
                    //System.out.println(count[j]);
                    break;
                }
                /*else if(l == 1000-1){
                    count[j] = 0;
                    //System.out.println(count[j]);
                }*/
            }
        }
        /*for(m = 0; m < n - 1; m++){
            ans += count[m];
            //System.out.println(ans);
        }*/
        
        if(ans > 0 )System.out.println("No");
        else System.out.println("Yes");
    }
}


Measured memory_bytes: 29272