akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,x,y,z,k,m,n,l,q,h,w,ans=0;
vl v,v1;
ll dp[200001];
vp p,p1;
string s;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
   cin>>s;
   n=s.length();
   a=1;
   v1.push_back(1);
   rep(i,n){
       v1.push_back((v1.back()*3)%MOD);
   }
   rep(i,n){
       if(s[i]=='1'){
           ans+=(a*v1[n-i-1])%MOD;
       }
       if(s[i]=='1'){
           a=(a*2)%MOD;
       }
   }

   cout<<(ans+a)%MOD<<endl;
}

Measured memory_bytes: 1480
import java.util.*;

public class Main {

    public static List<List<Integer>> switchList;

    public static void main(String[] args) {
        switchList = new ArrayList<>();

        for (List<Integer> list : switchList) {
            for (int i : list) {
                System.out.print(i + " ");
            }
            System.out.println();
        }

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        getAllpatterns(N, new ArrayList<>(), 0);

        Map<Integer, List<Integer>> lampMap = new HashMap<>();
        Map<Integer, Integer> conditionMap = new HashMap<>();
        for (int i = 1; i <= M; i++) {
            int k = sc.nextInt();
            List<Integer> switchList = new ArrayList<>();
            for (int j = 0; j < k; j++) {
                int s = sc.nextInt();
                switchList.add(s);
            }
            lampMap.put(i, switchList);
        }

        for (int i = 1; i <= M; i++) {
            conditionMap.put(i, sc.nextInt());
        }
        sc.close();

        int count = 0;
        for (List<Integer> conditions : switchList) {
            boolean isOk = true;
            for (int lamp : lampMap.keySet()) {
                List<Integer> sws = lampMap.get(lamp);
                int onCount = 0;
                for (int switchNo : sws) {
                    if (conditions.get(switchNo - 1) == 1) {
                        onCount++;
                    }
                }
                if (onCount % 2 != conditionMap.get(lamp)) {
                    isOk = false;
                    break;
                }
            }
            if (isOk) {
                count++;
            } else {
                continue;
            }
        }

        System.out.println(count);
    }

    public static void getAllpatterns(int N, List<Integer> switches, int cnt) {
        if (cnt >= N) {
            List<Integer> copy = new ArrayList<>(switches);
            switchList.add(copy);
            return;
        }
        switches.add(0);
        getAllpatterns(N, switches, cnt + 1);
        switches.remove(switches.size() - 1);
        switches.add(1);
        getAllpatterns(N, switches, cnt + 1);
        switches.remove(switches.size() - 1);
    }
}


Measured memory_bytes: 23892
#include<stdio.h>
int main()
{
  int N;
  scanf("%d", &N);
  if ( ( N - 7 ) % 10 == 0 ) {
    printf( "Yes" );
  }
  else if ( N % 100 >= 70 && N % 100 < 80 ) {
    printf( "Yes" );
  }
  else if ( N - 700 >= 0 && N - 700 < 100 ) {
    printf( "Yes" );
  }
  else {
    printf( "No" );
  }
  return 0;
}


Measured memory_bytes: 1720
rot = int(input())
strlist = list(input())

def shift(char, rot):
  str = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
         "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
         "W", "X", "Y", "Z"]
  index = str.index(char)
  index = (index + rot) % 26
  return str[index]

ret = []
for c in strlist:
  ret.append(shift(c, rot))
 
print("".join(ret))

Measured memory_bytes: 3188
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	while (cin >> n&&n) {
		int g[15][15];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> g[i][j];
			}
		}
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += g[i][j];
			}
			g[i][n] = sum;
		}
		for (int j = 0; j < n; j++) {
			int sum = 0;
			for (int i = 0; i < n; i++) {
				sum += g[i][j];
			}
			g[n][j] = sum;
		}
		int ssum = 0;
		for (int i = 0; i < n; i++) {
			ssum += g[i][n];
		}
		g[n][n] = ssum;
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				if (g[i][j] < 10)cout << "    " << g[i][j];
				else if (g[i][j] < 100)cout << "   " << g[i][j];
				else if (g[i][j] < 1000)cout << "  " << g[i][j];
				else if (g[i][j] < 10000)cout << " " << g[i][j];
				else cout << g[i][j];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 3068
#include <iostream>
#include <cstdlib>
#include <queue>
using namespace std;

struct Process {
    string name;
    int time;
};

/* ALDS1_3_B: Queue */
int main() {
    int n, quantum;
    cin >> n >> quantum;

    queue<Process*> pqueue;
    Process *ps;

    for (int i = 0; i < n; i++) {
        ps = new Process();
        cin >> ps->name >> ps->time;
        pqueue.push(ps);
    }

    int elapsed = 0;
    while(! pqueue.empty() ) {
        ps = pqueue.front();
        pqueue.pop();

        if (quantum < ps->time) {
            elapsed += quantum;
            ps->time -= quantum;
            pqueue.push(ps);
        } else {
            elapsed += ps->time;
            cout << ps->name << " " << elapsed << endl;
        }
    }
    free(ps);

    return 0;
}

Measured memory_bytes: 5548
fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<usize>();
    let vb = read_vec::<usize>();

    let mut ret = 0;
    for i in 0..n {
        let mut b = vb[i];

        if a[i] < b {
            let tmp = a[i];
            ret += tmp;
            a[i] = 0;
            b -= tmp;
        } else {
            a[i] -= b;
            ret += b;
            b = 0;
        }

        if b == 0 { continue; }

        if a[i+1] < b {
            let tmp = a[i+1];
            ret += tmp;
            a[i+1] = 0;
            b -= tmp;
        } else {
            a[i+1] -= b;
            ret += b;
            b = 0;
        }
    }

    println!("{}", ret);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

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

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

vector<int> price;

int main(){
	int n,m;
	int ans;
	int i;
	while( cin >> n >> m )
	{
		if( n == 0 && m == 0 )
			break;
		ans = 0;
		price.resize( n );
		for( i = 0;i < n;i++ ){
			cin >> price[i];
			ans += price[i];
		}

		sort( price.begin(),price.end(),greater<int>() );

		for( i = 0;i < n;i++ ){
			if( i%m < m-1 )
				continue;
			ans -= price[i];
		}
		cout << ans << endl;

		price.clear();
	}
	return 0;
}

Measured memory_bytes: 1224
// Crt. 2019-12-17  08:10:43
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;

ll n;
int cl[200], cr[200], lc, rc;

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n, ++n;

    int cnt = 101;
    while (n > 1) {
        if (n & 1) cl[++lc] = --cnt, --n;
        else cr[++rc] = --cnt, n >>= 1;
    }

    cout << 202 - 2 * cnt << endl;

    for (int i = 1; i <= lc; ++i)
        cout << cl[i] << " ";
    for (int i = rc; i >= 1; --i)
        cout << cr[i] << " ";
    for (int i = cnt; i <= 100; ++i)
        cout << i << " ";

    return 0;
}


Measured memory_bytes: 256
//atcoder B 101
#include<stdio.h>
int main(void)
{
	int n,m,x=0;
	scanf("%d",&m);
	n=m;
	while(n>0){
		x+=n%10;
		n/=10;
	}
	if(m%x==0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(100000)
INF = float('inf')

N = int(sys.stdin.readline())
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(N - 1)]
Q, K = list(map(int, sys.stdin.readline().split()))
X, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(Q)]))

#: :type: list of (list of (int, int))
graph = [[] for _ in range(N + 1)]
for a, b, c in ABC:
    graph[a].append((b, c))
    graph[b].append((a, c))

stack = [(K, 0)]
dists = {K: 0}
while stack:
    v, vw = stack.pop()
    for u, w in graph[v]:
        if u not in dists:
            dists[u] = vw + w
            stack.append((u, vw + w))

for x, y in zip(X, Y):
    print(int(dists[x] + dists[y]))


Measured memory_bytes: 86740
fun main(args: Array<String>) {
    val (n, p) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!.reversed()

    val ans = if (10 % p == 0) {
        (0 until n)
                .filter { (s[it] - '0') % p == 0 }
                .map { 0L + n - it }
                .sum()
    } else {
        val d = IntArray(n + 1)
        var b = 1
        for (i in 0 until n) {
            val x = (s[i] - '0') * b % p
            d[i + 1] = (d[i] + x) % p
            b = b * 10 % p
        }

        val cnt = IntArray(p)
        (0..n).map { 0L + cnt[d[it]]++ }.sum()
    }

    println(ans)
}


Measured memory_bytes: 52200
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>
#include <queue>

using namespace std;
typedef long long int ll;

int main(){

    ll N;
    cin >> N;
    vector<ll > H(N, 0);
    for(ll i = 0; i < N; i++){
        cin >> H[i];  
    }

    ll ans = 0;    
    
    for(;;){
        ll i = 0;
        ll max = *std::max_element(H.begin(), H.end());
        if(max == 0) break;

        while(i < N){
            if(H[i] == 0){
                i++;
                continue;
            }else{
                ans++;
                while(i < N && H[i] > 0){
                    H[i]--;
                    i++;
                }
            }
        }

    }

    cout << ans << endl;


} 

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


#define mx 100005
#define ll long long 

void IO()
{
  #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
  #endif
}


int ar[mx];
char ch[mx];
int m,n,k,ii;

void solve()
{
   ll x;
   cin>>x;
   int re=0;
   for(int i=1;i<=x;i++)
   {
      for(int j=1;;j++)
      {
        if(i*j>=x)break;
        // if(i!=j)re+=2;
        // else re++;
        re++;
      }
   }
   cout<<re<<endl;
}

int main()
{
   IO();
  int t=1;
 // scanf("%d",&t);
  while(t--)
  {
    solve();
  }
  return 0;
}

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

deque<int> ans;
int m;

void DFS(long long n) {
    if (n == 1) return ;
    if (n & 1) {
        DFS(n-1);
        ans.push_front(++m);
    } else {
        DFS(n>>1);
        ans.push_back(++m);
    }
}

int main() {
    long long n;
    scanf("%lld", &n);
    m = 0;
    DFS(n+1);
    printf("%d\n", m*2);
    for (int x: ans) {
        printf("%d ", x);
    }
    for (int i=1; i<=m; ++i) {
        printf("%d%c", i, i==m ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,B,C;
	while(cin>>A>>B>>C) {
		ll ans = 0;
		while(A<=B) {
			B-=A;
			ans++;
		}
		
		cout<<min(C, ans)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
/// BISMILLAH
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(void){
    int n, val;
    cin >> n;
    val = 1000;
    int fin, temp, r;

    if(!(n % val))
        fin = 0;
    else{
        temp = n % val;
        fin = val - temp;
    }

    cout << fin << "\n"; 

    return 0;
}


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

int main( ){
  int i,n;
  int Fib[45];
  scanf("%d",&n);
  Fib[0] =Fib[1]=1;
  
  for(i=2;i<=n;i++){
    Fib[i]= Fib[i-1]+Fib[i-2];
  }
  
  printf("%d\n",Fib[n]);
  return 0;
}



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

using namespace std;

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

ll gcd(ll x, ll y){
	if (x < y){
		swap(x,y);
	} // end if

	while(y > 0LL){
		ll r = x % y;
		x = y;
		y = r;
	} // end while
	
	return x;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	vector<ll> T(N, 0LL);
	rep (i, N) cin >> T[i];

	ll ans = 1LL;
	ll curr = ans;
	rep (i, N){
		ll g = gcd(curr,T[i]);
		ans = T[i] / g * curr;
		curr = ans;
	} // end rep

	cout << ans << endl; 

	return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;



int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)   cin >> a[i];



    vector<int> r(n, 0);
    rep(i, n){
        if((a[i]-1)%2 == 0) r[i]++;
        if((a[i]  )%2 == 0) r[i]++;
        if((a[i]+1)%2 == 0) r[i]++;
    }

    ll res = 1;
    rep(i, n)   res *= (3 - r[i]);

    cout << pow(3, n) - res << endl;

    return 0;
}

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

using namespace std;

template <long long Mod> struct ModInt { /* {{{ */
  long long v;
  constexpr ModInt(const long long x = 0) {
    v = x % Mod;
    if (v < 0) {
      v += Mod;
    }
  }
  constexpr ModInt operator+(const ModInt rhs) const {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const {
    return ModInt(*this) /= rhs;
  }
  const ModInt &operator+=(const ModInt rhs) {
    v += rhs.v;
    if (v >= Mod) {
      v -= Mod;
    }
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) {
    if (v < rhs.v) {
      v += Mod;
    }
    v -= rhs.v;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) {
    v = v * rhs.v % Mod;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) {
    long long exp = Mod - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  friend ostream &operator<<(ostream &s, ModInt<Mod> m) {
    s << m.v;
    return s;
  }
  friend istream &operator>>(istream &s, ModInt<Mod> m) {
    s >> m.v;
    return s;
  }
}; /* }}} */

const int mod = 1e9 + 7;
using modint = ModInt<mod>;

int main() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  modint fact[2000005];
  fact[0] = 1;
  for (int i = 1; i < 2000005; i++) {
    fact[i] = fact[i - 1] * i;
  }
  auto count = [&](int r, int c) -> modint {
    r++;
    c++;
    return fact[r + c] / fact[r] / fact[c];
  };
  modint ans = count(r2, c2) - count(r2, c1 - 1) - count(r1 - 1, c2) +
               count(r1 - 1, c1 - 1);
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 15872
s=input()
if int(s[:4])<2019:
    print("Heisei")
    print("3")
elif int(s[:4])>2019:
    print("TBD")
elif int(s[5])==1 or int(s[6])>4:
    print("TBD")
else:
    print("Heisei")

Measured memory_bytes: 3060
#include <stdio.h>

int main() 
{
    int a,n,b,c;
    
    c=0;
    scanf("%d %d %d",&n,&a,&b);
    c=n*a;
    if(c<=b)
    {
        printf("%d",c);
    }else printf("%d",b);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

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

	if (((N / 2) >= K) || ((N + 1) / 2 >= K)) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;
vector<long> memo;
vector<int> vc;
int dp(int num)
{
    if(memo[num] != -1) return memo[num];
    else{
        memo[num] =  min(dp(num-1)+abs(vc[num]-vc[num-1]),dp(num-2)+abs(vc[num]-vc[num-2]));
        return memo[num];
    }
}


int main()
{
    int N;
    cin >> N;
   
    int temp;
    
    for (int i = 0; i < N; i++)
    {
        cin >> temp;
        vc.push_back(temp);
        memo.push_back(-1);
    }
    
    memo[0]=0;
    memo[1] = abs(vc[0]-vc[1]);

    cout << dp(N-1) << endl;
    
}

Measured memory_bytes: 3952
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m;
  cin>>n>>m;
  vll s(n),t(m);
  rep(i,n) cin>>s[i];
  rep(i,m)cin>>t[i];
  vvll dp(n+1,vll(m+1));
  rep(i,n)rep(j,m){
    if(s[i]==t[j]){
      dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j])+dp[i][j]+1;
      dp[i+1][j+1]%=MOD;
    }
    else{
      dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j];
      dp[i+1][j+1]%=MOD;
    }
  }
  dp[n][m]++;
  if(dp[n][m]<0) dp[n][m]+=MOD;
  COUT(dp[n][m]);
}


Measured memory_bytes: 34676
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int N = Integer.parseInt(s[0]);
			int M = Integer.parseInt(s[1]);
			int[] road = new int[N];
			Arrays.fill(road, 0);
			for(int i = 0; i < M;i++) {
				str = br.readLine();
				s = str.split(" ",0);
				int a = Integer.parseInt(s[0]);
				int b = Integer.parseInt(s[1]);
				road[a-1]++;
				road[b-1]++;
			}

			for(int i = 0; i < N;i++) {
				System.out.println(road[i]);
			}
//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}
}


Measured memory_bytes: 21076
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long int ll;

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  int flag = 0;
  string top = "", bottom = "";
  rep (i, q) {
    int t;
    cin >> t;
    if (t == 1) { // 反転
      if (flag) flag = 0;
      else flag = 1;
    } else { // 追加
      int f;
      char c;
      scanf("%d %c", &f, &c);
      f -= flag;
      if (f == 1) { // 先頭
        top = c + top;
        // s = c + s;
      } else { // 末尾
        bottom += c;
        // s += c;
      }
    }
  }
  if (flag) {
    reverse(s.begin(), s.end());
    reverse(top.begin(), top.end());
    reverse(bottom.begin(), bottom.end());
    cout << bottom << s << top << endl;
  } else {
    cout << top << s << bottom << endl;
  }

  return 0;
}

Measured memory_bytes: 1104
N,K = list(map(int,input().split()))
data = list(map(int,input().split()))
s = {}
ans = 0
for i in data:
    if i not in s:
        s[i] = 1
    else:
        s[i] += 1

if len(s) <= K:
    print('0')
    
else:
    fl = 0
    for k,v in sorted(s.items(),key = lambda x:x[1]):
        ans += v
        fl += 1
        if len(s)-K == fl:
            print(ans)
            break

Measured memory_bytes: 38964
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int n,k,r,s,p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;

  map<int,string> dict;

  for(int i = 0;i < t.size();i++){
    dict[i%k] += t[i];
  }

  int ans = 0;
  for(auto P:dict){
    string now = P.second;
    vector<int> rdp(now.size()+1,0);
    vector<int> sdp(now.size()+1,0);
    vector<int> pdp(now.size()+1,0);

    for(int i = 0;i < now.size();i++){
      if(now[i] == 'r'){
        pdp[i+1] = max(rdp[i]+p,sdp[i]+p);
        sdp[i+1] = max(pdp[i],rdp[i]);
        rdp[i+1] = max(sdp[i],pdp[i]);
      }
      if(now[i] == 's'){
        rdp[i+1] = max(sdp[i]+r,pdp[i]+r);
        sdp[i+1] = max(rdp[i],pdp[i]);
        pdp[i+1] = max(sdp[i],rdp[i]);      
      }
      if(now[i] == 'p'){
        sdp[i+1] = max(rdp[i]+s,pdp[i]+s);
        rdp[i+1] = max(sdp[i],pdp[i]);
        pdp[i+1] = max(rdp[i],sdp[i]);
      }
    }
    ans += max({rdp[now.size()],pdp[now.size()],sdp[now.size()]});
  }

  cout << ans << endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long

int main(){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    int k;
    cin>>k;
    if(e-a>k) cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	string s;
	bool ch=true;
	cin>>s;
	for(int i=0;i!=s.size();++i){
		if(i!=a && !isdigit(s[i]))
			ch=false;
	}
	if(s[a]!='-')
		ch=false;
	cout<<(ch ? "Yes":"No");
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC051
{
    class Program
    {
        static void Main(string[] args)
        {
            solve();
        }

        static void solve()
        {
            string[] inputStr = Console.ReadLine().Split(' ');
            int k = int.Parse(inputStr[0]);
            int s = int.Parse(inputStr[1]);

            int count = 0;

            for (int x = 0; x <= k; ++x)
            {
                if (x + k + k < s)
                    continue;
                for (int y = 0; y <= k; ++y)
                {
                    if (x + y + k < s)
                        continue;
                    int z = s - y - x;
                    if (0 <= z && z <= k)
                        count++;
                }
            }

            Console.WriteLine(count.ToString());
        }

    }
}


Measured memory_bytes: 2776
#include <stdio.h>
int max(int a, int b){
  if(a>b)return a;
  else return b;
}
int a[50][4];
int n,m,q;
int ans=0;

int dfs(int res[], int pt, int max_res){
  if(max_res>m)return 0;
  if(pt==n){//終了条件
    int tmp=0;
    for(int j = 0; j<q; j++){//得点を数える
      if(res[a[j][1]-1]-res[a[j][0]-1]==a[j][2])tmp+=a[j][3];
    }
    ans = max(ans, tmp);
    return ans;
  }
  //ptより大きい数字を選んで再帰、選ばず再帰の二通り
  for(int i=max_res; i<11; i++){
    res[pt]=i;
    dfs(res, pt+1, i);//数字iを選んだら配列の一番後ろを指すptが後ろにずれる
  }
  return ans;
}
int main(){
  int i;
  int res[10];
  int used[10];
  for(i=0;i<10;i++)res[i]=used[i]=0;
  res[0]=used[0]=1;
  scanf("%d %d %d", &n, &m, &q);
  for(i=0;i<q;i++){
    scanf("%d %d %d %d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]);
  }
  int pt=1;
  printf("%d\n", dfs(res, pt, 1));
  //長さnの整数列を作ってその整数列に対して得点を見ていく漢字の全探索
  return 0;
}

Measured memory_bytes: 1696
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  string s;
  ll k;
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
    if (i == k - 1) {
      cout << '1' << endl;
      return 0;
    }
  }
  return 0;
}


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

void maxHeapify(int i);
void buildMaxHeap(void);
int left(int i);
int right(int i);

int heap[500001];
int n;

int main()
{
  int i;

  scanf("%d",&n);

  for(i = 1; i <= n; i++){
    scanf("%d",&heap[i]);
  }

  buildMaxHeap();

  for(i = 1; i <= n; i++){
    if(i >= 1)printf(" ");
    printf("%d",heap[i]);
  }
  printf("\n");

  return 0;
}

void maxHeapify(int i)
{
  int l,r,largest,temp;

  l = left(i);
  r = right(i);

  if(l <= n && heap[l] > heap[i])
    largest = l;
  else
    largest = i;
  if(r <= n && heap[r] > heap[largest])
    largest = r;

  if(largest != i){
    temp = heap[i];
    heap[i] = heap[largest];
    heap[largest] = temp;
    maxHeapify(largest);
  } 
}

void buildMaxHeap(void)
{
  int i;

  for(i = n/2; i > 0; i--)
    maxHeapify(i);
}

int left(int i)
{
  return 2 * i;
}

int right(int i)
{
  return 2 * i + 1;
}



Measured memory_bytes: 3680
import sys
fin = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush


class Vertex(object):
    def __init__(self, name, distance):
        self.name = name
        self.distance = distance


    def __lt__(self, other_vertex):
        return self.distance < other_vertex.distance
    

    def __le__(self, other_vertex):
        return self.distance <= other_vertex.distance
    

    def __gt__(self, other_vertex):
        return self.distance > other_vertex.distance
    

    def __ge__(self, other_vertex):
        return self.distance >= other_vertex.distance


def initialize(adj, s):
    MAX_NUM = float('inf')
    parent = {s: None}
    d = {vertex: MAX_NUM for vertex in adj.keys()}
    d[s] = 0
    return d, parent


# Dijkstra can work using a minheap which does not have decrease_key.
# and also we do not have to implement Vertex class.
# Instead, we can use (distance, vertex).
# in this case, the time it takes is O(ElgE).
# E is at most O(V^2), thus O(ElgE) = O(ElgV).
def dijkstra_simple(adj, w, s):
    d, parent = initialize(adj, s)
    priority_queue = []
    heappush(priority_queue, (d[s], s))
    while priority_queue:
        distance, source = heappop(priority_queue) 
        for neighbor in adj[source]:
            new_distance = distance + w[(source, neighbor)]
            if new_distance < d[neighbor]:
                d[neighbor] = new_distance
                parent[neighbor] = source
                heappush(priority_queue, (new_distance, neighbor))
    return d


n, m, s, t = [int(elem) for elem in fin().split(' ')]
adj = defaultdict(list)
yen_weights = dict()
snuuk_weights = dict()
for _ in range(m):
    u, v, a, b = [int(elem) for elem in fin().split(' ')]
    for v1, v2 in [(u, v), (v, u)]:
        adj[v1].append(v2)
        yen_weights[(v1, v2)] = a
        snuuk_weights[(v1, v2)] = b

d_yen = dijkstra_simple(adj, yen_weights, s)
d_snuuk = dijkstra_simple(adj, snuuk_weights, t)
min_cost = float('inf')
min_cost_after_each_year_reversed = []
for vertex in range(n, 0, -1):
    min_cost = min(min_cost, d_yen[vertex] + d_snuuk[vertex])
    min_cost_after_each_year_reversed.append(min_cost)

initial_money = 10**15
print(*(initial_money - cost for cost in reversed(min_cost_after_each_year_reversed)), sep='\n')


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

typedef long long ll;
const int INF = 1e8;
// const ll INF = 1LL << 60;
typedef pair<int, int> P;

ll L;

int main() {
    cin >> L;
    double ed = L / 3.0;
    double ans = 0;
    ans = ed * ed * ed;

    printf("%.10f\n", (double)ans);
}

Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		100000									// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数
static int siM;													// M

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// ソート関数 - int降順
int
fSortFncID(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int *lipVal1 = (int *)pzpVal1;
	int *lipVal2 = (int *)pzpVal2;

	// int降順
	if (*lipVal1 > *lipVal2) {
		return -1;
	}
	else if (*lipVal1 < *lipVal2) {
		return 1;
	}

	return 0;
}

// 最大公約数 - 取得
int
fGetGcd(
	int piVal1					// <I> 値１
	, int piVal2				// <I> 値２
)
{
	int liWork;

	// ユークリッドの互除法
	if (piVal1 < piVal2) {
		liWork = piVal1;
		piVal1 = piVal2;
		piVal2 = liWork;
	}
	while (piVal2 > 0) {
		liWork = piVal1 % piVal2;
		piVal1 = piVal2;
		piVal2 = liWork;
	}

	return piVal1;
}

// 最小公倍数 - 取得
int
fGetLcm(
	int piVal1					// <I> 値１
	, int piVal2				// <I> 値２
)
{
	// 最大公約数 - 取得
	int liGcd = fGetGcd(piVal1, piVal2);

	// 約数
	int liVal1 = piVal1 / liGcd;
	int liVal2 = piVal2 / liGcd;

	return liVal1 * liVal2 * liGcd;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 配列数、M - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siACnt, &siM);

	// 配列 - 取得
	for (i = 0; i < siACnt; i++) {
		fscanf(szpFpI, "%d", &si1Array[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	qsort(si1Array, siACnt, sizeof(int), fSortFncID);

	// 初期値
	int liLcm = si1Array[0];
	int liMin = liLcm / 2;

	// 値更新
	for (i = 1; i < siACnt; i++) {
		int liHalf = si1Array[i] / 2;
		while (liMin <= siM) {
			if (liMin % liHalf == 0) {
				int liVal = liMin / liHalf;
				if (liVal % 2 == 1) {
					break;
				}
			}

			// 次の値
			liMin += liLcm;
		}

		// 最小公倍数 - 更新
		liLcm = fGetLcm(liLcm, si1Array[i]);
	}
	if (liMin > siM) {
		return 0;
	}

	// 個数 - 取得
	return (siM  - liMin) / liLcm + 1;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, L;
    cin >> N >> L;
    int ans = 0;
    REP(i, 1, N) {
        ans += L + i - 1; 

    }
    //cout << ans << endl;
    int ans2 = INF;
    int idx = -1;
    REP(i, 1, N) {
        if (abs(ans2) > abs(L + i - 1))
            ans2 = L + i - 1;
    }
    cout << ans - ans2 << endl;

    return 0;
}


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

typedef long long LL;

const int MaxN=1e5+5;

int N,M;
LL K;
int X[MaxN],A[MaxN],D[MaxN];
int Base[MaxN],Ans[MaxN],Tmp[MaxN];

void Mul(int *a,int *b){
	int i;
	for(i=1;i<N;i++)
		Tmp[i]=b[a[i]];
	copy(Tmp+1,Tmp+N,a+1);
}

int main(){
	int i,j;
	LL now;
	scanf("%d",&N);
	for(i=1;i<=N;i++){
		scanf("%d",&X[i]);
		Base[i]=Ans[i]=Tmp[i]=i;
	}
	for(i=1;i<N;i++)
		D[i]=X[i+1]-X[i];
	scanf("%d%lld",&M,&K);
	for(i=1;i<=M;i++)
		scanf("%d",&A[i]);
	for(i=1;i<=M;i++)
		swap(Tmp[A[i]-1],Tmp[A[i]]);
	for(i=1;i<N;i++)
		Base[Tmp[i]]=i;
	for(;K;K>>=1){
		if(K&1)
			Mul(Ans,Base);
		Mul(Base,Base);
	}
	for(i=1;i<N;i++)
		Tmp[Ans[i]]=i;
	for(now=X[i=1];i<=N;i++){
		printf("%lld\n",now);
		now+=D[Tmp[i]];
	}
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int main() {
    int n, k; long long h, ans = 0;
    cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < n;i++) {
        cin >> h;
        v.push_back(h);
    }
    sort(v.begin(), v.end());
    for (int i = 0;i < n - k;i++) {
        ans += v[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long n = long.Parse(input[0]);
		long k = long.Parse(input[1]);
    long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[] sums = new long[n];//累積和
    long[] sumsPlus = new long[n];//正のみの累積和
    long answer = 0;

    sums[0] = nums[0];
    if(nums[0] > 0) sumsPlus[0] = nums[0];
    for(long i = 1; i < n; i++)//累積和の計算
    {
      sums[i] = sums[i-1] + nums[i];
      if(nums[i] > 0) sumsPlus[i] = sumsPlus[i-1] + nums[i];
      else sumsPlus[i] = sumsPlus[i-1];
    }

    for(long i = 0; i < n-k+1; i++)
    {
      long memo = 0;
      if(i > 0) memo = sumsPlus[i-1];//左の自由和
      memo += sumsPlus[n-1] - sumsPlus[k+i-1];//右の自由和
      if(i > 0)
      {
        if(sums[k+i-1] - sums[i-1] > 0) memo += sums[k+i-1] - sums[i-1];
      }else
      {
        if(sums[k+i-1] > 0) memo += sums[k+i-1];
      }
      answer = Math.Max(answer, memo);
    }

		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 27356
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.to!int;
  writeln(n*n-a);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();

		int outputMax = 0;
		for (int i = a; i < a + k && i <= b ; i++) {
			outputMax = i;
			System.out.println(i);
		}

		int minOfRight = b - k + 1;
		if (minOfRight <= outputMax) minOfRight = outputMax + 1;
		for (int i = minOfRight; i <= b; i++) {
			System.out.println(i);
		}

		sc.close();
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using  namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 1e18

int main(){
	vector<pair<long long,long long> >P;
	long long w[2],p;
	cin>>w[0]>>w[1];
	long long c[2];
	memset(c,0,sizeof(c));
	REP(i,w[0]){
		cin>>p;
		P.PB(MP(p,0));
	}
	REP(i,w[1]){
		cin>>p;
		P.PB(MP(p,1));
	}
	sort(ALL(P));
	long long ans=0;
	REP(i,P.size()){
		pair<long long,long long> q = P[i];
		long long a=q.first,b=q.second;
		ans+=(w[b^1]-c[b^1]+1)*a;
		c[b]++;
	}
	cout<<ans<<endl;
}
	

Measured memory_bytes: 4464
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;


int main() {
    long n;
    scanf ("%ld",&n);
    long s,d;
    long ans;
    for (int t=0;t<n;t++){
      ans=0;
      scanf("%ld %ld",&s,&d);
      s=s+1073741824;
      d=d+1073741824;
      while(d-s){
        switch(d-s){
          case 1:
            ans++;
            s=d;
            break;
          case 2:
            if(s&1){
              ans++;
            }
            ans++;
            s=d;
            break;
          default:
            if(s&1){
              ans++;
              s++;
            }
            if(d&1){
              ans++;
              d--;
            }
            s=s>>1;
            d=d>>1;
            break;
        }
      }
      printf("%ld\n",ans);
    }
}



Measured memory_bytes: 3200
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N, M = read_int_list()
    p = [0] * M
    S = [''] * M
    for i in range(M):
      l = read_str_list()
      p[i] = int(l[0])
      S[i] = l[1]
      
    r = set()
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in r:
          r.add(p[i])

    correct, penalties = 0, 0
    f = set()  
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in f:
          f.add(p[i])
          correct += 1
      # print(p[i], S[i], f, r)
      
      if S[i] == 'WA':
        if p[i] not in f and p[i] in r:
          penalties += 1

    print(correct, penalties)


def main0():
    N, M = read_int_list()
    p = [0] * M
    S = [''] * M
    for i in range(M):
      l = read_str_list()
      p[i] = int(l[0])
      S[i] = l[1]
      
    r = set()
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in r:
          r.add(p[i])

    correct = len(r)
    penalties = 0
    f = set()  
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in f:
          f.add(p[i])
      
      if S[i] == 'WA':
        if p[i] not in f and p[i] in r:
          penalties += 1

    print(correct, penalties)


def main1():
    N, M = read_int_list()
    correct = 0
    penalties = 0
    WA = [0] * (N + 1)
    AC = [0] * (N + 1)
    for i in range(M):
      l = read_str_list()
      p = int(l[0])
      S = l[1]

      if S == 'AC':
        AC[p] += 1
      if S == 'WA':
        WA[p] += 1

      if S == 'AC' and AC[p] == 1:
        correct += 1
        penalties += WA[p]
      
      # print(AC[1:], WA[1:])

    print(correct, penalties)

main1()


Measured memory_bytes: 5108
#include<stdio.h>
 int main(void)
 {
     int N,K;
     int p[1000];
     int i,j,tmp,Value=0;

     scanf("%d%d",&N,&K);

     for(i=0;i<N;i++)
       scanf("%d",&p[i]);

     for(i=0;i<N;i++){
       for(j=i+1;j<N;j++){
         if(p[i]>p[j]){
           tmp=p[i];
           p[i]=p[j];
           p[j]=tmp;
         }
       }
     }

     for(i=0;i<K;i++)
       Value+=p[i];

     printf("%d\n",Value);

     return 0;
 }


Measured memory_bytes: 1736
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,p=parseMap(split(readline()))
    a=parseMap(split(readline()))
    cnt=[count(x->x%2==0,a),count(x->x%2==1,a)]
    if cnt[1]==n
        if p==0
            println(BigInt(2^n))
        else
            println(0)
        end
    else
        println(BigInt(2^(n-1)))
    end
end
main()

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

int main() {
    int n, l;
    cin >> n >> l;
    vector<int> d(n);
    for (int i = 1; i <= n; i++) {
        d[i-1] = l+i-1;
    }
    int all = 0;
    rep(i,n) all += d[i];
    int ans = 0;
    int mn = 10000;
    rep(i,n) {
        int dall = all-d[i];
        if (abs(all-dall) < mn) {
            mn = abs(all-dall);
            ans = dall;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
X,Y,Z,K=map(int,input().split())
A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]
C=[int(x) for x in input().split()]
A.sort(reverse =True)
B.sort(reverse =True)
C.sort(reverse =True)
answer=[]
for p in range(min(X,K)):
  for q in range(min(Y,K)):
    if p*q>K:
      break
    for r in range(min(Z,K)):
      if p*q*r>K:
        break
      answer +=[A[p]+B[q]+C[r]]
answer.sort()
for i in range(K):
  print(answer[-i-1])

Measured memory_bytes: 112068
ans = [0] * 100001
ans[0] = 0

n = int(input())

for i in range(1,n+1):
    cand1 = ans[i-1]
    cand2 = 100001
    cand3 = 100001
    x = 6
    while (x<=i):
        cand2 = ans[i-x]
        x=6*x
    y = 9
    while (y<=i):
        cand3 = ans[i-y]
        y=9*y
    ans[i] = min(cand1,cand2,cand3) + 1

print(ans[n])

Measured memory_bytes: 3828
#枚数主体でいく
n,y = gets.strip.split.map(&:to_i)
ymax = (y.to_f/10).floor
ary = []
for i in 0..ymax
  for j in 0..n-i
    if 10*i+5*j+n-i-j == y/1000
      ary << [i,j,n-i-j].to_a
    end
  end
end
if ary.size == 0
  puts [-1,-1,-1].join(" ")
else
  puts ary[0].join(" ")
end

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Combination {
    Combination(ll n) {
        mNumTbl.resize(n + 1);
        mInverseNumTbl.resize(n + 1);
        mNumTbl[0] = 1;
        mInverseNumTbl[0] = 1;
        FOR(i, n + 1, 1) {
            mNumTbl[i] = (mNumTbl[i - 1] * i) % MOD;
        }
        FOR(i, n + 1, 1) {
            mInverseNumTbl[i] = modpow(mNumTbl[i]);
        }
    }

    ll get(ll n, ll r) {
        if (n < r || n < 0)
            return 0;
        return (((mNumTbl[n] * mInverseNumTbl[r]) % MOD) * mInverseNumTbl[n - r]) % MOD;
    }

    ll modpow(ll n) {
        ll s = 1, p = n;
        for (ll i = 0; (1LL << i) <= MOD - 2; ++i, p = (p * p) % MOD) {
            if (((MOD - 2) & (1 << i)) == 0)
                continue;
            s *= p;
            s %= MOD;
        }
        return s;
    }

    vector<ll> mInverseNumTbl;
    vector<ll> mNumTbl;
};

Combination cmb(2500000);

//! (0,0)->g
ll calc(pll g) {
    ll ret = 0;
    REP(i, g.first + 1) {
        ret += cmb.get(i + g.second + 1, g.second);
        ret %= MOD;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    pll a, b;
    cin >> a.first >> a.second >> b.first >> b.second;

    ll ans = calc(b);
    ans -= (calc(pll(a.first - 1, b.second)) + calc(pll(b.first, a.second - 1)));
    ans = (2 * MOD + ans) % MOD;
    ans += calc(pll(a.first - 1, a.second - 1));

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

Measured memory_bytes: 39296
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 vector<ll> vec(3);
  for(ll i=0;i<3;i++) {
    cin>>vec[i];
  }
  sort(all(vec));
  cout<<vec[0]*vec[1]/2<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int q;
    cin >> q;
    vector<int> m(q);
    rep(i, q) cin >> m[i];
    
    set<int> ans;
    for (int bit = 0; bit < (1 << N); ++bit) {
        vector<int> S;
        rep(i, N) {
            if (bit & (1 << i)) S.push_back(i);
        }
        int sum = 0;
        for (int i : S) sum += A[i];
        ans.insert(sum);
    }
    
    rep(i, q) {
        if (ans.count(m[i])) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}



Measured memory_bytes: 3160