akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>
#include <regex.h>

#define lli long long int
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)<0?-(a):(a))
#define alloc(type,size) calloc(sizeof(type),size)

#define N 1020

typedef struct {
	double x;
	double y;
	double r;
} circle;


typedef struct node {
	struct branch {
		struct branch *next;
		struct node *below;
		double cost;
	} *branch;
	bool bl;
	bool vs;
	double val;
} node;
typedef struct branch branch;

typedef struct heap {
	node *nd;
	double val;
} hp;


circle point[N];
int n;

void push_back(node *a,node *b,branch *c){
	c->next = a->branch;
	c->below = b;
	a->branch = c;
	return;
}
void hp_push(hp x,hp *heap,int *heap_size){
	int i = (*heap_size)++;
	while(i>0){
		int p = (i-1)/2;
		if(heap[p].val < x.val) break;
		heap[i] = heap[p];
		i = p;
	}
	heap[i] = x;
}

hp hp_pop(hp *heap,int *heap_size){
	hp ret = heap[0];
	hp x = heap[--*heap_size];
	int i = 0;
	while(i*2+1 < *heap_size){
		int a = i*2+1;
		int b = i*2+2;
		if(b < *heap_size && heap[b].val < heap[a].val)a = b;
		if(heap[a].val >= x.val)break;
		heap[i] = heap[a];
		i = a;
	}
	heap[i] = x;
	return ret;
}

void dijkstra(node *start,hp *heap,int *heap_size){
	branch *br;
	if(start->bl){
		if(*heap_size) return dijkstra(hp_pop(heap,heap_size).nd,heap,heap_size);
		else return;
	}

	start->bl = true;
	for(br=start->branch;br;br=br->next){
		if(br->below->bl) continue;
		if(br->below->val > start->val+br->cost){
			br->below->val = start->val+br->cost;
			hp x;
			x.nd = br->below;
			x.val = br->below->val;
			hp_push(x,heap,heap_size);
		}else if(br->below->vs == false){
			br->below->val = start->val+br->cost;
			br->below->vs = true;
			hp x;
			x.nd = br->below;
			x.val = br->below->val;
			hp_push(x,heap,heap_size);
		}
	}
	if(*heap_size){
		return dijkstra(hp_pop(heap,heap_size).nd,heap,heap_size);
	}
}
void init(node *nd,int n){
	int i;
	for(i=1;i<=n;i++){
		nd[i].bl = false;
		nd[i].val = 0;
	}
}


double dist(circle a,circle b){
	double x = a.x-b.x;
	double y = a.y-b.y;
	double d = sqrt(x*x+y*y)-a.r-b.r;
	return d<0.0?0.0:d;
}

int main(void){
	int i,j;
	double m;
	node *nd;
	hp *heap;
	branch *br;
	int *heap_size = alloc(int,1);

	scanf("%lf%lf",&point[0].x,&point[0].y);
	scanf("%lf%lf",&point[1].x,&point[1].y);
	scanf("%d",&n);
	n+=2;
	nd = alloc(node,n+n);
	br = alloc(branch,n*n+n);
	heap = alloc(hp,n*n+n);
	for(i=2;i<n;i++){
		scanf("%lf%lf%lf",&point[i].x,&point[i].y,&point[i].r);
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			br->cost = dist(point[i],point[j]);
			push_back(&nd[i],&nd[j],br++);
		}
	}
	dijkstra(&nd[1],heap,heap_size);
	printf("%.10lf\n", nd[0].val);

    return 0;
}
















Measured memory_bytes: 27648
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n;
   cin >> n;
   string c;
   cin >> c;
   int j = n - 1;
   int ans = 0;
   for (int i = 0; i < n; i++) {
      while (i < j && c[j] == 'W')
         j--;
      if (i > j) break;
      if (c[i] == 'W' && i < j) {
         c[i] = 'R';
         c[j] = 'W';
         ans++;
      }
   }
   rep(i, 0, n - 1) {
      if (c[i] == 'W' && c[i + 1] == 'R') {
         c[i + 1] = 'W';
         ans++;
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3764
/**
 *    created by : PawPaw       
**/

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

#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LL long long
#define N 1000001
#define PB push_back
#define MP make_pair


int solve(){
  string s;
  cin >> s;
  if(s == "SUN") cout << "7\n";
  if(s == "MON") cout << "6\n";
  if(s == "TUE") cout << "5\n";
  if(s == "WED") cout << "4\n";
  if(s == "THU") cout << "3\n";
  if(s == "FRI") cout << "2\n";
  if(s == "SAT") cout << "1\n";
  return 0;
}

void fun(){
  int t = 1;
  // cin >> t;
  while(t--) solve();
} 

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

  fun();
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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(){
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N-1);
  rep(i, N) {
    cin >> A[i];
    A[i]--;
  }
  rep(i, N) cin >> B[i];
  rep(i, N-1) cin >> C[i];
  int ans = 0;
  rep(i, N) {
    ans += B[A[i]];
    if(i < N-1 && A[i]+1 == A[i+1])
      ans += C[A[i]];
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    int n;
    long long dp[35] = {0};

    dp[0] = 1;
    dp[1] = 2;
    dp[2] = 4;

    for (int i = 3; i < 30; i++) {
        dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
    }

    while (1) {
        cin >> n;
        if (n - 1 == -1) break;

        long long ans = 0;
        ans = dp[n - 1] / 3650;
        if (dp[n - 1] % 3650) ans++;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  if (a == 0) {
    cout << 1 << '\n';
  }
    if (b == 0) {
    cout << 2 << '\n';
  }
  if (c == 0) {
    cout << 3 << '\n';
  }
  if (d == 0) {
    cout << 4 << '\n';
  }
  if (e == 0) {
    cout << 5 << '\n';
  }
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		SomethingOnIt solver = new SomethingOnIt();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}

	static class SomethingOnIt {

		private Scanner scanner;
		private String s;
		private String answer;

		public SomethingOnIt() {
			scanner = new Scanner(System.in);
		}

		public void readInput() {
			s = scanner.next();
		}

		public void solve() {
			int price = 700;
			for(String t : s.split("")) {
				if(t.equals("o")) {
					price += 100;
				}
			}
			answer = String.valueOf(price);
		}

		public void writeOutput() {
			System.out.println(answer);
		}

	}


}


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

int main(){
  int a;
  int b;
  cin >> a >> b;
  if(a==b){
  cout << 0 << endl;
    
  }
  else if(a!=b){
    if((a+b)%2==0){
      cout << (a+b)/2 << endl;
    }
    else{
      cout << "IMPOSSIBLE" << endl;
    }
  }
}




    


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

int main() {
    int a, b; cin >> a >> b;
    for(int i = 0; i <= 20000; ++i) {
        int A = i * 0.08;
        int B = i * 0.10;
        if(a == A && b == B) {
            cout << i << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int wro[100][100];
// int b[100][100];
void mainmain(){
	int T,P,R;
	while(cin>>T>>P>>R,T||P||R){
		vector<pii> res(T);
		vector<pair<pii,int> > ans;
		rep(i,T){
			res[i]=mkp(0,0);
		}
		rep(i,100){
			rep(j,100){
				wro[i][j]=0;
				// b[i][j]=0;
			}
		}
		rep(i,R){
			int a,b,c;
			string s;
			cin>>a>>b>>c>>s;
			if(s=="WRONG"){
				wro[a-1][b-1]++;
			}
			else{
				res[a-1].F++;
				res[a-1].S+=1200*wro[a-1][b-1]+c;
			}
		}
		rep(i,T){
			ans.PB(mkp(mkp(-res[i].F,res[i].S),i));
		}
		sort(ALL(ans));
		rep(i,T){
			cout<<ans[i].S+1<<" "<<-ans[i].F.F<<" "<<ans[i].F.S<<endl;
		}
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    if(n<=999){
        Cout("ABC");
    }
    else Cout("ABD");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n;
  cin >> n;
  vi L(n);
  rep(i,n) cin >> L[i];
  SORT(L);
  int ans = 0;
  rep(b,n)rep(a,b) {
    int ab = L[a]+L[b];
    int r = lower_bound(rng(L),ab) - L.begin();
    int l = b+1;
    // c = [l,r)
    ans += max(0,r-l);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 200015

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

int N,K,N1,a;
set<int>  s;

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> K;

    for(int i=1;i<=K;i++){
        cin >> N1;
        for(int j=1;j<=N1;j++)
            cin >> a, s.insert(a);
    }

    cout << N-s.size();






}


Measured memory_bytes: 3656
#include<stdio.h>
#include<math.h>
#define M 1000000
#define N 1000
#define ROOP(i,a,b) for(i = a;i < b;i++) //* [a,b)

//* important!!!
//* dp[y(i)][x(j)]
int dp[N+2][N+2];
int board[N+2][N+2],prime[M+1];

void init();
void print();
	
int main(){
	int i,j,k,l,m,n;
	int x,y;
	int cnt,ans,max;
	int q;
	//int* tmp1;
	//int* tmp2;

	init();
	//print();

	while(scanf("%d%d",&m,&n),m+n){
		ROOP(x,1,N+1)ROOP(y,1,N+1)if(board[y][x] == n)goto BREAK;
		BREAK:

		ROOP(i,1,N+1)ROOP(j,1,N+1)dp[i][j] = 0;
		
		dp[y][x] = (prime[n] == 1);
		max = dp[y][x];
		ans = (max?n:0);
		q = sqrt(m-1)/2+1;

		i = y;
		while(i < q+501 && i < N){
			j = x-(i-y);
			if(j <= 0)j = 1;
			while(j <= x+(i-y) && j <= N+1){
				ROOP(k,-1,2){
					//tmp1 = &(board[i+1][j+k]);
					//tmp2 = &(dp[i+1][j+k]);
					if(board[i+1][j+k] > m)continue;
					if(j+k == 0 || j+k == 1001)continue;
					if(dp[i][j]+prime[board[i+1][j+k]] > dp[i+1][j+k])
						dp[i+1][j+k] = dp[i][j]+prime[board[i+1][j+k]];
					if(max == dp[i+1][j+k] && prime[board[i+1][j+k]])
						if(ans < board[i+1][j+k])
							ans = board[i+1][j+k];
					if(max < dp[i+1][j+k]){
						max = dp[i+1][j+k];
						ans = board[i+1][j+k];
						//printf("%d %d\n",max,ans);
					}
				}
				j++;
			}
			i++;
		}
		printf("%d %d\n",max,ans);
	}
	return 0;
}

void init(){
	int i,j;
	int dir,x,y,nowx,nowy;
	int vecx[4] = { 1, 0,-1, 0};
	int vecy[4] = { 0, 1, 0,-1};
	
	//* set prime
	prime[2] = 1;
	for(i = 3;i <= M;i += 2)prime[i] = 1;
	for(i = 3;i*i <= M;i += 2)
		if(prime[i])for(j = i*i;j <= M;j += i)prime[j] = 0;

	//* make wall around the board
	ROOP(i,0,N+2){
		board[0][i] = 1;
		board[i][0] = 1;
		board[N+1][i] = 1;
		board[i][N+1] = 1;
	}

	//* set board
	dir = 0;x = 0;y = 1;
	for(i = M;i >= 0;i--){	//* fill from the outside
		nowx = x+vecx[dir];
		nowy = y+vecy[dir];
		if(board[nowy][nowx]){//* if hit the wall
			dir = (dir + 1)%4;
			nowx = x+vecx[dir];
			nowy = y+vecy[dir];
		}
		board[nowy][nowx] = i;
		x = nowx;y = nowy;
	}
}

void print(){
	int i,j;
	int m = 1039,n = 1;
	int q;
	int x,y;

	ROOP(x,1,N+1)ROOP(y,1,N+1)if(board[y][x] == n)goto BREAK;
	BREAK:

	q = sqrt(m)/2+1;printf("%d %d\n\n",y,x);
	for(i = 0;y+i < 501+q;i++){
		for(j = 0;x+j < 501+q;j++){
			printf("%4d ",board[y+i][x+j]);
		}puts("");
	}
}













				

Measured memory_bytes: 12348
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

int res;

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

    int N,X,T;
    cin >> N >> X >> T;
    if(N%X == 0){
        cout << N/X*T << endl;
    }else{
        cout << (N/X+1)*T << endl;

    }
return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n,m;
	cin>>n>>m;
	
	vi a(n);
	REP(i,n) cin>>a[i];
	sort(ALL(a),greater<int>());
	
	int sum=0;
	REP(i,n) sum+=a[i];
	
	debug(sum*(1.0/(4*m)));
	REP(i,m){
		if(a[i]<sum*(1.0/(4*m))){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }

//original problem

int prime[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
string S;
int B;
int decomposition_of_numbers[101];
int prime_filling_up[101];

int main() {
    string S, T;
    cin >> S >> T;
    bool ans = false;
    rep(i, 101) {
        if(S == T) {
            ans = true;
            break;
        }
        char temp = S[S.size() - 1];
        for(int i = S.size() - 1; i > 0; --i) {
            S[i] = S[i - 1];
        }
        S[0] = temp;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int k,x,i;
	scanf("%d %d",&k,&x);
	for(i=x-k+1;i<=x+k-1;i++){
		if(i>x-k+1){
			printf(" ");
		}
		if(i>=-1000000&&i<=1000000){
			printf("%d",i);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);


struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 19;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}


void solve() {
	int n, m; cin >> n >> m;
	vector<vector<int>> a(n, vector<int>(m));
	vector<int> c(n);
	int x; cin >> x;
	rep(i, n) {
		cin >> c[i];
		rep(j, m)cin >> a[i][j];
	}
	int ans = mod;
	rep(i, (1 << n)) {
		int cost = 0;
		rep(j, n)if (i&(1 << j))cost += c[j];
		vector<int> s(m);
		rep(j, n)rep(k, m) {
			if (i&(1 << j)) {
				s[k] += a[j][k];
			}
		}
		bool valid = true;
		rep(k, m)if (s[k] < x)valid = false;
		if (valid) {
			ans = min(ans, cost);
		}
	}
	if (ans == mod)ans = -1;
	cout << ans << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init_f();
	//init();
	//int t; cin >> t;rep(i,t)
	solve();
	stop
		return 0;
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	for(int i=0;i<s.size();i++)
	{
		ans += s[i] - '0';
	}
	cout << ((ans%9)? "No":"Yes");
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (int)(a); v < (int)(b); ++v)
#define FORE(v, a, b) for(int v = (int)(a); v <= (int)(b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

void split(string str, char chr, vector< string > *res){
	stringstream ss(str);
	string itm;
	while(getline(ss, itm, chr)){
		(*res).PB(itm);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string expr;
	vector< string > clause;
	
	while(cin >> expr, expr != "#"){
		clause.CLR();
		split(expr, '|',  &clause);
		bool result = false;
		
		for(vector< string >::iterator it = clause.begin(); it != clause.end(); ++it){
			it->erase(it->begin());
			it->erase(it->end()-1);
			
			vector< string > literal;
			vector< pair< char, int > > lit(3);
			
			split(*it, '&', &literal);
			
			REP(i, 3){
				if(literal[i][0] == '~'){
					lit[i] = make_pair< char, int >(literal[i][1], 1);
				}else{
					lit[i] = make_pair< char, int >(literal[i][0], 0);
				}
			}
			
			bool temp = true;
			REP(i, 3){
				REP(j, 3){
					if(i != j){
						if(lit[i].first == lit[j].first){
							if(lit[i].second != lit[j].second){
								temp = false;
							}
						}
					}
				}
			}
			if(temp){
				result = true;
				break;
			}
		}
		
		cout << (result ? "yes" : "no" ) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1224
n = int(input())
s = input()


score = s[1:].count("E")
result = score

for i in range(1,n):
    if(s[i]=="E"):
        score -= 1
    if(s[i-1]=="W"):
        score += 1
    
    if(score < result):
        result = score

print(result)

Measured memory_bytes: 3676
#include <cstdio>
#include <cstdlib>
#include <iostream>

int main() {
	const int size = 21;
	char str[size];
	std::scanf("%s", &str);

	for (int i = size - 1; i >= 0; i--)
		if (48 <= str[i] && str[i] <= 57)
			std::cout << str[i];
		else if(97 <= str[i] && str[i] <= 122)
			std::cout << str[i];

	std::cout << std::endl;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define dbl double
#define pi acos(-1)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pb push_back

priority_queue<ll>pq;
ll ara[1000006];
ll p[100005];
map<ll,ll>vis;

int main()
{
    ll a,b,t;;
    for(ll i=1; i<=9; i++)
    {
        sc1(ara[i]);
    }
    ll n,item;
    sc1(n);
    for(ll i=1; i<=n; i++)
    {
        sc1(item);
        vis[item]++;
    }
    if((vis[ara[2]]!=0 && vis[ara[5]]!=0 && vis[ara[8]]!=0) ||(vis[ara[4]]!=0 && vis[ara[5]]!=0 && vis[ara[6]]!=0) ||(vis[ara[1]]!=0 && vis[ara[2]]!=0 && vis[ara[3]]!=0) || (vis[ara[1]]!=0 && vis[ara[4]]!=0 && vis[ara[7]]!=0) || (vis[ara[7]]!=0 && vis[ara[8]]!=0 && vis[ara[9]]!=0) || (vis[ara[3]]!=0 && vis[ara[6]]!=0 && vis[ara[9]]!=0) || (vis[ara[1]]!=0 && vis[ara[5]]!=0 && vis[ara[9]]!=0) || (vis[ara[3]]!=0 && vis[ara[5]]!=0 && vis[ara[7]]!=0))
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)

ll maxn=365;
ll d=0;
ve <ll> c(26);
ve <ve <ll>> v(maxn,ve <ll> (26));
ve <ll> last(26,-1);
ve <ll> assigned(maxn,-2);
ll ini=0;
//ll a[26][365][2];

ll score(){
	ll sats=0;
	FOR(i,0,d){
	FOR(j,0,26){
		sats-=c[j]*(i-last[j]);
	 }
	ll take=assigned[i];
	sats+=v[i][take]+c[take]*(i-last[take]);
	last[take]=i;
	//cout<<sats<<"\n";
}
return sats;
}

pair <ll,ll> fun1(ll da,ll q){

ll x1=-1,x2=d;
FORR(i,da,0)
if(assigned[i]==q){
	x1=i;
	break;
}
FOR(i,da+1,d)
if(assigned[i]==q){
	x2=i;
	break;
}
return make_pair(x1,x2);
}

ll modify(ll da,ll q){
pair <ll,ll> a1=fun1(da,assigned[da]);
pair <ll,ll> a2=fun1(da,q);
ll z=ini;
ll f=assigned[da];
z-=v[da][f];
z-=c[f]*(da-a1.F)*(a1.S-da);
z+=v[da][q];
z+=c[q]*(da-a2.F)*(a2.S-da);
return z;
}

void change(ll da,ll q){
 	assigned[da]=q;
}





int main(){


    FAST
//	PRECISE


cin>>d;
FOR(i,0,26)
cin>>c[i];



FOR(i,0,d)
	FOR(j,0,26)
		cin>>v[i][j];
set <tuple <ll,ll,ll>,greater <tuple<ll,ll,ll>> > s;
FOR(i,0,d){
FOR(j,0,26)
s.insert({v[i][j]-c[j]*c[j],i,j});
} 


ve <ll> dummy(d);
FOR(i,0,d){
dummy[i]=rand()%26;
}
assigned=dummy;
ini=score();


while(!s.empty()){
	ll x1=GET(*s.begin(),1);
	ll x2=GET(*s.begin(),2);
	ll z=modify(x1,x2);
	if(z>ini){
		ini=z;
		change(x1,x2);
	}
	s.erase(s.begin());
}

ll it=1000000;
while(it>0){
	it--;
	ll x1=rand()%d;
	ll x2=rand()%26;
	ll z=modify(x1,x2);
	if(z>ini){
		ini=z;
		change(x1,x2);
	}
}

FOR(i,0,d)
cout<<assigned[i]+1<<"\n";




return 0;
 }

Measured memory_bytes: 4324
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define mp           make_pair
#define int          long long
#define uint         unsigned long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define repr(i,x,m)  for(int i=x;i>=m;i--)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define vs           vector<string>
#define pi           pair<int,int>
#define di           deque<int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define pqs          priority_queue<int,vi,greater<int> >
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define noob         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int fac[2000005]={0};
void factorial(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=((i%MOD)*(fac[i-1]%MOD))%MOD;}
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int ncr(int n,int r){return ((fac[n]*power(fac[r],MOD-2))%MOD*power(fac[n-r],MOD-2))%MOD;}

void ram5564()
{
    int n;
    cin>>n;
   
    vi v;
    while(n>0)
    {
        n-=1;
        v.pb(n%26);
        n/=26;
        
        
    }
    string s="";
    map<int,char>m1;
    char ch='a';
    rep(i,0,26)
    {
      m1[i]=ch;
      ch+=1;
    }
     
     for(auto x:v)
        s+=m1[x];
    reverse(all(s));
    cout<<s;
}

signed main()
{
        noob
        // #ifndef ONLINE_JUDGE
        //  freopen("input.txt","r",stdin);
        //  freopen("output.txt","w",stdout);
        //  #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 3616
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long n, k, c;
std::string s;

bool workable(long x){
    if(s[x] == 'o'){
        return true;
    }else{
        return false;
    }
}

int main(){
    scanf("%ld%ld%ld", &n, &k, &c);
    std::cin >> s;
    long l[n], r[n];
    long vis = 0;
    for(int i = 0; i < k; i++){
        for( ; !workable(vis); vis++);
        l[i] = vis;
        vis += c+1;
    }
    /*
    for(int i = 0; i < k; i++){
        printf(" %ld", l[i]);
    }
    printf("\n");
    //*/

    vis = n-1;
    for(int i = k-1; i >= 0; i--){
        for( ; !workable(vis); vis--);
        r[i] = vis;
        vis -= c+1;
    }
    /*
    for(int i = 0; i < k; i++){
        printf(" %ld", r[i]);
    }
    printf("\n");
    //*/

    for(long i = 0; i < k; i++){
        if(l[i] == r[i]){
            printf("%ld\n", r[i] + 1);
        }
    }
}


Measured memory_bytes: 4996
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n,ans;
map<pii,int> o; 
int main(){
    cin>>n;
    int ans;
    for(int i=1;i<=n;i++){
        int fir=i;
        while(fir>=10) fir/=10;
        int lst=i%10;
        o[mp(fir,lst)]++;
    }
    for(int i=1;i<=n;i++){
        int fir=i;
        while(fir>=10) fir/=10;
        int lst=i%10;
        ans+=o[mp(lst,fir)];
    }
    cout<<ans<<endl;
    return 0;
}

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

def sep_to_1(n):
    sep_mon=n
    count=0
    mons_num=1
    sum_sep_count=0
    while sep_mon!=1:
        count+=1
#         print("stage",count)
        sep_mon=sep_mon//2
        sum_sep_count+=mons_num
        mons_num=2*mons_num
        
#         print("sep_mon",sep_mon)
#         print("mons_num",mons_num)
#         print("sum_sep_count",sum_sep_count)
    return sum_sep_count+mons_num

print(sep_to_1(N))


Measured memory_bytes: 38384
#include <stdio.h>
int main(void)
{
    int  N, C, s, t, c;
    int  i, j, sum, max, v[30][100000]={{0}};
    
    scanf("%d %d", &N, &C);
    for(i = 0; i < N; i++){
        scanf("%d %d %d", &s, &t, &c);
        for(j = s-1; j < t; j++){
            v[c-1][j] = 1;
        }
    }
    max = 0;
    for(j = 1; j < 100000; j++){
        sum = 0;
        for(i = 0; i < C; i++){
            if(v[i][j] > 0){
                sum++;
            }
        }
        if(sum > max){
            max = sum;
        }
    }
    printf("%d\n", max);
    
    return 0;
}


Measured memory_bytes: 11904
import java.util.Scanner;

public class Main {
	public static int algoOne(int[] nums) {
		int maxProfit = Integer.MIN_VALUE;
		for (int i = 0; i < nums.length; i++) {
			for (int j = i+1; j < nums.length; j++) {
				if (nums[j] - nums[i] > maxProfit) {
					maxProfit = nums[j] - nums[i];
				}
			}
		}
		return maxProfit;
	}
	
	public static int algoTwo(int[] nums) {
		int maxProfit = Integer.MIN_VALUE;
		int minValue = Integer.MAX_VALUE;
		
		for (int i = 0; i < nums.length; i++) {
			if (nums[i] - minValue > maxProfit) maxProfit = nums[i] - minValue;
			
			if (nums[i] < minValue) minValue = nums[i];
		}
		
		return maxProfit;
	}
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int numNums = scanner.nextInt();
		int[] nums = new int[numNums];
		
		//read numbers
		for (int i = 0; i < numNums; i++) {
			nums[i] = scanner.nextInt();
		}
		
		//run algorithm here
		System.out.println(algoTwo(nums));
		
		scanner.close();
	}
}


Measured memory_bytes: 101792
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
	int N, L;
	cin >> N >> L;
	int all=0;
	int small = 500;
	rep(i, N) {
		all += L+i;
		small=min(small,abs(L+i));
	}
	int ans = 0;
	if (0 <L) {
		ans = all - small;
	}
	else if (L<=0&&0<=(L+N-1)) {
		ans = all;
	}
	else {
		ans = all + small;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	aMin := pow(10, 10)
	aMax := 0

	for range make([]struct{}, n) {
		var a int
		fmt.Scan(&a)

		aMin = min(aMin, a)
		aMax = max(aMax, a)
	}
	fmt.Println(aMax - aMin)
}

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

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

func pow(a, b int) int {
	res := 1
	for range make([]struct{}, b) {
		res *= a
	}
	return res
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-9;
const int inf=1e8;
int main(){
	vector<bool>sosu(300010);
	sosu[0]=sosu[1]=1;
	for(int i=2;i*i<=300010;i++)if(sosu[i]==0&&(i%7==1||i%7==6)){
		for(int j=i*2;j<300010;j+=i)sosu[j]=1;
	}
	int n;
	while(cin>>n,n-1){
		cout<<n<<":";
		rep(i,300010)if(sosu[i]==0&&(i%7==1||i%7==6)&&n%i==0)cout<<" "<<i;
		cout<<endl;
	}
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  string s;
  cin >> s;
  vector<int> a(4);
  rep(i, 4) a[i] = s[i] - '0';

  rep(tmp, 1<<(3)){
    bitset<3> bs(tmp);
    int sum = a[0];
    rep(i, 3){
      if(bs.test(i)) sum += a[i+1];
      else sum -= a[i+1];
    }
    if(sum == 7){
      cout << a[0];
      rep(i, 3){
        if(bs.test(i)) cout << "+";
        else cout << "-";
        cout << a[i+1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	lint MOD = 1000000007;
	lint N;
	cin >> N;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	vector<lint>abc(3);
	lint ans = 1;
	lint cnt = 0;
	rep(i, N) {
		rep(j, 3) {
			if (abc[j] == A[i]) {
				cnt++;
			}
		}
		ans *= cnt;
		ans %= MOD;
		cnt = 0;
		rep(j, 3) {
			if (A[i] == abc[j]) {
				abc[j]++;
				break;
			}
		}

	}
	cout << ans << endl;
}



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

int main() {
  int v,max=0;
  map<string,int>memo;
  map<string,int>:: iterator it;

  int n;
cin>>n;
for(int i= 0;i<n;i++){

string s;
cin>>s;
memo[s]+=1;
}


for(it=memo.begin();it!=memo.end();it++){
  v=it->second;
  if(v>max){
    max=v;
  }
}
for(it=memo.begin();it!=memo.end();it++) {
  if(it->second==max) {
  cout<<it->first<<endl;


}
}}


Measured memory_bytes: 25216
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;
 
int main() {
	int N;
	cin >> N;
	ll W,w,w0,vv;
	vector<ll> v[4];
	cin >> W >> w0 >> vv;
	v[0].push_back(vv);
	REP(i,N-1){
		cin >> w >> vv;
		v[w-w0].push_back(vv);
	}
	REP(i,4){
		sort(v[i].begin(),v[i].end());
		reverse(v[i].begin(),v[i].end());
	}
	ll mac=0,sum[4][110]={}; //[0]が0の累積和
	REP(i,4)
		REP(j,v[i].size()) sum[i][j+1]+=sum[i][j]+v[i][j];
	REP(w1,W/w0+1){
		REP(w2,W/(w0+1)+1){
			REP(w3,W/(w0+2)+1){
				REP(w4,W/(w0+3)+1){
					if(w1*w0+w2*(w0+1)+w3*(w0+2)+w4*(w0+3)>W) break;
					if(w4>v[3].size()||w3>v[2].size()||w2>v[1].size()||w1>v[0].size()) break;
					mac = max(mac,sum[0][w1]+sum[1][w2]+sum[2][w3]+sum[3][w4]);
				}
			}
		}
	}
	cout << mac << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  vector<int> C(9, 0);
  for(int i=0; i<N; i++){
    int X=A.at(i)/400;
    if(X>=8){
      C.at(8)++;
    }
    else{
      C.at(X)=1;
    }
  }
  int S=0;
  for(int i=0; i<8; i++){
    S+=C.at(i);
  }
  if(S==0){
    cout << 1 << " " << C.at(8) << endl;
  }
  else{
    cout << S << " " << S+C.at(8) << endl;
  }
}

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

int main(){
  string s;
  cin >> s;
  int cnt = 0;
  rep(i,s.size())cnt+= s[i]-'0';
  if(cnt%9==0)cout <<"Yes" <<endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    
    for (ll i = 2; (i * i) <= n; i++) {
        if (n % i) {
            continue;
        }
        
        res.emplace_back(i, 0);
        
        while((n % i) == 0) {
            n /= i;
            res.back().second++;
        }
    }
    
    if (n != 1) {
        res.emplace_back(n, 1);
    }
    
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<ll> fac(n + 1, 0);
    int ans = 0;
    
    reps(i, 2, n + 1) {
        auto f = factorize(i);
        
        rep(ii, sz(f)) {
            fac[f[ii].first] += f[ii].second;
        }
    }
    
    rep(i, n + 1) {
        if (fac[i] >= 74) {
            ans++;
        }
    }
    
    rep(i, n + 1) {
        rep(ii, n + 1) {
            if (i == ii) {
                continue;
            }
            
            if ((fac[i] >= 2) && (fac[ii] >= 24)) {
                ans++;
            }
        }
    }
    
    rep(i, n + 1) {
        rep(ii, n + 1) {
            if (i == ii) {
                continue;
            }
            
            if ((fac[i] >= 4) && (fac[ii] >= 14)) {
                ans++;
            }
        }
    }
    
    rep(i, n + 1) {
        rep(ii, n + 1) {
            if (i == ii) {
                continue;
            }
            
            reps(iii, ii + 1, n + 1) {
                if ((i == iii) || (ii == iii)) {
                    continue;
                }
                
                if ((fac[i] >= 2) && (fac[ii] >= 4) && (fac[iii] >= 4)) {
                    ans++;
                }
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = 1000001;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

//Mは隣接行列
int n, M[MAX][MAX];


void dijkstra(){
    int minv;
    int d[MAX] ,color[MAX];

    for(int i=0; i<n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }
    d[0] = 0;
    color[0] = GRAY;
    while(1){
        minv = INFTY;
        int u = -1;
        for(int i=0; i<n; i++){
            if(minv > d[i] && color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        //cout << "u=" << u << endl;
        if(u == -1) break;
        color[u] = BLACK;
        //d[i]にBLACkからiへの最短経路を入れる
        for(int i=0;  i<n; i++){
            if(color[i]!=BLACK) d[i] = min(M[u][i]+d[u], d[i]);
        }
    }
    for(int i=0; i<n; i++){
        cout << i << " " << d[i] << endl;
    }
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            M[i][j] = INFTY;
        }
    }

    int k, c, u, v;
    for(int i=0; i<n; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v >> c;
            M[u][v] = c;
        }
    }
     dijkstra();
     return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int digit(int n){
  int ans=0;
  while(n!=0){
    ans+=n%10;
    n=n/10;
  }
  return ans;
}
int main(){
  int n,a,b,i;
  cin >> n >> a >> b;
  int ans=0;
  for(i=1;i<=n;i++){
    if(digit(i)>=a && digit(i)<=b){
      ans+=i;
    }
  }
  cout << ans << endl;
}

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

int main(){
	int h, w;
	cin >> h >> w;
	vector<vector<int> > a(h + 1, vector<int> (w + 1));
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			cin >> a[i][j];
		}
	}

	int cnt = 0;
	vector<tuple<int, int, int, int>> v;
	for(int i = 1; i <= h; i++){
		for(int j = 2; j <= w; j++){
			if(a[i][j - 1] %2 == 1){
				a[i][j - 1]--;
				a[i][j]++;
				v.push_back(make_tuple(i, j - 1, i, j));
				cnt++;
			}
		}
	}
	for(int i = 2; i <= h; i++){
		if(a[i-1][w]%2==1){
			a[i-1][w]--;
			a[i][w]++;
			v.push_back(make_tuple(i-1, w, i, w));
			cnt++;
		}
	}

	cout << cnt << endl;
	for(int i=0; i<v.size(); i++){
		cout << get<0>(v[i]) << " " << get<1>(v[i]) << " " << get<2>(v[i]) << " " << get<3>(v[i]) << endl;
	}
	return 0;
}


Measured memory_bytes: 5232