akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <map>
#include <limits>
#include <vector>
using namespace std;

typedef long long ll;

#ifdef MUTABLE
int mod;
#else
template<int mod>
#endif
struct ModInt {
  int val;
  ModInt inv() const{
    int tmp,a=val,b=mod,x=1,y=0;
    while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
    return ModInt(x);
  }
  ModInt():val(0){}
  ModInt(ll x){if((val=x%mod)<0)val+=mod;}
  ModInt pow(ll t){ModInt res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
  ModInt& operator+=(const ModInt& x){if((val+=x.val)>=mod)val-=mod;return *this;}
  ModInt& operator-=(const ModInt& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
  ModInt& operator*=(const ModInt& x){val=(ll)val*x.val%mod; return *this;}
  ModInt& operator/=(const ModInt& x){return *this*=x.inv();}
  bool operator==(const ModInt& x) const{return val==x.val;}
  bool operator!=(const ModInt& x) const{return val!=x.val;}
  bool operator<(const ModInt& x) const{return val<x.val;}
  bool operator<=(const ModInt& x) const{return val<=x.val;}
  bool operator>(const ModInt& x) const{return val>x.val;}
  bool operator>=(const ModInt& x) const{return val>=x.val;}
  ModInt operator+(const ModInt& x) const{return ModInt(*this)+=x;}
  ModInt operator-(const ModInt& x) const{return ModInt(*this)-=x;}
  ModInt operator*(const ModInt& x) const{return ModInt(*this)*=x;}
  ModInt operator/(const ModInt& x) const{return ModInt(*this)/=x;}
  static int get_mod() { return mod; }
};

#ifndef MUTABLE
using modint = ModInt<1000000007>;
#endif

template <int mod>
struct Factorial {
  using mint = ModInt<mod>;
  vector<modint> Fact, Finv;
public:
  Factorial(int _n): Fact(_n+1), Finv(_n+1) {
      Fact[0]=mint(1); for (int i = 0; i < _n; ++i) Fact[i+1]=Fact[i]*(i+1);
      Finv[_n]=mint(1)/Fact[_n]; for (int i = _n; i > 0; --i) Finv[i-1]=Finv[i]*i;
  }
  mint fact(int n,bool inv=0) { if (inv) return Finv[n]; else return Fact[n]; }
  mint nPr(int n,int r){ if (n<0||n<r||r<0) return mint(0); else return Fact[n]*Finv[n-r]; }
  mint nCr(int n,int r){ if (n<0||n<r||r<0) return mint(0); else return Fact[n]*Finv[r]*Finv[n-r]; }
};

using factorial = Factorial<1000000007>;


int main() {
  int n, k;
  cin >> n >> k;
  vector<int> la(n);
  for (int i = 0; i < n; ++i) { 
    cin >> la[i];
  }
  sort(la.begin(), la.end());
  factorial fact(n);
  modint ma = 0;
  modint mi = 0;
  for (int i = 0; i < n; ++i) {
    ma += fact.nCr(i, k-1)*la[i];
    mi += fact.nCr(n-i-1, k-1)*la[i];
  }
  modint ans = ma-mi;
  cout << ans.val << endl;
}



Measured memory_bytes: 1408
<>=~$";
for($i=0;$i<=$`;$i++){
	for($j=0;$j<=$`-$i;$j++){
		$k=$`-$i-$j;
		if($i*1000+$j*5000+$k*10000==$'){
			printf("%d %d %d",$k,$j,$i);
			exit
		}
	}
}
print"-1 -1 -1"

Measured memory_bytes: 384
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=5e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const double PI = acos(-1);

void solve(){
    //6
    int n;
    cin>>n;
    double arr[n];
    loop(n,i,0) {
        cin>>arr[i];
    }
    sort(all(arr,n));
    double res=(arr[0]+arr[1])/2;
    loop(n,i,2){
        res+=arr[i];
        res/=2;
    }
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


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

using ll =  long long;
using pint =  pair<int,int>;

#define INF 99999999
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i)) 
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(v,x) for(const auto& (x) : (v)) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義(使うときはINFも書き換えろ!!)
#define int long long
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());

int solve(int n){
  int res=n/10;
  int t=n/10,d=5;
  while(t/d>0){
    res+=t/d;
    d*=5;
  }
  return res;
}

signed main(void){
  int n;cin>>n;
  if(n%2==1) cout << 0 << endl;
  else printf("%lld\n",solve(n));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
struct edge{int to,cost;};

int main() {
  int n,m,s;
  cin >> n >> m >> s;
  vector<edge> G[n];
  rep(i,m) {
    edge e;
    int x;
    cin >> x >> e.to >> e.cost;
    G[x].pb(e);
  }
  int d[n];
  fill(d,d+n,MAX);
  d[s]=0;
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,s));
  while(!que.empty()) {
    P p=que.top();
    que.pop();
    int v=p.second;
    if(d[v]<p.first) continue;
    for(int i=0; i<G[v].size(); i++) {
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost) {
	d[e.to]=d[v]+e.cost;
	que.push(P(d[e.to],e.to));
      }
    }
  }
  rep(i,n) {
    if(d[i]==MAX) pr("INF");
    else pr(d[i]);
  }
  return 0;
}


Measured memory_bytes: 11224
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def main():
    a = I()
    print(a + a * a + a * a * a)
    

main()


Measured memory_bytes: 65416
from collections import defaultdict

N = int(input())

shops = defaultdict(list)
for i in range(N):
    Si, Pi = input().split()
    shops[Si].append({
        'no': i + 1,
        'point': int(Pi)
    })

for city, city_shops in sorted(shops.items(), key=lambda x:x[0]):
    for shops in sorted(city_shops, key=lambda x:(x['point']), reverse=True):
        print(shops['no'])


Measured memory_bytes: 3316
import collections
class Dinic:
    def __init__(self, n):
        self.n = n
        self.g = [[] for i in range(n)]
    def add_edge(self, fr, to, cap):
        self.g[fr].append([to, cap, len(self.g[to])])
        self.g[to].append([fr, 0, len(self.g[fr])-1])
    def add_multi_edge(self, v1, v2, cap1, cap2):
        self.g[v1].append([v2, cap1, len(self.g[v2])])
        self.g[v2].append([v1, cap2, len(self.g[v1])-1])
    def bfs(self, s):
        level = [-1]*self.n
        deq = collections.deque()
        level[s] = 0
        deq.append(s)
        while deq:
            v = deq.popleft()
            for e in self.g[v]:
                if e[1]>0 and level[e[0]]<0:
                    level[e[0]] = level[v] + 1
                    deq.append(e[0])
        self.level = level
    def dfs(self, v, t, f):
        if v==t: return f
        es = self.g[v]
        level = self.level
        for i in range(self.it[v], len(self.g[v])):
            e = es[i]
            if e[1]>0 and level[v]<level[e[0]]:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d>0:
                    e[1] -= d
                    self.g[e[0]][e[2]][1] += d
                    self.it[v] = i
                    return d
        self.it[v] = len(self.g[v])
        return 0
    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t]<0: break
            self.it = [0]*self.n
            while True:
                f = self.dfs(s, t, 10**9+7)
                if f>0:
                    flow += f
                else:
                    break
        return flow

X, Y, E = map(int, input().split())
dinic = Dinic(2+X+Y)
for i in range(X):
    dinic.add_edge(0, 2+i, 1)
for i in range(Y):
    dinic.add_edge(2+X+i, 1, 1)
for i in range(E):
    x, y = map(int, input().split())
    dinic.add_edge(2+x, 2+X+y, 1)
print(dinic.max_flow(0, 1))

Measured memory_bytes: 10060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <utility>
#include <unordered_map>
#include <numeric>
using namespace std;
#define fol(i,n) for (int i=0;i<n;i++)
int main(){
    int n,m,a,s,b;
    cin >>n;
    vector <int>t;
    fol(i,n){
        cin >>a;
        t.push_back(a);
    }
    s = accumulate(t.begin(), t.end(), 0);
    cin >>m;
    fol(i,m){
        cin >>a>>b;
        cout << s-t[a-1]+b <<endl;
    }
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
main () {
	string s;
  	int benar = 0, benar1 = 0;
  	cin>>s;
  	for (int i=0;i<s.length();i++) {
    	if (s[i] == 'A') {
        	benar++;
        } else if (s[i] == 'B') {
        	benar1++;
        }
    }
  
  if (benar > 0 && benar1 > 0) {
  	cout<<"Yes"<<endl;
  } else {
  	cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=105;

int n, ans=1e9;
int a[N];

int calc(int x)
{
	int cur=0;
	for(int i=1;i<=n;i++)
		cur+=abs(a[i]-x)*abs(a[i]-x);
	return cur;
}

int ternary_search(int lo, int hi)
{
	while(hi-lo>2)
	{
		int m1=(lo*2+hi)/3;
		int m2=(lo+hi*2)/3;
		if(calc(m1)<=calc(m2))
			hi=m2;
		else
			lo=m1;
	}
	int ans=calc(lo);
	for(int i=lo+1;i<=hi;i++)
		ans=min(ans, calc(i));
	return ans;
}

int32_t main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int ans=ternary_search(-100, 100);
	cout<<ans;
	return 0;
}


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

using namespace std;

#define pb			push_back
#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define hastr(s, c)		((s).find(c) != string::npos)

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
#ifndef	ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    int a[n + 9];
    for(int i = 0; i < n; ++i)	cin >> a[i];
    sort(a, a + n);
    ll s = 0;
    for(int i = 0; i < k; ++i)
    	s += a[i];
    cout << s << endl;
    return 0;
}


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

using namespace std;

namespace FastRead {
  const int Dim(5000);
  char ibuf[Dim];
  int ipos, ilen;
  char nc() {
    if (ipos == ilen) {
      ipos = 0;
      ilen = fread(ibuf, 1, Dim, stdin);
      if (!ilen) return EOF;
    }
    return ibuf[ipos++];
  }
  template<class T> void read(T& x) {
    char ch;
    int sgn = 1;
    while (!isdigit(ch = nc()))
      if (ch == '-')
        sgn = -1;
    x = ch - '0';
    while (isdigit(ch = nc()))
      x = x * 10 + (ch - '0');
    x *= sgn;
  }
}
using namespace FastRead;

vector < long long > aib;

long long Query (int poz) {
  long long ans = 0;
  while (poz > 0) {
    ans = max (ans, aib[poz]);
    poz -= poz & (-poz);
  }
  return ans;
}

void Update (int poz, long long val) {
  while (poz < (int)aib.size()) {
    aib[poz] = max (aib[poz], val);
    poz += poz & (-poz);
  }
}

int main () {
  int N;
  read(N);
  vector < int > h(N), a(N);
  for (int i = 0; i < N; ++i)
    read(h[i]);
  for (int i = 0; i < N; ++i)
    read(a[i]);
  aib.resize(N + 2);
  vector < long long > dp(N + 1);
  for (int i = 0; i < N; ++i) {
    long long best = Query (h[i] + 1) + a[i];
    if (best > dp[h[i]]) {
      dp[h[i]] = best;
      Update (h[i] + 1, dp[h[i]]);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= N; ++i)
    ans = max (ans, dp[i]);
  cout << ans;
}


Measured memory_bytes: 7948
import heapq

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

for i in range(len(A)):
    A[i] *= -1

heapq.heapify(A)
for _ in range(M):
    x = heapq.heappop(A)
    heapq.heappush(A, (-x//2)*(-1))

print(-sum(A))

Measured memory_bytes: 14184
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:64000000")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
using namespace std;

#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, b, a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979
#define x0 ikjnrmthklmnt
#define y0 lkrjhkltr
#define y1 ewrgrg

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<Int, Int> PLL;
typedef pair<double, double> PDD;
typedef complex<double> base;

const int INF = 1000000000;
const int BASE = 1000000007;
const int MAX = 20007;
const int MAXV = 100007;
const int MAXE = 100000;
const int ADD = 1000000;
const int MOD = 1000000007;
const int CNT = 800;


int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("distance.in",  "r", stdin);
    //freopen("distance.out", "w", stdout);
    //freopen("out.txt" , "w" , stdout);

	string s;
	cin >> s;
	FOR(i,0,4)
	{
		cout << s[i];
	}
	cout << ' ';

	FOR(i,4,12)
	{
		cout << s[i];
	}
	cout << endl;


    return 0;
}


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

int main(void) {

	int a,b;
	char op;
	
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='?'){
			break;
		}else if(op=='+'){
			printf("%d\n",a+b);
		}else if(op=='-'){
			printf("%d\n",a-b);
		}else if(op=='*'){
			printf("%d\n",a*b);
		}else if(op=='/'){
			printf("%d\n",a/b);
		}
	}
	return 0;
}

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

using namespace std;

using namespace std;
struct p
{
    int to;
    int dis;
};
vector<p>w[100009];
int val[100009];
void dfs(int x,int sign,int fa)
{
    for(int i=0;i<w[x].size();i++)
    {
        p s=w[x][i];
        if(s.to==fa)
            continue;
        if(s.dis%2==0)
            val[s.to]=sign;
        else
            val[s.to]=!sign;
        dfs(s.to,val[s.to],x);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++)
    {
        int q,u,e;
        cin>>q>>u>>e;
        w[q].push_back(p{u,e});
        w[u].push_back(p{q,e});
    }
    val[1]=1;
    dfs(1,1,0);
    for(int i=1;i<=n;i++)
        cout<<val[i]<<endl;
    return 0;
}


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

using namespace std;

bool isP(string s) {
	string rev = s;
	reverse(rev.begin(), rev.end());
	return (s == rev);
}

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

	string s;
	cin >> s;
	string s1 = "", s2 = "";
	int n = s.length();
	for(int i = 0; i < (n-1)/2; i++) {
		s1 += s[i];
	}
	for(int i = (n+3)/2 - 1; i < n; i++) {
		s2 += s[i];
	}
	if(isP(s1) and isP(s2) and isP(s)) {
		cout << "Yes\n";
	}
	else cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
/*
 Sarthak Jain
*/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
	return (a<b)?a:b;
}
int max(int a,int b){
	return (a>b)?a:b;
}
int fp(int a,int b){
	if(b==0) return 1;
	int x=fp(a,b/2);
	x=(x*x)%mod;
	if(b&1) x=(x*a)%mod;
	return x;
}

int sum(int n)
{
	return (n*(n+1))/2;
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

 int n;
 cin>>n;
 int ans=0;
 for(int i=1;i<=n;i++)
 {
 	ans+=i*sum(n/i);
 }
 cout<<ans;


}


Measured memory_bytes: 3584
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		//char[] c = sc.next().toCharArray();
		int INF = Integer.MAX_VALUE;
		int ans = INF;
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] W = new int[N];
		for(int i=0; i<N; i++){
			W[i] = Integer.parseInt(sc.next());
		}
		
		//Arrays.sort(W);
		
		for(int T=1; T<N; T++){
			int left = 0;
			int right = 0;
			for(int i=0; i<N; i++){
				if(i<=T){
					left += W[i];
				}else{
					right += W[i];
				}
			}
			int tmp = Math.abs(right-left);
			ans = Math.min(ans, tmp);
		}
		
		
		
		System.out.println(ans);
		
	}
	
	
}



Measured memory_bytes: 23124
N,K,Q=map(int,input().split())
A = [0] * N
if K>Q:
    for i in range(N):
        print("Yes")
else:
    for i in range(Q):
        a=int(input())-1
        A[a]+=1
    for k in range(N):
        if K>Q-A[k]:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 4680
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vectors<decltype(inner)>(x, inner); }
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int W,H;
bool inrange(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define MP make_pair
signed main(){
    int N,M,C; cin >> N >> M >> C;
    vector<int>lim(C);
    rep(i,C) cin >> lim[i];
    priority_queue<pii,vector<pii>>que;
    rep(i,N){
        pii temp;
        cin >> temp.first >> temp.second;
        swap(temp.first, temp.second);
        que.push(temp);
    }
    int ans = 0;
    while(M>0 && !que.empty()){
        pii temp = que.top();
        que.pop();
        if(lim[temp.second-1] == 0) continue;
        lim[temp.second-1]--;
        ans += temp.first;
        --M;
    }
    cout << ans << endl;
}



Measured memory_bytes: 5676
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
mt19937 rnd(1337);
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pNN pair <Node *, Node *>
#define SZ(x) (int)(x).size()
#define pii pair <int, int>
#define pb push_back
#define rev reverse
#define ins insert
#define ers erase
#define S second
#define F first
#define int ll
const int N = 1e5 + 10, INF = 1e9 + 10;

int cnt_div(int x) {
	int cnt = 0;
	for (int i = 1; i * i <= x; ++i) {
		if (x % i == 0) {
			if (i * i == x) {
				++cnt;
			} else {
				cnt += 2;
			}
		}
	}
	return cnt;
}

int res(int n, int k) {
	while (n % k == 0) {
		n /= k;
	}
	return n % k;
}

void solve() {
	int n;
	cin >> n;
	int ans = cnt_div(n - 1) - 1;
	for (int i = 2; i * i <= n; ++i) {
		if (n % i == 0) {
			if (res(n, i) == 1) {
				++ans;
			}
			if (i * i != n && res(n, n / i) == 1) {
				++ans;
			}
		}
	}
	cout << ans + 1;
}
 
signed main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    #ifdef Solenoid555
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    //cin >> t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>

using namespace std;

int main() {
    int N, M, s, c, ans = 0;
    map<int, int> m;
    cin >> N >> M;
    while (M--) {
        cin >> s >> c;
        if (m.count(s)) {
            if (m[s] != c) {
                cout << "-1" << endl;
                return 0;
            } else {
                continue;
            }
        }
        m.insert(make_pair(s, c));
        ans += c * (int) (pow(10, N - s) + 0.5);
    }

    if (N > 1 && m.count(1) && m[1] == 0) {
        cout << "-1" << endl;
        return 0;
    }
    if (N > 1 && !m.count(1)) {
        ans += 1 * (int) (pow(10, N - 1) + 0.5);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int H,W,N;
    cin >> H>>W>>N;
    if(H>=W){
        if(N%H!=0){
            cout << N/H+1 << endl;
        }
        else{
            cout << N/H << endl;
        }
    }
    else{
        if(N%W!=0){
            cout << N/W+1 << endl;
        }
        else{
            cout << N/W << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  int f[n][10];
  int p[n][11];

  rep(i,n){
    rep(j,10) cin >> f[i][j];
  }
  rep(i,n){
    rep(j,11) cin >> p[i][j];
  }

  ll ans = -1001001001;
  srep(t,1,pow(2,10)){
    ll tmp = 0;
    bitset<10> b(t);
    rep(i,n){
      int count = 0;
      rep(j,10){
        if(b[j]&f[i][j]) count++;
      }
      tmp+=p[i][count];
    }
    maxs(ans,tmp);
  }

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a-1;i>=b;i--)
#define rep0(i,n) for(int i=0;i<n;i++)
#define per0(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 

void solve() {
    int h, w; cin >> h >> w;
    char board[h][w];
    int x_board[h][w];
    int y_board[h][w];
    int tot = 0;
    rep0(i,h){
        rep0(j,w){
            cin >> board[i][j];
        }
    }

    rep0(i,h){
        if(board[i][0] == '#') x_board[i][0] = 0;
        else x_board[i][0] = 1;
    }
    rep0(j,w){
        if(board[0][j] == '#') y_board[0][j] = 0;
        else y_board[0][j] = 1;
    }
    rep0(i,h){
        rep(j,1,w){
            if(board[i][j] == '#'){x_board[i][j] = 0;}
            else x_board[i][j] = x_board[i][j-1] + 1;
        }
    }
    //rep0(i,h) rep0(j,w) cout << x_board[i][j];
    rep0(j,w){
        rep(i,1,h){
            if(board[i][j] == '#'){y_board[i][j] = 0;}
            else y_board[i][j] = y_board[i-1][j] + 1;
        }
    }
    rep0(i,h){
        per0(j,w-1){
            if(x_board[i][j] > 0) chmax(x_board[i][j], x_board[i][j+1]);
        }
    }
    rep0(j,w){
        per0(i,h-1){
            if(y_board[i][j] > 0) chmax(y_board[i][j], y_board[i+1][j]);
        }
    }
    rep(i,0,h){
        rep(j,0,w){
            chmax(tot, x_board[i][j] + y_board[i][j] - 1);
        }
    }
    cout << tot;
//    rep0(i,h) rep0(j,w) cout << x_board[i][j];
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <string> 
using namespace std; 
int main(){

 int a=0,b=0,time=0;
 int ans=0;
   
  cin >> time >> a >> b ;
  ans = time * a ;
  if(ans < b){
  	cout << ans  << endl;
  }else{
  	cout << b << endl;
  }
  

}


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

int main(){

  int n,a;
  cin >> n;
  vector<int> vec;

  for(int i = 0; i < n; i++){
    cin >> a;
    vec.push_back(a);
  }
  vec.insert(vec.begin(),0);
  vec.push_back(0);

  int sum = 0;
  for(int i = 1; i < vec.size(); i++){
    sum += abs(vec[i-1] - vec[i]);
  }

  for(int i = 1; i < vec.size()-1; i++){
    int ans = sum;
    int res = abs(vec[i-1] - vec[i]) + abs(vec[i] - vec[i+1]);
    ans += abs(vec[i-1] - vec[i+1]) - res;
    cout << ans << endl;
  }

  return 0;
}


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

int main()
{
    int n = 0;

    // input
    std::cin >> n;

    if (n < 0 || n > 100)
    {
        std::cout << "Error : out of range!" << std::endl;
        return -1;
    }

    int tmp;
    std::vector<int> a_i;

    // input
    for (int i = 0; i < n; ++i)
    {
        std::cin >> tmp;

        if (tmp < 1 || tmp >= 1000)
        {
            std::cout << "Error : out of range!!" << std::endl;
            return -2;
        }

        a_i.push_back(tmp);
    }

    // output
    for(int i = 0; i < n; ++i)
    {
        std::cout << a_i.at( (n - 1) - i );

        if ( n -1 != i )
        {
            std::cout << " ";
        }
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 3144
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int b = int.Parse(input[2]);
        int ab = int.Parse(input[1]) + b;

        char[] s = Console.ReadLine().ToCharArray();
        int cnt = 0, cntF = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'a' && cnt < ab)
            {
                cnt++;
                Console.WriteLine("Yes");
            }
            else if (s[i] == 'b' && cnt < ab)
            {
                
                if (cntF < b)
                {
                    cnt++;
                    cntF++;
                    Console.WriteLine("Yes");
                }
                else
                    Console.WriteLine("No");
            }
            else
                Console.WriteLine("No");

        }
    }
}


Measured memory_bytes: 15608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  cin>>s>>t;
  int ans=0;
  int n=s.size();
  for(int i=0;i<n;i++){
  	if(s[i]!=t[i]) ans++;
  }
  cout<<ans;
}

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

int N, M;
int cnt[100000];
bool in[100000];
int main() {
  cin >> N >> M;
  
  for(int i = 0; i < N; ++i) {
    cnt[i] = 1;
  }
  in[0] = true;
  
  for(int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    --cnt[a];
    ++cnt[b];
    if(in[a]) in[b] = true;
    if(cnt[a] == 0) in[a] = false;
  }
  cout << count(in, in + N, true) << endl;
}


Measured memory_bytes: 768
while True:
    
    has=[False, False, False, False]
    
    n=input()
    if n=='0':
        break
    te=[]
    te.append(n)
    has[int(n)]=True
    for adf in range(4):
        n=input()
        has[int(n)] = True
        te.append(n)
        
    if has[1] and has[2] and has[3]:
        for qwer in range(5):
            print(3)
    elif te[1]==te[2] and te[2]==te[3] and te[3]==te[4] and te[0]==te[4]:
        for asdd in range(5):
            print(3)
    elif not has[3]:
        for g in range(5):
            if te[g]=='1':
                print('1')
            else:
                print('2')
    elif not has[2]:
        for g in range(5):
             if te[g]=='3':
                print('1')
             else:
                print('2')
    else:
        for g in range(5):
            if te[g]=='2':
                print('1')
            else:
                print('2')


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    map<int, int> mp;
    rep(i, n)
    {
        mp[a[i]] += 1;
    }
    vector<pair<int, int>> list;
    for (auto itr = mp.begin(); itr != mp.end(); itr++)
    {
        list.push_back(make_pair(itr->second, itr->second));
    }
    SORT(list);
    if (list.size() <= k)
    {
        cout << "0" << endl;
        return 0;
    }
    else
    {
        int sum = 0;
        rep(i, list.size() - k)
        {
            sum += list[i].first;
        }
        cout << sum << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
	int n, k;
	string s;
	cin >> n >> k >> s;
	int unhappy = 0;
	for(int i = 0; i < n - 1; i++){
		if(s[i] != s[i + 1]) unhappy++;
	}
	unhappy = max(0, unhappy - 2 * k);
	int happy = n - 1 - unhappy;
	cout << happy << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
struct point
{
	int x, y, h;
}p[110];
int main()
{
	int n;
	int i, j, k, pp;
	int H, flag, h;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
		scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].h);
	pp = 1;
	while (!p[pp].h)pp++;
	for (i = 0; i <= 100; i++)
	{
		for (j = 0; j <= 100; j++)
		{
			flag = 0;
			H = p[pp].h + fabs(p[pp].x - i) + fabs(p[pp].y - j);
			if (!H)H = 0;
			for (k = 1; k <= n; k++)
			{
				h = H - fabs(p[k].x - i) - fabs(p[k].y - j);
				if (h<0)h = 0;
				if (h != p[k].h)
				{
					flag = 1;
					break;
				}
			}
			if(!flag)
				printf("%d %d %d", i, j, H);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

ll dsum(ll a){
	ll res = 0 ;
	while(a>0){
		res += a%10 ;
		a /= 10 ;
	}
	return res ;
}

int main(){
	ll n,a,b ;
	cin >> n >> a >> b ;
	ll ans = 0 ;
	for(int i=1;i<=n;i++){
		ll d = dsum(i) ;
		if(a<=d&&d<=b) ans += i ;
	}
	cout << ans << endl ;
}


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

int main(){
  long long mod = 1e9 + 7;
  int H, W; cin >> H >> W;

  string a[1005];
  for (int i=0; i<H; i++){
    cin >> a[i];
  }

  long long dp[1005][1005];
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++) dp[i][j] = 0;
  }
  
  queue<int> qi;
  queue<int> qj;
  qi.push(0);
  qj.push(0);
  dp[0][0] = 1;

  while (!qi.empty()){
    int i = qi.front();
    qi.pop();
    int j = qj.front();
    qj.pop();

    if (i == H - 1 && j == W - 1) break;

    if (j < W - 1){
      if (a[i][j+1] == '.'){
        if (dp[i][j+1] == 0){
          if (i == 0) dp[i][j+1] = dp[i][j];
          else {
            dp[i][j+1] = dp[i][j] + dp[i-1][j+1];
            if (dp[i][j+1] > mod) dp[i][j+1] -= mod;
          }
          qi.push(i);
          qj.push(j+1);
        }
      }
    }

    if (i < H - 1){
      if (a[i+1][j] == '.'){
        if (dp[i+1][j] == 0){
          if (j == 0) dp [i+1][j] = dp[i][j];
          else {
            dp[i+1][j] = dp[i][j] + dp[i+1][j-1];
            if (dp[i+1][j] > mod) dp[i+1][j] -= mod;
          }
          qi.push(i+1);
          qj.push(j);
        }
      }
    }
  }

  cout << dp[H-1][W-1] << endl;

  return 0;
}


Measured memory_bytes: 9216
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderMake.ABC164
{
    class ABC164C
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            Dictionary<string, string> dic = new Dictionary<string, string>();
            string c = Console.ReadLine();
            while (c != null)
            {
                if (dic.ContainsKey(c) == false)
                {
                    dic.Add(c, "");
                }
                c = Console.ReadLine();
            }
            Console.WriteLine(dic.Count);
        }
    }
}


Measured memory_bytes: 50056
from collections import defaultdict
import itertools

n = int(input())
li = [input() for _ in range(n)]
check = ['M', 'A', 'R', 'C', 'H']
res = []

ans = 0
d = defaultdict(int)

for i in li:
    if i[0] in check:
        d[i[0]] += 1
        res.append(i[0])
res = list(set(res))

arr = itertools.combinations(res,3)
for s,t,u in arr:
    ans += d[s] * d[t] * d[u]

print(ans)

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m, c;
  while (cin >> n >> m >> c) {
    vector<int> a(m);
    cin >> a;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      vector<int> b(m);
      cin >> b;
      int x = c;
      for (int j = 0; j < m; ++j) {
        x += a[j] * b[j];
      }
      cnt += (0 < x);
    }
    cout << cnt << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int s;
	int a,b;
	cin >> s;
	a = s /100;
	b = s % 100;
	if (a >= 1 && a <= 12 ) {
		if (b >= 1 && b <= 12) {
			cout << "AMBIGUOUS" << endl;
		} else {
		cout << "MMYY" << endl;
		}
	} else {
		if (b >= 1 && b <=12) {
		cout << "YYMM" << endl;
		}	
		else {
			cout << "NA" << endl;
		}
	}
	return 0;
}


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

int main(){
    string s;
    cin>>s;
    while(s[0]!='0'){
        int sum=0;
        for(int i=0;i<(int)s.size();i++){
            sum+=s[i]-'0';
        }
        cout<<sum<<endl;
        cin>>s;
    }
    return 0;
}



Measured memory_bytes: 3224
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  1e+5+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,W;
ll v[108],w[108];
ll dp[100007];
//<<-----Implement Functions Here---->>//

//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n>>W;
		ll total = 0;
		for(ll i=0;i<n;i++){cin>>w[i]>>v[i];total+=v[i];}
		for(ll i=0;i<=total;i++)dp[i] = 1e+18;dp[0] = 0;
		//for loop style
		for(ll i=0;i<n;i++)
		{
			for(ll j=total-v[i];j>=0;j--)
			{
				dp[j+v[i]] = min(dp[j+v[i]],dp[j]+w[i]);
			}
		}

		for(ll i=total;i>=0;i--)
		{
			if(dp[i]<=W){cout<<i;break;}
		}
		
	}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

   
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


template<typename T1, typename T2> 
ll gcd(T1 a, T2 b){
    if(b==0) return a; 
    return gcd(b, a%b);
}

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

    ll n, p;
    cin >> n >> p;
    ll bufp = p;
    map<ll, int> element;
    reps(i, 2, sqrt(p)){
        while(p%i == 0){
            element[i]++;
            p /= i;
        }
    }

    ll res = 1;
    for(auto const& e : element){
        if(e.second >= n) res *= pow(e.first, e.second/n);
    }

    if(n == 1) res = bufp;

    cout << res << endl;

    //mdeb(element);

    return 0;
}


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

typedef long long ll;

int N, K;

int get(int rem) {
	return rem > N ? 0 : (N - rem) / K + !!rem;
}

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

	ll ans = 0;	
	for (int a = 0; a < K; a++) {
		int b = (K - a) % K;
		if (!(2 * b % K))
			ans += (ll)get(a) * get(b) * get(b);
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    char a, b; cin >> a >> b;

    char ans;
    if (a == 'H') {
        if (b == 'H') {
            ans = 'H';
        } else {
            ans = 'D';
        }
    } else {
        if (b == 'H') {
            ans = 'D';
        } else {
            ans = 'H';
        }
    }

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

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    A, B, C, X, Y = MI()

    a = A * X + B * Y
    b = max(C * X * 2, C * Y * 2)
    c = C * X * 2 + B * max(Y - X, 0)
    d = C * Y * 2 + A * max(X - Y, 0)
    print(min(a, b, c, d))


if __name__ == '__main__':
    main()


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

ll N, M;
vector<ll> A, F;

int main() {
    cin >> N >> M;
    A.resize(N);
    F.resize(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];

    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());

    ll left = -1, right = 1e12;

    while (right - left > 1) {
        ll middle = (left + right) / 2;
        bool ok = [&]{
            ll s = 0;
            rep(i, N) {
                s += max(0ll, A[i] - middle / F[i]);
            }

            return s <= M;
        }();
        if (ok) right = middle; else left = middle;
    }

    cout << right << endl;
}

Measured memory_bytes: 3328
#include <stdio.h>
int main()
{
	int a,b,c,d,e,k;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	scanf("%d",&k);

	int h[10];
	h[0]=b-a;
	h[1]=c-a;
	h[2]=d-a;
	h[3]=e-a;
	h[4]=c-b;
	h[5]=d-b;
	h[6]=e-b;
	h[7]=d-c;
	h[8]=e-c;
	h[9]=e-d;

	int flag=0;
	for (int i = 0; i < 10; ++i)
	{
		if (h[i]>k)
		{
			flag=1;
		}
	}

	if (flag==1)
	{
		printf(":(\n");
	}else{
		printf("Yay!\n");
	}

}

Measured memory_bytes: 128