akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n, m; cin >> n >> m;
    vector<bool> seen(n, false);
    seen[0] = true;
    vint a(n, 1);

    rep(i, m){
        // prvec(a);
        int x, y; cin >> x >> y;
        x--; y--;
        if(seen[x] && a[x]==1){
            seen[x] = false;
            seen[y] = true;
            a[y]++;
            a[x]--;
        }else if(seen[x]){
            seen[y] = true;
            a[y]++;
            a[x]--;
        }else{
            a[y]++;
            a[x]--;
        }
    }

    int ans = 0;
    rep(i, n) ans += seen[i];
    pr(ans);
    return 0;}

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

#define X first
#define Y second

using namespace std;

const int N=100;
int n,k;

int cnt;
pair<int,int> Edge[N*N/2];

void Print()
{
    printf("%d\n",cnt);
    for(int k=1; k<=cnt; k++)
        printf("%d %d\n",Edge[k].X,Edge[k].Y);
}

int main()
{
    scanf("%d %d",&n,&k);
    int num=(n-1)*(n-2)/2;
    if(k>num)
    {
        printf("-1\n");
        return 0;
    }

    for(int i=2; i<=n; i++)
        Edge[++cnt]=make_pair(1,i);

    if(num>k)
    {
        for(int i=2; i<=n; i++)
            for(int j=i+1; j<=n; j++)
            {
                Edge[++cnt]=make_pair(i,j);
                if( --num == k )
                {
                    Print();
                    return 0;
                }
            }
    }
    Print();
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N;
	cin>>N;
	if(N==7){
		cout<<"Yes"<<endl;
		return 0;
	}
	while(N%4!=0)N-=7;
	if(N<4)
	cout<<"No"<<endl;
	else
	cout<<"Yes"<<endl;

	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int l = 1;
	while (true) {
		int x, y; cin >> x >> y;
		if (!x && !y)return 0;
		if (x > y) {
			cout << y << ' ' << x << endl;
		}
		else {
			cout << x << ' ' << y << endl;
		}
	}
}


Measured memory_bytes: 3080
#include <stdio.h>

int main(void){

  int a,b,i,d;
 
  while(1){
  scanf("%d %d",&a,&b);
if(a==0 && b==0)break;
 
  for(i=0;i<a;i++){

    for(d=0;d<b;d++)
{
    printf("#");
  } 
  printf("\n");
 
  
  }
  printf("\n");
  }
  
 
  return 0;
  }


Measured memory_bytes: 2104
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
const long long INF=9e15;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long id=0;id<N;id++) cin>>v.at(id)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(2);
  
  lin(S);

  ll p =(ll)floor(sqrt(S));

  ll i = p, j = p;

  while(true){
    if((i - 1) * (i - 1) < S && S <= i * i){
      p = i; break;
    }
    if((j - 1) * (j - 1) < S && S <= i * i){
      p = j; break;
    }

    i++; j--;

  }

  ll q = -S + p*p;


  cout << p << " " << 1 << " " << q <<" " << p << " " << "0 0" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include <math.h>
#include<vector>
#include<stack>
#include<malloc.h>
#define INF 0x3f3f3f3f
#define maxn 1000006
using namespace std;
int a[102];
int main()
{     int n,x,i,couts=0;
      cin>>n>>x;
      for(i=0;i<n;i++)
      {
          cin>>a[i];
      }
      sort(a,a+n);
      for(i=0;i<n;i++)
      {
         if(x-a[i]<0)
            break;
          x-=a[i];

          couts++;
       }
      if(x>0&&i==n)
        couts--;
       cout<<couts<<'\n';

 return 0;
}


Measured memory_bytes: 764
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        String s = sc.next();
        int fh = Integer.parseInt("" + s.charAt(0) + s.charAt(1));
        int sh = Integer.parseInt("" + s.charAt(2) + s.charAt(3));
        String ans;
        if (fh >= 0 && fh < 100 && sh > 0 && sh < 13) {
            if (sh >= 0 && sh < 100 && fh > 0 && fh < 13) {
                ans = "AMBIGUOUS";
            } else {
                ans = "YYMM";
            }
        } else if (sh >= 0 && sh < 100 && fh > 0 && fh < 13) {
            ans = "MMYY";
        } else {
            ans = "NA";
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 21844
#include<stdio.h>
int n,A[50];
int solve(int i,int m){
	if(m==0){return 1;}
	if(i>=n){return 0;}
	int res=solve(i+1,m) || solve(i+1,m-A[i]);
	return res;
}
int main(void)
{
	int q,M,i;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &A[i]);
	}
	scanf("%d", &q);
	for(i=0; i<q; i++){
		scanf("%d", &M);
			if(solve(0,M)){printf("yes\n");}
			else {printf("no\n");
			}
	}
	return 0;
}


Measured memory_bytes: 2144
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	string s, t, u; cin >> s >> t >> u;
    cout << "A" << t[0] << "C" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
sushis = N.times.map { gets.split.map(&:to_i) }.sort_by! { |sushi| -sushi[1] }
current_sushis = sushis[0...K]
used = Hash.new(false)
tpt = 0
dup_sushis = []
current_sushis.each do |sushi|
  tpt += sushi[1]
  dup_sushis << sushi if used[sushi[0]]
  used[sushi[0]] = true
end
dup_sushis.sort_by! { |sushi| sushi[1] }
# p sushis, current_sushis, dup_sushis, used

max_points = used.size ** 2 + tpt

sushis[K..-1].each do |sushi|
  next if used[sushi[0]]

  outdated_sushi = dup_sushis.shift
  break unless outdated_sushi

  tpt = tpt - outdated_sushi[1] + sushi[1]
  used[sushi[0]] = true

  max_points = [max_points, used.size ** 2 + tpt].max
  # p current_sushis, max_points
end

puts max_points

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

int dp[100005];
vector<int>v[100005];
int n;

int func(int pos)
{
    if(dp[pos]!=-1)return dp[pos];

    int re=0;

    for(int i=0;i<v[pos].size();i++)
    {

        re=max(re,1+func(v[pos][i]));

    }

   // cout<<re<<endl;

    return dp[pos]=max(re,1);

}

int main()
{
    int m;
    scanf("%d%d",&n,&m);

    memset(dp,-1,sizeof dp);

    for(int i=0;i<m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
    }

    int fi=0;

    for(int i=1;i<=n;i++)
    {
        fi=max(fi,func(i));
    }

    printf("%d\n",fi-1);

    return 0;
}


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

#define ar array
#define ll long long int

auto cmp = [] (const ar<int, 3> &a, const ar<int, 3> &b) {
    return a[2] > b[2];
    
};

const ll mod = 1e9 + 7;
int n, m;
vector<string> a;
vector<vector<ll>> vis;

bool isSafe(int x, int y) {
    return x >= 0 and y >= 0 and x < n and y < m and a[x][y] == '.' ; 
}

int bfs(int ix, int iy, int fx, int fy) {
    vis = vector<vector<ll>>(n, vector<ll>(m, INT_MAX));
    if (a[ix][iy] == '#' or a[fx][fy] == '#')
        return -1;
    priority_queue<ar<int, 3>, vector<ar<int, 3>>, decltype(cmp)> q(cmp);
    q.push({ix, iy, 0});
    vis[ix][iy] = 0;
    while (!q.empty()) {
        ar<int, 3> fr = q.top();
        q.pop();
        int x = fr[0], y = fr[1], c = fr[2];
        if (vis[x][y] < c)
            continue;
        // cout << x << ' ' << y << ' ' << fr[1] <<  endl;
        
        for (int i = -1; i <= 1; ++i) {
            int nx = x + i;
            if (isSafe(nx, y) and vis[nx][y] > c and a[nx][y] == '.' and a[x][y] == '.') {
                vis[nx][y] = c ;
                q.push({nx, y, c});
            }
            int ny = y + i;
            // if (x == 0 and ny == 1) {
            //     cout << "hi" << ' ' << vis[x][ny] << ' ' << c <<  '\n';
            // }
            if (isSafe(x, ny) and vis[x][ny] > c and a[x][ny] == '.'  and a[x][y] == '.') {
                vis[x][ny] = c ;
                // cout << x << ' ' << ny << "hi" << c <<  '\n';
                q.push({x, ny, c});
            }

        }
        // if (isSafe(x - 2, y - 2) and isSafe(x + 2, y + 2)) {
            for (int i = -2; i <= 2; ++i) {
                for (int j = -2; j <= 2; ++j) {
                    int nx = x + i, ny = y + j;
                    if (isSafe(nx, ny) and  vis[nx][ny] > c + 1 and a[nx][ny] == '.') {
                        vis[nx][ny] = c + 1;
                        q.push({nx, ny, c + 1});
                    }
                }

            }
        // }

    }
    if (vis[fx][fy] != INT_MAX)
        return vis[fx][fy];
    return -1;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
       cin >> n >> m;
       int ix, iy, fx, fy;
      cin >> ix >> iy >> fx >> fy;
       a = vector<string>(n);
       for (string &x : a)
        cin >> x;
      
      ix--, iy--, --fx, --fy;
      cout << bfs(ix, iy, fx, fy);
    }

    return 0;
}

Measured memory_bytes: 12496
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
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;}

int dp[100010];

int main(){
  int N;
  cin >> N;
  
  dp[0] = 0;
  
  for(int n = 1; n <= 100010; n++){
    int power = 1;
    dp[n] = 1 << 30;
    while(power <= n){
      dp[n] = min(dp[n], dp[n-power]+1);
      power *=6;
    }
    
    power = 1;
    while(power <= n){
      dp[n] = min(dp[n], dp[n-power]+1);
      power *=9;
    }
  }
  
  cout << dp[N];
  
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int n, i, j;
    char ch;
    char kind;
    char kinda[4] = {'S', 'H', 'C', 'D'};
    int nums;
    int cards[4][13];
    for(i = 0; i < 4; i++){
        for(j = 0; j < 13; j++){
            cards[i][j] = 0;
        }
    }
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%c", &ch);
        scanf("%c %d", &kind, &nums);
        for(j = 0; j < 4; j++){
            if(kind == kinda[j]){
                cards[j][nums - 1] = 1;
                break;
            }
        }
    }
    for(i = 0; i < 4; i++){
        for(j = 0; j < 13; j++){
            if(cards[i][j] == 0){
                printf("%c %d\n", kinda[i], j + 1);
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2056
while 1:
    try:
        t500, t1000 = map(float, input().split())
    except EOFError:
        break

    if t500 < 35.5 and t1000 < 71:
        print("AAA")
    elif t500 < 37.5 and t1000 < 77:
        print("AA")
    elif t500 < 40 and t1000 < 83:
        print("A")
    elif t500 < 43 and t1000 < 89:
        print("B")
    elif t500 < 50 and t1000 < 105:
        print("C")
    elif t500 < 55 and t1000 < 116:
        print("D")
    elif t500 < 70 and t1000 < 148:
        print("E")
    else:
        print("NA")



Measured memory_bytes: 5576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 301000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

int main(){
    ll K,A,B; cin >> K >> A >> B;
    ll bisket = 1;
    if(K+1 <= A){
        cout << K + 1 << endl;
        return 0;
    }
    if(A+2 >= B){
        cout << K + 1 << endl;
        return 0;
    }
    for(int i = 0; i < K; i++){
        if(bisket < A) bisket++;
        else {
            if((K-i) == 1){
                bisket++;
                break;
            } else if((K-i)%2 == 0){
                bisket += ((K-i)/2)*(B-A);
                break;
            } else {
                bisket += ((K-i)/2)*(B-A) + 1;
                break;
            }
        }
    }
    cout << bisket << endl;
}


Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Maybe as Maybe
import qualified Data.Char as Char
import Control.Monad

-------------------------------------------------------------------------------

main :: IO ()
main = do
    input <- getInput
    print (solve input)

getInput :: IO [Int]
getInput =
    runParser parser <$> B.getContents
    where
        parser = do
            n <- parseInt
            replicateM n parseInt

solve :: [Int] -> Int
solve xs =
    minimum $ map f xs
    where
        f n | n `mod` 2 == 0 = 1 + f (n `div` 2)
            | otherwise      = 0


-------------------------------------------------------------------------------

newtype Parser a =
    Parser (B.ByteString -> (a, B.ByteString))

instance Functor Parser where
    fmap f (Parser parser) =
        Parser $ \input ->
            let (v, remainder) = parser input in
                (f v, remainder)

instance Applicative Parser where
    pure v =
        Parser $ \input ->
            (v, input)

    (Parser parser1) <*> (Parser parser2) =
        Parser $ \input ->
            let
                (f, remainder1) = parser1 input
                (v, remainder2) = parser2 remainder1
            in
                (f v, remainder2)

instance Monad Parser where
    return = pure

    (Parser parser1) >>= f =
        Parser $ \input ->
            let
                (v, remainder) = parser1 input
                Parser parser2 = f v
            in
                parser2 remainder

consumeSpace :: Parser ()
consumeSpace =
    Parser $ \input ->
        ((), B.dropWhile Char.isSpace input)

lexeme :: Parser a -> Parser a
lexeme parser =
    consumeSpace *> parser

parseInt_ :: Parser Int
parseInt_ =
    Parser $ \input ->
        Maybe.fromJust (B.readInt input)

parseInt :: Parser Int
parseInt =
    lexeme parseInt_

parseChar :: Parser Char
parseChar =
    Parser $ \input ->
        Maybe.fromJust (B.uncons input)

runParser :: Parser a -> B.ByteString -> a
runParser (Parser parser) input =
    fst $ parser input

-------------------------------------------------------------------------------


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

#define _USE_MATH_DEFINES
#define reb(i,b,n)         for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n)           reb(i,0,n)
#define each(it,v)         for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v)        for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vsort(v)           sort((x).begin(), (x).end()
#define rvsort(v)          sort((x).rbegin(), (x).rend()
#define mp(a, b)           make_pair(a, b)
#define fi                 first
#define se                 second
#define pb                 push_back
#define dbg(x)             cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;
#define dbgArr(table, n)   rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define dbg2Arr(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}

using namespace std; using std::stringstream;

typedef long long       ll; typedef unsigned long long ull; typedef long double     ld;
typedef pair <int, int> P;  typedef pair <int, P>      PP;
typedef vector<int>     vi; typedef vector<vi>         vvi; typedef vector<ll>      vl;
typedef vector<P >      vP; typedef vector<char>       vc;  typedef vector<string>  vs;

static const int    INF  = 0x3f3f3f3f;
static const ll     INFL = 0x3f3f3f3f3f3f3f3fLL;
static const double EPS  = 1e-9;
static const ll     MOD  = 1000000007LL;

static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main(int argc, char *argv[])
{
    int N, K;
    cin >> N >> K;

    vector<bool> v(N, false);
    rep(i, K) {
        int d;
        cin >> d;
        rep(j, d) {
            int t;
            cin >> t;
            v[--t] = true;
        }
    }

    int ans=0;
    rep(i, N) {
        if (!v[i]) ans++;
    }

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


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

int main()
{
  int n,a[10000],i,min=10000000,max=-10000000;
  long int sum=0;

  cin>>n;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0;i<n;i++){
    if(a[i]<min) min=a[i];
    if(a[i]>max) max=a[i];
    sum+=a[i];
  }
  cout<<min<<" "<<max<<" "<<sum<<endl;
}


Measured memory_bytes: 1204
a = int(input())
b = {}
strings = ''
ans = 0

for i in range(a):
    check = False
    strings = ''.join(sorted(list(input())))
    if strings in b.keys():
      check = True
    if check == True:
      ans += b[strings]
      b[strings] += 1
    else:
      b[strings] = 1

print(ans)

Measured memory_bytes: 17808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
vector<double> k;
int main() {
    int n;
    cin>>n;
    double r=0,c=2;
    for(int i=0;i<n;i++)
        {cin>>r;k.pb(r);}
    r=0;
    for(int i=0;i<n-1;i++)
    {
        sort(k.begin(),k.end());
        c=k[0]+k[1];c/=2;
        k.erase(k.begin());
        k.erase(k.begin());
        k.push_back(c);
    }
    printf("%.10f",k[0]);
    return 0;
}
// ABAB
//


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
total = 0
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if A[mid]>=B[i]:
      right = mid
    else:
      left = mid
  left2 = -1
  right2 = N
  while right2-left2>1:
    mid2 = left2 + (right2-left2)//2
    if C[mid2]>B[i]:
      right2 = mid2
    else:
      left2 = mid2
  total+=right*(N-right2)
print(total)

Measured memory_bytes: 24052
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
const int MAX_N = 1000010;

int prime[MAX_N];
bool is_prime[MAX_N + 1];
void sieve(int n){
   int p = 0;
   for(int i = 0; i <= n; i++) is_prime[i] = true;
   is_prime[0] = is_prime[1] = false;
   for(int i = 2; i <= n; i++){
   if(is_prime[i]){
           prime[p++] = i;
           for(int j = 2*i; j <= n; j += i) is_prime[j] = false;
       }
   }
}
int dy[4] = {0, -1, 0, 1};
int dx[4] = {1, 0, -1, 0};

int m, st;
int a[2010][2010];
int dp[2010][2010];
int cnt[MAX_N];

int main() {
    sieve(MAX_N);
    while(1){
        cin >> m >> st;
        if(m + st == 0) break;
        rep(i, 0, 2010) rep(j, 0, 2010){
            a[i][j] = -1; dp[i][j] = -1;
        }
        memset(cnt, 0, sizeof(cnt));
        int l = 1, dir = 0, num = 1;
        int y = 1000, x = 1000;
        a[y][x] = num++;
        for(int i = 0;; i++){
            if(num > m) break;
            rep(j, 0, l){
                if(num > m) break;                
                y += dy[dir];
                x += dx[dir];
                a[y][x] = num++;
            }
            dir = (dir + 1) % 4;
            if(i % 2) l++;
        }
        // rep(i, 990, 1011){
        //     rep(j, 990, 1011){
        //         cout << a[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        int sy = -1, sx = -1;
        rep(i, 0, 2010) rep(j, 0, 2010) if(a[i][j] == st){
            sy = i; sx = j; i = 2010; break;
        }
        dp[sy][sx] = 0;
        if(is_prime[st]){
            dp[sy][sx] = 1;
            cnt[st] = 1;
        }
        rep(i, sy, 2000){
            rep(j, 0, 2000){
                if(dp[i][j] == -1) continue;
                rep(k, -1, 2){
                    int nxt = j + k;
                    if(nxt < 0) continue;
                    int nxtNum = a[i + 1][nxt];
                    if(nxtNum == -1 || !is_prime[nxtNum]){
                        dp[i + 1][nxt] = max(dp[i + 1][nxt], dp[i][j]);
                    }else{
                        dp[i + 1][nxt] = max(dp[i + 1][nxt], dp[i][j] + 1);
                        cnt[nxtNum] = max(cnt[nxtNum], dp[i][j] + 1);
                    }
                }
            }
        }
        int ans = 0, MAXid = 0;
        rep(i, 0, 2010) ans = max(ans, dp[2000][i]);
        if(ans != 0){
            rep(i, 0, MAX_N){
                if(cnt[i] == ans){
                    MAXid = i;
                }
            }
        }
        cout << ans << " " << MAXid << endl;
    }
}


Measured memory_bytes: 39852
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>

using namespace std;

int divup(int n, int k) {
    return (n + k - 1) / k;
}

int main() {
    int n, k;
    cin >> n >> k;
    cout << divup(n - 1, k - 1) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int h, w, i, j;
	char s[300];

	while(1) {
		scanf("%d%d", &h, &w);

		if(h == 0 && w == 0) break;

		for(i = 0; i < h; i++) {
			for(j = 0; j < w; j++) {
				printf(i == 0 || i == h - 1 || j == 0 || j == w - 1? "#" : ".");
			}
			printf("\n");
		}

		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 2040
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int main()
{
    double a,b,c,degree,S;
    cin>>a>>b>>degree;
    S=(0.5)*a*b*sin(M_PI*degree/180);
    c=sqrt(a*a+b*b-2*a*b*cos(M_PI*degree/180));
    printf("%.8lf\n",S);
    printf("%.8lf\n",a+b+c);
    printf("%.8lf\n",2*S/a);

}


Measured memory_bytes: 3420
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))

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 (b < a) { a = b; return true; } return false; }

template<class T> void dump(const vector<T> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

template<class T> void dump(int w, int h, const vector<T> &v)
{
	REP(j, h){
		REP(i, w-1){ cout << v[j * w + i] << " "; }
		cout << v[j * w + w-1] << endl;
	}
}

template<class T> struct Matrix
{
	T w, h;
	vector<T> A;
	Matrix(T w_, T h_) : w(w_), h(h_), A(w * h) {}
	T get(T x, T y) const { return A[y * w + x]; }
};

template<class T> void input(Matrix<T> &m)
{
	REP(j, m.h){
		REP(i, m.w){
			cin >> m.A[j * m.w + i];
		}
	}
}

template<class T> Matrix<T> prod(const Matrix<T> &a, const Matrix<T> &b)
{
	Matrix<T> m(b.w, a.h);

	REP(j, m.h){
		REP(i, m.w){
			ll c = 0;
			REP(k, a.w){
				c += a.A[j * a.w + k] * b.A[k * b.w + i];
			}
			m.A[j * m.w + i] = c;
		}
	}

	return m;
}

void dump(const Matrix<ll> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%lld ", m.A[j * m.w + i]); }
		printf("%lld\n", m.A[j * m.w + m.w-1]);
	}
}

void dump(const Matrix<double> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%f ", m.A[j * m.w + i]); }
		printf("%f\n", m.A[j * m.w + m.w-1]);
	}
}

string &to_upper(string &s)
{
	REP(i, s.length()){
		if('a' <= s[i] && s[i] <= 'z'){
			s[i] -= 32;
		}
	}

	return s;
}

string &to_lower(string &s)
{
	REP(i, s.length()){
		if('A' <= s[i] && s[i] <= 'Z'){
			s[i] += 32;
		}
	}

	return s;
}

int main()
{
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	printf("%.6f\n", sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));

	return 0;
}



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

using namespace std;

int main(void){
    int n, x, N;
    cin >> n >> x;
    N = n;
    
    if(x == 1 || 2 * n - 1 == x){
        cout<<"No"<<endl;
        return 0;
    }
    if(n == 2 && x != 2){
        cout<<"No"<<endl;
        return 0;
    }else if(n == 2 && x == 2){
        cout<<"Yes"<<endl;
        cout<<1<<endl;
        cout<<2<<endl;
        cout<<3<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    if(x < 2 * n - 2){
        vector<int> is_used(2 * N, 0);
        vector<int> ans(2 * N - 1, -1);
        ans[N - 1] = x;
        ans[N - 2] = x + 2;
        ans[N] = x - 1;
        ans[N + 1] = x + 1;
        is_used[x] = 1;
        is_used[x + 2] = 1;
        is_used[x - 1] = 1;
        is_used[x + 1] = 1;
        int cnt = 0;
        for(int i = 1;i <= 2 * N - 1;i++){
            if(is_used[i] == 0){
                while(ans[cnt] != -1)cnt++;
                ans[cnt] = i;
                cnt++;
            }
        }
        for(auto a : ans)cout<<a<<endl;
    }else{
        vector<int> is_used(2 * N, 0);
        vector<int> ans(2 * N - 1, -1);
        ans[N - 1] = x;
        ans[N - 2] = x - 2;
        ans[N] = x + 1;
        ans[N + 1] = x - 1;
        is_used[x] = 1;
        is_used[x - 2] = 1;
        is_used[x + 1] = 1;
        is_used[x - 1] = 1;
        int cnt = 0;
        for(int i = 1;i <= 2 * N - 1;i++){
            if(is_used[i] == 0){
                while(ans[cnt] != -1)cnt++;
                ans[cnt] = i;
                cnt++;
            }
        }
        for(auto a : ans)cout<<a<<endl;
    }
}


Measured memory_bytes: 3072
n = int(input())
a = list(map(int,input().split()))
sum_ = sum(a)
a.sort()
#print(a)
alice = 0
for i in range(len(a)):
    if i % 2 == 0:
        #print(a[-i-1],alice)
        alice += a[-i-1]
print(2*alice - sum_)
#print(alice)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int n;
cin>>n;
n%=10;
if(n==2||n==4||n==5||n==7||n==9)
{
	cout<<"hon\n";
}
else if(n==0||n==1||n==6||n==8)
{
		cout<<"pon\n";
}
else
{
		cout<<"bon\n";
}
return  0;
}





Measured memory_bytes: 3644
;グローバル変数
(setq *n* (read))
(setq *l* nil)

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

;マージソート実装
(defun merge-list (f l1 l2)
  (cond ((atom l1) l2)
        ((atom l2) l1)
        ((funcall f (car l1) (car l2))
         (cons (car l1) (merge-list f (cdr l1) l2)))
        (t (cons (car l2) (merge-list f l1 (cdr l2))))))

(defun merge-sort (f l n)
  (cond ((= n 1) (list (car l)))   ; 新しいリストを返す
        ((= n 2)
         (let ((x (first l)) (y (second l)))
           (if (funcall f x y) (list x y) (list y x))))
        (t (let ((m (truncate n 2)))
             ; リストを二分割し再帰呼び出しの結果をマージする
             (merge-list f
                         (merge-sort f l m)
                         (merge-sort f (nthcdr m l) (- n m)))))))

;ガイドブック順ソートの定義
(defun my< (a b)
  (cond
    ((equal (car a) (car b))
     (if (> (parse-integer (cadr a)) (parse-integer (cadr b))) t nil))
    ((string< (car a) (car b))
     t)
    (t nil)))

;入力
(dotimes (i *n*)
  (setq *l* (append *l* (list (append (split " " (read-line)) (list (1+ i)))))))

;ソート実行
(setq *l* (merge-sort #'my< *l* (length *l*)))

;出力
(format t "~{~a~^~%~}~%" (mapcar #'caddr *l*))


Measured memory_bytes: 16356
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf (1ll<<60)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll A, B, Q; cin >> A >> B >> Q;
    vll s(A); rep(i, A) cin >> s[i];
    vll t(B); rep(i, B) cin >> t[i];
    vll x(Q); rep(i, Q) cin >> x[i];

    sort(all(s)), sort(all(t));
    s.insert(s.begin(), -inf);
    t.insert(t.begin(), -inf);
    s.push_back(inf);
    t.push_back(inf);

    for (ll pos : x) {
        vll ns(2), nt(2);
        ll left = 0, right = s.size()-1;
        ll mid;
        while (left + 1 < right) {
            mid = (left + right) / 2;
            if (s[mid] < pos && pos <= s[mid+1]) {
                ns[0] = s[mid], ns[1] = s[mid+1];
                break;
            }

            if (s[mid] < pos) left = mid; else right = mid;
        }
        ns[0] = s[mid], ns[1] = s[mid+1];

        left = 0, right = t.size()-1;
        while (left + 1 < right) {
            mid = (left + right) / 2;
            if (t[mid] < pos && pos <= t[mid+1]) {
                nt[0] = t[mid], nt[1] = t[mid+1];
                break;
            }

            if (t[mid] < pos) left = mid; else right = mid;
        }
        nt[0] = t[mid], nt[1] = t[mid+1];

        ll minn = inf;
        rep(i, 2) rep(j, 2) minn = min(
            minn,
            abs(ns[i] - pos) + abs(nt[j] - ns[i])
        );

        rep(i, 2) rep(j, 2) minn = min(
            minn,
            abs(nt[i] - pos) + abs(ns[j] - nt[i])
        );
        cout << minn << endl;
    }
    return 0;
}

Measured memory_bytes: 3680
#include<stdio.h>

int check(int n, int* a, int count) {
  for (int i=0; i<n; i++) {
    if (a[i]%2 == 1) {
      return count;
    }

    a[i] = a[i]/2;
  }

  return check(n, a, count+1);
}

int main(void) {
  int a[200];
  int n;

  scanf("%d", &n);

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

  printf("%d\n", check(n, a, 0));

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#define I(i,n)for(int i=0,p=0;i<n;i++)
long long M=1e9+7,n,a[2],s[100000],w[2][100001],e[2],l[2][100000];
int main(){
	std::cin>>n>>*a>>a[1];
	I(i,n)std::cin>>s[i];
	I(k,2){w[k][0]=1;I(i,n){while(s[i]-s[p]>=a[k]&&p<i-1)p++;l[k][i]=p;}}
	I(i,n){if(i){
		I(k,2)w[k][i]=(e[!k]<=l[k][i])*w[!k][l[k][i]];
		I(k,2)if(s[i]-s[i-1]<a[k])e[k]=i;else(w[k][i]+=w[k][i-1])%=M;
	}}
	std::cout<<(w[0][--n]+w[1][n])%M;
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

int damerau_levenshtein_distance(const string &a,const string &b,const int alphabet_size){
    unordered_map<int,int> da;
    unordered_map<int,map<int,int>> d;
    int maxdist=a.size()+b.size();
    d[-1][-1]=maxdist;
    for(int i=0; i<=a.size(); ++i){
        d[i][-1]=maxdist;
        d[i][0]=i;
    }
    for(int i=0; i<=b.size(); ++i){
        d[-1][i]=maxdist;
        d[0][i]=i;
    }
    for(int i=1; i<=a.size(); ++i){
        int db=0;
        for(int j=1; j<=b.size(); ++j){
            int k=da[b[j-1]],l=db,cost;
            if(a[i-1]==b[j-1]){
                cost=0;
                db=j;
            }else cost=1;
            d[i][j]=min({d[i-1][j-1]+cost,d[i][j-1]+1,d[i-1][j]+1,d[k-1][l-1]+(i-k-1)+1+(j-l-1)});
        }
        da[a[i-1]]=i;
    }
    return d[a.size()][b.size()];
}

void solve(int n){
    int d;
    vector<string> name(n);
    cin >> d;
    rep(i,0,n) cin >> name[i];
    sort(name.begin(),name.end());

    int count=0;
    rep(i,0,n){
        rep(j,i+1,n){
            if(damerau_levenshtein_distance(name[i],name[j],26)>d) continue;
            ++count;
            cout << name[i] << "," << name[j] << endl;
        }
    }
    cout << count << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    for(;;){
        int n;
        cin >> n;
        if(!n) break;
        solve(n);
    }
    return 0;
}

Measured memory_bytes: 3132
sentence = input()
sentence_len = len(sentence)
iter_num = int(sentence_len/2)-1 if sentence_len % 2 == 0 else int(sentence_len/2)

counter = 0

for i in range(iter_num+1):
    if sentence[i] == sentence[sentence_len-i-1]:
        pass
    else:
        counter += 1
        
print(counter)

Measured memory_bytes: 2940
/*
  Contest 068
  B - Break Number
  Rakesh Kumar --> 01/09/2020
 */

#include <bits/stdc++.h>

/*
  Maths question -->
  Max div by 2 number will be log2(n)
*/

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);
    int n = 0;
    std::cin >> n;
    std::cout << (1 << static_cast<int>(std::floor(std::log2(n)))) << std::endl;

    return 0;
}


Measured memory_bytes: 3832
def main():
    num = int(input())
    dp = [[0, 0, 0] for i in range(num)]
    dp[0] = list(map(int, input().split()))

    for i in range(1, num):
        data = list(map(int, input().split()))
        for j in range(3):
            dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + data[j]

    print(max(dp[-1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 56352
arr = raw_input().split(' ')
n = int(arr[0])
k = int(arr[1])
l = raw_input().split(' ')
l = map(int,l)
l.sort()
for i in l:
	i = int(i)
ans = 0
for i in range(n-k, n):
	ans = l[i] + ans
print ans

Measured memory_bytes: 2692
#include<stdio.h>
#define min(x, y) ((x) < (y) ? (x) : (y))
int main(){
  int n, m, i;
  while(1){
    scanf("%d", &n);
    if(n == 0)return 0;
    scanf("%d\n", &m);
    int ppo = 0, po = 0, ppi = 0, pi = 0, res = 0;
    for(i = 0;i < m;i++){
      char c = getchar();
      int ni = 0, no = 0;
      if(c == 'I'){
	ni = ppi + 1;
	if(n <= min(ni - 1, po)){
	  res++;
	}
      }
      else{
	no = ppo + 1;
      }
      ppo = po;
      ppi = pi;
      po = no;
      pi = ni; 
    }
    printf("%d\n",res);
  }
}

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

const int MAXN = 100005;

struct node {
	int to, next;
} edge[MAXN*2];
int head[MAXN], top = 0;
inline void push(int i, int j)
{ edge[++top] = (node){j, head[i]}, head[i] = top; }

int n, u, v, d[MAXN];
int vis[MAXN];
queue<int> que;

#define NEW 0
#define LEAF 1
#define DEL 2
#define CHO 3

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	if (n == 1) {
		puts("First");
		return 0;
	}
	for (int i = 1; i < n; i++) {
		cin >> u >> v;
		push(u, v), push(v, u), d[u]++, d[v]++;
	}
	for (int i = 1; i <= n; i++)
		if (d[i] == 1)
			vis[i] = LEAF, que.push(i);
	while (!que.empty()) {
		int nd = que.front(); que.pop();
		if (vis[nd] == LEAF) {
			vis[nd] = DEL;
			int flag = 1;
			for (int i = head[nd]; i; i = edge[i].next) {
				int to = edge[i].to;
				if (vis[to] == CHO) {
					puts("First");
					return 0;
				} else if (vis[to] == LEAF) flag = 0, vis[to] = DEL;
				else if (vis[to] == NEW) {
					d[to]--;
					vis[to] = CHO, que.push(to);
					flag = 0;
				}
			}
			if (flag) {
				puts("First");
				return 0;
			}
		} else if (vis[nd] == CHO) {
			vis[nd] = DEL;
			for (int i = head[nd]; i; i = edge[i].next) {
				int to = edge[i].to;
				if (vis[to] == NEW) {
					if ((--d[to]) == 1) vis[to] = LEAF, que.push(to);
				} 
								    
			}
		} else if (vis[nd] == DEL) continue;
	}
	puts("Second");
	return 0;
}


Measured memory_bytes: 3200
h, n = map(int, input().split())

inf = 10**9
magic = []
c = 0
for i in range(n):
	a, b = map(int, input().split())
	magic.append([a,b])
	c = max(c,a)

dp = [inf] * (h+c)

for i, j in magic:
	dp[i] = min(dp[i],j)

for i in range(len(dp)):
	for j in range(n):
		if i - magic[j][0] <= 0 or dp[i-magic[j][0]] == inf:
			continue
		else:
			dp[i] = min(dp[i],dp[i-magic[j][0]] + magic[j][1])

print (min(dp[h:]))


Measured memory_bytes: 42220
#include<stdio.h>
#include<math.h>

int n,m,sum=0,i,in;
int main()
{
     scanf("%d %d",&n,&m);
     for( i=1;i<=m;i++) {scanf("%d",&in); sum=sum+in;}
     sum=n-sum;
     if(sum<0) {printf("-1\n");return 0;}
     printf("%d\n",sum);
}


Measured memory_bytes: 1732
//BUGSBUNNY
//IIT ROORKEE
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
#define mod 1000000007
// #define mod 163577857 
// #define mod 998244353
#define rep(i,n) for (int i = 0; i < n; i++)
#define repp(i,a,b) for(int i = a ; i<b ; i++)
#define reppr(i,a,b) for(int i = a-1 ; i>=b ; i--)
#define repr(i,n) for (int i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprec(x) cout << fixed << setprecision(x);
#define REVERSE(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()
 
//GCD and LCM
    int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
    int lcm (int a, int b) { return a / gcd(a, b) * b; }
 
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
 
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }


void solve();
signed main()
{
    //-------------------------------------------------------------------------------   
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        clock_t clk = clock();
    //-------------------------------------------------------------------------------   
    //-------------------------------------------------------------------------------
        int t = 1;
        // cin >> t;       
        rep(i,t)
        {
            // cout << "Case #" << i+1 << ": ";
            solve();
        }
    //-------------------------------------------------------------------------------
        clk = clock() - clk;
        cerr << fixed << setprecision(12) << "Time: " << ((double)clk)/CLOCKS_PER_SEC;
    //-------------------------------------------------------------------------------
}

void solve()
{
    int a , b , c , k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    ans += min(a,k);
    k -=  min(a,k);
    // ans += min(a,k);
    k -=  min(b,k);
    ans -= min(c,k);
    k -=  min(c,k);
    cout << ans << endl;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int N, K;
vector<int> G[2005];

int dfs(int u, int p, int d){
    int res = 0;
    for(auto v : G[u]) if(v != p) res += dfs(v, u, d+1);
    if(d>K/2) res++;
    return res;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N >> K;
    for(int i=0;i<N-1;i++){
        int a, b; cin >> a >> b;
        G[a].push_back(b); G[b].push_back(a);
    }

    int ans = N;
    for(int i=1;i<=N;i++){
        if(K%2){
            for(auto u : G[i]) if(i<u) ans = min(ans, dfs(i, u, 0)+dfs(u, i, 0));
        }
        else ans = min(ans, dfs(i, -1, 0));
    }

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

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

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const ll MOD = 1e9+7;

/**グローバル変数**/
int n,ans,cnt;
string s;

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

cin >> n;
int a[n] = {};
for (int i = 0; i < n; i++) {
  cin >> a[i];
}
sort(a,a+n);
int sum = 0;
for (int i = 0; i < n-1; i++) {
  sum += a[i];
}
cout << (sum > a[n-1] ? "Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
function Main(input) {
  var inputs = input.split(" ");
  var k = Number(inputs[0]);
  var s = Number(inputs[1]);
  var cnt = 0;
 
  for (var x = 0; x <= k; x++)
    for (var y = 0; y <= k; y++) if (s - (x + y) >= 0 && s - (x + y) <= k) cnt++;
  console.log(cnt)
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1LL << 62;
constexpr ll MAX_T = 1e5;

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

    ll N, C;
    cin >> N >> C;

    vector<vector<ll> > recs(C, vector<ll>(2 * MAX_T + 1, 0));
    for (ll i = 0; i < N; i++) {
        ll s, t, c;
        cin >> s >> t >> c;
        c--;
        recs[c][2 * s - 1] += 1;
        recs[c][2 * t] -= 1;
    }

    for (ll c = 0; c < C; c++) {
        for (ll i = 1; i < recs[c].size(); i++) {
            recs[c][i] += recs[c][i - 1];
        }
    }

    vector<ll> record_per_time(2 * MAX_T + 1, 0);
    for (ll i = 0; i < record_per_time.size(); i++) {
        for (ll c = 0; c < C; c++) {
            if (recs[c][i]) {
                record_per_time[i]++;
            }
        }
    }

    cout << accumulate(record_per_time.begin(), record_per_time.end(), 0LL, [](ll l, ll r) {
        return max(l, r);
    }) << endl;

    return 0;
}




Measured memory_bytes: 48768