akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {   
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    reverse(sa.begin(), sa.end());
    reverse(sb.begin(), sb.end());
    reverse(sc.begin(), sc.end());
    char last = 'a';
    while (1) {
        if (last == 'a') {
            if (sa.empty()) {
                cout << "A" << endl;
                return 0;
            }
            last = sa.back();
            sa.pop_back();
        } else if (last == 'b') {
            if (sb.empty()) {
                cout << "B" << endl;
                return 0;
            }
            last = sb.back();
            sb.pop_back();
        } else {
            if (sc.empty()) {
                cout << "C" << endl;
                return 0;
            }
            last = sc.back();
            sc.pop_back();
        }
    }
}




Measured memory_bytes: 3596
def solve():
    S = input()
    
    N = len(S)
    ans, i = 0, 0
    while i < N:
        count = 0
        j = i
        while j < N:
            if S[j] == 'A' or S[j] == 'C' or S[j] == 'G' or S[j] == 'T':
                count += 1
                j += 1
            else:
                break
        i = j + 1
        ans = max(ans, count)
    print(ans)


if __name__ == '__main__':
    solve()


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

#define pr_double(x) cout << fixed << setprecision(10)<< x;


double dp[301][301][301];
double solve(int x,int y,int z,int& n){

    if(x<0 || y<0 || z<0){
      return 0;
    }

    if(x==0 && y==0 && z==0){
       return 0;
    }
 
    if(dp[x][y][z]>-0.9){
        return dp[x][y][z];
    }
   
    double exp = n + x*solve(x-1,y,z,n)+ y*solve(x+1,y-1,z,n)+ z*solve(x,y+1,z-1,n); 
    return dp[x][y][z]=(double)exp/(x+y+z);
}


int main(){

   int n,x;
   cin>>n;
   memset(dp,-1,sizeof dp);
   int one=0,two=0,three=0;

   for(int i=1;i<=n;i++){
       cin>>x;
       if(x==1){
        one++;
       }
       else if(x==2){
        two++;
       }
       else{
        three++;
       }
   }
   pr_double(solve(one,two,three,n));
}

Measured memory_bytes: 216876
#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ff first
#define ss second
using namespace std;
typedef long long ll;

int main() {
    IO;
    ll n;
    cin >> n;
    ll sum = n * (n + 1) / 2;
    ll x = n / 3;
    ll y = n / 5;
    ll z = n / (15);
    sum -= 3LL * (x * (x + 1) / 2);
    sum -= 5LL * (y * (y + 1) / 2);
    sum += 15LL * (z * (z + 1) / 2);
    cout << sum << '\n';
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int *a,n,i,f=0,f1=0,sum=0;
	cin>>n;
	a = new int[n];
	vector<int>v;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		if(a[i]%10==0&&!f1)
		{
			if(a[i]!=0)
			v.push_back(a[i]);			
			f=0;
		}
		else
		{
			if(a[i]!=0)
			v.push_back(a[i]);
			f=1;
			f1=1;
		}
	}
	if(f)
	{
		sort(v.begin(),v.end());
		if(sum%10==0)
		{
			for(i=0;i<v.size();i++)
			{
				sum=sum-v[i];
				if(sum%10==0)
				{
					sum=sum+v[i];
				}
				else break;
			}
			cout<<sum;
		}
		else
		cout<<sum;
	}
	else cout<<0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = "";
		int[] top = new int[] { 21, -1 };

		br.readLine();
//		int n = Integer.parseInt(br.readLine());
//		int i = 0;
		while ((s = br.readLine()) != null) {
//			if (i == n)
//				break;
			Scanner sc = new Scanner(s);
			int _angler = sc.nextInt();
			int _catch = sc.nextInt();

//			if (_angler < 0 || _angler > 20)
//				continue;
//			if (_catch < 0 || _angler > 100)
//				continue;

			if (top[1] < _catch || (top[1] == _catch && top[0] > _angler)) {
				top[0] = _angler;
				top[1] = _catch;
			}
//			i++;
		}
		System.out.println(top[0] + " " + top[1]);
	}
}

Measured memory_bytes: 24456
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Set;
import java.util.HashSet;

public class Main {

    public static void main(String[] args) throws IOException {
        try (InputReader reader = new InputReader(System.in)) {
            solve(reader);
        }
    }

    private static void solve(InputReader reader) throws IOException {
        long n = reader.readLong();
        long min = Long.MAX_VALUE;
        for (long i = 1; i <= n; i++) {
            long b = n / i;
            if (i > b) {
                break;
            }

            if (i * b == n) {
                long f = Math.max(String.valueOf(i).length(), String.valueOf(b).length());
                min = Math.min(min, f);
            }
        }
        System.out.println(min);
    }
}

class Util {
    static int gcd(int m, int n) {
        int min = Math.min(m, n);
        int max = Math.max(m, n);
        while (min != 0) {
            int tmp = min;
            min = max % tmp;
            max = tmp;
        }

        return max;
    }
}

class InputReader implements Closeable, AutoCloseable {
    private final BufferedReader br;

    InputReader(InputStream inputStream) {
        this.br = new BufferedReader(new InputStreamReader(inputStream));
    }

    String readLine() throws IOException {
        return this.br.readLine();
    }

    int readInt() throws IOException {
        return Integer.parseInt(this.readLine());
    }

    long readLong() throws IOException {
        return Long.parseLong(this.readLine());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(this.readLine());
    }

    String[] readStringsSplitByDelimiter(String delimiter) throws IOException {
        return this.readLine().split(delimiter);
    }

    int[] readIntsSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        int[] ints = new int[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            ints[i] = Integer.parseInt(strings[i]);
        }

        return ints;
    }

    long[] readLongsSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        long[] longs = new long[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            longs[i] = Long.parseLong(strings[i]);
        }

        return longs;
    }

    double[] readDoublesSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        double[] doubles = new double[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            doubles[i] = Double.parseDouble(strings[i]);
        }

        return doubles;
    }

    @Override
    public void close() throws IOException {
        this.br.close();
    }
}


Measured memory_bytes: 21332
#include <iostream>
using namespace std;
int main(){
    int H,R,ans;
    cin>>H>>R;
    ans=H+R;
    if(ans>0){
        cout<<"1"<<endl;
    }else if(ans<0){
        cout<<"-1"<<endl;
    }else{
        cout<<"0"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include <stdio.h>
int main(void) {
	int a, b, c, d;
	scanf("%d %d %d", &a, &b, &c);
	if(b < a) {
		d = a;
		a = b;
		b = d;
	}
	if(c < b) {
		d = b;
		b = c;
		c = d;
	if(b < a) {
		d = a;
		a = b;
		b = d;
	}
	}
	printf("%d %d %d\n", a, b, c);
	return 0;
}

Measured memory_bytes: 596
// 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

// 0: available, 1: unavailable, return: length of side
int largestSquare(const vector<vector<int>> &v) {
  int h = v.size(), w = v[0].size();
  vector<vector<int>> dp(h, vector<int>(w));
  rep(i, h) dp[i][0] = v[i][0] == 0;
  rep(j, w) dp[0][j] = v[0][j] == 0;
  loop(i, 1, h) loop(j, 1, w) dp[i][j] = v[i][j] == 1 ? 0 : min({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]}) + 1;
  int maxi = 0;
  rep(i, h) rep(j, w) cmax(maxi, dp[i][j]);
  return maxi;
}

main {
  int h, w;
  cin >> h >> w;
  auto c = vectors(h, w, 0LL);
  cin >> c;
  int l = largestSquare(c);
  cout << l * l << endl;
}



Measured memory_bytes: 33476
// ~/BAU/ACM-ICPC/Teams/Rampage/Abukhadijah
// ~/sudo apt-get verdict Accpeted
// ~/Remember,remember the 6th of March
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
const double PI = acos(-1.0);
const double  EPS = 1e-11;
typedef long long ll;
typedef unsigned long long ull;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
int main()
{
	int x;
	cin >> x;
	vector<int>vis(x+1);
	vis[1] = 1;
	for (int i = 2; i <= x; i++)
	{
		int j = i;
		while (i*j <= x)
		{
			j *= i;
			vis[j] = 1;
		}
	}
	for(int i=x;i>0;i--)
		if (vis[i])
		{
			cout << i << endl;
			return 0;
		}
	return 0;
}

Measured memory_bytes: 256
<?php
$stdins = '';
$msg = 'yes';

$stdins = trim(fgets(STDIN));

for($i = 0; $i < strlen($stdins); $i++) {
	for($j =0; $j < strlen($stdins); $j++) {
		if($i != $j && $stdins[$i] == $stdins[$j]) {
			$msg = 'no';
			break;
		}
	}
}

printf($msg);


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

void solve(std::string s) {
	if((s.size()%2 == 0) ^ (s[0] == s[s.size()-1]))cout<<"Second";
  else cout<<"First";
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


Measured memory_bytes: 512
s = input() #sys.stdin.readlineは最後が改行

ans = 0
cnt = 0
atgc = ['A','T','G','C']
for i in range(len(s)):
    if s[i] in atgc:
        cnt+=1
    else:
        ans = max(ans,cnt)
        cnt = 0
ans = max(ans,cnt)
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int N, M;
int K, S;

vector< vector<int> > sw;
int defaultBright = 0;
int bright = 0;
void turnOnSwitch(int idx) {
	for (int item : sw[idx]) {
		bright ^= (1 << (item - 1));
	}
}


int main() {
	scanf("%d %d", &N, &M);
	sw.resize(N + 1);
	for (int i = 1; i <= M; i++) {
		scanf("%d", &S);
		for (int j = 0; j < S; j++) {
			scanf("%d", &K);
			sw[K].push_back(i);
		}
	}
	int last = (1 << N);
	int sol = 0;
	int allBright = (1 << M)-1;
	for (int i = 0; i < M; i++) {
		scanf("%d", &K);
		if (K == 1) {
			defaultBright += (1 << i);
		}
	}
	for (int state = 0; state < last; state++) {
		bright = 0;
		for (int swItem = 0; swItem < N; swItem++) {
			if (state & (1 << swItem)) {
				turnOnSwitch(swItem + 1);
			}
		}
		if (bright == defaultBright) {
			sol++;
		}
	}
	printf("%d\n", sol);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, k, ans, t;
  cin >> n >> k;
  unordered_set<int> d;
  rep(i, k) cin >> t, d.insert(t);

  bool ok;
  while (1) {
    ok = true;
    ans = n;
    while (ans) {
      if (d.find(ans % 10) != d.end()) {
        ok = false;
        break;
      }
      ans /= 10;
    }

    if (ok) break;
    n++;
  }

  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
// abc.cpp : 此檔案包含 'main' 函式。程式會於該處開始執行及結束執行。
//

#include <iostream>
using namespace std;
int main()
{
	int N,a,i,j,k,L[100],L1[100],b,c,l;
	l = 0;
	cin >> N;
	for (a = 0; a < N; a++) {
		cin >> L[a];
	}
	for (a = 0; a < N-2; a++) {
		for (b = a+1; b < N-1; b++) {
			for (c = b+1; c < N; c++) {
				if ((L[a] + L[b] > L[c]) && (L[a] + L[c] > L[b]) && (L[b] + L[c] > L[a])&&(L[a] != L[b]) && (L[b] !=L[ c]) && (L[a] != L[c])) {
					
						l++;
					
				}
			}
		}
	}
	printf("%d", l);
	return 0;
}

// 執行程式: Ctrl + F5 或 [偵錯] > [啟動但不偵錯] 功能表
// 偵錯程式: F5 或 [偵錯] > [啟動偵錯] 功能表

// 開始使用的提示: 
//   1. 使用 [方案總管] 視窗，新增/管理檔案
//   2. 使用 [Team Explorer] 視窗，連線到原始檔控制
//   3. 使用 [輸出] 視窗，參閱組建輸出與其他訊息
//   4. 使用 [錯誤清單] 視窗，檢視錯誤
//   5. 前往 [專案] > [新增項目]，建立新的程式碼檔案，或是前往 [專案] > [新增現有項目]，將現有程式碼檔案新增至專案
//   6. 之後要再次開啟此專案時，請前往 [檔案] > [開啟] > [專案]，然後選取 .sln 檔案


Measured memory_bytes: 3744
var
	a,b,c,d,e,f,g,t,u:int64;
	i,N:Longint;
begin
	read(N);
	g:=1;
	for i:=1 to N do begin
		t:=(g*4-b-c-d-a*3)mod 1000000007;
		if t<0 then inc(t,1000000007);
		u:=c;
		a:=b;
		b:=e;
		c:=e-d;
		d:=f;
		e:=g;
		f:=g-u;
		g:=t;
	end;
	writeln(g);
end.


Measured memory_bytes: 128
#include<iostream>
#include<map>
using namespace std;
int N,K;
int A[2<<17];
long tmp[2<<17];
main()
{
	cin>>N>>K;
	map<long,int>M;
	long ans=0,cumsum=0;
	M[0]=1;
	for(int i=0;i<N;i++)
	{
		if(i>=K-1)M[tmp[i+1-K]]--;
		cin>>A[i];
		tmp[i+1]=(cumsum+=A[i]-1)%=K;
		ans+=M[cumsum]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 15104
n = int(input())
t,x,y = 0,0,0
for i in range(n):
  nt, nx, ny  = map(int, input().split())
  if not(abs(nx-x)+abs(ny-y) <= nt-t and t%2 == (x+y)%2):
    print("No")
    exit()
  t,x,y = nt,nx,ny
print("Yes")
    

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

struct Event {
  int t;
  int d;
  int a;
  bool operator<(const Event& r) const {
    return t < r.t;
  }
};

int R, K, Q;
int s[100000];
int t[100000];
int a[100000];

void sub(int t, int d, int a) {
  static int prev_d = 1;
  static int prev_t = 0;
  static int l = 0;
  static int r = R;
  static int x = 0;
  
  bool q = d == 0;
  if (q) {
    d = -prev_d;
  }
  
  x += d * (t - prev_t);
  l = min(max(l, -x), -x + R);
  r = min(max(r, -x), -x + R);
  
  if (q) {
    a = max(a, l);
    a = min(a, r);
    cout << x + a << endl;
  }
  
  if (!q) {
    prev_d = d;
  }
  prev_t = t;
}

int main() {
  cin >> R >> K;
  for (int i = 0; i < K; ++i) cin >> s[i];
  cin >> Q;
  for (int i = 0; i < Q; ++i) cin >> t[i] >> a[i];
  
  vector<Event> es;
  int d = -1;
  for (int i = 0; i < K; ++i) {
    es.push_back(Event{ s[i], d, 0 });
    d = -d;
  }
  for (int i = 0; i < Q; ++i) {
    es.push_back(Event{ t[i], 0, a[i] });
  }
  sort(es.begin(), es.end());
  for (auto e : es) {
    sub(e.t, e.d, e.a);
  }
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long h[] = new long[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextLong();
		}
		Arrays.sort(h);
		long ans = 999999999;
		for (int i = 0; i < n - k + 1; i++) {
			if (h[i + k - 1] - h[i] < ans) {
				ans = h[i + k - 1] - h[i];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 50780
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#define debug cout

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n);i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

int bit[100100],n,k,m;

int sum(int i){
	int s=0;
	while(i>0){
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}

void del(int i){
	while(i<=n){
		--bit[i];
		i+=i&-i;
	}
}

void init(){
	repn(i,1,n){
		rep(j,20){
			if(i&1<<j){
				bit[i]=1<<j;
				break;
			}
		}
	}
}

int find(){
//debug<<"sum:"<<bit[n]<<endl;
	int kk=(k+sum(m))%sum(n);
	if(kk==0)kk=sum(n);
//debug<<"kk:"<<kk<<endl;
	int a=1,b=n+1;
	while(a<b-1){
//debug<<"a:"<<a<<",b:"<<b<<endl;
		int mid=(a+b)/2;
		if(sum(mid)>kk)b=mid;
		else a=mid;
	}
//debug<<"a:"<<a<<",b:"<<b<<endl;
	b=a,a=0;
	while(a<b-1){
//debug<<"a:"<<a<<",b:"<<b<<endl;
		int mid=(a+b)/2;
		if(sum(mid)==kk)b=mid;
		else a=mid;
	}
//debug<<"a:"<<a<<",b:"<<b<<endl;
	return b;
}

int main() {
	IL{
		cin>>n>>k>>m;
		if(n==0&&k==0&&m==0)break;
		init();
		rep(i,n-1){
//debug<<"m:"<<m<<endl;
			del(m);
			m=find();
		}
		cout<<m<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import heapq
n,m = map(int,input().split())
arr= list(map(lambda x: int(x)*(-1) ,input().split()))
heapq.heapify(arr)
for i in range(m):
    d = heapq.heappop(arr)
    heapq.heappush(arr,-( -d//2))
print(sum(arr)*-1)

Measured memory_bytes: 14180
a = int(input())
b = int(input())

if a == 1 and b==2:
    print('3')

elif a==1 and b==3:
    print('2')

elif a==2 and b==3:
    print('1')

elif a==2 and b==1:
    print('3')

elif a==3 and b==1:
    print('2')

elif a==3 and b==2:
    print('1')

Measured memory_bytes: 2568
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        if(a<1200)System.out.println("ABC");
          else if(a<2800)System.out.println("ARC");
            else System.out.println("AGC");
    }
}

Measured memory_bytes: 20692
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Ribhav
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AOnTheWay solver = new AOnTheWay();
        solver.solve(1, in, out);
        out.close();
    }

    static class AOnTheWay {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int a = s.nextInt();
            int b = s.nextInt();
            int c = s.nextInt();

            if (a < b) {
                if (c < b && c > a) {
                    out.println("Yes");
                } else {
                    out.println("No");
                }
            } else {
                if (c > b && c < a) {
                    out.println("Yes");
                } else {
                    out.println("No");
                }
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
template<class T>bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;

static const int MAX=3005;

ll MOD;
ll fact[MAX], fact_inv[MAX];

ll comb(ll n, ll r){
    return (fact[n] * fact_inv[r]) % MOD * fact_inv[n-r] % MOD;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}//mod mでの逆元aを計算

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    iosetup;
    int p; IN(p);
    MOD = p;
    vector<int> a(p);
    rep(i, 0, p) cin >> a[i];

    fact[0] = 1;
    for(int i = 0; i < MOD - 1; i++) fact[i+1] = fact[i] * (i+1) % MOD;
    fact_inv[MOD-1] = modpow(fact[MOD-1], MOD - 2, MOD);
    for(int i = MOD - 2; i >= 0; i--) fact_inv[i] = fact_inv[i+1]%MOD*(i+1)%MOD;

    cout << a[0];
    rep(i, 1, p){
        ll ans = 0;
        rep(j, 0, p) if(a[j] == 1){
            if(((p-1-i)&1) == 0) ans -=(comb(p-1, i) * modpow(j,p-1-i, p))%p;
            else ans += (comb(p-1, i) * modpow(j, p-1-i, p))%p;
        }
        ans %= p;
        if(ans < 0) ans += p;
        cout << " ";
        cout << ans;
    }
    cout << endl;
    
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> P;

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

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

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

    if(k%2==0) {
        cout << -1 << endl;
        return 0;
    }

    int mod = 7%k;
    int cnt = 1;
    set<int> s;
    while(!s.count(mod)) {
        if(mod == 0) {
            cout << cnt << endl;
            return 0;
        }
        s.insert(mod);
        mod = (mod*10+7)%k;
        cnt++;
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 50384
from collections import deque
S=deque(input())
Q=int(input())
reverse=0
for q in range(Q):
    Query=list(input().split())
    T=Query[0]
    if T=="1":
        reverse+=1
    if T=="2":
        F,C=Query[1],Query[2]
        if F=="1" and reverse%2==0 or F=="2" and reverse%2==1:
            S.appendleft(C)
        else:
            S.append(C)
S="".join(S)
print(S if reverse%2==0 else S[::-1])

Measured memory_bytes: 14144
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int maxn = 105;
const int maxw = 100005;

int N,W, w[maxn], v[maxn];
long long dp[maxn][maxw];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>N>>W;
    
    for(int i = 1; i <= N; i++)cin>>w[i]>>v[i];
    
    for(int i = 0; i<= W; i++){
        if(i < w[1])dp[1][i] = 0;
        else dp[1][i] = v[1];
    }
    
    for(int i = 2; i<=N; i++){
        for(int j = 0; j<=W; j++ ){
            dp[i][j] = dp[i-1][j];
            if(w[i]<=j) dp[i][j] = max(dp[i][j], dp[i-1][j - w[i]] +v[i]);
        }
    }
    
    cout<<dp[N][W]<<endl;
    return 0;
}


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

int main() {
    int N=0,ans=0,t=1;
    cin >> N;
    while(N > 0){
        int x = N%10;
        N /= 10;
        if(x==1){
            ans+=9*t;
        }else if(x==9){
            ans+=1*t;
        }
        t*= 10;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        int n = scanner.nextInt();
        int[] a = new int[n], aa = new int[n], b = new int[n], bb = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            aa[i] = a[i];
        }
        for(int i = 0; i < n; i++) {
            b[i] = scanner.nextInt();
            bb[i] = b[i];
        }
        Arrays.sort(aa);
        Arrays.sort(bb);
        //viability check after sorting
        for(int i = 0; i < n; i++) {
            if (aa[i] > bb[i]) {
                System.out.println("No");
                return;
            }
        }
        //whether we can do this with n-2 naive swaps
        for(int i = 1; i < n; i++) {
            if (aa[i] <= bb[i-1]) {
                System.out.println("Yes");
                return;
            }
        }
        //create a mapping of the sorted elts into 1...n
        HashMap<Integer, Integer> mapb = new HashMap<>();
        HashMap<Integer, Integer> mapa = new HashMap<>();
        for(int i = 0; i < n; i++) {
            mapa.put(aa[i], i);
            mapb.put(bb[i], i);
        }
        //get the permutation compared the what is needed for b;
        int[] perm = new int[n];
        for(int i = 0; i < n; i++) {
            perm[mapb.get(b[i])] = mapa.get(a[i]);
        }
        boolean[] vis = new boolean[n];
        int cnt = 0;
        for(int i = 0; i < n; i++) {
            if (vis[i]) continue;
            int cur = i;
            do {
                vis[cur] = true;
                cur = perm[cur];
            } while(!vis[cur]);
            cnt++;
        }
        //issue if all in one cycle, would require n-1 swaps
        if (cnt == 1) System.out.println("No");
        else System.out.println("Yes");
        out.flush();
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 57696
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main( void ) {
    int n, a, b;
    std::cin >> n >> a >> b;

    std::vector< int > hs;
    for( size_t i = 0; i < n; ++i ) {
        int h;
        std::cin >> h;
        hs.push_back( h );
    }

    // とりあえずbでx回攻撃して削ったとみなして
    // 残ったヒットポイントは
    // 「実は必要な分はこの怪物をaで攻撃してたから0になってるんだよ！」
    // と後付けでいう。
    // それが全ての怪物で問題なく言えるなら、x回の攻撃で倒せる
    // その上で最小のxを二分探索で探す

    // 一番少ないものを、aだけで倒せばOKの時が最小
    size_t min = std::floor( *std::min_element(hs.begin(), hs.end()) / (double)a );
    // 初期上限としては、最大のものをbだけで吹き飛ばすほどの回数で十分
    size_t max = std::ceil( *std::max_element(hs.begin(), hs.end()) / (double)b );

    while( min != max ) {
        const size_t mid = (min + max) / 2;

        size_t a_attacks = 0;
        const int base = mid * b;
        for( size_t i = 0; i < hs.size(); ++i ) {
            // 何回分のa攻撃が必要なのか求める。
            // b攻撃してきた中にa攻撃であるものが実はある程度あった、、、という計算は
            // hs[i] - baseでb攻撃分のhを削ったあと、a-bだけダメージが増す攻撃があったということ
            const int attacks = std::ceil( (double)(hs[ i ] - base) / (a - b) );
            // 0を下回る場合、もうb攻撃だけで死んでいるからa攻撃しない
            if( attacks <= 0 ) continue;
            a_attacks += attacks;
        }

        if( a_attacks <= mid ) {
            max = mid;
        } else {
            min = mid + 1;
        }
    }

    std::cout << min << std::endl;
    
    return 0;
}

Measured memory_bytes: 892
# -*- coding: utf-8 -*-

N = int(input())
a = list(map(int, input().split()))

count = [0] * (10**5+1)

for i in range(N):
    count[a[i]] += 1
    if a[i]-1 >=0:
        count[a[i]-1] += 1
    if a[i]+1 <=10**5:
        count[a[i]+1] += 1

max_value = max(count)
#max_index = count.index(max_value)
print(max_value)

Measured memory_bytes: 20508
s = input()
mod = [0] * 2019
mod[0] = 1
d = 1
n = 0
for i in reversed(s):
    n += int(i) * d
    n %= 2019
    d *= 10
    d %= 2019
    mod[n % 2019] += 1
print(sum(i*(i-1)//2 for i in mod))


Measured memory_bytes: 9276
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string s;
    cin >> s;
    ll ans = 700;
    
    for (int i = 0; i < 3; ++i){
        if (s[i] == 'o')ans += 100;
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define maxn 300005
int tree[4*maxn],f[maxn],a[maxn],lazy[4*maxn];
void pushup(int i)
{
	tree[i] = max(tree[i << 1], tree[i << 1 | 1]);
}
void xia(int i,int l,int r)
{
	tree[i<<1]=max(tree[i<<1],lazy[i]);
	tree[i<<1|1]=max(tree[i<<1|1],lazy[i]);
	lazy[i<<1]=max(lazy[i<<1],lazy[i]);
	lazy[i<<1|1]=max(lazy[i<<1|1],lazy[i]);
	lazy[i]=0 ; 
}
void update(int i, int l, int r, int x,int y, int val)
{
	if (x <= l && r <= y)
	{
		tree[i] =max(tree[i],val);
		lazy[i]=max(lazy[i],val);
		return;
	}
	if(lazy[i]) xia(i,l,r); 
	int mid = (l + r) / 2;
	if (x<=mid) update(i<<1,l,mid,x,y,val);
	if (y>mid) update(i<<1|1,mid+1,r,x,y,val);
	pushup(i);
}
int query(int i, int l, int r, int x, int y)
{
	if (x <= l && r <= y) return tree[i];
	int maxm = 0;
	if(lazy[i]) xia(i,l,r);
	int mid=(l+r)/2;
	if (x <= mid) maxm = max(maxm, query(i << 1, l, mid, x, y));
	if (y>mid) maxm = max(maxm, query(i << 1 | 1, mid + 1, r, x, y));
	return maxm;
}
int tree1[4*maxn],lazy1[4*maxn];
void pushup1(int i)
{
	tree1[i] = max(tree1[i << 1], tree1[i << 1 | 1]);
}
void xia1(int i,int l,int r)
{
	tree1[i<<1]=max(tree1[i<<1],lazy1[i]);
	tree1[i<<1|1]=max(tree1[i<<1|1],lazy1[i]);
	lazy1[i<<1]=max(lazy1[i<<1],lazy1[i]);
	lazy1[i<<1|1]=max(lazy1[i<<1|1],lazy1[i]);
	lazy1[i]=0 ; 
}
void update1(int i, int l, int r, int x,int y, int val)
{
	if (x <= l && r <= y)
	{
		tree1[i] =max(tree1[i],val);
		lazy1[i]=max(lazy1[i],val);
		return;
	}
	if(lazy1[i]) xia1(i,l,r); 
	int mid = (l + r) / 2;
	if (x<=mid) update1(i<<1,l,mid,x,y,val);
	if (y>mid) update1(i<<1|1,mid+1,r,x,y,val);
	pushup1(i);
}
int query1(int i, int l, int r, int x, int y)
{
	if (x <= l && r <= y) return tree1[i];
	int maxm = 0;
	if(lazy1[i]) xia1(i,l,r);
	int mid=(l+r)/2;
	if (x <= mid) maxm = max(maxm, query1(i << 1, l, mid, x, y));
	if (y>mid) maxm = max(maxm, query1(i << 1 | 1, mid + 1, r, x, y));
	return maxm;
}
int ans=0,n,k;
int da=0;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),da=max(da,a[i]);
	for(int i=1;i<=n;i++)
	{
		int tmp=0;
		tmp=max(tmp,query1(1,0,da,max(0,a[i]-k),a[i]));
		tmp=max(tmp,query(1,0,da,a[i],min(da,a[i]+k)));
		f[i]=tmp+1;
		ans=max(f[i],ans);
		update1(1,0,da,max(a[i]-k,0),a[i],f[i]);
		update(1,0,da,a[i],min(da,a[i]+k),f[i]);
	}
	cout<<ans;
}
 

Measured memory_bytes: 22508
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout<<(x)<<endl
template<class T> inline void chmax(T& a, T b) {
  if (a < b) a = b;
}

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

const long long INF = 1LL << 60;
int main() {
  string n;
  cin >> n;
  if (n[0] == '7' || n[1] == '7' || n[2] == '7') COUT("Yes");
  else COUT("No");
  return 0;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
#define MOD 1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N,a;cin>>N;
  map<int,int> mp;
  REP(i,0,N){
    cin>>a;
    mp[a-1]++;
    mp[a]++;
    mp[a+1]++;
  }
  int ans=-1;
  each(m,mp){
    ans=max(ans,m.second);
  }
  print(ans)

}


Measured memory_bytes: 6144
#include <cstdio>
#include <algorithm>
using namespace std;

const int MXN = 100 + 5;
int N;

int a[MXN];

int main(void) {
    scanf("%d", &N);
    int sum = 0;
    for (int i = 1; i <= N; i++) scanf("%d", a+i), sum += a[i];
    
    int ans1 = 0, ans2 = 0;
    for (int i = 1; i <= N; i++)
        ans1 += (a[i] - sum/N) * (a[i] - sum/N), ans2 += (a[i] - sum/N - 1) * (a[i] - sum/N - 1);
    
    printf("%d\n", min(ans1, ans2));
    return 0;
}

Measured memory_bytes: 128
p[1<<21]={1};a[999],I,j,A=1e9+7;main(x){while(~scanf("%d",a+j++));for(;I<1<<*a;I++)for(j=0;j<*a;!a[*a*__builtin_popcount(I)+j]|I&x?:(p[x|=I]+=p[I],p[x]%=A))x=1<<j++;printf("%d",p[I-1]);}

Measured memory_bytes: 8320
#include<iostream>
#include<deque>
using namespace std;
deque<int> a;
int main()
{
	int p,q,opt,d,x;
	cin >> q;
	while (q--)
	{
		cin >> opt;
		if (opt == 0)
		{
			cin >> d >> x;
			if (d == 0) a.push_front(x);
			if (d == 1) a.push_back(x);
		}
		if (opt == 1)
		{
			cin >> p; 
			cout << a[p] << endl; 
		}
		if (opt == 2)
		{
			cin >> d;
			if (d == 0) a.pop_front();
			if (d == 1) a.pop_back();
		}
	}
	return 0;
}


Measured memory_bytes: 4672
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
L = LIST()

cnt = [0]*(10**3+1)
for x in L:
	cnt[x] += 1

cnt = list(accumulate(cnt))

ans = 0
for x, y in combinations(L, 2):
	ans += cnt[min(x+y-1, 1000)] - cnt[abs(x-y)] - (abs(x-y) < x < x+y) - (abs(x-y) < y < x+y)

print(ans//3)

Measured memory_bytes: 65256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}

using mint = modint998244353;

mint op(mint a,mint b){
    return a+b;
}

mint e(){
    return 0;
}

void solve(){
    int n,k,l;
    cin>>n>>k;
    l=n-k+1;
    vector<int> p(n),q(n);
    iota(q.begin(),q.end(),0);
    for(auto&i:p) cin>>i;
    vector<mint> pw(l,1);
    for(int i{1};i<l;++i){
        pw[i]=pw[i-1]*(k-1)/k;
    }
    mint ans=0;
    {
        fenwick_tree<mint> fw(l);
        segtree<mint,op,e> seg(l),SEG(l);
        sort(q.begin(),q.end(),[&](int i,int j){
            return p[i]>p[j];
        });
        for(auto&i:q){
            int I=i-k+1;
            if(I<0) I=0;
            ans+=fw.sum(0,I);
            ans-=seg.prod(0,I)/pw[l-I-1]/2;
            ans+=SEG.prod(I,l)/pw[I]/2;
            fw.add(I,1);
            seg.set(I,seg.get(I)+pw[l-I-1]);
            SEG.set(I,SEG.get(I)+pw[I]);
        }
    }
    cout<<ans.val()<<'\n';


}

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

Measured memory_bytes: 11076
n = gets.chomp.to_i
jobs = []
n.times do
    jobs << gets.chomp.split(" ").map(&:to_i)
end

# 締め切りが早い順にソート
jobs = jobs.sort_by{|x| x[1]}

time = 0
can = true

jobs.each do |t, lim|
    time += t
    if time > lim
        can = false
        break
    end
end

puts 'Yes' if can
puts 'No' if !can

Measured memory_bytes: 22392
import sys
sys.setrecursionlimit(10**7)

# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

mem = {}

def fib(n):
    if n == 0:
        return 1
    if n == 1:
        return 1
    if n not in mem.keys():
        res = fib(n-1) + fib(n-2)
        mem[n] = res
        return res
    else:
        return mem[n]

def solve():
    n = int(input())
    print(fib(n))

solve()


Measured memory_bytes: 5604
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int h, w;
	string hw[110];
	cin >> h >> w;
	vector<bool> H(h, 0), W(w, 0);
	FOR(i, h) {
		cin >> hw[i];
		FOR(j, w) {;
			if (hw[i][j] == '#') {
				H[i] = 1;
				W[j] = 1;
			}
		}
	}

	FOR(i, h) {
		FOR(j, w) {
			if (H[i] == 1 && W[j] == 1)cout << hw[i][j];
		}
		if(H[i])cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
    int l;
    cin>>l;
    double a=l*1.0/3;
    printf("%lf\n",a*a*a);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	int n; cin >> n;
	string u;
	double x, sum = 0.0;

	for (int i = 0; i < n; i++) {
		cin >> x >> u;
		if (u[0] == 'J') sum += x;
		else sum += (x * 380000.0);
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n, a,b,c,d;
	int arr[4][3][10] = {0};

	cin >> n;
	for (int i = 0; i != n; ++i)
	{
		cin >> a >> b >> c >> d;
		arr[a - 1][b - 1][c - 1] += d;
	}
	
	for (int i = 0; i != 4; ++i)
	{
		for (int j = 0; j != 3; ++j)
		{
			for (int k = 0; k != 10; ++k)
			{
				cout << " "<<arr[i][j][k];
			}
			cout << endl;
		}
		if (i != 3)
		{
			cout << "####################" << endl;
		}
		
	}
	
	return 0;

}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    map<char,int> cnt;
    int n;
    cin>>n;
    REP(i,n) {
        string s;
        cin>>s;
        cnt[s[0]]++;
    }
    vector<char> a={'M','A','R','C','H'};
    int ans=0;
    REP(i,5) {
        REPF(j,i+1,5) {
            REPF(k,j+1,6) {
                ans+=cnt[a[i]]*cnt[a[j]]*cnt[a[k]];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256