akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int test(int M, int K) {
  int arr[SIZE];

  int N = 1 << M;

  for (int i=0; i<N; i++)
    arr[i*2] = arr[i*2+1] = i;

  bool res = false;

  do{
    bool ok = true;

    for (int i=0; i<N*2; i++) {
      ll sum = 0;
      for (int j=i+1; j<N*2; j++) {
        if (arr[i] == arr[j]) {
          ok &= sum == K;
        }
        sum ^= arr[j];
      }
    }

    if (ok) {
      for (int i=0; i<N*2; i++)
        cerr << arr[i] << ", ";
      cerr << endl;
      return true;
    }

    res |= ok;

  }while(next_permutation(arr, arr+2*N));

  return res;
}

int main() {
  int M, K;

  cin >> M >> K;

  int N = 1 << M;

  if (K >= N || (M == 1 && K > 0)) {
    puts("-1");
    return 0;
  }

  if (K == 0) {
    for (int i=0; i<N; i++) {
      printf("%d %d%c", i, i, " \n"[i+1==N]);
    }
    return 0;
  }

  vector<int> ans;

  ans.push_back(K);

  for (int i=0; i<N; i++)
    if (i != K)
      ans.push_back(i);

  ans.push_back(K);

  for (int i=N-1; i>=0; i--)
    if (i != K)
      ans.push_back(i);

  for (int i=0; i<N*2; i++)
    printf("%d%c", ans[i], " \n"[i == N*2-1]);

#ifdef LOCAL
  bool ok = true;

  for (int i=0; i<N*2; i++) {
    ll sum = 0;
    for (int j=i+1; j<N*2; j++) {
      if (ans[i] == ans[j]) {
        ok &= sum == K;
      }
      sum ^= ans[j];
    }
  }

  cerr << (ok ? "OK!" : "WA...") << endl;
#endif

  return 0;
}


Measured memory_bytes: 2932
import java.util.PriorityQueue;

public class Main {
  private static void solve() {
    int n = ni();
    int k = ni();
    int[] v = na(n);
    int ret = 0;
    for (int i = 0; i <= Math.min(k, n); i ++) {
      for (int j = 0; j <= i; j ++) {
        PriorityQueue<Integer> q = new PriorityQueue<>();
        for (int s = 0; s < j; s ++) {
          q.add(v[s]);
        }
        for (int s = n - 1; s >= n - (i - j); s --) {
          q.add(v[s]);
        }

        int now = 0;
        for (int x : q) {
          now += x;
        }
        ret = Math.max(ret, now);
        for (int s = 0; s < (k - i) && q.size() > 0; s ++) {
          now -= q.poll();
          ret = Math.max(ret, now);
        }
      }
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 24788
#include <bits/stdc++.h>
using namespace std;
int f[100000];
int cx[100][100][100];
int main()
{
    int x,y,s;
    for(int i=1; i<=100; i++)
        for(int j=1; j<=100; j++)
            for(int k=1; k<=100; k++)
            {
                if(cx[i][j][k]==0)
                {
                    s=(i+j)*(i+j)+(i+k)*(i+k)+(k+j)*(k+j);
                    if(s%2==0)
                        f[s/2]++;
                }
            }
            int n;
            cin>>n;
   for(int i=1;i<=n;i++)
    printf("%d\n",f[i]);
}


Measured memory_bytes: 3924
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fi first
#define se second
using ll=long long int;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
	ll n;
	cin>>n;
	vector<ll>a(n),b(n);
	rep(i,n)cin>>a[i];
	rep(i,n)b[i]=a[i];
	sort(b.begin(),b.end());
	bool j=false;
	if(b[n-1]==b[n-2])j=true;
	for(int i=0;i<n;++i){
		if(j){
			cout<<b[n-1]<<endl;
		}
		else{
			if(a[i]!=b[n-1])cout<<b[n-1]<<endl;
			else cout<<b[n-2]<<endl;
		}
	}
		return 0;
}




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

int main() {
	int n, sum, sum1, x[105];
	double p;
	while (cin >> n) {
		sum = 0;
		sum1 = 0;
		for (int i = 0; i < n; i++) {
			cin >> x[i];
			sum += x[i] * x[i];
			sum1 += x[i];
		}
		p = (int)(sum1 * 1.0 / n + 0.5);
		sum += p * p * n - 2 * p * sum1;
		cout << sum << endl;
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int a = Integer.parseInt(st[0]);
        int b = Integer.parseInt(st[1]);
        bw.append(gcd(a, b) + "\n");
        bw.flush();
    }

    static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }


}


Measured memory_bytes: 24368
#include<stdio.h>
int main(void){
int a=100000;
int i,n;
scanf("%d",&n);
for(i=0;i<n;i++){
    a=a+a*0.05;
    if(a%1000!=0){
    a=a/1000;
    a=a*1000;
    a=a+1000;
    }

}
 printf("%d\n",a);









return 0;
}

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

int main() {
  char c;
  cin >> c;
  if(c == 'a' || c == 'e' ||c == 'i' || c=='o' || c== 'u'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
_=int(input())
hs = [int(x) for x in input().split()][::-1]
cannot = False


for i in range(len(hs)-1):
    if hs[i]<hs[i+1]:
        hs[i+1]-=1
    if hs[i]<hs[i+1]:
        cannot=True
        break
print("No" if cannot else "Yes")
    

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
ll int large=(ll int)1e13+7;
ll int mod=(ll int)1e5;
ll int const N=(ll int)1e5+10;

ll int mod_exp(ll int x,ll int n)
{
    ll int result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n=n/2;
    }
    return result;
}

ll int mod_inverse(ll int a)
{
    return mod_exp(a,mod-2);
}




int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll int T,i,j,ij;
T=1;
//cin>>T;
while(T--)
{
  ll int n;
  cin>>n;
  cout<<(n%1000==0? 0: 1000-(n%1000));


}
return 0;
}
















Measured memory_bytes: 3636
# frozen_string_literal: true

N = gets.chomp.to_i
X = gets.chomp
X_NUM = X.to_i(2)

# bit数え上げ
def popcount(x)
  x.to_s(2).count('1')
end

def f(x)
  return 1 if x == 0
  x = x % popcount(x)
  1 + f(x)
end

# 操作
def func
  default = X.count('1')
  high = default + 1
  low = default - 1
  x_mod_high = X_NUM % high
  low = 1 if default == 1
  x_mod_low = X_NUM % low

  N.times do |i|
    i = N - i
    x = 0
    if X[-i] == '0'
      x = x_mod_high + 2.pow(i - 1, high)
      x = x % high
    elsif default == 1
      puts 0
      next
    elsif X[-i] == '1'
      x = x_mod_low - 2.pow(i - 1, low)
      x = x % low
    end
    puts f(x)
  end
end

func


Measured memory_bytes: 14728
#include<iostream>
#include<string>

using namespace std;

int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; ++i) {
		bool carry = false;
		string first, second;
		cin >> first >> second;

		string sum;

		auto it1 = first.rbegin();
		auto it2 = second.rbegin();
		while (it1 != first.rend() || it2 != second.rend()) {

			int temp1 = (it1 != first.rend()) ? (*it1++) - '0' : 0;
			int temp2 = (it2 != second.rend()) ? (*it2++) - '0' : 0;
			int temp_sum = temp1 + temp2 + (carry ? 1 : 0);
			if (temp_sum / 10 != 0) {
				carry = true;
				temp_sum %= 10;
			}
			else {
				carry = false;
			}

			sum.insert(0, to_string(temp_sum));
		}
		if (carry == true) {
			sum.insert(0, 1, '1');
		}

		if (first.length() > 80 || second.length() > 80 || sum.length() > 80) {
			cout << "overflow" << endl;
		}
		else {
			cout << sum << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 1248
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n;
long long B,A,h[110000],l,r,m;
priority_queue<long long> q;
bool vic(long long x){
	long long tt=0;
	fo(i,1,n){
		long long hh=h[i]-x*B;
		if (hh>0) tt+=(hh-1)/A+1;
		if (tt>x) return 0;
	}
	return 1;
}
int main(){
	scanf("%d%lld%lld",&n,&A,&B);A-=B;
	fo(i,1,n) scanf("%lld",&h[i]);
	l=1;r=1e9;
	while (l<r){
		m=(l+r)>>1;
		if (vic(m)) r=m;else l=m+1;
	}
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        long suma = 0;
        long sumb = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            suma += a[i];
        }

        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
            sumb += b[i];
        }

        long limit = Math.max(sumb - suma, 0);

        long cnt1 = 0;
        long cnt2 = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] > b[i]) {
                cnt1 += a[i] - b[i];
            } else if (a[i] < b[i]) {
                cnt2 += (b[i] - a[i] + 1) / 2;
            }
        }

        System.out.println(((cnt1 <= limit) && (cnt2 <= limit)) ? "Yes" : "No");
    }

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


Measured memory_bytes: 43708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static string Solve(string S, int K)
        {
            int N = S.Length;
            var s = S.ToCharArray();
            for (int i = 0; i < N - 1; ++i)
            {
                int k = 'z' - s[i] + 1;
                if (s[i] != 'a' && K >= k)
                {
                    s[i] = 'a';
                    K -= k;
                }
            }
            s[N - 1] = (char)((s[N - 1] - 'a' + K) % 26 + 'a');
            return new string(s);
        }
        static void Main(string[] args)
        {
            string S = Read();
            int K = ReadInt();
            Console.WriteLine(Solve(S, K));
        }
    }
}


Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

struct Edge{
    // 始点, 終点, 重み, 最大量
    long long src, dst, weight, capacity;
    Edge(): src(0), dst(0), weight(0), capacity(0) {}
    Edge(long long s, long long d, long long w): src(s), dst(d), weight(w) {}
    Edge(long long s, long long d, long long w, long long c): src(s), dst(d), weight(w), capacity(c) {}
};

class Graph{
public:
    long long size;
    vector<vector<Edge>> node;
    Graph(long long n): size(n), node(n) {}
    // 無向辺の追加
    void addEdge(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
        node[d].emplace_back(d, s, w);
    }
    // 有向辺の追加
    void addArc(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
    }
    // ノードの追加
    void addNode(){
        size++;
        node.emplace_back();
    }
};

// Dijkstra(Heap); 単一始点最短路（優先度付きキューを利用したダイクストラ法）
// ：負辺がある場合はループにハマる可能性があるため、Bellman-Fordを使うこと。[O((E+V)logV)]
vector<long long> Dijkstra(const Graph &g, long long src){
    const long long WeightINF = numeric_limits<long long>::max()/2-1;
    using state = pair<long long, long long>;
    priority_queue<state> que;
    vector<long long> d(g.size, WeightINF);
    d[src] = 0;
    que.emplace(0, src);
    while(!que.empty()){
        auto p = que.top(); que.pop();
        long long w = -p.first;
        long long v = p.second;
        if(d[v] < w) continue;
        for(const auto &edge: g.node[v]){
            if(d[edge.dst] > d[v] + edge.weight){
                d[edge.dst] = d[v] + edge.weight;
                que.emplace(-d[edge.dst], edge.dst);
            }
        }
    }
    return d;
}

int main(){
    Init();
    ll n; cin >> n;
    Graph g(n);
    rep(i, n-1){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g.addEdge(a, b);
    }

    auto dij1 = Dijkstra(g, 0);
    auto dij2 = Dijkstra(g, n-1);
    map<string, ll> cnt;
    rep(i, n) (dij1[i] <= dij2[i]) ? cnt["Fennec"]++ : cnt["Snuke"]++;
    if(cnt["Fennec"] > cnt["Snuke"]) cout << "Fennec" << endl;
    else if(cnt["Fennec"] <= cnt["Snuke"]) cout << "Snuke" << endl;
}

Measured memory_bytes: 16188
n = int(input())
ans=0
def dfs(A):
    global ans
    
    if A and int(''.join(A)) > n:
        return
    # 七五三がすべてつかわれているか?
    if not (set(A) ^ set('357')):
        ans+=1
    for v in '357':
        A.append(v)
        dfs(A)
        A.pop()
dfs([])
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define z 100
using namespace std;
int n,a,b,q[z],l[z],la,be,an,ct[z],c[z][z];bool v[z],s[z];void d(int x,int len){if(len>be){la=x;be=len;}v[x]=1,s[x]=1;for(int i=0;i<ct[x];i++)if(!v[c[x][i]]){d(c[x][i],len+1);v[c[x][i]]=0;}}int main(){while(1){cin>>n;if(!n)break;r(i,z)ct[i]=0;r(i,n){cin>>a>>b;a--,b--;c[a][ct[a]]=b,c[b][ct[b]]=a;ct[a]++,ct[b]++;}r(i,z)s[i]=0;an=0;for(int i=0;i<z;i++)if(!s[i]){r(i,z)v[i]=0;be=0;d(i,1);r(i,z)v[i]=0;be=0;d(la,1);an=max(an,be);}cout<<an<<endl;}return 0;}

Measured memory_bytes: 3048
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
//最大公約数
template<typename T>
constexpr T gcd(T a, T b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

//最小公倍数
template<typename T>
constexpr T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) PRIY;
	else PRIN;
	return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <deque>
using namespace std;

const int MAX_N = 200005;

deque<int> q;

char S[MAX_N];

int main() {
  int N, K;
  
  scanf("%d%d", &N, &K);
  scanf("%s", S + 1);

  for (int i = 1; i <= N; ++i) 
    q.push_back(S[i] == 'A' ? 1 : 0);

  int rev = 0, l = 0;
  while (K > 0) {
    K--;
    if (q[0] ^ rev == 1) {
      q[0] = rev;
    } else {
      q.pop_front();
      q.push_back(rev);
      rev ^= 1, l++;
      if (l == N) break;
    }
  }

  K %= 2 * N;

  for (int i = 1; i <= K; ++i) {
    if (q[0] ^ rev == 1) {
      q[0] = rev;
    } else {
      q.pop_front();
      q.push_back(rev);
      rev ^= 1, l++;
    }    
  }

  for (int i = 0; i < q.size(); ++i)
    putchar((q[i] ^ rev) == 1 ? 'A' : 'B');
  puts("");
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//int cnt[100];
//int cnt1[100];
int main () {
//ll t; cin>>t; while(t--)
ll a,b,c,d,e,f,g,h,x,y,z; cin>>a>>b>>c>>d;
e=a*c;
f=a*d;
x=max(e,f);
g=b*c;
h=b*d;
y=max(g,h);
z=max(x,y);
cout<<z<<endl;
return 0;
}


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

using namespace std;

int N, a[3017];
bool dp[3017];
vector < int > v[3017];

void solve (int nod, int tata)
{
    dp[nod] = 0;
    for (auto it : v[nod])
        if (it != tata)
        {
            solve (it, nod);
            if (dp[it] == 0 && a[it] < a[nod])
                dp[nod] = 1;
        }
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    v[x].push_back (y);
    v[y].push_back (x);
}
for (int i=1; i<=N; i++)
{
    solve (i, -1);
    if (dp[i])
        printf ("%d ", i);
}
printf ("\n");

return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,n,d,tmp = 0,cnt,sum = 0,i,j,a,b,c,mx = LLONG_MIN,mn = LLONG_MAX;

    string str,str1;
    map<int,int>mp;
    vector<int>v;
    set<string>s;
    cin>>n;
    for(i = 0;i < n;i++)
    {
        cin>>str;
        s.insert(str);
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 19116
//                                 Alisher_2211
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        # include <bits/stdc++.h>
# define  long          long long
# define  all(vc)       vc.begin(),vc.end()
# define  allr(vc)      vc.rbegin(),vc.rend()
# define  pb            push_back
# define  fi            first 
# define  se            second
# define  pi            pair <long, long>    
# define  lcm(a, b)     (a * b) / __gcd(a, b)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        using namespace std;
const long N = 100100;
void read(){freopen("input.txt" , "r" , stdin );freopen("output.txt", "w" , stdout );}

void solve(){
    string w;
    cin >> w;
    map<char, long> mp;
    for (int i = 0; i < w.size(); ++i){
        mp[ w[i] ] ++;
    }
    for (int i = 0; i < w.size(); ++i){
        if( mp[ w[i] ] % 2 ){
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 
        long T = 1;
        //cin >> T;
        while( T-- ){
            solve();
            cout<<'\n';
        }
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}

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

int main() {
    int n, q; cin >> n >> q;
    vector<int> c(n);
    for(auto& x : c) cin >> x;
    sort(begin(c), end(c));
    const int max_c = *max_element(begin(c), end(c));

    for(int i = 0; i < q; ++i) {
        int y; cin >> y;
        int ans = 0;
        for(int j = y; j <= max_c + y; j += y) {
            auto it = lower_bound(begin(c), end(c), j);
            if(it != begin(c)) {
                ans = max(ans, *prev(it) % y);
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3780
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	ll k; cin >> k;
	int n = 50, d = k % n;
	
	vector<ll> v(n);
	rep(i, n){
		if(i < d) v[i] = n + k / n;
		else v[i] = n - 1 - d + k / n;
	}
	cout << n << endl;
	rep(i, n) cout << v[i] << (i==n-1?"\n":" ");
	return 0;
}

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

const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

bool IsPrime(ll num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}

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

    if(s == "SUN") cout << "7" << endl;
    if(s == "MON") cout << "6" << endl;
    if(s == "TUE") cout << "5" << endl;
    if(s == "WED") cout << "4" << endl;
    if(s == "THU") cout << "3" << endl;
    if(s == "FRI") cout << "2" << endl;
    if(s == "SAT") cout << "1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int Q=1<<18;
int las[Q],e[Q<<1],nn[Q<<1],inc=0;
void ins(int x,int y)
{
	e[++inc]=y;
	nn[inc]=las[x];
	las[x]=inc;
}
#define ll long long 
ll als=0;
int up[Q],down[Q];
int fa[Q],si[Q],mlen[2][Q],id[Q],flen[Q];
char s[Q];
void dfs(int x)
{
	si[x]=s[x]-'0';
	for(int t=las[x];t;t=nn[t]){
		int y=e[t];
		if(y==fa[x])continue;
		fa[y]=x;
		dfs(y);
		si[x]+=si[y];
		int v=mlen[0][y]+1;
		if(v>mlen[0][x])id[x]=y,mlen[1][x]=mlen[0][x],mlen[0][x]=v;
		else mlen[1][x]=max(mlen[1][x],v);
	}
}
const int inf=998244353;
void ddfs(int x)
{
	if(fa[x]){
		int fat=fa[x];
		if(id[fat]==x)
			flen[x]=mlen[1][fat]+1;
		else flen[x]=mlen[0][fat]+1;
		flen[x]=max(flen[x],flen[fat]+1);
	}
	else flen[x]=-inf;
	int u=max(flen[x],mlen[0][x])-1,d=inf;
	for(int t=las[x];t;t=nn[t]){
		int y=e[t];
		if(y==fa[x]){
			u=min(u,mlen[0][x]+1);
			if(si[1]-si[x])
				d=min(d,flen[x]);
		}
		else{
			if(y==id[x])u=min(u,max(flen[x],mlen[1][x])+1);
			else u=min(u,max(flen[x],mlen[0][x])+1);
			if(si[y])d=min(d,mlen[0][y]+1);
		}
	}
	if(s[x]=='1')d=0;
	als+=max(0LL,(ll)u-d+1);
	for(int t=las[x];t;t=nn[t]){
		int y=e[t];
		if(y==fa[x])continue;
		ddfs(y);
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++)
		scanf("%d%d",&x,&y),ins(x,y),ins(y,x);
	scanf("%s",s+1);
	dfs(1);
	ddfs(1);
	printf("%lld\n",als+1LL);
	return 0;
}

Measured memory_bytes: 20096
require 'bigdecimal'

#n = BigDecimal(gets.to_i)
n = gets.to_i
# puts n / 26
str = ""
alphabet = "abcdefghijklmnopqrstuvwxyz"


class Integer
  def bijective_s(base=nil, offset=nil)
    offset ||= 'A'.ord #65
    base ||= 26
    value = self
    result = []
    while value > 0
      value -= 1
      result << (value%base+offset).chr
      value /= base
    end
    result.reverse.join
  end
end

puts n.bijective_s.downcase



Measured memory_bytes: 14432
#include <iostream>
#include <cmath>
#include<stdio.h>
using namespace std;
int main(){

double x1,y1,x2,y2,res;
cin>>x1>>y1>>x2>>y2;

res=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));

printf("%.8f\n",res);

}

Measured memory_bytes: 1236
package main

import (
	"errors"
	"fmt"
	"strings"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	m := loadMaze(h, w)
	fmt.Printf("%v\n", maxScore(m, pos{w - 1, h - 1}))
}

type pos struct {
	x, y int
}

func maxScore(maze []string, goal pos) int {
	sum := countBlock(maze)
	l, e := searchMinPathLength(maze, pos{0, 0}, goal)
	if e != nil {
		return -1
	}
	return (goal.x+1)*(goal.y+1) - sum - l
}

func countBlock(maze []string) (sum int) {
	for i := 0; i < len(maze); i++ {
		sum += strings.Count(maze[i], "#")
	}
	return sum
}

func searchMinPathLength(maze []string, start, goal pos) (int, error) {
	dists := make([][]int, goal.y+1)
	for y := 0; y < len(dists); y++ {
		dists[y] = make([]int, goal.x+1)
	}
	dfs(maze, pos{0, 0}, goal, dists)
	if l := dists[goal.y][goal.x]; l > 0 {
		return l, nil
	}
	return -1, errors.New("not found")
}

func dfs(maze []string, start, goal pos, dists [][]int) {
	dists[start.y][start.x] = 1

	var cur pos
	var candidates []pos

	candidates = append(candidates, start)
	for len(candidates) > 0 {
		cur, candidates = candidates[0], candidates[1:]
		if cur.x == goal.x && cur.y == goal.y {
			return
		}
		for _, diff := range []pos{{0, 1}, {0, -1}, {1, 0}, {-1, 0}} {
			next := pos{
				cur.x + diff.x,
				cur.y + diff.y,
			}
			if isBlocked(maze, next.x, next.y) || dists[next.y][next.x] > 0 {
				continue
			}
			dists[next.y][next.x] = dists[cur.y][cur.x] + 1
			candidates = append(candidates, next)
		}
	}
	return
}

func loadMaze(h, w int) []string {
	maze := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&(maze[i]))
	}
	return maze
}

func isBlocked(maze []string, x, y int) bool {
	if x < 0 || y < 0 || y >= len(maze) || x >= len(maze[y]) {
		return true
	}
	if maze[y][x] == '#' {
		return true
	}
	return false
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
 
#define M 1 //masculino
#define F (-1) //femenino
#define U 0 //no marcado
#define PB push_back
vector<long long int> dp(100001,-1);
int s=0;
 long long int solve(long long int arr[],long long int n,long long int i,long long int k)
 {  if(dp[i]!=-1)
    return dp[i];


    if(i==n-1)
     return 0;
     if(i==n-2)
     return abs(arr[i]-arr[i+1]);
    long long  int an,minv=INT_MAX;

    for (int j = 1; j<=k; j++) 
    {    if(i+j<n)
         minv = min(minv, (abs(arr[i]-arr[i+j])+solve(arr,n,i+j,k))); 
    
    }

     an =minv;
     dp[i]=an;
     return an;
 }

int main()
{
    long long int n,k;
    cin>>n>>k;
    long long int arr[n];
    for(long long int i=0;i<n;i++)
    {cin>>arr[i];
    s+=arr[i];
    }
     long long int ans = solve(arr,n,0,k);
     cout<<ans;

}


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

int main(){
int ans=0;
int get=0;
int n,m;
scanf("%d",&n);
char s[n][100];
for(int i=0;i<n;i++){
scanf("%s",s[i]);
}
scanf("%d",&m);
char t[m][100];
for(int i=0;i<m;i++){
scanf("%s",t[i]);
}

for(int i=0;i<n;i++){
	get=0;
	for(int j=0;j<n;j++){
		if(strcmp(s[i],s[j])==0){
			get=get+1;
		}
	}
	for(int j=0;j<m;j++){
		if(strcmp(s[i],t[j])==0){
			get=get-1;
		}
	}
	if(get>ans){
		ans=get;
	}
}
printf("%d\n",ans);
}

Measured memory_bytes: 128
line = input().split()

num = int(line[0])
arrn = int(line[1])

if arrn==0:
  print(num)
  
else:
  arr = input().split()
  i = 1;
  
  if str(num) in arr:
    while True:
      #小さい側
      left = num - i
      if str(left) in arr:
        print("",end="")
      else:
        print(left)
        break

      #大きい側
      right = num + i
      if str(right) in arr:
        print("",end="")
      else:
        print(right)
        break

      i += 1
  else:
    print(num)

Measured memory_bytes: 9212
const { isNumber } = require("util")

const input = require("fs").readFileSync("/dev/stdin", "utf8")
let cin = input.split(/ |\n/), cid = 0
const next = () => cin[cid++]
const nexts = (n) => cin.slice(cid, cid+=n).map(i=>parseInt(i))

const alphabet = [
    'a',
    'b',
    'c',
    'd',
    'e',
    'f',
    'g',
    'h',
    'i',
    'j',
    'k',
    'l',
    'm',
    'n',
    'o',
    'p',
    'q',
    'r',
    's',
    't',
    'u',
    'v',
    'w',
    'x',
    'y',
    'z'
]

let n = parseInt(next()) - 1
result = ''
while (n > 0) {
    result = alphabet[n%26] + result
    n = Math.floor(n/26) - 1
}
if (n === 0) {
    console.log("a" + result)
} else {
    console.log(result)
}


Measured memory_bytes: 29704
#include <stdio.h>
#include <iostream>
#include <algorithm>

#define rep(index,from,to) for(int index=from;index<to;index++)

using namespace std;

int main(){
    int n,m;
    int c[25];
    int dp[50010];
    cin>>n>>m;
    rep(i,0,m) cin>>c[i];
    sort(c,c+m);
    rep(j,0,n+1) dp[j]=j;
    rep(i,1,m){
        rep(j,0,n+1-c[i]){
            dp[j+c[i]]=min(dp[j+c[i]],dp[j]+1);
        }
    }
    
    cout<<dp[n]<<endl;
    return 0;
}

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

int main() {
    Int n, h, w;
    cin >> n >> h >> w;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (a >= h && b >= w) cnt++;
    }
    dump(cnt);
    return 0;  
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    while (true) {
        int n, m;
        scan(n, m);

        if (n == 0 && m == 0) return;

        auto t = iota(n).map!(i => readln.chomp.to!int).array;
        auto h = iota(m).map!(i => readln.chomp.to!int).array;

        solve(n, m, t, h);
    }
}

void solve(int n, int m, int[] t, int[] h) {
    int ts = t.sum, hs = h.sum;
    int ps = 10000;
    int st = -1, sh = -1;

    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. m) {
            auto a = ts - t[i] + h[j];
            auto b = hs - h[j] + t[i];

            if (a == b && t[i] + h[j] < ps) {
                st = i, sh = j;
                ps = t[i] + h[j];
            }
        }
    }

    if (st != -1) {
        writeln(t[st], " ", h[sh]);
    }
    else {
        writeln(-1);
    }
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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


def countDigits(n):
    return len(str(n))


ans = countDigits(N)
A = 1
while A * A <= N:
    if(N % A != 0):
        A += 1
        continue
    B = N // A

    cur = max(countDigits(A), countDigits(B))
    if (ans > cur):
        ans = cur
    A += 1
print(ans)


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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int N, D;
    cin >> N >> D;

    int cnt = 0;
    for(int i=0; i<N; i++){
        int X, Y;
        cin >> X >> Y;
        if(D * D >= X*X + Y*Y){
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi = 3.141592654;
void solve()
{
    ll n;
    cin>>n;
    ll cnt=0,temp=0;
    ll arr[n+1];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(temp<=arr[i])
        {
            cnt++;
            temp=arr[i];
        }
    }
    cout<<cnt<<endl;


}

int main()
{

    //freopen("Input.txt","r",stdin);
    ios_base :: sync_with_stdio(false);
    ll t;
   // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
}


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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int a = 0, b = 0;
    rep(i, n) {
        if(s[i] == 'R') a++;
    }
    int ans = max(a, b);
    rep(i, n) {
        if(s[i] == 'R') a--;
        else b++;
        int now = max(a, b);
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}


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

long long A[1000010];
long long X, Y;
int index = 0;
int main(void) {
	cin >> X >> Y;
	for (long long i = X; i <= Y; i*=2) {
		A[index] = i;
		index++;
	}
	cout << index << endl;
	return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b){if (b == 0) return a;return gcd(b, a % b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main(){
    int N;
    int x, ans=0;
    cin >> N >> x;
    vector<int> a(N);
    for(int i = 0; i < N; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < N; ++i){
        if(a[i] <= x){
            ans++;
            x -= a[i];
        }
    }
    if(ans == N && x > 0) ans--;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;
use std::collections::HashMap;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn combination(n: u64, mut m: u64) -> u64 {
    if n < m {
        return 0;
    }
    if m > n - m {
        m = n - m
    }

    let mut ret = 1u64;
    for i in 0..m {
        ret *= n - i;        
    }

    let mut div = 1u64;
    for i in 1..(m+1) {
        div *= i;
    }
    ret / div
}

fn main() {
    let (n, m) = input_tuple();
    let a_vec = input_vec();
    let mut sum_vec: Vec<u64> = Vec::new();
    let mut sum = 0;
    sum_vec.push(sum);
    for a in a_vec {
        sum += a;
        sum %= m;
        sum_vec.push(sum);
    }

    let mut sum_map: HashMap<u64, u64> = HashMap::new();
    for sum in sum_vec {
        let n = sum_map.entry(sum).or_insert(0);
        *n += 1;
    }

    let mut ans = 0;
    for n in sum_map.values() {
        ans += combination(*n, 2);
    }
    // println!("{:?}", sum_map);
    println!("{}", ans);
}


Measured memory_bytes: 12756
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
int A[10001],n,q;
bool find(int x){
	A[n]=x;
	int i=0;
	while (A[i]!=x) i++;
	if (i!=n) return true;
	else return false;
}
int main(){
	int x,cnt=0;
	scanf("%d",&n);
	for (int i=0;i<n;i++) scanf("%d",&A[i]);
	scanf("%d",&q);
	for (int i=0;i<q;i++){
		scanf("%d",&x);
		if (find(x)) cnt++;
	}
	printf("%d\n",cnt);
} 


Measured memory_bytes: 3248
s = gets.chomp.split('')
q = gets.chomp.to_i

flag = false
q.times do |i|
  i = gets.chomp.split(' ')
  if i == ['1']
    flag = !flag
  else
    if flag
      s.push(i[2]) if i[1] == '1'
      s.unshift(i[2]) if i[1] == '2'
    else
      s.unshift(i[2]) if i[1] == '1'
      s.push(i[2]) if i[1] == '2'
    end
  end
end

if flag
  puts s.join().reverse
else
  puts s.join()
end


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

using namespace std;

int main(int argc, char *argv[]) {
    int K;
    cin >> K;
    int64_t ans = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                int tmp = gcd(i, j);
                ans += gcd(tmp, k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  string s;
  cin>>s;
  if(s[0]==s[1] and s[1]==s[2]){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }

} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


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

#define pb push_back

#define jael(args...) { string  _s =#args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cout <<  *it  << " : " << a << endl;
    err(++it, args...);
}


const int N=4010,inf = 1e9 + 7;
int a[N],b[N],c[N],d[N],e[N],f[N];
int uu[N][N],dd[N][N],ll[N][N],rr[N][N];
bool vis[N][N];

int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

int main(){

	std::ios::sync_with_stdio(0); std::cin.tie(0);

	int n,m; cin>>n>>m;
	vector<int>  xs,ys;
	xs.pb(inf),xs.pb(inf*-1);
	ys.pb(inf),ys.pb(inf*-1);

	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
		xs.pb(a[i]),xs.pb(b[i]);
		ys.pb(c[i]);
	}
	for(int i=0;i<m;i++){
		cin>>d[i]>>e[i]>>f[i];
		xs.pb(d[i]);
		ys.pb(e[i]),ys.pb(f[i]);
	}

	// la magie opère ici
	sort(xs.begin(),xs.end()),sort(ys.begin(),ys.end());
	xs.resize(unique(xs.begin(),xs.end())-xs.begin());
	ys.resize(unique(ys.begin(),ys.end())-ys.begin());

	for(int i=0;i<n;i++){ // ici on remplit les contraintes de mouvements de haut en bas
		int x1=lower_bound(xs.begin(),xs.end(),a[i])-xs.begin();
		int x2=lower_bound(xs.begin(),xs.end(),b[i])-xs.begin();
		int y=lower_bound(ys.begin(),ys.end(),c[i])-ys.begin();
		for(int j=x1;j<x2;j++){
			uu[j][y-1]=1;
			dd[j][y]=1;
		}
	}

	for(int i=0;i<m;i++){// ici on remplit les contraintes de mouvements gauche et droite
		int x=lower_bound(xs.begin(),xs.end(),d[i])-xs.begin();
		int y1=lower_bound(ys.begin(),ys.end(),e[i])-ys.begin();
		int y2=lower_bound(ys.begin(),ys.end(),f[i])-ys.begin();
		for(int j=y1;j<y2;j++){
			rr[x-1][j]=1;
			ll[x][j]=1;
		}
	}
	////////ici se termine la magie /////////
	////////////////////////////////////////

	int x=lower_bound(xs.begin(),xs.end(),0)-xs.begin();
	int y=lower_bound(ys.begin(),ys.end(),0)-ys.begin();
	x--,y--;

	//trace(x,y);
	///////////////// largeur première recherche //////////////////////

	queue<pair<int,int> > q;
	q.push({x,y});
	vis[x][y]=1;
	//trace(q.size())	;
	while(!q.empty()){
		int xf=q.front().first;
		int yf=q.front().second;
		//trace(xf,yf,vis[xf][yf]);
		q.pop();
		for(int i=0;i<4;i++){
			if(i==0 and uu[xf][yf]) continue;
			if(i==1 and dd[xf][yf]) continue;
			if(i==2 and rr[xf][yf]) continue;
			if(i==3 and ll[xf][yf]) continue;
			int nx=xf+dx[i],ny=yf+dy[i];
			if(nx<0 or nx>=xs.size()-1 or ny<0 or ny>=ys.size()-1) continue;
			if(vis[nx][ny]) continue;
			vis[nx][ny]=true;
			q.push({nx,ny});
		}
	}

	////////////////////////////////////////////////////////////////

	if(vis[0][0] or vis[xs.size()-1][ys.size()-1]){cout<<"INF"<<endl;return 0;}

	long long wyn=0;
	for(int i=0;i<xs.size()-1;i++){
		for(int j=0;j<ys.size()-1;j++){
			if(vis[i][j]) {
			//	trace(i,j);
				wyn+=(long long)(xs[i+1]-xs[i])*(ys[j+1]-ys[j]);
			}
		}
	}
	cout<<wyn<<endl;

	return 0;
}

Measured memory_bytes: 118296