akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    int R[n];
    for(int i=0;i<n;i++){
        cin>>R[i];
    }
    int minv=R[0];
    int maxv=-1000000000;
    for(int i=0;i<n-1;i++){
        minv=min(minv,R[i]);
        maxv=max(maxv,R[i+1]-minv);
    }
    cout<<maxv<<endl;
}


Measured memory_bytes: 3880
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <ctime>
using namespace std;
typedef long long ll;
const int maxn=100050;
const int inf=0x3f3f3f3f;
const ll N=1e9+7;
struct Edge{
    int v,nxt,c;
}e[maxn*4];
int h[maxn],tot;
void addEdge(int x,int y,int c){
    e[++tot]=(Edge){y,h[x],c};
    h[x]=tot;
}
struct node{
    int x,d;
    node(int x,int d):x(x),d(d){}
    bool operator < (const node&y)const{
        return d>y.d;
    }
};
int n,m;
bool vis[maxn];
int dis[maxn];
int pre[maxn];
set<int> s[maxn];
int dijkstra(){
    priority_queue<pair<int,int> > q;
    memset(dis,0x3f,sizeof dis);
    q.push({0,1});
    dis[1]=0;
    while(!q.empty()){
        int ud=-q.top().first;
        int ux=q.top().second;
        q.pop();
        if(ud>dis[ux]) continue;
        for (int i = h[ux]; i ; i=e[i].nxt)
        {
            int v=e[i].v;
            int w=(s[ux].count(e[i].c)?0:1)+ud;
            if(dis[v]>w){
                dis[v]=w;
                q.push({-dis[v],v});
                s[v].clear();
                s[v].insert(e[i].c);
            }
            else if(dis[v]==w) s[v].insert(e[i].c);
        }
    }
    return dis[n]>=inf?-1:dis[n];
}
int main(int argc, char const *argv[])
{
    scanf("%d%d", &n,&m);
    for(int i = 0; i < m; ++i){
        int x,y,c;
        scanf("%d%d%d", &x,&y,&c);
        addEdge(x,y,c);
        addEdge(y,x,c);
    }
    cout << dijkstra() << endl;
    return 0;
}

Measured memory_bytes: 20600
N = int(input())
A = list(map(int, input().split()))


m = 1000
k = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        p = int(m//A[i])
        k += p
        m -= A[i]*p
    elif A[i] > A[i+1]:
        m += A[i]*k
        k = 0

m += A[N-1]*k
print(m)

Measured memory_bytes: 9192
#include<iostream>
using namespace std;
 
int main(){
  int N,Y;
  cin>>N>>Y;
  int a,b,c;
  for(a=0;a<=N;a++){
    for(b=0;b<=N;b++){ 
      c=N-a-b;
          if(c>=0 && a*10000+b*5000+c*1000==Y){
            cout<<a<<' '<<b<<' '<<c<<endl;
            return 0;
          
        }
      }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jul 25 21:37:54 JST 2020
 **/

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

const Int INF = 1e9;
const Int K = 200002;
const std::string s = "URDL";

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> x(n), y(n), u(n);
    REP(i, n) {
        char c;
        std::cin >> x[i] >> y[i] >> c;
        u[i] = std::find(ALL(s), c) - s.begin();
    }
    auto solve = [&]() {
        Int ret = INF;
        std::vector<std::vector<int>> ids(K);
        REP(i, n) { ids[x[i]].push_back(i); }
        REP(k, K) {
            std::sort(ALL(ids[k]), [&](Int i, Int j) { return y[i] < y[j]; });
            Int ma = -1;
            for (Int i : ids[k]) {
                if (u[i] == 0) chmax(ma, y[i]);
                if (u[i] == 2 && ma != -1) chmin(ret, (y[i] - ma) * 5);
            }
        }
        std::unordered_map<Int, std::vector<Int>> mp;
        REP(i, n) {
            if (u[i] == 0) mp[x[i] + y[i]].push_back(x[i]);
        }
        for (auto& p : mp) std::sort(ALL(p.second));
        REP(i, n) {
            if (u[i] == 1) {
                auto it = std::lower_bound(ALL(mp[x[i] + y[i]]), x[i]);
                if (it != mp[x[i] + y[i]].end()) chmin(ret, (*it - x[i]) * 10);
            }
        }
        return ret;
    };
    Int ans = INF;
    auto rotate = [&]() {
        REP(i, n) {
            Int a = x[i], b = y[i];
            x[i] = b, y[i] = K - 1 - a;
            u[i] = (u[i] + 1) % 4;
        }
    };
    auto rev = [&]() {
        REP(i, n) {
            x[i] = K - 1 - x[i];
            if (u[i] % 2) u[i] = (u[i] + 2) % 4;
        }
    };
    REP(p, 4) {
        REP(q, 2) {
            chmin(ans, solve());
            rev();
        }
        rotate();
    }
    if (ans == INF) {
        std::cout << "SAFE\n";
    } else {
        std::cout << ans << "\n";
    }
}


Measured memory_bytes: 36100
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    size_t N, T;
    scanf("%zu %zu", &N, &T);

    vector<int> a(T+1);
    for (size_t i=0; i<N; ++i) {
        size_t l, r;
        scanf("%zu %zu", &l, &r);
        ++a[l];
        --a[r];
    }

    for (size_t i=1; i<=T; ++i)
        a[i] += a[i-1];

    printf("%d\n", *max_element(a.begin(), a.end()));
    return 0;
}

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

int main()
{
  int H,i,p,l,r;
  int *A;

  scanf("%d",&H);
  A=(int *)malloc(sizeof(int)*H+1);


  for(i=1;i<H+1;i++)
    {
      scanf("%d",&A[i]);
    }

  for(i=1;i<H+1;i++)
    {
      p=i/2;
      l=2*i;
      r=2*i+1;

      printf("node %d: key = %d, ",i,A[i]);
      if(p!=0) printf("parent key = %d, ",A[p]);
      if(l<H+1 && r>H) printf("left key = %d, \n",A[l]);
      else if(l<H+1) printf("left key = %d, ",A[l]);
      else printf("\n");
      if(r<H+1 && l<H+1) printf("right key = %d, \n",A[r]);

      
    }
  

  return 0;
}



Measured memory_bytes: 2112
/**
 *    This code has been written by YueGuang, feel free to ask me question. Blog: http://www.yx.telstudy.xyz
 *    created:
 */
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;

using namespace std;
int main(){
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    return (a+b>=c)? printf("Yes\n") * 0 :printf("No\n") * 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
        int input_a = 0;
        int input_b = 0;
        int output_area = 0;
        int output_peri = 0;

        scanf("%d %d",&input_a, &input_b);

        output_area = input_a * input_b;
        output_peri = input_a * 2 + input_b * 2;

        printf("%d %d\n",output_area, output_peri);

        return 0;
}



Measured memory_bytes: 2100
abl = [map(int,input().split()) for nesya in range(3)]
s = [1,1,2,2,3,3,4,4]
c = 0
for ab in abl:
  for n in ab:
    if n in s:
      s.remove(n)
    else:
      c += 1
if c == 0:
  print('YES')
else:
  print('NO')


Measured memory_bytes: 3060
#static info
array = ['Sunny', 'Cloudy', 'Rainy', 'Sunny']

#input
weather = str(input())

#def
def predict_wether(weather):
    for k,s in enumerate(array):
        if weather == s:
            output = array[k+1]
            break

    return output

#main
print(predict_wether(weather))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin,(a).rend()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));

	int ans = inf;
	rrep(i, 101) {
		int b = 0;
		rep(j, n) {
			b += (i - a[j]) * (i - a[j]);
		}
		ans = min(ans, b);
	}

	dunk(ans);

	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,command;
    unsigned long num = 0,one = 1,index;
    cin >> n;
    
    for(int i = 0;i < n;++i){
        cin >> command;
        switch (command) {
            // test(i): i番目のフラグの状態がONの場合1、OFFの場合0を出力する
            case 0:{
                cin >> index;
                index = one << index;
                bool on = (num & index) > 0 ? true : false;
                cout << on << endl;
                break;
            // set(i): i番目のフラグをONにする
            }
            case 1:
                cin >> index;
                index = one << index;
                num = index | num;
                break;
            // clear(i): i番目のフラグをOFFにする
            case 2:
                cin >> index;
                index = ~(one << index);
                num = index & num;
                break;
            // flip(i): i番目のフラグを反転する
            case 3:
                cin >> index;
                index = one << index;
                num = index ^ num;
                break;
            // all: 全てのフラグがONになっている場合1、なっていない場合0を出力する
            case 4:
                cout << (num == __UINT_LEAST64_MAX__) << endl;
                break;
            // any: 何れかのフラグがONになっている場合1、なっていない場合0を出力する
            case 5:
                cout << (num != 0) << endl;
                break;
            // none: 全てのフラグがOFFになっている場合1、なっていない場合0を出力する
            case 6:
                cout << (num == 0) << endl;
                break;
            // count: ONになっているフラグの数を出力する
            case 7:{
                int bitNum = 0;
                unsigned long bit = one;
                for(int i = 0;i < 64;++i){
                    bit = one << i;
                    bool on = (num & bit) > 0 ? true : false;
                    if(on){
                        bitNum++;
                    }
                }
                cout << bitNum << endl;
                break;
            }
            // val: 状態の整数値を出力する
            default:
                cout << num << endl;
                break;
        }
    }
}



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

map<long long, long long> prime_factor(long long n) {
  map<long long, long long> res;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main(void) {
  long long N;
  cin >> N;
  map<long long, long long> primes = prime_factor(N);
  bool flag = true;
  long long ans = 0;
  long long i = 1;
  while (flag) {
    bool continueFlag = false;
    for (auto prime : primes) {
      if (prime.second >= i) {
        continueFlag = true;
        ans++;
        primes[prime.first] -= i;
      }
    }
    i++;
    flag = continueFlag;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3560
import bisect

N,K=map(int,input().split())
X=list(map(int,input().split()))

if 0 in X:
  K=K-1
ans=[]
Right=[]
Left=[]
  
for x in X:
  if x>0:
    Right.append(x)
  else:
    Left.append(abs(x))

Left.append(0)
Left.sort()
Right=[0]+Right
    
for i in range(K+1):
  if i<=len(Right)-1 and K-i<=len(Left)-1:
    ans.append(min(Right[i],Left[K-i])*2+max(Right[i],Left[K-i]))

if K==0:
  ans.append(0)

print(min(ans))


Measured memory_bytes: 14660
from copy import deepcopy
import itertools


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


S = input()
K = read()

substring = set()
for k in range(1, min(K, len(S))+1):
    for i in range(len(S)-k+1):
        substring.add(S[i:i+k])

sub = sorted(list(substring))
print(sub[K-1])


Measured memory_bytes: 5104
H, W, K = map(int, input().split())
cake = []
ans = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    cake.append(list(input()))


def change(i, j, count, count2, count3):
    #print(i, j, count,count2,  count3)
    for k in range(count2):
        for a in range(count):
            ans[i-k][j-a] = count3
stflag = 0
count2 = 0
count3 = 1
for i in range(len(cake)):
    count = 0
    stflag = 0
    for j in range(len(cake[i])):
        count += 1
        if cake[i][j] == "#":
            #print(i, j)
            change(i, j, count, count2 + 1, count3)
            count = 0
            count3 += 1
            stflag = 1
        if j == len(cake[i])-1:
            if stflag == 1:
                count3 -= 1
                change(i, j, count, count2 + 1, count3)
                count = 0
                count3 += 1
                count2 = 0
            else:
                count2 += 1

if count2 != 0:
    for i in range(count2):
        for j in range(len(cake[i])):
            ans[H - i - 1][j] = ans[H - count2 - 1][j]


for i in range(len(ans)):
    for j in range(len(ans[i])):
        print(ans[i][j], end=" ")
    print()

Measured memory_bytes: 8304
//created by pyoxiao on 2020/04/04
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
LL n, a[5];
void solve() {
    cin >> n;
    for(int i = 0; i < 5; i ++) cin >> a[i];
    LL mmin = *min_element(a, a + 5);
    cout << (4LL + n / mmin + (n % mmin == 0 ? 0 : 1)) << '\n';
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 256
x=[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]
K = int(input())
ans = x[K-1]
print(ans)

Measured memory_bytes: 3316
#include <stdio.h>
int main(void)
{
    int N,i,c = 0;;
    scanf("%d",&N);
    char S[N + 1];
    scanf("%s",S);
    for(i = 0; i < N - 1;i++)
    {
        if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
            c++;
    }
    printf("%d",c);
    return 0;
}

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

int main() {
  ll n,k;
  
  cin >> n >> k;
    
  vector<int> a(n);
  vector<int> f(n);
  
  for(int i = 0;i<n;i++){
    cin >> a[i];
  }
  for(int i = 0;i<n;i++){
    cin >> f[i];
  }
  
  sort(a.begin(), a.end(),greater<int>());
  sort(f.begin(), f.end());
  ll mn = 0;
  ll mx = 1000000000000;
  //ll mx = 4;
  ll md;
  int flg = 0;
  int i;
  ll tmp;
  ll sh;
  while(mn != mx){
    
    tmp = k;
    md = (mn+mx)/2;
    //cout << mn << " " << md << " " << mx << endl;
    flg = 0;
    i = 0;
    while(i<n){
      sh =  md/f[i];
      if(a[i] > sh){
        tmp -= (a[i] -sh);
      }
      //cout << "a" << f[i] << " " << a[i] << " " << sh << " "<< tmp << endl;
      if(tmp<0){
        flg = 1;
        break;
      }
      i++;
    }
    
    if(flg == 0){
      mx = md; 
    }else{
      mn = md+1;
    }
  
  }
  cout << mx;
  //cout << sum;
}

Measured memory_bytes: 4756
#include<iostream>

using namespace std;

int main (){
    int a,b,c,S,M,L;
    cin >> a >> b >> c;
    if ( a < b && b < c){
    cout << a << " " << b << " " << c << endl;
    } 
    if( a < c && c < b ){
    cout << a << " " << c << " " << b << endl;
    }
    if( b < a && a < c ){
    cout << b << " " << a << " " << c << endl; 
    }
    if( b < c && c < a ){
    cout << b << " " << c << " " << a << endl; 
    }
    if( c < a && a < b ){
    cout << c << " " << a << " " << b << endl; 
    }
    if( c < b && b < a ){
    cout << c << " " << b << " " << a << endl; 
    }
    if( a == b && b == c ){
    cout << a << " " << b << " " << c << endl; 
    }
    if( a == b && c < a ){
    cout << c << " " << b << " " << a << endl; 
    }
    if( a == c && b < a ){
    cout << b << " " << a << " " << a << endl; 
    }
    if( a == b && c > a ){
    cout << a << " " << b << " " << c << endl; 
    }
    if( a == c && b > a ){
    cout << a << " " << c << " " << b << endl; 
    }
    if( b == c && b < a ){
    cout << b << " " << c << " " << a << endl; 
    }
    if( b == c && b > a ){
    cout << a << " " << c << " " << b << endl; 
    }
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    int copy = n;
    vector<int> prime;
    int cnt = 2;
    map<int, int> mp;
    while (cnt * cnt <= copy)
    {
        if(copy%cnt==0){
            copy /= cnt;
            prime.push_back(cnt);
            mp[cnt]++;
        }
        else{
            cnt++;
        }
    }
    if(copy!=1){
        prime.push_back(copy);
        mp[copy]++;
    }
    //show(prime);
    int ans = 0;
    for (auto &u : mp)
    {
        int x = 2 * u.second;
        int l = -1;
        int r = 1e9;
        while(l+1<r){
            int c = (l + r) / 2;
            if (c * (c+1) <= x){
                l = c;
            }
            else{
                r = c;
            }
        }
        //cerr << l << " "<<x<<endl;
        ans += l;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        int m1;
        cin>>m1;
        vector <int> a(n+1,0);
        vector <int> b(m+1,0);
        int h[m1];int w[m1];
        for(int i=0;i<m1;i++){
            cin>>h[i]>>w[i];
            a[h[i]]++;
            b[w[i]]++;
        }
        int ans=0;
        int val,val1;
        val=val1=0;
        for(int i=1;i<=n;i++)
            val=max(val,a[i]);
        for(int i=1;i<=m;i++)
            val1=max(val1,b[i]);
        int ctr=0;
        for(int i=1;i<=m;i++){
            if(val1==b[i])
                ctr++;
        }
        vector <int> a1(n+1,0);
        for(int i=0;i<m1;i++){
            if(b[w[i]]==val1)
                a1[h[i]]++;
        }
        ans=val+val1-1;
        for(int i=1;i<=n;i++){
            if(a1[i]<ctr&&a[i]==val)
                ans=val+val1;
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 9000
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main(void){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if((std::abs(a-b)<=d&&std::abs(c-b)<=d)||(std::abs(a-c)<=d)){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 256
//int _(){
//    int n;
//    cin >> n;
//    vi arr(n);
//    cin >> arr;
//    map<int,int> cnt;
//    for(int x : arr)
//        cnt[x]++;
//    int ans = 0;
//    for(auto _ : cnt)
//        ans += _.Y-1;
//    return n-(ans+1)/2*2;
//}
#include <map>
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define all(v) (v).begin(), (v).end()
#define Y second
#define T1 template<typename T> static
using namespace std;
typedef vector<int> vi;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
int _(){
    int n;
    cin >> n;
    vi arr(n);
    cin >> arr;
    map<int,int> cnt;
    for(int x : arr)
        cnt[x]++;
    int ans = 0;
    for(auto _ : cnt)
        ans += _.Y-1;
    return n-(ans+1)/2*2;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


Measured memory_bytes: 5376
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	char b;
	cin >> b;
	
	// 解法
	
	//出力
	if (b=='A') cout << 'T' << endl;
	else if (b=='T') cout << 'A' << endl;
	else if (b=='G') cout << 'C' << endl;
	else if (b=='C') cout << 'G' << endl;
}

Measured memory_bytes: 256
s=list(input())
d=["+","-"]
for i in d:
  for j in d:
    for k in d:
      if eval(s[0]+i+s[1]+j+s[2]+k+s[3])==7:
        ans=s[0]+i+s[1]+j+s[2]+k+s[3]
        
print(ans+"=7")

Measured memory_bytes: 9016
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };


ll v[55];
ll comb[100][100];


void combinit(ll p) {
	for (int i = 0; i <= p; i++) {
		comb[i][0] = 1LL;
		comb[i][i] = 1LL;
	}
	for (int i = 1; i <= p; i++) {
		for (int j = 1; j <= i - 1; j++) {
			comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
		}
	}
}




int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	map<ll,ll>cnt;
	map<ll,ll>inicnt;

	combinit(55);

	rep(i, 0, n) {
		cin >> v[i];
		cnt[v[i]]++;
	}
	sort(v,v+n);
	reverse(v,v+n);

	double av = 0.0;
	rep(i, 0, a) {
		av += v[i];
		inicnt[v[i]]++;
	}
	av /= a;
	printf("%.10lf\n", av);


	int fl = 0;
	ll ini = v[0];
	rep(i, 1, a) {
		if (v[i] != ini)fl = 1;
	}

	ll ans;
	if (!fl) {
		ans = 0;
		for (int i = a; i <= min(cnt[v[0]],b); i++) {
			ans += comb[cnt[v[0]]][i];
		}
	}
	else {
		ans = 1;
		fore(x, inicnt) {
			ans *= comb[cnt[x.first]][x.second];
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
x=int(input())
while True:
  flag=0
  for i in range(2,int(x**0.5)+2):
    if x%i==0:
      flag=1
      break
    else:
      continue
  if x==2:
    flag=0
  if flag==0:
    print(x)
    break
  else:
    x+=1

Measured memory_bytes: 9316
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

ans = r * g * b

for i in range(1, (N - 1) // 2 + 1):
    for j in range(N - i * 2):
        if S[j] != S[j+i] and S[j] != S[j+2*i] and S[j+i] != S[j+2*i]:
            ans -= 1

print(ans)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    ll r, d, x; cin >> r >> d >> x;
    rep(i, 10) {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <stdexcept>
#include <utility>
// #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,n,h) for(int i = n; i < h; ++i)
#define rep3(l,n,h) for(int l = n; l <= h; ++l)
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.begin(),a.end());
    cout << a.at(n-1) - a.at(0);
    return 0;
}


Measured memory_bytes: 256
lst = raw_input().split()
lst2 = []
for v in lst:
    if v == "+":
        lst2[len(lst2)-2] += lst2.pop()
    elif v == "-":
        lst2[len(lst2)-2] -= lst2.pop()
    elif v == "*":
        lst2[len(lst2)-2] *= lst2.pop()
    elif v == "/":
        lst2[len(lst2)-2] /= lst2.pop()
    else:
        lst2.append(int(v))
print lst2[0]

Measured memory_bytes: 6460
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

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

using namespace std;

int road[55][55];

int main()
{
    REP(i, 55) { REP(j, 55) { road[i][j] = 0; } }
    int N, M;
    cin >> N >> M;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        road[a][b] += 1;
        road[b][a] += 1;
    }
    for(int i=1; i <= N; ++i) {
        int ans = 0;
        for(int j=1; j<=N; ++j) {
            ans += road[i][j];
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





// thanks for pasta
// https://agc021.contest.atcoder.jp/submissions/2133151



int H, W, yoko, tate;
string ans[2020];
//---------------------------------------------------------------------------------------------------
void yokooki(int y, int x) {
    if (yoko and ans[y][x] == '.' and ans[y][x + 1] == '.') {
        ans[y][x] = '<';
        ans[y][x + 1] = '>';
        yoko--;
    }
}
void tateoki(int y, int x) {
    if (tate and ans[y][x] == '.' and ans[y + 1][x] == '.') {
        ans[y][x] = '^';
        ans[y + 1][x] = 'v';
        tate--;
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W >> yoko >> tate;
    rep(y, 0, H) rep(x, 0, W) ans[y] += ".";

    if (H % 2 == 1) {
        // y=0の上一列に「<>」を敷き詰める
        rep(x, 0, W / 2) yokooki(0, (W % 2) + x * 2);
    }

    if (W % 2 == 1) {
        // x=0の縦一列に「^v」を敷き詰める
        rep(y, 0, H / 2) tateoki((H % 2) + y * 2, 0);
    }

    if (2 < H and 2 < W and H % 2 == 1 and W % 2 == 1 and yoko % 2 == 1 and tate % 2 == 1) {
        // 左上を3*3をうまく配置する
        rep(x, 0, 3) rep(y, 0, 3) ans[y][x] = '.';
        yoko++; tate++;

        yokooki(0, 0);
        yokooki(2, 1);
        tateoki(0, 2);
        tateoki(1, 0);
    }

    //printf("<> = %d ^v = %d \n", yoko, tate);  rep(y, 0, H) printf("%s\n", ans[y].c_str());

    // 残りの部分は貪欲に縦縦か横横で2*2を埋めていく
    rep(x, 0, W / 2) rep(y, 0, H / 2) {
        if (yoko) {
            yokooki(y * 2 + (H % 2), x * 2 + (W % 2));
            yokooki(y * 2 + (H % 2) + 1, x * 2 + (W % 2));
        }
        else if (tate) {
            tateoki(y * 2 + (H % 2), x * 2 + (W % 2));
            tateoki(y * 2 + (H % 2), x * 2 + (W % 2) + 1);
        }
    }
    
    if (yoko or tate) printf("NO\n");
    else {
        printf("YES\n");
        rep(y, 0, H) printf("%s\n", ans[y].c_str());
    }
}

Measured memory_bytes: 2304
#include <iostream>

int main()
{
    int a, b;
    while (std::cin >> a >> b) {
        if ((a == 0) && (b == 0)) {
            break;
        }

        std::cout << std::min(a, b) << " " << std::max(a, b) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3048
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

int now,n,k;

int main(){
  int ans=0;
  cin >> n ;
  vector<int> a(n),b(n);
  REP(i,n){
      cin>>a[i];
      b[i]=a[i];
  }

  sort(a.begin(), a.end());
  int maxa0=a[n-1];
  int maxa1=a[n-2];
  
    REP(i,n){
    if (b[i]==maxa0){
        cout<<maxa1<<endl;
    }else{
        cout<<maxa0<<endl;
    }
    }
      return 0;
  
}

Measured memory_bytes: 3200
n = int(input())
line = list(map(int, input().split()))
max = line[0]
min = line[0]
sum = line[0]
for i in range(1, n):
    if max < line[i]:
        max = line[i]
    elif min > line[i]:
        min = line[i]
    sum += line[i]
print(min, max, sum)

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 + 7 ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
    int n ;
    cin >> n ;
    string s ;
    cin >> s ;
    int r=0   , w = 0 ;
    for( int i = 0 ; i < n ; i++){
        if(s[i]=='R'){
            r++;
        }
        else{
            w++;
        }
    }
    if(r==0){
        cout << "0";
        return ;
    }
    int lw = 0 ;
    for( int i = 0 ; i < r ;i++){
        if(s[i]=='W') lw++;
    }
    cout << lw << "\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    // cin >> t ;
    while(t--){
        solve( );
    }
}


Measured memory_bytes: 3736
#include <iostream>

int main(int argc, char *argv[]) {
    char str[100];
    unsigned long long K;
    scanf("%s",str);
    std::cin>>K;
    char *p=str;
    int count=0;
    for(;*p!='\0';p++){
        if((*p)!='1'){
            break;
        }
        count++;
    }
    if(K<=count){
        std::cout<<'1'<<std::endl;
    }else{
        printf("%c", *p);
    }
    return 0;
}

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

int main() {
	long long n;
	cin>>n;
	long long ans=0;
	for(int i=2;i<= sqrt(n);i++)
	{
		int cur=0;
		while(n%i==0)
		{
			cur++;
			n/=i;
		}
		for(int j=1;j<100000;j++)
		{
			if(cur<j)break;
			ans++;
			cur-=j;
		}
	}
	if (n>1) ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>

using namespace std;

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

  int n, l;

  vector<string> ans;
  string s;

  cin >> n;
  cin >> l;

  for(int i=0; i<n; i++){
    cin >> s;
    ans.push_back(s);
  }

  /*for(int i=1; i<n; i++){
    if(ans[i] < ans[i-1]){
      (ans[i]).swap(ans[i-1]);
    }
    }*/

  sort(ans.begin(), ans.end());

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


Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
qn = [list(map(int, input().split())) for _ in range(Q)]
cnt = [0 for _ in range(N+10)]
for i in range(1, N+1):
    if (S[i-1:i+1] == "AC"):
        cnt[i] = cnt[i-1] + 1
    else:
        cnt[i] = cnt[i-1]
for q in qn:
    l, r = q
    print(cnt[r-1] - cnt[l-1])










Measured memory_bytes: 29684
#include <cstdio>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int,int> P;

const int UNKNOWN=2000000;
const int MAX_N=100000,MAX_M=100000;

int N,M;
char type[MAX_M+1];
int a[MAX_M],b[MAX_M],w[MAX_M];

int p[MAX_N],cost[MAX_N],height[MAX_N];	//union find??¨

vector<int> out;

void init(int n){
	for (int i=0;i<n;i++){
		p[i]=i;
		cost[i]=0;
		height[i]=0;
	}
	return;
}

P find(int i){
	//????????????????????????
	if (i==p[i]){
		return P(i,0);	//first=?????????,second=?????????
	}
	P pa=find(p[i]);
	p[i]=pa.first;
	cost[i]+=pa.second;
	return P(p[i],cost[i]);
}

void solve(){
	init(N);
	for (int i=0;i<M;i++){
		P roota=find(a[i]);
		P rootb=find(b[i]);
		if (type[i]=='!'){
			if (height[roota.first]<height[rootb.first]){
				p[roota.first]=rootb.first;
				cost[roota.first]=w[i]+rootb.second-roota.second;
			}
			else{
				p[rootb.first]=roota.first;
				cost[rootb.first]=roota.second-rootb.second-w[i];
				if (height[roota.first]==height[rootb.first]){
					height[roota.first]++;
				}
			}
		}
		else{
			if (roota.first!=rootb.first){
				out.push_back(UNKNOWN);
			}
			else{
				out.push_back(roota.second-rootb.second);
			}
		}
	}
}

int main(){
	do{
		scanf("%d %d",&N,&M);
		if (N || M){
			for (int i=0;i<M;i++){
				scanf(" %c %d %d",&type[i],&a[i],&b[i]);
				a[i]--;
				b[i]--;
				if (type[i]=='!'){
					scanf("%d",&w[i]);
				}
			}
			solve();
		}
	}while(N || M);
	for (int i=0;i<out.size();i++){
		if (out[i]==UNKNOWN){
			printf("%s\n","UNKNOWN");
		}
		else{
			printf("%d\n",out[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 7608
import fractions
A, B, C, D = map(int, input().split())
wari = [(A-1)//C+(A-1)//D-(A-1)//(C*D//fractions.gcd(C,D)), B//C+B//D-B//(C*D//fractions.gcd(C,D))]
print(B-A+1-wari[1]+wari[0])

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  int n = 0, s = 0, w = 0, e = 0;
  for (int i = 0; i < (int)S.size(); i++) {
    if (S[i] == 'N')
      n++;
    else if (S[i] == 'S')
      s++;
    else if (S[i] == 'W')
      w++;
    else if (S[i] == 'E')
      e++;
  }
  if (((n > 0 && s > 0) || (n == 0 && s == 0)) &&
      ((w > 0 && e > 0) || (w == 0 && e == 0))) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//

struct Unionfind {
  vector<int> d;
  Unionfind(int n): d(n, -1) {}
  int root (int x){
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y){
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) {return root(x) == root(y);}
  int size(int x) {return -d[root(x)];}
};

int main() {
  int n, m;
  cin >> n >> m;
  Unionfind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    uf.unite(a, b);
  }
  int ans = 0;
  rep(i, n) ans = max(ans, uf.size(i));
  cout << ans << endl;
}

Measured memory_bytes: 4040
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int H = sc.nextInt();
    int W = sc.nextInt();
    int D = sc.nextInt();
    int[] x = new int[H*W+1];
    int[] y = new int[H*W+1];

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        int tmp = sc.nextInt();
        x[tmp] = i;
        y[tmp] = j;
      }
    }

    int[] cost = new int[H*W+1];
    for (int i = D+1; i < H*W+1; i++) {
      cost[i] = cost[i-D] + Math.abs(x[i] - x[i-D]) + Math.abs(y[i] - y[i-D]);
    }

    int Q = sc.nextInt();
    int[] L = new int[Q];
    int[] R = new int[Q];

    for (int i = 0; i < Q; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    for (int i = 0; i < Q; i++) {
      System.out.println(cost[R[i]] - cost[L[i]]);
    }
  }
}


Measured memory_bytes: 91220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,sum=0,x;
    cin>>n>>m;
    while(m--)
    {
        cin>>x;
        sum+=x;
    }
    if(sum>n) cout<<-1;
    else cout<<n-sum;
}


Measured memory_bytes: 3620
import sys
from collections import Counter
from typing import Callable, NoReturn, Tuple


def main() -> NoReturn:
    scan: Callable[[], str] = sys.stdin.readline

    n: int = int(scan().rstrip())
    a: Tuple[int] = tuple(int(a_i) for a_i in scan().rstrip().split())

    count: Counter = Counter(a)

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


if __name__ == '__main__':
    main()


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

using namespace std;

#define all(x) x.begin(), x.end()
#define inf ((int) 1e9)
#define Linf ((long long) 1e18)

typedef long long ll;
typedef long double ld;

const int N = 123456;
const int M = 1234567;
const int P = 400004;
const int A = 256;

ll ncr(int n, int r){

	if(n < r)
		return 0;

	if(n < 0 || r < 0)
		return 0;

	if(n == r)
		return 1;

	return ncr(n - 1, r - 1) + ncr(n - 1, r);
}


void qsort(auto * a, int i, int j){

	if(i >= j) return;

	int l = i;
	int r = j;

	while(r > l){ 

		while(r > l && a[r] >= a[l]) r--;

		if(a[r] < a[l]){
			swap(a[r], a[l]);
		}

	}	

	qsort(a, i, r - 1);
	qsort(a, r + 1, j);

	return;
}


auto bpow(auto base, auto exp, auto MOD){

	ll ans = 1;
	for(; exp; exp>>=1){
		if(exp & 1)
			ans = (ans * base) % MOD;
		base = (base * 1ll * base) % MOD;
	}

	return ans;
}

int main(int argc, char const *argv[])
{
	
	#ifdef Cyborg1o1
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif	

	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int a, b, c;
	cin >> a >> b >> c;

	int num = a * 100 + b * 10 + c;

	if(num % 4 == 0)
		puts("YES");
	else
		puts("NO");

	return 0;					
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int a[200005];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int p=0;
	FOR(i,1,n){
		cin>>a[i];p^=a[i];
	}
	FOR(i,1,n)cout<<(p^a[i])<<' ';
	RE 0;
}




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


int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	if (K <= A) {
		cout << K;
	}
	else if (K > A && K <= (A + B)) {
		cout << A;
	}
	else if (K > (A + B)) {
		cout << A - (K - (A + B));
	}
	return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;

namespace zyt
{
	template<typename T>
	inline bool read(T &x)
	{
		char c;
		bool f = false;
		x = 0;
		do
			c = getchar();
		while (c != EOF && c != '-' && !isdigit(c));
		if (c == EOF)
			return false;
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
		return true;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	typedef long long ll;
	typedef pair<int, int> pii;
	const int N = 2e5 + 10;
	int n, sufmx[N], sufmn[N];
	pii arr[N];
	int work()
	{
		read(n);
		int mx = 0, mn = 1e9;
		for (int i = 1; i <= n; i++)
		{
			read(arr[i].first), read(arr[i].second);
			if (arr[i].first > arr[i].second)
				swap(arr[i].first, arr[i].second);
			mx = max(mx, arr[i].second), mn = min(mn, arr[i].second);
		}
		sort(arr + 1, arr + n + 1);
		ll ans = ll(arr[n].first - arr[1].first) * (mx - mn), k = mx - arr[1].first;
		mn = 1e9, mx = 0;
		sufmx[n + 1] = 0, sufmn[n + 1] = 1e9;
		for (int i = n; i > 0; i--)
			sufmx[i] = max(sufmx[i + 1], arr[i].first), sufmn[i] = min(sufmn[i + 1], arr[i].first);
		for (int i = 1; i <= n; i++)
		{
			mn = min(mn, arr[i].second), mx = max(mx, arr[i].second);
			ans = min(ans, k * (max(sufmx[i + 1], mx) - min(sufmn[i + 1], mn)));
		}
		write(ans);
		return 0;
	}
}
int main()
{
	return zyt::work();
}

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

using namespace std;

int main() {
	string num;
  	int msum=0;
  	while(true){
    	cin>>num;
      	if(num=="0") break;
    	for (int i=0;i<num.size();i++){
        	msum +=(num.at(i)-'0');	
        }
    	cout<<msum<<endl;  
      	msum=0;
    }
}	


Measured memory_bytes: 3156
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

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

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}


int solve(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i, n) {
    cin>>a[i];
  }
  dump(a);

  auto check=[&](vi x){
    rep(i, 1, n){
      if (x[i]<x[i-1]) return false;
    }
    return true;
  };
  rep(i, n){
    rep(j, n){
      vi b(a);
      b[i] = a[j];
      b[j] = a[i];

      rep(i, n){
        if (check(b)) {
          cout << "YES" << endl;
          return 0;
        }
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256