akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <set>
#include <iostream>
#include "cmath"
#include <map>
#include "unordered_map"
#include <queue>

using namespace std;

pair<int, int> go[4] = {
        {1, 0},
        {0, 1},
        {-1, 0},
        {0, - 1}
};
vector<int> graph[(int)1e6 + 7];
void explore(int k, vector<vector<int>>& belong, map<pair<int ,int>, bool>& g, pair<int, int> v, vector<pair<int, int>>& carry) {
    if(!g[v]) return;
    else {
        carry.push_back(v);
        for(auto x: go) {
            g[v] = false;
            belong[v.first][v.second] = k;
            explore(k, belong, g, {v.first + x.first, v.second + x.second}, carry);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int ch, cw;
    cin >> ch >> cw;
    int dh, dw;
    cin >> dh >> dw;
    map<pair<int, int>, bool> x;
    for(int i = 0; i < n; i++) {
        string g;
        cin >> g;
        for (int j = 0; j < m; j++) {
            x[{i + 1, j + 1}] = g[j] == '.';
        }
    }
    vector<vector<int>> belong(n + 1, vector(m + 1, -1));
    vector<vector<pair<int, int>>> comps;
    int k = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++)
        {
            if(x[{i, j}]) {
                vector<pair<int, int>> new_comp;
                explore(k, belong, x, {i, j}, new_comp);
                comps.push_back(new_comp);
                ++k;
            }
        }
    }

    for(auto &v : comps) {
        for(auto c: v) {
            for (int i = max(1, c.first - 2); i <= min(n, c.first + 2); ++i) {
                for (int j = max(1, c.second - 2); j <= min(m, c.second + 2); ++j) {
                    if (belong[i][j] != -1 && belong[i][j] != belong[c.first][c.second]) {
                        graph[belong[c.first][c.second]].push_back(belong[i][j]);
                        graph[belong[i][j]].push_back(belong[c.first][c.second]);;
                    }
                }
            }
        }
    }
    vector<int> used(comps.size() + 1, 0);
    vector<int> d(comps.size() + 1, (int)1e9 + 7);
    queue<int> bfs;
    bfs.push(belong[ch][cw]);
    d[belong[ch][cw]] = 0;
    while(!bfs.empty()) {
        int v = bfs.front();
        bfs.pop();
        used[v] = true;
        for(auto to: graph[v]) {
            if (!used[to]) {
                bfs.push(to);
                used[to] = true;
                d[to] = d[v] + 1;
            }
        }
    }
    if(d[belong[dh][dw]] == (int)1e9 + 7) {
        printf("-1\n");
    } else printf("%d", d[belong[dh][dw]]);
}

Measured memory_bytes: 122296
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
    IOS;
    int n, a;
    cin >> n;
    vector<int> cnt(n+1, 0);
    vector<int> arr(n);

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

    int tot = 0;
    for(int i = 1; i <= n; i++){
        tot = tot + ( (cnt[i]*(cnt[i]-1))/2 );
    }

    for(int i = 0; i < n; i++){
        cout << tot-cnt[arr[i]]+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

/* see https://github.com/pllk/cphb/ */
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;

typedef unsigned int uint;
typedef long long ll;
//typedef __int128 lll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    int w, h, x, y;
    cin>>w>>h>>x>>y;

    double area=(1LL*w*h)/2.0;
    bool mult= (x*2==w) && (y*2==h);

    cout<<area<<" "<<(mult?1:0)<<endl;
}



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

const long long MOD = 1000000007;

long long com(long long r,long long c)
{
    long long ans=1;
    for (int  i = 0; i < c; ++i) {
        ans*=r-i;
        ans%=MOD;
    }

    long long inv[c+1], finv[c+1];
    finv[0]=finv[1]=1;
    inv[0]=inv[1]=1;

    for (int  i = 2; i < c+1; ++i) {
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
    ans*=finv[c]%MOD;
    return ans%MOD;
}

long long pow(int a, int b)
{
    long long ans=1;
    for (int  i = 0; i < b; ++i) {
        ans*=a;
        ans%=MOD;
    }
    return ans;
}

int main()
{      
    long long n,a,b;
    cin >> n >> a >> b;

    std::string str;
    str = std::to_string(n);
    size_t size = str.length();
    
    std::string substr = str.substr(size-1,1);
    int num = std::stoi(substr);
    long long ans=pow(2,num);
    long long p=2;
    for (int  i = 1; i < size; ++i) {
        substr = str.substr(size-i-1,1);
        num = std::stoi(substr);
        p=pow(p,10);
        //cout << num << endl;
        ans*=pow(p,num);
        ans%=MOD;
    }
    
    ans-=1;
    ans-=com(n,a);
    if (ans < 0){ans+=MOD;}
    ans-=com(n,b);
    if (ans < 0){ans+=MOD;}

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


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <map> 
#include <algorithm>
#include <cstring>

#define ll long long
using namespace std; 

void solve(){
  int a[2], b[2]; 
  cin >> a[0] >> a[1] >> b[0] >>b[1];
  ll ans = INT64_MIN; 
  for(int i=0; i<2; i++){
    for(int j=0; j<2; j++){
      ans = max(ans, (ll)a[i] * (ll)b[j]); 
    }
  }
  cout << ans << "\n"; 
}

int main(){
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
 return 0;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class
Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    long mod = 1000000007L;
    long all = 1L;
    long missOne = 1L;
    long missTwo = 1L;
    for (int i = 0; i < n; i++) {
      all *= 10L;
      all %= mod;
      missOne *= 9L;
      missOne %= mod;
      missTwo *= 8L;
      missTwo %= mod;
    }
    long result = (all - 2L * missOne + missTwo) % mod;
    if (result < 0) result += mod;
    System.out.println(result);
  }
}

Measured memory_bytes: 32936
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N=1e5+5;
ll n,w,W[N],v[N];
ll dp[105][N];
ll solve(ll idx,ll capacity){
  if(idx==n){
    return 0;
  }
  if(dp[idx][capacity]!=-1)
    return dp[idx][capacity];
  if(capacity+W[idx]<=w){
    dp[idx][capacity]=max(solve(idx+1,capacity+W[idx])+v[idx],solve(idx+1,capacity));
  }
  else
    dp[idx][capacity]=solve(idx+1,capacity);
  return dp[idx][capacity];
}
int main()
{
    cin>>n>>w;
    for(ll i=0;i<n;i++){
        cin>>W[i]>>v[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,0);
    return 0;
}


Measured memory_bytes: 82304
import bisect
N, C, K = map(int, input().split())
T = [0]*N
for i in range(N):
    T[i] = int(input())

T = sorted(T)
j = 0
ans = 0
while j < N:
    t = T[j]
    ret = bisect.bisect_right(T, t+K, lo=j, hi=min(j+C, N))
    if ret-j > C:
        ret = C
    j += ret-j
    ans += 1
print(ans)


Measured memory_bytes: 8240
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class NumTh{
    // Generate Permutation of n elements
    static List<List<Integer>> genPermutations(int n){
		if(n == 1) {
			List<Integer> elem = new ArrayList<Integer>();
			elem.add(1);
			List<List<Integer>> ans = new ArrayList<List<Integer>>();
			ans.add(elem);
			return ans;
		}
		List<List<Integer>> recPerm = genPermutations(n - 1); // (n - 1)!
		List<List<Integer>> ans = new ArrayList<List<Integer>>();
		for(List<Integer> perm : recPerm) {
			for(int i = 0; i < n; i++) {
				List<Integer> newperm = new ArrayList<Integer>(n);
				for(int j = 0; j < n; j++) newperm.add(0);
				perm.add(i, n);
				Collections.copy(newperm, perm);
				ans.add(newperm);
				perm.remove(i);
			}
		}
		return ans;
	}
}

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		List<List<Integer>> perm = NumTh.genPermutations(N);
		int[][] adj = new int[N][N];
		for(int i = 0; i < N; i++) {
			Arrays.fill(adj[i], Integer.MAX_VALUE);
			adj[i][i] = 0;
		}
		for(int i = 0; i < M; i++) {
			int a = sc.nextInt() - 1, b = sc.nextInt() - 1;
			adj[a][b] = 1;
			adj[b][a] = 1;
		}
		int ans = 0;
		for(List<Integer> p : perm) {
			boolean check = true;
			if(p.get(0) != 1) continue;
			for(int i = 0; i + 1 < p.size(); i++) {
				if(adj[p.get(i) - 1][p.get(i + 1) - 1] == Integer.MAX_VALUE) check = false;
			}
			if(check) ans++;
		}
		System.out.println(ans);
	}
}


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

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define ff first
#define ss second
#define err stderr
#define out stdout

typedef long long int ll;
typedef long double ld;
typedef short int sh;

inline void readI(int *i)
{
	register int t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=(t*znak);
}
inline void readUI(int *i)
{
	register int t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=t;
}
inline void readL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak*=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=(t*znak);
}
inline void readUL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=t;
}
inline void writeL(ll l)
{
	if (l==0)
	{
		putchar(48);
	}
	else
	{
		if (l<0)
		{
		   l*=-1;
		   putchar(45);
		}
		int _tab[21];
		int wsk=0;
		while (l>0)
		{
			++wsk;
			_tab[wsk]=(l%10)+48;
			l/=10;
		}
		for (int j=wsk; j>=1; --j)
		{
			putchar(_tab[j]);
		}
	}
}
inline void writeS(string s)
{
	int l=s.length();
	for (int i=0; i<l; ++i)
	{
		putchar(s[i]);
	}
}
inline void space()
{
	putchar(32);
}
inline void endl()
{
	putchar(10);
}

#define debug if(1)
#define debug2 if(1)
#define debug3 if(1)
#define debug4 if(1)
#define MAXN (int)(1e5)+5

int n, a, b;
vector <int> v[MAXN];
bitset <MAXN> odw;
ll dp[MAXN][2];
ll P=(1e9)+7;

void dfs(int x)
{
	odw[x]=true;
	int l=v[x].size();
	dp[x][0]=dp[x][1]=1;
	for (int i=0; i<l; ++i)
	{
		if (!odw[v[x][i]])
		{
			dfs(v[x][i]);
			dp[x][0]*=dp[v[x][i]][1];
			dp[x][1]*=(dp[v[x][i]][0]+dp[v[x][i]][1]);
			dp[x][0]%=P;
			dp[x][1]%=P;
		}
	}
}
int main()
{
	readUI(&n);
	for (int i=1; i<n; ++i)
	{
		readUI(&a);
		readUI(&b);
		v[a].eb(b);
		v[b].eb(a);
	}
	dfs(1);
	fprintf (out, "%lld\n", (dp[1][0]+dp[1][1])%P);
	return 0;
}
/*
*/




Measured memory_bytes: 11520
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
   int a,b;
   cin >> a >> b;
   cout << (b%a==0 ? a+b : b-a) << endl; 
}

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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}

class graphwal
{
  public:
    int n;
    //0 1->bidirectional, 2->reverse edges
    typedef vector<pair<int,ll>> vpi;
    vector<vpi> ed;
    graphwal(int n):n(n),ed(n){}
    void reset(int n){
    ed.clear();
    this->n=n;
    ed.resize(n);
  }
    void add(int a, int b, int w){ed[a].pb(mp(b,w));}
    void load(int m){ for(int i=0;i<m;i++){int a=gi(),b=gi();ll w=gll();add(a-1,b-1,w);}}
};

class prims{
  public:
    typedef ll dt;
    typedef pair<dt,int> pt;
    int n;
    const graphwal &g;
    vector<dt> d;
    vi pr;
    vector<bool> v;
    const static dt MAXV=LLONG_MAX;
    priority_queue<pt,vector<pt>,greater<pt>> h;
    prims(const graphwal &g):
      n(g.n),g(g),d(n),pr(n),v(n){}
    dt calc(int sr=0){
      pt ret;
      dt mst=0;
      int nmst=0;
      fill(v.begin(),v.end(),false);
      fill(pr.begin(),pr.end(),-1);
      fill(d.begin(),d.end(),MAXV);
      d[sr]=0;
      h.push(pt(0,sr));
      while(!h.empty()){
        ret=h.top();
        h.pop();
        if(v[ret.se])continue;
        v[ret.se]=true;
        mst+=ret.fi;
        nmst++;
        for(auto i:g.ed[ret.se]){
          if(!v[i.fi] && d[i.fi] > i.se){
            d[i.fi]=i.se;
            pr[i.fi]=ret.se;
            h.push(pt(d[i.fi],i.fi));
          }
        }
      }
      if(nmst!=n)return -1;
      return mst;
    }
    bool inmst(int a, int b){
      return (pr[a]==b || pr[b]==a);
    }
};

int main() {
  int n=gi();
  set<pair<ll,int>> x,y;
  vi ax,ay;
  for(int i=0;i<n;i++) {
    ll tx=gi(), ty=gi();
    x.insert({tx,i}), y.insert({ty,i});
    ax.pb(tx), ay.pb(ty);
  }
  graphwal g(n);
  for(int i=0;i<n;i++) {
    ll tx=ax[i], ty=ay[i];
    auto it=x.find({tx,i});
    it++;
    if(it!=x.end()){
      g.add(i,(*it).se,(*it).fi-tx);
    }
    it--;
    if(it!=x.begin()){
      it--;
      g.add(i,(*it).se,tx-(*it).fi);
    }

    auto yt=y.find({ty,i});
    yt++;
    if(yt!=y.end()){
      g.add(i,(*yt).se,(*yt).fi-ty);
    }
    yt--;
    if(yt!=y.begin()){
      yt--;
      g.add(i,(*yt).se,ty-(*yt).fi);
    }
  }
  prims pr(g);
  cout<<pr.calc()<<endl;


  return 0;
}

Measured memory_bytes: 27116
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>

int main()
{
	long long N, A, B, C, D;
	scanf("%lld%lld%lld%lld%lld", &N, &A, &B, &C, &D);
	N--;
	long long sa = abs(A - B);
	long long kai = C == 0 ? N : sa / C;
	if (kai > N) {
		kai = N;
	} else {
		if (N % 2 == 0) {
			if (kai % 2 == 1) {
				kai--;
			}
		} else {
			if (kai % 2 == 0) {
				kai--;
			}
		}
	}
	long long plus = (N + kai) / 2;
	long long ato = sa - kai * C;
	if (ato <= plus * (D - C)) {
		printf("YES\n");
	} else {
		bool yes = false;
		long long mi = INT_MAX, mx = INT_MIN;
		for (int i = 0; i <= N; i++) {
			long long mi = C * i - D * (N - i);
			long long mx = D * i - C * (N - i);
			if (sa >= mi && sa <= mx) {
				yes = true;
				break;
			}
		}
		if (yes) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}

	return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Numerics;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var varN = int.Parse(Console.ReadLine());
        var varX = Console.ReadLine().Trim().Select(x => (byte)(x - '0')).ToArray();

        var popcount = 0;
        int lastPop = -1;
        for (int i = 0; i < varX.Length; ++i)
        {
            popcount += varX[i];
            if (varX[i] != 0)
            {
                lastPop = i;
            }
        }

        var fs = new int[varX.Length];
        if (popcount == 0)
        {
            fs.AsSpan().Fill(1);
        }
        else if (popcount == 1)
        {
            fs.AsSpan().Fill(varX[^1] == 0 ? 1 : 2);
            fs[^1] = 2;
            fs[lastPop] = 0;
        }
        else
        {
            var pow2 = new (int Upper, int Lower)[varX.Length];
            var inc = popcount + 1;
            var dec = popcount - 1;
            pow2[0] = (1 % inc, 1 % dec);
            for (int i = 1; i < pow2.Length; ++i)
            {
                pow2[i].Upper = pow2[i - 1].Upper * 2 % inc;
                pow2[i].Lower = pow2[i - 1].Lower * 2 % dec;
            }
            Array.Reverse(pow2);

            var (upperX, lowerX) = (0, 0);
            for (int i = 0; i < varX.Length; ++i)
            {
                if (varX[i] == 0)
                {
                    continue;
                }

                upperX += pow2[i].Upper; upperX %= inc;
                lowerX += pow2[i].Lower; lowerX %= dec;
            }

            for (int i = 0; i < varX.Length; ++i)
            {
                var (t, m) = varX[i] switch
                {
                    0 => (upperX + pow2[i].Upper, inc),
                    _ => (lowerX - pow2[i].Lower + dec, dec),
                };
                if (t < 1)
                {
                    continue;
                }

                t %= m;
                ++fs[i];

                while (t > 0)
                {
                    t %= BitOperations.PopCount(t.AsUInt32());
                    ++fs[i];
                }
            }
        }

        Console.WriteLine(string.Join(Environment.NewLine, fs));
    }
}

static class ConversionExtension
{
    public static uint AsUInt32(this int signed) => BitConverter.ToUInt32(BitConverter.GetBytes(signed));
}


Measured memory_bytes: 50444
#include <iostream>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <climits>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <bitset>
#include <fstream>
#include <tr1/unordered_map>
#include <assert.h>

#define x first
#define y second
#define y0 Y0
#define y1 Y1
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int MAXN = 3000;

int N, A[MAXN + 5];
int e, Begin[MAXN + 5], To[MAXN * 2 + 5], Next[MAXN * 2 + 5];

inline void add_edge (int x, int y) { To[++e] = y; Next[e] = Begin[x]; Begin[x] = e; }

inline int dfs (int x, int f, int d)
{
	for (int i = Begin[x]; i; i = Next[i])
	{
		int y = To[i];
		if (y == f || A[y] >= A[x]) continue;

		if (dfs (y, x, !d) == d) return d;
	}
	return !d;
}

inline void Solve ()
{
	for (int i = 1; i <= N; ++i) if (dfs (i, 0, 1)) printf("%d ", i);
}

inline void Input ()
{
	N = read<int>();
	for (int i = 1; i <= N; ++i) A[i] = read<int>();
	for (int i = 1; i < N; ++i)
	{
		int x = read<int>(), y = read<int>();
		add_edge (x, y);
		add_edge (y, x);
	}
}

int main ()
{

#ifdef hk_cnyali
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	string s;
	cin>>s;
	for(int i=0;i<3;i++){
		if(s.substr(i,1)=="1"){
			s.replace(i,1,"9");
		}else if(s.substr(i,1)=="9"){
			s.replace(i,1,"1");
		}
	}
	cout<<s<<endl;

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int N, M;
    cin >> N >> M;
    int max_X, min_Y;
    cin >> max_X >> min_Y;
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        max_X = max(max_X, x);
    }
    for(int i = 0; i < M; i++){
        int y;
        cin >> y;
        min_Y = min(min_Y, y);
    }
    if(max_X < min_Y){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }
}


Measured memory_bytes: 256
import std.stdio,
       std.string,
       std.conv,
       std.algorithm;

void main() {
  int N = readln.chomp.to!(int);
  int[string] s;
  for (int i = 0; i < N; i++) {
    s[readln.chomp]++;
  }
  int M = readln.chomp.to!(int);
  for (int i = 0; i < M; i++) {
    s[readln.chomp]--;
  }

  int ans = s.values.reduce!(max);
  writeln(ans >= 0 ? ans : 0);
}


Measured memory_bytes: 256
#include <stdio.h>

void swap(int *i, int *j)
{
	*i += *j;
	*j = *i - *j;
	*i -= *j;
}

int main(void)
{
	int score[2][10];
	int ans[2];
	int i, j;
	int k, l;
	
	for (i = 0; i < 2; i++){
		for (j = 0; j < 10; j++){
			scanf("%d", &score[i][j]);
		}
		for (k = 0; k < 9; k++){
			for (l = 0; l < 9 - k; l++){
				if (score[i][l] < score[i][l + 1]){
					swap(&score[i][l], &score[i][l + 1]);
				}
			}
		}
		
		ans[i] = score[i][0] + score[i][1] + score[i][2];
	}
	
	printf("%d %d\n", ans[0], ans[1]);
	
	return (0);
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll a[200005];
ll sum;
ll b;
ll ans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]-=(i+1);
    }
    sort(a,a+n);
    b=a[n/2];
    for(int i=0;i<n;i++){
        ans+=abs(a[i]-b);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 5124
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
const lli MAX=1e9+7;

int main()
{
    fast;
    lli n, k, d;
    cin>>n>>k>>d;
    lli a=abs(n)/d;
    if(k<=a){
        cout<<(abs(n)-k*d);
    }
    else{
        lli b=abs(n)-d*a, c=b-d;
        b=abs(b), c=abs(c);
        lli rem=k-a;
        if(rem%2) cout<<c;
        else cout<<b;
    }
    return 0;
}

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

// ショートハンド
// #define ll intに変えればメモリ節約
#define ll long long

/* 
 * ループ系のマクロ
 * `REP(i, 10) { cout << i; }`のように、変数名,回数で動く
 */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define EACH(i, n) for (auto&& i : n)

/*
 * 正規表現系
 */
#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)
const int MAX = 510000;
const int MOD = 1e9 + 7;

ll fac[MAX], finv[MAX], inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

  	ll x;
  	cin >> x;
    for(int i = 119; i >= 0; i--) {
      int powI = i * i * i * i * i;
      for(int j = i - 1; j > -120; j--) {
          int res = powI - j * j * j * j * j;
          if(res == x) {
              cout << i << " " << j;
              return 0;
          }
      }
    }
    return 0;
}

Measured memory_bytes: 3604
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}

	ans := math.MaxInt32
	for i := -100; i <= 100; i++ {
		sum := 0
		for _, a := range as {
			sum += abs(a-i) * abs(a-i)
		}
		ans = min(ans, sum)
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll x;
    cin >> x;
    ll ma = x / 100;
    ll mi = x / 105;
    for (int i = mi; i <= ma; i++)
    {
        ll tmp = x - 100 * i;
        if (0 <= tmp && tmp <= 5 * i)
        {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<50;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

struct UnionFind{
    int root[10010];
    int w[10010];

    UnionFind(){
        for(int i = 0; i < 10010; i++){
            root[i] = i;
            w[i] = 0;
        }
    }

    int getRoot(int n){
        if(root[n] == n) return n;
        else return (root[n] = getRoot(root[n]));
    }

    void merge(int x, int y, int aw){
        if(w[x] < w[y]) swap(x,y);
        int ry = getRoot(y);
        int rx = getRoot(x);
        root[ry] = rx;
        w[rx] += w[ry];
        w[rx] += aw;
    }

    bool isSame(int x, int y){
        if(getRoot(x) == getRoot(y)){
            return true;
        }
        return false;
    }

    int getWeight(int n){
        int rn = getRoot(n);
        return w[rn];
    }
};

int main(){
    int v,e;
    cin >> v >> e;
    vector<pair<int, pair<int,int> > > edge;
    for(int i = 0; i < e; i++){
        int s,t,w;
        cin >> s >> t >> w;
        edge.push_back(make_pair(w,make_pair(s,t)));
    }

    UnionFind uf;
    sort(edge.begin(),edge.end());

    for(int j = 0; j < edge.size(); j++){
        int s = edge[j].second.first;
        int t = edge[j].second.second;
        int w = edge[j].first;
        if(uf.isSame(s,t) == false){
            uf.merge(s,t,w);
        }
    }

    cout << uf.getWeight(1) << endl;

    return 0;
}


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

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] arr = new int[n+1];
      for(int i = 1; i <= n; i++)
        arr[i] = sc.nextInt();

      int[] res = new int[n+1];

      int m = 0;
      for(int i = n; i >= 1; i--) {
        int cnt = cntSum(res, i);
        if(cnt % 2 != arr[i]) {
          m++;
          res[i] = 1;
        }
      }
      
      System.out.println(m);
      
      StringBuilder sb = new StringBuilder();
      for(int i = 1; i <= n; i++) {
        if(res[i] == 0) continue;
        sb.append(i + " ");
      }
      if(sb.length() > 0)
        System.out.println(sb.toString().substring(0, sb.length() - 1));
  }

  private static int cntSum(int[] res, int n) {
    int sum = 0;
    for(int i = n * 2; i < res.length; i += n)
      sum += res[i];
    return sum;
  }
}

Measured memory_bytes: 81620
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(3);}} __init;
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; }

int main(){
ll h;
cin>>h;
ll cnt=0;
ll ans=0;
while(h!=0){
   h/=2;
   ans+=(1ll<<cnt);
   cnt++;
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int x;
  cin >> x;
  if (x >= 30)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

}


Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;


int main(int argc, char* argv[]){
	int a,b,c,k;
	int after_a, after_b, after_c;
	scanf("%d %d %d %d",&a,&b,&c,&k);
	bool flag=false;
	for(int i=0; i<k+1;i++){
		for(int j=0; j<k+1-i;j++){
			for(int kk=0; kk<k+1-i-j; kk++){
				after_a = a*pow((double)2,(double)i);
				after_b = b*pow((double)2,(double)j);
				after_c = c*pow((double)2,(double)kk);
//				printf("%d %d %d\n",after_a,after_b,after_c);
				if(after_a<after_b&&after_b<after_c){
					flag=true;
					break;
				}
			}
			if(flag){
				break;
			}
		}
		if(flag){
			break;
		}
	}
	if(flag){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

}




Measured memory_bytes: 4068
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long L = sc.nextLong();
    long R = sc.nextLong();

    sc.close();

    long r = Math.min(R, L + 2019);

    long min = 2018;
    
    for (long i = L; i <= r; i++){
      for (long j = i + 1; j <= r; j++){
        long m = (i % 2019) * (j % 2019) % 2019;
        min = Math.min(min, m);
      }
    }

    System.out.println(min);
    
  }

}

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

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  constexpr ModInt() : v(0) {}
  constexpr ModInt(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool)*this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t)v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  M pow(auto n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  friend M operator*(auto l, M r) { return M(l) *= r; }
  friend M operator/(auto l, M r) { return M(l) /= r; }
  friend M operator+(auto l, M r) { return M(l) += r; }
  friend M operator-(auto l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  friend bool operator==(auto l, M r) { return M(l) == r; }
  friend bool operator!=(auto l, M r) { return !(l == r); }
};
using Mint = ModInt<(unsigned)1e9 + 7>;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint l, r; cin >> l >> r;

  Mint dp[2][2][2];
  dp[1][1][0] = 1;
  for (int i = 59; i >= 0; --i) {
    Mint ndp[2][2][2];
    int a = l >> i & 1, b = r >> i & 1;
    for (int c = 0; c < 2; ++c) for (int d = 0; d < 2; ++d) for (int f = 0; f < 2; ++f) {
      for (int y = 0; y < 2; ++y) for (int x = 0; x <= y; ++x) {
        if (c and x < a or d and y > b) continue;
        if (!f and x < y) continue;
        ndp[c and x == a][d and y == b][f or x and y] += dp[c][d][f];
      }
    }
    swap(dp, ndp);
  }

  Mint res;
  for (int c = 0; c < 2; ++c) for (int d = 0; d < 2; ++d) {
    res += dp[c][d][1];
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF 9999999
#define LINF 99999999999
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}

class hasi{
public:
	int a;
	int b;

};

bool cmp(hasi x, hasi y){
	return x.b < y.b;
}



int main(void){
	int n,m;
	cin>>n>>m;
	hasi hashi[112345];
	int memo[112345];
	memo[0] = 0;
	rep(i,m){
		hashi[i] = hasi();
		cin>>hashi[i].a>>hashi[i].b;
	}
	sort(hashi,hashi+m,cmp);
	int bi = 0;
	rep(i,n){
		if(i==0){
			continue;
		}
		//cout<<i<<" "<<hashi[bi].a<<" "<<hashi[bi].b<<endl;
		if(i+1 == hashi[bi].b){
			memo[i] = memo[i-1];
			while(bi < m && hashi[bi].b == i+1){
				if(memo[i] == memo[hashi[bi].a - 1]){
					memo[i] = memo[i-1] + 1;
				}
				bi++;
			}
	
		}else{
			memo[i] = memo[i-1];
		}
	}
	cout<<memo[n-1]<<endl;

	return 0;
}

Measured memory_bytes: 1408
S=input()
N=len(S)
s=S[2:-1]
s2=S[1]
sl=S[N-1]
sr=s.replace("C","c")
sf=s2+sr+sl
if S.startswith("A"):
	if s.count("C")==1:
		if sf.islower():
			print("AC")
		else:
			print("WA")	
	else:
		print("WA")
else:
	print("WA")


Measured memory_bytes: 3060
tp = hp = 0
for i in range(int(input())):
    taro, hana = map(list, input().split())
    short = min(len(taro), len(hana))
    result = 0
    for k in range(short):
        if ord(taro[k]) != ord(hana[k]):
            result = ord(taro[k]) - ord(hana[k])
            break
    if not result:
        if len(taro) < len(hana):
            result = -1
        elif len(taro) > len(hana):
            result = 1
    if result > 0:
        tp += 3
    elif result < 0:
        hp += 3
    else:
        tp += 1
        hp += 1
print(tp, hp)


Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n;
    float v[55];
    float ans;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    sort(v,v+n);
    ans = (v[0] + v[1]) / 2;
    for(int i=2;i<n;i++){
        ans = (ans + v[i]) / 2;
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

const int MAX_V = 100010;
const int MAX_LOG_V = 30;
vector<int> G[MAX_V];
int root;
int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];

void dfs(int v, int p, int d){
    parent[0][v] = p;
    depth[v] = d;
    for(int i = 0; i < G[v].size(); i++){
        if(G[v][i] != p) dfs(G[v][i], v, d + 1);
    }
}

void init(int V){
    dfs(root, -1, 0);
    for(int k = 0; k + 1 < MAX_LOG_V; k++){
        for(int v = 0; v < V; v++){
            if(parent[k][v] < 0) parent[k + 1][v] = -1;
            else parent[k + 1][v] = parent[k][parent[k][v]];
        }
    }
}

int lca(int u, int v){
    if(depth[u] > depth[v]) swap(u, v);
    for(int k = 0; k < MAX_LOG_V; k++){
        if((depth[v] - depth[u]) >> k & 1){
            v = parent[k][v];
        }
    }
    if(u == v) return u;
    for(int k = MAX_LOG_V - 1; k >= 0; k--){
        if(parent[k][u] != parent[k][v]){
            u = parent[k][u];
            v = parent[k][v];
        }
    }
    return parent[0][u];    
}

signed main(){
    int n;
    root = 0;
    cin >> n;
    rep(i, 0, n){
        int k;
        cin >> k;
        rep(j, 0, k){
            int c;
            cin >> c;
            G[i]. push_back(c);
            // G[c]. push_back(i);
        }
    }
    init(n);
    int q;
    cin >> q;
    rep(i, 0, q){
        int u, v;
        cin >> u >> v;
        int tmp = lca(u, v);
        cout << tmp << endl;
    }
}

Measured memory_bytes: 25280
#include <iostream>
#include <string>
using namespace std;
string s,t;
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(i+1<s.size()&&s[i]=='B'&&s[i+1]=='C'){
            t=t+"D";
            i++;
        }else t=t+s[i];
    }
    long long ans=0;
    int x=0;
    for(int i=0;i<t.size();i++){
        if(t[i]=='B'||t[i]=='C')x=0;
        if(t[i]=='A')x++;
        if(t[i]=='D')ans+=x;
    }
    cout<<ans<<endl;
}


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

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy>> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    for(int i = 0; i < dx; i++){
        cout << "R";
    }
    for(int i = 0; i < dy; i++){
        cout << "U";
    }
    for(int i = 0; i < dx; i++){
        cout << "L";
    }
    for(int i = 0; i < dy + 1; i++){
        cout << "D";
    }
    for(int i = 0; i < dx + 1; i++){
        cout << "R";
    }
    for(int i = 0; i < dy + 1; i++){
        cout << "U";
    }
    cout << "LU";
    for(int i = 0; i < dx + 1; i++){
        cout << "L";
    }
    for(int i = 0; i < dy + 1; i++){
        cout << "D";
    }
    cout << "R" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <vector>
#include <numeric>
#include<string>
#include <map>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793



int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(cnt, 0, n) {
        cin >> a[cnt];
    }
    ll allxor = a[1];
    rep(cnt, 2, n - 2) {
        allxor = allxor ^ a[cnt];
    }
    cout << allxor;
    allxor = allxor ^ a[0]; //allxor の完成
    ll hoge;
    rep(cnt, 1, n - 1) {
        hoge = allxor ^ a[cnt];
        cout << " " << hoge;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4704
n = int(input())
ans = n
for i in range(n+1):
    a=0
    t=i
    while t>0:
        a+=t%6
        t=t//6
    t=n-i
    while t>0:
        a+=t%9
        t=t//9
    ans = min(ans,a)
print(ans)


Measured memory_bytes: 3060
n=int(input())
xy=[tuple(map(int,input().split())) for _ in range(n)]
pq=[]
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        sx,sy=xy[i]
        gx,gy=xy[j]
        pq.append((gx-sx,gy-sy))



ans=n
for p,q in pq:
    now=0
    for x,y in xy:
        if (x+p,y+q) not in xy:
            now+=1
    ans=min(ans,now)

print(ans)


Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int n;
int k;
int h[100010];
int dp[100010];

void chmin(int a, int *b)
{
	if (*b > a)
		*b = a;
}

int main(int argc, char const *argv[])
{
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) scanf("%d", h+i);
	for (int i = 0; i < 100010; i++) dp[i] = INT_MAX;

	dp[0] = 0;
	//今の足場
	for (int i = 0; i < n; i++)
	{
		//次の足場(j)
		for (int j = i+1; j - i <= k; j++)
		{
			chmin(dp[i] + abs(h[j] - h[i]), &dp[j]);
		}
	}
	printf("%d", dp[n-1]);
	return 0;
	
}


Measured memory_bytes: 896
//20
#include<iostream>
#include<sstream>
#include<string>
#include<algorithm>

using namespace std;

string sadd(string a,string b){
  reverse(a.begin(),a.end());
  reverse(b.begin(),b.end());
  if(a.size()<b.size()){
    swap(a,b);
  }
  int c=0;
  string r;
  for(int i=0;i<a.size();i++){
    int n=a[i]-'0'+c;
    if(i<b.size()){
      n+=b[i]-'0';
    }
    c=n/10;
    r+=char(n%10+'0');
  }
  if(c){
    r+=char('1');
  }
  reverse(r.begin(),r.end());
  return r;
}

int main(){
  for(string se;cin>>se;){
    int i;
    for(i=0;i<=9;i++){
      string s=se;
      replace(s.begin(),s.end(),'X',char('0'+i));
      replace(s.begin(),s.end(),'+',' ');
      replace(s.begin(),s.end(),'=',' ');
      stringstream ss(s);
      string n[3];
      for(int i=0;i<3;i++){
	ss>>n[i];
	if(n[i].size()>1&&n[i][0]=='0')goto next;
      }
      if(sadd(n[0],n[1])==n[2])break;
    next:
      ;
    }
    if(i<=9){
      cout<<i<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
	char S[5];
	scanf("%s",&S);
	int ans=0;
	int i;
	for(i=0;i<4;i++){
		if(S[i] == '+')	ans++;
		else			ans--;
	}
	
	
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

string cnt(int x){
    int num = (int)to_string(x).size();
    string ans = "";
    rep(i,6-num) ans += "0";
    return ans + to_string(x);
}

int main(){
    int n,m; cin >> n >> m;
    vector<vector<pair<int,int>>> a(n, vector<pair<int,int>>());
    vector<string> ans(m);
    rep(i,m){
        int p,y; cin >> p >> y; p--;
        a[p].push_back(make_pair(y,i));
    }
    rep(i,n) sort(a[i].begin(), a[i].end());
    rep(i,n) rep(j,a[i].size()) ans[a[i][j].second] = cnt(i+1) + cnt(j+1);
    rep(i,m) cout << ans[i] << endl;
    return 0;
}

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

int main(void){
  int N,cs=0;
  while(cin>>N,N){
    int B[5][5][5];
    for(int i=0;i<5;++i){
      for(int j=0;j<5;++j){
        string s;cin>>s;
        for(int k=0;k<5;++k)B[i][j][k]=s[k]-'0';
      }
    }
    
    int M1,M2;
    set<int> a,b;
    cin>>M1;
    for(int i=0,t;i<M1;++i){cin>>t;a.insert(t);}
    cin>>M2;
    for(int i=0,t;i<M2;++i){cin>>t;b.insert(t);}
    
    for(int d=0;d<N;++d){
	    int C[5][5][5];
      for(int i=0;i<5;++i)
        for(int j=0;j<5;++j)
          for(int k=0;k<5;++k)
            C[i][j][k]=0;
	    
      for(int z=0;z<5;++z){
        for(int y=0;y<5;++y){
          for(int x=0;x<5;++x){
            if(B[z][y][x]==1)
            for(int dz=-1;dz<=1;++dz){
              for(int dy=-1;dy<=1;++dy){
                for(int dx=-1;dx<=1;++dx){
                	if(dx==0&&dy==0&&dz==0) continue;
                  if(x+dx<0 || y+dy<0 || z+dz<0
                    || 5<=x+dx || 5<=y+dy || 5<=z+dz
                  	//|| !(dx==0||dy==0||dz==0)
                  	) continue;
                  	++C[z+dz][y+dy][x+dx];
                }
              }
            }
          }
        }
      }
      for(int z=0;z<5;++z){
        for(int y=0;y<5;++y){
          for(int x=0;x<5;++x){
          	//cerr<<C[z][y][x];
            if(B[z][y][x]==0 && a.find(C[z][y][x])!=a.end()) B[z][y][x]=1;
            else if(B[z][y][x]==1 && b.find(C[z][y][x])==b.end()) B[z][y][x]=0;
          }
          //cerr<<endl;
        }
      }
    }
    
    if(cs)cout<<endl;
    ++cs;
    cout<<"Case "<<cs<<":"<<endl;
    for(int i=0;i<5;++i){
      for(int j=0;j<5;++j){
        for(int k=0;k<5;++k){
          cout<<B[i][j][k];
        }
        cout<<endl;
      }
      if(i!=4)cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1212
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	
	s := scanText()

	f := true
	for i,e := range s {
		if (i+1)%2 == 0 {
			if e == 'R' {
				f = false
			}
		} else {
			if e == 'L' {
				f = false
			}
		}
	}

	if f {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640