akhauriyash/Code-Regression huggingface dataset:
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};
const main=()=>{
  let n=tn(),ans=0
  for(let i=1;i<=n;i++){
    if(i%2==1){
      let c=0
      for(let j=1;j<=i;j++){
        if(i%j==0)c++
      }
      if(c==8)ans++
    }
  }
  to(ans)
}
main()


Measured memory_bytes: 7500
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	int INF = 1 << 28;
	double EPS = 1e-9;

	int n;
	String s, t;
	
	void run() {
		n=sc.nextInt();
		for(int i=0;i<n;i++){
			s=sc.next();
			t=sc.next();
			solve();
		}
	}

	void solve() {
		int[] a=new int[256];
		a['m']=1000;
		a['c']=100;
		a['x']=10;
		a['i']=1;
		int v1=0;
		for(int i=0;i<s.length();i++){
			if(Character.isDigit(s.charAt(i))){
				v1+=(s.charAt(i)-'0')*a[s.charAt(i+1)];
				i++;
			}else{
				v1+=a[s.charAt(i)];
			}
		}
		int v2=0;
		for(int i=0;i<t.length();i++){
			if(Character.isDigit(t.charAt(i))){
				v2+=(t.charAt(i)-'0')*a[t.charAt(i+1)];
				i++;
			}else{
				v2+=a[t.charAt(i)];
			}
		}
		int v=v1+v2;
//		debug(v1,v2,v);
		char[] cs={'i','x','c','m'};
		String ans="";
		for(int i=0;i<4;i++){
			if(v%10==1){
				ans=cs[i]+ans;
			}else if(v%10>1){
				ans=(v%10)+""+cs[i]+ans;
			}
			v/=10;
		}
//		debug(ans);
		println(ans);
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s) {
		System.out.print(s);
	}

	void println(String s) {
		System.out.println(s);
	}

	public static void main(String[] args) {
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
def main():
    a = list(map(int, input().split()))
    ans = 'No'
    a.sort()
    if a[0] == a[1] and a[1] != a[2]:
        ans = 'Yes'
    elif a[0] != a[1] and a[1] == a[2]:
        ans = 'Yes'
    print(ans)

main()

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int>a(n);
  int sum = 0;
  rep(i,n) {
    cin >> a[i];
    sum += a[i];
  }
  int ans = 0;
  rep(i,n){
    if(4*m*a[i] < sum) continue;
    else ans++;
  }
  if(ans>= m) puts("Yes");
  else puts("No");
  return 0;
}


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

struct node{
  int key;
  node *l,*r,*p;
};

node* root;

node* make_node(int a){
  node* ret = new node();
  ret->key = a;
  ret->p = ret->l = ret->r = NULL;
  return ret;
}

void insert(node *z){
  node *y = NULL;
  node *x = root;
  while( x != NULL ){
    y = x;
    if( z->key < x->key )
      x = x->l;
    else
      x = x->r;
  }
  z->p = y;
  if( y == NULL )
    root = z;
  else if( z->key < y->key )
    y->l = z;
  else
    y->r = z;
}

bool find(int k){
  node* x = root;
  while( x != NULL ){
    if( k < x->key )
      x = x->l;
    else if( k > x->key )
      x = x->r;
    else
      return true;
  }
  return false;
}

void delete_node(node *x){
  if( x->l == NULL && x->r == NULL ){
    if( x->p != NULL ){
      if( x->p->l == x ) x->p->l = NULL;
      else x->p->r = NULL;
    }
    delete x;
  } else if( x->l == NULL ){
    if( x->p != NULL ){
      if( x->p->l == x ) x->p->l = x->r;
      else x->p->r = x->r;
    }
    x->r->p = x->p;
    delete x;
  } else if( x->r == NULL ){
    if( x->p != NULL ){
      if( x->p->l == x ) x->p->l = x->l;
      else x->p->r = x->l;
    }
    x->l->p = x->p;
    delete x;
  } else
    assert(false);
}

void del(int key){
  node* x = root;
  while( x != NULL ){
    if( key < x->key )
      x = x->l;
    else if( key > x->key )
      x = x->r;
    else
      break;
  }
  if( x == NULL ) return;

  if( x->l && x->r ){
    node* y = x->r;
    while( y->l  )
      y = y->l;
    x->key = y->key;
    delete_node(y);
  } else {
    delete_node(x);
  }
}

void inorder(node* n){
  if( n == NULL) return;
  inorder(n->l);
  cout << " " << n->key;
  inorder(n->r);
}

void preorder(node* n){
  if( n == NULL ) return;
  cout << " " << n->key;
  preorder(n->l);
  preorder(n->r);
}

int main(){
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    string s; int k;
    cin >> s;
    if( s[0] == 'i' ) {
      cin >> k;
      insert(make_node(k));
    } else if( s[0] == 'f' ){
      cin >> k;
      if( find(k) ) cout << "yes" << endl;
      else cout << "no" << endl;
    } else if( s[0] == 'p' ){
      inorder(root); cout << endl;
      preorder(root); cout << endl;
    } else {
      cin >> k;
      del(k);
    }
  }
}

Measured memory_bytes: 19960
n=gets.to_i
a=gets.split.map(&:to_i)

len=a.sum
half_a=0
half_b=0
i=0
while (half_a+a[i])<=len/2
    half_a+=a[i]
    i+=1
end
i.upto(n-1) do |j|
    half_b+=a[j]
end
puts [half_b-half_a,(half_a+a[i])-(half_b-a[i])].min


Measured memory_bytes: 28076
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
  int a,b;
  cin>>a>>b;
  if(b%a==0)
    cout<<a+b;
  else
    cout<<b-a;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main ()
{
	int a,b;

	cin >> a >> b;

	if (a == 0)
	{
		if (b >= 1868 && b <= 1911)
		{
			cout << 'M' << 44 - (1911 - b) << endl;
		}
		else if (b <= 1925)
		{
			cout << 'T' << 14 - (1925 - b) << endl;
		}
		else if (b <= 1988)
		{
			cout << 'S' << 63 - (1988 - b) << endl;
		}
		else
		{
			cout << 'H' << 28 - (2016 - b) << endl;
		}
	}
	else
	{
		if (a == 1)
		{
			cout << 1867 + b << endl;
		}
		else if (a == 2)
		{
			cout << 1911 + b << endl;
		}
		else if (a == 3)
		{
			cout << 1925 + b << endl;
		}
		else
		{
			cout << 1988 + b << endl;
		}
	}
	//tired = DX
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const ll INF = 1001001001000000;
 
ll dp[110][100100];
int main(){
  int n, W;
  cin >> n >> W;
  ll w[110], v[110];
  rep(i, n) cin >> w[i] >> v[i];
 
  rep(i, 110) rep(j, 100100) dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i, n) {
    for(int j = 0; j <= 100000; ++j) {
      dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
      if(j - v[i] >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
    }
  }
  
  ll ans = 0;
  rep(i, 100001) {
    if(dp[n][i] <= W) ans = i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 86272
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, i;

int main()
{
	in >> N >> i;
	out << N - i + 1 << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

const int maxn = 10005;

int h,w,n;
int A[maxn],B[maxn][maxn];

int main(){
//	freopen("in15.txt","r",stdin);
	scanf("%d%d%d", &h, &w, &n);
	for(int i=1;i<=n;i++){
		scanf("%d",&A[i]);//颜色i的数量 
	}
	//h行  w列 
	int index = 0;
	for(int i=1;i<=n;i++){
		//分配颜色
		while(A[i]--){
			//第index个元素
			int c = index-(index/w*w);
			if(index/w%2 == 0){//0 2 4顺着的行 
				B[index/w][c] = i;
			}else{//逆着的行 
				B[index/w][w-1-c] = i;
			} 
			index++; 
		} 	
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(j<w-1){
				printf("%d ",B[i][j]);
			}else{
				printf("%d\n", B[i][j]);
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);

		for (int i = 1; i <= 10000; i++) {
			double e = (double) (i * 0.08);
			double t = (double) (i * 0.1);

			e = Math.floor(e);
			t = Math.floor(t);

			if (e == a && b == t) {
				System.out.println(i);
				return;
			}
		}
		System.out.println("-1");
	}
}

Measured memory_bytes: 32672
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    double solve(int L) {
        double x = L / 3.0;
        return pow(x, 3);
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    Solution sol;
    int L;
    cin >> L;

    cout << sol.solve(L) << "\n";

    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    ans = 0
    for i in range(1, n + 1):
        ans += i * (n + 1 - i)

    used = set()

    for _ in range(n - 1):
        u, v = map(int, readline().split())
        u, v = min(u, v), max(u, v)
        if (u, v) not in used:
            ans -= u * ((n + 1) - v)
            used.add((u, v))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 98144
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,a[300010],num;
bool h[100010];

int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>a[i];
		h[a[i]]=true;
	}
	repn(i,100000) if(h[i]) num++;
	if(num%2==1) cout<<num<<endl;
	else cout<<num-1<<endl;
	rt0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    while(cin >> H >> W,H+W){
        rep(i,H){
            rep(j,W)cout << (i == 0 or i == H-1 or j == 0 or j == W-1 ? "#":".");
            cout << endl;
        }
        cout << endl;
    }
}





Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;

void Main(){
    int N, K;
    scanf("%d%d", &N, &K);
    K--;
    long long A[N];
    for(int i = 0; i < N; i++)scanf("%lld", &A[i]);
    
    long long ans = INF;
    for(int i = 0; i < N - K; i++){
        long long time = max(abs(A[i]), abs(A[i + K]));
        if(A[i] * A[i + K] < 0)time += min(abs(A[i]), abs(A[i + K])) * 2;
        if(time < ans)ans = time;
    }
    printf("%lld\n", ans);
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
}

Measured memory_bytes: 1024
n, q = map(int, input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rank = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x_root = self.Find_Root(x)
        y_root = self.Find_Root(y)

        if(x_root == y_root):
            return
        # 違う木に属していた場合rankを見てくっつける方を決める
        if self.rank[x_root] >= self.rank[y_root]:
            self.rank[x_root] += self.rank[y_root]
            self.root[y_root] = x_root
        else:
            self.rank[y_root] += self.rank[x_root]
            self.root[x_root] = y_root

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return self.rank[self.Find_Root(x)]

tree = UnionFind(n)

for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        tree.Unite(x, y)
    else:
        is_same = tree.isSameGroup(x, y)
        print(1 if is_same else 0)


Measured memory_bytes: 5816
{-# OPTIONS_GHC -Wno-tabs #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	[a, b, c, d] <- readIntToList <$> BS.getLine
	print . maximum $ do
		x <- [a, b]
		y <- [c, d]
		return $ x * y


Measured memory_bytes: 3728
/*************************************************************************
	> File Name: A.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Created Time: 2020/4/12 19:55:02
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
int main()
{
/*
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
*/
	int n;
	scanf("%d",&n);
	bool flag=0;
	while(n){
		int x=n%10;
		if(x==7) flag=1;
		n/=10;
	}
	if(flag) printf("Yes");
	else printf("No");
	return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max(a*b,c*d);
  return 0;
}


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

#define int long long
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define vint vector<int>
#define vchar vector<char>
#define vstr vector<string>
#define pb(n) push_back(n)

signed main(){
  int A,B,N,M,count=0,count2=0,count3=0,stack=0;
  str S,T;
  int C='A'-'a';
  cin>>N>>M;
  vstr W(N);
  vint l(N);
  rep(0,N)cin>>l.at(i);
  sort(all(l));
  rep(1,M+1)count+=l.at(N-i);
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#define MAX 201
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int>a(N);
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	int number = 0;
	while (true)
	{
		for (int i = 0; i < N; i++)
		{
			if (a[i] % 2 == 1)
			{
				cout << number << endl;
				return 0;
			}
			else
			{
				a[i] = a[i] / 2;
			}

		}
		number = number + 1;
	}
	
}

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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> ab(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    ab.at(i) = make_pair(b, a);
  }
  
  vector<pair<int, int>> cd(N);
  for (int i = 0; i < N; i++) {
    int c, d;
    cin >> c >> d;
    cd.at(i) = make_pair(c, d);
  }

  sort(ab.rbegin(), ab.rend());
  sort(cd.begin(), cd.end());

  int ans = 0;
  // 青から見て、次の条件を満たす赤とペアにする
  // x座標が小さいかつ、y座標が最も大きい
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int c = cd.at(i).first;
      int d = cd.at(i).second;
      
      int a = ab.at(j).second;
      int b = ab.at(j).first;
      
      if (c > a && d > b) {
        ab.at(j).first = 2 * N;
        ans++;
        break;
      }
    }
  }

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


Measured memory_bytes: 256
using System;

namespace Attack_Survival
{
    class Program
    {
        static void Main(string[] args)
        {
            //N=参加者
            //Q=正解数
            //k＝ポイント数
            string[] NKQ = Console.ReadLine().Split(' ');
            int[] Participant = new int[int.Parse(NKQ[0])];
            for (int i = 0; i < int.Parse(NKQ[0]);i++)
            {
                Participant[i] = 0;
            }
            for(int i = 0; i < int.Parse(NKQ[2]); i++)
            {
                int Answer = int.Parse(Console.ReadLine());
                Participant[Answer-1] += 1;
            }
            
            for(int i = 0; i < int.Parse(NKQ[0]); i++)
            {
                if (int.Parse(NKQ[2])-Participant[i] < int.Parse(NKQ[1]))
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
        }
    }
}


Measured memory_bytes: 17756
#include <queue>
#include <cstdio>
#include <iostream>
typedef std :: pair <int, int> pii;
typedef std :: pair <pii, pii> pII;
const int N = 2e5 + 5;
const int inf = 1e9;
inline int Get() {
	char ch;
	while ((ch = getchar()) < '0' || ch > '9');
	int Num = ch - '0';
	while ((ch = getchar()) >= '0' && ch <= '9')
		Num = (Num << 3) + (Num << 1) + ch - '0';
	return Num;
}
int n, a[N];
pII val[N << 3];
std :: priority_queue <pII, std :: vector <pII>, std :: greater <pII> > que;
void build(int k, int l, int r) {
	if (l == r) {
		val[k] = std :: make_pair(std :: make_pair(a[l], l), std :: make_pair(inf, 0));
		return;
	}
	
	int mid = l + r >> 1;
	build(k << 1, l, mid), build((k << 1) | 1, mid + 1, r);
	if ((l ^ mid) & 1) {
		val[k].first = std :: min(val[k << 1].first, val[(k << 1) | 1].first);
		val[k].second = std :: min(val[k << 1].second, val[(k << 1) | 1].second);
	}
	else {
		val[k].first = std :: min(val[k << 1].first, val[(k << 1) | 1].second);
		val[k].second = std :: min(val[k << 1].second, val[(k << 1) | 1].first);
	}
	return;
}
pII query(int k, int l, int r, int x, int y) {
	if (x <= l && r <= y) return val[k];
	
	int mid = l + r >> 1;
	if (y <= mid) return query(k << 1, l, mid, x, y);
	if (x > mid) return query((k << 1) | 1, mid + 1, r, x, y);
	
	pII vl = query(k << 1, l, mid, x, y), vr = query((k << 1) | 1, mid + 1, r, x, y), res;
	
	if (((std :: max(l, x)) ^ mid) & 1) {
		res.first = std :: min(vl.first, vr.first);
		res.second = std :: min(vl.second, vr.second);
	}
	else {
		res.first = std :: min(vl.first, vr.second);
		res.second = std :: min(vl.second, vr.first);
	}
	
	return res;
}
void insert(int l, int r) {
	pII res = query(1, 1, n, l, r);
	que.push(std :: make_pair(res.first, std :: make_pair(l, r)));
}
int main() {
	n = Get();
	for (int i = 1; i <= n; ++i) a[i] = Get();
	build(1, 1, n);
	
	insert(1, n);
	while (!que.empty()) {
		pII cur = que.top(); que.pop();

		int l = cur.second.first, r = cur.second.second;
		
		int posL = cur.first.second;
		int posR = query(1, 1, n, posL + 1, r).first.second;
		
		printf("%d %d ", a[posL], a[posR]);
		
		if (l < posL - 1) insert(l, posL - 1);
		if (posL + 1 < posR - 1) insert(posL + 1, posR - 1);
		if (posR + 1 < r) insert(posR + 1, r);
	}
}

Measured memory_bytes: 13300
n = int(input())
s = input()

min_dict = {}
max_dict = {}
for i in range(10):
    for j in range(n):
        if s[j] == str(i):
            min_dict[i] = j
            break
    for j in range(n-1, -1, -1):
        if s[j] == str(i):
            max_dict[i] = j
            break

res = 0
for k1, v1 in min_dict.items():
    for k2, v2 in max_dict.items():
        if v1 >= v2:
            continue
        else:
            res += len(list(set(list(s[v1+1:v2]))))

print(res)


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

using namespace std;

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

    int ans = 0;
    // D = pow(D, 2);
    for(int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        if(pow(x, 2) + pow(y, 2) <= pow(D, 2)) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)

void solve(int y, int m, int d) {
    int all_day = 0; // since 01/01/01 until 1000/01/01
    FOR(year, 1, 1000) all_day += (year%3==0 ? 20*10 : 20*5 + 19*5);
    ++all_day;

    int by_lastyear = 0, by_lastmonth = 0;
    FOR(year, 1, y) by_lastyear += (year%3==0 ? 20*10 : 20*5 + 19*5);
    FOR(month, 1, m) {
        if(y % 3 == 0) {
            by_lastmonth += 20;
        } else {
            by_lastmonth += (month % 2 == 0 ? 19 : 20);
        }
    }

    int ans = all_day - by_lastyear - by_lastmonth - d;
    cout << ans << "\n";
    return ;
}

int main() {
    int n; cin>>n;
    rep(data,n) {
        int y,m,d; cin>>y>>m>>d;
        solve(y,m,d);
    }
    return 0;
}

Measured memory_bytes: 3132
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

def main():
    n = int(input())

    ans = 0

    for i in range(1,n+1):
        if i % 2 == 0:
            continue
        if len(make_divisors(i)) == 8:
            ans += 1
        
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}



using namespace std;
int main(){
    ll x;
    cin >> x;
    string S = "";

    while (x){
        if(x %2 != 0){
            S = '1' + S;
            x--;
        }else{
            S = '0' + S;
        }

        x/= -2;
    }

    if(S =="") S = "0";
    cout << S <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
int a[1010][1010];
int n, m;
string s;
queue<pair<int, int>>q;
int deep = 1, cnt = 0, len = 0;
void add(int x, int y) {
	if (x >= 0 && x < n && y >= 0 && y < m) {
		if (a[x][y] == 0) {
			q.push({ x,y });
			a[x][y] = deep;
			++cnt;
		}
	}
}
int main() {
	int i, j;
	cin >> n >> m;
	for (i = 0; i < n; ++i) {
		cin >> s;
		for (j = 0; j < m; ++j) {
			if (s[j] == '#') {
				q.push({ i,j });
				a[i][j] = 1;
				++len;
			}
			else a[i][j] = 0;
		}
	}
	while (!q.empty()) {
		++deep;
		while (len--) {
			pair<int, int>t = q.front();
			q.pop();
			int x = t.first, y = t.second;
			add(x - 1, y), add(x + 1, y), add(x, y - 1), add(x, y + 1);
		}
		len = cnt;
		cnt = 0;
	}
	cout << deep - 2 << endl;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  double A[N];
  double sum=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    sum+=A[i];
  }
  int ans=-1;
  double dif=1000;
  double ave=sum/N;
  for(int i=0;i<N;i++){
    if(abs(A[i]-ave)<dif){
      dif=abs(A[i]-ave);
      ans=i;
    }
    //cout<<A[i]<<" "<<i<<" "<<dif<<endl;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
r=filter
f=lambda c:sum([map(lambda z:z+y,f(c-1))for y in'357'],[]) if c!=0 else ['']
print(sum([len(r(lambda y:y==3,map(lambda x:len(set(sorted(x))),r(lambda z:int(z)<=N,f(e+1)))))for e in range(10)]))


Measured memory_bytes: 7752
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    3.rep!(() => readln.chomp.map!(c => c-'a').pipe!(str => DList!int(str))).pipe!((ary) {
        int now = 0;
        while(!ary[now].empty) {
            int tmp = ary[now].front;
            ary[now].removeFront;
            now = tmp;
        }
        return now;
    }).pipe!(i => "ABC"[i]).writeln;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int N, L;
    cin >> N >> L;
    vs strings = input<string>(N);

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

    stringstream ss;
    repeat (i, strings.size()) {
        ss << strings[i];
    }
    cout << ss.str() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    string s;
    cin>>s;
    int a=0;
    int b=0;
   if(s[0]=='1')  a++;
               
    for(int i=1;i<s.size();i++){
        if(i%2==1){
            if(s[i]=='0'){
                a++;
            }
        }else{
            if(s[i]=='1'){
                a++;
            }
        }
    }
    if(s[0]=='0')  b++;
        for(int i=1;i<s.size();i++){
            if(i%2==1){
                if(s[i]=='1'){
                    b++;
                }
            }else{
                if(s[i]=='0'){
                    b++;
                }
            }
        }
    
    
    
    cout<<min(a,b);
    return 0;
}


Measured memory_bytes: 512
import sys
input=sys.stdin.readline
import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
r=a[n-1]*2+1
l=0
while r-l>=2:
	mid=(l+r)//2
	#mid以上はいくつあるか
	#答えはl以上r未満
	cnt=0
	for i in range(n):
		cnt+=n-bisect.bisect_left(a,mid-a[i])
	if cnt>=k:
		l=mid
	else:
		r=mid
#lだとk個以上　rだとk個未満
ans,p,=0,0
b=[0]
for i in range(n):
	p+=a[i]
	b.append(p)
for i in range(n):
	q=bisect.bisect_left(a,r-a[i])
	ans+=b[n]-b[q]
	ans+=a[i]*(n-q)
	k-=n-q
ans+=l*k
print(ans)


Measured memory_bytes: 14536
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(0, s.size()) {
    if (s[i] == '+') {
      ans++;
    } else {
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3192
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
	int n;
	cin >> n;
	int count=0;
	int input;
	REP(i,n){
		cin >> input;
		if(i+1!=input) count++;
	}
	
	if(count==0 || count==2) cout << "YES\n";
	else cout << "NO\n";
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

int _find(vector<string> &arr,int n){
    set<string> s;
    if(n==0){return 1;}
    s.insert(arr[0]);
    int lastCh=arr[0].back();
    for(int i=1;i<n;i++){
        if(s.count(arr[i])){
            return false;
        }
        if(arr[i][0]!=lastCh){
            return false;
        }
        s.insert(arr[i]);
        lastCh=arr[i].back();
    }
    return 1;
}

void solve(){
    int n;
    cin>>n;
    vector<string> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    if(_find(arr,n)){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}




int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
typedef double DB;
const DB eps=1e-8;
bool EQ(DB x,DB y) {
	return abs(x-y)<eps;
}
struct O {
	DB x,y;
	O operator + (const O &_) const {return (O){x+_.x,y+_.y};}
	O operator - (const O &_) const {return (O){x-_.x,y-_.y};}
	O operator * (const DB &k) const {return (O){x*k,y*k};}
	O operator / (const DB &k) const {return (O){x/k,y/k};}
	DB operator * (const O &_) const {return x*_.y-y*_.x;}
	DB operator ^ (const O &_) const {return x*_.x+y*_.y;}
	DB len() {return sqrt(x*x+y*y);}
	bool dn() {return y<-eps||(EQ(y,0)&&x<0);}
	bool operator < (const O &_) const {return x<_.x||(x==_.x&&y<_.y);}
};
bool cmp(O a,O b) {
	if(a.dn()!=b.dn()) return a.dn()<b.dn();
	return a*b>0;
}
void rd(O &P) {
	scanf("%lf%lf",&P.x,&P.y);
}
void wt(O p,int w=2) {
	printf("(%.*f,%.*f)\n",w,p.x,w,p.y);
}
struct L {
	O p,v;
	O operator & (const L &_) const {
		return p+v*((_.v*(p-_.p))/(v*_.v));
	}
	bool operator < (const L &_) const {
		return cmp(v,_.v);
	}
};
O operator / (const O &p,const L &l) {
	return l.p+l.v*((l.v^(p-l.p))/(l.v^l.v));
}
DB dis(O a,O b) {
	return (a-b).len();
}
DB dis(O a,L b) {
	return dis(a,a/b);
}
O rot(O v,DB a) {
	return (O){v.x*cos(a)-v.y*sin(a),v.x*sin(a)+v.y*cos(a)};
}
bool beng(O a,O b,O c) {
	return (b.y-a.y)*(c.x-b.x)<=(c.y-b.y)*(b.x-a.x);
}
bool onSeg(O a,O b,O c) {
	return EQ((b-a)*(c-a),0)&&((b-a)^(c-a))<eps;
}
bool ri(O p,L l) {
	return (p-l.p)*l.v>eps;
}
int n,q; O Q[107],p;
void inPoly() {
	int wn=0;
	For(i,0,n-1) {
		if(onSeg(p,Q[i],Q[i+1])) {
			puts("1");
			return;
		}
		DB k=(Q[i+1]-Q[i])*(p-Q[i]),a=Q[i].y-p.y,b=Q[i+1].y-p.y;
		if(k>eps&&a<eps&&b>eps) ++wn;
		if(k<-eps&&b<eps&&a>eps) --wn;
	}
	if(wn!=0) puts("2");
	else puts("0");
}
int main() {
	scanf("%d",&n);
	For(i,1,n) rd(Q[i]); Q[0]=Q[n];
	scanf("%d",&q);
	while(q--) {
		rd(p);
		inPoly();
	}
	return 0;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 1; i < n; i++){
        int cnt = 0;
        for(char c = 'a'; c <= 'z'; c++){
            bool left = false;
            bool right = false;
            for(int j = 0; j < i; j++){
                if(s[j] == c) left = true;
            }
            for(int j = i; j < n; j++){
                if(s[j] == c) right = true;
            }
            if((left == true) && (right == true)) cnt++;
        }
        if(ans < cnt) ans = cnt;
    }
    cout << ans << endl;
    return 0;
}

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

const int dx[4] = { 0, 0, -1, 1 };
const int dy[4] = { -1, 1, 0, 0 };
const char mov[] = "UDLR";
const char tank[] = "^v<>";

int h, w, d, x, y;
string map[22], command;

int main()
{
    int t, n;
    cin >> t;
    map[0] = "######################";

    for(int i = 1; ; ++i)
    {
        cin >> h >> w;
        for(int j = 1; j <= h; ++j) {
            cin >> map[j];
            map[j] = "#" + map[j] + "#";
        }
        map[h+1] = map[0];
        cin >> n >> command;

        for(int j = 1; j <= h; ++j)
            for(int k = 0; k < 4; ++k)
				if(map[j].find(tank[k]) != string::npos)
					y = j, x = map[j].find(tank[k]), d = k, map[y][x] = '.';

        for(int j = 0; j < n; ++j)
        {
            for(int k = 0; k < 4; ++k)
                if(command[j] == mov[k]) {
                    d = k;
                    if(map[y+dy[d]][x+dx[d]] == '.')
                        x += dx[d], y += dy[d];
                }

            if(command[j] == 'S')
                for(int xx = x, yy = y; map[yy][xx] != '#'; xx += dx[d], yy += dy[d])
                    if(map[yy][xx] == '*') { map[yy][xx] = '.'; break; }
        }

        map[y][x] = tank[d];

        for(int j = 1; j <= h; ++j)
            cout << map[j].substr(1, w) << endl;

        if(i == t) break;
        cout << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,k;
    cin>>n>>k;
    ll x=(n-1)/2;
    if(2*k+2*n-1>k+2*n+x){cout<<-1;return 0;}
    vector<ll> ans;
    rep(i,n) ans.push_back(i+k);
    ll m=n;
    if(n%2==0) m--;
    ll a=m/2,b=m-a;
    if(a%2==0) swap(a,b);
    rep(i,a/2) swap(ans[i],ans[a-i-1]);
    for(int i=a;i<a+b/2;i++) swap(ans[i],ans[b+2*a-i-1]);
    vector<pair<ll,ll>> ANS;
    rep(i,n) ANS.push_back(make_pair(ans[i]+k+2*n-1-i,ans[i]));
    sort(ANS.begin(),ANS.end());
    rep(i,n){
        cout<<ANS[i].second<<" "<<ANS[i].first-ANS[i].second<<" "<<k+2*n+i;
        cout<<endl;
    }
}

Measured memory_bytes: 4720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,d,k,l,ans;
int main(){
	scanf("%lld%lld%lld",&x,&k,&d);
	if (x==0){
		if (k%2==0) printf("0\n");
		else printf("%lld\n",d);
	}
	else if (x>0){
		l=min(x/d,k);
		x-=d*l;
		k-=l;
		if (k==0) printf("%lld\n",x);
		else {
			x=x-k%2*d;
			printf("%lld\n",abs(x));
		}
	}
	else {
		l=min(abs(x)/d,k);
		x+=d*l;
		k-=l;
		if (k==0) printf("%lld\n",abs(x));
		else {
			x=x+k%2*d;
			printf("%lld\n",abs(x));
		}
	}
}

Measured memory_bytes: 3756
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
abc = []
for i in range(m):
    a, b = map(int, input().split())
    tmpc = map(int, input().split())
    c = sum(1 << (ci - 1) for ci in tmpc)
    abc.append([a,b,c])

# 解説AC
dp = [[0] + [pow(10, 9)] * (pow(2, n) - 1)]
for i, (ai, _, ci) in enumerate(abc, 1):
    dp.append(dp[-1][:])
    for j in range(pow(2, n)):
        tmp = min(dp[i - 1][j | ci], dp[i - 1][j] + ai)
        dp[i][j | ci] = min(tmp, dp[i][j | ci])
print(-1 if dp[-1][-1] == pow(10, 9) else dp[-1][-1])


Measured memory_bytes: 105332
#include <iostream>
#include <algorithm>
#include <limits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <cmath>

using namespace std;

int s;
const int mod = 1e9 + 7;

int main() {
    scanf("%d", &s);
    vector<long long> cnt(s + 1, 0);
    cnt[0] = 1;
    for (int i = 3; i <= s; ++i) {
        for (int k = 3; k <= i; ++k) {
            cnt[i] += cnt[i - k];
            cnt[i] %= mod;
        }
    }
    printf("%lld\n", cnt[s]);
    return 0;
}


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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
// #define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acosl(-1)
#define ld long double
#define prime (1000000000 + 7)
#define INF 1000000000

using namespace std;

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

    vector<vl> vet(3, vl(3));
    vll mapa(101, {-1, -1});
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < 3; ++j){
            ll a;
            cin >> a;
            mapa[a] = {i, j};
        }
    }
    ll n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        ll b;
        cin >> b;
        if(mapa[b] != pll{-1, -1}){
            vet[mapa[b].ff][mapa[b].ss] = 1;
        }
    }
    if((vet[0][0] == 1 && vet[0][1] == 1 && vet[0][2] == 1) || (vet[1][0] == 1 && vet[1][1] == 1 && vet[1][2] == 1) || (vet[2][0] == 1 && vet[2][1] == 1 && vet[2][2] == 1) || (vet[0][0] == 1 && vet[1][0] == 1 && vet[2][0] == 1) || (vet[0][1] == 1 && vet[1][1] == 1 && vet[2][1] == 1) || (vet[0][2] == 1 && vet[1][2] == 1 && vet[2][2] == 1) ||(vet[0][0] == 1 && vet[1][1] == 1 && vet[2][2] == 1) || (vet[0][2] == 1 && vet[1][1] == 1 && vet[2][0] == 1)){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<numeric>
#include<vector>
#include<iostream>
#include<map>

using namespace::std;

int main(void)
{

  vector<int>h(10);

  for(int i = 0; i < 10; i++)
    {
      cin >> h[i];
    }

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

  for(int i = 0; i < 3; i++)
    {
      cout << h[i] << endl;
    }

  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

// template from zscoder

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,t,x,y,pt(0);
    cin >> n;
    vi tt(n+1);
    vi xx(n+1);
    vi yy(n+1);
    bool ok = true;
    for(int i = 1; i <= n; i++)
    {
        cin >> tt[i] >> xx[i] >> yy[i];
    }
    tt[0] = 0;
    xx[0] = 0;
    yy[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        t = abs(tt[i]-tt[i-1]);
        x = abs(xx[i]-xx[i-1]);
        y = abs(yy[i]-yy[i-1]);
        if(t<(x+y)||(t-(x+y))%2==1)ok = false;
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
# Written by NoKnowledgeGG @YlePhan
 
#import math
#mod = 10**9+7
 
 
 
def main():
  s = input()
  t = input()
  
  s = sorted(list(s))
  t = sorted(list(t),reverse=True)
  #print(s,t)
  if s < t:
    print('Yes')
  else:
    print('No')
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N= 1e7 + 5;
const ll mod=1e9 + 7;
ll fct[N],inv[N],invfct[N];
void init(){
    fct[0]=fct[1]=1;
	inv[1]=1;
	invfct[0]=invfct[1]=1;
	for(ll i=2;i<N;i++){
		fct[i]=i*fct[i-1]%mod;
		inv[i]=ll(mod-inv[mod%i])*(mod/i)%mod;
		invfct[i]=ll(inv[i])*invfct[i-1]%mod;
	}
}


int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    init();
    ll x,y;
    cin>>x>>y;
    if((x+y)%3)return cout<<0 , 0;
    if(x>y)swap(x,y);
    ll n = (x+y)/3;
    ll r = (2*x-y)/3;
    if(r>n || r<0)return cout<<0 , 0;
    cout<<( (fct[n]*invfct[r])%mod * invfct[n-r] )%mod;

}



Measured memory_bytes: 234624