akhauriyash/Code-Regression huggingface dataset:
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
const int N=25;
int root,par[N],chl[N][2],sib[N];
int depth(int v){
	if (par[v]==-1) return 0;
	else return depth(par[v])+1;
}
int height(int v){
	if (chl[v][0]==-1&&chl[v][1]==-1) return 0;
	int a=0,b=0;
	if (chl[v][0]!=-1) a=height(chl[v][0]);
	if (chl[v][1]!=-1) b=height(chl[v][1]);
	return 1+max(a,b);
}
main(){
	int n,node,l,r;
	scanf("%d",&n);
	memset(par,-1,sizeof(par));
	memset(sib,-1,sizeof(sib));
	for (int i=0;i<n;i++){
		scanf("%d%d%d",&node,&l,&r);
		chl[node][0]=l;chl[node][1]=r;
		par[l]=par[r]=node;
		sib[l]=r;sib[r]=l;
	}
	for (int i=0;i<n;i++)
		if (par[i]==-1){
			root=i;
			break;
		}
	for (int i=0;i<n;i++){
		printf("node %d: ",i);
		printf("parent = %d, ",par[i]);
		printf("sibling = %d, ",sib[i]);
		int deg=0;for (int j=0;j<2;j++) if (chl[i][j]!=-1) deg++;
		printf("degree = %d, ",deg);
		printf("depth = %d, ",depth(i));
		printf("height = %d, ",height(i));
		if (root==i) printf("root");
		else if (deg) printf("internal node");
		else printf("leaf");
		printf("\n");
	}	
}
//node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root


Measured memory_bytes: 3212
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,s;
	while(~scanf("%d%d",&a,&b))
	{
		s=0;
		int z[a],x[a];
		for(int i=1;i<a;i++)
		{
			z[0]=b;
			x[0]=fabs(z[0]);
			z[i]=z[i-1]+1;
			x[i]=fabs(z[i]);
			s+=z[i]; 
		}
		sort(x,x+a);
		if(s+z[0]<0)
		printf("%d\n",s+z[0]+x[0]);
		else
		printf("%d\n",s+z[0]-x[0]);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        Integer c[] = new Integer[n];

        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }
        Arrays.sort(c, Collections.reverseOrder());
        int a = 0, b = 0;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                a += c[i];
            } else {
                b += c[i];
            }
        }
        System.out.println(a - b);
    }
}

Measured memory_bytes: 22732
a = [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]

k = int(input())

print(a[k-1])

Measured memory_bytes: 38256
#include<iomanip>
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;
const int INF = 1001001001;
int main(){
  int n,tmp=0;
  cin >> n;
  vector<int> h(n);h.at(0)=0;
  vector<int> t(n);
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  for(int i=0;i<n-1;i++){
    if(h.at(i)>=h.at(i+1)){
      tmp++;
      t.at(i+1)=tmp;
    }
    else{
      tmp=0;
      t.at(i+1)=tmp;
    }
  }
  sort(t.begin(), t.end());
  cout << t.at(n-1);
}
  

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	static int[] G => ReadLine().Split().Select(int.Parse).ToArray();
	public K()
	{
		N = G[0];
		A = G;
		WriteLine(Calc(0, N - 1, 1, 1) + A[0] + A[N - 1]);
	}
	readonly int N;
	readonly int[] A;
	readonly Dictionary<Pair, long> memo = new Dictionary<Pair, long>();
	long Calc(int l, int r, long wl, long wr)
	{
		if (r - l <= 1) return 0;
		var p = new Pair(l, r, wl, wr);
		if (!memo.ContainsKey(p))
		{
			var w = wl + wr;
			memo[p] = long.MaxValue;
			for (var i = l + 1; i < r; i++) memo[p] = Min(memo[p], w * A[i] + Calc(l, i, wl, w) + Calc(i, r, w, wr));
		}
		return memo[p];
	}
}
struct Pair : IEquatable<Pair>
{
	public readonly int l, r;
	public readonly long wl, wr;
	public Pair(int l, int r, long wl, long wr) { this.l = l; this.r = r; this.wl = wl; this.wr = wr; }
	public bool Equals(Pair other) => l == other.l && r == other.r && wl == other.wl && wr == other.wr;
	public override int GetHashCode() => CombineHashCodes(l.GetHashCode(), r.GetHashCode(), wl.GetHashCode(), wr.GetHashCode());
	static int CombineHashCodes(int h1, int h2) => (((h1 << 5) + h1) ^ h2);
	static int CombineHashCodes(int h1, int h2, int h3, int h4) => CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4));
}


Measured memory_bytes: 39520
from heapq import heappush,heappop

def dij(s,g,E):
  h = []
  U = []
  heappush(h,(0,s))
  while h:
    v = heappop(h)
    if v[1] == g:
      if v[0] >= INF:print(-1)
      else:print(v[0])
      break
    U.append(v[1])
    for e in E[v[1]]:
      if not e[0] in U:
        heappush(h,(v[0] + e[1],e[0]))
  else:print(-1)
INF = 100000000
while True:
  try:
    n,k = map(int,input().split())
    if n == 0 and k == 0: break
    E = [[] for i in range(n)]
    for _ in range(k):
      lst = list(map(int,input().split()))
      if lst[0] == 0:
        dij(lst[1] - 1, lst[2] - 1, E)
      else:
        E[lst[1] - 1].append([lst[2] - 1, lst[3]])
        E[lst[2] - 1].append([lst[1] - 1, lst[3]])

  except EOFError:
    break



Measured memory_bytes: 5940
function main(input) {
    var a = input[0].split(" ")[0]-0;
    var b = input[0].split(" ")[1]-0;
    console.log(~~Math.max(a+b, a-b, a*b));
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))

Measured memory_bytes: 21064
#include <stdio.h>
#include <math.h>

typedef struct {double x,y;}Point;

void koch(int n,Point a,Point b){
  if(n==0)return;

  Point s,t,u;
  double th =M_PI *60.0/180.0;

  s.x =(2.0*a.x +1.0 *b.x)/3.0;
  s.y =(2.0*a.y +1.0 *b.y)/3.0;
  t.x = (1.0*a.x+2.0*b.x)/3.0;
  t.y = (1.0*a.y+2.0*b.y)/3.0;
  u.x = (t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y = (t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}

int main(){
  Point a,b;
  int n;

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}




Measured memory_bytes: 2036
S=list(input())
N2=((int(len(S))//2))
SS=S[0:N2]
A=0
B=-1

while SS[A]==SS[B]:
    A+=1
    B-=1
    if A>int(len(SS)//2):
        break

X=tuple(SS)
Y=tuple(S[N2+1:])
if A!=0 and X==Y:
    print("Yes")
else:
    print("No")

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

int n, k;
string s;

int main(){
  cin >> n >> k >> s;
  int fukou = 0;
  rep(i, n - 1){
    if(s[i] == 'R' && s[i + 1] == 'L'){
      fukou += 2;
    }
  }
  if(s.at(0) == 'L') fukou++;
  if(s.at(n - 1) == 'R') fukou++;
  cout << min(n - 1, n - fukou + k * 2) << endl;
  return 0;
}

Measured memory_bytes: 512
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

h ,w = gi
str = []
str << '#'*(w+2)
rep h do
str << '#'+gsf+'#'
end
str << '#'*(w+2)

puts str

Measured memory_bytes: 2300
const p = (...args) => {
  process.env.NODE_ENV === "test" ? console.log(...args) : ""
}

const solve = (n) => {
  const a = n.sort((a, b) => a - b)
  return a[0] + a[1]
  // ...
}
const main = (input) => {
  const n = input.split(" ").map(Number)
  return solve(n)
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}

if (process.env.NODE_ENV === "test") {
  // module.exports = (input) => solve(input.trim())
  // main(``)
  // solve(1, [2, 3, 4])
}


Measured memory_bytes: 7500
n, m = map(int, input().split())
ans = [0] * m
for _ in range(n):
    k, *a = [int(x) for x in input().split()]
    for i in a:
        ans[i-1] += 1
tmp = 0
for a in ans:
    if a == n:
        tmp += 1
print(tmp)


Measured memory_bytes: 3060
#include <iostream>
#define lli long long int
using namespace std;

int main()
{
    lli n;
    double a;
    cin >> n;
    if((lli)n % 2 == 1)
        a = (double)(n/2 + 1)/(double)n;
    if(n == 1)
        cout << "1.0000000000" << endl;
    else if(n % 2 == 0)
        cout << "0.5000000000" << endl;
    else if(n % 2 == 1)
        cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
        	int n = scan.nextInt();
        	if(n == 0){
        		break;
        	}
        	int[][] sq = new int[n][n];
        	int a = 2;
        	int x = n/2 + 1;
        	int y = n/2;
        	sq[x][y] = 1;
        	while(a <= n*n){
        		while(true){
        			x = (x == n-1)?0:x+1;
        			y = (y == n-1)?0:y+1;
        			if(sq[x][y] == 0){
        				sq[x][y] = a;
        				break;
        			}else{
        				x = (x == n-1)?0:x+1;
        				y = (y == 0)?n-1:y-1;
        				sq[x][y] = a;
        				break;
        			}
        		}
        		a++;
        	}
        	for(int i = 0;i < n;i++){
        		for(int j = 0;j < n;j++){
        			System.out.printf("%4d",sq[i][j]);
        		}
        		System.out.println();
        	}
        }
    }
}

Measured memory_bytes: 20068
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
 
#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

#define int long long

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9+7;

const int N = 2e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p=clock();



int32_t main(){
  fast;

  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);

  int n;
  cin >> n;
  vector<ii>v(n);
  FOR(i,0,n-1) {
    int x,l;
    cin >> x >> l;
    v[i].F = x - l;
    v[i].S = x + l;
  }
  int ans = 0;
  sort(all(v));
  debug(v);
  int maxr = -(1e9 + 1);
  for(auto x : v) {
    if(x.F < maxr) {
      if(x.S < maxr) {
        maxr = x.S;
      }
    }
    else {
      ans++;
      maxr = x.S;
    }
  }
  cout << ans << "\n";
  time_p=clock()-time_p;
  cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

  return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string s;
  ll w;
  cin>>s;
  cin>>w;
  
  for(ll i=0; i<s.size(); i+=w)
    cout<<s[i];
  cout<<endl;
    

}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
using namespace std;

long long gcd(long long a,long long b){
  return b?gcd(b,a%b):a;
}

long long lcm(long long a,long long b){
  return a/gcd(a,b)*b;
}

int f(int x){
  int res=0;
  while (x%2==0) {
    x/=2;
    res++;
  }
  return res;
}


int main() {
  int n,m;
  std::cin >> n>>m;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    if(a[i]%2==1)
    {
      std::cout << 0 << '\n';
      return 0;
    }
    a[i]/=2;
  }

  int t=f(a[0]);
  for (int i = 0; i < n; i++) {
    if(f(a[i])!=t){
      std::cout << 0 << '\n';
      return 0;
    }
    a[i]>>=t;
  }
  m>>=t;

  long long l=1;
  for (int i = 0; i < n; i++) {
    l=lcm(l,a[i]);
    if(l>m){
      std::cout << "0" << '\n';
      return 0;
    }
  }

  m/=l;
  int ans = (m+1)/2;
  std::cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        if (A * N > B) {
            System.out.println(B);
        } else {
            System.out.println(A * N);
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<set>
#include<map>
#include<iterator>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int main()
{
	int n;
	cin >> n;
	if (n == 25)
		cout << "Christmas" << endl;
	else if (n == 24)
		cout << "Christmas Eve" << endl;
	else if (n == 23)
		cout << "Christmas Eve Eve" << endl;
	else
		cout << "Christmas Eve Eve Eve" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ll N = 200005;
const ll M = 100005;
ll n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t, alphabet = "abcdefghijklmnopqrstuvwxyz";
ll a[N] = {}, b[N] = {}, dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
vll v;
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> m >> s >> t){
        ll n_mag = n / gcd(n, m), m_mag = m / gcd(n, m);
        rep(i, gcd(n, m)){
            if(s[i * n_mag] != t[i * m_mag]){
                print(-1);
                return 0;
            }
        }
        print(lcm(n, m));
    }
}


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

using namespace std;

void hawawa()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto&& i : a) {
		cin >> i;
	}
	long long ans = 0;
	int s = 0, now = 0, e = 0;
	while (e < n) {
		if (!(now & a[e]) || !now) {

			now += a[e];
			e++;
			ans += e - s;
		}
		else {
			now -= a[s];
			s++;
		}
	}
	cout << ans << "\n";
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define YESNO(i) if((i)) puts("YES");else puts("NO");
#define YesNo(i) if((i)) puts("Yes");else puts("No");
#define yesno(i) if((i)) puts("yes");else puts("no");
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  YesNo(!(s=="AAA"||s=="BBB"));
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//data types useful short forms
typedef long long ll;
typedef pair <ll, ll> pll;
// convenient definitions and functions
#define FIO                ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb                 push_back
#define sz(a)              long((a).size())
#define REP(x,l,u)         for(ll x = l;x<=u;x++)
#define loop(x,l,u)        for(ll x=  l;x<u;x++)
#define all(x)             (x).begin(),(x).end()
#define sorting(c)         sort(all(c))
const   ll mod = 1e9+7;



int main()
{
    FIO;
    int n,total;
    cin>>n>>total;
    vector<int>weight(n),value(n);
    for(int i=0;i<n;i++)
        cin>>weight[i]>>value[i];

    ll dp[n+1][total+1];
    //dp[I][J] gives the answer for array of lenght "I" with maximum capacity of 'J' 

    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=total;j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
            else
            {
            	dp[i][j]=dp[i-1][j];
            	if(j-weight[i-1]>=0)
                	dp[i][j]=max(value[i-1]+dp[i-1][j-weight[i-1]],dp[i][j]);
            }
        }
    }

    cout<<dp[n][total]<<endl;
}



Measured memory_bytes: 82424
import heapq
import math

n,m=map(int,input().split())
aa=list(map(int,input().split()))
a=[i*(-1) for i in aa]
heapq.heapify(a)

for i in range(m):
    high=heapq.heappop(a)
    heapq.heappush(a,-math.floor(-high/2))

print(-sum(a))


Measured memory_bytes: 85380
n, k = map(int, input().split())
ps = list(map(int, input().split()))
acc = 0
for i in range(k):
    acc += ps[i]
max_a = acc
for i in range(1,n-k+1):
    acc -= ps[i-1]
    acc += ps[i+k-1]
    max_a = max(max_a, acc)
print((max_a+k)/2)

Measured memory_bytes: 32056
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


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

    set<plint> info[100001];
    REP(i, M)
    {
        lint P, Y;
        cin >> P >> Y;
        info[P - 1].insert(plint(Y, i));
    }

    vector<lint> ans(M);
    REP(i, N)
    {
        lint now = 1;
        for (auto pa : info[i])
        {
            ans[pa.second] = 1000000LL * (i + 1) + now;
            now++;
        }
    }
    REP(i, M) printf("%012lld\n", ans[i]);
}


Measured memory_bytes: 13312
#include<stdio.h>
int main(void){
int a[31],b,c,i,j,k,l;
for(i=1;i<=30;i++){
    a[i]=i;
}
for(j=1;j<=28;j++){
    scanf("%d",&c);
    a[c]=0;
}

for(l=1;l<=30;l++){
    if(a[l]>0){
       printf("%d\n",a[l]);
    }
}
return 0;
}

Measured memory_bytes: 2752
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
    int order[5];
    for (int i = 0; i < 5; i++)
        cin >> order[i];

    int amari = 10;
    int last;
    for (int i = 0; i < 5; i++) {
        if (amari > order[i] % 10 && order[i] % 10 != 0) {
            last = i;
            amari = order[i] % 10;
        }
    }
    int time = 0;
    for (int i = 0; i < 5; i++) {
        if (i != last) {
            time += order[i];
            if (time % 10 != 0) {
                time += 10 - time % 10;
            }
        }
    }

    time += order[last];

    cout << time << endl;

    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* [💭] [💡] [🎈] */

bool f(vector<char> &res, char A, char B, int &a, int &b, bool nxa, bool nxb) {
    if (a == 0 && b == 0) {
        return false;
    } else if (a == 0) {
        res.emplace_back(A);
        a++, b--;
    } else if (b == 0) {
        res.emplace_back(B);
        b++, a--;
    } else {
        int m = (a + b) / 2;
        if (nxa && a == 1) {
            a++, b--;
            res.emplace_back(A);
        } else if (nxb && b == 1) {
            a--, b++;
            res.emplace_back(B);
        } else if (m > a) {
            a++, b--;
            res.emplace_back(A);
        } else {
            a--, b++;
            res.emplace_back(B);
        }
    }
    return true;
}

int op[100000];
// [0] = 'AB', [1] = 'BC', [2] = 'AC';

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

    int n, a, b, c;
    cin >> n >> a >> b >> c;

    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        if (str == "AB") op[i] = 0;
        if (str == "BC") op[i] = 1;
        if (str == "AC") op[i] = 2;
    }

    bool flag = true;
    vector<char> res;
    for (int i = 0; i < n && flag; i++) {
        if (a < 0 || b < 0 || c < 0) flag = false;

        bool nxa = false, nxb = false, nxc = false;
        if (i != n - 1) {
            if (op[i + 1] == 0)nxa = nxb = true;
            if (op[i + 1] == 1)nxb = nxc = true;
            if (op[i + 1] == 2)nxa = nxc = true;
        }
        if (op[i] == 0 && !f(res, 'A', 'B', a, b, nxa, nxb)) flag = false;
        if (op[i] == 1 && !f(res, 'B', 'C', b, c, nxb, nxc)) flag = false;
        if (op[i] == 2 && !f(res, 'A', 'C', a, c, nxa, nxc)) flag = false;
        if (!flag) break;
    }
    if (a < 0 || b < 0 || c < 0) flag = false;

    if (flag) {
        cout << "Yes\n";
        for (char c : res) {
            cout << c << '\n';
        }
    } else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 4164
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out ="";
    while (scanner.hasNext()) {
      int hh = scanner.nextInt();
      int mm = scanner.nextInt();
      int ss = scanner.nextInt();
      if (hh == -1 && mm == -1 && ss == -1) {
        break;
      }
      int remain1 = 120 * 60 - (hh * 60 * 60 + mm * 60 + ss);
      int remain3 = remain1 * 3;
      int rh = remain1 / 3600;
      int rm = (remain1 % 3600) / 60;
      int rs = remain1 - (rh * 3600 + rm * 60);
      out += String.format("%02d:%02d:%02d\n", rh, rm, rs);
      rh = remain3 / 3600;
      rm = (remain3 % 3600) / 60;
      rs = remain3 - (rh * 3600 + rm * 60);
      out += String.format("%02d:%02d:%02d\n", rh, rm, rs);
    }
    System.out.print(out);
  }
}

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

using namespace std;
using ll = long long;

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

    int n, a, ans = 0;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a;
        if(!(i & 1) && a & 1) ans++;
    }

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

    return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int h, w;
  int n;
  cin >> h >> w;
  cin >> n;
  int s = max(h, w);
  cout << (n + s - 1) / s << endl;
}

Measured memory_bytes: 256
def total_price(x, y, N):
    if (x + y) == N:
        return True
    elif x + y > N:
        return False
    ret1 = total_price(x + 4, y, N)
    ret2 = total_price(x, y + 7, N)
    return ret1 or ret2

N = int(input())
if total_price(0, 0, N):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 59608
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  Int neg=0;
  for(Int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]<0) neg++,a[i]*=-1;
  }
  sort(a.begin(),a.end());
  Int sum=0;
  for(Int i=0;i<n;i++) sum+=a[i];
  neg%=2;
  if(neg) sum-=a[0]*2;
  cout<<sum<<endl;
  return 0;
}


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

using namespace std;
using ll = long long;
#define BIG_PRIME 1000000007

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

int main()
{
    int n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    ll horizontal_sum = a[n-1];
    ll ans = 0;
    for (int i = n-2;i>=0;--i){
        ans+=horizontal_sum*a[i];
        ans%=BIG_PRIME;
        horizontal_sum+=a[i];
        horizontal_sum%=BIG_PRIME;
    } 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4840
n = int(input())
s1 = input()
s2 = input()
mod = 10 ** 9 + 7
if s1[0] == s2[0]:
  ans = 3
  flag = 1
  now = 1
else:
  ans = 6
  flag = 0
  now = 2
while now < n:
  if s1[now] == s2[now]:
    if flag:
      ans *= 2
    flag = 1
    now += 1
  else:
    if flag:
      ans *= 2
    else:
      ans *= 3
    flag = 0
    now += 2
  ans %= mod
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

	float a = 2 * X - Y / 2;
	float b = Y / 2 - X;
	if (a < 0 || b < 0 || Y % 2 != 0) cout << "No";
	else cout << "Yes";

	return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string n; cin >> n;
    
    vector<vector<vector<vector<vector<int>>>>> dp(n.size() + 1, vector<vector<vector<vector<int>>>>(2, vector<vector<vector<int>>>(2, vector<vector<int>>(2, vector<int>(2, 0)))));
    
    dp[0][0][0][0][0] = 1;
    
    for (int i = 0; i < n.size(); i++) {
        int ni = n.at(i) - '0';
        for (int j = 0; j < 2; j++) {
            for (int k3 = 0; k3 < 2; k3++) {
                for (int k5 = 0; k5 < 2; k5++) {
                    for (int k7 = 0; k7 < 2; k7++) {
                        for (int l = 0; l <= (j ? 9 : ni); l++) {
                            if (l == 0 && k3 == 0 && k5 == 0 && k7 == 0) {
                                dp[i + 1][j || l < ni][0][0][0] += dp[i][j][0][0][0];
                            }
                            if (l == 3) {
                                dp[i + 1][j || l < ni][1][k5][k7] += dp[i][j][k3][k5][k7];
                            }
                            if (l == 5) {
                                dp[i + 1][j || l < ni][k3][1][k7] += dp[i][j][k3][k5][k7];
                            }
                            if (l == 7) {
                                dp[i + 1][j || l < ni][k3][k5][1] += dp[i][j][k3][k5][k7];
                            }
                        }
                    }
                }
            }
        }
    }
    
    cout << dp[n.size()][0][1][1][1] + dp[n.size()][1][1][1][1] << endl;
    
    return 0;
}


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

int main(){
    int s;
    cin >>s;
if (s>=1200) cout << "ARC"<<endl;
else cout << "ABC"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <set>
std::set < int > S;
int a[100001], N;
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		scanf("%d", a + i);
	for (int i = 1; i <= N; i += 2)
		S.insert(a[i]);
	std::sort(a, a + N + 1);
	for (int i = 1; i <= N; i += 2)
	{
		auto it = S.find(a[i]);
		if (it != S.end())
			S.erase(it);
	}
	printf("%d\n", int(S.size()));
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
//vector<ll> visited(100,0);
vector<ll> vec[100];
vector<ll> cou(100,-1);
ll sum = 0;
queue<pair<ll,ll>> q;
void bfs(ll k,ll num){
  q.push(make_pair(k,num));
  pair<ll,ll> piv;
  while(!q.empty()){
    piv = q.front();
    q.pop();
    if(cou[piv.first] != -1){
      continue;
    }
    cou[piv.first] = piv.second;
    for(auto itr:vec[piv.first]){
      q.push(make_pair(itr,piv.second+1));
    }
  }
  cou[k] = num;

}
int main(){
  ll n;
  cin >> n;
  ll u,k,v;
  rep(i,n){
    cin >> u >> k;
    u--;
    rep(j,k){
      cin >> v;
      v--;
      vec[u].push_back(v);
    }
  }
  bfs(0,0);
  rep(i,n){
    cout << i+1 << " " << cou[i] << endl;
  }
}



Measured memory_bytes: 3172
from itertools import accumulate

n, k = list(map(int,input().split(" ")))
s = input()


def solve():
    l=[]
    prev = '1'
    cnt = 0
    for c in s:
        if prev ==c:
            cnt+=1
        else:
            l.append(cnt)
            cnt = 1
        prev=c
    l.append(cnt)
    if prev=='0':
        l.append(0)

    w = 2*k+1

    if len(l)<=w:
        return n

    acc = [0]+list(accumulate(l))
    ans = 0
    for i in range(0, len(l)-w+1,2):
        ans = max(ans,acc[i+w]-acc[i])
    return ans
print(solve())

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    int n, m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

char c[4] = {'m','c','x','i'};
int hun[4] = {1000,100,10,1};

int getsum(string a, string b){

  int ina = 0, inb = 0;
  int status = 1, kake = 0;
  for(int i = 0; i < a.length(); i++){
    if(a[i] >= '0' && a[i] <= '9') status = a[i]-'0';
    else{
      if(a[i] == 'm') kake = 1000;
      if(a[i] == 'c') kake = 100;
      if(a[i] == 'x') kake = 10;
      if(a[i] == 'i') kake = 1;
      ina += status * kake;
      status = 1;
    }
  }

  for(int i = 0; i < b.length(); i++){
    if(b[i] >= '0' && b[i] <= '9') status = b[i]-'0';
    else{
      if(b[i] == 'm') kake = 1000;
      if(b[i] == 'c') kake = 100;
      if(b[i] == 'x') kake = 10;
      if(b[i] == 'i') kake = 1;
      inb += status * kake;
      status = 1;
    }
  }
  return ina+inb;
}

string conv(int in){
  string out = "";
  int sum[4] = {0,0,0,0};
  for(int i = 0; i < 4; i++){
    sum[i] = in/hun[i];
    in  %= hun[i];
  }
  for(int i = 0; i < 4; i++){
    if(sum[i]){
      if(sum[i] > 1)out += sum[i]+'0';
      out += c[i];
    }
  }
  return out;
}

int main(){
  int num;
  cin >> num;
  for(int i = 0; i < num; i++){
    string a,b;
    cin >> a >> b;
    cout << conv(getsum(a,b)) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x));
            var a = input.First();
            var b = input.Skip(1).First();

            Console.WriteLine(new int[] { a + b, a + a - 1, b + b - 1 }.Max());
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;


int main(){
  while(true){
    int n,d;
    cin >> n >> d;
    if (n==0) break;
    vector<vector<int>> a(n,vector<int>(0));
    rep(i,n){
      int m;
      cin >> m;
      rep(j,m){
        int f;
        cin >> f;
        a[i].push_back(f);
      }
    }
    vector<int> b(n,0),c(n,0);
    int mi=0,mi2=0;
    while(true){
      bool t=true,tt=true;
      rep(i,n){
        if (b[i]==a[i].size()) continue;
        t=false;
        if (c[i]!=mi){
        if (a[i][b[i]]+c[i]<=mi+d){
          c[i]+=a[i][b[i]];
          b[i]++;
          tt=false;
          // cout << i << " " << c[i] << endl;
          break;
        }
        }
        else if (c[i]==mi){
        if (a[i][b[i]]+c[i]<=mi2+d){
          c[i]+=a[i][b[i]];
          b[i]++;
          tt=false;
          // cout << i << " " << c[i] << endl;
          break;
        }
        }
      }
      mi=inf;mi2=inf;
      rep(i,n){
        // cout << c[i] << " ";
        if (c[i]<mi){
          mi2=mi;
          mi=c[i];
        }
        else{
          mi2=min(mi2,c[i]);
        }
      }
      // cout << endl;
      // cout << mi << " " << mi2 << endl;
      if (tt) {
        if (t) cout << "Yes" << endl;
        else cout << "No" << endl;
        break;
      }
    }
  }
}



Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    string S;
    cin >> S;

    int ret = 0;
    FOR(i, 0, 3)
        ret += S[i] == '1';
    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


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

using namespace std;

typedef tuple<int, int, int, int> state;
typedef long long ll;

const int MAX_N = 20;

ll arr [MAX_N];
map<state, ll> dp;

ll calc_dp (state s) {
  if (dp.count(s) != 0) {
    return dp[s];
  }

  ll ans = 1LL << 60;
  int l = get<0>(s);
  int xl = get<1>(s);
  int r = get<2>(s);
  int xr = get<3>(s);
  
  if (l + 1 == r) {
    ans = arr[l] * (ll) xl + arr[r] * (ll) xr;
  } else {
    for (int k = l + 1; k < r; k++) {
      ans = min(ans,
		calc_dp(state(l, xl, k, xl + xr)) +
		calc_dp(state(k, xl + xr, r, xr)) -
		arr[k] * (ll) (xl + xr));
    }
  }

  // cout << l << " " << xl << " " << r << " " << xr << " " << ans << endl;
  dp[s] = ans;
  return ans;
}

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }

  cout << calc_dp(state(1, 1, n, 1)) << endl;

  // cerr << (int) dp.size() << endl;
}


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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};

int n, k, a[100001];


int main(){
	int mini;
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(a[i] == 1) mini = i;
	}

	if(mini <= k || mini > n-k){
		n-=k;
		cout << 1+n/(k-1)+(n%(k-1)?1:0) << endl;
	}else{
		int left1 = mini-(k-1)-1, right1 = n-(mini+(k-1));
		int ret1 =  2+left1/(k-1)+right1/(k-1)+(left1%(k-1)?1:0)+ (right1%(k-1)?1:0);
		int left2 = mini-(k-1)/2-1, right2 = n-(mini+(k-1)/2);
		int ret2 =  1+left2/(k-1)+right2/(k-1)+(left2%(k-1)?1:0)+ (right2%(k-1)?1:0);
		cout << min(ret1, ret2) << endl;
	}



	return 0;
}

Measured memory_bytes: 640
n, m, q = map(int, input().split())

arr = [[0 for j in range(n)] for i in range(n)]
arr_sum = []
arr_sum2 = []

for i in range(m):
    l, r = map(int, input().split())
    arr[l-1][r-1] += 1


for i in range(n):
    s = 0
    arr_tmp = []
    for j in range(n):
            s += arr[i][j]
            arr_tmp.append(s)
    arr_sum.append(arr_tmp)


for j in range(n):
    s = 0
    arr_tmp2 = []
    for i in range(n-1,-1,-1):
            s += arr_sum[i][j]
            arr_tmp2.append(s)
    arr_sum2.append(arr_tmp2)

arr_sum3 = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
    for j in range(n):
        arr_sum3[i][j] = arr_sum2[j][n-i-1]

ans_arr = []
for k in range(q):
    p, q = map(int, input().split())
    ans = arr_sum3[p-1][q-1]
    ans_arr.append(ans)

for i in ans_arr:
    print(i)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, x; cin >> N >> x;
    ll cnt = 0;
    vector<ll> a(N);
    rep(i, N){cin >> a.at(i);}
    rep(i, N - 1){
        if (a.at(i) >= x){cnt += (a.at(i) - x); a.at(i) = x;}
        ll b = a.at(i) + a.at(i + 1);
        if (b >= x){
            ll c = b - x;
            if (c >= a.at(i + 1)){
                cnt += a.at(i + 1);
                a.at(i + 1) = 0;
            } else {
                cnt += c;
                a.at(i + 1) -= c;
            }
        }
    }
    cout << cnt << endl;
}

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


Measured memory_bytes: 3952
#include<stdio.h>
int main()
{
    int N;
    double x,p;
    scanf("%d",&N);
    if(N%2==0){
        x=N/2;
        p=x/N;
        printf("%0.10lf\n",p);
    }
    else{
        x=(N+1)/2;
        p=x/N;
        printf("%0.10lf\n",p);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

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

int n;
cin >> n;
vi p(n),ps(n);
rep(i,n){
    cin >> p[i];
    ps[i] = p[i];
}
Sort(ps);
int temp=0;
rep(i,n)if(p[i]!=ps[i])temp++;
if(temp>=3)fin("NO");else fin("YES");
//////////////////////////////////////////////////////
return 0;}

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

using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long
#define all(x) (x).begin(), (x).end()
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

const ll MOD = 1e9+7;

ll dp[2004];

void solve() {
    int n;
    cin >> n;
    for (int i = 3; i <= n; ++i) {
        dp[i] = 1;
        for (int k = i - 3; k >= 3; --k)
            dp[i] = (dp[i] + dp[k]) % MOD;
    }
    cout << dp[n];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    // int t;
    // cin >> t;
    // while (t--)
        solve();
       
    return 0;
}


Measured memory_bytes: 3660
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using PLL = pair<LL,LL>;
using VPI = vector<PII>;
using VPL = vector<PLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)
#define all(v) v.begin(), v.end()

int main(){
  int n,m,ans=0;
  cin >> n >> m;
  VI a(m),b(m);
  REP(i,0,m){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }
  VI path(n-1);
  REP(i,0,n-1){
    path[i] = i+1;
  }
  
  sort(all(path));
  do{
    bool ok = false;
    
    REP(i,0,n-1){
      ok = false;
      if(i==0){
        REP(j,0,m){
          if(a[j] == 0 && b[j] == path[0]){
            ok = true;
            break;
          }
        }
      }
      
      if(i>0){
        int former = min(path[i],path[i-1]);
        int latter = max(path[i],path[i-1]);
        REP(j,0,m){
          if(former == a[j] && latter == b[j]){
            ok = true;
            break;
          }
        }
      }
      
      if(!ok){break;}
    }
    
    if(ok){
      ans++;
    }
    
  }while(next_permutation(all(path)));
    
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        // 同じなら進めるだけ進める
        while(i+1 <= n-1 && a[i] == a[i+1])i++;
        if(i+1 <= n-1 && a[i] > a[i+1]){
            while(i+1 <= n-1 && a[i] >= a[i+1]) i++;
        }
        else if(i+1 <= n-1 && a[i] < a[i+1]){
            while(i+1 <= n-1 && a[i] <= a[i+1]) i++;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import math
l=list(map(int,input().split()))
n,k=l[0],l[1]
while n>k:
  s=n//k
  n=n-(k*s)
if n==0:
  print('0')
else:
  if n<math.fabs(n-k):
    print(int(n))
  else:
    print(int(math.fabs(n-k)))

Measured memory_bytes: 3060