akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ve vector
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())
//using namespace __gnu_pbds;
using namespace std;

// // // functions: find_by_order  & order_of_key
// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

const int inf=(int)2e9;
const long long mod=1000000007; //1E9+7
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

ll powmod(ll a,ll p){
	ll ans=1;
	while(p){
		if(p&1) ans*=a;
		p/=2;a*=a; ans%=mod;a%=mod;
	}
	return ans;
}
ll mdinv(ll a){return powmod(a,mod-2); }


signed main(){
	IOS
	int n;cin>>n;
	int m;cin>>m;
	vvi v(n+2,vi(m+2,0));
	char chl;
	vvi d(n+2,vi(m+2,0));
	d[n][m]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			cin>>chl;
			if(chl=='#') v[i][j]=1;
		}
	for(int i=n;i>=1;i--){
		for(int j=m;j>=1;j--){
			if(i==n && j==m) continue;
			if(!v[i+1][j]){
				d[i][j]+=d[i+1][j];
				if(d[i][j]>=mod) d[i][j]-=mod;
			}
			if(!v[i][j+1]){
				d[i][j]+=d[i][j+1];
				if(d[i][j]>=mod) d[i][j]-=mod;
			}
		}
	}
	cout<<d[1][1];
}


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

int compare_ascending(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

int main(){
    int n;
    scanf("%d", &n);
    int d[n];
    for(int i=0; i<n; i++){
        scanf("%d", &d[i]);
    }
    qsort(d, n, sizeof(int), compare_ascending);
    printf("%d", d[n/2] - d[n/2 - 1]);

    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<map>
#include<string>
using namespace std;

int main() {
	typedef int Freqency;
	typedef string Name;
	map<Name, Freqency> table;
	string name, freqMax = "", lenMax = "";

	while (cin >> name) {
		table[name]++;
		if (table[name] > table[freqMax]) freqMax = name;

		if (name.size() > lenMax.size()) lenMax = name;
	}

	cout << freqMax << " " << lenMax << endl;
}

Measured memory_bytes: 1196
#include <stdio.h>

#define MAX 100000

int gcd(int x, int y);

int main()
{
  int n, a[100000];
  int i, g;
  
  scanf("%d", &n);

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

  g = a[0];

  for (i = 1; i < n; i++) {
    g = gcd(g, a[i]);
  }

  printf("%d\n", g);
  
  return 0;
}

int gcd(int x, int y)
{
  int tmp, z;

  if (x < y) {
    tmp = x;
    x = y;
    y = tmp;
  }

  while (z = x % y) {
    x = y;
    y = z;
  }

  return y;
}

Measured memory_bytes: 512
def IsCommutable(A,B,d):
    if(abs(A-B)<=d):
        return True
    else:
        return False
    
a,b,c,d = map(int,input().split())
#print(a,b,c,d)

Flag = False

if IsCommutable(a,c,d) or (IsCommutable(a,b,d) and IsCommutable(b,c,d)) == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
from  collections import Counter

def main():
    num, avg = map(int, input().split())
    data = list(map(int, input().split()))

    dp = [[[0 for i in range(6000)] for j in range(num + 1)] for k in range(num + 1)]
    dp[0][0][0] = 1

    for i in range(1, num + 1):
        now_card = data[i - 1]
        for j in range(num + 1):
            for k in range(6000):
                # print(i, j, k)
                dp[i][j][k] += dp[i - 1][j][k]
                if k - now_card >= 0 and j - 1 >= 0:
                    dp[i][j][k] += dp[i - 1][j - 1][k - now_card]
        # print(dp[i][j])

    ans = 0
    for i in range(1, num + 1):
        ans += dp[num][i][i * avg]
    print(ans)





if __name__ == '__main__':
    main()


Measured memory_bytes: 158344
node = Struct.new(:key, :left, :right)
root = nil

insert = ->(pa, z) {
  if pa.key > z
    if pa.left
      insert.(pa.left, z)
    else
      pa.left = node.new(z)
    end
  else
    if pa.right
      insert.(pa.right, z)
    else
      pa.right = node.new(z)
    end
  end
}

inorder = ->(x) {
  a = x.left
  inorder.(a) if a
  print " " + x.key.to_s
  a = x.right
  inorder.(a) if a
}

preorder = ->(x) {
  print " " + x.key.to_s
  a = x.left
  preorder.(a) if a
  a = x.right
  preorder.(a) if a
}

find = ->(x, k, bool) {
  if x.key == k
    bool = true
  else
    if x.left && x.key > k
      bool = find.(x.left, k, bool)
    end
    if x.right && x.key < k
      bool = find.(x.right, k, bool)
    end
  end
  bool
}

gets.to_i.times do
  command = gets.split(" ")
  case command[0]
  when "insert"
    if root
      insert.(root, command[1].to_i)
    else
      root = node.new(command[1].to_i)
    end
  when "print"
    inorder .(root)
    puts
    preorder.(root)
    puts
  when "find"
    puts find.(root, command[1].to_i, false) ? "yes" : "no"
  end
end


Measured memory_bytes: 31252
#include<stdio.h>


int main(){
	int card[201],n,m,k,i,ocard[201];
	
	scanf("%d%d",&n,&m);
	for(i=0;i<=2*n;i++)card[i]=i;
	
	while(m>0){
		--m;
		
		scanf("%d",&k);
		if(k==0){
			for(i=1;i<=n;i++){
				ocard[2*i-1]=card[i];
				ocard[2*i]=card[i+n];
			}
		}else{
			for(i=1;i<=2*n;i++){
				if(k+i==2*n){
					ocard[i]=card[2*n];
					continue;
				}
				ocard[i]=card[(k+i)%(2*n)];
			}
		}
		for(i=0;i<=2*n;i++){
			card[i]=ocard[i];
		}
	}
	for(i=1;i<=2*n;i++){
		printf("%d\n",card[i]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#define mod 1000000007
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define srep(i,s,t) for (ll i = s; i < t; i++)
#define drep(i,n) for(ll i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef vector<vector<char>> field_t;
typedef unsigned long long ull;
typedef pair<ll, ll> point_t;


int main()
{
    ll n;
    ll ans=0;
    cin >> n;
    vector<ll> a(n,0); 
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    rep(i,n-1){
        if(i==0){
            ans+=a[i];
        }else{
            if(i%2!=0){
                ans+=a[(i+1)/2];
            }else{
                ans+=a[i/2];
            }
        }
    }
    cout << ans<< endl;
    return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
    u64 A;
    cin >> A;
    
    int Bint, Bsub;
    scanf("%d.%d", &Bint, &Bsub); 

    u64 ans = A * Bint;
    ans +=  (A * Bsub) / 100;
    cout << ans << endl;

    return 0;
}

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n, m;

vpi v;

void read() {
  cin >> n >> m;
  for(int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    v.pb({a, b});
  }
}

bool cmp(pi a, pi b) {
  return a.first < b.first;
}


void solve() {
  sort(v.begin(), v.end(), cmp);

  ll pr = 0;
  for(int i = 0; i < n && m > 0; ++i) {
    int nr = min(m, v[i].second);
    pr += 1ll * nr * v[i].first;
    m -= nr;
  }
  cout << pr;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=1000010;
const ll mod=1e9+7;

unordered_map<int,int> lcm_map;

vector<int> ip(mx,0);

bool isprime(int x){
  if(x==2 || x==3){ return true; }
  if(x<2 || x%2==0){ return false; }
  
  int sqrtx = ceil(sqrt(x));
  for(int i=3; i<=sqrtx; i+=2){ if(x%i==0){ return false; } }
  return true;
}
 
void ipset(int x){                                        //x miman prime set
  for(int i=2; i<x; i++){ ip[i]=(int)isprime(i);}
}

vector<ll> inv,fact,invfact;
void mod_build(int n=1010010){  
  fact.resize(n+1);
  inv.resize(n+1);
  invfact.resize(n+1);
  fact[0]=inv[0]=invfact[0]=1;
  inv[1]=1;
  rep(i,n){
    fact[i+1]=fact[i]*(i+1)%mod;
    if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
    invfact[i+1]=invfact[i]*inv[i+1]%mod;
  }
}
ll perm(int n,int k){
  if(n<0||k<0||k>n)return 0;
  return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
  if(n<0||k<0||k>n)return 0;
  return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
  k%=mod-1;
  if(k<0)k+=mod-1;
  ll ret=1;
  while(k){
    if(k&1)ret=ret*n%mod;
    n=n*n%mod;
    k>>=1;
  }
  return ret;
}

ll lcm_vec(vector<int> &ar){
  int sz=ar.size();
  rep(i,sz){
    unordered_map<int,int> tmp;
    int num=ar[i];
    for(int i=2; i<=num; i++){
      if(!ip[i]){continue;}
      while(num%i==0){ tmp[i]++; num/=i; }
      if(num==1){break;}
      if(ip[num]){ tmp[num]++; break; }
    }
    for(auto it:tmp){
      lcm_map[it.F] = max(lcm_map[it.F], it.S);
    }
  }
  ll ans=1;
  for(auto it:lcm_map){
    ans = (ans*powmod(it.F,it.S))%mod;
  }
  return ans;
}

int main(){
  ipset(1000010);
  mod_build();
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){ cin>>a[i]; }
  ll lcm=lcm_vec(a);
  ll ans=0;
  rep(i,n){
    ll now = lcm;
    now *= inv[a[i]];      //=  now*=powmod(a[i],mod-2));
    now %= mod;
    ans += now;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int counter = 0;
  
  if (s[0] == '1') ++counter;
  if (s[1] == '1') ++counter;
  if (s[2] == '1') ++counter;  
    cout << counter << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	char b;
	scanf("%c",&b);
	if(b=='A'){
		printf("T\n");
	}
	else if(b=='T'){
		printf("A\n");
	}
	else if(b=='G'){
		printf("C\n");
	}
	else if(b=='C'){
		printf("G\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
  char s[10];
  scanf("%s",s);
  if(s[0]=='S'){
    printf("Cloudy\n");
  }
  else if (s[0]=='C'){
    printf("Rainy\n");
  }
  else{
    printf("Sunny\n");
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long LL;

int main(){
  int H,W;
  cin>>H>>W;
  vector<int> alpha(26,0);
  for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	  char alpha_num;
	  cin>>alpha_num;
	  alpha[alpha_num-'a']++;
	}
  }
  int num_2=0;
  int num_1=0;
  if(H%2==1){
	num_2+=W/2;
  }
  if(W%2==1){
	num_2+=H/2;
  }
  if(H%2==1&&W%2==1){
	num_1=1;
  }
  for(int i=0;i<26;i++){
	if(alpha[i]%4==2){
	  num_2--;
	  if(num_2<0){
		cout << "No" << endl;
		return 0;
	  }
	}else if(alpha[i]%4==1){
	  num_1--;
	  if(num_1<0){
		cout << "No" << endl;
		return 0;
	  }
	}
  }
  if(num_1!=0){
	cout << "No" <<endl;
	return 0;
  }
  cout << "Yes" <<endl;
  return 0;
}

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

const int MAX = 100000;

typedef struct process{
  string name;
  int time;
} Process;

int head, tail;
Process q[MAX];

void initializa() { head = tail = 0; }

bool isEmpty() { return head == tail; }

bool isFull() { return head == (tail + 1) % MAX; }

void enqueue(Process p) {
  if (isFull()) {
    fprintf(stderr, "error: full\n");
    exit(1);
  }
  q[tail] = p;
  if (tail + 1 == MAX) tail = 0;
  else tail++;
}

Process dequeue() {
  if (isEmpty()) {
    fprintf(stderr, "error: empty\n");
    exit(1);
  }
  Process p = q[head];
  if (head + 1 == MAX) head = 0;
  else head++;
  return p;
}

int main() {
  int n, q, time = 0; 
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    Process p;
    p.name = s1;
    p.time = atoi(s2.c_str());
    enqueue(p);
  }

  while (!isEmpty()) {
    Process p = dequeue();
    if (p.time > q) {
      time += q;
      p.time -= q;
      enqueue(p);
    } else {
      time += p.time;
      cout << p.name << " " << time << endl;
    }
  }
}

Measured memory_bytes: 6888
using System;
using System.Linq;

namespace question4
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            p.Run();
        }

        void Run()
        {
            var n = int.Parse(Console.ReadLine());
            var alist = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

            if (alist.Count(a => a < 0) % 2 == 0)
            {
                Console.WriteLine(alist.Sum(a => Math.Abs(a)));
            }
            else
            {
                Console.WriteLine(alist.Sum(a => Math.Abs(a)) - 2 * alist.Select(a => Math.Abs(a)).Min());
            }
        }
    }
}


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

int main(){
    int n;
    vector<int> a;
    cin >> n;
    for(int temp;cin >> temp;) a.push_back(temp);
    for(int i=0; i<a.size(); i++){
        cout << a[i] << ((i==n-1)?'\n':' ');
    }
    for(int i=1; i<n; i++){
        int v = a[i];
        int j = i - 1;
        while(j>=0 && a[j]>v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        for(int t=0; t<a.size();t++){
            cout << a[t] << ((t==n-1)?'\n':' ');
        }
    }
    return 0;
}


Measured memory_bytes: 3076
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;

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

Measured memory_bytes: 25044
import sys
sys.setrecursionlimit(pow(10, 6))
# input = sys.stdin.readline

import numpy as np

def pow_matmul(r, n, m):
  if n == 1:
    return r
  if n % 2 == 0:
    _r = pow_matmul(r, n//2, m)
    return np.mod(np.dot(_r, _r), m)
  else:
    _r = pow_matmul(r, n//2, m)
    _r = np.mod(np.dot(_r, _r), m)
    return np.mod(np.dot(r, _r), m)

def main():
  l, a, b, m = map(int, input().split())
  c = [min(max(0, (10**i - a - 1) // b + 1), l) for i in range(19)]
  ans = 0
  r = np.ones((3,3))
  s = np.array([0, a%m, 1])

  for d in range(1, 19):
    dnum = c[d] - c[d-1]
    if dnum==0:
      continue
    r_s = np.array([[pow(10, d, m), 1, 0], [0, 1, (b%m)], [0, 0, 1]])
    r = pow_matmul(r_s, dnum, m)
    s = np.mod(np.dot(r, s), m)
    if c[d] > l:
      break
  print(s[0])


if __name__ == '__main__':
  main()


Measured memory_bytes: 12496
//  [amitdu6ey]
// g++ -std=c++11 -o2 -Wall filename.cpp -o filename
#include <bits/stdc++.h>
#define hell 1000000009
#define bug1(x) cout<<"$ "<<x<<" $"<<endl
#define bug2(x) cout<<"% "<<x<<" %"<<endl
#define bug3(x) cout<<"# "<<x<<" #"<<endl
#define ll long long
#define pb push_back
#define mp make_pair
#define tr(z) for(auto it=z.begin(); it!=z.end(); it++)
#define rloop(i,a,b) for(long long i=a; i>=b;i--)
#define loop(i,a,b) for(long long i=a; i<b; i++)
#define vbool vector< bool >
#define vvbool  vector< vector<bool> >
#define vchar vector<char>
#define vi vector<int>
#define vvi vector< vector<int> >
#define pll pair<long long, long long>
#define vll vector<long long>
#define vvl vector< vector<long long> >
#define ninf numeric_limits<long long>::min()
#define pinf numeric_limits<long long>::max()
#define comp(a,b) (abs(a-b)<1e-9) // to compare doubles
using namespace std;

void solve(){
    ll N, W;
    cin>>N>>W;
    vll wt(N+1,0);
    vll val(N+1,0);
    loop(i,1,N+1) cin>>wt[i]>>val[i];
    vector< vector<ll> > dp(2, vector<ll>(W+1,0));
    loop(i,1,N+1){
        loop(j,1,W+1){
            if(j-wt[i] >= 0)
                dp[1][j] = max(dp[0][j], val[i] + dp[0][j-wt[i]]);
            else
                dp[1][j] = dp[0][j];
        }
        loop(j,1,W+1){
            dp[0][j] = dp[1][j];
        }
    }
    // loop(i,0,N+1){
    //     loop(j,0,W+1){
    //             cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<dp[1][W]<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int test_cases=1;
    //cin>>test_cases;
    while(test_cases--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 5584
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE StrictData #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Char

main :: IO ()
main = do
    (n,m,q) <- (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) . VU.unfoldrN 3 (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    vec <- VU.replicateM q $ (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2, vec VU.! 3)) . VU.unfoldrN 4 (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    let all :: [[Int]]
        all = [ [x1,x2,x3,x4,x5,x6,x7,x8,x9,x10] | x1 <- [1..m], x2 <- [x1..m], x3 <- [x2..m], x4 <- [x3..m], x5 <- [x4..m], x6 <- [x5..m], x7 <- [x6..m], x8 <- [x7..m], x9 <- [x8..m], x10 <- [x9..m]]
    let solve :: [Int] -> [(Int,Int,Int,Int)] -> Int
        solve _ []      = 0
        solve xs ((a,b,c,d):ys) = if (xs !! (b-1)) - (xs !! (a-1)) == c then d+(solve xs ys) else solve xs ys
    print $ maximum [ solve xs (VU.toList vec) | xs <- map (take n) all]

Measured memory_bytes: 7100
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let m1: usize = iterator.next().unwrap().parse().unwrap();
    let _d1: usize = iterator.next().unwrap().parse().unwrap();
    let m2: usize = iterator.next().unwrap().parse().unwrap();
    let _d2: usize = iterator.next().unwrap().parse().unwrap();

    return if m1 != m2 {
        "1".to_string()
    } else {
        "0".to_string()
    };
}


Measured memory_bytes: 2164
x,n = gets.chomp.split.map(&:to_i)
ps = gets.chomp.split.map(&:to_i)

hash = Hash.new(0)
ps.each do |i|
	hash[i] += 1
end
dist = 10 ** 18
ans = -1
(0..101).each do |i|
	if (x - i).abs < dist && hash[i] == 0
		ans = i
		dist = (x - i).abs
	end
end

puts ans


Measured memory_bytes: 14384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare(const void*a,const void *b) {
	return *(int*)a - *(int*)b;
}

int main() {
	int n, t, x, ans = 0, r[200010] = {0};
	char a[200010] = {0};
	scanf("%d%d%d", &n,&t,&x);
	if (n > x * t)printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 1732
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n, m = map(int, input().split())
data = getSomeInputListInt(n)

data_list = [[0] for _ in range(m)]

for i in range(n):
    if data[i][0]-1 < m:
        data_list[data[i][0]-1].append(-data[i][1])

heap_list = []
heapq.heapify(heap_list)
# heapq.heapify(data_list)

ans = 0
for j in range(m):
    for i in range(len(data_list[j])):
        heapq.heappush(heap_list, data_list[j][i])
    a = heapq.heappop(heap_list)
    ans += a

print(-ans)

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


A=[]
for i in range(N):
    A.append(list(map(int,input().split())))
c=0
for i in range(N):
    res=0
    for a,b in zip(A[i],B):
        res+=a*b
    res+=C
    if(res>0):
        c+=1

print(c)

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

using namespace std;

int main (void) {
    int N, M, X, a;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N);
    for ( int i=0; i<N; i++ ) {
        cin >> C.at(i);
        for ( int j=0; j<M; j++ ) {
            cin >> a;
            A.at(i).push_back(a);
        }
    }

    long long cost = 0;
    long long ans = LLONG_MAX;
    vector<int> u(M);
    /* 参考書のすべての組み合わせを試す */
    for ( int i=0; i<(1<<N); i++ ) {
        /* 初期化 */
        cost = 0;
        for ( int j=0; j<M; j++ )
            u.at(j) = 0;
        /* bit が立っている参考書を買った分理解する */
        for ( int j=0; j<N; j++ ) {
            if ( ((i >> j) & 1) == 1 ) {
                cost += C.at(j);
                for ( int k=0; k<M; k++ ) {
                    u.at(k) += A.at(j).at(k);
                }
            }
        }
        /* 全部の理解度がX以上なら候補 */
        bool ok = true;
        for ( int j=0; j<M; j++ ) {
            if ( u.at(j) < X ) {
                ok = false;
                break;
            }
        }
        if ( ok )
            ans = min(ans, cost);
    }

    if ( ans == LLONG_MAX )
        ans = -1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int lli;
#define bs binary_search
void ans()
{
   string s;
   cin>>s;
   if(s[2]==s[3]&&s[4]==s[5])
   {
       cout<<"Yes";
   }
   else
   {
       cout<<"No";
   }
}
int main()
{
    ios::sync_with_stdio(0);
	cin.tie(0);
	ans();
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <deque>
#include <vector>
using namespace std;

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

typedef unsigned long long lu;
const int mod = 1e9 + 7;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x = Sub(x - y); }
inline int Mul(int x, int y) { return (int)((lu)x * y % mod); }
inline int Mul(int x, int y, int z) { return (int)((lu)x * y % mod * z % mod); }

int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

int Inv(int x) { return Pow(x, mod - 2); }

// ----------------------------------------

const int maxn = 3e5;

int n;
char s[maxn + 1];
int dp[3][5], dp2[3][5];

int to[5][3] = {
  3, 0, 1,
  0, 1, 0,
  3, 2, 3,
  4, 3, 2,
  4, 4, 4
};

void Tran0(void) {
  for (int x = 0; x < 3; ++x) {
    for (int y = 0; y < 5; ++y) {
      int x2 = x + 1;
      if (x2 == 3) x2 = 1;
      Add(dp2[x2][y], dp[x][y]);
    }
  }
}

void Tran1(void) {
  for (int x = 0; x < 3; ++x) {
    for (int y = 0; y < 5; ++y) {
      Add(dp2[0][to[y][x]], dp[x][y]);
    }
  }
}

void TranE(void) {
  Tran1();
}

int main(void) {
  scanf("%s", s);
  n = strlen(s);
  FILLA(dp, 0);
  dp[0][0] = 1;

  for (int i = 0; i < n; ++i) {
    FILLA(dp2, 0);
    if (s[i] != '0') Tran1();
    if (s[i] != '1') Tran0();
    COPYA(dp2, dp);
  }
  FILLA(dp2, 0);
  TranE();
  COPYA(dp2, dp);

  int ans = dp[0][4];
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 512
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
mod =10**9+7
def solver(k,n):
    ans=int((k*(2*n-k+1)-k*(k-1))/2)+1
    ans=ans%mod
    return ans 
def do():
    sol=0
    n,k=INTM()
    for i in range(k,n+1):
        sol+=solver(i,n)
        sol=sol%mod
        #print(solver(i,n))
    print(sol+1)
        
if __name__ == '__main__':
    do()

Measured memory_bytes: 9224
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  ll all = 0;
  REP(i, N) {
    cin >> A[i];
    all ^= A[i];
  }
  REP(i, N) { A[i] &= ~all; }

  ll rank = 0;
  ll j = 0;
  RREP(i, 60) {
    for (j = rank; j < N; j++) {
      if (A[j] & (1LL << i))
        break;
    }
    if (j == N)
      continue;
    if (j > rank)
      A[rank] ^= A[j];
    for (j = rank + 1; j < N; j++) {
      A[j] = min(A[j], A[j] ^ A[rank]);
    }
    rank++;
  }
  ll x = 0;
  REP(i, N) x = max(x, x ^ A[i]);
  cout << (x * 2) + all << endl;

  return 0;
}


Measured memory_bytes: 1024
import collections
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
k= []
l = []
f = 0
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")
a = ai()
x = lma()
k = [0]*a
s = 0
t = 0
for i in range(a):
    if i%2==0:
        k[s] = x[-1-i]
        s+=1
    else:
        k[-t-1] = x[-1-i]
        t+=1
s = str(k[0])
for i in range(1,a):
    s+=" "+str(k[i])
print(s)

Measured memory_bytes: 25536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  string S;
  cin>>S;
  int N=S.size(),ans=0;
  rep(i,0,(1<<N-1)){
    bitset<10> A(i);
    int sum=0;
    string X;
    X+=S[0];
    rep(i,0,N-1){
      if(A.test(i)){
        sum+=stoll(X);
        X="";
        }
      X+=S[i+1];
      }
    sum+=stoll(X);
    ans+=sum;
    }
  cout<<ans<<endl;
  }


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

bl = al[:]
bl[0] = bl[0] * 4
bl[1] = bl[1] * 2
bl[2] = bl[2] * 1
bl[3] = bl[3] / 2

idx = bl.index(min(bl))
idx2 = bl[:3].index(min(bl[:3]))
if idx == 3:
    print(n//2*al[idx] + (n%2) * bl[idx2])
else:
    print(bl[idx]*n)

Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
using namespace std;

int h[200200];

int main()
{
	int n, k; scanf ("%d %d", &n, &k);
	for (int i = 0; i < n; i++) scanf ("%d", &h[i]);
	sort(h, h + n);
	reverse(h, h + n);
	long long a = 0;
	for (int i = k; i < n; i++) a += h[i];
	printf ("%lld\n", a);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll k, a, b;
    cin >> k >> a >> b;
    if(b - a <= 2){
        cout << k+1 << endl;
        return 0;
    }
    ll q = 1;
    q += min(a-1, k);
    k -= min(a-1, k);
    if(k == 0){
        cout << q << endl;
        return 0;
    }
    // a, k
    q += (b-a)*(k/2);
    k %= 2;
    if(k == 1){
        q++;
        k--;
    }
    cout << q << endl;
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<ll> v(n);
  vector< P > t(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
    t[i]=P(v[i],i);
  }

  sort(t.begin(),t.end());

  vector<ll> ans(n);
  for(int i=0;i<n;i++){
    ll fi=t[i].first;
    ll se=t[i].second;
    if(i<n/2){
      ans[se]=t[n/2].first;
    }else{
      ans[se]=t[n/2-1].first;
    }
  }

  for(int i=0;i<n;i++){
    cout<<ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 8448
A, B, K = (int(i) for i in input().split()) 
 
a = set()
b = set()
 
for i in range(1, A + 1):
    if A % i == 0:
        a.add(i)
 
for i in range(1, B + 1):
    if B % i == 0:
        b.add(i)

c = list(a & b)
c.sort()
c.reverse()
print(c[K-1])

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

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int A, B;
	string S;
	bool ans = true;

	cin >> A >> B >> S;

	rep(i, S.length()) {
		if (i + 1 <= A && S[i] == '-') ans = false;
		else if (i + 1 == A + 1 && S[i] != '-') ans = false;
		else if (i + 1 > A + 1 && S[i] == '-') ans = false;
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
o=->a,n{n<1?1:a**n[0]*o[a,n/2]**2%M}
eval'N,A,B,C='+`dd`.split*?,
a=o[A*=t=o[A+B,-2+M=10**9+7],N]
b=o[B*=t,N]
f=f=1,*(1..2*N).map{|i|f=f*i%M}
N.times{|i|$.=($.+(N+i)*f[N+i-1]*o[f[N-1]*f[i],M-2]*(a+b)*100*t)%M
a=a*B%M
b=b*A%M}
p$.

Measured memory_bytes: 5128
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll, ll>
#define vi vector<ll>
#define vii vector<ii>
#define vs vector<string>
#define si set<ll>
#define endl "\n"
#define pb push_back
#define x first
#define y second
//g++ -std=c++11 -Wall -Wextra -pedantic-errors main.cpp -o main
const int ms = 1e5 + 5, base = 31, mod = 1e5 + 7;
using namespace std;

vi H;

int dp[ms];

int solve(int i){

	if (i == H.size()-1) return 0;
	
	if (i == H.size()-2) return abs(H[i] - H[i+1]);
	
	if (dp[i] != -1) return dp[i];
	
	int one = abs(H[i] - H[i+1]) + solve(i+1);
	int two = abs(H[i] - H[i+2]) + solve(i+2);
	
	return dp[i] = min(one, two);
	
}

int main(){
	ios::sync_with_stdio(false), cin.tie(0);
	memset(dp, -1, sizeof(dp));
	int n; cin >> n;
	while(n--){
		int a; cin >> a;
		H.pb(a);
	}
	cout << solve(0) << endl;
	
	//for (auto x : H) cout << x << " "; cout << endl;
	
	
	return 0;
}


Measured memory_bytes: 6260
#include <bits/stdc++.h>
using namespace std;
char a[5],b[5];
int ans;
int main(){
	scanf("%s",a+1);
	scanf("%s",b+1);
	for(int i=1;i<=3;i++)
		if(a[i]==b[i]) ++ans;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * http://abc075.contest.atcoder.jp/tasks/abc075_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		final int H = sc.nextInt();
		final int W = sc.nextInt();
		int[][] f = new int[H+2][W+2];
		for(int y=1; y<=H; y++){
			String s = sc.next();
			for(int x=1; x<=W; x++){
				f[y][x] = s.charAt(x-1)=='.' ? 0 : 1;
			}
		}
		sc.close();
		
		for(int y=1; y<=H; y++){
			for(int x=1; x<=W; x++){
				if(f[y][x]==1){
					System.out.print('#');
				}else{
					int ans = 0;
					ans += f[y-1][x-1];
					ans += f[y-1][x];
					ans += f[y-1][x+1];
					ans += f[y][x-1];
					ans += f[y][x+1];
					ans += f[y+1][x-1];
					ans += f[y+1][x];
					ans += f[y+1][x+1];
					System.out.print(ans);
				}
			}
			System.out.println();
		}
	}

}


Measured memory_bytes: 24148
#include <stdio.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int A,B,C,D;
  scanf("%d%d%d%d",&A,&B,&C,&D);

  printf("%d\n",max(0,min(B,D)-max(A,C)));

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
int main()
{
    ll a , b , c , res = 0;
    cin >> a >> b >> c;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0 && res <= 1e7)
    {
        ll a1 = b / 2 + c / 2 , b1 = a / 2 + c / 2 , c1 = a / 2 + b / 2;
        a = a1;
        b = b1;
        c = c1;
        res++;
    }
    cout << (res > 1e7 ? -1 : res);
}


Measured memory_bytes: 256
#import <stdio.h>



int main() {
    int N;
    scanf("%d", &N);

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

    int reversed_flag;
    int swap_count = 0;

    // sort
    do {
        reversed_flag = 0;

        for (int i = N - 1; i > 0; i--) {
            if (V[i] < V[i - 1]) {
                int temp_element = V[i];
                V[i] = V[i - 1];
                V[i - 1] = temp_element;

                reversed_flag = 1;
                swap_count++;
            }
        }
    } while (reversed_flag);

    // output answer
    for (int i = 0; i < N; i++) {
        printf("%d", V[i]);
        if (i < N - 1) {
             printf(" ");
         } else {
             printf("\n");
         }
    }

    printf("%d\n", swap_count);
    return 0;
}



Measured memory_bytes: 2040
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 210000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
long long dp[610][310][310];
int p[610];
int rev[610];
int main(){
	int a;scanf("%d",&a);
	int L=0;
	for(int i=0;i<a*2;i++)rev[i]=-1;
	for(int i=0;i<a*2;i++){
		scanf("%d",p+i);
		if(p[i]>0){
			p[i]--;
			rev[p[i]]=i;
		}
	}
	init_C(1100);
	for(int i=0;i<a*2;i+=2){
		if(p[i]==-1&&p[i+1]==-1)L++;
	}
	dp[0][0][0]=1;
	for(int i=0;i<a*2;i++){
		for(int j=0;j<=a;j++){
			for(int k=0;k<=a;k++){
				if(dp[i][j][k]==0)continue;
				// printf("%d %d %d: %lld\n",i,j,k,dp[i][j][k]);
				if(rev[a*2-1-i]!=-1){
					if(p[rev[a*2-1-i]^1]!=-1){
						dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%mod;continue;
					}
					if(j)dp[i+1][j-1][k]=(dp[i+1][j-1][k]+dp[i][j][k])%mod;
					dp[i+1][j][k+1]=(dp[i+1][j][k+1]+dp[i][j][k])%mod;
				}else{
					if(j)dp[i+1][j-1][k]=(dp[i+1][j-1][k]+dp[i][j][k])%mod;
					if(k)dp[i+1][j][k-1]=(dp[i+1][j][k-1]+dp[i][j][k]*k)%mod;
					dp[i+1][j+1][k]=(dp[i+1][j+1][k]+dp[i][j][k])%mod;
				}
			}
		}
	}

	printf("%lld\n",dp[a*2][0][0]*fact[L]%mod);
}

Measured memory_bytes: 456832
ss = int(input())
r = 10
while 1:
	cnt = 0
	for a in range(r):
		for b in range(r):
			for c in range(r):
				for d in range(r):
					if a+b+c+d==ss: cnt+=1
	print(cnt)
	try: ss = int(input())
	except EOFError: break


Measured memory_bytes: 7600
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=110;
int n,m,a[N],b[N];
int main(){
	scanf("%d%d",&n,&m);
	int odd=0;
	for(int i=1;i<=m;i++)
	  scanf("%d",&a[i]),odd+=(a[i]&1);
	if(m==1){
	  if(a[1]==1) printf("1\n1\n1\n");
	  else printf("%d\n2\n%d 1\n",a[1],a[1]-1);
	  return 0;
	}
	if(odd>2) puts("Impossible");
	else{
	  for(int i=2;i<=m;i++)
		if(a[i]&1) (a[1]&1)?swap(a[m],a[i]):swap(a[1],a[i]);
	  int t=0; if(a[1]>1) b[++t]=a[1]-1;
	  for(int i=2;i<m;i++) b[++t]=a[i];
	  b[++t]=a[m]+1;
	  for(int i=1;i<=m;i++) printf("%d ",a[i]);
	  printf("\n%d\n",t);
	  for(int i=1;i<=t;i++) printf("%d ",b[i]);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
	int res = 0;
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] != t[i])
			++res;
	}

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

	return 0;
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  int x, y;
  cin >> x >> y;
  if (x <= 8 && y <= 8) cout << "Yay!" << endl;
  else cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
#! /usr/bin/perl

use strict;
use warnings;

my $in = <>;
chomp($in);
my ($a, $b, $c, $d) = split(/\s+/, $in);

my $n1 = int($c / $b);
$n1 ++ if $c % $b != 0;

my $n2 = int($a / $d);
$n2 ++ if $a % $d != 0;

if($n1 <= $n2) {
    print "Yes\n";
}else{
    print "No\n";
}


Measured memory_bytes: 5136
#include <iostream>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    a = (a + 11) % 13;
    b = (b + 11) % 13;
    if (a > b)
        puts("Alice");
    else if (a < b)
        puts("Bob");
    else
        puts("Draw");
}

Measured memory_bytes: 256
s = input()
n = len(s)

for bit in range(1 << (n -1)):

    f = s[0]

    for i in range(n -1):
        if bit & (1 << i):
            f += '+'
        else:
            f += '-'
        f += s[i + 1]

    if eval(f) == 7:
        print(f + '=7')
        break


Measured memory_bytes: 9080
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int c[10][100000];
int k[100000];
bool d[10];
int w,h,v;
void REC(int q){
	rep(i,h)d[i]=q%2,q/=2;
	return;
}
int main(){
	while(true){
	cin>>h>>w;
	if(!h&&!w)break;
	v=1;
	rep(i,w)k[i]=0;
	rep(i,h){
		rep(j,w){
			cin>>c[i][j];
			k[j]+=c[i][j];
		}
		v*=2;
	}
	int ans=0;
	rep(i,v){
		REC(i);
		rep(j,h)if(d[j])rep(r,w){k[r]++;if(c[j][r])k[r]-=2;}
		int cnt=0;
		rep(j,w)cnt+=max(k[j],h-k[j]);
		ans=max(cnt,ans);
		rep(j,h)if(d[j])rep(r,w){k[r]--;if(c[j][r])k[r]+=2;}
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3420
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int H = sc.nextInt();
      int M = sc.nextInt();
      
      // 算出
      double degree = getDegree(H, M);
      double result = cosFormula(A, B, degree);
      
      // 出力
      System.out.println(result);
    }
    
    // 時針と分針の間の角を求める関数
    public static double getDegree(int H, int M){
      double degH = 30 * H + 0.5 * M;
      double degM = 6 * M;
      double degHM = 0;
      if(degH <= degM){
        degHM = degM - degH;
      }else{
        degHM = degH - degM;
      }
      if(degHM > 180){
        degHM = 360 - degHM;
      }
      
      return degHM;
    }
    
    // 余弦定理を用いて辺を求める関数
    public static double cosFormula(int A, int B, double degree){
      double hen = Math.sqrt(A*A + B*B - 2*A*B * Math.cos(Math.toRadians(degree)));
      
      return hen;
    }

}

Measured memory_bytes: 35992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=998244353;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n;cin>>n;
    ll res=1;
    vi v(n);
    rep(i,n)cin>>v[i];
    rep(i,n)if(v[i]==0)dame(0);
    rep(i,n){
        ll a=v[i];
        if(res>1000000000000000001/a)dame(-1);
        res*=a;
    }
    if(res<=1000000000000000000)out(res);
    else out(-1);
}

Measured memory_bytes: 4052