akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	ma, sum := 1, 0
	for sum < N {
		sum += ma
		ma++
	}
	ma--
	// 解くべき配点の最大値はma
	for score := ma; score > 0; score-- {
		if N-score >= 0 {
			fmt.Println(score)
			N -= score
		}
		if N == 0 {
			break
		}
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define endl "\n"
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)                   
using namespace std;                            
                                                
void yes() {cout << "YES" << endl;}                                               
void no() {cout << "NO" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const long long INF = 8e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7;

void solve() {
    string s; cin >> s;
    int mx = 0, t = 0;;
    for (int i = 0; i < sz(s); i++) {
        if (s[i] == 'R') {
            t++;
            mx = max(mx, t);
        }
        else t = 0;
    }
    cout << mx << endl;
}

int main() {
    jonathan; 
    livingston;
    bool tests = 0;
    int t = 1;
    if (tests) cin >> t;
    for (int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
typedef long long int lli;

int main() {
  lli N, M;
  cin >> N >> M;
  lli ans=0;
  if (2*N<=M) {
    ans=(M-2*N)/4+N;
  } else {
    ans=M/2;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

const int N = int(1e8) + 7;
long long l, r;

void init(){
    scanf("%lld %lld", &l, &r);
}

void solve(){
    init();
    if(r-l > 2019){
        printf("0\n");
        return;
    }
    long long ans = (l*(l+1))%2019;
    for(long long i = l; i <= r-1; i++)
    for(long long y = l+1; y <= r; y++){
        ans = min(ans, (i*y)%2019);
    }
    printf("%lld\n", ans);
}

const bool mtc = false;

int main(){
    int t;
    if(mtc){
        scanf("%d", &t);
        while(t--) solve();
    }
    else solve();
}


Measured memory_bytes: 256
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! { a, b };
    if a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 {
        println!("Possible");
    } else {
        println!("Impossible");
    }
}


Measured memory_bytes: 4352
#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 all(A) A.begin(),A.end()
typedef long long ll;



int main(){
  
  int n,m,k;
  cin >> n >> m >> k;
  vector<vector<int>> dp(n+1,vector<int>(m+1));
  dp[0][0] = 0;
  rep(i,n){
    rep(j,m){
      dp[i+1][j] = dp[i][j]+m-j*2;
      dp[i][j+1] = dp[i][j]+n-i*2;
    }
  }
  rep(i,n+1) rep(j,m+1){
    if(dp[i][j] == k){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

int main()
{
	int minn = 0x7fffffff;
	int n;
	int t = 0;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		if(a < minn) minn = a;
		if(a <= minn) t++;
	}
	cout << t <<endl;
	return 0;
}


Measured memory_bytes: 256
lx = list(map(int,input().split(" ")))
lb = list(map(int,input().split(" ")))
#la = [li[0]][li[1]]
la = []
for i in range(0, lx[0]):
    la.append(list(map(int,input().split(" "))))

cnt = 0

for i in range(0,lx[0]):
    tmp = lx[2]
    for j in range(0, lx[1]):
        tmp += la[i][j] * lb[j]
    if (tmp > 0):
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string s[101];
int n;
int main() {
	scanf("%d%*d",&n);
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	sort(s+1,s+n+1);
	for(int i=1;i<=n;i++){
		printf("%s",s[i].c_str());
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>                                                      
#include <cstdio>                                                        
using namespace std;                                                     
                                                                         
int main() {                                                             
  int a, b;                                                              
  cin >> a >> b;                                                         
  int d = a/b;                                                           
  int r = a%b;                                                           
  double f = (double)a/b;                                                
  printf("%d %d %.5f\n", d, r, f);                                       
  return 0;                                                              
}                                                                        
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                             

Measured memory_bytes: 3144
#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 ALL(obj) (obj).begin(), (obj).end()
#define INF (int)1e9
typedef long long ll;

//1 2 3 4 5 6 7 8 9
//2 5 5 4 5 6 3 7 6

//-> {1} {7} {4} {2,3,5} {6,9} {8}
//->  2   3   4     5      6    7

int main() {
    int N,M; cin >> N >> M;
    vector<int> A(10,INF);
    vector<int> cost{INF,2,5,5,4,5,6,3,7,6};
    REP(i,M){
        int a; cin >> a;
        A[a] = cost[a];
    }
    if(A[2]!=INF && A[3]!=INF) A[2]=INF;//わざわざ同じ本数で小さい数字を使う必要はない
    if(A[3]!=INF && A[5]!=INF) A[3]=INF;
    if(A[2]!=INF && A[5]!=INF) A[5]=INF;
    if(A[6]!=INF && A[9]!=INF) A[6]=INF;

    vector<vector<int>> dp(10, vector<int>(10100,-1));
    vector<vector<int>> prev(10, vector<int>(10100,-1));//復元用
    dp[0][0] = 0;
    REP(i,10){
        REP(j,N+1){
            if(dp[i][j]==-1) continue;
            if(j+A[i]<=N){
                if(dp[i][j+A[i]] <= dp[i][j]+1){
                    dp[i][j+A[i]] = dp[i][j]+1;
                    prev[i][j+A[i]] = j;
                }
            }
            if(i!=9){
                dp[i+1][j] = dp[i][j];
                prev[i+1][j] = j;
            }
        }
    }

    // REP(i,10){
    //     REP(j,N+1){
    //         cout << prev[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    int cur = N;
    int i = 9;
    while(i!=0 || cur!=0){
        if(prev[i][cur] == cur){//縦に来た場合
            i--;
        }
        else{
            cur -= A[i];
            cout << i;
        }
    }
    cout << endl;

    //cout << prev[9][N] << endl;
    //cout << dp[9][N] << endl;
    return 0;
}

Measured memory_bytes: 4156
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

struct Node
{
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node*)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL)
	{
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void inorder(Node* u) {
	if (u == NIL)
		return;
	inorder(u->left);
	cout << " " << u->key;
	inorder(u->right);
}

void preoder(Node* u) {
	if (u == NIL)
		return;
	cout << " " << u->key;
	preoder(u->left);
	preoder(u->right);
}

int main()
{
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		char c[32];
		cin >> c;
		if (c[0] == 'i') {
			int k;
			cin >> k;
			insert(k);
		}
		else {
			inorder(root);
			cout << endl;
			preoder(root);
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 26504
#include<iostream>
#include<queue>
#include<map>
using namespace std;

int c[4];

struct State{
	int x,y,d,cost;
};


bool operator < (const State a, State b){
	return a.cost>b.cost;
}

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

void calc(int w,int h){
	int direction[30][30];
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cin>>direction[j][i];

	for(int i=0;i<4;i++)
		cin>>c[i];

	priority_queue<State> Q;
	bool costmap[30][30][4];

	for(int i=0;i<30;i++)
		for(int j=0;j<30;j++)
			for(int z=0;z<4;z++)
				costmap[i][j][z]=false;

	costmap[0][0][0]=true;

	State first;
	first.x=first.y=first.cost=first.d=0;
	Q.push(first);

	State k;
	while(!Q.empty()){
		k=Q.top();
		Q.pop();
		costmap[k.x][k.y][k.d]=true;
		if(k.x==w-1 && k.y==h-1)
			break;

		for(int i=0;i<4;i++){
			int tx,ty,td,tcost;
			State temp;
			td=(k.d+i)%4;
			tx=k.x+dx[td];
			ty=k.y+dy[td];
			if(tx<0 || ty<0 || tx>=w || ty>=h)
				continue;
			tcost=k.cost;
			if(direction[k.x][k.y]!=i)
				tcost+=c[i];
			temp.x=tx;
			temp.y=ty;
			temp.d=td;
			temp.cost=tcost;
			if(!costmap[temp.x][temp.y][temp.d])
				Q.push(temp);
		}
	}

	cout<<k.cost<<"\n";
}

int main(){
	int w,h;
	cin>>w>>h;
	while(w!=0){
		calc(w,h);
		cin>>w>>h;
	}
	return 0;
}

Measured memory_bytes: 0
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n,k= map(int, input().split())

tmp = n//k

a = abs(n-k*tmp)
b = abs(a-k)

print(min(a,b))





Measured memory_bytes: 9096
#abc098c

n=int(raw_input())
s=raw_input()
cnt=s[1:].count('E')
res=cnt
for i in xrange(1,n):
 if s[i-1]=='W':
  cnt+=1
 if s[i]=='E':
  cnt-=1
 res=min(cnt,res)
print res


Measured memory_bytes: 3304
n, a, b = STDIN.gets.chomp.split(" ").map{|p| p.to_i}
x = STDIN.gets.chomp.split(" ").map{|p| p.to_i}
sum = 0

for i in 0..(n-2) do
  t = (x[i+1] - x[i]) * a
  if t < b
    sum += t
  else
    sum += b
  end
end

puts sum

Measured memory_bytes: 9476
def count_up(ary)
    hash = Hash.new(0)
    ary.each do |item|
     hash[item] += 1  
  end
 return hash
end

# 要素数を取得
n = gets.chop.to_i
array = gets.split(' ')
 
# 偶数のみ、奇数のみの配列を抽出する
even = array.select.with_index {|a, i| i%2 == 0 }
odd  = array.select.with_index {|a, i| i%2 == 1 }

# p even
# p odd

# どの数字が何回出現するかを示すハッシュをつくる
even_count = count_up(even)
odd_count  = count_up(odd)

# p even_count
# p odd_count


# 出現回数順に並べ替える
even_count = even_count.sort_by{ |_, v| -v }
odd_count = odd_count.sort_by{ |_, v| -v }

# p even_count
# p odd_count


# 出現回数トップの数字が異なる場合
if even_count[0][0] != odd_count[0][0]
    replace = n - (even_count[0][1] + odd_count[0][1])
 
# 出現回数トップの数字が同じ場合
else
    # 1種類しか数字がない場合は、2番目に多い数字の出現回数を0とする
    if even_count.size > 1
        even_second = even_count[1][1]
    else
        even_second = 0
    end
    if odd_count.size > 1
        odd_second = odd_count[1][1]
    else
        odd_second = 0
    end
    replace = n - [even_count[0][1] + odd_second, even_second + odd_count[0][1]].max
end
 
p replace


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

using namespace std;

int main()
{
 int n,x,t;
 
 cin>>n>>x>>t;
  int i=1;
  while(1){
  if(x*i>=n)
    break;
    i++;
    }
  cout<<t*i;
  return 0;
  
}


Measured memory_bytes: 3604
# coding: utf-8
import sys,pprint

(N,M) = map(int,input().split())
paths = {}
for i in range(1,N+1):
    paths[i] = set()
for i in range(M):
    (a,b) = map(int,input().split())
    paths[a].add(b)
    paths[b].add(a)

result = [0]*N

searchroom = []
nextsearch = []
searchroom.append(1)
while len(searchroom) > 0:
    for n in searchroom:
        for s in paths[n]:
            if result[s-1] == 0:
                result[s-1] = n
                nextsearch.append(s)
    searchroom = nextsearch.copy()
    nextsearch.clear()

# no判定
for i in result[1:]:
    if i == 0:
        print("No")
        sys.exit()
print("Yes")    
for i in result[1:]:
    print(i)

Measured memory_bytes: 71292
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, W = gets_i_list
wv_list = []
N.times do
  wv_list.push gets_i_list
end
wv_list.sort!{|x,y| x[0]<=>y[0]}
INF = Float::INFINITY

# dpをhashで管理する。 {容量 => 最大価値}
dp = Hash.new(INF)
dp[0] = 0

wv_list.each do |w, v|
  # ループで更新した値を参照してしまうため、dupする
  # (計測したい処理)
  dp.dup.each do |dpv, dpw|
    nw = dpw + w
    nv = dpv + v
    # 容量を超えた場合は next
    next if nw > W
    # 同じ重さで価値が大きければ更新
    dp[nv] = nw if dp[nv] > nw
  end
end
puts dp.keys.max

# # dpをhashで管理する。 {容量 => 最大価値}
# dp = Hash.new(0)
# dp[0] = 0

# wv_list.each do |w, v|
#   # ループで更新した値を参照してしまうため、dupする
#   # (計測したい処理)
#   dp.dup.each do |dpw, dpv|
#     nw = dpw + w
#     nv = dpv + v
#     # 容量を超えた場合は next
#     next if nw > W
#     # 同じ重さで価値が大きければ更新
#     dp[nw] = nv if dp[nw] < nv
#   end
# end
# puts dp.values.max


Measured memory_bytes: 80584
import copy
H,W,K = map(int,input().split())
c = [[0] * W for i in range(H)]
for i in range(H):
  s = input()
  for j in range(W):
    if(s[j] == "#"):
      c[i][j] = 1
#goukei = sum([sum(c[i]) for i in range(H)])
#sa = goukei-K
count = 0
for i in range(2**H):
  temp = copy.deepcopy(c)
  for j in range(H):
    if ((i >> j) & 1):
      for k in range(W):
        temp[j][k]=0
  for ii in range(2**W):
    temp2 = copy.deepcopy(temp)
    for jj in range(W):
      if ((ii >> jj) & 1):
        for k in range(H):
          temp2[k][jj]=0
    if(sum([sum(temp2[k]) for k in range(H)]) == K):
      count += 1    
print(count)   

Measured memory_bytes: 9236
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

struct Node{
	int key;
	Node *p,*l,*r;
}; 

Node *root,*NIL;

void insert(int k){
	Node *x = root;
	Node *y = NIL;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->l = NIL;
	z->r = NIL;
	
	while(x!=NIL){
		y=x;
		if(z->key<x->key){
			x = x->l;
		}else{
			x= x->r;
		}
	}
		
		z->p = y;
		if(y==NIL){
			root = z;
		}else {
			if(z->key<y->key){
				y->l=z;
			}else{
				y->r = z;
			}
		}
	}
	
	Node *find(Node *u, int k)
	{
		while(u!=NIL&&u->key!=k){
			if(u->key>k){
				u = u->l;
			}else{
				u = u->r;
			}
		}
		return u;
	}
	
	
	
	
		
	void inorder(Node *u){
		if(u==NIL) return;
		inorder(u->l);
		printf(" %d",u->key);
		inorder(u->r);
	}
	
	
	
	void preorder(Node *u){
		if(u==NIL) return;
		printf(" %d",u->key);
		preorder(u->l);
		preorder(u->r);
	}
	
	
	int main(){
		int n,i,x;
		string com;
		
		scanf("%d",&n);
		
		for(int i=0;i<n;i++){
			cin>>com;
			if(com=="insert"){
				scanf("%d", &x);
				insert(x);
			}else if(com=="find"){
				scanf("%d", &x);
				Node *p = find(root,x);
				if(p!=NIL) printf("yes\n");
				else printf("no\n");
			}
			else if(com=="print"){
				inorder(root);
				printf("\n");
				preorder(root);
				printf("\n");
			}
		}
		
		
		return 0;
}

Measured memory_bytes: 22048
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

//デバッグ
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};


ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}


//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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] % MOD * finv[n-k] % MOD;
}

ll N;
ll a[20][20];
ll memo[1<<16];
ll P[1<<16];
ll saiki(ll S){
  if(S == 0) return 0;
  if(memo[S] != INFL) return memo[S];
  ll res = -INFL;
  for(ll T = S; T >= 0; T = (T-1) & S){
    if(T == S) continue;
    res = max(res, P[S-T] + saiki(T));
    if(T == 0) break;
  }
  return memo[S] = res;
}

void solve(){
  rep(i, 1<<N){
    vector<ll> x(N, 0);
    rep(j, N) if((i>>j) & 1) x[j] = 1;
    rep(j, N-1){
      for(ll k = j+1; k < N; k++){
        if(x[j] & x[k]) P[i] += a[j][k];
      }
    }
  }
  rep(i, 1<<N) memo[i] = INFL;
  cout << saiki((1<<N)-1) << endl;
}

int main(){
  cin >> N;
  rep(i, N)rep(j, N) cin >> a[i][j];
  solve();
}


Measured memory_bytes: 1280
CHARACTER(26) S,ABC
INTEGER X(26)
READ*,S
ABC="abcdefghijklmnopqrstuvwxyz"
X=0
DO I=1, LEN_TRIM(S)
  DO J=1,26
   IF ( S(I:I)==ABC(J:J) ) X(J)=X(J)+1
  END DO
END DO
PRINT"(A)",MERGE("yes"," no",MAXVAL(X)==1)
END 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,a[200],c=0,ans=INF;
  cin>>n;
  rep(i,n)cin>>a[i];
  FOR(i,-100,101){
    rep(j,n)c+=(i-a[j])*(i-a[j]);
    ans=min(ans,c);
    c=0;
  }
  printf("%lld",ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

int main() {

	int size = 0;
	vector <int> list;

	int num = 0;
	int max = 0;
	int mperfit= -999999999;

	scanf("%d", &size);
	for (int i = 0; i < size; i++) {
		scanf("%d", &num);
		list.push_back(num);
	}

	max= list[ size-1];
	for (int i = size-2; i >= 0; i--) {
	     num=max-list[i];
	     if(num>mperfit){mperfit=num;}
	     if(list[i]>max){max=list[i];}
	}

	printf("%d\n", mperfit);
}



Measured memory_bytes: 3352
#include<iostream>
using namespace std;
long long o,n;
int main(){
  int i,j,k;long long d[4][4001]={{}};
  for(i=0;i<=1000;i++) d[0][i]=1;
  for(j=1;j<4;j++){
    for(i=0;i<=4001;i++) d[j][i]=0;
    for(i=0;i<=4000;i++){
      for(k=0;k<=1000;k++){
	if(i+k>4000) break;
	d[j][i+k]+=d[j-1][i];
      }
    }
  }
  while(cin>>n) cout << d[3][n] << endl;
}


Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
const double EPS = 1e-9;
const double INF = 1e18;
const double base = 3*1e4;
vector<double> mincost((int)1e4, INF);

double prim(int s, vector<vector<pair<int, double> > > &adj){
    int n = adj.size();
    //vector<double> mincost(n, INF);
    priority_queue<pair<double, int> > wait;
    wait.push(make_pair(0, s));
    
    int v = 0;
    double ret = 0;
    while(!wait.empty() && v<n){
        double cost = -wait.top().first;
        int idx = wait.top().second;
        wait.pop();
        if(cost > mincost[idx] +EPS) continue;
        ret += cost;
        v++;
        mincost[idx] = -INF;
        for(int i=0; i<(int)adj[idx].size(); i++){
            int nidx = adj[idx][i].first;
            double ncost = adj[idx][i].second;
            if(ncost +EPS < mincost[nidx]){
                wait.push(make_pair(-ncost, nidx));
                mincost[nidx] = ncost;
            }
        }
    }
    
    for(int i=0; i<n; i++){
        if(mincost[i] == INF){
            ret += prim(i, adj);
        }
    }
    return ret -(v-1)*base;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<double> px(n), py(n);
    for(int i=0; i<n; i++){
        cin >> px[i] >> py[i];
    }
    vector<vector<pair<int, double> > > adj(n);
    double sum = 0;
    for(int i=0; i<m; i++){
        int p,q;
        cin >> p >> q;
        p--; q--;
        double d = sqrt((px[p]-px[q])*(px[p]-px[q]) +(py[p]-py[q])*(py[p]-py[q]));
        sum += d;
        adj[p].push_back(make_pair(q, base -d));
        adj[q].push_back(make_pair(p, base -d));
    }
    cout << fixed;
    cout << setprecision(3);
    cout << sum +prim(0, adj) << endl;
    return 0;
}

Measured memory_bytes: 5268
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n, m;
  cin >> n >> m;

  if (n == m) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

# A.sort(reverse=True)
# B.sort(reverse=True)

rowrange = 0
colrange = 0
ans = 1
for i in reversed(range(1, N * M + 1)):
    r = i in A
    c = i in B
    if r is True and c is True:
        rowrange += 1
        colrange += 1
        A.remove(i)
        B.remove(i)
    elif r is True and c is False:
        rowrange += 1
        ans = (colrange * ans) % (10 ** 9 + 7)
        A.remove(i)
    elif r is False and c is True:
        colrange += 1
        ans = (rowrange * ans) % (10 ** 9 + 7)
        B.remove(i)
    else:
        ans = ((rowrange * colrange - (N * M - i)) * ans) % (10 ** 9 + 7)
print(ans)


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

bool izryt(vector<int> &v) {
  int d = 0;
  bool res = true;
  for (int i = 0; i < v.size(); ++i) {
    if (i > d) {
      res = false;
      break;
    }

    d = max(d, i + v[i]);
  }

  return res;
}

int main() {
  int n;
  cin >> n;

  vector<int> d(n);
  for (auto &i : d) cin >> i;
  for (auto &i : d) i /= 10;

  bool ans = true;
  if (!izryt(d)) ans = false;
  reverse(d.begin(), d.end());
  if (!izryt(d)) ans = false;

  cout << (ans ? "yes" : "no") << endl;
}

Measured memory_bytes: 3864
#include <iostream>
#include <algorithm>

#define ll long long int

using namespace std;

ll x[100005];
ll v[100005];
ll sums[100005];
ll maxes[100005];
ll sums2[100005];
ll maxes2[100005];
ll n, c;

int main() {
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
  }
  ll ans = 0;
  ll cals = 0;
  for (int i = 1; i <= n; i++) {
    cals += v[i];
    ans = max(ans, cals - x[i]);
  }
  cals = 0;
  for (int i = n; i >= 1; i--) {
    cals += v[i];
    ans = max(ans, cals - (c - x[i]));
  }
  sums[0] = 0;
  maxes[0] = 0;
  // xes[0] = 0;

  for (int i = 1; i <= n; i++) {
    sums[i] = sums[i - 1] + v[i];
    maxes[i] = max(maxes[i - 1], sums[i] - x[i]);
    // xes[i] = maxes[i] > maxes[i - 1] ? x[i] : xes[i - 1];
  }
  
  sums2[n + 1] = 0;
  maxes2[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    sums2[i] = sums2[i + 1] + v[i];
    maxes2[i] = max(maxes2[i + 1], sums2[i] - (c - x[i]));
  }

  for (int i = 1; i <= n; i++) {
    ans = max(ans, maxes[i] + maxes2[i + 1] - x[i]);
  }
  for (int i = n; i >= 1; i--) {
    ans = max(ans, maxes2[i] + maxes[i - 1] - (c - x[i]));
  }

  // for (int i = 1; i <= n; i++) {
  //   ll left_sum = sums[n] - sums[i - 1] - (c - x[i]);
  //   ll dbld = (c - x[i] > xes[i - 1]) ? xes[i - 1] : c - x[i];
  //   ans = max(ans, maxes[i - 1] + left_sum - dbld);
  // }
  
  // for (int i = 0; i < n; i++) {
  //   for (int j = n - 1; j > i; j--) {
  //     ll cals = 0;
  //     for (int k = 0; k <= i; k++) {
  // 	cals += v[k];
  //     }
  //     for (int k = n - 1; k >= j; k--) {
  // 	cals += v[k];
  //     }
  //     ll dist = min(2 * x[i] + c - x[j], 2 * (c - x[j]) + x[i]);
  //     ans = max(ans, cals - dist);
  //   }
  // }
  cout << ans;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
int vis[N];
int main()
{
    int n;
    ll sum=0;
    scanf("%d",&n);
    for(int i=3;i<=n;i+=3)
        vis[i]=1;
    for(int i=5;i<=n;i+=5)
        vis[i]=1;
    for(int i=1;i<=n;i++)
        sum+=(vis[i]==1?0:i);
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 7672
/*https://atcoder.jp/contests/abc087/tasks/abc087_b*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	int a, b, c, x, count = 0;
	cin >> a >> b >> c >> x;
	if (x % 50 != 0)
	{
		cout << "0";
		return 0;
	}
	for (int i = 0; i <= a; i++)
	{
		for (int j = 0; j <= b; j++)
		{
			for (int k = 0; k <= c; k++)
			{
				int temp = i * 500 + j * 100 + k * 50;
				// cout << temp << " " << i << " " << j << " " << k << endl;
				if (temp == x)
					count++;
			}
		}
	}
	cout << count;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;


int main() {
  ll n, k; cin >> n >> k;
  map<char, ll> ma;
  cin >> ma['s'] >> ma['p'] >> ma['r'];
  string t; cin >> t;

  ll ans = 0;
  rep(i, 0, n){
    if(i < k) ans += ma[t[i]];
    else{
      if(t[i] == t[i-k]){
        t[i] = '.';
      }else{
        ans += ma[t[i]];
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
import heapq

x = map(int,raw_input().split())
n=x[0]
m=x[1]
a = map(int, raw_input().split())

def minus(n):
    return float(n*(-1))

def plus(n):
    return int(n*(-1))

a=list(map(minus, a))
heapq.heapify(a)

for i in range(m):
    heapq.heappush(a, heapq.heappop(a)/2)

a=list(map(plus, a))

print(sum(a))


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

int main(){
	double r, S, L, pi = 3.14159265358979;
	
	cin >> r;
	S = r*r*pi;
	L = 2*r*pi;
	
	printf("%f %f\n", S, L);
	
	return 0;
}

Measured memory_bytes: 1232
n=input()
s=range(1,14)
h=range(1,14)
c=range(1,14)
d=range(1,14)
trump={'S':s,'C':c,'H':h,'D':d}
for i in range(n):
    suit,num=raw_input().split()
    num=int(num)
    trump[suit].remove(num)
count=0
for suit in ['S','H','C','D']:
    for num in trump[suit]:
        print('%s %d'%(suit,num))

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

 
int main(){
  int N, M;
  cin >> N >> M;

  vector<int> ac(N, 0), wa(N, 0);
  int num;
  string result;
  int ac_cnt = 0, wa_cnt = 0;
  for(int i = 0; i < M; i++){
    cin >> num >> result;
    if(result == "AC"){
      if(ac[num-1] == 1){
        continue;
      } else{
          ac[num-1] = 1;
          ac_cnt += 1;
          wa_cnt += wa[num-1];
      }
    } else {
       if(ac[num-1] == 1){
         continue;
       } else {
         wa[num-1] = wa[num-1] +1;
       } 
    }
  }

  cout << ac_cnt << " " << wa_cnt << endl;

}


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

#define MAX_N 100010

int r, c, n;
stack<int> s;
struct point {int id, coor;} p[4][2 * MAX_N];

int boundary(int x, int y)
{
    if (x == 0) return 0;
    else if (y == c) return 1;
    else if (x == r) return 2;
    else if (y == 0) return 3;
    else return -1;
}

bool cmp_inc(point a, point b)
{
    return a.coor < b.coor;
}

bool cmp_dec(point a, point b)
{
    return a.coor > b.coor;
}

int main(void)
{
    scanf("%d%d%d", &r, &c, &n);
    int cnt[4] = {0};
    for (int i = 1; i <= n; i++) {
        int x[2], y[2];
        scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);
        bool is_boundary = true;
        for (int j = 0; j < 2; j++) {
            if (x[j] % r && y[j] % c) is_boundary = false;
        }
        if (is_boundary) {
            for (int j = 0; j < 2; j++) {
                int t = boundary(x[j], y[j]);
                p[t][cnt[t]].id = i;
                p[t][cnt[t]].coor = t % 2? x[j]: y[j];
                cnt[t]++;
            }
        }
    }
    for (int i = 0; i < 4; i++) {
        if (i < 2) sort(p[i], p[i] + cnt[i], cmp_inc);
        else sort(p[i], p[i] + cnt[i], cmp_dec);
        for (int j = 0; j < cnt[i]; j++) {
            if (s.size() && s.top() == p[i][j].id)
                s.pop();
            else
                s.push(p[i][j].id);
        }
    }
    if (s.empty()) printf("YES\n");
    else printf("NO\n");
    return 0;
}

Measured memory_bytes: 5632
package main

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

const (
	MOD = 1000*1000*1000 + 7
	N   = 3*1000*1000*10 + 10
)

func main() {
	in := IOInitialize()
	N := Int(in)
	Arr := IntArray(in, N)

	Alice, Bob := 0, 0
	for i := 0; i < N; i++ {
		big := 0
		index := 0
		for jj := range Arr {
			if big < Arr[jj] {
				big = Arr[jj]
				index = jj
			}
		}
		if i%2 == 0 {
			Alice += big
		} else {
			Bob += big
		}
		Arr = append(Arr[0:index], Arr[index+1:len(Arr)]...)
		big = 0
	}

	fmt.Println(Alice - Bob)
}

//////////
//
//

func IOInitialize() *bufio.Scanner {
	t := bufio.NewScanner(os.Stdin)
	t.Split(bufio.ScanWords)
	return t
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("\t\tThere is a FALSE not to want.")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("\t\tError:Failed to convert text to int,")
	}
	return value
}

func IntArray(s *bufio.Scanner, size int) []int {
	deepArray := make([]int, size)
	for i := range deepArray {
		deepArray[i] = Int(s)
	}
	return deepArray
}

func GraphSetByEdge(s *bufio.Scanner, v int) [][]int {
	g := make([][]int, v)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for xxNonUsedInLoopI := 0; xxNonUsedInLoopI < v-1; xxNonUsedInLoopI++ {
		a, b := Int(s)-1, Int(s)-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	return g
}


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

int main() {

  int n;
  cin >> n;
  
  if (n%1000 == 0) cout << 0 << endl;
  else cout << 1000 - n%1000 << endl;
  
}


Measured memory_bytes: 3620
from collections import deque

def solve(X):
    if X >= 2000:
        return 1

    prices = list(range(100, 106))
    Q = deque([(0, 0)])
    while Q:
        i, pNow = Q.popleft()
        if i == 6:
            if pNow == X:
                return 1
        else:
            price = prices[i]
            for num in range(20):
                p2 = pNow + price*num
                if p2 > X: break
                Q.append((i+1, p2))

    return 0

X = int(input())

print(solve(X))


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

int main() {
	long count_1 = 0, count_0 = 0;
	string s;
	cin >> s;
	char b[100010];
	for (int i = 0; i < s.size(); i++)
	{
		b[i] = s[i];
		if ((i % 2 == 0) && s[i] == '1')
		{
			count_0++;
		}
		else if ((i % 2 == 0) && s[i] == '0')
		{
			count_1++;
		}
		else if ((i % 2 == 1) && s[i] == '1')
		{
			count_1++;
		}
		else if ((i % 2 == 1) && s[i] == '0')
		{
			count_0++;
		}
	}
	cout << min(count_1, count_0);
}

Measured memory_bytes: 512
program sample
    implicit none
  
    integer(8) :: i,j,m,n,x,y
    real(8)::a,b
    
  
    read(*,*) x,y
    m=0
    if (x==1)then
        m=m+300000
        if (y==1)then
            m=m+400000
        end if
    end if
    if (x==2)then
        m=m+200000
    end if
    if (x==3)then
        m=m+100000
    end if
    if (y==1)then
        m=m+300000
    end if
    if (y==2)then
        m=m+200000
    end if
    if (y==3)then
        m=m+100000
    end if
    write(*,*) m
  
    stop
end program sample
  



Measured memory_bytes: 2828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    long long int A, B, V, W, T;
    cin >> A >> V >> B >> W >> T;

    if (W * T + abs(B - A) <= V * T) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
N = int(input())
A = list(map(int,input().split()))
ans = 10**15

for s in [1,-1]:
  cos = 0
  tot = 0
  
  for a in A:
    tot+=a
    if s*tot<=0:
      cos+=abs(tot-s)
      tot=s
    s*=-1
  
  ans=min(ans,cos)

print(ans)


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

int main(){
    string S;
    cin >> S;
    if(S.at(0) == S.at(1) == S.at(2)){
        cout << "No" << endl;
    }
    else if(S == "AAA"){
      cout << "No" << endl;
    }
    else if(S == "BBB"){
      cout << "No" << endl;
    }
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;



int main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	int da = -1, db = -1;
	for (int i = 0; i <= h; i++) {
		for (int j = 0; j <= w; j++) {
			int cnt1 = i * a + (h - i) * (w - a);
			int cnt2 = j * b + (w - j) * (h - b);
			if (cnt1 == cnt2) {
				da = i, db = j;
			}
		}
	}
	if (da == -1) return 0;
	vector <vector <int> > res(h, vector <int> (w, 0));
	vector <pair <int, int> > cnt(w);
	for (int i = 0; i < w; i++) {
		if (i < db) {
			cnt[i] = {b, i};
		} else {
			cnt[i] = {h - b, i};
		}
	}
	for (int i = 0; i < h; i++) {
		int now = 0;
		sort(cnt.rbegin(), cnt.rend());
		int na = (i < da ? a : w - a);
		for (int j = 0; j < na; j++) {
			int jj = cnt[j].second;
			assert(cnt[j].first != 0);
			res[i][jj] = 1;
			cnt[j].first--;
		}
		//assert(now == a);
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << res[i][j];
		}
		cout << "\n";
	}
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define bpc __builtin_popcount
#define MOD (ll)(1e9+7)
#define INF (2e9)
#define EPS (1e-6)
#define NATHANLEE_IS_EVIL_AND_ELECTRIC true
#define int ll
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<"\n";}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif
void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(!NATHANLEE_IS_EVIL_AND_ELECTRIC);
	cin.tie(0);
}

ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll fpow(ll b,ll p){
	b%=MOD;
	ll ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int dp[100010];

int32_t main() {
	INIT();
	//code...
	int n,lim; cin>>n>>lim;
	memset(dp,0,sizeof(dp));
	while(n--){
		int w,v; cin>>w>>v;
		Forr(i,lim,w) dp[i]=max(dp[i],dp[i-w]+v);
	}
	int ans=0;
	For(i,0,lim) ans=max(ans,dp[i]);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 4436
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int M = s.nextInt();
		int X = s.nextInt();
		int[][] A = new int[N][M];
		int[] C = new int[N];
		
		for(int i=0; i<N; i++) {
			C[i] = s.nextInt();
			for(int k=0; k<M; k++) {
				A[i][k] =s.nextInt();
			}
		}
		ArrayList<Integer> sum_Cs = new ArrayList<Integer>();
		for(int i=0; i< 1<<N; i++) {
			int sum_C =0; //探索一回ごとの購入した参考書の金額の総計
			boolean skillcheck = true;
			int[] myP = new int[M]; //得た能力値の総計
			
			for(int j=0; j<N; j++) {
				if((1 & i>>j ) == 1) { //j番目の参考書が条件を満たすのなら、参考書購入
					sum_C += C[j]; //金額を足す
					for(int k=0; k<M; k++) {  //参考書から能力を得る
						myP[k] += A[j][k];
					}
					
				}
			}
			for(int j=0; j<M; j++) { //全ての能力値がXを満たしているか判定
				if(myP[j] <X) {skillcheck = false; break;}
			}
			if(skillcheck) { //全ての能力値を満たしているのでリストに今回の探索の結果得られた金額を追加
				sum_Cs.add(sum_C);
			}
				
		}
		int ans =0;
		if(sum_Cs.size() == 0) {ans =-1;}
		else {
			Collections.sort(sum_Cs);
			ans = sum_Cs.get(0);
		}
		
		System.out.println(ans);
		
		
		
	}

}


Measured memory_bytes: 38264
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int N; cin>>N;
	vector<int> A(N),B(N),C(N);
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	for(int i=0;i<N;i++)cin>>C[i];
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());
	int ans=0,tmp=1;
	for(int i=0;i<N;i++){
		auto ita=lower_bound(A.begin(),A.end(),B[i]);
		auto itc=lower_bound(C.begin(),C.end(),B[i]+1);
		tmp=1;
		tmp*=(C.end()-itc);
		tmp*=ita-A.begin();
		ans+=tmp;
	}
	cout<<ans<<endl;
	return 0;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  
  int n;cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  LL f = 0;
  for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) f += a[i]*a[j];
  cout << f << endl;

  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
 

int main() {
   int n;
   cin >> n;
   cout <<(1+n)*n/2 <<endl;
}

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

int main() {
  int h,w,ch,dh,cw,dw;
  cin>>h>>w>>ch>>cw>>dh>>dw;

  string table[h];
  for(int i=0; i<h; i++) cin>>table[i];

  int dist[h][w];
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(table[i][j]=='.') dist[i][j]=30000000;
      else dist[i][j] = -1;
    }
  }

  using point = tuple<int, int, int>;





  dist[ch-1][cw-1] = 0;
  priority_queue<point, vector<point>, greater<point>> todo;
  for(int i=ch-3; i<=ch+1; i++) {
    for(int j=cw-3; j<=cw+1; j++) {
      if(i<0 || i>=h || j<0 || j>=w || (i==ch-1 && j==cw-1)) continue;

      if(table[i][j]=='.') {
        point add;
        if(abs(ch-1-i)+abs(cw-1-j)==1) {
          dist[i][j] = 0;
          add = make_tuple(0,i,j);
          todo.push(add);
        }
        else {
          dist[i][j] = 1;
          add = make_tuple(1,i,j);
          todo.push(add);
        }
      }
    }
  }

  while(!todo.empty()) {
    point now = todo.top();
    todo.pop();
    int a = get<1>(now);
    int b = get<2>(now);
    for(int i=a-2; i<=a+2; i++) {
      for(int j=b-2; j<=b+2; j++) {
        if(i<0 || i>=h || j<0 || j>=w || (i==a && j==b)) continue;

        if(table[i][j]=='.') {
          point add;
          if(abs(a-i)+abs(b-j)==1) {
            if(dist[i][j]>dist[a][b]) {
              dist[i][j] = dist[a][b];
              add = make_tuple(dist[a][b],i,j);
              todo.push(add);
            }
          }
          else {
            if(dist[i][j]>dist[a][b]+1) {
              dist[i][j] = dist[a][b]+1;
              add = make_tuple(dist[a][b]+1,i,j);
              todo.push(add);
            }
          }
        }
      }
    }
  }

  int ans = dist[dh-1][dw-1];
  if(ans==30000000) ans=-1;

  cout<<ans<<endl;

  // for(int i=0; i<h; i++) {
  //   for(int j=0; j<w; j++) {
  //     cout<<dist[i][j]<<' ';
  //   }
  //   cout<<endl;
  // }


  return 0;
}

Measured memory_bytes: 9428
S = input()
Q = int(input())
is_turned = False
head = []
tail = []
for _ in range(Q):
    tmp = input().split()
    if len(tmp) == 1:
        is_turned = not is_turned
        continue
    f, c = int(tmp[1]), tmp[2]
    # print('f c ', f, c)
    if not is_turned:
        if f == 1:
            head.append(c)
        else:
            tail.append(c)
    else:
        if f == 1:
            tail.append(c)
        else:
            head.append(c)

if not is_turned:
    # S = ''.join(S)
    head = ''.join(reversed(head))
    tail = ''.join(tail)
    ans = head + S + tail
else:
    S = ''.join(reversed(S))
    head = ''.join(head)
    tail = ''.join(reversed(tail))
    ans = tail + S + head
# print('head tail', head, tail, is_turned, S)
print(ans)


Measured memory_bytes: 6272
//************************
//*  Date: 2018.9.1      *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,k,ans=0;
bool isk[200010];

int main()
{
	cin>>n>>k;
	repn(i,n) if(2*i%k==0) isk[i]=true;
	repn(i,n)
	{
		if(!isk[i]) continue;
		LL p=(n-(LL)i)/k+1LL;
		ans+=p*p*p;
		for(int j=i+k;j<=n;j+=k) isk[j]=false;
		//cout<<p*p*p<<endl;
	}
	cout<<ans<<endl;
	rt0;
}    

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
using T=tuple<int,bool,int>;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,m; cin >> n >> m;
	vector<T>x;
	int a,b;
	for(int i=0; i<m; i++){
		cin >> a >> b;
		x.eb(a,0,i); x.eb(b-1,1,i);
	}
	sort(all(x));
	set<int>s;
	vector<bool>vis(m);
	int ans = 0;
	for(int i=0; i<(int)x.size(); i++){
		int cor_x, ind;
		bool c;
		tie(cor_x,c,ind)=x[i];
		if(c){
			if(!vis[ind]){
				for(auto id:s)vis[id]=1;
				ans++;
			}
			s.erase(ind);
		}else{
			s.insert(ind);
		}
	}
	cout << ans << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 5360