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

int main(){

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

    long long ans = 0;
    long long s = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == 0){
            ans += s/2;
            s = 0;
        }else{
            s += a[i];
        }
    }
    ans += s/2;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define sze 10009
//#define mod 1000000007
using namespace std;
const int mod =1e9+7;
int h,w;
char arr[1009][1009];
int dp[1009][1009];
int dp_fn(int r,int c){


    if(r==h-1 && c==w-1){
        return dp[r][c]=1;
    }
     if(dp[r][c]!=-1){
        return (dp[r][c])%mod;
     }
    if(r>=h || c>=w ||r<0 ||c<0 || arr[r][c]=='#'){
        return 0;
    }
   /* if(arr[r][c]=='#'){
        return 0;
    }   */

    return dp[r][c]=((dp_fn(r+1,c))%mod+(dp_fn(r,c+1))%mod)%mod;


}

int32_t main(){
      cin>>h>>w;
       char ch;
       for(int i=0;i<h;i++){
          for(int j=0;j<w;j++){
              cin>>arr[i][j];
          }
       }

      memset(dp,-1,sizeof(dp));
      cout<<(dp_fn(0,0))%mod<<endl;
      //else cout<<"false"<<endl;
      //cout<<res<<endl;


}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define per(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    string s;
    cin>>s;
    int f,t;
    rep(i,s.size()){
        if(s[i]=='A'){
            f = i;
            break;
        }
    }
    per(i,s.size()){
        if(s[i]=='Z'){
            t = i;
            break;
        }
    }
    
    cout << t-f+1<< endl;
    return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var (
		N, K, ans int
		S         string
	)
	fmt.Scan(&N, &K, &S)

	block := 1
	for i := 1; i < len(S); i++ {
		if S[i-1] != S[i] {
			block++
		}
	}

	if block/2 > K {
		ans = N + K*2 - block
	} else {
		ans = N - 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

int main(int argc, char *argv[]) {
	int n;
	scanf("%d",&n);
	int a[4];
	for(int i=0;i<4;i++){
		a[i]=n%10;
		n/=10;
	}
	if(a[0]==a[1]&&a[1]==a[2]||a[1]==a[2]&&a[2]==a[3]){
		printf("Yes");
	}
	else printf("No");
	return 0;
}

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

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

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

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

    int sum = 0;
    for (int i = 0; i < K; i++)
    {
        sum += p.at(i);
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3536
import java.util.*;

public class Main {
	Scanner sc;
	
	void run() {
		sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) break;
			
			int[] a = new int[n];
			for (int i=0;i<n;i++) {
				a[i] = sc.nextInt();
			}
			
			int sum;
			int correct = Integer.MIN_VALUE;
			
			for (int i=0;i<n;i++) {
				sum = a[i];
				if (sum > correct)
					correct = sum;
				for (int j=i+1;j<n;j++) {
					sum += a[j];
					if (sum > correct)
						correct = sum;
				}
			}
			
			System.out.println(correct);
		}
	}
	
	
	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = li_input()

    D = collections.defaultdict(lambda: 0)
    X = [0, 0]
 
    for a in A:
        D[a] += 1
 
    for k, v in D.items():
        if 2 <= v:
            X.append(k)
        if 4 <= v:
            X.append(k)
 
    X.sort(reverse=True)
 
    print(X[0] * X[1])
 
 
main()


Measured memory_bytes: 19776
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long int  ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define pic pair<ll,char>
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii > 
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
pair < ll , ll > dp[1<<19];
signed main()
{
    fast;
    ll n;
    cin>>n;
    ll i;
    for(i=0;i<(1<<19);i++)
        dp[i].fi = -1e18,dp[i].sec = -1e18;
    for(i=0;i<(1<<n);i++)
    {
        cin>>dp[i].fi;
    }
    for(i=0;i<n;i++)
    {
        for(ll j=0;j<(1<<n);j++)
        {
            if((j&(1<<i)))
            {
                vi temp;
                temp.pb(dp[j].fi);
                temp.pb(dp[j].sec);
                temp.pb(dp[j^(1<<i)].fi);
                temp.pb(dp[j^(1<<i)].sec);
                sort(all(temp));
                reverse(all(temp));
                dp[j].fi = temp[0];
                dp[j].sec = temp[1];
            }
        }
    }
    ll ans = -1;
    for(i=1;i<(1<<n);i++)
    {
        ans = max(ans,dp[i].fi+dp[i].sec);
        cout<<ans<<"\n";
    }
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define range(i, l, r) for(lint (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (lint (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N, K;
    cin >> N >> K;
    lint ans = K;
    range(i, 0, N - 1) ans *= (K - 1);
    cout << ans << "\n";
}


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

int R,C,N,x1,x2,y1,y2;

int online(int x, int y){
	if(x==0) return 1;
	if(y==C) return 2;
	if(x==R) return 3;
	if(y==0) return 4;
	return -1;
}

int main(){
	cin >> R >> C >> N;
	vector<pair<pair<int,int>,int>> v;
	for(int i=1;i<=N;i++){
		cin >> x1 >> y1 >> x2 >> y2;
		int a = online(x1,y1),b = online(x2,y2);
		if(a!=-1 && b!=-1){
			if(a==1) v.push_back({{1,y1},i});
			if(a==2) v.push_back({{2,x1},i});
			if(a==3) v.push_back({{3,-y1},i});
			if(a==4) v.push_back({{4,-x1},i});
			if(b==1) v.push_back({{1,y2},i});
			if(b==2) v.push_back({{2,x2},i});
			if(b==3) v.push_back({{3,-y2},i});
			if(b==4) v.push_back({{4,-x2},i});
		}
	}
	sort(v.begin(),v.end());
	stack<int> s;
	for(int i=0;i<v.size();i++){
		if(s.empty()){
			s.push(v[i].second);
			continue;
		}
		if(v[i].second!=s.top()) s.push(v[i].second);
		else s.pop();
	}
	cout << (s.empty()? "YES":"NO") << endl;
}

Measured memory_bytes: 4980
import sys

n = int(input())
s = [input().strip() for i in range(n)]

dicstok = {}
dicktos = {}

for i in range(n):
  k = s[i]
  v = dicstok.get(k, 0)
  dicstok[k] = v+1

  if(dicktos.get(v+1) == None):
    dicktos[v+1] = set([])
  dicktos[v+1].add(k)
  # setから消す
  if(v>=1):
    dicktos[v].discard(k)


ls = len(dicktos)
l = list(sorted(list(dicktos[ls])))

for k in l:
  print(k)


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

d={}

for n in range(N):
    if d.get(A[n])==None:
        d[A[n]]=1
    else:
        d[A[n]]+=1

d=sorted(d.items(),reverse=True)

cnt=0
ans=0
for i in range(len(d)):
    if cnt==0:
        if d[i][1]>=4:
            ans=d[i][0]**2
            break
        elif d[i][1]>=2:
            temp=d[i][0]
            cnt+=1
    else:
        if d[i][1]>=2:
            ans=temp*d[i][0]
            break
print(ans)
    

Measured memory_bytes: 25552
# N A B C
# l1
# l2
# ...

tmp = input().split()
(N, A, B, C) = (int(tmp[i]) for i in range(4))
L = []
for i in range(N):
    l = int(input())
    L.append(l)
# N = 5
# A = 100
# B = 90
# C = 80
# L = [98, 40, 30, 21, 80]

def recur_function(a, b, c, n):
    if n == N:
        return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else 10**9
    ret0 = recur_function(a + L[n], b, c, n + 1) + 10 if a > 0 else recur_function(a + L[n], b, c, n + 1)
    ret1 = recur_function(a, b + L[n], c, n + 1) + 10 if b > 0 else recur_function(a, b + L[n], c, n + 1)
    ret2 = recur_function(a, b, c + L[n], n + 1) + 10 if c > 0 else recur_function(a, b, c + L[n], n + 1)
    ret3 = recur_function(a, b, c, n + 1)
    return min(ret0, ret1, ret2, ret3)

print(recur_function(0, 0, 0, 0))

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A > B && B >= C && A == B + C) {
    cout << "Yes" << endl;
  } else if (B > A && A >= C && B == A + C) {
    cout << "Yes" << endl;
  } else if (C > A && A >= C && C == A + B) {
    cout << "Yes" << endl;
  } else if (A > C && C >= B && A == B + C) {
    cout << "Yes" << endl;
  } else if (B > C && C >= A && B == A + C) {
    cout << "Yes" << endl;
  } else if (C > B && B >= A && C == A + B) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int iniNum;
        iniNum = scan.nextInt();
        int[] a=new int[iniNum];
        
        for(int i=0; i<iniNum; i++){
            a[i]=scan.nextInt();
        }
        insertionSort(a, iniNum);
    }

    public static void insertionSort(int[] A, int N){ // N個の要素を含む0-オリジンの配列A
        int j, v;
        Pattern pat1 = Pattern.compile("[^0-9 ]");
        for(int i=0; i<N; i++){
            v = A[i];
            j = i - 1;
            
            while(j >= 0 && A[j] > v){
                A[j+1] = A[j];
                j--;
            }
            A[j+1] = v;
            Matcher mat1 = pat1.matcher(Arrays.toString(A));
            System.out.println(mat1.replaceAll(""));
        }
    }
}


Measured memory_bytes: 32536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define  _(x)  cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v)  (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;
long long gcd(long long a, long long b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main() {

    int n,m;
    cn n>>m;

     if(n>=2){
     	n=n*(n-1);
     	n/=2;

     }
     else n=0;

     if(m>=2){
     	m=m*(m-1);
     	m/=2;

     }
     else m=0;

     ct n+m;nl;







    return 0;
}


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

using namespace std;

int main(){
    int N,ma=0,a;
    cin>>N;
    vector<int> p(N);

    for(int i=0;i<N;i++){
        int tmp;
        cin>>tmp;
        p[i]=tmp;
        if(ma<tmp){
            a = i;
            ma = tmp;
        }
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(a!=i){
            ans += p[i];
        }else{ ans += p[i]/2;}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int INF=(1<<21);
int n,M[111][111];
int d[111]; //最短距離を記録（到達不可な時はINF）
void bfs(int s){
  queue<int>q;
  q.push(s); //始点INFを入れる（訪問）
  for(int i=0;i<n;i++) d[i]=INF; //あらかじめINFを入れておく
  d[s]=0;
  while(!q.empty()){
    int u=q.front();
    q.pop(); //キューから頂点uを取り出し訪問
    for(int v=0;v<n;v++){
      if(M[u][v]==0) continue; //辺がない
      if(d[v]!=INF) continue; //訪問したことがある
      d[v]=d[u]+1; //vは未訪問の頂点であり、隣接しているためd[u]に1を足す
      q.push(v); //vを始点に
    }
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<' '<<( (d[i]==INF)?(-1):d[i] )<<endl;
  }
}
int main(){
  int u,k,v;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  bfs(0);
  return(0);
}



Measured memory_bytes: 3104
/*
Author : Hocky Yudhiono
5/31/2020 7:01:04 PM

1. You can sort the query if offline!
2. Don't bring the dp remaining state when dfsing on DP on Tree.
3. Try to reverse (Think from the back) if you stuck.
4. Be careful when submitting Div. 2 D-F, dont waste it on stupid WAs.
5. Try to reduce a problem
*/

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef vector<int> vi;
typedef pair<LL,LL> PLL;
typedef pair<LL,int> PLI;
typedef pair<int,int> PII;
typedef pair<int,int> pii;
typedef vector<vector<LL>> VVL;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define popf pop_front
#define pf push_front
#define popb pop_back
#define mp make_pair
#define pb push_back
#define remove erase
#define fi first
#define se second

//If the time limit is strict, try not to use long double

//Remember to undefine if the problem is interactive
#define endl '\n'
#define DEBUG(X) cout << ">>> DEBUG(" << __LINE__ << ") " << #X << " = " << (X) << endl

const double EPS = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const LL LINF = 4557430888798830399LL;
const double DINF = numeric_limits<double>::infinity();
const LL MOD = 1000000007;
const int dx[8] = {0,0,1,-1,1,-1,1,-1};
const int dy[8] = {1,-1,0,0,1,-1,-1,1};
// Do dir^1 to get reverse direction
const char dch[4] = {'R','L','D','U'};
// const string ds[8] = {"E","W","S","N","SE","NW","SW","NE"};
const double PI = 3.141592653589793;

inline void open(string a){
    freopen((a+".in").c_str(),"r",stdin);
    freopen((a+".out").c_str(),"w",stdout);
}

inline void fasterios(){
    //Do not use if interactive
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

LL a,b;

int main(){
    cin >> a >> b;
    cout << a*b << endl;
    return 0;
}

Measured memory_bytes: 3636
s = input()
flag = False
for i in range(len(s)-1) :
    if s[i] == s[i+1] :
        flag = True
        print(i+1, i+2)
        break
if flag == False :
    for i in range(len(s)-2) :
        if s[i] == s[i+2] :
            flag = True
            print(i+1, i+3)
            break
if not flag :
    print("-1 -1")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
//#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200000];
vll v;
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            v.push(p);
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[60];
void power()
{
    powe[0]=1;
    REP(i,1,15)
    {
        powe[i]=2*powe[i-1];
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 
ll fact[100005];
void factorial()
{
    fact[0]=1;
    REP(i,1,100002)
    {
        fact[i]=mymod(i*fact[i-1], num);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    factorial();
    ll n,k;
    ll A[100005];
    cin>>n>>k;
    REP(i,0,n)
    {
        cin>>A[i];
    }
    sort(A,A+n);
    ll minx=0,maxx=0;
    REP(i,0,n-k+1)
    {
        ll a=mymod(A[i]*fact[n-1-i],num);
        ll b=mymod(modInverse(fact[k-1],num)*modInverse(fact[n-k-i],num),num);
        minx=mymod(minx+mymod(a*b,num),num);
        ll c=mymod(A[n-1-i]*fact[n-1-i],num);
        maxx=mymod(maxx+mymod(c*b,num),num);

    }
    ll diff=mymod((maxx-minx),num);
    cout<<diff<<"\n";
	return 0;
}


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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2);
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"

//----------------------------------------------------------------
ll xor_until(ll x){
  if(x%2==0) return ((x/2)%2) ^ x;
  else return ((x+1)/2)%2;
}

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

  if(a==0){
    prt(xor_until(b));
  } else {
    prt(((xor_until(a-1))^(xor_until(b))));
  }

}


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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin>>n;
  string a[n];
  for(ll i=0; i<n; i++){
    cin>>a[i];    
  }
  string c;
  ll ans[4] = {0};
  for(ll i=0; i<n; i++){
    c = a[i];
    if(c == "AC" ){
      ans[0]++;
    }
    else if(c == "WA" ){
      ans[1]++;
    }
    else if(c == "TLE" ){
      ans[2]++;
    }
    else {
      ans[3]++;
    }    
  }
  cout<<"AC x "<<ans[0]<<"\n";
  cout<<"WA x "<<ans[1]<<"\n";
  cout<<"TLE x "<<ans[2]<<"\n";
  cout<<"RE x "<<ans[3]<<"\n"; 
  
    return 0;
}

Measured memory_bytes: 6736
#include<bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 ll mod=(ll)1e9+7;
 ll dp[1002][1002]; 
 int main(){
  ll m,i,n,j;
  cin>>n>>m;
  vector<string > v(n);
  for(i=0;i<n;i++)
   cin>>v[i];
  for(i=0;i<=n;i++)
   for(j=0;j<=m;j++)
    if(i==0||j==0||v[i-1][j-1]=='#')dp[i][j]=0;
    else if(i==1&&j==1)dp[i][j]=1;
    else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
  cout<<dp[n][m];     
 }

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  
  rep(i,n) cin >> h[i];
  
  rep(i,m){
  int a,b;
    cin >> a >> b;
    a--,b--;
    if (h[a] <= h[b]) ok[a] = false;
    if (h[b] <= h[a]) ok[b] = false;
  }
  
  int ans=0;
  rep(i,n) {
    if (ok[i]) ans++;
  }
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string s;
int main()
{
    cin >>s ;
    if (s=="Sunny")
        cout <<"Cloudy";
    else if (s=="Cloudy")
        cout <<"Rainy";
    else
        cout <<"Sunny";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>
#pragma comment(linker, "/STACK:836777216")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define N 200005

ll Cn2(ll n) {
	if (n < 2) {
		return 0;
	}

	return (n) * (n - 1) / 2;
}

ll a[N];

int main(void) {
	int n;
	scanf("%d", &n);
	map<ll, ll> m;
	REP(i, n) {
		scanf("%lld", &a[i]);
		m[a[i]]++;
	}

	ll total = 0;
	for (map<ll, ll>::iterator it = m.begin(); it != m.end(); it++) {
		total += Cn2((*it).Y);
	}

	REP(i, n) {
		printf("%lld\n", total - (m[a[i]] - 1));
	}

	//scanf("%d", &n);
}

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

using namespace std;

int main() {
  
  int n, k;
  cin >> n >> k;
  
  int vals[n];
  int result[n];
  
  for (int i = 0; i < n; i++) {
    cin >> vals[i];
  }
  
  result[0] = 0;
  result[1] = abs(vals[0] - vals[1]);
  
  for (int i = 2; i < n; i++) {
    int currentResult = 2e9;
    for (int j = i-1; j >= 0 && j >= i-k; j--) {
      currentResult = min(currentResult, result[j] + abs(vals[i] - vals[j]));
    }
    result[i] = currentResult;
  }
  
  cout << result[n-1] << endl;

}

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

class AtCoder {
    static void Main(string[] args) {
        var a = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();

        if (a >= 3200) Console.WriteLine(s);
        else Console.WriteLine("red");
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
int main(void){
	int n,m;
	int i,j;
	int k,g;
	int zi[24][60];
	scanf("%d",&n);
	for(i=0;i<=23;i++){
		for(j=0;j<=59;j++){
			zi[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		scanf("%d %d",&k,&g);
		zi[k][g]++;
	}
	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%d %d",&k,&g);
		zi[k][g]++;
	}
	int flg=0;
	for(i=0;i<=23;i++){
		for(j=0;j<=59;j++){
			if(flg==0){
				if(zi[i][j]!=0 && j>=10){
					printf("%d:%d",i,j);
					flg=1;
				}
				else if(zi[i][j]!=0 && j<10){
					printf("%d:0%d",i,j);
					flg=1;
				}
			}
			else {
				if(zi[i][j]!=0 && j>=10){
					printf(" %d:%d",i,j);
				}
				else if(zi[i][j]!=0 && j<10){
					printf(" %d:0%d",i,j);
				}
			}
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1036
#include<stdio.h>
int h,w;
char c[101][101];
int dy[4] = {0,0,1,-1};
int dx[4] = {1,-1,0,0};
void dfs(int y,int x,char cc){
  
  for(int i=0;i<4;i++){
    
    c[y][x] = '.';
    int yy = y+dy[i];
    int xx = x+dx[i];
    if(yy<0 || xx<0 || yy>=h || xx>=w || c[yy][xx] != cc) continue;
    dfs(yy,xx,cc);
  }

}
int main(){
  scanf("%d %d",&h,&w);
  while(h != 0 && w != 0){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	scanf(" %c",&c[i][j]);
      }
    }
    
    int ans = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(c[i][j] != '.'){
	  dfs(i,j,c[i][j]);
	  ans++;
	}
      }
    }
    
    printf("%d\n",ans);
    scanf("%d %d",&h,&w);
  }
  return (0);
}

Measured memory_bytes: 3304
def solve(a, b):
    if a <= 0 and 0 <= b:
        return 'Zero'
    if 0 < a:
        return 'Positive'
    length = b - a + 1
    return 'Positive' if length % 2 == 0 else 'Negative'


a, b = map(int, input().split())
print(solve(a, b))


Measured memory_bytes: 2940
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tlll tuple<ll, ll, ll>

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) cout << "x";
    cout << endl;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
from collections import deque
input = sys.stdin.readline

new_cards = defaultdict(int)
n, m = map(int, input().split())
A = deque(sorted(list(map(int, input().split()))))

for i in range(m):
    b, c = map(int, input().split())
    new_cards[c] += b

for card, count in sorted(new_cards.items(), reverse=True):
    for i in range(count):
        if A[0] < card:
            A.append(card)
            A.popleft()
        else:
            print(sum(A))
            exit()

print(sum(A))



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

int main()
{
  for (int t = in(); t--;){
    int forb[32][32][2] = {};
    int gx, gy;
    gx = in() + 1, gy = in() + 1;
    for (int p = in(); p--;){
      int x1, y1, x2, y2;
      x1 = in() + 1, y1 = in() + 1, x2 = in() + 1, y2 = in() + 1;
      if (x1 > x2) swap(x1, x2);
      if (y1 > y2) swap(y1, y2);
      forb[y2][x2][y1 < y2] = 1;
    }
    int dp[32][32] = {};
    dp[0][1] = 1;
    for (int y = 1; y <= gy; y++){
      for (int x = 1; x <= gx; x++){
        dp[y][x] += 
          !forb[y][x][0] * dp[y][x - 1] +
          !forb[y][x][1] * dp[y - 1][x];
      }
    }
    if (dp[gy][gx] == 0) puts("Miserable Hokusai!");
    else printf("%d\n", dp[gy][gx]);
  }
  return 0;
}

Measured memory_bytes: 1184
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    int A, B;
    cin >> A >> B;

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

    if (B < A) {
        cout << 0 << '\n';
        cout << 0 << '\n';
        return 0;
    }

    vector<pair<long long, long long>> dp(B + 1, make_pair(0, 0));
    dp[0] = make_pair(0, 1);

    auto update = [&](const pair<long long, long long>& L, const pair<long long, long long>& R) -> pair<long long, long long> {
        long long x = 0;
        if (L.second > 0) {
            x = max(x, L.first);
        }
        if (R.second > 0) {
            x = max(x, R.first);
        }
        long long cnt = 0;
        if (x == L.first) {
            cnt += L.second;
        }
        if (x == R.first) {
            cnt += R.second;
        }
        return {x, cnt};
    };

    for (auto x : V) {
        for (int i = B - 1; i >= 0; --i) {
            if (dp[i].second == 0) {
                continue;
            }
            int ni = i + 1;
            dp[ni] = update(dp[ni], make_pair(dp[i].first + x, dp[i].second));
        }
    }

    long long sum = 0;
    int sz = 1;
    long long cnt = 0;
    for (int i = A; i <= B; ++i) {
        long long P = dp[i].first;
        if (sum * i < P * sz) {
            sum = P;
            sz = i;
            cnt = 0;
        }
        if (sum * i == P * sz) {
            cnt += dp[i].second;
        }
    }

    long double avg = (long double) sum / sz;

    cout << avg << '\n' << cnt << '\n';


    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define ll          long long
#define int 		long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

int solve(int n){
	//write here
	if (n>=400 && n<600)return 8;
	if (n>=600 && n<800)return 7;
	if (n>=800 && n<1000)return 6;
	if (n>=1000 && n<1200)return 5;
	if (n>=1200 && n<1400)return 4;
	if (n>=1400 && n<1600)return 3;
	if (n>=1600 && n<1800)return 2;
	else return 1;
}

int32_t main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	int t;
	cin>>t;
	cout<<solve(t)<<endl;
	return 0;
}

Measured memory_bytes: 3636
parseInt(x) = parse(BigInt, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	h,w = readline() |> split |> parseMap
	if h==1||w==1
		println(1)
	else
		println((h*w+1)>>1)
	end
end

main()

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

class Main{
        static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public static void main(String[] args) throws IOException{
                String[] line = br.readLine().split(" ");
                int num = Integer.parseInt(line[0]);
                int truck = Integer.parseInt(line[1]);
                int[] weight = new int[num];
                int ave = 0;
                int max = 0;
                for(int i=0; i<num; i++){
                        weight[i] = Integer.parseInt(br.readLine());
                        ave += weight[i];
                        if(max<weight[i])
                                max = weight[i];
                }
                int s = ave%truck;
                ave /= truck;
                if(s>0)
                        ave++;

                if (ave<max)
                        ave=max;
                int ans=ave;
                int m=1;
                for(;m>0;ans++){
                        int c = 0;
                        for(int i=0; i<num;){
                                int t = 0;
                                while(i<num){
                                        if((t+weight[i])>ans){
                                                break;
                                        }
                                        t += weight[i];
                                        i++;
                                }
                                c++;
                        }
                        m=c-truck;
                }
                System.out.println(ans-1);
        }
}

Measured memory_bytes: 35064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
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; }
const long long INF = 1LL << 60;

int N,Q;
vector<int> x;
vector<bool> visited;
vector<vector<int>> graph;
vector<int> score;

void dfs(int i){
    //cout << i<<":" << graph[i].size()<< endl;
    visited[i] = true;
    for(int next_i:graph[i]){
        if(visited[next_i]) continue;
        score[next_i] += score[i];
        dfs(next_i);
    }
    visited[i] = false;
    return;
}

int main()
{
    cin>>N>>Q;
    x.resize(N);

    visited.resize(N);
    REP(i,N) visited[i]= false;

    graph.resize(N);
    REP(i, N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    // REP(i, N){
    //     for(int x:graph[i]){
    //         cout << i <<" -> "<< x << endl;
    //     }
    // }

    score.resize(N);
    REP(i,Q){
        int a,b;
        cin>>a>>b;
        a--;
        score[a] += b;
    }

    dfs(0);
    
    REP(i,N) cout <<score[i] << endl;



    return 0;
}

Measured memory_bytes: 27392
import math
n, d = map(int, input().split())
p = []
cnt = 0
for i1 in range(n):
    p.append(list(map(int, input().split())))

def check(l1, l2, d1):
    v = 0
    for k in range(d1):
        v += (l1[k] - l2[k]) ** 2
    if float.is_integer(math.sqrt(v)):
        return True
    else:
        return False

for j1, j2 in enumerate(p[:n]):
    for j3 in p[j1+1:]:
        if check(j2, j3, d):
            cnt += 1
print(cnt)

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

P f(int x)
{
    int a = x%10; //last digit of x
    int b = to_string(x)[0]-'0';

    return P(a,b);

}
int main()
{

    int n;
    cin>>n;
    map<P,int> freq;
    for(int i = 1; i<= n ; ++i)
    {
        P p = f(i);
        freq[p]++;
    }

    ll ans = 0 ;

    for(int i = 1; i<= n ; ++i)
    {
        P p = f(i);
        P q = P(p.second , p.first);
        ans += freq[q];
    }

    cout<<ans<<endl;
    return 0;
}


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

int gcd(int x, int y)
{
  if (y == 0){
    return (x);
  }
  else {
    return (gcd(y, x % y));
  }
}

int lcm(int x, int y)
{
  return (x / gcd(x, y) * y);
}

int main()
{
  int n;
  int a[10];

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

  int ans = lcm(a[0], a[1]);

  for (int i = 2; i < n; i++){
    ans = lcm(ans, a[i]);
  }

  printf("%d\n", ans);

  return (0);
}

Measured memory_bytes: 1192
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int main() {
	int N, i, j;
	scanf("%d", &N);

	for (i = 0; i <= 100; i++) for (j = 0; j <= 100; j++) if (4 * i + 7 * j == N) return !printf("Yes\n");
	return !printf("No\n");
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,high,maxh;
char s;
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>s;
		if(s=='I') high++;
		else high--;
		if(high>maxh) maxh=high;
	}
	cout<<maxh<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, t;std::cin >> n >> t;
  vll zero;
  vvl dat;
  re(i, n){
    ll a, b;std::cin >> a >> b;
    if(a==0) zero.push_back(b);
    else dat.push_back(vll{a, b});
  }
  sort(all(dat), [](vll x, vll y){
    return x[0]*(y[1]+1) > y[0]*(x[1]+1);
  });
  sort(all(zero));
  ll m = dat.size();
  ll INF = 1000000001;
  vvl dp = VV(m+1, 31, INF, ll);
  dp[0][0] = 0;
  for(int i=1;i<=m;i++){
    for(int j=0;j<=30;j++){
      dp[i][j] = dp[i-1][j];
      if(j!=0){
        ll prev = dp[i-1][j-1]+1;
        if(prev==INF) continue;
        dp[i][j] = min(dp[i][j], prev+prev*dat[i-1][0]+dat[i-1][1]);
      }
    }
  }
  //for(int i=0;i<10;i++) std::cout << dp[m][i] << '\n';
  ll ans = 0;
  for(int i=0;i<=30;i++){
    ll cost = dp[m][i], num = i;
    for(auto z:zero){
      if(z+cost+1<=t) cost += z+1, num++;
      else break;
    }
    if(cost>t) continue;
    ans = max(ans, num);
  }
  std::cout << ans << '\n';
  return 0;
}


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

int main(){
    string a, b;
    cin >> a >> b;

    long long x = stoll(a+b);
    long long y = sqrt(x);

    if(x == y*y) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

using namespace std;

const int maxn=1e5+5;

typedef long long ll;

int a[maxn];

priority_queue<int> q;

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		q.push(x);
	}
	
	while(m--){
		int tmp=q.top();
		q.pop();
		tmp/=2;
		q.push(tmp);
	}
	ll ans=0;
	while(!q.empty()){
		ans+=q.top();
		q.pop();
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main() {
  long A, V, B, W, T;
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;
  bool tag = false;
  if(A < B) {
    if(A + V * T >= B + W * T) tag = true;
    
  }else {
    if(A - V * T <= B - T * W) tag = true;
  }

  if(tag) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int P, Q, R;
    cin >> P >> Q >> R;
    cout << (P + Q + R - max(P, max(Q, R))) << endl;
    return 0;
}


Measured memory_bytes: 256
n=input()

m=n[0]+n[1]

o=n[2]+n[3]

x=int(m)
y=int(o)

if x>0 and x<13 and y>0 and y<13:
    print("AMBIGUOUS")

elif (x<13 and x>0) and (y>12 or y==0):
    print("MMYY")
elif (x>12 or x==0) and (y<13 and y>0):
    print("YYMM")

elif x==0 or y==0 or x>12 or y>12:
    print("NA")


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> cnt(m + 1, 0);
    for (int i = 0; i < n;i++){
        int k;
        cin >> k;
        for (int j = 0; j < k;j++){
            int a;
            cin >> a;
            cnt[a]++;
        }
    }
    int sum = 0;
    for (int i = 1; i <= m; i++){
        if(cnt[i]==n)
            sum++;
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for(int i=0; i<S.size(); i++){
        if(S.at(i) != T.at(i)){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3856