akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int N, M;
P p[100000];
map<P, int> edge_idx;
vector<int> G[100000];
int D[100000];
bool used[100000];
bool colored[100000];
bool color[100000];
int U[200000], V[200000], ans[200000];

void paint(int v, int col){
    color[v] = col;
    colored[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        if(!colored[G[v][i]]){
            int s = v;
            int t = G[v][i];
            if(s > t) swap(s, t);
            int idx = edge_idx[P(s, t)];
            if(ans[idx] == 0) continue;
            if(ans[idx] > 0) paint(G[v][i], col);
            if(ans[idx] < 0) paint(G[v][i], col^1);
        }
    }
}

const int INF = 1e+9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        cin >> D[i];
        p[i] = P(D[i], i);
    }
    for(int i = 0; i < M; i++){
        cin >> U[i] >> V[i];
        U[i]--; V[i]--;
        G[U[i]].push_back(V[i]);
        G[V[i]].push_back(U[i]);
        if(U[i] > V[i]) swap(U[i], V[i]);
        edge_idx[P(U[i], V[i])] = i;
    }
    sort(p, p+N);
    for(int i = 0; i < N; i++){
        int v = p[i].second;
        int w = p[i].first;
        // cout << v << ' ' << w << endl;
        if(used[v]) continue;
        for(int j = 0; j < G[v].size(); j++){
            if(D[G[v][j]] < D[v]){
                int s = v;
                int t = G[v][j];
                int w = D[s]-D[t];
                if(s > t) swap(s, t);
                ans[edge_idx[P(s, t)]] = w;
                used[v] = true;
                break;
            }else if(D[G[v][j]] == D[v]){
                int s = v;
                int t = G[v][j];
                int w = D[s];
                if(s > t) swap(s, t);
                ans[edge_idx[P(s, t)]] = -w;
                used[s] = true;
                used[t] = true;
                // cout << s << ' ' << t << ' ' << w << endl;
                break;
            }
            if(j+1 == G[v].size()){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    for(int i = 0; i < N; i++){
        if(!colored[i]) paint(i, 0);
    }
    for(int i = 0; i < M; i++){
        if(ans[i] == 0) ans[i] = INF;
    }
    for(int i = 0; i < N; i++){
        cout << (color[i] == 1 ? "W":"B");
        if(i == N-1) cout << endl;
    }
    for(int i = 0; i < M; i++){
        cout << abs(ans[i]) << endl;
    }
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  string s; cin>>s;
  int n = s.length();
  int res = 0;
  for (int i=0; i<n/2; i++) {
    res += s[i]!=s[n-1-i];
  }
  
  cout<<res;

  return 0;
}


Measured memory_bytes: 256
N=int(input())
S=input()
a=i=j=0
while j<N:
  if j-i > N-j:
      break  

  t=S[i:j]
  if t in S[j:]:
    a=max(a,len(t))
    j+=1
  else:
    i+=1
print(a)  

Measured memory_bytes: 3188
n, m = map(int, input().split())

graph1 = [[] for _ in range(n * 3)]

for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph1[u * 3 + 0].append(v * 3 + 1)
    graph1[u * 3 + 1].append(v * 3 + 2)
    graph1[u * 3 + 2].append(v * 3 + 0)

s, t = map(int, input().split())
s -= 1
t -= 1
s = s * 3
t = t * 3

from heapq import heappush, heappop


def dijkstra(graph: list, n: int, start: int, INF: int = float('inf')) -> list:
    # graph[node] = [(cost, to)]
    dist = [INF] * n
    num = [0] * n

    dist[start] = 0
    heap = [(0, start)]
    while heap:
        _, v_from = heappop(heap)
        for v_to in graph[v_from]:
            dist_cand = dist[v_from] + 1
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist
    # dist = [costs to nodes]


INF = 10**10
dist = dijkstra(graph1, n * 3, s, INF=INF)
if dist[t] == INF:
    print(-1)
else:
    print(dist[t] // 3)


Measured memory_bytes: 62252
#include<bits/stdc++.h>
using namespace std;
void ts()
{
    cout<<"***我只想过个水题抽奖****"<<endl;
    cout<<"***I JUST WANT PASS A WATER-PROBLEM FOR LUCK DRAW***"<<endl;
}
#define ll long long
int x,y,z,m;
ll a[1005],b[1005],c[1005];
vector<ll>v;
void solve1()
{
    for(int i=1;i<=min(200,x);i++)
        for(int j=1;j<=min(200,y);j++)
            for(int k=1;k<=min(200,z);k++)
        v.push_back(a[i]+b[j]+c[k]);
    for(int i=201;i<=x;i++)
        for(int j=1;j<=min(50,y);j++)
            for(int k=1;k<=min(50,z);k++)
            v.push_back(a[i]+b[j]+c[k]);
    for(int i=1;i<=min(50,x);i++)
        for(int j=201;j<=y;j++)
            for(int k=1;k<=min(50,z);k++)
            v.push_back(a[i]+b[j]+c[k]);
    for(int i=1;i<=min(50,x);i++)
        for(int j=1;j<=min(50,y);j++)
            for(int k=201;k<=z;k++)
            v.push_back(a[i]+b[j]+c[k]);
}
bool judge(ll p)
{
    int tot=0;
    for(int i=1;i<=x;i++)
        for(int j=1;j<=y;j++)
        {
            if(a[i]+b[j]+c[1]<p) break;
            for(int k=1;k<=z;k++)
            {
                if(a[i]+b[j]+c[k]<p) break;
                tot++;
                if(tot>=m) return true;
            }
        }
    return false;
}
void solve2()
{
    ll l=0,r=3e10,ans;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m)) ans=m,l=m+1;
        else r=m-1;
    }
    for(int i=1;i<=x;i++)
        for(int j=1;j<=y;j++)
        {
            if(a[i]+b[j]+c[1]<ans) break;
            for(int k=1;k<=z;k++)
            {
                if(a[i]+b[j]+c[k]<ans) break;
                v.push_back(a[i]+b[j]+c[k]);
            }
        }
}
void solve3()
{
    for(int i=1;i<=x;i++)
        for(int j=1;j<=y;j++)
            for(int k=1;k<=z;k++)
            if(i*j*k<=m) v.push_back(a[i]+b[j]+c[k]);
            else break;
}
int main()
{
    scanf("%d%d%d%d",&x,&y,&z,&m);
    for(int i=1;i<=x;i++)
        scanf("%lld",&a[i]);
    for(int i=1;i<=y;i++)
        scanf("%lld",&b[i]);
    for(int i=1;i<=z;i++)
        scanf("%lld",&c[i]);
    sort(a+1,a+1+x);
    sort(b+1,b+1+y);
    sort(c+1,c+1+z);
    reverse(a+1,a+1+x);
    reverse(b+1,b+1+y);
    reverse(c+1,c+1+z);
    //solve1();
    //solve2();
    solve3();
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i=0;i<m;i++)
        printf("%lld\n",v[i]);
}


Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
#include <float.h>
using namespace std;


int main() {
	string s, tmp[10];
	unsigned int bit = 0, count = 0, last = 0, num = 0;
	unsigned long long int sum = 0;
	cin >> s;
	while (bit < pow(2,s.size()-1)) {
		count = 0;
		last = 0;
		num = 1;
		for (int i = 0; i < s.size()-1; ++i) {
			if ((bit >> i) % 2 == 1) {
				tmp[count++] = s.substr(last, num);
				last += num;
				num = 1;
			}
			else {
				num++;
			}
			
		}
		if (last < s.size()) {
			tmp[count++] = s.substr(last, s.size() - last);
		}
		
		for (unsigned int i = 0; count > i; ++i) {
			sum += stoll(tmp[i]);
		}
		++bit;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>
#define INF 100000000
using namespace std;
int N,A,B,C,l;
vector<int> L;

int main(void){
 int redCnt=0;
 int blueCnt=0;
 char s[100050];
 cin>>s;

 for(int i=0; i<strlen(s);i++){
  if(s[i]=='0')redCnt++;
  else blueCnt++;
 }
 cout<<min(redCnt,blueCnt)*2<<endl;
 return 0;
}


Measured memory_bytes: 384
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed parsing")
}

use std::cmp::{min, max};
use std::num;

const MAX : usize = 2000 + 1;
const MOD : u64 = 1_000_000_007;

static mut fac : [u64; MAX] = [1; MAX];
static mut finv : [u64; MAX] = [1; MAX];
static mut inv : [u64; MAX] = [1; MAX];

pub fn initialize_combination() {
    unsafe {
        for i in 2..MAX {
            fac[i] = fac[i - 1] * i as u64 % MOD;
            inv[i] = MOD - inv[ (MOD % (i as u64)) as usize ] * (MOD / (i as u64) ) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
}

pub fn combination(n : usize, k : usize) -> u64 {
    if n < k || n >= MAX {return 0;}
    unsafe {
        fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
    }
}

fn main() {
    
    initialize_combination();
    
    let n = read::<usize>();
    let k = read::<usize>();
    
    // n-k+1 C i * k-1 C i-1
    for i in 1..k+1 {
        println!("{}", combination(n-k+1, i) * combination(k-1, i-1) % MOD);
    }
    
}

Measured memory_bytes: 4352
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		ArrayList<Integer> A = new ArrayList<Integer>();
		for(int i = 0; i < N; i ++) {
			A.add(stdIn.nextInt());
		}
		Collections.sort(A, Comparator.reverseOrder());
		long ans = 0;
		ans += A.get(0);
		for(int i = 2; i < N; i ++) {
			ans += A.get((int) Math.floor((double) i/2));
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 65676
'use strict'
function Main(input) {
  const numP = input.split("\n").map(Number);
  numP.pop();
  let numG = numP[0];
  numP.shift();
  // console.log({ numG, numP });

  numP.sort((a, b) => a - b);
  // console.log({ numG, numP });

  let btlNeck = Math.ceil(numG / numP[0]);
  let Ans = btlNeck + 4;
  console.log(Ans);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}


fun solve(out: PrintWriter) {
    val (n, k) = readLongList().map { ModInt(it) }
    var ans = ModInt(0)
    for (i in k.x..(n.x + 1)) {
        val x = ModInt(i)
        ans += x * (n + n - x + ModInt(1)) / ModInt(2) - x * (x - ModInt(1)) / ModInt(2) + ModInt(1)
    }
    println(ans)
}

/** always positive number (Use for minus) */
data class ModInt(val xx: Long, val MOD: Long = 1000000007L) {
    val x = ((xx % MOD) + MOD) % MOD

    operator fun unaryMinus() = ModInt(-x, MOD)

    operator fun plus(other: ModInt): ModInt {
        var value = x + other.x
        if (value >= MOD) { value -= MOD }
        return ModInt(value, MOD)
    }

    operator fun minus(other: ModInt): ModInt {
        var value = x + MOD - other.x
        if (value >= MOD) { value -= MOD }
        return ModInt(value, MOD)
    }

    operator fun times(other: ModInt): ModInt {
        val value = (x * other.x) % MOD
        return ModInt(value, MOD)
    }

    operator fun div(other: ModInt) = this * other.inverse()

    override fun toString() = x.toString()


    /** O(log(n)) */
    private fun pow(n: Long): ModInt {
        var ret = ModInt(1L, MOD)
        var x = this
        var k = n
        while (k > 0) {
            if ((k and 1L) == 1L) { ret *= x }
            x *= x
            k = k shr 1
        }
        return ret
    }

    /**  O(log(MOD)) */
    private fun inverse() = pow(MOD - 2)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

int main() {
  string a, b;
  cin >> a >> b;

  cout << b + a << endl;

  return 0;
}

Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    dist = 0

    for i in range(1, N + 1):
        dist += i
        if dist >= N:
            print(i)
            exit()


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef pair< int, int > PII;
typedef pair< ll, ll > PLL;

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define PI 3.14159265358979323846
#define INF 1000000006
#define LINF 1000000000000000006
#define DINF 1e300
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair

const int N = 2e5 + 10;

int n, k, l, ans[ N ];

class DisjointSet {
 public:
  int p[ N ];
  void Init( int x ) {
    for ( int i = 1 ; i <= x ; ++i )
      p[ i ] = i;
  }
  int Find( int x ) {
    return x == p[ x ] ? x : p[ x ] = Find( p[ x ] );
  }
  void Union( int x, int y ) {
    p[ Find( x ) ] = Find( y );
  }
};
DisjointSet st, pst;
void init() {
  cin >> n >> k >> l;
  st.Init( n );
  pst.Init( n );
  for ( int i = 0 ; i < k ; ++i ) {
    int x, y;
    cin >> x >> y;
    pst.Union( x, y );
  }
  for ( int i = 0 ; i < l ; ++i ) {
    int x, y;
    cin >> x >> y;
    st.Union( x, y );
  }
}
void solve() {
  vector< vector< int > > group;
  map< PII, int > mp;
  int sz = 0;
  for ( int i = 1 ; i <= n ; ++i ) {
    int ro = pst.Find( i ), ra = st.Find( i );
    PII now = MP( ro, ra );
    if ( mp.count( now ) == 0 ) {
      mp[ now ] = sz;
      vector< int > tmp;
      tmp.PB( i );
      group.PB( tmp );
      ++sz;
    }
    else  
      group[ mp[ now ] ].PB( i );
  }
  for ( int i = 0 ; i < group.size() ; ++i ) {
    for ( int j = 0 ; j < group[ i ].size() ; ++j ) {
      int now = group[ i ][ j ];
      ans[ now ] += group[ i ].size();
    }
  }

  for ( int i = 1 ; i <= n ; ++i )
    cout << ans[ i ] << " ";
  cout << endl;
}
int main() {
  IOS;
  int __ = 1;
  //cin >> __;
  while ( __-- ) {
    init();
    solve();
  }
  return 0;
}


Measured memory_bytes: 24492
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> K >> N;
    vi a(N);
    cin >> a;
    ans = K - (a[1] - a[0]);
    REPS(i, N - 1) {
        ans = min(K - (a[i] - a[i - 1]), ans);
    }
    ans = min(K - (a[0] + K - a[N - 1]), ans);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

double calc(int y, int r, int t)
{
    if(t == 1){
        return 1 + y * r / 100.0;
    } else {
        return pow(1 + r / 100.0, y);
    }
}

int main()
{
    int n, y, b, r, t;
    while(cin >> n, n){
        double Max = -1;
        int num;
        cin >> y;
        for(int i = 0; i < n; ++i){
            cin >> b >> r >> t;
            double temp = calc(y,r,t);
            if(temp > Max){
                Max = temp;
                num = b;
            }
        }
        cout << num << endl;
    }
}

Measured memory_bytes: 1164
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 static int a_dist[];
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();	
	        long D = sc.nextInt();
	        long d2 = D*D;
	        long ans =0;
	        for (int i=0 ; i<N; i++) {
	            long a = Long.parseLong(sc.next());
	            long b = Long.parseLong(sc.next());
	            if(a*a+b*b<=d2)ans++;
	        }
	        System.out.println(ans);
		 }
		 
	}

Measured memory_bytes: 58988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e9+7;
const ll N = 53;
ll n,p,a,ki=0,gu=0,ans,x=0,y=0;
ll c[N][N];
ll combi(ll r,ll k){
	if(c[r][k]!=0)return c[r][k];
	if(r==k)return 1;
	if(k==0)return 1;
	return c[r][k]=combi(r-1,k)+combi(r-1,k-1);
}

int main(){
	cin>>n>>p;
	FOR(i,0,n){
		cin>>a;
		if(a%2==1)ki++;
		else gu++;
	}
	FOR(i,0,N){
		FOR(j,0,N){
			c[i][j]=0;
		}
	}

	if(p==1){
		FOR(i,0,gu+1)x+=combi(gu,i);
		FOR(i,0,ki+1){
			if(i%2==1)y+=combi(ki,i);
		}
	}else{
		FOR(i,0,gu+1)x+=combi(gu,i);
		FOR(i,0,ki+1){
			if(i%2==0)y+=combi(ki,i);
		}
	}
	cout<<x*y<<endl;
	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    if n == 3:
        return '2 5 63'
    if n == 4:
        return '2 5 20 63'
    a = []
    c = 1
    for i in range(n):
        while c%2 > 0 and c%3 > 0 and c%5 > 0:
            c += 1
        a.append(c)
        c += 1
    a[-3] += 30 - (a[-3] % 30)
    a[-2] += 120 - (a[-2] % 30)
    a[-1] += 180 - (a[-1] % 30)
    t = sum(a)
    while t % 2 == 1:
        a[-3] += 3
        t += 3
    while t % 3 > 0:
        a[-2] += 10
        t += 10
    while t % 5 > 0:
        a[-1] += 6
        t += 6

    return ' '.join(map(str, a))


print(main())




Measured memory_bytes: 8916
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int n,m;
vector<int> k[10];
int p[10];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        for(int j=0;j<x;j++){
            int y;
            cin>>y;
            y--;
            k[i].push_back(y);
        }
    }
    for(int i=0;i<m;i++){
        cin>>p[i];
    }
    int limit = (1<<n);
    int ans = 0;
    for(int i=0;i<limit;i++){
        bool valid = true;
        for(int j=0;j<m && valid;j++){
            int cnt = 0;
            for(int h=0;h<k[j].size();h++){
                if(i & (1<<k[j][h])){
                    ++cnt;
                }
            }
            if(cnt % 2 != p[j]){
                valid = false;
                break;
            }
        }
        if(valid){
            ans++;
        }
    }
    cout<<ans<<"\n";

    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>

int gcd(int,int);

int main(){
  int x,y,d;
  scanf("%d %d",&x,&y);
  printf("%d\n",gcd(x,y));
  return 0;
}

int gcd(int x,int y){
  if(y==0) return x;
  return gcd(y,x%y);
}



Measured memory_bytes: 2048
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), c
  cout << fixed << setprecision(15);

  ll l, r, d;
  cin >> l >> r >> d;

  ll nl = (l-1)/d;
  ll nr = r/d;

  ll ans = nr - nl;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
using namespace std;
int n,d[110],ans;
int main() {
	scanf("%d",&n);
	ans=0;
	for (int i=1;i<=n;i++) {
		scanf("%d",&d[i]);
		ans+=d[i];
	}
	if (ans%10==0) {
	sort(d+1,d+(n+1));
		bool t=false;
		for (int i=1;i<=n;i++)
			if (d[i]%10!=0) {
				ans-=d[i];
				t=true;
				break;
			}
		if (!t)
			ans=0;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;


int main()
{
    int n;

    
       // cout<<"give n"<<endl;
        cin>>n;
    
   // while ((n<1)||(n>20 ));
        int v[50],c[50];
   // cout<<"values of the gems"<<endl;
    int res=0;
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
    }
    //cout<<"cost of the gems"<<endl;

    for(int i=0; i<n; i++)
    {
        cin>>c[i];
        
    }
     for(int i=0; i<n; i++)
    {
        if(v[i]>c[i])
        res+=v[i]-c[i];
    }

    cout<<res;
        return 0;
}


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

using namespace std;

int main(){
  int r, d, x2000;
  std::cin >> r >> d >> x2000;

  int before = x2000;
  for(int i=0; i<10; i++){
    int ans = r * before - d;
    std::cout << ans << '\n';
    before = ans;
  }
  return 0;
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline void chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
}
template <class T1, class T2>
inline void chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }

    sort(all(A));
    ll M = A[N - 1] + 1;
    vector<bool> table(M, false);
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        if (table[A[i]] == false) {
            for (int j = A[i]; j < M; j += A[i]) {
                table[j] = true;
            }
            if (i < N - 1) {
                if (A[i + 1] == A[i]) {
                    continue;
                }
            }
            ++ans;
        }
    }

    cout << ans << endl;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const ll MOD = 1000000007;

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

    ll ans = 0;
    ll x = 0;
    rep(i,n){
        ans += a[i]*x;
        ans %= MOD;
        x += a[i];
        x %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5196
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int q,x,ty,cnt = 0;cin>>q;
	char ch;
	while(q--)
	{
		scanf("%d",&ty);
		if(ty==1)    cnt++;
		else 
		{
			scanf("%d %c",&x,&ch);
			if(x ==1)
			{
				if(cnt % 2!=0)a.insert(a.end(),ch);
				else	a.insert(a.begin(),ch);
			}
			else 
			{
				if(cnt % 2 ==0)a.insert(a.end(),ch);
				else	a.insert(a.begin(),ch);
			}
		}
	}
	if(cnt%2 == 1)	reverse(a.begin(),a.end());
	cout<<a;
	
	return 0;
}

Measured memory_bytes: 900
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int D;
    ll G;
    cin>>D>>G;
    vector<ll> p(D),c(D);
    REP(i,D) cin>>p[i]>>c[i];
    ll ans=INF;
    REP(bit,1<<D){
        ll score=0;
        ll num=0;
        bool ok=false;
        REP(i,D){
            ll mask=1<<i;
            if(mask&bit){
                score+=p[i]*100*(i+1)+c[i];
                num+=p[i];
            }
        }
        if(score>=G){
            ans=min(ans,num);
        }
        REPD2(i,D-1,-1){
            ll mask=1<<i;
            if(mask&bit) continue;
            REP(j,p[i]){
                score+=100*(i+1);
                num++;
                if(score>=G){
                    ok=true;
                    break;
                }
            }
            if(ok) break;
        }
        if(ok){
            ans=min(ans,num);
        }
        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N;
	cin >> N;
	long long maxA = 0;
	long long sumDai = 0;
	for (int i = 0; i < N; ++i) {
		long long A;
		cin >> A;
		sumDai += max(maxA - A, 0ll);
		maxA = max(maxA, A);
	}

	cout << sumDai << endl;
}

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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int max_num = max(max(a, b), c);
    cout << pow(2, k)*max_num + a+b+c - max_num << endl;
    return 0;
}

Measured memory_bytes: 512
S = input()
T = input()

for _ in range(len(S)):
    S_lst = list(S)
    tmp = S[0]
    for i in range(len(S) - 1):
        S_lst[i] = S_lst[i+1]
    S_lst[-1] = tmp
    S = ''.join(S_lst)
    
    if S == T:
        print("Yes")
        exit()
else:
    print("No")

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

int main(){
	int k,x;
	cin>>k>>x;
	for(int i=x-k+1;i<x;i++){
		cout<<i<<" ";
	}
	for(int j=x;j<k+x-1;j++){
		cout<<j<<" ";
	}
	cout<<k+x-1;
}

Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		
		if(a.equals("H")){
			if(b.equals("H")){
				System.out.println("H");
			}else if(b.equals("D")) {
				System.out.println("D");
			}
		}
		if(a.equals("D")){
			if(b.equals("H")){
				System.out.println("D");
			}else if(b.equals("D")) {
				System.out.println("H");
			}
		}
	}

}


Measured memory_bytes: 20052
#include<stdio.h>

int main(){
  int n,data[100],temp,i,j,k;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
  scanf("%d",&data[i]);
  }
  for(i = 0;i <= n-1;i++){
    temp = data[i];
    j = i - 1;
    while(j >= 0 && data[j] > temp){
      data[j+1] = data[j];
      j--;
    }
    data[j+1] = temp;
    for(k = 0;k < n-1;k++)printf("%d ",data[k]);
    printf("%d",data[k]);
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2052
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int main() {
	string s; cin >> s;
	int q; cin >> q;
	while (q--) {
		string t; int a, b; cin >> t >> a >> b;
		if (t == "print")
			cout << s.substr(a, b - a + 1) << endl;
		if (t == "reverse")
			for (; a < b; a++, b--) swap(s[a], s[b]);
		if (t == "replace") {
			string p; cin >> p;
			for (int i = 0; i < p.length(); i++)
				s[a + i] = p[i];
		}
	}
}

Measured memory_bytes: 1220
#include<stdio.h>
#include<math.h>
main(){
  int n,data[100000],i,j,count;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
    for(j=2;j<=sqrt(data[i]);j++)
      if(data[i]%j==0){
	data[i]=-1;
      } 
  }
  for(i=0;i<n;i++)
    if(data[i]!=-1)
      count++;
  printf("%d\n",count);
  return 0;
}

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

namespace my {
/*汎用*/
template <typename T>
void input_vec(vector<T> &a, ll n) {
  if (!a.empty()) {
    cout << "error in input_vec" << endl;
    exit(1);
  }
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
}
template <typename T>
void input_set(set<T> &a, ll n) {
  if (!a.empty()) {
    cout << "error in input_set" << endl;
    exit(1);
  }
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.insert(tmp);
  }
}

char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }

/*整数*/
ll gcd(ll a, ll b) {  // O( log(max(a,b)) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * (b / my::gcd(a, b)); }  // O( log(max(a,b)) )
ll modinv(ll n, ll mod) {                               // O( log(max(n,mod)) )
  if (mod < 0 || my::gcd(n, mod) != 1) {
    cout << "error in modinv" << endl;
    exit(1);
  }
  n %= mod;
  if (n < 0) n += mod;
  ll a = mod, b = n, x = 1, y = 0;
  while (b != 0) {
    ll q = a / b, r = a % b;
    a = b;
    b = r;
    y -= q * x;
    swap(x, y);
  }
  y %= mod;
  if (y < 0) y += mod;
  return y;
}

bool isPrime(ll n) {  // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
vector<pair<ll, ll>> primeFac(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////////////////////////////

int main() {
  const ll M = 1e9 + 7;
  int n;
  cin >> n;

  ll all = 1;
  for (int i = 1; i <= n; i++) {
    all *= 10;
    all %= M;
  }

  ll yojisho = 1;
  for (int i = 1; i <= n; i++) {
    yojisho *= 9;
    yojisho %= M;
  }
  yojisho *= 2;
  yojisho %= M;
  ll hoge = 1;
  for (int i = 1; i <= n; i++) {
    hoge *= 8;
    hoge %= M;
  }
  yojisho -= hoge;
  yojisho %= M;
  if (yojisho < 0) yojisho += M;

  ll ans = all - yojisho;
  ans %= M;
  if (ans < 0) ans += M;
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, m;
map<int, int> prime_factor(int n) {
  map<int, int> res;
  for(int i=2; i*i<=n; i++) {
    while(n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if(n != 1) ++res[n];
  return res;
}

const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}


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

  cin >> n >> m;
  auto v = prime_factor(m);

  ll ans = 1;
  COMinit();

  for(auto& x: v) {
    ans = ans * COM(x.second + n - 1, n - 1) % mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 8552
#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,m,d;
    string s[100],rev[100];
    cin>>n>>m>>d;
    for(int i=0;i<n;i++)
        cin>>s[i];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            rev[j]+=s[i][j];
    int ans=0;
    for(int i=0;i<n;i++)
        for(int j=0;j+d<=m;j++)
            if(string(d,'.')==s[i].substr(j,d))
                ans++;
    for(int i=0;i<m;i++)
        for(int j=0;j+d<=n;j++)
            if(string(d,'.')==rev[i].substr(j,d))
                ans++;
    cout<<ans<<endl;
}


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

int main(void) {
    int N, ans=0;
    cin >> N;


    for(int i=1; i<=N; i=i+2){
      int cnt = 0;
      for(int j=1; j<=N; j++){
        if(i%j==0)
          cnt++;
      }
      if(cnt==8)
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    logging.info("Hello!")

    answer = 0

    if N < 10:
        answer = N
    elif N >= 10 and N < 100:
        answer = 9
    elif N >= 100 and N < 1000:
        answer = 9 + N % 100 + 1 + int(N // 100 - 1) * 100
    elif N >= 1000 and N < 10000:
        answer = 909
    elif N >= 10000 and N < 100000:
        answer = 909 + N % 10000 + 1 + int(N // 10000 - 1) * 10000
    else:
        answer = 90909

    print(answer)
        
if __name__ == "__main__":
    main()


Measured memory_bytes: 4212
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    b, e, t = map(int, input().split())
    for k in range(e-b):
        a[t+k],a[b+k] = a[b+k],a[t+k]
             
print(*a)


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

int main()
{
  int N;
  cin >> N;
  vector<double> v(N);

  for (int i = 0; i < N; i++)
  {
    cin >> v.at(i);
  }

  sort(v.begin(), v.end());
  double vv = v.front();
  for (auto vi : v)
  {
    vv = (vv + vi) / 2.0;
  }
  cout << fixed << setprecision(10) << vv << endl;
}


Measured memory_bytes: 3260
#include<stdio.h>
#include<string.h>

#define DOWN -1
#define UP 1
#define EDGE 0

int main()
{
    int n;
    int array[80];
    long long int stock_num = 0;
    long long int total = 1000;
    int current_desition = EDGE;

    scanf("%d", &n);

    for (int i = 0; i<n; i++)
    {
        scanf("%d", &array[i]);
    }

    if (array[0] < array[1])
    {
        current_desition = UP;
        stock_num = total/array[0];
        total = total%array[0];
    } else {
        current_desition = DOWN;
    }

    for (int i = 1; i<(n-1); i++)
    {
        if ((array[i] < array[i+1])&&(current_desition == DOWN))
        {
            current_desition = UP;
            stock_num = total/array[i];
            total = total%array[i];
        } else if ((array[i] > array[i+1])&&(current_desition == UP))
        {
            current_desition = DOWN;
            total += stock_num*array[i];
            stock_num = 0;
        }
    }

    if (stock_num != 0)
    {
        total += stock_num*array[n-1];
    }

    printf("%lld", total);

    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
long long dp[403][403],a[403],n,sum[403];
long long tot(int x,int y){
	return sum[y]-sum[x];
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i],sum[i+1]=sum[i]+a[i];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			dp[i][j]=1e17;
	for(int i=0;i<n;i++)dp[i][i]=0;
	for(int i=1;i<n;i++)
		for(int j=0;j+i<n;j++)
			for(int k=j;k<j+i;k++)
				dp[j][j+i]=min(dp[j][j+i],dp[j][k]+dp[k+1][j+i]+tot(j,j+i+1));
	cout<<dp[0][n-1];
}

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

using namespace std;

int A[105];
int N, M;
vector<int> v;

int main() {
	scanf("%d%d", &N, &M);
	int o = 0;
	for(int i = 1; i <= M; i++) {
		scanf("%d", &A[i]);
		if(A[i] & 1) o++;
	}
	if(o > 2) { puts("Impossible"); return 0; }
	if(M == 1) {
		if(N == 1) printf("1\n1\n1\n");
		else printf("%d\n2\n%d %d\n", A[1], A[1] - 1, 1);
		return 0;
	}

	for(int i = 1; i <= M; i++) if(A[i] & 1) swap(A[i], A[1]);
	for(int i = 2; i <= M; i++) if(A[i] & 1) swap(A[i], A[M]);

	for(int i = 1; i <= M; i++) printf("%d ", A[i]); puts("");

	v.push_back(A[1] + 1);
	for(int i = 2; i < M; i++) v.push_back(A[i]);
	if(A[M] > 1) v.push_back(A[M] - 1);
	printf("%d\n", v.size());
	for(int i : v) printf("%d ", i); puts("");

	return 0;
}

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

using ll = long long;

ll MOD = 1000000007;

ll mod_pow(ll a, ll n) {
    if (n == 0) return 1LL;
    if (n % 2 == 1) return a * mod_pow(a, n-1) % MOD;
    ll h = mod_pow(a, n/2);
    return h * h % MOD;
}

ll fact[101010], inv[101010], sum_inv[101010];

void init() {
    fact[0] = 1;
    for (int i = 1; i < 101010; ++i)
        fact[i] = i * fact[i-1] % MOD;

    inv[0] = 0;
    for (int i = 1; i < 101010; ++i) {
        inv[i] = mod_pow(i, MOD-2);
        sum_inv[i] = (sum_inv[i-1] + inv[i]) % MOD;
    }
}

int N, A[101010];

int main() {
    init();
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];

    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += A[i] * (sum_inv[i+1] + sum_inv[N-i] - 1) % MOD * fact[N] % MOD;
        ans %= MOD;
    }

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


Measured memory_bytes: 3072
//Author: gkashish

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <iomanip>

using namespace std;

#define mod 1000000007
#define x first
#define y second

bool cmp(pair<int, int> a, pair<int, int> b)
{
    return a.x<b.x;
}
int main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(nullptr);
//    cout.tie(nullptr);


    int n, t;
    cin >> n >> t;
    pair<int, long long int> arr[n];
    for (int i = 0; i < n; i++)
        cin >> arr[i].x >> arr[i].y;
    sort(arr, arr+n, cmp);
    vector<long long int> vals(10000, 0);
    long long int res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = t - 1; j >= 0; j--) {
            vals[j + arr[i].x] = max(vals[j + arr[i].x], vals[j] + arr[i].y);
            res = max(res, vals[j + arr[i].x]);
        }
    }
//    for (int i = 0; i < 10000; i++)i
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 384
package main

import (
    "fmt"
    "math"
)

var num int
var nc map[int]int
var ps []int
var ns [][]int
var sum int

func main() {
    fmt.Scan(&num)

    rn := int(math.Sqrt(float64(num)))
    makePl(rn)

    nc = make(map[int]int)
    pf(num)

    //fmt.Println(nc)

    ns = make([][]int, 0)
    for k, v := range nc {
        ns = append(ns, []int{k, v})
    }

    calc(0, 1)

    fmt.Println(sum)
}

// 2^3 = 8 0,2,4,8
// 3^2 = 9 0,3,9
func calc(k, n int) {
    if k >= len(ns) {
        if n > 2 && num%(n-1) != 0 && num/n < n-1 {
            //fmt.Println(n - 1)
            sum += (n - 1)
        }
        return
    }
    //fmt.Println(ns, k)
    p, cnt := ns[k][0], ns[k][1]
    calc(k+1, n) // 0
    for i := 1; i <= cnt; i++ {
        n *= p
        calc(k+1, n)
    }
}

func makePl(n int) {
    var npm = make(map[int]bool)
    for i := 2; i <= n; i++ {
        if b, ok := npm[i]; ok && b {
            continue
        }
        for j := i * 2; j <= n; j += i {
            npm[i] = true
        }
        ps = append(ps, i)
    }
}

func pf(n int) {
    if n <= 1 {
        return
    }
    for _, p := range ps {
        for n%p == 0 {
            nc[p]++
            n /= p
        }
    }
    if n != 1 {
        nc[n]++
    }
}


Measured memory_bytes: 63104
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int INV2 = (MOD + 1) / 2;

int dp[3005][3005];
int n, p[3005];
PII pinv[3005];
int m, u[3005], v[3005];
int cdp[3005];

int main()
{
	scanf("%d%d", &n, &m);
	rep1(i, n) scanf("%d", &p[i]);
	rep(i, m) scanf("%d%d", &u[i], &v[i]);
	
	rep1(i, n) dp[i][i] = 1;
	rep(i, m) rep1(j, n) {
		int cur = 1LL * (dp[j][u[i]] + dp[j][v[i]]) * INV2 % MOD;
		dp[j][u[i]] = dp[j][v[i]] = cur;
	}
	
	rep1(i, n) pinv[i] = MP(p[i], i);
	sort(pinv + 1, pinv + n + 1);
	int ans = 0;
	rep1(i, n) {
		int tot = 0;
		for(int j = n; j >= 1; j --) {
			ans = (ans + 1LL * (tot + 1LL * cdp[j] * INV2 % MOD) * dp[pinv[i].second][j]) % MOD;
			tot = (tot + cdp[j]) % MOD;
		}
		if(i == n || pinv[i].first != pinv[i + 1].first)
		for(int i0 = i; i0 >= 0 && pinv[i0].first == pinv[i].first; i0 --)
		rep1(j, n) cdp[j] = (cdp[j] + dp[pinv[i0].second][j]) % MOD;
	}
	
	rep(i, m) ans = ans * 2 % MOD;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 35584
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e9
typedef long long ll;
typedef pair<ll,ll> P;

ll dp[52][52][2510];

int main(void){
    ll n,a;
    cin>>n>>a;
    vector<ll>x(n);
    for(ll i=0;i<n;i++)cin>>x[i];
    dp[0][0][0]=1;
    for(ll i=1;i<=n;i++){
        for(ll j=0;j<=i;j++){
            for(ll k=0;k<=2500;k++){
                dp[i][j][k]+=dp[i-1][j][k];
                if(j==0)continue;
                if(k>=x[i-1])dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]];
            }
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 50176
#include<stdio.h>
#include<stdlib.h>
#define N 100

int main(){

  int a[N];
  int i,j,len,c,count=0;

  scanf("%d",&len);
  if(len>N)exit(8);
  for(i = 0; i < len; i++){
    scanf("%d",&a[i]);
  }

  for(i = 0; i < len; i++){
    for(j = len -1; i < j; j--){
      if(a[j] < a[j-1]){
	c = a[j];
	a[j] = a[j-1];
	a[j-1] = c;
	count++;
      }
    }
  }
      for(i = 0; i < len; i++){
	if(i == len-1)printf("%d",a[i]);
	else {
	  printf("%d",a[i]);
	  printf(" ");
	}
      }
      
      printf("\n");
      printf("%d\n",count);

      return 0;
  }

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N, 0);
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        A[a]++;
        A[b]++;
    }
    
    bool jdg = true;
    for(int i = 0; i < N; i++){
        if(A[i] % 2 != 0)jdg = false;
    }
    
    if(jdg)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 640