akhauriyash/Code-Regression huggingface dataset:
// @prefix atcoder
// @description atcoder template

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

VVI v(3, VI(3, 0));
bool check[3][3];
int n;
VI b(10);
signed main() {
    REP(i, 3) {
        REP(j, 3) {
            cin >> v[i][j];
        }
    }
    cin >> n;
    b.resize(n);
    REP(i, n) {
        cin >> b[i];
    }

    REP(i, 3) {
        REP(j, 3) {
            check[i][j] = false;
            REP(k, n) {
                if (b[k] == v[i][j]) {
                    check[i][j] = true;
                    break;
                }
            }
        }
    }
    // REP(i, 3) {
    //     REP(j, 3) {
    //         cout << check[i][j] << endl;
    //     }
    // }
    string s = "No";

    REP(i, 3) {
        if (check[i][0] && check[i][1] && check[i][2])
            s = "Yes";
    }

    REP(i, 3) {
        if (check[0][i] && check[1][i] && check[2][i])
            s = "Yes";
    }

    if (check[0][0] && check[1][1] && check[2][2])
        s = "Yes";
    if (check[0][2] && check[1][1] && check[2][0])
        s = "Yes";
    cout << s << endl;

    return 0;
}


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

from collections import deque

############### TESTCASE ###############
test = ""
#test = \
"""
3
1 2 2
2 3 1
ans:
0
0
1
"""

"""
5
2 5 2
2 3 10
1 3 8
3 4 2
ans:
1
0
1
0
1
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
################# MAIN ################# 
        
n = int(input2())
edges = [0] * (n-1)
for i in range(n-1):
    edges[i] = tuple(map(int, input2().split()))

adjacency_list = [[] for i in range(n+1)]
for edge in edges:
    adjacency_list[edge[0]].append((edge[1], edge[2]))
    adjacency_list[edge[1]].append((edge[0], edge[2]))

nodeL = [None] * (n+1)
nodeL[1] = 0
nodeQ = deque([[1]])
while nodeQ:
    tmp = nodeQ.popleft()
    tmp = tmp[0]
    
    nodes = adjacency_list[tmp]
    for nd in nodes:
        if nodeL[nd[0]] == None:
            nodeL[nd[0]] = nodeL[tmp] ^ nd[1]%2
            nodeQ.append([nd[0]])

    
for i in range(1, n+1):
    print(nodeL[i])



Measured memory_bytes: 47152
#include <iostream>
#include <stdio.h>
#include <cctype>
using namespace std;

int main(void){
  int n;
  int size;
  int awin=0,bwin=0;
  string a,b;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a >> b;
    size = (a.size()<b.size()) ? a.size() : b.size();
    //cout << size << endl;
    for(int j=0;j<size;j++){
      if(a[j]==b[j]){
        if(j==size-1){
          if(a.size()==b.size()){
            awin++;bwin++;
          }else if(a.size()>b.size()){
            awin += 3;
          }else{
            bwin += 3;
          }
          break;
        }
        continue;
      }else if(a[j]<b[j]){
        bwin += 3;
        break;
      }else{
        awin += 3;
        break;
      }
    }
  }
  cout << awin << " " << bwin << endl;
}


Measured memory_bytes: 3096
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#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 CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n; R(n);
    string s;
    R(s);
    int v=0;
    REP(i,n){
        if(s[i]=='R')v++;
        else v--;
    }
    W(v>0?"Yes":"No");
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int cnt = 1;
  int a = N % 10;
  while (N /= 10) {
    if (a == N % 10) {
      ++cnt;
      if (cnt == 3) {
        cout << "Yes" << endl;
        return 0;
      }
    } else {
      cnt = 1;
      a = N % 10;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8

A, B, C, X, Y = [int(x) for x in input().split()]

p1 = X * A + Y * B
m = min(X, Y)
p2 = m * 2 * C + (X - m) * A + (Y - m) * B
M = max(X, Y)
p3 = M * 2 * C

print(min(p1, p2, p3))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a,b;
	long long sum1=0;
	cin>>a>>b;
	while(n){
		int sum=0;
		int z=n;
		while(z){
			sum+=z%10;
			z/=10;
		}
		if(sum>=a&&sum<=b){
			sum1+=n;
		}
		n--;
	}
	cout<<sum1<<endl;
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int a,b; cin >> a >> b;
    if(a<=5) cout << 0 << endl;
    else if(a<=12) cout << b/2 << endl;
    else cout << b << endl;
    return 0;
}

Measured memory_bytes: 3580
def examC(inf):
    N = I()
    A = LI()
    sumA = [0]*N
    sumA[0] = A[0]
    cur = inf
    for i in range(N-1):
        sumA[i+1] = sumA[i]+A[i+1]
    for i in range(N-1):
        if cur>abs(sumA[N-1]-sumA[i]*2):
            cur = abs(sumA[N-1]-sumA[i]*2)
    ans = cur
    print(ans)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC(inf)


Measured memory_bytes: 72048
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int Max(int a,int b){return a>b?a:b;}
const long long Mod=1e9+7;
long long inv[5005],dp[5005][5005];
long long quipow(long long x,long long n)  
{
    long long res=1;
    while(n>0)
    {
        if(n&1) res=res*x%Mod;
        x=x*x%Mod;
        n>>=1;
    }
    return res;
}
int main()
{
	int n,len;char s[5005];
	scanf("%d%s",&n,s);len=strlen(s);
    inv[0]=1;inv[1]=quipow(2,Mod-2);
    for(int i=2;i<5002;++i) inv[i]=1ll*inv[i-1]*inv[1]%Mod;
	dp[0][0]=1;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			dp[i+1][j+1]=(dp[i+1][j+1]+2*dp[i][j])%Mod;
			dp[i+1][Max(j-1,0)]=(dp[i+1][Max(j-1,0)]+dp[i][j])%Mod;
		}
	}
	printf("%I64d",1ll*dp[n][len]*inv[len]%Mod);
}

Measured memory_bytes: 193920
package main
import "fmt"
func main(){
var a, b, c int
fmt.Scan(&a, &b, &c)
var x, y, z int
x=a+b
y=b+c
z=c+a
if x<=y && x<=z{
  fmt.Println(x)
}else if y<=x && y<=z{
  fmt.Println(y)
}else{
  fmt.Println(z)
}
}


Measured memory_bytes: 512
h = gets.to_i
strs = h.times.map{ gets.chomp.split('') }

if strs.uniq.size != h
  puts 'No'
  exit
end

strs.each_with_index do |str, idx|
  break if idx == h-1
  if str[-1] != strs[idx+1][0]
    puts 'No'
    exit
  end
end

puts 'Yes'

Measured memory_bytes: 1916
#include <iostream>
#include <deque>
#include <tuple>
#include <vector>
#include <algorithm>

typedef std::tuple<int, int, int> T;

int S(T a) {
	return std::get<0>(a) * std::get<1>(a);
}

int main()
{
	while(true){
		int n, w, d;
		std::cin >> n >> w >> d;
		if ( n == 0 && w == 0 && d == 0 ) break;
		std::deque<T> q;

		q.push_back(T(w, d, 1));

		for ( int i = 0; i < n; ++i ) {
			int p, s;
			std::cin >> p >> s;

			for ( int j = 0; j < q.size(); ++j ) {
				if ( std::get<2>(q[j]) == p ) {
					int pw = std::get<0>(q[j]); 
					int pd = std::get<1>(q[j]); 
					q.erase(q.begin() + (j));
					s %= pw+pd;
					T a, b;

					if ( s < pw ) {
						a = T(s, pd, 0);
						b = T(pw - s, pd, 0);
					} else {
						s -= pw;
						a = T(pw, s, 0);
						b = T(pw, pd - s, 0);
					}
					if (S(b) < S(a)) {
						std::swap(a,b);
					}
					q.push_back(a);
					q.push_back(b);
					for ( int i = 0; i < q.size(); ++i ) {
						std::get<2>(q[i]) = i+1;
					}
					break;
				}
			}
		}
		std::vector<int> p;
		for ( auto &v: q ) {
			p.push_back(std::get<0>(v) * std::get<1>(v));
		}
		std::sort(p.begin(), p.end());
		for (int i = 0; i < p.size(); ++i) {
			std::cout << p[i] << ((i == p.size()-1) ? "" : " ");
		}
		std::cout << std::endl;
	}

	return 0;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  
  vector<int> X(4);
  for (int i = 0; i < 4; ++i) {
    X[i] = s[i] - '0';
  }

  for (int i = 0; i < (1 << 3); ++i) {
    int total = X[0];
    for (int j = 0; j < 3; ++j) {
      if (i >> j & 1) total += X[j + 1];
      else total -= X[j + 1];
    }
    if (total == 7) {
      cout << X[0];
      for (int j = 0; j < 3; ++j) {
	if (i >> j & 1) cout << '+';
	else cout << '-';
	cout << X[j + 1];
      }
      puts("=7");
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N;
  cin >> N;
  string ans;
  N--;
  while (0 <= N)
  {
    ans += N % 26 + 'a';
    N /= 26;
    N--;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    cin >> A >> B >> C;
    vector<ll> v;
    rep(i,X)rep(j,Y){
        v.emplace_back(A[i]+B[j]);
    }
    sort(all(v), greater<>());
    dump(v);
    while(v.size() > K){
        v.pop_back();
    }
    dump(v);
    vector<ll> w;
    rep(i,v.size())rep(j,Z){
        w.emplace_back(v[i]+C[j]);
    }
    sort(all(w), greater<>());
    while(w.size() > K)w.pop_back();
    rep(i,K){
        cout << w[i] << endl;
    }
}


Measured memory_bytes: 44036
def main():
  string = input()
  if string[len(string)-1]=='2' or string[len(string)-1]=='4' or string[len(string)-1]=='5' or string[len(string)-1]=='7' or string[len(string)-1]=='9':
    print('hon')
  elif string[len(string)-1]=='0' or string[len(string)-1]=='1' or string[len(string)-1]=='6' or string[len(string)-1]=='8':
    print('pon')
  else:
    print('bon')

main()

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

using namespace std;

const int N = 2e5 + 233;

struct P {
  int l, r;
}p[N];

int ans, n;

bool cmp(P a, P b) {
  return a.l < b.l || a.l == b.l && a.r < b.r;
}

int main(void) {
  cin >> n;
  for (int i = 1; i <= n; i ++)
    cin >> p[i].l >> p[i].r, ++ p[i].r;
  sort(p + 1, p + n + 1, cmp);
  int prel = p[1].l;
  int prer = p[1].r;
  for (int i = 2; i <= n; i ++) {
    if (p[i].l <= prer) {
      prer = p[i].r;
    } else {
      ans += prer - prel;
      prel = p[i].l;
      prer = p[i].r;
    }
  }
  ans += prer - prel;
  cout << ans << "\n";
}


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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

ll Pow(ll base,ll power) {
   if (power == 0)
   return 1;
   else
   return (base * Pow(base, power-1));
}
int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n;
        cin>>n;
        loop(i,-200,200)
        {
            loop(j,-200,200)
            {
                if(Pow(i,5)-Pow(j,5)==n)
                {
                    cout<<i<<' '<<j;
                    return 0;
                }
            }
        }

    }
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#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;
    cin >> n;
    vector<ll> a(n+1), b(n);
    rep(i, n+1){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }
    ll ans = 0;
    rep(i, n){
        ans += min(a[i] + a[i+1], b[i]);
        if(a[i] < b[i]){
            a[i+1] -= (b[i] - a[i]);
            if(a[i+1] < 0){
                a[i+1] = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let N = get!(usize);
    let S = get!(String);

    let (ans, _) = S.chars().fold(
        (0, 0),
        |(m, acc), c| if c == 'I' {
            let x = acc + 1;
            (cmp::max(m, x), x)
        } else {
            (m, acc - 1)
        }
    );

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main(){
  int N;
  cin >> N;
  map<string,int> list;
  string tmp;
  rep(i, N) { cin >> tmp;
  list[tmp]++;}
  cout << list.size();
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の string型配列と同じような感じ）
map<int, string> mp;
for (auto itr =mp.begin(); itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;

//pair
//たくさんつくる
vector<pair<int,string>> hoge(10);
//参照
hoge[0].first
sort(all(hoge), greater<pair<int, string>>());




*/


Measured memory_bytes: 19076
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = b; i >= (a); --i)
#define repdl(i, a, b) for(ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool ihmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
#endif
#ifndef _TEMPLATE_OPT
#define _TEMPLATE_OPT
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#endif
using namespace std;

int a[500005];

struct Query {
  int l, r, id, ans;
};

// freqcnt
int freq[500005];
int distinct = 0;
void freqadd(int x) { 
//write("FA", x, freq[x], "->", freq[x]+1);
  if (!freq[x]) distinct++; freq[x]++; }
void freqrem(int x) { 
  
//write("FR", x, freq[x], "->", freq[x]-1);
  freq[x]--; if (!freq[x]) distinct--; }
Query query[500005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n, q; read(n, q);
  rep(i, 1, n + 1) read(a[i]);
  rep(i, 0, q) read(query[i].l, query[i].r), query[i].id = i;
  
  const int BS = 1000;
  sort(query, query + q, [](const Query& a, const Query& b) {
    if (a.l / BS != b.l / BS) return a.l / BS < b.l / BS;
    else return a.r < b.r;
    });

  // inclusive [cl, cr]
  int cl = 1, cr = 0;
  rep(i, 0, q) {
    int nl = query[i].l, nr = query[i].r;
    while (cl > nl) freqadd(a[--cl]);
    while (cr < nr) freqadd(a[++cr]);
    while (cl < nl) freqrem(a[cl++]);
    while (cr > nr) freqrem(a[cr--]);
    query[i].ans = distinct;
  }

  sort(query, query + q, [](const Query& a, const Query& b) { return a.id < b.id; });
  rep(i, 0, q) write(query[i].ans);
}



Measured memory_bytes: 15456
s=input()
q=int(input())
cnt=0 #反転の回数の偶奇を記憶
right=""
left=""
for i in range(q):
	query=list(input().split())
	if query[0]=="1":
		cnt+=1
	else:
		if (cnt+int(query[1]))%2==0:
			right+=query[2]
		else:
			left+=query[2]
if cnt%2==0:
	print(left[::-1]+s+right)
else:
	print(right[::-1]+s[::-1]+left)

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m);
  for(int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
  }
  for(int i = 0; i < m; i++){
    cin >> c[i] >> d[i];
  }

  for(int i = 0; i < n; i++){
    int min = abs(a[i]-c[0]) + abs(b[i]-d[0]);
    int min_ind = 0;
    for(int j = 1; j < m; j++){
      int l = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(l < min){
        min = l;
        min_ind = j;
      }
    }
    cout << min_ind+1 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int a,b;
	cin >> a >> b;
	cout << (b%a==0?a+b:b-a) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1234567;
int u[maxn], dist[maxn];
void init(int sz){
	for(int i = 0; i < sz; i++) u[i] = i;
}
int find(int x){
	if(x == u[x]) return x;
	return u[x] = find(u[x]);
}
vector<pair<int,int> > e[maxn], ed[maxn];
int nds;
int main(){
	int n, m; cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y, z; cin >> x >> y >> z;
		ed[z].push_back({x, y});
	}
	nds = n + 1;
	for(int i = 0; i < maxn; i++){
		if(ed[i].empty()) continue;
		vector<int> now;
		for(auto ee : ed[i]){
			now.push_back(ee.first);
			now.push_back(ee.second);
		}
		sort(now.begin(), now.end());
		now.erase(unique(now.begin(), now.end()), now.end());
		int len = now.size();
		init(len);
		for(auto ee : ed[i]) u[find(lower_bound(now.begin(), now.end(), ee.first) - now.begin())] = find(lower_bound(now.begin(), now.end(), ee.second) - now.begin());
		vector<int> who(len);
		for(int i = 0; i < len; i++) who[i] = nds++;
		for(auto ee : ed[i]){
			int x, y; tie(x, y) = ee; int par = who[find(lower_bound(now.begin(), now.end(), x) - now.begin())];
			e[x].push_back({par, 1});
			e[y].push_back({par, 1});
			e[par].push_back({x, 0});
			e[par].push_back({y, 0});
		}
	}
	deque<pair<int,int> > q;
	memset(dist, -1, sizeof(dist));
	q.push_back({1, 0}); dist[1] = 0;
	while(!q.empty()){
		int cur, steps; tie(cur, steps) = q.front(); q.pop_front();
		if(cur == n) return cout << steps << endl, 0;
		for(auto ee : e[cur]){
			if(dist[ee.first] == -1 || dist[ee.first] > dist[cur] + ee.second){
				dist[ee.first] = dist[cur] + ee.second;
				if(ee.second) q.push_back({ee.first, dist[ee.first]});
				else q.push_front({ee.first, dist[ee.first]});
			}
		}
	}
	cout << -1 << endl;
	return 0;
}





Measured memory_bytes: 81920
#include <stdio.h>
int main(void){
    int X;
    scanf("%d",&X);
    if(X==25){
        printf("Christmas");
    }
    if(X==24){
        printf("Christmas Eve");
    }
    if(X==23){
        printf("Christmas Eve Eve");
    }
    if(X==22){
        printf("Christmas Eve Eve Eve");
    }
    return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define index INDEX
#ifndef ONLINE_JUDGE
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, const string& NAME) {
    cerr << NAME << " = " << fixed << VARIABLE << '\n';
}
#else
#define print(x) 0
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
const double PI = atan(1) * 4;
const double EPS = 1e-6;
const int SEED = (int)1e3 + 7;
const int MOD = (int)1e9 + 7;
const int NMAX = (int)2 * 1e5 + 5;

#define int ll
	
int n;
int v[NMAX];
map<int, vector<int> > have;
map<int, int> cnt;
int sol;
bool trecut[NMAX];

int32_t main() {
    FASTIO;
    cin >> n;
    for1(i, n) 
        cin >> v[i];

    for1(i, n) cnt[v[i]]++;

    for(ll i = (1LL << 33); i >= 1; i /= 2)
    {
        for(auto &j: cnt) {
            if(i - j.first > j.first) {
                int temp = j.second;
                sol += min(temp, cnt[i - j.first]); 
                j.second -= min(temp, cnt[i - j.first]);
                cnt[i - j.first] -= min(temp, cnt[i - j.first]);
            }
            else if(i - j.first == j.first)
            {
                sol += j.second / 2;
                j.second /= 2;
            }
            else break;
        }
    }



    cout << sol;

    return 0;
}


Measured memory_bytes: 76672
#include <bits/stdc++.h>
using namespace std;
string s,t;
int n;
char rev(char c)
{
	return c=='S'?'W':'S';
}
bool check(string str)
{
	bool ok=true;
	for(int i=0;i<n;i++)
	{
		char cl=str[(i+n-1)%n];
		char cr=str[(i+1)%n];
		if(s[i]=='o' && str[i]=='S')ok&=cl==cr;
		else if(s[i]=='x' && str[i]=='S')ok&=cl!=cr;
		else if(s[i]=='o' && str[i]=='W')ok&=cl!=cr;
		else ok&=cl==cr;
	}
	return ok;
}
void process(string str)
{
	t=str;
	t.resize(n);
	for(int i=1;i<n-1;i++)
	{
		if(t[i]=='S' && s[i]=='o')t[i+1]=t[i-1];
		else if(t[i]=='S' && s[i]=='x')t[i+1]=rev(t[i-1]);
		else if(t[i]=='W' && s[i]=='o')t[i+1]=rev(t[i-1]);
		else t[i+1]=t[i-1];
	}
//	cout<<t<<endl;
	if(check(t))
	{
		cout<<t<<endl;
		exit(0);
	}
}
int main()
{
	cin>>n;
	cin>>s;
	process("SS");
	process("SW");
	process("WS");
	process("WW");
	puts("-1");
	return 0;
}

Measured memory_bytes: 640
from sys import stdin
import math
def isPrime(x):
    if x == 2 or x == 3: return True
    elif (x < 2 or x % 2 == 0 or x % 3 == 0): return False
    s = int(math.sqrt(x) + 1)
    for i in range(5, s + 1, 2):
        if x % i == 0: return False
    return True
print(sum([isPrime(int(stdin.readline())) for _ in range(int(stdin.readline()))]))



Measured memory_bytes: 5760
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n, x;
  for (;;) {
    cin >> n >> x;
    if (!n && !x)
      break;

    int c = 0;
    for (int i = 1; i < n - 1; ++i) {
      if (i >= x)
        continue;
      for (int j = i + 1; j <= n - 1; ++j) {                                                                                                                              
        if (i + j >= x)
          continue;
        for (int k = j + 1; k <= n; ++k) {
          if (i + j + k == x)
            ++c;
        }
      }
    }
    printf("%d\n", c);
  }
  return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _cin      ios_base::sync_with_stdio(0);  cin.tie(0);
#define READ      freopen("input.txt", "r", stdin);
#define WRITE     freopen("output.txt", "w", stdout);
#define endl "\n"
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<ll> >
#define vll vector<ll>
#define mll map<ll,ll>
#define sz(x) (ll)x.size()
#define sll set<ll>
#define pll pair<ll,ll>
#define F first
#define S second
const ll MAX = 1000004;
const ll INF = 1e18L + 5;


int main() {

	_cin
	// READ
	// WRITE
	ll H, W;
	cin >> H >> W;
	char path[H + 1][W + 1];
	ll dp[H + 1][W + 1];
	memset(dp, 0, sizeof(dp));
	bool bad = 0;

	rep(i, 1, H + 1) {
		rep(j, 1, W + 1) {
			cin >> path[i][j];
			if (path[i][j] != '#') {
				if (i == 1) {
					if (!bad) {
						dp[i][j] = 1;
					} else dp[i][j] = 0;
				}
				else {
					dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % hell;
				}
			} else bad = 1;
		}
	}


	cout << dp[H][W] % hell << endl;




}

Measured memory_bytes: 12348
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let x: usize = iter.next().unwrap().parse().unwrap();

    let ans =
        if x < 600 {
            8
        }
        else if x < 800 {
            7   
        }
        else if x < 1000 {
            6
        }
        else if x < 1200 {
            5
        }
        else if x < 1400 {
            4
        }
        else if x < 1600 {
            3
        }
        else if x < 1800 {
            2
        }
        else {
            1
        };
    println!("{}", ans);
}

Measured memory_bytes: 2128
#include <stdio.h>

int main(void){

    char A[100];
    scanf("%s", A);

    if(A[0] == 'a' && A[1] == 'b' && A[2] == 'c'){
        puts("Yes");
    } else if(A[0] == 'a' && A[1] == 'c' && A[2] == 'b'){
        puts("Yes");
    } else if(A[0] == 'b' && A[1] == 'a' && A[2] == 'c'){
        puts("Yes");
    } else if(A[0] == 'b' && A[1] == 'c' && A[2] == 'a'){
        puts("Yes");
    } else if(A[0] == 'c' && A[1] == 'a' && A[2] == 'b'){
        puts("Yes");
    } else if(A[0] == 'c' && A[1] == 'b' && A[2] == 'a'){
        puts("Yes");
    }else{
        puts("No");
    }


    return 0;
}

Measured memory_bytes: 128
H,W = map(int,raw_input().split(" "))
field = [raw_input() for i in range(H)]



def calc(h,w):
    res = 0
    for i in range(-1,2):
        for j in range(-1,2):
            nh = h + i
            nw = w + j
            
            if nh >= 0 and nh < H and nw >= 0 and nw < W and (not (nh == h and nw == w)):
                if field[nh][nw] == "#":
                    res+=1
    return res




for h,line in enumerate(field):
    newline = ""
    for w,c in enumerate(line):
        if c == "#":
            newline += "#"
        else:
            newline += str(calc(h,w))
    print newline



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

int main() {
	int a[5],i,ans;
	for(i=0;i<5;i++)
	cin>>a[i];
	for(i=0;i<5;i++){
	    if(a[i]==0){
	        ans=i+1;
	        break;
	    }
	}
	cout<<ans;
}


Measured memory_bytes: 3632
//abc173_c.cpp
//Sun Jul  5 20:55:24 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

int main(){
	int h,w,k;
	cin >> h >> w >> k;

	string s[h];
	for (int i=0;i<h;i++){
		cin >> s[i];
	}

	int ans = 0;
	for (int i=0;i<1<<h;i++){
		for (int j=0;j<1<<w;j++){
//			cout << i << " " << j << endl;
			int tmp = 0;
			for (int k=0;k<h;k++){
				for (int l=0;l<w;l++){
					// cout << "  " << (i>>k&1) << " " << (j>>l&1) << " "<< (s[k][l]=='#') << endl; 
					if ((i>>k&1)==0 && (j>>l&1)==0 && s[k][l]=='#'){
						tmp++;
					}
				}
			}
			// cout << i << " " << j << " " << tmp << endl;
			if (tmp==k){
				ans++;
			}
		}
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if (2 * x < a * a * b) {
        printf("%.6f", atan((ll)a * b * (double)b / 2 / x) / PI * 180);
    }
    else {
        printf("%.6f", atan((double)(2 * ((ll)a * a * b - x)) / a / a / a) / PI * 180);
    }
    return 0;
}

Measured memory_bytes: 3920
#include<cstdio>
#include<cmath>
#define R(i,n) for(int i=0;i<n;i++)
#define D double
using namespace std;
main(){int n,l[256],x,y,z;while(scanf("%d",&n),n){R(i,n)scanf("%d",&l[i]);D m=1e9;R(s,16)R(a,16)R(c,16){int u[256]={0};int r=s;R(i,n){r = (a*r + c)&255;u[(r + l[i])&255]++;}D tmp=0;R(i,256)if(u[i]){tmp-=u[i]*log((D)u[i]/n);if(m+1e-9<tmp)break;}if(m>tmp+1e-9){m=tmp;x=s;y=a;z=c;}}printf("%d %d %d\n",x,y,z);}}

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

int main(){
    int n;
    cin>>n;
    vector<int>x(n);
    int sum=0;
    for(int i=0; i<n; i++){
        cin>>x.at(i);
        sum+=x.at(i);
    }
    double av= (double)sum/n;
    int p;
    int ans;
    if((av-sum/n)>=0.5) p=sum/n+1;
    else p=sum/n;
    for(int i=0; i<n; i++){
        ans+=pow((p-x.at(i)),2);
    }
    cout<<ans<<endl;
}

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

int main(){
  int A,B,C,X;
  cin>> A>>B>>C>>X;
  int pt =0;
  for(int i = 0; i <= A; i++){
    for(int j = 0; j <= B; j++){
      for(int k = 0; k <= C; k++){
        int total = 500*i+100*j+50*k;
        if(total == X)pt++;
      }
    }
  }
           
       cout << pt<< endl;
        return 0;
      }


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

int main() {
    int a;
    int b;

    cin >> a >> b;

    int c = a * b;

    if (c % 2 == 0) {
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }
}


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

char s[102400];
int k, l;
int main() {
	scanf("%s %d", s, &k);
	l = strlen(s);
	for(int i = 0; i + 1< l; ++i) {
		int t = ('a' - s[i] + 26) % 26;
		if(t <= k) {
			k-=t;
			s[i] = 'a';
		}
	}
	k %= 26;
	if((int)s[l-1] + k > 'z') s[l - 1] += k - 26;
		else s[l-1] += k;
	puts(s);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i) 
using namespace std;
using ll = long long;
int main() {
 int r,g,b;
 cin >> r >> g>> b;
 int x;
 x = 100*r+10*g + b;
 int a;
 a = x%4;
 if (a==0) cout << "YES" << endl;
 else cout<< "NO" << endl;
}

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

public class Main {

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

Measured memory_bytes: 52844
#include<stdio.h>                                                         
                                                                          
int main(void){                                                           
                                                                          
  int W,H,x,y,r;                                                          
                                                                          
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);                                 
                                                                          
  if((x + r) <= W && (y + r) <= H && x >= 0 && y >= 0 && x >= r && y >= r\
)                                                                         
  {                                                                       
    printf("Yes\n");                                                      
  } else {                                                                
    printf("No\n");                                                       
  }                                                                       
                                                                          
    return 0;                                                             
  } 

Measured memory_bytes: 2668
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/1/ALDS1_1_D
# O(n**2)のプログラムを書かないように注意

import sys
read = sys.stdin.readline


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


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


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


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


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

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

    return ret


n = read_a_int()
R = read_col(n, 1)[0]

# dp的な考え方？
# 各時刻における損益の最大値は、前の時刻における損益の最大値と現時刻の最小値から計算可能
# 最小値にぶち当たるたびに、そこにひっつきながら収益がもっと上がるか見張る感じ

r_min = R[0]
ans = -10**9
for r in R[1:]:
    ans = max(ans, r-r_min)
    r_min = min(r, r_min)

print(ans)



Measured memory_bytes: 14948
n = input()
A = [input() for i in range(n)]

def insertionSort(A,n,g):
    cnt = 0
    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v

    return cnt

def shellSort(A,n):
    cnt = 0
    m = int((n-1)/3)
    G = [1]
    for i in range(1,n):
        gn = G[i-1]+3**i
        if gn > n:
            break
        G.append(gn)
    m = len(G)
    for i in range(m):
        j = (m-1) - i
        cnt += insertionSort(A,n,G[j])

    return m, G, cnt

m, G, cnt = shellSort(A,n)

print m

for i in range(1,m):
    j = m - i
    print G[j],
print G[0]

print cnt

for item in A:
    print item

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, d2, d4;

int main() {
	cin >> n;
	rep(i,n) {
		cin >> a;
		if (a%4==0) d4++;
		else if (a%2==0) d2++;
	}
	int d1 = n - (d2+d4);
	// d2が存在しないなら14141と並べればいい
	if (d2==0 && d1<=d4+1) cout << "Yes" << ln;
	// d2が存在するなら、d2を全部1まとめにしてしまうとd1一個と同じ扱いができる
	else if (d2!=0 && d1<=d4) cout << "Yes" << ln;
	else cout << "No" << ln;
}

Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x,'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x,'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x,'x') # rev => int(res, 16)
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n = IS()
    hon = [2,4,5,7,9]
    pon = [0,1,6,8]
    s = int(n[-1])
    if s in hon: print('hon')
    elif s in pon: print('pon')
    elif s == 3: print('bon')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9584
#! /usr/bin/env python3
# -*- coding:utf-8 -*-
import math

def get_net_price(N):
    N_upper = math.ceil((N+1)/1.08 - 1)
    N_lower = math.ceil(N/1.08)
    if N_upper < N_lower: return None
    else: return N_lower

def main():
    gross_price = int(input())
    net_price = get_net_price(gross_price)
    if net_price == None: print(":(")
    else: print(net_price)

if __name__ == "__main__":
    try:
        assert get_net_price(432) == 400
        assert get_net_price(1079) == None
        assert get_net_price(1001) == 927
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()


Measured memory_bytes: 3060
def main():
    n = int(input())
    ans = [0]*(n+1)
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if tmp <= n:
                    ans[tmp] += 1
    for i in range(1, n+1):
        print(ans[i])

if __name__ == "__main__":
    main()

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

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

	int n, q;
	cin >> n >> q;

	vector<priority_queue<int>> que( n );
	while( q-- > 0 ) {
		int cmd, t, x;
		cin >> cmd >> t;

		if( cmd == 0 ) {
			cin >> x;
			que[t].push( x );
		}
		else if( cmd == 1 && que[t].size() ) {
			cout << que[t].top() << '\n';
		}
		else if( cmd == 2 && que[t].size() ) {
			que[t].pop();
		}
	}

	return 0;
}



Measured memory_bytes: 3916
#include<iostream>
using namespace std;
#define MAX 100
#define INF (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

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

  for(int i = 0;i<n;i++){
    d[i] = INF;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INF;
    int u=-1;
    for(int i=0;i<n;i++){
      if(minv > d[i] && color[i] != BLACK){
	u=i;
	minv = d[i];
      }
    }
    if(u==-1) break;
    color[u] = BLACK;
    for(int v=0;v<n;v++){
      if(color[v] != BLACK && M[u][v] != INF){
	if(d[v] > d[u] + M[u][v]){
	  d[v] = d[u] + M[u][v];
	  color[v] =GRAY;
	}
      }
    }
  }
  for(int i = 0;i<n;i++){
    cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

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



Measured memory_bytes: 3128
from collections import deque
s=deque(input())
q=int(input())
direction=1
for i in range(q):
  k=deque(input().split())
  if k[0]=='1':
    direction*=(-1)
  if k[0]=='2':
    if k[1]=='1':
      if direction==1:
        s.appendleft(k[2])
      else:
        s.append(k[2])
    if k[1]=='2':
      if direction==1:
        s.append(k[2])
      else:
        s.appendleft(k[2])
if direction==-1:
  s.reverse()
print("".join(list(s)))

Measured memory_bytes: 8436