akhauriyash/Code-Regression huggingface dataset:
import Data.List

pack [] = []
pack str@(s:_) =
  let n = length $ filter (== s) str
      r = filter (/= s) str
  in
    (s,n):(pack r)

ans ("0":_) = []
ans (n:x) =
  let n' = read n :: Int
      s  = pack $ concat $ map words $ take n' x
      s' = sortBy (\ (w0,n0) (w1,n1) -> let c = compare n1 n0
                                        in if c /= EQ
                                           then c
                                           else compare w0 w1 ) s
                                              
      c  = head $ head $ drop n' x
      r  = drop (n'+1) x
      a  = map fst $ take 5 $ filter (\(w,n) -> c == (head w)) s'
      t  = ans r
  in
    if a == []
    then "NA":t
    else (unwords a):t

main = do
  c <- getContents
  let i = lines c
      o = ans i
  mapM_ putStrLn o

Measured memory_bytes: 6428
fun main(args: Array<String>) {
    while (true) {
        val n = readLine()!!.toInt()

        if (n == 0) break

        val s = readLine()!!.split(" ").map(String::toInt)
        println(Math.sqrt(s.map { Math.pow(it - s.average(), 2.0) }.sum().div(n)))
    }
}


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

int main(){
  int n;
  cin >> n;
  int check =0;
  vector <int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i) ==i+1){
      check++;
    }
  }
    if(check >=n-2){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N>>M>>A;
    vec a(M);
    rep(i,M) cin>>a[i];
    ll temp = lower_bound(a.begin(), a.end(), A) - a.begin();
    cout<<min(temp, M - temp)<<endl;
}

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

int main(){
	int n,l;
	cin>>n>>l;
	string s[n];
	rep(i,n)cin>>s[i];
	sort(s,s+n);
	string ans;
	rep(i,n)ans+=s[i];
	puts(ans);
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    inf = 10 ** 7
    s = input()
    n = len(s)
    s += "".join(chr(i + 97) for i in range(26))
    # print(s)
    # 次をその文字にした時の「長さ、位置」
    size = [0] * 26
    pos = [n + i for i in range(26)]
    # 解答復元のための移動先
    nxt = [-1] * n
    # 後ろの文字から順に見る
    for i in range(n - 1, -1, -1):
        min_size = inf
        min_pos = -1
        # 次をどの文字にすれば短くなるか調べる
        # 同じ長さの時は辞書順優先
        for sz, p in zip(size, pos):
            if sz < min_size:
                min_size = sz
                min_pos = p
        code = ord(s[i]) - 97
        size[code] = min_size + 1
        pos[code] = i
        nxt[i] = min_pos
        # print(size)
        # print(pos)
        # print(nxt)
        # print()
    # 最短になる最初の文字を調べて、nxtの順にたどる
    min_size = inf
    min_pos = -1
    for sz, p in zip(size, pos):
        if sz < min_size:
            min_size = sz
            min_pos = p
    i = min_pos
    ans = s[i]
    while i < n:
        i = nxt[i]
        ans += s[i]
    print(ans)

main()


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

#define ff first
#define ss second
#define int long long
#define MOD 1000000007

using namespace std;

vector<vector<int>> adj;
vector<vector<int>> dp;

void dfs(int idx, int last){
    //dp[idx][0] = dp[idx][1] = 1;

    for (auto it : adj[idx]){
        if (it==last)
            continue;
        dfs(it, idx);
        dp[idx][0] = (dp[idx][0] * ((dp[it][0]+dp[it][1]) % MOD) ) % MOD;
        dp[idx][1] = (dp[idx][1] * dp[it][0]) % MOD;
    }
}

signed main() {
    //freopen("input1.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    adj.resize(n);
    dp.resize(n, vector<int>(2, 1));

    int u, v;
    for (int i=0; i<n-1; i++){
        cin >> u >> v;
        adj[u-1].push_back(v-1);
        adj[v-1].push_back(u-1);
    }

    dfs(0, -1);
    cout << (dp[0][0] + dp[0][1])%MOD;

    return 0;
}

Measured memory_bytes: 21068
x = input().split()
h = int(x[0])
n = int(x[1])

a = input().split()
a = [int(i) for i in a]
a.sort(reverse=True)

w = False
for i in range(n):
  h -= a[i]
  if 0 >= h:
    w = True
    break

print('Yes') if	True ==	w else print('No')

Measured memory_bytes: 13836
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var sum = r[0] + r[1];
            Console.WriteLine((sum + 2 - 1) / 2);
        }
    }
}

Measured memory_bytes: 13268
function Main(input) {
    input = input.split("\n");
    tmp = input[1].split(" ");
    all = Number(input[0]);
    var maxest = Number(tmp[0]);
    ans = 1;
    for(i = 2; i <= all; i++){
        the_Num = Number(tmp[i-1]);
        if(maxest >= the_Num){
            ans++;
        }
        if(maxest > the_Num) maxest = the_Num;

    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  int a,b,c,d,L,R;
  cin >> a >> b >> c >> d;
  
  L = a + b;
  R = c + d;
  
  if (L > R)
    cout << "Left" << endl;
  else if (L == R)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;

}


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

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int k = Integer.parseInt(scan.next());
        boolean[] sunuke = new boolean[n];
        Arrays.fill(sunuke, false);
        for (int i = 0; i < k; i++) {
            int d = Integer.parseInt(scan.next());
            for (int j = 0; j < d; j++) {
                int a = Integer.parseInt(scan.next());
                a--;
                sunuke[a] = true;
            }
        }
        scan.close();

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (!sunuke[i]) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 41332
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

constexpr int N = 64;
constexpr ll M = 2500;
vector<tuple<int, ll, ll>> g[N];
ll ans[N];
ll c[N], d[N];
bool u[N][M+1] = {};

pque<tuple<ll, int, ll>> que;

int main(){
	int n, m; ll s; scanf("%d%d%lld", &n, &m, &s);
	REP(i, m){
		int u, v; ll a, b; scanf("%d%d%lld%lld", &u, &v, &a, &b);
		g[u].EB(v, a, b);
		g[v].EB(u, a, b);
	}
	REP(i, n) scanf("%lld%lld", c+i+1, d+i+1);

	fill(ans, ans+N, -1);
	que.emplace(0, 1, min(s, M));
	while(que.size()){
		auto [a, i, s] = que.top(); que.pop();
		if(u[i][s]) continue;
		u[i][s] = true;
		if(!~ans[i]) ans[i] = a;
		// DEBUG("%d: %lld, %lld\n", i, a, s);
		// DEBUG("   => %d: %lld, %lld\n", i, a+d[i], min(s+c[i], M));
		que.emplace(a+d[i], i, min(s+c[i], M));
		for(auto [j, t, b] : g[i]){
			if(t > s) continue;
			// DEBUG("   => %d: %lld, %lld\n", j, a+b, s-t);
			que.emplace(a + b, j, s - t);
		}
	}

	FOR(i, 2, n+1) printf("%lld\n", ans[i]);
}





Measured memory_bytes: 9732
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



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

	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;
	


	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  char a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  if(a==f&&b==e&&c==d)cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	string s; cin >> s;
	cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> A(n);
  map<int, int> cnt;
  rep(i, n) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  int rem = 0;
  for(auto ele: cnt) {
    rem += ele.second - 1;
  }
  cout << n - (rem+1)/2*2 << endk;
  return 0;
}


Measured memory_bytes: 8280
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n, m, q;
	scanf("%d %d %d", &n, &m, &q);
	int rail[n+2][n+2] = {};
	REP(i, 0, m){
		int l, r;
		scanf("%d %d", &l, &r);
		rail[l][r]++;
	}

	REP(i, 0, n+2) for(ll j=n+1; j>0; j--)  rail[i][j-1] += rail[i][j];
	REP(i, 1, n+2) for(ll j=n+1; j>=0; j--) rail[i][j] += rail[i-1][j];

	REP(i, 0, q){
		int l, r, ans = 0;
		scanf("%d %d", &l, &r);
		ans = rail[n+1][0] - rail[l-1][0] - rail[n+1][r+1] + rail[l-1][r+1];
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 4812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

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

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}



int main(){
    string s;
    cin >> s;
    for (int i = 0; i < s.size()-1; i++)
    {
        if(s[i] == 'A' && s[i+1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <ctype.h>
const int bufSize = 1e6;
#define DEBUG
inline char nc()
{
    #ifdef DEBUG
    return getchar();
    #endif
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
inline void read(char *s)
{
    static char c;
    for (; !isalpha(c); c = nc());
    for (; isalpha(c); c = nc()) *s++ = c;
    *s = '\0';
}
template<typename T>
inline T read(T &r)
{
    static char c;
    static int flag;
    flag = 1, r = 0;
    for (c = nc(); !isdigit(c); c = nc()) if (c == '-') flag = -1;
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r *= flag;
}
const int maxn = 19;
int n;
int X[maxn],Y[maxn],P[maxn];
long long xdis[maxn][maxn],ydis[maxn][maxn];
long long xval[maxn][1<<maxn],yval[maxn][1<<maxn];
long long ans[maxn];
int id[maxn];
template<typename T>
inline T abs(const T &x) {return x > 0 ? x : -x;}
int main()
{
    read(n);
    for (int i = 0; i < n; ++i) read(X[i]), read(Y[i]), read(P[i]);
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) xdis[i][j] = abs(X[i] - X[j]), ydis[i][j] = abs(Y[i] - Y[j]);
    for (int i = 0; i <= n; ++i) ans[i] = 1ll << 62;
    int maxx = (1 << n) - 1;
    for (int i = 0; i <= maxx; ++i)
        for (int j = 0; j < n; ++j)
        {
            xval[j][i] = abs(X[j]), yval[j][i] = abs(Y[j]);
            for (int k = 0; k < n; ++k) if (i & (1 << k))  xval[j][i] = std::min(xval[j][i], xdis[k][j]), yval[j][i] = std::min(yval[j][i], ydis[k][j]);
            xval[j][i] *= P[j],yval[j][i] *= P[j];
        }
    for (int i = 0; i <= maxx; ++i)
    {
        int num = 0;
        for (int j = i; j > 0; j >>= 1) num += j & 1;
        for(int j = i;j >= 0;--j)
        {
            j &= i;
            long long tans = 0;
            for (int k = 0; k < n; ++k) if (!((1 << k) & i)) tans += std::min(xval[k][j],yval[k][(~j) & i]);
            ans[num] = std::min(ans[num], tans);
        }
    }
    for (int i = 0; i <= n; ++i) printf("%lld\n", ans[i]);
    return 0;
}

Measured memory_bytes: 10952
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vvi as(n, vi(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> as[i][j];
        }
    }

    vi dp(1 << n, -1e18);
    dp[0] = 0;
    vi sum(1 << n);
    for (int i = 0; i < 1 << n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (i >> j & 1) if (i >> k & 1) {
                    sum[i] += as[j][k];
                }
            }
        }
    }

    for (int i = 1; i < 1 << n; i++) {
        for (int j = i; j > 0; j = (j - 1) & i) {
            // jを同じグループとする
            dp[i] = max(dp[i], sum[j] + dp[i ^ j]);
        }
    }
    cout << dp.back() << endl;
}

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

int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  for(int i=0;i<=k;i++){
    int d=b,e=c;
    for(int j=0;j<i;j++){
      d*=2;
    }
    for(int j=i;j<k;j++){
      e*=2;
    }
    if(a<d&&d<e){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}
    
  

Measured memory_bytes: 3568
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int32_t h, w;
	cin >> h >> w;

	char temp;
	int32_t count{ 0 };
	for (auto i = 0; i < h * w; ++i) {
		cin >> temp;
		count += (temp == '#' ? 1 : 0);
	}

	cout << (count == h + w - 1 ? "Possible" : "Impossible") << endl;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    vector<int> a(n);
    vector<int> b(n);
    for(int in=0;in<n;++in) {
        cin >> a[in];
    }
    for(int in=0;in<n;++in) {
        cin >> b[in];
    }

    int j = 0, bef = -1;
    for(int in=0;in<n;++in) {
        if(bef!=a[in]) j = 0;
        if(a[in]==b[in]) {
            for(;j<n;++j) {
                if(a[j]!=a[in]&&b[j]!=a[in]) {
                    swap(b[in], b[j]);
                    break;
                }
            }
            if(a[in]==b[in]) {
                cout << "No" << endl;
                return 0;
            }
        }
        bef = a[in];
    }
    
    cout << "Yes" << endl;
    for(int in=0;in<n;++in) {
        if(in) cout << " ";
        cout << b[in];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });



int main(){
	ll r, D, x;
	cin >> r >> D >> x;
	REP(i, 10) {
		x = r*x - D;
		cout << x << "\n";
	}
    return 0;
}


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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N,Q;
    string S;
	cin>>N;
    cin>>S;
    cin>>Q;
    ll t,a,b;
    char c;
    map<char,set<ll>> s_mp;
    rep(i,26){
        char a = (char)(int('a')+i);
        s_mp[a] = {};
    }

    rep(i,N){
        s_mp[S[i]].insert(i);
    }
    ll ans = 0;
    
    rep(i,Q){
        cin>>t;
        if(t==1){
            cin>>a>>c;
            s_mp[S[a-1]].erase(a-1);
            S[a-1] = c;
            s_mp[S[a-1]].insert(a-1);
        }else{
            cin>>a>>b;
            ans = 0;
            rep(i,26){
                char c = (char)(int('a')+i);
            
                auto x = s_mp[c].lower_bound(a-1);
                if(x != s_mp[c].end()){
                    if(*x<= b-1){
                        ++ans;
                    }    
                }
                
                // auto x = s_mp[c].lower_bound(a-1);
                // auto y = s_mp[c].upper_bound(b-1);
                // if(x!= y){
                //     ++ans;
                // }
            }
            cout<<ans<<"\n";
        }

    }
	

	return 0;
}

Measured memory_bytes: 26268
#include <bits/stdc++.h> 
#define rep(a,b) for(int i = a;i < b; i++)
using namespace std;


int main() {
	int x;

	scanf("%d", &x);

	if(x >= 30) {
		puts("Yes");
	}else{
		puts("No");
	}
	
	return 0;
}

Measured memory_bytes: 3680
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      char[] charStr = br.readLine().toCharArray();
      StringBuilder rvsStr = new StringBuilder();
      for(int i=charStr.length-1; i>-1; i--)
        rvsStr.append(charStr[i]);

      System.out.println(rvsStr);
    }
  }
}


Measured memory_bytes: 24040
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string w;
  cin >> w;
  vector <string> W;
  W.push_back(w);
  bool flg = 0;
  for (int i = 0;i< n-1;i++){
    string w_new;
    cin >> w_new;
    if (find(W.begin(),W.end(),w_new)!=W.end()){
      flg = 1;
      break;
    }else{
      W.push_back(w_new);
    }if(w_new.at(0)== w.back()){
      w = w_new;
    }else{
      flg = 1;
      break;
    }
  }
  if (flg){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}
    
      

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x) make_pair(x)

using namespace std;
using ll=long long;

int main() {
  int n;cin>> n;
  vector<int> fig(n);
  reps(i,n){int a;cin >> a;fig[a-1]=i;}

  rep(i,n) cout << fig[i] << (i<n-1?" ":"\n");
}

Measured memory_bytes: 1152
//cf.cpp
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <string.h>
#include <cstring>
#include <queue>
#include <math.h>
#include <stack>
#include <bitset>
#include <utility>
#define mp make_pair
#define pb push_back
#define llc (long long)
#define pob pop_back
#define pm %1000000007
using namespace std;

int main(){
	int n;
	int a[100];
	cin>>n;
	int tot=0;int inp;
	for(int i = 0;i < n;i ++){
		cin>>a[i];
		tot+=a[i];
	}
	int sd=10000;
	int ans=0;
	for(int i = 0;i < n;i ++){
		if(abs(tot-a[i]*n)<sd){
			sd=abs(tot-a[i]*n);
			ans=i;
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
n = int(input())
S = sorted([int(input()) for i in range(n)])
ans = sum(S)

if ans % 10 == 0:
    for i in range(n):
        if S[i] % 10 != 0:
            ans -= S[i]
            break
        elif i == n-1:
            ans = 0
            
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    ll n, m, l;
    cin >> n >> m >> l;
    vector<vector<ll>> A(n, vector<ll>(m)), B(m, vector<ll>(l)), C(n, vector<ll>(m));
    repi(i, n, 0)
    {
        repi(j, m, 0)
        {
            cin >> A[i][j];
        }
    }
    repi(i, m, 0)
    {
        repi(j, l, 0)
        {
            cin >> B[i][j];
        }
    }

    repi(i, n, 0)
    {
        repi(j, l, 0)
        {
            ll sum = 0;
            repi(k, m, 0)
            {
                sum += A.at(i).at(k) * B.at(k).at(j);
            }
            cout << sum << ((j+1)%l == 0?"\n":" ");
        }
    }
    return 0;
}


Measured memory_bytes: 3232
#include<stdio.h>

int main(){
 int term[3];
 int five=0,seven=0;
 int i;
 scanf("%d %d %d",term,term+1,term+2);
 for(i=0;i<3;i++){
  five+=term[i]==5;
  seven+=term[i]==7;
 }
 if(five==2 && seven==1){
  printf("YES\n");
 }else{
  printf("NO\n");
 }
 return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;

class Dijkstra {
#define MAX_V 101
  typedef pair<int, int> P;

private:
  const int INF = 1e9 + 10;
  struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) { }
  };

  int V;
  vector<Edge> G[MAX_V];

public:

  Dijkstra(int V): V(V) { 
    if (V >= MAX_V) {
      assert(false);
    }
  }

  void AddEdge(int from, int to, int cost) {
    G[from].push_back(Edge(to, cost));
  }

  vector<int> Solve(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> d(V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
      P p = que.top(); que.pop();
      int v = p.second;
      if (d[v] < p.first) {
        continue;
      }
      for (int i = 0; i < G[v].size(); i++) {
        Edge e = G[v][i];
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(P(d[e.to], e.to));
        }
      }
    }

    return d;
  }
};


int main() {
  int n, m;
  cin >> n >> m;
  Dijkstra dijkstra(n);
  for (int i = 0; i < m; i++) {
    int a, b, c, d;
    char delim;
    cin >> a >> delim >> b >> delim >> c >> delim >> d;
    a--;
    b--;
    
    dijkstra.AddEdge(a, b, c);
    dijkstra.AddEdge(b, a, d);
  }

  int s, g, v, p;
  char delim;
  cin >> s >> delim >> g >> delim >> v >> delim >> p;
  s--;
  g--;
  
  vector<int> dgo = dijkstra.Solve(s);
  vector<int> dreturn = dijkstra.Solve(g);

  int cost = dgo[g] + dreturn[s];

  int ans = v - p - cost;

  cout << ans << endl;
   
  
  return 0;
}

Measured memory_bytes: 3084
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            long n = Input();
            long[] a = Input3();
            long[] b = Input3();
            long ans = 0;

            for(int i = 0; i < n; i++)
            {
                if (a[i] >= b[i]) ans += b[i];
                else
                {
                    ans += a[i];
                    ans += Math.Min(b[i] - a[i], a[i + 1]);
                    a[i + 1] = Math.Max(a[i + 1] + a[i] - b[i], 0);
                }
            }

           
            
            Console.WriteLine(ans);
                
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }

        
       
    }
}


Measured memory_bytes: 35292
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int N = S.Length;
		var h = new HashSet<char>();
		for(int i=0;i<N;i++) h.Add(S[i]);
		
		int min = N + 1;
		foreach(var c in h){
			int cnt = 0;
			var ca = S.ToCharArray();
			while(true){
				bool chk = true;
				for(int i=0;i<ca.Length;i++){
					chk &= ca[i] == c;
				}
				if(chk){
					break;
				}
				cnt++;
				var nca = new char[ca.Length - 1];
				for(int i=0;i<nca.Length;i++){
					if(ca[i] == c || ca[i+1] == c){
						nca[i] = c;
					} else {
						nca[i] = ca[i];
					}
				}
				ca = nca;
			}
			min = Math.Min(cnt, min);
		}
		
		
		
		
		Console.WriteLine(min);
		
	}
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    ll now = 0;
    for(ll i = 0; i < n; i++){
        if(s[i] == 'W'){
            ans += (i - now);
            now++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import           Data.List.Split

readIntList :: [Int] -> Int -> IO [Int]
readIntList list count
    | count == 0 =
        return list
    | otherwise = do
        ai <- readLn :: IO Int
        list' <- return $ list ++ [ai]
        readIntList list' (count - 1)

calcNumAteChoco :: Int -> Int -> Int
calcNumAteChoco coefficient numDays =
    sum $ map
        (\day ->
            -- TODO
            if null [True | n <- [0..100], 1 + coefficient * n <= numDays, day == 1 + coefficient * n] then
                0
            else
                1)
        [1..numDays]

main = do
    numPeople <- readLn :: IO Int
    line2 <- getLine
    [numDays, numExtraChocos] <- return $ map (\el -> read el :: Int) (splitOn " " line2)
    coefficients <- readIntList [] numPeople
    print $
        numExtraChocos +
        (sum $ map (\personId -> calcNumAteChoco (coefficients !! personId) numDays) [0..(numPeople - 1)] :: Int)


Measured memory_bytes: 1020
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

typedef long long LL;

const LL MOD = 1000000007;
static const size_t MAX_N = 1000001;

struct modll {
	long long x;
	modll() { }
	modll(long long _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(const modll& r) { return (x + r.x) % MOD; }
	modll operator+=(const modll& r) { return x = (x + r.x) % MOD; }
	modll operator-(const modll& r) { return (x + MOD - r.x) % MOD; }
	modll operator-=(const modll& r) { return x = (x + MOD - r.x) % MOD; }
	modll operator*(const modll& r) { return (x * r.x) % MOD; }
	modll operator*(int r) { return (x * r) % MOD; }
	modll operator*=(const modll& r) { return x = (x * r.x) % MOD; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

vector<modll> fact, inv;

modll combination(LL n, LL r) {
	if (r > n) {
		return 0;
	}
	return (fact[n] * inv[r]) * inv[n - r];
}

int main(int argc, char* argv[]) {
	cout.precision(20);

#ifdef _MSC_VER
	while (true)
#endif
	{
		int x = -1, y = -1;
		cin >> x >> y;
		if (x < 0 || y < 0) return 0;

		int xy = x + y;
		fact.resize(xy + 1);
		inv.resize(xy + 1);
		fact[0] = 1;
		for (int i = 1; i <= xy; ++i) {
			fact[i] = fact[i - 1] * i;
		}
		inv[xy] = modll::modinv(fact[xy]);
		for (int i = xy; i >= 1; --i) {
			inv[i - 1] = inv[i] * i;
		}

		modll ans = 0;
		for (int i = 0; i <= x; ++i) {
			int rx = x - i, ry = y - i * 2;
			if (rx == ry * 2) {
				modll a = combination(i + ry, ry);
				ans += a;
			}
		}

		cout << ans << endl;
	}
	return 0;
}


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

int main() {
  char c;
  cin >> c;

  if (c  == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')  cout << "vowel" << endl;
  else cout << "consonant" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, K; cin >> N >> K;

    vector<bool> chk(N,false);
    for(int i=0; i<K; i++){
        int d; cin >> d;
        for(int j=0; j<d; j++){
            int A; cin >> A;
            chk.at(A-1) = true;
        }

    }

    int ans = 0;
    for(int i=0; i<N; i++){
        if(!chk.at(i)){
            ans++;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=a+b,y=c+d;
    if(x>y) cout<<"Left"<<endl;
    else if(y>x) cout<<"Right"<<endl;
    else cout<<"Balanced"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

char grid[1005][1005];

int dp[1005][1005];

const int MOD=1e9+7;

void addmod(int& x,int y){x=(x+y)%MOD;}

int main(){
  int H,W;
  scanf("%d %d",&H,&W);
  for(int i=0;i<H;i++){
    scanf("%s",grid[i]);
  }
  dp[0][0]=1;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(grid[i][j]=='.'){
	addmod(dp[i+1][j],dp[i][j]);
	addmod(dp[i][j+1],dp[i][j]);
      }
    }
  }
  printf("%d\n",dp[H-1][W-1]);
  return 0;
}


Measured memory_bytes: 5120
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=110;
int n,k,ban[N];
int main()
{
	n=gi();k=gi();
	while(k--)
	{
		int d=gi();
		while(d--){int x=gi();ban[x]=1;}
	}
	int ans=0;
	for(int i=1;i<=n;i++)if(!ban[i])ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3752
from operator import itemgetter

def main():
    N,M = list(map(int, input().split()))
    lst = [[] for i in range(N)]
    anslst = []

    for i in range(M):
        P,Y = list(map(int, input().split()))
        lst[P-1].append({'city_id':i, 'pref':P, 'year':Y})

    for i in range(N):
        tmp = lst[i]
        tmp = sorted(tmp, key = itemgetter('year'))
        for j in range(len(tmp)):
            city_id = tmp[j]['city_id']
            pref = tmp[j]['pref']
            year = tmp[j]['year']
            id = '{0:06d}'.format(pref) + '{0:06d}'.format(j+1)
            anslst.append({'city_id':city_id, 'pref':pref, 'year':year, 'id':id})

    anslst = sorted(anslst, key = itemgetter('city_id'))
    for i in range(len(anslst)):
        print(anslst[i]['id'])

if __name__ == '__main__':
    main()


Measured memory_bytes: 99504
import java.io.{BufferedReader, InputStreamReader}

object Main extends App {
  val in = new BufferedReader(new InputStreamReader(System.in))
  val Array(x, a, b) = in.readLine.split(" ").map(_.toInt)
  val xa = (a - x).abs
  val xb = (b - x).abs
  val ans = if(xa < xb) "A" else "B"
  println(ans)
}

Measured memory_bytes: 27436
while True:
    h, w = [int(num) for num in input().split()]
    if h == w == 0:
        break
    for i in range(h):
        if 1 <= i <= h - 2:
            print("#", end="")
            print("." * (w - 2), end="")
            print("#")
        else:
            print("#" * w)
    print("")



Measured memory_bytes: 5644
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using Int = int64_t;
const Int INF = 1<<30;
const Int MOD = (Int)1e9 + 7;
const Int MAX_N = (Int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int x, n; cin >> x >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    vector<int> v;
    for(int k = -500; k <= 500; k++)
    {
        bool is_ok = true;
        for(int i = 0; i < n; i++)
        {
            if(k == p[i]) is_ok = false;
        }
        if(is_ok == false) continue;
        v.push_back(k);
    }

    int ans = -1;
    int dist = INF;
    for(int i = 0; i < v.size(); i++)
    {
        if(abs(x - v[i]) < dist)
        {
            dist = abs(x - v[i]);
            ans = v[i];
        }
    }
    cout << ans << endl;

}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;

int n; ll m;
vector<int> G[1 << 17];
bool used[1 << 17];
ll ans[1 << 17];
ll out[1 << 17];
vector<LP> v[1 << 17];
void dfs(int root) {
	used[root] = true;
	ans[root] = 1;
	rep(j, G[root].size()) {
		int to = G[root][j];
		if (used[to])continue;
		else {
			dfs(to);
			(ans[root] *= ans[to] + 1) %= m;
			v[root].push_back({ ans[to],to });
		}
	}

}
void q(int root, ll g) {
	out[root] = (g + 1)*ans[root] % m;
	int len = v[root].size();
	vector<ll> sv;
	ll pro = 1;
	rep(i, len) {
		sv.push_back(pro);
		pro *= v[root][i].first + 1; pro %= m;
	}
	ll cpro = g + 1; cpro %= m;
	per(i, len) {
		int to = v[root][i].second;
		ll nex = sv[i] * cpro%m;
		q(to, nex);
		cpro *= v[root][i].first + 1; cpro %= m;
	}
}
int main() {
	cin >> n; cin >> m;
	rep(i, n - 1) {
		int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a);
	}
	dfs(0);
	q(0, 0);
	rep(i, n) {
		cout << out[i] << endl;
	}
	//stop
	return 0;
}

Measured memory_bytes: 25728
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int C = sc.nextInt();
        char[] chars = sc.next().toCharArray();

        int[] left = new int[N];
        int[] right= new int[N];

        int count = 0;

        int lcount =0;
        for (int i = 0; i < N; i++) {
            if(chars[i]=='o'){
                left[i] = ++lcount;
                i+=C;
            }
            if(lcount==K) break;
        }
        int rcount =0;
        for (int i = N-1; i >= 0; i--) {
            if(chars[i]=='o'){
                right[i] = K-rcount;
                ++rcount;
                i-=C;
            }
            if(rcount==K) break;
        }


        for (int i = 0; i < N ; i++) {
            if(left[i]==right[i] && right[i]!=0){
                System.out.println(i+1);
            }
            
        }

    }

}


Measured memory_bytes: 58428
#include <iostream>
using namespace std;
int main(){
	int n;
	long long dan[31] = {1,1,2};
	for(int i=3;i<31;i++){
		dan[i] = dan[i-3] + dan[i-2] + dan[i-1];
	}
	while(cin >> n,n){
		int year = dan[n] / 10 / 365;
		if((double)dan[n] / 10.0 / 365.0 - year > 0)year++;
		cout << year << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

class B {
	int N, ans{ 100000000 };
public:
	void solve()
	{
		cin >> N;
		int a, count{ 0 };
		for (int i{ 0 }; i < N; i++)
		{
			cin >> a;
			count = 0;
			while (!(a & 1))
			{
				a >>= 1;
				count++;
			}

			if (count < ans) ans = count;
			if (ans == 0) break;
		}

		cout << ans << endl;

	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        times: [u64; n],
    }

    let (h, t) = times.split_first().unwrap();
    println!("{}", t.to_vec().into_iter().fold(*h, |a, b| lcm(a, b)));
}

fn gcd(a: u64, b: u64) -> u64 {
    match a {
        0 => b,
        _ => gcd(b % a, a),
    }
}

fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}

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

typedef long long ll;
typedef pair <ll, ll> llll;

ll n, x, d;
map <ll, vector <llll> > M;

ll Small(int x)
{
    if (x == 0) return 0;
    return ll(x) * (x - 1) / 2;
}

ll Big(int x)
{
    if (x == 0) return 0;
    return ll(x) * (2 * n - x - 1) / 2;
}

int main()
{
    cin >> n >> x >> d;
    if (d == 0)
        if (x == 0) printf("1\n");
        else printf("%d\n", (n + 2) / 2 + (n + 1) / 2);
    else {
        if (d < 0) {
            x += (n - 1) * d;
            d = -d;
        }
        for (int i = 0; i <= n; i++) {
            int j = n - i;
            ll st = ll(i - j) * x;
            ll mn = Small(i) - Big(j);
            ll mx = Big(i) - Small(j);
            ll val = st + mn * d;
            ll ind = val % (2ll * d);
            if (ind < 0) ind += 2ll * d;
            ll a = (val - ind) / (2ll * d);
            ll b = a + (mx - mn) / 2ll;
            M[ind].push_back(llll(a, b));
        }
        ll res = 0;
        for (auto it: M) {
            sort(it.second.begin(), it.second.end());
            res += it.second[0].second - it.second[0].first + 1;
            ll lst = it.second[0].second;
            for (int i = 1; i < it.second.size(); i++)
                if (it.second[i].second <= lst) ;
                else if (it.second[i].first <= lst) {
                    res += it.second[i].second - lst;
                    lst = it.second[i].second;
                } else {
                    res += it.second[i].second - it.second[i].first + 1;
                    lst = it.second[i].second;
                }
        }
        printf("%lld\n", res);
    }
    return 0;
}


Measured memory_bytes: 22144
#include <iostream>
#include <algorithm>
#include <vector>

typedef long long ll;

ll INF = 1000000;

void dfs(auto linked_list, auto node, ll cost[])
{
  for (const auto& x : linked_list[node]) {
    cost[x] = std::min(cost[x], cost[node] + 1);
    if (cost[x] == cost[node] + 1)
      dfs(linked_list, x, cost);
  }
}

int main()
{
  ll N;
  ll a, b;
  std::vector<ll> linked_list[100000];
  ll cost_a[100000];
  ll cost_b[100000];
  ll count_a = 0;
  ll count_b = 0;
  std::cin >> N;

  for (ll i = 0; i < N - 1; i++) {
    std::cin >> a >> b;
    a--;
    b--;
    linked_list[a].push_back(b);
    linked_list[b].push_back(a);
    cost_a[i] = INF;
    cost_b[i] = INF;
  }
  cost_a[N - 1] = INF;
  cost_a[0] = 0;
  cost_b[N - 1] = 0;

  dfs(linked_list, 0, cost_a);
  dfs(linked_list, N - 1, cost_b);

  for (ll i = 0; i < N; i++) {
    if (cost_a[i] > cost_b[i])
      count_b++;
    else
      count_a++;
  }

  if (count_a > count_b)
    std::cout << "Fennec" << std::endl;
  else
    std::cout << "Snuke" << std::endl;

  return 0;
}


Measured memory_bytes: 11904