akhauriyash/Code-Regression huggingface dataset:
from collections import deque
n,q = map(int,raw_input().split())
que = deque()
for i in xrange(n):
    namei, timei = raw_input().split()
    que.append([namei,int(timei)])

tot = 0
while len(que)>0:                     
    if que[0][1] <= q:
        tot += que[0][1]
        print '%s %d'% (que.popleft()[0],tot)
    else:
        que[0][1] -= q
        tot += q
        que.rotate(-1)   
                

Measured memory_bytes: 12596
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val t = Array.fill(n)(sc.nextInt())
  val v = Array.fill(n)(sc.nextInt())
  var endLimit = List(0)
  for (i <- n-2 to 0 by -1) {
    endLimit ::= v(i).min(v(i+1)).min(endLimit.head + t(i+1))
  }

  var now = 0
  var ans = 0.0
  for (i <- 0 until n) {
    if (now + t(i) <= endLimit(i)) {
      ans += (2 * now + t(i)) * t(i) / 2.0
      now += t(i)
    } else {
      val max = (endLimit(i) + now + t(i)) / 2.0
      ans += (now + max) * (max - now) / 2.0
      ans += (max + endLimit(i)) * (max - endLimit(i)) / 2.0
      if (max > v(i)) {
        val d = max - v(i)
        ans -= d * d
      }
      now = endLimit(i)
    }
  }
  println(ans)
}


Measured memory_bytes: 55648
#include<bits/stdc++.h>
using namespace std;
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double

int ans=0;
int32_t main()
{
	IOS
	int n,m,c;cin>>n>>m>>c;
	vector<int>B(m);
	for(int i=0;i<m;i++)cin>>B[i];
	for(int i=0;i<n;i++)
	{
		int sum=0,x;
		for(int j=0;j<m;j++)
		{
			cin>>x;sum+=B[j]*x;
		}
		if(sum +c > 0)ans++;
	}
	cout<<ans<<endl;
			
	
}
			
	
	
	
	
	

	

	

	
		


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
    while (u != NIL && k != u->key)
    {
        if (k < u->key) u = u->left;
        else u = u->right;
    }
    
    return u;
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL){
      y = x;
      if (z->key < x->key) {
          x = x->left;
      } else {
          x = x->right;
      }
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }



}

void inorder(Node u){
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node u){
    if (u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}


Measured memory_bytes: 20472
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <cassert>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int N, M,ans;
	scanf("%d%d", &N, &M);
	ans = M * 10;
	rep(i, 20) {
		if ((ans) * 8 / 100 == N && (ans) / 10 == M) {
			printf("%d", ans);
			return 0;
		}
		ans++;
	}
	printf("-1");
}

Measured memory_bytes: 3820
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                        

using namespace std;
#define ll long long

int px[90001], py[90001];
int d[90001];

int main(){
  int H, W, D;
  cin >> H >> W >> D;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      int in;
      cin >> in;
      px[in] = i;
      py[in] = j;
    }
  }
  for(int i=D+1; i<=H*W; i++)
    d[i] = d[i-D] + abs(px[i] - px[i-D]) + abs(py[i] - py[i-D]);
  int Q;
  cin >> Q;
  for(int i=0; i<Q; i++){
    int l, r;
    cin >> l >> r;
    cout << d[r] - d[l] << endl;
  }
  return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int cnt[26];
map<string, bool>m;

signed main()
{ // #define int long long をしてるのでscanfを使うと意味不明な値が入力され死にます
    int N, K; cin >> N >> K;

    rep(i, N) {
        string S; cin >> S;
        if (m.find(S) != m.end()) continue;
        m[S] = true;
        cnt[S[0] - 'A'] += 1;
    }

    int ans = 0;

    while (true) {
        sort(cnt, cnt + 26, greater<int>());

        int a = 0;

        rep(i, 26) {
            if (cnt[i]) {
                cnt[i] -= 1;
                a += 1;
            }

            if (a == K) {
                break;
            }
        }

        if (a != K) {
            break;
        }

        ans += 1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1536
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: usize = read();
    let xlv: Vec<Vec<i64>> = read_vec2(n);

    let mut lrv_prt: Vec<(i64, i64)> = vec![];

    for i in 0..n {
        let x = xlv[i][0];
        let l = xlv[i][1];
        lrv_prt.push((x - l, x + l));
    }

    lrv_prt.sort_by(|x, y| {
        if x.1 != y.1 {
            x.1.partial_cmp(&y.1)
        } else {
            y.0.partial_cmp(&x.0)
        }
        .unwrap()
    });

    let mut lrv: Vec<(i64, i64)> = vec![];

    let mut lr = lrv_prt[0];
    for i in 1..n {
        let tmp = lrv_prt[i];
        if lr.1 != tmp.1 {
            if lr.0 < tmp.0 {
                lrv.push(lr);
                lr = tmp;
            }
        }
    }
    lrv.push(lr);

    let mut ans = 0;
    let mut right = -1000000001;
    for (l, r) in lrv {
        if right <= l {
            right = r;
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    int n,m; cin >> n >> m;
    int h[n];
    rep(i,n) cin >> h[i];
    vector<int> G[n];
    rep(i,m){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        int tmp = h[i];
        bool ok = true;
        for(auto ne : G[i]){
            if(h[ne] >= tmp) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 9104
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

struct Point{
	double x,y;
};


int main(){

	int n,count = 1;

	while(true){
		scanf("%d",&n);
		getchar();
		if(n == 0)break;

		double gaiseki,sum = 0;

		Point points[n];

		for(int i=0; i < n; i++){
			scanf("%lf %lf",&points[i].x,&points[i].y);
		}
		sum = points[n-1].x*points[0].y - points[n-1].y*points[0].x;
		for(int i=0; i < n-1; i++){
			gaiseki = points[i].x*points[i+1].y - points[i].y*points[i+1].x;
			sum += gaiseki;
		}

		printf("%d %.1lf\n",count,fabs(sum)/2);
		count++;

	}
    return 0;
}

Measured memory_bytes: 2600
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int E = sc.nextInt();
        int F = sc.nextInt();
        float maxNode = 0;
        int maxS = 0;
        int maxW = 0;

        for(int a = 0; a<=30; a++) {
            for(int b = 0; b<=30; b++) {
                for(int c = 0; c<=100; c++) {
                    for(int d = 0; d<=100; d++) {
                        float water = a*A*100+b*B*100;
                        float suger = c*C + d*D;
                        float weight = water + suger;
                        if(weight > F) continue;
                        if(weight == 0) continue;
                        if(suger>(float)(E*water/100)) continue;
                        if(maxNode< (float)(100*suger/weight)) {
                            maxNode = (float)(100*suger/weight);
                            maxS = (int)suger;
                            maxW = (int)weight;
                        }
                    }
                }
            }
        }
        if(maxW == 0) maxW = 100*A;
        System.out.println(maxW+ " " + maxS);
    }
}

Measured memory_bytes: 23380
#include<iostream>

using namespace std;

int main(void)
{
    long long int a,b,k;
    cin >> a >> b >> k;

    if(a>=k)
    {
        a=a-k;
    }
    else
    {
        k=k-a;
        a=0;
        if(b>=k)
            b=b-k;
        else
            b=0;
    }
    cout << a << " " << b << endl;

    return 0;

}

Measured memory_bytes: 3228
n = int(input())
p = list(map(int,input().split()))

count = 0

for i in range(1,n-1):
    if p[i] > p[i-1] and p[i] < p[i+1]:
        count += 1
    elif p[i] < p[i-1] and p[i] > p[i+1]:
        count += 1
    
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = (int)1e9 + 7;

int N;
string S1, S2;
ll dp[100];

bool tate(int i) {
  if (S1[i] == S2[i]) {
    return true;
  }
  else {
    return false;
  }
}

void abc071d() {
  int i;
  if (tate(0)) {
    dp[0] = 3;
    i = 0;
  }
  else {
    dp[0] = dp[1] = 6;
    i = 1;
  }
  while (i < N) {
    if (tate(i) && tate(i + 1)) {
      dp[i + 1] = dp[i] * 2;
      i++;
    }
    else if (tate(i) && !tate(i + 1)) {
      dp[i + 1] = dp[i] * 2;
      dp[i + 1] %= MOD;
      dp[i + 2] = dp[i + 1];

      i += 2;
    }
    else if (!tate(i) && tate(i + 1)) {
      dp[i + 1] = dp[i];
      i++;
    }
    else if (!tate(i) && !tate(i + 1)) {
      dp[i + 1] = dp[i] * 3;
      dp[i + 1] %= MOD;
      dp[i + 2] = dp[i + 1];
      i += 2;
    }
  }
  cout << dp[N - 1] % MOD << "\n";
}

int main() {
  cin >> N >> S1 >> S2;
  abc071d();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib> 
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;
 
int main() {
  string str;
  string strI;
  cin >> str;
  strI = str;
  int counter;
  counter = 0;

  if(str.at(0) != 'A' ){
       cout << "WA" << endl;
       return 0;
    }else{
       strI.at(0) = 'a';
      }
 
  for(int i = 2; i < str.size() - 1; i++){
   if(str.at(i) == 'C' ){
       counter = counter + 1;
       strI.at(i) = 'c';
    }
    }
  
  if(counter != 1 ){
       cout << "WA" << endl;
       return 0;
    }
  
  for(int i = 0; i < str.size(); i++){
      str.at(i) = tolower(str.at(i));
    }
  
  if(str == strI){
    cout << "AC" << endl;
   }
  else{
    cout << "WA" << endl;
  }
}

Measured memory_bytes: 256
N=int(input())
H=list(map(int, input().split()))
S=0
XX=[0]
for x in range(0,N-1):
    if H[x]>=H[x+1]:
        S=S+1
    if H[x]<H[x+1]:
        XX.append(S)
        S=0
XX.append(S)
print(max(XX))



Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long int ll;
const int N = (int)1e5+5;

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

    int k;
    cin>>k;
    ll ans = 0;
    rep(i,1,k) {
        rep(j,1,k) {
            int g = __gcd(i,j);
            rep(m,1,k) {
                ans += __gcd(g,m);
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3640
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 5121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[210000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a*2;i++){
		scanf("%d",p+i);
	}
	std::sort(p,p+a*2);
	int left=-1;
	int right=a+1;
	while(left+1<right){
		int M=(left+right)/2;
		bool ok=true;
		for(int i=0;i<a-M;i++){
			if(p[M*2+i]+p[a*2-1-i]<b)ok=false;
		}
		if(ok){
			right=M;
		}else{
			left=M;
		}
	}
	// printf("%d\n",right);
	int ret=0;
	for(int i=0;i<right;i++){
		ret=max(ret,p[i]+p[right*2-1-i]);
	}
	for(int i=0;i<a-right;i++){
		ret=max(ret,(p[a*2-1-i]+p[right*2+i])%b);
	}
	printf("%d\n",ret);
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>
#include <map>

using namespace std;
 
int main() {
	int n,a,x,y,ans;
	cin >> n;
	x = 800 * n;
	a = n / 15;
	y = 200 * a;
	ans = x - y;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
program main 
     implicit none
     integer a, b, c, d, e
     read(*, *) a, b, c, d, e
     
     if(a == 0)then
          write(*, *) 1
     else if (b == 0) then
          write(*, *) 2
     else if (c == 0) then
          write(*, *) 3
     else if (d == 0) then
          write(*, *) 4
     else if (e == 0) then
          write(*, *) 5
     endif 
     stop
end program main 
    
          

Measured memory_bytes: 2832
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cassert>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX 1000
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef VVI matrix;

const int diff = 500;
int dx[] = { 0,1,1,0,-1,-1};
int dy[] = {-1,0,1,1, 0,-1};
int N,L,min_x,min_y,max_x,max_y;
int Index[MAX][MAX];
ll M;

matrix identity(int n)
{
  matrix A(n,vector<ll>(n));
  for(int i=0;i<n;i++) A[i][i] = 1;
  return A;
}

vector<ll> multi(const matrix& A,const vector<ll>& B)
{
  vector<ll> ret(A.size());
  for(int i=0;i<A.size();++i)
    for(int j=0;j<A[0].size();++j)
      ret[i] += (A[i][j]*B[j])%M;
  return ret;
}

matrix multi(const matrix& A,const matrix& B)
{
  matrix C(A.size(),vector<ll>(B[0].size()));
  for(int i=0;i<C.size();++i)
    for(int j=0;j<C[i].size();++j)
      for(int k=0;k<A[i].size();++k)
	C[i][j] = (C[i][j]+(A[i][k]*B[k][j])%M)%M;
  return C;
}

matrix pow(const matrix& A,int e)
{
  return !e?identity(A.size()):
    (e%2?multi(A,pow(A,e-1)):pow(multi(A,A),e/2));
}


int main()
{
  int CNT = 1;
  while(cin >> N >> M >> L,N|M|L)
    {
      min_x = min_y = 999;
      max_x = max_y = 0;
      rep(i,MAX)rep(j,MAX)Index[i][j] = inf;

      int x = diff;
      int y = diff;
      int add = 0;
      int size = 0;
      vector<ll> b;

      rep(i,2*N-1)
	{
	  int nx = x,ny = y;
	  rep(j,N+add)
	    {
	      int value;
	      cin >> value;
	      b.push_back(value);
	      Index[ny][nx] = size;
	      size++;
	      nx += dx[1];
	      ny += dy[1];
	    }
	  if(i < N-1)add++;
	  else       add--;
	  if(i < N-1)
	    {
	      x += dx[3], y += dy[3];
	    }
	  else 
	    {
	      x += dx[2], y += dy[2];
	    }
	}

      matrix A = identity(size);

      REP(i,diff,diff+2*N)
	{
	  REP(j,diff,diff+2*N)
	    {
	      if(Index[i][j] == inf)continue;
	      int cur = Index[i][j];
	      rep(k,6)
		{
		  int nx = j + dx[k];
		  int ny = i + dy[k];
		  if(Index[ny][nx] == inf)continue;
		  int next = Index[ny][nx];
		  A[cur][next] = 1;
		}
	    }
	}
      /*
      cout << "A=--------" << endl;
      rep(i,A.size())
	{
	  rep(j,A[i].size())
	    {
	      cout << A[i][j] << " ";
	    }
	  cout << endl;
	}

      rep(i,b.size())
	{
	  cout << "b[" << i << "] = " << b[i] << endl;
	}
      */
      A = pow(A,L);

   
      vector<ll> c = multi(A,b);
      ll ans = 0;
      rep(i,c.size())
	{
	  ans += c[i]%M;
	  //cout << "c[" << i << "] = " << c[i] << endl;
	}
      cout << "Case " << CNT++ << ": " << ans << endl;

    }
  return 0;
}

Measured memory_bytes: 7296
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let x: Vec<i32> = readnc();
    let L: i32 = read();
    let q: usize = read();
    let queries: Vec<(usize, usize)> = readn(q);

    let mut left: Vec<Vec<usize>> = vec![vec![0; n]; 18];
    let mut right: Vec<Vec<usize>> = vec![vec![0; n]; 18];

    {
        let mut head = 0;
        for i in 0..n {
            while head+1 < n && x[head+1] - x[i] <= L {
                head += 1;
            }
            right[0][i] = head;
        }
    }
    {
        let mut head = n-1;
        for i in (0..n).rev() {
            while head >= 1 && x[i] - x[head-1] <= L {
                head -= 1;
            }
            left[0][i] = head;
        }
    }

    for k in 1..left.len() {
        for i in 0..n {
            left[k][i] = left[k-1][left[k-1][i]];
            right[k][i] = right[k-1][right[k-1][i]];
        }
    }

    for &(a, b) in &queries {
        let mut len = 0;
        let mut head = a - 1;
        let to = b - 1;
        if head < to {
            for k in (0..left.len()).rev() {
                if right[k][head] < to {
                    len += 1<<k;
                    head = right[k][head];
                }
            }
        } else {
            for k in (0..left.len()).rev() {
                if to < left[k][head] {
                    len += 1<<k;
                    head = left[k][head];
                }
            }
        }
        if head != to {
            len += 1;
        }
        println!("{}", len);
    }
}



Measured memory_bytes: 43644
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a,b;
  cin>>a>>b;
  vector<int> c(a);
  rep(i,a)
    cin>>c[i];
  sort(all(c));
  reverse(all(c));
  int d=0;
  rep(i,b)
    d+=c[i];
  out(d);
}


Measured memory_bytes: 256
public class Main {

  private static void solve() {
    String s = next();

    System.out.println(s.equals("ARC") ? "ABC" : "ARC");

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 36588
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

/* デカい配列はここで宣言 */

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i < n; i++)
    {
        ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
def main():
    INF = float("inf")
    input = sys.stdin.readline
    N, M = map(int,input().split())
    G = [[] for k in range(N)]
    for k in range(M):
        u, v = map(int,input().split())
        u -= 1
        v -= 1
        G[u] += [v]
    S, T = map(int,input().split())
    S -= 1
    T -= 1
    D = [[INF,INF,INF] for k in range(N)]
    D[S][0] = 0
    Q = deque([[S,0]])
    while len(Q) > 0:
        t = Q.popleft()
        ima = t[0]
        k = t[1]
        for tsugi in G[ima]:
            if D[tsugi][(k+1)%3] != INF:
                pass
            else:
                D[tsugi][(k+1)%3] = D[ima][k] + 1
                Q.append([tsugi,(k+1)%3])
    if D[T][0] == INF or D[T][0]%3 != 0:
        print(-1)
    else:
        print(D[T][0]//3)

if __name__ == '__main__':
    main()


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

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

	unordered_map<int, pair<int, int>> map;
	int p;
	string s;
	rep(i, M)
	{
		cin >> p >> s;
		if (s == "AC")
			map[p].second = 1;
		else
		{
			if (map[p].second != 1)
				map[p].first++;
		}
	}

	int ac = 0, wa = 0;
	for (const auto& m : map) {
		if (m.second.second == 1)
		{
			ac++;
			wa += m.second.first;
		}
	}

	cout << ac << " " << wa << endl;
}


Measured memory_bytes: 4388
using System;

namespace B___Uneven_Numbers
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static int solver()
        {
            var N = int.Parse(Console.ReadLine());
            if (N < 10) return N;
            if (N < 100) return 9;
            if (N < 1000) return N - 90;
            if (N < 10000) return 909;
            if (N < 100000) return N - 9090;
            if (N == 100000) return 90909;
            return 90909;
        }
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

bool canBeTriangle(int a,int b,int c){
	return (a < b + c) && (b < a + c) && (c < a + b);
}

bool desc(const int& left,const int& right){
	return left > right;
}

int main()
{
	int n;
	cin>>n;
	int *L = new int[n];
	int sum = 0;
	for(int i = 0 ; i < n; i++){
		cin>>L[i];
	}
	sort(L,L+n,desc);
	for(int i = 0; i < n - 2; i++){
		for(int j = i + 1; j < n - 1; j++){
			for(int k = j + 1; k < n; k++){
				int a,b,c;
				a = L[i];
				b = L[j];
				c = L[k];
				if( canBeTriangle(a,b,c) == true) sum++;
				else break;
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

class Edge {
 public:
  int t, w;
  Edge() {}
  Edge(int t, int w) : t(t), w(w) {}
};

vector<vector<Edge>> G;
vi d;

void bfs(int s) {
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (!q.empty()) {
    auto u = q.front();
    q.pop();
    for (auto &&e : G[u]) {
      if (d[e.t] == INF) {
        d[e.t] = d[u] + e.w;
        q.push(e.t);
      }
    }
  }
}

void solve() {
  auto n = G.size();
  bfs(0);
  int maxv = 0;
  int tgt = 0;
  REP(i, n) {
    if (d[i] == INF) continue;
    if (maxv < d[i]) {
      maxv = d[i];
      tgt = i;
    }
  }

  fill(ALL(d), INF);
  bfs(tgt);
  maxv = 0;
  REP(i, n) {
    if (d[i] == INF) continue;
    maxv = max(maxv, d[i]);
  }
  cout << maxv << endl;
}

int main() {
  int n, s, t, w;
  cin >> n;
  G.resize(n);
  d.resize(n, INF);
  REP(i, n - 1) {
    cin >> s >> t >> w;
    G[s].emplace_back(t, w);
    G[t].emplace_back(s, w);
  }
  solve();
}


Measured memory_bytes: 9800
#!/usr/bin/env python3
import sys
# import numpy as np
import bisect

def solve(N: int, L: "List[int]"):
    L = sorted(L)
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        for b in range(a+1, len(L)-1):
            b_in = bisect.bisect_left(L,a_+L[b]) - b -1
            if b_in > 0:
                ct+=b_in

            # print("L :{} a+Lb :{}  b_in:{}".format(L[b+1:],a_+L[b],ct))
        # ct += sum([bisect.bisect_left(L[b+1:],a_+L[b]) for b in range(a+1, len(L)-1)])
    print(ct)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


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

int n;
int a[100000];

int main(){
    while(cin >> n){
        if(n == 0) break;
        memset(a,0,sizeof(a));
        rep(i,n) cin >> a[i];
        sort(a,a+n);
        int ans = INF;
        for(int i = 1; i < n; i++) ans = min(ans,a[i]-a[i-1]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = LLONG_MAX;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */


int main() {
    string s;
    cin >> s;
    rep(i, 26) {
        rep(j, s.size()) {
            if(s[j] == char(i+'a')) break;
            if(j==s.size()-1){
                cout << char(i+'a') << endl;
                return 0;
            }
        }
    }
    cout << "None" << endl;
    return 0;
}

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

namespace ABC061_C
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] NK = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
            int[][] ab = new int[NK[0]][].Select(_ => Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray()).OrderBy(x => x[0]).ToArray();

            long nowindex = 0;
            for (int i = 0; i < ab.Length; i++)
            {
                nowindex += ab[i][1];
                if (nowindex >= NK[1])
                {
                    Console.WriteLine(ab[i][0]);
                    break;
                }
            }

        }
    }
}


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

#define int long long int 

int32_t main()
{

  int n,m;
  cin>>n>>m;
  vector<string> A,B;
  for(int i=0;i<n;i++)
  {
    string str;
    cin>>str;
    A.push_back(str);
  }
  for(int i=0;i<m;i++)
  {
    
      string str;
      cin>>str;
       B.push_back(str);
    
  }

  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++)
    {
      if((i+m-1)>= n || (j+m-1)>=n)
      continue;
      int match=true;
      for(int p=0;p<m;p++)
      {
        for(int k=0;k<m;k++)
        {
          if(A[i+p][j+k]!=B[p][k])match=false;
        }
      }
      if(match)
      {cout<<"Yes"<<endl;return 0;}

    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int imos[112345];
    memset(imos, 0, sizeof(imos));

    int n, m;
    int l[112345], r[112345];
    cin >> n >> m;
    REP(i, m)
    {
        cin >> l[i] >> r[i];
        imos[l[i]]++;
        imos[r[i] + 1]--;
    }

    int res = 0;

    int num = 0;
    for (int i = 1; i <= n; i++)
    {
        num += imos[i];
        res += num == m;
    }

    cout << res << endl;

    return 0;
}

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<int, pi> node;


int main()
{
    int n;
    cin >> n;
    queue<vector<int> > qu;
    vector<int>v(n);
    for(auto &x: v) cin >> x;
    qu.push(v);
    int ans = 0;
    while(!qu.empty()){
        vector<int> u = qu.front();
        qu.pop();
        int mn = *min_element(u.begin(), u.end());
        ans += mn;
        vector<int> ne;
        for(int i=0; i<u.size(); i++){
            int fx = u[i]-mn;
            if(fx == 0){
                if(!ne.empty()){
                    qu.push(ne);
                }
                ne.clear();
            }
            else{
                ne.push_back(fx);
            }
        }
        if(!ne.empty()){
            qu.push(ne);
        }
    }
    cout << ans << "\n";

    return 0;
}


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


int main(){
    double a,b,h,m;
    scanf("%lf %lf %lf %lf",&a,&b,&h,&m);
    printf("%.15lf\n",sqrt(a*a+b*b-2*a*b*cos((h/12-m/60)*2*M_PI+(m/60*M_PI)/6)));
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;

  vector<bool> valid(n, false);
  vector<int> balls(n, 1);
  valid[0] = true;
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --balls[--x];
    ++balls[--y];
    if (valid[x]) {
      valid[y] = true;
      if (!balls[x]) {
        valid[x] = false;
      }
    }
  }
  cout << count(valid.begin(), valid.end(), true) << endl;

  return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n = 0;
	static int SIZE = 100005;
	static int[] even = new int[SIZE];
	static int[] odd = new int[SIZE];
	static Pair[] evenPair = null;
	static Pair[] oddPair = null;
	static int ans = 0;
	
	public static void main(String[] args) {
		n = sc.nextInt();
		for(int i = 0; i < n; ++i) {
			int v = sc.nextInt();
			if(i % 2 == 0) ++even[v];
			else ++odd[v];
		}
		
		evenPair = getSortedArray(even);
		//System.out.println(Arrays.toString(evenPair));
		oddPair = getSortedArray(odd);
		//System.out.println(Arrays.toString(oddPair));
		
		if(evenPair[0].y != oddPair[0].y) {
			ans = n - evenPair[0].x - oddPair[0].x;
		} else {
			int p = n - evenPair[0].x - oddPair[1].x;
			int q = n - evenPair[1].x - oddPair[0].x;
			ans = Math.min(p, q);
		}
		System.out.println(ans);
	}
	
	static Pair[] getSortedArray(int[] cnt) {
		Pair[] res = new Pair[SIZE];
		for(int i = 0; i < SIZE; ++i) res[i] = new Pair(cnt[i], i);
		Arrays.sort(res, Comparator.reverseOrder());
		return res;
	}
}

class Pair implements Comparable<Pair> {
	int x;
	int y;
	
	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}
	
	@Override
	public int compareTo(Pair p) {
		if(this.x != p.x) return this.x - p.x;
		else return this.y - p.y;
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append('(');
		sb.append(this.x);
		sb.append(", ");
		sb.append(this.y);
		sb.append(')');
		return sb.toString();
	}
}

Measured memory_bytes: 52132
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T>
ostream& operator<<(ostream& stream, const vector<T> v){ stream << "["; for (int i=0; i<(int)v.size(); i++) cout << v[i] << " "; stream << "]"; return stream;}

int H,W,a[510][510],d;
char col[4]={'R','Y','G','B'};

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> H >> W >> d;

    int i,j;
    if (d%2){
        for (i=1; i<=H; i++)
            for (j=1; j<=W; j++)
                a[i][j]=(i+j)%2;
    }
    else {
        for (i=1; i<=H; i++)
            for (j=1; j<=W; j++){
                int d1=i+j-2,d2=i-j+W-1;

                if ((d1/d)%2==1) a[i][j]+=1;
                if ((d2/d)%2==1) a[i][j]+=2;
            }
    }

    for (i=1; i<=H; i++, cout << "\n")
        for (j=1; j<=W; j++)
            cout << col[a[i][j]];
    return 0;
}


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

int main()
{
  int time;
  cin >> time;
  
  int h, m, s;  
  s = time % 60;
  m = (time / 60) % 60;
  h = time / 60 / 60;

  cout << h << ":" << m << ":" << s << endl;
  return 0;
}



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

using namespace std;

int main(){
    long long n;
    cin >> n;
    std::vector<long long> a(n,0);
    long long i = 0;
    long long buf = 0;
    long long ans = 0;
    while(n > i){
        cin >> a[i];
        if(i==0) buf = a[i];
        else{
            if(a[i]>buf) buf = a[i];
            else ans += buf - a[i];
        }
        i++;
    }
    cout << ans;
}

Measured memory_bytes: 4720
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int,P> PP;
typedef pair<int,PP> PPP;
struct edge { int to;  int cost; };

int DP[1000000];

signed main() {
	int N, Q;
	string s;
	cin >> N >> Q;
	cin >> s;
	rep(i, N){
		if(i == 0) continue;
		DP[i] = DP[i-1];
		if(s[i] == 'C' && s[i-1] == 'A'){
			DP[i]++;
		}
	}

	rep(i, Q){
		int a,b;
		cin >> a >> b;
		a--;b--;
		cout << DP[b] - DP[a] << endl;
	}

	return 0;
}

Measured memory_bytes: 1792
/*
AizuOnline A0028
Mode Value
*/
#include <stdio.h>


main()
{
  int N;
  int data[101];
  int i;
  int s;
  int maxhin;

  for(i=1;i<=100;i++)
    data[i]=0;
  N=0;

  while(EOF != scanf("%d",&s))
    {
      data[s]++;
      N++;
    }

  maxhin = 0;
  for(i=1;i<=100;i++)
    {
      if(maxhin < data[i])
	maxhin = data[i];
    }

  for(i=1;i<=100;i++)
    {
      if(data[i]==maxhin)
	printf("%d\n",i);
    }
return(0);
}

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

#define N 1000000
#define NIL -1
#define LEN 13

int change(char c);
int makekey(char *);
int insert(char *);
int h1(int);
int h2(int);
int find(char *);

int n;
char H[N][LEN];

int main(){
  
  int i, h;
  char string[LEN], command[7];
 
  for(i=0;i<N;i++){
    H[i][0]='\0';
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",command,string);
    if(command[0]=='i'){
      insert(string);
    }
    else{
      if(find(string)==1) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

int change(char c){
  int num;
  
  if(c=='A') num=1;
  else if(c=='C') num=2;
  else if(c=='G') num=3;
  else if(c=='T') num=4;
  return num;
}

int makekey(char string[]){  

  int i, sum=0, a=1;

  for(i=0;i<strlen(string);i++){
    sum+=a*(change(string[i]));
    a*=3;
  }
  return sum;
}

int h1(int key){

 return key%N;
}

int h2(int key){

  return 1+(key%(N-1));
}

int find(char string[]){

  int i=0, key, h;

  key=makekey(string);
  
  while(1){
    h=(h1(key)+i*h2(key))%N;
    if(strcmp(H[h],string)==0) return 1;
    else if(strlen(H[h])==0) return 0;
    i++;
  }
  return 0;
}

int insert(char string[]){

  int key, i=0, h;

  key=makekey(string);
  while(1){
    h=(h1(key)+i*h2(key))%N;
    if(strcmp(H[h],string)==0) return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],string);
      return 0;
    }
    i++;
  }
  return 0;
}


Measured memory_bytes: 14440
h,n=map(int,input().split())
a=list(map(int,input().split()))

a.sort(reverse=True)

ans=0
power=0
for i in range(n):
    power+=a[i]
    if power>=h:
        ans=1
        break
if ans==1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 20592
import sys
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A

if __name__ == '__main__':
    N = int(input())
    A = InputToInt()
    if set(A) == {0}:
        print('Yes')
        sys.exit()
    
    if N%3 != 0:
        print('No')
        sys.exit()
    A.sort()

    n = int(N/3)
    if 1 == len(set(A[0:n])) and 1 == len(set(A[n:2*n])) and 1 == len(set(A[2*n:3*n])) and A[0] == A[n] ^ A[2*n]:
        print('Yes')
    else:
        print('No')


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N;
    cin>>N;
    vi A(N);
    vector<pint> E;
    REP(i, 0, N) cin >> A[i];
    sort(A.begin(), A.end());
    int Least = A[0];
    int M, p;
    for(int i = N-1; i > 0; i--){
        if(A[i]>=0 && A[i-1] >= 0 && i >1){
            E.push_back({Least, A[i]});
            Least -= A[i];
        }else{
            M = A[i];
            E.push_back({M, Least});
            M -= Least;
            p = i;
            break;
        }
    }
    REP(i, 1, p){
        E.push_back({M, A[i]});
        M -= A[i];
    }
    cout << M << endl;
    REP(i, 0, N-1) cout << E[i].first << " " << E[i].second << endl;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    ll y[x];
    for (int i=0; i<x; i++)
        cin>>y[i];
    sort(y,y+x);
    ll sum=0,ans=1e9;
    for (int i=0; i<=101; i++)
    {
        sum=0;
        for (int j=0; j<x; j++)
        {
            sum+=abs(i-y[j])*abs(i-y[j]);
        }
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
f = []
for i in range(n):
  f.append(list(map(int, input().split())))
p = []
for i in range(n):
  p.append(list(map(int, input().split())))

cand = []
for i in range(1, 2 ** 10):
  cnt = [0] * n
  for j in range(10):
    if i & (1 << j):
      for k in range(n):
        if f[k][j]:
          cnt[k] += 1
  v = 0
  for k in range(n):
    v += p[k][cnt[k]]
  cand.append(v)
    
print(max(cand))
  


Measured memory_bytes: 3064