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

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


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

#define eps 1e-8

bool is_ok(int hx,int hy, int tx, int ty, int td,int a,int w){

  int dx = hx - tx;
  int dy = hy - ty;

  if(a*a < dx*dx + dy*dy) return false;

  double rad;

  if(dx == 0){
    if(dy < 0) rad = 270;
    else rad = 90;
  }else if(dy == 0){
    if(dx < 0) rad = 180;
    else rad = 0;
  }else{
    rad = atan((double)dy/dx);

    if(rad < 0){
      rad += M_PI;
    }
  
    if(dy < 0){
      rad += M_PI;
    }

    rad = rad/M_PI * 180;
  }
  
  rad += 180 - w;
  w = 180;

  if(rad >= 360) rad -= 360;
  if(rad < 0) rad += 360;
    
  return w - td/2.0 - eps < rad && rad < w + td/2.0 + eps;
}

bool calc(){
  int h,r,t;
  int hx[SIZE],hy[SIZE];
  int u,m,s,du,dm,ds;
  int tx[SIZE],ty[SIZE],td[SIZE];
  int w[SIZE],a[SIZE];
  
  scanf("%d%d",&h,&r);

  if(h==0) return false;

  for(int i=0;i<h;i++){
    scanf("%d%d",hx+i,hy+i);
  }

  scanf("%d%d%d%d%d%d",&u,&m,&s,&du,&dm,&ds);

  t = u+m+s;
  
  for(int i=0;i<u;i++){
    scanf("%d%d",tx+i,ty+i);
    td[i] = du;
  }

  for(int i=u;i<u+m;i++){
    scanf("%d%d",tx+i,ty+i);
    td[i] = dm;
  }

  for(int i=u+m;i<u+s+m;i++){
    scanf("%d%d",tx+i,ty+i);
    td[i] = ds;
  }

  for(int i=0;i<r;i++){
    scanf("%d%d",w+i,a+i);
  }

  int max_d = 0;
  int ans[SIZE] = {};

  for(int i=0;i<h;i++){

    for(int j=0;j<r;j++){
      bool flag = true;

      for(int k=0;k<t;k++){
        if(is_ok(hx[i],hy[i],tx[k],ty[k],td[k],a[j],w[j])) flag = false;
      }

      if(flag && is_ok(hx[i],hy[i],0,0,du,a[j],w[j])) ans[i]++;
    }
  }
  
  for(int i=0;i<h;i++)
    max_d = max(max_d,ans[i]);

  if(max_d > 0){
  
    bool flag1 = false;
    
    for(int i=0;i<h;i++){
      if(max_d == ans[i]){
        if(flag1) printf(" ");
        flag1 = true;
        printf("%d",i+1);
      }
    }
    
    printf("\n");
  }else{
    puts("NA");
  }
  
  return true;
}
  

int main(){

  while(calc());
  
  return 0;
}

Measured memory_bytes: 1332
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e12;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ll> h(n);
  rep(i, n) {
    cin >> h[i];
  }
  vector<ll> dp(n, INF);
  dp[0] = 0;
  rep(i, n) {
    if (i >= 1) {
      chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
    }
    if (i >= 2) {
      chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
    }
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
#include "bits/stdc++.h"
struct UnionFind {
  std::vector<int> par;
  std::vector<int> sizes;

  UnionFind(int n) {
    par.resize(n);
    sizes.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      sizes[i] = 1;
    }
  }

  int root(int a) {
    return par[a] == a ? a : par[a] = root(par[a]);
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (sizes[x] < sizes[y])
      std::swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];
  }
  int size(int x) {
    return sizes[root(x)];
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi a(n), b(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];

  auto c = a, d = b;
  sort(ALL(c));
  sort(ALL(d));
  REP(i, n) {
    if (c[i] > d[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  REP(i, n - 1) {
    if (c[i + 1] <= d[i]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  vector<pair<int, int>> aa(n), bb(n);
  REP(i, n) {
    aa[i] = { a[i],i };
  }
  REP(i, n) {
    bb[i] = { b[i],i };
  }
  sort(ALL(aa));
  sort(ALL(bb));
  REP(i, n) {
    if (aa[i].second == bb[i].second) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  UnionFind uf(n);
  REP(i, n)uf.unite(aa[i].second, bb[i].second);
  set<int> st;
  REP(i, n)st.insert(uf.root(i));
  if (st.size() == 1)cout << "No" << endl;
  else cout << "Yes" << endl;

}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int h, w, X[] = {1, -1, 0, 0}, Y[] = {0, 0, -1, 1};
char arr[30][30];
bool check(int i, int j)
{
    return (i >= 0 && i < h) && (j >= 0 && j < w);
}
int bfs(int stx, int sty, int enx, int eny)
{
    queue<pair<int, int>> q;
    bool vis[30][30] = {};
    int lvl[30][30] = {};
    q.push({stx, sty});
    vis[stx][sty] = true;
    lvl[stx][sty] = 0;
    while(q.size())
    {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        if(x == enx && y == eny)
            return lvl[x][y];
        for(int i = 0; i < 4; i++)
        {
            if(check(x + X[i], y + Y[i])
               && !vis[x + X[i]][y + Y[i]]
               && arr[x + X[i]][y + Y[i]] == '.')
            {
                vis[x + X[i]][y + Y[i]] = true;
                lvl[x + X[i]][y + Y[i]] = lvl[x][y] + 1;
                q.push({x + X[i], y + Y[i]});
            }
        }
    }
    return -1;
}
int main()
{
    Hello
    cin >> h >> w;
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            cin >> arr[i][j];
    int ans = 0;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(arr[i][j] == '#') continue;
            for(int a = 0; a < h; a++)
            {
                for(int b = 0; b < w; b++)
                {
                    if(arr[a][b] == '#' || (i == a && j == b)) continue;
                    /*cout << i << " " << j << " to ";
                    cout << a << " " << b << endl;
                    cout << "dist " << bfs(i, j, a, b) << endl;*/
                    ans = max(ans, bfs(i, j, a, b));
                }
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	long double a, b;
	cin >> a >> b;
	
	long double ans = a * b;
	cout << (ll)ans << endl;
	
	return 0;
}


Measured memory_bytes: 3780
import java.util.Scanner;

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

		int a = sc.nextInt();
		String op = sc.next();
		int b = sc.nextInt();
		if(op.equals("+")){
			System.out.println(a+b);
		}else{
			System.out.println(a-b);
		}
	}
}


Measured memory_bytes: 10320
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int prime[55556];

void era() {
    for (int i = 0; i < 55556; i++) {
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;
    for (int i = 2; i < 55556; i++) {
        if (prime[i]) {
            for (int j = i + i; j < 55556; j+=i) {
                prime[j] = 0;
            }
        }
    }
}

bool ok(int i) {
    return i % 5 == 1;
}

int main() {
    era();
    int N;
    cin >> N;

    int i = 2;
    vector<int> ans;
    while(N) {
        if (prime[i] && ok(i)) {
            N--;
            ans.push_back(i);
        }
        i++;
    }
    for (int j = 0; j < ans.size(); j++) {
        cout << ans[j] << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll H, W, N; cin >> H >> W >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  
  ll ans = 0;
  // bool ok = false;

  ll M = max(H, W);
  ans = (N - 1) / M + 1;


  
  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3680
N = int(input())
S = input()
count = {"R":[],"G":[],"B":[]}

for i in range(N):
    count[S[i]].append(i)
ans = len(count["R"])*len(count["G"])*len(count["B"])
for r in range(N):
    for g in range(r+1,N):
        if  0 <= g*2-r < N and ord(S[g*2-r]) + ord(S[r]) + ord(S[g]) == 219:
            ans -= 1

print(ans)

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

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

    map<int, int> mp;
    rep(i, n) {
        int a;
        cin >> a;
        ++mp[a];
    }

    int q;
    cin >> q;

    ll int ans = 0;
    for(auto x : mp) ans += x.first * x.second;

    rep(i, q) {
        ll int b, c;
        cin >> b >> c;
        ans = ans - b*mp[b] + c*mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 7904
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main() {
    int n,x,y;
    cin >> n >> x >> y;
    
    int a[n-1];
    for(int i=0;i<n-1;i++) a[i]=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++) a[min(j-i,min(abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j)))-1]++;
    }

    for(int i=0;i<n-1;i++) cout << a[i] << endl;
}

Measured memory_bytes: 3592
#include<stdio.h>
int main(){
  int n,m=10,i,s=0;
  for(i=0;i<5;i++){
    scanf("%d",&n);
    if(n%10){
      if(m>n%10)m=n%10;
      s++;
    }
    s+=n/10;
  }
  printf("%d\n",s*10+m-10);
  return 0;
}


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

int main() {
  int N, Y;
  cin >> N >> Y;
  int res10000 = -1, res5000 = -1, res1000 = -1;
  for (int a = 0; a <= N; ++a) {
    for (int b = 0; b + a <= N; ++b) {
      int c = N - a - b;
      int total = 10000 * a + 5000 * b + 1000 * c;
      if (total == Y) {
        res10000 = a;
        res5000 = b;
        res1000 = c;
      }
    }
  }

  cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

Measured memory_bytes: 3580
#include <stdio.h>
int UDLR(int n,char a)
{
	int i;
	for(i=1; i<=n; i++){
		printf("%c",a);
	}
}
int main(void)
{
	int sx,sy,tx,ty,x,y;
	scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
	x=tx-sx;y=ty-sy;
	UDLR(y,'U');
	UDLR(x,'R');
	UDLR(y,'D');
	UDLR(x,'L');
	UDLR(1,'L');
	UDLR(y+1,'U');
	UDLR(x+1,'R');
	UDLR(1,'D');
	UDLR(1,'R');
	UDLR(y+1,'D');
	UDLR(x+1,'L');
	UDLR(1,'U');
	puts("");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>

using namespace std;

int h, w, a, b;

int main()
{
    scanf("%d%d%d%d", &h, &w, &a, &b);
    for(int i = 0; i < h; i++, puts("")) for(int j = 0; j < w; j++) printf("%d", (j >= a) ^ (i >= b));
    return 0;
}


Measured memory_bytes: 1280
macro_rules! input { (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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: u32,
        k: u32,
    }
    let mut ans = 0;
    ans = k * (k - 1).pow(n - 1);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll N,Q,t,u,ANS=0;
	map<ll,ll>mp;
	cin>>N;
	rep(i,N){
		cin>>t;
		ANS=ANS+t;
		mp[t]++;
	}
	cin>>Q;
	rep(i,Q){
		cin>>t>>u;
		ANS=ANS+mp[t]*(u-t);
		mp[u]=mp[u]+mp[t];
		mp[t]=0;
		cout<<ANS<<endl;
	}
}

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

class P
{
    static void Main()
    {
        int[] NMA = Console.ReadLine().Split().Select(int.Parse).ToArray();
        bool[] N = new bool[NMA[1]];
        int i = 0;
        while (true)
        {
            int a = NMA[0] * i % NMA[1];
            if (N[a]) break;
            N[a] = true;
            i++;
        }
        Console.WriteLine(N[NMA[2]] ? "YES" : "NO");
    }
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n];
        for(int i = 0;i < n;i++) d[i] = sc.nextInt();
        System.out.println(Arrays.stream(d).distinct().count());
    }
}

Measured memory_bytes: 26964
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,ans,a[100100];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    for(int i=1;i<=n;i++){
        if(i+1>a[i+1]){
               for(int j=i+1;a[j]==i;j++) ans^=1;
               ans|=(a[i]-i)&1;
               puts(ans? "First":"Second");
               return 0;
           }    
    }    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long int ll;
#define pb         push_back
#define mp         make_pair
#define F          first
#define S          second
#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define pll        pair<ll,ll>
#define pii        pair<int,int>
#define all(v)     v.begin(),v.end()
#define M          998244353
#define M2         1000000007
#define inf        100000000000000
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

bool isPrime(ll n)
{
    if(n<=1)
        return false;
    if(n<=3)
        return true;
    if(n%2==0 || n%3==0)
        return false;
    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0|| n%(i+2)==0)
            return false;
    return true;
}

int main()
{
    off;
    string s,t;
    cin>>s>>t;
     t = t.substr(0,s.length());
    if(s==t)
        cout<<"Yes";
    else
        cout<<"No";
}








Measured memory_bytes: 3652
answers = Array.new
 
while true
    exp = gets.split(" ")
    break if exp[1] == "?"
    answer = exp[0].to_i + exp[2].to_i if exp[1] == "+"
    answer = exp[0].to_i - exp[2].to_i if exp[1] == "-"
    answer = exp[0].to_i * exp[2].to_i if exp[1] == "*"
    answer = exp[0].to_i / exp[2].to_i if exp[1] == "/"
    answers.push answer
end
 
answers.each{|ans|
    puts ans
}

Measured memory_bytes: 8720
#include<bits/stdc++.h>
#define maxn 200000
using namespace std;
int res[maxn], tmp[maxn];
void solve(int st, int n, int a, int b)
{
	if (n == 1)
	{
		res[st] = a;
		res[st + 1] = b;
		return;
	}
	int len = 1 << n, A, B, tag = a;
	a ^= tag; b ^= tag;
	if ((b >> n - 1) & 1)
	{
		int x = b - (1 << n - 1), tmp = x ^ (1 << n - 2);
		solve(st, n - 1, 0, tmp);
		A = tmp + (1 << n - 1);
		B = b;
		solve(st + len / 2, n - 1, A, B);
	}
	else
	{
		solve(st, n - 1, a, b);
		A = 1 << n - 1;
		B = res[st + 1] ^ (1 << n - 1);
		solve(st + len / 2, n - 1, A, B);
		int cur = st;
		tmp[st] = res[st];
		for (int i = len / 2 + 1; i <= len; i++)
			tmp[++cur] = res[st + i - 1];
		for (int i = 2; i <= len / 2; i++)
			tmp[++cur] = res[st + i - 1];
		for (int i = 1; i <= len; i++)
			res[st + i - 1] = tmp[st + i - 1];
	}
	for (int i = 1; i <= len; i++)
		res[st + i - 1] ^= tag;
}
int main()
{
	int n, a, b, diff = 0;
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i <= n - 1; i++)
		if (((a >> i) & 1) != ((b >> i) & 1)) diff++;
	if (diff % 2 == 0)
	{
		puts("NO");
		return 0;
	}
	solve(1, n, a, b);
	int full = (1 << n);
	puts("YES");
	for (int i = 1; i <= full; i++)
		printf("%d ", res[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 2048
#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 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<ll> A(n); rep(i, n) cin >> A[i];
  vector<ll> gl(n), gr(n);
  gl[0] = A[0];
  rep(i, n) {
    if(i) gl[i] = __gcd(gl[i-1], A[i]);
  }
  gr[n-1] = A[n-1];
  rrep(i, n) {
    if(i != n-1) gr[i] = __gcd(gr[i+1], A[i]);
  }
  ll ans = 1;
  rep(i, n) {
    if(i == 0) chmax(ans, gr[i+1]);
    else if(i == n-1) chmax(ans, gl[i-1]);
    else chmax(ans, __gcd(gl[i-1], gr[i+1]));
  }
  cout << ans << endk;
  return 0;
}


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


int main()
{
	string s;
	cin>>s;
	s[0] = '2';
	s[1] = '0';
	s[2] = '1';
	s[3] = '8';
	printf("%s\n", s.c_str());



	return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())

for h in range(1, 3500):
    for n in range(1, 3500):
        bumbo = 4*h*n - N*n - N*h
        if bumbo > 0:
            if (N*h*n) % bumbo == 0:
                w = (N*h*n) // bumbo
                print(h, n, w)
                sys.exit()

Measured memory_bytes: 40412
#include <bits/stdc++.h>
using namespace std;
const int N = 300000;
int n, x, y;
vector <int> bi[N], ci[N];
int dep[N], fa[N], A[N], B[N], GG[N];
void dfs1(int t, int f = 0, int d = 0)
{
    dep[t] = d; fa[t] = f;
    for (int i = 0; i < ci[t].size(); ++ i)
        if (ci[t][i] != f) dfs1(ci[t][i], t, d + 1);
}
int ans, loop;
void dfs2(int t, int f = 0, int d = 0)
{
    if (GG[t]) loop = 1; ans = max(ans, dep[t]);
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f && dep[bi[t][i]] > d + 1) dfs2(bi[t][i], t, d + 1);
}
int main()
{
    cin >> n >> x >> y;
    for (int i = 1; i < n; ++ i)
    {
        int a, b;
        cin >> a >> b;
        bi[a].push_back(b);
        bi[b].push_back(a);
        A[i] = a; B[i] = b;
    }
    for (int i = 1; i < n; ++ i)
    {
        int a, b;
        cin >> a >> b;
        ci[a].push_back(b);
        ci[b].push_back(a);
    }
    dfs1(y);
    for (int i = 1; i < n; ++ i)
    {
        if (fa[fa[A[i]]] == B[i] || fa[A[i]] == fa[B[i]] || A[i] == fa[fa[B[i]]] || fa[A[i]] == B[i] || A[i] == fa[B[i]]);
        else GG[A[i]] = GG[B[i]] = 1;
    }
    dfs2(x);
    if (loop) cout << -1 << endl; else cout << ans * 2 << endl;
}


Measured memory_bytes: 43644
#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 <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n, k;
	cin >> n >> k;
	vector<int> cnt(n);
	rep(i, n) {
		int a;
		cin >> a;
		a--; 
		cnt[a]++;
	}
	sort(all(cnt)); reverse(all(cnt));
	int ans = 0;
	for (int i = k; i < n; i++) ans += cnt[i];
	cout << ans << '\n';
}

Measured memory_bytes: 4004
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream> 
#include <cmath>
#include <map>
#include <queue>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
const ll MOD=ll(1e9+7);
 
//repetition
#define REP(i,n)  for(ll i=0;i<n;i++)
 
ll P_POW(ll i, ll n) {
  if(n==0) return 1;
 
  n--;
  ll rep = i;
 
  while(n) {
    rep = rep * i;
    n--;
  }
  return rep;
} 
 
unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
 
unsigned binarySearch(ll target, ll max, ll min) {
  while((max - min) > 1) {
      if((max + min)/2 > target) {
        max = (max + min)/2;
        min = min;
      } else {
        max = max;
        min = (max + min)/2;
      }
    }
}
 
ll solve(ll n) {
    if (n % 2 == 1) return 0;
 
    ll res = 0;
    n /= 2;
    int c = 1;
 
    while ((ll) n/((ll)pow(5,c))) {
      res += n/P_POW(5,c);
      c++;
    }
    return res;
}
 
void f(int rest, string s) {
  char abc[] = "abc";
  if(rest == 0) {
    cout << s << endl;
  } else {
    for(int i=0; i < 3; i++) {
      f(rest - 1, s+abc[i]);
    }
  }
} 
 
int main() {
  // vector<vector<ll>> a(n ,vector<ll>{2,0});
  // vector
  // vector<ll> s(n,0);
  // vector<vector<ll>> v;
  // map<ll,ll> m;
  // priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
  // vector<pair<ll, ll>> epv(n, {0, 0});
  
  /* iterator
  for(auto&& m: em) {
    epv.push_back({ m.second, m.first });
  }
  */

  char a;
  cin >> a;
  a++;
  cout << a << endl;
  //cout << static_cast<char>(a + 1) << endl;


}



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

public class Main {

    int MAX = 1000000;
    boolean[] primes;

    void run() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong(), B = sc.nextLong();

        long x = gcd(A, B);

        HashSet<Long> y = new HashSet<>();

        for (long i = 1; i * i <= x; i++) if (x % i == 0){
            y.add(i);
            y.add(x / i);
        }
//        debug(y.size(), y);

        int ans = 0;
        for (long i : y) {
            if (isPrime(i)) ans++;
        }

        System.out.println(ans);
    }

    boolean isPrime(long y) {
        for (long i = 2; i * i <= y; i++) {
            if (y % i == 0) return false;
        }
        return true;
    }

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

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int b = sc.nextInt();

		if(n<=5) {
			System.out.println(0);
		}else if(n>12) {
			System.out.println(b);
		}else {
			System.out.println(b/2);
		}

	}
}




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

template <typename T>
struct Edge {
  int from, to;
  T weight;
};

template <typename T>
class Graph {
 public:
  Graph(int n) : edges_(n) {}
  void AddEdge(int from, int to, T weight = T()) {
    edges_[from].push_back({from, to, weight});
  }
  const std::vector<Edge<T>>& Edges(int from) const { return edges_[from]; }
  int NumVertices() const { return edges_.size(); }

 private:
  std::vector<std::vector<Edge<T>>> edges_;
};

template <typename T>
bool BellmanFord(const Graph<T>& graph, int start, std::vector<T>& dist) {
  std::size_t n = graph.NumVertices();

  dist.resize(n);
  T inf = std::numeric_limits<T>::max();
  fill(dist.begin(), dist.end(), inf);
  dist[start] = 0;

  for (std::size_t iter = 0; iter < n; ++iter) {
    for (std::size_t i = 0; i < n; ++i) {
      if (dist[i] == inf) continue;
      for (const Edge<T>& e : graph.Edges(i)) {
        if (T d = dist[i] + e.weight; dist[e.to] > d) {
          if (iter == n - 1) return false;
          dist[e.to] = d;
        }
      }
    }
  }
  return true;
}

#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(ll, n, m, p);

  V<int> a(m), b(m), c(m);
  Graph<ll> bg(n);
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i], --b[i];
    bg.AddEdge(b[i], a[i], 0);
  }

  vector<ll> bgd;
  BellmanFord(bg, n - 1, bgd);

  Graph<ll> g(n);
  rep(i, m) if (bgd[a[i]] == 0) g.AddEdge(a[i], b[i], p - c[i]);

  vector<ll> d;
  if (BellmanFord(g, 0, d)) {
    wt(max(-d[n - 1], 0LL));
  } else {
    wt(-1);
  }
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main ()
{


    float x;
    float y=0;

    cin >>x;
    float sum=0;

    for (int i=1;i<=3;i++)
    {
        y=pow(x,i);
        sum=sum+y;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 4208
s = list(input())
for i in range(len(s)):
    s[i] = int(s[i])

def f(x,y):
    if x == 0:
        if y == 0:
            return 0
        return 1
    elif x == 1:
        if y <= 2:
            return 1
    return 0

fi = f(s[0],s[1])
se = f(s[2],s[3])

if fi < 0 or se < 0:
    print('NA')
elif fi == 0:
    if se == 0:
        print('NA')
    else:
        print('YYMM')
elif se == 0:
    print('MMYY')
else:
    print('AMBIGUOUS')


Measured memory_bytes: 3064
def f(a1,a2,a3,b1,b2,b3)
    return (b3-b2)*(a2-a1) >= (b2-b1)*(a3-a2)
end

n,c = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
dp = Array.new(n,0)
b = [0]
for i in 1..n-1
    while b.size > 1 && dp[b[0]]+(h[i]-h[b[0]])**2 > dp[b[1]]+(h[i]-h[b[1]])**2
        b.shift
    end
    dp[i] = dp[b[0]]+(h[i]-h[b[0]])**2+c
    while b.size > 1 && f(-2*h[b[-2]],-2*h[b[-1]],-2*h[i],dp[b[-2]]+h[b[-2]]**2,dp[b[-1]]+h[b[-1]]**2,dp[i]+h[i]**2)
        b.pop
    end
    b.push(i)
end
p dp[-1]

Measured memory_bytes: 18980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 2e9;

int main()
{
    int w, h, x, y, g = 0;
    long double ans;
    cin >> w >> h >> x >> y;
    if (2 * x == w && 2 * y == h)
    {
        g = 1;
    }
    ans = (long double)w * h / 2;
    cout << setprecision(12) << ans << ' ' << g << endl;
}


Measured memory_bytes: 256
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}
import scala.math._

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val n = input.toInt
    (1 to n by 2).count(divisors(_).size == 8).toString
  }

  def divisors(n: Int): List[Int] =
    for (i <- (1 to n).toList if n % i == 0) yield i

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """105""".stripMargin -> """1
                                   |""".stripMargin,
    """7""".stripMargin -> """0""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 26180
#include <iostream>
#include <algorithm>
#include <float.h>
#include <stdio.h>
#include <math.h>
using namespace std;

int main() {
    double r;

    cin >> r;   

    printf("%5f %5f\n", r*r*M_PI, 2*M_PI*r);
    return 0;

}


Measured memory_bytes: 3204
import sys
input = sys.stdin.readline


class BIT:
    def __init__(self, a):
        self.n = len(a)
        self.a = [0] * (self.n + 1)

        for i, j in enumerate(a):
            self.update(i, j)

    def update(self, i, x):
        i += 1
        while i <= self.n:
            self.a[i] = self.a[i] + x
            i += i & (-i)

    def get(self, i):
        s = 0
        i += 1
        while i != 0:
            s = s + self.a[i]
            i -= i & (-i)
        return s


def inmin(x):
    return int(x)-1


if __name__ == "__main__":
    n, q = map(int, input().split())
    c = list(map(inmin, input().split()))
    que = [[i, list(map(inmin, input().split()))] for i in range(q)]
    que.sort(key=lambda x: x[1][1])
    ans = [0] * q

    last = [-1] * n
    bit = BIT([0]*(n+10))
    j = 0
    for i in range(n):
        if last[c[i]] >= 0:
            bit.update(last[c[i]]+5, -1)
        bit.update(i+5, 1)
        last[c[i]] = i
        while j < q and que[j][1][1] == i:
            ans[que[j][0]] = bit.get(i+5) - bit.get(que[j][1][0]+4)
            j += 1
    print(*ans)


Measured memory_bytes: 238008
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using ProCon.Util;

namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {
            AC137B();
        }

        static void AC137B()
        {
            //https://atcoder.jp/contests/abc137/tasks

            
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var k = input[0];
            var x = input[1];

            for (int i = x - k + 1; i < x + k; i++ )
            {
                Console.Write(i);
                Console.Write(" ");
            }

            Console.ReadKey();

        }

    }
}


Measured memory_bytes: 11348
x, y, a, b, c = [int(i) for i in input().split()]
pa = [int(i) for i in input().split()]
pb = [int(i) for i in input().split()]
pc = [int(i) for i in input().split()]

pa = sorted(pa, reverse=True)
pa = pa[:x]
pb = sorted(pb, reverse=True)
pb = pb[:y]
pc = sorted(pc, reverse=True)

l = pa + pb + pc
l = sorted(l, reverse=True)
l = l[:int(x+y)]
print(sum(l))

Measured memory_bytes: 23340
#include<stdio.h>

#define MAX 200000

int main(){
    int R, n, i, maxv, minv;

    scanf("%d", &n);

    for(i=0; i<n; i++){

        scanf("%d", &R);

        if(i==0){
            maxv=-2000000000;
            minv=R;
        }else{
            if(maxv < (R-minv)) maxv=R-minv;
            if(minv > R) minv=R;
        }
    }

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

    return 0;
}



Measured memory_bytes: 2140
import sys
read = sys.stdin.read
from itertools import accumulate
def main():
    n = int(input())
    s = list(input())

    if n == 2:
        if s[0] == 'E' or s[1] == 'W':
            print(0)
            sys.exit()
        else:
            print(1)
            sys.exit()
    e = [0] * n
    w = [0] * n
    for i1 in range(n):
        e[i1] = 1 if s[i1] == 'E' else 0
        w[i1] = 1 if s[i1] == 'W' else 0
    e.insert(0, 0)
    e.append(0)
    w.insert(0, 0)
    w.append(0)

    ea = list(accumulate(e))
    wa = list(accumulate(w))
    rt = n
    for j1 in range(1, n+1):
        rt = min(rt, wa[j1 - 1] + (ea[-1] - ea[j1]))
    print(rt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 39952
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int64_t N;
bool is_ng[200000];
int main()
{
    using std::endl;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);

    int M;
    in >> N >> M;
    for (size_t i = 0; i < M; i++)
    {
        int d;
        in >> d;

        for (size_t i = 0; i < d; i++)
        {
            int b;
            in >> b; --b;
            is_ng[b] = true;
        }


    }

    out << std::count_if(is_ng, is_ng + N, [](auto b) {return !b; }) << endl;


    return 0;
}
#endif


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

bool sosu(lli x){
	if(x<2)return false;
	if(x==2)return true;
	if(x%2==0)return false;
	
	lli sqx = sqrt(x);
	for(int i=3;i<=sqx;i+=2){
		if(x%i==0){
			return false;
		}
	}
	return true;
}



int main () {
	lli x;
	int ans=0,n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x;
		if(sosu(x)==true){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

const int maxN = 3e3 + 5;

#define pii pair<int, int>

vector<vector<int> > dp(maxN, vector<int>(maxN, 0));
vector<vector<pii> > p(maxN, vector<pii>(maxN, {-1, -1}));

int main()
{
    string t, s;
    cin >> t >> s;
    for(int i = 1; i <= s.length(); i++) {
        for(int j = 1; j <= t.length(); j++) {
            if(s[i - 1] == t[j - 1]) {
                dp[i][j] = 1 + dp[i - 1][j - 1];
                p[i][j] = {i - 1, j - 1};
            }
            else {
                if(dp[i - 1][j] < dp[i][j - 1]) {
                    dp[i][j] = dp[i][j - 1];
                    p[i][j] = {i, j - 1};
                }
                else {
                    dp[i][j] = dp[i - 1][j];
                    p[i][j] = {i - 1, j};
                }
            }
        }
    }
    //cout << dp[s.length()][t.length()];
    string ans = "";
    int x = s.length(), y = t.length(), temp;
    while(p[x][y] != make_pair(-1, -1)) {
        if(s[x - 1] == t[y - 1]) ans += s[x - 1];
        temp = x;
        x = p[x][y].first;
        y = p[temp][y].second;
    }
    char tmp;
    for(int i = 0; i < ans.length()/2; i++) {
        tmp = ans[i];
        ans[i] = ans[ans.length() - 1 - i];
        ans[ans.length() -1 - i] = tmp;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 109176
import copy
n=int(input())
a=[0]*n
for i in range(n):
  a[i]=int(input())
b=copy.deepcopy(a)
m1=max(a)
a.remove(m1)
m2=max(a)
for i in range(n):
  if b[i]==m1:
    print(m2)
  else:
    print(m1)

Measured memory_bytes: 14688
#include <stdio.h>
#define N 100

int main(){

  int n, A[N];
  int i, j, temp, count;

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

  for(i=0; i<n-1; i++){
    for(j=n-1; j>i; j--){
      
      if(A[j]<A[j-1]){
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
	
	count++;
      }
    }
  }

  for(i=0; i<n-1; i++){
    printf("%d ", A[i]);
  }
  printf("%d\n", A[n-1]);

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

  return 0;
}



Measured memory_bytes: 2104
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc076.contest.atcoder.jp/tasks/abc076_c>
問題文============================================================
 E869120 は、宝物が入ってそうな箱を見つけました。
 しかし、これには鍵がかかっており、鍵を開けるためには英小文字からなる文字列 S が必要です。
 彼は文字列 S' を見つけ、これは文字列 S の 0 個以上 |S| 個以内の文字が ? に置き換わった文字列であることも分かりました。
 ただし、文字列 A に対して、|A| を「文字列 A の長さ」とします。
 
 そこで、E869120 はヒントとなる紙を見つけました。
 
 条件1：文字列 S の中に連続する部分文字列として英小文字から成る文字列 T が含まれている。
 条件2：S は、条件1を満たす文字列の中で辞書順最小の文字列である。
 そのとき、鍵となる文字列 S を出力しなさい。
 ただし、そのような文字列 S が存在しない場合は代わりに UNRESTORABLE と出力しなさい。
=================================================================

解説=============================================================
文字列最小であるには 文字列Sに関係のない ? を全て a にすれば良い
 よって、文字列Sに関係のある　？　を判別さえすればもとまる
================================================================
*/
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    string S,T; cin >> S >> T;
    string ans(S.length(),'z');
    bool f = false;
    for(int i = 0; i < S.length();i++){
        if(i + T.length() >S.length())break;
        string tmp = "";
        for(int j = 0; j < i;j++){
            if(S[j] == '?') tmp+="a";
            else tmp += S[j];
        }
        bool dame = false;
        for(int j = i; j < i + T.length();j++){
            if(S[j] == '?') tmp += T[j-i];
            else{
                if(S[j] == T[j-i]){
                    tmp += T[j-i];
                }else{
                    dame = true;
                    break;
                }
            }
        }
        if(dame)continue;
        for(int j = i + T.length(); j < S.length();j++){
            if(S[j] == '?') tmp += "a";
            else tmp += S[j];
        }
        
        f = true;
        ans = min(ans,tmp);
    }
    
    if(f){
        cout << ans << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}


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

using namespace std;

bool data[90][90];
int w, h, dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};

bool check(int y, int x){
  if(y<0 || y>=h) return false;
  if(x<0 || x>=w) return false;
  return true;
}

int dfs(int y, int x, int d){
  int res = d;
  for(int i=0;i<4;i++){
    int ny = y + dy[i];
    int nx = x + dx[i];
    if(check(ny, nx) && data[ny][nx]){
      data[ny][nx] = false;
      res = max(res, dfs(ny, nx, d+1));
      data[ny][nx] = true;
    }
  }
  return res;
}

main(){
  while(cin >> w >> h && (w|h)){
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> data[i][j];
    int ans = 0;
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(data[i][j]) ans = max(ans, dfs(i, j, 0));
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
a[99][999],c;f(i,d,s,b){for(++a[d++][s];i--;)b>>i&1||f(10,d,s+i*d,b|1<<i);}main(){for(f(10,0,0,0);scanf("%d%d",a,&c)/2;)printf("%d\n",a[**a][c]);}

Measured memory_bytes: 640
import sys
from collections import defaultdict

S = input()
T = input()
L = len(S)

dcts = defaultdict(int)
dctt = defaultdict(int)
for i in range(L):
    s = S[i]
    t = T[i]
    if dcts[s] == 0:
        dcts[s] = t
    else:
        if dcts[s] != t:
            print('No')
            sys.exit()
    if dctt[t] == 0:
        dctt[t] = s
    else:
        if dctt[t] != s:
            print('No')
            sys.exit()
print('Yes')

Measured memory_bytes: 3888
import sys
input = sys.stdin.readline

n = int(input())
a = 0
b = 0
ba = 0
ans = 0

for i in range(n):
  s = input().strip()
  leng = len(s)
  if s[0] == 'B' and s[-1] == 'A':
    ba += 1
    a += 1
    b += 1
  elif s[-1] == 'A':
    a += 1
  elif s[0] == 'B':
    b += 1
  for j in range(leng - 1):
    if s[j] == 'A' and s[j+1] == 'B':
      ans += 1

if ba == b == a > 0:
  ans += min(b,a) - 1
else:
  ans += min(b,a)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,m,cnt=0,i;
	cin>>n>>k>>m;
	for(i=min(n,k);cnt!=m;i--)
		if(n%i==0&&k%i==0)
			cnt++;
	cout<<i+1;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#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, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#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:
		std::cout << "ERR_ctoi" << std::endl;
		return -1;
	}
}
long long inverse(long long mod, long long val) {
	long long x[2] = { mod, val };
	long long a[2] = { 1, 0 };
	long long i;
	for (i = 0; x[!i]; i ^= 1) {
		a[!i] -= x[i] / x[!i] * a[i];
		x[i] = x[i] % x[!i];
	}
	if (!i) a[!i] += mod;
	return a[!i];
}


int main() {
	vector<ll> T;
	string str;
	ll N, P;
	cin >> N >> P;
	cin >> str;
	if (P == 2 || P == 5) {
		ll sum = 0;
		for (int i = N - 1; i >= 0; --i) if (ctoi(str[i]) % P == 0) sum += i + 1;
		PRI(sum);
		return 0;
	}
	T.resize(P, 0);
	ll c0 = ctoi(str[0]) % P;
	++T[c0];
	ll ans = T[0];
	ll inv10 = inverse(P, 10);
	ll inv10i = 1;
	ll s_sum = 0;
	auto p = [&](ll x) {return inv10i * (P + x - s_sum) % P; };
	REP(i, 1, N) {
		int ci = ctoi(str[i]) % P;
		s_sum = (10 * s_sum + ci) % P;
		inv10i = inv10i * inv10 % P;
		++T[p(ci)];
		ans += T[p(0)];
	}
	PRI(ans);
	return 0;
}




Measured memory_bytes: 3764