akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
 
using namespace std;

vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
#define MOD 1000000007
#define A first
#define B second
#define all(x) (x).begin(), (x).end

typedef long long ll;
 
inline int mulmd(ll a, ll b){
  ll ret = (a * b) % MOD;
  return (int) ret;
}
 
inline int power(ll x, ll y, int m){
  ll res = 1;
  x = x % m;
  while(y > 0){
    if(y & 1){
      res = mulmd(res, x);
    }
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int) res;
}
 
inline int submd(ll a, ll b){
  ll ret = (a - b);
  if(ret < 0) ret += MOD;
  return (int) ret;
}
 
inline int addmd(ll a, ll b){
  ll ret = (a + b) % MOD;
  return (int) ret;
}
 
inline int invPow(ll a){
  return power(a, MOD - 2, MOD);
}
 
inline int divmd(ll a, ll b){
  ll ret = mulmd(a, invPow(b));
  return (int) ret;
}
 
const int N = 1e5 + 5;

int arr[N];

void solve(){
  int n, k;
  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  int s = 0;
  for(int i = 0; i < k; i++){
    s += arr[i];
  }
  cout << s;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll k;
    cin >> k;
    ll digit = 1;
    ll now = 0;
    ll ans = 0;
    for(ll i=1;i<=1e6;i++){
        now += 7 * digit;
        now %= k;
        digit *= 10;
        digit %= k;
        if(now%k==0){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

int main(void){
	int n;
	int i,j;
	vector<int> a;
	int max,min;
	long long sum = 0;

	cin >> n;
	for(i=0;i<n;i++){
		cin >> j;
		sum+=j;
		a.push_back(j);
	}
	max=a.at(max_element(a.begin(),a.end())-a.begin());
	min=a.at(min_element(a.begin(),a.end())-a.begin());

	cout << min << " " << max << " " << sum << endl;
	return 0;
}

Measured memory_bytes: 1324
#include <stdio.h>

int main(void){
    int N;
    double ans = 0;
    scanf("%d", &N);
    for(int i = 0; i < N; i++) {
        double x;
        scanf("%lf", &x);
        char str[3];
        scanf("%s", str);
        ans += str[0] == 'J' ? x : x * 380000;
    }
    printf("%lf", ans);
}


Measured memory_bytes: 384
N, K = map(int, input().split())

def comb(n):
    return (n-1) * (n-2) // 2

def answer(n, k, m):
    o = 1
    while m != 0:
        for i in range(n-o):
            print('{} {}'.format(o, i + o + 1))
            m -= 1
            if m == 0:
                break
        o += 1
    
E = comb(N)
if E < K:
    print(-1)
else:
    M = N - 1 + (E - K) 
    print(M)
    answer(N, K, M)

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

int main(){
	int n;
	cin>>n;
	ll x[n],y[n];
	vector<pair<ll,ll>>pair(n*n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		//p = make_pair(x[i],y[i]);
	}
	ll p,q;
	int ans=51;
	int k=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)continue;
//			pair.push_back(make_pair(x[i]-x[j],y[i]-y[j]));	
			pair[k]= make_pair(x[i]-x[j],y[i]-y[j]);
			k++;
		}
	}
	for(int i=0;i<n*n-n;i++){
		int tmp=n-1;
		p=pair[i].first;
		q=pair[i].second;
		//cout<<"p,q:"<<p<<" "<<q<<endl;
		for(int j=0;j<n*n-n;j++){
			if(i==j)continue;
			//cout<<"pair:"<<pair[j].first<<" "<<pair[j].second<<endl;
			if(p==pair[j].first&&q==pair[j].second){
				tmp--;
			}
		}
		ans = min(ans,tmp);
	}
	if(n==1)ans=1;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000

void Go(map<long long,long long> &mp,long long key,long long value){
	if(mp.count(key))mp[key] = min(mp[key],value);
	else mp[key] = value;
}

int main(){
	
	
	int T;
	cin>>T;
	
	for(int i=0;i<T;i++){
		long long N,A,B,C,D;
		cin>>N>>A>>B>>C>>D;
		long long ans = Inf;
		map<long long,long long> mp;
		mp[N] = 0;
		for(auto a:mp){
			if(a.first!=0&&D+10>(Inf)/a.first)continue;
			ans = min(ans,a.second + D * a.first);
		}
		while(mp.size()!=0){

			map<long long,long long> Nmp;
			for(auto a:mp){
				//cout<<a.first<<','<<a.second<<endl;
				for(int j=-1;j<=1;j++){
					long long t = a.first+j;
					if(t<0)continue;
					if(t%2!=0)continue;
					if(t/2>=a.first)continue;
					Go(Nmp,t/2,a.second + A + D * abs(j));
				}
				
				for(int j=-2;j<=2;j++){
					long long t = a.first+j;
					if(t<0)continue;
					if(t%3!=0)continue;
					if(t/3>=a.first)continue;
					Go(Nmp,t/3,a.second + B + D * abs(j));
				}
				
				for(int j=-4;j<=4;j++){
					long long t = a.first+j;
					if(t<0)continue;
					if(t%5!=0)continue;
					if(t/5>=a.first)continue;
					Go(Nmp,t/5,a.second + C + D * abs(j));
				}
				
			}
			for(auto a:Nmp){
				if(a.first!=0&&D+10>(Inf)/a.first)continue;
				ans = min(ans,a.second + D * a.first);
			}
			Nmp.erase(0);
			mp = Nmp;
			//cout<<endl;
		}
		cout<<ans<<endl;
	}
				
	
	return 0;
}

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

long long f(long long t,long long x){

  if(t==-1){return 0;}
  
  return t/x+1;
  
}

int main(){

  ll a,b,x=0;
  cin>>a>>b>>x;
	

  cout<<f(b,x)-f(a-1,x)<<endl;
  

}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main()
{
	long long int a, b, c, k;
	cin>>a>>b>>c>>k;
	long long int m_sum;
	if(k<=a)
	{
		m_sum=k;
	}
	else if(k>a&&k<=a+b)
        {
               m_sum=a;
        }
else
	{
		m_sum=(2*a)+b-k;
	}
	cout<<m_sum<<endl;
	return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  INT(D);
  INT(G);
  vector<P> A(D);
  REP(i,D) cin >> A[i].first >> A[i].second;

  ll MIN=INF;
  REP(i,1<<D){
    bitset<10> bs(i);
    ll cnt=0;
    ll score=0;
    REP(j,D){
      if(bs[j]==1){
        score+=A[j].second;
        score+=A[j].first*100*(j+1);
        cnt+=A[j].first;
      }
    }

    if(score>G){
      MIN=min(MIN,cnt);
      continue;
    }

    REPR(j,D-1,0){
      if(bs[j]==0){
        ll need=(G-score)/(100*(j+1));
        if((G-score)%(100*(j+1))!=0){
          need++;
        }
        if(need>A[j].first-1){
          score+=(A[j].first-1)*100*(j+1);
          cnt+=A[j].first-1;
        }else{
          cnt+=need;
          score+=need*100*(j+1);
          break;
        }
      }
    }
    if(score<G){
      continue;
    }
    MIN=min(MIN,cnt);
  }
  cout << MIN << endl;
}

Measured memory_bytes: 3640
str = input()
q = int(input())

for i in range(q):
    sc = input().split()
    a = int(sc[1])
    b = int(sc[2])
    if sc[0] == 'replace':
        str = str[:a] + sc[3] + str[b+1:]
    elif sc[0] == 'reverse':
        str = str[:a] + str[b::-1][:b-a+1] + str[b+1:]
    elif sc[0] == 'print':
        print(str[a:b+1])


Measured memory_bytes: 5608
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, a: [f64; n]);

    let aaa = 1e9f64;
    let mut vvv: Vec<Vec<_>> = Vec::new();
    for v in a {
        let buff = (v * aaa + 0.5) as usize;
        vvv.push(count_div2and5(buff));
    }

    let mut gurahu = vec![vec![0isize; 19]; 19];
    for v in &vvv {
        gurahu[v[0]][v[1]] += 1;
    }

    let mut count: isize = 0;
    for i in 0..n {
        for j in 0..19 {
            for k in 0..19 {
                if vvv[i][0] + j >= 18 && vvv[i][1] + k >= 18 {
                    count += gurahu[j][k];
                }
            }
        }
        if vvv[i][0] * 2 >= 18 && vvv[i][1] * 2 >= 18 {
            count -= 1;
        }
    }

    println!("{}", count / 2);
}

fn count_div2and5(target: usize) -> Vec<usize> {
    let mut count2: usize = 0;
    let mut count5: usize = 0;
    let mut buff = target;
    loop {
        if buff % 2 == 0 && count2 != 18 {
            buff /= 2;
            count2 += 1;
        } else {
            break;
        }
    }
    loop {
        if buff % 5 == 0 && count5 != 18 {
            buff /= 5;
            count5 += 1;
        } else {
            break;
        }
    }

    return vec![count2, count5];
}


Measured memory_bytes: 17208
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] Az = new int[N];
        int[] sortedAz = new int[N];
        for (int i = 0; i < N; i++) {
            Az[i] = sc.nextInt();
        }
        Arrays.sort(Az);
        for (int i = N - 1; i >= 0; i--) {
            sortedAz[N - i - 1] = Az[i];
//            System.out.println(sortedAz[N - i - 1]);
        }
        long sum = 0;
        for (int i = 0; i < N - 1; i++) {
            sum += sortedAz[(i + 1) / 2];
        }
        System.out.println(sum);

    }
}


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


int main()
{
	int w, n, A, B;
	int a[30], b[30][2];
	cin >> w >> n;
	for (int i = 0;i < w; i++) {
		a[i] = i + 1;
	}
	for (int j = 0;j < n;j++) {
		scanf("%d,%d", &b[j][0], &b[j][1]);
		A = a[b[j][0]-1], B = a[b[j][1]-1];
		a[b[j][0]-1] = B, a[b[j][1]-1] = A;
	}
	for (int k = 0;k < w;k++) {
		cout << a[k] << endl;
	}

    return 0;
}




Measured memory_bytes: 3164
N = int(input())
A = list(map(int, input().split()))
bottom = sum(A)

if A[0] >= 2:
  print(-1)
  exit()

ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)


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

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int64_t n;
  cin >> n;
  map<int64_t, int> fact;
  for (int64_t i = 2; i*i <= n; i++) {
    while (n%i == 0) {
      ++fact[i];
      n /= i;
    }
  }
  if (n != 1) ++fact[n];
  int ans = 0;
  for (auto& f : fact) {
    int l = 1, r = f.second;
    while (l < r) {
      int mid = (l + r + 1) >> 1;
      if ((mid*(mid+1))/2 <= f.second) l = mid;
      else r = mid-1;
    }
    // cerr << f.first << " " << l << '\n';
    ans += l;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define int long long
#define M 1000000007

double maxvolume(double s)
{
    // finding length
    double length = s / 3;

    s -= length;

    // finding breadth
    double breadth = s / 2;

    // finding height
    double height = s - breadth;

    return length * breadth * height;
}
signed main()
{
    rootdada;
    // #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
    double n;
    cin >> n;
    printf("%0.12f\n", maxvolume(n));
}

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

using namespace std;

struct Node{
 Node *right;
 Node *left;
 Node *parent;
 int key;
public:
 Node(Node *r,Node *l,Node *p,int k) : right(r), left(l), parent(p), key(k){};
};

class Tree{
 Node *root;
public:
 Tree(){root = 0;}
 void insert(int v){
  Node *z = new Node(0,0,0,v);
  Node *y = 0;
  Node *x = root;
  while(x != 0){
   y = x;
   if(z->key < x->key){
    x = x->left;
   }else{
    x = x->right;
   }
  }
  z->parent = y;
  if( y == 0){
   root = z;
  }else if(z->key < y->key){
   y->left = z;
  }else{
   y->right = z;
  }
 } 
 void mainoutput(Tree tree){
  outputInorder(tree.root); cout << endl;
  outputPreorder(tree);
 }
 void outputPreorder(Tree tree){
  stack<Node*> pre;
  pre.push(tree.root);
  while(!pre.empty()){
   Node *buf = pre.top(); pre.pop();
   cout <<" "<< buf->key;
   if(buf->right != 0) pre.push(buf->right);
   if(buf->left != 0) pre.push(buf->left);
  }
  cout << '\n';
 }
 void outputInorder(Node* node){
  if(node->left != 0)
   outputInorder(node->left);
  cout << " " << node->key;

  if(node->right != 0)
   outputInorder(node->right);
 }
};


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

 Tree tree;

 int n = 0;
 cin >> n;

 for(int i=0; i < n; i++){
  string str = "";
  int num = -1;
  cin >> str;
  if(str == "insert"){
   cin >> num;
   tree.insert(num); 
  }else if(str == "print"){
   tree.mainoutput(tree); 
  }
 }

 
 return 0;
}

Measured memory_bytes: 24668
#include<stdio.h>

int main(void){
  int n,k,i,cnt=0;
  scanf("%d %d",&n,&k);
  int num[n];
  
  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
    if(num[i]>=k){
      cnt++;
    }
  }
  printf("%d",cnt);
  
  return 0;
}

Measured memory_bytes: 512
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)


R = ni()
print(float(R)*3.141592653 * 2 )


Measured memory_bytes: 9188
package main
import (
	"bufio"
	"fmt"
	"os"
)
func main(){
	stdin:=bufio.NewReader(os.Stdin)
	cnt:=0
	for i:=1;i!=0; {
		cnt++
		fmt.Fscan(stdin,&i)
		if i!=0{
			fmt.Printf("Case %d: %d\n",cnt,i)
		}
	}
}


Measured memory_bytes: 1392
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    rep(i, x+1){
        int numt = i;
        int numk = x-i;
        
        if(numt*2 + numk*4 == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int cou;
	cou = 0;
	vint load(6);
	vint ans(4);
	ans[0] = 0;
	ans[1] = 0;
	ans[2] = 0;
	ans[3] = 0;
	for (int i = 0; i < 6; i++) cin >> load[i];
	sort(load.begin(), load.end());

	for (int i=0;i<5;i++){
	if (load[i] == load[i + 1])cou++;
		else {
			ans[load[i] - 1] = cou+1;
			
			cou = 0;
		}
	}
	ans[3]=cou+1;
	if (ans[0] < 3 && ans[1] < 3 && ans[2] < 3 && ans[3] < 3)cout << "YES" << endl;
	else cout << "NO" << endl;


}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [h1, m1, h2, m2, k] <- getIntList
  let t1 = h1 * 60 + m1
      t2 = h2 * 60 + m2
      ans = t2 - t1 - k
  print ans


Measured memory_bytes: 3772
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo;}
  else return mpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  ll n,K;cin>>n>>K;
  vector<vector<vector<ll>>> dp;
  if(K%2==1){
    cout<<0<<endl;
    return 0;
  }
  rep(i,51){
    dp.push_back(vector<vector<ll>>());
    rep(j,2500){
      dp[i].push_back(vector<ll>());
      rep(k,51){
        dp[i][j].push_back(0);
      }
    }
  }
  dp[0][0][0] = 1;

  rep(i,n){
    rep(j,n*n){
      rep(k,n+1){
        for(int x=-1; x<=1; x++){
          if(j+k+x >= 0 && j+k+x < 2500 && k+x>=0 && k+x < 51){
            if(x==-1){
              dp[i+1][j+(k+x)][k+x] += dp[i][j][k] * k * k;
            }else if(x==0){
              dp[i+1][j+(k+x)][k+x] += dp[i][j][k] * (k + k + 1);
            }else{
              dp[i+1][j+(k+x)][k+x] += dp[i][j][k];
            }
            
            dp[i+1][j+(k+x)][k+x] %= MOD;
          }
        }
      }
    }
  }

  /*rep(i,n+1){
    cout<<i<<endl;
    rep(j,n*n){
      ll sum = 0;
      rep(k,K){
        sum+=dp[i][j][k];
      }
      cout<<" "<<j<<" "<<sum<<endl;
    }
    cout<<endl;
  }*/
  cout<<dp[n][K/2][0]<<endl;

  return 0;
}


Measured memory_bytes: 69416
#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(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){ 
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a+b) * h /2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define rep(i, n)       reps (i, 0, n)
#define reps(i, m, n)   for  (int i = (int)(m); i < (int)(n); ++i)
#define iter(c)         __typeof((c).begin())
#define foreach(it, c) for (iter(c) it = (c).begin(); it != (c).end(); ++it)

typedef long long ll;

int main()
{
    int n, m, h[1555], w[1555];
    while (cin >> n >> m, n) {
        h[0] = w[0] = 0;
        reps (i, 1, n + 1) cin >> h[i];
        reps (i, 1, m + 1) cin >> w[i];
        reps (i, 1, n + 1) h[i] += h[i-1];
        reps (i, 1, m + 1) w[i] += w[i-1];
        
        map<int, int> table;
        rep (i, n + 1) rep (j, i) ++table[h[i] - h[j]];
        
        ll ans = 0;
        rep (i, m + 1) rep (j, i) ans += table[w[i] - w[j]];
        cout << ans << endl;
    }
}

Measured memory_bytes: 19044
from sys import stdin as st


def main():
    l = [int(e) for e in st.readline().split()]
    if l[0] <= l[2]:
        l[2] -= l[0]
        l[0] = 0
        if l[1]<=l[2]:
            print('0 0')
        else:
            l[1] -= l[2]
            l[2] = 0
            print('%d %d' % (l[0], l[1]))
    else:
        l[0] -= l[2]
        l[2] = 0
        print('%d %d' % (l[0], l[1]))


main()


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

const int N = (1e5) + 5;
const ll OO = LLONG_MAX;
ll interval_l[N], interval_r[N];
int interval_ind[N];
int n;

bool compInd_r(int i, int j) {
  return interval_r[i] < interval_r[j];
}

int activitySelection(int interval_ind[], int n) {
  sort(interval_ind, interval_ind + n, compInd_r);
  int mx = 0;
  ll last_r = -OO;
  for (int i = 0; i < n; ++i) {
    int ind = interval_ind[i];
    if (last_r <= interval_l[ind]) {
      ++mx;
      last_r = interval_r[ind];
    }
  }
  return mx;
}

int main() { // claudio van
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x, l; cin >> x >> l;
    interval_l[i] = x - l;
    interval_r[i] = x + l;
    interval_ind[i] = i;
  }
  cout << activitySelection(interval_ind, n) << "\n";
  return 0;
}

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

unsigned int calculate_cost (const unsigned int* const num_traveler, const unsigned int* const cost_train, const unsigned int* const cost_taxi)
{
	return std::min(*num_traveler * *cost_train, *cost_taxi);
}

int main (void)
{
	// variables for main process
	unsigned int N, A, B;

	// STEP.01
	// read out the given data
	std::cin >> N >> A >> B;

	// STEP.02
	// output the answer of this task
	std::cout << calculate_cost (&N, &A, &B) << std::endl;

	// STEP.END
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	deque<int> a(n);
	rep(i,n){
		cin>>a[i];
	}
	vector<vector<ll>> dp(n,vector<ll>(n,inf));
	function<ll(int,int)> dfs=[&](int l,int r){
		if(dp[l][r]!=inf) return dp[l][r];
		if(l==r){
			if((n-1)%2==0) return dp[l][r]=a[l];
			else return dp[l][r]=-a[l];
		}
		ll ret;
		if((n-1)%2==(r-l)%2){
			ret=max(dfs(l+1,r)+a[l],dfs(l,r-1)+a[r]);
		}else{
			ret=min(dfs(l+1,r)-a[l],dfs(l,r-1)-a[r]);
		}
		return dp[l][r]=ret;
	};
	cout<<dfs(0,n-1)<<endl;
}

Measured memory_bytes: 71040
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[222222];
signed main(){
	ic(n)
	int sum=0;
	rep(0,i,n){
		cin>>a[i];
		sum+=a[i];
	}
	int sum1=0,sum2=0;
	int ans1=sum,ans2=sum;
	rep(0,i,n){
		sum1+=a[i];
		if(sum1*2<=sum&&sum-sum1*2<ans1){
			ans1=sum-sum1*2;
		}
	}
	for(int i=n-1;i>=0;i-=1){
		sum2+=a[i];
		if(sum2*2<=sum&&sum-sum2*2<ans2){
			ans2=sum-sum2*2;
		}
	}
	c(min(ans1,ans2))
}	

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

using namespace std;
const int N = 1000010;
int _w;

int C( int n, int m ) {
	return (n|m) == n;
}

int n, a[N], cnt[3];
char s[N];

int main() {
	cin >> n;
	cin >> (s+1);
	for( int i = 1; i <= n; ++i ) {
		a[i] = s[i] - '0' - 1;
		++cnt[a[i]];
	}
	if( cnt[1] == 0 ) {
		for( int i = 1; i <= n; ++i )
			if( a[i] == 2 )
				a[i] = 1;
	} else {
		for( int i = 1; i <= n; ++i )
			if( a[i] == 2 )
				a[i] = 0;
	}
	int ans = 0;
	for( int i = 1; i <= n; ++i )
		ans = (ans + a[i] * C(n-1, i-1)) & 1;
	if( cnt[1] == 0 ) ans *= 2;
	printf( "%d\n", ans );
	return 0;
}


Measured memory_bytes: 8632
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){

  /*while(u != NIL && k != u->key){
    if(k < u->key){
      u = u->left;
    }else{
      u = u->right;
    }
  }
  return u;*/

  while(u != NIL){
    if(u->key == k){
      return u;
    }else if(u->key > k){
      u = u->left;
    }else{
      u = u->right;
    }
  }
    return NIL;
}

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

  z = malloc(sizeof(struct 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);
  printf(" %d",u->key);
  inorder(u->right);

}
void preorder(Node u){

  if(u == NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
   if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
  }

  }
  return 0;
}




Measured memory_bytes: 20456
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	long long n, k, s;
	bool z;
	s = 0;
	scanf("%lld", &n);
	k = n;
	
	while(n!=0){
		s += (n%10);
		n = n / 10;
	}
	if (k%s == 0)z = true;
	else z = false;

	if (z)printf("Yes\n");
	else printf("No\n");

	return 0;
}


Measured memory_bytes: 128
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for(int i = 0 ; i < n ; i ++){
          array[i] = sc.nextInt();
        }
      	Arrays.sort(array);
        int a = 0 ;
        int b = 0 ;
      	
      	for(int i = 1 ; i <= n ; i ++){
          if(i % 2 != 0){
          	a += array[n-i];
          }else{
          	b += array[n-i];
          }
        }
       System.out.print(a-b);
      
    }
}




Measured memory_bytes: 36036
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#define MOD1 1e9 + 7
#define MOD2 1e9 + 9
#define inf  (int)2e9
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
 
 
 
using namespace std;
 
 
typedef long long ll;
 
int main() {
 
    int n;
    bool OK = true;
    string s;
    cin >> s;
    n = s.length();
    int end1 = (n / 2) - 1;
    int start1 = 0;
    int start2 = (n / 2) + 1;
    int end2 = n - 1;
    while (1) {
        if (n % 2 == 0) {
            OK = false;
            break;
        }
        if (s[end1] != s[start1]) {
            OK = false;
            break;
        }
        if (s[end2] != s[start2]) {
            OK = false;
            break;
        }
        start1++;
        start2++;
        end1--;
        end2--;
        if (start1 >= end1 || start2 >= end2) break;
    }
    if (OK) {
        int i = 0;
        int j = n - 1;
        while(1) {
            if (s[i] != s[j]) {
                OK = false;
                break;
            }
            if (i >= j) break;
            i++;
            j--;
        }
        if(OK) {
            printf("Yes\n");
        }
        else printf("No\n");
    }
    
    //if (OK) printf("Yes\n");
    else printf("No\n");
    return 0;
 
 
}

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

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, ll> mp;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mp[a[i]]++;
  }
  ll sum = 0;
  map<int, pair<ll, ll> > mp2;
  for (auto &e: mp) {
    ll one = max(e.second * (e.second - 1) / 2, 0LL);
    ll two = max((e.second - 1) * (e.second - 2) / 2, 0LL);
    mp2[e.first].first = one;
    mp2[e.first].second = two;
    sum += one;
  }

  for (int i = 0; i < n; ++i) {
    ll ans = sum - mp2[a[i]].first + mp2[a[i]].second;
    cout << ans << '\n';
  }
  return 0;
}



Measured memory_bytes: 18176
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define pb push_back
using namespace std;

int na[111111];
int use[111111];
int main(void){
  int i,n,x;
  int m;
  int res;
  vector<int> a;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>x;
    a.pb(x);
    na[x]++;
  }
  sort(a.begin(),a.end());
  res=m=0;
  for(i=0;i<n;i++){

    if(use[a[i]]!=1){

      use[a[i]]=1;
      na[a[i]]=na[a[i]]%2==1?1:2;
      if(na[a[i]]==1) res++;
      if(na[a[i]]==2){
        res++;
        m++;
      }
    }
  }

  if(m%2==1) res--;
  cout<<res<<endl;
  return 0;
}

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

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

  int tmp = 0;
  int sum = 0;
  for(int i = 0; i < M; i++) {
    cin >> tmp;
    sum += tmp;
  }

  if(N >= sum) {
    cout << N - sum << endl;
  }
  else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3196
//==========================================c#
/* ===========================================
// null
// 
// 
=========================================== */
using System; //Console, IComparable
using System.IO; //StreamWriter 
using System.Linq; //Select(), Where(), OrderBy(), Count()
using System.Collections.Generic; //List<T>

class Program { 
    static void Main() { 
        StreamWriter so = new StreamWriter(Console.OpenStandardOutput());
        IOC io = new IOC();
        
        int n = io._int;
        var hash = new Dictionary<string, int>();
        
        for (int i = 0; i < n; i++){
            var s = io._string;
            if (!hash.ContainsKey(s)){
                hash.Add(s, 1);
            }
            else{
                hash[s]++;
            }
        }
        
        var max_cnt = hash.Values.Max();
        
        var ans = new List<string>();
        foreach(var fd in hash){
            if (fd.Value == max_cnt){
                ans.Add(fd.Key);
            }
        }
        
        ans.Sort(StringComparer.Ordinal);
        
        foreach(var fd in ans){
            so.WriteLine(fd);
        }
        so.Close();
    } 
}

public class IOC{
    public int _int{get{return int.Parse(Console.ReadLine());}}
    public int[] _inta{get{return Array.ConvertAll(Console.ReadLine().Split(), int.Parse);}}
    public long _long{get{return long.Parse(Console.ReadLine());}}
    public long[] _longa{get{return Array.ConvertAll(Console.ReadLine().Split(), long.Parse);}}
    public string _string{get{return Console.ReadLine();}}
    public string[] _stringa{get{return (Console.ReadLine().Split());}}
    public double _double{get{return double.Parse(Console.ReadLine());}}
    public double[] _doublea{get{return Array.ConvertAll(Console.ReadLine().Split(), double.Parse);}}
}

/* ===========================================
            int n = int.Parse(Console.ReadLine());

for(int i = 0; i < n; i++){
                int sum = Console.ReadLine().Split().Select(int.Parse).Sum();
                so.WriteLine(sum.ToString());
            }
            so.Close();
=========================================== */



Measured memory_bytes: 41436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define mod (1000000007)

void solve() 
{
    int n;cin>>n;
    int a[n],b[n],c[n+1],d[n+1];
    REP(i,n)cin>>a[i];REP(i,n)cin>>b[i];
    REP(i,n+1)c[i]=d[i]=0;
    REP(i,n)c[a[i]]++,d[b[i]]++;
    REP(i,n+1)if(c[i]+d[i]>n){cout<<"No"<<endl;return;}
    cout<<"Yes"<<endl;
    rep(i,1,n+1)c[i]+=c[i-1],d[i]+=d[i-1];
    int x=0;rep(i,1,n+1)x=max(x,c[i]-d[i-1]);
    REP(i,n)cout<<(i?" ":"")<<b[(i+n-x)%n];cout<<endl;
}

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

Measured memory_bytes: 6748
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s;
	int a;
	int b;
	int c;
	a=(getchar());
	b=(getchar());
	c=(getchar());
	if(a!=b&&b!=c&&a!=c)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
} 

Measured memory_bytes: 256
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		boolean[] isuruu=new boolean[3000];
		for(int i=0;i<3000;i++){
			isuruu[i]=i%400==0 || (i%100!=0 && i%4==0);
		}
		boolean isFirst=true;
		while(true){
			int a=sc.nextInt(),b=sc.nextInt();
			if(a==0 && b==0)break;

			if(!isFirst)ln();

			boolean isset=false;
			for(int y=a;y<=b;y++){
				if(isuruu[y]){
					ln(y);
					isset=true;
				}
			}
			if(!isset)ln("NA");
			isFirst=false;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
N = int(input())
S_list = []
for _ in range(N):
    S_list.append(input())
M = int(input())
T_list = []
for _ in range(M):
    T_list.append(input())

dict_ = {0: 0}
for s in S_list:
    if s not in dict_.keys():
        dict_[s] = 1
    else:
        dict_[s] += 1
for t in T_list:
    if t not in dict_.keys():
        dict_[t] = -1
    else:
        dict_[t] -= 1

print(max(dict_.values()))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    //--<for debugging>
    #define whatis(x) cout << #x << " is " << x<<" ";
    #define whatisl(x) cout << #x << " is " << x<<"\n";
    #define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
    #define lline cout<<"\n";
    #define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
    #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"___";}
        
    void err(istream_iterator<string> it) {}
    template<typename T, typename... Args>
    void err(istream_iterator<string> it, T a, Args... args) {
        cout << *it << " = " << a <<" , ";
        err(++it, args...);
    }
    //--</for debugging> 
    #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
    #define testcase ll tt; cin >> tt; while(tt--)
    #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
    #define pb push_back 
    #define vars ll h,i,j,k,d,l,p,q,r,x,y,a,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;string str;
    #define vll vector<ll>
    #define pll pair<ll,ll>
    #define sll set<ll>
    #define pint pair<int,int>
    const ll INF=1e9+7;
    const ll MOD=1e9+7;
    const string yes="YES\n";
    const string no="NO\n";
    int main()
    {
        boost vars
        //freopen("input.txt","r",stdin);
        //freopen("input.txt","w",stdout);
        cin>>n;
        ll arr[n],pre[n+1]={0};
        pre[0]=0;
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
            pre[i+1]=arr[i]+pre[i];
        }
        ans=0;
        for(i=0;i<n;i++)
        {
            var=(pre[n]-pre[i+1])%MOD;
            ans=(ans+(arr[i]*var)%MOD)%MOD;
        }
        cout<<ans;
        
    }

Measured memory_bytes: 6780
#include <stdio.h>
int main(void)
{
	int H;
	int W;
	int i, j,k=1;

	while (1) {
		scanf("%d", &H);
		scanf("%d", &W);

		if (H == 0 && W == 0) {
			break;
		}
		k = 1;
		for (i = 0; i < H; i++) {
			if (k % 2 == 1) {
				for(j = 0; j < W; j++) {
					if (j % 2 == 0) {
						printf("#");
					}
					else {
						printf(".");
					}
				}
				printf("\n");
				k++;
			}
			else {
				for (j = 0; j < W; j++) {
					if (j % 2 == 0) {
						printf(".");
					}
					else {
						printf("#");
					}
				}
				printf("\n");
				k++;
			}
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 400005
#define ll long long
void Read(int &p)
{
	p = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
}
int n, A[N], nex[N], lst[N];
int top, ins[N], stk[N], vis[N];
ll k, sum[N];
int main()
{
	scanf("%d%lld", &n, &k);
	for (int i = 1; i <= n; i++)
		Read(A[i]), A[i + n] = A[i];
	for (int i = 2 * n; i >= 1; i--)
	{
		if (i <= n)
			nex[i] = lst[A[i]] - i + 1;
		lst[A[i]] = i;
	}
	int now = 1;
	ll m = n * k, cyc;
	for (; ; )
	{
		if (vis[now])
		{
			cyc = sum[now] - m;
			break;
		}
		vis[now] = 1;
		sum[now] = m;
		if (m <= nex[now])
		{
			for (int i = now; i < now + m; i++)
			{
				int v = A[(i - 1) % n + 1];
				if (ins[v])
				{
					while (top && ins[v])
						ins[stk[top--]] = 0;
				}
				else
				{
					stk[++top] = v;
					ins[v] = 1;
				}
			}
			for (int i = 1; i <= top; i++)
				printf("%d%c", stk[i], i == top ? 10 : 32);
			return 0;
		}
		m -= nex[now];
		now = (now + nex[now]) % n;
		if (!now)now = n;
	}
	m %= cyc;
	for (; ; )
	{
		if (m <= nex[now])
		{
			for (int i = now; i < now + m; i++)
			{
				int v = A[(i - 1) % n + 1];
				if (ins[v])
				{
					while (top && ins[v])
						ins[stk[top--]] = 0;
				}
				else
				{
					stk[++top] = v;
					ins[v] = 1;
				}
			}
			for (int i = 1; i <= top; i++)
				printf("%d%c", stk[i], i == top ? 10 : 32);
			return 0;
		}
		m -= nex[now];
		now = (now + nex[now]) % n;
		if (!now)now = n;
	}
}


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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
  vector<int> x, y;
  REP(i, 31) {
    REP(j, 31) {
      if(a * i + b * j > f) break;
      x.pb(100 * (a*i + b*j));
    }
  }

  REP(i, 3001) {
    REP(j, 3001) {
      if(c * i + d * j > f) break;
      y.pb(c*i + d*j);
    }
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  int t1 = 0, t2 = 100*a;
  int m = 100*a, msu = 0;
  
  REP(i, x.size()) {
    REP(j, y.size()) {
      if(x[i] + y[j] > f) break;
      if(e * x[i] - 100 * y[j] < 0) break;
      if(t2 * y[j] - t1 * x[i] > 0) {
        t1 = y[j];
        t2 = x[i];
        m = x[i] + y[j];
        msu = y[j];
      }
    }
  }

  cout << m << " " << msu << endl;
}


Measured memory_bytes: 2432
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,W = inputMap()
    N = inputInt()
    A = inputList()
    
    ans = []
    retu = 0
    tmp = []
    for i, val in enumerate(A):
        for j in range(val):
            tmp.append(i+1)
            if len(tmp) == W:
                if retu == 0:
                    ans.append(tmp)
                    tmp = []
                    retu += 1
                elif retu % 2 == 1:
                    ans.append(reversed(tmp))
                    tmp = []
                    retu += 1
                elif retu % 2 == 0:
                    ans.append(tmp)
                    tmp = []
                    retu += 1
                    
    for i, val in enumerate(ans):
        print(*val)
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 42864
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef pair<double, ll> pdl;

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready, resolve
    int N,M;
    cin >> N >> M;
    ll dp[(int)pow(2,N)];
    for(int i=0; i < (int)pow(2,N); i++) dp[i] = -1;
    dp[0] = 0;
    for (int i=0; i<M; i++) {
        ll a;
        int b;
        cin >> a >> b;
        int kbit = 0;
        for (int j=0; j<b; j++) {
            int k;
            cin >> k;
            k--;
            kbit = kbit | 1 << k;
        }

        for (int j = 0; j< (int)pow(2,N); j++) {
            if (dp[j] != -1) {
                if (dp[j|kbit] == -1) dp[j|kbit] = dp[j] + a;
                else dp[j|kbit] = min(dp[j|kbit], dp[j] + a);
            }
        }
    }

    cout << dp[(int)pow(2,N)-1];

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<ll> A;
  REP(i, N) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  sort(all(A));
  reverse(all(A));
  ll width = 0, length = 0;
  REP(i, N - 1) {
    if (A[i] == A[i + 1]) {
      if (width) {
        length = A[i];
        break;
      } else
        width = A[i];
      if (i == N - 1) break;
      i += 1;
    }
  }

  cout << width * length << endl;
  return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;

    int m = n + 1;
    vector<int> bad(m) , heroes(n);
    for (int i = 0 ;i < m ;i++)
        cin >> bad[i];

    long long ans = 0;
    for (int i = 0 ;i < n ;i++) {
        cin >> heroes[i];
        if (heroes[i] <= bad[i])
            ans += heroes[i];
        else {
            ans += bad[i];
            heroes[i] -= bad[i];
            ans += min(heroes[i] , bad[i + 1]);
            bad[i + 1] -= min(heroes[i] , bad[i + 1]);
        }
    }

    cout << ans;
}


Measured memory_bytes: 3964