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


using namespace std;

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int n1 = mid -left;
  int n2 = right - mid;

  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i=0, j=0;
  for(int k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

	cin >> n; // scanf("%d",&n);
  for(i=0;i<n;i++) cin >> A[i];

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " "; // printf(" "); 
  	cout << A[i]; // printf("%d",A[i]);
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 6952
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#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 MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;

const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 1, 0,-1};
const int dy4[6] = {-1, 0, 1,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};
void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}

ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 6e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1000000007;
/*************************************************************************/

void solve() {
    vector<int> s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin>>n;
    cout<<s[n-1]<<endl;
}


int main()
{

  solve();
  return 0;
}





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

using namespace std;

int limit=0,T[4][4];

int evaluate(){
  int cx[]={3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2},cy[]={3,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3};
  int ret=0;
  for (int i=0;i<4;i++){
    for (int j=0;j<4;j++){
      int ti = T[i][j];
      if (ti==0)continue;
      ret+=abs(cx[ti]-j);
      ret+=abs(cy[ti]-i);
      // if (cx[ti]!=j||cy[ti]!=i)ret++;
    }
  }
  return ret;
}

bool trymove(int c,int zx,int zy,int pzx,int pzy){
  int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
  if (evaluate()==0)return true;
  if (c+evaluate()>limit)return false;
  for (int i=0;i<4;i++){
    if (0>zx+dx[i]||zx+dx[i]>3||0>zy+dy[i]||zy+dy[i]>3)continue;
    if (zx+dx[i]==pzx&&zy+dy[i]==pzy)continue;
    swap(T[zy][zx],T[zy+dy[i]][zx+dx[i]]);
    if (trymove(c+1,zx+dx[i],zy+dy[i],zx,zy)) return true;
    swap(T[zy][zx],T[zy+dy[i]][zx+dx[i]]);
  }
  return false;
}

int main(){
  int zx,zy;
  for (int i=0;i<4;i++){
    for (int j=0;j<4;j++){
      cin >> T[i][j];
      if (T[i][j]==0){
	zx=j;
	zy=i;
      }
    }
  }
  
  while (evaluate()){
    limit++;
    if (trymove(0,zx,zy,zx,zy))break;
  }
  
  cout << limit << endl;
  
  return 0;
}

Measured memory_bytes: 3084
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll a[1000000];
ll b[1000000];
ll c[1000000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
int main() {
	ll t;
	cin>>N>>t;
	double ans =0;
	rep(i,0,N){
		ll x,h;
		cin>>x>>h;
		double a = (double)h/x;
		ans = max(ans,a*t);
	}
	cout<<fixed<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3304
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let n: usize = read();
    let mut cnt:HashMap<String, usize> = HashMap::new();

    for _ in 0..n {
        let e = read();
        let n = cnt.entry(e).or_insert(0);
        *n += 1;
    }
    
    let mut max = 0;
    for c in &cnt {
        if *c.1 > max {
            max = *c.1;
        }
    }
    
    let mut ans: Vec<String> = Vec::new();
    for c in &cnt {
        if *c.1==max {
            ans.push(c.0.to_string());
        }
    }

    ans.sort();

    for a in ans{
        println!("{}", a);
    }

}

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

typedef long long int ll;
typedef unsigned long long int ull;

int main() {
  int k;
  string s;

  cin >> k >> s;
  if (s.size() <= k) {
    cout << s << "\n";
  } else {
    cout << s.substr(0, k) << "..."
         << "\n";
  }
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

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

    int n;
    cin >> n;
    if(n==1){
        cout << "Hello World\n";
    }else{
        int a,b;
        cin >> a >> b;
        cout << a + b << '\n';
    }
}


Measured memory_bytes: 256
from heapq import heappush, heappushpop

N = int(input())
a = list(map(int, input().split()))

a_list_1 = []
a_list_2 = []
for i in a[0:N]:
    heappush(a_list_1, i)
for i in list(reversed(a))[0:N]:
    heappush(a_list_2, -i)

sum_1 = sum(a_list_1)
sum_2 = sum(a_list_2)
sum_arr_1 = [0] * (N + 1)
sum_arr_1[0] = sum_1
sum_arr_2 = [0] * (N + 1)
sum_arr_2[-1] = sum_2
for k in range(N, 2 * N):
    l = heappushpop(a_list_1, a[k])
    sum_1 += a[k] - l
    sum_arr_1[k - N + 1] = sum_1

for k in reversed(range(N, 2 * N)):
    l = heappushpop(a_list_2, -a[k])
    sum_2 += -a[k] - l
    sum_arr_2[k - N] = sum_2

max_score = float('-inf')
for s1, s2 in zip(sum_arr_1, sum_arr_2):
    score = s1 + s2
    if score > max_score:
        max_score = score

print(max_score)

Measured memory_bytes: 40196
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
int main()
{
	cin>>n;
	b=n/7;
	for(int i=0;i<=b;i++)
	{
		a=n;
		a-=i*7;
		if(a%4==0){cout<<"Yes";return 0;}
	}
	cout<<"No";
	return 0;
}

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);
        char[] s = sc.next().toCharArray();
        Arrays.sort(s);
        String sortedS = String.valueOf(s);

        char[] t = sc.next().toCharArray();
        Arrays.sort(t);
        String sortedT = String.valueOf(t);
        String sortedTDesc = new StringBuilder(sortedT).reverse().toString();

        if (sortedS.compareTo(sortedTDesc) < 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}

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

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

    int origin = std::floor(x / 1.08f);
    for (int i = 0; i < 3; i++)
    {
        int pay = std::floor((origin - 1 + i) * 1.08f);
        if (pay == x)
        {
            cout <<  origin+i-1 << endl;
            return 0;
        }
    }
    cout <<  ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a[101];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3,greater<int>() );
  cout<<(a[0]-a[1])+(a[1]-a[2])<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;

    FOR(i, 1, 10) {
        if(N%i) continue;
        else if(N/i < 10) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define ll long long int
#define MOD ((int)(1e9) + 7)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a, b,c;
  cin >> a >> b >> c;
  if((a%2) == 1 || (b%2) == 1 || (c%2) == 1){
    cout << "0\n"; return 0;
  }
  if(a == b && b == c) {
    cout << "-1\n";
    return 0;
  }
  ll cnt = 0;
  while((a%2 == 0) && (b%2 == 0) && (c%2 == 0)) {
    ll pa = a, pb = b, pc=c;
    a = (pb+pc)/2;
    c = (pa+pb)/2;
    b = (pa+pc)/2;
    cnt++;
  }
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
function main(input) {
    var line = input.split(/\r?\n/g);
    var arr = line[0].split(" ");
    const H = arr[0], N = arr[1];
    var A = line[1].split(" ").map(Number);
    var accum = 0
    A.forEach(Ai => {
        accum += Ai
    });
    console.log(1 < Math.ceil(H / accum) ? "No" : "Yes");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

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

  vector<int> X(N);
  int P = 0;
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
    P += X.at(i);
  }
  P /= N;

  vector<int> sum(2);

  for (int i = 0; i < N; i++) {
    sum.at(0) += X.at(i) * X.at(i) - 2 * X.at(i) * P + P * P;
    sum.at(1) += X.at(i) * X.at(i) - 2 * X.at(i) * (P + 1) + (P + 1) * (P + 1);
  }

  int min_val = min(sum.at(0), sum.at(1));

  cout << min_val << endl;
  return 0;
}

Measured memory_bytes: 256
// Created by sz
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;

const int N = 1e5 + 5;
string s;

bool in_acgt(char c){
    if(c=='A'||c == 'C'||c=='G'||c=='T')return true;
    return false;
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>s;
    int len = s.length();
    s = "#" + s;
    int mxlen = 0;
    int l = 1, r = 1;
    while (r<=len) {
        if(in_acgt(s[r])){
            mxlen = max(mxlen, r -l+1);
             r++;
        }else{
            l = ++r;
        }
    }
    cout<<mxlen<<endl;
    return 0;
}


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

int main () {
  string s;
  cin >> s;
  bool flag = false;
  int count = 0;
  int max_count = 0;
  int pos_a = -1;
  int pos_z = -1;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' && pos_a == -1) pos_a = i;
    if (s[i] == 'Z') pos_z = i;
  }
  cout <<  pos_z - pos_a + 1 << endl;
}


Measured memory_bytes: 640
import math


def max_heapify(A, n, i):
    largest = most_largest(A, n, i)
    x = i
    while largest is not x:
        tmp = A[x]
        A[x] = A[largest]
        A[largest] = tmp
        x = largest
        largest = most_largest(A, n, x)


def most_largest(A, n, i):
    l = left(i)
    r = right(i)
    largest = None
    if l <= n and A[i] < A[l]:
        largest = l
    else:
        largest = i
    if r <= n and A[largest] < A[r]:
        largest = r
    return largest


def left(i):
    return 2 * i


def right(i):
    return 2 * i + 1


def parent(i):
    return math.floor(i / 2)


def build_max_heap(A, n):
    for i in range(math.floor(n/2), 0, -1):
        max_heapify(A, n, i)


n = int(input())
heap = [None] + list(map(int, input().split()))

build_max_heap(heap, n)

print(' ', end='')
print(*heap[1:])



Measured memory_bytes: 63768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,h,w;
    cin >> n >> h >> w;
    ll tate=n-h+1,yoko=n-w+1;
    cout << tate*yoko << endl;
}

Measured memory_bytes: 3620
# https://atcoder.jp/contests/abc104/submissions/7167759

INF = float('inf')
D, G = map(int, input().split())
problems = [] * D
bonus = [] * D
ans = 0
for _ in range(D):
    p, c = map(int, input().split())
    problems.append(p)
    bonus.append(c)

ans = INF
for bit in range(1 << D):
    total_problem = 0
    total_score = 0
    # --------------
    # bit全探索
    # --------------
    for i in range(D):
        if bit & (1 << i):
            s = (i + 1) * 100
            total_score += s * problems[i] + bonus[i]
            total_problem += problems[i]

    for i in range(D - 1, -1, -1):
        if G <= total_score:
            break
        if bit & (1 << i):
            continue

        s = (i + 1) * 100
        required_score = G - total_score
        required_problem = (required_score + s - 1) // s
        total_score += min(required_problem, problems[i]) * s
        total_problem += min(required_problem, problems[i])

    if G <= total_score:
        ans = min(ans, total_problem)

print(ans)


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

int N;
string S[10005];

bool cmp(string a, string b) {
	for (int i = 0; i < min(a.length(), b.length()); i++) {
		
		if (a[i] == '?' && b[i] > 'a') return 1;
		if (a[i] > 'a' && b[i] == '?') return 0;
		if (a[i] < b[i]) return 1;
		if (a[i] > b[i]) return 0;
	}
	if (a.length() < b.length()) return 1;
	else return 0;
}

bool cmp1(string a, string b) {
	for (int i = 0; i < min(a.length(), b.length()); i++) {
		
		if (a[i] == '?' && b[i] < 'z') return 0;
		if (b[i] == '?' && a[i] < 'z') return 1;
		if (a[i] < b[i]) return 1;
		if (a[i] > b[i]) return 0;
	}
	if (a.length() < b.length()) return 1;
	else return 0;
}

string T;

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N + 1; i++) cin >> S[i];
	T = S[N];
	sort(S, S + N + 1, cmp1);
	int mini = 2000000000;
	for (int i = 0; i < N + 1; i++) if (T == S[i]) mini = min(mini, i + 1);
	sort(S, S + N + 1, cmp);
	int maxi = 0;
	for (int i = 0; i < N + 1; i++) if (T == S[i]) maxi = max(maxi, i + 1);
	for (int i = mini; i <= maxi; i++) {
		if (i != mini) printf(" ");
		printf("%d", i);
	}
	printf("\n");
}


Measured memory_bytes: 896
h, w = map(int, input().split())
c = [list(input()) for _ in range(h)]
cc = [[] for i in range(2 * h)]
for i in range(h):
    cc[2*i].append(c[i])
    print("".join(*cc[2*i]))
    cc[2*i + 1].append(c[i])
    print("".join(*cc[2*i + 1]))



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

const double PI = acos(-1);

int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double angleOfHour = 2 * PI / 12;
    double angleOfMinute = 2 * PI / 60;
    double diffAngle = abs((angleOfHour * H + angleOfMinute * M / 12) - angleOfMinute * M);  // 角度（ラジアン）

    // 余弦定理
    double cPower2 = pow(A, 2.0) + pow(B, 2.0) - 2 * A * B * cos(diffAngle);
    double ans = pow(cPower2, 0.5);

    cout << fixed << setprecision(20) << ans << endl;

    return 0;
}

Measured memory_bytes: 4312
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int, int>;
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
constexpr int INF = 1234567890;
constexpr int MOD = 1000000000 + 7;
// constexpr int MOD = 998244353;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int fact(int n) { return n > 1 ? n * fact(n - 1) % MOD : 1; }
int modinv(int a)
{
    int b = MOD, u = 1, v = 0;
    while (b)
    {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if (u < 0)
        u += MOD;
    return u;
}
constexpr int modpow(int a, int n)
{
    int rtn = 1;
    while (n > 0)
    {
        if (n & 1)
            rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    string s,t;
    cin>>s>>t;
    cout << t + s << endl;
}


Measured memory_bytes: 256
import heapq
INF=10**15
class weighted_graph():
    Vertex= 1
    AdjList=[dict() for i in range(Vertex)]
    Edge=[]
    directed=False
    def __init__(self,size,directed=False):
        self.directed=directed
        self.Vertex=size
        self.AdjList=[dict() for i in range(self.Vertex)]
    def add_edge(self,start,finish,weight):
        self.AdjList[start][finish]=weight
        self.Edge.append((start,finish,weight))
        if not(self.directed):
            self.AdjList[finish][start]=weight
    def Dijkstra(self, st):
        dist=[INF for i in range(N)]
        dist[st]=0
        q=[]
        heapq.heappush(q,(0,st))
        while (len(q)!=0):
            prc,src=heapq.heappop(q)
            if dist[src]<prc:
                continue
            for dest in self.AdjList[src]:
                cost=self.AdjList[src][dest]
                if dist[dest]>dist[src]+cost:
                    dist[dest]=dist[src]+cost
                    heapq.heappush(q,(dist[dest],dest))                
        return dist
    def Warshall_Floyd(self):
        d=[[INF for i in range(self.Vertex)] for i in range(self.Vertex)]
        for seq in self.Edge:
            d[seq[0]][seq[1]]=seq[2]
            if not(self.directed):
                d[seq[1]][seq[0]]=seq[2]
        for k in range(self.Vertex):
            for i in range(self.Vertex):
                for j in range(self.Vertex):
                    if d[i][j]>d[i][k]+d[k][j]:
                        d[i][j]=d[i][k]+d[k][j]
        return d
N,M,s,t=map(int,input().split())
s-=1;t-=1
G=weighted_graph(N,directed=False)
H=weighted_graph(N,directed=False)
for _ in range(M):
    u,v,a,b=map(int,input().split())
    G.add_edge(u-1,v-1,a)
    H.add_edge(u-1,v-1,b)
dist1=G.Dijkstra(s)
dist2=H.Dijkstra(t)
tmp=[INF-dist1[i]-dist2[i] for i in range(N)]
ans=[0 for i in range(N)]
ans[-1]=tmp[-1]
for i in range(N-1)[::-1]:
    ans[i]=max(ans[i+1],tmp[i])
for i in ans:
    print(i)


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n, k;
  std::cin >> n >> k;
  string s = readString();
  int diffCnt = 0, equalCnt = 0;
  REP(i, n - 1) {
    if (s[i] != s[i + 1])
      diffCnt++;
    else
      equalCnt++;
  }
  int ans = equalCnt;
  while (k != 0 && diffCnt != 0)
    if (diffCnt > 1)
      ans += 2, k--, diffCnt -= 2;
    else
      ans += 1, k--, diffCnt -= 1;

  print(ans);
}


Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>

using namespace std;

long long solve(long long  h, long long  w)
{
	long long ans = 1LL * h * w;
	for (int y = 1; y <= h - 1; ++y) {
		long long s1 = y * w;
		if (w >= 2) {
			long long s2 = (w / 2) * (h - y);
			long long s3 = w * (h - y) - s2;
			long long mn = min({ s1, s2, s3 });
			long long mx = max({ s1, s2, s3 });
			ans = min(ans, mx - mn);
		}
		if (h - y >= 2) {
			long long s2 = w * ((h - y) / 2);
			long long s3 = w * (h - y) - s2;
			long long mn = min({ s1, s2, s3 });
			long long mx = max({ s1, s2, s3 });
			ans = min(ans, mx - mn);
		}
	}
	return ans;
}

int main()
{
	int H, W;
	cin >> H >> W;
	cout << min(solve(H, W), solve(W, H)) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int list[2][10000];
int friend[500];
int friendoffriend[500];
int n,m,i,j,count;
while(1){
scanf("%d",&n);
scanf("%d",&m);
if(n==0&&m==0) return 0;
for(i=0;i<500;i++){
friend[i]=0;
friendoffriend[i]=0;
}
count=0;
for(i=0;i<m;i++){
scanf("%d %d",&list[0][i],&list[1][i]);
if(list[0][i]==1) friend[list[1][i]-1]=1;
if(list[1][i]==1) friend[list[0][i]-1]=1;
}
for(i=1;i<n;i++){
if(friend[i]>0){
for(j=0;j<m;j++){
if(list[0][j]==i+1) friendoffriend[list[1][j]-1]=1;
if(list[1][j]==i+1) friendoffriend[list[0][j]-1]=1;
}
}
}
for(i=1;i<n;i++) if(friend[i]>0||friendoffriend[i]>0) {
count++;
}
printf("%d\n",count);
}
}

Measured memory_bytes: 680
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: u64,
    }
    println!("{}", N*800 - N/15*200);
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<stack>
#include<cstdlib>

using namespace std;

int main ()
{
	string word;
	stack<int> S;
	while(cin>>word){
		if(word=="+"){
			int sum=0;
			sum+=S.top();
			S.pop();
			sum+=S.top();
			S.pop();
			S.push(sum);
		}
		else if(word=="-"){
			int sub=0;
			sub-=S.top();
			S.pop();
			sub+=S.top();
			S.pop();
			S.push(sub);

		}
		else if (word=="*"){
			int product=1;
			product*=S.top();
			S.pop();
			product*=S.top();
			S.pop();
			S.push(product);
		}
		else{
			int num=atoi(word.c_str());
			S.push(num);
		}
	}

	cout<<S.top()<<endl;
	return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, L; cin >> N >> L;
    deque<pair<double, int>> X;
    cout << fixed << setprecision(9);
    double TV = 0;
    for (int i = 0; i < N; i++) {
        int T, V; cin >> T >> V;
        if (i != 0) {
            int v = V;
            while (X.front().second <= v) {
                TV -= X.front().first * X.front().second;
                v -= X.front().second;
                X.pop_front();
            }
            TV -= X.front().first * v;
            X.front().second -= v;
        }
        X.emplace_back(T, V);
        TV += (Int)T * V;
        cout << TV / L << '\n';
        while (X.size()>=2 && X[X.size()-2].first > X.back().first) {
            double t1 = X[X.size()-2].first, t2 = X.back().first;
            int v1 = X[X.size()-2].second, v2 = X.back().second;
            X.pop_back();
            X.back() = make_pair((t1*v1+t2*v2)/(v1+v2), v1+v2);
        }
    }
    return 0;
}


Measured memory_bytes: 18192
from collections import deque

def main():
    k = int(input())
    q = deque(range(1, 10))
    for _ in range(k):
        x = q.popleft()
        y = x * 10 + x % 10
        if x % 10 > 0:
            q.append(y - 1)
        q.append(y)
        if x % 10 < 9:
            q.append(y + 1)
    print(x)

if __name__ == '__main__':
    main()

Measured memory_bytes: 11864
main=map read.words<$>getLine>>=print.(\x->if x!!0>=x!!1 then 0 else(f(x!!0)(x!!1)(x!!0)((x!!0)+1)2019)).(\x->(if x!!1-x!!0>2019 then[0,0] else[mod y 2019|y<-x]))
 where f l r i j a = if j>r then a else(f l r (i+(if j==r then 1 else 0))(if j==r then (i+2) else (j+1))(min a(mod(i*j)2019)))

Measured memory_bytes: 278524
#include<bits/stdc++.h>			//edit by thidailoc
using namespace std;			//team three wolves
typedef long long ll;
ll mark[1000000],ans;
vector<ll>dske[100001];
class Info{
	public: ll prevv,v;
};
ll BFS(ll start){
	Info now,x;
	queue<Info>qu;
	now.prevv=now.v=start;
	qu.push(now);
	ll flag=0,step=0;
	while(qu.size()){
		step++;
		now=qu.front();
		qu.pop();
		if(mark[now.v]){continue;}	//chu trinh la 2
		mark[now.v]=ans;
		if(dske[now.v].empty())continue;
		for(ll i=0;i<dske[now.v].size();i++){
			if(!mark[dske[now.v][i]]){
				x.prevv=now.v;
				x.v=dske[now.v][i];
				qu.push(x);
			}
			else if(step!=1 and dske[now.v][i]!=now.prevv)flag=2;
		}
	}
	if(!flag)flag=(step>1?1:0);		// khung la 1
	return flag;
}
ll arr2[1000000];
int main(){
	//freopen("locin.txt","r",stdin);
	// chu trinh la 1
	//khung la 2
	// 1 dinh la n*2+1
	
	ll n,m,a,b;
	cin>>n;
	for(ll i=0;i<n;i++)scanf("%lld",&arr2[i]);
	
	sort(arr2,arr2+n);
	
//	for(ll i=n-1;i>=0;i--){
//		if(arr2[i]*2<arr2[n-1])return cout<<n-1-i,0;
//	}	
//	cout<<n;
	ll sum=0,pos=0;
	for(ll i=0;i<n;i++){
		if(sum*2<arr2[i])pos=i;
		sum+=arr2[i];
	}
	
	cout<<n-pos;
}

Measured memory_bytes: 5120
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    string s,t; cin>>s>>t;
    vector<char> S,T;
    for(auto ch : s) S.push_back(ch);
    for(auto ch : t) T.push_back(ch);
    sort(al(S)); sort(al(T));
    reverse(al(T));
    rep(i,s.size()) s[i]=S[i];
    rep(i,t.size()) t[i]=T[i];
    cout<<(s<t ? "Yes" : "No");
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int max = 0;
		int min = 124;
		for(int i = 0; i < 5; i++){
			int antena = sc.nextInt();
			if(antena > max){
				max = antena;
			}
			if(antena < min){
				min = antena;
			}
		}
		int k = sc.nextInt();
		if(max - min <= k){
			System.out.println("Yay!");
		}else{
			System.out.println(":(");
		}
	}
}

Measured memory_bytes: 22740
program ABC160C
    implicit none
    integer(8)::K,N,i,ans
    integer(8),allocatable,dimension(:)::A,diff,dsum
    read*,K,N
    allocate(A(N))
    allocate(diff(N))
    allocate(dsum(N))
    read*,A
    ans=99999999

    do i=1,N
        if(i==N)then
            diff(i)=A(1)+K-A(N)
        else
            diff(i)=A(i+1)-A(i)
        end if
    end do

    ans=sum(diff)-maxval(diff)

    print'(i0)',ans
end program ABC160C

Measured memory_bytes: 3968
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
ans=0
for i in range(n):
    u=input().rstrip().split(" ")
    a=float(u[0])
    s=u[1]
    if s=="JPY":
        ans+=a
    else:
        ans+=a*380000
print(ans)
  
        

Measured memory_bytes: 3436
N = int(input())
H = list(map(int,input().split()))
Sa=[0]*(len(H)-1)
for i in range(len(H)-1):
    if (H[i+1]-H[i]) <=0:
        Sa[i] = 1 
    else: Sa[i] = 0
mx = 0
itr = 0
for j in range(len(H)-1):
    if Sa[j]==1:
        itr += 1
        if itr>mx: mx = itr
    else: itr = 0
print(mx)

Measured memory_bytes: 14224
//パターン1：OK(小数点以下切り捨て)
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int len = sc.nextInt();

		BigDecimal wSide = new BigDecimal((double)len/3);
		BigDecimal tSide = new BigDecimal((double)len/3);
		BigDecimal hSide = new BigDecimal((double)len/3);

//		System.out.println(wSide);
//		System.out.println(tSide);
//		System.out.println(hSide);

		BigDecimal result = wSide.multiply(tSide).multiply(hSide);

		System.out.print(result);
		sc.close();
	}
}


//パターン2：OK(小数点以下6桁以降に桁落ちアリ)
//package ojt.AtCoder;
//import java.util.Scanner;
//public class TestC_159 {
//	public static void main(String[] args) {
//		Scanner sc = new Scanner(System.in);
//		int len = sc.nextInt();
//
//		double wSide = (double)len/3;
//		double tSide = (double)len/3;
//		double hSide = (double)len/3;
//
//		System.out.println(wSide);
//		System.out.println(tSide);
//		System.out.println(hSide);
//
//		double result = wSide*tSide*hSide;
//
//		System.out.print(result);
//		sc.close();
//	}
//}


//パターン3：OK(小数点以下6桁以降に桁落ちアリ)
//package ojt.AtCoder;
//import java.util.Scanner;
//public class TestC_159 {
//	public static void main(String[] args) {
//		Scanner sc = new Scanner(System.in);
//		double len = sc.nextDouble();
//
//		System.out.println(Math.pow(len/3 , 3));
//
//		sc.close();
//	}
//}


Measured memory_bytes: 22868
#include <iostream>

using namespace std;

int main(){
    int N;
    cin>>N;
    long long int L[N+1];
    L[0]=2;
    L[1]=1;
    int i=2;
    while(i<=N){
        L[i]=L[i-1]+L[i-2];
        i++;
    }
    cout<<L[N]<<"\n";
    return 0;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;

int main() {
	int n, d;
	cin >> n >> d;
	if (n % (2 * d + 1) == 0) cout << n / (2 * d + 1) << endl;
	else cout << n / (2 * d + 1) +1<< endl;
	return 0;
}

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

/**
 * Created by shoya on 2017/04/11.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> ar = new ArrayList<>();
        for (int i = 0; i < n; i++)
            ar.add(sc.nextInt());
        //System.out.println(ar);
        insertionSort(ar);
    }

    static ArrayList<Integer> insertionSort(ArrayList<Integer> ar){
        for (int i = 0; i < ar.size(); i++){
            for (int j = 0; j < i; j++){
                if (ar.get(j) > ar.get(i)){
                    for (int k = i; k > j; k--){
                        int tmp = ar.get(k - 1);
                        ar.set(k - 1, ar.get(k));
                        ar.set(k, tmp);
                    }
                }
            }
            for (int n = 0; n < ar.size() - 1; n++)
                System.out.printf("%d ", ar.get(n));
            System.out.println(ar.get(ar.size() - 1));
        }
        return ar;
    }

}

Measured memory_bytes: 42068
Uses math;
var
	n,i,x,y:Longint;
	a,b,c,d:int64;
begin
	read(n);
	a:=1;
	b:=1;
	for i:=1 to n do begin
		read(x,y);
        c:=Max((a-1)div x,(b-1)div y)+1;
		a:=c*x;
		b:=c*y;
	end;
	writeln(a+b);
end.


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int a = 0, w = 0, t = 0, r = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "AC") a++;
    else if (s == "WA") w++;
    else if (s == "TLE") t++;
    else r++;
  }
  
  cout << "AC x " << a << '\n';
  cout << "WA x " << w << '\n';
  cout << "TLE x " << t << '\n';
  cout << "RE x " << r << '\n';
}

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

int main()
{
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  for(auto& i : A) cin >> i;
  
  int count_less = 0, count_grat = 0;
  for(auto i : A)
  {
    if(i > X) ++count_grat;
    else ++count_less;
  }
  
  cout << min(count_less, count_grat) << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
HH = [1]*N
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] > H[B-1]:
        HH[B-1] = 0
    elif H[A-1] < H[B-1]:
        HH[A-1] = 0
    else:
        HH[A-1] = 0
        HH[B-1] = 0
print(sum(HH))

Measured memory_bytes: 84964
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

bool isPalindrome(int x){
  string s = to_string(x);
  int n=s.length();
  bool ret=true;
  repeat(i,(n+1)/2){
    ret &= s[i]==s[n-1-i];
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int D,N;cin>>D>>N;
  int ans = N==100? 101:N;
  repeat(i,D)ans *= 100;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define MAX 200000
#define MIN -999999999

int maximumProfit(int* profit, int n);

int main(){
	int n; scanf("%d", &n);
	
	int profit[MAX];
	for(int i = 0; i < n; i++) scanf("%d", &profit[i]);
	
	int max = maximumProfit(profit, n);
	
	printf("%d\n", max);
	
	return 0;
}

int maximumProfit(int* profit, int n){
	int max = MIN, min = profit[0];
	for(int i = 1; i < n; i++){
		max = max > profit[i] - min ? max : profit[i] - min;
		min = min < profit[i] ? min : profit[i];
	}
	return max;
}

Measured memory_bytes: 1804
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m,q = li()
train = []
query = []

field = [[0 for _ in range(n+1)] for _ in range(n+1)]

for _ in range(m):
    train.append(tuple(li()))
    
for _ in range(q):
    query.append(tuple(li()))
    
for ts, tt in train:
    field[ts][tt] += 1
    
for r in range(n+1):
    for c in range(n):
        field[r][c+1] += field[r][c]
        
for c in range(n+1):
    for r in range(n):
        field[r+1][c] += field[r][c]
        
for qs,qt in query:
    print(field[qt][qt] - field[qt][qs-1] - field[qs-1][qt] + field[qs-1][qs-1])
    

Measured memory_bytes: 44504
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] sn=sc.nextLine().split(" ");
int mae=Integer.parseInt(sn[0]);
int naka=Integer.parseInt(sn[1]);
int usi=Integer.parseInt(sn[2]);


if(mae+naka+usi>21){
System.out.println("bust");

}else{
System.out.println("win");

}



	}
}

Measured memory_bytes: 21716
N,K=map(int,input().split())
A=[0]*N
A=list(map(int,input().split()))
Anum={}
for i in range(N):
    if A[i] in Anum:
        Anum[A[i]]+=1
    else:
        Anum[A[i]]=1
if len(Anum)<=K:
    print("0")
else:
    ans=0
    i=0
    for k, v in sorted(Anum.items(), key=lambda x: x[1]):
        if i==len(Anum)-K:
            break
        ans+=v
        i+=1
    print(ans)

Measured memory_bytes: 38944
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll i = 1; i <= k; ++i) {
        r *= n--;
        r /= i;
    }
    return r;
}

ll f(unsigned ll n){
    if(n < 2)return 1;
    else return n * f(n - 2);
}

int main()
{
    ll h,w,d,q;
    cin >> h >> w >> d;
    map<ll, pair<ll,ll>> g;
    vector<ll> cost(w*h + 1);
    rep1(i, h)rep1(j, w){
        ll a;
        cin >> a;
        g.insert(make_pair(a, make_pair(i, j)));
    }
    rep1(i, h*w){
        if(i <= d)cost[i] = 0;
        else cost[i] = cost[i - d] + abs(g[i].first - g[i - d].first) + abs(g[i].second - g[i - d].second);
    }
    cin >> q;
    vector<ll> l(q),r(q);
    rep0(i, q)cin >> l[i] >> r[i];
    rep0(i, q)pf(abs(cost[r[i]] - cost[l[i]]))
    return 0;
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    string a,b;cin>>a>>b;
    int M = stoi(a+b);
    int P = (int)sqrt((double)M);
    cout<<(P*P==M?"Yes":"No")<<endl;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,m;
	cin >> n >> m;
	vector<long long> d(n);
	for(int i=0;i<n;i++) cin >> d[i];
	
	vector<pair<int,int>> ed(m);
	vector<vector<int>> ad(n);
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		ed[i]={a,b};
		ad[a].push_back(b);
		ad[b].push_back(a);
	}
	
	vector<int> ind(n);
	for(int i=0;i<n;i++) ind[i]=i;
	sort(ind.begin(),ind.end(),
		[&](int i0,int i1){
			return d[i0]<d[i1];
		}
	);
	
	for(int i=0;i<n;i++){
		bool bo2=false;
		for(int ch:ad[i]){
			if(d[ch]<=d[i]){
				bo2=true;
			}
		}
		if(!bo2){
			cout << -1 << "\n";
			return 0;
		}
	}
	
	map<pair<int,int>,long long> mp;
	set<pair<int,int>> st;
	
	vector<vector<int>> ad2(n);
	for(int i=0;i<n;i++){
		int cur=ind[i];
		
		int par=-1;
		for(int ch:ad[cur]){
			if(par==-1) par=ch;
			else{
				if(d[par]>d[ch]) par=ch;
			}
		}
		ad2[cur].push_back(par);
		ad2[par].push_back(cur);
		
		for(int ch:ad[cur]){
			if(ch==par) continue;
			if(st.find({ch,cur})!=st.end()) continue;
			mp[{cur,ch}]=1000000000;
			mp[{ch,cur}]=1000000000;
		}
		mp[{cur,par}]=d[cur];
		mp[{par,cur}]=d[cur];
		st.insert({par,cur});
		st.insert({cur,par});
	}
	
	vector<int> c(n);
	function<void(int,int)> dfs=[&](int cur,int par){
		for(int ch:ad2[cur]){
			if(ch==par) continue;
			if(c[ch]==0){
				c[ch]=3-c[cur];
				dfs(ch,cur);
			}
		}
	};
	for(int i=0;i<n;i++){
		if(c[i]==0){
			c[i]=1;
			dfs(i,-1);
		}
	}
	for(int i=0;i<n;i++){
		if(c[i]==1) cout << "W";
		else cout << "B";
	}
	cout << "\n";
	for(int i=0;i<m;i++){
		cout << mp[ed[i]] << "\n";
	}
	return 0;
}

Measured memory_bytes: 51584
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define maxn 100005
#define maxm 100005
#define eps 1e-6
typedef long long ll;
using namespace std; 
const ll mod = 1e9 + 7;
inline int read(){
	int x = 0, f = 1;char ch = getchar();
	while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch -'0';ch = getchar();}
	return x * f;
}

int n ,m;
int prime[1000005],f[1000005],tot;
bool vis[1000005];
void pre(){
	for(int i = 2;i <=1000000;i++){
		if(!vis[i]) prime[++tot]=i,f[i]=i;
		for(int j = 1;j<=tot&&prime[j] * i <=1000000;j++){
			vis[prime[j] * i]=1;
			f[prime[j] * i]=prime[j];
		}
	}
}
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int a[1000005];
int cnt[1000005];
int main(){
	int i, j,u,v;
	pre();
	n = read();
	for(i = 1;i <= n;i++) a[i] = read();
	int G = a[1];
	for(i = 2;i <= n;i++)
		G=gcd(G,a[i]);
	if(G!=1) return puts("not coprime"),0;
	bool flag= 0;
	for(i = 1;i <= n;i++){
		while(a[i] != 1){
			if(cnt[f[a[i]]]) {flag = 1;break;}
			int t = f[a[i]];
			while(a[i] %t==0)a[i]/=t;
			cnt[t]++;
		}
		if(flag) break; 
	}
	if(!flag) puts("pairwise coprime");
	else puts("setwise coprime");
}
//

Measured memory_bytes: 12996
import fractions
n,k=map(int,input().split())
a=list(map(int,input().split()))
if max(a)<k:
    print("IMPOSSIBLE")
    exit()
t=a[0]
if n!=1:
    for i in range(1,n):
        t=fractions.gcd(t,a[i])

if k%t==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")



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

int main() {
  int N,K,i,d;
  cin >> N >> K;
  int x[N];
  d = 0;
  for(i=0;i<N;i++){
    cin >> x[i];
    if(x[i]<=K/2) d += 2*x[i];
    else d += 2*K - 2*x[i];
  }
  cout << d << endl;    
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int N=0;
	int temp=0;
	int sum=0;
	scanf("%d",&N);

	int a[N];
	for(int i=0; i<N; i++){
		scanf("%d",&a[i]);
	}

	for(int j=0;j<N-1 ;j++){
		for(int k=0; k<N-1 ; k++){
			if(a[k]<a[k+1]){
				temp = a[k];
				a[k] = a[k+1];
				a[k+1] = temp;
			}else{

			}
		}
	}

	for(int l=0; l<N-1; l++){
		sum += a[l] - a[l+1];
	}
	
	printf("%d",sum);

	return 0;

}

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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(void){
  int n;
  cin>>n;
  cout<<48-n<<endl;  
}

Measured memory_bytes: 256
N,M = map(int, input().split())
G = [[] for j in range(N)]
for i in range(M):
    a,b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
visited = [False]*N
visited[0] = True
def DFS(v,visited):
    #もし全てTrueなら1を返す
    if all(visited):
        return 1
    ans = 0
    for i in G[v]:
        if visited[i]:
            continue
        visited[i] = True
        ans += DFS(i,visited)
        visited[i] = False
    return ans
 
print(DFS(0,visited))

Measured memory_bytes: 9196
n,m,x=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(n)]
sm=-1

for i in range(2**n):#全探索ループ
  bin(i)
  d=[0 for _ in range(m+1)]
  
  for j in range(n):#それぞれの本
    if ((i >> j) & 1):#フラグ立ってると足してく
      for k in range(m+1):
        d[k]+=c[j][k]
        
  for j in range(m):
    if d[j+1] <x:
      break
  else:
    if sm>d[0] or sm==-1:
      sm=d[0]
      
print(sm)
    
  
      
    
    
  
  



Measured memory_bytes: 9188
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m1 = sc.nextInt();
		int d1 = sc.nextInt();
		int m2 = sc.nextInt();
		int d2 = sc.nextInt();
		
		int ans = m2 - m1;
		System.out.println(ans);
		
		sc.close();
		
	}
}

Measured memory_bytes: 21844