akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a_list=list(map(int,input().split()))
a=set(a_list)
if 0 not in a:
  if len(a)!=3:
    print("No")
    exit()
  a=list(a)
  count_a0=a_list.count(a[0])
  count_a1=a_list.count(a[1])
  count_a2=a_list.count(a[2])
  if count_a0!=count_a1 or count_a1!=count_a2 or count_a2!=count_a0:
    print("No")
    exit()
  if a[0]==a[1]^a[2]:
    print("Yes")
  else:
    print("No")
else:
  if len(a)==2:
    a=list(a)
    count_a0=a_list.count(0)
    count_a1=a_list.count(a[0]) if a[0]!=0 else a_list.count(a[1])
    if count_a0*2!=count_a1:
      print("No")
    else:
      print("Yes")
  elif len(a)==1:
    if 0 in a:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Measured memory_bytes: 14212
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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 long long INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    string s[n];
    map<string,int> t;
    set<string> u,v;
    set<string>::iterator itr;
    for(int i = 0; i < n; i++) {
        cin >> s[i];
        v.insert(s[i]);
    }
    for(itr = v.begin(); itr != v.end(); itr++) {
        t[*itr] = 0;
    }
    for(int i = 0; i < n; i++) {
        t[s[i]] += 1;
    }
    
    int max = 0;
    for(int i = 0; i < n; i++) {
        if(max <= t[s[i]]) {
            max = t[s[i]];
        }
    }
    for(int i = 0; i < n; i++) {
        if(max == t[s[i]]){
            u.insert(s[i]);
        }
    }
    for(itr = u.begin(); itr != u.end(); itr++) {
        cout << *itr << endl;
    }
    return 0;
}



Measured memory_bytes: 45568
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct UnionFind {
  const int n;
  V<> t; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  VV<> g(n, V<>(n));
  UnionFind uf(2 * n);
  for (int i = 0; i < n; ++i) {
    string s; cin >> s;
    for (int j = 0; j < n; ++j) if (s[j] == '1') {
      g[i][j] = 1;
      uf.unite(i, n + j);
      uf.unite(n + i, j);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (uf.same(i, n + i)) {
      return cout << -1 << '\n', 0;
    }
  }
  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (i != j and !g[i][j]) {
    g[i][j] = 1e9;
  }
  for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  }
  int mx = 0;
  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
    mx = max(mx, g[i][j]);
  }
  cout << mx + 1 << '\n';
}

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

int main(){
   int n,k,q; cin>>n>>k>>q;
   vector<int> a(q);
   rep(i,q) cin>>a[i];
   vector<int> ans(n);
   rep(i,n) ans[i]=k-q;
   rep(i,q){
      ans[a[i]-1]++;
   }
   int cnt=0;
   rep(i,n){
      if(ans[i]>0) cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
   }
   return 0;
}

   


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

int	main()
{
  int digits = 0;
  int number = 0;
  int cnt = 1;
  
  cin >> digits >> number;
  while ( digits >= number)
  {
    digits = digits / number;
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  ll k;
  cin >> n >> k;
  map<int, ll> mp;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    mp[a] += b;
  }
  for(auto p : mp){
    if(k - p.second > 0){
      k -= p.second;
    }else{
      cout << p.first << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 7524
num_input = input()
list_input = input().split(" ")
N = int(num_input)
count = 0
for i in range(0,N-1):
  check = int(list_input[i])-(i+1)
  if not check == 0:
    count += 1
    if count == 3:
      break

if count == 3:
  print('NO')
else:
  print('YES')


Measured memory_bytes: 3060
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
B=[-i for i in A[::-1]]
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac


MOD = 10**9 + 7
fac, ifac = make_tables(MOD, N)

max_=0
min_=0
for i in range(1,N+1):
    if i >= K:
        max_ = (max_+A[i-1]*cmb(i-1,K-1,MOD,fac,ifac))%MOD
        min_ = (min_+B[i-1]*cmb(i-1,K-1,MOD,fac,ifac))%MOD
print((max_+min_)%MOD)

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

int main(){
  int n;
  cin >>n;
  
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);

  for(int i=0;i<n;i++){
    cin >>a.at(i);
  }
  for(int i=0;i<n;i++){
    cin >>b.at(i);
  }
  for(int i=0;i<n-1;i++){
    cin >>c.at(i);
  }
  
  int sum=0;
  for(int i=0;i<n;i++){
    sum+=b.at(a.at(i)-1);
    //cout<<i<<"ban "<<sum<<endl;
    if(i!=0 && a.at(i)==a.at(i-1)+1){
      sum+=c.at(a.at(i)-2);
     // cout <<"tuika"<<sum<<endl;
    }
  }
  
  cout <<sum<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

//aのb乗
int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N);
	
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	map<int,int> mp;
	
	for(int i=0;i<N;i++){
		map<int,int> temp;
		int X = A[i];
		for(int j=2;j*j<=X;j++){
			while(X%j==0){
				temp[j]++;
				X /= j;
			}
		}
		if(X!=0)temp[X] ++;
		
		for(auto a:temp){
			mp[a.first] = max(mp[a.first],a.second);
		}
	}
	
	int L = 1;
	
	for(auto a:mp){
		L = mod(L * beki(a.first,a.second));
	}
	
	
	int ans = 0;
	
	for(int i=0;i<N;i++){
		ans = mod(ans + mod(L * gyakugen(A[i])));
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <map>
#include <cstdio>
#include <cmath>

using namespace std;

int n,m,k;
map<int,int> mp;
void loop(int sum, int l);

int main(int argc, char const *argv[])
{

	while(1){
		cin>>n>>m>>k;
		if(n+m+k==0) break;

		mp.clear();
		loop(0,1);

		int sum=0;
		for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
			sum+=((*it).first*(*it).second);
		}

		printf("%0.8f\n",sum/pow((double)m,(double)n));


	}
	return 0;
}

void loop(int sum,int l)
{
	for(int i1=1;i1<=m;i1++){
		if(l<n) loop(sum+i1,l+1);
		else {
			int temp=sum+i1-k;
			if(temp<=0) temp=1;
			mp[temp]++;
		}
	}
}

Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
    
int dh[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dw[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

struct Tree {
    int H, W;
    vector<vector<bool>> board;
    vector<vector<bool>> visited;
    vector<vector<int>> edges;
    int nid;

    Tree(int H, int W, vector<string> vs) 
        : H(H), W(W), edges((H + 2) * (W + 2)), visited(H + 2, vector<bool>(W + 2, false)), nid(0) 
    {
        board = vector<vector<bool>>(H + 2, vector<bool>(W + 2, false));
        for(int i = 1; i <= H; i++) {
            for(int j = 1; j <= W; j++) {
                board[i][j] = vs[i - 1][j - 1] == '#';
            }
        }
    }

    bool check_range(int h, int w) {
        return 0 <= h && h < H + 2 &&
               0 <= w && w < W + 2;
    }

    int dfs(int h, int w) {
        const int id = nid++;
        queue<pair<int, int>> que;
        queue<pair<int, int>> nodes;
        int dir = board[h][w] ? 8 : 4;

        que.emplace(h, w);
        visited[h][w] = true;
        while(que.size()) {
            int now_h, now_w;
            tie(now_h, now_w) = que.front();
            que.pop();
            nodes.emplace(now_h, now_w);
            for(int i = 0; i < dir; i++) {
                int nxt_h = now_h + dh[i];
                int nxt_w = now_w + dw[i];
                if(!check_range(nxt_h, nxt_w)) continue;
                if(visited[nxt_h][nxt_w]) continue;
                if(board[nxt_h][nxt_w] != board[now_h][now_w]) continue;
                visited[nxt_h][nxt_w] = true;
                que.emplace(nxt_h, nxt_w);
            }
        }

        while(nodes.size()) {
            int now_h, now_w;
            tie(now_h, now_w) = nodes.front();
            nodes.pop();
            for(int i = 0; i < 4; i++) {
                int nxt_h = now_h + dh[i];
                int nxt_w = now_w + dw[i];
                if(!check_range(nxt_h, nxt_w)) continue;
                if(visited[nxt_h][nxt_w]) continue;
                if(board[nxt_h][nxt_w] == board[now_h][now_w]) continue;
                edges[id].push_back(dfs(nxt_h, nxt_w));
            }
        }

        return id;
    }

    string calc_hash(int id) {
        string ret = "";
        vector<string> vch;
        for(int cid : edges[id]) vch.push_back(calc_hash(cid));
        if(vch.empty()) return "1";
        sort(vch.begin(), vch.end());
        for(auto &&s : vch) ret += move(s);
        return move("(" + ret + ")");
    }

    string solve() {
        dfs(0, 0);
        // for(int i = 0; i < nid; i++) { cout << i << " : { "; for(int ch : edges[i]) cout << ch << ", "; cout << " } \n"; }
        return move(calc_hash(0));
    }
};

string solve(int H, int W) {
    vector<string> vs(H);
    for(auto &s : vs) cin >> s;
    return move(Tree(H, W, vs).solve());
}

bool solve() {
    int H, W;
    cin >> H >> W;
    if(!(H + W)) return false;

    string s1 = solve(H, W);
    cin >> H >> W;
    string s2 = solve(H, W);

    // cout << s1 << ", " << s2 << endl;

    cout << (s1 == s2 ? "yes" : "no") << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}



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

using namespace std;
long long num[1000000],b[1000005];
map <long long,long long> m;
int main()
{
    //freopen("cbarn.out", "w", stdout) ;
    //freopen("cbarn.in", "r", stdin) ;
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(0);
    long long a,sum=0;
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>num[i];
        b[num[i]]++;
    }
    for(int i=1;i<=a;i++)
    {
        m[i]=b[i];
    }
    for(int i=0;i<=a;i++)
        sum+=(m[i]*(m[i]-1))/2;
    for(int i=0;i<a;i++)
    {
        cout<<sum-(m[num[i]]-1)<<"\n";
    }
    return 0;
}


Measured memory_bytes: 19840
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
int N,M,P;
int x[1<<10],y[1<<10];

const int dx[]={0,1,1,1,0,0,-1,-1,-1,1,1,1,0};
const int dy[]={1,1,1,1,1,1,1,1,1,0,0,0,0};
const int dz[]={0,-1,0,1,-1,1,-1,0,1,-1,0,1,1};
int fld[8][8][8];
int Stack[8][8];
inline bool check(int x,int y,int z){
    if(x<0||x>=N)return false;
    if(y<0||y>=N)return false;
    if(z<0||z>=N)return false;
    return true;
}
int counter(int x,int y,int z,int d,int t,int r){
    if(fld[x][y][z]!=t)return 0;
    int tx=x+dx[d]*r,ty=y+dy[d]*r,tz=z+dz[d]*r;
    int ret=0;
    if(check(tx,ty,tz))ret+=counter(tx,ty,tz,d,t,r);
    return ret+1;
}
void solve(){
    for(int i=0;i<P;i++){
        int pos=Stack[x[i]][y[i]]++;
        fld[x[i]][y[i]][pos]=i&1;

        for(int k=0;k<13;k++){
            int cnt=0;
            cnt+=counter(x[i],y[i],pos,k,i&1,1);
            cnt+=counter(x[i],y[i],pos,k,i&1,-1);
            if(cnt-1>=M){
                if(i&1)printf("White %d\n",i+1);
                else printf("Black %d\n",i+1);
                return;
            }
        }
    }
    puts("Draw");
}
int main(){
    while(scanf("%d%d%d",&N,&M,&P),N||M||P){
        for(int i=0;i<P;i++){
            scanf("%d%d",&x[i],&y[i]);
            x[i]--;y[i]--;
        }
        fill_n(**fld,8*8*8,-1);
        fill_n(*Stack,8*8,0);
        solve();
    }
}

Measured memory_bytes: 1048
import java.util.*;
import java.util.stream.Collectors;

public class Main{

    public static void main(String[] args) {

        Scanner in =new Scanner(System.in);
        int n = in.nextInt();
        in.nextLine();
        
        Restrant[] rest=new Restrant[n];
        Restrantrating rating=new Restrantrating();

        for(int i=0;i<n;i++)
		{   
			rest[i]=new Restrant(i+1,in.next(),in.nextInt());
        }
        
        Arrays.sort(rest,rating);

        for(int i=0;i<n;i++)
		{   
            System.out.println(rest[i].num);
        }
    }
    
}

class Restrant{
    int num;
    String city;
    int score;

    Restrant(int num,String city, int score){
        this.num=num;
        this.city=city;
        this.score=score;
    }
}

class Restrantrating implements Comparator<Restrant>{
    
    public int compare(Restrant a, Restrant b){
        if( !(a.city.equals(b.city)) ){
            return a.city.compareTo(b.city);
        }
        else return b.score-a.score;
    }

}



Measured memory_bytes: 23764
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   unik(v)       v.erase(unique(all(v)),v.end())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
void solve()
{
    ll a;
    cin>>a;
    cout << (a+(a*a) + (a*a*a))<<"\n";
}
int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int n = s.length();
		boolean[] vis = new boolean[n + 1];
		vis[0] = true;
		for (int i = 0; i < n; ++i) {
			if (!vis[i])
				continue;
			if (i + 5 <= n) {
				String s5 = s.substring(i, i + 5);
				if (s5.equals("dream") || s5.equals("erase")) {
					vis[i + 5] = true;
				}
			}
			if (i + 6 <= n) {
				String s6 = s.substring(i, i + 6);
				if (s6.equals("eraser")) {
					vis[i + 6] = true;
				}
			}
			if (i + 7 <= n) {
				String s7 = s.substring(i, i + 7);
				if (s7.equals("dreamer")) {
					vis[i + 7] = true;
				}
			}
		}
		if (vis[n]) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 18348
#include<stdio.h>
int main()
{
  int a,b;
  scanf("%d %d",&a,&b);
  if(a<b){
    printf("a < b\n");
  }
  else if(a>b){
    printf("a > b\n");
  }
  else if(a==b){
    printf("a == b\n");
  }
  return 0;
}



Measured memory_bytes: 2076
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
#define pii pair<int,int>
#define pqi priority_queue<int>
#define pb push_back()
#define INF 1000000000000000000
#define pi acos(-1)
#define deb(x) cout<<#x" = "<<x<<" "
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
const int modu=1e9+7;
 
int bigmod(int n,int p){
    if(p==0) return 1;
    int x=bigmod(n,p/2)%modu;
    x=(x*x)%modu;
    if(p%2) return (x*n)%modu;
    return x;
}
 
int modInverse(int a){
    return bigmod(a,modu-2)%modu;
}
 
void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
}
 
void defInit(){
    faster();
    #ifdef OFFLINE
      auto dummy_in=freopen("in.txt", "r", stdin);
      auto dummy_out=freopen("out.txt", "w", stdout);
      if(0) dummy_in=dummy_out;
      else dummy_out=dummy_in;
    #endif
}

int add(int x,int y){
    int z =(x%modu + y%modu)%modu;
    while(z<0) z=(z+modu)%modu;
    return z;
}
 
int mul(int x,int y){
    int z = (x%modu * y%modu)%modu;
    while(z<0) z=(z+modu)%modu;
    return z;
}
// starts here

const int MAXN = 2*(1e5);

int ncr(int n,int r){
    int x=1;
    for(int i=n;i>n-r;i--){
        x=mul(x,i);
    }
    int y=1;
    for(int i=1;i<=r;i++){
        y=mul(y,i);
    }
    return mul( x , modInverse(y) );
}

int32_t main(){
    faster();
    //Now I will start writing codes and start preparation to get errors
 	int n,a,b;
    cin>>n>>a>>b;
    int ans=bigmod(2LL,n)-1;
    int nca=ncr(n,a);
    int ncb=ncr(n,b);
    ans=add(ans,-add(nca,ncb));
    cout<<ans;
    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int MaxN = 2e5;
int n, a[MaxN + 5];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	if (n & 1) {
		for (int i = n; i >= 1; i -= 2) printf("%d ", a[i]);
		for (int i = 2; i <= n - 1; i += 2) printf("%d ", a[i]);
		printf("\n");
	}
	else {
		for (int i = n; i >= 2; i -= 2) printf("%d ", a[i]);
		for (int i = 1; i <= n - 1; i += 2) printf("%d ", a[i]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s, n) for(int i = s; i < (int)(n); i++)
#define co(x) cout<<x<<endl
#define SQvec(i,j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000000+7
typedef long long int lint;

int main() {
  lint N,M,cnt,S;
  cin >> N;
  M = N;
  while(N / 10 != 0){
    S += (N % 10);
    N /= 10;
  }
  S += N;
  if(M%S == 0){co("Yes");}
  else{co("No");}
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]))
print(dp[n - 1])

Measured memory_bytes: 13928
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int a[3];
	for(int i=0;i<3;i++)
		scanf("%d",&a[i]);
	sort(a,a+3,cmp);
	int ans=0;
	ans=a[0]*10+a[1]+a[2];
	printf("%d\n",ans);	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define For(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
// const ll MOD=1000000007ll;
const ll MOD=998244353ll;
const int MAX=510000;

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

    int anscnt = 0;

    for(int i = 1; i <= n; i += 2){
        int cnt = 0;
        for(int j = 1; j <= i; j++){
            if(i%j == 0) cnt++;
        }

        if(cnt == 8) anscnt++;
    }

    cout << anscnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    LL K,A,B;
    cin >> K >> A >> B;
    LL ans = 1;
    int coin = 0;

    REP(i,K)
    {
        if(i != K-1)
        {
            if(B-A >= 3) //交換したほうが得
            {
                if(coin == 1)
                {
                    ans += B;
                    coin--;
                }
                else
                {
                    if(ans >= A)
                    {
                        coin++;
                        ans -= A;
                    }
                    else
                    {
                        ans++;
                    }
                }
            }
            else
            {
                ans++;
            }

        }
        else
        {
            if(coin == 1)
            {
                ans += B;
                coin--;
            }
            else
            {
                ans++;
            }
        }
        dump(ans)
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] Hi = new int[N];
   for(int i =0;i<N;i++)
   {
   Hi[i] = sc.nextInt();
   }
   int outcount=0;
   for(int k=0;k<N-1;k++)
   {
    if( Hi[k] < Hi[k+1] )
    {
    outcount=0;
    }
    else if (Hi[k] == Hi[k+1]){}
    else
    {
    if(Hi[k] == Hi[k+1]+1) outcount++;
    else outcount=2;
    }
    
    if(outcount==2) break;
   }
    if(outcount==2) System.out.println("No");
    else System.out.println("Yes");
 }
}

Measured memory_bytes: 50200
#include<stdio.h>

int m,n,k;

bool slove()
{
    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= m; j++)
        {
            int tmp = i * m + n * j - 2 * i * j;
            if(tmp == k)
                return true;
        }
    return false;
}

int main()
{
    while(scanf("%d%d%d",&m,&n,&k) == 3)
    {
        if(slove()) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


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

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

    int n; cin >> n;
    int h[n+1];
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    int c[n+1];
    c[1] = 0;
    c[2] = abs(h[1] - h[2]);
    for (int i = 3; i <= n; i++) {
        c[i] = min(c[i-1] + abs(h[i-1] - h[i]), c[i-2] + abs(h[i-2] - h[i]));
    }
    cout << c[n];

    return 0;
}

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

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      long[] sum = new long[n];
      sum[0] = sc.nextInt();
      for(int i = 1; i < n; i++) {
        sum[i] = (sum[i-1] + (sc.nextInt() % m)) % m;
      }

      Map<Integer, Long> cntMap = new HashMap<>();
      for(int i = 0; i < n; i++) {
        int remainder = (int)(sum[i] % m);
        cntMap.put(remainder, cntMap.getOrDefault(remainder, 0L) + 1);
      }
      long cnt = cntMap.getOrDefault(0,0L);
      for(Map.Entry<Integer, Long> entry : cntMap.entrySet()) {
        if(entry.getValue() < 2) continue;
        cnt += comb(entry.getValue());
      }
        
      System.out.println(cnt);
  }

  private static long comb(long n) {
      if(n % 2 == 0)
        return n / 2 * (n - 1);
      else
        return (n - 1) / 2 * n;
  }
}

Measured memory_bytes: 57312
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << "(" << v.first << ", " << v.second << ")";
    return ostr;
}

vector<string> split(const string &s, char delim) {
    vector<string> result;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
        if (!item.empty()) {
            result.push_back(item);
        }
    }
    return result;
}

#define M map<int64, int64>
M f(int64 n) {
    M m;

    while (n % 2 == 0) {
        m[2]++;
        n = n / 2;
    }

    int64 c = 3;
    while (c * c <= n) {
        if (n % c == 0) {
            n = n / c;
            m[c]++;
        } else {
            c += 2;
        }
    }
    if (n != 1) m[n]++;
    return m;
}

int main() {
    int64 a, b; cin >> a >> b;

    M a2 = f(a);
    M b2 = f(b);
    a2[1] = 1;
    b2[1] = 1;

    int ans = 0;
    for (auto v : a2) {
        if (b2[v.first] != 0) {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string S, T;
    cin >> S >> T;
    cout << T + S << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	n, m := sc.getInt2()
	ps := make([]int, n)
	for i := range ps {
		ps[i] = sc.getInt() - 1
	}

	uf := newUnionFind(n)
	for i := 0; i < m; i++ {
		x, y := sc.getInt()-1, sc.getInt()-1
		uf.unite(x, y)
	}

	ans := 0
	for i, p := range ps {
		if uf.same(i, p) {
			ans++
		}
	}
	fmt.Fprintln(wr, ans)
}

// union-find tree
type unionFind struct {
	pars []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.pars = make([]int, n)
	for i := range uf.pars {
		uf.pars[i] = -1
	}
	return uf
}

func (uf *unionFind) root(x int) int {
	if uf.pars[x] < 0 {
		return x
	}
	uf.pars[x] = uf.root(uf.pars[x])
	return uf.pars[x]
}

func (uf *unionFind) unite(_x, _y int) {
	x, y := uf.root(_x), uf.root(_y)
	if x == y {
		return
	}

	if uf.size(x) < uf.size(y) {
		x, y = y, x
	}
	uf.pars[x] += uf.pars[y]
	uf.pars[y] = x
}

func (uf *unionFind) same(x, y int) bool {
	return uf.root(x) == uf.root(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.pars[uf.root(x)]
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)
vector<long> DP, S;

int main() {
    int N, K;
    cin>>N >> K;
    DP.resize(N+1, __INT_MAX__); S.resize(N+1);
    REP(i, 1, N+1){
        cin >> S[i];
    }
    DP[1] = 0;
    REP(i, 2, N+1){
        REP(j, 1, K+1){       
            if(i-j >= 0){ 
                DP[i] = min(DP[i], DP[i-j]+abs(S[i]-S[i-j]));
            }
        }
    }
    cout << DP[N] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, c, k;
  cin >> n >> c >> k;
  vector<int> t(n);
  rep(i, 0, n) cin >> t[i];
  sort(t.begin(), t.end());

  int first = t[0], count = 1, ans = 1;
  rep(i, 1, n) {
    if (t[i] - first > k || count == c) {
      first = t[i];
      ans++;
      count = 1;
    } else {
      count++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
  int a,b;
  char op;
  while(1) {
    scanf("%d %c %d", &a, &op, &b);
    if(op=='?')
    	break;
    else if(op== '+') 
    	printf("%d\n",a+b);
    else if(op== '-') 
    	printf("%d\n",a-b);
    else if(op== '*') 
    	printf("%d\n",a*b);
    else if(op== '/') 
    	printf("%d\n",a/b);
    }
  return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
vector<string>vs;
string s;
int main(){
    int n,l,i;
    scanf("%d%d",&n,&l);
    for(i=0;i<n;i++){
        cin>>s;
        if(s.length()==l)vs.push_back(s);
    }
    sort(vs.begin(),vs.end());
    for(i=0;i<vs.size();i++)cout<<vs[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.State

main = do
        [n, q] <- map read.words<$>getLine
        pstrs  <- replicateM n getLine
        let procs = setProcess pstrs
        simulateProcess q procs

simulateProcess :: Int -> Queue Process -> IO ()
simulateProcess q = evalStateT (evalStateT (roundRobin q) 0)

type Queue a = ([a],[a])

enQueue :: Monad m => a -> StateT (Queue a) m ()
enQueue x = get >>= \(as,xs) -> put ((as, x:xs))

deQueue :: Monad m => StateT (Queue a) m a
deQueue = do
        (as, xs) <- get
        if null as then do
                       let xs' = reverse xs
                       put (tail xs', [])
                       return $ head xs'
                   else do
                       put (tail as, xs)
                       return $ head as

isEmpty :: Monad m => StateT (Queue a) m Bool
isEmpty = do
        (as,xs) <- get
        return $ null as && null xs


data Process = P { name :: String
                 , time :: Int } deriving (Show)

process :: [String] -> Process
process [x,y] = P x (read y)

setProcess :: [String] -> Queue Process
setProcess pstrings = execState action ([],[])
        where ps = map (process.words) $ pstrings
              action = sequence_ $ map enQueue ps

roundRobin :: Int -> StateT Int (StateT (Queue Process) IO) ()
roundRobin q = do
        t <- get
        p <- lift deQueue
        runProcess q p t
        emptyCheck
        where emptyCheck = do
                empty <- lift isEmpty
                if empty then return ()
                         else roundRobin q

runProcess :: Int -> Process -> Int -> StateT Int (StateT (Queue Process) IO) ()
runProcess q p t
    | q >= time p = do
        liftIO (putStrLn $ unwords [name p, show (t+time p)])
        modify (+ time p)
    | otherwise   = do
        let p' = p {time = time p - q}
        modify (+ q)
        lift $ enQueue p'

Measured memory_bytes: 49236
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>



int main(){
	char s[100];
	int flag = 1;
	int flag1 = 0;
	scanf("%s",s);
	int num = strlen(s);
	for(int i=0;i<100;i++){
		if(s[i]<'A'||s[i]>'z')break;
		if(i==0){
			if(s[i]!='A'){
			flag=0;
			break;
			}
		}
		else if(s[i]<'a'){
			if(i>=2&&i<=num-2){
				if(s[i]=='C'){
					if(flag1==0){
						flag1=1;
					}
					else{
						flag=0;
					}
				}
				else{
					flag=0;
				}
			}
			else{
				flag=0;
				break;
			}
		}
	}
	if(flag1==0)flag=0;
	printf(flag==0?"WA":"AC");
	
	return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

int main()
{
    ll n;
    cin >> n;
    vll b(n-1);
    rep(i,n-1)cin >> b[i];
    ll ans = b[0] + b[n-2];
    REP(i,1,n-1)ans += min(b[i-1],b[i]);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
#define lchild v<<1,l,m
#define rchild v<<1|1,m+1,r
const int N =5e5+9;
struct node {
    ll val;
    node operator + (const node &a) const {
        node c;
        c.val = val + a.val;
        return c;
    }
} st[N*4];
ll A[N];
int last[N];

struct Data {
    int l, r, id;
    ll res;
    bool operator < (const Data& other) {
        if(r==other.r) return l<other.l;
        return r<other.r;
    }
} Q[N];

inline void pushup(int v) {
    st[v].val = st[v*2].val + st[v*2+1].val;
}

void update(int v, int l, int r, int i, ll x) {
    if(l==r) {
        st[v].val = x;
        return;
    }
    int m = (l+r)/2;
    if(i<=m) update(lchild, i, x);
    else update(rchild, i, x);
    pushup(v);
}
node query(int v, int l, int r, int i, int j) {
    if(l>=i && r<=j) return st[v];
    int m = (l+r)/2;
    if(j<=m) return query(lchild, i, j);
    else if(i>m) return query(rchild, i, j);
    else {
        node a = query(lchild, i, m);
        node b = query(rchild, m+1, j);
        return a+b;
    }
}

void dbgst(int v, int l, int r) {
    cerr<<v<<" ("<<l<<" "<<r<<") -> "<<st[v].val<<" "<<endl;
    if(l==r) return;
    int m = (l+r)/2;
    dbgst(v*2,l,m);
    dbgst(v*2+1,m+1,r);
}


int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n,m;
    cin>>n>>m;
    for(int i=1;i<=n;++i) cin>>A[i];
    for(int i=1;i<=m;++i) {
        cin>>Q[i].l>>Q[i].r;
        Q[i].id = i;
    }
    sort(Q+1, Q+m+1);
    // for(int i=1;i<=m;++i) {
    //     cout<<Q[i].l<<" "<<Q[i].r<<endl;
    // }

    for(int i=1, j=1;i<=n;++i) {
        if(last[A[i]]) update(1,1,n, last[A[i]], 0);
        update(1,1,n, i, 1);
        last[A[i]] = i;
        while(j<=m && Q[j].r==i) {
            Q[Q[j].id].res = query(1,1,n, Q[j].l, Q[j].r).val;
            // cout<<" "<<Q[Q[j].id].res<<endl;
            j++;
        }
    }

    for(int i=1;i<=m;++i) {
        cout<<Q[i].res<<endl;
    }
    // dbgst(1,1,n);
    return 0;
}

Measured memory_bytes: 29588
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll a, b, ans = 0;
int main() {
	cin >> a >> b;
	FOR(i, a, (a + 4) / 4 * 4) {
		ans ^= i;
	}
	FOR(i, 4 * (b / 4), b + 1) {
		ans ^= i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
def b j,k,l
k.any?{m,*n=k.rotate!
o=m.index j[l].swapcase
o&&([*0..5]-[o,5-o]).any?{|p|yield m,n,o,p}}end
def e a,b
a==b.swapcase
end
y=(0..5).map{[]}
(a=[*1..4,2,4,1,3]).zip(a.rotate(4),[0]*4+[5]*4).map{|b|b.map{i,j,k=b=b.rotate;y[i][j]=k}}
while gets[0]>?0
z=$<.take(7)<<$_
puts z.any?{a,*o=z.rotate!
(0..5).any?{|c|
b(a,o,c){|d,o,f,i|
b(d,o,i){|g,o,tt,j|
b(g,o,j){|p,o,r,k|
([*0..5]-[c,5-c]).any?{|l|
e(p[k],a[l])&&b(a,o,y[l][c]){|s,o,u,m|
b(s,o,m){|v,o,x,n|
e(d[y[f][i]],v[n])&&b(v,o,y[x][n]){|h,o,cc,q|
e(h[q],g[y[tt][j]])&&b(h,o,y[cc][q]){|w,_,o,t|
e(w[t],p[y[r][k]])&&e(w[y[o][t]],s[y[u][m]])}}}}}}}}}}?:YES:"NO"end

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
const long long INF = 1e18;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int num, cap;
    cin >> num >> cap;
    vector<pair<int, int>> items(num);
    long long sum = 0;
    for(int i = 0; i < num; i++) {
        int a, b;
        cin >> a >> b;
        items[i] = {a, b};
        sum += b;
    }
    vector<long long> dp(sum + 1, INF);
    dp[0] = 0;
    for(int i = 0; i < num; i++) {
        for(int j = sum - items[i].s; j >= 0; j--) {
            dp[j + items[i].s] = min(dp[j + items[i].s], dp[j] + items[i].f);
        }
    }
    int ans = 0;
    for(int i = 0; i <= sum; i++) {
        if(dp[i] <= cap) {
            ans = (long long) i;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3988
#include <iostream>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define MAX_N 101
#define MAX_M 101
using namespace std;
int N, s;
int subaverage(int sum[]){
  int average = 0;
  for(int i = 1; i < N - 1; i++){
    average += sum[i];
  }
  average = average / (N - 2);
  return average;
}
int main(){
while(true){
  cin >> N;
  int sum[N];
  if(N == 0){
    break;
  }
  for(int i = 0; i < N; i++){
    cin >> s;
    sum[i] = s;
  }
  sort(sum, sum + N);
  cout << subaverage(sum) << endl;
}
  return 0;
}



Measured memory_bytes: 3060