akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
  /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,i;
    cin>>n>>i;
    cout<<(n-i+1)<<endl;

    
    
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  ll res = INF;
  rep(i, n-m+1) {
    ll tmp;
    if (v.at(i)*v.at(i+m-1) < 0) {
      tmp = v.at(i+m-1)-v.at(i) + min(abs(v.at(i)), v.at(i+m-1));
    } else {
      tmp = max(abs(v.at(i)), abs(v.at(i+m-1)));
    }
    chmin(res, tmp);
  }
  cout << res << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='1'){
			s[i]='9';
		}
		else{
			s[i]='1';
		}
	}
	cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, N;
  cin >> H >> N;
  for (int i = 0; i < N + 2; i++) {
    cout << "#";
  }
  cout << endl;
  vector<string> a(H);
  for (int i = 0; i < H; i++) {
    cin >> a.at(i);
    cout << "#" << a.at(i) << "#" << endl;
  }
  for (int i = 0; i < N + 2; i++) {
    cout << "#";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s; cin>>s;
    int k; cin>>k;
    vector<string> substring;
    for(int i=0; i<s.size(); i++){
        for(int j=1; j<=k and i+j<=s.size(); j++){
            substring.push_back(s.substr(i,j));
        }
    }
    sort(substring.begin(), substring.end());
    substring.erase(unique(substring.begin(),substring.end()),substring.end());
    cout<<substring.at(k-1)<<endl;
}


Measured memory_bytes: 1660
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
  int N;
  string S;
  cin >> N >>S;

  int a[N+1];
  int count = 0;
  a[0] = 0;

  for(int i=1;i<N+1;i++){
    if(S[i-1]=='#'){
      count++;
      a[i] = count;
    }else{
      a[i] = count;
    }
  }

 // for(int i=0;i<N+1;i++) cout << a[i] <<endl;


  int ans = N+1;
  for(int i=0;i<N+1;i++){
    ans = min(ans, 2*a[i]+N-i-a[N]);
  }
  cout << ans <<endl;

  return 0;
}

Measured memory_bytes: 1412
#include <iostream>
#include <complex>
#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>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    ll h,n;
    int i;
    int *a=(int*)malloc(sizeof(int)*n);
    
    cin>>h>>n;
    rep(i,n){
        cin>>a[i];
    }
    ll sum=std::accumulate(a,a+n,0);
    sum<h ? cout<<"No" : cout<<"Yes";
    return 0;
}

Measured memory_bytes: 2304
N = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(str(i))
            divisors.append(str(n // i))
    return divisors


divisors = make_divisors(N)
length = [max(len(divisors[i]), len(divisors[i + 1]))
          for i in range(0, len(divisors), 2)]
print(min(length))

Measured memory_bytes: 3188
from sys import stdin
import sys

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs


def main(inputs):
	s=inputs[0][0]
	if "A" in s and "B" in s:
		print("Yes")
		sys.exit(0)
	print("No")
			
		
	
	
	

if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)
	


Measured memory_bytes: 2940
import numpy as np
import math

# K = int(input())
# A, B = map(int, input().split())
# A = list(map(int, input().split()))

N, M = map(int, input().split())

edges = []
E = np.zeros((N, N), dtype=int)

for m in range(M):
    s, t = map(int, input().split())
    s = s - 1
    t = t - 1
    E[s][t] = 1
    E[t][s] = 1

# print('edge=', E)


def count(path, E):
    if len(path) == N:
        return 1
    else:
        edges = []
        cur = path[-1]
        ret = 0
        for n in range(N):
            if E[cur][n] == 1 and n not in path:
                npath = path + [n]
                ret += count(npath, E)
        return ret

ret = count([0], E)
print(ret)


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        G.at(a-1).push_back(b);
        G.at(b-1).push_back(a);
    }
    for(int i=0;i<N;i++){
        cout <<G.at(i).size() << endl;
    }
    return 0;

}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>
#include <list>
#include <assert.h>
using namespace std;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) (v).erase( unique(all(v), (v).end() );
#define SZ(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define SUM(v) accumulate((v).begin(), (v).end(), (ll)0)
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

using ll = long long;
using ull = unsigned long long;

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

const char newl = '\n';

ll qp(ll a,ull b){ll ans=1;do{if(b&1u)ans*=a;a*=a;}while(b>>=1u);return ans;}
ll qp(ll a,ull b,ll mod){ll ans=1;do{if(b&1u)ans=ans*a%mod;a=a*a%mod;}while(b>>=1u);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


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

    ll r = 0;
    for (char c : s) {
        ll n = c - '0';
        r += n;
    }

    YesNo(r % 9 == 0);

    return 0;
}


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

int main() {
  int A,B,C,D;
  
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D)
    cout << "Left" << endl;
  
  else if (A + B == C + D)
    cout << "Balanced" << endl;
  
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int dx[4]={-1,0,1,0};
const int dy[4]={0,1,0,-1};
const int maxr = 1100;
const int maxc = 1100;

char str[maxc];
int n,m,K;
int a[maxr][maxc],sx,sy;

int d[maxr][maxc];
struct node
{
	int x,y,d;
	node(){}
	node(const int _x,const int _y,const int _d){x=_x;y=_y;d=_d;}
};
inline bool operator <(const node x,const node y){return x.d>y.d;}
priority_queue<node>q;
void bfs()
{
	d[sx][sy]=0; q.push(node(sx,sy,0));
	while(!q.empty())
	{
		const node now=q.top(); q.pop();
		if(now.d!=d[now.x][now.y]) continue;
		for(int i=0;i<4;i++)
		{
			int nx=now.x+dx[i],ny=now.y+dy[i];
			if(a[nx][ny]&&d[nx][ny]>now.d+1) d[nx][ny]=now.d+1,q.push(node(nx,ny,now.d+1));
		}
	}
}

int main()
{
	memset(d,63,sizeof d);
	
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;i++) 
	{
		scanf("%s",str);
		for(int j=1;j<=m;j++)
		{
			if(str[j-1]=='#') a[i][j]=0;
			else a[i][j]=1;
			if(str[j-1]=='S') sx=i,sy=j;
		}
	}
	bfs();
	int ans=INT_MAX;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(d[i][j]<=K)
	{
		int x=1+(min(i-1,n-i)+K-1)/K;
		int y=1+(min(j-1,m-j)+K-1)/K;
		ans=min(ans,min(x,y));
	}
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 8448
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
using static Func;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; }
	static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		var S = Str;
		var T = new StringBuilder(S);
		T[I[1] - 1] = char.ToLower(T[I[1] - 1]);
		WriteLine(T);
	}
}
static class Func { }


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

int x;

int main() {
	cin >> x;
	int a = x / 100;
	if(a >= 21) cout << "1" << endl;
	else {
		if(5 * a >= x % 100) cout << "1" << endl;
		else cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main() {
    fastIO;
    int a, b, k, lim, ind;
    vector<int> div;
    cin >> a >> b >> k;
    lim = min(a, b);
    for(int i = 1; i <= lim; i++){
        if(a%i == 0 && b%i == 0){
            div.pb(i);
        }
    }
    sort(div.begin(), div.end());
    ind = div.size() - k;
    cout << div[ind] << endl;
    return 0;
}



Measured memory_bytes: 3644
import           Data.Char                      ( isSpace )
import qualified Data.Vector.Unboxed           as V
import qualified Data.ByteString.Char8         as C

main = do
    [n, m] <- map read . words <$> getLine :: IO [Int]
    a      <- V.unfoldr (C.readInt . C.dropWhile isSpace) <$> C.getLine
    let a_tot = V.sum a
        count = V.length . V.filter (>= a_tot) . V.map (* (4 * m)) $ a
    putStrLn $ if count >= m then "Yes" else "No"


Measured memory_bytes: 508
import math
def main():

    N = int(input())

    d = [2 for _ in range(N+1)]
    d[1] = 1

    v = int(math.sqrt(N))
    for i in range(2, N//2+1):
        for j in range(i+i, N+1, i):
            d[j] += 1

    # v = int(math.sqrt(N))
    # for i in range(2, v+1):
    #     for j in range(i+i, N+1, i):
    #         d[j] += 1
    #         if j//i > v: d[j] += 1

    ans = 0
    for i in range(1, N+1):
        ans += i * d[i]
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 224848
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int N, h[100000], dp[100000];
int main(int argc, char *argv[])
{

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

  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);

  for (int i = 2; i < N; i++) {
    dp[i] = min(abs(h[i-1]-h[i]) + dp[i-1], abs(h[i-2]-h[i]) + dp[i-2]);
  }

  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
// https://atcoder.jp/contests/abc174/tasks/abc174_f
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

// BIT(Binary-Indexed-Tree) 別名：Fenwick Tree
template <typename T> struct BIT {
    int n;
    vector<T> d;
    BIT(int n = 0) : n(n), d(n + 1) {}
    // 要素iにxを加算
    void add(int i, T x = 1) {
        for (i++; i <= n; i += i & -i) {
            d[i] += x;
        }
    }
    // 区間[0, i]の合計を求める（閉区間）
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i & -i) {
            x += d[i];
        }
        return x;
    }
    // 区間[l, r]の合計を求める（閉区間）
    T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
};

signed main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    vector<int> c(N, -1);
    // (s, t)
    vector<pair<int, int>> A;
    REP(i, N) {
        int a;
        cin >> a;
        if (c[a] != -1) {
            A.emplace_back(c[a], i + 1);
        }
        c[a] = i + 1;
    }
    sort(ALLR(A));

    vector<pair<int, int>> B(Q);
    REP(i, Q) { cin >> B[i].first >> B[i].second; }
    vector<int> ord(Q);
    iota(ALL(ord), 0);
    sort(ALL(ord), [&](int x, int y) {
        if (B[x].first == B[y].first)
            return B[x].second > B[y].second;
        return B[x].first > B[y].first;
    });

    BIT<int> bit(N + 1);
    vector<int> ans(Q);

    int j = 0;
    REP(k, Q) {
        int i = ord[k];
        while (j < (int)A.size() && B[i].first <= A[j].first) {
            bit.add(A[j].second, 1);
            j++;
        }
        int l = B[i].first;
        int r = B[i].second;
        ans[i] = r - l + 1 - bit.sum(r);
    }

    REP(i, Q) { cout << ans[i] << "\n"; }

    return 0;
}


Measured memory_bytes: 18840
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    scanf("%lld", &N);
    vector<ll> P(N);
    ll minval;
    REP(ll,i,0,N) scanf("%lld", &P.at(i));
    ans = 1;
    minval = P.at(0);
    REP(ll,i,1,N){
        if ( minval >= P.at(i) ){
            ans++;
            minval = P.at(i);
        }
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main() {
  int i=0,j,k;
  double a,b,x;
  double ans;
  
  cin >> a >> b >> x;

  if (a*a*b/2<x)
  {
      double h = (2.0*((a*a*b)-x))/(a*a);
      ans = 180.0*(atan(h/a))/(acos(-1));
  }else
  {
      double h = (2.0*x)/(a*b);
      ans = 180.0*(atan(b/h))/(acos(-1));
  }
  
  



  printf("%f\n",ans);
  
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	long long a,b,c;
	long k;
	char p;
	cin >> a >> b >> c;
    getchar();
    cin >> k;
    while(b<=a){
    	b=b*2;
    	k--;
	}
	while(c<=b){
		c=c*2;
		k--;
	}
	if(k<0){
		printf("No");
	}
	else printf("Yes");
} 


Measured memory_bytes: 3656
#include<cstdio>
using namespace std;
int A, B, C;
int X;
int solve(){
int ans = 0;
for(int i = 0; i <= A; ++i){
for(int j = 0; j <= B; ++j){
for(int k = 0; k <= C; ++k){
int tmp = i * 500 + j * 100 + k * 50;
if(tmp == X) ans++;
}
}
}
return ans;
}
int main(){
scanf("%d%d%d%d", &A, &B, &C, &X);
int ans = solve();
printf("%d\n", ans);
return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
 
using namespace std;
#define sz(x) (int)(x).size()
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ll long long
const int N=3e5+5;


int main()
{	
	

	int n;

	cin>>n;

	std::vector<string> a(n);

	for(int i=0;i<n;i++)cin>>a[i],sort(all(a[i]));

	ll ans = 0;
 	map<string,int>occ;
	for(int i=0;i<n;i++){
		ans+=occ[a[i]];
		occ[a[i]]++;
	}

	printf("%lld\n",ans );
 	
}

Measured memory_bytes: 18176
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    String[] S;
    int[] P;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        N = sc.nextInt();
        S = new String[N];
        P = new int[N];
        for (int i=0; i<N; i++) {
        	S[i] = sc.next();
        	P[i] = sc.nextInt();
        }
    }
    
    //解答処理
    private List<Restaurant> solve() {
    	List<Restaurant> restaurant = new ArrayList<Restaurant>();
        
    	for (int i=0; i<N; i++) {
    		Restaurant res = new Restaurant();
    		res.setCity(S[i]); 
    		res.setPoint(P[i]);
    		res.setI(i+1);
    		restaurant.add(res);
    	}
    	
    	Collections.sort(restaurant);
        return restaurant;
    }
    
    //出力
    public void show(List<Restaurant> answer) {
        for (Restaurant restaulant : answer) {
			System.out.println(restaulant.getI());
		}
    }

}


class Restaurant implements Comparable<Restaurant>{
	private String city;
	private int point;
	private int i;
	
	//public String getCity() {
	//	return city;
	//}
	public void setCity(String city) {
		this.city = city;
	}
	//public int getPoint() {
	//	return point;
	//}
	public void setPoint(int point) {
		this.point = point;
	}
	public int getI() {
		return i;
	}
	public void setI(int i) {
		this.i = i;
	}

	//点数を比較するメソッド
	public int compareTo(Restaurant other) {
	    int ans = city.compareTo(other.city);
	    if (ans != 0) return ans;
	    return Integer.compare(other.point, point);
	  }
}


Measured memory_bytes: 35988
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

// 1indexed2dimention[]
class imos2d{
    public:
    vector<vector<ll> >t, v;
    ll h, w, flg;
    imos2d(ll H = 0, ll W = 0){
        flg = 0;
        h = H + 10;
        w = W + 10;
        v = vector<vector<ll> >(h, vector<ll>(w, 0));
        t = vector<vector<ll> >(h, vector<ll>(w, 0));
    }
    void add(ll x, ll y, ll val){
        flg = 0;
        t[y][x] += val;
    }
    void make(){
        flg = 1;
        for(ll y = 1; y < h; y++){
            for(ll x = 1; x < w; x++){
                v[y][x] = t[y][x] + v[y][x - 1];
            }
        }
        for(ll x = 1; x < w; x++){
            for(ll y = 1; y < h; y++){
                v[y][x] += v[y - 1][x];
            }
        }
    }
    ll sum(ll x1, ll y1, ll x2, ll y2){
        if(!flg)make();
        return v[y2][x2] + v[y1 - 1][x1 - 1] - v[y2][x1 - 1] - v[y1 - 1][x2];
    }
};

class bit1d{
    public:
    vector<ll>v;
    ll num;
    bit1d(ll NUM = 0){
        num = NUM + 10;
        v = vector<ll>(num, 0);
    }
    void add(ll idx, ll x){
        if(idx == 0)return;
        while(idx <= num){
            v[idx] += x;
            idx += idx & -idx;
        }
    }
    ll sum_of_1_to_idx(ll idx){
        if(idx <= 0)return 0;
        ll s = 0;
        while(idx > 0){
            s += v[idx];
            idx -= idx & -idx;
        }
        return s;
    }
    ll sum(ll l, ll r){
        return sum_of_1_to_idx(r) - sum_of_1_to_idx(l - 1);
    }
};

int main(){
    
    ll N;
    cin >> N;
    imos2d data(2000, 2000);
    vector<ll>v(2010);
    for(ll i = 1; i <= N; i++){
        ll x;
        cin >> x;
        data.add(i, x, 1);
        v[i] = x;
    }
    ll ans = 0;
    for(ll i = 1; i <= N; i++){
        for(ll j = i + 1; j < N; j++){
            ll a = v[i], b = v[j];
            ll mn = max(a - b, b - a) + 1;
            ll mx = a + b - 1;
            ans += data.sum(j + 1, mn, N, mx);
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

int main(void)
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    int d = (a[2] - a[1] + a[2] - a[0]);
    int k = (d + 1) / 2 + d % 2;
    cout << k << endl;
     
}


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

int main(void){
    int f[100];
    f[0]=f[1]=1;
    int n,i;
    cin>>n;
    
    for(i=2;i<=n;i++){
        f[i]=f[i-1]+f[i-2];
    }
    
    cout<<f[n]<<endl;
    
    return 0;
}


Measured memory_bytes: 3104
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


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

  int sl = s.length();
  if (s[0] != s[sl-1]) {
    if (sl%2 == 0) {
      cout << "Second" << endl;
    } else {
      cout << "First" << endl;
    }
  } else {
    if (sl%2 == 0) {
      cout << "First" << endl;
    } else {
      cout << "Second" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <string>
using namespace std;

int dp[1000][1000];
string grid[1000];

int main(){
    int H;
    int W;
    cin >> H >> W;

    for(int i = 0; i < H; i++){
        cin >> grid[i];
    }
    
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            dp[i][j] = 0;
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(i == 0 & j == 0){
                dp[0][0] = 1;
                continue;
            }
            if(grid[i][j] == '#'){
                continue;
            }
            if(i - 1 >= 0){
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % 1000000007;
            }
            if(j - 1 >= 0){
                dp[i][j] = (dp[i][j] + dp[i][j - 1]) % 1000000007;
            }
        }
    }
    cout << dp[H - 1][W - 1] << endl;

    /*
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    return 0;

}

Measured memory_bytes: 5248
#include <stdio.h>
int main(void) {
	int A,B,C,K;
	scanf("%d%d%d%d",&A,&B,&C,&K);
	if(K<=A)
	printf("%d",K);
	else if(A<K&&K<=A+B)
	printf("%d",A);
	else
	printf("%d",A-(K-(A+B)));
	return 0;
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int x,y,a,b,c;
int p[maxn],q[maxn],r[maxn];
priority_queue<int,vector<int>,greater<int> > q1,q2;
bool cmp(int a,int b){
	return a>b;
}
int sum1=0,sum2=0;
signed main(){
	x=read(),y=read(),a=read(),b=read(),c=read();
	for(int i=1;i<=a;i++)p[i]=read();
	for(int j=1;j<=b;j++)q[j]=read();
	for(int i=1;i<=c;i++)r[i]=read();
	sort(p+1,p+1+a,cmp);
	sort(q+1,q+1+b,cmp);
	sort(r+1,r+1+c,cmp);
	for(int i=1;i<=x;i++){q1.push(p[i]);sum1+=p[i];}
	for(int i=1;i<=y;i++){q2.push(q[i]);sum2+=q[i];}
	for(int i=1;i<=c;i++){
		int p1=q1.top(),p2=q2.top();
		if(p1<p2){
			if(r[i]>p1){
				q1.pop();
				q1.push(r[i]);
				sum1+=r[i];sum1-=p1;
			}
		}
		else{
			if(r[i]>p2){
				q2.pop();
				q2.push(r[i]);
				sum2+=r[i];sum2-=p2;
			}
		}
	}
	printf("%lld\n",sum1+sum2);
	return 0;
}


Measured memory_bytes: 4852
using System;

class B
{
	static void Main()
	{
		var h = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
		Console.WriteLine($"{Math.Max(0, h[0] - h[2])} {Math.Max(0, h[1] - Math.Max(0, h[2] - h[0]))}");
	}
}


Measured memory_bytes: 13268
import decimal
a,b,c=map(int,input().split())
a=decimal.Decimal(a)
b=decimal.Decimal(b)
c=decimal.Decimal(c)


if c-a-b>=0:
    if (c-a-b)**2>4*a*b:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

int main() {
    string s;
    cin >> s;
    int len = s.length();
    int m = INT_MAX;

    for(int i=0; i<=len-3; i++) {
        string tmp = "";
        for(int j=0; j<3; j++) {
            tmp += s[i+j];
        }
        int n = atoi(tmp.c_str());
        if(abs(n-753) < m)
            m = abs(n-753);
    }

    cout << m << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
int main()
{
  int N,i;
  scanf("%d",&N);
  for(i=1;i<=9;i++)
  {
    if(N%i==0&&N/i<=9)
    {
      printf("Yes");
      exit(0);
    }
  }
    printf("No");
}
  

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s,t; cin>>s>>t;
	int a,b; cin>>a>>b;
	string u; cin>>u;
	if(u==s) a--; else b--;
	cout << a SP b << endl;


  return 0;
}


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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
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 bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

lint N, M, L, Q;
lint dist[330][330];
lint dist2[330][330];

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

  cin >> N >> M >> L;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dist[i][j] = INF;
      dist2[i][j] = INF;
    }
    dist[i][i] = 0;
    dist2[i][i] = 0;
  }

  int a, b, c;
  for (int i = 0; i < M; i++) {
    cin >> a >> b >> c;
    a--;
    b--;
    dist[a][b] = dist[b][a] = c;
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        chmin(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (dist[i][j] <= L) dist2[i][j] = 1;
    }
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        chmin(dist2[i][j], dist2[i][k] + dist2[k][j]);
      }
    }
  }

  cin >> Q;
  int s, t;
  while (Q--) {
    cin >> s >> t;
    s--;
    t--;
    int ans = dist2[s][t] - 1;
    if (dist2[s][t] == INF) ans = -1;
    cout << ans << "\n";
  }

  return 0;
}

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

// 方針
// 条件を満たす時、N = m*商 + m が成立するときで、N = k(m+1)　∀k　∈　自然数　とあらわせる。
// このとき、Nは約数に　ｋ　と　ｍ＋１　をもつことを意味する。
// すなわち、自然数ｍは　「Nの約数　－　１」　に限定される。
// よって、Nの約数を列挙し、約数-1　に関して数え上げればいい。

// 約数の列挙
// 約数は配列に収納しておく。
// このとき、動的に配列を作っておくとよさそう。（vector）
// ちなみに、約数の列挙はO(√n)で作る必要あり。

vector<long long int> div(long long int n){
    vector<long long int> list;
    for(long long int i = 1;i*i < n;i++){
        if(n % i == 0){
            list.push_back(i);

            if(i * i != n)list.push_back(n / i);
        }
    }
    sort(list.begin(),list.end(),greater<long long int>()); //greaterつけると降順
    return list;

}

int main(){
    long long int N;
    cin >> N;
    vector<long long int> div_list = div(N);
    long long int count = 0;
    long long int temp = 0;


   
    for(int j = 0; j < div_list.size();j++){
        temp = div_list[j] - 1 ;
        if(temp == 0)continue;
       
        if((N / temp) == (N % temp)){
            count += temp;
        
        }

    }
    cout << count << endl;
}
    

Measured memory_bytes: 384
use strict;
my ($N) = split(/ /,<>);
my $s = <>;chomp $s;
my @dat = split(/ /,$s);
my $MAX = 10**6;
#@dat = sort{$a<=>$b}@dat; 
my %DB;
for(my $i=0;$i<=$#dat;$i++){
   if( defined($DB{$dat[$i]})){  $DB{$dat[$i]}++;next;}
   $DB{$dat[$i]}=1;       
}
foreach my $key ( sort{$a<=>$b} keys %DB){
    #print "$key\n";
    if($DB{$key}==0){next;}
    for(my $i=2;$i<=($MAX/$key);$i++){
        if( defined($DB{$key*$i})){
            $DB{$key*$i}=0;
        }
    }
}
my $count =0;
foreach my $key (keys %DB){
    if( $DB{$key} == 1){
        $count++;
    }
}

print "$count";

Measured memory_bytes: 63692
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a,b;
	cin>>a>>b;
	if (a>0){
		cout<<"Positive"<<endl;
		return 0;
	}
	if (a<=0&&b>=0){
		cout<<"Zero"<<endl;
		return 0;
	}
	if ((b-a)%2==0){
		cout<<"Negative"<<endl;
	}
	else{
		cout<<"Positive"<<endl;
	}
}

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


int main(){
    int d,g;
    cin >> d >> g;
    int p[10],c[10];
    bool e[10];
    rep(i,d) cin >> p[i] >> c[i];
    int ans = 1e9;
    for(int i=0; i<(1<<d); i++){
        for(int j=0; j<d; j++){
            if(i>>j & 1) e[j]=true;
            else e[j]=false;
        }
        int now = 0;
        int cost = 0;
        for(int j=0; j<d; j++){
            if(e[j]) {
                now += c[j]+100*(j+1)*p[j];
                cost += p[j];
            }
        }
        if(now >= g){
            ;
        }
        else{
            bool check = false;
            for(int j=d-1; j>=0; j--){
                if(e[j]) continue;
                //need more g-now points
                if(g-now <= (j+1)*100*p[j]){
                    cost += ( (g-now)%((j+1)*100) == 0 ? (g-now)/((j+1)*100) : (g-now)/((j+1)*100)+1);
                    check = true;
                    break;
                }else{
                    now -= (j+1)*100*p[j];
                    cost += p[j];
                }
            }
            if(!check) continue;
        }
        ans = min(ans,cost);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long c = in.nextLong();
		long k = in.nextLong();
		ArrayList<Long> t = new ArrayList<>();

		for(int i=0; i<n; i++){
			t.add(in.nextLong());
		}
		Collections.sort(t);

		long count = 0;
		int i = 0;

		while(t.size()>0){
			while(i<t.size() &&t.get(0)>=t.get(i)-k && i<c){
				i++;
			}
			count++;
			for(int j=0; j<i; j++){
				t.remove(0);
			}
			i = 0;
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 53684
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#define re register
const int MAXN=2e5+10;
int n,K,s[MAXN],a[MAXN],timee;
char fin[10010],*p1=fin,*p2=fin;
char getc()
{
	return p1==p2&&(p2=(p1=fin)+fread(fin,1,10000,stdin),p1==p2)?EOF:*p1++;
}
int read()
{
	re int x=0;
	re char ch=0;
	while(ch<'0'||ch>'9') ch=getc();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getc();
	return x;
}
inline void insert(int x,int w)
{
	for(;x<=n;x+=x&-x) s[x]+=w;
}
inline int query(int x)
{
	re int res=0;
	for(;x;x-=x&-x) res+=s[x];
	return res;
}
int main()
{
	//freopen("t2.out","w",stdout);
	n=read();
	K=read();
	for(re int i=1;i<=n;i++) a[i]=read();
	if(K>=41)
	{
		for(re int i=1;i<=n;i++) printf("%d ",n);
		return 0;
	}
	while(K--)
	{
		re bool flag=1;
		memset(s,0,(n+5)*sizeof(int));
		for(re int i=1;i<=n;i++) insert(std::max(1,i-a[i]),1),insert(std::min(n,i+a[i])+1,-1);
		for(re int i=1;i<=n;i++) a[i]=query(i),flag&=(a[i]==n);
		if(flag) break;
	}
	for(re int i=1;i<=n;i++) printf("%d ",a[i]);
	printf("\n");
	return 0;
}
/*
5 1
1 0 0 1 0
*/

Measured memory_bytes: 5204
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define loop(i,a,b) for(ll i=a; i<b; i++)
#define revloop(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define vl vector<ll>
#define vvl vector<vl>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define all(c) (c).begin(), (c).end()
#define sz(a) ((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i!=(c).end(); i++))
#define mp make_pair
#define ss second
#define ff first
#define ld long double
const ll INF = 1e13;
const ll N = 301;
const ll mod= 1000000007;
bool prime(ll x)
{
	if(x<2) return false;
	for(ll i=2; i*i<=x; i++) if(x%i==0) return false;
	return true;
}
vl fac(N);
void fact()
{
	fac[0]=1;
	loop(i,1,N) fac[i]=(fac[i-1]*i)%mod;
}

void solve()
{
  ll n; 
  cin>>n;
  vl a(n);
  loop(i,0,n) cin>>a[i];
  ll dp[n+1][n+1];
  loop(i,0,n) loop(j,0,n) dp[i][j]=0;
  loop(l,1,n)
  {
   loop(j,0,n-l)
   {
   	ll sum=0, temp = 10000000000000000;
   	loop(k,j,j+l)
   	{
   		temp = min(temp, dp[j][k]+dp[k+1][j+l]);
   		sum+=a[k];
	}
	sum+=a[j+l];
	dp[j][j+l]=temp+sum;
   }
  }
   cout<<dp[0][n-1];
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--) solve();
 return 0;
}

Measured memory_bytes: 1536
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"

using namespace std;
typedef long long ll;

int n;
ll wmax;
ll w[102];
int v[102];
ll dp[102][100010];
ll inf = 100000000000;

//x以降、y以上の価値で最小の重さ
int main()
{
  cin >> n >> wmax;
  for (int i = 0; i < n; i++)
  {
    cin >> w[i] >> v[i];
  }
  fill(dp[0], dp[101], inf);
  dp[n][0] = 0;
  for (int x = n - 1; x >= 0; x--)
  {
    for (int y = 0; y < 100010; y++)
    {
      if (y < v[x])
      {
        dp[x][y] = dp[x + 1][y];
      }
      else
      {
        dp[x][y] = min(dp[x + 1][y - v[x]] + w[x], dp[x + 1][y]);
      }
    }
  }
  int ans;
  for (int i = 0; i < 100010; i++)
  {
    if (dp[0][i] <= wmax)
    {
      ans = i;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 4e2+7;
int a[N];
ll sum[N], f[N][N];
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		sum[i] = sum[i-1]+a[i];
	}
	for(int i = 2; i <= n; i++)
	{
		for(int l = 1, r = i; r <= n; l++, r++)
		{
			f[l][r] = 1e18;
			for(int k = l; k < r; k++)
			{
				f[l][r] = min(f[l][r], f[l][k]+f[k+1][r]+sum[r]-sum[l-1]);
			}
		}
	}
	printf("%lld\n", f[1][n]);
	return 0;
}

Measured memory_bytes: 1536
k = int(input())

li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(li[k-1])

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

int main(){
	ios::sync_with_stdio(false);
	string s,t; cin>>s>>t;

	int ct=0, ans=0;
	for(int i=0; i<s.size(); i++){
		ct=0;
		for(int j=0; j<t.size(); j++){
			if(i+j>=s.size()){
				ct=0;
				break;
			}
			if(s[i+j]==t[j]) ct++;
		}
		ans = max(ans,ct);
	}

	cout << t.size() - ans << endl;
}


Measured memory_bytes: 3616
r,c = map(int,input().split())
l2 = [0]*(c+1)
for i in range(r):
  l = [int(x) for x in input().split()]
  print(*l,sum(l))
  for j in range(c):
    l2[j] += l[j]
  l2[c] += sum(l)
print(*l2)


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long
int main() {

	int n, m;
	scanf("%d%d", &n, &m);
	char arr[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> arr[i][j];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (arr[i][j] == '#') {
				bool flag = 0;
				if (i + 1 < n && arr[i + 1][j] == '#')
					flag = 1;
				if (i - 1 >= 0 && arr[i - 1][j] == '#')
					flag = 1;
				if (j + 1 < m && arr[i][j + 1] == '#')
					flag = 1;
				if (j - 1 >= 0 && arr[i][j - 1] == '#')
					flag = 1;
				if (!flag) {
					return printf("No\n"), 0;
				}

			}
		}

	}
	printf("Yes\n");
}


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

int main() {
  int a,b,c,d;
  string res;
  cin >> a >> b >> c >> d;
  if(a+b-c-d==0){
    res="Balanced";
  }else if(a+b-c-d<0){
    res="Right";
  }else{
    res="Left";
  }
  cout << res << endl;
}


Measured memory_bytes: 512
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations, permutations
from copy import deepcopy
import sys
import numpy as np
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    r = int(input())
    print(r*r)

Measured memory_bytes: 27132
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ma=0; int nema=0;
    int cp=-1;
    for(int i=0;i<n;i++){
        if(ma<a[i]){
            cp=i;
            ma=a[i];
        }
    }
    for(int i=0;i<n;i++){
        if(i==cp)continue;
        nema=max(nema,a[i]);
    }
    for(int i=0;i<n;i++){
        if(a[i]==ma){
            cout << nema << endl;
        }
        else{
            cout << ma << endl;
        }
    }
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
//#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
ll n, a, b;
ll sum1=0, sum2=0;
int main() {
	cin >> n >> a >> b;
	b -= a;
	a = 0;
	if (n < 2) {
		if (a != b) {
			cout << 0 << endl;
			return 0;
		}
	}
	if (a > b) {
		cout << 0 << endl;
		return 0;
	}
	sum1 = b;
	sum2 = (n - 1)*b;
	cout << sum2 - sum1 + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
/*for better*/
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define M 998244353
using namespace std;

ll n,h[100005],dp[100005][2];

ll fun(int i,int p)
{
	if(i==n-1)
		return 0;
	if(dp[i][p]!=-1)
		return dp[i][p];
	if(i>=n)
		return 1e9;
	return dp[i][p]=abs(h[i]-h[i+p])+min(fun(i+p,1),fun(i+p,2));
}

int main()
{
    fast; 
    int i;
    cin>>n;
    f(i,0,n)
    	cin>>h[i];
    memset(dp,-1,sizeof(dp));
    cout<<min(fun(0,1),fun(0,2));
}


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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll n; cin>>n;
	ll ret=LLONG_MAX;
	for (ll d=1; d*d<=n; d++)
		if(n%d==0)
			ret=min(ret,d+n/d-2);
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [int(c) for c in input().split()]
A.sort(reverse=True)
B = A[::-1]
l = 0
r = 10**6
def f(m):
  cnt = 0
  j = 0
  for i in range(N):
    while j<N:
      if A[i]+B[j]>=m:
        cnt += N-j
        break
      j += 1
  return cnt>=M
while l+1<r:
  n = (l+r)//2
  if f(n):
    l = n
  else:
    r = n
C = [0]
for i in range(N):
  C += [C[-1]+B[i]]
ans = 0
j = 0
m = 0
flag = False
for i in range(N):
  while j<N:
    if A[i]+B[j]>l:
      ans += C[-1]-C[j]+A[i]*(N-j)
      m += N-j
      break
    j += 1
ans += (M-m)*l
print(ans)

Measured memory_bytes: 14548
#include <iostream>

using namespace std;

int n,m,q;
int en[50][4];
int res[10];
int ma;

void se(int ac,int ba){
	if(ac==n){
		int can =0;
		for(int i=0;i<q;i++){
			if(res[en[i][1]-1]-res[en[i][0]-1]==en[i][2])can+=en[i][3];
		}
		if(can>ma)ma = can;
		return;
	}
	res[ac] = ba;
	se(ac+1,ba);
	if(ba<m)se(ac,ba+1);
}

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	cin>>n>>m>>q;
	for(int i=0;i<q;i++){
		for(int j=0;j<4;j++)cin>>en[i][j];
	}ma = 0;
	se(0,1);
	
	cout<<ma<<endl;
	
	return 0;
}

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

dp = [False]*(2*K + 1)
for i in range(K):
    if not dp[i]:
        for a in A:
            dp[i+a] = True
if dp[K]:
    print("First")
else:
    print("Second")


Measured memory_bytes: 40688
#include<stdio.h>

struct DICE {
		int data;
		struct DICE *N;
		struct DICE *E;
		struct DICE *S;
		struct DICE *W;
		struct DICE *B;
		};

struct DICE *turn(struct DICE *NOW,char com);


int main(void){
struct DICE A[6],*NOW;
int i;
char str[105];

for(i=0;i<6;i++){
	scanf("%d",&A[i].data);
}
A[0].N=&A[4];
A[0].E=&A[2];
A[0].S=&A[1];
A[0].W=&A[3];
A[0].B=&A[5];
NOW=&A[0];
scanf("%s",str);
i=0;
while(str[i]!='\0'){
	NOW=turn(NOW,str[i]);
	i++;
}
printf("%d\n",NOW->data);

return 0;
}

struct DICE *turn(struct DICE *NOW,char com){
	struct DICE *TEMP;
	TEMP=NOW;
	switch(com){
	case 'N':
		NOW=NOW->S;
		NOW->N=TEMP;
		NOW->S=TEMP->B;
		NOW->E=TEMP->E;
		NOW->W=TEMP->W;
		NOW->B=TEMP->N;
		break;
	case 'S':
		NOW=NOW->N;
		NOW->N=TEMP->B;
		NOW->S=TEMP;
		NOW->E=TEMP->E;
		NOW->W=TEMP->W;
		NOW->B=TEMP->S;
		break;
	case 'E':
		NOW=NOW->W;
		NOW->N=TEMP->N;
		NOW->S=TEMP->S;
		NOW->E=TEMP;
		NOW->W=TEMP->B;
		NOW->B=TEMP->E;
		break;
	case 'W':
		NOW=NOW->E;
		NOW->N=TEMP->N;
		NOW->S=TEMP->S;
		NOW->E=TEMP->B;
		NOW->W=TEMP;
		NOW->B=TEMP->W;
		break;
	}
	return(NOW);
}

Measured memory_bytes: 596