akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;


int main(){
    int k,x;
    cin>>k>>x;
    if(k*500>=x){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if((s.at(0)==s.at(1))||(s.at(1)==s.at(2))||(s.at(2)==s.at(3))){
    cout<<"Bad"<<endl;
  }else{
    cout<<"Good"<<endl;
  }
}

Measured memory_bytes: 256
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap());
    let a = it.next().unwrap();
    let b = it.next().unwrap();
    if a + b < 10 {
        println!("{}", a + b);
    } else {
        println!("error");
    }
}


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

using namespace std;
using ll = long long;

// hs[i] = número de ocorrências do valor 1 no bit i dos números 1, 2, ..., N
// xorN = 1 ^ 2 ^ ... ^ N
ll xorN(ll N)
{
//    cout << "N = " << N << '\n';

    if (N == 0)
        return 0;

    vector<int> hs(64, 0);

    for (int k = 60; k >= 0; --k)
    {
        ll mask = (1LL << k);

        if (mask > N)
            continue;

        // Todos os números até a maior potência de 2 menor que N tem k-ésimo bit
        // ligado
        hs[k] += (N - mask + 1);

        // Os números até a maior potência de 2 menos 1 distribuem o mesmo número
        // de 1s em todas as posições
        for (int j = 0; j < k; ++j)
            hs[j] += (mask / 2);

        N -= mask;
    }

    //cout << "hs = ";
    //for (int k = 0; k < 20; ++k)
    //    cout << hs[k] << (k == 19 ? '\n' : ' ');

    ll ans = 0;

    for (int k = 60; k >= 0; --k) 
    {
        if (hs[k] % 2)
            ans += (1LL << k);
    }

//cout << "ans = " << ans << '\n';
    return ans;
}

ll solve(ll A, ll B)
{
    return xorN(A - 1) ^ xorN(B);
}

int main()
{
    ios::sync_with_stdio(false);

    ll A, B;
    cin >> A >> B;

    auto ans = solve(A, B);

    cout << ans << '\n';

    return 0;
}


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



int main() {
    int n, y;
    cin >> n >> y;
    int cnt[3];
    
    y /= 1000;
    
    for (int i = 0; i <= n; i++) {
        for (int ii = 0; ii <= (n - i); ii++) {
            if ((i + ii * 5 + (n - i - ii) * 10) == y) {
                cout << (n - i - ii) << " " << ii << " " << i << endl;
                return 0;
            }
        }
    }
    
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
import std;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
  int n = scan!int;
  long p = scan!long;
  long[] as = scan.split("").to!(long[]);
  
  long ans;
  if(10 % p == 0){
    foreach(i, a; as) if(a % p == 0) ans += i + 1;
  }
  else{
    int[long] cnt = [0: 1];
    long x = 0;
    long m = 1;
    foreach_reverse(a; as){
      x += a * m, x %= p;
      m *= 10, m %= p;
      if(x !in cnt) cnt[x] = 0;
      ans += cnt[x];
      cnt[x] += 1;
    }
  }
  ans.writeln;
}

Measured memory_bytes: 9840
#python3
from collections import deque
def f(x, y):
    return (x+y)/2

def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    while len(v) > 1:
        v.sort()
        a = v.pop(0)
        b = v.pop(0)
        v.append(f(a, b))
    print("{0:.12f}".format(v[0]))
main()


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

int main(){
#ifdef LOCAL
	freopen("inp.txt", "r", stdin );
	freopen("ans.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	if(s=="SUN") cout << 7 << '\n';
	if(s=="MON") cout << 6 << '\n';
	if(s=="TUE") cout << 5 << '\n';
	if(s=="WED") cout << 4 << '\n';
	if(s=="THU") cout << 3 << '\n';
	if(s=="FRI") cout << 2 << '\n';
	if(s=="SAT") cout << 1 << '\n';
}


Measured memory_bytes: 3600
module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
import           Data.Ord
--import           Data.Vector.Algorithms.Search
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.IO                 as AIO
import qualified Data.Set                      as S


getVUIL :: IO (VU.Vector Int)
getVUIL = VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
readI :: BSC8.ByteString -> Int
readI = fst . fromJust . BSC8.readInt
readIL :: BSC8.ByteString -> [Int]
readIL = map readI . BSC8.words
getI :: IO Int
getI = readI <$> BSC8.getLine
getIL :: IO [Int]
getIL = readIL <$> BSC8.getLine

getNIS :: Int -> IO [(Int, BSC8.ByteString)]
getNIS 0 = return []
getNIS n = do
    [aFst, aSnd] <- BSC8.words <$> BSC8.getLine
    next         <- (getNIS (n - 1))
    return ((readI aFst, aSnd) : next)

il2ss :: [Int] -> String
il2ss = unwords . map show

il2sn :: [Int] -> String
il2sn = unlines . map show

modNum = 10 ^ 9 + 7
newtype Mint = M Int
instance Num Mint where
    (M a) + (M b) = M $ mod (a + b) modNum
    (M a) - (M b) = M (a - b)
    (M a) * (M b) = M $ mod (a * b) modNum
    fromInteger a = M $ mod (fromInteger a) modNum
    abs (M a) = M $ abs a
    signum (M a) = M $ signum a
instance Show Mint where
    show (M a) = show (mod a modNum)

int2MInt :: Int -> Mint
int2MInt a = M (mod a modNum)

main = do
    --[aN, aM] <- getIL
    aS' <- VU.fromList <$> getLine
    aT  <- VU.fromList <$> getLine
    let cList    = getCandidates aS' aT
    let filtered = filter (/= []) cList
    putStrLn $ if filtered == [] then "UNRESTORABLE" else minimum filtered

getCandidates :: VU.Vector Char -> VU.Vector Char -> [[Char]]
getCandidates s' t =

    let lS' = VU.length s' - 1
        lT  = VU.length t - 1
    in  map
            (\x ->
                let target = (getCandidates' s' t x 0 lT [])
                in  if target /= []
                        then
                            (compCandidate s' 0 (x - 1))
                            ++ target
                            ++ (compCandidate s' (x + lT + 1) lS')
                        else []
            )
            [0 .. lS' - lT]


getCandidates' s' t x y lT ret
    | y > lT = ret
    | otherwise = if (s' VU.! (x + y) == '?') || (s' VU.! (x + y) == (t VU.! y))
        then getCandidates' s' t x (y + 1) lT (ret ++ [t VU.! y])
        else []

compCandidate s x1 x2
    | x1 > x2 = []
    | otherwise = map
        (\y -> let target = s VU.! y in if target == '?' then 'a' else target)
        [x1 .. x2]


Measured memory_bytes: 636
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstdlib>

#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <tuple>

using namespace std;

using ii = pair < int, int >;
using ti = tuple < int, int, int>;
using lint = long long;

const int N = 105;

int a[N];

vector < int > v;
bool c[N];

int n;
int mx;

bool rem() {
	sort(v.begin(), v.end());
	auto t = v.end();
	t--;
	mx = *t;
	for (int i = 0; i <= mx; i++) {
		int val;
		val = max(mx - i, i);
		bool o = false;
		for (int i = 0; i < n; i++) {
			if (!c[i] && v[i] == val) {
				c[i] = true;
				o = true;
				break;
			}
		}
		if (!o)return false;
	}
	return true;
}

bool chk() {
	if (n == mx-1)return true;
	int lb = mx / 2 + mx % 2 + 1;
	int ub = mx;
	for (size_t i = 0; i < n; i++) {
		if (c[i])continue;
		if (v[i] < lb || ub < v[i]) {
			return false;
		}
	}
	return true;
}

#define Ia

int main() {
#ifdef I
	freopen("in.txt", "r", stdin);
#endif
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
		v.push_back(a[i]);
	}
	if (rem()) {
		if (chk()) {
			puts("Possible");
		}
		else {
			puts("Impossible");
		}
	}
	else {
		puts("Impossible");
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  cerr<<"hoge\n";
  ll ans = 1;
  REP(i,n){
    ans *= x;
  }
  return ans;
}

ll cube(ll x){
  return x*x*x;
}


/*
n k

n k 2*10^5
 */
int n,k;

int main(){
  cin>>n>>k;
  if(k%2==0){
    cout<< pow(n/k,3) + pow((2*n+k)/(2*k),3) <<endl;
  } else {
    cout<< pow(n/k,3) <<endl;    
  }
  return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l, r;
  l = a + b; r = c + d;
  
  if(l > r) cout << "Left" << endl;
  else if(l < r) cout << "Right" << endl;
  else cout << "Balanced" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    N %= K;
    ll ans = min(N, K - N);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define tezz std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int mod=1e9+7;
int main() {
    tezz
    ll k;
    string s;
    cin>>s>>k;
   int n=s.length();
    int res1=0,res2=0;
    if(s==string(n,s[0])){
        cout<<n*k/2<<endl;
        return 0;
    }
    else{
        res1=0;
        res2=0;
        for(int i=0;i<s.length()-1;i++){
            if(s[i%n]==s[(i+1)%n]){
                ++res1;
                ++i;
                
            }
            
        }
        for(int i=0;i<2*s.length()-1;i++){
            if(s[i%n]==s[(i+1)%n]){
                ++res2;
                ++i;
                
            }
        }
        cout<<res1+(res2-res1)*(k-1)<<endl;
    }
    return 0;
    
}

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

using namespace std;

int n;
int a[100010],b[100010],c[100010];
int f[100010][3];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",a+i,b+i,c+i);
	}
	for(int i=1;i<=n;i++){
		f[i][0]=a[i]+max(f[i-1][1],f[i-1][2]);
		f[i][1]=b[i]+max(f[i-1][0],f[i-1][2]);
		f[i][2]=c[i]+max(f[i-1][0],f[i-1][1]);
	}
	printf("%d\n",max(f[n][0],max(f[n][1],f[n][2])));

	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>

int main(){
	int a, b, n;
	char op;
	while(1){
		scanf("%d %c %d", &a, &op, &b);
		if(op == '?') break;
		if(op == '+'){
			n=a+b;
		}else if(op == '-'){
			n=a-b;
		}else if(op == '*'){
			n=a*b;
		}else if(op == '/'){
			n=a/b;
		}
		printf("%d\n", n);
	}

	return 0;
}

Measured memory_bytes: 1028
H,W=map(int,input().split())
s=[]
for i in range(H):
  s.append(input())
# print(s)

def isValid(i,j):
  # print("(i,j) = (" + str(i) + "," + str(j) + ")")
  st=False
  if i>0:
    st|=s[i-1][j]=='#'
  if i+1<H:
    st|=s[i+1][j]=='#'
  if j>0:
    st|=s[i][j-1]=='#'
  if j+1<W:
    st|=s[i][j+1]=='#'
  return st

for i in range(H):
  for j in range(W):
    if s[i][j]=='.':
      continue
    elif not isValid(i,j):
      print("No")
      exit(0)
print("Yes")



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, x);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void) {
  int a, b;
  cin >> a >> b;
  (a + b >= 24) ? cout << (a + b) - 24 << endl : (cout << a + b << endl);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#define LL long long
using namespace std;
const int maxn=1e5+10;
struct node
{
    LL pos,val;
} a[maxn];
bool cmp(node a,node b)
{
    if(a.val==b.val)return a.pos<b.pos;
    return a.val>b.val;
}
int n;
LL ans[maxn];
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(ans,0,sizeof ans);
        for(int i=1; i<=n; i++)
        {
            scanf("%lld",&a[i].val);
            a[i].pos=i;
        }
        sort(a+1,a+n+1,cmp);
        a[n+1].val=0;
        LL tmp=1;
        int num=a[1].pos;
        for(int i=2; i<=n+1; i++)
        {
            if(a[i].val==a[i-1].val) tmp++;
            else ans[num]+=(a[i-1].val-a[i].val)*tmp,tmp++;
            if(a[i].pos<num) num=a[i].pos;
        }
        for(int i=1;i<=n;i++)printf("%lld\n",ans[i]);
    }
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int N;
set<int> s;
int main() {
  cin >> N;

  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (s.count(a)) {
      s.erase(a);
    } else {
      s.insert(a);
    }
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 4864
H,W = map(int,input().split())
S = [[i for i in input().split()] for _ in range(H)]

for h in range(H):                  
    for w in range(W):                      
        if S[h][w] == "snuke":              
            break
    else:
        continue 
    break
    
print(chr(ord("A")+w) + str(h+1))


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

struct Card {char suit, value; };

void bubble(struct Card A[], int N) {
    for (int i=0; i<N; i++) {
        for (int j=N-1; j>=i+1; j--) {
            if (A[j].value < A[j-1].value) {
                Card t = A[j]; A[j] = A[j-1]; A[j-1] = t;
            }
        }
    }
}

void selection(struct Card A[], int N) {
    for (int i=0; i<N; i++) {
        int minj = i;
        for (int j=i; j<N; j++) {
            if (A[j].value < A[minj].value ) minj = j;
        }
        Card t = A[i]; A[i] = A[minj]; A[minj] = t;
    }
}

void print(struct Card A[], int N) {
    for (int i=0; i<N; i++) {
        if (i>0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

//バブルソートと選択ソートの結果を比較
bool isStable(struct Card C1[], struct Card C2[], int N) {
    for (int i=0; i<N; i++) {
        if (C1[i].suit != C2[i].suit ) return false;
    }
    return true;
}

int main() {
    Card C1[100], C2[100];
    int N;
    char ch;

    cin >> N;
    for (int i=0; i<N; i++) {
        cin >> C1[i].suit >> C1[i].value;
    }

    for (int i=0; i<N; i++) C2[i] = C1[i];

    bubble(C1, N);
    selection(C2, N);

    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);
    if (isStable(C1, C2, N)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    return 0;
}



Measured memory_bytes: 3100
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
x = [0] * 26
h = 0
for i in range(1, d + 1):
    t = int(input()) - 1
    for j in range(26):
        if j == t:
            h += s[i - 1][j]
            x[t] = i
        else:
            h -= ((i - x[j]) * c[j])
    print(h)

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define INF LLONG_MAX/2
#define PI acos(-1.0)
//#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    string s;
    cin>>s;
    int n=s.size();
    reverse(ALL(s));
    Vi dp(n+1);
    REP(i,0,n){
        int k=ctoi(s[i]);
        dp[i+1]=(dp[i]+k*mypow(10,i,2019))%2019;
    }

//    vout(dp);

    map<int,int> ma;
    REP(i,0,n+1){
        ma[dp[i]]++;
    }
    int ans=0;
    for(auto x : ma){
        ans += x.second*(x.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    int a, b, c, d, p, t, h;
    cin >> a >> b >> c >> d >> p;
    t = a * p;
    h = b + (p>c?p-c:0) * d;
    if(t<h) cout << t << endl;
    else cout << h << endl;
    return 0;
}

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

int main() {
int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if ( L == R){
    cout << "Balanced";
  }
  else if(L > R){
    cout << "Left";
  }
  else{
    cout << "Right";
  }
  
}


Measured memory_bytes: 256
import sys
from collections import defaultdict

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


def main():

    N, M = map(int, input().split())
    G = defaultdict(lambda: [])

    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)

    # print(G)

    def dfs(v, is_visited):
        if sum(is_visited) == N:
            return 1
        ans = 0
        for u in G[v]:
            if is_visited[u]:
                continue
            is_visited[u] = True
            ans += dfs(u, is_visited)
            is_visited[u] = False

        return ans

    is_visited = [False] * N
    is_visited[0] = True

    print(dfs(0, is_visited))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;

vi A;
ll n;

ll Get_mx() {
	vi Ne = {3};
	rep(i,0,n-1) Ne.pb(((Ne[i]/A[i+1])+1)*A[i+1]-1);
	rep(i,0,n) if(A[i] > Ne[i]) return -1;
	return Ne[n-1];
}

ll Get_mn() {
	ll mn = 2;
	rep(i,0,n-1) {
		mn = max(mn,A[i+1]);
		if((mn/A[i+1]+1)*(A[i+1])-A[i+1] >= mn) mn = (mn/A[i+1]+1)*(A[i+1])-A[i+1];
		else mn = (mn/A[i+1]+1)*A[i+1];
	}
	return mn;
}

int main() {
    cin.sync_with_stdio(false);
	cin >> n;
	A = vi(n);
	rep(i,0,n) cin >> A[i];
	reverse(A.begin(),  A.end());
	if(A[0] > 2) cout << -1 << endl;
	else {
		ll mx = Get_mx();
		ll mn = Get_mn();
		if(mx == -1 || mn == -1 || mx < mn) cout << -1 << endl;
		else cout << mn << " " << mx << endl;
	}
    return 0;
}


Measured memory_bytes: 2168
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

const int maxn = 1e5 + 5;
map<int, bool> ok;
int dp[maxn];

int main(){
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
		#if __cplusplus >= 201103L
		auto start = steady_clock::now();
		#endif
	#endif
	int n = read(), m = read();
	rep(i, 1, m) {
		int x = read();
		ok[x] = true;
	}
	for (int i = 1; i <= n; ++i) {
		if (ok[i]) continue;
		else {
			if (ok[i - 1] == 0 && i == 1) {
				dp[i] = 1;
			}else if (ok[i - 2] == 0 && i == 2) {
				dp[i] += 1;
				if (ok[i - 1] == 0) dp[i] += 1;
			}else {
				if (ok[i - 1] == 0) {
					(dp[i] += dp[i - 1])  %= mod;
				}
				if (ok[i - 2] == 0) {
					(dp[i] += dp[i - 2]) %= mod;
				}
			}
		}
		// pr(i);prln(dp[i]);
	}
	cout << (dp[n] % mod) << endl;
	#ifdef LOCAL
		#if __cplusplus >= 201103L
		auto end = steady_clock::now();
		duration<double> time_span = duration_cast<duration<double>>(end - start);;
		printf("Total time: %.6fs\n", time_span.count());
		#endif
	#endif
	return 0;
}

Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W; cin >> H >> W;
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N) { cin >> a[i]; }
	vector<vector<int>>v(H, vector<int>(W, -1));
	int k = 0, j = 0;
	bool r = true;
	rep(i, 0, N) {
		for (; a[i]; a[i]--) {
			v[k][j] = i + 1;

			if (r)j++;
			else j--;

			if (j == W) {
				k++;
				j--;
				r = false;
			}
			else if (j == -1) {
				k++;
				j++;
				r = true;
			}

		}
	}

	rep(i, 0, H)rep(j, 0, W) {
		cout << v[i][j] << (j == W - 1 ? '\n' : ' ');
	}

	return 0;
}










//#include "bits/stdc++.h"
//using namespace std;
//#ifdef _DEBUG
//#include "dump.hpp"
//#else
//#define dump(...)
//#endif
//
////#define int long long
//#define rep(i,a,b) for(int i=(a);i<(b);i++)
//#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
//#define all(c) begin(c),end(c)
//const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
//const int MOD = (int)(1e9) + 7;
//const double PI = acos(-1);
//const double EPS = 1e-9;
//template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
//template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
//int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 };
//signed main() {
//	cin.tie(0);
//	ios::sync_with_stdio(false);
//	int H, W; cin >> H >> W;
//	int N; cin >> N;
//	vector<int> a(N); rep(i, 0, N) { cin >> a[i]; }
//	vector<vector<int>>v(H, vector<int>(W, -1));
//
//	auto within = [&](int x, int y) {
//		return 0 <= x&&x < H && 0 <= y&&y < W;
//	};
//	rep(i, 0, N) {
//		rep(j, 0, H)rep(k, 0, W) {
//			queue<tuple<int, int, int>>q;
//			q.push(make_tuple(j, k, i));
//			while (!q.empty()) {
//				auto u = q.front(); q.pop();
//
//				int x = get<0>(u), y = get<1>(u), z = get<2>(u);
//				if (!within(x, y))continue;
//				if (v[x][y] != -1)continue;
//				if (a[z] == 0)continue;
//
//				bool f = false;
//				rep(i, 0, 4) {
//					int X = x + dx[i], Y = y + dy[i];
//					if (!within(X, Y))continue;
//					if (v[X][Y] == z)f = true;
//				}
//				if (f) { v[x][y] = z; a[z]--; }
//
//				rep(i, 0, 4) {
//					int X = x + dx[i], Y = y + dy[i];
//					if (!within(X, Y))continue;
//					if (v[X][Y] != -1)continue;
//					if (a[z] == 0)continue;
//					q.push(make_tuple(X, Y, z));
//				}
//
//				rep(i, 0, H)rep(j, 0, W) {
//					cout << v[i][j] << (j == W - 1 ? '\n' : ' ');
//				}
//			}
//		}
//	}
//	rep(i, 0, H)rep(j, 0, W) {
//		cout << v[i][j] << (j == W - 1 ? '\n' : ' ');
//	}
//	return 0;
//}

Measured memory_bytes: 384
#include <bits/stdc++.h>
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  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    VL a(x), b(y), c(z);
    rep(i,x) cin >> a[i];
    rep(i,y) cin >> b[i];
    rep(i,z) cin >> c[i];

    sort(rall(a));
    sort(rall(b));
    sort(rall(c));

    VL ans;
    rep(l, x){
        rep(m, y){
            rep(n, z){
                if ((l+1) * (m+1) * (n+1) <= k) ans.push_back(a[l] + b[m] + c[n]);
                else break;
            }
        }
    }
    sort(rall(ans));
    rep(i,k) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4328
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 1000000
#define INF 1e9

int gcd(int a, int b){

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

//辺を表す構造体　(行先、容量、逆辺の場所)
struct edge{
    int to, cap, rev;
};

//vector<vector<edge> > G(MAX_V);       //グラフの隣接リスト表現
bool used[MAX_V];                    //DFSですでに調べたかのグラフ


// from から to へ向かう容量 cap の辺をグラフに張る
void add_edge(int from, int to, int cap, vector<vector<edge> >& G){

    edge F;
    edge T;
    F.to = to;
    F.cap = cap;
    F.rev = G[to].size();
    G[from].push_back(F);

    T.to = from;
    T.cap = 0;
    T.rev = G[from].size() - 1;
    G[to].push_back(T);    
}

//増加パスをDFSで探す
int dfs(int v, int t, int f, vector<vector<edge> >& G){
    if(v == t) return f;
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        edge &e = G[v][i];                          //すごい
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f, e.cap), G);
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;            //もっとすごい
                return d;
            }
        }
    }
    return 0;
}

//s から t への最大流を求める
int max_flow(int s, int t, vector<vector<edge> >& G){
    int flow = 0;
    while(1){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF, G);
        if(f == 0) return flow;
        flow += f;
    }
}

int main(){
    
    while(1){

        int m, n; cin >> m >> n;
        if(!m) break;
  
        vector<vector<edge> > G(MAX_V);
        vector<int> b(m);
        vector<int> r(n);
        for(int i = 0; i < m; i++) cin >> b[i];
        for(int i = 0; i < n; i++) cin >> r[i];

        //入力
        //xはuに属する
        //yはvに属する
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                if(gcd(b[i], r[j]) != 1){
                    int x = i + 1;
                    int y = j + 1;
                    y += m;
                    add_edge(x, y, 1, G);
                }
            }
        }

        for(int i = 1; i <= m; i++) add_edge(0, i, 1, G);
        for(int i = m + 1; i <= m + n; i++) add_edge(i, m + n + 1, 1, G);
        
        cout << max_flow(0, m + n + 1, G) << endl;
    }
    return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n; cin >> n;
	
	for(int i = 0; i <= 100/4; i++){
		for(int j = 0; j <= 100/7; j++){
			int $ = 4*i + 7*j;
			if($ == n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
def up_right(x,y):
    s = ""
    for i in range(y):
        s += 'U'
    for i in range(x):
        s += 'R'
    return s
def left_down(x,y):
    s = ""
    for i in range(y):
        s += 'D'
    for i in range(x):
        s += 'L'
    return s

sx,sy,tx,ty = map(int,input().split())
xdis = tx - sx
ydis = ty - sy
ans1 = ""
ans2 = ""
ans1 = up_right(xdis,ydis) + left_down(xdis,ydis)
ans2 = 'L' + up_right(xdis+1,ydis+1) + 'D' + 'R' + left_down(xdis+1,ydis+1) +'U'
print(ans1+ans2)

Measured memory_bytes: 3064
#include <iostream>
int main(){
    std::string s;
    std::cin >> s;
    long long ans = 0;
    long long count = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != 'A' && s[i] != 'T' && s[i] != 'C' && s[i] != 'G'){
            ans = std::max(ans, count);
            count = 0;
        }
        else count++;
    }
    ans = std::max(ans, count);
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
s = input()
t = input()

u = s * (len(t) // len(s) + 2)

t_add = t + "."


def partial_match_table(word):
    table = [0] * (len(word) + 1)
    table[0] = -1
    i, j = 0, 1

    while j < len(word):
        matched = word[i] == word[j]

        if not matched and i > 0:
            i = table[i]
        else:
            if matched:
                i += 1
            j += 1
            table[j] = i

    return table


table_tx = partial_match_table(t_add)

match = [0] * len(s)

i = j = 0
while i < len(u) and j < len(t_add):
    if u[i] == t_add[j]:
        i += 1
        j += 1
    elif j == 0:
        i += 1
    else:
        j = table_tx[j]
    if j == len(t_add) - 1:
        match[(i - j) % len(s)] = 1


# search
searched = [0] * len(s)
longest = 0
infinity = False
for i in range(len(s)):
    if searched[i]:
        continue
    searched[i] = 1
    p = i
    right = 0
    while match[p]:
        right += 1
        p = (p + len(t)) % len(s)
        searched[p] = 1
        if p == i:
            infinity = True
            break
    left = 0
    p = i
    while match[(p - len(t)) % len(s)]:
        left += 1
        p = (p - len(t)) % len(s)
        searched[p] = 1
        if p == i:
            infinity = True
            break
    if left + right > longest:
        longest = left + right

if infinity:
    print(-1)
else:
    print(longest)


Measured memory_bytes: 70316
# coding=utf-8
from math import sin, pi, sqrt, cos


def main():
    a, b, CinDeg = map(int, raw_input().split())
    CinRad = pi * CinDeg / 180
    S = 0.5 * a * b * sin(CinRad)
    c = sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(CinRad))
    L = a + b + c
    h = S / (0.5 * a)
    print S
    print L
    print h

if __name__ == '__main__':
    main()

Measured memory_bytes: 4424
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int a, b, c;
    int tmp;
 
    scanf("%d%d%d", &a, &b, &c);
    if (a > b) tmp = a, a = b, b = tmp;
    if (b > c) {
        tmp = b, b = c, c = tmp;
        if (a > b) tmp = a, a = b, b = tmp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2064
N, M = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(M)]

Lma = 0
Rmi = N + 1
for L, R in LR:
  Lma = max(L, Lma)
  Rmi = min(R, Rmi)

print(max(0, Rmi - Lma + 1))

Measured memory_bytes: 27332
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
int n;
ll a[200000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0;i<n;i++) cin>>a[i];
    ll b[n];
    for(int i=0;i<n;i++){
        b[i]=a[i]-i-1;
    }
    sort(b,b+n);
    ll axis;
    if(n%2==0){
        axis=(b[n/2]+b[n/2-1])/2;
    }
    else{
        axis=b[n/2];
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=abs(b[i]-axis);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3328
import sys
from io import StringIO
import unittest
import math
from decimal import Decimal, ROUND_FLOOR

def resolve():
    # s = input()
    # n = int(input())
    a, b = map(float, input().split())
    # l = [list(map(int, input().split())) for _ in range(n)]

    ans = Decimal(str(a)) * Decimal(str(b))

    print(ans.quantize(Decimal('0'), rounding=ROUND_FLOOR))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """198 1.10"""
        output = """217"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1 0.01"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1000000000000000 9.99"""
        output = """9990000000000000"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16984
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(auto i=0; i<(n); i++)

const int mod = 1000000007;

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

  int n;
  cin >> n;

  vector<int> l(n);
  fillInt(l, n);

  sortv(l);

  long res = 0;

  for(int i = 2; i < n; i++) {
    rep(j, i-1) {
      int k = lbv(l, l[i]-l[j]+1);
      if(k<=j) k=j+1;
      res+=max(0, i-k);
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 256
from itertools import combinations
from collections import defaultdict
d = defaultdict(int)

n = int(input())
for _ in range(n):
    d[input()[0]] += 1

ans = 0
for com in combinations('MARCH', 3):
    ans += d[com[0]] * d[com[1]] * d[com[2]]
print(ans)

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

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            int[] od = new int[N];
            String S = Console.ReadLine();
            String[] L = S.Split(' ');

            for(int i=0; i<N; i++)
            {
                A[i] = int.Parse(L[i]);
                od[i] = i;
            }

            Array.Sort(A, od);

            for (int i = 0; i < N; i++)
            {
                Console.Write(od[i] + 1);
                if(i != N - 1)
                {
                    Console.Write(" ");
                }
            }





        }
    }
}

Measured memory_bytes: 23004
#Satoooh
N, K = map(int, input().split())
*V, = map(int, input().split())#タプルとして入力
ans = 0#格納されている宝石が負ばかりなら、何もしない

for l in range(K + 1):#左から最大K個取り出す
	for r in range(K - l + 1):
    #右から取り出すのはK-L個、左からL個取り出しているので
		inHand = []#手持ちを格納する配列
		if l + r > N:  # Nを超えてしまうありえない場合を処理
			break#ありえないケースはブレイク
		# inHandに左からl個、右からr個の要素を追加
		inHand = V[: l]
		inHand.extend(V[N - r:])
		tmp = sum(inHand)  # 現時点でのinHandの和をtmpとして負の要素をtmpから引いていく
		# inHand中の負の要素を消せるだけ消す
		inHand.sort()
		for i in range(min(K - l - r, l + r)):
			if inHand[i] >= 0:#負の要素だけ消す
				break
			tmp -= inHand[i]#負の要素は手持ちしないことにする
		ans = max(ans, tmp)#求めるのは手持ちの価値の最大値

print(ans)

Measured memory_bytes: 3064
#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;
int v[100002];

void read() {
  cin >> n;
}

void solve() {
  v[0] = 0; v[1] = 1; v[2] = 2; v[3] = 3; v[4] = 4; v[5] = 5; v[6] = 1; v[7] = 2; v[8] = 3; v[9] = 1;
  for(int i = 10; i <= n; ++i) {
    v[i] = v[i - 1] + 1;
    for(int j = 6; j <= i; j *= 6)
      v[i] = min(v[i - j] + 1, v[i]);
    for(int j = 9; j <= i; j *= 9)
      v[i] = min(v[i - j] + 1, v[i]);
  }
  cout << v[n] << "\n";
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  //cin >> t           // PLEASE REMOVE IT IF NEEDED
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
using P = std::pair<int,int>;
const int INF = 1e17;
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<P> a,b;
	int sum=0;
	rep(i,n) {
		std::string s;
		std::cin >> s;
		int A=0;
		int D=0;
		/*
		for(auto c:s) {
			A += (c=='(')?1:-1;
			D=std::min(D,A);
		}
		if(A>=0) a.emplace_back(D,A);
		else b.emplace_back(D-A,-A);
		sum+=A;
		*/
		std::stack<char> stack;
		for(auto c:s) {
			if(stack.empty()) {
				stack.emplace(c);
				continue;
			}
			char x = stack.top();
			if(x==')' || x==c) stack.emplace(c);
			else {
				stack.pop();
			}
		}
		while(!stack.empty()) {
			char x = stack.top();
			stack.pop();
			if(x=='(') A++;
			else {
				A--;
				D--;
			}
		}
		if(A>=0) a.emplace_back(D,A);
		else b.emplace_back(D-A,-A);
		sum+=A;
	}
	std::sort(a.rbegin(),a.rend());
	std::sort(b.rbegin(),b.rend());
	int ok=true;
	int curr=0;
	for(auto p:a) {
		if(curr+p.first<0) ok=false;
		curr+=p.second;
	}
	for(int i=b.size()-1;i>=0;i--) {
		auto p = b[i];
		if(curr+p.first-p.second<0) ok=false;
		curr-=p.second;
	}
	if(sum==0 && ok) print("Yes");
	else print("No");
	return 0;
}


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

using namespace std;


int main()
{
   int x,ans=0;
   int temp;
   cin>>x;
   if(x>=500)
   {
       ans=x/500;
       x=x%500;
       ans=ans*1000;
   }

   if(x)
   {
       temp=x/5;
       temp=temp*5;
       ans=ans+temp;
        }

        cout<<ans<<endl;
        return 0;

}




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

using namespace std;

// template copied from others
namespace __output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);
 
    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }
 
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.first,", ",x.second,"}");
    }
    template<class T, bool pretty = true> void prContain(const T& x) {
        if (pretty) pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?pretty?", ":" ":"",a), fst = 0;
        if (pretty) pr("}");
    }
    template<class T> void pc(const T& x) { prContain<T, false>(x); pr("\n"); }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }
 
    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps();
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...);
    }
}
using namespace __output;

#ifdef DBG
    #define TRACE(x) x
#else
    #define TRACE(x)
#endif

#define p(x) TRACE(pr(x); cout << endl;)
#define __pn(x) pr(#x, " = ")
#define pd(...) TRACE(__pn((__VA_ARGS__)); ps(__VA_ARGS__); cout << flush;)

const int B = 2019;

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

    string s;
    cin >> s;
    int N = s.length();

    vector<int> prefix(N);
    for (int i = 0; i < N; ++i) {
        if (i > 0) {
            prefix[i] += (prefix[i - 1] * 10) % B;
        }
        prefix[i] = (prefix[i] + s[i] - '0') % B;
    }

    long long total = 0;

    vector<int> freq(B);
    freq[0] = 1;
    for (int i = 0; i < N; ++i) {
        total += freq[prefix[i]];

        freq[prefix[i]]++;

        vector<int> next_freq(B);
        for (int j = 0; j < B; ++j) {
            next_freq[(j * 10) % B] += freq[j];
        }
        freq = next_freq;
    }

    cout << total << "\n";

    return 0;
}


Measured memory_bytes: 4340
#include<stdio.h>
int nums[100000+1];
int main()
{
	int num,n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&num);
		nums[num]=i+1;
	}
	for(int i=1;i<=n;i++)printf("%d ",nums[i]);
 } 

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

int main() {
    int a, b;
    cin >> a >> b;
    int c = a * b;
    if (c % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inc(l,i,r) for (int i=l;i<=r;i++)
#define dec(r,i,l) for (int i=r;i>=l;i--)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define ___ putchar(10);
using namespace std;
typedef long long ll;

int A, B, C; 

int main() {
	cin >> A >> B >> C;
	cout << B + (C-A-B>=1 ? A+B+1 : C);
}

Measured memory_bytes: 256
H,W=map(int,input().split())
S=['$'*(W+2)]
for i in range(H):
    S.append('$'+input()+'$')
S.append('$'*(W+2))

def count(T,h,w):
    re=0
    re+=[T[h+1][w],T[h+1][w+1],T[h+1][w-1],T[h][w+1],T[h][w-1],\
         T[h-1][w],T[h-1][w+1],T[h-1][w-1]].count('#')
    return re

ans=['']*(H+2)
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=='#':
            ans[i]+='#'
        else:
            ans[i]+=str(count(S,i,j))
            
for i in ans:
    if i!='':
        print(i)

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

int main()
{
	int r,g;

	cin >> r >> g ;

	if (r%g==0) {
		cout << 0 << endl;
	}

	else if(r%g>0){
		cout << 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256