akhauriyash/Code-Regression huggingface dataset:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a = input()[:-1]

su = (len(a)*(len(a)-1))//2

po = [0 for i in range(26)]

for i in range(len(a)):
    on = ord(a[i]) - 97
    su -= po[on]
    po[on] += 1
print(su+1)




Measured memory_bytes: 40176
import java.util.*;
import java.io.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                PrintWriter ou = new PrintWriter(System.out);
                int n = Integer.parseInt(sc.next());
                char[] z = new char[10];
                String[] s = new String[n];
                for(int i = 0 ; i < n ; i++){
                        s[i] = sc.next();
                        for(int ii = 0 ; ii <= 9 ; ii++){
                                z[ii] = s[i].charAt(ii);
                        }
                        Arrays.sort(z);
                        s[i] = "";
                        for(int ii = 0 ; ii < 10 ; ii++){
                                s[i] += z[ii];
                        }
                }
                for(String pp : s){
                        int c = 0;
                        if(hs.containsKey(pp)) c = (int)hs.get(pp);
                        hs.put(pp , c + 1);
                }
                long[] yono = {0};
                long[] q = {0};
                hs.forEach((pp , c) -> {
                        q[0] = (int)c;
                        yono[0] += q[0] * (q[0] - 1) / 2;
                });
                ou.print(yono[0] + "\n");
                ou.flush();
        }
}

Measured memory_bytes: 68448
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
typedef pair<double,double>d_d;
#define inf 100000000//10^8

/////////////////////////////////




int main(){
    int n;cin>>n;
    int t,x,y,post,posx,posy;t=x=y=0;int i=1;
    for(i=1;i<=n;i++){
        cin>>post>>posx>>posy;
        if(post-t<abs(posx-x)+abs(posy-y))break;
        else if((post-t-abs(posx-x)-abs(posy-y))%2==1)break;
        t=post;x=posx;y=posy;
    }
    if(i==n+1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	ll n;
	cin >> n;
	for (ll i = 0; i < sqrt(n); i++) {
		ll a = sqrt(n)-i;
		if(n % a == 0){
			cout << to_string(n/a).size() << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,k,i,d,ans;
  cin>>n>>k;
  vector<int64_t> x(n);
  for(i=0;i<n;i++) cin>>x.at(i);
  for(i=0;i<=n-k;i++){
    if(x.at(i)*x.at(i+k-1)>=0) d=max(abs(x.at(i)),abs(x.at(i+k-1)));
    else d=x.at(i+k-1)-x.at(i)+min(-x.at(i),x.at(i+k-1));
    if(i==0||d<ans) ans=d;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4008
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
#ifdef LOCAL
#define dbg(x) cerr << #x << " = " << x << endl;
#else 
#define dbg(x)
#endif
#define endl "\n"
#define int long long                   	
#define x first 
#define y second
#define len(x) (int)((x).size())
 
using namespace std;
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(3);
    solve();
}
 
const int INF = 1e18, MAXN = 1e6 + 10, MOD = 1e9 + 7;	
                                                                                            
void solve() {                    
	string s, prev = "";
	cin >> s;

	int i = 0, cnt = 0;
	while (i < len(s)) {
		if (prev != s.substr(i, 1)) {
		    cnt++;
		    prev = s.substr(i, 1);
		    i++;
		}	
		else {
		 	if (i < len(s) - 1) {
		 	 	cnt++;
		 	}
		 	prev = s.substr(i, 2);
		 	i += 2;
		}
	}

	cout << cnt << endl;
}    		


                                 

Measured memory_bytes: 720
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 3 * 1000 * 100 + 47;
const double EPS = 1e-8;
const int MOD = 1000 * 1000 * 1000 + 7;


int A[4][4] =
{
    {1, 0, 0, 1},
    {1, 1, 0, 1},
    {1, 0, 1, 1},
    {1, 1, 1, 2}
};

int B[4][4] =
{
    {1, 0, 0, 0},
    {1, 1, 0, 0},
    {1, 0, 1, 0},
    {1, 1, 1, 1}
};

struct vect
{
    int A[4];
    vect()
    {
        FILL(A, 0);
    }
};

struct matrix
{
    int A[4][4];
    
    matrix()
    {
        FILL(A, 0);
    }
    
    matrix operator*(const matrix &m) const
    {
        matrix M;
        FOR(i, 0, 4)
            FOR(j, 0, 4)
                FOR(k, 0, 4)
                    M.A[i][j] = (M.A[i][j] + A[i][k] * 1LL* m.A[k][j]) % MOD;
        return M;
    }
    vect operator * (const vect& v) const
    {
        vect V;
        FOR(i, 0, 4)
            FOR(j, 0, 4)
                V.A[i] = (V.A[i] + A[i][j] * 1LL * v.A[j]) % MOD;
        return V;
    }
};


matrix BP(matrix M, int n)
{
    matrix RES;
    FOR(i, 0, 4)RES.A[i][i] = 1;
    while(n)
    {
        if (n & 1)RES = RES * M;
        M = M * M;
        n >>=1;
    }
    return RES;
}

int X[MAX];

int main()
{
    matrix A, B;
    FOR(i, 0, 4)FOR(j, 0, 4)A.A[i][j] = ::A[i][j];
    FOR(i, 0, 4)FOR(j, 0, 4)B.A[i][j] = ::B[i][j];
    
    int n, m;
    scanf("%d%d", &n, &m);
    FOR(i, 0, m)
    scanf("%d", X + i);
    X[m++] = n;
    
    vect V;
    V.A[0] = 1;
    FOR(i, 0, m)
    {
        matrix M = BP(A, X[i] - (i ? X[i-1] : 0) - 1);
        V = (M * B) * V;
    }
    cout << V.A[3] << endl;
    
    
    
}
    
    


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

int main() {
    long long N;
    cin >> N;
    map <long long, long long> A;
    for (long long i=0; i<N; i++) {
        long long a;
        cin >> a;
        A[a]=i;
    }
    for( auto i = A.begin(); i != A.end(); ++i ) {
        cout << i->second+1 << " ";
    }
}

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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int X = scan.nextInt();
		long[] x = new long[n+1];
		for (int i = 0; i < n; i++) {
			x[i] = scan.nextLong();
		}
		x[n] = X;
		Arrays.sort(x);
		if (x.length == 2) {
			System.out.println(x[1]-x[0]);
			return;
		}
		long[] s = new long[n];
		for (int i = 0; i < n; i++) {
			s[i] = x[i+1]-x[i];
		}
		long g = 0;
		if (s[1] >= s[0]) {
			g = gcd(s[1], s[0]);
		} else {
			g = gcd(s[0], s[1]);			
		}
		for (int i = 1; i < n-1; i++) {
			g = gcd(g, s[i+1]);
		}
		System.out.println(g);
	}
	public static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a%b);
	}
}


Measured memory_bytes: 48104
str = input()

if(len(str)%2 != 0):
    print("No")
    exit()
for i in range(len(str)):
    if(i % 2 == 0):
        if(str[i]!='h'):
            print("No")
            exit()
    if(i % 2 == 1):
        if(str[i]!='i'):
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 19191919;

struct Point{
    int x,y;
};

bool solve(int n, int m){
    vector<Point> b(n),w(m);
    rep(i,n) cin >>b[i].x >>b[i].y;
    rep(i,m) cin >>w[i].x >>w[i].y;

    int blx = INF, brx = -INF;
    int bly = INF, bry = -INF;
    int wlx = INF, wrx = -INF;
    int wly = INF, wry = -INF;
    rep(i,n){
        blx = min(blx, b[i].x);
        brx = max(brx, b[i].x);
        bly = min(bly, b[i].y);
        bry = max(bry, b[i].y);
    }
    rep(i,m){
        wlx = min(wlx, w[i].x);
        wrx = max(wrx, w[i].x);
        wly = min(wly, w[i].y);
        wry = max(wry, w[i].y);
    }

    if(brx<wlx || wrx<blx) return true;
    if(bry<wly || wry<bly) return true;

    rep(i,n)rep(j,m){
        int A = w[j].y - b[i].y;
        int B = b[i].x - w[j].x;
        int C = b[i].y*w[j].x - b[i].x*w[j].y;

        bool ok = true;

        int bp = 0, bm = 0;
        rep(k,n)if(k != i){
            int v = A*b[k].x + B*b[k].y + C;
            if(v==0) ok = false;

            if(v>0) ++bp;
            else ++bm;
        }

        int wp = 0 , wm = 0;
        rep(k,m)if(k != j){
            int v = A*w[k].x + B*w[k].y + C;
            if(v==0) ok = false;

            if(v>0) ++wp;
            else ++wm;
        }

        if(bp>0 && bm>0) ok = false;
        if(wp>0 && wm>0) ok = false;
        if(bp>0 && wp>0) ok = false;
        if(bm>0 && wm>0) ok = false;

        if(ok) return true;
    }

    return false;
}

int main(){
    int n,m;
    while(cin >>n >>m,n) cout << (solve(n,m)?"YES":"NO") << endl;
    return 0;
}



Measured memory_bytes: 3084
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
  }

  return sum;
}

/*考えを書くスペース

*/
//main.cpp----------------------------
#define max_n 100000

void solve();
ll dfs(ll);

ll n;
ll h[max_n+1];
ll dp[100000001];

int main() {
  scanf("%lld", &n);
  rep(i, n) scanf("%lld", &h[i]);

  solve();

  return 0;
}

void solve() {
  memset(dp, -1, sizeof(dp));

  cout << dfs(0) << endl;

}

//iは今いる足場、costは現在のコスト
ll dfs(ll i) {

  if(dp[i]>=0) {
    return dp[i];
  }

  if((i+1)==n) {
    return 0;
  }else if((i+2)==n) {
    return dp[i] = dfs(i+1)+abs(h[i]-h[i+1]);
  }else {
    return dp[i] = min(dfs(i+1)+abs(h[i]-h[i+1]), dfs(i+2)+abs(h[i]-h[i+2]));
  }
}


Measured memory_bytes: 783872
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int k; cin >> k;
    string s; cin >> s;
    if(s.size() <= k) cout << s << endl;
    else cout << s.substr(0, k) + "..." << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include <vector>
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;

ll n, m, L;

vector<vector<ll>> dist;
vector<vector<ll>> d;
const ll LARGE = (ll)1e15;

void initialize() {
	dist.resize(n);
	d.resize(n);
	for (int i = 0; i < n; i++) {
		dist[i].resize(n);
		d[i].resize(n);
		for (int j = 0; j < n; j++) {
			if (i == j) {
				dist[i][j] = 0;
				d[i][j] = 0;
			}
			else {
				dist[i][j] = LARGE;
				d[i][j] = LARGE;
			}
		}
	}
}

void solve() {

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				if (dist[i][j] <= L) {
					d[i][j] = 0;
				}
			}
		}
	}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (d[i][k] + d[k][j] >= LARGE) {
					d[i][j] = min(d[i][j], LARGE);
				}
				else {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j] + 1);
				}
			}
		}
	}
}

int main(void)
{
	cin >> n >> m >> L;
	initialize();
	for (int i = 0; i < m; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		dist[a][b] = c;
		dist[b][a] = c;
	}
	solve();
	int q;
	cin >> q;
	vector<ll> ans(q);
	for (int i = 0; i < q; i++) {
		int s, t;
		cin >> s >> t;
		s--;
		t--;
		auto v = d[s][t];
		if (v >= LARGE) {
			ans[i] = -1;
		}
		else {
			ans[i] = d[s][t];
		}
	}
	for (int i = 0; i < q; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 2688
import sys
input = sys.stdin.readline

h,w=map(int,input().split())
s=[[] for i in range(h)]
for i in range(h):
    si=input()
    s[i]=si
"""
h,w=4,6
s=[['#', '.', '.', '#', '.', '.'], ['.', '.', '.', '.', '.', '#'], ['.', '.', '.', '.', '#', '.'], ['#', '.', '#', '.', '.', '.']]    
"""
ww=[[0]*w for i in range(h)]
#www=[[0]*w for i in range(h)]
www=[0]*w
for i in range(h):
    jsum=0
    jcnt=1
    jj=[0]*(w+1)
    for j in range(w):
        if s[i][j]==".":
#            www[i][j]=jcnt
            www[j]=jcnt
            if j<w-1 and s[i][j+1]=="#":
                jcnt+=1
            jsum+=1
        else:
#            print(jsum,jst,jed)
            if jsum!=0:
                jj[jcnt-1]=jsum
            jsum=0
    jcnt+=1
    jj[jcnt-1]=jsum
            
    for j in range(w):
        if s[i][j]==".":
#            ww[i][j]=jj[www[i][j]]
            ww[i][j]=jj[www[j]]
#    print(jj)
                
hh=[[0]*w for i in range(h)]
hhh=[0]*h
for j in range(w):
    isum=0
    icnt=1
    ii=[0]*(h+1)
    for i in range(h):
        if s[i][j]==".":
#            www[i][j]=jcnt
            hhh[i]=icnt
            if i<h-1 and s[i+1][j]=="#":
                icnt+=1
            isum+=1
        else:
#            print(jsum,jst,jed)
            if isum!=0:
                ii[icnt-1]=isum
            isum=0
    icnt+=1
    ii[icnt-1]=isum
            
    for i in range(h):
        if s[i][j]==".":
#            ww[i][j]=jj[www[i][j]]
            hh[i][j]=ii[hhh[i]]
#    print(jj)
            
ijmax=0
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            ijmax=max(ijmax,ww[i][j]+hh[i][j]-1)

print(ijmax)
                


Measured memory_bytes: 142228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,B;
  cin >>N>>A>>B;
  if (N*A<B){
    cout<<N*A<<endl;
  }
  else if (N*A>B){
    cout<<B<<endl;
  }
  else {
    cout<<B<<endl;
  }
}

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

#define INF 1e9
using namespace std;
using ll = long long;

int main() {

    ll A, B, C; cin >> A >> B >> C;

    ll t;
    t = C - (A - B);

    if (t > 0) {
        cout << t << endl;
    } else {
        puts("0");
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX_i 55000

typedef struct process{
    char name[11];
    int time;
}pr;
void enqueue(pr x);
pr dequeue();
pr p[MAX_i];
int head,tail;

int main(void){
    int n,q,i,sum=0;
    pr x;
    
    scanf("%d %d",&n,&q);
    for(i=0;i<n;i++){
        scanf("%s %d",p[i].name,&p[i].time);
    }
    head=0;
    tail=n;
    while(head!=tail){
        x=dequeue();
        if(x.time<=q){
            sum+=x.time;
            printf("%s %d\n",x.name,sum);
        }else{
            sum+=q;
            x.time-=q;
            enqueue(x);
        }
    }
    return 0;
}

void enqueue(pr x){
    p[tail]=x;
    if(tail+1==MAX_i){
        tail=0;
    }else{
        tail++;
    }
}

pr dequeue(){
    if(head+1==MAX_i){
        head=0;
        return p[MAX_i-1];
    }else{
        head++;
        return p[head-1];
    }
}



Measured memory_bytes: 2596
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define Rep1(i,k,n) for(int i=k ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

int main(){

    int n,m; cin >> n >> m;
    int c[n];
    rep(i,m) cin >> c[i];

    int dp[n+10];
    rep(i,n+10) dp[i] = INF;
    dp[0] = 0;
    rep1(i,n){
        rep(j,m){
            if(i - c[j] >= 0) dp[i] = min(dp[i - c[j]] + 1 , dp[i]);
        }
    }

    cout << dp[n] << endl;



}


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

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

  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];

  int Max=A[0],Min=A[0];
  for (int i = 0; i < N; ++i) {
    if (Max < A[i]) Max=A[i];
    if (Min > A[i]) Min=A[i];
  }
  cout << Max - Min << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[]agrs){
		Scanner sc=new Scanner(System.in);
	   int x[]=new int [5];
	   for(int i=0;i<x.length;i++){
		   x[i]=sc.nextInt();
	   }Arrays.sort(x);
	   for(int j=4;j>=0;j--){
		   System.out.print(x[j]);
		   if(j!=0){
			   System.out.print(" ");
		   }
		   
	   }
	   System.out.println();
	}
}

Measured memory_bytes: 17164
#include <iostream>


using namespace std;


int main()
{
  int n, m, a, b, r[100]={0};
  
  cin >> n >> m;
  for (int i=0; i<m; i++){
    cin >> a >> b;
    r[a]++;
    r[b]++;
  }

  for (int i=1; i<n+1; i++) cout << r[i] << endl;
    
  return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

D = INT()
C = LIST()
s = [LIST() for _ in range(D)]
t = [INT() for _ in range(D)]

## 1回最終スコアを計算する
score = [0]*26
last = [0]*26
now = 0
for i in range(D):  # i+1日目
    score[t[i]-1] += s[i][t[i]-1]
    last[t[i]-1] = i+1
    for j in range(26):
        score[j] -= C[j]*(i+1-last[j])

now = sum(score)
M = INT()

ans = [0]*M
for i in range(M):  # nowからの差分を考える
    d, q = MAP()  # q:更新後
    d -= 1
    q -= 1
    c = t[d]-1  # c:更新前
    t[d] = q+1
    last_c = 0
    last_q = 0
    score_c = 0
    score_q = 0
    for j in range(D):
        if t[j]-1 == c:
            last_c = j+1
            score_c += s[j][c]
        elif t[j]-1 == q:
            last_q = j+1
            score_q += s[j][q]
        score_c -= C[c] * (j+1 - last_c)
        score_q -= C[q] * (j+1 - last_q)
    now += -score[c]-score[q]+score_c+score_q
    score[c] = score_c
    score[q] = score_q
    ans[i] = now

print(*ans, sep="\n")


Measured memory_bytes: 75456
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>

#define ll long long int

using namespace std;

const int INF = (1<<30) - 1;

bool formula(string str, int &vals){
    char c = str[0];
    
    if(c == 'T')
        return true;
    else if(c == 'F')
        return false;
    
    if('a'<=c && c<='k')
        return vals>>(c-'a')&1;
    
    //substr???string &?????¨NG?
    if(c == '-')
        return !formula(str.substr(1, str.size()-1), vals);

    //c == '('
    int count = 0;
    for(int i=1; i<str.size(); i++){
        char c = str[i];
        
        if(c == '(')
            count++;
        if(c == ')')
            count--;
        if(count == 0){
            if(c == '*'){
                string left = str.substr(1, i-1);
                string right = str.substr(i+1, str.size()-i-2);
                return formula(left, vals) && formula(right, vals);
            }
            if(c == '+'){
                string left = str.substr(1, i-1);
                string right = str.substr(i+1, str.size()-i-2);
                return formula(left, vals) || formula(right, vals);
            }
            if(str[i] == '-' && str[i+1] == '>'){
                string left = str.substr(1, i-1);
                string right = str.substr(i+2, str.size()-i-3);
                return !(formula(left, vals)) || formula(right, vals);
            }
        }
    }
    //No Implement
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string equation;
    while(cin>>equation, equation!="#"){
        int s = equation.find("=");
        string left = equation.substr(0, s);
        string right = equation.substr(s+1, equation.size()-s-1);
        
        bool is_identity = true;
        for(int i=0; i<1<<11; i++){
            is_identity &= formula(left, i)==formula(right, i);
        }
            
        cout << (is_identity ? "YES" : "NO") << endl;
    }
    return 0;
}

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

int main() {
	int H,W;
	string A;
	cin>>H>>W;
for(int i=0; i<W+2; i++){
	cout<<"#";
}
cout<<endl;
for(int i=0; i<H; i++){
	cin>>A;
	cout<<"#"<<A<<"#"<<endl;
}
for(int i=0; i<W+2; i++){
	cout<<"#";
}
cout<<endl;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
X = []
Y = []
Z = []

for i in range(N):
    x, y, z = map(int, input().split())
    X += [x]
    Y += [y]
    Z += [z]

sign = [-1, 1]
ans = 0
for i in range(2):
    sx = sign[i]
    for j in range(2):
        sy = sign[j]
        for k in range(2):
            sz = sign[k]
            sum_xyz = []
            for x, y, z in zip(X, Y, Z):
                sum_xyz += [sx*x + sy*y + sz*z]
            sum_xyz = sorted(sum_xyz)[::-1]
            ans = max(ans, sum(sum_xyz[:M]))
print(ans)

Measured memory_bytes: 74116
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 1005000000
#define MOD 1000000007
#define N 903
#define M 1000005
#define LOG 20
#define KOK 32000
using namespace std;

char s[N][N];
int h,w,pre[2][N][N];
ll ans;

int main() {

	//freopen("input.txt","r",stdin);

	scanf("%d %d",&h,&w);

	for(int i=h+1;i<=2*h;i++) scanf("%s",s[i]+1+w);

	for(int i=1;i<=3*h;i++) {

		for(int j=1;j<=3*w;j++) {

			pre[0][i][j]=pre[0][i-1][j-1]+(s[i][j]=='#');

		}

		for(int j=3*w;j>=1;j--) {

			pre[1][i][j]=pre[1][i-1][j+1]+(s[i][j]=='#');

		}

	}

	for(int i=h+1;i<=2*h;i++) {

		for(int j=w+1;j<=2*w;j++) {

			for(int k=1;k<=max(h,w);k++) {

				int tot=(s[i-k][j]=='#')+(s[i+k][j]=='#')+(s[i][j-k]=='#')+(s[i][j+k]=='#');

				ans+=tot*(tot-1)*(tot-2)/6;

				if(s[i-k][j]=='#' && s[i][j+k]=='#') {

					tot=pre[0][i+k-1][j-1]-pre[0][i][j-k];

					ans+=tot;

				}

				if(s[i][j+k]=='#' && s[i+k][j]=='#') {

					tot=pre[1][i-1][j-k+1]-pre[1][i-k][j];

					ans+=tot;

				}

				if(s[i+k][j]=='#' && s[i][j-k]=='#') {

					tot=pre[0][i-1][j+k-1]-pre[0][i-k][j];

					ans+=tot;

				}

				if(s[i][j-k]=='#' && s[i-k][j]=='#') {

					tot=pre[1][i+k-1][j+1]-pre[1][i][j+k];

					ans+=tot;

				}

			}

		}

	}

	printf("%lld",ans);

}

Measured memory_bytes: 6912
N, K = map(int, input().split())
X = list(map(int,input().split()))
ans = float("INF")
for i in range(N - K + 1):
  if X[i] * X[i + K - 1] >= 0:
    t = max(abs(X[i]), abs(X[i + K - 1]))
  else:
    t = X[i + K - 1] - X[i] + min(abs(X[i]), abs(X[i + K - 1]))
  ans = min(ans, t)
print(ans)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  string s; cin >> s;
  int w; cin >> w;
  string ans;
  for (int i = 0; i < s.size(); i += w) {
    ans += s[i];
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

// reference: http://ir5.hatenablog.com/entry/20171209/1512821837

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

use std::mem;
use std::cmp;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let S: String = sc.read();
    let mut ans = 0;
    for i in 0..S.len() {
        if S.chars().nth(i).unwrap() == '2' { ans += 1; }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2092
#include <string>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){

  string str;

  while(getline(cin,str)){

    int ix = 0;
    while( (ix = str.find("apple", ix)) >= 0 ) {
      str.replace(ix, strlen("apple"), "inari");
    }

    int iy = 0;
    while( (iy= str.find("peach", iy)) >= 0 ) {
      str.replace(iy, strlen("peach"), "apple");
    }


    int iz = 0;
    while( (iz= str.find("inari", iz)) >= 0 ) {
      str.replace(iz, strlen("inari"), "peach");
    }

    cout << str ;
    cout << endl;
  }

  return 0;

}


Measured memory_bytes: 3164
# C - Maximal Value

N = int(input())
B = [int(b) for b in input().split()]

A = [float('inf')] * N
for i in range(N - 1):
    A[i + 1] = B[i]
    if B[i] < A[i]:
        A[i] = B[i]

print(sum(A))


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int k;
    cin >> k;
    //処理
    int ans;
  	if(k%2==0){
    	ans = k*k/4;
    }else{
    	ans = (k+1)*(k-1)/4;
    }
  
    //出力
    cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 256
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
X = str(input())
start_mod = X.count("1")
if start_mod == 1:
  for i in range(n):
    if X[i] == "1":
      key = i
else: key = -1

def bin_to_int(n,binstr,mod):
  retval = 0
  for i in range(n-1,-1,-1):
    retval += (pow(2,n-1-i,mod) if binstr[i] == "1" else 0)
    retval %= mod
  return retval

start_number_plus = bin_to_int(n,X,start_mod+1)
if key == -1:
  start_number_minus = bin_to_int(n,X,start_mod-1)
# print(start_number_plus,start_number_minus,"debug")

# print(key,"debug3")
for i in range(n):
  if i == key:print(0);continue
  if X[i] == "1":
    now_mod = start_mod - 1
    now_number = (start_number_minus - pow(2,n-1-i,now_mod))%now_mod
      
  else:
    now_mod = start_mod + 1
    now_number = (start_number_plus + pow(2,n-1-i,now_mod))%now_mod
  # print(i,now_number,now_mod,"debug")
  ci = 1
  while now_number != 0:
    # print(now_number,now_mod)
    now_mod = bin(now_number).count("1")
    now_number %= now_mod
    ci += 1
  print(ci)

Measured memory_bytes: 80380
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n,m=map(int,input().split())
    dist=[float("inf")]*n
    dist[0]=0
    edges=[0]*m
    for i in range(m):
        a,b,c=map(int,input().split())
        edges[i]=[a-1,b-1,-c]

    # Bellman-Ford
    for k in range(1,2*n): # 2n-1回やって、n-1と2n-1のscoreを見る
        for u,v,cost in edges:
            if dist[v]>dist[u]+cost:
                dist[v]=dist[u]+cost
        if k==n-1:
            ans=dist[n-1]

    print(-ans if ans==dist[n-1] else "inf")

resolve()

Measured memory_bytes: 41708
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
#define N 100100
int ans,x,y,n,m,g[N],d[N],sel[N];
vector <int> a[N];
queue <int> q;
int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; ++i){
        cin >> x >> y;
        --x;--y;
        a[x].push_back (y);
        ++g[y];
    }
    for (int i = 0; i < n; ++i)
        if (!g[i])
            q.push (i);
    while (!q.empty()){
        x = q.front ();
        q.pop();
        for (int i = 0; i < a[x].size(); ++i){
            d[a[x][i]] = max (d[a[x][i]],d[x] + 1);
            --g[a[x][i]];
            if (!g[a[x][i]])
                q.push (a[x][i]);
        }
    }
    for (int i = 0; i < n; ++i)
        ans = max (ans, d[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;
 
int main()
{
    Khela
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>str)
    {
         int len=str.length();
         int sum[len];
         memset(sum,0,sizeof sum);
         vector<pii>R,L;
         ct=1;
         for(i=1;i<len;i++){
             if(str[i]==str[i-1] && str[i]=='R') ++ct;
             else{
                 if(ct>0) R.push_back({ct,i-1});
                 ct=0;
                 if(str[i]=='R') ct=1;
                 else ct=0;
             }
         }
         if(ct>0) R.push_back({ct,i-1});

          ct=1;
          for(i=len-2;i>=0;i--){
             if(str[i]==str[i+1] && str[i]=='L') ++ct;
             else{
                 if(ct>0) L.push_back({ct,i+1});
                 ct=0;
                 if(str[i]=='L') ct=1;
                 else ct=0;
             }
         }
         if(ct>0) R.push_back({ct,i+1});
         
         reverse(L.begin(),L.end());
         int siz=L.size();
         
         i=0;
         while(i<siz){
             p=R[i].f-L[i].first;
             ll tot=R[i].f+L[i].first;
             ll  mx=max(R[i].f,L[i].first);
             x=abs(p);
             sum[R[i].second]=tot/2;
             sum[L[i].second]=tot/2;
             if(tot & 1){
                 if(p>=0) sum[R[i].second]+=1;
                 else sum[L[i].second]+=1;
             }

             if((mx-1) & 1) swap(sum[R[i].second],sum[L[i].second]);
             ++i;
             
         }


         for(i=0;i<len;i++) cout<<sum[i]<<" ";
         cout<<endl;

        
    }





}

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

long long gcd(long long n, long long m){
  if(n%m==0) return m;
  else gcd(m, n%m);
}

int main(){
  long long a,b;
  cin >> a >> b;
  vector<long long> prime = {2};
  long long std = gcd(a,b);
  int ans = (std%2==0 ? 2:1);  
  while (std%2==0) std=std/2;
  long long small = min(a,b);
  
  long long cand = 3;
  
  while(std>=cand){
    if(cand*cand>std){
      ans ++;
      cand=std;
      std=1;
    }
    if(std%cand==0){
        ans ++;
        while (std%cand==0) std=std/cand;
      }
    
    cand++;
    
  }
  cout << ans << endl;    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dbl double
#define forn(i,n,k) for(int i=0;i<n;i=i+k)
#define forpn(p,n,k) for(int i=p;i<n;i+=k)
#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define vi vector<int>
#define vii vector<pair<int,int>>
#define all(x) (x).begin,(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pb push_back
using namespace std;
int no_of_bits(long long n)
{
    int count=0;
    while(n>0)
    {
        n=n>>1;
        count++;
    }
    return count;
}
long long gcd(int a,int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
bool isPrime(int n) {
    
    if (n == 1) {
        return false;
    }

    int i = 2;
  
    while (i*i <= n) {
        
        if (n % i == 0) {
            
            return false;
        }
        i += 1;
    }
    
    return true;
}
void solve(){
     ll a;
     cin>>a;
     long double b;
     cin>>b;
     ll p=a*b;
    cout<<p;
}
int main()
{   ios::sync_with_stdio(0);
    
    cin.tie(0);
    cout.tie(0);
    int p;
    p=1;
    while(p--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 3760
i, o, t, j, l, s, z = gets.split.map(&:to_i)
answer = 0
100.times do |cnt|
  break if [i, l, j].min < cnt
  answer = [answer, ((i - cnt) / 2) * 2 + o * 1 + ((l - cnt) / 2) * 2 + ((j - cnt) / 2) * 2 + cnt * 3].max
end
puts answer

Measured memory_bytes: 1916
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI 3.14159265358979323846264338327950L

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b){
    if(a % b == 0){
        return(b);
    }
    else{
        return(gcd(b, a % b));
    }
}

bool isPalindrome(string s){
    REP(i, s.length() / 2){
        if(s[i] != s[(s.length() - 1) - i]){
            return false;
        }
    }
    return true;
}

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

 ll N, M, K, Q, i, j, k, l, tmp, ans;

int main(){
    map<int, ll> Ms;
    map<int, ll> SMs;
    vector<int> As;
    cin >> N;
    REP(i, N){
        int t;
        scanf("%d", &t);
        As.push_back(t - 1);
        Ms[t - 1]++;
    }
    
    ll sum = 0;//トータル
    for(auto& m : Ms){
        // もしその数を１つ引く場合に、消す数
        if(m.second >= 2){
            sum += m.second * (m.second - 1) / 2;
            if(m.second >= 3){
                SMs[m.first] = (m.second * (m.second - 1) / 2) - ((m.second - 1) * (m.second - 2) / 2);
            }else{
                SMs[m.first] = (m.second * (m.second - 1) / 2);
            }
        }
    }

    REP(i, N){
        printf("%lld\n", sum - SMs[As[i]]);
    }
     return 0;
}

Measured memory_bytes: 20032
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 100000 + 5;
const int M = 3000 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline ll read() {
    ll res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

int n, m, ans;
char map[55][55];
int dep[55][55];

inline bool check(int x, int y) {
    if (x > n || x < 1) return false;
    if (y > m || y < 1) return false;
    if (map[x][y] == '#') return false;
    return true;
}

inline int bfs(int s, int t) {
    int res = 0;
    std::queue< Pair > q;
    memset(dep, -1, sizeof(dep));
    dep[s][t] = 0;
    q.push(mp(s, t));
    while (!q.empty()) {
        int x = q.front().fir, y = q.front().sec;
        q.pop();

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (check(nx, ny) && !~dep[nx][ny]) {
                dep[nx][ny] = dep[x][y] + 1;
                res = std::max(res, dep[nx][ny]);
                q.push(mp(nx, ny));
            }
        }
    }
    return res;
}

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%s", map[i] + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (map[i][j] == '.') ans = std::max(ans, bfs(i, j));
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m;
vector<int> E[maxn];
int dis[maxn], fa[maxn];
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	memset(dis, -1, sizeof dis);
	dis[1] = 1;
	queue<int> Q;
	Q.push(1);
	while(!Q.empty())
	{
		int x = Q.front(); Q.pop();
		for(auto v : E[x])
			if(dis[v] == -1)
			{
				dis[v] = dis[x] + 1;
				Q.push(v);
				fa[v] = x;
			}
	}
	for(int i = 1; i <= n; ++i) if(dis[i] == -1) { puts("No"); return 0;}
	puts("Yes");
	for(int i = 2; i <= n; ++i)
		cout << fa[i] << endl;
	return 0;
}

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

int main() {
    int h, w, m;
    cin >> h >> w >> m;
    map<pair<int, int>, int> mp;
    map<int, int> h_mp, w_mp;
    for(int i = 0; i < m; ++i) {
        int h1, w1;
        cin >> h1 >> w1;
        h_mp[h1]++;
        w_mp[w1]++;
        mp[{h1, w1}]++;
    }
    vector<int> h_mp_max_index, w_mp_max_index;
    int h_mp_max = 0, w_mp_max = 0;
    auto begin = h_mp.begin(), end = h_mp.end();
    for(auto iter = begin; iter != end; iter++) {
        if(iter->second > h_mp_max) h_mp_max = iter->second;
    }
    for(auto iter = begin; iter != end; iter++) {
        if(iter->second == h_mp_max) h_mp_max_index.push_back(iter->first);
    }

    begin = w_mp.begin(), end = w_mp.end();
    for(auto iter = begin; iter != end; iter++) {
        if(iter->second > w_mp_max) w_mp_max = iter->second;
    }
    for(auto iter = begin; iter != end; iter++) {
        if(iter->second == w_mp_max) w_mp_max_index.push_back(iter->first);
    }

    for(auto v : h_mp_max_index) {
        for(auto e : w_mp_max_index) {
            if(mp[{v, e}] == 0) {
                cout << (h_mp_max + w_mp_max) << '\n';
                return 0;
            }
        }
    }
    cout << (h_mp_max + w_mp_max - 1) << '\n';
}


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

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

int main()
{
    string S;
    cin >> S;
    vector<string> v = {"SUN", "MON", "TUE","WED","THU","FRI","SAT"};

    rep(i, 7) {
        if (v[i] == S) {
            print(7-i);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;




int main() {
	string s1,s2;
	cin >> s1 >> s2;
	if (s1[0] == s2[2] && s1[2] == s2[0]&&s1[1]==s2[1]) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


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

int ta[10][10];

int table(vector<int> v){
    int ret = ta[0][v[0]];
    ret = ta[ret][v[1]];
    ret = ta[ret][v[2]];
    ret = ta[ret][v[3]];
    if(v.size() > 4) ret = ta[ret][v[4]];
    return ret;
}

int check(string s){
    vector<int> num;
    rep(i,s.size()) num.push_back(s[i]-'0');
    num.push_back(table(num));
    rep(i,5){
        rep(j,10){
            if(j == num[i]) continue;
            vector<int> tmp = num;
            tmp[i] = j;
            if(table(tmp) == 0) return 1;
        }
    }
    rep(i,4){
        if(num[i] == num[i+1]) continue;
        vector<int> tmp = num;
        swap(tmp[i],tmp[i+1]);
        if(table(tmp) == 0) return 1;
    }
    return 0;
}

int main(){
    int ans = 0;
    rep(i,10) rep(j,10) cin >> ta[i][j];
    for(int i = 0; i <= 9999; i++){
        string s = to_string(i);
        while(s.size() < 4) s.insert(0,"0");
        ans += check(s);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3252
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	printf("%d\n",max(a*b,c*d));
	return 0;
}

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

#define int long long 

int n;
int a[100];

int po[128][32];

int dfs(int i, int sum)
{
  if (sum < 0 || sum > 20) return 0;
  if (i == n - 1) {
    return sum == a[n - 1];
  }

  int &ret = po[i][sum];
  if (ret != -1) return ret;
  ret = dfs(i + 1, sum + a[i]) + dfs(i + 1, sum - a[i]);
  return ret;
}

main()
{
  memset(po, -1, sizeof(po));
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }

  cout << dfs(1, a[0]) << endl;
}

Measured memory_bytes: 3124