akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)

//AB^2=AC^2+BC^2-2*AC*BC*COSC

signed main(){
    string S,T;
    cin>>S>>T;

    if(S==T.substr(0,T.size()-1)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 3108
#include <iostream>
#include <deque>

using namespace std;

int main()
{
	deque<int> st;
	int n;
	while(cin >>n){
		if(n){
			st.push_back(n);
		}else{ // 0が入力されたとき
			cout << st.back() << endl;
			st.pop_back();
		}
	}
	return 0;
}

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

int main() {
	int x;
	cin >> x;
	if(x < 400) return 0;
	else if(x < 600) cout << 8 <<endl;
	else if(x < 800) cout << 7 <<endl;
	else if(x < 1000) cout << 6 <<endl;
	else if(x < 1200) cout << 5 <<endl;
	else if(x < 1400) cout << 4 <<endl;
	else if(x < 1600) cout << 3 <<endl;
	else if(x < 1800) cout << 2 <<endl;
	else if(x < 2000) cout << 1 <<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,flag=1;std::cin >> n;
    std::vector<std::string> a(n);
    for (int i = 0; i < n; i++) {
        cin>>a[i];
    }
    for (int i = 0; i < n; i++) {
        if(i>0){
            if(a[i].front()!=a[i-1].back()){
                flag=0;
                break;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if(a[i]==a[j]){
                flag=0;
                break;
            }
        }
        if(flag==0)break;
    }
    
    flag ? std::cout << "Yes" :std::cout << "No" ;

}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = 0;
    int M = 0;
    int X = 0;

    while (N < 1 || N > 100) {
      N = sc.nextInt();
    }

    while (M < 1 || M > 100) {
      M = sc.nextInt();
    }

    while (X < 1 || X > N - 1) {
      X = sc.nextInt();
    }

    int[] A = new int[M];
    int s;

    for (int i = 0; i <= M - 1; i++) {
      s = 0;

      while (s < 1 || s > N -1 || s == X) {
        s = sc.nextInt();
      }
      A[i] = s;
    }

    int X2 =X;
    int  c1 = 0;

      while (X2 <= N - 1) {
      for (int ii = 0; ii <= M - 1; ii++) {
        if (A[ii] == X2) {
          c1++;
        }
      }
      X2++;
    }

    X2 =X;
    int  c2 = 0;

      while (X2 >= 0) {
      for (int iii = 0; iii <= M - 1; iii++) {
        if (A[iii] == X2) {
          c2++;
        }
      }
      X2--;
    }

    if (c1 < c2) {
      System.out.println(c1);
    }else {
      System.out.println(c2);
    }


    }
  }

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N;
  cin >> N;
  vector<vector<char>> S(N, vector<char>(N));
  rep(i, N) {
    rep(j, N) {
      cin >> S[i][j];
    }
  }

  vector<vector<char>> SS(2 * N, vector<char>(2 * N));
  rep(i, N) {
    rep(j, N) {
      SS[i][j] = S[i][j];
      SS[i + N][j] = S[i][j];
      SS[i][j + N] = S[i][j];
      SS[i + N][j + N] = S[i][j];
    }
  }

  int ans = 0;
  rep(i, N) {
    int j = 0;
    bool ok = true;
    rep(ii, N) {
      rep(jj, N) {
        if (SS[i + ii][j + jj] != SS[i + jj][j + ii])
          ok = false;
      }
    }
    if (ok)
      ans++;
  }
  ans *= N;
  cout << ans << endl;
}

Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main(void){
    // Your code here!
    int n;
    int a[10000];
    int count = 0;
    int ans = 0;
    
    std::cin >>n;
    
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
    }
    
    for(int i = 0; i < n; i++){
        count = 0;
        while(1){
            if(a[i] % 2 == 0){
                a[i] /= 2;
                count++;
            }
            else{
                break;
            }
        }
        
        ans += count;
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;

string S;

bool C(int k){
	bool flg=true;
	char c=S[(int)S.size()-k];
	FOR(i,(int)S.size()-k+1,k){
		if (S[i]!=c){
			flg=false;
		}
	}
	return flg;
}

int main(){
	cin>>S;
	int lb=1,ub=(int)S.size()+1;
	while(ub-lb>1){
		int mid=(ub+lb)>>1;
		if (C(mid)){
			lb=mid;
		}else{
			ub=mid;
		}
	}
	cout<<lb<<endl;
	return 0;
}

Measured memory_bytes: 512
/*input

*/

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb          push_back
#define pp          pop_back
#define nl          cout << "\n"
#define MIN(con)    (*min_element(ALL(con)))
#define MAX(con)    (*max_element(ALL(con)))
#define NX(cont)    next_permutation(ALL(cont))
#define PX(cont)    prev_permutation(ALL(cont))
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define all(c)      c.begin(),c.end()
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sp          cout << " "
#define ifalse      ios_base::sync_with_stdio(false),cin.tie(NULL)
#define debug(x)    cout << #x << " = " << x << "\n";

using ll = long long;
using ld = long double;
 
template <typename T> T GCD(T a, T b) { ll t; while(a){ t=a; a=b%a; b=t; } return b; }
template <typename T> T LCM(T a, T b) { return (a*b) / GCD(a, b); }
template <typename T> string toString(T a) { return to_string(a); }
template <typename T> void toInt(string s, T &x) { stringstream str(s); str >> x; }

ll add(ll x, ll y, ll MOD) { x += y; if(x >= MOD) x -= MOD; return x; }
ll sub(ll x, ll y, ll MOD) { x -= y; if(x < 0) x += MOD; return x; }
ll mul(ll x, ll y, ll MOD) { return ((x % MOD) * (y % MOD)) % MOD; }

ll powr(ll a, ll b, ll MOD) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a, MOD);
    a = mul(a, a, MOD);
    b >>= 1;
  }
  return x;
}

ll inv(ll a, ll MOD) { return powr(a, MOD-2, MOD); }
const ll INF =  1e18;
const int SINF = 1e9;
const ll MOD = 1e9 + 7;

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/************************************START***************************************/
const int N = 100005;

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

  int w = count(all(s), '.');
  int b = 0;
  int ans = min(w, n - w);
  for(int i = 0; i < n; i ++) {
    if(s[i] == '.') {
      w --;
    }
    else {
      b ++;
    }
    ans = min(ans, b + w);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n,i,sum=0,k;
 cin>>n>>k;
int a[n];
for(i=0;i<n;i++)
 cin>>a[i];
sort(a,a+n);
for(i=n-1;i>=n-k;i--)
 sum+=a[i];
cout<<sum;
}

Measured memory_bytes: 256
//abc151_e.cpp
//Sun Jan 12 20:59:41 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

const ll MAX = 400000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(ll n, ll k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main(){
	ll n,k;
	cin >> n >> k;

	COMinit();

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

	if (k==1){
		cout << 0 << endl;
		return 0;
	}

	sort(a,a+n,greater<ll>());

	ll ans = 0;
	for (int i=0;i<=n-k;i++){
		ll temp = mod(a[i]*COM(n-i-1,k-1),MOD);
		ans = mod(ans+temp,MOD);
	}

	sort(a,a+n);

	for (int i=0;i<=n-k;i++){
		ll temp = mod(a[i]*COM(n-i-1,k-1),MOD);
		ans = mod(ans-temp+MOD,MOD);
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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


int maxn = 2e5 + 1;
vector<vector<int>> g(maxn);
vector<bool> used(maxn);
int dfs(int v) {
    used[v] = true;
    int cnt =1;
    for (auto to : g[v]) {
        if (!used[to]) cnt += dfs(to);
    }
    return cnt;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt = 1; // cin >> t;
    for (; tt; tt--) {
        int n, m; cin >> n >> m;
        for (int i = 0; i < m; i++) {
            int a, b; cin >> a >> b; a--; b--;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (!used[i]) ans = max(ans, dfs(i));
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 23432
N = int(input())

restaurants = {}
for i in range(N):
  city, score = tuple(map(str, input().split()))
  if city not in restaurants.keys():
    restaurants[city] = [(i + 1, int(score))]
  else:
    restaurants[city].append((i + 1, int(score)))

for k, v in sorted(restaurants.items()):
  sorted_restaurants = sorted(v, key=lambda x: x[1], reverse=True)
  for restaurant in sorted_restaurants:
    print(restaurant[0])

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

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 ll INF = 10000000000;

int main()
{
    int n,k; cin >> n >> k;
    vector<int> h(n);
    vector<ll> dp(n,INF);
    for( int i = 0; i < n; ++i )
    {
        cin >> h[i];
    }

    dp[0] = 0;
    for( int i = 0; i < n; ++i )
    {
        for( int j = 1; j <= k; ++j )
        {
            if( i+j > n )
            {
                continue;
            }
            chmin(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}



Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
/*------------------junk----------------------*/
typedef long long int lli;
typedef unsigned long long int ulli;
const int MOD = 1e9 + 7;
#define ff first
#define ss second
#define gc getchar_unlocked
#define fri(i, j , n) for (auto (i) = (j); (i) < (n); ++(i))
#define frie(i, j , n) for (auto (i) = (j); (i) <= (n); ++(i))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f2a(x , n , v)  fill(&(x)[0][0], &(x)[0][0] + (0 + n) *(0 + n) , (v))
#define fa(x , n , v) fill( (x), (x)+(n), (v)) 
#define pb emplace_back
#define mp make_pair
#define getchar_unlocked getchar
# define TMP template<typename
#ifdef LOCAL 
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
    
    ~debug() { cerr << endl; }
    template < class c > typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { cerr << boolalpha << i; return * this; }
    template < class c > typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { return * this << range(begin(i), end(i)); }
    template < class c, class b > debug & operator <<(pair < b, c > d) {
        return * this << "(" << d.first << ", " << d.second << ")";
    }
    template < class c > debug & operator <<(rge<c> d) {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
            *this << ", " + 2 * (it == d.b) << *it;
        return * this << "]";
    }};
#define oo(...) __f(#__VA_ARGS__, __VA_ARGS__)
TMP Arg1>
void __f(const char *name, Arg1 &&arg1)
{cout << name << ": " << arg1 << "\n";}
TMP 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...);
}
void in(int &x){
    cin  >> x;
}
#else
inline void in(int &x)
    {
    register int c = getchar_unlocked();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar_unlocked());
    if(c=='-') {neg=1;c=getchar_unlocked();}
    for(;c>47 && c<58;c = getchar_unlocked()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
    }
inline void uin(ulli &n){
    register ulli c=gc();
    n=0;
    while(c<'0'||c>'9')
    c=gc();
    while(c<='9'&&c>='0'){
    n=n*10+c-'0';
    c=gc();}
}
#endif
/*----------check constraints again-------------*/

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
    stack<char> stk;
    int n;string s;
    cin >> n >> s;
    for(char & c : s){
        if(stk.empty()){
            stk.push(c);
        }else{
            if(stk.top() == c){
                continue;
            }else{
                stk.push(c);
            }
        }
    }
    cout << stk.size();
}











Measured memory_bytes: 512
#include <stdio.h>
long int gcd(long int a, long int b) { return b ? gcd(b, a%b) : a; }

int main(){
  long int a,b;
  scanf("%ld%ld",&a,&b);
  long int abgcd = gcd(a,b);
  long int ans = 0;
  for(long int i = 2; i * i <= abgcd; i++){
    if(abgcd % i == 0)ans++;
    while(abgcd % i == 0)abgcd /= i; 
  }
  if(abgcd > 1)ans++;
  printf("%ld",ans+1);
  return 0;
} 

Measured memory_bytes: 128
def solve():
    N = int(input())
    C = input()
    i = 0
    j = N - 1
    ans = 0
    while i < j:
        if C[i] == 'W' and C[j] == 'W':
            j -= 1
        elif C[i] == 'W' and C[j] == 'R':
            # tmp = C[i]
            # C[j] = C[i]
            # C[i] = tmp
            i += 1
            j -= 1
            ans += 1
        elif C[i] == 'R' and C[j] == 'R':
            i += 1
        elif C[i] == 'R' and C[j] == 'W':
            i += 1
            j -= 1
    print(ans)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 67592
#include <cmath>
#include <functional>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> a(n);
  set <int> q;
  a[0] = 0;
  vector<int>ans(n,-1);
  ans[0]=0;
  vector<vector<int>>g(n);
  for (int i = 1; i < n; i++) {
    int x;
    cin>>x;
    x--;
    g[x].push_back(i);
  }
  function<int(int)>solve=[&](int i){
    vector<int>cur;
    for (int j:g[i]){
      cur.push_back(solve(j));
    }
    int mx = 0;
    sort(cur.rbegin(),cur.rend());
    for (int i = 0; i < (int) cur.size(); i++) {
      mx = max(mx, cur[i] + i + 1);
    }
    return mx;
  };
  cout<<solve(0)<<endl;
}


Measured memory_bytes: 17408
using System;
using System.Collections.Generic;
using System.Linq;

namespace ALDS1_6_D {
    public static class Problem {
        public static int GetMinCost(this int[] source) {
            int n = source.Length;
            int minCost = 0;

            int[] sorted = (int[])source.Clone();
            Array.Sort(sorted);
            int minValue = sorted[0];

            Dictionary<int, int> valueToIndex = new Dictionary<int, int>();
            for (int i = 0; i < n; i++)
                valueToIndex[source[i]] = i;

            bool[] used = new bool[n];
            
            for(int i = 0; i < n; i++) {
                if (used[i])
                    continue;

                int minValueInGroup = sorted[i];
                int curPosition = valueToIndex[minValueInGroup];
                int sumOriginal = 0;
                int sumReplace = (minValue + minValueInGroup) * 2;

                while (curPosition != i) {
                    used[curPosition] = true;
                    int nextValue = sorted[curPosition];
                    sumOriginal += nextValue + minValueInGroup;
                    sumReplace += nextValue + minValue;
                    curPosition = valueToIndex[nextValue];
                }
                minCost += Math.Min(sumOriginal, sumReplace);
            }
            return minCost;
        }
    }

    class Program {
        static void Main(string[] args) {
            Console.ReadLine();
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(input.GetMinCost());
        }
    }
}

Measured memory_bytes: 10296
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int p[10],c[10];
int main() {
  ll d,g, ans = 1 << 30;
  cin >> d >> g;
  rep(i, d){
    cin >> p[i] >> c[i];
  }
  for(int i = 0; i < 1 << d; i++){
    for(int j = 0; j < d; j++){
      ll ps = 0;
      ll to = 0;
      for(int k = 0; k < d; k++){
        if(j != k && (i >> k & 1)){
          to += c[k] + p[k] * (k+1)*100;
          ps += p[k];
        }
      }
      if(to >= g){
        ans = min(ans, ps);
      }else if(to + 100*(j+1)*(p[j]-1) >= g){
        int m = ceil((double)(g - to)/((j+1)*100));
        ps += m;
        ans = min(ans, ps);
      }
      else if(to + 100*(j+1)*p[j] + c[j] >= g){
        ps += p[j];
        ans = min(ans,ps);
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)

N = n1()
A = nn()

t = A[0]
ans = 0

for i in range(1, N):
    if A[i] <= t:
        ans += t - A[i]
    else:
        t = A[i]

print(ans)

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

int main() {
    int N; cin >> N;
    int fX = 0;
    for (int x=N; x!=0; ) {
        fX += x % 10;
        x /= 10;
    }
    if (N % fX)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;
int L[2123];

int main() {

	scanf("%d", &N);
	rep(i, N) scanf("%d", &L[i]);

	sort(L, L + N);

	ll ans = 0;
	rep(i, N) {
		for (int j = i + 1; j < N; ++j) {
			int t = L[N - i - 1] - L[N - j - 1];
			int d = upper_bound(L, L + N, t) - L;
			ans += max(0,N - j - 1 - d);
		}
	}


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

	return 0;
}


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

using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);

    int cnt[26] = {};

    int n;
    cin >> n;

    for(int i = 0; i < n; ++i)
    {
        char q;
        cin >> q;
        ++cnt[q - 'a'];
    }

    int ans = 1;
    for(int i = 0; i < 26; ++i)
        ans = (long long) ans * (cnt[i] + 1) % MOD;

    --ans;
    if(ans < 0)
        ans += MOD;

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
H, W = tuple(map(int, input().split()))
C = []
for h in range(H):
    C.append([c for c in input()])
res = [["." for _ in range(W)] for _ in range(2*H)]
diff = 0
for h in range(H):
    for w in range(W):
        if C[h][w] == "*":
            res[h+diff][w] = "*"
            res[h+diff+1][w] = "*"
    diff += 1
res = ["".join(x) for x in res]
res = "\n".join(res)
print(res)

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        try (Scanner sc = new Scanner  (System.in)){
            String line = sc.nextLine();
            String answer = "";
            int length = line.length();
            for(int i=0;i<length;i++){
                char ch = line.charAt(i);
                if(Character.isLowerCase(ch)){
                    answer += Character.toUpperCase(ch);
                } else {
                    answer += Character.toLowerCase(ch);
                }
            }
            System.out.println(answer);
        }
    }
}



Measured memory_bytes: 31596
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }

const int MAXN = 100000;

int n;
int l[MAXN], r[MAXN];


void run() {
	scanf("%d", &n);
	REP(i, n) scanf("%d%d", &l[i], &r[i]);
	sort(r, r + n); sort(l, l + n);  reverse(l, l + n);

	ll ret = 0, cur = 0;
	REP(i, n) {
		ret = max(ret, cur + 2 * l[i]);
		ret = max(ret, cur - 2 * r[i]);
		ret = max(ret, cur + 2 * (l[i] - r[i]));
		cur += 2 * (l[i] - r[i]);
	}
	printf("%lld\n", ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 1024
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
LL A, B, C;
int main() {
	cin >> A >> B >> C;
	if (A + B >= C) return printf("%lld\n", B + C), 0;
	else {
		return printf("%lld\n", min(A + B + 1ll, C) + B), 0;
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
constexpr int f(int a){
	return a?a%10+f(a/10):0;
}
template<int N>struct ans{
	int a[N+1];
	constexpr ans(){
		for(int i=1;i<=N;i++)a[i]=f(i);
	}
};
void print(int a){
	a?print(a/10),putchar(a%10+48):0;
}
ans<10000>memo;
int t,n,a,b,c;
main(){
	while((c=getchar())>47)n=n*10+c-48;
	while((c=getchar())>47)a=a*10+c-48;
	while((c=getchar())>47)b=b*10+c-48;
	for(int i=1;i<=n;i++)if(a<=memo.a[i]&&memo.a[i]<=b)t+=i;
	t?print(t),0:putchar(48);
}


Measured memory_bytes: 384
Lower = [chr(i) for i in range(65, 65 + 26)]

h, w = map(int, input().split())
ans = "A1"
for i in range(h):
    s = list(map(str, input().split()))
    for j in range(w):
        if s[j] == "snuke":
            ans = Lower[j] + str(i + 1)
print(ans)


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int m, k;

int main() {
	cin.tie(0)->sync_with_stdio(0);
    cin >> m >> k;
    if (k > (1 << m) - 1) {
        cout << -1;
        return 0;
    } else if (m == k && k == 1) {
        cout << -1;
        return 0;
    }

    if (k == 0) {
        rep(i, 0, (1 << m)) {
            cout << i << ' ' << i << ' ';
        }
    } else {
        set<int> core;
        deque<int> ans;
        rep(i, 0, m + 2) {
            if (k & (1 << i)) {
                core.insert((1 << i));
                ans.push_back((1 << i));
            }
        }

        rep(i, 0, (1 << m)) {
            if (core.find(i) == core.end()) {
                ans.push_front(i);
                ans.push_back(i);
            }
        }

        auto it = core.rbegin();
        while (it != core.rend()) {
            ans.push_back(*it);
            ++it;
        }

        while (!ans.empty()) {
            cout << ans.front() << ' ';
            ans.pop_front();
        }
    }
}


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

#define LL long long
#define P pair<LL, LL>
vector<vector<P>> g1(100005), g2(100005);
LL s, t, x, y, a, b, n, m, ans[100005];
LL da[100005], db[100005];

void dkstr(vector<vector<P>>& g, LL v, LL *d) {
	priority_queue<P, vector<P>, greater<P>> pq;
	int vis[n+1] = {};
	pq.push({0, v});
	while(!pq.empty()) {
		LL i = pq.top().second, c = pq.top().first; pq.pop();
		if(vis[i]) continue;
		vis[i] = 1; d[i] = c;
		for(auto j : g[i])
			if(!vis[j.first]) pq.push({c + j.second, j.first});
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> s >> t;
	while(m--) {
		cin >> x >> y >> a >> b;
		g1[x].push_back({y, a});
		g2[x].push_back({y, b});
		g1[y].push_back({x, a});
		g2[y].push_back({x, b});
	}
	dkstr(g1, s, da);
	dkstr(g2, t, db);

	ans[n+1] = 1e15;
	for(int i = n; i > 0; i--) ans[i] = min(ans[i+1], da[i] + db[i]);
	for(int i = 1; i <= n; i++) cout << 1000000000000000 - ans[i] << '\n';
}

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

int main(){
  int mt[10];
  for(int i = 0; i < 10; i++) cin >> mt[i];

  for(int i = 0; i < 3; i++){
    int *ans;
    ans = max_element(mt, mt+10);
    cout << *ans << endl;
    *(mt+(ans-mt)) = 0;
  }
}

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

typedef long long ll;
typedef pair <int, int> ii;

const int Maxn = 100005;
const int mod = 998244353;
const int pw = 1000000;
const int Maxm = 1005;

int n;
vector <int> neigh[Maxn];
vector <int> my[3];
int col[3][Maxn];
int res;
bool was[3][Maxm][Maxm];

int toPower(int a, int p)
{
    int res = 1;
    while (p) {
        if (p & 1) res = ll(res) * a % mod;
        p >>= 1; a = ll(a) * a % mod;
    }
    return res;
}

void Solve(vector <int> &res, int col[])
{
    int m; scanf("%d", &m);
    for (int i = 1; i <= n; i++)
        neigh[i].clear();
    for (int i = 0; i < m; i++) {
        int a, b; scanf("%d %d", &a, &b);
        if (a > b) swap(a, b);
        neigh[a].push_back(b);
    }
    for (int i = n; i > 0; i--) {
        vector <int> seq;
        for (int j = 0; j < neigh[i].size(); j++)
            seq.push_back(col[neigh[i][j]]);
        sort(seq.begin(), seq.end());
        col[i] = 0;
        int my = toPower(pw, 3 * i);
        for (int j = 0; j < seq.size(); j++)
            if (seq[j] == col[i]) col[i]++;
        if (col[i] == res.size()) res.push_back(my);
        else res[col[i]] = (res[col[i]] + my) % mod;
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < 3; i++) {
        Solve(my[i], col[i]);
        assert(my[i].size() < Maxm);
    }
    for (int i = 0; i < my[0].size(); i++)
        for (int j = 0; j < my[1].size(); j++)
            for (int k = 0; k < my[2].size(); k++) {
                if (was[0][i][j] || was[1][i][k] || was[2][j][k]) continue;
                was[0][i][j] = was[1][i][k] = was[2][j][k] = true;
                res = (res + ll(my[0][i]) * my[1][j] % mod * my[2][k]) % mod;
            }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 7296
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=parseMap(split(readline()))
    l=[0 for i in 1:n+1]
    r=[0 for i in 1:n+1]
    l[2],r[2]=abs(a[1]),abs(a[end])
    for i in 3:n+1
        l[i]=l[i-1]+abs(a[i-1]-a[i-2])
    end
    for i in 3:n+1
        r[i]=r[i-1]+abs(a[n-i+2]-a[n-i+3])
    end
    println(l[1]+r[n]+abs(a[2]))
    for i in 2:n-1
        println(l[i]+r[n-i+1]+abs(a[i+1]-a[i-1]))
    end
    println(l[n]+r[1]+abs(a[end-1]))
end
main()

Measured memory_bytes: 134792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <queue>
#include <list>
using namespace std;

string s;
long long k;

long long ans[107][5][2];

long long f(long long idx, long long c, bool a){
    if(ans[idx][c][a] == -2){
        if(c > k) return 0;
        if(idx >= s.size()){
            return (c == k);
        }
        long long r = 0;
        r += f(idx+1, c, (a && s[idx] == '0'));
        for(long long i = '1'; i < (a ? s[idx] : '9'+1); i++){
            r += f(idx+1, c+1, false);
        }
        if(a && s[idx] != '0'){
            r += f(idx+1, c+1, true);
        }
        ans[idx][c][a] = r;
    }
    return ans[idx][c][a];
}

int main(){
    for(long long i = 0; i < 107; i++){
        for(long long j = 0; j < 5; j++){
            for(long long k = 0; k < 2; k++){
                ans[i][j][k] = -2;
            }
        }
    }
    cin >> s >> k;
    cout << f(0, 0, 1) << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int n, k[3], l[8], ans;

void calc(int b[8],int depth){
	if (depth == n) {
		int m[4] = {}, i, mp=0;
		for (i = 0;i < n;i++) {
			if (b[i] != 3 && m[b[i]] != 0) {
				mp += 10;
			}
			m[b[i]] += l[i];
		}
		for (i = 0;i < 3;i++) {
			if (m[i] == 0) {
				return;
			}
			else {
				mp += abs(m[i] - k[i]);
			}
		}
		if (mp < ans) {
			ans = mp;
		}
		return;
	}
	else {
		b[depth] = 0;
		calc(b, depth + 1);
		b[depth] = 1;
		calc(b, depth + 1);
		b[depth] = 2;
		calc(b, depth + 1);
		b[depth] = 3;
		calc(b, depth + 1);

		return;
	}
}

int main(void) {
	int i, j;
	cin >> n;
	cin >> k[0] >> k[1] >> k[2];

	for (i = 0;i < n;i++) {
		cin >> l[i];
	}

	ans = 2000000000;
	int b[8] = {};
	calc(b, 0);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner (System.in);

		boolean inhand[][]= new boolean[4][13];
		for (int i=0; i<4;++i){
			for (int j=0;j<13;++j){
				inhand[i][j] = false;
			}
		}
		int n= sc.nextInt();
		String suit;
		int s=0;
		int rank;

		String suitnum[]={"S","H","C","D"};

		for(int i=0; i<n;++i){
			suit = sc.next();
			if (suit.equals("S")) s = 0;
			if (suit.equals( "H")) s = 1;
			if (suit.equals("C")) s =2;
			if (suit.equals( "D")) s =3;
			rank = sc.nextInt();
			inhand[s][rank-1] = true;
		}
		for (int i=0;i<4;++i){
			for (int j=0;j<13;++j){
				if (inhand[i][j] == false){
					System.out.println(suitnum[i]+" "+(j+1));
				}
			}
		}
	}
}


Measured memory_bytes: 26216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int n, m; cin >> n >> m;
    if(n == 0) break;
    vi a(n);
    for(int i=0;i<n;++i) {
      cin >> a[i];
    }
    int ma = -1;
    for(int i=0;i<n;++i) {
      for(int j=i+1;j<n;++j) {
        if(a[i] + a[j] <= m) ma = max(ma, a[i] + a[j]);
      }
    }
    if(ma == -1) cout << "NONE" << endl;
    else cout << ma << endl;
  }
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N, count = 0;
  string s, t, c, d;
  cin >> N >> s >> t;
  for (int i = 0; i < N; i++)
  {
    c = s.substr(i, N);
    d = t.substr(0, N - i);
    if (c == d)
    {
      count = c.size();
      break;
    }
  }
  cout << 2 * N - count << endl;
  return 0;
}

Measured memory_bytes: 3524
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int d;
int c[27];
int s[366][27];
int calc(vector<int> t){
    int last[26]={};
    vector<int> ret(d);
    int ans=0;
    for(int i=0; i<d; i++){
        ans+=s[i][t[i]];
        last[t[i]]=i+1;
        for(int j=0; j<26; j++){
            ans-=c[j]*(i+1-last[j]);
        }
        ret[i]=ans;
    }
    return ans;
}
mt19937 mt(334);

int main()
{
    cin>>d;
    for(int i=0; i<26; i++) cin>>c[i];
    for(int i=0; i<d; i++) for(int j=0; j<26; j++) cin>>s[i][j];
    vector<int> t(d);
    
    int last[26]={};
    for(int i=0; i<d; i++){
        int kmx=0, mx=-1e9;
        for(int k=0; k<26; k++){
            int sum=s[i][k];
            int myon=last[k];
            last[k]=i+1;
            for(int j=0; j<26; j++){
                sum-=c[j]*(i+1-last[j]);
            }
            last[k]=myon;
            if(mx<sum) kmx=k, mx=sum;
        }
        t[i]=kmx;
        last[kmx]=i+1;
    }

    uniform_int_distribution<> rndk(0, d-1), rndq(0, 25);
    clock_t start = clock();
    int ans=calc(t);
    while((double)(clock()-start)/CLOCKS_PER_SEC<1.9){
        int k, q;
        k=rndk(mt), q=rndq(mt);
        if(t[k]==q){
            continue;
        }
        int pr=t[k], ansp=ans;
        ans-=s[k][pr];
        ans+=s[k][q];
        int last[2]={};
        for(int i=0; i<d; i++){
            if(t[i]==pr) last[0]=i+1;
            else if(t[i]==q) last[1]=i+1;
            ans+=c[pr]*(i+1-last[0]);
            ans+=c[q]*(i+1-last[1]);
        }
        t[k]=q, last[0]=last[1]=0;
        for(int i=0; i<d; i++){
            if(t[i]==pr) last[0]=i+1;
            else if(t[i]==q) last[1]=i+1;
            ans-=c[pr]*(i+1-last[0]);
            ans-=c[q]*(i+1-last[1]);
        }
        if(ansp>ans){
            t[k]=pr;
            ans=ansp;
        }
    }
    for(int i=0; i<d; i++){
        cout<<t[i]+1<<endl;
    }
	return 0;
}


Measured memory_bytes: 3700
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("%s = %d\n", #x, x)
#define debug2(x, y) printf("%s = %d, %s = %d\n", #x, x, #y, y)
#define debug3(x, y, z) printf("%s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z)
#define debug4(x, y, z, t) printf("%s = %d, %s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z, #t, t)
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 200005;

int n, tot, cur, A[MAXN], S[MAXN];

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    for (int i = n - 1; i >= 0; i--) {
        cur = 0;

        for (int j = i; j < n; j += (i + 1)) {
            cur += S[j];
        }

        S[i] = (cur + A[i]) % 2;
        tot += S[i];
    }

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

    for (int i = 0; i < n; i++) {
        if (S[i]) {
            printf("%d ", i + 1);
        }
    }

    printf("\n");

    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define ff first
#define ss second
#define long int64_t
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF<<1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

const int N = 2002;

char a[N][N];
int b[4][N][N];

int main()
{
	fio;
	int h, w;
	cin >> h >> w;
	for(int i=1; i<=h; i++)
		cin >> (a[i]+1);
	for(int i=1; i<=h; i++)
	{
		for(int j=1; j<=w; j++)
		{
			if(a[i][j] == '#')
			{
				b[0][i][j] = j;
				b[1][i][j] = i;
			}
			else
			{
				b[0][i][j] = b[0][i][j-1];
				b[1][i][j] = b[1][i-1][j];
			}
		}
	}
	for(int i=1; i<=h; i++)
		b[2][i][w+1] = w+1;
	for(int i=1; i<=w; i++)
		b[3][h+1][i] = h+1;
	for(int i=h; i; i--)
	{
		for(int j=w; j; j--)
		{
			if(a[i][j] == '#')
			{
				b[2][i][j] = j;
				b[3][i][j] = i;
			}
			else
			{
				b[2][i][j] = b[2][i][j+1];
				b[3][i][j] = b[3][i+1][j];
			}
		}
	}
	int ans = 0;
	for(int i=1; i<=h; i++)
		for(int j=1; j<=w; j++)
			if(a[i][j] != '#')
			ans = max(ans, b[2][i][j] - b[0][i][j] + b[3][i][j] - b[1][i][j] - 3);
	cout << ans << endl;
	return 0;
}

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

#define st              first
#define nd              second
#define pb              push_back
#define lwb             lower_bound
#define upb             upper_bound
#define Size(a)         int((a).size())
#define reset(s, n)     memset(s, n, sizeof(s))
#define bit(n, i)       (((n) >> (i)) & 1)
#define cntbit(n)       __builtin_popcountll(n)
#define all(a)          (a).begin(), (a).end()
#define unique(a)       (a).resize(unique(all(a)) - (a).begin())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))

typedef long double ld;
typedef long long ll;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-7;
inline ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll lcm(ll a, ll b) {return a / __gcd(a, b) * b;}
inline void onbit(ll &a, int i){a |= 1LL << i;}
inline void offbit(ll &a, int i){onbit(a, i), a -= (1LL << i);}

const int N = 3e5 + 5;

ll n, m, k;
ll a[N][3];

void solve(){
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i][1] >> a[i][2];
  }
  for(int i = 2; i < n; i++){
    if(a[i][1] == a[i][2] && a[i - 2][1] == a[i - 2][2] && a[i - 1][1] == a[i - 1][2]){
      cout << "Yes";
      return;
    }
  }
  cout << "No";
}

main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
  cout << fixed << setprecision(10);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int query = 1;
  // cin >> query;
  int start = 1000 * clock() / CLOCKS_PER_SEC;
  while(query--) solve();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC  - start << "ms\n";
}


Measured memory_bytes: 3572
#include <stdio.h>

int main(void){
  int N, K;
  int i, j, k;

  scanf("%d %d", &N, &K);

  if(N%K == 0){
    printf("%d\n", 0);
  }else{
    printf("%d\n", 1);
  }
  return 0;
}


Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            if (a >= b && a >= c)
                out.println(b + c);
            else if (b >= a && b >= c)
                out.println(a + c);
            else
                out.println(a + b);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 21204