akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, a, b;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin  >>a >> b;
    cout  << max(a-b,max(a+b, a*b))<< "\n";
}

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

//#define NDEBUG
// for DEBUG {{{
#ifdef NDEBUG
#define DEBUG_PRINT(fmt, ...) ((void)0)
#else
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#endif
#define ASSERT_RANGE(min,x,max) assert(((x)>=(min)) && ((x)<=(max)))
// }}}

int sort_int(int *a, int N) {// {{{
	int i;
	for (i = 0; i < N-1; i++) {
		int j;
		for (j = i + 1; j < N; j++) {
			if (a[i] > a[j]) {
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	return 0;
}// }}}
void merge_int(int *a, int *b, int lower, int sep, int upper) {// {{{
	int i_lower = lower;
	int i_upper = sep;
	int i_b = 0;
	while ((i_lower < sep) && (i_upper < upper)) {
		if (a[i_lower] < a[i_upper]) {
			b[i_b++] = a[i_lower++];
		} else {
			b[i_b++] = a[i_upper++];
		}
	}
	if (i_lower >= sep) {
		while (i_upper < upper) {
			b[i_b++] = a[i_upper++];
		}
	} else {
		while (i_lower < sep) {
			b[i_b++] = a[i_lower++];
		}
	}
	for (i_lower = 0; i_lower < i_b; i_lower++) {
		a[i_lower+lower] = b[i_lower];
	}
}// }}}
void merge_sort_int(int *a, int *b, int lower, int upper) {// {{{
	int sep;
	if ((lower == upper) || (lower + 1 == upper)) {
		return;
	}
	sep = (lower + upper) / 2;
	merge_sort_int(a,b,lower,sep);
	merge_sort_int(a,b,sep,upper);
	merge_int(a,b,lower,sep,upper);
}// }}}

int main(int argc, char **argv) {
	int m1, d1, m2, d2;
	fscanf(stdin,"%d%d",&m1,&d1) > 0;
	fscanf(stdin,"%d%d",&m2,&d2) > 0;
	if (m1 != m2) {
		fprintf(stdout,"1\n");
	} else {
		fprintf(stdout,"0\n");
	}
	return 0;
}



Measured memory_bytes: 128
n = int(input())
ans_lis = [0 for _ in range(n)]
for x in range(1,101):
    for y in range(1, 101):
        for z in range(1, 101):
            f = x**2+y**2+z**2+x*y+y*z+z*x
            if f<=n:
                ans_lis[f-1]+=1
for ans in ans_lis:
    print(ans)

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

using namespace std;
typedef long long ll;

ll m;

int main(){
    cin >> m;
    ll n1 = m / 500;
    ll n2 = (m -  n1 * 500) / 5;
    cout << n1 * 1000 + n2 * 5 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
using namespace std;
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define fill(x, y)     memset(x, y, sizeof(y))
#define all(x)         (x).begin(), (x).end()
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;

const ll INF = 1000000100;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, W;
  cin >> N >> W;

  ll w[N+1];
  int v[N+1];

  int V = 0;
  for (int i = 1; i <= N; i++) {
    cin >> w[i] >> v[i];
    V += v[i];
  }

  ll dp[N+1][V+1];
  for (int i = 0; i <= V; i++) {
      dp[0][i] = INF;
  }
  for (int i = 0; i <= N; i++) {
      dp[i][0] = 0;
  }

  for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= V; j++) {
          if (v[i] > j) {
              dp[i][j] = dp[i-1][j];
          } else {
              dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]]+w[i]);
          }
      }
  }

  int opt = 0;
  for (int i = 0; i <= N; i++) {
      for (int j = 0; j <= V; j++) {
          if (dp[i][j] <= W) {
              opt = max(opt, j);
          }
      }
  }
  cout << opt << "\n";

  return 0;
}

Measured memory_bytes: 82460
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	vector<pair<double,int> > v,v1,v2,temp;
	int a;
	double b;
	
	rep(i,8)
	{
		cin >> a >> b;
		v.push_back(make_pair(b,a));
	}

	rep(i,8)
	{
		cin >> a >> b;
		v1.push_back(make_pair(b,a));
	}

	rep(i,8)
	{
		cin >> a >> b;
		v2.push_back(make_pair(b,a));
	}

	sort(v.begin(),v.end());
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	
	cout << fixed;
	cout.precision(2);

	REP(i,2,4)
	{
		temp.push_back(v[i]);
		temp.push_back(v1[i]);
		temp.push_back(v2[i]);
	}

	sort(temp.begin(),temp.end());

	rep(i,2) cout << v[i].second << " " << v[i].first << endl;
	rep(i,2) cout << v1[i].second << " " << v1[i].first << endl;
	rep(i,2) cout << v2[i].second << " "<< v2[i].first << endl;
	rep(i,2) cout << temp[i].second << " " <<temp[i].first << endl;
	return 0;
}

Measured memory_bytes: 1300
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  echo f($n);

function f($n){
    $ans = 0;
    for ($i=1; $i<=$n; $i++) {
      $intdiv = intdiv($n, $i);
      $multi = $intdiv * $i;
      $ans += ($multi+$i) * $intdiv  / 2;
    }
    return $ans;
}

Measured memory_bytes: 16148
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int n,w;
vector< vector<int> > dp(100, vector<int>(10001,-1) );
vector<pair<int,int> > c(0);

int search(int i,int j){
  int ans;
  if(i==n){
    return 0;
  }
  else if( dp[i][j]> -1 ) return dp[i][j];
  else if( c[i].second > j ){
    ans = search(i+1,j);
  }
  else{
    ans = max(search(i+1,j) , search(i+1,j-c[i].second)+c[i].first );
  }
  dp[i][j]=ans;
  return ans;
}

int main(void){

  cin>>n;
  cin>>w;

  for(int i=0;i<n;i++){
    int x,y;
    cin>>x;
    cin>>y;
    c.push_back(make_pair(x,y));
  }

  cout << search(0,w) << endl;


  return 0;
}



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

int main() {
  while (true) {
    int n; cin >> n;
    if (!n) break;
    int min = 1000, max = 0, sum = 0;
    for (int i = 0; i < n; i++) {
      int s; cin >> s;
      sum += s;
      if (s < min) min = s;
      if (s > max) max = s;
    }
    cout << (sum - min - max) / (n - 2) << endl;
  }
  return 0;
}


Measured memory_bytes: 3016
import sys
from collections import deque

sys.setrecursionlimit(200000)


def hierarchize(source: int) -> bool:
    global edges, hierarchy
    hierarchy = [-1] * n
    queue = deque([(0, source)])
    while queue:
        h, v = queue.popleft()
        if hierarchy[v] != -1:
            continue
        hierarchy[v] = h
        if v == sink:
            return True
        queue.extend((h + 1, target)
                     for remain, target, _ in edges[v]
                     if hierarchy[target] == -1 and remain)
    return False


def augment(v: int, limit: int) -> int:
    global sink, edges, hierarchy
    if v == sink:
        return limit
    res = 0
    for e in edges[v]:
        remain, target, idx = e
        if remain == 0 or hierarchy[v] >= hierarchy[target]:
            continue
        aug = augment(target, min(limit, remain))
        e[0] -= aug
        edges[target][idx][0] += aug
        res += aug
        limit -= aug
        if not limit:
            break
    return res


if __name__ == "__main__":
    n, m = map(lambda x: int(x), input().split())
    sink = n - 1
    edges = [[] for _ in range(n)]  # type: ignore

    hierarchy = [-1] * n

    for _ in range(m):
        s, t, c = map(lambda x: int(x), input().split())
        es, et = edges[s], edges[t]
        ls, lt = len(es), len(et)
        edges[s].append([c, t, lt])
        edges[t].append([0, s, ls])

    ans = 0
    while hierarchize(0):
        ans += augment(0, 10000001)

    print(ans)



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

#define N 1001

void LCS(char *x,char *y){
  int m=strlen(x+1),n=strlen(y+1);
  int i,j,c[N][N];
  
  /*c=malloc(sizeof(int *)*(m+1));
  for(i=0;i<=m+1;i++){
    c[i]=malloc(sizeof(int *)*(n+1));
    }*/

  for(i=0;i<=m;i++){
    c[i][0]=0;
  }

  for(j=0;j<=n;j++){
    c[0][j]=0;
  }
  
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(x[i]==y[j]) c[i][j]=c[i-1][j-1]+1;
      else if(c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
    }
  }
  printf("%d\n",c[i-1][j-1]);
}

main(){
  int i,n;
  char str1[N],str2[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s%s",str1+1,str2+1);
    
    LCS(str1,str2);
  }

  return 0;
}

Measured memory_bytes: 4524
n = int(input())
L = list(map(int, input().split()))

#sL = sorted(L)
#print(sL)
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a, b, c = L[i], L[j], L[k]
            if a==b or a==c or b==c: continue
            if a+b > c and a+c > b and b+c > a:
                ans += 1

print(ans)


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

int main() {
    long long n;
    cin >> n;
    vector<long long> A(n);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        long long a;
        cin >> a;
        A[i] = a;
        sum += a;
    }

    long long sum_left = 0;
    long long sum_left1;
    for (int i = 0; i < n; i++) {
        sum_left += A[i];
        if (sum_left * 2 >= sum) {
            sum_left1 = sum_left - A[i];
            break;
        }
    }

    long long sum_right;
    long long sum_right1;
    sum_right = sum - sum_left;
    sum_right1 = sum - sum_left1;
    long long cost, cost1;
    cost = abs(sum_right - sum_left);
    cost1 = abs(sum_right1 - sum_left1);

    cout << min(cost, cost1) << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }


    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int m = in.nextInt();
        char[][] board = new char[n][];
        for(int i = 0; i < n; i++) {
            String s = in.next();
            board[i] = s.toCharArray();
        }

        Queue<Integer> next = new ArrayDeque<>();
        int[][] moves = new int[n][m];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if (board[i][j] == '.') {
                    moves[i][j] = 10000000;
                } else {
                    next.add(i * m + j);
                }
            }
        }
        int ret = 0;
        final int[] di = new int[]{-1, 0, 1, 0};
        final int[] dj = new int[]{0, 1, 0, -1};
        while(!next.isEmpty()) {
            int x = next.poll();
            int i = x / m;
            int j = x % m;
//            System.out.println(i + " " + j + " " + moves[i][j]);
            for(int k = 0; k < 4; k++) {
                int ii = i + di[k];
                int jj = j + dj[k];
                if (ii < 0 || ii >= n || jj < 0 || jj >= m) continue;
                if (board[ii][jj] == '#') continue;
                moves[ii][jj] = moves[i][j] + 1;
                board[ii][jj] = '#';
                next.add(ii * m + jj);
                ret = Math.max(ret, moves[ii][jj]);
            }
        }
        System.out.println(ret);
    }
}


Measured memory_bytes: 68304
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdio>

using namespace std;



int main() {
   int h,w;
   for(int k=0; ;k++){
    cin >>h>>w;
    if(w==0 && h==0)break;
   for(int i=0;i<h;i++){
      
       for(int j=0;j<w;j++){
           cout<<"#";
           
       }
       cout<<endl;
   }
   cout <<""<<endl;
  }
}


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

int main() {
    int N, Y;
    cin >> N >> Y;

    int res10000 = -1, res5000 = -1, res1000 = -1;
    int a, b, c, total;
    bool flg = false;
    rep(a, N+1) {
        rep(b, N-a+1) {
            c = N - a - b;
            total = 10000 * a + 5000 * b + 1000 * c;
            if (total == Y) {
                res10000 = a;
                res5000 = b;
                res1000 = c;
                flg = true;
            }
            if (flg) break;
        }
        if (flg) break;
    }

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

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    int c = max(a,b);
    if(c > 8){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }


    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String res = "NO";
        int index = 0;
        while (true){
            if (s.length() == index){
                res = "YES";
                break;
            }
            if (s.length() - index < 5){
                break;
            }
            
            if(s.startsWith("dream",index)){
               index += 5; 
               if (s.startsWith("eraser",index)){
                   index += 6;
               }else if (s.startsWith("erase",index)){
                   index += 5;
               }else if (s.startsWith("er",index)){
                   index += 2;
               }
               
            }else if (s.startsWith("erase",index)){
                index += 5;
                if (s.startsWith("eraser",index)){
                    index += 6;
                }else if (s.startsWith("r",index)){
                    index += 1;
                }
            }else{
                break;
            }
        }

        System.out.println(res);
        
    }

}


Measured memory_bytes: 24536
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

int h, w;
int n;
int num[10002];
int ans[102][102];

int main() {
	cin >> h >> w >> n;
	for (int i = 1; i <= n; i++) {
		cin >> num[i];
	}
	int r = 0, c = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < num[i]; j++) {
			if (r % 2 == 0) {
				ans[r][c] = i;
			}
			else {
				ans[r][w - 1 - c] = i;
			}
			c++;
			if (c == w) {
				c = 0;
				r++;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << ans[i][j];
			if (j < w - 1) cout << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stack>

using namespace std;

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

    stack<char> stk;

    for (char c : S) {
        if (c == '(') {
            stk.push(c);
        } else if (c == ')') {
            stk.pop();
        } else {
            break;
        }
    }

    cout << stk.size() << endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      ll div[1000001]={0};
      for(int i=1;i<1000001;i++){
        for(int j=i;j<1000001;j+=i){
          div[j]++;
        }
      }
      cin>>n;
      ll ans=0;
      for(int i=1;i<n;i++){
        ans+=div[n-i];
      }
      cout<<ans;
      
}

Measured memory_bytes: 11460
#include <cstdio>

inline int readin(){
	int x=0,c;
	for (;(c=getchar())<'0'||c>'9';);
	for (;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+c-48;
	return x;
}

int main(){
	int L=readin();
	int min=233,ans=0;
	for (int i=0;i<20;i++) if ((1<<i)&L) min=i,ans++;
	ans+=min*2;
	if (min==19) ans--;
	printf("20 %d\n",ans);
	for (int i=1;i<=min;i++) printf("%d %d %d\n%d %d %d\n",i,i+1,0,i,i+1,1<<(i-1));
	int x=min==19?524288:0;
	for (int i=0;i<19;i++) if ((1<<i)&L) printf("%d %d %d\n",i+1,20,x),x+=1<<i;
}

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

int main() {
  int n;
  double a, b, c, d, e, f, px, py, r;
  cin >> n;
  while (cin >> a >> b >> c >> d >> e >> f) {
    double aa = a * a;
    double bb = b * b;
    double cc = c * c;
    double dd = d * d;
    double ee = e * e;
    double ff = f * f;
    py = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee - ff)) /
         (2 * (e - a) * (b - d) - 2 * (c - a) * (b - f));
    if (c == a) {
      px = (2 * (b - f) * py - aa - bb + ee + ff) / (2 * (e - a));
    } else {
      px = (2 * (b - d) * py - aa - bb + cc + dd) / (2 * (c - a));
    }
    r = sqrt((px - a) * (px - a) + (py - b) * (py - b));
    cout << fixed << setprecision(3) << px << " " << py << " " << r << "\n";
  }
  return 0;
}


Measured memory_bytes: 3224
n,m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]

count = float('inf')
if n == 3:
    for i in range(100, 1000):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                 count = i
elif n == 2:
    for i in range(10, 100):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                count = i
elif n == 1:
    for i in range(0, 10):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                count = i

if count == float('inf'):
    print(-1)
else:
    print(count)


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

using namespace std;

int main(int argc, char const *argv[]) {
  int x, y, sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  string ans;
  
  for (size_t i = 0; i < abs(tx-sx); i++) ans.push_back('R');
  for (size_t i = 0; i < abs(ty-sy); i++) ans.push_back('U');
  for (size_t i = 0; i < abs(tx-sx); i++) ans.push_back('L');
  for (size_t i = 0; i < abs(ty-sy); i++) ans.push_back('D');
  ans.push_back('D');
  for (size_t i = 0; i < abs(tx-sx)+1; i++) ans.push_back('R');
  for (size_t i = 0; i < abs(ty-sy)+1; i++) ans.push_back('U');
  ans.push_back('L');
  ans.push_back('U');
  for (size_t i = 0; i < abs(tx-sx)+1; i++) ans.push_back('L');
  for (size_t i = 0; i < abs(ty-sy)+1; i++) ans.push_back('D');
  ans.push_back('R');

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


Measured memory_bytes: 256
n = int(input())
d_li = list(map(int,input().split()))
m = int(input())
t_li = list(map(int,input().split()))

d_li.sort()
t_li.sort()

check = 0

for i in range(n):
    if d_li[i] == t_li[check]:
        check += 1
        
    if check == m:
        print("YES")
        exit()
else:
    print("NO")
    


Measured memory_bytes: 127568
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)
const double PI=3.14159265358979323846;
int main() {
  double a,b,x; cin >> a >> b >> x;
  x/=a;
  if(x > (a*b)/2){
  double tantheta = 2*(a*b - x) / (a*a);
  double theta = atan(tantheta);
  theta *= (180 / PI);
  printf("%.16f", theta);
  }
  else{
  double tantheta = b*b / (2*x);
  double theta = atan(tantheta);
  theta *= (180 / PI);
  printf("%.16f", theta);
  }
    
}

Measured memory_bytes: 4080
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<vector<char> > s(H, vector<char>(W));
    REP(i,H){
        REP(j,W){
            cin >> s[i][j];
        }
    }
    REP(i,H){
        REP(j,W){
            //'#'の部分だけ判定
            if (s[i][j]=='.') continue;
            //隣接マスに'#'があればセーフ
            if (s[max(i-1,0)][j]=='#')continue;
            if (s[i][max(j-1,0)]=='#')continue;
            if (s[min(i+1,H-1)][j]=='#')continue;
            if (s[i][min(j+1,W-1)]=='#')continue;
            //ない場合は"No"
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int Linearsearch(int *,int,int);

int main(){
  int i,j=0,n,q;
  int S[10000+1],T[10000+1];

  scanf("%d",&n);

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

  scanf("%d",&q);

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

for(i=0;i<q;i++){
if(Linearsearch(S,n,T[i])==1)j++;
}

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

int Linearsearch(int S[],int n,int key){
  int i;

  for(i=0;i<n;i++){
    if(S[i] == key)return 1;
  }
  return 0;
}



Measured memory_bytes: 2088
s=int(input())
a=s//100
b=s%100
if (a==0 or a>=13) and (b==0 or b>=13):
  print("NA")
elif (a==0 or a>=13):
  print("YYMM")
elif (b==0 or b>=13):
  print("MMYY")
else:
  print("AMBIGUOUS")

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s0;
        if(!(cin >> s0))
            return 0;

        int a = s0.find('+');
        int b = s0.find('=');
        vector<string> s(3);
        s[0] = s0.substr(0, a);
        s[1] = s0.substr(a+1, b-a-1);
        s[2] = s0.substr(b+1);

        bool notZero = false;
        int n = 0;
        for(int i=0; i<3; ++i){
            if(s[i][0] == 'X' && s[i] != "X")
                notZero = true;
            n = max(n, (int)s[i].size() + 1);
        }
        for(int i=0; i<3; ++i)
            s[i] = string(n-s[i].size(), '0') + s[i];

        bool na = true;
        for(int i=0; i<=9; ++i){
            if(i == 0 && notZero)
                continue;

            vector<string> s1 = s;
            for(int j=0; j<3; ++j)
                replace(s1[j].begin(), s1[j].end(), 'X', (char)(i+'0'));

            bool ok = true;
            int c = 0;
            for(int j=n-1; j>=0; --j){
                int sum = s1[0][j] - '0' + s1[1][j] - '0' + c;
                c = sum / 10;
                sum %= 10;
                if(sum != s1[2][j] - '0'){
                    ok = false;
                    break;
                }
            }

            if(ok){
                na = false;
                cout << i << endl;
                break;
            }
        }

        if(na)
            cout << "NA" << endl;
    }
}

Measured memory_bytes: 0
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class ATherefore {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      n %= 10;
      if (n == 3) {
        cout << "bon" << endl;
      } else if (n==0 || n==1 || n==6 || n==8) {
        cout << "pon" << endl;
      } else {
        cout << "hon" << endl;
      }

    }
};

signed main() {
  ATherefore solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3656
// Problem : C - Repsept
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mk make_pair
#define fast                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x) (int)x.size()
#define mem(a, val) memset(a, val, sizeof(a))
#define deci(x) cout << fixed << setprecision(x);
#define bitcount(x) __builtin_popcountll(x)

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

const long long int mod = 1e9 + 7;
const long double EPS = 1e-12;
const int N = 1e5 + 20;

void solve() {
  ll k;
  cin >> k;
  set<ll> rem;
  bool flag = true;
  ll ans = -1, st = 1, sum = 0, i = 1;
  while (flag) {
    ll cur = 7 * st;
    st = (st * 10) % k;
    sum = (sum + cur) % k;
    if (sum % k == 0) {
      ans = i;
      flag = false;
    }
    if (rem.find((sum % k)) != rem.end()) {
      flag = false;
    }
    rem.insert((sum % k));
    i++;
  }

  cout << ans << '\n';
}
int main() {
  fast;
  ll t;
  t = 1;

  // cin>>t;

  while (t--) {
    solve();
  }

  return 0;
}


Measured memory_bytes: 50448
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007
#define BOX 200000

typedef long long ll;

#define rep(i, s, e) for(unsigned int i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)
#define so(a) sort(begin(a), end(a))
#define soR(a) sort(begin(a), end(a), greater<ll>())
#define uni(a) a.erase(unique(begin(a), end(a)), end(a))
#define sum(a) accumulate(begin(a), end(a), 0)


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; }

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A;
    rep(i, 0, M) {
        ll temp;
        cin >> temp;
        A.push_back(temp);
    }
    ll sum = sum(A);
    if (sum <= N) {
        cout << N - sum << endl;
    }
    else {
        cout << -1 << endl;
    }
    return 0;

}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define maxn 100005
using namespace std;
typedef pair<long long,long long> pii;
typedef vector<pii> vii;
typedef long long ll;
ll n,q;
string s;
ll sum[maxn];
int main()
{
    while(cin>>n>>q>>s)
    {
        for(int i=0;i<s.length();i++)
        {
            if(i==n-1) sum[i]=sum[i-1];
            else
            {
                sum[i]=sum[i-1];
                if(s[i]=='A'&&s[i+1]=='C') sum[i]++;
            }
        }
        //rep(i,n) cout<<sum[i]<<" ";
        while(q--)
        {
            int a,b;
            cin>>a>>b;
            a--;b--;
            cout<<sum[b-1]-sum[a-1]<<"\n";
        }

    }

}


Measured memory_bytes: 1920
int main(void){
        int a,b,c,d,e,f,sum,n=0;
        scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
        sum=a+5*b+10*c+50*d+100*e+500*f;

        if(sum>=1000)
        n=1;

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

        return 0;
}

Measured memory_bytes: 1836
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif

int search(const std::vector<unsigned> &a)
{
  unsigned N = a.size();
  
  std::vector<bool> f(N, false);
  f[0] = true;
  
  unsigned pos = 0, count = 0;
  while (pos != 1) {
    unsigned next = a[pos];
    
    if (f[next]) return -1;
    
    f[next] = true;
    
    ++count;
    
    pos = next;
  }
  
  return count;
}

int main()
{
  unsigned N;
  std::cin >> N;
  
  std::vector<unsigned> a(N);
  for (unsigned n = 0; n < N; ++n) {
    std::cin >> a[n];
    --a[n];
  }
  
  std::cout << search(a) << std::endl;
  
  return 0;
}

Measured memory_bytes: 640
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf
import Debug.Trace

readInt = ( readLn :: IO Int )
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >>= putStrLn . which "YES" "NO" . ( < 2 ) . uncurry (-) . ( maximum &&& minimum ) .  flip map ( map ( == ) "abc" ) .  ( length . ) . flip filter

Measured memory_bytes: 7164
#include<bits/stdc++.h>
#define mp make_pair
#define endl "\n"
#define v vector
#define b begin()
#define e end()
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

int main(){

    int n;
    string s;
    cin>>n>>s;
    int x=0,max_num = 0;
    for(int i=0;i<s.length();i++){
        if(s[i] == 'I'){
            x++;
        }
        else{
            x--;
        }
        if(x>max_num){
            max_num = x;
        }
    }
    cout<<max_num;
    return 0;

}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
	int n,m;
	cin >> n >> m;
	int a[100010],b[100010];
	vector<pair<int,int>> v;
	FOR(i,n){
		cin >> a[i] >> b[i];
		v.push_back(make_pair(a[i],b[i]));
	}
	sort(all(v));
	int cnt=0,ans=0;
	priority_queue<int> q;
	for(int i=1;i<=m;i++){
		for(int j=cnt;j<=n;j++){
			if(v[j].first!=i){
				cnt=j;
				if(!q.empty()){
					ans+=q.top();
					q.pop();
				}
				break;
			}else{
				if(j==n)break;
				q.push(v[j].second);
			}
		}
	}
	cout << ans << endl;


}

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

int main()
{
    int n, m; cin>>n>>m;
    vector<int> x(m);
    for(int i=0; i<m; ++i) cin>>x[i];
    sort(begin(x), end(x));
    vector<int> d;
    for(int i=1; i<m; ++i) d.push_back(x[i]-x[i-1]);
    sort(begin(d), end(d));
    long res=0;
    for(int i=0; i<m-n; ++i) res+=d[i];
    cout<<res<<endl;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ar array
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a[5];
  for(int i=0; i<5; i++)
    cin >> a[i];
  for(int i=0; i<5; i++){
    if(a[i]==0){
      cout << i+1;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>

int main(void) {
	int w,tm,lm = 4280;
	while (scanf("%d",&w ), w != -1){
		if (w <= 10){
			tm = 1150;
		}
		else if (w <= 20){
			tm = 1150 + 125 * (w - 10);
		}
		else if (w <= 30){
			tm = 1150 + 1250 + 140 * (w - 20);
		}
		else{
			tm = 1150 + 1250 + 1400 + 160 * (w - 30);
		}
		printf("%d\n",lm - tm);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
struct edge{
    ll p;//点
    ll w;//辺の重み*-1
};
vector<vector<edge> > graph(100000);
vector<ll> res(100000);
ll v,e,r;//vは頂点,eは辺,rは始点
void dijkstra(){
  for(int i = 0;i < v;i++)res[i] = pow(10,18);
    res[r] = 0;
    priority_queue<pair<ll,ll> > que;//重み、頂点
    que.push(make_pair(0,r));
    while(!que.empty()){
        edge now;
        now.p = que.top().second;
        now.w = que.top().first * -1;
        que.pop();
        if(res[now.p] < now.w)continue;
        for(int i = 0;i < graph[now.p].size();i++){
            if(res[graph[now.p][i].p] > now.w + graph[now.p][i].w){
                res[graph[now.p][i].p] = now.w + graph[now.p][i].w;
                que.push(make_pair(res[graph[now.p][i].p] * -1,graph[now.p][i].p));
            }
        }
    }
}
int main(){
  cin >> v >> e;
  for(int i = 0;i < e;i++){
        ll a,b,c;
        cin >> a >> b;//マイナスするか?気をつける
        c = 1;
        a--,b--;
        edge memoa = {b,c};
        edge memob = {a,c};
        graph[a].push_back(memoa);
        graph[b].push_back(memob);//無向グラフのときはこれを追加
   }
  vector<vector<ll>> cost(v,vector<ll>(v));
  for(int i = 0;i < v;i++){
    r = i;
    dijkstra();
    for(int j = 0;j < v;j++)cost[i][j] = res[j];
  }
  vector<int> num(v);
  for(int i = 0;i < v;i++)num[i] = i;
  ll res = 0;
  do{
    if(num[0] != 0)break;
    ll now = 0;
    for(int i = 1;i < v;i++){
      now += cost[num[i]][num[i - 1]];
    }
    //for(int i = 0;i < v;i++)cout << num[i];
      //cout << endl;
    //cout << now << endl;
    if(now == v - 1){
      res++;
      //for(int i = 0;i < v;i++)cout << num[i];
      //cout << endl;
      //cout << now << endl;
    }
    //cout << endl;
  }while(next_permutation(num.begin(),num.end()));
  cout << res << endl;
}

Measured memory_bytes: 3328
N = int(input())
A = list(map(int,input().split()))
A = [A[i]-i-1 for i in range(N)]
A = sorted(A)
cnt = 0
for i in range(N//2):
    cnt -= A[i]
for i in range(1,N//2+1):
    cnt += A[-i]
print(cnt)

Measured memory_bytes: 26360
#include<bits/stdc++.h>
using namespace std;
int N, M;
long long arr0[1010101];
long long arr1[1010101];
long long arr2[1010101];
long long ans = 0;
void add(int x, int y)
{
    if(y<x) y += M;
    if(y-x >= 2)
    {
        arr2[x+2] += 1;
        arr2[y+1] += x - y;
        arr2[y+2] += y - x - 1;
    }
    ans += y - x;
}
int main()
{
    scanf("%d%d", &N, &M);
    int ai; scanf("%d", &ai);
    for(int i=1; i<N; ++i)
    {
        int t; scanf("%d", &t); add(ai, t);
        ai = t;
    }
    for(int i=1; i<=2*M; ++i)
    {
        arr1[i] = arr1[i-1] + arr2[i];
        arr0[i] = arr0[i-1] + arr1[i];
    }
    long long maxv = 0;
    for(int i=1; i<=M; ++i)
        maxv = max(maxv, arr0[i] + arr0[i+M]);
    printf("%lld\n", ans - maxv);
}

















Measured memory_bytes: 10112
#include <stdio.h>
int main(void)
{
    int num_a,num_b;

    scanf("%d %d",&num_a,&num_b);

    if(num_a < num_b){
        printf("a < b");
    }else if(num_a > num_b){
        printf("a > b");
    }else{
        printf("a == b");
    }
    printf("\n");
    return (0);
}

Measured memory_bytes: 1828
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;

using namespace std;

const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int a;
	string s;
	cin >> a >> s;

	if (a >= 3200) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}


}

int main()
{

	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n;
    cin >> n;
    ll ret = INF;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ll cntM=0;
            ll now = n/i;
            while(now){
                cntM++;
                now/=10;
            }
            ret = min(ret,cntM);
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class program
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var elements = new List<long>();
        var max = (long)0;
        for (var i = 0; i < N; i++)
        {
            var num = long.Parse(Console.ReadLine());
            if (!elements.Contains(num))
            {
                elements.Add(num);
                max = max > num ? max : num;
            }
        }
        var prime = new bool[max + 1];
        for (var i = 2; i <= max; i++)
        {
            if (!prime[i])
            {
                var times = 2;
                while (true)
                {
                    if (i * times > max)
                    {
                        break;
                    }
                    else
                    {
                        prime[i * times] = true;
                        times++;
                    }
                }
            }
        }
        var count = 0;
        foreach (var num in elements)
        {
            if (!prime[num])
            {
                count++;
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 104432
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int L[10];
    for(int i=0;i<N;i++)
        cin >> L[i];
    
    // 降順ソート
    sort(L, L + N, greater<int>());
    int max = L[0], sum = 0;
    for(int i=1;i<N;i++)
        sum += L[i];

    if(max < sum)    
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}


template<typename F>
void all_permutations(int n,F f){
  vector<int> vs(n);
  iota(vs.begin(),vs.end(),0);
  do f(vs); while(next_permutation(vs.begin(),vs.end()));
}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> ps(n),qs(n);
  for(int i=0;i<n;i++) cin>>ps[i],ps[i]--;
  for(int i=0;i<n;i++) cin>>qs[i],qs[i]--;
  int a=-1,b=-1,cnt=0;
  auto f=
    [&](auto vs){
      if(ps==vs) a=cnt;
      if(qs==vs) b=cnt;
      cnt++;
    };
  all_permutations(n,f);
  cout<<abs(a-b)<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

mod = 998244353

n, k = map(int, input().split())
l = []
r = []
for _ in range(k):
    l_, r_ = map(int, input().split())
    l.append(l_)
    r.append(r_)
dp = [0] * (n + 1)
dp_csum = [0] * (n + 1)
dp[1] = 1
dp_csum[1] = 1
for i in range(2, n + 1):
    for j in range(k):
        left = i - r[j]
        right = i - l[j]
        if right >= 1:
            dp[i] += dp_csum[right] - dp_csum[max(left, 1) - 1]
            dp[i] %= mod
    dp_csum[i] = dp_csum[i - 1] + dp[i]
    dp_csum[i] %= mod
print(dp[-1])

Measured memory_bytes: 76848
#include <iostream>
#include<string.h>
using namespace std;

int main(){
  int m, f, r;
  int sum;
  cin >> m >> f >> r;
  while(true){
    if( m == -1 && f == -1 && r ==-1){
      break;
    }
    sum = m+ f;
    if(m == -1 || f == -1){
      cout << "F" << endl;
    } else if(sum >= 80){
      cout << "A" << endl;
    } else if(sum< 80 && 65<=sum){
      cout << "B" << endl;
    } else if(sum< 65 && 50<=sum){
      cout << "C" << endl;
    } else if(sum< 50 && 30<=sum ){
      if(r >= 50){
        cout << "C" << endl;
      } else {
        cout << "D" << endl;
      }
    } else {
      cout << "F" << endl;
    }
    cin >> m >> f >> r;
  }
}



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



const int maxn = 3005;
string s,t;
int dp[maxn][maxn];

int32_t main()
{
    cin >> s >> t;
    int n = s.size();
    int m = t.size();



    for(int i = 1;i<=n;i++){
        for(int j = 1;j <=m;j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }


    string ans = "";
    while(m!=0 && n!=0){
        if(dp[n][m] == dp[n-1][m])
            n--;
        else if(dp[n][m] == dp[n][m-1]){
            m--;
        }
        else{
            ans = s[n-1] + ans;
            m--;
            n--;
        }
    }



    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 38868
n,m,x = gets.split(' ').map(&:to_i)
costs =[]
skills = []
min = -1
(0...n).each do |i|
  line = gets.split(' ').map(&:to_i)
  costs << line[0]
  skills << line[1..-1]
end
(1...2 ** n).each do |i|
  marker = i.to_s(2).rjust(n, "0")
  total = Array.new(m,0)
  cost_total = 0
  (0...n).each do |j|
    next if marker[j] == "0"
    total.map!.with_index{|e,index| e + skills[j][index]}
    cost_total += costs[j]
  end
  min = cost_total if total.min >= x && (min > cost_total || min == -1)
end
puts(min)

Measured memory_bytes: 14420
use proconio::input;
fn main() {
    input!{
        mut S:String,
    }
    let m:Vec<&str>=["dream","dreamer","erase","eraser"].to_vec();
    'outer:loop{
        for s in &m{
            let S_cut=S.trim_end_matches(s);
            if S_cut!=S{
                S=S_cut.to_string();
                continue 'outer;
            }
        }
        break;
    }
    println!("{}",if S==""{"YES"} else {"NO"});

}


Measured memory_bytes: 2448