akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main(){
	ll a,b; cin >> a >> b;
	if (min(a,b)==1){
		if (max(a,b)==1){
			cout << 1 << endl;
		}else{
			cout << max(a,b) - 2 << endl;
		}
	}else{
		cout << (a-2)*(b-2) << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF (1LL<<60)
#define MOD 1000000007

int N, M;
int A[100000], B[100000];
vector<int> G[100000];
int U[100000], R[100000];
int repr[100000];

int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y];
  R[y] = 0;
}

bool same(int x, int y) {
  return find(x) == find(y);
}
vector<int> G2[100000];
bool used[100000];
long long dp[100000], sum[100000];

void dfs(int x) {
  sum[x] = B[x];
  if (G2[x].empty()) dp[x] = B[x];
  for (int t : G2[x]) {
    dfs(t);
    sum[x] += sum[t];
  }
  //dp[x] = max(dp[x], sum[x]);
  for (int t : G2[x]) {
    dp[x] = min(dp[x], max(dp[t] + (sum[x]-sum[t]), max(A[x]+sum[x]-B[x]-sum[t], A[t]+sum[x]-sum[t])));
  }
  dp[x] = min(dp[x], sum[x]-B[x]+max(A[x], B[x]));
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, N) cin >> A[i] >> B[i];
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  rep(i, N) U[i] = i, R[i] = 1, repr[i] = i;
  vector<P> ord;
  rep(i, N) ord.pb(P(A[i]-B[i], i));
  sort(all(ord));
  for (P p : ord) {
    int x = p._2;
    used[x] = true;
    for (int t : G[x]) if (used[t] && !same(x, t)) {
      assert(repr[find(x)] == x);
      int c = repr[find(t)];
      unite(x, t);
      repr[find(x)] = x;
      G2[x].pb(c);
      //cout<<x<<"->"<<c<<"\n";
    }
  }
  rep(i, N) dp[i] = INF;
  int root = ord.back()._2;
  assert(root == repr[find(0)]);
  dfs(root);
  long long m = dp[root];
  rep(i, N) m = max(m, A[i]);
  cout << m << "\n";
  return 0;
}


Measured memory_bytes: 23024
#include<bits/stdc++.h>
using namespace std;
const int Log=19;
int L,m;
int p2[Log+5];
vector<int> oa,ob,ow;
void add(int u,int v,int w)
{
	oa.push_back(u);
	ob.push_back(v);
	ow.push_back(w);
	m++;
	return;
}
int main()
{
	p2[0]=1;
	for(int i=1;i<=Log;i++) p2[i]=p2[i-1]*2;
	scanf("%d",&L);
	for(int i=1;i<=18;i++)
	{
		add(i,i+1,p2[i-1]);
		add(i,i+1,0);
	}
	int bac=0;
	for(int i=Log;i>=0;i--)
	{
		if(!(p2[i]&L)) continue;
		if(i==19)
		{
			add(19,20,p2[18]);
			add(19,20,0);
		}
		else add(i+1,20,bac);
		bac|=p2[i];
	}
	printf("20 %d\n",m);
	for(int i=0;i<(int)oa.size();i++) printf("%d %d %d\n",oa[i],ob[i],ow[i]);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
src = [input() for i in range(N)]
T = input()

before = after = 0
for s in src:
    if s.replace('?','z') < T:
        before += 1
    elif s.replace('?','a') > T:
        after += 1
print(*range(before+1, N-after+2))


Measured memory_bytes: 4084
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int i, j;
    int[] a;

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      a = new int[n];
      for(i = 0;i < n;i++)a[i] = sc.nextInt();

      i = 0;
      if(i >= n - 1 || a[i] != a[i + 1] - 1)out.print(a[i++]);
      else{
        for(j = i + 1;j < n;j++)if(j >= n - 1 || a[j] != a[j + 1] - 1){
          out.print(a[i] + "-" + a[j]);
          i = j + 1;
          break;
        }
      }
      for(;i < n;){
        if(i >= n - 1 || a[i] != a[i + 1] - 1)out.print(" " + a[i++]);
        else{
          for(j = i + 1;j < n;j++)if(j >= n - 1 || a[j] != a[j + 1] - 1){
            out.print(" " + a[i] + "-" + a[j]);
            i = j + 1;
            break;
          }
        }
      }
      out.println();
    }

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

Measured memory_bytes: 26144
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e3 + 10;
const ll INF = 1e18;
const ll LOG = 20;

ll n, m;
char grid[N][N];
bool isval(ll x, ll y){
	return (x > 0 && x <= n) && (y > 0 && y <= m);
}
ll dis[N][N];
ll a[] = {0, 0, 1, -1};
ll b[] = {1, -1, 0, 0};


void BFS(){
	queue<pll> q;
	memset(dis, 63, sizeof dis);
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			if (grid[i][j] == '#'){
				q.push({i, j});
				dis[i][j] = 0;
			}
		}
	}
	while (q.size()){
		pll fr = q.front();
		q.pop();
		//cout << fr.F << ' ' << fr.S << '\n'; 
		for (int i = 0; i < 4; i++){
			if (isval(fr.F + a[i], fr.S + b[i]) && dis[fr.F + a[i]][fr.S + b[i]] > dis[fr.F][fr.S] + 1){
				q.push({fr.F + a[i], fr.S + b[i]});
				dis[fr.F + a[i]][fr.S + b[i]] = dis[fr.F][fr.S] + 1;
			}
		}
		
	}
	return;
	
	
}


int main(){
	IOS;
	cin >> n >> m;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			cin >> grid[i][j];
		}
	}
	BFS();
	ll ans = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			ans = max(ans, dis[i][j]);
		}
	}
	cout << ans;
	
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 51380
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
#define MAX 100010
int dc=100000;
typedef long int li;

li que[2*MAX];
int head=0,tail=0;
void enque(li a){
  que[tail++]=a;
}
li deque(){
  return que[head++];
}
int comp(const void* a,const void* b){
  li x=*((li*)a),y=*((li*)b);
  return (x-y>0)?1:-1;
}
typedef struct{
  li b;
  li c;
}data;
data change[MAX];

int comp_c(const void* a,const void* b){
  data x=*((data*)a),y=*((data*)b);
  return (y.c-x.c>0)?1:-1;
}

int main(){
  if(df)printf("*** debug mode ***\n");
  int n,m,i;
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++){
    li a;
    scanf("%ld",&a);
    enque(a);
  }
  qsort(que,n,sizeof(li),comp);
  if(df){
    for(i=head;i<tail;i++)
      printf("%d ",que[i]);
    printf(":que\n");
  }
  for(i=0;i<m;i++){
    li b,c;
    scanf("%ld%ld",&b,&c);
    change[i].b=b;
    change[i].c=c;
  }
  qsort(change,m,sizeof(data),comp_c);
  if(df){
    for(i=0;i<m;i++)
      printf("%d(%d) ",change[i].c,change[i].b);
    printf(":change\n");
  }
  i=0;
  while(i<m && que[head]<change[i].c){
    int j;
    for(j=0;j<change[i].b;j++){
      if(que[head]>change[i].c)break;
      deque();
      enque(change[i].c);
    }
    if(df){
      for(i=head;i<tail;i++)
	printf("%d ",que[i]);
      printf(":que\n");
    }
    i++;
  }

  li sum=0;
  for(i=head;i<tail;i++){
    sum+=que[i];
  }

  printf("%ld",sum);
  return 0;
}


/// confirm df==0 ///


Measured memory_bytes: 4084
#include <iostream>

using namespace std;


int main()
{
      char s[17];
      char a[17]="CODEFESTIVAL2016";
      int cnt=0;
      cin >> s;
      for(int i=0;i<16;i++){
        if(s[i]!=a[i])cnt++;
      }
      cout << cnt << endl;

      return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
        
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k == X:
                ans += 1
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <cstring>

using namespace std;
char a[100005];
int main()
{
    int S = 0, n, k;

    cin >> n >> k;
    cin >> a;
    for(int i = 0; i < n; i++){
        if(a[i] == a[i+1]){
            S++;
        }
    }
    S = min(n - 1, S+k*2);
    cout << S;

}


Measured memory_bytes: 384
program test
	implicit none
	integer i,j,bit
	integer :: n=0,m=0,x=0, ans=100000000, money=0,count=0
	integer :: a(13,13)=0,c(13)=0, summ(13)=0
	integer, allocatable :: tmp(:)
    read (*,*) n,m,x
    allocate(tmp(m+1))
    do i=1,n
    	read *, tmp
    	c(i)=tmp(1)
    	do j=1,m
    		a(j,i)=tmp(j+1)
    	end do
    end do
    do bit=0,lshift(1,n)-1
    	do i=1,13
    		summ(i)=0
    	end do
    	money=0
    	do i=1,n
    		if(and(bit, lshift(1,i-1))/=0) then
    			do j=1,m
    				summ(j)=summ(j)+a(j,i)
    			end do
    			money=money+c(i)
    		end if
    	end do
    	do i=1,m
    		if(summ(i)<x) exit
    		count=count+1
    	end do
    	if(count==m) ans=min(ans,money)
    	count=0
    end do
    if(ans==100000000) then
    	write (*,'(i0)') -1
    else 
    	write (*,'(i0)') ans
    end if
    deallocate(tmp)
end program test

Measured memory_bytes: 2928
// clang-format off
#include <bits/stdc++.h>
using namespace std;





// #define int long long





#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    int n = in();
    if (n == 0) break;
    vector<int> x(n), y(n), r(n), c(n);
    rep(i, n) cin >> x[i] >> y[i] >> r[i] >> c[i];
    auto intersectCC = [&](int i, int j) {
      int r2 = (r[i] + r[j]) * (r[i] + r[j]);
      int d = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
      return d < r2;
    };
    auto intersect = [&](int t, int used) {
      bool f = false;
      rep(i, t) f |= (~used >> i & 1) && intersectCC(t, i);
      return f;
    };
    vector<int> dp(1 << n, -1);
    function<int(int)> dfs = [&](int used) {
      if (dp[used] != -1) return dp[used];
      cmax(dp[used], 0);
      rep(i, n) loop(j, i + 1, n) {
        if ((used >> i & 1) || (used >> j & 1) || c[i] != c[j]) continue;
        if (intersect(i, used) || intersect(j, used)) continue;
        cmax(dp[used], dfs(used | (1 << i) | (1 << j)) + 2);
      }
      return dp[used];
    };
    cout << dfs(0) << endl;
  }
}



Measured memory_bytes: 68456
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[5000];
signed main(){
	int n;scanf("%d",&n);
	int cnt=0;
	rep(i,n)scanf("%d",&a[i]),cnt+=a[i]-1;
	cout<<cnt<<endl;
}

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

int main() {
  int n, y;
  cin >> n >> y;
  for (int a=0; a<n+1; a++) {
    for (int b=0; b<(n+1)-a; b++) {
      int c = n - (a + b);
      if (a*10000 + b*5000 + c*1000 == y) {
        cout << a << " " << b << " " << c << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1"<< endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;
	string s[50];
	int t[50];
	cin >> n;
	int i;
	for (i = 0; i < n; i++) {
		cin >> s[i] >> t[i];
	}
	string x;
	cin >> x;
	int k;
	for (i = 0; i < n; i++) {
		if (s[i] == x) {
			k = i+1;
			
			break;
		}
	}
	int counter = 0;
	for (i = k; i < n; i++) {
		counter = counter + t[i];
	}
	cout << counter << endl;
	return 0;

}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main{
	public static int n;
	public static int A[];
	public static int B[];
	public static int C[] = new int[10000];
	public static StringBuilder sb = new StringBuilder();

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		A = new int[n];
		B = new int[n];

		for(int i = 0; i<n ;i++){
			A[i] = scan.nextInt();
			C[A[i]]++;
		}

		for(int i=1;i<10000;i++){
			C[i] = C[i-1]+C[i];
		}

		for(int i = n-1;i>=0;i--){
			B[C[A[i]]-1] = A[i];
			C[A[i]]--;
		}

		for(int i = 0; i < n-1 ;i++){
			sb.append(B[i]);
			sb.append(" ");
		}
		System.out.println(sb.toString()+B[n-1]);

	}

}

Measured memory_bytes: 623156
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	string x;
	cin>>x;
	if(x[2]==x[3] && x[4]==x[5])
	cout<<"Yes";
	else
	cout<<"No";	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(){
    int N, K;
    while(cin >> N >> K){
        int res = 0;
        vector<int> deg(N, 0);
        vector<int> next(N, -1);
        vector<int> dist(N, 0);
        for(int i=0;i<N;i++){
            cin >> next[i];
            --next[i];
            if(i == 0 && next[i]){
                ++res;
                next[i] = 0;
            }
            ++deg[next[i]];
        }
        queue<int> qu;
        for(int i=1;i<N;i++) if(!deg[i]) qu.push(i);
        while(!qu.empty()){
            int p = qu.front(); qu.pop();
            if(!p) break;
            if((next[p] && dist[p] == K-1) || (!p && !next[p])){
                ++res;
            } else {
                dist[next[p]] = max(dist[next[p]], dist[p]+1);
            }
            --deg[next[p]];
            if(!deg[next[p]]) qu.push(next[p]);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 1792
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>
#include <numeric>
 
#include <stdio.h>
#include <string.h>
 
using namespace std;
  
int main(int argc, char* argv[])
{
 
	int N;

	cin >> N;

	vector<int> a(N);

	for(int i=0;i<N;i++){
		cin >> a[i];
	}

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

	cout << a[N-1]-a[0] << endl;
 
	return 0;
 
}

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

const int N = 100050;
int dp[N];
int n,k,arr[N];

int rec(int pos)
{
    if(pos==n) return 0;
    int &ret=dp[pos];
    if(ret!=-1) return ret;
    ret=1e9;
    for(int i=1; i<=k; i++)
    {
        if(pos+i>n) break;
        ret=min(ret,abs(arr[pos]-arr[pos+i])+rec(pos+i));
    }
    return ret;
}

int main()
{
    memset(dp,-1,sizeof dp);
    scanf("%d %d",&n,&k);
    for(int i=1; i<=n; i++) scanf("%d",&arr[i]);
    printf("%d\n",rec(1));

}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, x[200100], y[200100], i, ans=-1, distx, disty;
    cin >> n;
    for(i=0;i<n;i++){
        long long tmpx, tmpy;
        cin >> x[i] >> y[i];
        tmpx=x[i];tmpy=y[i];
        x[i]-=tmpy;
        y[i]+=tmpx;
    }
    sort(x, x+n);
    sort(y, y+n);
    distx=x[n-1]-x[0];
    disty=y[n-1]-y[0];
    ans=max(distx, disty);
    cout << ans <<endl;
    return 0;
}

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

int main(){
  	string S;
  	cin >> S;
  	for(int i=0; i<S.length(); i++){
    	if((i+1)%2==0 && S[i]=='R'){
        	cout << "No" << endl;
          	return 0;
        }else if((i+1)%2==1 && S[i]=='L'){
        	cout << "No" << endl;
          	return 0;
        }
    }
  	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91
#include <utility>

template <class F> class fix_point : private F {
public:
  explicit constexpr fix_point(F &&f) : F(std::forward<F>(f)) {}

  template <class... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class F> constexpr decltype(auto) make_fix(F &&f) noexcept {
  return fix_point<F>(std::forward<F>(f));
}
#include <algorithm>
#include <iostream>
#include <map>
#include <utility>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const int n = scan<int>();
  const std::string s = scan<std::string>();
  for (const auto e : s) {
    std::cout << char('A' + (e - 'A' + n) % 26);
  }
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  for(int i = 0; i <= 10000; i++){
    if((B*i+C) % A == 0){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define pi          3.14159265358979323
#define M           998244353


void solve()
{
      ll n, m;
      cin>>n>>m;
      ll a[n];
      rep(i,0,n) cin>>a[i];
      sort(a, a+n);
      pll b[m];
      rep(i,0,m) cin>>b[i].S>>b[i].F;
      sort(b, b+m);
      reverse(b, b+m);
      ll ind=0;
      rep(i,0,m)
      {
             ll cnt=0;
             for(ind; ind<n && cnt<b[i].S; ind++)
             {
                    if(a[ind] >= b[i].F) break;
                    a[ind] = b[i].F;
                    cnt++;
             }
      }
      ll sum=0;
      for(ll x : a) sum += x;
      cout<<sum<<endl;
}


int main()
{
       speed_up;
       //pre();
       ll T=1;
       //cin>>T;
       while(T--) solve();
	return 0;
}


Measured memory_bytes: 2560
import java.util.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int sum = 0;
        int max_xy = Max(x,y);
        int min_xy = Min(x,y);
        int max_ab = Max(a,b);
        int max_num, min_num;
        if(max_xy == x){ max_num = a; min_num = b; }
        else           { max_num = b; min_num = a; }

        if( c*2 >= a+b ){
            sum = a*x + b*y;
        }
        if( c*2 < a+b ){
            if( c*2 >= max_num){
                sum = max_num * Math.abs(x-y) + 2 * min_xy * c;
            }
            else{
                sum = 2 * max_xy * c;
            }
        }
        /*if( c <= min){
            sum = c * Max(x,y) * 2;
        }*/
        System.out.println(sum);
    }
    public static int Max (int p, int q){
        int res;
        if( p >= q ) res = p;
        else         res = q;
        return(res);
    }
    public static int Min (int p, int q){
        int res;
        if( p <= q ) res = p;
        else         res = q;
        return(res);
    }
}

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,pi,qi;
    cin>>n;
    vector<string> str;
    string s,p,q,c;
    for(int i=0;i<n;i++){
        cin>>c;
        p+=c;
    }
    
    for(int i=0;i<n;i++){
        cin>>c;
        q+=c;
        s+=to_string(i+1);
    }

    str.push_back(s);
    while (next_permutation(s.begin(), s.end())){
        str.push_back(s);
    }
    
    for(int i=0;i<str.size();i++){
        if(str[i]==p) pi=i;
        if(str[i]==q) qi=i;
    }
    cout<<abs(pi-qi)<<endl;
}


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

int main()
{
	int S,h,m,s;
	
	cin>>S;
	h=S/3600;
	S=S%3600;
	m=S/60;
	s=S%60;
    cout <<h<<":"<<m<<":"<<s<<endl;

    return 0;
}

Measured memory_bytes: 1168
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().ToCharArray();
        Array.Sort(s);

        var ans = 'a';
        for (int i = 0; i < s.Length; i++)
        {
            if (ans == s[i])
            {
                ans++;
            }
        }

        if ('z' < ans)
        {
            Console.WriteLine("None");
        }
        else
        {
            Console.WriteLine(ans);
        }
    }
}

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

int main() {
    ll d, g;
    cin >> d >> g;
    vector<ll> dv(d);
    vector<ll> gv(d);
    for (int i = 0; i < d; ++i) {
        cin >> dv[i] >> gv[i];
    }
    ll ans = 1e9;
    for (int mask = 0; mask < (1 << d); ++mask) {
        int tmp = mask;
        ll score = g;
        ll cnt = 0;
        int last = 0;
        for (int i = 0; i < d; ++i) {
            if (tmp & 1) {
                score -= (dv[i] * 100 * (i + 1) + gv[i]);
                cnt += dv[i];
            } else last = i;
            tmp >>= 1;
        }
        if (score <= 0) ans = min(ans, cnt);
        else {
            for (int j = 0; j < dv[last]; ++j) {
                if (100 * (j + 1) * (last + 1) >= score) {
                    cnt += j + 1;
                    ans = min(ans, cnt);
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

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

int N;
int main(){
    scanf("%d",&N);
    printf("%s", N < 1000 ? "ABC" : "ABD");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    vector<string> S(3);
    REP(i,3)cin >> S[i];
    cout << S[0][0] << S[1][1] << S[2][2] << "\n";
}

Measured memory_bytes: 256
/**
 * @author Vicfred
 * 11/3/18
 */

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N, T;
        N = scanner.nextInt();
        T = scanner.nextInt();
        int minima = 999999;
        boolean found = false;
        for(int i = 0; i < N; ++i) {
            int c, t;
            c = scanner.nextInt();
            t = scanner.nextInt();
            if(t > T)
                continue;
            minima = Math.min(minima, c);
            found = true;
        }
        if(found)
            System.out.println(minima);
        else
            System.out.println("TLE");
    }
}


Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

#include <limits>
#include <limits.h>

struct WORK
{
	long S;
	long T;
	long X;
};

int main()
{
	int N, Q;
	std::vector<WORK> W;
	std::vector<long> D;

	std::cin >> N >> Q;
	W.resize(N);
	for (auto& w : W) {
		std::cin >> w.S >> w.T >> w.X;
	}
	D.resize(Q);
	for (auto& d : D) {
		std::cin >> d;
	}

	std::sort(W.begin(), W.end(), [](auto&a, auto&b)->bool{
		if (a.X != b.X)
			return a.X < b.X;
		return a.S < b.S;
	});

	std::map<long, WORK> WW; // 補正済み工事開始時刻 -> 補正済み工事

	WW.insert({LONG_MIN, {LONG_MIN, LONG_MIN+1, -1}});
	WW.insert({LONG_MAX-1, {LONG_MAX-1, LONG_MAX, -1}});

	for (auto w : W) {
		w.S -= w.X;
		w.T -= w.X;
//std::cout << "checking  " << w.S << " - " << w.T << " at " << w.X << "\n";

		auto it = WW.lower_bound(w.S); // S と同じかより大きい開始時刻を持つ工事
		--it;
//std::cout << it->second.S << " - " << it->second.T << "\n";
		while (it != WW.end() && it->second.S < w.T) {
//std::cout << it->second.S << " - " << it->second.T << "\n";
			auto jt = it;
			++jt;
			if (jt == WW.end())
				break;

			long s = w.S;
			long t = w.T;
			if (s < it->second.T)
				s = it->second.T;
			if (t < it->second.T)
				t = it->second.T;
			if (s > jt->second.S)
				s = jt->second.S;
			if (t > jt->second.S)
				t = jt->second.S;
			if (s != t) {
//std::cout << "inserting " << s << " - " << t << " at " << w.X << "\n";
				WW.insert({s, {s, t, w.X}});
			} else {
//std::cout << "no insert " << s << " - " << t << " at " << w.X << "\n";
			}
			it = jt;
		}
	}

	for (auto d : D) {
		auto it = WW.upper_bound(d);
		if (it != WW.begin()) {
			--it;
			if (it->second.S <= d && it->second.T > d) {
				std::cout << it->second.X << "\n";
			} else {
				std::cout << "-1\n";
			}
		} else {
			std::cout << "-1\n";
		}
	}
}


Measured memory_bytes: 23424
def trace() :
    li=[]
    for i in xrange(n):
        li.append(str(a[i]))
    print(" ".join(li))
    
n=input()
a=map(int,raw_input().split())

for i in xrange(n):
    v=a[i]
    j=i-1
    while j>=0 and a[j]>v:
        a[j+1]=a[j]
        j-=1
    a[j+1]=v
    trace()
    

Measured memory_bytes: 6444
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    Map<Integer, Integer> count = new HashMap<>();
    for (int i = 0; i < N; i++) {
      int D = scanner.nextInt();
      count.put(D, count.getOrDefault(D, 0) + 1);
    }
    int M = scanner.nextInt();
    int[] T = new int[M];
    for (int i = 0; i < M; i++) T[i] = scanner.nextInt();
    for (int i = 0; i < M; i++) {
      if (count.getOrDefault(T[i], 0) == 0) {
        System.out.println("NO");
        return;
      }
      count.put(T[i], count.get(T[i]) - 1);
    }
    System.out.println("YES");
  }
}


Measured memory_bytes: 143924
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def main():
    N, X = map(int, input().split())
    L = list(map(int, input().split()))
    count, D = 1, 0
    for l in L:
        D += l
        if D <= X:
            count += 1

    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
	int m;
	cin >> m;
	while (m--)
	{
		int p, x;
		cin >> p >> x;
		cout << sum - a[p] + x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,i=0;
	scanf("%d%d",&a,&b);
	if((a*25/2<=b*10)&&(b*10<(a+1)*25/2)){
		for(i=0;(b*10-i)*0.1==b;i++);
		printf("%d",(b*10-i+1));
	}
	else if((b*10<=a*12.5)&&(a*12.5<(b+1)*10)){
		while((a*25/2-i)*0.08==a) i++;
		printf("%d",(a*25/2-i+1));
	}
	else printf("-1");
	return 0;
}

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

bool solve(string S){
  vector<bool> dp(100010, false);
  dp[0] = true;

  vector<string> dreams = {"dreameraser", "dreamerase", "dreamer", "dream"};
  vector<string> erases = {"eraser", "erase"};

  int L = S.length();
  for(int i=5; i<=L; i++){
    for(int j=0; j<4; j++){
      int l = dreams[j].length();
      if(i-l >= 0 && dp[i-l] && S.substr(i-l, l) == dreams[j]){
        dp[i] = true;
      }
    }

    for(int j=0; j<2; j++){
      int l = erases[j].length();
      if(i-l >= 0 && dp[i-l] && S.substr(i-l, l) == erases[j]){
        dp[i] = true;
      }
    }

    //cout << dp[i] << endl;
  }

  return dp[L];
}

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

  if(solve(S)){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
} 

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

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

int main()
{
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, s = 0, sq = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        s += x;
        sq += x * x;
    }
    int x = s / n-1;
    int ans = n * x * x - 2 * s * x + sq;
    ++x;
    ans = min(n * x * x - 2 * s * x + sq, ans);
    ++x;
    ans = min(n * x * x - 2 * s * x + sq, ans);
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#define MAXN 100005
#define LL long long
using namespace std;

int n, l=1e9, r, ans, a[MAXN], b[MAXN], c[MAXN];
LL t[MAXN*2];

void add(int x, int y)
{
	for(; x<=2e5; x+=(x&-x)) t[x]+=y;
}

LL ask(int x)
{
	LL sum=0;
	for(; x; x-=(x&-x)) sum+=t[x];
	return sum;
}

bool check(int mid)
{
	LL num=0;
	memset(t, 0, sizeof(t));
	for(int i=1; i<=n; i++)
	{
		if(a[i]<mid) c[i]=-1;
		else c[i]=1;
		c[i]=c[i]+c[i-1];
	}
	for(int i=0; i<=n; i++)
	{
		num+=ask(c[i]+1e5);
		add(c[i]+1e5, 1);
	}
	return num>=1LL*(n+1)*n/4;
}


int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d", &a[i]);
		b[i]=a[i];
	}
	sort(b+1, b+n+1);
	l=1; r=n; 
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(b[mid])) ans=mid, l=mid+1;
		else r=mid-1;
	}
	printf("%d\n", b[ans]); 
}
 

Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	string s;
	cin >> s;

	int K;
	cin >> K;

	set<string> setstr;
	vector<string> vstr;

	for (int j = 0; j != s.length(); ++j) {
		for (int i = 1; i != s.length() - j + 1; ++i) {
//	for (int i = 1; i != s.length()+1; ++i) {
//		for (int j = 0; j != s.length() - i + 1; ++j) {
			const string tmpstr = s.substr(j, i);
			if (setstr.size() > 5) {
				if (*setstr.rbegin() > tmpstr) {
					setstr.erase(*setstr.rbegin());
					setstr.insert(tmpstr);
				}
				else {
					break;
				}
			}
			else {
				setstr.insert(tmpstr);
			}
			vstr.push_back(s.substr(j, i));
		}
	}

	set<string>::iterator it = setstr.begin();
	for (int i = 0; i != K-1; ++i) {
		it++;
	}
	cout << *it << endl;

	return 0;
}

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=(int)((int)1e5 +5);
int dp[N];int arr[N];
int solve(int i)
{
    if(i<2)return dp[i];
    else
    {
        if(dp[i]!=-1)return dp[i];
        else
        {
            dp[i]=min(solve(i-1)+abs(arr[i]-arr[i-1]),solve(i-2)+abs(arr[i-2]-arr[i]));
            return dp[i];
        }
    }
    return 0;
}

int main()
{ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
for(int i=0;i<N;i++)dp[i]=-1;
 int n;
 cin>>n;
 for(int i=0;i<n;i++)cin>>arr[i];
 dp[0]=0;dp[1]=abs(arr[0]-arr[1]);
 cout<< solve(n-1)<<endl;
}

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

using namespace std;
 
int main(){
    long long n,a,b,c,p,r,m;
    cin>>a>>p>>c>>r>>n;
    c=(c-a)*60;
    r=r-p;
    c=c+r;
    c=c-n;
    if(c>0)
    cout<<c;
    else
    cout<<0;

    return 0;
    }
 


Measured memory_bytes: 3632
#include <stdio.h>


int trsr_v[1001], trsr_w[1001], dp[1001][1001];


int main(void) {
    int W, N, v, w, i, case_id = 0;

    while (scanf("%d", &W) == 1 && W) {
        case_id++;
        scanf("%d", &N);
        for (i = 1; i <= N; i++) {
            scanf("%d,%d", &trsr_v[i], &trsr_w[i]);
        }

        for (i = 0; i <= N; i++) {
            for (w = 0; w <= W; w++) {
                dp[i][w] = w == 0? 0: -1;
            }
        }
        for (i = 1; i <= N; i++) {
            for (w = 1; w <= W; w++) {
                if (w < trsr_w[i]) {
                    dp[i][w] = dp[i-1][w];
                }
                else {
                    if (dp[i-1][w-trsr_w[i]] >= 0) {
                        v = dp[i-1][w-trsr_w[i]] + trsr_v[i];
                        dp[i][w] = v > dp[i-1][w]? v: dp[i-1][w];
                    }
                    else {
                        dp[i][w] = dp[i-1][w];
                    }
                }
            }
        }
        for (w = W; w > 0; w--) {
            if (dp[N][w] < 0) continue;
            if (dp[N][w] > dp[N][w-1]) {
                break;
            }
        }
        printf("Case %d:\n%d\n%d\n", case_id, dp[N][w], w);
    }
    return 0;
}

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

const int N_MAX = 1e4;
vector<int> dp(N_MAX + 1, -N_MAX);
int mat[] = {
  2, 5, 5,
  4, 5, 6,
  3, 7, 6};

int main() {
  int N, M; cin >> N >> M;
  vector<pair<int, int> > a;
  for(int i = 0; i < M; i++){
    int tem; cin >> tem;
    a.push_back(make_pair(tem, mat[tem - 1]));
  }
  sort(a.begin(), a.end(), greater<pair<int, int> >() );
  
  dp[0] = 0;
  for(int i = 0; i <= N; i++){
    for(int j = 0; j < M; j++){
      int um = a[j].second;
      if(i < um) continue;
      if(dp[i - um] < 0) continue;
      dp[i] = max(dp[i], dp[i - um] + 1);
    }
  }
  int keta = dp[N];
  for(int i = 0; i < keta; i++){
    for(int j = 0; j < M; j++){
      if(N < a[j].second) continue;
      if(dp[N - a[j].second] == dp[N] - 1) {
        cout << a[j].first;
        N -= a[j].second;
        break;
      }
    }
  }
  
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

ll count(ll n, ll c, ll d) {
	ll g = gcd(c, d);
	ll x = c / g * d;
	return  n - n / c - n / d + n / x;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << count(b, c, d) - count(a - 1, c, d) << endl;

	return 0;
}

Measured memory_bytes: 384
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:F[v]=t;heappush(H,(t,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:c,d,e=map(int,f[2:].split());E[c]+=[(e,d)];E[d]+=[(e,c)]
if'__main__'==__name__:
 for e in iter(r,'0 0\n'):s(*map(int,e.split()))


Measured memory_bytes: 6308
/**
 * B - Bounding
 * https://atcoder.jp/contests/abc130/tasks/abc130_b
 **/
#include<iostream>

using namespace std;

const int MAX_N = 100;
const int MAX_X = 10000;

int N, X;
int d[MAX_N+1], l[MAX_N+1];

void solve() {
    int ans = N + 1;
    for (int i = 0; i < N + 1; i++) {
        if (i == 0) {
            d[i] = 0;
        } else {
            d[i] = d[i-1] + l[i-1];
            if (d[i] > X) {
                ans = i;
                break;
            }
        }
    }
    cout << ans << endl;
}

int main() {
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> l[i];
    }
    solve();
}

Measured memory_bytes: 256
n = input()
l = list(map(int, input().split()))

cnt = 0
flg = True
while flg:
  for i in range(len(l)):
    if l[i] % 2 == 0:
      l[i] /= 2
    else:
      flg = False
      break
  if flg:
    cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n, M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for( v = 0; v < n; v++){
    if( M[u][v] == 0)continue;
    if(color[v] == WHITE ){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}
void dfs(){
  int u;
  for( u = 0;u < n; u++)color[u] = WHITE;
  tt = 0;
  for(u = 0; u < n; u++){
    if(color[u] == WHITE)dfs_visit(u);
  }
  for(u = 0; u < n; u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u, v, k, i, j;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    for(j = 0;j < n; j++)M[i][j] = 0;
  }
  for(i = 0; i < n; i++){
    scanf("%d %d",&u,&k);
    u--;
    for( j = 0; j < k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e5)+10;
int n,a[3];
char s[maxn][3];
char ans[maxn];
void No() { printf("No\n"); exit(0); }
void Yes() {
	printf("Yes\n");
	for (int i=1;i<=n;i++) printf("%c\n",ans[i]);
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	read(a[0]); read(a[1]); read(a[2]);
	for (int i=1;i<=n;i++) {
		scanf("%s",s[i]+1);
	}
	s[n+1][1]='A',s[n+1][2]='B';
	int x,y,z,p,q;
	for (int i=1;i<=n;i++) {
		x=s[i][1]-'A',y=s[i][2]-'A';
		if (!a[x]&&!a[y]) No();
		if (!a[x]) z=x;
		else if (!a[y]) z=y;
		else {
			if (a[y]==1) {
				p=s[i+1][1]-'A',q=s[i+1][2]-'A';
				if (y==p||y==q) z=y; else z=x;
			} else z=x;
		}
		a[z]++;
		a[x+y-z]--;
		ans[i]='A'+z;
	}
	Yes();
	
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 4172
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<int> a(n);
	for (auto &v : a) {
		cin >> v;
	}

	vector<int> left(n + 1, 0), right(n + 1, 0);
	for (int i = 0; i < n; i++) {
		left[i + 1] = gcd(left[i], a[i]);
	}

	for (int i = n - 1; i >= 0; i--) {
		right[i] = gcd(right[i + 1], a[i]);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int l = left[i];
		int r = right[i + 1];

		ans = max(ans, gcd(l, r));
	}

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


Measured memory_bytes: 1408
s = input()
i, n = 0, len(s)
res = [0] * n
while i < n:
    j = i
    while j < n and s[j] == s[i]: j += 1
    if s[i] == 'R':
        k = j - 1
        while i < j:
            if (k - i) & 1: res[j] += 1
            else: res[j - 1] += 1
            i += 1
    else:
        k = i
        while i < j:
            if (i - k) & 1: res[k - 1] += 1
            else: res[k] += 1
            i += 1
print(' '.join(map(str, res)))

Measured memory_bytes: 10484