akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.buffer.readline()[:-1].decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

s=input()
n=len(s)+1
ans=[0]*n
for i in range(n-1):
    if s[i]=='<':
        ans[i+1]=max(ans[i+1],ans[i]+1)
for i in range(n-2,-1,-1):
    if s[i]=='>':
        ans[i]=max(ans[i+1]+1,ans[i])
print(sum(ans))


Measured memory_bytes: 51440
# -*- coding: utf-8 -*-
n = int(input())
ot, ox, oy = 0, 0, 0
flg = True

for i in range(n):
    t, x, y = map(int, (input().split()))
    dt, dxy = t - ot, abs(x - ox) + abs(y - oy)

    if dt < dxy or (dt + dxy) % 2 != 0:
        flg = False

    ot, ox, oy = t, x, y

print('Yes' if flg else 'No')


Measured memory_bytes: 3060
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

namespace CSharp_Shell
{

    public static class Program 
    {
        public static void Main() 
        {
           var inputs=Console.ReadLine().Split();
           foreach(var input in inputs)
           {
               Console.Write(input.ToUpper()[0]);
           }
           Console.WriteLine();
        }
    }
}

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

using namespace std;

//#define debug

#ifdef debug
#define dump(i) cout << "[*] " #i ": " << i << endl;
#else
#define dump(i)
#endif

int main() {
  int m;
  cin >> m;
  cout << 48 - m << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    long long d,n,t=1;
    cin>>d>>n;
    for(long long i=0;i<d;i++)
        t*=100;
if(n!=100)
    cout<<t*n;
else cout<<(n+1)*t;
    return 0;
}

Measured memory_bytes: 256
while True:
  a, b = map(int, input().split())
  if a == 0 and b == 0:break
  w = b - a
  x = w // 1000
  w %= 1000
  y = w // 500
  w %= 500
  z = w // 100
  print(z, y, x)
 


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#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 repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

struct UnionFind {
  vector<int> data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y)
      return (false);
    if (data[x] > data[y])
      swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int root(int k) {
    if (data[k] < 0)
      return (k);
    return (data[k] = root(data[k]));
  }

  int size(int k) {
    return (-data[root(k)]);
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }
};

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M), B(M);
  rep(i, M) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }

  reverse(all(A));
  reverse(all(B));

  UnionFind u(N);
  vector<ll> inconv(M);
  inconv[0] = N * (N - 1) / 2;
  repp(i, 1, M - 1) {
    int a = A[i - 1], b = B[i - 1];
    if (u.issame(a, b)) {
      inconv[i] = inconv[i - 1];
    } else {
      inconv[i] = inconv[i - 1] - u.size(a) * u.size(b);
      u.unite(a, b);
    }
  }

  reverse(all(inconv));
  rep(i, M) {
    cout << inconv[i] << endl;
  }
}

Measured memory_bytes: 4096
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    int L[N];
    for (int i = 0; i < N; i++) cin >> L[i];

    int ret = INF;

    int mul = 1;
    for (int i = 0; i < N; i++) mul *= 4;

    for (int mask = 0; mask < mul; mask++) {
        int m = mask;

        int acnt = 0;
        int bcnt = 0;
        int ccnt = 0;
        int ascore = 0;
        int bscore = 0;
        int cscore = 0;
        for (int i = 0; i < N; i++) {
            if (m % 4 == 0) {
                acnt++;
                ascore += L[i];
            }

            if (m % 4 == 1) {
                bcnt++;
                bscore += L[i];
            }

            if (m % 4 == 2) {
                ccnt++;
                cscore += L[i];
            }

            m /= 4;
        }

        if (acnt == 0 || bcnt == 0 || ccnt == 0) continue;

        int tmp = (acnt - 1) * 10 + (bcnt - 1) * 10 + (ccnt - 1) * 10;
        tmp += abs(A - ascore) + abs(B - bscore) + abs(C - cscore);

        ret = min(ret, tmp);
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
 
class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String W=br.readLine();
        String[] T;
        int c=0;
        while(true){
            T=br.readLine().split(" ");
            if(T[0].equals("END_OF_TEXT")) break;
            for(String str : T){
              if(str.equalsIgnoreCase(W)) c++;
            }
        }
        System.out.println(c);
    }
}

Measured memory_bytes: 24420
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		private static Queue<Tuple<int, int>> q;
		private static int[,] dist;
		private static string[] s;
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int h = cin.Int();
			int w = cin.Int();
			s = new string[h];
			for (int i = 0; i < h; i++) {
				s[i] = cin.Next();
			}

			int inf = 3000;
			dist = new int[h, w];
			int black = 0;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					dist[i, j] = inf;
					if (s[i][j] == '#') {
						++black;
					}
				}
			}

			q = new Queue<Tuple<int, int>>();
			dist[0, 0] = 1;
			q.Enqueue(new Tuple<int, int>(0, 0));
			while (q.Count > 0) {
				var next = q.Dequeue();
				int i = next.Item1;
				int j = next.Item2;

				if (j - 1 >= 0) {
					Check(i, j, i, j - 1);
				}

				if (j + 1 < w) {
					Check(i, j, i, j + 1);
				}

				if (i - 1 >= 0) {
					Check(i, j, i - 1, j);
				}

				if (i + 1 < h) {
					Check(i, j, i + 1, j);
				}
			}

			if (dist[h - 1, w - 1] == inf) {
				Console.WriteLine(-1);
				return;
			}

			int minD = dist[h - 1, w - 1];
			int ans = (h * w) - black - minD;
			Console.WriteLine(ans);
		}

		static void Check(int i, int j, int ni, int nj)
		{
			if (s[ni][nj] == '.') {
				int nd = dist[i, j] + 1;
				if (nd < dist[ni, nj]) {
					dist[ni, nj] = nd;
					q.Enqueue(new Tuple<int, int>(ni, nj));
				}
			}
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

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

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


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

int main() {
    int n,k;
    int cnt;
    cin>>n>>k;

    double ans;

    REP(i,n)
    {
        int tmp;
        tmp=0;
        cnt=0;

        tmp=(i+1);

        while(tmp<k)
        {
            tmp *= 2;
            cnt++;
            //if (tmp>=k) break;
        }
        ans += ((double)1/n) * pow(0.5, cnt);
    }
    
    cout << std::setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N=2e5+5;
#define inf 1e18+8
#define pii pair<int, int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define vpii vector<pair<int,int> > 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

signed  main()
{
    fastio;
    float r;cin>>r;
    float ans=2*22*r/7;
    cout<<ans;
  
    
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
    ll a,b;cin>>a>>b;
    ll k = (a*a - b*b)/(2*a-2*b);
    if(abs(a-k) == abs(b-k)){
        cout << k << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define lo long long
using namespace std;
int n,cev;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int z=i;
		int say=0;
		while(z){
			say++;
			z/=10;
		}
		if(say%2==1) cev++;
	}
	printf("%d\n",cev);
	return 0;
}




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

int main(void)
{
    string s, t;
    vector<int> sd(26),td(26);

    cin >> s >> t;
    //s
    rep(i, s.size()) {
        ++sd[(s[i] - 'a')];
    }
    sort(sd.begin(), sd.end());
    //t
    rep(i, t.size()) {
        ++td[(t[i] - 'a')];
    }
    sort(td.begin(), td.end());
    //sとtをチェック
    rep(i, 26) {
        if (sd[i] != td[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

int main() {
    int n, g; cin >> n >> g;
    vector<int> v(n, 0), w(n, 0);
    for (int i = 0; i < n; i += 1)
        cin >> w[i] >> v[i];
    
    vector<int64_t> dp(g + 1, -1);
    dp[0] = 0;

    for (int i = 0; i < n; i += 1)
        for (int j = g; j >= 0; j -= 1)
            if (j - w[i] >= 0 and dp[j - w[i]] >= 0)
                dp[j] = max(dp[j], dp[j - w[i]] + v[i]);

    cout << *max_element(dp.begin(), dp.end()) << "\n";
}

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long

int n;
int p[50],in[50],ans[50];

int s=0,nsr=0;
void solve(int lit,int rit){
	if(lit>=rit) return;
	int hoge=p[s];
	s++;
	lp(i,n){
		if(in[i]==hoge){
			solve(lit,i);
			solve(i+1,rit);
			break;
		}
	}
	ans[nsr]=hoge;
	nsr++;
}

signed main(){
	cin>>n;
	lp(i,n)cin>>p[i];
	lp(i,n)cin>>in[i];
	solve(0,n);
	lp(i,n){
		if(i!=0) cout<<" ";
		cout<<ans[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    int len = a.length();
    char[] b = a.toCharArray();
    boolean ans = false; 
    for(int i = 0;i < len;i++){
      if(b[i] == '7'){
        ans = true;
      }
    }
    if(ans){
      System.out.println("Yes");
    }else{
      System.out.println("No");      
    }
  }
}

Measured memory_bytes: 35688
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){

    int N = 0, M = 0 ,K;
    string S;

    cin >> N;
    cin >> S;
    cin >> K;

    string a;
    for(int i = 0; i < S.size() ; i++){
        if(S[i] == S[K - 1]){
            a += S[i];
        }
        else {
            a += "*";
        }
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


def odd(n): return n & 1


def even(n): return not odd(n)


def comb(n, m):
    r = 1
    for i in range(1, n+1):
        r *= i
    for i in range(1, m+1):
        r //= i
    for i in range(1, n-m+1):
        r //= i
    return r


N, P = map(int, input().split())
A = [int(n) % 2 for n in input().split()]
cnt0 = len([a for a in A if a == 0])
cnt1 = len([a for a in A if a == 1])
ans = 0
if odd(P):
    for i in range(cnt1 + 1):
        if odd(i):
            ans += comb(cnt1, i)
else:
    for i in range(cnt1 + 1):
        if even(i):
            ans += comb(cnt1, i)
ans *= pow(2, cnt0)
print(ans)


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

int main() {
    int n,m;
    int asum=0;
    int res;
    cin >> n >> m;
    vector<int> a(m);
    for(int i=0;i<m;++i){
        cin >> a[i];
        asum+=a[i];
    }
    if(asum>n){
        cout << -1 << endl;
        return 0;
    }
    res=n-asum;
    cout << res << endl;
}

Measured memory_bytes: 3636
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;

template <class T>
void Swap(T& r, T& l) {
    T tmp = r;
    r = l;
    l = tmp;
}



int main() {

  long n,t,a;
  cin >>n;
  cin >>t >> a;

  vector<double> h(n);
  vector<pair<int,double> > c(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> h[i];

    c[i].second = abs(a - (t - h[i] * 0.006) );
    c[i].first = i+1;


  }


  sort(c.begin(),c.end() ,[](pair<int,double> &l,pair<int,double> &r){
    return l.second < r.second;
  } );



  cout << c[0].first;


}



























Measured memory_bytes: 256
n = raw_input()
step_array = map(int, raw_input().split())
score_array = []
for i in range(len(step_array)):
	if i ==0:
		score_array.append(0)
	elif i == 1:
		score_array.append(abs(step_array[1]-step_array[0]))
	else:
		check_num_1 = abs(step_array[i] - step_array[i-1]) + score_array[i-1]
		check_num_2 = abs(step_array[i] - step_array[i-2]) + score_array[i-2]
		append_num = check_num_1 if check_num_1 < check_num_2 else check_num_2
		score_array.append(append_num)
print(score_array[len(step_array)-1])


Measured memory_bytes: 12676
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}

signed main(){
	int k,n;
	cin>>n>>k;
	cout<<n-k+1<<endl;
	return 0;
}


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


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

	vector<int> cnt(n,0);
	int x;
	
	rep(i, n-1){
		cin >> x;
		cnt[x-1]++;
	}

	rep(i, n) cout << cnt[i] << endl; 


}


Measured memory_bytes: 3960
#include <iostream>
using namespace std;
int n; 
int arr[22];
int main() {
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	int cnt = 0;
	for(int i = 1; i < n-1; i++){
		if((arr[i] > arr[i+1]  && arr[i] < arr[i-1]) || (arr[i] > arr[i-1] && arr[i] < arr[i+1])){
			cnt++;
		}
	}
	cout << cnt;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int arr[N];
int brr[N];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>arr[i]>>brr[i];
	}
	sort(arr+1,arr+1+n);
	sort(brr+1,brr+1+n);
	if(n%2==0) 	cout<<brr[n/2]+brr[n/2+1]-arr[n/2]-arr[n/2+1]+1<<endl;
	else  cout<<brr[(n+1)/2]-arr[(n+1)/2]+1<<endl;
	return 0;
}

Measured memory_bytes: 5204
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void integerFactorization(long long n, vector<long long>& base, vector<int>& exp)
{
    base.clear();
    exp.clear();
    long long a = 2;
    while(a * a <= n){
        int b = 0;
        while(n % a == 0){
            ++ b;
            n /= a;
        }
        if(b > 0){
            base.push_back(a);
            exp.push_back(b);
        }
        ++ a;
    }
    if(n > 1){
        base.push_back(n);
        exp.push_back(1);
    }
}

long long solve(long long n)
{
    vector<long long> base;
    vector<int> exp;
    integerFactorization(n, base, exp);
    int m = exp.size();

    long long ret = 1;
    for(int i=0; i<m; ++i)
        ret *= 2 * exp[i] + 1;
    ++ ret;
    ret /= 2;
    return ret;
}

int main()
{
    for(;;){
        long long n;
        cin >> n;
        if(n == 0)
            return 0;
        cout << solve(n) << endl;
    }
}

Measured memory_bytes: 912
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n,x,y;
  cin >> n;
  vpi xy(n);
  double sum=0;
  REP(i,n) {
    cin >> x >> y;
    pi s(x,y);
    xy[i]=s;
  }
  REP(i,n-1) {
    REPD(j,i+1,n) {
      double temp=0;
      temp+=pow(xy[i].first-xy[j].first,2);
      temp+=pow(xy[i].second-xy[j].second,2);
      temp=sqrt(temp);
      sum+=temp;
    }
  }
  double ans = 2*sum/n;
  cout << fixed << setprecision(8) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

struct dat {
    int X, Y, P;
};

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

    int N;
    cin >> N;
    vector<dat> v(N);
    for (int i = 0; i < N; ++i)
        cin >> v[i].X >> v[i].Y >> v[i].P;

    vector<vector<int>> xcost(N, vector<int>(1 << N, INT_MAX));
    vector<vector<int>> ycost(N, vector<int>(1 << N, INT_MAX));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 1 << N; ++j) {
            xcost[i][j] = abs(v[i].X);
            ycost[i][j] = abs(v[i].Y);
            for (int k = 0; k < N; ++k) {
                if (j & (1 << k)) {
                    xcost[i][j] = min(xcost[i][j], abs(v[i].X - v[k].X));
                    ycost[i][j] = min(ycost[i][j], abs(v[i].Y - v[k].Y));
                }
            }
        }
    }

    vector<ll> ans(N + 1, LLONG_MAX);
    for (int i = 0; i < 1 << N; ++i) {
        for (int j = i;; j = (j - 1) & i) {
            int xbit = j, ybit = i ^ j;
            ll tmp = 0;
            for (int k = 0; k < N; ++k)
                tmp += min<ll>(xcost[k][xbit], ycost[k][ybit]) * v[k].P;

            int cnt = __builtin_popcount(xbit | ybit);
            ans[cnt] = min(ans[cnt], tmp);

            if (!j)
                break;
        }
    }

    for (int i = 0; i <= N; ++i)
        cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 7160
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

class node{
public:
  int x, y, id;
};
class tree{
public:
  int l, r, key;
};
node p[500000];
tree t[500000];
vector<int> ans;
bool compx(const node& l, const node& r){
  return l.x < r.x;
}
bool compy(const node& l, const node& r){
  return l.y < r.y;
}

int n, q, sx[20000], tx[20000], sy[20000], ty[20000], np = 0;

int make2dtree(int l, int r, int d){
  if(l >= r) return -1;
  int x = np++;
  if(d % 2 == 0) sort(p + l, p + r, compx);
  else sort(p + l, p + r, compy);
  int mid = (l + r) / 2;
  t[x].key = mid;
  t[x].l = make2dtree(l, mid, d + 1);
  t[x].r = make2dtree(mid + 1, r, d + 1);
  return x;
}

void findx(int v, int sx, int tx, int sy, int ty, int d){
  int x = p[t[v].key].x, y = p[t[v].key].y;
  if(sx <= x && x <= tx && sy <= y && y <= ty) ans.push_back(p[t[v].key].id);
  if(d % 2 == 0){
    if(t[v].l != -1 && sx <= x) findx(t[v].l, sx, tx, sy, ty, d + 1);
    if(t[v].r != -1 && tx >= x) findx(t[v].r, sx, tx, sy, ty, d + 1);
  }
  else{
    if(t[v].l != -1 && sy <= y) findx(t[v].l, sx, tx, sy, ty, d + 1);
    if(t[v].r != -1 && ty >= y) findx(t[v].r, sx, tx, sy, ty, d + 1);
  }
  return;
}

void solve(){
  cin >> n;
  for(int i = 0; i < n; i++){
    scanf("%d %d", &p[i].x, &p[i].y);
    p[i].id = i;
    t[i].l = -1;
    t[i].r = -1;
  }
  make2dtree(0, n, 0);
  cin >> q;
  int sx, tx, sy, ty;
  for(int i = 0; i < q; i++){
    scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
    findx(0, sx, tx, sy, ty, 0);
    sort(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++){
      printf("%d\n", ans[i]);
    }
    printf("\n");
    ans.clear();
  }
  return;
}

int main(){
  solve();
  return 0;
}



Measured memory_bytes: 14556
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

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

  int ans = 0;
  for(int i=1; i<=12; i++) {
    if ( i < a ) ans++;
    else if ( i == a ) {
      if ( i <= b ) ans++;
      break;
    }
    else break;
  } 
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
usrInput = input()

if usrInput == "SUN":
    DayPlace = 0
elif usrInput == "MON":
    DayPlace = 1
elif usrInput == "TUE":
    DayPlace = 2
elif usrInput == "WED":
    DayPlace = 3
elif usrInput == "THU":
    DayPlace = 4
elif usrInput == "FRI":
    DayPlace = 5
elif usrInput == "SAT":
    DayPlace = 6

finalOutput = 7 - DayPlace
print(finalOutput)

Measured memory_bytes: 2940
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    swap(A, B);
    int a = (A-1+49)/50;
    int b = (B-1+49)/50;
    int h = a*2+b*2+2;
    cout << h << ' ' << 100 << endl;
    for(int i = 0; i < 100; i++){
        cout << '.';
    }
    cout << endl;
    
    for(int i = 0; i < a; i++){
        if(i != a-1){
            for(int j = 0; j < 50; j++){
                cout << '.' << '#';
            }
            cout << endl;
        }else{
            int A_;
            if((A-1)%50 == 0) A_ = 50;
            else A_ = (A-1)%50;
            for(int j = 0; j < A_; j++){
                cout << '.' << '#';
            }
            for(int j = A_; j < 50; j++){
                cout << '.' << '.';
            }
            cout << endl;
        }
        for(int j = 0; j < 100; j++){
            cout << '.';
        }
        cout << endl;
    }
    for(int i = 0; i < 100; i++){
        cout << '#';
    }
    cout << endl;
    for(int i = 0; i < b; i++){
        if(i != b-1){
            for(int j = 0; j < 50; j++){
                cout << '#' << '.';
            }
            cout << endl;
        }else{
            int B_;
            if((B-1)%50 == 0) B_ = 50;
            else B_ = (B-1)%50;
            for(int j = 0; j < B_; j++){
                cout << '#' << '.';
            }
            for(int j = B_; j < 50; j++){
                cout << '#' << '#';
            }
            cout << endl;
        }
        for(int j = 0; j < 100; j++){
            cout << '#';
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
ll mod1=1000000007ll;
ll mod2=998244353ll;

bool vis[200002];
ll ma[200002],bit[200005],rank1[200005],parent[200005];
ll c=0,x=0,n,an=0;
ll gcd(ll a, ll b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
ll power(ll x,ll y)
{   if(y==0) return 1;
    ll p=power(x,y/2);
    p=(p*p)%mod2;
    if(y%2) return  (p*x)%mod2;
    return p;
}
ll sum(ll in)
{   in++;
    ll sum1=0;
    while(in>0)
    {
        sum1+=bit[in];
        in-=in & (-in);
    }
    return sum1;
}
void update(ll in,ll val)
{   in++;
    while(in<=200002)
    {
        bit[in]+=val;
        in+=in & (-in);
    }
}
 struct vec {
    vector<ll> v;
    bool operator<( const  vec& a) const
    { return a.v[0] < v[0]; }
  };

ll find(ll x)
{
    if(x==parent[x])
    return x;
    else
    return find(parent[x]);
}
void merged(ll x, ll y)
{
    x=find(x);
    y=find(y);
    if(rank1[x]>rank1[y])
    {
        parent[y]=x;
        rank1[x]+=rank1[y];
    }
    else
    {
        parent[x]=y;
        rank1[y]+=rank1[x];
    }

}
void solve()
{
   string s,p;
   cin>>s>>p;
   ll c=0;
   for(ll i=0;i<3;i++)
    if(s[i]==p[i])
    c++;
   cout<<c;
}

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


Measured memory_bytes: 256
import math
a, b, c = map(int, input().split())

r = c * (math.pi/180)
h = b * math.sin(r)
S = a * h / 2
L = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(r))

print(S)
print(L)
print(h)



Measured memory_bytes: 5704
#include<bits/stdc++.h>
#define maxn 500050
#define M 1000000007

using namespace std;
typedef long long ll;
char s[maxn];
ll dp[maxn][5][2],n,k;

int main()
{
    scanf("%s",s);
    n=strlen(s);
    dp[0][2][0]=1;
    for (int i=0;i<n;i++)
    {
        if (s[i]!='0'){
            (dp[i+1][4][1]+=dp[i][4][1])%=M;
            (dp[i+1][4][1]+=dp[i][3][1])%=M;
            (dp[i+1][3][1]+=dp[i][2][0])%=M;
            (dp[i+1][3][1]+=dp[i][2][1])%=M;
            (dp[i+1][2][0]+=dp[i][1][0])%=M;
            (dp[i+1][2][1]+=dp[i][1][1])%=M;
            (dp[i+1][1][0]+=dp[i][0][0])%=M;
        }
        if (s[i]!='1'){
            (dp[i+1][4][1]+=dp[i][4][1])%=M;
            (dp[i+1][2][1]+=dp[i][3][1])%=M;
            (dp[i+1][1][0]+=dp[i][2][0])%=M;
            (dp[i+1][1][1]+=dp[i][2][1])%=M;
            (dp[i+1][0][0]+=dp[i][1][0])%=M;
            (dp[i+1][2][1]+=dp[i][1][1])%=M;
            (dp[i+1][1][0]+=dp[i][0][0])%=M;
        }
    }
    cout << (dp[n][3][1]+dp[n][4][1])%M << endl;
    return 0;
}


Measured memory_bytes: 25088
import Data.Char
import Data.Array.Unboxed
import Debug.Trace
 
type Table = Array Char Int
type TableInf = Array Int Char
 
main :: IO ()
main = do
  s <- getLine
  n <- readLn :: IO Int
  let table = listArray ('a', 'z') [0..25] :: Table
  let table' = listArray (0, 25) ['a'..'z'] :: TableInf
  putStrLn $ solve table table' s n
 
solve :: Table -> TableInf -> String -> Int -> String
solve tab tab' str allNum = go str allNum
  where
    go [x] n = let m = tab ! x 
                   n' = (m + n `mod` 26) `mod` 26 in
                 [tab' ! n']
    go (x:xs) n = let m = tab ! x
                      n' = (26 - m) `mod` 26 in
                    if n' <= n
                       then 'a' : go xs (n - n')
                       else x : go xs n

Measured memory_bytes: 5116
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return a % 1000000007;
}


int main(){
  ll n; cin >> n; vl num(n); queue<ll> q; ll asum = 0; ll bsum = 0;
  rep(i,n){ ll x; cin >> x; num[i] = x; }
  
  sort(all(num)); reverse(all(num));
  
  for(ll x: num) q.push(x);
  
  while(!q.empty()){
    asum += q.front(); q.pop();
    
    if(!q.empty()){
      bsum += q.front(); q.pop();
    }
  }
  
  cout << asum - bsum  << endl;
}
    
  

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

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		int total = 0;
		for (int i = 0; i<n; i++) {
			arr[i] = sc.nextInt(); 
			total += arr[i];	
		}
		int m = sc.nextInt();
		while (m-- > 0) {
			int p = sc.nextInt(); int x = sc.nextInt();
			int temp = total - arr[p-1] + x;
			System.out.println(temp);
		}
	}
}


Measured memory_bytes: 36216
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
#define first fi
#define second se
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int sosu(int a){
    if(a==2){
        return 1;
    }
    for(int i=2;i<sqrt(a)+1;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
vector<int> v;
int n,m,cnt=0,ans=0,aa[220000];
pair<int,int> pp[220000];
string s,ss[220000],sa;
char ch[110][110];
queue<int> que;
signed main(){
    cin>>n>>m>>cnt;
    rep(i,10000){
        if(cnt%n==0){
            cout<<"YES"<<endl;
            return 0;
        }
        cnt+=m;
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 10576
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

        d := a / b
        r := a % b
        f := float64(a) / float64(b)

        fmt.Printf("%d %d %.5f\n", d, r, f)
}


Measured memory_bytes: 1112
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
const ld eps = 1e-4;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int d; cin >> d;
    int c[26];
    REP(i,26) cin >> c[i];
    int lsum = 0;
    REP(i,26) lsum += c[i];
    int v[d][26];
    REP(i,d)REP(j,26) cin >> v[i][j];
    V<> sol(d);
    V<> loss(26,0);
    REP(i,d){
        V<pair<ld,ll>> score(26,{0.0,0});
        REP(j,26) score[j] = {v[i][j] + loss[j] + c[j] * eps, j};
        sort(rall(score));
        int r = score[0].second;
        sol[i] = r;
        REP(j,26){
            if(j == r) loss[j] = 0;
            else loss[j] += c[j];
        }
    }
    REP(i,26) loss[i] = 0;
    ll nowres = 0;
    REP(i,d){
        nowres += v[i][sol[i]];
        REP(j,26){
            if(j == sol[i]) loss[j] = 0;
            else loss[j] += c[j];
            nowres -= loss[j];
        }
    }
    int Q = 245000;
    random_device rnd;
    int newi, newsol, old;
    ll newres;
    while(Q--){
        newi = rnd() % 365;
        newsol = rnd() % 26;
        if(sol[newi] == newsol) continue;
        old = sol[newi];
        sol[newi] = newsol;
        REP(i,26) loss[i] = 0;
        newres = 0;
        REP(i,d){
            newres += v[i][sol[i]];
            REP(j,26){
                if(j == sol[i]) loss[j] = 0;
                else loss[j] += c[j];
                newres -= loss[j];
            }
        }
        if(newres <= nowres) sol[newi] = old;
        else nowres = newres;
    }
    REP(i,d) cout << sol[i] + 1 << '\n';
}


Measured memory_bytes: 3720
s = input()
length = len(s)
ans = '-1 -1'
for i in range(length - 1):
  if s[i] == s[i + 1]:
    ans = '{} {}'.format(i + 1, i + 2)
    break
  if i < length - 2 and s[i] == s[i + 2]:
    ans = '{} {}'.format(i + 1, i + 3)
    break
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
カードは1か2
Zで偶数奇数がわかる
Unionかな
*/
vector<bool> seen;
vector<vector<ll>> G;
struct UnionFind{
  vector<ll> par,siz;
  
  UnionFind(ll N):par(N+1),siz(N+1,1){
    for(int i=0; i<=N; i++)
      par[i]=i;
  }
  
  void mkpar1(ll parent, ll n){//親は最上位
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n]=true;
      par[next_n]=parent;
      mkpar1(parent, next_n);
    }
  }
  
  void mkpar2(ll n){//親は1個うえ
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n]=true;
      par[next_n]=n;
      mkpar2(next_n);
    }
  }
  
  ll root(ll x){
    if(par[x]==x)
      return x;
    return par[x]=root(par[x]);
  }
  
  void unite(ll x, ll y){
    ll rx=root(x), ry=root(y);
    if(rx==ry)
      return;
    par[ry]=rx;
    siz[rx]+=siz[ry];    
  }
  
  bool issame(ll x, ll y){
    return root(x)==root(y);
  }
  
  ll size(ll x){
    return siz[root(x)];
  }
};
int main(){
  ll N,M; cin>>N>>M;
  seen.assign(N+1,false);
  G.assign(N+1, vector<ll>(0,0));
  for(ll i=0; i<M; i++){
    ll x,y,z; cin>>x>>y>>z;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  UnionFind tree(N);
  for(ll i=1; i<=N; i++){
    seen[i]=true;
    tree.mkpar1(i,i);
  }
  set<ll> S;
  for(ll i=1; i<=N; i++) S.insert(tree.par[i]);
  cout<<S.size()<<endl;
}

Measured memory_bytes: 10880
#define _USE_MATH_DEFINES
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	rep(i, s.size()) {
		char c = s[i] + n;
		if (c <= 'Z' && c >= 'A') {
			cout << c;
		}
		else {
			char now = 'A' + (c - 'Z') - 1;
			cout << now;
		}
	}
	cout << endl;

	return 0;
}


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

signed main(){
  int N;
  cin>>N;
  vector<string> A(N);
  rep(i,N)cin>>A[i];
  int ans=1;
  sort(begin(A),end(A));
  rep(i,N-1){
    if(A[i]!=A[i+1])ans+=1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 9596
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> hist(N + 1, 0);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    hist[A]++;
  }

  sort(hist.begin(), hist.end(), greater<int>());
  int tmp = 0;
  for (int i = 0; i < K; i++) {
    tmp += hist[i];
  }
  cout << (N - tmp) << endl;

  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int arg_amax = -1;
            int amax = 0;
            int arg_amax_2 = -1;
            int amax_2 = 0;
            for (int i=0; i<n; i++)
            {
                int a = int.Parse(Console.ReadLine());
                if (a >= amax)
                {
                    amax_2 = amax;
                    arg_amax_2 = arg_amax;
                    amax = a;
                    arg_amax = i;
                }
                else if (a >= amax_2)
                {
                    amax_2 = a;
                    arg_amax_2 = i;
                }
            }
            for (int i=0; i<n; i++)
            {
                if (i == arg_amax) Console.WriteLine(amax_2);
                else Console.WriteLine(amax);
            }

            
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 18632
#include <iostream>

using namespace std;
int aa[(int )5e5];
int an = 0, mod = 1e9+7;
int fst(int n,int p){
    if(p==0)return 1;
    int res=fst(n,p>>1);
    res=res*1LL*res%mod;
    if(p&1)res=res*1LL*n%mod;
    return res;
}
int calc(int c){
    int y = c*1LL*(c+1)%mod;
    y = y*1LL*fst(2,mod-2)%mod;
    return y;
}
int main() {
    int n,k;
    cin>>n>>k;
    
    for(int i=0;i<n;i++){
        cin>>aa[i];
        int cnt = 0 ;
        for(int j=0;j<i;j++)cnt += aa[j] > aa[i];
        an += cnt * 1LL * calc(k) % mod;
        an%=mod;
    }
    for(int i=0;i<n;i++){
        int cnt = 0;
        for(int j=i+1;j<n;j++)
            cnt += aa[j] > aa[i];
        an += cnt * 1LL * calc(k-1) % mod;
        an%=mod;
    }
    cout<<an;
    return 0;
}

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

namespace AtCoderBeginnerContest178
{
	class Program
	{
		static readonly int DIV = (int)Math.Pow(10, 9) + 7;

		static void Main(string[] args)
		{
			var input = long.Parse(Console.ReadLine());

			if (input == 1)
			{
				Console.WriteLine(0);
				return;
			}
			else if (input == 2)
			{
				Console.WriteLine(2);
				return;
			}

			// 求めるべきは 10^(n-2) * nC2

			long ten = 10;
			long nine = 9;
			long eight = 8;

			for (var i = 0; i < input - 1; i++)
			{
				ten = (ten * 10) % DIV;
				nine = (nine * 9) % DIV;
				eight = (eight * 8) % DIV;
			}

			var tmp = (ten + eight) % DIV;


			nine = (nine * 2) % DIV;
			var result = 0L;
			if (tmp > nine)
			{
				result = (ten - nine + eight) % DIV;
			}
			else
			{
				result = (ten - nine + eight + DIV) % DIV;
			}

			Console.WriteLine(result);
		}
	}
}


Measured memory_bytes: 27788
#include <bits/stdc++.h>
#define fname "C"
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << (#x) << " = " << (x) << '\n'
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<float, float> ff;
typedef pair<double, double> dd;
ll upper(ll a, ll b) {return a%b == 0 ? (a/b) : (a/b + 1);}

int main()
{
	if (fopen(fname".INP", "r")) {
		freopen(fname".INP", "r", stdin);
		freopen(fname".OUT", "w", stdout);
	}
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	ll a, b, x, y;
	scanf("%d %lld %lld", &n, &x, &y);
	REP0(i, n - 1) {
		scanf("%lld %lld", &a, &b);
		ll t = max(upper(x, a), upper(y, b));
		x = a*t; y = b*t;
	}
	cout << x + y;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a;
      a = new int[n];
      for(int i=0;i<n;i++){
        a[i] = sc.nextInt();
        //System.out.println(a[i]);
      }
      int count = 0;
      for(int i=0;i<n-1;i++){
        for(int j=0;j<n-1;j++){
          if(a[j]>a[j+1]){
            int temp = a[j];
            a[j] = a[j+1];
            a[j+1] = temp;
            count++;
          }
        }
      }
      for(int i = 0;i<n;i++){
        System.out.print(a[i]);
        if(i==n-1){
          System.out.println();
        }else{
        System.out.print(" ");
        }
      }
      System.out.println(count);
  }
}


Measured memory_bytes: 26232
n, k = map(int, input().split())

H = sorted(int(input().strip()) for i in range(n))
min_diff = 10e9 + 5

cumsum = []
for h in H:
  cumsum.append(h)
  if len(cumsum) >= k:
    min_diff = min(min_diff, cumsum[-1] - cumsum[-k])

print(min_diff)


Measured memory_bytes: 8028
#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() {
    cout << fixed << setprecision(10);
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    
    int mult = 0;
    double ans = (double) w * h / 2;
    if (2*x == w && 2*y == h) mult = 1;
    cout << ans << ' ' << mult << endl;
    return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <cstring>
#include <queue>
#define LL long long
#define MAXN (1000000 + 5)
using namespace std;
int n;
LL fr[MAXN];
char s[MAXN];
void solve(int k) {
	LL dqd = 0, ans = 0;
	queue<int> q;
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'M')	q.push(i), dqd += fr[i];
		if (s[i] == 'C') {
			while (!q.empty() && i - q.front() >= k)
				dqd -= fr[q.front()], q.pop();
			ans += dqd - fr[max(0, i - k)] * q.size();	
		}
	}
	printf("%lld\n", ans);
}
int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++)
		fr[i] = fr[i - 1] + (s[i] == 'D');
	int q;
	scanf("%d", &q);
	for (int i = 1, srq; i <= q; i++)
		scanf("%d", &srq), solve(srq);
	return 0;
}


Measured memory_bytes: 10448
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000
#define ll long long
#define MOD 1000000007
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()


ll f(ll N, ll k)
{
    ll sum = ((N*k)%MOD - (k*k)%MOD + k + MOD + 1) % MOD;
    return sum;
}

int main()
{
    ll N, k;
    cin >> N >> k;
    ll sum = 0;
    for(int i = k; i <= (N + 1); i++)
    {
        sum = (sum + f(N, i)) % MOD;
    }
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 3552