akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) { s >> x; } return s;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}

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

    int N, M; cin >> N >> M;
    vector<string> A(N); cin >> A;
    vector<string> B(M); cin >> B;

    // cout << FMT2(N, M) << endl;
    for (int i = 0; i < N - M + 1; i++) {
        for (int j = 0; j < N - M + 1; j++) {
            // cout << FMT2(i, j) << endl;
            bool f = true;
            for (int k = 0; k < M; k++) {
                // cout SP FMT3(k, B[i + k], A[i + k].substr(j, M)) << endl;
                if (B[k] != A[i + k].substr(j, M)) {
                    f = false;
                    break;
                }
            }
            if (f) {
                Yes(true);
                return 0;
            }
        }
    }
    Yes(false);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    string A[N],B[M];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<M;i++){
        cin >> B[i];
    }
    for(int H=0;H+M-1<N;H++){
        for(int W=0;W+M-1<N;W++){
            bool OK = true;
            for(int i=0;i<M;i++){
                if(!OK)break;
                for(int j=0;j<M;j++){
                    if(B[i][j] != A[H+i][W+j]){
                        OK = false;
                        break;
                    }
                }
            }
            if(OK){
                cout << "Yes" << endl;
                return 0;
            }
            
        }
        
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3100
n = int(input())
x = input()
import copy

memo = [0]*n
ans = [-1]*n
popcnt = 0

for i in range(n):
    if x[i] == "1":
        popcnt += 1

amariStaticA = 0
amariStaticB = 0
aaa = -1
if popcnt == 1:
    for i in range(n):
        if x[i] == "1":
            ans[i] = 0
            aaa = i
            amariStaticB += pow(2, n-i-1, popcnt+1)
    amariStaticB %= popcnt+1
else:
    for i in range(n):
        if x[i] == "1":
            amariStaticA += pow(2, n-i-1, max(1, popcnt-1))
            amariStaticB += pow(2, n-i-1, popcnt+1)
    amariStaticA %= max(1, popcnt-1)
    amariStaticB %= popcnt+1

for i in range(n):
    if popcnt == 1 and i == aaa:
        continue
    if x[i] == "0":
        amari = amariStaticB + pow(2, n-i-1, popcnt+1)
        amari %= popcnt+1
    else:
        amari = amariStaticA - pow(2, n-i-1, max(1, popcnt-1))
        amari %= max(1, popcnt-1)
    if amari == 0:
        ans[i] = 1
    else:
        memo[i] = amari

for i in range(len(memo)):
    cnt = 1
    firstMemo = copy.deepcopy(memo[i])
    while memo[i] != 0:
        popcnt = bin(memo[i]).count("1")
        memo[i] %= max(1, popcnt)
        cnt += 1
        if memo[i] == 0:
            ans[i] = cnt
            break


for anss in ans:
    print(anss)

Measured memory_bytes: 18852
n = int(input())
A = list(map(int,input().split()))

four_gcd = 0
two_gcd = 0
odd = 0

for a in A:
	if a%4 == 0:
		four_gcd += 1
	elif a%2 == 0:
		two_gcd += 1
	else:
		odd += 1

# print(four_gcd,two_gcd,odd)
if two_gcd > 0:
	odd += 1
# print(four_gcd,two_gcd,odd)
if odd > four_gcd+1:
	print('No')
else:
	print('Yes')

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    int m = 0;
    for (int i = 0; i < n; i++) {
        ll b;
        cin >> b;
        if(b < 0) m++; 
        b = abs(b);
        ans += b;
        a[i] = b;
    }
    SORT(a);
    if(m % 2) ans -= a[0]*2; 
    pr(ans);
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var n = l[0]; var a = l[1]; var b = l[2];
        var s = Console.ReadLine().ToCharArray();
        var count = 0;
        var ac = 0;

        for (var i = 0; n > i; i++)
        {
            if (s[i] == 'a' && a + b > count)
            {
                Console.WriteLine("Yes");
                count++;
            }
            else if (s[i] == 'b' && a + b > count && b > ac)
            {
                Console.WriteLine("Yes");
                count++;
                ac++;
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 15968
#include <stdio.h>
#include <string.h>
 
int main(){
    char x[2000000], y[2000000];
    int len, i, count = 0;
    scanf("%s %s", &x, &y);
    len = strlen(x);
    for (i = 0; i < len; i++){
        if (x[i] != y[i]) count++;
    }
    printf("%d", count);
    return 0;
}

Measured memory_bytes: 2100
from itertools import product

N, M = map(int, input().split())
sw = [[0] * N for _ in range(M)]
for i in range(M):
    ks = input().split()
    for j in ks[1:]:
        sw[i][int(j)-1] = 1
P = list(map(int, input().split()))

ans = 0
for switch in product(range(2), repeat=N):
    isOK = True

    for i in range(M):
        cnt = 0
        for j in range(N):
            if sw[i][j] == switch[j] == 1:
                cnt += 1
        if cnt % 2 != P[i] % 2:
            isOK = False
            break

    if isOK:
        ans += 1

print(ans)


Measured memory_bytes: 3064
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
s = list(input())

cw,ce = 0,0

for i in s:
  if i=="E":
    ce+=1
if s[0]=="E":
  ce -= 1
now = ce
ans = now

for i in range(1, len(s)):
  if s[i-1]=="W":
    cw += 1
  if s[i]=="E":
    ce -= 1
  ans = min(ans,ce+cw)
print(ans)

Measured memory_bytes: 11788
#include <iostream>
#include <vector>

using namespace std;

class UnionFind {
public:
    explicit UnionFind(int N) : root(N, -1), size(N, 1) {}
    int getRoot(int u){ return root[u] == -1 ? u : root[u] = getRoot(root[u]); }
    int getSize(int u){ return size[getRoot(u)]; }
    bool same(int a, int b){
        return getRoot(a) == getRoot(b);
    }
    bool merge(int a, int b){
        int u = getRoot(a);
        int v = getRoot(b);
        if(u == v) return false;
        root[u] = v;
        size[v] += size[u];
        return true;
    }
private:
    vector<int> root;
    vector<int> size;
};

int main(){
    int N, M; cin >> N >> M;
    UnionFind uf(N);
    for(int i=0;i<M;i++){
        int a, b; cin >> a >> b;
        --a; --b;
        uf.merge(a, b);
    }
    int res = -1;
    for(int i=0;i<N;i++) if(uf.getRoot(i) == i) ++res;
    cout << res << endl;
}

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

int main(){
   string a,b,c;
   cin >> a >> b >> c;
   if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
      cout << "YES";
   }else{
      cout << "NO";
   }
   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void shellSort(int *,int);
int formula(int,int *);
void insertionSort(int *,int,int);

int cnt=0;

int main(){
  int i;
  int num;
  int array[1000000];
 
  scanf("%d",&num);
 
  for(i=0;i<num;i++){
    scanf("%d",&array[i]);
  } 

  shellSort(array,num);
  printf("%d\n",cnt);
  for(i=0;i<num;i++){
    printf("%d\n",array[i]);
  } 
 return 0;
}

void shellSort(int NUM[],int num){
  int i;
  int m_count=0;
  int recursion[1000];
  
  m_count=formula(num,recursion);
 
  printf("%d\n",m_count);
  for(i=0;i<m_count;i++){
    if(i!=0) printf(" ");
    printf("%d",recursion[i]);
  }
  printf("\n");
  for(i=0;i<m_count;i++){
    insertionSort(NUM,num,recursion[i]);
  }
}

void insertionSort(int NUM[],int num,int recursion){
  int i,j;
  int mask;

  for(i=recursion;i<num;i++){
    mask=NUM[i];
    j=i-recursion;
    while(j>=0&&NUM[j]>mask){
      NUM[j+recursion]=NUM[j];
      j=j-recursion;
      cnt++;
    }
    NUM[j+recursion]=mask;
  }
}

int formula(int num,int array[]){
  int i,j;
  int count=1;
  int mask[1000];
  
  mask[0]=1;

  while(1){
    mask[i+1]=3*mask[i]+1;
    if(mask[i+1]>num)break;
    count++;
    i++;
  }
 
  j=count-1;
 
  for(i=0;i<count;i++){
    array[j]=mask[i];
    j--;
  }
  return count;
}

Measured memory_bytes: 4516
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    int64_t n;
    cin >> n;
    int64_t min = n - 1;
    int64_t nn = int64_t(sqrt((double)n));
    // cerr << nn << endl;
    for (int64_t i = 1; i <= nn; ++i) {
        auto j = n / i;
        if ((i * j) != n) {
            continue;
        }
        if ((i + j - 2) < min) {
            min = i + j - 2;
        }
    }
    cout << min << endl;
}


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

using namespace std;

#define int long long

const int N = 1e5 + 7, mod = 998244353, base = 716070898, sz = 1005;
vector<int> g[3][N], m(3), power(N);

int n, grundy[3][N], sum[4][sz]; // sum of powers of each grundy value

void dfs(int idx, int u){
	if(g[idx][u].empty()) {
		grundy[idx][u] = 0;
		return;
	}
	set<int> num;
	for(auto v : g[idx][u]){
		if(grundy[idx][v] == -1) dfs(idx, v);
		num.insert(grundy[idx][v]);
	}
	int mex = 0;
	while(num.count(mex)) ++mex;
	grundy[idx][u] = mex;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n;
	for(int i = 0; i < 3; ++i){
		cin >> m[i];
		for(int j = 0; j < m[i]; ++j){
			int u, v;
			cin >> u >> v;
			if(u > v) swap(u, v);
			g[i][u].push_back(v);
		}
	}
	power[0] = 1;
	for(int i = 1; i < N; ++i) power[i] = (power[i - 1] * base) % mod;
	memset(grundy, -1, sizeof(grundy));
	for(int i = 0; i < 3; ++i){
		for(int j = 1; j <= n; ++j){
			if(grundy[i][j] == -1) dfs(i, j);
		}
	}
	
	for(int i = 0; i < 3; ++i){
		for(int j = 1; j <= n; ++j){
			(sum[i][grundy[i][j]] += power[j]) %= mod;
		}
	}
	
	for(int i = 0; i < sz; ++i){
		for(int j = 0; j < sz; ++j){
			if((i ^ j) < sz) (sum[3][i ^ j] += sum[0][i] * sum[1][j]) %= mod;
		}
	}
	int ans = 0;
	for(int i = 0; i < sz; ++i) (ans += sum[2][i] * sum[3][i]) %= mod;
	cout << ans;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

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

    map<string,int> mp;

    for (size_t i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    

    int ans;
    cout << mp.size() << endl;

    return 0;
}

Measured memory_bytes: 19176
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll x, y, z;
  int i = 0;
  scanf("%lld%lld%lld", &x, &y, &z);
  ll ans = 0;
  for (;; i++)
  {
    if (ans > x)
      break;
    ans = y * i + z * (i + 1);
  }
  printf("%lld\n", MIN(i - 2, x));
  return 0;
}

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

int main()
{
	int n;
	cin>>n;
	
	long long int a[n];
	
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	
	
	cout<<abs(a[n-1]-a[0]);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<typeinfo>
#include<numeric>
#include<complex>
#include<memory>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cWeightEdges=vector<vector<pair<int,int>>>;
using cEdges=vector<vector<int>>;

int main(){
	int H,W;
	cin>>H>>W;
	vector<string> C(H);
	for(auto& val:C)
		cin>>val;

	long long ans=0;
	for(int cnt=1;cnt<W;++cnt){
		vector<vector<long long>> dp(H+1,vector<long long>(H+1,LLONG_MAX));
		vector<vector<long long>> cost(H+1,vector<long long>(H+1,0));

		for(int i=0;i<H;++i){
			int L=i,R=0;
			while(L<H && R<H){
				if(C[H-L-1][cnt-1]==C[H-R-1][cnt])++cost[i][0];
				++L,++R;
			}
		}
		for(int i=1;i<H;++i){
			int L=0,R=i;
			while(L<H && R<H){
				if(C[H-L-1][cnt-1]==C[H-R-1][cnt])++cost[0][i];
				++L,++R;
			}
		}

		for(int i=0;i<H;++i){
			int j=1;
			while(j+i<H){
				cost[j+i][j]=(C[H-i-j][cnt-1]==C[H-j][cnt]?cost[j+i-1][j-1]-1:cost[j+i-1][j-1]);
				++j;
			}
		}

		for(int i=0;i<H;++i){
			int j=1;
			while(j+i<H){
				cost[j][j+i]=(C[H-j][cnt-1]==C[H-i-j][cnt]?cost[j-1][j+i-1]-1:cost[j-1][j+i-1]);
				++j;
			}
		}

		for(int i=0;i<=H;++i){
			for(int j=0;j<=H;++j){
				if(i==0 && j==0){
					dp[i][j]=0;
				}
				else{
					if(i>0){
						dp[i][j]=min(dp[i][j],dp[i-1][j]+cost[i-1][j]);
					}

					if(j>0){
						dp[i][j]=min(dp[i][j],dp[i][j-1]+cost[i][j-1]);
					}
				}
			}
		}
		ans+=dp[H][H];
	}

	cout<<ans<<endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 1900
S = int(input())

# if S == (10**18):
#     print(0, 0, 10**9, 0, 1, 10**9)
#     exit()

X1, Y1 = 0, 0

X2 = 10**9
Y3 = -(-S//(10**9))

X3 = 1
Y2 = -(S%-(10**9))

print(X1, Y1, X2, Y2, X3, Y3)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
using namespace std;
typedef pair<int,int>pii;
int n,m;
int a[510][510];
vector<pair<pii,pii> >opt;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++){
		int t=(i&1?1:-1),e=(i&1?m:1);
		for(int j=m-e+1;j<=m&&j>=1;j+=t){
			// cout<<"Go: "<<i<<' '<<j<<endl;
			if(a[i][j]&1){
				if(j==e){
					if(i<n){
						opt.pb(mp(mp(i,j),mp(i+1,j)));
						a[i+1][j]++,a[i][j]--;
					}
				}else{
					opt.pb(mp(mp(i,j),mp(i,j+t)));
					a[i][j+t]++,a[i][j]--;
				}
			}
		}
	}
	cout<<opt.size()<<endl;
	for(auto i:opt){
		printf("%d %d %d %d\n",i.first.first,i.first.second,i.second.first,i.second.second);
	}
	return 0;
}


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

int main(void) {
    long long int X;
    cin >> X;
    int year = 0;
    long long int yokin = 100;
    while (yokin < X) {
        year++;
        long long int tmp =  floor(yokin * 0.01);
        yokin += tmp;
    }
    printf("%d\n" ,year);
    return 0;
}

Measured memory_bytes: 3808
input();a=list(map(int,input().split()))
b1,b2,b4=0,0,0
for i in a:
  if i%2!=0: b1+=1
  elif i%4==0: b4+=1
  elif i%2==0: b2+=1
print('Yes' if b1<=b4 else 'No' if b2 else 'Yes' if b1<=b4+1 else 'No')

Measured memory_bytes: 20132
#C
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i in range(M)]

on = [[] for i in range(N)]
for ab in AB:
    u,v = ab
    if v-1 not in on[u-1]:
        on[u-1].append(v-1)
    if u-1 not in on[v-1]:
        on[v-1].append(u-1)
    
ans = 0
for i in range(N):
    nh = H[i]
    non = on[i]
    
    flag = True
    for o in non:
        if H[o] >= nh:
            flag = False
            break
            
    if flag:
        ans+=1
        
print(ans)
    


Measured memory_bytes: 104536
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, q, x, y, a[20000000]; string c;
int main() {
	while(cin >> n >> q, n + q) {
		fill(a, a + n * n * n / 32 + 1, 0);
		for(int i = 0; i < q; i++) {
			cin >> c >> x >> y; x--, y--;
			if(c == "xy") {
				for(int j = 0; j < n; j++) {
					int w = x * n * n + y * n + j;
					a[w >> 5] |= (1 << (w & 31));
				}
			}
			if(c == "xz") {
				for(int j = 0; j < n; j++) {
					int w = x * n * n + j * n + y;
					a[w >> 5] |= (1 << (w & 31));
				}
			}
			if(c == "yz") {
				for(int j = 0; j < n; j++) {
					int w = j * n * n + x * n + y;
					a[w >> 5] |= (1 << (w & 31));
				}
			}
		}
		int ret = 0;
		for(int i = 0; i <= n * n * n / 32; i++) ret += __builtin_popcount(a[i]);
		cout << n * n * n - ret << endl;
	}
}

Measured memory_bytes: 18252
def main():
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op == "?":
        return False
    if op == "+":
        ans = a+b
    elif op == "-":
        ans = a-b
    elif op == "*":
        ans = a*b
    else:
        ans = a//b
    print(ans)
    return True

while main():
    pass


Measured memory_bytes: 5596
#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#include <numeric>
#include <set>
#include <queue>
#include <deque>
#include <array>
#include <string>
#include <cmath>
#include <random>
#include <ctime>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;

int32_t main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	const int M = 1e9 + 7;
	int n, k;
	cin >> n >> k;
	const int N = 2000;
	vi cnt(N);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		--x;
		for (int j = x + 1; j < N; j++) {
			(ans += (ll)k * cnt[j]) %= M;
		}
		cnt[x]++;
	}
	int pref = 0;
	for (int i = 0; i < N; i++) {
		(ans += (k * (k - 1LL) / 2 % M * pref % M * cnt[i])) %= M;
		pref += cnt[i];
	}
	cout << ans;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    M = int(input())
    T = [input() for _ in range(M)]

    s = Counter(S)
    t = Counter(T)
    result = 0

    for key, value in s.items():
        if value - t[key] > result:
            result = value - t[key]

    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,k;
    cin>>n>>k;
    int v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int ans=0;
    for(int i=1;i<=min(k,n);i++){
        for(int j=0;j<=i;j++){
            int l=j,r=n-(i-j);
            vector<int> mi;
            int sum=0;
            for(int a=0;a<l;a++){
                sum+=v[a];
                if(v[a]<0){
                    mi.push_back(v[a]);
                }
            }
            for(int a=r;a<n;a++){
                sum+=v[a];
                if(v[a]<0){
                    mi.push_back(v[a]);
                }
            }
            sort(mi.begin(),mi.end());
            for(int a=0;a<min(k-i,(int)mi.size());a++){
                sum-=mi[a];
            }
            ans=max(ans,sum);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int a[1001],ta[1001],tta[1001];
int dp[1000021],dp2[1000010];
const int INF=99999999;
int main(){
	a[1]=1,ta[1]=1,tta[1]=1;
	int cnt=1;
	for(int i=2;i<=1000;i++)a[i]=i+a[i-1];
	for(int i=2;i<=1000;i++){
	ta[i]=a[i]+ta[i-1];
	if(ta[i]%2==1)tta[++cnt]=ta[i];
	}

	fill(dp,dp+1000001,INF);
	fill(dp2,dp2+1000001,INF);
	dp[0]=0,dp2[0]=0;
	for(int i=1;i<=200;i++){
		for(int j=1;j<=1000000;j++){
		if(j>=ta[i])dp[j]=min(dp[j],dp[j-ta[i]]+1);
		}//
	}//endfor
	for(int i=1;i<=100;i++){
		for(int j=1;j<=1000000;j++){
		if(j>=tta[i])dp2[j]=min(dp2[j],dp2[j-tta[i]]+1);
		}
	}//endfor
	int n;
	while(true){
	cin>>n;
	if(n==0)break;
	cout<<dp[n]<<" "<<dp2[n]<<endl;
	}//endwhile
	return 0;
}

Measured memory_bytes: 8984
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	//Variables
	public int size;
	public int[][] graph;
	int[] distances;
	int currentV;
	
	public void printGraph() {
		for(int i = 0; i < size; i++) {
			for(int j = 0; j < size; j++) {
				if(j == size - 1) {
					System.out.print(graph[i][j]);
				} else
					System.out.print(graph[i][j]+ " ");
			}
			System.out.println();
		}
	}
	
	public void dijkstra(int source) {
		
	
		// create a storage for all the distances
		distances = new int[size];
		
		//initialize their values
		for(int i = 0; i < size; i++) {
			distances[i] = Integer.MAX_VALUE;
		}
		
		ArrayList<Integer> S = new ArrayList<Integer>(size);
		for(int i = 0; i < size; i++) S.add(i);
		
		distances[source] = 0; // distance is 0 
		
		while(S.isEmpty() == false) {
			
			int closestV = getClosest(S);
	
			// mark it as visited
			S.remove(S.indexOf(closestV));
			
			
			
			LinkedList<Integer> neighbors = getNeighbors(closestV);
			
			for(int i = 0; i < neighbors.size(); i++) {
				int aNeighbor = neighbors.get(i);
				if(S.contains(aNeighbor))
					distances[aNeighbor] = Math.min(distances[aNeighbor], distances[closestV] + graph[closestV][aNeighbor]);
			}
		}
	}
	
	public void printDist() {
		for(int i = 0; i < size; i++) {
			System.out.println(i + " " + distances[i]);
		}
	}
	
	public LinkedList<Integer> getNeighbors(int v){
		LinkedList<Integer> ns = new LinkedList<Integer>();
		for(int i = 0; i < size; i++) {
			if(graph[v][i] > 0)
				ns.add(i);
		}
		
		return ns;
	}
	
	public int getClosest(ArrayList<Integer> vertexList) {
		int v = vertexList.get(0);
		double minDist = distances[v];
		
		for(int i = 1; i < vertexList.size();i++) {
			if(distances[vertexList.get(i)] < minDist) {
				v = vertexList.get(i);
				minDist = distances[vertexList.get(i)];
			}
		}
		return v;
		
	}
	public static void main(String[] args) {
		
		Main s = new Main();
		
		Scanner in = new Scanner(System.in);
		
		s.size = in.nextInt();
		s.graph = new int[s.size][s.size];
		
		// create graph
		for(int i = 0; i < s.size; i++) {
			int u = in.nextInt();
			int kDegrees = in.nextInt();
			
			for(int k = 1; k <= kDegrees; k++) {
				int v = in.nextInt();
				int weight = in.nextInt();
				s.graph[u][v] = weight;
			}
		}
		

		s.dijkstra(0);
		
		s.printDist();
		
	}

}



Measured memory_bytes: 38696
#include<bits/stdc++.h>
#define ULL unsigned long long
#define LL long long
#define Max 105
#define mem(a,b) memset(a,(int)b,sizeof(a));
#define pb push_back
#define mp make_pair
#define debug printf("debug\n");
const LL mod=1e9+7;
const ULL base=131;
const LL LL_MAX=9223372036854775807;
using namespace std;
int n,k;
LL a[Max];
priority_queue<LL,vector<LL>,greater<LL> >p;
LL fun(int l,int r){
    //debug
    for(int i=1;i<=l;i++)
        p.push(a[i]);
    for(int j=1,t=n;j<=r;j++,t--)
        p.push(a[t]);
    int opt=k-l-r;
    while(p.size() && p.top()<0 && opt)
        p.pop(),opt--;
    LL sum=0;
    while(p.size())
        sum+=p.top(),p.pop();
    return sum;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    LL sum=0;
    for(int i=0;i<=k;i++){
       for(int j=0;(i+j)<=min(n,k);j++){
            sum=max(fun(i,j),sum);
       }
    }
    printf("%lld\n",sum);
    return 0;
}


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

x = 1
while True:
    A = int(x * 0.08)
    B = int(x * 0.1)
    if A == a and B == b:
        print(x)
        break
    elif A > a or B > b:
        print(-1) 
        break
    x += 1

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	ll k;
	cin >> n >> k;
	
	vector<int> a(n);
	
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i]--;
	}
	
	int cur = 0;
	vector<bool> look(n, false);
	vector<int> to;
	
	to.push_back(cur);

	while( !look[cur] ) {
		look[cur] = true;
		cur = a[cur];
		to.push_back(cur);
	}
	
	to.pop_back();
	
	int x, y;
	for(int i = 0; i < to.size(); ++i) {
		if( to[i] == cur ) {
			x = i;
			break;
		}
	}
	
	y = (int)to.size() - x;
	
	if( x > k ) {
		cout << to[k] + 1 << endl;
	} else {
		int m = ((k - x) % y) + x;
		cout << to[m] + 1 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 5092
N, K = [int(i) for i in input().split()]
S = input()
arr_0,arr_1 = [],[]
val = 1
temp = S[0]
if temp == '0':
    arr_1 += [0]
for s in S[1:]+"_":
    if s == temp:
        val+=1
    else:
        if temp=="1":
            arr_1 += [val]
        else:
            arr_0 += [val]
        val = 1
    temp = s
if S[-1] == "0":
    arr_1 += [0]

max_ = sum(arr_0[:K]+arr_1[:K+1])
for i in range(1, len(arr_0)-K+1):
    if (arr_0[i+K-1]+arr_1[i+K]) > (arr_0[i-1]+arr_1[i-1]):
        tmp = sum(arr_0[i:i+K])+sum(arr_1[i:i+K+1])
        if tmp > max_:
            max_ = tmp
print(max_)

Measured memory_bytes: 5020
#include <iostream>
#include <set>
#define MAX(a,b) ((a>b)?(a):(b))
using namespace std;

int main(void){
	int n,m;
	int a;
	while(cin>>n>>m,n||m){
		std::set<int> ms;
		for(int i=0;i<n+m;i++)cin>>a,ms.insert(a);
		int m=*(ms.begin());
		for(__typeof(ms.begin()) it=++ms.begin(),b=ms.begin();it!=ms.end();it++,b++){
			m=MAX(m,*it-*b);
		}
		cout<<m<<endl;
	}
	return 0;
}

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

int main() {
  int A[5];
  int k;
  
  for(int i=0; i<5; i++) {
    cin >> A[i];
  }
  cin >> k;
  
  if(A[4]-A[0] <= k) {
    cout << "Yay!";
  } else {
    cout << ":(";
  }
  return 0;
}


Measured memory_bytes: 384
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);

  // v.at(0) = 1;
  for (int i = 1; i < n; i++) {
    cin >> v.at(i);
  }
  vector<int> v1(n, 0);
  for (int i = 1; i < n; i++) {
    v1.at(v.at(i) - 1)++;
  }
  // v1.at(0)++;

  rep(i, n) { cout << v1.at(i) << endl; }
  return 0;
}


Measured memory_bytes: 4844
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 

 
 
const int INF = 10000000;

int main(){
	int n, m;
	string s;
	int a, b;
	while(cin>>n>>m && n > 0 && m > 0){
		map<int, string> ms;
		map<string, int> me;
		rep(i, n){
			cin>>s>>a>>b;
			ms[b - a + 1] = s;
			me[s] = b;
		}
		rep(i, m){
			cin>>a;
			auto it = ms.upper_bound(a);
			if(it == ms.begin()){
				cout<<"Unknown"<<endl;
				continue;
			}
			--it;
			if(a <= me[it->se]) cout<<it->se<<" "<<a - it->fi + 1<<endl;
			else cout<<"Unknown"<<endl;
		}
	}
	
}

Measured memory_bytes: 3216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
	    String str=reader.readLine();
	    String s[]=str.split(" ");
	    int w=Integer.parseInt(s[0]);
	    int h=Integer.parseInt(s[1]);
	    int c=Integer.parseInt(s[2]);

	    int fee=0;
	    
	    int gc=gcd(w,h);
	    int gw=w/gc;
	    int gh=h/gc;
	    fee=(gw*gh)*c;
	    
	    System.out.println(fee);
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static int gcd (int a, int b){
	return b>0?gcd(b,a%b):a;
    }
    static int lcm (int a, int b) {
	return a*b/gcd(a,b);
    }
}



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

const long long MOD = 1000000007;

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

    long long cntA = 0;
    for (long long i = 0; i < N - 1; i++) {
        for (long long j = i + 1; j < N; j++) {
            if (A[i] > A[j]) {
                cntA++;
            }
        }
    }
    long long cntB = 0;
    for (long long i = 0; i < N; i++) {
        for (long long j = 0; j < N; j++) {
            if (A[j] > A[i]) {
                cntB++;
            }
        }
    }

    cout << ((cntA * K) % MOD + (cntB * ((K * (K - 1) / 2) % MOD))) % MOD << endl;
    return 0;
}


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

int main(void){
  int MeatTemp;
  int TargetTemp;
  int FrozenStateTime;
  int TransrateTime;
  int NotFrozenStateTime;

  cin >> MeatTemp >> TargetTemp >> FrozenStateTime
      >> TransrateTime >> NotFrozenStateTime;

  if(MeatTemp >= 0){
    cout << (TargetTemp - MeatTemp) * NotFrozenStateTime << endl;
  }else{
    cout << (TargetTemp*NotFrozenStateTime)-(MeatTemp*FrozenStateTime)+TransrateTime << endl;
  }
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
int read(){
	int g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const int N=3e5+5;
const int mod=1e9+7;
int f[N][3][3],n,ans;
char s[N];
signed main(){
	scanf("%s",s+1);n=strlen(s+1);
	f[0][0][0]=1;
	for(int i=0;i<n;i++){
		for(int x=0;x<=2;x++)for(int y=0;y<=2;y++)if(f[i][x][y]){
			if(s[i+1]!='0'){
				if(y==0)f[i+1][x+(x!=2)][y]=(f[i+1][x+(x!=2)][y]+f[i][x][y])%mod;
				else f[i+1][x][y-1]=(f[i+1][x][y-1]+f[i][x][y])%mod;
			}
			if(s[i+1]!='1'){
				if(y==2)f[i+1][x][y-1]=(f[i+1][x][y-1]+f[i][x][y])%mod;
				else f[i+1][x][y+1]=(f[i+1][x][y+1]+f[i][x][y])%mod;
			}
		}
	}
	for(int x=0;x<=2;x++)for(int y=0;y<=x;y++)ans=(ans+f[n][x][y])%mod;
	return cout<<ans,signed();
}

Measured memory_bytes: 14560
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    hw = sum(A)

    if N >= hw:
        print(N-hw)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 68132
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ll long long int
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl

using namespace std;

int main() {
    IOS;

    ll n; cin>>n;
    vec<ll> v(n);
    forn(i) cin>>v[i];

    for(ll i=1; i<n; i++){
        if( v[i] > v[i-1] ) v[i]--;
        else if( v[i] == v[i-1] ) continue;
        else{
            cout<<"No"<<endl; return 0;
        }
    }

    cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
A = list(map(int,input().split()))
ans = "No"

odd = 0
even = 0
four = 0

for i in A:
    if i % 4 == 0:
        four += 1
    elif i % 2 == 0:
        even += 1
    else:
        odd += 1
        
if four >= even + odd - 1:
    ans = "Yes"

if four >= odd and even > 1:
    ans = "Yes"
    
print(ans)

Measured memory_bytes: 15020
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define cout (cout << setprecision(12))

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll row = 0, ans = 0;
//
//    while (true) {
//        if (row + a <= n) {
//            row += a;
//            ans += a;
//        }
//        else {
//            ans += n - row;
//            break;
//        }
//
//        if (row + b <= n) {
//            row += b;
//        }
//        else {
//            break;
//        }
//    }

    ll loop = n / (a + b);
    row = (a + b) * loop;
    ll blue = a * loop;

    if (row == n) {
        cout << blue << endl;
        return 0;
    }

    if (row + a <= n) {
        row += a;
        blue += a;
    } else {
        blue += n - row;
    }

    cout << blue << endl;
}

Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n,t,a;
	cin>>n>>t>>a;
	int ind=-1;
	long double mi=INT_MAX;
	for(int i=0;i<n;i++){
		int h;
		cin>>h;
		long double temp=t-(h*0.006);
		//cout<<temp<<" ";
		if(mi>abs(temp-a)){
			mi=abs(temp-a);
			ind=i+1;
		}
	}
	cout<<ind<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N,answer = 0;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for (int i = 0; i < N; i++)
    {
        if(i%2 == 0){
            answer += a.at(i);
        }if(i%2 == 1){
            answer -= a.at(i);
        }
        
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3108
#include <cstdio>
#include <utility>
#include <vector>
#include <queue>
#include <functional>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll inf = 1e18;

ll n, m, k, s;
ll p, q;
ll c[123456];
vector<pll>ab;

struct edge { ll to, cost; };

ll dist[123456];
void dijkstra(vector<edge>graph[],ll start)
{
	fill(dist, dist + 123456, inf);
	dist[start] = 0;
	priority_queue<pll,vector<pll>,greater<pll>> que;
	que.push({ 0, start });
	while (!que.empty())
	{
		pll par = que.top(); que.pop();
		ll pass = par.first;
		ll vecid = par.second;
		if (dist[vecid] < pass)continue;
		for (auto ed : graph[vecid])
		{
			if (pass + ed.cost < dist[ed.to])
			{
				dist[ed.to] = pass + ed.cost;
				que.push({ dist[ed.to],ed.to });
			}
		}
	}
}

vector<edge>zombgr[123456];
vector<edge>truegr[123456];

int main()
{
	scanf("%lld %lld %lld %lld", &n, &m, &k, &s);
	scanf("%lld %lld", &p, &q);
	for (ll i = 0; i < k; ++i)
	{
		scanf("%lld", c + i);
		zombgr[0].push_back({ c[i],0 });
	}
	for (ll j = 0;j < m;++j)
	{
		ll a, b;
		scanf("%lld %lld", &a, &b);
		ab.emplace_back(a, b);
		zombgr[a].push_back({ b,1 });
		zombgr[b].push_back({ a,1 });
	}
	dijkstra(zombgr, 0);
	ll distn = dist[n];
	for (auto ed : ab)
	{
		ll a = ed.first, b = ed.second;
		if (dist[a] && dist[b])
		{
			if (b == n)
			{
				truegr[a].push_back({ b,0 });
				truegr[b].push_back({ a,(dist[a] <= s) ? q : p });
			}
			else
			{
				truegr[a].push_back({ b,(dist[b] <= s) ? q : p });
				truegr[b].push_back({ a,(dist[a] <= s) ? q : p });
			}
		}
	}
	dijkstra(truegr, 1);
	printf("%lld\n", dist[n]);
	return 0;
}

Measured memory_bytes: 32916
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
#define lint long long
#define ll long long
static const int INF = 1 << 22;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/*******source code below********/
int main(void) {

	int N, H; cin >> N >> H;
	vector<pii> sw(N);
	int amax = 0; int ai;
	for (int i = 0; i < N; i++)
	{
		int a, b; cin >> a >> b;
		if (a > amax) {
			amax = a;
			ai = i;
		}
		sw[i] = make_pair(b, a);
	}
	sort(sw.begin(), sw.end());
	reverse(all(sw));
	int cnt = 0; int j = N-1;
	for (int i = 0; i < N; i++)
	{
		if (sw[i].first >=  amax) {
			H -= sw[i].first;
			cnt++;
			if (H <= 0) break;
			continue;
		}

	}
	if (H <= 0) {
		cout << cnt << endl;
		return 0;
	}
	if (H %amax == 0) {
		cnt += H / amax;
	}
	else {
		cnt += H / amax + 1;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>

using namespace std;

int main(void) {
  double min, max, in;

  cin >> in;
  min = in;
  max = in;

  while(cin >> in) {
    if(min > in) {
     min = in;
    }

    if(max < in) {
      max = in;
    }
  }

  cout << (max - min) << endl;
  return 0;
}

Measured memory_bytes: 1280
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int num = Integer.parseInt(br.readLine());
        ArrayList<Restaurant> restaurants = new ArrayList<>();
        for (int i = 0; i < num; ++i) {
            String[] temp = br.readLine().split(" ");
            restaurants.add(new Restaurant(i + 1, Integer.parseInt(temp[1]), temp[0]));
        }

        Collections.sort(restaurants);
        for (Restaurant x : restaurants) {
            bw.append(x.order + "\n");
        }
        bw.flush();
    }
}

class Restaurant implements Comparable<Restaurant> {
    int order, rating;
    String item;

    public Restaurant(int order, int rating, String item) {
        this.order = order;
        this.rating = rating;
        this.item = item;
    }

    @Override
    public int compareTo(Restaurant that) {
        if (this.item.equals(that.item)) {
            return that.rating - this.rating;
        } else {
            return this.item.compareTo(that.item);
        }
    }
}

Measured memory_bytes: 20564
#include <iostream>
#include <sstream>
#include <vector>
#include <bitset>
using namespace std;

long long int calc(long long int n)
{
    long long int ans = 0;
    if(n % 2 == 0)
    {
        long long int cnt = (long long int)(n / 2);
        if(cnt % 2 == 0)
        {
            ans = 0;
        }
        else if(cnt % 2 == 1)
        {
            ans = 1;
        }
        ans = ans ^ n;
    }
    else if(n % 2 == 1)
    {
        long long int cnt = (long long int)((n+1) / 2);
        if(cnt % 2 == 0)
        {
            ans = 0;
        } 
        else if(cnt % 2 == 1)
        {
            ans = 1;
        }
    }

    return ans;
}

int main()
{
    long long int A, B;
    int sum[42] = {0};
    cin >> A >> B;

    long long int ans = calc(A-1) ^ calc(B);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

rain = 0
for i in 1..n do
    if i.odd? 
        rain += a[i-1]
    else
        rain -= a[i-1]
    end
end

print rain," "


for i in 1..n-1 do
    rain = 2*(a[i-1] - (rain/2))
    print rain, " "
end

Measured memory_bytes: 13316
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
#define int long long
signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    int pra[26];
    memset(pra, -1,sizeof(pra));
    vector<vector<int> > v(n, vector<int> (26));
    for(int i=n-1;i>=0;i--){
    	int num = s[i] - 'a';
    	pra[num] = i;
    }
    for(int i=n-1;i>=0;i--){
    	for(int j=0;j<26;j++){
    		if(pra[j] == -1) v[i][j] = -1;
    		else if(pra[j] <= i) v[i][j] = n - i + pra[j];
    		else v[i][j] = pra[j] - i;
    	}
        int num = s[i] - 'a';
        pra[num] = i;
    }
    int ans = 1;
    int tnow = 0;
    int snow = 0;
    if(s[0] == t[0]) tnow++;
    while(tnow < m){
    	if(v[snow][t[tnow] - 'a'] == -1) {
    		cout << -1 << endl;
    		return 0;
    	}
    	ans += v[snow][t[tnow] - 'a'];
    	snow += v[snow][t[tnow] - 'a'];
    	snow %= n;
    	tnow++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 24656
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define rep(i,s,e)  for(int i=s;i<e;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)

#define TRACE
#ifdef TRACE
#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
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set

const int mxn=1e5+13;
int n;

int h[mxn];
int dp[mxn];

int func(int idx){
	if(idx>=n) return 0;

	if(dp[idx]!=-1) return dp[idx];

	int ans;

	if(idx<n-2){
		ans=min(abs(h[idx+1]-h[idx])+func(idx+1),abs(h[idx+2]-h[idx])+func(idx+2));
	}
	else if(idx==n-2){
		ans=abs(h[idx+1]-h[idx]);
	}
	else if(idx==n-1){
		ans=0;
	}

	return dp[idx]=ans;
}

void solve(){
	cin>>n;

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

	memset(dp,-1,sizeof(dp));

	int ans=func(0);

	// for(int i=0;i<n;i++){
	// 	trace(dp[i]);
	// }

	cout<<ans<<endl;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
// #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3328
#include<stdio.h>

int main()
{
    int n,i;
    long long int sum=0;
    scanf("%d",&n);
    for(i=1; i<=n; i++) {
        if((i%3!=0)&&(i%5!=0))
            sum=sum+i;
    }
    printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 1728
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A[100010], B[100010];
    int N; cin >> N;
    bool same = true;
    int sum = 0;
    int small = INF2;
    rep(i, N) {
        cin >> A[i] >> B[i];
        if (A[i] != B[i]) same = false;
        sum += A[i];
        if (A[i] - B[i] > 0) small = min(small, B[i]);
    }
    if(same) {cout << 0 << endl; return 0;}
    cout << sum - small << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
  string s;
  cin>>s;
  for(auto it=s.begin();it!=s.end();it++){
    if(*it=='7'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var R = int.Parse(ss[0]);
            var G = int.Parse(ss[1]);
            var B = int.Parse(ss[2]);
            var N = int.Parse(ss[3]);

            var count = 0;
            for (int r = 0; true; r++)
            {
                var sumR = R * r;
                if (sumR > N) break;
                for (int g = 0; true; g++)
                {
                    var sumRG = sumR + G * g;
                    if (sumRG > N) break;

                    if ((N - sumRG) % B == 0) count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 11092
INF = float("inf")
cnt = 0
def merge(A, left, mid, right):
    global cnt
    L = A[left: mid] + [INF]
    R = A[mid: right] + [INF]
    i = j = 0
    limit = mid - left
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
            if i >= limit:
                A[k + 1: right] = R[j: -1]
                break
        else:
            cnt += limit - i
            A[k] = R[j]
            j += 1
def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
n = int(input())
S = list(map(int, input().split()))
mergeSort(S, 0, n)
print(cnt)



Measured memory_bytes: 27480