akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	a = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int h,w,n,i,j,sr,sc,l,r,u,d;
	string s[2];
	cin >> h >> w >> n;
	cin >> sr >> sc;
	cin >> s[0];
	cin >> s[1];
	u = 1; d = h; l = 1; r = w;
	for(i=(n-1); i>=0; --i){
		switch(s[1][i]){
			case 'U':
			d = min(d+1,h);
			break;
			case 'D':
			u = max(u-1,1);
			break;
			case 'L':
			r = min(r+1,w);
			break;
			case 'R':
			l = max(l-1,1);
			break;
		}
		switch(s[0][i]){
			case 'U':
			++u;
			break;
			case 'D':
			--d;
			break;
			case 'L':
			++l;
			break;
			case 'R':
			--r;
			break;
		}
		if(u>d || l>r){
			break;
		}
	}
	cout <<((u<=sr&&sr<=d&&l<=sc&&sc<=r)?"YES":"NO") << endl;
	return 0;
}


Measured memory_bytes: 776
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Control.Monad
import Control.Monad.ST
import Control.Monad.Except
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntSet as IntSet

-- 閉路を見つける
findCycle :: V.Vector IntSet.IntSet -> Either [Int] ()
findCycle edges = runST $ runExceptT $ do
  let !n = V.length edges  -- 頂点の個数
  seen <- UM.replicate n (0 :: Int) -- 0: new, 1: DFSの最中, 2: チェック済み
  let dfs !x path = do
        -- x を通る閉路があるかチェックする
        UM.write seen x 1
        forM_ (IntSet.toList $ edges V.! x) $ \y -> do
          -- 辺 (x,y) が存在
          s <- UM.read seen y
          case s of 0 -> dfs y (y : path)
                    1 -> throwError (y : reverse (y : takeWhile (/= y) path)) -- コールスタックのどこかで dfs y が呼ばれている。閉路
                    _ -> return ()
        UM.write seen x 2
  forM_ [0..n-1] $ \x -> do
    s <- UM.read seen x
    when (s == 0) $ dfs x [x]
  return ()

reduceCycle ::  V.Vector IntSet.IntSet -> [Int] -> [Int]
reduceCycle edges_from = reduce1
  where
    -- 閉路の一部をショートカットする経路があったらそっちに繋ぎかえる、という操作を繰り返す
    loop :: IntSet.IntSet -> IntSet.IntSet -> [Int] -> [Int] -> [Int]
    loop m seen revAcc (i:ys@(j:_)) =
      case IntSet.maxView $ IntSet.delete j $ edges_from V.! i `IntSet.intersection` m of
        Nothing -> loop m (IntSet.insert i seen) (i : revAcc) ys
        Just (j',_) | j' `IntSet.member` seen -> reduce1 (j' : reverse (j' : i : takeWhile (/= j') revAcc))
                    | otherwise -> loop m (IntSet.insert i seen) (i : revAcc) (dropWhile (/= j') ys)
    loop m seen revAcc [i] = reverse revAcc -- ショートカットできる経路はもうない
    loop _ _ _ [] = error "something is wrong"
    reduce1 :: [Int] -> [Int]
    reduce1 path = loop (IntSet.fromList path) IntSet.empty [] path

main = do
  [n,m] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM m $ do
    [x,y] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (x-1,y-1)
  let edges_from :: V.Vector IntSet.IntSet
      edges_from = V.create $ do
        vec <- VM.replicate n IntSet.empty
        U.forM_ edges $ \(a,b) ->
          VM.modify vec (IntSet.insert b) a
        return vec
  case findCycle edges_from of
    Right _ -> putStrLn "-1"
    Left path -> do
      let path' = reduceCycle edges_from path
      print $ length path'
      forM_ path' $ \i -> do
        print (i+1)


Measured memory_bytes: 1148
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

long long calc(long long a,long long b){

	if(a>b) swap(a,b);
	if(a==0) return -b;

	return 2LL*a*(b/a)+calc(a,b%a);
}

int main(){

	long long n,x;
	cin>>n>>x;

	cout<<n+calc(n-x,x)<<endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
#define cd complex<double>
#define PI 4*atan(1)
#define MOD 998244353
#define pi 3.14159265358979323846//20 decimals
#define eps -0.000001
#define N 4000000

int32_t main()
{
    IOS;
   
    int n;

    cin>>n;
    vi v(n);
    map<int,int> m;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        m[v[i]]++;
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=n-1;i>=0;i--)
    {
        if(m[v[i]]==0)
            continue;
        for(int j=30;j>=0;j--)
        {
            if(m.find((1<<j)-v[i])!=m.end() and m[(1<<j)-v[i]]>0)
            {
                if((1<<j)-v[i]==v[i])
                {
                    if(m[v[i]]<=1)
                        continue;
                }
                ans++;
                m[(1<<j)-v[i]]--;
                m[v[i]]--;
            }
        }
    }
    cout<<ans;
    return 0;


}

Measured memory_bytes: 14336
/*
СТРОИМ СТЕНУ РАБОТЯГИ!
█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
*/

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
    
     
     
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
/** Interface */
     
inline int readChar();
template <class T = int> inline T readInt(); 
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x ); 
inline void writeWord( const char *s );
     
/** Read */
     
static const int buf_size = 4096;
     
inline int getChar() {
    static char buf[buf_size];
    static int len = 0, pos = 0;
    if (pos == len) {
        pos = 0, len = fread(buf, 1, buf_size, stdin);
    }
    if (pos == len) {
        return -1;
    }
    return buf[pos++];
}
     
inline int readChar() {
    int c = getChar();
    while (c <= 32) {
        c = getChar();
    }
    return c;
}
     
template <class T>
inline T readInt() {
    int s = 1, c = readChar();
    T x = 0;
    if (c == '-')
        s = -1, c = getChar();
    while ('0' <= c && c <= '9')
        x = x * 10 + c - '0', c = getChar();
    return s == 1 ? x : -x;
}
     
/** Write */
     
static int write_pos = 0;
static char write_buf[buf_size];
     
inline void writeChar( int x ) {
    if (write_pos == buf_size)
        fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}
     
template <class T> 
inline void writeInt( T x, char end ) {
    if (x < 0)
        writeChar('-'), x = -x;
     
    char s[24];
    int n = 0;
    while (x || !n)
        s[n++] = '0' + x % 10, x /= 10;
    while (n--)
        writeChar(s[n]);
    if (end)
        writeChar(end);
}
     
inline void writeWord( const char *s ) {     while (*s)
writeChar(*s++); }
     
struct Flusher {
    ~Flusher() {
        if (write_pos)
            fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
    }
} flusher;   
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228  


int n;
int a[11];


int main() {
    cin >> n;
    int t = 1;
    int bad = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        t *= 3;
        if (a[i] % 2 == 0) {
            bad *= 2;
        } else {
            bad *= 1;
        }
    }
    t -= bad;
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
X = input()
sc = 0
cnt = 0
ln = len(X)
for i in range(ln):
    if X[i] == 'S':
        sc += 1
    if X[i] == 'T':
        if sc >= 1:
            sc -= 1
            cnt += 1
print(ln - cnt * 2)


Measured memory_bytes: 10500
#include <iostream>
#include <vector>
#include <algorithm>
#define INF (1<<30)
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	vector<long long> dp(n + 10001, INF);
	vector<int> c(m, 0);
	for (int i = 0; i < m;i++) {
		cin >> c[i];
	}
	for (int i = 1; i <= n + 10000;i++) {
		for (auto val : c) {
			if (i - val < 0) continue;
			if (dp[i - val] == INF) {
				dp[i] = 1; continue;
			}
			dp[i] = min(dp[i], dp[i - val] + 1);
		}
	}
	cout << dp[n] << endl;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int w;
int d[20];

int dfs(int p){
	if(p==w)
		return 0;
	if(d[p]==0)
		return dfs(p+1);
	else{
		int e=d[p];
		int res=110;
		for(int i=p;i<w;++i){
			d[i]=(d[i]-e+10)%10;
			res=min(res,dfs(p+1));
		}
		for(int i=p;i<w;++i) d[i]=(d[i]+e+10)%10;
		return res+1;
	}
}

int main(void){
	while(cin >> w){
		if(w==0) break;
		string a,b;
		cin >> a >> b;
		rep(i,w){
			int aa=a[i]-'0';
			int bb=b[i]-'0';
			d[i]=(bb-aa+10)%10;
		}
		cout << dfs(0) << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc127/tasks/abc127_a

a, b = [int(x) for x in input().split()]
if a >= 13:
    print(b)
elif 12 >= a >= 6:
    print(b // 2)
elif a <= 5:
    print(0)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
int main() {
  string S;
  cin >> S;
  int st = 0;
  int t = 0;
  REP(i, 0, S.length()) {
    if (S[i] == 'S') {
      ++st;
    } else {
      if (st == 0) {
        ++t;
      } else {
        st--;
      }
    }
  }
  cout<<2*t<<endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  cin >> n;
  priority_queue<double, vector<double>, greater<double> > pq;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    pq.push(x);
  }

  while (pq.size() != 1) {
    double a = pq.top();
    pq.pop();
    double b = pq.top();
    pq.pop();
    pq.push((a + b) / 2);
  }
  cout << pq.top();

  return 0;
}



Measured memory_bytes: 3804
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner=new Scanner(System.in);
        int N=scanner.nextInt();
        int ints[]=new int[N];
        int originInts[]=new int[N];
        for(int i=0;i<N;i++){
            ints[i]=scanner.nextInt();
            originInts[i]=ints[i];
        }
        Arrays.sort(ints);
        if(ints[N/2]==ints[N/2-1]){
            for(int i=0;i<N;i++){
                System.out.println(ints[N/2]);
            }
            return;
        }
        for(int i=0;i<N;i++){
            if((ints[N/2-1]+ints[N/2])/2.0>originInts[i]){
                System.out.println(ints[N/2]);
            }else{
                System.out.println(ints[N/2-1]);
            }
        }
    }
}


Measured memory_bytes: 92196
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	string S;
	cin >> S;

	for (int i = 0; i < S.length() - 1; i++) {
		if (S[i] == S[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}





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

using namespace std;
const int MAXN=2222;
int edgeR[MAXN][MAXN],edgeC[MAXN][MAXN],dot[MAXN][MAXN],g[MAXN][MAXN],tmpEC[MAXN][MAXN],tmpER[MAXN][MAXN];
int main()
{
    int n,m,q;
    cin >> n >> m >> q;
    for (int i=0;i<n;i++)
    {
        string s;
        cin >> s;
        for (int j=0;j<m;j++)
        {
            g[i+1][j+1]=s[j]-'0';
            dot[i+1][j+1]=dot[i+1][j]+dot[i][j+1]-dot[i][j]+g[i+1][j+1];
        }
    }
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            if (i+1<=n&&g[i][j]==1&&g[i+1][j]==1) tmpEC[i+1][j]++;
            if (j+1<=m&&g[i][j]==1&&g[i][j+1]==1) tmpER[i][j+1]++;
        }
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            edgeC[i][j]=tmpEC[i][j]-edgeC[i-1][j-1]+edgeC[i-1][j]+edgeC[i][j-1];
            edgeR[i][j]=tmpER[i][j]-edgeR[i-1][j-1]+edgeR[i-1][j]+edgeR[i][j-1];
        }
    /*for (int i=1;i<=n;i++,puts(""))
        for (int j=1;j<=m;cout << setw(2)<<edgeC[i][j++]);
    puts("");
    for (int i=1;i<=n;i++,puts(""))
        for (int j=1;j<=m;cout << setw(2)<<edgeR[i][j++]); */
    while(q--)
    {
        int x,y,xx,yy;
        cin >>x >>y >>xx >> yy;
        int td=dot[xx][yy]-dot[xx][y-1]-dot[x-1][yy]+dot[x-1][y-1];
        int te=(edgeR[xx][yy]+edgeC[xx][yy])-
               (edgeC[x][yy] +edgeR[xx][y] +edgeR[x-1][yy]+edgeC[xx][y-1])+
               (edgeR[x-1][y]+edgeC[x][y-1]);
        //cout << td << " "<< te<< " ";
        cout << td-te << endl;
    }
    return 0;
}

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

#define fst first
#define snd second
typedef long long ll;
typedef pair<ll, ll> pll;
const int MAXN = 100010;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int n, C, K;
pll p[MAXN];

int main() {

	int i, j;
	n = read(), C = read(), K = read();
	for(i = 1; i <= n; i++) {
		p[i].fst = read();
		p[i].snd = p[i].fst+K;
	}

	sort(p+1, p+n+1);

	int ans = 0;
	for(i = 1; i <= n; i++) {
		int ed = min(i+C-1, n);
		if(p[ed].fst <= p[i].snd) {
			i = ed, ans++;
			continue;
		}
		for(j = i+1; j <= n; j++) 
			if(p[j].fst > p[i].snd) break;
		ans++, i = j-1;
	}
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

#define int long long
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define FI first
#define SE second
typedef pair< int,pair<int,pair<int, int> > > P3;
typedef pair<int, pair<int, int> > P2;
typedef pair<int, int> P1;
typedef tuple<int,int,int,int> T3;
typedef tuple<int,int,int> T2;
typedef tuple<int,int> T1;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int N,A,B;
int X[100005];
int V[100005];
int mem[100005];
int ans=INF;

int solve(int n){
    int res=INF;
    if(n==N-1)return 0;
    if(mem[n]!=-1)return mem[n];
    res=min(res,min(solve(n+1)+A*(V[n+1]-V[n]),solve(n+1)+B));
    return mem[n]=res;
}

signed main(){
    memset(mem,-1,sizeof(mem));
    cin>>N>>A>>B;
    for(int i=0;i<N;++i)cin>>X[i];
    for(int i=1;i<N;++i)V[i]=V[i-1]+(X[i]-X[i-1]);
    cout<<solve(0)<<endl;
}



Measured memory_bytes: 5760
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String correctString = "CODEFESTIVAL2016";
        while (in.hasNextLine()) {//注意while处理多个case
        	String inCorrectString = in.nextLine();
        	int operation = 0;
        	for(int i = 0; i < 16; i++){
        		if (correctString.charAt(i)!=inCorrectString.charAt(i)) {
					++operation;
				}
        	}
        	System.out.println(operation);
        }
        in.close();
    }
}

Measured memory_bytes: 10068
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n,k;
    cin>>n>>k;

    vector<int> a(n);
    int s = 0;
    rep(i,0,a.size())
    {
        cin>>a[i];
        s += a[i];
    }

    vector<int> div;

    rep(i,1,sqrt(s)+1)
    {
        if ( s % i == 0 )
        {
            div.pb(i);
            if ( s/i != i )
            {
                div.pb(s/i);
            }
        }
    }

    sort(all(div),greater<int>());

    // rep(i,0,div.size())
    // {
    //     out1(div[i]);
    // }
    int ans = 1;
    rep(i,0,div.size())
    {
        vector<int> temp;
        int d = div[i];
        int sum = 0;
        int found = 0;
        rep(j,0,a.size())
        {
            if ( a[j] % d == 0 )
            {
                continue;
            }
            temp.pb(a[j]%d);
            sum += (a[j]%d);
        }
        // out1(sum);
        sort(all(temp));
        int csum = 0;
        rep(j,0,temp.size())
        {
            csum += (temp[j]);

            if ( csum > k )
            {
                break;
            }

            if ( csum == (d*(temp.size()-j-1) - (sum-csum)) )
            {
                found = 1;
                break;
            }
        }

        if ( found == 1 )
        {
            ans = d;
            break;
        }
    }

    cout<<ans<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    ll N, M;
    cin >> N >> M;
    UnionFind tree(N);
    rep(0, i, M)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        tree.unite(a, b);
    }

    map<ll, ll> m;
    rep(0, i, N)
    {
        m[tree.root(i)]++;
    }

    ll ans = 0;
    rep(0, i, N)
    {
        ans = max(ans, m[i]);
    }

    cout << ans << endl;
}

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

int dp(int n){
    int A[31];
    for(int i=0; i<31; i++){
    if(i==0)    A[0] = 1;
    else if(i==1) A[1]= 1;
    else if(i==2) A[2]= 2;
    else A[i]=A[i-1]+A[i-2]+A[i-3];
    }
    return A[n];
}

int main(void){
    int n, p;
    while(cin >> n){
        if(n==0)    break;
        p = dp(n);
        if(p%10!=0){
            p = p/10+1;
            if(p>365)   p = p/365+1;
            else        p = 1;
        }
        else{
            p = p/10;
            if(p>365)   p = p/365+1;
            else        p = 1;
        }
        cout << p << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
def matrix_chain_multiplication(n, m, p):
    for l in range(2, n+1):
        for i in range(1, n-l+2):
            j = i + l - 1
            m[i][j] = float("inf")
            for k in range(i, j):
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j])
    return m


n = int(input())
N = 100
p = [0 for i in range(N+1)]
m = [[0 for a in range(N+1)] for b in range(N+1)]

for i in range(1, n+1):
    p[i-1], p[i] = map(int, input().split())
print(matrix_chain_multiplication(n, m, p)[1][n])




Measured memory_bytes: 5724
#include<iostream>

using namespace std;
const int maxn = 1e5 + 50;
const int mod = 1e9 + 7;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i=1;i<=n;++i){
        ll r = n/(n/i);
        ll t = n/i;
        if(n%t==0){
            ll x = n/t - 1;
            if(x>=i && x<=r) ans += x;
        }
        i = r;
    }
    cout << ans << endl;
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int cyadder(char& c,int add,int cyc,char start){
	int carry=add/cyc;
	add%=cyc;
	if(c-start+add>=cyc)carry++;
	c=start+(c-start+add)%cyc;
	return carry;
}

int fulladder(char* s,int add,int cyc,char start,int n){
	int r=add;
	for(int i=n-1;i>=0;i--){
		r=cyadder(s[i],r,cyc,start);
		if(r==0)break;
	}
	return r;
}

char s[111111];
int k;

int main(){
	cin.sync_with_stdio(false);
	cin>>s>>k;
	int n=strlen(s);
	rep(i,n){
		if(i==n-1){
			if(k>0)cyadder(s[i],k,26,'a');
		}else{
			if(s[i]!='a'&&k+s[i]>'z'){
				k-=('z'-s[i]+1);
				s[i]='a';
				//dbg(k);
			}
		}
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 512
#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;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	char c;cin>>c;
	if(isupper(c))puts("A");
	else puts("a");
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <utility>
#include <set>
#include <bitset>
#define ls x<<1
#define rs x<<1|1
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(x) scanf("%d", &x)
#define scdd(x,y) scanf("%d%d", &x, &y)
#define scddd(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define eb emplace_back
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define IOS std::ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppp;

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double pi = 2*acos(0.0);
const double eps = 1e-13;
const ll mod = 1e9+7;
const int maxn = 1e5 + 10;
const int maxm = 50000 + 10;

int a[maxn], stk[maxn], l[maxn], r[maxn];
void solve() {
    int n;
    scd(n);
    int top=0;
    for(int i=1; i<=n; i++) {
        scd(a[i]);
        while(top>0 && a[stk[top-1]] < a[i]) top--;
        stk[top++] = i;
        if(top==1) l[i]=0;
        else l[i]=stk[top-2];
    }

    top=0;
    for(int i=n; i>0; i--){
        while(top>0 && a[stk[top-1]] < a[i]) top--;
        stk[top++] = i;
        if(top==1) r[i]=n+1;
        else r[i] = stk[top-2];
    }
    ll ans=0;
    for(int i=1; i<=n; i++){
        if(l[i]!=0){
            int ll=l[i]-1;
            while(1){
                if(a[ll]>a[i] || ll==0) break;
                ll--;
            }
            int f1=l[i]-ll;
            int f2=r[i]-i;
            ans += 1LL*a[i]*f1*f2;
        }
        if(r[i]!=n+1){
            int rr=r[i]+1;
            while(1){
                if(a[rr]>a[i] || rr==n+1) break;
                rr++;
            }
            int f1=i-l[i];
            int f2=rr-r[i];
            ans += 1LL*a[i]*f1*f2;
        }
    }
    printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
    freopen("in.txt","r",stdin);
    //freopen("ans.txt","w",stdout);
#endif
    //IOS;
    solve();

    return 0;
}


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

const ll N = 4e5 + 5;
const ll mod = 998244353;

ll fac[N], inv[N];

ll power(ll x, ll y)
{
    ll res = 1;
    while (y)
    {
        if (y & 1)
            res = res * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return res;
}

void init()
{
    fac[0] = inv[0] = 1;
    for (ll i = 1; i < N; i++)
    {
        fac[i] = i * fac[i - 1] % mod;
        inv[i] = power(fac[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    if (r < 0 || r > n)
        return 0;
    return fac[n] * inv[r] % mod * inv[n - r] % mod;
}
// https://betrue12.hateblo.jp/entry/2020/05/11/093054
signed main()
{
    init();

    ll n, m, k;
    cin >> n >> m >> k;

    ll ans = 0;
    for (ll i = 0; i <= k; i++)
    {
        ll curr = ncr(n - 1, i) * m % mod * power(m - 1, n - 1 - i) % mod;
        ans = (ans + curr) % mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n; cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for (auto i = 0; i < n; i++) {
        string s; cin >> s;
        if(s == "AC") ac++;
        if(s == "WA") wa++;
        if(s == "TLE") tle++;
        if(s == "RE") re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

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

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

const lint MOD = 1000000007LL;

lint modpow(lint a, lint x)
{
    if (x == 0)
        return 1;
    if (x % 2 == 1)
        return a * modpow(a, x - 1) % MOD;

    lint t = modpow(a, x / 2);
    return t * t % MOD;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, K;
    cin >> N >> K;
    VEC(lint) F(K + 1);
    F[1] = 1;
    // F(K) = no. of sequences A of length N with gcd = 1 and Ai <= K
    FOR(k, 2, K + 1) {
        lint t = 0;
        // F(K) = K ^ N - SIGMA (F(K, g), 2 <= g <= K)
        // F(K) = K ^ N - SIGMA (F(K / g), 2 <= g <= K)
        for (int g = 2;g <= k;) {
            int v = k / g;
            int g1 = k / v + 1;
            t += (g1 - g) * F[v] % MOD;
            t %= MOD;
            g = g1;
        }

        F[k] = modpow(k, N) + MOD - t;
        F[k] %= MOD;
    }

    lint ret = 0;
    FOR(g, 1, K + 1)
        ret += g * F[K / g] % MOD;
    ret %= MOD;
    cout << ret << endl;
    return 0;
};

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

int main() {
    int x, n;
    cin >> x >> n;
    vector<int> hukumanai(n);
    vector<int> hukumu(0);
    for (int i = 0; i < n; i++){
        cin >> hukumanai.at(i);
    }
    for (int i = -100; i < 102; i++){
        bool a = 1;
        for (int j = 0; j < n; j++){
            if(hukumanai.at(j) == i)a = 0;
        }
        if(a)hukumu.push_back(i);
    }
    vector<pair<int, int>> p(hukumu.size());
    for (int i = 0; i < hukumu.size(); i++){
        p.at(i).second = hukumu.at(i);
        p.at(i).first = abs((x - hukumu.at(i)));
    }
    sort(p.begin(), p.end());
    cout << p.at(0).second << endl;
}

Measured memory_bytes: 3640
N,H=map(int,input().split())
As=[]
Bs=[]
for _ in range(N):
    a,b=map(int,input().split())
    As.append(a)
    Bs.append(b)
ans=0
max_a=max(As)
sort_Bs=sorted(Bs,reverse=True)
new_Bs=[]
for b in sort_Bs:
    if b>max_a:
        new_Bs.append(b)
for b in new_Bs:
    H-=b
    ans+=1
    if H<=0:
        break
if H>0:
    if H%max_a==0:
        ans+=(H//max_a)
    else:
        ans+=(H//max_a+1)
print(ans)


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

using namespace std;

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

//    int a=11^9^24;
//    int b=20^9^24;
//    int c = a^20^11;
//    cout<<a<<" "<<b<<" "<<c;

    long int N,ans;
    cin>>N;

    long int arr[N]={};

    for(long int i=0;i<N;i++){
        cin>>arr[i];
    }

    ans=arr[1];

    for(long int i=2;i<N;i++){
        ans^=arr[i];
    }
    cout<<ans<<" ";

    for(long int i=0;i<N-1;i++){
        ans^=arr[i]^arr[(i+1)%N];
        cout<<ans<<" ";
    }


    return 0;
}


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


int main() {
  long L,R;
  cin>>L>>R;
  long ans=1234567890;
  for(long i=L;i<R;i++){
    for(long j=i+1;j<=R;j++){
      ans=min((i*j)%2019,ans);
      if(ans==0){
        cout<<0<<endl;
        return 0;
      }
    }
  }
  cout<<ans<<endl;
  }


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

int main(){
  string s;
  cin>>s;
  if(((s.at(0)==s.at(1))&&(s.at(0)!=s.at(2))&&(s.at(2)==s.at(3)))||((s.at(0)==s.at(2))&&(s.at(0)!=s.at(1))&&(s.at(1)==s.at(3)))||((s.at(0)==s.at(3))&&(s.at(0)!=s.at(2))&&(s.at(1)==s.at(2)))){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  } 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
string ans[111][111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;cin>>a>>b;
  for(int i=0;i<100;i++){
    for(int j=0;j<50;j++){
      ans[i][j] = '#';
    }
  }
  for(int i=0;i<100;i++){
    for(int j=50;j<100;j++){
      ans[i][j] = '.';
    }
  }
  ll cnt = 1;
  for(int i=0;i<100;i++){
    for(int j=i%2+1;j<49;j+=3){
      if(cnt == a){break;}
      ans[i][j] = '.';
      cnt++;
    }
    if(cnt == a)break;
  }
  cnt = 1;
  for(int i=0;i<100;i++){
    for(int j=51+i%2;j<100;j+=3){
      if(cnt == b){break;}
      ans[i][j] = '#';
      cnt++;
    }
    if(cnt == b)break;
  }
  cout<<100<<" "<<100<<endl;
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++)
      cout<<ans[i][j];
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
 
typedef long long int ll;
typedef string str;
 
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;   
    while (y) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll nCrModP(ll n, ll r, ll p) 
{ 
    if (!r) 
      return 1; 
  
	ll fac[n+1]; 
   	fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p; 
}
 
ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);
}
 
void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main ()
{
	
	ll t,n,m,k,i,j,a,b=pow(10,9)+7;
	// cin >> t;
    str st,s;
    cin >> n;
    ll arr[n+2];
    ll sum[n+2]={0};
    for(i=1;i<=n;i++)
    {
        cin >> arr[i];
        sum[i]=arr[i]+sum[i-1];
        sum[i]%=b;
    }
    ll ans=0;
    for(i=2;i<=n;i++)
    {
        a=(arr[i]%b)*(sum[i-1]%b);
        a%=b;
        ans+=a;
        ans%=b;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6724
n = gets.to_i
a = gets.split.map &:to_i

cnt = Hash.new(0)
n.times do |i|
  cnt[a[i]] += 1
end

all = 0
cnt.values.each do |v|
  all += v*(v-1)/2
end

# p a
# p cnt
# p [all]

n.times do |i|
  v = cnt[a[i]]
  # p [v]
  puts all - (v - 1)
end


Measured memory_bytes: 29700
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pair_i;

int main()
{
	int n, m;

	while(cin>> m && m){
		vector<Pair_i> target(m);
		for(int i = 0; i < m; i++)	cin >> target[i].first >> target[i].second;

		cin>>n;
		vector<Pair_i> night(n);
		for(int i = 0; i < n; i++)	cin >> night[i].first >> night[i].second;

		sort(night.begin(), night.end());
		sort(target.begin(), target.end());

		for(int i = 0; i < n; i++){
			bool flag = false;
			Pair_i d = make_pair(target[0].first - night[i].first, target[0].second - night[i].second);

			for(int j = 1; j < m; j++){
				if(!binary_search(night.begin(), night.end(), make_pair(target[j].first - d.first, target[j].second - d.second))) break;
				else if(j == m-1){
					cout<<-d.first<<" "<<-d.second<<endl;;
					flag = true;
					break;
				}
			}
			if(flag) break;
		}
	}
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int L, n, m, Q;
int Y[1010], H[1010];
char Res[1010];
int w[1010];
char p[1010];
map<int, char>Map[1010];
vector<int>G[1010];
int Loc(int x) {
	return (lower_bound(Y, Y + m + 2, x+1) - Y) - 1;
}
int main(){
	int i;
	scanf("%d%d%d%d", &L, &n, &m, &Q);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		scanf("%s", p+i);
	}
	for (i = 1; i <= m; i++) {
		scanf("%d%d", &Y[i],&H[i]);
	}
	Y[m + 1] = L + 1;
	for (i = 0; i <= m; i++)if (!H[i])H[i] = -L;
	for (i = 1; i <= n; i++) {
		int x = w[i];
		while (1) {
			int t = Loc(x);
			Map[t][x % (Y[t] - H[t])] = p[i];
			if (H[t] <= 0)break;
			x -= ((x - Y[t]) / (Y[t] - H[t]) + 1) * (Y[t] - H[t]);
		}
	}
	for (i = 1; i <= Q; i++) {
		int x;
		char u = '?';
		scanf("%d", &x);
		while (1) {
			int t = Loc(x);
			if (Map[t].count(x % (Y[t] - H[t]))) u = Map[t][x % (Y[t] - H[t])];
			if (H[t] <= 0)break;
			x -= ((x - Y[t]) / (Y[t] - H[t]) + 1) * (Y[t] - H[t]);
		}
		printf("%c", u);
	}
	printf("\n");
}

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

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

	string s;
	cin >> s;

	bool seven = false;
	for (int i = 0; i < (int)s.size(); ++i) {
		if (s[i] == '7') seven = true;
	}

	if (seven)
		cout << "Yes";
	else
		cout << "No";
}


Measured memory_bytes: 3640
function main()
  V=zeros(Int,3010,3010)
  dp=zeros(Int,3010,3010,4)
  R,C,K=parse.(Int,split(readline()))
  for i=1:K
    r,c,v=parse.(Int,split(readline()))
    V[r,c]=v
  end
  for i=1:R
    for j=1:C
      for k=1:3
        dp[i+1,j+1,k+1]=max(max(dp[i,j+1,4],dp[i+1,j,k])+V[i,j],dp[i+1,j,k+1])
      end
    end
  end
  println(dp[R+1,C+1,4])
end
main()

Measured memory_bytes: 571508
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}

#define P (1'000'000'007)

template<int MOD=P>
struct Mod {
public:
    long long signed value;

    Mod(long long signed val): value(val % MOD) {
        if (value < 0) value += MOD;
    }

    constexpr Mod& operator+=(const Mod& other) noexcept { 
        value += other.value;
        value %= MOD;
        return *this;
    }
    constexpr Mod& operator-=(const Mod& other) noexcept {
        value -= other.value;
        if (value < 0) value += MOD;
        return *this;
    }
    constexpr Mod& operator*=(const Mod& other) noexcept {
        value *= other.value;
        value %= MOD;
        return *this;
    }

    constexpr Mod operator-() noexcept {
         return value == 0 ? 0 : MOD - value;
    }

    constexpr Mod operator+(const Mod& other) const noexcept { return Mod(*this) += other; }
    constexpr Mod operator-(const Mod& other) const noexcept { return Mod(*this) -= other; }
    constexpr Mod operator*(const Mod& other) const noexcept { return Mod(*this) *= other; }
    constexpr bool operator==(const Mod& other) const noexcept { return this->value == other.value; }
    constexpr bool operator!=(const Mod& other) const noexcept { return this->value != other.value; }
};

signed main() {
    capi(n);

    int d[61][2] = {0};

    rep(i, n) {
        capi(a);
        rep(j, 61) {
            ++d[j][a & 1];
            a >>= 1;
        }
    }

    Mod ans(0);

    rep(j, 61) {
        Mod x(1ll << j);
        x *= d[j][0] * d[j][1];
        ans += x;
    }

    cout << ans.value;

    return 0;
}


Measured memory_bytes: 3192
n = int(input())
p = [int(input()) for i in range(n)]
tl = 1
n2i = [-1 for i in range(n)]
for i in range(n):
    n2i[p[i]-1] = i
tmp = 1
for i in range(n-1):
    if n2i[i] < n2i[i+1]:
        tmp += 1
    else:
        tmp = 1
    tl = max(tl, tmp)

ans = n - tl
print(ans)

Measured memory_bytes: 18968
countTri = 0
countTriCho = 0
countTriSma = 0
countTriLar = 0
while(True):
    hens = list(map(int, input().split()))
    MAX = max(hens)
    hens.remove(MAX)
    SUM = 0
    for hen in hens:
        SUM += hen
    if MAX >= SUM:
        print(countTri, countTriCho, countTriSma, countTriLar)
        break
    else:
        countTri+=1
        SUM_2 = 0
        for hen in hens:
            SUM_2 += (hen**2)
        MAX_2 = (MAX ** 2)
        if (MAX_2 == SUM_2):
            countTriCho+=1
        elif (MAX_2 < SUM_2):
            countTriSma+=1
        else:
            countTriLar+=1


Measured memory_bytes: 5592
#include<stdio.h>
signed main(void)
{
  int X,Y;
  if(~scanf("%d %d",&X,&Y))
  {
    if((Y&1))return puts("No"),0;
    if(2*X>Y||4*X<Y)return puts("No"),0;
    if(!((4*X-Y)&1))return puts("Yes"),0;
    else return puts("No"),0;
  }
}

Measured memory_bytes: 1660
import Control.Monad

data Dice = Dice {top :: Int,
                  south :: Int,
                  east :: Int,
                  west :: Int,
                  north :: Int,
                  bottom :: Int}
fromList :: [Int] -> Dice
fromList [t,s,e,w,n,b] = Dice t s e w n b

rotate :: Dice -> Char -> Dice
rotate d 'N' = d {bottom = north d,
                  north = top d,
                  top = south d,
                  south = bottom d}
rotate d 'S' = d {bottom = south d,
                  south = top d,
                  top = north d,
                  north = bottom d}
rotate d 'E' = d {bottom = east d,
                  east = top d,
                  top = west d,
                  west = bottom d}
rotate d 'W' = d {bottom = west d,
                  west = top d,
                  top = east d,
                  east = bottom d}
rotate d 'c' = d {north = west d,
                  west = south d,
                  south = east d,
                  east = north d}
rotate d 'C' = rotateAll d "ccc"

rotateAll :: Dice -> [Char] -> Dice
rotateAll d [] = d
rotateAll d (op:ops) = rotateAll (rotate d op) ops

rotateWithTop :: Dice -> Int -> Dice
rotateWithTop d t | t == top d = d
                  | t == north d = rotate d 'S'
                  | t == south d = rotate d 'N'
                  | t == east d = rotate d 'W'
                  | t == west d = rotate d 'E'
                  | t == bottom d = rotateAll d "NN"

rotateWithMatch :: Dice -> [Int] -> Dice
rotateWithMatch d [t, s] | t /= top d =
                           rotateWithMatch (rotateWithTop d t) [t, s]
                         | s == south d = d
                         | s /= south d =
                           rotateWithMatch (rotate d 'c') [t, s]

main :: IO ()
main = do
  d <- fmap (fromList . map read . words) getLine
  q <- readLn
  qs <- replicateM q $ fmap (map read . words) getLine
  mapM_ (putStrLn . show . east . rotateWithMatch d) qs

Measured memory_bytes: 3772
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
BC=[list(map(int,input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])
cnt=0
for b,c in BC:
    tmp=0
    while tmp<b:
        idx=cnt+tmp
        if idx>=n:
            break
        if A[idx]<c:
            A[idx]=c
            tmp+=1
        else:
            break
    cnt+=tmp
    if cnt>=n:
        break
print(sum(A))

Measured memory_bytes: 73240
N = int(input())
H = list(map(int, input().split()))

max_count = 0
this_count = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        this_count += 1
        if this_count > max_count:
            max_count = this_count
    else:
        this_count = 0

print(max_count)

Measured memory_bytes: 14252