akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	LL n; cin >> n;
	vector<LL> a(n);

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

	LL cnt = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] < 0)cnt++;
	}

	LL sum = 0;
	LL mi = INF2;
	for (int i = 0; i < n; i++) {
		LL tmp = abs(a[i]);
		sum += tmp;

		mi = min(mi, tmp);
	}

	if (cnt % 2 == 0) {
		cout << sum << endl;
	}
	else {
		cout << sum - 2 * mi << endl;
	}

	
	return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int main(){
  ll k, a, b;
  cin >> k >> a >> b;
  ll res = 1;
  ll num = 0;
  num =  a-1;
  ll nokori = k - num;

  if(nokori < 2 || b - a <= 2){
    cout << k+1 << endl;
    return 0;
  }

  res = a;
  res += (b - a) * (nokori / 2);

  if(nokori % 2 == 1){
    res++;
  }
  cout << res << endl;

}


Measured memory_bytes: 256
N, M = map(int,input().split())
count = yen = imp = 0
li = [list(map(int,input().split())) for i in range(N)]
li.sort()
for i in range(0,len(li),1):
  count += li[i][1] 
  yen += li[i][0]*li[i][1] 
  if count > M:
    imp = abs(M-count)
    count -= abs(M-count)
    yen -= li[i][0]*imp
  if count == M: 
    break
print(yen)

Measured memory_bytes: 27880
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
	        int A = sc.nextInt();
	        int B = sc.nextInt();
	        int K = sc.nextInt();
	        int cnt = 0;
	        int ans = 0;
	        
	        for(int i=100; i>0; i--){
	        	if(A % i == 0){
	        		if(B % i == 0){
	        			cnt = cnt +1;
	        			if (K == cnt){
	        				ans = i;
	        				break;
	        			}
	        		}
	        	}
	        }
	        System.out.println(ans);
	}
}

Measured memory_bytes: 21588
N, K = map(int, input().split())
MOD = 10**9+7
edge = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(lambda x:int(x)-1, input().split()) # 0-indexed
    edge[a].append(b)
    edge[b].append(a)

def P(n, k):
    ans = 1
    for i in range(k):
        ans *= n
        ans %= MOD
        n -= 1
    return ans

visit = [False]*N

def dfs(v):
    Stack = [v]
    visit[v] = True
    ans = K
    while Stack:
        v = Stack.pop()
        if v == 0:
            color = K-1
            ans *= P(color, len(edge[v]))
            ans %= MOD
        else:
            color = K-2
            child = 0
            for i in edge[v]:
                if not visit[i]:
                    child += 1
            ans *= P(color, child)
            ans %= MOD
        for i in edge[v]:
            if not visit[i]:
                visit[i] = True
                Stack.append(i)
    return ans

print(dfs(0))




Measured memory_bytes: 71456
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000007
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



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

int n;
cin>>n;

int b = n;
int sum = 0;
while(n)
{
    sum+=n%10;
    n/=10;
}

if(b%sum)
    cout<<"No"<<endl;
else
    cout<<"Yes"<<endl;

 return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
	long long int nn = s.size();
	long long int n = 0;
	for (long long int i = 0; i < s.size(); i++) {
		if (s[i] == 'S') {
			n++;
		} else if (s[i] == 'T') {
			if (n > 0) {
				n--;
				nn -= 2;
			}
		}
	}
	cout << nn << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=500010;
using namespace std;
int head[N],tot=0,a[N],n,pos[N],ans[N],k,cnt=-1;
vector<int>G[N];
int maxv[N<<2];
#define lson (o<<1)
#define rson (o<<1|1)
inline void pushup(int o){maxv[o]=max(maxv[lson],maxv[rson]);}
inline void change(int o,int l,int r,int q,int v){
	if(l==r)return void(maxv[o]=v);
	int mid=(l+r)>>1;
	if(q<=mid)change(lson,l,mid,q,v);
	if(q>mid)change(rson,mid+1,r,q,v);
	pushup(o);
}
inline int query(int o,int l,int r,int ql,int qr){
	if(ql<=l&&r<=qr)return maxv[o];
	int mid=(l+r)>>1,ans=0;
	if(ql<=mid)ans=max(ans,query(lson,l,mid,ql,qr));
	if(qr>mid)ans=max(ans,query(rson,mid+1,r,ql,qr));
	return ans;
}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
inline void addedge(int u,int v){G[u].push_back(v);}
inline void dfs(int u){
	ans[++cnt]=u;
	sort(G[u].begin(),G[u].end());
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];
		dfs(v);
	}
}
int main(){
	n=read();k=read();
	for(int i=1;i<=n;i++)a[i]=read(),pos[a[i]]=i;
	pos[n+1]=n+1;
	for(int i=1;i<=n;i++){
		int pre=query(1,1,n,pos[i]+1,pos[i]+k-1);
		if(!pre)pre=n+1;
		addedge(pos[pre],pos[i]);
		change(1,1,n,pos[i],i);
	}
	dfs(n+1);
	for(int i=1;i<=n;i++)a[ans[i]]=i;
	for(int i=1;i<=n;i++)printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 59392
fn main() {
  let (n, l): (i32, i32) = read_tuple();
  let vec: Vec<i32> = read_vec();
  
  let mut knot = None;
  for (w, i) in vec.windows(2).zip(1..) {
    if w[0] + w[1] >= l {
      knot = Some(i);
      break;
    }
  };
  
  let mut ans: Vec<i32> = vec![];
  match knot {
    None => {
      println!("Impossible");
      return
    },
    
    Some(i) => {
      println!("Possible");
      for j in 1 .. i {
        ans.push(j);
      }
      for j in (i .. n).rev() {
        ans.push(j);
      }
      print_vec(&ans, " ");
    }
  }
}

fn read_tuple<T1: std::str::FromStr, T2: std::str::FromStr>() -> (T1, T2) {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  (x, y)
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
}

fn print_vec<T: std::string::ToString>(vec: &Vec<T>, sep: &str) {
  let out = vec.iter().map(|e| e.to_string()).collect::<Vec<_>>().as_slice().join(sep);
  println!("{}", out);
}

Measured memory_bytes: 10492
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int sqfun(int val){
	int a=0;
	double sq=sqrt(val);
  if((sq - floor(sq)) == 0)
  {a=1; }
  return a;
}
int main() {
	int n,d;
	cin>>n>>d;
	int ans=0;
	int a[n][d];
	for(int i=0;i<n;i++){
	    for(int j=0;j<d;j++){
	        cin>>a[i][j];
	    }
	}
	for(int i=0;i<n-1;i++){
		int val,v1;
		for(int k=i+1;k<n;k++){
		    val=0;v1=0;
		for(int j=0;j<d;j++){
			val+=pow(abs(a[i][j]-a[k][j]),2);
		}
		v1=sqfun(val);
	//	cout<<v1<<"v1"<<endl;
		ans=ans+v1;
		
	}
	}

	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int main()
{
	ll n , m;
	cin >> n >> m;
	if(abs(n - m) >= 2)
		return cout << 0 ,0;
	ll ans = 1LL;
	for(ll i = 1 ; i <= n ; i++)
		ans = (ans*i)%mod;
	for(ll i = 1 ; i <= m ; i++)
		ans = (ans*i)%mod;
	if(abs(n - m) == 0)
		cout << (2LL*ans)%mod << endl;
	else
		cout << ans << endl;
	return 0;
} 




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
char s[25][25];
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int n,m,ex,ey;
int d[25][25];
void bfs(int x,int y) {
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			d[i][j]=INF;
		}
	}
	d[x][y]=0;
	queue<pair<int,int> > qu;
	qu.push({x,y});
	while(!qu.empty()) {
		pair<int,int> u=qu.front();
		qu.pop();
		for(int i=0;i<4;i++) {
			int xx=dx[i]+u.first,yy=dy[i]+u.second;
			if(xx<0||xx>=n||yy<0||yy>=m||s[xx][yy]=='#') continue;
			if(d[xx][yy]>d[u.first][u.second]+1) {
				d[xx][yy]=d[u.first][u.second]+1;
				qu.push({xx,yy});
			}
		}
	}
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) {
		scanf("%s",s[i]);
	}
	int ans=0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if(s[i][j]=='#') continue;
			bfs(i,j);
			for(int k=0;k<n;k++) {
				for(int l=0;l<m;l++) {
					if(d[k][l]!=INF) ans=max(ans,d[k][l]);
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
/*
author : seryu
title : ABC176B_"Multiple of 9"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

void solve()
{
    string n;
    cin >> n;
    int sum = 0;
    rep(i, sz(n))sum += n[i]-'0';
    if(sum % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return;	
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

A.sort()
check=[0]*N

for idx in range(N%2,N,2):
    check[idx]=idx+1
    check[idx+1]=idx+1

ans=0
mod=10**9+7
if check==A:
    if N%2==0:
        ans=(2**(N//2))%mod
    else:
        ans=(2**((N-1)//2))%mod
print(ans)

Measured memory_bytes: 20644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_121
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] hw = ReadInts();
            int[] hw2 = ReadInts();
            WriteLine(hw[0] * hw[1] - hw[1] * hw2[0] - hw[0] * hw2[1] + hw2[0] * hw2[1]);
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String string;
		String string2 = "";

		string = scanner.next();
		for (int i = 0; i < string.length(); i++) {
			switch (string.charAt(i)) {
			case 'A':	string2 += "X";	break;
			case 'B':	string2 += "Y";	break;
			case 'C':	string2 += "Z";	break;
			case 'D':	string2 += "A";	break;
			case 'E':	string2 += "B";	break;
			case 'F':	string2 += "C";	break;
			case 'G':	string2 += "D";	break;
			case 'H':	string2 += "E";	break;
			case 'I':	string2 += "F";	break;
			case 'J':	string2 += "G";	break;
			case 'K':	string2 += "H";	break;
			case 'L':	string2 += "I";	break;
			case 'M':	string2 += "J";	break;
			case 'N':	string2 += "K";	break;
			case 'O':	string2 += "L";	break;
			case 'P':	string2 += "M";	break;
			case 'Q':	string2 += "N";	break;
			case 'R':	string2 += "O";	break;
			case 'S':	string2 += "P";	break;
			case 'T':	string2 += "Q";	break;
			case 'U':	string2 += "R";	break;
			case 'V':	string2 += "S";	break;
			case 'W':	string2 += "T";	break;
			case 'X':	string2 += "U";	break;
			case 'Y':	string2 += "V";	break;
			case 'Z':	string2 += "W";	break;
			default:	break;
			}
		}
		System.out.println(string2);
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

int n;
std::vector<long long int> v;
int x;
int main()
{
    scanf("%d", &n);
    v.resize(n);
    for(int i=0;i<n;i++)
    {
        scanf("%lld", &v[i]);
    }
    for(int i=1;i<n;i++)
    {
        v[i] += v[i-1];
    }
    long long int ans = v[n-1];
    for(int i=2;i<n-1;i++) // [0, i), [i, n)
    {

        int it1 = std::lower_bound(v.begin(), v.begin()+i, v[i-1]/2LL) - v.begin();
        int it2 = std::lower_bound(v.begin()+i, v.end(), v[i-1]+(v[n-1]-v[i-1])/2LL) - (v.begin());
        long long int t[4];
        for(int j=-1;j<=1;j++)
        {
            for(int k=-1;k<=1;k++)
            {
                if(it1+j < 0 || it1+j >= i-1 || it2+k < i || it2+k >= n-1) continue;
                t[0] = v[it1+j];
                t[1] = v[i-1] - v[it1+j];
                t[2] = v[it2+k] - v[i-1];
                t[3] = v[n-1] - v[it2+k];
                ans = std::min({
                    ans, *std::max_element(t, t+4) - *std::min_element(t, t+4)});
            }
        }
    }
    printf("%lld\n", ans);
}

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

int main()
{
    int input_s,h,m,s;
    cin >> input_s;
    s = input_s % 60;
    input_s /= 60;
    m = input_s % 60;
    h = input_s / 60;

    cout<<h<<":"<<m<<":"<<s<<endl;

    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const double PI=3.14159265359;
const int N_MAX=1000000;

int main(){
	int a,b;
	cin>>a>>b;
	if((b-1)%(a-1)==0){
		cout<<(b-1)/(a-1)<<endl;
	}else{
		cout<<(b-1)/(a-1)+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); 
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    
    public static int[] generatePrimes(int n) {
		boolean[] prime = new boolean[n + 1];
		Arrays.fill(prime, 2, n + 1, true);
		for (int i = 2; i * i <= n; i++)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
		int[] primes = new int[n + 1];
		int cnt = 0;
		for (int i = 0; i < prime.length; i++)
			if (prime[i])
				primes[cnt++] = i;
		return Arrays.copyOf(primes, cnt);
	}
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}	
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}		    
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}	    	  	
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}		
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}	
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}	    	
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}	    	
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}				
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int a[] = in.nextIntArray(n);
        // int a[] = new int[1002];
        // for(int i=0;i<n;i++) a[in.nextInt()]++;
        // for(int i=0;i<1002;i++)
        // {
        //     for(int j=0;j<1002;j++)
        //     {
        //         if()
        //     }
        // }
        Arrays.sort(a);
        long sum=0l;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                for(int k=j+1;k<n;k++)
                {
                    if(a[k]>=a[i]+a[j]) break;
                    sum++;
                }
            }
        }
        out.println("\n"+sum);
    }
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e12;
using Graph = vector<vector<int>>;

signed main(){
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  vector<int> B(N);
  for( int i = 0; i < N; i++ ) cin >> A[i] >> B[i];

  vector<int> dp(100000, INF);
  dp[0] = 0;
  for( int i = 0; i <= H; i++ ){
    for( int j = 0; j < N; j++ ){
      dp[i] = min(dp[i], dp[max(i-A[j], 0LL)]+B[j]);
    }
  }
  cout << dp[H] << endl;

}

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

using namespace std;
typedef pair<int,int> P;
const int INF=1e9+7;

int n;
int a[100005];

int main() {

cin.tie(0);
ios::sync_with_stdio(false);

cin>>n; 

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

sort(a,a+n);

int c;
int p=INF;

for(int i=0; i<n; i++){
  if(a[n-1]%2==0){
    int x=a[n-1]/2;
    if(abs(a[i]-x)<p){
      p=abs(a[i]-x);
      c=a[i];
    }
  }
  else{
    int x=a[n-1]/2;
    int y=a[n-1]/2+1;
    if(abs(a[i]-x)<p){
      p=abs(a[i]-x);
      c=a[i];
    }
    if(abs(a[i]-y)<p){
      p=abs(a[i]-y);
      c=a[i];
    }
  }
}

cout<<a[n-1]<<" "<<c<<endl;

}


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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m ,c, x;
    cin >> n >> m >> c;
    int b[m];
    for(int i=0; i<m; ++i){
        cin >> b[i];
    }
    int ct=0;
    for(int i=0; i<n; ++i){
        int sum = 0;
        for(int i=0; i<m; ++i){
            cin >> x;
            sum += x * b[i];
        }
        if(sum +c > 0 ) ++ct;
    }
    cout << ct << "\n";
}


Measured memory_bytes: 256
while True:
    n, x = [int(i) for i in input().split()]
    
    if n == x == 0:
        break
        
    count = 0
    for s in range(1, n - 1):
        for m in range(s + 1, n):
            for e in range(m + 1, n + 1):
                if x == sum([s, m, e]):
                    count += 1
                    
    print(count)
    

Measured memory_bytes: 7728
uses
	SysUtils,
	Classes;

function Shiritori(const n: Integer): Boolean;
	var
		i: Integer;
		lastWord: string;
		aWordList: TStringList;
		aText: string;
	begin
	Result := False;
	aWordList := TStringList.Create;
	lastWord := '';
	try
		for i := 1 to n do
			begin
			ReadLn(aText);
			if aWordList.IndexOf(aText) <> -1 then
				Exit;
			if  (lastWord <> '') and (lastWord[Length(lastWord)] <> aText[1]) then
				Exit;
			aWordList.Add(aText);
			lastWord := aText;
			end;
	finally
		FreeAndNil(aWordList);
		end;	
	Result := True;
	end;
	
procedure MainProc;
	var
		aText: string;
		numOfWord: Integer;
	begin
	ReadLn(aText);
	numOfWord := StrToInt(aText);
	if (2 > numOfWord) or (100 < numOfWord) then
		Exit;
	if  Shiritori(numOfWord) then	
		WriteLn('Yes')
	else
		WriteLn('No');
	end;

begin
MainProc;
end.

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

using namespace std;

const int N = 25;
int t[N][N], d[N][N][N][N];
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
int n, m;

bool ok(int x, int y) {
  return 0 <= x and x < n and 0 <= y and y < m and t[x][y];
}

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

  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < n; ++k) {
        for (int g = 0; g < m; ++g) {
          d[i][j][k][g] = 1337;
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char c;
      cin >> c;
      t[i][j] = (c == '.');
      d[i][j][i][j] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < 4; ++k) {
        if (ok(i + dx[k], j + dy[k])) {
          d[i][j][i + dx[k]][j + dy[k]] = 1;
        }
      }
    }
  }
  for (int kx = 0; kx < n; ++kx) {
    for (int ky = 0; ky < m; ++ky) {
      for (int ix = 0; ix < n; ++ix) {
        for (int iy = 0; iy < m; ++iy) {
          for (int jx = 0; jx < n; ++jx) {
            for (int jy = 0; jy < m; ++jy) {
              d[ix][iy][jx][jy] = min(d[ix][iy][jx][jy], d[ix][iy][kx][ky] + d[kx][ky][jx][jy]);
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < n; ++k) {
        for (int g = 0; g < m; ++g) {
          if (t[i][j] and t[k][g]) {
            ans = max(ans, d[i][j][k][g]);
          }
        }
      }
    }
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 1280
s = gets.chomp.to_i
array = []
array << s

f = 1
count = 1
while f == 1 do
    count += 1
    if array[-1].even? then
        array << array[-1] / 2
    else
        array << 3*array[-1] + 1
    end
    if array.count != array.uniq.count then
        f = 0
    end
end

print count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define int long long
using namespace std;
main()
{

    string a,b;
    cin>>a>>b;
    string tempa= "",tempb="";
    int first = a[0]-'0';
    int second = b[0]-'0';
    for(int i = 0 ; i< first; i++){
        tempb+=b;
    }
    for(int i =0 ; i<second; i++)    tempa+=a;

    if(tempa < tempb)cout<<tempa<<endl;
    else cout<<tempb<<endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] words = line.split(" ");
        int n = words.length;
        
        HashMap<String, Integer> dic = new HashMap<String, Integer>();
        
        for(int i = 0; i < n; i++) {
            String word = words[i];
            if(dic.containsKey(word)) {
                dic.put(word, dic.get(word)+1);
            }else {
                dic.put(word, 1);
            }
        }
        
        String maxtimesword = "";
        int maxtimes = 0;
        String maxlengthword = "";
        int maxlength = 0;
        
        for(String key : dic.keySet()) {
            if(dic.get(key) > maxtimes) {
                maxtimes = dic.get(key);
                maxtimesword = key;
            }
            if(key.length() > maxlength) {
                maxlength = key.length();
                maxlengthword = key;
            }
        }
        System.out.println(maxtimesword+" "+maxlengthword);
    }    
}



Measured memory_bytes: 26024
import java.util.*

fun main(args: Array<String?>) {
    val scanner = Scanner(System.`in`)

    val n = scanner.nextInt()
    val k = scanner.nextInt()
    val s = scanner.next()

    s.toCharArray().let {
        it[k - 1] = it[k - 1].toLowerCase()
        println(it)
    }
}


Measured memory_bytes: 29592
/*input
6
AC
TLE
AC
AC
WA
TLE
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll INF64=8e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
ll mult(ll a,ll b){
    a%=MOD;
    b%=MOD;
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=1e5+5;
const ll maxlg=__lg(maxn)+2;
string ans[4]={"AC","WA","TLE","RE"};
int cnt[4];
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        REP(k,4){
            if(ans[k]==s) cnt[k]++;
        }
    }
    REP(i,4){
        cout<<ans[i]<<" x "<<cnt[i]<<'\n';
    }
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    
    char[] src = new char[26];
    char[] dst = new char[26];
    
    for (int i = 0; i < S.length(); i++) {
      char s = S.charAt(i);
      char t = T.charAt(i);
      
      // src
      if (src[s-'a'] == 0) {
        src[s-'a'] = t;
      } else {
        if (src[s-'a'] != t) {
          System.out.println("No");
          return;
        }
      }

      // dst
      if (dst[t-'a'] == 0) {
        dst[t-'a'] = s;
      } else {
        if (dst[t-'a'] != s) {
          System.out.println("No");
          return;
        }
      }
    }      

    System.out.println("Yes");
  }
}

Measured memory_bytes: 28500
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>

constexpr size_t di[]={size_t(-1), 0, 1, 0};
constexpr size_t dj[]={0, size_t(-1), 0, 1};

int testcase_ends() {
  size_t W, H;
  scanf("%zu %zu", &W, &H);

  if (W == 0 && H == 0)
    return 1;

  std::vector<std::string> S(H);
  size_t h=0, w=0;
  for (size_t i=0; i<H; ++i) {
    char buf[32]={};
    scanf("%s", buf);
    S[i] = buf;
    for (size_t j=0; j<W; ++j) {
      if (S[i][j] == '@') {
        h = i;
        w = j;
        break;
      }
    }
  }

  std::queue<std::pair<size_t, size_t>> q;
  q.emplace(h, w);
  int res=1;
  while (!q.empty()) {
    const auto p=q.front();
    q.pop();

    size_t i=p.first, j=p.second;
    S[i][j] = '*';
    for (size_t k=0; k<4; ++k) {
      size_t ni=i+di[k], nj=j+dj[k];
      if (!(ni < H && nj < W)) continue;

      if (S[ni][nj] == '.') {
        q.emplace(ni, nj);
        ++res;
        S[ni][nj] = '*';
      }
    }
  }

  printf("%d\n", res);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll _R(){
	ll d=0;bool b=1;char t=getchar();
	while(t<'0'||t>'9'){if(t=='-')b=0;t=getchar();}
	for(;t>='0'&&t<='9';t=getchar())d=(d<<3)+(d<<1)+t-'0';
	return b?d:-d;
}
char s[200005]; 
ll cnt[30],Ans=1;
int main(){
 	scanf("%s",s+1);
 	cnt[s[1]-'a']++;
 	for(int i=2;i<=strlen(s+1);i++)
 		Ans+=i-1-cnt[s[i]-'a'],cnt[s[i]-'a']++;
 	printf("%lld",Ans);
 }

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


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

    int m = 0, b = 0;
    int c = 0;
    rep(i, S.size()) {
        if (S[i] == 'o')m++;
        if (S[i] == 'x')b++;
        c++;
    }
    int r = 15-c;
    
    if (m + r >= 8)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import fractions
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
gcd_all = A[0]
for i in range(1, N):
    gcd_all = fractions.gcd(gcd_all, A[i])
if K <= max(A) and K % gcd_all == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

typedef long long l;

int main(){
  string s,t;
  l count=0;
  cin>>s>>t;
  for(l i =0 ;i<3;i++){
    if(s[i] == t[i]) count++;
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int i ,j ,minj ,count=0 ,a;
        int array[] = new int[N];

        for(i = 0;i < N;i++){
            array[i] = sc.nextInt();
        }

        for(i = 0;i < N;i++){
            minj = i;
            for(j = i;j < N;j++){
                if(array[j] < array[minj]){
                    minj = j;
                }
            }
            if(i != minj){
                count++;
                a = array[i];
                array[i] = array[minj];
                array[minj] = a;
            }
        }

        for(i = 0;i < N;i++){
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        }

        System.out.printf("%d\n",count);
        
    }
}


Measured memory_bytes: 26460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
string s;
map<string,int> f,g;
int G(string);
int F(string s){
	if(f.count(s)) return f[s];
	int n=s.size(),ans=G(s);
	FOR(i,1,n-1) ans=(ans+1ll*F(s.substr(0,i))*G(s.substr(i,n)))%mod;
	return f[s]=ans;
}
int G(string s){
	if(g.count(s)) return g[s];
	int n=s.size();
	if(n==1) return s[0]-'0'+1;
	int ans=0;
	FOR(i,1,n-1) if(n%i==0){
		string t;
		FOR(j,0,i-1){
			bool flag=true;
			for(int k=j;k<n;k+=i) flag&=s[k]-'0';
			t+=flag+'0';
		}
		ans=(ans+F(t))%mod;
	}
	return g[s]=ans;
}
int main(){
	cin>>s;
	cout<<F(s)<<endl;
}
// fk

Measured memory_bytes: 12928
// In the name of God 
#include <bits/stdc++.h>

using namespace std ;


#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

int n ;

int sum ( int x ) {
	int ret = 0 ;
	while ( x ) {
		ret += x % 10 ;
		x /= 10 ; 
	}
	return ret ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int res = ( int ) 2e9 + 10 ;
	cin >> n ; 
	for ( int a = 1 ; a < n ; ++a ) {
		smin ( res , sum ( a ) + sum ( n - a ) ) ; 
	}
	cout << res << '\n' ; 
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const d = arg[1].split(" ").map(n=>parseInt(n)).sort((a,b)=>a-b);
    
    const middleHigh = d[N / 2];
    const middleLow  = d[(N / 2) - 1];
    
    console.log(middleHigh - middleLow);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 28236
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}


char s[33000];
int main(void) {

  string s;
  ll n;
  ll p;
  cin >> n >> p;
  cin >> s;

  

  
  ll m = s.size();

  if (p == 2) {
    ll ans = 0;
    for (ll i = m - 1; i >= 0; i--) {
      if ((s[i] - '0') % 2 == 0) {
	ans += i + 1LL;
      }
    }
    cout << ans << endl;
    return 0;
  }
  if (p == 5) {
    ll ans = 0;
    for (ll i = m - 1; i >= 0; i--) {
      if (s[i] == '5' || s[i] == '0') {
	ans += i + 1LL;
      }
    }
    cout << ans << endl;
    return 0;
  }
  ll d = 1;
  ll num = 0;
  ll ar[10010] = {};
  ar[0]++;
  for (ll i = m - 1; i >= 0; i--) {
    d *= 10;
    d %= p;
    num = (num + (d * (s[i] - '0')) % p) % p;
    ar[num]++;
  }
  ll ans = 0;
  for (int i = 0; i < p; i++) {
    ans += ar[i] * (ar[i] - 1LL) / 2LL;
  }
  cout << ans << endl;
}
  
    


Measured memory_bytes: 644
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0
before = 9999
for i in range(N):
    ans += B[A[i]-1]
    if A[i]== (before+1):
        ans += C[A[i]-2]
    before = A[i]

print(ans)


Measured memory_bytes: 3064
// This is the start of  template//
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define ll int 
#define vll vector<int>
#define pb push_back
#define pll pair<int,int>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
void input(){
#ifndef ONLINE_JUDGE 
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout); 
#endif
}
#define INF LONG_LONG_MAX
#define mod 1000000007
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define cases int t; cin>>t; while(t--)
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
ll power(ll a,ll n)
{
	if(n==0)
		return 1;
	if(n%2)
	{
		return a*power(a*a,n/2);
	}
	return power(a*a,n/2);
}

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  //input();
  string s,t;
  cin>>s>>t;
  int ans = INT_MAX ;
  for(int i = 0 ;i<s.size()-t.size()+1;i++)
  {
  	int curr = 0;
  	for(int j = 0 ;j<t.size();j++)
  	{
  		// cout<<s[i+j]<<" ";

  		if(s[i+j]!=t[j])
  			{
  				curr++;
  			}
  		
  	}
  	// cout<<endl;
  	ans = min(curr,ans); 
  }
  cout<<ans<<" ";
}



Measured memory_bytes: 3660
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = INTINF;
	int tmp;
	int n, k;
	cin >> n >> k;
	REP(i, 1 << n){
		tmp = 1;
		REP(j, n){
			if(i & 1 << j) tmp += k;
			else tmp *= 2;
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

class Combination(object):
    '''
        See:
        http://drken1215.hatenablog.com/entry/2018/06/08/210000
    '''

    def __init__(self, max_value=500050, mod=10 ** 9 + 7):
        self.max_value = max_value
        self.mod = mod
        self.fac = [0 for _ in range(self.max_value)]
        self.finv = [0 for _ in range(self.max_value)]
        self.inv = [0 for _ in range(self.max_value)]

        self.fac[0] = 1
        self.fac[1] = 1
        self.finv[0] = 1
        self.finv[1] = 1
        self.inv[1] = 1

        for i in range(2, self.max_value):
            self.fac[i] = self.fac[i - 1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i - 1] * self.inv[i] % self.mod

    def count_nCr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        return self.fac[n] * (self.finv[r] * self.finv[n - r] % self.mod) % self.mod


def main():
    n, k = map(int, input().split())
    # abst: 数列の並び順が問題にならない場合は、ソートするのも選択肢に入れる
    a = sorted(list(map(int, input().split())))
    com = Combination()
    ans = 0

    # KeyInsight
    # Σf(x) = Σmax(x) - Σmin(x)と置き換えられる
    # abst: 等価な性質を利用して、シンプルな問題に
    # See:
    # https://www.youtube.com/watch?v=1oLDDdWRu6Y&feature=youtu.be
    # 最大値が選ばれるパターン
    for index, ai in enumerate(a):
        # abst: ◯◯◯◯◯◯◯ (昇順に並び替えた数字のイメージ)
        #            ↑
        # 矢印の位置が最大値となる場合、左から5つのうちk - 1個を自由に選べる
        # この例だと、5Ck-1個
        # abst: 視点をある位置に固定する
        # abst: 条件を満たす場合は二項係数を使うことで組み合わせを高速に数えられる
        # nCrを高速に計算する&ライブラリ化
        now = com.count_nCr(n=index, r=k - 1)
        ans += now * ai

    # 最小値が選ばれるパターン
    # abst: 数列の並びを逆順に
    for index, ai in enumerate(a[::-1]):
        now = com.count_nCr(n=index, r=k - 1)
        ans -= now * ai

    print(ans % (10 ** 9 + 7))


if __name__ == '__main__':
    main()


Measured memory_bytes: 103540
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n,a,b;
int sz[300111];
void print_ans()
{
	int sum=0;
	for(int i=1;i<=b;i++)
	{
		for(int j=n-sum-sz[i]+1;j<=n-sum;j++)puti(j);
		sum+=sz[i];
	}
}
int main()
{
	getiii(n,a,b);
	if(a+b>n+1||1ll*a*b<n)
	{
		puts("-1");
		return 0;
	}
	int lft=n-a;
	sz[1]=a;
	for(int i=2;i<=b;i++)sz[i]=1,lft--;
	for(int i=2;i<=b;i++)
	{
		while(lft>0&&sz[i]<a)lft--,sz[i]++;
	}
	print_ans();
	return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)

#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;


int dp[100010][2];
signed main() {
	
	fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//https://codeforces.com/contest/1084/problem/D
	// https://codeforces.com/contest/1155/problem/E
	//https://www.spoj.com/problems/MON2012/
	//https://codeforces.com/blog/entry/52726	
	int n;
	cin>>n;	
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];

	}
	dp[0][0]=0;
	dp[0][1]=-1e18;
	for(int i=0;i<n;i++)
	{
		dp[i+1][0]=max(dp[i][0]+arr[i],dp[i][1]-arr[i]);
		dp[i+1][1]=max(dp[i][0]-arr[i],dp[i][1]+arr[i]);
		//cout<<dp[i+1][0]<<" "<<dp[i+1][1]<<endl;
	}
	cout<<dp[n][0];
	return  0;


}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef vector<vector<int> > mat;
int h,w,n;
inline void mat_mul(mat &A, mat &B, int M=1000000009){
  mat ret(w,vector<int>(w));
  for(int i = 0; i < w; ++i){
    for(int j = 0; j < w; ++j){
      ret[i][j] = 0;
      for(int k = 0; k<w; ++k){
        ret[i][j] += (A[i][k]*B[k][j])%M;
        ret[i][j] %= M;
      }
    }
  }
  A=ret;
}
 
inline mat mat_pow(mat &A, int N, int M=1000000009){
  mat ret(A.size(),vector<int>(A.size(),0)), t = A;
  for(int i = 0; i < A.size(); ++i) ret[i][i] = 1;
  int k = 0;
  while(N>0){
    if(N&1){
      mat_mul(ret,t,M);
    }
    mat_mul(t,t,M);
    N>>=1;
  }
  return ret;
}
 
mat XXX;
 
void init(){
    mat res(w,vector<int>(w,0));
    for(int i=0;i<w;i++){
        for(int j=0;j<w;j++){
            if(i==j){
                if(i)res[i-1][j]=1;
                res[i][j]=1;
                if(i!=w-1)res[i+1][j]=1;
            }
        }
    }
    XXX=res;
}
 
 
inline mat make_mat(vector<int> &V){
    mat res=XXX;
    for(int i=0;i<V.size();i++){
        for(int j=0;j<w;j++){
            res[j][V[i]]=0;
        }
    }
    return res;
}
 
signed main(){
    init();
    int cnt=0;
    while(cin>>w>>h>>n,w){
        init();
        cout<<"Case "<<(++cnt)<<": ";
        vector<P>v;
        vector<int>v1;
        r(i,n){
            int x,y;
            cin>>x>>y;
            x--;y--;
            if(y==0)v1.push_back(x);
            else v.push_back(P(y,x));
        }
        v.push_back(P(1e18+1,0));
        int y=0;
        sort(v.begin(),v.end());
        mat A(w,vector<int>(w,0));
        A[0][0]=1;
        r(i,v1.size())A[v1[i]][v1[i]]=0;
        for(int i=0;i<v.size();i++){
            int s=v[i].first;
            int c=s-y;
            vector<int>vs,kara;
            vs.push_back(v[i].second);
            while(v[i].first==v[i+1].first){
                vs.push_back(v[i+1].second);
                i++;
            }
            mat B=make_mat(vs);
            mat C=make_mat(kara);
            if(s==1e18+1){
                c=(h-1)-y;
                if(c){
                    C=mat_pow(C,c);
                    mat_mul(A,C);
                }
                break;
            }
            if(c>1){
                C=mat_pow(C,c-1);
                mat_mul(A,C);
            }
            mat_mul(A,B);
            y=s;
        }
        int ans=0;
        r(i,w)ans=(ans+A[i][w-1])%1000000009;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3260
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int index = 0;
		Set<Integer> A = new HashSet<Integer>();
		for(int i = 0; i < N; i++) {
			index = scan.nextInt();
			if(A.contains(index)) {
				A.remove(index);
			} else {
				A.add(index);
			}
		}
		System.out.println(A.size());
		scan.close();

	}

}


Measured memory_bytes: 62296
n, m, x = map(int, input().split())
CA = [tuple(map(int, input().split())) for _ in range(n)]

minimum = float("inf")
for i in range(2**n):
    select = [0] * n
    a = [0] * m
    money = 0
    for j in range(n):
        if (i>>j)&1:
            select[n-1-j] = 1
    for i, v in enumerate(select):
        if v == 1:
            money += CA[i][0]
            for j, u in enumerate(CA[i][1:]):
                a[j] += u
    if not len([l for l in a if l < x]):
        minimum = min(minimum, money)
print(-1 if minimum == float("inf") else minimum)

Measured memory_bytes: 69288