akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <cstring>	// require memset
//#include <fstream>	// require freopen

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;

int b[2][105];
bool used[2][105];

int bfs (int n )
{
	int res = 0;
	memset (used, false, sizeof (used ) );

	queue<PP> q;
	P p0(0, 0 ), p1(1, 0 );
	PP pp0 (p0, 0 ), pp1(p1, 0 );
	q.push (pp0 );
	q.push (pp1 );

	P curr_pos; PP curr;
	bool disable = false;
	int count = 0;

	while (!q.empty() ){
		curr = q.front(); q.pop();
		curr_pos = curr.first;
		count  = curr.second;

		int number = curr_pos.first;
		int floor  = curr_pos.second;

		bool hashigo = false;
		while (b[number][floor] == 1 && floor <= n ){
			++floor;
			if (!hashigo ){
				hashigo = true;
			} // end if
		} // end if
		if (hashigo ){
			--floor;
		} // end if
		
		while (b[number][floor] == 2 ){
			--floor;
		} // end if

		if (floor >= n - 1 ){
			return count;
		} // end if

		used[number][floor] = true;

		if (number == 0 ){
			number = 1;
		}else{
			number = 0;
		} // end if

		for (int i = 0; i <= 2; ++i ){
			if (used[number][floor+i] ){
				continue;
			}else{
				used[number][floor+i] = true;
				P next (number, floor+i );
				PP ne (next, count + 1 );
				q.push (ne );
			} // end if
		} // end for
	} // end while

	return -1;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.ninja2", "r", stdin );
	int n;

	while (cin >> n && n ){
		memset (b, -1, sizeof (b ) );
		int i, j;

		for (i = 0; i < 2; ++i ){
			for (j = 0; j < n; ++j ){
				cin >> b[i][j];
			} // end for
		} // end for

		int res = 0;

		res = bfs (n );

		if (res == -1 ){
			cout << "NA" << endl;
		}else{
			cout << res << endl;
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)

#define pb              push_back
#define ff              first
#define ss              second
#define mp              make_pair

#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))

#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)

#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())

#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )

#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("out.txt","w",stdout)

/// DEBUG
#define deb             printf("OKA\n")
/// DEBUG ENDSk

using namespace std;



int main(){

   LL x,y,z;
   SL(x); SL(y); SL(z);
   swap(x,y);
   swap(x,z);
   cout<<x<<" "<<y<<" "<<z<<endl;    
   
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>

using namespace std;



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



	//calc
	int ans;
	if (b % a){
		ans = b - a;
	}
	else{
		ans = a + b;
	}


	//ans
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	static int count;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
		int n = sc.nextInt();
		for(int i=0;i<n;i++){
			graph.add(new ArrayList<Integer>());
		}
		int m = sc.nextInt();
		for(int i=0;i<m;i++){
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			graph.get(a).add(b);
			graph.get(b).add(a);
		}
		boolean[] vis = new boolean[n];
		int max=0;
		for(int i=0;i<n;i++){
			if(vis[i]==false){
				count=0;
				dfs(graph,vis,i);
				if(count>max){
					max=count;
				}
			}
		}
		System.out.println(max);

	}
	public static void dfs(ArrayList<ArrayList<Integer>> graph, boolean[] vis,int start){
		vis[start]=true;
        count++;
        for(int i=0;i<graph.get(start).size();i++){
             if(vis[graph.get(start).get(i)]==false){
             	dfs(graph,vis,graph.get(start).get(i));
             }
        }
	}
}

Measured memory_bytes: 119108
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <bitset>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

int run(istream& in, ostream& out) {
    ll N;
    in >> N;
    ll A[100] = {0};
    ll x[15][15] = {0};
    ll y[15][15] = {0};
    REP(i, N) {
        in >> A[i];
        REP(j, A[i]) {
            in >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    ll ans = 0;

    // solution here
    int shojiki[15] = {0};
    int fuseijitu[15] = {0};
    REP(i, N) {
        int  s{};
        int  f{};
        s |= 1 << i;
        REP(j, A[i]) {
            if (y[i][j] == 1) {
                s |= 1 << x[i][j];
            } else {
                f |= 1 << x[i][j];
            }
        }
        shojiki[i] = s;
        fuseijitu[i] = f;
    }

    ll ret = 0;
    REP(i, 1 << N) {
        int s{};
        int f{};
        ll count = 0;
        REP(j, N) {
            if (i & (1 << j)) {
                s = s | shojiki[j];
                f = f | fuseijitu[j];
                count++;
            }
        }
        if ((s & f) == 0 && (s & ~i) == 0) {
            ret = max(ret, count);
        }
    }
    out << ret << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}

int main()
{
	int N,M;
	cin >> N;
	vector<int> s(N);
	int sum = 0;
	for(int i = 0; i < N; i++) cin >> s[i],sum += s[i];
	if(sum % 10 != 0)
	{
		cout << sum << endl;
		return 0;
	}
	sort(s.begin(),s.end());
	int max = sum;
	for(int i = 0; i < N; i++)
	{
		max -= s[i];
		if(max % 10 != 0)
		{
			cout << max << endl;
			return 0;
		}
		max += s[i];
	}
	cout << 0 << endl;
}


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

using namespace std;

int main(){
	while(1){
		int n,q; cin >> n >> q;
		if (n + q == 0) break;
		
		vector<int> date(101,0);

		for (int i = 0; i < n; i++){
			int m; cin >> m;
			for (int j = 0; j < m; j++){
				int d; cin >> d;
				date[d]++;
			}
		}
		int max = 0;
		int maxdate = 0;
		for (int i = 0; i < date.size(); i++){
			if (max < date[i] and q <= date[i]){
				max = date[i];
				maxdate = i;
			}
		}
		cout << maxdate << endl;
	}
			
return 0;
}

Measured memory_bytes: 3036
def solve(string):
    n, k, *td = map(int, string.split())
    td = sorted([(t, d) for t, d in zip(td[::2], td[1::2])], key=lambda x: x[1], reverse=True)
    max_variety = len(set([c[0] for c in td]))
    choice = td[:k]
    count = [0] * n
    r = []
    for _c in choice:
        if count[_c[0] - 1] > 0:
            r.append(_c[1])
        count[_c[0] - 1] += 1
    variety = set([c[0] for c in choice])
    ans = [len(variety)**2 + sum([c[1] for c in choice])]
    i_append = k
    while len(variety) < min(max_variety, k):
        while td[i_append][0] in variety:
            i_append += 1
        variety.add(td[i_append][0])
        ans.append(ans[-1] - r.pop() + td[i_append][1] + 2 * len(variety) - 1)
    return str(max(ans))


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 26868
import java.util.*;
public class Main{
    public static void main(String[]args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    
    String s;
    int a, b;
    int game;

    void run(){
	game = 0;
	while(sc.hasNext()){
	    s = sc.next();
	    solve();
	    game++;
	}
    }

    void solve(){
	//System.out.println(a+" "+b+" "+s);
	String ss = s.substring(0, 1);
	if(game > 0){
	    if(game%3 != 0){
		if(ss.equals("A")) a++;
		else if(ss.equals("B")) b++;
	    }
	    else {
		if(a>b) a++;
		else b++;
	    }
	    System.out.println(a+" "+b);
	}
	a = 0;
	b = 0;
	
	/* "0" が来た時ここでプログラム終了 */
	for(int i=1; i<s.length(); i++){
	    ss = s.substring(i, i+1);
	    if(ss.equals("A")) a++;
	    else b++;
	}
    }
}

Measured memory_bytes: 17136
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 

int n;
int i,j;
double x,y;
double a[101],b[101];
int cou[101];
double kyo;
double ima;
int look;
double ookii;

int main(){
	cin>>n;
	memset(cou,0,sizeof(cou));
	for(i=0;i<n;i++){
		cin>>x>>y;
		a[i]=x*1.000/10;
		b[i]=y*1.000/10;
		ookii=max(ookii,max(x,y));
	}
	double xx,yy;
	for(i=0;i<1000000;i++){
		ima = INF;
		xx=ookii * 1000000 *sin(i*7.000000/Pi);
		yy=ookii * 1000000 *cos(i*7.000000/Pi);
		for(j=0;j<n;j++){
			kyo  =-a[j]*xx - b[j] * yy ;
			if(kyo<ima){
				ima = kyo;
				look = j;
			}
		}
		cou[look] += 1;

	}
	for(i=0;i<n;i++){
		cout<< fixed << setprecision(15) <<(double)cou[i]*1.00000000/1000000<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		a: usize,
		b: usize,
	}

	println!("{}", min(a*n, b));
}



Measured memory_bytes: 2072
import sys
def main():
    input = sys.stdin.readline
    H,W,K=map(int, input().split())
    A=[list(input()) for _ in range(H)]

    from collections import deque
    q=deque()
    for i in range(H):
        for j in range(W):
            if A[i][j]=='S':
                q.append((i,j,0))
                A[i][j]='#'

    ans=10**9
    while q:
        i,j,d = q.popleft()
        if i==0 or i==H-1 or j==0 or j==W-1:
            print(1)
            exit()
        ans = min(ans, (min(i,j,H-1-i,W-1-j) + K-1) // K + 1)
        if d==K: continue
        for di,dj in ((-1,0),(1,0),(0,-1),(0,1)):
            ni,nj=i+di,j+dj
            if A[ni][nj]!='#':
                q.append((ni,nj,d+1))
                A[ni][nj]='#'
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68592
#include <iostream>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int g[n+1][m+1];
    int h[m+1];
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            int a;
            cin>>a;
            g[i][j]=a;
        }
    }
    for (int i=1;i<=m;i++){
        int a;
        cin>>a;
        h[i]=a;
    }
    for (int i=1;i<=n;i++){
        int sum=0;
        for (int j=1;j<=m;j++){
            sum+=g[i][j]*h[j];
        }
        cout<<sum<<endl;
    }
    return 0;
    
    
}


Measured memory_bytes: 3112
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  int N,K;
  long int n,m,n_min,n_max;
  int i,j,k;
  int a,b,c;
  int ans=0;
  scanf("%d",&N);
  if(N==1){
    printf("Hello World\n");
    return 0;
  }else{
    scanf("%d %d",&a,&b);
    printf("%d\n",a+b);
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
 
    static int h,w;
    static int[] v1={0,1,0,-1};
    static int[] v2={1,0,-1,0};
    static int[][] field;
    static Queue<Integer[]> q = new LinkedList<Integer[]>();
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        while(true){
            h = cin.nextInt();
            w = cin.nextInt();
            if(h+w==0){
                break;
            }
            field= new int[h+2][w+2];
            for(int i = 1;i<=h;i++){
                String ss = cin.next();
                char[] s = ss.toCharArray();
                for(int j = 1;j<=w;j++){
                    if(s[j-1]=='@'){
                        field[i][j]=1;
                    }
                    else if(s[j-1]=='#'){
                        field[i][j]=2;
                    }
                    else if(s[j-1]=='*'){
                        field[i][j]=3;
                    }
                }
            }
            int cnt=0;
            for(int i = 1;i<=h;i++){
                for(int j = 1;j<=w;j++){
                    if(dfs(i,j, field[i][j],0)){
                        cnt++;
                        //output();
                    }
                    boolean f = false;
                    while(!q.isEmpty()){
                    	Integer[] a = q.poll();
                    	dfs(a[0],a[1],field[a[0]][a[1]],0);
                    	f=true;
                    }
                    if(f){
                    	//System.out.println("QUEUEUEUEUE");
                    	//output();
                    }
                }
            }
            System.out.println(cnt);
        }
    }
    static boolean dfs(int x,int y,int now,int depth){
    	if(depth>=100){
    		Integer[] next = {x,y};
    		q.add(next);
    		return true;
    	}
        if(now!=0 && field[x][y]==now){
            field[x][y]=0;
            for(int i = 0;i<4;i++){
            	int xx=x+v1[i];
            	int yy=y+v2[i];
            	if(field[xx][yy]==now){
            		dfs(xx,yy,now,depth+1);	
            	}
            }
            return true;
        }
        else{
            return false;
        }
    }
    static void output(){
    	for(int i = 1;i<=h;i++){
    		for(int j = 1;j<=w;j++){
    			System.out.print(field[i][j]+" " );
    		}
    		System.out.println();;
    	}
    	System.out.println();;
    }
}

Measured memory_bytes: 12000
#include<stdio.h>

int LinearSearch(int [],int,int);

int main(){
  int i,n,A[10001],j,key,sum = 0;

  scanf("%d",&n);
  for(i = 0;i< n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&j);
  for(i = 0;i < j;i++){
    scanf("%d",&key);
    if(LinearSearch(A,n,key))
      sum++;
  }
  printf("%d\n",sum);

  return 0;
}

int LinearSearch(int A[],int n,int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key){
    i++;
  }
  return i != n;
 }




Measured memory_bytes: 2100
a = int(input())
b = int(input())
c = int(input())
x = int(input())


count = 0
for i_a in range(a + 1):
    for i_b in range(b + 1):
        for i_c in range(c + 1):
            if ((i_a * 500) + (i_b * 100) + (i_c * 50)) == x:
                count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int n;
    cin >> n;
    int value[n];
    int cost[n];
    REP(i,n) cin >> value[i];
    REP(i,n) cin >> cost[i];

    int ans = 0;
    REP(i,n){
        ans += max(llong(0), value[i] -cost[i]);
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 200200;
const long double PI = acos(-1);

ll n, m, k;

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> k; 
    vector<ll> a(n+1), b(m+1);

    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=m; i++) cin >> b[i];

    for (int i=0; i<=max(n, m); i++){
        if (i > 0 and i <= n) a[i] += a[i-1];
        if (i > 0 and i <= m) b[i] += b[i-1];
    }
    b.push_back(oo);
    ll ans = 0;

    for (int i=0; i<=n; i++){
        ll val, pos;
        val = a[i];
        if (val > k) break;
        pos = lower_bound(all(b), k - val) - b.begin();
        if (b[pos] + val > k) pos--;
        ans = max(ans, pos + i);
    }

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

Measured memory_bytes: 7948
a,b,c,d=map(int,input().split());m=998244353;x=range(3010);D=[[0]*3011for _ in [0]*3011];D[a][b]=1
for i in x:
 for j in x:D[i+1][j+1]+=(D[i+1][j]*(i+1)+D[i][j+1]*(j+1)-D[i][j]*i*j)%m
print(D[c][d])

Measured memory_bytes: 133880
#include <bits/stdc++.h>
using namespace std;
int a[1000010];
int ma[1000010];
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
int main()
{
    int n;
    cin>>n;
    int mx=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mx=max(mx,a[i]);
    }
    int te=a[1];
    for(int i=2;i<=n;i++){
        te=gcd(te,a[i]);
    }
    if(te==1){
        int flag=0;
        for(int i=1;i<=n;i++){
        for(int j=1;j*j<=a[i];j++){
            if(a[i]%j==0){
                if(a[i]/j!=j){
                    ma[a[i]/j]++;
                    if(ma[a[i]/j]>1){
                        flag=1;break;
                    }
                }
                ma[j]++;
                if(j!=1){
                    if(ma[j]>1){flag=1;break;}
                }
            }
        }
        if(flag)break;
        }

        if(flag){
            cout<<"setwise coprime";
        }else{
            cout<<"pairwise coprime";
        }
    }else{
        cout<<"not coprime";
    }
    //map<int,int>ma;

    return 0;
}


Measured memory_bytes: 7772
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    n, m = gets.chomp.split.map(&:to_i)
    nums = Array.new(n, -1)
    # puts nums
    m.times do |i|
      s, c = gets.chomp.split.map(&:to_i)
      s -= 1

      if nums[s] != -1 && nums[s] != c
        puts "-1"
        return
      end

      nums[s] = c
    end

    if nums[0] == 0
      if n == 1
        puts "0"
        return
      else
        puts "-1"
        return
      end
    elsif nums[0] == -1
      if n == 1
        puts "0"
        return
      else
        nums[0] = 1
      end
    end

    nums.each_with_index do |v, i|
      if v == -1
        nums[i] = 0
      end
    end

    puts nums.join
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define oo 100005
using namespace std;
const int mod = 1e9 + 7;
int n, m, a[18], S;
long long dp[18][oo], p[oo], inv[oo];
inline bool cmp (int i, int j) {return i > j;}
long long qpow (long long x, int k)
{
    long long ret = 1;
    while(k) {if(k & 1) ret = ret * x % mod; x = x * x % mod; k >>= 1;}
    return ret;
}
void init ()
{
    p[0] = inv[0] = inv[1] = 1;
    for(int i = 1; i < oo; ++ i)
    p[i] = p[i - 1] * i % mod;
    for(int i = 2; i < oo; ++ i)
    inv[i] = qpow(p[i], mod - 2);
}
inline long long get_c (int a, int b)
{
    if(a < b || b < 0) return 0;
    return p[a] * inv[b] % mod * inv[a - b] % mod;
}
void work ()
{
    dp[0][0] = 1;
    for(int i = 1; i <= m; ++ i)
    for(int j = 0; j < S; ++ j)
    {
        dp[i][j] = dp[i - 1][j];
        for(int k = 1; k < S; k <<= 1)
        if(j & k) (dp[i][j] += dp[i - 1][j ^ k] * p[k] % mod * get_c(S - a[i] - (j ^ k), k - 1)) %= mod;
    }
    long long ans = 0;
    for(int i = 0; i < S; ++ i)
    {
        int bit = __builtin_popcount(i);
        if(bit & 1) (ans -= dp[m][i] * p[S - i - 1]) %= mod;
        else (ans += dp[m][i] * p[S - i - 1]) %= mod;
    }
    printf("%lld", (ans + mod) * S % mod);
}
int main ()
{
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; ++ i)
    scanf("%d", &a[i]);
    sort(a + 1, a + m + 1, cmp);
    S = 1 << n; init(); work();
    return 0;
}

Measured memory_bytes: 14336
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower

using namespace std;

int main()
{
    //system("chcp 65001");

    int a,b,c;
    cin >> a >> b >>c;

    if(a+b+c < 22)
    {
        cout << "win";
    }
    else
    {
        cout << "bust";
    }
    

    return 0;
}

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

using namespace std;

const int N = 101;
const int W = 1e5 + 5;

long long dp[N][W];
pair<int, int> arr[N];

int n, wt;

long long rec(int i, int w) {
  if(i == n) return 0;
  if(dp[i][w] != -1) return dp[i][w];
  long long& iw = dp[i][w];
  iw = rec(i + 1, w);
  if(w + arr[i].first <= wt) 
    iw = max(iw, rec(i + 1, w + arr[i].first) + arr[i].second);
  return iw;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> wt;
  for(int i = 0; i < n; ++i){
    cin >> arr[i].first >> arr[i].second;
  }
  memset(dp, -1, sizeof dp);
  cout << rec(0, 0) << "\n";
}

Measured memory_bytes: 79232
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------
bool color[300][300];    ll a[300][300];int n;ll ans=0;ll b[300][300];
void warshall_floyd(){
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
        if(b[i][k]==INF)continue;
      for (int j = 0; j < n; j++) {  // 終点
          if(b[k][j]==INF)continue;
        chmin(b[i][j], b[i][k] + b[k][j]);
      }
    }
  }
}
//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    cin>>n;

    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            cin>>b[i][j];
            a[i][j]=b[i][j];
        }
    }
    warshall_floyd();
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(b[i][j]<a[i][j]){
                cout<<-1<<endl;
                return 0;
            }
            else{
                bool abc=1;
                for(int x=0;x<n;x++){
                    if(x==i||x==j)continue;
                    if(b[i][j]==b[i][x]+b[x][j]){
                        abc=0;
                    }
                }
                if(abc==1)ans+=a[i][j];
            }
        }
    }
    
    cout<<ans/2<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------
/*
int n;cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)
    cin>>a[i];
*/


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
const int INF = 100000;
typedef pair<int, int> P;
int w, h;
int ny,nx;
int main()
{
    while (cin >> w >> h)
    {
        int dis[h][w];
        bool wall[2][h][w];
        if (w == 0 && h == 0)
            return 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                dis[i][j] = INF;
            }
        }
        for (int i = 0; i < 2 * h - 1; i++)
        {
            //横
            if (i % 2 == 0)
            {
                for (int j = 0; j < w - 1; j++)
                {
                    cin >> wall[0][i / 2][j];
                }
            }
            //縦
            else
            {
                for (int j = 0; j < w; j++)
                {
                    cin >> wall[1][i / 2][j];
                }
            }
        }
        dis[0][0] = 1;
        queue<P> que;
        que.push(P(0, 0));
        while (!que.empty())
        {
            P p = que.front();
            que.pop();
            ny = p.first;
            nx = p.second;
            if (ny - 1 >= 0 && wall[1][ny - 1][nx] == 0 && dis[ny-1][nx] == INF)
            {
                dis[ny - 1][nx] = dis[ny][nx] + 1;
                que.push(P(ny - 1, nx));
            }
            if (ny + 1 < h && wall[1][ny][nx] == 0 && dis[ny + 1][nx] == INF)
            {
                dis[ny + 1][nx] = dis[ny][nx] + 1;
                que.push(P(ny + 1, nx));
            }
            if (nx - 1 >= 0 && wall[0][ny][nx - 1] == 0 && dis[ny][nx - 1] == INF)
            {
                dis[ny][nx - 1] = dis[ny][nx] + 1;
                que.push(P(ny, nx - 1));
            }
            if (nx + 1 < w && wall[0][ny][nx] == 0 && dis[ny][nx + 1] == INF)
            {
                dis[ny][nx + 1] = dis[ny][nx] + 1;
                que.push(P(ny, nx + 1));
            }
        }
        if (dis[h - 1][w - 1] == INF)
            cout << 0 << endl;
        else
            cout << dis[h - 1][w - 1] << endl;
    }
}


Measured memory_bytes: 3116
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

namespace {
    struct Edge{
        int dst, cost;
    };
    typedef vector<Edge> Node;
    typedef vector<Node> Graph;
    Graph G;
    typedef tuple<int, int, int> TP;
    vector<TP> es;
    vector<bool> is_base;
    int N, T, K;

    set<int> used[10000];

    bool find(int u, int p) {
        if(is_base[u]) return true;
        for(Edge e : G[u]) {
            if(e.dst == p) continue;
            if(used[u].count(e.dst)) continue;
            if(find(e.dst, u)) return true;
        }
        return false;
    }

    int solve() {
        REP(i, N) used[i].clear();
        int ans = 0;
        for(auto tp : es) {
            if(K == 0) break;
            int w, a, b;
            tie(w, a, b) = tp;
            if(find(a, b) && find(b, a)) {
                K--;
                ans += w;
                used[a].insert(b);
                used[b].insert(a);
            }
        }
        return ans;
    }
}


int main(){
    iostream_init();
    int Case = 0;
    while(cin >> N >> T >> K && N > 0) {
        cout << "Case " << ++Case << ": ";
        G.assign(N, Node());
        es.clear();
        is_base.assign(N, false);

        REP(i, N-1) {
            int a, b, w;
            cin >> a >> b >> w;
            a--; b--;
            G[a].push_back({b, w});
            G[b].push_back({a, w});
            es.push_back(TP(w, a, b));
        }
        sort(es.begin(), es.end());

        REP(i, T){
            int base;
            cin >> base;
            base--;
            is_base[base] = true;
        }

        cout << solve() << endl;
    }
    return 0;
}

/* vim:set foldmethod=marker: */

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  using BS = bitset<32>;
  Int a,b;
  cin>>a>>b;
  BS x(a),y(b);
  cout<<(x&y)<<endl;
  cout<<(x|y)<<endl;
  cout<<(x^y)<<endl;
  return 0;
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
#define ls (x<<1)
#define rs (x<<1|1)
const int N=3e5+10;
const int lim=1023;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,v[N],w[N],sv,sw,q;
vector<pii> all[N],oth;

void dfs(int x) {
	if(x>lim||x>n) return;
	all[x].pb(mp(sv,sw));
	dfs(ls);dfs(rs);
	sv+=v[x];sw+=w[x];
	all[x].pb(mp(sv,sw));
	dfs(ls);dfs(rs);
	sv-=v[x];sw-=w[x];
}

vector<pii> build(vector<pii> vec) {
	sort(vec.begin(),vec.end());
	int mx=0;vector<pii> ret;
	for(auto t:vec) {
		if(t.se>mx) mx=t.se,ret.pb(t);
	}
	return ret;
}

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) w[i]=gi(),v[i]=gi();
	dfs(1);
	for(int i=1;i<=lim&&i<=n;i++) all[i]=build(all[i]);
	cin>>q;
	for(int i=1;i<=q;i++) {
		int x=gi(),l=gi(),y=x;
		oth.clear();
		while(y>lim) {
			oth.pb(mp(v[y],w[y]));
			y>>=1;
		}
		int ans=0;
		for(int s=0;s<(1<<sz(oth));s++) {
			sv=0;sw=0;
			for(int j=0;j<sz(oth);j++)
				if(s>>j&1) sv+=oth[j].fi,sw+=oth[j].se;
			if(sv>l) continue;
			auto it=lower_bound(all[y].begin(),all[y].end(),mp(l-sv,1234567890));
			if(it==all[y].begin()) ans=max(ans,sw);
			else --it,ans=max(ans,sw+it->se);
		}
		cout<<ans<<'\n';
	}
	return 0;
}


Measured memory_bytes: 18244
#include <iostream>
#include<vector>
#include <algorithm>
using namespace std;
int main(void)
{
	int N;
	cin >> N;
	vector<int> data(N);
	vector<int> data1(N);
	for (int i = 0; i < N; i++)
	{
		cin >> data[i];
		data1[i] = data[i];
	}
	std::sort(data1.begin(), data1.end());
	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		if (data[i] != data1[i])
		{
			cnt++;
		}
		
	}
	if (cnt == 0 || cnt == 2)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))


def kitai(i: int) -> int:
    if i % 2:
        return ((1 + i) * (i // 2) + (i // 2) + 1) / i
    else:
        return ((1 + i) * (i // 2)) / i


kitai_dict = dict()
kitai_list = list()

for i in range(n):
    if a[i] in kitai_dict:
        kitai_list.append(kitai_dict[a[i]])
    else:
        kitai_dict[a[i]] = kitai(a[i])
        kitai_list.append(kitai_dict[a[i]])

current_sum = sum(kitai_list[:k])
ans = current_sum
for i in range(k, n):
    current_sum += kitai_list[i]
    current_sum -= kitai_list[i - k]
    ans = max(ans, current_sum)

print(ans)


Measured memory_bytes: 77448
n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
max_num = max(a_list)
a_list.pop()
n_half = max_num / 2
a_list_dif = [abs(i - n_half) for i in a_list]
dif_min_num = min(a_list_dif)
r = 0
if n_half + dif_min_num in a_list:
    r = int(n_half + dif_min_num)
elif n_half - dif_min_num in a_list:
    r = int(n_half - dif_min_num)
else:
    r = 0
print(max_num, r)


Measured memory_bytes: 14428
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, k := intScanner(), intScanner()
	ps := intSliceScanner(n)
	sort.Ints(ps)
	ans := 0
	for i := 0; i < k; i++ {
		ans += ps[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  int64_t N;
  cin>>N;
  bool ok=true;
    int64_t ans=99999999999999;
  for(int64_t i=1;i*i<=N;i++){
    if(N%i!=0){continue;}
    int64_t b=N/i;
    int64_t dis=i+b-2;
    if(dis<ans){ans=dis;}
   }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;
const ll YEAR = 5e15;


int main(int argc, char* argv[])
{
  std::string S;
  ll K;
  std::cin >> S >> K;

  ll cnt = INF;
  for (ll i = 0; i < (ll)S.size(); i++) {
    if (S[i] != '1') {
      cnt = i;
      break;
    }
  }

  char ans = K > cnt ? S[cnt] : '1';
  std::cout << ans << std::endl;

  return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  int c;
  if(b<10) c = 10*a+b;
  else if(b<100) c = 100*a+b;
  else if(b==100) c = 1000*a+b;
  for(int i=0;i*i<=100100;i++){
    if(i*i == c){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
num = 0
n.times do |i|
  (n-1).downto(i+1) do |j|
    if a[j] < a[j-1]
      tmp = a[j]
      a[j] = a[j-1]
      a[j-1] = tmp
      num += 1
    end
  end
end
puts a.join(' ')
puts num

Measured memory_bytes: 8716
#include <iostream>
#include <cmath>
#include <limits.h>
using namespace std;

long long H,W;
int main(){
	cin >> H >> W;
	long long ans = 10e11;
	if(H%3 == 0 || W%3 == 0){
		cout << 0 << endl;
	}else{
		if(W%2==0){
			for(int A=1;A<H;A++){
				if(fabs(W*H-3*W*A/2)<ans) ans = fabs(W*H-3*W*A/2);
			}
		}else if(W%2==1){
			for(int A=1;A<H;A++){
				long long ma = max((W+1)*A/2,W*(H-A));
				long long mi = min((W-1)*A/2,W*(H-A));
				if(ma-mi < ans) ans = ma-mi;
			}
		}
		if(H%2==0){
			for(int A=1;A<W;A++){
				if(fabs(W*H-3*H*A/2)<ans) ans = fabs(W*H-3*H*A/2);
			}
		}else if(H%2==1){
			for(int A=1;A<W;A++){
				long long ma = max((H+1)*A/2,H*(W-A));
				long long mi = min((H-1)*A/2,H*(W-A));
				if(ma-mi < ans) ans = ma-mi;
			}
		}

		cout << min(ans,min(W,H)) << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    ll n,a,sum=0,mini=99999;
    cin>>n;
    lol(i,n){
	cin>>a;
	sum+=a;
	if(a%2==1)mini=min(mini,a);
    }
    if(sum%2==0)cout<<sum/2<<endl;
    else cout<<(sum-mini)/2<<endl;
    return 0;
}


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

int main()
{
  long long  n,i,uniq = 1;
  cin >> n;
    string s[n];
    for(i=0; i< n ; i++)
    {
        cin >> s[i];
    }
    sort(s,s+n);
    for (int i = 0; i <n-1 ; i++) {
        if(s[i]!=s[i+1])
            uniq++;
    }
    cout << uniq << endl;
}


Measured memory_bytes: 9856
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>

typedef long long ll;
#define fi first
#define se second

int W, H;
ll P[112345];
ll Q[112345];
ll ans;

using namespace std;

int main(){
  
  cin>>W>>H;
  
  int i;
  
  for( i = 0; i < W; i++ ){
    scanf("%d", P+i);
  }
  
  P[W] = 112345678;
  
  for( i = 0; i < H; i++ ){
    scanf("%d", Q+i);
  }
  
  Q[H] = 112345678;
  
  ll numP, numQ;
  
  numP = H+1;
  numQ = W+1;
  
  int idxP;
  int idxQ;
  
  idxQ = 0;
  idxP = 0;
  
  sort( P, P+W );
  sort( Q, Q+H );
  
  ans = 0;
  
  
  while( idxP != W || idxQ != H ){
    
    if( P[idxP] > Q[idxQ] ){
      ans += Q[idxQ]*numQ;
      idxQ++;
      numP--;
    }
    else{
      ans += P[idxP]*numP;
      idxP++;
      numQ--;
    }
    
    //printf("%d %d\n",idxP, idxQ );
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    int N;
    cin >> N;
    VI A(N);
    rep(i,N){
        cin >> A[i];
    }
    int q;
    cin >> q;
    VI m(q);
    rep(i,q){
        cin >> m[i]; 
    }
    vector<string> ans_print(q, "no");
    for(int j=0; j<(1<<N); j++){
        int ans=0;
        rep(k,N){
            if((j>>k) & 1){
                ans+=A[k];
            }
        }
        for(int l=0; l<q; l++){
            if(ans==m[l]){
                ans_print[l]="yes"; 
            }
        }            
    }
    rep(i,q){
        cout << ans_print[i] << endl;
    }
}



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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    combInit();
    int n, k;
    cin >> n >> k;
    vector< LL > v(n);
    for( int i = 0; i < n; ++i ) {
        cin >> v[i];

    }
    sort(all(v), greater< LL >());

    LL mx = 0;
    for( int i = 0; i < n; ++i ) {
        LL p = comb(n - i - 1, k - 1) % MOD;
        p = p * v[i] % MOD;
        mx += p;

    }

    reverse(all(v));
    LL mn = 0;
    for( int i = 0; i < n; ++i ) {
        LL p = comb(n - i - 1, k - 1) % MOD;
        p = p * v[i] % MOD;
        mn += p;

    }
    cout << (mx - mn) % MOD << endl;

    return 0;
}



Measured memory_bytes: 5760
X = int(input())

maxi = 0

if X < 4:
    print(1)
    exit()

for i in range(1, X+1):
    for j in range(2, X+1):
        if i**j <= X and i**j >= maxi:
            maxi = i**j
        if i**j > X:
            break

print(maxi)

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

using namespace std;

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

    int n;
    string s;
    cin >> n >> s;
    int sum = 0;
    int prev = -1;
    for(int i = 0; i < s.length(); i++) {
        int cur = s[i];
        if(cur != prev) {
            sum++;
        }
        prev = cur;
    }
    cout << sum << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  string S;
  cin>>S;
  int ans=0;
  int count=0;
  for(int i=1;i<=(int)S.size();i++){//i文字含む
    //cout<<i<<endl;
    for(int j=0;j<(int)S.size()-i+1;j++){//スタート
      //cout<<" "<<j<<endl;
      int count=0;
      for(int k=j;k<j+i;k++){
        //cout<<"   "<<k<<endl;
        if(S.at(k)=='A' || S.at(k)=='G' || S.at(k)=='C' || S.at(k)=='T'){
          count++;
        }
      }
      if(count==i){
        ans=max(ans,count);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length() - 1;
        long sum = 0;
        for (int i = 0 ; i < (Math.pow(2,  n)); i++) {
            List<Integer> list = new ArrayList<Integer>();
            list.add(0);
            for (int j = 0 ; j < n ; j++) {
                if ((1 & i >> j) == 1) {
                    list.add(j + 1);
                }

            }
            list.add(s.length());
            for (int k = 0 ; k < list.size() - 1 ; k++) {
                long num = Long.valueOf(s.substring(list.get(k), list.get(k + 1)));

                sum += num;
            }
        }
        System.out.println(sum);
    }

}

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

using namespace std;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.setf(ios::fixed); cout.precision(17);
	int n, a, b;
	double z[51];
	long long c[51][51];
	cin >> n >> a >> b;
	for(int  i = 0; i < n; i++){
		cin >> z[i];
	}	
	sort(z, z + n);
	double mean = 0.0, last;
	for(int  i = n - 1; i >= n - a; i--){
		mean += z[i];
		last = z[i];
	}
	int x = 0, k = 0, cnt = 0;	
	for(int i = n - 1; i >= 0; i--){
		cnt++;
		if(z[i] != last) continue;
		if(z[i] < last) break;
		x++;
		if(cnt <= a) k++;
	}
	//cout << x << " " << k<< endl;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= i; j++){
			if(i == j || j == 0){
				c[i][j] = 1ll;
				continue;
			}
			c[i][j] = c[i-1][j] + c[i-1][j-1];
		}
	}
	long long ans = 0ll;
	if(k == a){
		for(k = a; k <= b; k++){
			ans += c[x][k];
		}
	}
	else ans += c[x][k];
	cout << mean/ (1.0 * a) << "\n" << ans << "\n";
	return 0;
}


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

int main(void){
    string _input;
    cin >> _input;

    if(_input == "Sunny") cout << "Cloudy" << endl;
    else if(_input == "Cloudy") cout << "Rainy" << endl;
    else if(_input == "Rainy") cout << "Sunny" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int main() {
  IN(N);

  int before = 0;
  vector<int> H;
  REP(i, N) {
    IN(h);
    H.push_back(h);
  }
  reverse(ALL(H));
  REP(i, N) {
    // 後ろから見ていく
    if (H[i+1] > H[i]) {
      --H[i+1];
      if (H[i+1] > H[i]) {
        OUT("No");
        return 0;
      }
    }
  }
  OUT("Yes");

  return 0;
}


Measured memory_bytes: 892
while True:
    n,m=map(int,input().split())
    if (n,m)==(0,0):
        break
    a=list(map(int,input().split()))
    b=0
    for i in range(n):
        for j in range(i+1,n):
            if a[i]+a[j]>m:
                continue
            else:
                b=max(b,a[i]+a[j])
    if b==0:
        print("NONE")
    else:
        print(b)


Measured memory_bytes: 5628