akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        System.out.println("2018" + reader.next().substring(4));
    }

    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



Measured memory_bytes: 23124
#include<stdio.h>

int main() {
	int A, B, C, D;
	scanf("%d%d%d%d", &A, &B, &C, &D);
	int l1 = (A < B) ? A:B, l2 = (C < D) ? C:D, sum = l1 + l2;
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
from collections import Counter

N = int(input())
s = [list(input()) for i in range(0,N,1)]
for i in range(0,N,1):
    s[i].sort()
S = ["".join(s[i]) for i in range(0,N,1)]

cnt = Counter(S)
ans =0
for i in set(S):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)

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

const int N = 100100;
int n, a[N], dp[N];

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  dp[2] = abs(a[2] - a[1]);
  for (int i = 3; i <= n; i++)
    dp[i] = min(dp[i - 2] + abs(a[i - 2] - a[i]), dp[i - 1] + abs(a[i - 1] - a[i]));
  cout << dp[n];
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
int main (void){
  int a[256];
  int i=0;
  int m=0;
  int j=0;
  int mozi=0; //文字数                                                          
  char str[256];
  scanf("%[^\n]",str);
  while(1){
    if(str[i]==' '||str[i]=='\n'||str[i]=='\0'){
      a[mozi]=0;
      while(j!=0){
        a[mozi]+=(str[i-j]-'0')*pow(10,j-1);
        j--;
      }
      mozi++;
      if(m==-1){
        a[mozi-1]=a[mozi-1]*-1;
        m=0;
      }
      j=-1;
      if(str[i]=='\n'||str[i]=='\0')break;
    }
    if(str[i]=='-'){
     m=-1;
     j--;
   }
    i++;
    j++;
  }
  if(a[0]==a[1]){
   printf("%d\n",a[2]);
  }else{
    if(a[0]==a[2]){
      printf("%d\n",a[1]);
    }else{
      printf("%d\n",a[0]);
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cstring>
#include <stack>
#include <numeric>
#include<climits>
#include<cmath>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
#include<unordered_map>
#define vi vector<float>
#define vl vector<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define loop(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define mp make_pair
#define ll long long
const int mod = 1e9 + 7;
using namespace std;

#define xx first
#define yy second


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


	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << endl;
	return 0;
}










Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	m := make(map[byte]int, 0)
	for i := 0; i < len(s); i++ {
		m[s[i]]++
	}
	ok := true
	if len(m) == 2 {
		for _, v := range m {
			if v != 2 {
				ok = false
				break
			}
		}
	} else {
		ok = false
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
n = int(input())
L = list(map(int, input().split()))

cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if L[i] != L[j] != L[k] != L[i] and L[i]+L[j]+L[k] > 2*max(L[i], L[j], L[k]):
                cnt += 1

print(cnt)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h1,m1,h2,m2,k,ans,tot;
    cin>>h1>>m1>>h2>>m2>>k;
    if(h1==h2){
        tot=m2-m1;
    }else{
        tot=60-m1;
        h1++;
        tot+=m2;
        tot+=(h2-h1)*60;
    }
    ans=tot-k;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
int a[1000006];
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    int tmp = 0;
    int head = 1;
    int lst = 0;
    long long rs = 0;
    for (int i = 1; i <= n; ++i) {
        while ((tmp ^ a[i]) != tmp + a[i]) {
            tmp ^= a[head];
            head++;
        }
        lst++;
        tmp ^= a[i];
        rs += (long long)(lst - head + 1);
    }
    cout <<rs;
    return 0;
}

Measured memory_bytes: 1024
#102_D
N = int(input())
A = [int(i) for i in input().split()]
s = 0
AS = []
for i in range(N):
    s += A[i]
    AS.append(s)
#尺取り法
Ans = AS[N-1]+1
L = 0
R = 2
for Mid in range(1, N-2):
    Sum_L = AS[Mid]
    Sum_R = AS[N-1]-Sum_L
    while abs((Sum_L - AS[L]) - AS[L]) > abs((Sum_L - AS[L+1]) - AS[L+1]):
        L += 1

    while abs((AS[N-1]-AS[R]) - (AS[R]-Sum_L)) > abs((AS[N-1]-AS[R+1]) - (AS[R+1]-Sum_L)):
        R += 1
    P = AS[L]
    Q = Sum_L-AS[L]
    S = AS[R]-Sum_L
    T = AS[N-1]-AS[R]
    #print(Mid,L,R,abs(max(P,Q,S,T)-min(P,Q,S,T)))
    Ans = min(Ans, abs(max(P, Q, S, T)-min(P, Q, S, T)))
print(Ans)


Measured memory_bytes: 25676
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n
 
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
 
N,M=map(int,input().split())
A = [[int(x)-1 for x in input().split()] for y in range(M)]

ans=[]
score=N*(N-1)//2
UF=UnionFind(N)

for i in range(M-1,-1,-1):
    a,b=A[i]
    ans.append(score)
    pa=UF.find(a)
    pb=UF.find(b)
    if not (UF.find(pa) == UF.find(pb)):
        score-= (UF.size[pa]*UF.size[pb])
    UF.union(a,b)

ans=ans[::-1]
for a in ans:
    print(a)

Measured memory_bytes: 28692
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>

#define int long long

//#define ENABLE_TRACE
#ifdef ENABLE_TRACE
#define TRACE cout << __func__ << "()" << endl;
#define TRACE1(a) cout << __func__ << "(" << a << ")" << endl;
#define TRACE2(a, b) cout << __func__ << "(" << a << ", " << b << ")" << endl;
#else
#define TRACE
#define TRACE1(a)
#define TRACE2(a, b)
#endif  // #ifdef ENABLE_TRACE

using namespace std;

// Greatest Common Divisor
int Gcd(int a, int b) {
  TRACE2(a, b);
  if (a % b == 0)
    return b;
  return Gcd(b, a % b);
}

void Main() {
  int s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
}

int32_t main() {
  Main();
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>

using namespace std;

int main() {
    string sin, sout;

    cin >> sin;

    for (int i=0; i<sin.size(); i++) {
        if(sin[i] == '0') {
            sout.push_back('0');
        } else if(sin[i] == '1') {
            sout.push_back('1');
        } else if(!sout.empty()){
            sout.pop_back();
        }
    }

    cout << sout;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main(){
int a=1,b=1,c;
	while(a <= 9){
		while(b <= 9){
   	 	c = a*b;
    	cout<<a<<"x"<<b<<"="<<c<<endl;	
    	b++;	
		}
	b = 1;
	a++;      
    }
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,m;
    cin>>n>>m;
    map<int,vector<int>>mp;
    vector<int>p(m),y(m);
    rep(i,m){
        cin>>p[i]>>y[i];
        mp[p[i]].push_back(y[i]);
    }
    for(auto&p:mp){
        sort(p.second.begin(),p.second.end());
    }
    rep(i,m){
        printf("%06d%06d\n",p[i],
        lower_bound(mp[p[i]].begin(),mp[p[i]].end(),y[i])
        -mp[p[i]].begin()+1);
    }
    return 0;
}


Measured memory_bytes: 13184
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            string seisuu = Console.ReadLine();
            string[] values = seisuu.Split(' ');
            var a = int.Parse(values[0]);
            var b = int.Parse(values[1]);

            Console.WriteLine(a * b);
        }
    }
}

Measured memory_bytes: 27532
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long long LL;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	string S;
	cin >> S;
	ll N = S.size();
	if (S.back() == '1') {
		cout << "-1\n";
		return 0;
	}
	if(S[0] == '0') {
		cout << "-1\n";
		return 0;
	}
	for (ll n = 1; n < N; n++) {
		if (S[n - 1] != S[N - n - 1]) {
			cout << "-1\n";
			return 0;
		}
	}
	VLL V;
	for (ll n = 2; n < N; n++) {
		if (S[n - 1] == '1')V.push_back(n);
	}
	V.push_back(N);
	ll prev = 1;
	for (ll n : V) {
		while (prev < n) {
			cout << prev << " " << n << "\n";
			prev++;
		}
	}
	return 0;
}


Measured memory_bytes: 2372
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

// End of template.


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

    constexpr int64 mod = 1000000007;
    int64 n;
    int64 a[300300];
    cin >> n;
    rep(i, n) cin >> a[i];
    
    int64 ones[64];
    memset(ones, 0, sizeof ones);

    rep(i, n) {
        rep(bit, 64) {
            ones[bit] += (a[i] >> bit) & 1;
        }
    }

    int64 ans = 0;
    for(int64 bit = 0; bit < 64; ++bit) {
        ans += ((ones[bit] * (n - ones[bit])) % mod) * ((1LL << bit) % mod);
        ans %= mod;
    }

    print(ans);
    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
//#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
//#include <stack>
//#include <limits>
#include <sstream>
//#include <functional>
using namespace std;

#define len(array)  (sizeof (array) / sizeof *(array))
#define rep(i, s, e) for(int i = s;i < e;i++)
#define rrep(i, e, s) for(int i = e;s <= i;i--)
#define vrange(v) v.begin(), v.end()
#define vrrange(v) v.rbegin(), v.rend()
#define vsort(v) sort(vrange(v))
#define vrsort(v) sort(vrrange(v))
#define arange(a) a, a + len(a)
#define asort(a) sort(arange(a))
#define arsort(a, t) sort(arange(a), greater<t>())
#define afill(a, v) fill(arange(a), v)
#define afill2(a, v, t) fill((t *)a, (t *)(a + len(a)), v)
#define fmax(a, b) (a < b? b : a)
#define fmin(a, b) (a > b? b : a)
#define fabs(a) (a < 0? -a : a)
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-10;
//const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
//const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
//const int weight[] = {0,1,10,100,1000,10000,100000,1000000,10000000};
//priority_queue< int, vector<int>, greater<int> > q;
int p, q, a, n, ans;


int gcd(int a, int b) {
  if( a < b ) swap( a, b );
  return b != 0 ? gcd(b, a % b) : a;
}

int calc(int limit, int pos, int nume, int deno, int prev){
  // printf("limit = %d, pos = %d, nume = %d,  deno = %d\n", limit, pos, nume, deno);
	int res = 0;
	if(a < deno || pos == limit + 1) return 0;
	if(p*deno == q*nume) return 1;
	rep(i, prev, a+1){
	  //(nume / deno) + (1/i) = (i*nume + deno) / (deno * i)
	  int den = deno * i;
	  int num = i * nume + deno;
	  if(a < den) break;
	  if(p*den-q*num < 0) continue;
	  res += calc(limit, pos + 1, num, den, i);
	}
	return res;
}


void doIt(){
	int gcd0;
	while(true){
		cin >> p >> q >> a >> n;
		if(p + q + a + n == 0) break;
		gcd0 = gcd(p, q);
		p /= gcd0;
		q /= gcd0;
		ans = calc(n, 0, 0, 1, 1);

		cout << ans << endl;
	}
}

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

Measured memory_bytes: 1160
#include<stdio.h>

int main(void){
	int i,j,n,m,num;
	scanf("%d%d",&n,&m);
	int A[n][m],B[m],C[n];
	num = m;
	//input A	
	for(i=0;i<n;i++){
		C[i] = 0;
		for(j=0;j<m;j++){
			scanf("%d",&A[i][j]);
		}
	}
	// input B
	for(i=0;i<m;i++){
		scanf("%d",&B[i]);
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			C[i] += A[i][j]*B[j];
		}
		printf("%d\n",C[i]);
	}

	return 0;
}

Measured memory_bytes: 640
h,w =  map(int,input().split())
mat = [input() for i in range(h)]
n = 0
max = h
while n<max:
    if mat[n]=="."*w:
        mat.pop(n)
        n -= 1
        max -= 1
    n += 1
flag = [True for i in range(w)]
for i in mat:
    for j in range(w):
        if i[j]=="#":
            flag[j] = False
ans = []
for i in mat:
    temp = ""
    for j in range(w):
        if not flag[j]:
            temp += i[j]
    ans.append(temp)
for i in ans:
    print(i)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e5+1;
const int mod = 1e9+7;
vector<int> Y[upperlimit];
vector<int> X[upperlimit];
int size[upperlimit];
int parent[upperlimit];
int findparent(int node){
	if(parent[node]==node) return node;
	else return(findparent(parent[node]));
}
void dsu(int a,int b){
	int k1=findparent(a);int k2=findparent(b);
	if(k1==k2) return;
	if(size[k1]<size[k2]) swap(k1,k2);
	parent[k2]=k1;size[k1]+=size[k2];
}
vi temp[upperlimit];
int main() {
	int n,x,y;
	sd(n);
	for(int i = 1; i <= n; i++){
		sd(x);sd(y);
		Y[y].pb(x);X[x].pb(y);
	}
	for(int i = 1; i < upperlimit; i++){
		size[i]=1;parent[i]=i;
	}
	for(int i = 1; i < upperlimit; i++){
		for(int j = 0; j < X[i].size(); j++){
			if(j==0) continue;
			else dsu(X[i][0],X[i][j]);
		}
	}
	for(int i = 1; i < upperlimit; i++){
		int k = findparent(i);
		for(int j = 0; j < Y[i].size(); j++){
			temp[k].pb(Y[i][j]);
		}
	}
	ll ans=-n,calc;
	for(int i = 1; i < upperlimit; i++){
		if(i!=parent[i]) continue;
		calc=1;
		if(! temp[i].size()) continue;
		sort(temp[i].begin(),temp[i].end());
		for(int j = 1; j < temp[i].size(); j++){
			if(temp[i][j]!=temp[i][j-1]) calc++;
		}
		calc*=size[i];
		ans+=calc;
	}
	plld(ans);
	return 0;
}

Measured memory_bytes: 11904
#include<iostream>
#include<algorithm>
using namespace std;
int t[6]={60,80,100,120,140,160};
int u[6]={2,5,10,15,20,25};
int v[7]={600,800,1000,1200,1400,1600,0};
int n;
int x,y,h,w;

int check_t(int x){
  for(int i=0;i<6;i++){
    if(x<=t[i])return i;
  }
  return 6;
}
int check_u(int x){
  for(int i=0;i<6;i++){
    if(x<=u[i])return i;
  }
  return 6;
}




int main(){
  int sum;
  while(cin>>n&&n){
    sum=0;
    for(int i=0;i<n;i++){
      cin>>x>>y>>h>>w;
      sum+=v[max(check_t(x+y+h),check_u(w))];
    }
    cout<<sum<<endl;
  }
  return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  int sum = 0;
  rep(i,m){
    int a;
    cin >> a;
    sum = sum + a;
  }
  if(n-sum>=0)
    cout << n-sum << endl;
  if(n-sum<0)
    cout << -1 << endl;
  
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
    using namespace std;
    int main(){
    string s;
    cin>>s;
    int c;
    if(s[0]=='1')c++;
    if(s[1]=='1')c++;
    if(s[2]=='1')c++;
    cout<<c<<endl;
    return 0;
    }

Measured memory_bytes: 256
object Main extends App {
var get1 = readLine.split(" ")
var loop = get1(1).toInt
var word = readLine.split("")
var count : Array[Int] = new Array(word.size)
	for(i <- 1 to word.size - 1) {
    	count(i) = 
     		if(word(i-1)=="A" && word(i)=="C") count(i - 1) + 1 
    		else count(i - 1)
    }
  	for(i <- 0 to loop - 1) {
      var position = readLine.split(" ")
    	println(count(position(1).toInt) - count(position(0).toInt))
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s;cin>>s;
    s[3]='8';
    cout<<s<<endl;
}


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

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;
int main(){
	vector<int>v(3);
	REP(i,3)cin>>v[i];
	sort(ALL(v));
	if(v[0]!=v[1]){
		cout<<v[0]<<endl;
	}else{
		cout<<v[2]<<endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>

using namespace std;

int main()
{
	int a[26] = {0};
	char x;
	bool flag = false;

	while(cin >> x) {
		if(isupper(x)) x = tolower(x);
		if ('a' <= x && x <= 'z') {
			a[x - 'a']++; 
		}
	}

	for (int i = 0; i < 26; i++) {
		printf("%c : %d\n", i + 'a', a[i]);
	}

	return (0);
}

Measured memory_bytes: 1124
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<cmath>
#include<deque>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1LL << 60
#define MAX 1000000000
int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

	return b ? gcd(b, a % b) : a;
}
int main() {
	int N;
	ll s = 0;
	scanf("%d", &N);
	rep(i, 1, N + 1) {
		rep(i2, 1, N + 1) {
			rep(i3, 1, N + 1) {
				s += gcd(gcd(i, i2), i3);
			}
		}
	}
	printf("%lld\n", s);
	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int n,m;
vector<vector<P>> g(100010);

void dfs() {
  queue<P> q;
  vector<int> dist(n, INF);

  // 全ての点について矛盾がないか調べる
  // 連結していないケースを考慮する
  REP(i,n) {
    if (dist[i] != INF) continue; // チェック済み

    q.push({ i, 0 });
    dist[i] = 0;
    while(!q.empty()) {
      auto v = q.front(); q.pop();
      int p = v.first;

      for(auto x: g[p]) {
        int np = x.first;
        int nd = dist[p] + x.second;

        if (dist[np] == INF) {
          dist[np] = nd;
          q.push(x);
        } else {
          // 矛盾していれば終了
          if (dist[np] != nd) { COUT("No"); return; }
        }
      }
    }
  }
  COUT("Yes");
}

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

  // m == 0の場合はそもそも矛盾しないためYes
  if (m == 0) { COUT("Yes"); return 0; }

  vector<int> l(m),r(m),d(m);
  REP(i,m) {
    cin >> l[i] >> r[i] >> d[i];
    l[i]--; r[i]--;
  }

  REP(i,m) {
    g[l[i]].push_back({ r[i], d[i] });
    g[r[i]].push_back({ l[i], -d[i] });
  }

  dfs();
  return 0;
}

Measured memory_bytes: 14972
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(read())

U = 10**6
is_prime = np.zeros(U, np.bool_)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
    # if p * p >= U:
    #     break
    if is_prime[p]:
        is_prime[p+p::p] = 0

primes = is_prime.nonzero()[0]


def factor(N):
    div = primes[N % primes == 0]
    for p in div:
        e = 0
        while N % p == 0:
            e += 1
            N //= p
        yield (p, e)
    if N != 1:
        yield (N, 1)


A = np.zeros(100, np.int32)
for i in range(14):
    k = i * (i + 1) // 2
    A[k] = i
np.maximum.accumulate(A, out=A)

x = 0
for p, e in factor(N):
    x += A[e]
print(x)


Measured memory_bytes: 29124
n, m = map(int, input().split())
a = list(map(int, input().split()))

a2 = [0]
for i in range(n):
    a2.append((a2[-1] + a[i]) % m)
a3 = {}
for i in a2:
    a3.setdefault(i, 0)
    a3[i] += 1
count = 0
for i in a3.values():
    count += i * (i - 1) // 2
print(count)

Measured memory_bytes: 16296
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,(n)-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int a[3];
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, 3) {
        cin >> a[i];
    }
    int ans = 10000;
    REP(i, 3) {
        REP(j, 3) {
            REP(k, 3) {
                if(i==j || j==k || i==k) continue;
                int now = abs(a[j]-a[i]);
                now += abs(a[k]-a[j]);
                ans = min(now, ans);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;

public class P
{
    public int x { get; set; }
    public int y { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var std = new P[n];
        var cp = new P[m];
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            std[i] = new P { x = a, y = b };
        }
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var c = int.Parse(line[0]);
            var d = int.Parse(line[1]);
            cp[i] = new P { x = c, y = d };
        }
        for (int i = 0; i < n; i++)
            Console.WriteLine(getCp(cp, std[i]) + 1);
    }
    public static int getCp(P[] cp, P a)
    {
        var ret = 999999999; var reti = -1;
        for (int i = 0; i < cp.Length; i++)
        {
            var w = Math.Abs(a.x - cp[i].x) + Math.Abs(a.y - cp[i].y);
            if (w < ret) { ret = w; reti = i; }
        }
        return reti;
    }
}

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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

int main(){
	ll n, m; cin >> n >> m;
	ll hgt[n+1];
	vector<ll>rec[n+1];
	for(ll i = 1; i <= n; i++) cin >> hgt[i];
	while(m--) {
		ll a, b; cin >> a >> b;
		rec[a].pb(b);
		rec[b].pb(a);
	}
	ll ans = 0;
	for(ll i = 1; i <= n; i++) {
		int flag = 0;
		if(rec[i].size() == 0) ans++;
		else {
			for(auto v: rec[i]) {
				if(hgt[v] >= hgt[i]) {
					flag = 1;
					break;
				}
			}
			if(!flag) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 10228
s = str(input())
s = s[::-1]  #sを逆にする

l = ['resare', 'esare', 'remaerd', 'maerd']

f = 0

if len(s) == 0:
    f = 1

while len(s) != 0:
    if s[:7] == 'remaerd':
        s = s[7::]
    elif s[:6] == 'resare':
        s = s[6::]
    elif s[:5] == 'esare':
        s = s[5:]
    elif s[:5] == 'maerd':
        s = s[5:]
    else:
        f = 1
        break

if f == 1:
    print("NO")
else:
    print("YES")




Measured memory_bytes: 3188
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    b = sum(map(lambda x: (x >> i)&1, a))
    c = n - b
    ans += b * c * (1<<i) % mod
print(ans%mod)

Measured memory_bytes: 122808
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
	int H, W , h, w;
	cin >> H >> W;
	cin >> h >> w;
	cout << (H - h) * (W - w) << endl;
    return 0;
}


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

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int n = arr[0];
    int m = arr[1];
    int[] a = new int[n];
    while (m-- > 0) {
      arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
      a[arr[0] - 1]++;
      a[arr[1] - 1]++;
    }
    foreach (var item in a) {
      Console.WriteLine(item);
    }
  }
}

Measured memory_bytes: 13268
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		a: [usize; n],
	}

	let mut prev = 0usize;
	let mut sum = 0usize;
	for i in 0..n {
		if prev > a[i] {
			let diff = prev - a[i];
			sum += diff;
			prev = a[i] + diff;
		}
		else {
			prev = a[i];
		}
	}
	println!("{}", sum);
}



Measured memory_bytes: 5520
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
 
using namespace std;
 
const ll MOD = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    set<pair<int,int>> st;
    int N,Q;
    cin >> N >> Q;
    vector<int> S(N),T(N),X(N);
    vector<tuple<int,int,int>> a(N); // 工事のデータが入っている
    rep(i,N){
        cin >> S[i] >> T[i] >> X[i];
        a[i] = tie(X[i],S[i],T[i]);
    }
    sort(ALL(a)); // X が小さい順にソートする
    vector<int> D(Q); 
    rep(i,Q)cin >> D[i];
    for(int i = 0; i < Q; i++){
        st.insert({D[i],i}); // 開始時刻が早い人から調べていく
    }
    vector<int> ans(Q,-1);
    for(int i = 0;i<N;i++){
        // 工事中で距離が近いやつから調べていく
        int x,l,r;
        tie(x,l,r) = a[i];
        l-=x;
        r-=x;
        auto it = st.lower_bound(pair<int,int>(l,-1));
        // 最初にl以上になるひとを探す
        while(it != st.end()){
            if(it->first >=r)break;// 今回出発する人がぶつからないなら次の工事現場を見る
            ans[it->second] = x; // もしも[l,r)に含まれていた場合そこでぶつかる
            st.erase(it++);
            // st は時刻でソート済みなので++して次に出発する人がa[i]にぶつかるかどうか調べる
        }
    }
    for(auto x:ans)cout << x << endl;
}

Measured memory_bytes: 17536
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    if(A + B > C + D)
        cout << "Left" << endl;
    else if(A + B == C + D)
        cout << "Balanced" << endl;
    else
        cout << "Right" << endl;






}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

// pdf editorial
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;

  ll ans = 0;
  rep3(C, 1, n) {
    set<int> s;
    ll tmp = 0;
    rep(k, n) {
      if (k * C >= n - 1) break;
      int A = n - 1 - k * C;
      if (A <= 0 || A >= n) break;
      if (C >= A) break; // debuged

      [&]() {
        rep(i, 2) {
          int add = n - 1 - k * C;
          if (i == 1) add = k * C;
          if (s.count(add) || add < 0 || add >= n) return;
          s.insert(add);
          tmp += a[add];
        }
        // if (chmax(ans, tmp)) cout << ans << " " << k << " " << C << " " << A << endl;
        chmax(ans, tmp);
      }();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5376
#include <iostream>
#include <set>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;

int keta(ll x, ll y) {
  int a = 0;
  while(x > 0) {
    a++;
    x /= 10;
  }
  int b = 0;
  while(y > 0) {
    b++;
    y /= 10;
  }
  return max(a, b);
}

int main(int argc, const char * argv[]) {
  ll N;
  cin >> N;

  int minv = 1e9;
  for (ll i = 1; i * i <= N; i++) {
    if(N % i == 0) {
      minv = min(minv, keta(i, N / i));
    }
  }
  cout << minv << endl;
  return 0;
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

/* 残りi枚で回ってきたときその人が勝てるかどうか */ 
bool dp[100001];

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    REPN(i, 1, K+1) REP(j, N) {
        dp[i] |= (a[j] <= i) && (!dp[i - a[j]]);
    }

    if(dp[K]) {
        cout << "First" << endl;
    } else {
        cout << "Second" << endl;
    }

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int R[n];
  for(int i=0;i<n;i++){
    cin >> R[i];
  }

  int maxv,minv;
  maxv = -1000000000;
  minv = R[0];
  for(int j=1;j<n;j++){
    maxv = max(maxv,R[j]-minv);
    minv = min(minv,R[j]);
  }
  
  cout << maxv << endl;
  
  return 0;
}

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

#define MAX_N 100000

using namespace std;

int n;

struct coord
{
    int x, y;
};

struct cmpX
{
    bool operator()(const coord &a, const coord &b)
    {
        return a.x < b.x;
    }
};

struct cmpY
{
    bool operator()(const coord &a, const coord &b)
    {
        return a.y < b.y;
    }
};

coord a[MAX_N + 1];
coord b[MAX_N + 1];

int s[MAX_N + 1];
int d[MAX_N + 1];

int rez;

void inter(int &st, int &dr, int a, int b)
{
    if(a > dr || b < st)
    {
        st = 0;
        dr = -1;
    }

    else
    {
        st = max(st, a);
        dr = min(dr, b);
    }
}

int k;
int diff[MAX_N * 2 + 1];

int dx[MAX_N * 2 + 1];

void getD()
{
    k = 0;
    dx[++ k] = diff[1];

    for(int i = 2; i <= 2*n; i ++)
    {
        if(diff[i] != diff[i - 1])
            dx[++ k] = diff[i];
    }
}

void doCalc(coord a[])
{
    int st = 1;
    int dr = (int)(1e9);
    for(int i = 1; i <= n; i ++)
    {
        inter(st, dr, a[i].x , a[i].y);

        s[i] = dr - st + 1;
    }

    st = 1;
    dr = (int)(1e9);
    for(int i = n; i >= 1; i --)
    {
        inter(st, dr, a[i].x , a[i].y);

        if(i >= 2)
            rez = max(rez, dr - st + 1 + s[i - 1]);

        d[i] = dr - st + 1;
    }
}

int main()
{

    cin >> n;
    int mx = 0;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i].x >> a[i].y;
        b[i].x = a[i].x;
        b[i].y = a[i].y;

        mx = max(mx, a[i].y - a[i].x + 1);
    }

    rez = max(rez, mx);

    sort(a + 1, a + n + 1, cmpX());
    sort(b + 1, b + n + 1, cmpY());

    doCalc(a);
    doCalc(b);

    rez = max(rez, mx + max(0, b[1].y - a[n].x + 1));

/*
    st = 1;
    dr = (int)(1e9);
    for(int i = n; i >= 1; i --)
    {
        inter(st, dr, a[i].x , a[i].y);

        d[i] = dr - st + 1;
    }

    for(int i = 1; i <= k; i ++)
    {
        int st = cautSt(diff[i]);
        int dr = cautDr(diff[i]);

        rez = max(rez, )
    }*/

    cout << rez << "\n";

    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >> n;
  if(n=="Sunny"){
    cout << "Cloudy" << endl;
  }
  else if(n=="Cloudy"){
    cout << "Rainy" << endl;
  }
  else{
    cout << "Sunny" << endl;
  }

}

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

int main(){
  int h, w;
  string s[100];
  cin >> h >> w;
  rep(i, h) cin >> s[i];
  rep(i, w + 2) cout << "#";
  cout << endl;
  rep(i, h) cout << "#" << s[i] << "#" << endl;
  rep(i, w + 2) cout << "#";
  cout <<endl;

}	

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
     
using namespace std;
     
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

     
int main(){
  ll M;

  cin >> M;

  cout << 48 - M << endl;

  return 0;
}


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

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

int calc(int y, int m, int d) {
	int dy = y - 1, dm = m - 1;
	int sum = 0;
	sum += (dy - dy / 3) * (39 * 5) + (dy / 3) * (10 * 20);
	sum += (y % 3) ? (dm / 2 * 39 + (dm % 2) * 20) : (dm * 20);
	sum += d - 1;
	return sum;
}

int main() {
	int n;
	while (cin >> n && n) {
		rep(i, n) {
			int y, m, d; cin >> y >> m >> d;
			cout << calc(1000, 1, 1) - calc(y, m, d) << endl;
		}
	}
}

Measured memory_bytes: 1160
package main
  
import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    bs := make([][]int, n)
    for i := 0; i < n; i++ {
        var x, y int
        fmt.Scan(&x, &y)
        bs[i] = []int{x, y}
    }
    tm := make(map[string][][]int)
    for i := 0; i < n-1; i++ {
        for j := i + 1; j < n; j++ {
            // bs[i], bs[j]のp,qを求めて、それごとにまとめて木を作る
            t := diff(bs[i], bs[j])
            if _, ok := tm[t]; !ok {
                tm[t] = make([][]int, n)
            }
            tm[t][i] = append(tm[t][i], j)
            tm[t][j] = append(tm[t][j], i)
        }
    }
    //fmt.Println(tm)
    var min = 51
    for _, v := range tm {
        var cost int
        cm := make(map[int]bool)
        for i := range v {
            if len(v[i]) > 0 {
                if _, ok := cm[i]; !ok {
                    check(i, v, cm)
                    cost++
                }
            }
        }
        for i := 0; i < n; i++ {
            if _, ok := cm[i]; !ok {
                cost++
            }
        }

        if cost < min {
            min = cost
        }
    }
    if n == 1 {
        min = 1
    }
    fmt.Println(min)
}

func check(k int, v [][]int, cm map[int]bool) {
    if b, ok := cm[k]; ok && b {
        return
    }
    //fmt.Println("k,v,cm", k, v, cm)
    cm[k] = true
    for _, i := range v[k] {
        check(i, v, cm)
    }
}

func diff(a, b []int) string {
    dx, dy := a[0]-b[0], a[1]-b[1]
    if dx < 0 {
        dx *= -1
        dy *= -1
    } else if dx == 0 {
        if dy < 0 {
            dx *= -1
            dy *= -1
        }
    }
    return fmt.Sprintf("%d,%d", dx, dy)
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <tuple>
#include <set>
#include <string>

using namespace std;

#define int long long

signed main() {
	int n, q;
	cin >> n >> q;
	vector<tuple<int, int>> scores;
	for (int i = 0; i < n; i++) {
		int score;
		cin >> score;
		scores.emplace_back(make_tuple(score, i + 1));
	}
	sort(scores.begin(), scores.end());
	map<int, int> indexes;
	int sameI = n - 1;
	for (int i = n - 1; i >= 0; i--) {
		if (get<0>(scores[i]) != get<0>(scores[sameI]))sameI = i;
		indexes.emplace(get<1>(scores[i]), sameI);
	}

	map<int,int> used_indexes;
	for (int i = 0; i < q; i++) {
		string s;
		int val;
		cin >> s >> val;
		if (s[0] == 'A') {
			used_indexes[indexes[val]]++;
		}
		if (s[0] == 'R') {
			used_indexes[indexes[val]]--;
			if (used_indexes[indexes[val]] <= 0)used_indexes.erase(indexes[val]);
		}
		if (s[0] == 'C') {
			int bottom = -1;
			int top = 2e9;
			while (bottom + 1 < top) {
				int mid = (bottom + top + 1) / 2;//r
				int cnt = 0;
				int prev = -1;
				for (auto index : used_indexes) {
					int bottom2 = -1;
					int top2 = index.first;
					while (bottom2 + 1 < top2) {
						int mid2 = (bottom2 + top2 + 1) / 2;
						if (get<0>(scores[index.first]) 
							- get<0>(scores[mid2]) <= mid) {
							top2 = mid2;
						}
						else {
							bottom2 = mid2;
						}
					}
					if (top2 <= prev)cnt += index.first - prev;
					else cnt += index.first - top2 + 1;
					prev = index.first;
				}

				if (n-cnt<=val)top = mid;
				else bottom = mid;
			}
			if (top == 2e9)cout << "NA" << endl;
			else cout << top << endl;
		}
	}
}


Measured memory_bytes: 80976
n = int(input())
al = list(map(int, input().split()))

ald = list(map(lambda x : x // 400,al))

allow = list(filter(lambda x: x<8, ald))
reslow = len(set(allow))

alhigh= list(filter(lambda x: x>=8,ald))
reshigh = len(alhigh)

resl = max(reslow,1)
resh = reslow+reshigh
print(resl,resh)

Measured memory_bytes: 3064
a = list(map(int, input().split(" ")))

ans = []
ans.append(abs(a[1]-a[0]) + abs(a[2]-a[1])) # 0 1 2
ans.append(abs(a[2]-a[0]) + abs(a[1]-a[2])) # 0 2 1
ans.append(abs(a[0]-a[1]) + abs(a[2]-a[0])) # 1 0 2
ans.append(abs(a[2]-a[1]) + abs(a[0]-a[2])) # 1 2 0
ans.append(abs(a[0]-a[2]) + abs(a[1]-a[0])) # 2 0 1
ans.append(abs(a[1]-a[2]) + abs(a[0]-a[1])) # 2 1 0

print(min(ans))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int n, flag; string S, U;
int p[26][26], q[26], r[26];
//tanjyun na zentansaku to bakkutorakku!
void backtruck(int c, int a) {
	if (a == n - 1) {
		if (c == (U[0] - 'a')) { flag = 1; }
	}
	if (flag) { return; }
	for (int i = 0; i < 26; i++) {
		if (p[c][i] >= 1) {
			p[c][i]--;
			backtruck(i, a + 1);
			p[c][i]++;
		}
	}
}
int main() {
	while (true) {
		for (int i = 0; i < 26; i++) {
			q[i] = 0; r[i] = 0;
			for (int j = 0; j < 26; j++)p[i][j] = 0;
		}
		cin >> n; flag = 0;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> S;
			S = S.substr(0, 1) + S.substr(S.size() - 1, 1);
			p[S[0] - 'a'][S[1] - 'a']++;
			q[S[0] - 'a']++; r[S[1] - 'a']++;
		}
		for (int i = 0; i < 26; i++) {
			if (q[i] != r[i])goto E;
		}
		U = S; p[S[0] - 'a'][S[1] - 'a']--;
		backtruck(U[1] - 'a', 0);
		if (flag == true) { cout << "OK" << endl; }
		else { cout << "NG" << endl; }
		goto F;
	E:; cout << "NG" << endl; F:;
	}
}

Measured memory_bytes: 1208
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 nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

// x!
func Calc(x int) int {
	return (x * (x + 1)) / 2
}

func main() {
	sc.Split(bufio.ScanWords)
	const mod = 1000000000 + 7

	//sc.Buffer(nil, 100000000)

	n, k := nextInt(), nextInt()

	ans := 0
	for i := k; i <= n+1; i++ {
		calc := Calc(i - 1)
		sum := i*n - calc
		diff := calc - 1
		ans += (sum - diff)
	}
	fmt.Println(ans % mod)
}


Measured memory_bytes: 1776