akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct tn{
  string name;
  int time;
};


int main(){

  int n, p;

  cin >> n >> p;

  queue<tn> qu;

  for(int i = 0; i < n; i++){
    int time;
    string name;
    cin >> name >> time;
    qu.push((tn){name,time});
  }

  int cnt = 0;

  while(!qu.empty()){

    tn ans = qu.front();
    qu.pop();

    if(ans.time - p > 0){
      qu.push((tn){ans.name,ans.time-p});
      cnt+=p;
    }
    else if(ans.time - p <= 0){
      cnt+=ans.time;
      cout << ans.name << " " << cnt << endl;
    }

  }




}

Measured memory_bytes: 4404
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64
const ll INF = (1<<30);
const ll NEGA=-INF*10000; 


ll ans = 0;
int p[200000];
int n,m;
int cnt=0;

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

int main() 
{
    cin>>n;
    int ptr=0;
    for(int i=2;i<=55555;++i){
        if(isPrime(i)) p[ptr++]=i;
    }

   int q=0;
   for(int i=0;i<n;++i){
     while((p[q]%5)!=2){
         q++;
     }
     if(i!=n-1)
     cout<<p[q]<<" ";
     else
     cout<<p[q]<<endl;
     q++;
   }
  
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 300005;
const ll N = 300000;
int n;
ll k;
ll niz[maxn];
ll kol[maxn];
ll bor[4*maxn];
void build(int v, int tl, int tr){
    if(tl == tr){
        bor[v] = 1;
        return;
    }
    int mid = (tl + tr)/2;
    build(v*2, tl, mid);
    build(v*2+1, mid+1, tr);
    bor[v] = max(bor[v*2], bor[v*2+1]);
}
void update(int v, int tl, int tr, int poz, ll vre){
    if(tl == tr){
        bor[v] = max(bor[v], vre);
        return;
    }
    int mid = (tl+tr)/2;
    if(poz <= mid)update(v*2,tl,mid,poz,vre);
    else update(v*2+1,mid+1,tr,poz,vre);
    bor[v] = max(bor[v*2], bor[v*2+1]);
}
ll kveri(int v, int tl, int tr, int l, int r){
    if(tl > r || l > tr)return (ll)0;
    if(l <= tl && r >= tr)return bor[v];
    int mid = (tl + tr)/2;
    return max(kveri(v*2,tl,mid,l,r), kveri(v*2+1,mid+1,tr,l,r));
}
int main()
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
	cin >> n >> k;
	for(int i=1;i<=n;i++)cin >> niz[i];
//	build(1,1,N);
	for(int i=n;i>=1;i--){
//		cout << endl;
		ll x = niz[i];
		kol[i] = kveri(1,1,N,max((ll)1,x - k), min(x + k, N)) + (ll)1;
//		cout << "kol[i]: " << kol[i] << endl;
		update(1,1,N,x,kol[i]);
//		for(int j=1;j<=9;j++)cout << kveri(1,1,N,j,j) << " ";
//		cout << endl;
	}	
	ll rez = 0;
	for(int i=1;i<=n;i++)rez = max(rez, kol[i]);
	cout << rez << endl;
    return 0;
}

Measured memory_bytes: 16568
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

func permutation(n int, k int) int {
	v := 1
	if 0 < k && k <= n {
		for i := 0; i < k; i++ {
			v *= (n - i)
		}
	} else if k > n {
		v = 0
	}
	return v
}

func factorial(n int) int {
	return permutation(n, n-1)
}

func combination(n int, k int) int {
	return permutation(n, k) / factorial(k)
}

func sortString(w string) string {
	s := strings.Split(w, "")
	sort.Strings(s)
	return strings.Join(s, "")
}

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Green Bin
	var N int
	fmt.Scanf("%d", &N)

	s := make(map[string]int, N)
	var S string
	for i := 0; i < N; i++ {
		S = nextStr()
		S = sortString(S)
		s[S]++
	}

	var ans int
	for _, v := range s {
		if v > 1 {
			ans += combination(v, 2)
		}
	}

	fmt.Println(ans)
}


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

int main(){
  int N ; cin >> N ;
  vector<int> D(55);
  for(int i=0;i<N;i++) cin >> D[i];
  int sum = 0;
  int mai = 0;
  for(int i=0;i<N;i++){
     mai += D[i]*D[i];
    for(int j=0;j<N;j++){
      sum += D[i]*D[j];
     
    }
  }
    
    cout << (sum-mai)/2 << endl;
    
  }


Measured memory_bytes: 256
module Main where

import Data.List (foldl')

main :: IO ()
main = do
  _ <- readLn :: IO Int
  results <- lines <$> getContents
  putStr "AC x " >>= \_ -> print $ count "AC" results
  putStr "WA x " >>= \_ -> print $ count "WA" results
  putStr "TLE x " >>= \_ -> print $ count "TLE" results
  putStr "RE x " >>= \_ -> print $ count "RE" results
  where
    count k vs = foldl' (\cnt v -> if v == k then cnt + 1 else cnt) 0 vs


Measured memory_bytes: 24092
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cassert>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

long long gcd(long long a, long long b) {
  long long r = 1;
  while (r != 0) {
    r = a%b; a = b; b = r;
  }
  return a;
}

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

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

  vector<bool> isPrime(n+1, true);
  isPrime[1] = false;
  for(int i=2; i<=n; i++) {
    if (isPrime[i]) {
      for(int j=2; i*j<=n; j++) {
        isPrime[i*j] = false;
      }
    }
  }
  set<int> ans;

  vector<ll> vec(n+1);
  for(int p=1; p<=n; p++) {
    if (!isPrime[p]) continue;
    if (a[0]%p != 0) continue;
    for(int i=1; i<p; i++) {
      vec[i] = 0;
    }
    for(int i=1, j=1; i<=n; i++, j++) {
      if (j==p) j=1;
      vec[j] += a[i];
    }
    bool flag = true;
    for(int i=1; i<p; i++) {
      if (vec[i]%p != 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans.insert(p);
    }
  }

  int gd = abs(a[n]);
  rep(i, n) {
    if (a[i] != 0) {
      gd = gcd(gd, abs(a[i]));
    }
  }
  for(int i=2; i*i<=gd; i++) {
    while (gd%i == 0) { ans.insert(i); gd /= i; }
  }
  if (gd > 1) ans.insert(gd);

  for(auto e: ans) {
    cout << e << '\n';
  }
}

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

const int N = 200006;
int ans[N];

int pop_count(int x) {
    int ret = 0;
    while (x) {
        ret += ((x & 1) == 1);
        x >>= 1;
    }
    return ret;
}

int f(int x) {
    int ret = 0;
    while (x != 0) {
        ++ret;
        x %= pop_count(x);
    }
    return ret;
}

int mod1, mod2;
int a1[N], a2[N];

int main () {
    int n; cin >> n;
    string s; cin >> s; reverse(s.begin(), s.end());
    int _1 = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            ++_1;
        }
    }
    if (_1 == 0) {
        for (int i = 0; i < n; ++i) {
            cout << 1 << endl;
        }
        return 0;
    }
    else if (_1 == 1) {
        for (int i = 0; i < n; ++i) {
            if (s[i] == '1') {
                ans[i] = 0;
            }
            else {
                if (i == 0 || s[0] == '1') {
                    ans[i] = 2;
                }
                else {
                    ans[i] = 1;
                }
            }
        }
        for (int i = n - 1; i >= 0; --i) {
            cout << ans[i] << endl;
        }
    }
    else {
        mod1 = _1 - 1;
        mod2 = _1 + 1;
        for (int i = 0; i < n; ++i) {
            if (i == 0) {
                a1[i] = 1 % mod1;
                a2[i] = 1 % mod2;
            }
            else {
                a1[i] = a1[i - 1] * 2 % mod1;
                a2[i] = a2[i - 1] * 2 % mod2;
            }
        }
        int p1 = 0, p2 = 0;
        for (int i = 0; i < n; ++i) {
            if (s[i] == '1') {
                p1 += a1[i];
                p2 += a2[i];
            }
            p1 %= mod1;
            p2 %= mod2;
        }
        for (int i = 0; i < n; ++i) {
            if (s[i] == '0') {
                ans[i] = 1;
                int ff = (p2 + a2[i]) % mod2;
                ans[i] += f(ff);
            }
            else {
                ans[i] = 1;
                int ff = (p1 - a1[i] + mod1) % mod1;
                ans[i] += f(ff);
            }
        }
        for (int i = n - 1; i >= 0; --i) {
            cout << ans[i] << endl;
        }
    }
}


Measured memory_bytes: 6060
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


ll n,x;

void solve()
{
    cin >> n >> x;
    nout(3*(n-__gcd(n,x)));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = long long;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  string s; cin >> s;
  string t = "abcdefghijklmnopqrstuvwxyz";
  int ans = INF;
  REP(i,26) {
    vector<int> v;
    v.push_back(0);
    REP(j,s.size()) {
      if (s[j] == t[i]) {
        v.push_back(j+1);
      }
    }
    v.push_back(s.size()+1);
    int res = 0;
    REP(j,v.size()-1) {
      chmax(res, v[j+1] - v[j] - 1);
    }
    chmin(ans, res);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

// はい
int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a == b) {
		cout << c << endl;
	} else if (b == c) {
		cout << a << endl;
	} else {
		cout << b << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )
#define SORT(x) sort(x.begin(), x.end())

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    int N; cin >> N;
    vector<ll> v(N);
    rep(i, N) cin >> v[i];
    sort(ALL(v), greater<ll>());
    ll max1 = 0, max2 = 0;
    rep(i, N) {
        if (v[i] == v[i + 1] && max1 == 0) {
            max1 = v[i];
            i++;
        }
        else if (v[i] == v[i + 1] && max2 == 0) {
            max2 = v[i];
            break;
        }
    }
    COUT(max1 * max2);
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	vector<ll> a(n);
	vector<ll> b(n);
	rep(i, n)
	{
		cin >> a[i];
		b[i] = a[i];
	}

	sort(b.begin(), b.end());
	rep(i, n)
	{
		if (a[i] == b[n - 1])
		{
			cout << b[n - 2];
		}
		else
		{
			cout << b[n - 1];
		}
		cout << endl;
	}


}

Measured memory_bytes: 4736
N,M=map(int,input().split())
Lks=[]
for _ in range(M):
    Lks.append(list(map(int,input().split())))
Lp=list(map(int,input().split()))

ans=0
Lswitches=[]
for j in range(2**N):
    Lswitches.append(format(j,'b').zfill(N))

for k in Lswitches:
    M_off=0
    for m in range(M):
        n=1
        Even_Odd=0
        while n<=Lks[m][0]:
            if k[Lks[m][n]-1]=="1":
                Even_Odd+=1
            else:
                pass
            n+=1
        if Even_Odd%2!=Lp[m]:
            M_off+=1
        else:
            pass
    if M_off==0:
        ans+=1
    else:
        pass

print(ans)

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

using namespace std;
typedef long long ll;
int main(){
    ll m,d;
    cin>>m>>d;
    int ans=0;
    for(int i=1;i<=m;i++){
        for(int j=10;j<=d;j++){
            int d1=j%10;
            int d2=j/10;
            if(d1*d2==i&&d1>=2&&d2>=2){
                //cout<<i<<' '<<j<<endl;
                 ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#import<cstdio>
int main(){for(int a,c,r;r=1,c=3,~a;~-r&&printf("%d\n",r))for(char d[]="12354",s[9];a=scanf("%s",s),*s>60;r+=*d&7)*s%6-4?d[5]=d[a+=*s%5+*s*2+c&3],d[a]=*d,d[++a%4+1]=~*d,*d=~d[5]:c+=*s+3;}

Measured memory_bytes: 0
def check(x, y):
    if x < 0:
        return "No"
    elif y < 0:
        return "No"
    if y // 1 == y and x // 1 == x:
        return "Yes"
    else:
        return "No"


X, Y = list(map(int, input().split()))

y = (Y - 2 * X) / 2
x = X - y
print(check(x, y))


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

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    
    vector<vector<int>> e(n);
    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        u--; v--;
        
        e[u].push_back(v);
        e[v].push_back(u);
    }
    
    vector<int> d(n, -1);
    d[0] = 0;
    
    deque<int> q;
    q.push_back(0);
    
    while (!q.empty())
    {
        int v = q.front();
        q.pop_front();
        
        for (int u: e[v])
        {
            if (d[u] == -1)
            {
                d[u] = d[v] + 1;
                q.push_back(u);
            }
        }
    }
    
    cout << ((d[n - 1] == 2) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    
    return 0;
}


Measured memory_bytes: 13168
//**KEEP IT SHORT AND SIMPLE**
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a)* (b)).imag()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
typedef tuple<ll, ll, ll> line;
typedef complex<double> point;
const double pi = 2 * acos(0.0);
const int OO = 0x3f3f3f3f;
ll a, b, c, d;
ll num(ll x)
{
    return b / x - (a / x - !(a % x));
}
int main()
{
    IO
    cin >> a >> b >> c >> d;
    ll e = (c * d) / __gcd(c, d);
    cout << (b - a + 1) - (num(c) + num(d) - num(e));
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    int sum = 0;
    int mx = 0;
    rep(i,n) {
        int l;
        cin >> l;
        sum += l;
        chmax(mx,l);
    }
    if(sum-mx > mx) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
    vector<string> weather{"Sunny", "Cloudy", "Rainy"};
    string s;
    cin >> s;
    int idx = find(weather.begin(), weather.end(), s) - weather.begin();
    cout << weather.at((idx + 1) % 3) << endl;
    return 0;
}


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

stack<char> commonString( string s, string t ){

    int x = s.size();
    int y = t.size();
    int valor[x+1][y+1];

    stack<char> CS;


    for(int i=0;i<=x;i++){
        for(int j=0;j<=y;j++){
            if(i==0 or j==0){
                valor[i][j]=0;
            }
            else if(s[i-1]==t[j-1]){
                valor[i][j]=valor[i-1][j-1]+1;
            }else{
                valor[i][j]=max(valor[i-1][j],valor[i][j-1]);
            }
        }
    }

    int tamanho = valor[x][y];
    int i=x,j=y;
    while(valor[i][j]!=0){
        if(valor[i][j] == valor[i][j-1]){
            j--;
        } else if(valor[i][j] == valor[i-1][j]){
            i--;
        } else {
            CS.push(s[i-1]);
            i--; j--;
        }
    }
    return CS;

}

int main() {
    string s,t;
    stack<char> CS;

    cin >> s; 
    cin >> t; 

    CS = commonString(s,t);

    while(!CS.empty()){
        cout << CS.top();
        CS.pop();
    }cout << endl;


}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;

int main() {
  string S; cin >> S;
  int end = 0;
  int first = 2000001;
  rep(i, S.size()){
    if (S[i] == 'A') {
      if (first > i) first = i;
    }
    if (S[i] == 'Z') {
      if (end < i) end = i;
    }
  }
  dump(end - first +1);
}

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


const int N = 100000 + 7, mod = 1000000000 + 7;

vector <int> pos[N], idx[N];

int mx, n, dp[N][3][3][3];


int f(int I, int p1, int p2, int p3) {
        if(I > mx) return 1;
        if(~dp[I][p1][p2][p3]) return dp[I][p1][p2][p3];
        int res = 0;

        do {
                if(pos[I - 1][p1] <= pos[I][idx[I][0]] && pos[I - 1][p2] <= pos[I][idx[I][1]] && pos[I - 1][p3] <= pos[I][idx[I][2]]) {
                        res += f(I + 1, idx[I][0], idx[I][1], idx[I][2]);
                        res %= mod;
                }
        }while(next_permutation(idx[I].begin(), idx[I].end()));


        return dp[I][p1][p2][p3] = res % mod;


}

int32_t main() {

      cin >> n;
      memset(dp, -1, sizeof dp);
      for(int i = 1; i <= n; i++) {
            int x; cin >> x;
            pos[x].push_back(i);
            idx[x].push_back(pos[x].size() - 1);
            mx = max(mx, x);
      }

      if(pos[0].size() > 3) {
            cout << 0 << endl;
            return 0;
      }

      for(int i = 1; i < N; i++) if(pos[i].size() > pos[i - 1].size()) {
            cout << 0 << endl;
            return 0;
      }

      for(int i = 0; i < N; i++) {
            while(pos[i].size() < 3) pos[i].push_back(n + 1), idx[i].push_back(2);
      }

      int res = 0;

      do {
            res += f(1, idx[0][0], idx[0][1], idx[0][2]);
            res %= mod;
      }while(next_permutation(idx[0].begin(), idx[0].end()));

      cout << res << endl;

}


Measured memory_bytes: 32640
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b, c, d, e;
	int k;
	cin >> a >> b >> c >> d >> e;
	cin >> k;
	int minv = min({ a,b,c,d,e });
	int maxv = max({ a,b,c,d,e });
	if (maxv - minv > k) puts(":(");
	else puts("Yay!");
	return 0;
}

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

#define N 100010

int main()
{
   int n,m,h[N],ma[N];
   cin >> n >> m;
   
   for(int i=1;i<=n;i++)
   {
      cin>>h[i];
	  ma[i]=0;
   }
   
   for(int i=0;i<m;i++)
   {
      int a,b;
	  cin>>a>>b;             
	  ma[a]=max(ma[a],h[b]);
	  ma[b]=max(ma[b],h[a]);
   }
   
   int ans=0;
   for(int i=1;i<=n;i++)
   {
      ans += h[i]>ma[i];     
   }
   
   cout << ans << endl;
}


Measured memory_bytes: 4400
N = gets.to_i
abc = N.times.map {gets.split.map &:to_i}

dp = Array.new(N + 1) {Array.new(3) {0}}
N.times do |i|
  3.times do |j|
    3.times do |k|
      if j != k
        res = dp[i][j] + abc[i][k]
        dp[i + 1][k] = dp[i][j] + abc[i][k] if dp[i + 1][k] < res
      end
    end
  end
end

puts dp[N].max

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

using namespace std;

typedef long long ll;

const int MAXN=2e5+1;

int n,num[MAXN],tot[MAXN]={0};
ll ans=0;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1; i<=n; ++i) {
		cin>>num[i];
		++tot[num[i]];
	}
	for(int i=1; i<=n; ++i) ans+=1LL*tot[i]*(tot[i]-1)>>1;
	for(int i=1; i<=n; ++i)
		cout<<ans-1LL*tot[num[i]]*(tot[num[i]]-1)/2+1LL*(tot[num[i]]-1)*(tot[num[i]]-2)/2<<'\n';
	cout.flush();
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
vector<ll> v;
void dfs(ll a){
  if(a>3234566667)return;
  v.push_back(a);
  if(a%10!=9)dfs(a*10+a%10+1);
  if(a%10!=0)dfs(a*10+a%10-1);
  dfs(a*10+a%10);
}
int main()
{
ll k ;
cin >> k ;
rep(i,9)dfs(1+i);
sort(v.begin(),v.end());
cout << v[k-1] << endl;
return 0;
}

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

#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define INF 1e9 + 1;
#define MOD 1e9 + 7;

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

int N, X;

int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

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

    cin >> N >> X;

    int x[N];
    REP(i, 0, N) cin >> x[i];

    int D;
    if(N == 1){
        D = abs(x[0] - X);
    }else{
        D = gcd(abs(x[0] - X), abs(x[1] - X));
        REP(i, 2, N){
            D = gcd(D, abs(x[i] - X));
        }
    }

    cout << D << '\n';

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define p_b push_back
#define MOD 1000000007l


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
   // ll val1 = -1,val2 =- 1,val3 = - 1;
    ll i;
    set<ll> s ;
    map<ll,ll> mp ;
    for(i=0;i<n;i++)
    {
        ll a;
        cin >> a;
        s.insert(a);
        mp[a]++;
    }
    if(s.size() > 3)
    {

        cout << "No" << endl;
        return 0;
    }
    vector <ll> v;
    ll is_zero = 0;
    for(auto x: s)
    {

        v.p_b(x);
        if(x == 0)
        {

            is_zero = 1;
        }
    }
    if(is_zero)
    {
        if(v.size()==1)
        {

            cout << "Yes" << endl;
            return 0;

        }
        if(v.size()!=2)
        {

            cout << "No" << endl;
            return 0;
        }
        else
        {
            ll temp ;
            if(v[0] == 0)
            {
                temp = v[1];
            }
            else
            {

                temp = v[0] ;
            }
            if(mp[temp] == (2*mp[0]))
            {

                cout << "Yes" << endl;
            }
            else
            {

                cout << "No" << endl;
            }
        }
    }
    else
    {
        if(v.size() != 3)
        {

            cout << "No" << endl;
            return 0;
        }

        if(((v[0]^v[1] )== v[2]) || ((v[0]^v[2]) == v[1]) )
        {
           // cout << (v[0]^v[2]) << " " << v[1] << endl;


            if(mp[v[0]] == mp[v[1]])
            {

                if(mp[v[0]] == mp[v[2]])
                {
                   // cout << "lol" << endl;


                    cout << "Yes" << endl;
                    return 0;
                }
            }

        }
        cout << "No" << endl;

    }


    return 0;
}


Measured memory_bytes: 8704
### constant

MOD = 100000;

### main

n, m = gets.strip.split(' ').map{|s| s.to_i}

sbs = [0]
sum = 0
(n - 1).times do
  sum += gets.strip.to_i
  sbs << sum
end

total = 0
pos = 0

m.times do
  d = gets.strip.to_i
  pos0 = pos + d
  total = (total + (sbs[pos0] - sbs[pos]).abs) % MOD
  pos = pos0
end

puts total

Measured memory_bytes: 7016
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

const int MAXN=550;
int H,W,h,w;
int f[MAXN][MAXN];
mt19937 rng;

void add(int x,int y,int z) {
	for (int i=x; i<H; i|=i+1) {
		for (int j=y; j<W; j|=j+1) {
			f[i][j]+=z;
		}
	}
}

int sum(int x,int y) {
	int res=0;
	for (int i=x; i>=0; i&=i+1, i--) {
		for (int j=y; j>=0; j&=j+1, j--) {
			res+=f[i][j];
		}
	}
	return res;
}

int sum(int x1,int y1,int x2,int y2) {
	return sum(x2,y2) - sum(x2,y1-1) - sum(x1-1,y2) + sum(x1-1,y1-1);
}

bool find() {
	rep(i,h-1,H) rep(j,w-1,W) {
		int s=sum(i-h+1,j-w+1,i,j);
		if (s>=0) {
			add(i,j,-s-1);
		}
	}
	
	int s=sum(0,0,H-1,W-1);
	if (s>0) return true;
	return false;
}

int main() {
	rng=mt19937(chrono::steady_clock::now().time_since_epoch().count());
	
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);
	
	cin>>H>>W>>h>>w;
	rep(i,0,H) rep(j,0,W) add(i,j,4000);
	
	if (find()) {
		cout<<"Yes\n";
		rep(i,0,H) rep(j,0,W) cout<<sum(i,j,i,j)<<" \n"[j+1==W];
		return 0;
	}
	
	cout<<"No\n";
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  char op;
  cin >> A >> op >> B;
  
  if(op == '+'){
    C = A + B;
  }else{
    C = A - B;
  }
  
  cout << C << endl;
  
}

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		long[] pren = new long[n+1];
		long[] prem = new long[m+1];
		for(int i = 1;i<=n;i++){
			pren[i] = pren[i-1]+in.nextInt();
		}
		for(int i=1;i<=m;i++){
			prem[i] = prem[i-1]+in.nextInt();
		}
		int ans=0;int j=m;
		for(int i=0;i<=n;i++){
			if(k<pren[i]){
				break;
			}
			while(prem[j]>k-pren[i]){
				j--;
			}
			
			ans = Math.max(ans,i+j);
		}
		System.out.println(ans);
	}
}

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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int M = 1000000007;

void solve()
{
	int a, b;
	cin >> a >> b;
	cout << (a * b) << endl;

	return;
}


int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
	run();
	int n;
	cin >> n;
	vector<int> frq(n + 1);
	while (--n) {
		int a;
		cin >> a;
		frq[a]++;
	}
	for (int i = 1; i < sz(frq); i++)
		cout << frq[i] << endl;
}


Measured memory_bytes: 3992
l = list(input())
ans = 10000000
for let in range(26):
    cur = chr(let+97)
    temp = l[:]
    cnt = 0
    while len(set(temp)) > 1:
        for i in range(len(temp)-1):
            if temp[i] == cur or temp[i+1] == cur:
                temp[i] = cur
            else:
                temp[i] = l[i]
        temp.pop()
        cnt += 1
    ans = min(ans, cnt)
    # print(temp)
print(ans)

Measured memory_bytes: 3064
// main.cpp : Defines the entry point for the application.
//

#include <iostream>

using namespace std;

int main()
{
	int n, x, t;
	cin >> n >> x >> t;
	int n_batch = n / x;
	if(n % x)
		++n_batch;
	int t_total = n_batch * t;
	cout << t_total << endl;
	return 0;
}

Measured memory_bytes: 3528
#include"iostream"

using namespace std;

int main()
{
    int d;
    cin >> d;
    
    switch (d) {
    case 22:cout << "Christmas Eve Eve Eve"; break;
    case 23:cout << "Christmas Eve Eve"; break;
    case 24:cout << "Christmas Eve"; break;
    case 25:cout << "Christmas"; break;
    }
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
   
    int n, i, Rt[200000], max=-1000000000;
    scanf("%d", &n);
          
    for(i=0; i<n; i++){
        scanf("%d", &Rt[i]);
    }
    
    int min =Rt[0];
    
    for(i=1; i<n; i++){
        if(max < Rt[i]-min){
            max = Rt[i]-min;
        }
        if(min > Rt[i]){
            min = Rt[i];
        }
    }
    printf("%d\n", max);
    return 0;
    
    
}

Measured memory_bytes: 1376
import math
import itertools
n = int(input())
x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
for i in range(n):
    x[i], y[i] = map(int, input().split())
a = [k for k in range(n)]
cnt = math.factorial(n)
l_list = [0 for _ in range(cnt)]
m = 0
for b in itertools.permutations(a):
    l = 0
    for j in range(1, n):
        l += ((x[b[j]] - x[b[j - 1]]) ** 2 + (y[b[j]] - y[b[j - 1]]) ** 2) ** 0.5
    l_list[m] = l
    m += 1
print(sum(l_list) / cnt)


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

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

ll INF = pow(10,18);

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

  vector<ll> a(n);
  for(int i=0; i<n; i++){
    cin >> a.at(i);
    if(a.at(i)==0){
      cout << 0;
      return 0;
    }
  }

  ll ans = a.at(0);
  for(int i=1; i<n; i++){
    if(INF/a.at(i)<ans){
      cout << "-1";
      return 0;
    }else{
      ans *= a.at(i);
    }
  }

  cout << ans;
}

Measured memory_bytes: 4008
use std::collections::*;
use std::io;
use std::cmp::*;

fn main(){
    let t_cases = 1;
    for _ in 0..t_cases{
        solve();
    }
}

fn solve(){
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().parse::<usize>().unwrap();
    let mut dp = vec![0;3];
    for _ in 1..(1+n){
        buf.clear();
        io::stdin().read_line(&mut buf).unwrap();
        let a = buf
                        .trim()
                        .split_whitespace()
                        .map(|x| x.parse::<i32>().unwrap())
                        .collect::<Vec<i32>>();
        let mut tdp = vec![0;3];
        for j in 0..3{
            for k in 0..3{
                if j==k{continue;}
                tdp[j] = max(tdp[j],dp[k]+a[j]);
            }
        }
        dp = tdp;
    }
    println!("{}",dp.iter().max().unwrap());
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  string S,T;
  ll N;
  cin >> N;
  cin >> S >> T;
  rep(i,N){
    cout << S[i] << T[i];
  }
  cout << endl;
}

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

using namespace std;

int main () {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if (A + B == C + D) {
        cout << "Balanced" << endl;
    } else if (A + B < C + D) {
        cout << "Right" << endl;
    } else {
        cout << "Left" << endl;
    }
}

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

int main() {
  int a1,a2,a3;
  int sum = 0;
  cin >> a1 >> a2 >> a3;
  sum = a1 + a2 + a3;
  if(sum >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

static const unsigned long long int MOD = 1000000007LL;

int main()
{
    int n, l, res = 0, eat = 1000000;
    cin >> n >> l;

    for (int i = 1; i <= n; i++)
    {
        int tmp = l + i - 1;
        res += tmp;
        if (abs(tmp) < abs(eat))
        {
            eat = tmp;
        }
    }

    cout << res - eat;

    return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			while (sc.hasNext()) {
				int[] n = new int[6];
				for (int i = 0; i < 6; i++) {
					n[i] = sc.nextInt();
				}
				BigDecimal y = BigDecimal.valueOf(n[3] * n[2] - n[0] * n[5])
						.divide(BigDecimal.valueOf(n[1] * n[3] - n[0] * n[4]), 3, RoundingMode.HALF_UP);
				BigDecimal x = BigDecimal.valueOf(n[2] * n[4] - n[1] * n[5])
						.divide(BigDecimal.valueOf(n[0] * n[4] - n[1] * n[3]), 3, RoundingMode.HALF_UP);

				System.out.printf("%s %s\n", x, y);
			}
		}
	}
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=n-1; i>0; i--){
        cout << a[i] << " ";
    }
        cout << a[0] << endl;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
long long n,t,a[1000010],now,maxx,w,w1,sum[4][110],ans;
vector<long long>v[4];
bool cmp(const long long &a,const long long &b)
{
	return a>b;
}
int main(void)
{
	scanf("%lld%lld%lld",&n,&w,&w1);
	scanf("%lld",&maxx);
	v[0].push_back(maxx);
	for(long long i=2;i<=n;i++)
	{
		scanf("%lld%lld",&now,&maxx);
		v[now-w1].push_back(maxx);
	}
	for(long long i=0;i<4;i++)
		sort(v[i].begin(),v[i].end(),cmp);
	for(long long i=0;i<4;i++)
		for(long long j=1;j<=v[i].size();j++)
			sum[i][j]=v[i][j-1]+sum[i][j-1];
	for(long long i=0;i<=v[0].size();i++)
		for(long long j=0;j<=v[1].size();j++)
			for(long long k=0;k<=v[2].size();k++)
				for(long long p=0;p<=v[3].size();p++)
				{
					if(w1*i+(w1+1)*j+(w1+2)*k+(w1+3)*p>w)
						continue;
					ans=max(ans,sum[0][i]+sum[1][j]+sum[2][k]+sum[3][p]);
				}
	cout<<ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

const int Maxn = 200005;

int n, m;
int a[Maxn];
int cnt[Maxn];
int glob[Maxn], tot;

void Add(int x)
{
	if (x - cnt[x] > 0)
		if (glob[x - cnt[x]]++ == 0) tot--;
	cnt[x]++;
}

void Rem(int x)
{
	cnt[x]--;
	if (x - cnt[x] > 0)
		if (--glob[x - cnt[x]] == 0) tot++;
}

int main()
{
	scanf("%d %d", &n, &m);
	tot = n;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]); Add(a[i]);
	}
	for (int i = 0; i < m; i++) {
		int x, y; scanf("%d %d", &x, &y);
		Rem(a[x]); a[x] = y; Add(a[x]);
		printf("%d\n", tot);
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

ll func(string s,string t){
    ll ans=0;
    for(char c='a';c<='z';c++){
        bool l=false,r=false;
        rep(i,s.size()){
            if(s[i]==c) l=true;
        }
        rep(i,t.size()){
            if(t[i]==c) r=true;
        }
        if(l&&r) ++ans;
    }
    return ans;
}

int main(void)
{
    ll n; cin>>n;
    string s; cin>>s;
    ll ans=0;
    rep(i,n+1){
        ll cnt=func(s.substr(0,i),s.substr(i));
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3552
#import <stdio.h>
#define ABS(a) ((a)>0?(a):(-(a)))
#define MIN(a,b) (((a)<(b))?(a):(b))
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    int s = 0;
    for (int i=0;i<n;i++) {
        int a;
        scanf("%d",&a);
        s += 2*MIN(a,ABS(k-a));
    }
    printf("%d",s);
}


Measured memory_bytes: 2164
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <cassert>

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

int main(){
    int n; cin >> n;
    ll ans = 0;
    rrep(i, n){
        if (i % 3 != 0 and i % 5 != 0) ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3156
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

#define fst first
#define snd second

typedef long long llint;
typedef pair<int, int> pii;

const int B = 27397, MOD = 1e9 + 7;
const int B1 = 33941, MOD1 = 1e9 + 9;

const int MAXN = 1e5 + 10;
const int MAXK = 1010;

bool want_change[MAXN];

int N, K;
int change[MAXK][MAXK], no_change[MAXK][MAXK];
int pref_change[MAXK][MAXK], pref_no_change[MAXK][MAXK];

void init_pref(int (&A)[MAXK][MAXK], int (&pref_A)[MAXK][MAXK]) {
  for (int i = 1; i <= K + 1; ++i)
    for (int j = 1; j <= K + 1; ++j)
      pref_A[i][j] = pref_A[i - 1][j] + pref_A[i][j - 1] - pref_A[i - 1][j - 1] + A[i][j];
}

int get_sum(int r1, int s1, int r2, int s2, int (&pref_A)[MAXK][MAXK]) {
  return pref_A[r2][s2] - pref_A[r2][s1 - 1] - pref_A[r1 - 1][s2] + pref_A[r1 - 1][s1 - 1];
}

int get_changed(int dr, int ds, int (&pref_A)[MAXK][MAXK]) {
  return get_sum(1, 1, dr, K + 1, pref_A) + get_sum(1, 1, K + 1, ds, pref_A) - 2*get_sum(1, 1, dr, ds, pref_A);
}

int main(void) {
  scanf("%d%d", &N, &K);

  int start = 0, sol = 0;
  for (int i = 0; i < N; ++i) {
    int r, s;
    char col[2];
    scanf("%d%d%s", &r, &s, col);

    bool want_col = col[0] == 'B';
    bool actual_col = (r / K) % 2 != (s / K) % 2;

    want_change[i] = want_col != actual_col;
    start += !want_change[i];

    if (want_change[i])
      ++change[(r % K) + 2][(s % K) + 2];
    else
      ++no_change[(r % K) + 2][(s % K) + 2];
  }

//  for (int i = 0; i <= K + 1; ++i) {
//    for (int j = 0; j <= K + 1; ++j) {
//      printf("%d ", change[i][j]);
//    }
//    printf("\n");
//  }
//  printf("\n");
//
//  for (int i = 0; i <= K + 1; ++i) {
//    for (int j = 0; j <= K + 1; ++j) {
//      printf("%d ", no_change[i][j]);
//    }
//    printf("\n");
//  }


  init_pref(change, pref_change);
  init_pref(no_change, pref_no_change);

  sol = max(start, N - start);
  for (int dr = 0; dr <= K; ++dr) {
    for (int ds = 0; ds <= K; ++ds) {
      int curr = start + get_changed(dr + 1, ds + 1, pref_change) - get_changed(dr + 1, ds + 1, pref_no_change);
      sol = max(sol, max(curr, N - curr));
    }
  }

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

  return 0;
}



Measured memory_bytes: 16256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string>

using namespace std;

int main(void)
{
	vector<int> coller(9,0);
	int n;
	int sum=0;
	cin >> n;
	vector<int> num(n);
	int i;
	int t;
	for (i = 0; i < n; i++)
	{
		cin >> num[i];
	}
	for (i = 0; i < n; i++)
	{
		for (t = 0; t < 9; t++)
		{
			if ((num[i] / 400) >= 8)
			{
				coller[8]++;
				break;
			}
			else if ((num[i] / 400) == t)
			{
				coller[t] = 1;
			}
	}
	}
	for (i = 0; i < 8; i++)
	{
		sum = sum + coller[i];
	}
	if (sum == 0)
	{
		cout << 1 << endl;;
	}
	else
	{
		cout << sum << endl;
	}
	if (sum == 0)
	{
		if (coller[8] == 0)
		{
			cout << 1 << endl;
		}
		else
		{
			cout << coller[8] << endl;
		}
	}
	else if (coller[8] != 0)
	{
		cout << sum + coller[8] << endl;

	}
	else if(coller[8]==0)
	{
		cout << sum << endl;
	}
	return 0;
}


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

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

int main(){
    int N;
    cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    int cnt = 0;
    rep(i, N){
        if((i + 1) == a[a[i] - 1]){
            cnt++;
        }
    }
    cout << cnt / 2 << endl;
    return 0;
}

Measured memory_bytes: 888
/// Zhupengfei 2018
/// Hereby declare: this program is in public domain.

/// Solution for problem: abc102A

#include <bits/stdc++.h>

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int N;
	cin>>N;
	if(N%2) N*=2;
	cout<<N<<endl;


	return 0;
}



Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
p=-1
r=0
for a in A:
    r=r+B[a-1] if a!=p+1 else r+B[a-1]+C[a-2]
    p=a
print(r)

Measured memory_bytes: 3060