akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int N;
	while(cin >> N){
		vector<int> cnt(N+1, 1);
		for(int i=2;i<=N;i++){
			int n = i;
			for(int j=2;j<=N;j++){
				while(n%j==0){
					cnt[j]++;
					n /= j;
				}
			}
		}
		long long res = 1;
		for(int i=2;i<cnt.size();i++){
			res = (res * cnt[i])%1000000007;
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>

int main(){
  
  int K = 0;
  std::cin >> K;
  
  int sum = 0;
  for(int i = 1; i <= K; i++){
    for(int j = 1; j <= K; j++){
      for(int k = 1; k <= K; k++){
        sum += std::gcd(std::gcd(i,j),k);
      }
    }
  }
  
  std::cout << sum << std::endl;
  
  return 0;
}

Measured memory_bytes: 3616
MUL = {
  "m" => 1000,
  "c" => 100,
  "x" => 10,
  "i" => 1
}

NUM = (2..9).map &:to_s

def read( v )
  n = 0
  rv = v.split(//).reverse
  i = 0
  while( i < rv.size )
    s = MUL[rv[i]]
    if NUM.include?( rv[i+1] )
      s *= rv[i+1].to_i
      i += 1
    end
    i += 1
    n += s
  end
  return n
end

def put( v )
  s = ""
  MUL.each do |k, m|
    i = v / m
    s += i.to_s if NUM.include?( i.to_s )
    s += k if i != 0
    v = v % m
  end
  return s
end


n = gets.to_i
n.times do
  v1, v2 = gets.chomp.split
  puts put( read( v1 ) + read( v2 ) )
end

Measured memory_bytes: 6124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
    string s;
    int k;
    cin >> s >> k;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'a') continue;
        if ('z' - s[i] < k) {
            k -= ('z' - s[i] + 1);
            s[i] = 'a';
        }
    }
    if (k > 0) {
        s[s.size() - 1] = (s[s.size() - 1] - 'a' + k) % 26 + 'a';
    }

    cout << s << "\n";
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  int n;cin>>n;
  int arr[n+1];
  for(int i=1;i<=n;i++)cin>>arr[i];
  int dp[n+1];
  memset(dp,0,sizeof(dp));
  dp[1]=0;
  if(n==1)
  {
    cout<<arr[1]<<endl;
  }
  else if(n==2)
  {
    cout<<abs(arr[2]-arr[1])<<endl;
  }
  else
  {
    dp[2]=abs(arr[2]-arr[1]);
    for(int i=3;i<=n;i++)
    {
      dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n]<<endl;
  }
return 0;  
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    ll n,d;
    cin >> n >> d;
    ll ans = 0;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        if(x*x + y*y <= d*d) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

int main() {
    using namespace std;
    int n, min=0, i, total=0, p;
    cin >> n;
    vector<int> x(n);
    for(i=0; i<n; i++) {
        cin >> x[i];
        total += x[i];
    }
    p = 0.5 + total/static_cast<double>(n);
    for(i=0; i<n; i++) min += pow(x[i]-p, 2);
    cout << min;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <stack>
#define N 1005
using namespace std;
typedef long long ll;
int main()
{
    int a,n;
    set<int>s;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        s.insert(a);

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


Measured memory_bytes: 256
R, C, N = map(int, input().split())
def calc(x, y):
    if x == 0 or y == C:
        return x + y
    return 2*R + 2*C - x - y
A = {}
for i in range(N):
    x1, y1, x2, y2 = map(int, input().split())
    if not ((x1 in [0, R] or y1 in [0, C]) and (x2 in [0, R] or y2 in [0, C])):
        continue
    A[calc(x1, y1)] = i
    A[calc(x2, y2)] = i

st = []
for i, a in sorted(A.items()):
    if st and st[-1] == a:
        st.pop()
    elif a is not None:
        st.append(a)
print('YES' if not st else 'NO')


Measured memory_bytes: 40972
from collections import deque
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[0 for _ in range(n+1)]
for _ in range(m):
  a,b=map(int,input().split())
  ab[a]=max(h[b-1],ab[a])
  ab[b]=max(h[a-1],ab[b])
ans=0
for i in range(1,n+1):
  if h[i-1]>ab[i]:
    ans+=1
print(ans)

Measured memory_bytes: 21440
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 100000;
ll const MOD = 1000000007;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> a(M), b(M);
    rep(i, M) cin >> a[i] >> b[i];

    vector<ll> cnt(N, 0);

    rep(i, M) {
        cnt[a[i] - 1]++;
        cnt[b[i] - 1]++;
    }

    bool flg = true;
    repv(cnt) {
        if (*it % 2 == 1) {
            flg = false;
            break;
        }
    }

    if (flg)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    // repv(cnt) cout << *it << " ";
    // cout << endl;

    return 0;
}


Measured memory_bytes: 5576
import math
import itertools

M = 0
N = int(input())
C = list(itertools.product([0,1],repeat=N))
A = [0]*N
x = [0]*N
y = [0]*N

for i in range(N):
  A[i] = int(input())
  x[i] = [0]*A[i]
  y[i] = [0]*A[i]
  for j in range(A[i]):
    x[i][j], y[i][j] = map(int, input().split())


for c in C:
  #print(c)
  marker = True
  for i in range(N):
    for j in range(A[i]):
      if c[i] == 1 and c[x[i][j]-1] != y[i][j]:
        #print(i,j)
        marker = False
  if marker == True:
    M = max(M,sum(c))
  
print(M)

Measured memory_bytes: 8820
n=int(input())
if n<10:
  print(n)
  exit()
if 10<=n<100:
  print(9)
  exit()
if 100<=n<1000:
  print(9+n-99)
if 1000<=n<10000:
  print(909)
if 10000<=n<100000:
  print(n-9999+909)
if n==100000:
  print(90909)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	ll n,k; cin>>n>>k;
	cout<<min(n%k,abs(k-n%k))<<endl;
	return 0;
}


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

using namespace std;

int main()
{
    int n;
    int d[100];
    int i,j,ans = 0;
    cin >> n;
    for(i = 0;i < n;i++)
    {
        cin >> d[i];
    }
    for(i = 0;i < n;i++)
    {
        for(j = i;j < n;j++)
        {
            if(i != j)
            {
            ans += d[i]*d[j];
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A, B;

		final int N = scanner.nextInt();

		visited = new boolean[N];
		root = new int[N];
		size = new int[N];
		int[] except = new int[N];
		graph = new ArrayList[N];

		for (int i = 0; i < N; i++) {
			graph[i] = new ArrayList<Integer>();
		}

		final int M = scanner.nextInt();
		final int K = scanner.nextInt();

		for (int i = 0; i < M; i++) {
			A = scanner.nextInt() - 1;
			B = scanner.nextInt() - 1;
			graph[A].add(B);
			graph[B].add(A);
			except[A]++;
			except[B]++;
		}

		for (int i = 0; i < N; i++) {
			if (!visited[i]) {
				DFS(i, i);
			}
		}

		for (int i = 0; i < K; i++) {
			A = scanner.nextInt() - 1;
			B = scanner.nextInt() - 1;
			if (root[A] == root[B]) {
				except[A]++;
				except[B]++;
			}
		}
		for (int i = 0; i < N; i++) {
			System.out.print(size[root[i]] - except[i] - 1);
			System.out.print(i == N - 1 ? "\n" : " ");
		}

	}

	static List<Integer>[] graph;
	static boolean[] visited;
	static int[] root;
	static int[] size;

	static void DFS(int rep, int vertex) {
		visited[vertex] = true;
		root[vertex] = rep;
		size[rep]++;
		graph[vertex].forEach(neighbor -> {
			if (!visited[neighbor]) {
				DFS(rep, neighbor);
			}
		});
	}

}


Measured memory_bytes: 160400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

//幅優先探索(グリッド)
//{i, j}:始点
//visit:1:訪問済み
//task:訪問予定
//depth:始点を0とするtask.front()の深さ
//pushしたマスは訪問済みにすること
ll bfs(ll h, ll w, vector<string> &grid, ll i, ll j) {
  vector<vector<ll>> visit(h, vector<ll>(w, 0));
  queue<vector<ll>> task;
  task.push({i, j});
  visit.at(i).at(j) = 1;
  ll depth = 0;
  while (task.size() > 0) {
    ll sz = task.size();
    for (ll i = 0; i < sz; i++) {
      ll y = task.front().at(0), x = task.front().at(1);
      if (y + 1 == h - 1 && x == w - 1) return depth + 1;
      if (y - 1 == h - 1 && x == w - 1) return depth + 1;
      if (y == h - 1 && x + 1 == w - 1) return depth + 1;
      if (y == h - 1 && x - 1 == w - 1) return depth + 1;
      if (y + 1 < h && grid.at(y + 1).at(x) == '.' && visit.at(y + 1).at(x) == 0) {
        task.push({y + 1, x});
        visit.at(y + 1).at(x) = 1;
      }
      if (y - 1 >= 0 && grid.at(y - 1).at(x) == '.' && visit.at(y - 1).at(x) == 0) {
        task.push({y - 1, x});
        visit.at(y - 1).at(x) = 1;
      }
      if (x + 1 < w && grid.at(y).at(x + 1) == '.' && visit.at(y).at(x + 1) == 0) {
        task.push({y, x + 1});
        visit.at(y).at(x + 1) = 1;
      }
      if (x - 1 >= 0 && grid.at(y).at(x - 1) == '.' && visit.at(y).at(x - 1) == 0) {
        task.push({y, x - 1});
        visit.at(y).at(x - 1) = 1;
      }
      task.pop();
    }
    depth++;
  }
  return - 1;
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; i++) cin >> grid.at(i);
  int cnt = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (grid.at(i).at(j) == '.') cnt++;
  int memo = bfs(h, w, grid, 0, 0);
  if (memo == - 1) neg();
  else cout << cnt - memo - 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	int H,W;
	for(;;){
		
		cin>>H>>W;
		
		if(H==0&&W==0)break;
		
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i==0||i==H-1||j==0||j==W-1){
					cout<<"#";
				}
				else
				    cout<<".";	
			}
			cout<<"\n";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
int n,k,a[105],m;
int half(int x,int m)
{
    if(m==0)
        return 1;
    if(x>=n)
        return 0;
    int ret=half(x+1,m)||half(x+1,m-a[x]);
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d",&k);
        if(half(0,k))
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}



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

int top, S[1000];

void push(int x)
{
S[++top]=x;

}
int pop()
{
top--;
return S[top+1];
}
int main()
{
int a,b;
top = 0;
char s[100];
while(scanf("%s",&s)!=EOF)
{
	if(s[0]=='+')
	{
		a =pop();
		b =pop();
		push(a + b);
	}
	else if(s[0]=='-')
	{
		b =pop();
		a =pop();
		push(a - b);
	}
	else if(s[0]=='*')
	{
		a = pop();
		b = pop();
		push(a * b);
	}
	else
	{
		push(atoi(s));
	}
}
printf("%d\n",pop());
return 0;

}


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

#define N 1000000007

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> p(n);
    vector<ll> c(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; i++)
        cin >> c[i];

    ll max_point = -10e16;

    for (int i = 0; i < n; i++) {
        int cur = i;
        ll point = 0;
        ll loop_size = 0;

        while (true) {
            cur = p[cur];
            point += c[cur];
            loop_size++;
            if (cur == i) break;
        }

        ll point_sub = 0;
        for (int j = 0; j < min(k, loop_size); j++) {
            cur = p[cur];
            point_sub += c[cur];
            max_point = max(max_point,
                    max(0ll, point) * (ll)((k - j - 1) / loop_size) + point_sub);
        }
    }
    cout << max_point << endl;
    return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
#define maxn 100005
#define inf (1<<30)
#define mod 1000000007
using namespace std;
typedef long long LL;
int read()
{
	char c=getchar();int f=1,sum=0;
	while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}
int L;
int bit[25],sum[25];
void init()
{
	sum[0]=bit[0]=1;
	for(int i=1;i<=21;i++)
	{
		bit[i]=bit[i-1]<<1;
		sum[i]=sum[i-1]+bit[i];
	}
}
int res[25],tot; 
int main()
{
	init();
	L=read();
	for(int i=0;bit[i]<=L;i++)
	{
		if(L&bit[i])
		res[++tot]=i;
	}
	printf("%d %d\n",res[tot]+1,res[tot]*2+tot-1);
	for(int i=1;i<=res[tot];i++)
		printf("%d %d 0\n",i,i+1);
	for(int i=res[tot]+1;i>=2;i--)
		printf("%d %d %d\n",i-1,i,bit[res[tot]+1-i]);
	int maxa=sum[res[tot]-1];
	for(int i=tot-1;i>=1;i--)
	{
		maxa++;
		printf("1 %d %d\n",res[tot]+1-res[i],maxa);
		maxa+=sum[res[i]-1];
	}
	return 0;
}


Measured memory_bytes: 256
H, W = (int(i) for i in input().split())
map = [list(input()) for i in range(H)]

count = 0
for h in range(H):
    for w in range(W):
        if map[h][w] == "#":
            count += 1
if count == H + W - 1:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;

int main() {
    string s;
    cin >> s;
    int n,m;
    for (int i=0;i<s.size();i++){
        if (s.at(i)=='A'){
            n =i;
            break;
        }
    }
    for (int i=s.size()-1;i>=0;i--){
        if (s.at(i)=='Z'){
            m =i;
            break;
        }
    }
    string new_s = s.substr(n,m-n+1);
    cout << new_s.size() << endl;
    return 0;
}

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

int main() {
	int n,flag=1;
	long a[200],ans=0;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(a[i]%2 != 0){
			flag=0;
			break;
		}
	}
	
	while(flag!=0){
		ans++;
		for(int j=0;j<n;j++){
			a[j] = a[j]/2;
			if(a[j]%2 != 0){
				flag=0;
				break;
			}
		}	
	}
	cout << ans << endl;
	return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int h, w;
int a[80][80];
int b[80][80];

const int kMax = 80 * 80 * 40;
using bs = bitset<kMax * 2 + 1>;
bs dp[81][81];

int main() {
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> a[i][j];
  rep(i, h) rep(j, w) cin >> b[i][j];
  dp[0][1][kMax] = 1;
  rep(i, h) rep(j, w) {
    int d = abs(a[i][j] - b[i][j]);
    // dbg(i + 1, j + 1, d);
    bs b = (dp[i][j + 1] | dp[i + 1][j]);
    rep(k, 1000) if (b[k]) {
      dbg(i, j, k);
    }
    // dbg(bitset<32>(b.to_ullong()));
    bs rev = 0;
    rep(i, d - 1) rev[d - 2 - i] = b[i];
    dp[i + 1][j + 1] = (b << d) | (b >> d) | rev;
    // dbg(bitset<32>(dp[i + 1][j + 1].to_ullong()));
  }
  rep(i, 80 * 80 * 40 + 1) if (dp[h][w][i + kMax]) {
    out(i);
    return 0;
  }
}


Measured memory_bytes: 406784
k = int(input())
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(s[k-1])

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main() {
	int A, B, C, D, P;
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;
	cin >> P;
	int x, y;
	x = A * P;
	if (C > P) {
		y = B;
	}
	if (C < P) {
		y = B + (P - C)*D;
	}
	if (x < y) {
		cout << x << endl;
	}
	if (x > y) {
		cout << y << endl;
	}
	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define MOD ll(1e9 + 7)
using namespace std;

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

int arr[81][81];
bool dp[81][81][81 * 2 * 81];

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

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++)
            cin >> arr[i][j];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0, t; j < m; j++) {
            cin >> t;
            arr[i][j] -= t;
        }
    }

    dp[0][0][abs(arr[0][0])] = true;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            for (int k = 0; k < 81 * 2 * 81; k++) {
                if (!dp[i][j][k]) continue;
                if (abs(k + arr[i][j+1]) < 81 * 2 * 81)
                    dp[i][j+1][abs(k + arr[i][j+1])] = true;
                if (abs(k - arr[i][j+1]) < 81 * 2 * 81)
                    dp[i][j+1][abs(k - arr[i][j+1])] = true;
                if (abs(k + arr[i+1][j]) < 81 * 2 * 81)
                    dp[i+1][j][abs(k + arr[i+1][j])] = true;
                if (abs(k - arr[i+1][j]) < 81 * 2 * 81)
                    dp[i+1][j][abs(k - arr[i+1][j])] = true;
            }
        }
    }

    for (int i = 0; i < 81 * 2 * 81; i++) {
        if (dp[n-1][m-1][i]) {
            cout << i;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 83456
n, w = map(int, input().split())

weight = []
value = []

for i in range(n):
    a, b = map(int, input().split())
    weight.append(a)
    value.append(b)

max_v = sum(value)

#dp[i][j] := i番目までの品物から価値がj以上を達成するように選んだときの重さの和の最小値
inf = float("inf")
dp = [[inf]*(max_v+1) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
    for j in range(max_v+1):
        if j - value[i] >= 0:
            dp[i+1][j] = dp[i][j-value[i]]+weight[i]
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

ans = 0
for j in range(max_v+1):
    if dp[n][j] > w:
            continue
    else:
        ans = max(ans, j)
print(ans)


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s = sc.next();
		//String t = sc.next();
		//String g = sc.next();
		long n = sc.nextLong();
		//long m = sc.nextLong();
		//long k = sc.nextLong();
		//long l = sc.nextLong();
		long count=0;
		long[] array=new long[3];

		/*for(int i=0;i<=3;i++) {
			if(s.substring(i,i+1).equals("+")) {
				count++;
			}else {
				count--;
			}
		}*/
		Arrays.sort(array);
		if(n==1) {
			System.out.println("Hello World");
		}else {
			long m = sc.nextLong();
			long k = sc.nextLong();
			System.out.println(m+k);
		}
		//System.out.println(array[2]*10+array[1]+array[0]);
		//System.out.println(Math.abs(array[2]-array[1])+Math.abs(array[1]-array[0]));
	}
}




Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;ans%=mod;}b/=2;a*=a;a%=mod;} return ans;}
//lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(vi) (vi.begin(),vi.end())
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
#define MAX 100005
lli fact[100005];
lli invmod[100005];
lli a[MAX];
int ct[MAX];

int main()
{
    int n,x,pos1=-1,pos2=-1;
    si(n);

    fact[0]=fact[1]=1;
    invmod[0]=invmod[1]=1;

    for(int i=2;i<MAX;i++){
        fact[i]=i*fact[i-1]*1LL;
        fact[i]%=mod;
        invmod[i]=power(fact[i],mod-2);
    }

    for(int i=0;i<=n;i++){
        si(x);
        a[i]=x;
        ct[x]++;
    }

    for(int i=0;i<=n;i++){
        if(ct[a[i]]>1){
            if(pos1==-1) pos1=i;
            else pos2=i;
        }
    }

    int d=pos2-pos1;

    for(int i=1;i<=n+1;i++){
        lli sub=0;
        lli ans=fact[n+1];
        ans*=invmod[i];
        ans%=mod;
        ans*=invmod[n+1-i];
        ans%=mod;

        if(n-d < i-1) sub=0;
        else{
            sub=fact[n-d];
            sub*=invmod[i-1];
            sub%=mod;
            sub*=invmod[n-d-i+1];
            sub%=mod;
        }
        ans-=sub;
        if(ans<0) ans+=mod;
        ans%=mod;

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


Measured memory_bytes: 3968
import scala.io.{StdIn => in}

object Main extends App {
  val Array(a, b) = in.readLine.split(" ").map(_.toInt)

  def check(i:Int):Boolean = {
    val s = String.valueOf(i)
    s(0) == s(4) && s(1) == s(3)
  }
  val ans = (a to b).map(check).count(_ == true)
  println(ans)
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
}

Measured memory_bytes: 3624
/**
 *   created: 09 January 2019  20:00:37
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#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 INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007

void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int n,a,b;
	cin>>n>>a>>b;
	cout<<(n-a+1)*(n-b+1);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define LL long long
using namespace std;
const int N=200005;
const LL inf=1ll<<40;
int n,q,sta,stb;
int x[N];
struct tree
{
	LL mv1[N*4],mv2[N*4],tag[N*4];//mv1-> f[x]-x mv2 -> f[x]+x
	void pushup(int k)
	{
		mv1[k]=min(mv1[k<<1],mv1[k<<1|1]);
		mv2[k]=min(mv2[k<<1],mv2[k<<1|1]);
	}
	void setv(int k,LL v){tag[k]+=v;mv1[k]+=v;mv2[k]+=v;}
	void pushdown(int k)
	{
		if(!tag[k])return;
		setv(k<<1,tag[k]);setv(k<<1|1,tag[k]);
		tag[k]=0;
	}
	void build(int k,int l,int r)
	{
		tag[k]=0;
		if(l==r){mv1[k]=mv2[k]=inf;return;}
		int mid=(l+r)>>1;
		build(k<<1,l,mid);build(k<<1|1,mid+1,r);
		pushup(k);
	}
	void upd(int k,int l,int r,int pos,LL v)
	{
		if(l==r){if(v<mv1[k]+l){mv1[k]=v-l;mv2[k]=v+l;}return;}
		int mid=(l+r)>>1;
		pushdown(k);
		if(mid>=pos)upd(k<<1,l,mid,pos,v);
		else upd(k<<1|1,mid+1,r,pos,v);
		pushup(k);
	}
	LL query1(int k,int l,int r,int ql,int qr)// query mv1
	{
		if((l>=ql&&r<=qr)||mv1[k]>=inf)return mv1[k];
		int mid=(l+r)>>1;LL res=inf;
		pushdown(k);
		if(mid>=ql)res=min(res,query1(k<<1,l,mid,ql,qr));
		if(mid<qr)res=min(res,query1(k<<1|1,mid+1,r,ql,qr));
		return res;
	}
	LL query2(int k,int l,int r,int ql,int qr)// query2 mv2
	{
		if((l>=ql&&r<=qr)||mv2[k]>=inf)return mv2[k];
		int mid=(l+r)>>1;LL res=inf;
		pushdown(k);
		if(mid>=ql)res=min(res,query2(k<<1,l,mid,ql,qr));
		if(mid<qr)res=min(res,query2(k<<1|1,mid+1,r,ql,qr));
		return res;
	}
	LL querya(int k,int l,int r)
	{
		if(l==r)return mv1[k]+l;
		int mid=(l+r)>>1;
		pushdown(k);
		return min(querya(k<<1,l,mid),querya(k<<1|1,mid+1,r));
	}
}t;
int Abs(int x){return x<0?-x:x;}
int input()
{
	int x=0,F=1;
	char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')F=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return x*F;
}
int main()
{
	cin>>n>>q>>sta>>stb;
	for(int i=1;i<=q;i++)x[i]=input();
	x[0]=sta;
	t.build(1,1,n);
	t.upd(1,1,n,stb,0);
	for(int i=1;i<=q;i++)
	{
		LL minv=min(t.query1(1,1,n,1,x[i])+x[i],t.query2(1,1,n,x[i]+1,n)-x[i]);
		t.setv(1,Abs(x[i]-x[i-1]));
		t.upd(1,1,n,x[i-1],minv);
	}
	cout<<t.querya(1,1,n);
	return 0;
}


Measured memory_bytes: 16272
import math
def f(a,b):
    return math.factorial(a) // (math.factorial(a - b) * math.factorial(b))

n,a,b=map(int, input().split())
v=list(map(int, input().split()))
v.sort(reverse=True)
c=0
if v[0]==v[a-1]:
    for i in range(a,min(b,v.count(v[0]))+1):
        c+=f(v.count(v[a-1]),i)
    print(sum(v[:a])/a)
    print(c)
else: 
    print(sum(v[:a])/a)
    print(f(v.count(v[a-1]),v[:a].count(v[a-1])) )

Measured memory_bytes: 3064
import scala.io.StdIn.{readLine,readDouble}

object Main extends App {

  val n = readDouble
  val v1 = readLine.split(" ").map(_.toDouble)
  val v2 = readLine.split(" ").map(_.toDouble)

  val p1 = (v1,v2).zipped.foldLeft(0d) {(x,y)=> x + Math.abs(y._1 - y._2)}
  val p2 = (v1,v2).zipped.foldLeft(0d) {(x,y)=> x + Math.pow(y._1 - y._2,2)}
  val p3 = (v1,v2).zipped.foldLeft(0d) {(x,y)=> x + Math.pow(Math.abs(y._1 - y._2),3)}
  val pinf = (v1,v2).zipped.foldLeft(0d) {(x,y)=> Math.max(x,Math.abs(y._1 - y._2))}

  println(p1)
  println(Math.sqrt(p2))
  println(Math.cbrt(p3))
  println(pinf)
}

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

using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<double> x(n), y(n);
  REP(i, n) cin >> x[i] >> y[i];
  double res = 0;
  REP(j, n) REP(i, j) {
    res += hypot(x[j] - x[i], y[j] - y[i]);
  }
  cout << fixed << setprecision(15) << res * 2 / n << endl;
}

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

struct pair{
	int a;
	int b;
};
int compare_int(const void *a, const void *b)
{
	return ((struct pair*)a)->b - ((struct pair*)b)->b;
}

int main(void){
	int n,m;
	scanf("%d %d",&n,&m);
	int i,j;
	struct pair arr[m];
	for(i=0;i<m;i++){
		scanf("%d %d",&arr[i].a,&arr[i].b);
	}
	qsort(arr,m,sizeof(struct pair), compare_int);
	int max = 0;
	int ans = 0;
	for(i=0;i<m;i++){
		if(max<arr[i].a){
			max = arr[i].b -1;
			ans ++;
		}
	}
	/*printf("--------\n");
	for(i=0;i<m;i++){
		printf("%d %d\n",a[i],b[i]);
	}*/
	printf("%d",ans);
	return 0;
}	

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


struct Point
{
	int x;
	int y;
	bool operator<(const Point &r) const
	{
		if(y!=r.y) return (y<r.y);
		return (x<r.x);
	}
};

bool notbottom(Point a, Point b, Point c)
{
	int val = (a.x-b.x)*(c.y-b.y)-(a.y-b.y)*(c.x-b.x);
	if(val<0) return false;
	return true;
}

//adrew convex hull implementation
int main()
{
	int n;
	scanf("%d", &n);
	Point array[n];
	int x,y;
	for(int i=0;i<n;i++)
	{
		scanf("%d %d", &x, &y);
		array[i] = {x,y};	
	}
	sort(array,array+n);

	//for(int i=0;i<n;i++) printf("%d %d\n", array[i].x, array[i].y);
	//build bottom part of hull
	vector<Point> bottom;
	for(int i=0;i<n;i++)
	{
		while((int)bottom.size()>=2 && notbottom(bottom[bottom.size()-2],bottom[bottom.size()-1], array[i])==false)
			bottom.pop_back();
		bottom.push_back(array[i]);
	}
	
	//build top side of hull
	vector<Point> top;
	for(int i=n-1;i>=0;i--)
	{
		while((int)top.size()>=2 && notbottom(top[top.size()-2],top[top.size()-1], array[i])==false)
			top.pop_back();
		top.push_back(array[i]);
	}
	printf("%d\n",(int)top.size()+(int)bottom.size()-2);
	for(int i=top.size()-1;i>=1;i--) printf("%d %d\n", top[i].x,top[i].y);
	for(int i=bottom.size()-1;i>=1;i--) printf("%d %d\n", bottom[i].x,bottom[i].y);


}



Measured memory_bytes: 4496
while 1:
	N, T, L, B = map(int,raw_input().split(" "))
	if N == T == L == B == 0: break
	check = 0
	dp = [[0 for _ in range(N+1)] for _ in range(T+1)]
	Lose = set([int(raw_input()) for _ in range(L)])
	Back = set([int(raw_input()) for _ in range(B)])
	dp[0][0] = 1
	for i in range(T):
		for j in range(N):
			rank = i-1 if j in Lose else i
			for d in range(1,7):
				next = j + d
				if next > N :
					next = N - (next - N)
				if next in Back:
					dp[i+1][0] += dp[rank][j] / 6.
				else :
					dp[i+1][next] += dp[rank][j] / 6.
	
	print "%6f" % sum([dp[i][N] for i in range(1,T+1)])

Measured memory_bytes: 4508
#include <stdio.h>
#include <string.h>

void wa(){ printf("WA\n"); }

int main(){
        char S[11] = {'\0'};
        int i, c = 0, a;
        scanf("%s", S);

        if(S[0] == 'A'){
                for(i = 2; i < strlen(S) - 1; i++){
                        if(S[i] == 'C') c++;
                }
                if(c == 1){
                        c = 0;
                        for(i = 0; i < strlen(S); i++){
                                if(!(S[i] >= 'a' && S[i] <= 'z')) c++;
                        }
                        if(c == 2) {
                                printf("AC\n");
                        }else {
                                wa();
                        }
                }else {
                        wa();
                }
        }else {
                wa();
        }
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
	int i, j;
	int x, y, z;
	
	cin >> x >> y;
	
	while (y > 0){
		z = x % y;
		x = y;
		y = z;
	}
	
	cout << x << "\n";
	
	return (0);
}



Measured memory_bytes: 3112
package main

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

func main() {
	s := nextLine()
	s = s[len(s)-1:]

	if s == "2" || s == "4" || s == "5" || s == "7" || s == "9" {
		fmt.Println("hon")
		return
	} else if s == "0" || s == "1" || s == "6" || s == "8" {
		fmt.Println("pon")
		return
	} else {
		fmt.Println("bon")
		return
	}
}

// =================================
// I/O util
// =================================

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 1756
#include <stdio.h>
int main(void){
	int N,Q,l,r,ans=0,i;
	scanf("%d%d",&N,&Q);
	char S[N+2];
	scanf("%s",S);
	S[N+1] = ' ';
	int ac[100001]={0},j=0;
	for(i=0;i<=N-1;i++){
		ac[i] = ans;
		if(S[i]=='A'&&S[i+1]=='C'){
			ac[i+1] = ++ans;
		}
	}
	for(i=0;i<Q;i++){
		scanf("%d%d",&l,&r);
		l--;r--;
		printf("%d\n",ac[r]-ac[l]);
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;


int main() {
    vector<int> v(100000,0),vv(100000,0);
    vector<int> rui(100000,0);
    v[1]=1;
    for(int i=3;i<=100000;i+=2){
        bool f=true;
        for(int j=3;j<=sqrt(i);j+=2){
            if(i%j==0){
                f=false;
                break;
            }
        }
        if(f)v[i-1]=1;
    }
    for(int i=1;i<=100000;i+=2){
        if(v[i-1]&&v[(i+1)/2-1])vv[i-1]=1;
    }
    rui[0]=vv[0];
    rep(i,1,100000){
        rui[i]=rui[i-1]+vv[i];
    }
    
    
    int n;cin>>n;
    rep(i,0,n){
        int a,b;
        cin>>a>>b;
        cout<<rui[b-1]-rui[a-2]<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
 int i;
 int n, x;
 scanf("%d", &n);
 for (i = 1; i <= n; i++){
  if (i % 3 == 0){
  printf(" %d", i);
  }
  else {
  x = i;
  while (x > 0){
   if (x % 10 == 3){
   printf(" %d", i);
   break;
   }
   x /= 10;
   }
  }
 }
 printf("\n");
 
 return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <algorithm>
#include <vector>
#include "string"

using namespace std;

typedef long long ll;

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

    string input;
    cin >> input;

    int sum = 0;
    for (int i = 0; i < input.length(); i++) {
        if (input[i] == 'o') sum++;
    }
    if (sum + 15 - input.length() >= 8) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


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

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n;
long long k;
const long long mod = 1e9+7;
struct matrix{
    long long t[51][51];
};
int can[51][51];
matrix multi(matrix a,matrix b)
{
    matrix c;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            c.t[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                c.t[i][j]=(c.t[i][j]+a.t[i][k]*b.t[k][j])%mod;
            }
        }
    }
    return c;
}
matrix power(matrix a,long long x)
{
    if(x==0)
    {
        matrix dv;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                dv.t[i][j]=0;
                if(i==j)
                    dv.t[i][j]=1;
            }
        }
        return dv;
    }
    if(x==1)
        return a;
    matrix t=multi(a,a);
    if(x%2==0)
        return power(t,x/2);
    else
        return multi(a,power(t,x/2));
}
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            scanf("%d",&can[i][j]);
        }
    }
    matrix t1,t2;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            t1.t[i][i]=1LL;
            t2.t[i][j]=can[i][j];
        }
    }
    while(k)
    {
        if(k%2)
        {
            t1=multi(t1,t2);
        }
        t2=multi(t2,t2);
        k/=2;
    }
    //matrix kq=power(t2,k);
    //kq=multi(kq,t1);
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            ans+=t1.t[i][j];
            ans%=mod;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
class Node:
    def __init__(self, value):
        self.value = value
        self.next = None


class Queue:
    def __init__(self):
        self.first = None
        self.last = None

    def enqueue(self, value):
        if value is None:
            raise ValueError('enqueue None')
        node = Node(value)
        if self.last is not None:
            self.last.next = node
        self.last = node
        if self.first is None:
            self.first = node

    def front(self):
        if self.first is None:
            return None
        return self.first.value

    def dequeue(self):
        if self.first is None:
            return None
        value = self.first.value
        if self.first == self.last:
            self.last = None
        self.first = self.first.next
        return value


def run():
    n, nq = [int(x) for x in input().split()]
    qs = [Queue() for _ in range(n)]

    for _ in range(nq):
        line = input()
        if line.startswith('0'):
            command, target, value = [int(x) for x in line.split()]
            qs[target].enqueue(value)
        elif line.startswith('1'):
            command, target = [int(x) for x in line.split()]
            value = qs[target].front()
            if value is not None:
                print(value)
        elif line.startswith('2'):
            command, target = [int(x) for x in line.split()]
            qs[target].dequeue()
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()



Measured memory_bytes: 45316
package main

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

var sc = bufio.NewScanner((os.Stdin))

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

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b, x := nextInt(), nextInt(), nextInt()

	fmt.Printf("%d\n", ABC048B(a, b, x))
}

// ABC048B ...
func ABC048B(a, b, x int) int {
	if a == 0 {
		return b/x - (a)/x + 1
	}
	return b/x - (a-1)/x
}


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

int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  if (k > a + b) {
    a = 0;
    b = 0;
  }
  else if (k > a) {
    b = b - (k - a);
    a = 0;
  }
  else {
    a = a - k;
  }
  cout << a << " " << b;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string x;
string b[10];
char a[11]="abcdefghij";
int n;
void dfs(int i,string s,char sh)
{    
    string v=s;
    if(i==n)
    {
    cout<<v<<endl;
    return ;
	}

	for(char ch='a';ch<='j';ch++)
	if(ch-'a'<=i&&ch-sh<=1)
	{	
	char th=(ch<=sh)? sh: ch;
	dfs(i+1,s+ch,th);
	
	}

}
int main()
{  
	scanf("%d",&n);
	dfs(1,"a",'a');
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
typedef pair<lli, int> pii;



int main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    vector<int> v;
    v.push_back(0);
    for(int i=0; i<n; ){
        char c = s[i];
        int cnt = 0;
        while(i<n && s[i] == c){
            cnt++;
            i++;
        }
        v.push_back(cnt);
    }
    for(int i=1; i<v.size(); i++){
        v[i] += v[i-1];
    }
    int kk = k*2;
    int mod = 1;
    if(s[0] == '1') kk++, mod--;

    if(kk >= v.size()-1){
        cout << n << "\n";
        return 0;
    }
//    for(auto x: v){
//        cout << x << " ";
//    }
//    cout << endl;
    int ans = 0, i, j;
    int cnt=0;
    for(i=1, j=0; j<v.size(); ){
        if(cnt < k){
            j++;
            if(j%2 == mod) cnt++;
        }
        else if(cnt > k){
            if(i%2 == mod && i!=0) cnt--;
            i++;
        }
        else if(cnt == k){
            ans = max(ans, v[j]-v[i-1]);
            j++;
            if(j%2 == mod)cnt++;
        }
    }
    cout << ans << "\n";

    return 0;
}


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

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


MOD = 10**9 + 7
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

L = read_a_int()
print((L / 3)**3)


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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define all(a) a.begin(), a.end()

template <typename T>
T Sum(vector<T> n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}
template <>
ld Sum(vector<ld> n, ll a, ll b)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T, typename U, typename W>
void V3(T &n, U &m, W &p)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i] >> p[i];
  }
}

void fYn(bool a)
{
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  exit(0);
}
//最大公約数
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
//最小公倍数
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}
//複数個の最小公倍数
ll nlcm(vector<ll> numbers)
{
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++)
  {
    res = lcm(res, numbers[i]);
  }
  return res;
}
//累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//大文字->小文字(+32)
//少数はなるべく整数に

void Main()
{
  ll n, d; cin >> n >> d;
  d = d + d + 1;
  ll ans = n / d;
  if(n % d != 0) ans++;
  fin(ans)
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
def matrix_chain_mutliplication(n, m, p)
  for l in 2..n
    for i in 1..n - l + 1
      j = i + l - 1
      m[i][j] = Float::INFINITY
      for k in i..j-1
        m[i][j] = [m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]].min
      end
    end
  end
end

n = gets.to_i
m = Array.new(n+1) { Array.new(n+1, 0) }
p = []
n.times do |i|
  r, c = gets.split.map(&:to_i)
  if i.zero?
    p << r
  end
  p << c
end
matrix_chain_mutliplication(n, m, p)
puts m[1][n]


Measured memory_bytes: 6924
x, n = gets.chomp.split(' ').map(&:to_i)
 
if n == 0
  puts x
  exit
end
 
ps = gets.chomp.split(' ').map(&:to_i)
 
values = (0..101).to_a.delete_if { |v| ps.include?(v) }
 
abs_values =
  values.each_with_object([]) do |value, objects|
    abs =  (x - value.abs).abs
    objects << abs
  end
 
min_abs = abs_values.min
puts values[abs_values.find_index(min_abs)]

Measured memory_bytes: 14348
#include<iostream>
using namespace std;
int main(){
  int n,i,flag=1;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=1;i<n;i++){
    if(a[i]-a[i-1]==-1)
      a[i]++;
    if(a[i]-a[i-1]<-1){
      flag=0;
      break;
    }
  }
  if(flag)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  
  return 0;
}

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

int st,e;

bool all_zero(int *h,int N){
  bool rtn = true;
  for(int i=0;i<N;i++){
    if(h[i] > 0) rtn = false;
  }
  for(int i=0;i<N;i++){
    if(h[i] != 0){
      st = i;
      break;
    }
  }
  for(int i=st;i<N;i++){
    e = i;
    if(h[i] == 0){
      e--;
      break;
    }
  }

  return rtn;
}

int main(void){
  int N;
  int h[101];
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  int ans = 0;
  while(!all_zero(h,N)){
    for(int i=st;i<=e;i++){
      h[i]--;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256